Skip to content

DO NOT MERGE: Turn off FunProto caching of typed args #3546

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

Closed
wants to merge 1 commit into from
Closed
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
12 changes: 9 additions & 3 deletions compiler/src/dotty/tools/dotc/typer/Applications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -409,9 +409,15 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
* @return A type transformation to apply to all arguments following this one.
*/
def addTyped(arg: Arg, formal: Type): Type => Type = {
addArg(typedArg(arg, formal), formal)
if (methodType.isParamDependent)
safeSubstParam(_, methodType.paramRefs(n), typeOfArg(arg))
val targ = typedArg(arg, formal)
addArg(targ, formal)
if (methodType.isParamDependent) {
val typeOfArg = targ match {
case tp: Type => tp
case tree: tpd.Tree => tree.tpe
}
safeSubstParam(_, methodType.paramRefs(n), typeOfArg)
}
else identity
}

Expand Down
22 changes: 3 additions & 19 deletions compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -202,25 +202,12 @@ object ProtoTypes {
* current constraint. A test case is pos/t1756.scala.
* @return True if all arguments have types (in particular, no types were forgotten).
*/
def allArgTypesAreCurrent()(implicit ctx: Context): Boolean = {
evalState foreachBinding { (arg, tstate) =>
if (tstate.uncommittedAncestor.constraint ne ctx.typerState.constraint) {
typr.println(i"need to invalidate $arg / ${myTypedArg(arg)}, ${tstate.constraint}, current = ${ctx.typerState.constraint}")
myTypedArg = myTypedArg.remove(arg)
evalState = evalState.remove(arg)
}
}
myTypedArg.size == args.length
}
def allArgTypesAreCurrent()(implicit ctx: Context): Boolean = false

private def cacheTypedArg(arg: untpd.Tree, typerFn: untpd.Tree => Tree)(implicit ctx: Context): Tree = {
var targ = myTypedArg(arg)
if (targ == null) {
targ = typerFn(arg)
if (!ctx.reporter.hasPending) {
myTypedArg = myTypedArg.updated(arg, targ)
evalState = evalState.updated(arg, ctx.typerState)
}
}
targ
}
Expand All @@ -229,9 +216,7 @@ object ProtoTypes {
* `typedArg` into account.
*/
def typedArgs: List[Tree] = {
if (myTypedArgs.size != args.length)
myTypedArgs = args.mapconserve(cacheTypedArg(_, typer.typed(_)))
myTypedArgs
args.mapconserve(cacheTypedArg(_, typer.typed(_)))
}

/** Type single argument and remember the unadapted result in `myTypedArg`.
Expand All @@ -245,8 +230,7 @@ object ProtoTypes {
/** The type of the argument `arg`.
* @pre `arg` has been typed before
*/
def typeOfArg(arg: untpd.Tree)(implicit ctx: Context): Type =
myTypedArg(arg).tpe
def typeOfArg(arg: untpd.Tree)(implicit ctx: Context): Type = ???

private[this] var myTupled: Type = NoType

Expand Down
14 changes: 14 additions & 0 deletions tests/pos/i3538.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Inv[T]

class Test {
implicit class Wrong(test: Test) {
def right: Any = ???
}
implicit class Right(test: Test) {
def right(node: Any): Any = ???
}

def inv[T](x: T): Inv[T] = ???

this.right(inv(1))
}