Skip to content

Commit 187f6a2

Browse files
committed
Infrastructure for import implied.
Interpretation of what `implied` means is still missing.
1 parent 181405f commit 187f6a2

File tree

27 files changed

+96
-74
lines changed

27 files changed

+96
-74
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ object desugar {
392392
if (isEnum) {
393393
val (enumCases, enumStats) = stats.partition(DesugarEnums.isEnumCase)
394394
val enumCompanionRef = new TermRefTree()
395-
val enumImport = Import(enumCompanionRef, enumCases.flatMap(caseIds))
395+
val enumImport = Import(impliedOnly = false, enumCompanionRef, enumCases.flatMap(caseIds))
396396
(enumImport :: enumStats, enumCases, enumCompanionRef)
397397
}
398398
else (stats, Nil, EmptyTree)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
358358
def statPurity(tree: Tree)(implicit ctx: Context): PurityLevel = unsplice(tree) match {
359359
case EmptyTree
360360
| TypeDef(_, _)
361-
| Import(_, _)
361+
| Import(_, _, _)
362362
| DefDef(_, _, _, _, _) =>
363363
Pure
364364
case vdef @ ValDef(_, _, _) =>

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ object Trees {
762762
* where a selector is either an untyped `Ident`, `name` or
763763
* an untyped thicket consisting of `name` and `rename`.
764764
*/
765-
case class Import[-T >: Untyped] private[ast] (expr: Tree[T], selectors: List[Tree[Untyped]])(implicit @constructorOnly src: SourceFile)
765+
case class Import[-T >: Untyped] private[ast] (impliedOnly: Boolean, expr: Tree[T], selectors: List[Tree[Untyped]])(implicit @constructorOnly src: SourceFile)
766766
extends DenotingTree[T] {
767767
type ThisTree[-T >: Untyped] = Import[T]
768768
}
@@ -1156,9 +1156,9 @@ object Trees {
11561156
case tree: Template if (constr eq tree.constr) && (parents eq tree.parents) && (derived eq tree.derived) && (self eq tree.self) && (body eq tree.unforcedBody) => tree
11571157
case tree => finalize(tree, untpd.Template(constr, parents, derived, self, body)(tree.source))
11581158
}
1159-
def Import(tree: Tree)(expr: Tree, selectors: List[untpd.Tree])(implicit ctx: Context): Import = tree match {
1160-
case tree: Import if (expr eq tree.expr) && (selectors eq tree.selectors) => tree
1161-
case _ => finalize(tree, untpd.Import(expr, selectors)(tree.source))
1159+
def Import(tree: Tree)(impliedOnly: Boolean, expr: Tree, selectors: List[untpd.Tree])(implicit ctx: Context): Import = tree match {
1160+
case tree: Import if (impliedOnly == tree.impliedOnly) && (expr eq tree.expr) && (selectors eq tree.selectors) => tree
1161+
case _ => finalize(tree, untpd.Import(impliedOnly, expr, selectors)(tree.source))
11621162
}
11631163
def PackageDef(tree: Tree)(pid: RefTree, stats: List[Tree])(implicit ctx: Context): PackageDef = tree match {
11641164
case tree: PackageDef if (pid eq tree.pid) && (stats eq tree.stats) => tree
@@ -1303,8 +1303,8 @@ object Trees {
13031303
cpy.TypeDef(tree)(name, transform(rhs))
13041304
case tree @ Template(constr, parents, self, _) if tree.derived.isEmpty =>
13051305
cpy.Template(tree)(transformSub(constr), transform(tree.parents), Nil, transformSub(self), transformStats(tree.body))
1306-
case Import(expr, selectors) =>
1307-
cpy.Import(tree)(transform(expr), selectors)
1306+
case Import(impliedOnly, expr, selectors) =>
1307+
cpy.Import(tree)(impliedOnly, transform(expr), selectors)
13081308
case PackageDef(pid, stats) =>
13091309
cpy.PackageDef(tree)(transformSub(pid), transformStats(stats)(localCtx))
13101310
case Annotated(arg, annot) =>
@@ -1427,7 +1427,7 @@ object Trees {
14271427
this(x, rhs)
14281428
case tree @ Template(constr, parents, self, _) if tree.derived.isEmpty =>
14291429
this(this(this(this(x, constr), parents), self), tree.body)
1430-
case Import(expr, selectors) =>
1430+
case Import(impliedOnly, expr, selectors) =>
14311431
this(x, expr)
14321432
case PackageDef(pid, stats) =>
14331433
this(this(x, pid), stats)(localCtx)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,8 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
329329
Block(cdef :: Nil, New(cls.typeRef, Nil))
330330
}
331331

332-
def Import(expr: Tree, selectors: List[untpd.Tree])(implicit ctx: Context): Import =
333-
ta.assignType(untpd.Import(expr, selectors), ctx.newImportSymbol(ctx.owner, expr))
332+
def Import(impliedOnly: Boolean, expr: Tree, selectors: List[untpd.Tree])(implicit ctx: Context): Import =
333+
ta.assignType(untpd.Import(impliedOnly, expr, selectors), ctx.newImportSymbol(ctx.owner, expr))
334334

335335
def PackageDef(pid: RefTree, stats: List[Tree])(implicit ctx: Context): PackageDef =
336336
ta.assignType(untpd.PackageDef(pid, stats), pid)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
326326
def Template(constr: DefDef, parents: List[Tree], derived: List[Tree], self: ValDef, body: LazyTreeList)(implicit src: SourceFile): Template =
327327
if (derived.isEmpty) new Template(constr, parents, self, body)
328328
else new DerivingTemplate(constr, parents ++ derived, self, body, derived.length)
329-
def Import(expr: Tree, selectors: List[Tree])(implicit src: SourceFile): Import = new Import(expr, selectors)
329+
def Import(impliedOnly: Boolean, expr: Tree, selectors: List[Tree])(implicit src: SourceFile): Import = new Import(impliedOnly, expr, selectors)
330330
def PackageDef(pid: RefTree, stats: List[Tree])(implicit src: SourceFile): PackageDef = new PackageDef(pid, stats)
331331
def Annotated(arg: Tree, annot: Tree)(implicit src: SourceFile): Annotated = new Annotated(arg, annot)
332332

compiler/src/dotty/tools/dotc/core/Contexts.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,8 @@ object Contexts {
404404
case ref: RefTree[_] => Some(ref.name.asTermName)
405405
case _ => None
406406
}
407-
ctx.fresh.setImportInfo(new ImportInfo(implicit ctx => sym, imp.selectors, impNameOpt))
407+
ctx.fresh.setImportInfo(
408+
new ImportInfo(implicit ctx => sym, imp.selectors, impNameOpt, imp.impliedOnly))
408409
}
409410

410411
/** Does current phase use an erased types interpretation? */

compiler/src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1872,7 +1872,8 @@ object SymDenotations {
18721872
maybeAdd(name)
18731873
val ownSyms =
18741874
if (keepOnly eq implicitFilter)
1875-
if (this is Package) Iterator.empty // !!!!
1875+
if (this is Package) Iterator.empty
1876+
// implicits in package objects are added by the overriding `memberNames` in `PackageClassDenotation`
18761877
else info.decls.iterator filter (_ is ImplicitOrImplied)
18771878
else info.decls.iterator
18781879
for (sym <- ownSyms) maybeAdd(sym.name)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Standard-Section: "ASTs" TopLevelStat*
5858
ValOrDefDef
5959
TYPEDEF Length NameRef (type_Term | Template) Modifier*
6060
OBJECTDEF Length NameRef Template Modifier*
61-
IMPORT Length qual_Term Selector*
61+
IMPORT Length [IMPLIED] qual_Term Selector*
6262
ValOrDefDef = VALDEF Length NameRef type_Term rhs_Term? Modifier*
6363
DEFDEF Length NameRef TypeParam* Params* returnType_Term rhs_Term?
6464
Modifier*

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -532,9 +532,13 @@ class TreePickler(pickler: TastyPickler) {
532532
}
533533
pickleStats(tree.constr :: rest)
534534
}
535-
case Import(expr, selectors) =>
535+
case Import(impliedOnly, expr, selectors) =>
536536
writeByte(IMPORT)
537-
withLength { pickleTree(expr); pickleSelectors(selectors) }
537+
withLength {
538+
if (impliedOnly) writeByte(IMPLIED)
539+
pickleTree(expr)
540+
pickleSelectors(selectors)
541+
}
538542
case PackageDef(pid, stats) =>
539543
writeByte(PACKAGE)
540544
withLength { pickleType(pid.tpe); pickleStats(stats) }

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -956,8 +956,10 @@ class TreeUnpickler(reader: TastyReader,
956956
assert(sourcePathAt(start).isEmpty)
957957
readByte()
958958
readEnd()
959+
val impliedOnly = nextByte == IMPLIED
960+
if (impliedOnly) readByte()
959961
val expr = readTerm()
960-
setSpan(start, Import(expr, readSelectors()))
962+
setSpan(start, Import(impliedOnly, expr, readSelectors()))
961963
}
962964

963965
def readSelectors()(implicit ctx: Context): List[untpd.Tree] = nextByte match {

0 commit comments

Comments
 (0)