Skip to content

Commit 04ea25c

Browse files
committed
add PreTypedTypeTree to memoize type checked trees
1 parent 26c8564 commit 04ea25c

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

compiler/src/dotty/tools/dotc/ast/untpd.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,12 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
345345
def derivedTree(originalSym: Symbol)(using Context): tpd.Tree
346346
}
347347

348+
/** A type tree that memoizes the result of a typed tree. Used when
349+
* typechecking selectDynamic calls to prevent typechecking type arguments
350+
* multiple types.
351+
*/
352+
final class MemoizedTypeTree(val result: tpd.Tree)(implicit @constructorOnly src: SourceFile) extends TypeTree
353+
348354
/** Property key containing TypeTrees whose type is computed
349355
* from the symbol in this type. These type trees have marker trees
350356
* TypeRefOfSym or InfoOfSym as their originals.

compiler/src/dotty/tools/dotc/typer/Applications.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1076,7 +1076,7 @@ trait Applications extends Compatibility {
10761076
case _ =>
10771077
}
10781078
def tryDynamicTypeApply(): Tree = typedFn match {
1079-
case typedFn: Select if !pt.isInstanceOf[FunProto] => typedDynamicSelect(typedFn, tree.args, pt)
1079+
case typedFn: Select if !pt.isInstanceOf[FunProto] => typedDynamicSelect(typedFn, typedArgs.map(untpd.MemoizedTypeTree(_)), pt)
10801080
case _ => tree.withType(TryDynamicCallType)
10811081
}
10821082
if (typedFn.tpe eq TryDynamicCallType) tryDynamicTypeApply()

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1695,6 +1695,7 @@ class Typer extends Namer
16951695
case None =>
16961696
errorTree(tree, "Something's wrong: missing original symbol for type tree")
16971697
}
1698+
case tree: untpd.MemoizedTypeTree => tree.result
16981699
case _ =>
16991700
tree.withType(
17001701
if (isFullyDefined(pt, ForceDegree.flipBottom)) pt

0 commit comments

Comments
 (0)