Skip to content

Update cc test compiler to latest dotc code base #16382

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

Merged
merged 2 commits into from
Nov 19, 2022
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
5 changes: 1 addition & 4 deletions tests/pos-with-compiler-cc/dotc/ast/TreeInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ import scala.collection.mutable

import scala.annotation.tailrec

trait TreeInfo[T >: Untyped <: Type] { self: Trees.Instance[T] =>

// Note: the <: Type constraint looks necessary (and is needed to make the file compile in dotc).
// But Scalac accepts the program happily without it. Need to find out why.
trait TreeInfo[T <: Untyped] { self: Trees.Instance[T] =>

def unsplice(tree: Trees.Tree[T]): Trees.Tree[T] = tree

Expand Down
308 changes: 153 additions & 155 deletions tests/pos-with-compiler-cc/dotc/ast/Trees.scala

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/pos-with-compiler-cc/dotc/ast/untpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
/** mods object name impl */
case class ModuleDef(name: TermName, impl: Template)(implicit @constructorOnly src: SourceFile)
extends MemberDef {
type ThisTree[-T >: Untyped] <: Trees.NameTree[T] with Trees.MemberDef[T] with ModuleDef
type ThisTree[+T <: Untyped] <: Trees.NameTree[T] with Trees.MemberDef[T] with ModuleDef
def withName(name: Name)(using Context): ModuleDef = cpy.ModuleDef(this)(name.toTermName, impl)
}

Expand Down
23 changes: 13 additions & 10 deletions tests/pos-with-compiler-cc/dotc/cc/CaptureOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -185,24 +185,27 @@ extension (tp: Type)
case _ =>
false

extension (cls: ClassSymbol)

def pureBaseClass(using Context): Option[Symbol] =
cls.baseClasses.find(bc =>
defn.pureBaseClasses.contains(bc)
|| {
val selfType = bc.givenSelfType
selfType.exists && selfType.captureSet.isAlwaysEmpty
})

extension (sym: Symbol)

/** A class is pure if:
* - one its base types has an explicitly declared self type with an empty capture set
* - or it is a value class
* - or it is Nothing or Null
* - or it is an exception
* - or it is one of Nothing, Null, or String
*/
def isPureClass(using Context): Boolean = sym match
case cls: ClassSymbol =>
val AnyValClass = defn.AnyValClass
cls.baseClasses.exists(bc =>
bc == AnyValClass
|| {
val selfType = bc.givenSelfType
selfType.exists && selfType.captureSet.isAlwaysEmpty
})
|| cls == defn.NothingClass
|| cls == defn.NullClass
cls.pureBaseClass.isDefined || defn.pureSimpleClasses.contains(cls)
case _ =>
false

Expand Down
5 changes: 0 additions & 5 deletions tests/pos-with-compiler-cc/dotc/cc/CaptureSet.scala
Original file line number Diff line number Diff line change
Expand Up @@ -327,11 +327,6 @@ object CaptureSet:
/** Used as a recursion brake */
@sharable private[dotc] val Pending = Const(SimpleIdentitySet.empty)

/** The empty capture set with a description that says it's the elf type of an
* exception class.
*/
val emptyOfException: CaptureSet.Const = Const(emptySet, "of an exception class")

def apply(elems: CaptureRef*)(using Context): CaptureSet.Const =
if elems.isEmpty then empty
else Const(SimpleIdentitySet(elems.map(_.normalizedRef)*))
Expand Down
9 changes: 6 additions & 3 deletions tests/pos-with-compiler-cc/dotc/cc/CheckCaptures.scala
Original file line number Diff line number Diff line change
Expand Up @@ -517,8 +517,10 @@ class CheckCaptures extends Recheck, SymTransformer:
for param <- cls.paramGetters do
if !param.hasAnnotation(defn.ConstructorOnlyAnnot) then
checkSubset(param.termRef.captureSet, thisSet, param.srcPos) // (3)
if cls.derivesFrom(defn.ThrowableClass) then
checkSubset(thisSet, CaptureSet.emptyOfException, tree.srcPos)
for pureBase <- cls.pureBaseClass do
checkSubset(thisSet,
CaptureSet.empty.withDescription(i"of pure base class $pureBase"),
tree.srcPos)
super.recheckClassDef(tree, impl, cls)
finally
curEnv = saved
Expand Down Expand Up @@ -880,6 +882,7 @@ class CheckCaptures extends Recheck, SymTransformer:
* - Check that externally visible `val`s or `def`s have empty capture sets. If not,
* suggest an explicit type. This is so that separate compilation (where external
* symbols have empty capture sets) gives the same results as joint compilation.
* - Check that arguments of TypeApplys and AppliedTypes conform to their bounds.
*/
def postCheck(unit: tpd.Tree)(using Context): Unit =
unit.foreachSubTree {
Expand Down Expand Up @@ -935,7 +938,7 @@ class CheckCaptures extends Recheck, SymTransformer:
case _ =>
}
if !ctx.reporter.errorsReported then
// We dont report errors hre if previous errors were reported, because other
// We dont report errors here if previous errors were reported, because other
// errors often result in bad applied types, but flagging these bad types gives
// often worse error messages than the original errors.
val checkApplied = new TreeTraverser:
Expand Down
6 changes: 5 additions & 1 deletion tests/pos-with-compiler-cc/dotc/config/Feature.scala
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ object Feature:
case Some(v) => v
case none => sourceVersionSetting

def migrateTo3(using Context): Boolean = sourceVersion == `3.0-migration`
def migrateTo3(using Context): Boolean =
sourceVersion == `3.0-migration`

def fewerBracesEnabled(using Context) =
sourceVersion.isAtLeast(`3.3`) || enabled(fewerBraces)

/** If current source migrates to `version`, issue given warning message
* and return `true`, otherwise return `false`.
Expand Down
1 change: 0 additions & 1 deletion tests/pos-with-compiler-cc/dotc/config/ScalaSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ trait AllScalaSettings extends CommonScalaSettings, PluginSettings, VerboseSetti
val oldSyntax: Setting[Boolean] = BooleanSetting("-old-syntax", "Require `(...)` around conditions.")
val indent: Setting[Boolean] = BooleanSetting("-indent", "Together with -rewrite, remove {...} syntax when possible due to significant indentation.")
val noindent: Setting[Boolean] = BooleanSetting("-no-indent", "Require classical {...} syntax, indentation is not significant.", aliases = List("-noindent"))
val YindentColons: Setting[Boolean] = BooleanSetting("-Yindent-colons", "(disabled: use -language:experimental.fewerBraces instead)")

/* Decompiler settings */
val printTasty: Setting[Boolean] = BooleanSetting("-print-tasty", "Prints the raw tasty.", aliases = List("--print-tasty"))
Expand Down
3 changes: 2 additions & 1 deletion tests/pos-with-compiler-cc/dotc/config/SourceVersion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import util.Property
enum SourceVersion:
case `3.0-migration`, `3.0`, `3.1` // Note: do not add `3.1-migration` here, 3.1 is the same language as 3.0.
case `3.2-migration`, `3.2`
case `3.3-migration`, `3.3`
case `future-migration`, `future`

val isMigrating: Boolean = toString.endsWith("-migration")
Expand All @@ -18,7 +19,7 @@ enum SourceVersion:
def isAtLeast(v: SourceVersion) = stable.ordinal >= v.ordinal

object SourceVersion extends Property.Key[SourceVersion]:
def defaultSourceVersion = `3.2`
def defaultSourceVersion = `3.3`

/** language versions that may appear in a language import, are deprecated, but not removed from the standard library. */
val illegalSourceVersionNames = List("3.1-migration").map(_.toTermName)
Expand Down
27 changes: 21 additions & 6 deletions tests/pos-with-compiler-cc/dotc/core/ConstraintHandling.scala
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,13 @@ trait ConstraintHandling {
inst
end approximation

private def isTransparent(tp: Type, traitOnly: Boolean)(using Context): Boolean = tp match
case AndType(tp1, tp2) =>
isTransparent(tp1, traitOnly) && isTransparent(tp2, traitOnly)
case _ =>
val cls = tp.underlyingClassRef(refinementOK = false).typeSymbol
cls.isTransparentClass && (!traitOnly || cls.is(Trait))

/** If `tp` is an intersection such that some operands are transparent trait instances
* and others are not, replace as many transparent trait instances as possible with Any
* as long as the result is still a subtype of `bound`. But fall back to the
Expand All @@ -568,18 +575,17 @@ trait ConstraintHandling {
var dropped: List[Type] = List() // the types dropped so far, last one on top

def dropOneTransparentTrait(tp: Type): Type =
val tpd = tp.dealias
if tpd.typeSymbol.isTransparentTrait && !tpd.isLambdaSub && !kept.contains(tpd) then
dropped = tpd :: dropped
if isTransparent(tp, traitOnly = true) && !kept.contains(tp) then
dropped = tp :: dropped
defn.AnyType
else tpd match
else tp match
case AndType(tp1, tp2) =>
val tp1w = dropOneTransparentTrait(tp1)
if tp1w ne tp1 then tp1w & tp2
else
val tp2w = dropOneTransparentTrait(tp2)
if tp2w ne tp2 then tp1 & tp2w
else tpd
else tp
case _ =>
tp

Expand Down Expand Up @@ -654,7 +660,16 @@ trait ConstraintHandling {

val wideInst =
if isSingleton(bound) then inst
else dropTransparentTraits(widenIrreducible(widenOr(widenSingle(inst))), bound)
else
val widenedFromSingle = widenSingle(inst)
val widenedFromUnion = widenOr(widenedFromSingle)
val widened =
if (widenedFromUnion ne widenedFromSingle) && isTransparent(widenedFromUnion, traitOnly = false) then
widenedFromSingle
else
dropTransparentTraits(widenedFromUnion, bound)
widenIrreducible(widened)

wideInst match
case wideInst: TypeRef if wideInst.symbol.is(Module) =>
TermRef(wideInst.prefix, wideInst.symbol.sourceModule)
Expand Down
10 changes: 5 additions & 5 deletions tests/pos-with-compiler-cc/dotc/core/Contexts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ object Contexts {
final def owner: Symbol = _owner

/** The current tree */
private var _tree: Tree[? >: Untyped]= _
protected def tree_=(tree: Tree[? >: Untyped]): Unit = _tree = tree
final def tree: Tree[? >: Untyped] = _tree
private var _tree: Tree[?]= _
protected def tree_=(tree: Tree[?]): Unit = _tree = tree
final def tree: Tree[?] = _tree

/** The current scope */
private var _scope: Scope = _
Expand Down Expand Up @@ -470,7 +470,7 @@ object Contexts {
}

/** The context of expression `expr` seen as a member of a statement sequence */
def exprContext(stat: Tree[? >: Untyped], exprOwner: Symbol): Context =
def exprContext(stat: Tree[?], exprOwner: Symbol): Context =
if (exprOwner == this.owner) this
else if (untpd.isSuperConstrCall(stat) && this.owner.isClass) superCallContext
else fresh.setOwner(exprOwner)
Expand Down Expand Up @@ -593,7 +593,7 @@ object Contexts {
assert(owner != NoSymbol)
this.owner = owner
this
def setTree(tree: Tree[? >: Untyped]): this.type =
def setTree(tree: Tree[?]): this.type =
util.Stats.record("Context.setTree")
this.tree = tree
this
Expand Down
3 changes: 3 additions & 0 deletions tests/pos-with-compiler-cc/dotc/core/Decorators.scala
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,9 @@ object Decorators {
s"[cannot display due to $msg, raw string = $x]"
case _ => String.valueOf(x).nn

/** Returns the simple class name of `x`. */
def className: String = getClass.getSimpleName.nn

extension [T](x: T)
def assertingErrorsReported(using Context): T = {
assert(ctx.reporter.errorsReported)
Expand Down
71 changes: 56 additions & 15 deletions tests/pos-with-compiler-cc/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,6 @@ class Definitions {

// Annotation base classes
@tu lazy val AnnotationClass: ClassSymbol = requiredClass("scala.annotation.Annotation")
@tu lazy val ClassfileAnnotationClass: ClassSymbol = requiredClass("scala.annotation.ClassfileAnnotation")
@tu lazy val StaticAnnotationClass: ClassSymbol = requiredClass("scala.annotation.StaticAnnotation")
@tu lazy val RefiningAnnotationClass: ClassSymbol = requiredClass("scala.annotation.RefiningAnnotation")

Expand Down Expand Up @@ -1350,6 +1349,15 @@ class Definitions {

@tu lazy val untestableClasses: Set[Symbol] = Set(NothingClass, NullClass, SingletonClass)

/** Base classes that are assumed to be pure for the purposes of capture checking.
* Every class inheriting from a pure baseclass is pure.
*/
@tu lazy val pureBaseClasses = Set(defn.AnyValClass, defn.ThrowableClass)

/** Non-inheritable lasses that are assumed to be pure for the purposes of capture checking,
*/
@tu lazy val pureSimpleClasses = Set(StringClass, NothingClass, NullClass)

@tu lazy val AbstractFunctionType: Array[TypeRef] = mkArityArray("scala.runtime.AbstractFunction", MaxImplementedFunctionArity, 0).asInstanceOf[Array[TypeRef]]
val AbstractFunctionClassPerRun: PerRun[Array[Symbol]] = new PerRun(AbstractFunctionType.map(_.symbol.asClass))
def AbstractFunctionClass(n: Int)(using Context): Symbol = AbstractFunctionClassPerRun()(using ctx)(n)
Expand Down Expand Up @@ -1830,20 +1838,53 @@ class Definitions {
def isInfix(sym: Symbol)(using Context): Boolean =
(sym eq Object_eq) || (sym eq Object_ne)

@tu lazy val assumedTransparentTraits =
Set[Symbol](ComparableClass, ProductClass, SerializableClass,
// add these for now, until we had a chance to retrofit 2.13 stdlib
// we should do a more through sweep through it then.
requiredClass("scala.collection.SortedOps"),
requiredClass("scala.collection.StrictOptimizedSortedSetOps"),
requiredClass("scala.collection.generic.DefaultSerializable"),
requiredClass("scala.collection.generic.IsIterable"),
requiredClass("scala.collection.generic.IsIterableOnce"),
requiredClass("scala.collection.generic.IsMap"),
requiredClass("scala.collection.generic.IsSeq"),
requiredClass("scala.collection.generic.Subtractable"),
requiredClass("scala.collection.immutable.StrictOptimizedSeqOps")
)
@tu lazy val assumedTransparentNames: Map[Name, Set[Symbol]] =
// add these for now, until we had a chance to retrofit 2.13 stdlib
// we should do a more through sweep through it then.
val strs = Map(
"Any" -> Set("scala"),
"AnyVal" -> Set("scala"),
"Matchable" -> Set("scala"),
"Product" -> Set("scala"),
"Object" -> Set("java.lang"),
"Comparable" -> Set("java.lang"),
"Serializable" -> Set("java.io"),
"BitSetOps" -> Set("scala.collection"),
"IndexedSeqOps" -> Set("scala.collection", "scala.collection.mutable", "scala.collection.immutable"),
"IterableOnceOps" -> Set("scala.collection"),
"IterableOps" -> Set("scala.collection"),
"LinearSeqOps" -> Set("scala.collection", "scala.collection.immutable"),
"MapOps" -> Set("scala.collection", "scala.collection.mutable", "scala.collection.immutable"),
"SeqOps" -> Set("scala.collection", "scala.collection.mutable", "scala.collection.immutable"),
"SetOps" -> Set("scala.collection", "scala.collection.mutable", "scala.collection.immutable"),
"SortedMapOps" -> Set("scala.collection", "scala.collection.mutable", "scala.collection.immutable"),
"SortedOps" -> Set("scala.collection"),
"SortedSetOps" -> Set("scala.collection", "scala.collection.mutable", "scala.collection.immutable"),
"StrictOptimizedIterableOps" -> Set("scala.collection"),
"StrictOptimizedLinearSeqOps" -> Set("scala.collection"),
"StrictOptimizedMapOps" -> Set("scala.collection", "scala.collection.immutable"),
"StrictOptimizedSeqOps" -> Set("scala.collection", "scala.collection.immutable"),
"StrictOptimizedSetOps" -> Set("scala.collection", "scala.collection.immutable"),
"StrictOptimizedSortedMapOps" -> Set("scala.collection", "scala.collection.immutable"),
"StrictOptimizedSortedSetOps" -> Set("scala.collection", "scala.collection.immutable"),
"ArrayDequeOps" -> Set("scala.collection.mutable"),
"DefaultSerializable" -> Set("scala.collection.generic"),
"IsIterable" -> Set("scala.collection.generic"),
"IsIterableLowPriority" -> Set("scala.collection.generic"),
"IsIterableOnce" -> Set("scala.collection.generic"),
"IsIterableOnceLowPriority" -> Set("scala.collection.generic"),
"IsMap" -> Set("scala.collection.generic"),
"IsSeq" -> Set("scala.collection.generic"))
strs.map { case (simple, pkgs) => (
simple.toTypeName,
pkgs.map(pkg => staticRef(pkg.toTermName, isPackage = true).symbol.moduleClass)
)
}

def isAssumedTransparent(sym: Symbol): Boolean =
assumedTransparentNames.get(sym.name) match
case Some(pkgs) => pkgs.contains(sym.owner)
case none => false

// ----- primitive value class machinery ------------------------------------------

Expand Down
9 changes: 4 additions & 5 deletions tests/pos-with-compiler-cc/dotc/core/Flags.scala
Original file line number Diff line number Diff line change
Expand Up @@ -350,14 +350,14 @@ object Flags {
/** Symbol is a method which should be marked ACC_SYNCHRONIZED */
val (_, Synchronized @ _, _) = newFlags(36, "<synchronized>")

/** Symbol is a Java-style varargs method */
val (_, JavaVarargs @ _, _) = newFlags(37, "<varargs>")
/** Symbol is a Java-style varargs method / a Java annotation */
val (_, JavaVarargs @ _, JavaAnnotation @ _) = newFlags(37, "<varargs>", "<java-annotation>")

/** Symbol is a Java default method */
val (_, DefaultMethod @ _, _) = newFlags(38, "<defaultmethod>")

/** Symbol is a transparent inline method or trait */
val (Transparent @ _, _, _) = newFlags(39, "transparent")
val (Transparent @ _, _, TransparentType @ _) = newFlags(39, "transparent")

/** Symbol is an enum class or enum case (if used with case) */
val (Enum @ _, EnumVal @ _, _) = newFlags(40, "enum")
Expand Down Expand Up @@ -477,7 +477,7 @@ object Flags {
*/
val AfterLoadFlags: FlagSet = commonFlags(
FromStartFlags, AccessFlags, Final, AccessorOrSealed,
Abstract, LazyOrTrait, SelfName, JavaDefined, Transparent)
Abstract, LazyOrTrait, SelfName, JavaDefined, JavaAnnotation, Transparent)

/** A value that's unstable unless complemented with a Stable flag */
val UnstableValueFlags: FlagSet = Mutable | Method
Expand Down Expand Up @@ -609,5 +609,4 @@ object Flags {
val SyntheticParam: FlagSet = Synthetic | Param
val SyntheticTermParam: FlagSet = Synthetic | TermParam
val SyntheticTypeParam: FlagSet = Synthetic | TypeParam
val TransparentTrait: FlagSet = Trait | Transparent
}
2 changes: 1 addition & 1 deletion tests/pos-with-compiler-cc/dotc/core/Scopes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ object Scopes {
override def size: Int = 0
override def nestingLevel: Int = 0
override def toList(using Context): List[Symbol] = Nil
override def cloneScope(using Context): MutableScope = unsupported("cloneScope")
override def cloneScope(using Context): MutableScope = newScope(nestingLevel)
override def lookupEntry(name: Name)(using Context): ScopeEntry | Null = null
override def lookupNextEntry(entry: ScopeEntry)(using Context): ScopeEntry | Null = null
}
Expand Down
1 change: 0 additions & 1 deletion tests/pos-with-compiler-cc/dotc/core/StdNames.scala
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@ object StdNames {
final val ToString: N = "ToString"
final val Xor: N = "^"

final val ClassfileAnnotation: N = "ClassfileAnnotation"
final val ClassManifest: N = "ClassManifest"
final val Enum: N = "Enum"
final val Group: N = "Group"
Expand Down
8 changes: 4 additions & 4 deletions tests/pos-with-compiler-cc/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ object SymDenotations {

/** Is this a Scala or Java annotation ? */
def isAnnotation(using Context): Boolean =
isClass && derivesFrom(defn.AnnotationClass)
isClass && (derivesFrom(defn.AnnotationClass) || is(JavaAnnotation))

/** Is this symbol a class that extends `java.io.Serializable` ? */
def isSerializable(using Context): Boolean =
Expand Down Expand Up @@ -1152,9 +1152,9 @@ object SymDenotations {
final def isEffectivelySealed(using Context): Boolean =
isOneOf(FinalOrSealed) || isClass && !isOneOf(EffectivelyOpenFlags)

final def isTransparentTrait(using Context): Boolean =
isAllOf(TransparentTrait)
|| defn.assumedTransparentTraits.contains(symbol)
final def isTransparentClass(using Context): Boolean =
is(TransparentType)
|| defn.isAssumedTransparent(symbol)
|| isClass && hasAnnotation(defn.TransparentTraitAnnot)

/** The class containing this denotation which has the given effective name. */
Expand Down
Loading