Skip to content

Commit 0cf9ee1

Browse files
committed
Revert "Performance optimization: Precompute SELECTin criteria"
This reverts commit af103a4. # Conflicts: # compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala
1 parent 0bc0a2e commit 0cf9ee1

File tree

3 files changed

+11
-37
lines changed

3 files changed

+11
-37
lines changed

compiler/src/dotty/tools/dotc/config/Config.scala

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ object Config {
8787
*/
8888
final val alignArgsInAnd = true
8989

90+
/** If this flag is set, higher-kinded applications are checked for validity
91+
*/
92+
final val checkHKApplications = false
93+
9094
/** If this flag is set, method types are checked for valid parameter references
9195
*/
9296
final val checkMethodTypes = false
@@ -136,14 +140,6 @@ object Config {
136140
*/
137141
final val checkAtomsComparisons = false
138142

139-
/** Normally, a Select node can be unpickled giving just the name and the signature
140-
* of the selected member. However, in some rare cases, this is not enough since there
141-
* are multiple possible members with the same signature. In that case we need to
142-
* pickle the Select with a SELECTin tag. If on, we check that all ambiguous selects do
143-
* get pickled with SELECTin
144-
*/
145-
final val checkAmbiguousSelects = false
146-
147143
/** In `derivedSelect`, rewrite
148144
*
149145
* (S & T)#A --> S#A & T#A

compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ import StdNames.nme
1616
import transform.SymUtils._
1717
import printing.Printer
1818
import printing.Texts._
19-
import util.{SourceFile, Property}
20-
import config.Config.checkAmbiguousSelects
19+
import util.SourceFile
2120
import annotation.constructorOnly
2221

2322
object TreePickler {
@@ -31,13 +30,6 @@ object TreePickler {
3130
if isTermHole then s"{{{ $idx |" ~~ printer.toTextGlobal(tpe) ~~ "|" ~~ printer.toTextGlobal(args, ", ") ~~ "}}}"
3231
else s"[[[ $idx |" ~~ printer.toTextGlobal(tpe) ~~ "|" ~~ printer.toTextGlobal(args, ", ") ~~ "]]]"
3332
}
34-
35-
/** Select tree cannot be unambiguously resolved with signature alone,
36-
* needs to be pickled using the SELECTin tag. This is set by Typer, if
37-
* after overloading resolution it is discovered that other alternatives
38-
* have the same signature as the one that was selected.
39-
*/
40-
val NeedsSelectIn = new Property.StickyKey[Unit]
4133
}
4234

4335
class TreePickler(pickler: TastyPickler) {
@@ -391,17 +383,12 @@ class TreePickler(pickler: TastyPickler) {
391383
}
392384
case _ =>
393385
val sig = tree.tpe.signature
394-
val needsSelectIn = tree.hasAttachment(NeedsSelectIn)
395-
if checkAmbiguousSelects then
396-
// We use needsSelectIn instead of isAmbiguous since isAmbiguous
397-
// is more expensive to compute. This matters since either criterion
398-
// is false in almost all cases.
399-
val isAmbiguous = qual.tpe.nonPrivateMember(name) match
386+
val isAmbiguous =
387+
sig != Signature.NotAMethod
388+
&& qual.tpe.nonPrivateMember(name).match
400389
case d: MultiDenotation => d.atSignature(sig).isInstanceOf[MultiDenotation]
401390
case _ => false
402-
assert(needsSelectIn == isAmbiguous,
403-
i"ambiguity misprediction for select node $tree, is ambiguous = $isAmbiguous")
404-
if needsSelectIn then
391+
if isAmbiguous then
405392
writeByte(SELECTin)
406393
withLength {
407394
pickleNameAndSig(name, tree.symbol.signature)

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

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ import rewrites.Rewrites.patch
4040
import NavigateAST._
4141
import transform.SymUtils._
4242
import transform.TypeUtils._
43-
import tasty.TreePickler.NeedsSelectIn
4443
import reporting.trace
4544
import Nullables.{NotNullInfo, given _}
4645
import NullOpsDecorator._
@@ -2828,16 +2827,9 @@ class Typer extends Namer
28282827
typr.println(i"adapt overloaded $ref with alternatives ${altDenots map (_.info)}%\n\n %")
28292828
def altRef(alt: SingleDenotation) = TermRef(ref.prefix, ref.name, alt)
28302829
val alts = altDenots.map(altRef)
2831-
2832-
def resolveWith(alt: TermRef) =
2833-
val resolved = tree.withType(alt)
2834-
if alts.exists(a => (a ne alt) && a.signature == alt.signature) then
2835-
resolved.pushAttachment(NeedsSelectIn, ())
2836-
readaptSimplified(resolved)
2837-
28382830
resolveOverloaded(alts, pt) match {
28392831
case alt :: Nil =>
2840-
resolveWith(alt)
2832+
readaptSimplified(tree.withType(alt))
28412833
case Nil =>
28422834
// If alternative matches, there are still two ways to recover:
28432835
// 1. If context is an application, try to insert an apply or implicit
@@ -2852,8 +2844,7 @@ class Typer extends Namer
28522844
tryInsertApplyOrImplicit(tree, pt, locked)(noMatches)
28532845
case _ =>
28542846
alts.filter(_.info.isParameterless) match {
2855-
case alt :: Nil =>
2856-
resolveWith(alt)
2847+
case alt :: Nil => readaptSimplified(tree.withType(alt))
28572848
case _ =>
28582849
if (altDenots exists (_.info.paramInfoss == ListOfNil))
28592850
typed(untpd.Apply(untpd.TypedSplice(tree), Nil), pt, locked)

0 commit comments

Comments
 (0)