Skip to content

Commit 5b0c484

Browse files
committed
Refactor checking for symbol references in signatures, when infering tracked
1 parent dd530d5 commit 5b0c484

File tree

3 files changed

+167
-28
lines changed

3 files changed

+167
-28
lines changed

after-printing.txt

+151
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
Header:
2+
version: <elided>
3+
tooling: <elided>
4+
UUID: <elided>
5+
6+
Names (351 bytes, starting from <elided base index>):
7+
0: ASTs
8+
1: <empty>
9+
2: scala
10+
3: reflect
11+
4: scala[Qualified . reflect]
12+
5: ClassTag
13+
6: Foo
14+
7: <init>
15+
8: java
16+
9: lang
17+
10: java[Qualified . lang]
18+
11: Object
19+
12: java[Qualified . lang][Qualified . Object]
20+
13: <init>[Signed Signature(List(),java.lang.Object) @<init>]
21+
14: Unit
22+
15: mkArray
23+
16: T
24+
17: Nothing
25+
18: Any
26+
19: WitnessNames
27+
20: annotation
28+
21: scala[Qualified . annotation]
29+
22: internal
30+
23: scala[Qualified . annotation][Qualified . internal]
31+
24: scala[Qualified . annotation][Qualified . internal][Qualified . WitnessNames]
32+
25: collection
33+
26: scala[Qualified . collection]
34+
27: immutable
35+
28: scala[Qualified . collection][Qualified . immutable]
36+
29: Seq
37+
30: scala[Qualified . collection][Qualified . immutable][Qualified . Seq]
38+
31: <init>[Signed Signature(List(scala.collection.immutable.Seq),scala.annotation.internal.WitnessNames) @<init>]
39+
32: String
40+
33: evidence$1
41+
34: evidence$
42+
35: [Unique evidence$ 1]
43+
36: ???
44+
37: Predef
45+
38: SourceFile
46+
39: scala[Qualified . annotation][Qualified . internal][Qualified . SourceFile]
47+
40: java[Qualified . lang][Qualified . String]
48+
41: <init>[Signed Signature(List(java.lang.String),scala.annotation.internal.SourceFile) @<init>]
49+
42: <elided source file name>
50+
43: Positions
51+
44: Comments
52+
45: Attributes
53+
54+
Trees (122 bytes, starting from <elided base index>):
55+
0: PACKAGE(120)
56+
2: TERMREFpkg 1 [<empty>]
57+
4: IMPORT(4)
58+
6: TERMREFpkg 4 [scala[Qualified . reflect]]
59+
8: IMPORTED 5 [ClassTag]
60+
10: TYPEDEF(110) 6 [Foo]
61+
13: TEMPLATE(89)
62+
15: APPLY(10)
63+
17: SELECTin(8) 13 [<init>[Signed Signature(List(),java.lang.Object) @<init>]]
64+
20: NEW
65+
21: TYPEREF 11 [Object]
66+
23: TERMREFpkg 10 [java[Qualified . lang]]
67+
25: SHAREDtype 21
68+
27: DEFDEF(7) 7 [<init>]
69+
30: EMPTYCLAUSE
70+
31: TYPEREF 14 [Unit]
71+
33: TERMREFpkg 2 [scala]
72+
35: STABLE
73+
36: DEFDEF(66) 15 [mkArray]
74+
39: TYPEPARAM(35) 16 [T]
75+
42: TYPEBOUNDStpt(8)
76+
44: TYPEREF 17 [Nothing]
77+
46: SHAREDtype 33
78+
48: TYPEREF 18 [Any]
79+
50: SHAREDtype 33
80+
52: ANNOTATION(22)
81+
54: TYPEREF 19 [WitnessNames]
82+
56: TERMREFpkg 23 [scala[Qualified . annotation][Qualified . internal]]
83+
58: APPLY(16)
84+
60: SELECTin(6) 31 [<init>[Signed Signature(List(scala.collection.immutable.Seq),scala.annotation.internal.WitnessNames) @<init>]]
85+
63: NEW
86+
64: SHAREDtype 54
87+
66: SHAREDtype 54
88+
68: REPEATED(6)
89+
70: TYPEREF 32 [String]
90+
72: SHAREDtype 23
91+
74: STRINGconst 33 [evidence$1]
92+
76: PARAM(14) 35 [[Unique evidence$ 1]]
93+
79: APPLIEDtpt(10)
94+
81: IDENTtpt 5 [ClassTag]
95+
83: TYPEREF 5 [ClassTag]
96+
85: SHAREDtype 6
97+
87: IDENTtpt 16 [T]
98+
89: TYPEREFdirect 39
99+
91: GIVEN
100+
92: IDENTtpt 17 [Nothing]
101+
94: TYPEREF 17 [Nothing]
102+
96: TERMREFpkg 2 [scala]
103+
98: TERMREF 36 [???]
104+
100: TERMREF 37 [Predef]
105+
102: SHAREDtype 33
106+
104: ANNOTATION(16)
107+
106: TYPEREF 38 [SourceFile]
108+
108: SHAREDtype 56
109+
110: APPLY(10)
110+
112: SELECTin(6) 41 [<init>[Signed Signature(List(java.lang.String),scala.annotation.internal.SourceFile) @<init>]]
111+
115: NEW
112+
116: SHAREDtype 106
113+
118: SHAREDtype 106
114+
120: STRINGconst 42 [<elided source file name>]
115+
122:
116+
117+
Positions (81 bytes, starting from <elided base index>):
118+
lines: 7
119+
line sizes:
120+
38, 0, 23, 0, 10, 41, 0
121+
positions:
122+
0: 40 .. 117
123+
4: 40 .. 63
124+
6: 47 .. 54
125+
8: 55 .. 63
126+
10: 65 .. 117
127+
13: 78 .. 117
128+
21: 71 .. 71
129+
27: 78 .. 78
130+
31: 78 .. 78
131+
36: 78 .. 117
132+
39: 90 .. 101
133+
44: 93 .. 93
134+
48: 93 .. 93
135+
64: 90 .. 90
136+
70: 90 .. 90
137+
74: 90 .. 90
138+
76: 93 .. 101
139+
81: 93 .. 101
140+
87: 93 .. 101
141+
92: 104 .. 111
142+
98: 114 .. 117
143+
110: 65 .. 117
144+
116: 65 .. 65
145+
120: 65 .. 65
146+
147+
source paths:
148+
0: 42 [<elided source file name>]
149+
150+
Attributes (2 bytes, starting from <elided base index>):
151+
SOURCEFILEattr 42 [<elided source file name>]

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ object Feature:
111111
* feature is defined.
112112
*/
113113
def enabled(feature: TermName)(using Context): Boolean =
114-
enabledBySetting(feature) || enabledByImport(feature) || feature == modularity
114+
enabledBySetting(feature) || enabledByImport(feature)
115115

