Skip to content

Commit fc45c25

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 51d69e8 commit fc45c25

Some content is hidden

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

45 files changed

+73
-68
lines changed

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

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

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

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

20532057
// ----- Initialization ---------------------------------------------------
20542058

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 =>

project/MiMaFilters.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ object MiMaFilters {
88
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.caps.cap"),
99
ProblemFilters.exclude[MissingClassProblem]("scala.caps$Sealed"),
1010
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.CanEqual.canEqualMap"),
11-
ProblemFilters.exclude[MissingClassProblem]("scala.caps$Pure"),
11+
ProblemFilters.exclude[MissingClassProblem]("scala.Pure"),
1212
ProblemFilters.exclude[MissingClassProblem]("scala.caps$unsafe$"),
1313
ProblemFilters.exclude[MissingClassProblem]("scala.annotation.unchecked.uncheckedCaptures"),
1414
ProblemFilters.exclude[MissingFieldProblem]("scala.runtime.stdLibPatches.language.3.3-migration"),
@@ -36,7 +36,6 @@ object MiMaFilters {
3636
// Added java.io.Serializable as LazyValControlState supertype
3737
ProblemFilters.exclude[MissingTypesProblem]("scala.runtime.LazyVals$LazyValControlState"),
3838
ProblemFilters.exclude[MissingTypesProblem]("scala.runtime.LazyVals$Waiting"),
39-
4039
)
4140
val TastyCore: Seq[ProblemFilter] = Seq(
4241
ProblemFilters.exclude[DirectMissingMethodProblem]("dotty.tools.tasty.TastyBuffer.reset"),
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 = _

0 commit comments

Comments
 (0)