Skip to content

Commit 8e033af

Browse files
committed
Rename caps.immutable to caps.freeze
1 parent 93a322b commit 8e033af

File tree

9 files changed

+35
-50
lines changed

9 files changed

+35
-50
lines changed

compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -800,8 +800,8 @@ class CheckCaptures extends Recheck, SymTransformer:
800800
capt.println(i"rechecking unsafeAssumePure of $arg with $pt: $argType")
801801
super.recheckFinish(argType, tree, pt)
802802

803-
/** Recheck `caps.immutable(...)` */
804-
def applyImmutable(tree: Apply)(using Context): Type =
803+
/** Recheck `caps.freeze(...)` */
804+
def applyFreeze(tree: Apply)(using Context): Type =
805805
val arg :: Nil = tree.args: @unchecked
806806
def imm = new TypeMap:
807807
def apply(t: Type) = t match
@@ -816,7 +816,7 @@ class CheckCaptures extends Recheck, SymTransformer:
816816
case defn.ContextFunctionType(Nil, resType) => imm(resType)
817817

818818
/** Recheck applications, with special handling of unsafeAssumePure,
819-
* unsafeDiscardUses, and immutable.
819+
* unsafeDiscardUses, and freeze.
820820
* More work is done in `recheckApplication`, `recheckArg` and `instantiate` below.
821821
*/
822822
override def recheckApply(tree: Apply, pt: Type)(using Context): Type =
@@ -826,8 +826,8 @@ class CheckCaptures extends Recheck, SymTransformer:
826826
else if meth == defn.Caps_unsafeDiscardUses then
827827
val arg :: Nil = tree.args: @unchecked
828828
withDiscardedUses(recheck(arg, pt))
829-
else if meth == defn.Caps_immutable then
830-
applyImmutable(tree)
829+
else if meth == defn.Caps_freeze then
830+
applyFreeze(tree)
831831
else
832832
val res = super.recheckApply(tree, pt)
833833
includeCallCaptures(meth, res, tree)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,7 @@ class Definitions {
10311031
@tu lazy val Caps_ContainsTrait: TypeSymbol = CapsModule.requiredType("Contains")
10321032
@tu lazy val Caps_ContainsModule: Symbol = requiredModule("scala.caps.Contains")
10331033
@tu lazy val Caps_containsImpl: TermSymbol = Caps_ContainsModule.requiredMethod("containsImpl")
1034-
@tu lazy val Caps_immutable: TermSymbol = CapsModule.requiredMethod("immutable")
1034+
@tu lazy val Caps_freeze: TermSymbol = CapsModule.requiredMethod("freeze")
10351035

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

@@ -2101,7 +2101,7 @@ class Definitions {
21012101
RequiresCapabilityAnnot,
21022102
captureRoot, Caps_CapSet, Caps_ContainsTrait, Caps_ContainsModule, Caps_ContainsModule.moduleClass,
21032103
ConsumeAnnot, UseAnnot, ReserveAnnot,
2104-
CapsUnsafeModule, CapsUnsafeModule.moduleClass, Caps_immutable,
2104+
CapsUnsafeModule, CapsUnsafeModule.moduleClass, Caps_freeze,
21052105
CapsInternalModule, CapsInternalModule.moduleClass,
21062106
RetainsAnnot, RetainsCapAnnot, RetainsByNameAnnot)
21072107

library/src/scala/caps/package.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ sealed trait Exists extends Capability
137137
* result of pure operation `op`, turning them into immutable types.
138138
*/
139139
@experimental
140-
def immutable[T](op: -> T): T = op
140+
def freeze[T](op: -> T): T = op
141141

142142
@experimental
143143
object internal:
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/freeze.scala:13:17 ---------------------------------------
2+
13 | val b = freeze(a) // error
3+
| ^
4+
| Found: () ?->{a} Arr[String]^{a}
5+
| Required: () ?-> <?>
6+
|
7+
| Note that capability a is not included in capture set {}.
8+
|
9+
| longer explanation available when compiling with `-explain`
10+
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/freeze.scala:22:4 ----------------------------------------
11+
21 | freeze:
12+
22 | mkExclusive() // error
13+
| ^
14+
| Capability cap outlives its scope: it leaks into outer capture set 's1 of method test3.
15+
| The leakage occurred when trying to match the following types:
16+
|
17+
| Found: EX^{cap}
18+
| Required: EX^'s1
19+
|
20+
| where: cap is a root capability associated with the result type of (): EX^
21+
|
22+
| longer explanation available when compiling with `-explain`

tests/neg-custom-args/captures/immutable.scala renamed to tests/neg-custom-args/captures/freeze.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ def test2 =
1010
val a = Arr[String](2)
1111
a(0) = "1"
1212
a(1) = "2"
13-
val b = immutable(a) // error
13+
val b = freeze(a) // error
1414
b
1515

1616
class EX
1717

1818
def mkExclusive(): EX^ = ???
1919

2020
def test3 =
21-
immutable:
21+
freeze:
2222
mkExclusive() // error
2323

tests/neg-custom-args/captures/immutable.check

Lines changed: 0 additions & 22 deletions
This file was deleted.

tests/pending/pos-custom-args/captures/immutable-cycle.scala renamed to tests/pending/pos-custom-args/captures/freeze-cycle.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class Node(val payload: Int) extends Mutable:
77
type INode = Node^{}
88

99
def cycle(x: Int, y: Int): (INode, INode) =
10-
immutable:
10+
freeze:
1111
val a = Node(x)
1212
val b = Node(y)
1313
a.next = b

tests/pos-custom-args/captures/immutable.scala renamed to tests/pos-custom-args/captures/freeze.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ class Arr[T: reflect.ClassTag](len: Int) extends Mutable:
88

99

1010
def test2 =
11-
val a = immutable:
11+
val a = freeze:
1212
val a = Arr[String](2)
1313
a(0) = "1"
1414
a(1) = "2"
1515
a
1616
val _: Arr[String]^{} = a
1717

18-
val a2 = immutable:
18+
val a2 = freeze:
1919
val a = Arr[String](2)
2020
val b = Arr[String](2)
2121
a(0) = "1"

tests/pos-custom-args/captures/immutable-cycle.scala

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)