Skip to content

Some more reductions of allocations #9621

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ object Types {
final def exists: Boolean = this.ne(NoType)

/** This type, if it exists, otherwise `that` type */
def orElse(that: => Type): Type = if (exists) this else that
inline def orElse(inline that: => Type): Type = if (exists) this else that

/** Is this type a value type? */
final def isValueType: Boolean = this.isInstanceOf[ValueType]
Expand Down
7 changes: 3 additions & 4 deletions compiler/src/dotty/tools/dotc/typer/Applications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1357,11 +1357,10 @@ trait Applications extends Compatibility {
followApply && tp.member(nme.apply).hasAltWith(d => p(TermRef(tp, nme.apply, d)))
}

/** Does `tp` have an extension method named `extension_name` with this-argument `argType` and
* result matching `resultType`?
/** Does `tp` have an extension method named `xname` with this-argument `argType` and
* result matching `resultType`? `xname` is supposed to start with `extension_`.
*/
def hasExtensionMethod(tp: Type, name: TermName, argType: Type, resultType: Type)(using Context) = {
val xname = name.toExtensionName
def hasExtensionMethodNamed(tp: Type, xname: TermName, argType: Type, resultType: Type)(using Context) = {
def qualifies(mbr: Denotation) =
mbr.exists && isApplicableType(tp.select(xname, mbr), argType :: Nil, resultType)
tp.memberBasedOnFlags(xname, required = ExtensionMethod) match {
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Checking.scala
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ object Checking {
def checkNoConflict(flag1: FlagSet, flag2: FlagSet, msg: => String) =
if (sym.isAllOf(flag1 | flag2)) fail(msg)
def checkCombination(flag1: FlagSet, flag2: FlagSet) =
checkNoConflict(flag1, flag2, i"illegal combination of modifiers: `${flag1.flagsString}` and `${flag2.flagsString}` for: $sym")
if sym.isAllOf(flag1 | flag2) then fail(i"illegal combination of modifiers: `${flag1.flagsString}` and `${flag2.flagsString}` for: $sym")
def checkApplicable(flag: FlagSet, ok: Boolean) =
if (!ok && !sym.is(Synthetic))
fail(i"modifier `${flag.flagsString}` is not allowed for this definition")
Expand Down
8 changes: 4 additions & 4 deletions compiler/src/dotty/tools/dotc/typer/Implicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ object Implicits:
* method with the selecting name? False otherwise.
*/
def hasExtMethod(tp: Type, expected: Type)(using Context) = expected match
case SelectionProto(name, _, _, _) =>
tp.memberBasedOnFlags(name.toExtensionName, required = ExtensionMethod).exists
case selProto @ SelectionProto(_: TermName, _, _, _) =>
tp.memberBasedOnFlags(selProto.extensionName, required = ExtensionMethod).exists
case _ => false

def strictEquality(using Context): Boolean =
Expand Down Expand Up @@ -1034,9 +1034,9 @@ trait Implicits:
pt, locked)
}
pt match
case SelectionProto(name: TermName, mbrType, _, _) if cand.isExtension =>
case selProto @ SelectionProto(_: TermName, mbrType, _, _) if cand.isExtension =>
def tryExtension(using Context) =
extMethodApply(untpd.Select(untpdGenerated, name.toExtensionName), argument, mbrType)
extMethodApply(untpd.Select(untpdGenerated, selProto.extensionName), argument, mbrType)
if cand.isConversion then
val extensionCtx, conversionCtx = ctx.fresh.setNewTyperState()
val extensionResult = tryExtension(using extensionCtx)
Expand Down
9 changes: 7 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ object ProtoTypes {
abstract case class SelectionProto(name: Name, memberProto: Type, compat: Compatibility, privateOK: Boolean)
extends CachedProxyType with ProtoType with ValueTypeOrProto {

private var myExtensionName: TermName = null
def extensionName: TermName =
if myExtensionName == null then myExtensionName = name.toExtensionName
myExtensionName

/** Is the set of members of this type unknown? This is the case if:
* 1. The type has Nothing or Wildcard as a prefix or underlying type
* 2. The type has an uninstantiated TypeVar as a prefix or underlying type,
Expand Down Expand Up @@ -416,8 +421,8 @@ object ProtoTypes {
def isMatchedBy(tp: Type, keepConstraint: Boolean)(using Context): Boolean =
ctx.typer.isApplicableType(tp, argType :: Nil, resultType) || {
resType match {
case SelectionProto(name: TermName, mbrType, _, _) =>
ctx.typer.hasExtensionMethod(tp, name, argType, mbrType)
case selProto @ SelectionProto(_: TermName, mbrType, _, _) =>
ctx.typer.hasExtensionMethodNamed(tp, selProto.extensionName, argType, mbrType)
//.reporting(i"has ext $tp $name $argType $mbrType: $result")
case _ =>
false
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2432,7 +2432,7 @@ class Typer extends Namer
case tree: untpd.Bind => typedBind(tree, pt)
case tree: untpd.ValDef =>
if (tree.isEmpty) tpd.EmptyValDef
else typedValDef(tree, sym)(using ctx.localContext(tree, sym).setNewScope)
else typedValDef(tree, sym)(using ctx.localContext(tree, sym))
case tree: untpd.DefDef =>
val typer1 = localTyper(sym)
typer1.typedDefDef(tree, sym)(using ctx.localContext(tree, sym).setTyper(typer1))
Expand Down Expand Up @@ -3468,10 +3468,10 @@ class Typer extends Namer

// try an extension method in scope
pt match {
case SelectionProto(name, mbrType, _, _) =>
case selProto @ SelectionProto(_: TermName, mbrType, _, _) =>
def tryExtension(using Context): Tree =
try
findRef(name.toExtensionName, WildcardType, ExtensionMethod, tree.srcPos) match {
findRef(selProto.extensionName, WildcardType, ExtensionMethod, tree.srcPos) match {
case ref: TermRef =>
extMethodApply(untpd.ref(ref).withSpan(tree.span), tree, mbrType)
case _ => EmptyTree
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/i7813.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
implicit def f[X <: Undefined](implicit a: Int): X = ??? // error
def g(arg: h.NonExistent): Int = ???
def g(arg: h.NonExistent): Int = ??? // error
val h: Int = ???