116116
/** Is auto-tupling enabled? */
117117
def autoTuplingEnabled(using Context): Boolean = !enabled(nme.noAutoTupling)

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

+15-27
Original file line numberDiff line numberDiff line change
@@ -2003,13 +2003,9 @@ class Namer { typer: Typer =>
20032003
/** Try to infer if the parameter needs a `tracked` modifier
20042004
*/
20052005
def needsTracked(psym: Symbol, param: ValDef, owningSym: Symbol)(using Context) =
2006-
// println(i"Checking if $psym needs tracked")
20072006
lazy val abstractContextBound = isContextBoundWitnessWithAbstractMembers(psym, param, owningSym)
20082007
lazy val isRefInSignatures =
20092008
psym.maybeOwner.isPrimaryConstructor
2010-
// && !psym.flags.is(Synthetic)
2011-
// && !psym.maybeOwner.flags.is(Synthetic)
2012-
// && !psym.maybeOwner.maybeOwner.flags.is(Synthetic)
20132009
&& isReferencedInPublicSignatures(psym)
20142010
!psym.is(Tracked)
20152011
&& psym.isTerm
@@ -2046,29 +2042,21 @@ class Namer { typer: Typer =>
20462042
case _ => false
20472043
checkOwnerMemberSignatures(owner)
20482044

2049-
private def namedTypeWithPrefixContainsSymbolRef(tpe: Type, syms: List[Symbol])(using Context): Boolean = tpe match
2050-
case tpe: NamedType => tpe.prefix.exists && tpeContainsSymbolRef(tpe.prefix, syms)
2051-
case _ => false
2052-
2053-
private def tpeContainsSymbolRef(tpe0: Type, syms: List[Symbol])(using Context): Boolean =
2054-
val tpe = tpe0.dropAlias.safeDealias
2055-
tpe match
2056-
case ExprType(resType) => tpeContainsSymbolRef(resType, syms)
2057-
case m : MethodOrPoly =>
2058-
m.paramInfos.exists(tpeContainsSymbolRef(_, syms))
2059-
|| tpeContainsSymbolRef(m.resultType, syms)
2060-
case r @ RefinedType(parent, _, refinedInfo) => tpeContainsSymbolRef(parent, syms) || tpeContainsSymbolRef(refinedInfo, syms)
2061-
case TypeBounds(lo, hi) => tpeContainsSymbolRef(lo, syms) || tpeContainsSymbolRef(hi, syms)
2062-
case t: Type =>
2063-
tpe.termSymbol.exists && syms.contains(tpe.termSymbol)
2064-
|| tpe.argInfos.exists(tpeContainsSymbolRef(_, syms))
2065-
|| namedTypeWithPrefixContainsSymbolRef(tpe, syms)
2066-
2067-
private def maybeParamAccessors(owner: Symbol, sym: Symbol)(using Context): List[Symbol] =
2068-
owner.infoOrCompleter match
2069-
case info: ClassInfo =>
2070-
info.decls.lookupAll(sym.name).filter(d => d.is(ParamAccessor)).toList
2071-
case _ => List.empty
2045+
/** Check if any of syms are referenced in tpe */
2046+
private def tpeContainsSymbolRef(tpe: Type, syms: List[Symbol])(using Context): Boolean =
2047+
val acc = new ExistsAccumulator(
2048+
{ tpe => tpe.termSymbol.exists && syms.contains(tpe.termSymbol) },
2049+
StopAt.Static,
2050+
forceLazy = false
2051+
) {
2052+
override def apply(acc: Boolean, tpe: Type): Boolean = super.apply(acc, tpe.safeDealias)
2053+
}
2054+
acc(false, tpe)
2055+
2056+
private def maybeParamAccessors(owner: Symbol, sym: Symbol)(using Context): List[Symbol] = owner.infoOrCompleter match
2057+
case info: ClassInfo =>
2058+
info.decls.lookupAll(sym.name).filter(d => d.is(ParamAccessor)).toList
2059+
case _ => List.empty
20722060

20732061
/** Under x.modularity, set every context bound evidence parameter of a class to be tracked,
20742062
* provided it has a type that has an abstract type member. Reset private and local flags

0 commit comments

Comments
 (0)