Skip to content

Commit c07f6fa

Browse files
committed
Don't allow instantiated ResultCaps to subsume anything
We map them to fresh caps but their hidden sets should not accept new elements.
1 parent 20c62f8 commit c07f6fa

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,13 @@ object Capabilities:
10331033
override def mapCapability(c: Capability, deep: Boolean) = c match
10341034
case c @ ResultCap(binder) =>
10351035
if localBinders.contains(binder) then c // keep bound references
1036-
else seen.getOrElseUpdate(c, FreshCap(origin)) // map free references to FreshCap
1036+
else
1037+
// Create a fresh skolem that does not subsume anything
1038+
def freshSkolem =
1039+
val c = FreshCap(origin)
1040+
c.hiddenSet.markSolved(provisional = false)
1041+
c
1042+
seen.getOrElseUpdate(c, freshSkolem) // map free references to FreshCap
10371043
case _ => super.mapCapability(c, deep)
10381044
end subst
10391045

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,6 +1206,7 @@ object CaptureSet:
12061206
if alias ne this then alias.add(elem)
12071207
else
12081208
def addToElems() =
1209+
assert(!isConst)
12091210
includeElem(elem)
12101211
deps.foreach: dep =>
12111212
assert(dep != this)
@@ -1378,8 +1379,10 @@ object CaptureSet:
13781379
* but the special state VarState.Separate overrides this.
13791380
*/
13801381
def addHidden(hidden: HiddenSet, elem: Capability)(using Context): Boolean =
1381-
hidden.add(elem)(using ctx, this)
1382-
true
1382+
if hidden.isConst then false
1383+
else
1384+
hidden.add(elem)(using ctx, this)
1385+
true
13831386

13841387
/** If root1 and root2 belong to the same binder but have different originalBinders
13851388
* it means that one of the roots was mapped to the binder of the other by a
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class B
2+
3+
def Test(consume b1: B^, consume b2: B^) =
4+
def f(): B^ = B()
5+
var x: B^ = f()
6+
x = b1 // error separation but should be OK, see #23889
7+
var y = f()
8+
y = b2 // error
9+

0 commit comments

Comments
 (0)