Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
odersky committed Sep 4, 2023
1 parent e8b8491 commit 9cb9206
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
2 changes: 0 additions & 2 deletions compiler/src/dotty/tools/dotc/cc/CaptureRoot.scala
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,5 @@ object CaptureRoot:
end isEnclosingRoot
end CaptureRoot

//class LevelError(val rvar: RootVar, val newBound: Symbol, val isUpper: Boolean) extends Exception



11 changes: 6 additions & 5 deletions compiler/src/dotty/tools/dotc/cc/Setup.scala
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,15 @@ extends tpd.TreeTraverser:
mapOverFollowingAliases(t)

private def transformExplicitType(tp: Type, boxed: Boolean, mapRoots: Boolean)(using Context): Type =
val tp1 = expandAliases(if boxed then box(tp) else tp)
val tp1 = expandAliases(tp)
val tp2 =
if mapRoots
then cc.mapRoots(defn.captureRoot.termRef, ctx.owner.localRoot.termRef)(tp1)
.showing(i"map roots $tp1, ${tp1.getClass} == $result", capt)
else tp1
if tp2 ne tp then capt.println(i"expanded: $tp --> $tp2")
tp2
val tp3 = if boxed then box(tp2) else tp2
if tp3 ne tp then capt.println(i"expanded: $tp --> $tp3")
tp3

/** Transform type of type tree, and remember the transformed type as the type the tree */
private def transformTT(tree: TypeTree, boxed: Boolean, exact: Boolean, mapRoots: Boolean)(using Context): Unit =
Expand Down Expand Up @@ -463,8 +464,8 @@ extends tpd.TreeTraverser:
newInfo
else new LazyType:
def complete(denot: SymDenotation)(using Context) =
// infos other methods are determined from their definitions which
// are checked on depand
// infos of other methods are determined from their definitions which
// are checked on demand
denot.info = newInfo
recheckDef(tree, sym))
else updateOwner(sym)
Expand Down
6 changes: 4 additions & 2 deletions compiler/src/dotty/tools/dotc/util/SimpleIdentitySet.scala
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,10 @@ object SimpleIdentitySet {
val y0 = f(x0.asInstanceOf[Elem])
val y1 = f(x1.asInstanceOf[Elem])
val y2 = f(x2.asInstanceOf[Elem])
if (y0 ne y1) && (y0 ne y2) && (y1 ne y2) then Set3(y0, y1, y2)
else super.map(f)
if y1 eq y0 then
if y2 eq y0 then Set1(y0) else Set2(y0, y2)
else if (y2 eq y0) || (y2 eq y1) then Set2(y0, y1)
else Set3(y0, y1, y2)
def /: [A, E >: Elem <: AnyRef](z: A)(f: (A, E) => A): A =
f(f(f(z, x0.asInstanceOf[E]), x1.asInstanceOf[E]), x2.asInstanceOf[E])
def toList = x0.asInstanceOf[Elem] :: x1.asInstanceOf[Elem] :: x2.asInstanceOf[Elem] :: Nil
Expand Down
6 changes: 6 additions & 0 deletions tests/neg-custom-args/captures/box-unsoundness.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@annotation.capability class CanIO { def use(): Unit = () }
def use[X](x: X): (op: X -> Unit) -> Unit = op => op(x)
def test(io: CanIO): Unit =
val f = use[CanIO](io)
val g: () -> Unit = () => f(x => x.use()) // error
// was UNSOUND: g uses the capability io but has an empty capture set

0 comments on commit 9cb9206

Please sign in to comment.