Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change @experimental spec #13305

Merged
merged 4 commits into from
Aug 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions compiler/src/dotty/tools/dotc/config/Feature.scala
Original file line number Diff line number Diff line change
Expand Up @@ -97,24 +97,20 @@ object Feature:
else
false

private val assumeExperimentalIn = Set("dotty.tools.vulpix.ParallelTesting")

def checkExperimentalFeature(which: String, srcPos: SrcPos)(using Context) =
if !isExperimentalEnabled then
report.error(i"Experimental $which may only be used with a nightly or snapshot version of the compiler", srcPos)

def checkExperimentalDef(sym: Symbol, srcPos: SrcPos)(using Context) =
if !isExperimentalEnabled then
val symMsg =
if sym eq defn.ExperimentalAnnot then
i"use of @experimental is experimental"
else if sym.hasAnnotation(defn.ExperimentalAnnot) then
if sym.hasAnnotation(defn.ExperimentalAnnot) then
i"$sym is marked @experimental"
else if sym.owner.hasAnnotation(defn.ExperimentalAnnot) then
i"${sym.owner} is marked @experimental"
else
i"$sym inherits @experimental"
report.error(s"$symMsg and therefore may only be used with a nightly or snapshot version of the compiler", srcPos)
report.error(s"$symMsg and therefore may only be used in an experimental scope.", srcPos)

/** Check that experimental compiler options are only set for snapshot or nightly compiler versions. */
def checkExperimentalSettings(using Context): Unit =
Expand All @@ -123,9 +119,6 @@ object Feature:
do checkExperimentalFeature(s"feature $setting", NoSourcePosition)

def isExperimentalEnabled(using Context): Boolean =
def hasSpecialPermission =
Thread.currentThread.getStackTrace.exists(elem =>
assumeExperimentalIn.exists(elem.getClassName().startsWith(_)))
(Properties.experimental || hasSpecialPermission) && !ctx.settings.YnoExperimental.value
Properties.experimental && !ctx.settings.YnoExperimental.value

end Feature
18 changes: 15 additions & 3 deletions compiler/src/dotty/tools/dotc/transform/SymUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,23 @@ object SymUtils:

/** Is symbol declared or inherits @experimental? */
def isExperimental(using Context): Boolean =
// TODO should be add `@experimental` to `class experimental` in PostTyper?
self.eq(defn.ExperimentalAnnot)
|| self.hasAnnotation(defn.ExperimentalAnnot)
self.hasAnnotation(defn.ExperimentalAnnot)
|| (self.maybeOwner.isClass && self.owner.hasAnnotation(defn.ExperimentalAnnot))

def isInExperimentalScope(using Context): Boolean =
def isDefaultArgumentOfExperimentalMethod =
self.name.is(DefaultGetterName)
&& self.owner.isClass
&& {
val overloads = self.owner.asClass.membersNamed(self.name.firstPart)
overloads.filterWithFlags(HasDefaultParams, EmptyFlags) match
case denot: SymDenotation => denot.symbol.isExperimental
case _ => false
}
self.hasAnnotation(defn.ExperimentalAnnot)
|| isDefaultArgumentOfExperimentalMethod
|| (!self.is(Package) && self.owner.isInExperimentalScope)

/** The declared self type of this class, as seen from `site`, stripping
* all refinements for opaque types.
*/
Expand Down
19 changes: 7 additions & 12 deletions compiler/src/dotty/tools/dotc/typer/RefChecks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -948,27 +948,23 @@ object RefChecks {
report.deprecationWarning(s"${sym.showLocated} is deprecated${since}${msg}", pos)

private def checkExperimental(sym: Symbol, pos: SrcPos)(using Context): Unit =
if sym.isExperimental
&& !sym.isConstructor // already reported on the class
&& !ctx.owner.isExperimental // already reported on the @experimental of the owner
&& !sym.is(ModuleClass) // already reported on the module
&& (sym.span.exists || sym != defn.ExperimentalAnnot) // already reported on inferred annotations
then
if sym.isExperimental && !ctx.owner.isInExperimentalScope then
Feature.checkExperimentalDef(sym, pos)

private def checkExperimentalSignature(sym: Symbol, pos: SrcPos)(using Context): Unit =
val checker = new TypeTraverser:
class Checker extends TypeTraverser:
def traverse(tp: Type): Unit =
if tp.typeSymbol.isExperimental then
Feature.checkExperimentalDef(tp.typeSymbol, pos)
else
traverseChildren(tp)
if !sym.owner.isExperimental && !pos.span.isSynthetic then // avoid double errors
checker.traverse(sym.info)
if !sym.isInExperimentalScope then
new Checker().traverse(sym.info)

private def checkExperimentalAnnots(sym: Symbol)(using Context): Unit =
for annot <- sym.annotations if annot.symbol.isExperimental && annot.tree.span.exists do
Feature.checkExperimentalDef(annot.symbol, annot.tree)
if !sym.isInExperimentalScope then
for annot <- sym.annotations if annot.symbol.isExperimental do
Feature.checkExperimentalDef(annot.symbol, annot.tree)

/** If @migration is present (indicating that the symbol has changed semantics between versions),
* emit a warning.
Expand Down Expand Up @@ -1338,7 +1334,6 @@ class RefChecks extends MiniPhase { thisPhase =>
}

override def transformTypeDef(tree: TypeDef)(using Context): TypeDef = {
checkExperimental(tree.symbol, tree.srcPos)
checkExperimentalAnnots(tree.symbol)
tree
}
Expand Down
Loading