From ba663f7b9f2d62f08d73133dab26d978d6a4ecb7 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sun, 21 Aug 2016 12:54:22 +0200 Subject: Address reviewers comments. --- src/dotty/tools/dotc/typer/ProtoTypes.scala | 34 ++++++++++++++--------------- 1 file changed, 16 insertions(+), 18 deletions(-) (limited to 'src/dotty/tools/dotc/typer/ProtoTypes.scala') diff --git a/src/dotty/tools/dotc/typer/ProtoTypes.scala b/src/dotty/tools/dotc/typer/ProtoTypes.scala index 4e2134c6a..f209c99be 100644 --- a/src/dotty/tools/dotc/typer/ProtoTypes.scala +++ b/src/dotty/tools/dotc/typer/ProtoTypes.scala @@ -182,20 +182,6 @@ object ProtoTypes { if ((args eq this.args) && (resultType eq this.resultType) && (typer eq this.typer)) this else new FunProto(args, resultType, typer) - def argsAreTyped: Boolean = myTypedArgs.size == args.length - - private def typedArg(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 - } - /** Forget the types of any arguments that have been typed producing a constraint in a * typer state that is not yet committed into the one of the current context `ctx`. * This is necessary to avoid "orphan" PolyParams that are referred to from @@ -206,7 +192,7 @@ object ProtoTypes { def allArgTypesAreCurrent()(implicit ctx: Context): Boolean = { evalState foreachBinding { (arg, tstate) => if (tstate.uncommittedAncestor.constraint ne ctx.typerState.constraint) { - println(i"need to invalidate $arg / ${myTypedArg(arg)}, ${tstate.constraint}, current = ${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) } @@ -214,11 +200,24 @@ object ProtoTypes { myTypedArg.size == args.length } + 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 + } + /** The typed arguments. This takes any arguments already typed using * `typedArg` into account. */ def typedArgs: List[Tree] = { - if (!argsAreTyped) myTypedArgs = args.mapconserve(typedArg(_, typer.typed(_))) + if (myTypedArgs.size != args.length) + myTypedArgs = args.mapconserve(cacheTypedArg(_, typer.typed(_))) myTypedArgs } @@ -226,7 +225,7 @@ object ProtoTypes { * used to avoid repeated typings of trees when backtracking. */ def typedArg(arg: untpd.Tree, formal: Type)(implicit ctx: Context): Tree = { - val targ = typedArg(arg, typer.typedUnadapted(_, formal)) + val targ = cacheTypedArg(arg, typer.typedUnadapted(_, formal)) typer.adapt(targ, formal, arg) } @@ -262,7 +261,6 @@ object ProtoTypes { */ class FunProtoTyped(args: List[tpd.Tree], resultType: Type, typer: Typer)(implicit ctx: Context) extends FunProto(args, resultType, typer)(ctx) { override def typedArgs = args - override def argsAreTyped = true } /** A prototype for implicitly inferred views: -- cgit v1.2.3