Skip to content

Commit ba663f7

Browse files
committed
Address reviewers comments.
1 parent b3a169a commit ba663f7

File tree

2 files changed

+21
-24
lines changed

2 files changed

+21
-24
lines changed

src/dotty/tools/dotc/core/TyperState.scala

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,12 @@ class TyperState(r: Reporter) extends DotClass with Showable {
6565
/** Optionally, if this is a mutable typerstate, it's creator state */
6666
def parent: Option[TyperState] = None
6767

68-
/** The closest ancestor of this typer state (including possible this typer state itself)
69-
* which is not yet committed.
68+
/** The closest ancestor of this typer state (including possibly this typer state itself)
69+
* which is not yet committed, or which does not have a parent.
7070
*/
71-
def uncommittedAncestor: TyperState = parent match {
72-
case Some(p) if p.isCommitted => p.uncommittedAncestor
73-
case _ => this
74-
}
71+
def uncommittedAncestor: TyperState =
72+
if (!isCommitted || !parent.isDefined) this
73+
else parent.get.uncommittedAncestor
7574

7675
/** Make type variable instances permanent by assigning to `inst` field if
7776
* type variable instantiation cannot be retracted anymore. Then, remove

src/dotty/tools/dotc/typer/ProtoTypes.scala

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -182,20 +182,6 @@ object ProtoTypes {
182182
if ((args eq this.args) && (resultType eq this.resultType) && (typer eq this.typer)) this
183183
else new FunProto(args, resultType, typer)
184184

185-
def argsAreTyped: Boolean = myTypedArgs.size == args.length
186-
187-
private def typedArg(arg: untpd.Tree, typerFn: untpd.Tree => Tree)(implicit ctx: Context): Tree = {
188-
var targ = myTypedArg(arg)
189-
if (targ == null) {
190-
targ = typerFn(arg)
191-
if (!ctx.reporter.hasPending) {
192-
myTypedArg = myTypedArg.updated(arg, targ)
193-
evalState = evalState.updated(arg, ctx.typerState)
194-
}
195-
}
196-
targ
197-
}
198-
199185
/** Forget the types of any arguments that have been typed producing a constraint in a
200186
* typer state that is not yet committed into the one of the current context `ctx`.
201187
* This is necessary to avoid "orphan" PolyParams that are referred to from
@@ -206,27 +192,40 @@ object ProtoTypes {
206192
def allArgTypesAreCurrent()(implicit ctx: Context): Boolean = {
207193
evalState foreachBinding { (arg, tstate) =>
208194
if (tstate.uncommittedAncestor.constraint ne ctx.typerState.constraint) {
209-
println(i"need to invalidate $arg / ${myTypedArg(arg)}, ${tstate.constraint}, current = ${ctx.typerState.constraint}")
195+
typr.println(i"need to invalidate $arg / ${myTypedArg(arg)}, ${tstate.constraint}, current = ${ctx.typerState.constraint}")
210196
myTypedArg = myTypedArg.remove(arg)
211197
evalState = evalState.remove(arg)
212198
}
213199
}
214200
myTypedArg.size == args.length
215201
}
216202

203+
private def cacheTypedArg(arg: untpd.Tree, typerFn: untpd.Tree => Tree)(implicit ctx: Context): Tree = {
204+
var targ = myTypedArg(arg)
205+
if (targ == null) {
206+
targ = typerFn(arg)
207+
if (!ctx.reporter.hasPending) {
208+
myTypedArg = myTypedArg.updated(arg, targ)
209+
evalState = evalState.updated(arg, ctx.typerState)
210+
}
211+
}
212+
targ
213+
}
214+
217215
/** The typed arguments. This takes any arguments already typed using
218216
* `typedArg` into account.
219217
*/
220218
def typedArgs: List[Tree] = {
221-
if (!argsAreTyped) myTypedArgs = args.mapconserve(typedArg(_, typer.typed(_)))
219+
if (myTypedArgs.size != args.length)
220+
myTypedArgs = args.mapconserve(cacheTypedArg(_, typer.typed(_)))
222221
myTypedArgs
223222
}
224223

225224
/** Type single argument and remember the unadapted result in `myTypedArg`.
226225
* used to avoid repeated typings of trees when backtracking.
227226
*/
228227
def typedArg(arg: untpd.Tree, formal: Type)(implicit ctx: Context): Tree = {
229-
val targ = typedArg(arg, typer.typedUnadapted(_, formal))
228+
val targ = cacheTypedArg(arg, typer.typedUnadapted(_, formal))
230229
typer.adapt(targ, formal, arg)
231230
}
232231

@@ -262,7 +261,6 @@ object ProtoTypes {
262261
*/
263262
class FunProtoTyped(args: List[tpd.Tree], resultType: Type, typer: Typer)(implicit ctx: Context) extends FunProto(args, resultType, typer)(ctx) {
264263
override def typedArgs = args
265-
override def argsAreTyped = true
266264
}
267265

268266
/** A prototype for implicitly inferred views:

0 commit comments

Comments
 (0)