Skip to content

CC-UPDATE: Update test compiler to latest version #16413

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 25, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion tests/pos-with-compiler-cc/dotc/Run.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import java.nio.charset.StandardCharsets
import scala.collection.mutable
import scala.util.control.NonFatal
import scala.io.Codec
import caps.unsafe.unsafeUnbox

/** A compiler run. Exports various methods to compile source files */
class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with ConstraintRunInfo {
Expand Down Expand Up @@ -270,7 +271,7 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
Rewrites.writeBack()
suppressions.runFinished(hasErrors = ctx.reporter.hasErrors)
while (finalizeActions.nonEmpty) {
val action = finalizeActions.remove(0)
val action = finalizeActions.remove(0).unsafeUnbox
action()
}
compiling = false
Expand Down
7 changes: 5 additions & 2 deletions tests/pos-with-compiler-cc/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ object desugar {
else (Nil, Nil)
}

var parents1 = parents
var parents1: List[untpd.Tree] = parents // !cc! need explicit type to make capture checking pass
if (isEnumCase && parents.isEmpty)
parents1 = enumClassTypeRef :: Nil
if (isNonEnumCase)
Expand Down Expand Up @@ -1789,7 +1789,10 @@ object desugar {
val elems = segments flatMap {
case ts: Thicket => ts.trees.tail
case t => Nil
} map {
} map { (t: Tree) => t match
// !cc! explicitly typed parameter (t: Tree) is needed since otherwise
// we get an error similar to #16268. (The explicit type constrains the type of `segments`
// which is otherwise List[{*} tree])
case Block(Nil, EmptyTree) => Literal(Constant(())) // for s"... ${} ..."
case Block(Nil, expr) => expr // important for interpolated string as patterns, see i1773.scala
case t => t
Expand Down
2 changes: 1 addition & 1 deletion tests/pos-with-compiler-cc/dotc/ast/Positioned.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import annotation.internal.sharable

/** A base class for things that have positions (currently: modifiers and trees)
*/
abstract class Positioned(implicit @constructorOnly src: SourceFile) extends SrcPos, Product, Cloneable {
abstract class Positioned(implicit @constructorOnly src: SourceFile) extends SrcPos, Product, Cloneable, caps.Pure {
import Positioned.{ids, nextId, debugId}

private var mySpan: Span = _
Expand Down
9 changes: 5 additions & 4 deletions tests/pos-with-compiler-cc/dotc/ast/TreeTypeMap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Types._, Contexts._, Flags._
import Symbols._, Annotations._, Trees._, Symbols._, Constants.Constant
import Decorators._
import dotty.tools.dotc.transform.SymUtils._
import language.experimental.pureFunctions

/** A map that applies three functions and a substitution together to a tree and
* makes sure they are coordinated so that the result is well-typed. The functions are
Expand All @@ -32,8 +33,8 @@ import dotty.tools.dotc.transform.SymUtils._
* set, we would get a data race assertion error.
*/
class TreeTypeMap(
val typeMap: Type => Type = IdentityTypeMap,
val treeMap: tpd.Tree => tpd.Tree = identity _,
val typeMap: Type -> Type = IdentityTypeMap,
val treeMap: tpd.Tree -> tpd.Tree = identity[tpd.Tree](_), // !cc! need explicit instantiation of default argument
val oldOwners: List[Symbol] = Nil,
val newOwners: List[Symbol] = Nil,
val substFrom: List[Symbol] = Nil,
Expand All @@ -42,8 +43,8 @@ class TreeTypeMap(
import tpd._

def copy(
typeMap: Type => Type,
treeMap: tpd.Tree => tpd.Tree,
typeMap: Type -> Type,
treeMap: tpd.Tree -> tpd.Tree,
oldOwners: List[Symbol],
newOwners: List[Symbol],
substFrom: List[Symbol],
Expand Down
6 changes: 4 additions & 2 deletions tests/pos-with-compiler-cc/dotc/ast/Trees.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import annotation.unchecked.uncheckedVariance
import annotation.constructorOnly
import compiletime.uninitialized
import Decorators._
import annotation.retains
import language.experimental.pureFunctions

object Trees {

Expand Down Expand Up @@ -431,7 +433,7 @@ object Trees {
def isBackquoted: Boolean = hasAttachment(Backquoted)
}

class SearchFailureIdent[+T <: Untyped] private[ast] (name: Name, expl: => String)(implicit @constructorOnly src: SourceFile)
class SearchFailureIdent[+T <: Untyped] private[ast] (name: Name, expl: -> String)(implicit @constructorOnly src: SourceFile)
extends Ident[T](name) {
def explanation = expl
override def toString: String = s"SearchFailureIdent($explanation)"
Expand Down Expand Up @@ -1518,7 +1520,7 @@ object Trees {
}
}

abstract class TreeAccumulator[X] { self =>
abstract class TreeAccumulator[X] { self: TreeAccumulator[X] @retains(caps.*) =>
// Ties the knot of the traversal: call `foldOver(x, tree))` to dive in the `tree` node.
def apply(x: X, tree: Tree)(using Context): X

Expand Down
3 changes: 2 additions & 1 deletion tests/pos-with-compiler-cc/dotc/ast/tpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import typer.ConstFold

import scala.annotation.tailrec
import scala.collection.mutable.ListBuffer
import language.experimental.pureFunctions

/** Some creators for typed trees */
object tpd extends Trees.Instance[Type] with TypedTreeInfo {
Expand Down Expand Up @@ -1454,7 +1455,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
* @return The symbols imported.
*/
def importedSymbols(imp: Import,
selectorPredicate: untpd.ImportSelector => Boolean = util.common.alwaysTrue)
selectorPredicate: untpd.ImportSelector -> Boolean = util.common.alwaysTrue)
(using Context): List[Symbol] =
imp.selectors.find(selectorPredicate) match
case Some(sel) => importedSymbols(imp.expr, sel.name)
Expand Down
9 changes: 6 additions & 3 deletions tests/pos-with-compiler-cc/dotc/ast/untpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import util.Spans.Span
import annotation.constructorOnly
import annotation.internal.sharable
import Decorators._
import annotation.retains
import language.experimental.pureFunctions

object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {

Expand Down Expand Up @@ -150,7 +152,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
case class CapturingTypeTree(refs: List[Tree], parent: Tree)(implicit @constructorOnly src: SourceFile) extends TypTree

/** Short-lived usage in typer, does not need copy/transform/fold infrastructure */
case class DependentTypeTree(tp: List[Symbol] => Type)(implicit @constructorOnly src: SourceFile) extends Tree
case class DependentTypeTree(tp: List[Symbol] -> Type)(implicit @constructorOnly src: SourceFile) extends Tree

@sharable object EmptyTypeIdent extends Ident(tpnme.EMPTY)(NoSource) with WithoutTypeOrPos[Untyped] {
override def isEmpty: Boolean = true
Expand Down Expand Up @@ -370,7 +372,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
// ------ Creation methods for untyped only -----------------

def Ident(name: Name)(implicit src: SourceFile): Ident = new Ident(name)
def SearchFailureIdent(name: Name, explanation: => String)(implicit src: SourceFile): SearchFailureIdent = new SearchFailureIdent(name, explanation)
def SearchFailureIdent(name: Name, explanation: -> String)(implicit src: SourceFile): SearchFailureIdent = new SearchFailureIdent(name, explanation)
def Select(qualifier: Tree, name: Name)(implicit src: SourceFile): Select = new Select(qualifier, name)
def SelectWithSig(qualifier: Tree, name: Name, sig: Signature)(implicit src: SourceFile): Select = new SelectWithSig(qualifier, name, sig)
def This(qual: Ident)(implicit src: SourceFile): This = new This(qual)
Expand Down Expand Up @@ -737,7 +739,8 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
}
}

abstract class UntypedTreeAccumulator[X] extends TreeAccumulator[X] { self =>
abstract class UntypedTreeAccumulator[X] extends TreeAccumulator[X] {
self: UntypedTreeAccumulator[X] @retains(caps.*) =>
override def foldMoreCases(x: X, tree: Tree)(using Context): X = tree match {
case ModuleDef(name, impl) =>
this(x, impl)
Expand Down
15 changes: 9 additions & 6 deletions tests/pos-with-compiler-cc/dotc/cc/CaptureSet.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import util.{SimpleIdentitySet, Property}
import util.common.alwaysTrue
import scala.collection.mutable
import config.Config.ccAllowUnsoundMaps
import language.experimental.pureFunctions

/** A class for capture sets. Capture sets can be constants or variables.
* Capture sets support inclusion constraints <:< where <:< is subcapturing.
Expand All @@ -37,7 +38,7 @@ import config.Config.ccAllowUnsoundMaps
* if the mapped function is either a bijection or if it is idempotent
* on capture references (c.f. doc comment on `map` below).
*/
sealed abstract class CaptureSet extends Showable:
sealed abstract class CaptureSet extends Showable, caps.Pure:
import CaptureSet.*

/** The elements of this capture set. For capture variables,
Expand Down Expand Up @@ -222,7 +223,7 @@ sealed abstract class CaptureSet extends Showable:
/** The largest subset (via <:<) of this capture set that only contains elements
* for which `p` is true.
*/
def filter(p: CaptureRef => Boolean)(using Context): CaptureSet =
def filter(p: CaptureRef -> Boolean)(using Context): CaptureSet =
if this.isConst then
val elems1 = elems.filter(p)
if elems1 == elems then this
Expand Down Expand Up @@ -372,8 +373,10 @@ object CaptureSet:
def isConst = isSolved
def isAlwaysEmpty = false

/** A handler to be invoked if the root reference `*` is added to this set */
var rootAddedHandler: () => Context ?=> Unit = () => ()
/** A handler to be invoked if the root reference `*` is added to this set
* The handler is pure in the sense that it will only output diagnostics.
*/
var rootAddedHandler: () -> Context ?-> Unit = () => ()

var description: String = ""

Expand Down Expand Up @@ -421,7 +424,7 @@ object CaptureSet:
else
CompareResult.fail(this)

override def disallowRootCapability(handler: () => Context ?=> Unit)(using Context): this.type =
override def disallowRootCapability(handler: () -> Context ?-> Unit)(using Context): this.type =
rootAddedHandler = handler
super.disallowRootCapability(handler)

Expand Down Expand Up @@ -613,7 +616,7 @@ object CaptureSet:

/** A variable with elements given at any time as { x <- source.elems | p(x) } */
class Filtered private[CaptureSet]
(val source: Var, p: CaptureRef => Boolean)(using @constructorOnly ctx: Context)
(val source: Var, p: CaptureRef -> Boolean)(using @constructorOnly ctx: Context)
extends DerivedVar(source.elems.filter(p)):

override def addNewElems(newElems: Refs, origin: CaptureSet)(using Context, VarState): CompareResult =
Expand Down
10 changes: 6 additions & 4 deletions tests/pos-with-compiler-cc/dotc/cc/CheckCaptures.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import CaptureSet.{withCaptureSetsExplained, IdempotentCaptRefMap}
import StdNames.nme
import NameKinds.DefaultGetterName
import reporting.trace
import language.experimental.pureFunctions

/** The capture checker */
object CheckCaptures:
Expand Down Expand Up @@ -738,20 +739,21 @@ class CheckCaptures extends Recheck, SymTransformer:
* the innermost capturing type. The outer capture annotations can be
* reconstructed with the returned function.
*/
def destructCapturingType(tp: Type, reconstruct: Type => Type = x => x): ((Type, CaptureSet, Boolean), Type => Type) =
def destructCapturingType(tp: Type, reconstruct: Type -> Type = (x: Type) => x) // !cc! need monomorphic default argument
: (Type, CaptureSet, Boolean, Type -> Type) =
tp.dealias match
case tp @ CapturingType(parent, cs) =>
if parent.dealias.isCapturingType then
destructCapturingType(parent, res => reconstruct(tp.derivedCapturingType(res, cs)))
else
((parent, cs, tp.isBoxed), reconstruct)
(parent, cs, tp.isBoxed, reconstruct)
case actual =>
((actual, CaptureSet(), false), reconstruct)
(actual, CaptureSet(), false, reconstruct)

def adapt(actual: Type, expected: Type, covariant: Boolean): Type = trace(adaptInfo(actual, expected, covariant), recheckr, show = true) {
if expected.isInstanceOf[WildcardType] then actual
else
val ((parent, cs, actualIsBoxed), recon) = destructCapturingType(actual)
val (parent, cs, actualIsBoxed, recon: (Type -> Type)) = destructCapturingType(actual)

val needsAdaptation = actualIsBoxed != expected.isBoxedCapturing
val insertBox = needsAdaptation && covariant != actualIsBoxed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import PlainFile.toPlainFile
import scala.jdk.CollectionConverters._
import scala.collection.immutable.ArraySeq
import scala.util.control.NonFatal
import language.experimental.pureFunctions

/**
* A trait allowing to look for classpath entries in directories. It provides common logic for
Expand All @@ -32,7 +33,7 @@ trait DirectoryLookup[FileEntryType <: ClassRepresentation] extends EfficientCla

protected def emptyFiles: Array[F] // avoids reifying ClassTag[F]
protected def getSubDir(dirName: String): Option[F]
protected def listChildren(dir: F, filter: Option[F => Boolean] = None): Array[F]
protected def listChildren(dir: F, filter: Option[F -> Boolean] = (None: Option[F -> Boolean])): Array[F] // !cc! need explicit typing of default argument
protected def getName(f: F): String
protected def toAbstractFile(f: F): AbstractFile
protected def isPackage(f: F): Boolean
Expand Down Expand Up @@ -90,7 +91,7 @@ trait JFileDirectoryLookup[FileEntryType <: ClassRepresentation] extends Directo
if (packageDir.exists && packageDir.isDirectory) Some(packageDir)
else None
}
protected def listChildren(dir: JFile, filter: Option[JFile => Boolean]): Array[JFile] = {
protected def listChildren(dir: JFile, filter: Option[JFile -> Boolean]): Array[JFile] = {
val listing = filter match {
case Some(f) => dir.listFiles(mkFileFilter(f))
case None => dir.listFiles()
Expand Down
3 changes: 2 additions & 1 deletion tests/pos-with-compiler-cc/dotc/classpath/FileUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import scala.language.unsafeNulls
import java.io.{File => JFile, FileFilter}
import java.net.URL
import dotty.tools.io.AbstractFile
import language.experimental.pureFunctions

/**
* Common methods related to Java files and abstract files used in the context of classpath
Expand Down Expand Up @@ -78,7 +79,7 @@ object FileUtils {
def mayBeValidPackage(dirName: String): Boolean =
(dirName != "META-INF") && (dirName != "") && (dirName.charAt(0) != '.')

def mkFileFilter(f: JFile => Boolean): FileFilter = new FileFilter {
def mkFileFilter(f: JFile -> Boolean): FileFilter = new FileFilter {
def accept(pathname: JFile): Boolean = f(pathname)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import FileUtils._
import java.net.URL

import dotty.tools.io.ClassPath
import language.experimental.pureFunctions

case class VirtualDirectoryClassPath(dir: VirtualDirectory) extends ClassPath with DirectoryLookup[ClassFileEntryImpl] with NoSourcePaths {
type F = AbstractFile
Expand All @@ -28,7 +29,7 @@ case class VirtualDirectoryClassPath(dir: VirtualDirectory) extends ClassPath wi
protected def emptyFiles: Array[AbstractFile] = Array.empty
protected def getSubDir(packageDirName: String): Option[AbstractFile] =
Option(lookupPath(dir)(packageDirName.split(java.io.File.separator).toIndexedSeq, directory = true))
protected def listChildren(dir: AbstractFile, filter: Option[AbstractFile => Boolean] = None): Array[F] = filter match {
protected def listChildren(dir: AbstractFile, filter: Option[AbstractFile -> Boolean]): Array[F] = filter match {
case Some(f) => dir.iterator.filter(f).toArray
case _ => dir.toArray
}
Expand Down
3 changes: 2 additions & 1 deletion tests/pos-with-compiler-cc/dotc/config/Feature.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import util.{SrcPos, NoSourcePosition}
import SourceVersion._
import reporting.Message
import NameKinds.QualifiedName
import language.experimental.pureFunctions

object Feature:

Expand Down Expand Up @@ -128,7 +129,7 @@ object Feature:
else
false

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

Expand Down
Loading