Skip to content

Commit

Permalink
Refactor checking for symbol references in signatures, when infering …
Browse files Browse the repository at this point in the history
…tracked
  • Loading branch information
KacperFKorban committed Nov 1, 2024
1 parent dd530d5 commit 5b0c484
Show file tree
Hide file tree
Showing 3 changed files with 167 additions and 28 deletions.
151 changes: 151 additions & 0 deletions after-printing.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
Header:
version: <elided>
tooling: <elided>
UUID: <elided>

Names (351 bytes, starting from <elided base index>):
0: ASTs
1: <empty>
2: scala
3: reflect
4: scala[Qualified . reflect]
5: ClassTag
6: Foo
7: <init>
8: java
9: lang
10: java[Qualified . lang]
11: Object
12: java[Qualified . lang][Qualified . Object]
13: <init>[Signed Signature(List(),java.lang.Object) @<init>]
14: Unit
15: mkArray
16: T
17: Nothing
18: Any
19: WitnessNames
20: annotation
21: scala[Qualified . annotation]
22: internal
23: scala[Qualified . annotation][Qualified . internal]
24: scala[Qualified . annotation][Qualified . internal][Qualified . WitnessNames]
25: collection
26: scala[Qualified . collection]
27: immutable
28: scala[Qualified . collection][Qualified . immutable]
29: Seq
30: scala[Qualified . collection][Qualified . immutable][Qualified . Seq]
31: <init>[Signed Signature(List(scala.collection.immutable.Seq),scala.annotation.internal.WitnessNames) @<init>]
32: String
33: evidence$1
34: evidence$
35: [Unique evidence$ 1]
36: ???
37: Predef
38: SourceFile
39: scala[Qualified . annotation][Qualified . internal][Qualified . SourceFile]
40: java[Qualified . lang][Qualified . String]
41: <init>[Signed Signature(List(java.lang.String),scala.annotation.internal.SourceFile) @<init>]
42: <elided source file name>
43: Positions
44: Comments
45: Attributes

Trees (122 bytes, starting from <elided base index>):
0: PACKAGE(120)
2: TERMREFpkg 1 [<empty>]
4: IMPORT(4)
6: TERMREFpkg 4 [scala[Qualified . reflect]]
8: IMPORTED 5 [ClassTag]
10: TYPEDEF(110) 6 [Foo]
13: TEMPLATE(89)
15: APPLY(10)
17: SELECTin(8) 13 [<init>[Signed Signature(List(),java.lang.Object) @<init>]]
20: NEW
21: TYPEREF 11 [Object]
23: TERMREFpkg 10 [java[Qualified . lang]]
25: SHAREDtype 21
27: DEFDEF(7) 7 [<init>]
30: EMPTYCLAUSE
31: TYPEREF 14 [Unit]
33: TERMREFpkg 2 [scala]
35: STABLE
36: DEFDEF(66) 15 [mkArray]
39: TYPEPARAM(35) 16 [T]
42: TYPEBOUNDStpt(8)
44: TYPEREF 17 [Nothing]
46: SHAREDtype 33
48: TYPEREF 18 [Any]
50: SHAREDtype 33
52: ANNOTATION(22)
54: TYPEREF 19 [WitnessNames]
56: TERMREFpkg 23 [scala[Qualified . annotation][Qualified . internal]]
58: APPLY(16)
60: SELECTin(6) 31 [<init>[Signed Signature(List(scala.collection.immutable.Seq),scala.annotation.internal.WitnessNames) @<init>]]
63: NEW
64: SHAREDtype 54
66: SHAREDtype 54
68: REPEATED(6)
70: TYPEREF 32 [String]
72: SHAREDtype 23
74: STRINGconst 33 [evidence$1]
76: PARAM(14) 35 [[Unique evidence$ 1]]
79: APPLIEDtpt(10)
81: IDENTtpt 5 [ClassTag]
83: TYPEREF 5 [ClassTag]
85: SHAREDtype 6
87: IDENTtpt 16 [T]
89: TYPEREFdirect 39
91: GIVEN
92: IDENTtpt 17 [Nothing]
94: TYPEREF 17 [Nothing]
96: TERMREFpkg 2 [scala]
98: TERMREF 36 [???]
100: TERMREF 37 [Predef]
102: SHAREDtype 33
104: ANNOTATION(16)
106: TYPEREF 38 [SourceFile]
108: SHAREDtype 56
110: APPLY(10)
112: SELECTin(6) 41 [<init>[Signed Signature(List(java.lang.String),scala.annotation.internal.SourceFile) @<init>]]
115: NEW
116: SHAREDtype 106
118: SHAREDtype 106
120: STRINGconst 42 [<elided source file name>]
122:

