Skip to content

Commit b8f8d36

Browse files
committed
Add workarounds to link on strawman
1 parent 9db592a commit b8f8d36

File tree

9 files changed

+843
-23
lines changed

9 files changed

+843
-23
lines changed

compiler/src/dotty/tools/dotc/transform/LinkAll.scala

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@ import dotty.tools.dotc.core.Symbols._
99
import dotty.tools.dotc.core.Flags._
1010
import dotty.tools.dotc.transform.TreeTransforms._
1111

12+
import scala.collection.immutable.ListSet
13+
1214
/** Loads all potentially reachable trees from tasty. ▲
1315
* Only performed on whole world optimization mode. ▲ ▲
1416
*
1517
* TODO: Next step is to only load compilation units reachable in the call graph
18+
* TODO: Use Set instead of ListSet. This is a temporary work around to global fresh names for anonymous classes (i.e. dependent on compilation order).
1619
*/
1720
class LinkAll extends MiniPhaseTransform {
1821
import tpd._
@@ -23,24 +26,24 @@ class LinkAll extends MiniPhaseTransform {
2326
override def prepareForUnit(tree: tpd.Tree)(implicit ctx: Context): TreeTransform = NoTransform
2427

2528
override def runOn(units: List[CompilationUnit])(implicit ctx: Context): List[CompilationUnit] =
26-
if (ctx.settings.XlinkOptimise.value) super.runOn(allUnits(Set.empty, units.toSet, Set.empty))
29+
if (ctx.settings.XlinkOptimise.value) super.runOn(allUnits(ListSet.empty, units.to, ListSet.empty))
2730
else super.runOn(units)
2831

2932
/** Loads and processes new compilation units, possibly loading more units. */
30-
private def allUnits(processed: Set[CompilationUnit], unprocessed: Set[CompilationUnit], loadedClasses: Set[ClassDenotation])(implicit ctx: Context): List[CompilationUnit] = {
33+
private def allUnits(processed: ListSet[CompilationUnit], unprocessed: ListSet[CompilationUnit], loadedClasses: ListSet[ClassDenotation])(implicit ctx: Context): List[CompilationUnit] = {
3134
if (unprocessed.isEmpty) processed.toList
3235
else {
3336
val accum = new ClassesToLoadAccumulator
34-
val classesToLoad = unprocessed.foldLeft(Set.empty[ClassDenotation])((acc, unit) => accum.apply(acc, unit.tpdTree)) -- loadedClasses
37+
val classesToLoad = unprocessed.foldLeft(ListSet.empty[ClassDenotation])((acc, unit) => accum.apply(acc, unit.tpdTree)) -- loadedClasses
3538
val loadedUnits = classesToLoad.flatMap(cls => loadCompilationUnit(cls))
3639
allUnits(processed ++ unprocessed, loadedUnits, loadedClasses ++ classesToLoad)
3740
}
3841
}
3942

4043
/** Collects all class denotations that may need to be loaded. */
41-
private class ClassesToLoadAccumulator extends TreeAccumulator[Set[ClassDenotation]] {
44+
private class ClassesToLoadAccumulator extends TreeAccumulator[ListSet[ClassDenotation]] {
4245
private var inParents = false
43-
override def apply(acc: Set[ClassDenotation], tree: tpd.Tree)(implicit ctx: Context): Set[ClassDenotation] = tree match {
46+
override def apply(acc: ListSet[ClassDenotation], tree: tpd.Tree)(implicit ctx: Context): ListSet[ClassDenotation] = tree match {
4447
case New(tpt) => accum(acc, tpt.tpe.classSymbol)
4548
case AppliedTypeTree(tpt, _) if inParents => accum(acc, tpt.symbol)
4649
case tree: RefTree if inParents || tree.symbol.is(Module) =>
@@ -55,7 +58,7 @@ class LinkAll extends MiniPhaseTransform {
5558
}
5659

5760
/** Accumulate class denotation for `sym` if needed */
58-
private def accum(acc: Set[ClassDenotation], sym: Symbol)(implicit ctx: Context): Set[ClassDenotation] = {
61+
private def accum(acc: ListSet[ClassDenotation], sym: Symbol)(implicit ctx: Context): ListSet[ClassDenotation] = {
5962
val topClass = sym.topLevelClass.denot.asClass
6063
if (topClass.is(JavaDefined) || topClass.is(Scala2x) || topClass.symbol == defn.ObjectClass) acc
6164
else acc + topClass

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ object Typer {
5656

5757
/** Assert tree has a position, unless it is empty or a typed splice */
5858
def assertPositioned(tree: untpd.Tree)(implicit ctx: Context) =
59-
if (!tree.isEmpty && !tree.isInstanceOf[untpd.TypedSplice] && ctx.typerState.isGlobalCommittable)
59+
if (!tree.isEmpty && !tree.isInstanceOf[untpd.TypedSplice] && ctx.typerState.isGlobalCommittable && !ctx.settings.XlinkOptimise.value) // FIXME: remove XlinkOptimise condition
6060
assert(tree.pos.exists, s"position not set for $tree # ${tree.uniqueId}")
6161

6262
private val ExprOwner = new Property.Key[Symbol]
Lines changed: 270 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,272 @@
1+
MyIterator
12
Test
23
Test$
4+
strawman/LowPriority
5+
strawman/collection/ArrayLike
6+
strawman/collection/ArrayOps
7+
strawman/collection/ArrayOps$
8+
strawman/collection/ArrayView
9+
strawman/collection/ArrayView$
10+
strawman/collection/BuildFrom
11+
strawman/collection/BuildFrom$
12+
strawman/collection/BuildFrom$$anon$21
13+
strawman/collection/BuildFrom$$anon$22
14+
strawman/collection/BuildFromLowPriority
15+
strawman/collection/BuildFromLowPriority$$anon$13
16+
strawman/collection/BuildFromLowPriority$$anon$14
17+
strawman/collection/FromSpecificIterable
18+
strawman/collection/Hashing
19+
strawman/collection/Hashing$
20+
strawman/collection/IndexedSeq
21+
strawman/collection/IndexedSeq$
22+
strawman/collection/IndexedSeqOps
23+
strawman/collection/IndexedSeqOps$$anon$37
24+
strawman/collection/IndexedView
25+
strawman/collection/IndexedView$
26+
strawman/collection/IndexedView$$anon$38
27+
strawman/collection/IndexedView$Drop
28+
strawman/collection/IndexedView$DropRight
29+
strawman/collection/IndexedView$Map
30+
strawman/collection/IndexedView$Reverse
31+
strawman/collection/IndexedView$Reverse$
32+
strawman/collection/IndexedView$Take
33+
strawman/collection/IndexedView$TakeRight
34+
strawman/collection/Iterable
35+
strawman/collection/IterableFactory
36+
strawman/collection/IterableFactory$
37+
strawman/collection/IterableFactory$$anon$36
38+
strawman/collection/IterableFactory$Delegate
39+
strawman/collection/IterableOnce
40+
strawman/collection/IterableOps
41+
strawman/collection/Iterator
42+
strawman/collection/Iterator$
43+
strawman/collection/Iterator$$anon$39
44+
strawman/collection/Iterator$$anon$40
45+
strawman/collection/Iterator$$anon$40$$anon$41
46+
strawman/collection/Iterator$$anon$42
47+
strawman/collection/Iterator$$anon$43
48+
strawman/collection/Iterator$$anon$44
49+
strawman/collection/Iterator$$anon$45
50+
strawman/collection/Iterator$$anon$46
51+
strawman/collection/Iterator$$anon$47
52+
strawman/collection/Iterator$$anon$48
53+
strawman/collection/Iterator$$anon$49
54+
strawman/collection/Iterator$$anon$50
55+
strawman/collection/Iterator$$anon$51
56+
strawman/collection/Iterator$$anon$52
57+
strawman/collection/Iterator$$anon$53
58+
strawman/collection/Iterator$$anon$54
59+
strawman/collection/Iterator$$anon$55
60+
strawman/collection/Iterator$GroupedIterator
61+
strawman/collection/LinearSeq
62+
strawman/collection/LinearSeqOps
63+
strawman/collection/LinearSeqOps$$anon$12
64+
strawman/collection/Map
65+
strawman/collection/Map$
66+
strawman/collection/MapFactory
67+
strawman/collection/MapFactory$
68+
strawman/collection/MapFactory$$anon$19
69+
strawman/collection/MapFactory$Delegate
70+
strawman/collection/MapOps
71+
strawman/collection/Seq
72+
strawman/collection/SeqOps
73+
strawman/collection/SeqOps$
74+
strawman/collection/SeqOps$$anon$26
75+
strawman/collection/SeqOps$$anon$27
76+
strawman/collection/SeqOps$$anon$28
77+
strawman/collection/SeqOps$CombinationsItr
78+
strawman/collection/SeqOps$PermutationsItr
79+
strawman/collection/Set
80+
strawman/collection/Set$
81+
strawman/collection/SetOps
82+
strawman/collection/SetOps$$anon$4
83+
strawman/collection/SetOps$SubsetsItr
84+
strawman/collection/StrictOptimizedIterableOps
85+
strawman/collection/StringOps
86+
strawman/collection/StringOps$
87+
strawman/collection/StringView
88+
strawman/collection/StringView$
89+
strawman/collection/View
90+
strawman/collection/View$
91+
strawman/collection/View$$anon$29
92+
strawman/collection/View$$anon$30
93+
strawman/collection/View$$anon$31
94+
strawman/collection/View$$anon$32
95+
strawman/collection/View$$anon$33
96+
strawman/collection/View$$anon$34
97+
strawman/collection/View$$anon$35
98+
strawman/collection/View$Append
99+
strawman/collection/View$Append$
100+
strawman/collection/View$Concat
101+
strawman/collection/View$Concat$
102+
strawman/collection/View$Drop
103+
strawman/collection/View$Drop$
104+
strawman/collection/View$DropRight
105+
strawman/collection/View$DropRight$
106+
strawman/collection/View$DropWhile
107+
strawman/collection/View$DropWhile$
108+
strawman/collection/View$Elems
109+
strawman/collection/View$Elems$
110+
strawman/collection/View$Empty$
111+
strawman/collection/View$Fill
112+
strawman/collection/View$Fill$
113+
strawman/collection/View$Filter
114+
strawman/collection/View$Filter$
115+
strawman/collection/View$FlatMap
116+
strawman/collection/View$FlatMap$
117+
strawman/collection/View$Map
118+
strawman/collection/View$Map$
119+
strawman/collection/View$PadTo
120+
strawman/collection/View$PadTo$
121+
strawman/collection/View$Partition
122+
strawman/collection/View$Partition$
123+
strawman/collection/View$Partitioned
124+
strawman/collection/View$Partitioned$
125+
strawman/collection/View$Prepend
126+
strawman/collection/View$Prepend$
127+
strawman/collection/View$ScanLeft
128+
strawman/collection/View$ScanLeft$
129+
strawman/collection/View$Single
130+
strawman/collection/View$Single$
131+
strawman/collection/View$Take
132+
strawman/collection/View$Take$
133+
strawman/collection/View$TakeRight
134+
strawman/collection/View$TakeRight$
135+
strawman/collection/View$TakeWhile
136+
strawman/collection/View$TakeWhile$
137+
strawman/collection/View$Unzip
138+
strawman/collection/View$Unzip$
139+
strawman/collection/View$Updated
140+
strawman/collection/View$Updated$
141+
strawman/collection/View$Zip
142+
strawman/collection/View$Zip$
143+
strawman/collection/View$ZipWithIndex
144+
strawman/collection/View$ZipWithIndex$
145+
strawman/collection/immutable/$colon$colon
146+
strawman/collection/immutable/$colon$colon$
147+
strawman/collection/immutable/HashMap
148+
strawman/collection/immutable/HashMap$
149+
strawman/collection/immutable/HashMap$$anon$15
150+
strawman/collection/immutable/HashMap$$anon$16
151+
strawman/collection/immutable/HashMap$$anon$17
152+
strawman/collection/immutable/HashMap$$anon$18
153+
strawman/collection/immutable/HashMap$EmptyHashMap$
154+
strawman/collection/immutable/HashMap$HashMap1
155+
strawman/collection/immutable/HashMap$HashMapCollision1
156+
strawman/collection/immutable/HashMap$HashTrieMap
157+
strawman/collection/immutable/HashMap$Merger
158+
strawman/collection/immutable/HashSet
159+
strawman/collection/immutable/HashSet$
160+
strawman/collection/immutable/HashSet$$anon$5
161+
strawman/collection/immutable/HashSet$$anon$6
162+
strawman/collection/immutable/HashSet$EmptyHashSet$
163+
strawman/collection/immutable/HashSet$HashSet1
164+
strawman/collection/immutable/HashSet$HashSetCollision1
165+
strawman/collection/immutable/HashSet$HashTrieSet
166+
strawman/collection/immutable/HashSet$LeafHashSet
167+
strawman/collection/immutable/ImmutableArray
168+
strawman/collection/immutable/ImmutableArray$
169+
strawman/collection/immutable/IndexedSeq
170+
strawman/collection/immutable/IndexedSeq$
171+
strawman/collection/immutable/IndexedSeqOps
172+
strawman/collection/immutable/Iterable
173+
strawman/collection/immutable/List
174+
strawman/collection/immutable/List$
175+
strawman/collection/immutable/ListMap
176+
strawman/collection/immutable/ListMap$
177+
strawman/collection/immutable/ListMap$$anon$8
178+
strawman/collection/immutable/ListMap$EmptyListMap$
179+
strawman/collection/immutable/ListMap$Node
180+
strawman/collection/immutable/ListSet
181+
strawman/collection/immutable/ListSet$
182+
strawman/collection/immutable/ListSet$$anon$1
183+
strawman/collection/immutable/ListSet$EmptyListSet$
184+
strawman/collection/immutable/ListSet$Node
185+
strawman/collection/immutable/Map
186+
strawman/collection/immutable/Map$
187+
strawman/collection/immutable/MapOps
188+
strawman/collection/immutable/Nil
189+
strawman/collection/immutable/Nil$
190+
strawman/collection/immutable/Range
191+
strawman/collection/immutable/Range$
192+
strawman/collection/immutable/RangeIterator
193+
strawman/collection/immutable/Seq
194+
strawman/collection/immutable/Seq$
195+
strawman/collection/immutable/SeqOps
196+
strawman/collection/immutable/Set
197+
strawman/collection/immutable/Set$
198+
strawman/collection/immutable/SetOps
199+
strawman/collection/immutable/TrieIterator
200+
strawman/collection/immutable/TrieIterator$$anon$7
201+
strawman/collection/immutable/TrieIterator$DupIterator
202+
strawman/collection/immutable/Vector
203+
strawman/collection/immutable/Vector$
204+
strawman/collection/immutable/Vector$$anon$24
205+
strawman/collection/immutable/VectorBuilder
206+
strawman/collection/immutable/VectorIterator
207+
strawman/collection/immutable/VectorPointer
208+
strawman/collection/mutable/ArrayBuffer
209+
strawman/collection/mutable/ArrayBuffer$
210+
strawman/collection/mutable/ArrayBufferView
211+
strawman/collection/mutable/Builder
212+
strawman/collection/mutable/Builder$$anon$25
213+
strawman/collection/mutable/DefaultEntry
214+
strawman/collection/mutable/FlatHashTable
215+
strawman/collection/mutable/FlatHashTable$
216+
strawman/collection/mutable/FlatHashTable$$anon$2
217+
strawman/collection/mutable/FlatHashTable$$anon$3
218+
strawman/collection/mutable/FlatHashTable$Contents
219+
strawman/collection/mutable/FlatHashTable$HashUtils
220+
strawman/collection/mutable/FlatHashTable$NullSentinel$
221+
strawman/collection/mutable/Growable
222+
strawman/collection/mutable/Growable$
223+
strawman/collection/mutable/GrowableBuilder
224+
strawman/collection/mutable/GrowableIterable
225+
strawman/collection/mutable/GrowableSeq
226+
strawman/collection/mutable/HashEntry
227+
strawman/collection/mutable/HashMap
228+
strawman/collection/mutable/HashMap$
229+
strawman/collection/mutable/HashMap$$anon$23
230+
strawman/collection/mutable/HashSet
231+
strawman/collection/mutable/HashSet$
232+
strawman/collection/mutable/HashTable
233+
strawman/collection/mutable/HashTable$
234+
strawman/collection/mutable/HashTable$$anon$20
235+
strawman/collection/mutable/HashTable$Contents
236+
strawman/collection/mutable/HashTable$HashUtils
237+
strawman/collection/mutable/ImmutableBuilder
238+
strawman/collection/mutable/IndexedOptimizedGrowableSeq
239+
strawman/collection/mutable/IndexedOptimizedSeq
240+
strawman/collection/mutable/Iterable
241+
strawman/collection/mutable/Iterable$
242+
strawman/collection/mutable/IterableOps
243+
strawman/collection/mutable/ListBuffer
244+
strawman/collection/mutable/ListBuffer$
245+
strawman/collection/mutable/Map
246+
strawman/collection/mutable/Map$
247+
strawman/collection/mutable/MapOps
248+
strawman/collection/mutable/RefArrayUtils
249+
strawman/collection/mutable/RefArrayUtils$
250+
strawman/collection/mutable/ReusableBuilder
251+
strawman/collection/mutable/Seq
252+
strawman/collection/mutable/SeqOps
253+
strawman/collection/mutable/Set
254+
strawman/collection/mutable/Set$
255+
strawman/collection/mutable/SetOps
256+
strawman/collection/mutable/Shrinkable
257+
strawman/collection/mutable/StringBuilder
258+
strawman/collection/package
259+
strawman/collection/package$
260+
strawman/collection/package$$anon$10
261+
strawman/collection/package$$anon$11
262+
strawman/collection/package$$anon$9
263+
strawman/collection/package$$anonfun$3
264+
strawman/collection/package$DebugUtils$
265+
strawman/collection/package$toNewIterator
266+
strawman/collection/package$toNewIterator$
267+
strawman/collection/package$toNewSeq
268+
strawman/collection/package$toNewSeq$
269+
strawman/collection/package$toOldIterator
270+
strawman/collection/package$toOldIterator$
271+
strawman/collection/package$toOldSeq
272+
strawman/collection/package$toOldSeq$

tests/link/strawman/iterator-1.scala

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,13 @@ import strawman.collection.Iterator
22

33
object Test {
44
def main(args: Array[String]): Unit = {
5-
// FIXME: issue loading package object
6-
// val it = new MyIterator
7-
// println(it.hasNext)
8-
// println(it.next())
9-
println(true)
10-
println(3)
5+
val it = new MyIterator
6+
println(it.hasNext)
7+
println(it.next())
118
}
129
}
1310

14-
//class MyIterator extends Iterator[Int] {
15-
// override def hasNext: Boolean = true
16-
// override def next(): Int = 3
17-
//}
11+
class MyIterator extends Iterator[Int] {
12+
override def hasNext: Boolean = true
13+
override def next(): Int = 3
14+
}

0 commit comments

Comments
 (0)