Skip to content

Commit

Permalink
Compute non-experimental top-level definition from symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasstucki committed Apr 30, 2024
1 parent ad92dcd commit 32701e1
Showing 1 changed file with 21 additions and 24 deletions.
45 changes: 21 additions & 24 deletions compiler/src/dotty/tools/dotc/typer/Checking.scala
Original file line number Diff line number Diff line change
Expand Up @@ -809,22 +809,24 @@ object Checking {
*
*/
def checkAndAdaptExperimentalImports(trees: List[Tree])(using Context): Unit =
def nonExperimentalStats(trees: List[Tree]): List[Tree] = trees match
case (_: ImportOrExport | EmptyTree) :: rest =>
nonExperimentalStats(rest)
case (tree @ TypeDef(_, impl: Template)) :: rest if tree.symbol.isPackageObject =>
nonExperimentalStats(impl.body) ::: nonExperimentalStats(rest)
case (tree: PackageDef) :: rest =>
nonExperimentalStats(tree.stats) ::: nonExperimentalStats(rest)
case (tree: MemberDef) :: rest =>
if tree.symbol.isExperimental || tree.symbol.is(Synthetic) then
nonExperimentalStats(rest)
else
tree :: nonExperimentalStats(rest)
case tree :: rest =>
tree :: nonExperimentalStats(rest)
case Nil =>
Nil
def nonExperimentalTopLevelDefs(pack: Symbol): Iterator[Symbol] =
def isNonExperimentalTopLevelDefinition(sym: Symbol) =
!sym.isExperimental
&& sym.source == ctx.compilationUnit.source
&& !sym.isConstructor // not constructor of package object
&& !sym.is(Package) && !sym.isPackageObject && !sym.name.endsWith(str.TOPLEVEL_SUFFIX)

val packageMembers =
pack.info.decls
.toList.iterator
.filter(isNonExperimentalTopLevelDefinition)
val packageObjectMembers =
pack.info.decls
.toList.iterator
.filter(sym => sym.isClass && (sym.is(Package) || sym.isPackageObject))
.flatMap(nonExperimentalTopLevelDefs)

packageMembers ++ packageObjectMembers

def unitExperimentalLanguageImports =
def isAllowedImport(sel: untpd.ImportSelector) =
Expand All @@ -842,14 +844,9 @@ object Checking {

if ctx.owner.is(Package) || ctx.owner.name.startsWith(str.REPL_SESSION_LINE) then
def markTopLevelDefsAsExperimental(why: String): Unit =
for tree <- nonExperimentalStats(trees) do
tree match
case tree: MemberDef =>
val sym = tree.symbol
if !sym.isExperimental then
sym.addAnnotation(ExperimentalAnnotation(s"Added by $why", sym.span))
case _ =>
// statements from a `val _ = ...`
for sym <- nonExperimentalTopLevelDefs(ctx.owner) do
sym.addAnnotation(ExperimentalAnnotation(s"Added by $why", sym.span))

unitExperimentalLanguageImports match
case imp :: _ => markTopLevelDefsAsExperimental(i"top level $imp")
case _ =>
Expand Down

0 comments on commit 32701e1

Please sign in to comment.