Positions (81 bytes, starting from <elided base index>):
lines: 7
line sizes:
38, 0, 23, 0, 10, 41, 0
positions:
0: 40 .. 117
4: 40 .. 63
6: 47 .. 54
8: 55 .. 63
10: 65 .. 117
13: 78 .. 117
21: 71 .. 71
27: 78 .. 78
31: 78 .. 78
36: 78 .. 117
39: 90 .. 101
44: 93 .. 93
48: 93 .. 93
64: 90 .. 90
70: 90 .. 90
74: 90 .. 90
76: 93 .. 101
81: 93 .. 101
87: 93 .. 101
92: 104 .. 111
98: 114 .. 117
110: 65 .. 117
116: 65 .. 65
120: 65 .. 65

source paths:
0: 42 [<elided source file name>]

Attributes (2 bytes, starting from <elided base index>):
SOURCEFILEattr 42 [<elided source file name>]
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/config/Feature.scala
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ object Feature:
* feature is defined.
*/
def enabled(feature: TermName)(using Context): Boolean =
enabledBySetting(feature) || enabledByImport(feature) || feature == modularity
enabledBySetting(feature) || enabledByImport(feature)

/** Is auto-tupling enabled? */
def autoTuplingEnabled(using Context): Boolean = !enabled(nme.noAutoTupling)
Expand Down
42 changes: 15 additions & 27 deletions compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2003,13 +2003,9 @@ class Namer { typer: Typer =>
/** Try to infer if the parameter needs a `tracked` modifier
*/
def needsTracked(psym: Symbol, param: ValDef, owningSym: Symbol)(using Context) =
// println(i"Checking if $psym needs tracked")
lazy val abstractContextBound = isContextBoundWitnessWithAbstractMembers(psym, param, owningSym)
lazy val isRefInSignatures =
psym.maybeOwner.isPrimaryConstructor
// && !psym.flags.is(Synthetic)
// && !psym.maybeOwner.flags.is(Synthetic)
// && !psym.maybeOwner.maybeOwner.flags.is(Synthetic)
&& isReferencedInPublicSignatures(psym)
!psym.is(Tracked)
&& psym.isTerm
Expand Down Expand Up @@ -2046,29 +2042,21 @@ class Namer { typer: Typer =>
case _ => false
checkOwnerMemberSignatures(owner)

private def namedTypeWithPrefixContainsSymbolRef(tpe: Type, syms: List[Symbol])(using Context): Boolean = tpe match
case tpe: NamedType => tpe.prefix.exists && tpeContainsSymbolRef(tpe.prefix, syms)
case _ => false

private def tpeContainsSymbolRef(tpe0: Type, syms: List[Symbol])(using Context): Boolean =
val tpe = tpe0.dropAlias.safeDealias
tpe match
case ExprType(resType) => tpeContainsSymbolRef(resType, syms)
case m : MethodOrPoly =>
m.paramInfos.exists(tpeContainsSymbolRef(_, syms))
|| tpeContainsSymbolRef(m.resultType, syms)
case r @ RefinedType(parent, _, refinedInfo) => tpeContainsSymbolRef(parent, syms) || tpeContainsSymbolRef(refinedInfo, syms)
case TypeBounds(lo, hi) => tpeContainsSymbolRef(lo, syms) || tpeContainsSymbolRef(hi, syms)
case t: Type =>
tpe.termSymbol.exists && syms.contains(tpe.termSymbol)
|| tpe.argInfos.exists(tpeContainsSymbolRef(_, syms))
|| namedTypeWithPrefixContainsSymbolRef(tpe, syms)

private def maybeParamAccessors(owner: Symbol, sym: Symbol)(using Context): List[Symbol] =
owner.infoOrCompleter match
case info: ClassInfo =>
info.decls.lookupAll(sym.name).filter(d => d.is(ParamAccessor)).toList
case _ => List.empty
/** Check if any of syms are referenced in tpe */
private def tpeContainsSymbolRef(tpe: Type, syms: List[Symbol])(using Context): Boolean =
val acc = new ExistsAccumulator(
{ tpe => tpe.termSymbol.exists && syms.contains(tpe.termSymbol) },
StopAt.Static,
forceLazy = false
) {
override def apply(acc: Boolean, tpe: Type): Boolean = super.apply(acc, tpe.safeDealias)
}
acc(false, tpe)

private def maybeParamAccessors(owner: Symbol, sym: Symbol)(using Context): List[Symbol] = owner.infoOrCompleter match
case info: ClassInfo =>
info.decls.lookupAll(sym.name).filter(d => d.is(ParamAccessor)).toList
case _ => List.empty

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

0 comments on commit 5b0c484

Please sign in to comment.