Skip to content

Commit aa7eae5

Browse files
committed
Make nextTreeId counter a context field
This removes some technical debt: nextId was a global counter, so unreliable under parallelism. That was OK so far since it was only intended for debugging. But now we want to give more significance to tree ids, since they will be used to determine the source file of a tree. Hence, we need to put this aspect in order by making nextTreeId a context field. This entailed a lot of changes, so no wonder it was not done before.
1 parent e7721a9 commit aa7eae5

File tree

12 files changed

+272
-256
lines changed

12 files changed

+272
-256
lines changed

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,23 @@ object desugar {
4242

4343
// ----- DerivedTypeTrees -----------------------------------
4444

45-
class SetterParamTree extends DerivedTypeTree {
45+
class SetterParamTree(implicit ids: TreeIds) extends DerivedTypeTree {
4646
def derivedTree(sym: Symbol)(implicit ctx: Context): tpd.TypeTree = tpd.TypeTree(sym.info.resultType)
4747
}
4848

49-
class TypeRefTree extends DerivedTypeTree {
49+
class TypeRefTree(implicit ids: TreeIds) extends DerivedTypeTree {
5050
def derivedTree(sym: Symbol)(implicit ctx: Context): tpd.TypeTree = tpd.TypeTree(sym.typeRef)
5151
}
5252

53-
class TermRefTree extends DerivedTypeTree {
53+
class TermRefTree(implicit ids: TreeIds) extends DerivedTypeTree {
5454
def derivedTree(sym: Symbol)(implicit ctx: Context): tpd.Tree = tpd.ref(sym)
5555
}
5656

5757
/** A type tree that computes its type from an existing parameter.
5858
* @param suffix String difference between existing parameter (call it `P`) and parameter owning the
5959
* DerivedTypeTree (call it `O`). We have: `O.name == P.name + suffix`.
6060
*/
61-
class DerivedFromParamTree(suffix: String) extends DerivedTypeTree {
61+
class DerivedFromParamTree(suffix: String)(implicit ids: TreeIds) extends DerivedTypeTree {
6262

6363
/** Make sure that for all enclosing module classes their companion classes
6464
* are completed. Reason: We need the constructor of such companion classes to
@@ -109,7 +109,7 @@ object desugar {
109109
}
110110

111111
/** A type definition copied from `tdef` with a rhs typetree derived from it */
112-
def derivedTypeParam(tdef: TypeDef, suffix: String = ""): TypeDef =
112+
def derivedTypeParam(tdef: TypeDef, suffix: String = "")(implicit ctx: Context): TypeDef =
113113
cpy.TypeDef(tdef)(
114114
name = tdef.name ++ suffix,
115115
rhs = new DerivedFromParamTree(suffix).withPos(tdef.rhs.pos).watching(tdef)
@@ -120,9 +120,9 @@ object desugar {
120120
TypeDef(sym.name, new DerivedFromParamTree("").watching(sym)).withFlags(TypeParam)
121121

122122
/** A value definition copied from `vdef` with a tpt typetree derived from it */
123-
def derivedTermParam(vdef: ValDef): ValDef =
123+
def derivedTermParam(vdef: ValDef)(implicit ctx: Context): ValDef =
124124
cpy.ValDef(vdef)(
125-
tpt = new DerivedFromParamTree("") withPos vdef.tpt.pos watching vdef)
125+
tpt = new DerivedFromParamTree("").withPos(vdef.tpt.pos).watching(vdef))
126126

127127
// ----- Desugar methods -------------------------------------------------
128128

@@ -931,9 +931,10 @@ object desugar {
931931
* def $anonfun(params) = body
932932
* Closure($anonfun)
933933
*/
934-
def makeClosure(params: List[ValDef], body: Tree, tpt: Tree = TypeTree(), isImplicit: Boolean)(implicit ctx: Context): Block =
934+
def makeClosure(params: List[ValDef], body: Tree, tpt: Tree = null, isImplicit: Boolean)(implicit ctx: Context): Block =
935935
Block(
936-
DefDef(nme.ANON_FUN, Nil, params :: Nil, tpt, body).withMods(synthetic | Artifact),
936+
DefDef(nme.ANON_FUN, Nil, params :: Nil, if (tpt == null) TypeTree() else tpt, body)
937+
.withMods(synthetic | Artifact),
937938
Closure(Nil, Ident(nme.ANON_FUN), if (isImplicit) ImplicitEmptyTree else EmptyTree))
938939

939940
/** If `nparams` == 1, expand partial function
@@ -1023,7 +1024,7 @@ object desugar {
10231024
mayNeedSetter
10241025
}
10251026

1026-
private def derivedDefDef(original: Tree, named: NameTree, tpt: Tree, rhs: Tree, mods: Modifiers) =
1027+
private def derivedDefDef(original: Tree, named: NameTree, tpt: Tree, rhs: Tree, mods: Modifiers)(implicit ids: TreeIds) =
10271028
DefDef(named.name.asTermName, Nil, Nil, tpt, rhs)
10281029
.withMods(mods)
10291030
.withPos(original.pos.withPoint(named.pos.start))
@@ -1387,5 +1388,6 @@ object desugar {
13871388
buf.toList
13881389
}
13891390

1390-
private class IrrefutableGenFrom(pat: Tree, expr: Tree) extends GenFrom(pat, expr)
1391+
private class IrrefutableGenFrom(pat: Tree, expr: Tree)(implicit ids: TreeIds)
1392+
extends GenFrom(pat, expr)
13911393
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ object DesugarEnums {
7373
else if (isEnumCase(cdef)) cdef.withMods(cdef.mods.withFlags(cdef.mods.flags | Final))
7474
else cdef
7575

76-
private def valuesDot(name: String) = Select(Ident(nme.DOLLAR_VALUES), name.toTermName)
76+
private def valuesDot(name: String)(implicit ids: TreeIds) =
77+
Select(Ident(nme.DOLLAR_VALUES), name.toTermName)
7778
private def registerCall(implicit ctx: Context): List[Tree] =
7879
if (enumClass.typeParams.nonEmpty) Nil
7980
else Apply(valuesDot("register"), This(EmptyTypeIdent) :: Nil) :: Nil

0 commit comments

Comments
 (0)