Skip to content
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
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1020,7 +1020,7 @@ class Definitions {
@tu lazy val Caps_ContainsModule: Symbol = requiredModule("scala.caps.Contains")
@tu lazy val Caps_containsImpl: TermSymbol = Caps_ContainsModule.requiredMethod("containsImpl")

@tu lazy val PureClass: ClassSymbol = requiredClass("scala.Pure")
@tu lazy val PureClass: ClassSymbol = requiredClass("scala.caps.Pure")

// Annotation base classes
@tu lazy val AnnotationClass: ClassSymbol = requiredClass("scala.annotation.Annotation")
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/TypeErasure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ object TypeErasure {
case _ => -1

def normalizeClass(cls: ClassSymbol)(using Context): ClassSymbol = {
if (defn.specialErasure.contains(cls))
return defn.specialErasure(cls).uncheckedNN
if (cls.owner == defn.ScalaPackageClass) {
if (defn.specialErasure.contains(cls))
return defn.specialErasure(cls).uncheckedNN
if (cls == defn.UnitClass)
return defn.BoxedUnitClass
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/Erasure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ class Erasure extends Phase with DenotTransformer {
|| isAllowed(defn.TupleClass, "Tuple.scala")
|| isAllowed(defn.NonEmptyTupleClass, "Tuple.scala")
|| isAllowed(defn.PairClass, "Tuple.scala")
|| isAllowed(defn.PureClass, "Pure.scala"),
|| isAllowed(defn.PureClass, /* caps/ */ "Pure.scala"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this comment truly necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just as a reminder, since isAllowed only checks the file name and not the full path

i"The type $tp - ${tp.toString} of class ${tp.getClass} of tree $tree : ${tree.tpe} / ${tree.getClass} is illegal after erasure, phase = ${ctx.phase.prev}")
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package scala
import annotation.experimental
package caps

/** A marker trait that declares that all inheriting classes are "pure" in the
* sense that their values retain no capabilities including capabilities needed
* to perform effects. This has formal meaning only under capture checking.
*/
@experimental trait Pure:
trait Pure:
this: Pure =>
4 changes: 2 additions & 2 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,6 @@ object Build {
file(s"${baseDirectory.value}/src/scala/CanEqual.scala"),
file(s"${baseDirectory.value}/src/scala/Conversion.scala"),
file(s"${baseDirectory.value}/src/scala/PolyFunction.scala"),
file(s"${baseDirectory.value}/src/scala/Pure.scala"),
file(s"${baseDirectory.value}/src/scala/IArray.scala"),
file(s"${baseDirectory.value}/src/scala/CanThrow.scala"),
file(s"${baseDirectory.value}/src/scala/Tuple.scala"),
Expand All @@ -1110,6 +1109,7 @@ object Build {
file(s"${baseDirectory.value}/src/scala/util/NotGiven.scala"),
file(s"${baseDirectory.value}/src/scala/util/boundary.scala"),
file(s"${baseDirectory.value}/src/scala/caps/package.scala"),
file(s"${baseDirectory.value}/src/scala/caps/Pure.scala"),
file(s"${baseDirectory.value}/src/scala/reflect/TypeTest.scala"),
file(s"${baseDirectory.value}/src/scala/reflect/Selectable.scala"),
file(s"${baseDirectory.value}/src/scala/reflect/Typeable.scala"),
Expand Down Expand Up @@ -1235,7 +1235,6 @@ object Build {
file(s"${baseDirectory.value}/src/scala/CanEqual.scala"),
file(s"${baseDirectory.value}/src/scala/Conversion.scala"),
file(s"${baseDirectory.value}/src/scala/PolyFunction.scala"),
file(s"${baseDirectory.value}/src/scala/Pure.scala"),
file(s"${baseDirectory.value}/src/scala/IArray.scala"),
file(s"${baseDirectory.value}/src/scala/CanThrow.scala"),
file(s"${baseDirectory.value}/src/scala/Tuple.scala"),
Expand All @@ -1248,6 +1247,7 @@ object Build {
file(s"${baseDirectory.value}/src/scala/util/NotGiven.scala"),
file(s"${baseDirectory.value}/src/scala/util/boundary.scala"),
file(s"${baseDirectory.value}/src/scala/caps/package.scala"),
file(s"${baseDirectory.value}/src/scala/caps/Pure.scala"),
file(s"${baseDirectory.value}/src/scala/reflect/TypeTest.scala"),
file(s"${baseDirectory.value}/src/scala/reflect/Selectable.scala"),
file(s"${baseDirectory.value}/src/scala/reflect/Typeable.scala"),
Expand Down
8 changes: 4 additions & 4 deletions scala2-library-cc/src/scala/collection/Factory.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import caps.unsafe.unsafeAssumePure
* @tparam A Type of elements (e.g. `Int`, `Boolean`, etc.)
* @tparam C Type of collection (e.g. `List[Int]`, `TreeMap[Int, String]`, etc.)
*/
trait Factory[-A, +C] extends Pure {
trait Factory[-A, +C] extends caps.Pure {

/**
* @return A collection of type `C` containing the same elements
Expand Down Expand Up @@ -82,7 +82,7 @@ object Factory {
* @define coll collection
* @define Coll `Iterable`
*/
trait IterableFactory[+CC[_]] extends Serializable, Pure {
trait IterableFactory[+CC[_]] extends Serializable, caps.Pure {

/** Creates a target $coll from an existing source collection
*
Expand Down Expand Up @@ -389,7 +389,7 @@ trait SpecificIterableFactory[-A, +C] extends Factory[A, C] {
* @define coll collection
* @define Coll `Iterable`
*/
trait MapFactory[+CC[_, _]] extends Serializable, Pure {
trait MapFactory[+CC[_, _]] extends Serializable, caps.Pure {

/**
* An empty Map
Expand Down Expand Up @@ -462,7 +462,7 @@ object MapFactory {
* @define coll collection
* @define Coll `Iterable`
*/
trait EvidenceIterableFactory[+CC[_], Ev[_]] extends Serializable, Pure {
trait EvidenceIterableFactory[+CC[_], Ev[_]] extends Serializable, caps.Pure {

def from[E : Ev](it: IterableOnce[E]^): CC[E]

Expand Down
2 changes: 1 addition & 1 deletion scala2-library-cc/src/scala/collection/Map.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ trait Map[K, +V]
with MapOps[K, V, Map, Map[K, V]]
with MapFactoryDefaults[K, V, Map, Iterable]
with Equals
with Pure {
with caps.Pure {

def mapFactory: scala.collection.MapFactory[Map] = Map

Expand Down
2 changes: 1 addition & 1 deletion scala2-library-cc/src/scala/collection/Set.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ trait Set[A]
with SetOps[A, Set, Set[A]]
with Equals
with IterableFactoryDefaults[A, Set]
with Pure {
with caps.Pure {
self: Set[A] =>

def canEqual(that: Any) = true
Expand Down
2 changes: 1 addition & 1 deletion scala2-library-cc/src/scala/collection/SortedMap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ trait SortedMap[K, +V]
trait SortedMapOps[K, +V, +CC[X, Y] <: Map[X, Y] with SortedMapOps[X, Y, CC, _], +C <: SortedMapOps[K, V, CC, C]]
extends MapOps[K, V, Map, C]
with SortedOps[K, C]
with Pure {
with caps.Pure {

/** The companion object of this sorted map, providing various factory methods.
*
Expand Down
2 changes: 1 addition & 1 deletion scala2-library-cc/src/scala/collection/StepperShape.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import scala.collection.Stepper.EfficientSplit
/** An implicit StepperShape instance is used in the [[IterableOnce.stepper]] to return a possibly
* specialized Stepper `S` according to the element type `T`.
*/
sealed trait StepperShape[-T, S <: Stepper[_]^] extends Pure {
sealed trait StepperShape[-T, S <: Stepper[_]^] extends caps.Pure {
/** Return the Int constant (as defined in the `StepperShape` companion object) for this `StepperShape`. */
def shape: StepperShape.Shape

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import language.experimental.captureChecking
trait StrictOptimizedMapOps[K, +V, +CC[_, _] <: IterableOps[_, AnyConstr, _], +C]
extends MapOps[K, V, CC, C]
with StrictOptimizedIterableOps[(K, V), Iterable, C]
with Pure {
with caps.Pure {

override def map[K2, V2](f: ((K, V)) => (K2, V2)): CC[K2, V2] =
strictOptimizedMap(mapFactory.newBuilder, f)
Expand Down
2 changes: 1 addition & 1 deletion scala2-library-cc/src/scala/collection/View.scala
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ object View extends IterableFactory[View] {

/** A view with given elements */
@SerialVersionUID(3L)
class Elems[A](xs: A*) extends AbstractView[A], Pure {
class Elems[A](xs: A*) extends AbstractView[A], caps.Pure {
def iterator = xs.iterator
override def knownSize = xs.knownSize
override def isEmpty: Boolean = xs.isEmpty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ sealed abstract class ArraySeq[+A]
with StrictOptimizedSeqOps[A, ArraySeq, ArraySeq[A]]
with EvidenceIterableFactoryDefaults[A, ArraySeq, ClassTag]
with Serializable
with Pure {
with caps.Pure {

/** The tag of the element type. This does not have to be equal to the element type of this ArraySeq. A primitive
* ArraySeq can be backed by an array of boxed values and a reference ArraySeq can be backed by an array of a supertype
Expand Down
6 changes: 3 additions & 3 deletions scala2-library-cc/src/scala/collection/immutable/Map.scala
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ object Map extends MapFactory[Map] {
override protected def nextResult(k: K, v: V): V = v
}

private abstract class Map2Iterator[A] extends AbstractIterator[A], Pure {
private abstract class Map2Iterator[A] extends AbstractIterator[A], caps.Pure {
private[this] var i = 0
override def hasNext: Boolean = i < 2
override def next(): A = {
Expand Down Expand Up @@ -417,7 +417,7 @@ object Map extends MapFactory[Map] {
override protected def nextResult(k: K, v: V): V = v
}

private abstract class Map3Iterator[A] extends AbstractIterator[A], Pure {
private abstract class Map3Iterator[A] extends AbstractIterator[A], caps.Pure {
private[this] var i = 0
override def hasNext: Boolean = i < 3
override def next(): A = {
Expand Down Expand Up @@ -537,7 +537,7 @@ object Map extends MapFactory[Map] {
override protected def nextResult(k: K, v: V): V = v
}

private abstract class Map4Iterator[A] extends AbstractIterator[A], Pure {
private abstract class Map4Iterator[A] extends AbstractIterator[A], caps.Pure {
private[this] var i = 0
override def hasNext: Boolean = i < 4
override def next(): A = {
Expand Down
2 changes: 1 addition & 1 deletion scala2-library-cc/src/scala/collection/immutable/Set.scala
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ object Set extends IterableFactory[Set] {
private[collection] def emptyInstance: Set[Any] = EmptySet

@SerialVersionUID(3L)
private abstract class SetNIterator[A](n: Int) extends AbstractIterator[A], Serializable, Pure {
private abstract class SetNIterator[A](n: Int) extends AbstractIterator[A], Serializable, caps.Pure {
private[this] var current = 0
private[this] var remainder = n
override def knownSize: Int = remainder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import language.experimental.captureChecking
final class WrappedString(private val self: String) extends AbstractSeq[Char] with IndexedSeq[Char]
with IndexedSeqOps[Char, IndexedSeq, WrappedString]
with Serializable
with Pure {
with caps.Pure {

def apply(i: Int): Char = self.charAt(i)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ object ArrayBuffer extends StrictOptimizedSeqFactory[ArrayBuffer] {

// TODO: use `CheckedIndexedSeqView.Id` once we can change the return type of `ArrayBuffer#view`
final class ArrayBufferView[A] private[mutable](underlying: ArrayBuffer[A], mutationCount: () -> Int)
extends AbstractIndexedSeqView[A], Pure {
extends AbstractIndexedSeqView[A], caps.Pure {
/* Removed since it poses problems for capture checking
@deprecated("never intended to be public; call ArrayBuffer#view instead", since = "2.13.7")
def this(array: Array[AnyRef], length: Int) = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ sealed abstract class ArraySeq[T]
with IndexedSeqOps[T, ArraySeq, ArraySeq[T]]
with StrictOptimizedSeqOps[T, ArraySeq, ArraySeq[T]]
with Serializable
with Pure {
with caps.Pure {

override def iterableFactory: scala.collection.SeqFactory[ArraySeq] = ArraySeq.untagged

Expand Down
2 changes: 1 addition & 1 deletion scala2-library-cc/src/scala/collection/mutable/Map.scala
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ trait MapOps[K, V, +CC[X, Y] <: MapOps[X, Y, CC, _], +C <: MapOps[K, V, CC, C]]
with Builder[(K, V), C]
with Growable[(K, V)]
with Shrinkable[K]
with Pure {
with caps.Pure {

def result(): C = coll

Expand Down
4 changes: 2 additions & 2 deletions tests/neg-custom-args/captures/leaked-curried-shared.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ trait Box:

def main(): Unit =
val leaked = withCap: (io: Cap) =>
class Fuzz extends Box, Pure:
class Fuzz extends Box, caps.Pure:
self =>
val get: () ->{} () ->{io} Cap =
() => () => io // error
class Foo extends Box, Pure:
class Foo extends Box, caps.Pure:
val get: () ->{} () ->{io} Cap =
() => () => io // error
new Foo
Expand Down
4 changes: 2 additions & 2 deletions tests/neg-custom-args/captures/leaked-curried.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ trait Box:

def main(): Unit =
val leaked = withCap: (io: Cap^) =>
class Fuzz extends Box, Pure:
class Fuzz extends Box, caps.Pure:
self =>
val get: () ->{} () ->{io} Cap^ = // error
() => () => io // error
class Foo extends Box, Pure:
class Foo extends Box, caps.Pure:
val get: () ->{} () ->{io} Cap^ = // error
() => () => io // error
new Foo
Expand Down
4 changes: 2 additions & 2 deletions tests/neg-custom-args/captures/selftype.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@annotation.experimental class C(x: () => Unit) extends Pure // error
@annotation.experimental class C(x: () => Unit) extends caps.Pure // error

@annotation.experimental class D(@annotation.constructorOnly x: () => Unit) extends Pure // ok
@annotation.experimental class D(@annotation.constructorOnly x: () => Unit) extends caps.Pure // ok

6 changes: 3 additions & 3 deletions tests/pos-custom-args/captures/cc-experimental.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ package scala.runtime
import language.experimental.captureChecking

object test:
type T = Pure
type T = caps.Pure

class Foo extends Object, Pure:
val x: Pure = ???
class Foo extends Object, caps.Pure:
val x: caps.Pure = ???
def foo() = ()

2 changes: 1 addition & 1 deletion tests/pos-custom-args/captures/dependent-pure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import language.experimental.captureChecking
class ContextCls
type Context = ContextCls^

class Filtered(p: (c: Context) ?-> () ->{c} Boolean) extends Pure
class Filtered(p: (c: Context) ?-> () ->{c} Boolean) extends caps.Pure
2 changes: 1 addition & 1 deletion tests/pos-custom-args/captures/invariant-cc.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import language.experimental.captureChecking
import scala.annotation.unchecked.uncheckedVariance

trait IterableFactory[+CC[_]] extends Pure:
trait IterableFactory[+CC[_]] extends caps.Pure:

def fill[A](n: Int)(elem: => A): CC[A]^{elem} = ???
def fill[A](n1: Int, n2: Int)(elem: => A): CC[(CC[A]^{elem}) @uncheckedVariance]^{elem} =
Expand Down
6 changes: 3 additions & 3 deletions tests/pos-custom-args/captures/steppers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ trait Stepper[+A]
object Stepper:
trait EfficientSplit

sealed trait StepperShape[-T, S <: Stepper[_]^] extends Pure
sealed trait StepperShape[-T, S <: Stepper[_]^] extends caps.Pure

trait IterableOnce[+A] extends Any:
def stepper[S <: Stepper[_]^{this}](implicit shape: StepperShape[A, S]): S = ???

sealed abstract class ArraySeq[T] extends IterableOnce[T], Pure:
sealed abstract class ArraySeq[T] extends IterableOnce[T], caps.Pure:
def array: Array[_]

def sorted[B >: T](implicit ord: Ordering[B]): ArraySeq[T] =
Expand All @@ -20,6 +20,6 @@ object ArraySeq:

def make[T](x: Array[T]): ArraySeq[T] = ???

final class ofRef[T <: AnyRef](val array: Array[T]) extends ArraySeq[T], Pure:
final class ofRef[T <: AnyRef](val array: Array[T]) extends ArraySeq[T], caps.Pure:
override def stepper[S <: Stepper[_]](implicit shape: StepperShape[T, S]): S & Stepper.EfficientSplit = ???

4 changes: 2 additions & 2 deletions tests/run-custom-args/captures/minicheck.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import compiletime.uninitialized
import annotation.{experimental, tailrec, constructorOnly}
import collection.mutable

case class Symbol(name: String, initOwner: Symbol | Null) extends Pure:
case class Symbol(name: String, initOwner: Symbol | Null) extends caps.Pure:
def owner = initOwner.nn
private var myInfo: Type = uninitialized
def infoOrCompleter: Type = myInfo
Expand All @@ -27,7 +27,7 @@ object NoSymbol extends Symbol("", null):
override def exists: Boolean = false
override def orElse(alt: => Symbol): Symbol = alt

abstract class Type extends Pure:
abstract class Type extends caps.Pure:
def exists = true
def show: String
case class IntType()(using @constructorOnly c: Context) extends Type:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ val experimentalDefinitionInLibrary = Set(
"scala.annotation.retains",
"scala.annotation.retainsByName",
"scala.annotation.retainsCap",
"scala.Pure",
"scala.caps.CapSet",
"scala.caps.Contains",
"scala.caps.Contains$",
Expand Down
Loading