Skip to content

Commit 264cf2e

Browse files
committed
Make Pure a class in scala that gets erased
The Pure marker trait is now a class in the scala package that gets erased to Object.
1 parent 996721f commit 264cf2e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+72
-66
lines changed

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,8 @@ class Definitions {
976976
@tu lazy val Caps_unsafeBoxFunArg: Symbol = CapsUnsafeModule.requiredMethod("unsafeBoxFunArg")
977977
@tu lazy val Caps_SealedAnnot: ClassSymbol = requiredClass("scala.caps.Sealed")
978978

979+
@tu lazy val PureClass: Symbol = requiredClass("scala.Pure")
980+
979981
// Annotation base classes
980982
@tu lazy val AnnotationClass: ClassSymbol = requiredClass("scala.annotation.Annotation")
981983
@tu lazy val StaticAnnotationClass: ClassSymbol = requiredClass("scala.annotation.StaticAnnotation")
@@ -2041,15 +2043,17 @@ class Definitions {
20412043
def isValueSubClass(sym1: Symbol, sym2: Symbol): Boolean =
20422044
valueTypeEnc(sym2.asClass.name) % valueTypeEnc(sym1.asClass.name) == 0
20432045

2044-
@tu lazy val specialErasure: SimpleIdentityMap[Symbol, ClassSymbol] =
2045-
SimpleIdentityMap.empty[Symbol]
2046-
.updated(AnyClass, ObjectClass)
2047-
.updated(MatchableClass, ObjectClass)
2048-
.updated(AnyValClass, ObjectClass)
2049-
.updated(SingletonClass, ObjectClass)
2050-
.updated(TupleClass, ProductClass)
2051-
.updated(NonEmptyTupleClass, ProductClass)
2052-
.updated(PairClass, ObjectClass)
2046+
@tu lazy val specialErasure: collection.Map[Symbol, ClassSymbol] =
2047+
val m = mutable.Map[Symbol, ClassSymbol]()
2048+
m(AnyClass) = ObjectClass
2049+
m(MatchableClass) = ObjectClass
2050+
m(PureClass) = ObjectClass
2051+
m(AnyValClass) = ObjectClass
2052+
m(SingletonClass) = ObjectClass
2053+
m(TupleClass) = ProductClass
2054+
m(NonEmptyTupleClass) = ProductClass
2055+
m(PairClass) = ObjectClass
2056+
m
20532057

20542058
// ----- Initialization ---------------------------------------------------
20552059

library/src/scala/Pure.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package scala
2+
import annotation.experimental
3+
4+
/** A marker trait that declares that all inheriting classes are "pure" in the
5+
* sense that their values retain no capabilities including capabilities needed
6+
* to perform effects. This has formal meaning only under capture checking.
7+
*/
8+
@experimental trait Pure:
9+
this: Pure =>

library/src/scala/caps.scala

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,3 @@ import annotation.experimental
4040
*/
4141
@deprecated("The Sealed annotation should not be directly used in source code.\nUse the `sealed` modifier on type parameters instead.")
4242
class Sealed extends annotation.Annotation
43-
44-
/** Mixing in this trait forces a trait or class to be pure, i.e.
45-
* have no capabilities retained in its self type.
46-
*/
47-
trait Pure:
48-
this: Pure =>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@annotation.experimental class C(x: () => Unit) extends caps.Pure // error
1+
@annotation.experimental class C(x: () => Unit) extends Pure // error
22

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

tests/pos-with-compiler-cc/backend/jvm/BCodeHelpers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
209209
}
210210
} // end of trait BCPickles
211211

212-
trait BCInnerClassGen extends caps.Pure {
212+
trait BCInnerClassGen extends Pure {
213213

214214
def debugLevel = 3 // 0 -> no debug info; 1-> filename; 2-> lines; 3-> varnames
215215

tests/pos-with-compiler-cc/backend/jvm/BCodeIdiomatic.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import dotty.tools.dotc.report
1717
* @version 1.0
1818
*
1919
*/
20-
trait BCodeIdiomatic extends caps.Pure {
20+
trait BCodeIdiomatic extends Pure {
2121
val int: DottyBackendInterface
2222
final lazy val bTypes = new BTypesFromSymbols[int.type](int)
2323

tests/pos-with-compiler-cc/backend/jvm/BTypes.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import scala.tools.asm
1414
* This representation is immutable and independent of the compiler data structures, hence it can
1515
* be queried by concurrent threads.
1616
*/
17-
abstract class BTypes extends caps.Pure {
17+
abstract class BTypes extends Pure {
1818

1919
val int: DottyBackendInterface
2020
import int.given
@@ -47,7 +47,7 @@ abstract class BTypes extends caps.Pure {
4747
* A BType is either a primitve type, a ClassBType, an ArrayBType of one of these, or a MethodType
4848
* referring to BTypes.
4949
*/
50-
/*sealed*/ trait BType extends caps.Pure { // Not sealed for now due to SI-8546
50+
/*sealed*/ trait BType extends Pure { // Not sealed for now due to SI-8546
5151
final override def toString: String = this match {
5252
case UNIT => "V"
5353
case BOOL => "Z"

tests/pos-with-compiler-cc/backend/sjs/ScopedVar.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package dotty.tools.backend.sjs
22

3-
class ScopedVar[A](init: A) extends caps.Pure {
3+
class ScopedVar[A](init: A) extends Pure {
44
import ScopedVar.Assignment
55

66
private[ScopedVar] var value = init

tests/pos-with-compiler-cc/dotc/ast/Positioned.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import annotation.internal.sharable
1515

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

2121
private var mySpan: Span = _

tests/pos-with-compiler-cc/dotc/cc/CaptureSet.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import annotation.retains
3939
* if the mapped function is either a bijection or if it is idempotent
4040
* on capture references (c.f. doc comment on `map` below).
4141
*/
42-
sealed abstract class CaptureSet extends Showable, caps.Pure:
42+
sealed abstract class CaptureSet extends Showable, Pure:
4343
import CaptureSet.*
4444

4545
/** The elements of this capture set. For capture variables,

0 commit comments

Comments
 (0)