Skip to content

Commit 0aa6794

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 7cbadac commit 0aa6794

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
@@ -1031,7 +1031,13 @@ object Capabilities:
10311031
override def mapCapability(c: Capability, deep: Boolean) = c match
10321032
case c @ ResultCap(binder) =>
10331033
if localBinders.contains(binder) then c // keep bound references
1034-
else seen.getOrElseUpdate(c, FreshCap(origin)) // map free references to FreshCap
1034+
else
1035+
// Create a fresh skolem that does not subsume anything
1036+
def freshSkolem =
1037+
val c = FreshCap(origin)
1038+
c.hiddenSet.markSolved(provisional = false)
1039+
c
1040+
seen.getOrElseUpdate(c, freshSkolem) // map free references to FreshCap
10351041
case _ => super.mapCapability(c, deep)
10361042
end subst
10371043

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)