Skip to content

Commit 401d7e6

Browse files
committed
Rename phase and fix some tests
1 parent 0b2480c commit 401d7e6

20 files changed

+60
-55
lines changed

effekt/jvm/src/test/scala/effekt/ParserTests.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,10 +338,9 @@ class ParserTests extends munit.FunSuite {
338338

339339
test("Boxing") {
340340
parseExpr("box f")
341-
parseExpr("unbox f")
342341
assertEqualModuloSpans(
343-
parseExpr("unbox box f"),
344-
parseExpr("unbox (box f)")
342+
parseExpr("box f"),
343+
parseExpr("(box f)")
345344
)
346345
assertNotEqualModuloSpans(
347346
parseExpr("box { 42 }"),

effekt/shared/src/main/scala/effekt/Compiler.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import effekt.core.Transformer
66
import effekt.namer.Namer
77
import effekt.source.{AnnotateCaptures, ExplicitCapabilities, ModuleDecl, ResolveExternDefs}
88
import effekt.symbols.Module
9-
import effekt.typer.{BoxUnboxInference, Typer, Wellformedness}
9+
import effekt.typer.{UnboxInference, Typer, Wellformedness}
1010
import effekt.util.messages.{CompilerPanic, FatalPhaseError}
1111
import effekt.util.{SourceTask, Task, VirtualSource, paths}
1212
import kiama.output.PrettyPrinterTypes.Document
@@ -207,7 +207,7 @@ trait Compiler[Executable] {
207207
* Explicit box transformation
208208
* [[NameResolved]] --> [[NameResolved]]
209209
*/
210-
BoxUnboxInference andThen
210+
UnboxInference andThen
211211
/**
212212
* Wellformedness checks (exhaustivity, non-escape)
213213
* [[Typechecked]] --> [[Typechecked]]

effekt/shared/src/main/scala/effekt/typer/BoxUnboxInference.scala renamed to effekt/shared/src/main/scala/effekt/typer/UnboxInference.scala

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ package typer
44
import effekt.context.{ Annotations, Context, ContextOps }
55
import effekt.symbols.*
66

7-
object BoxUnboxInference extends Phase[NameResolved, NameResolved] {
7+
object UnboxInference extends Phase[NameResolved, NameResolved] {
88

99
import source._
1010

11-
val phaseName = "box-unbox"
11+
val phaseName = "unbox"
1212

1313
def run(input: NameResolved)(using Context) = {
1414
val transformedTree = Context.timed(phaseName, input.source.name) { rewrite(input.tree) }
@@ -52,12 +52,18 @@ object BoxUnboxInference extends Phase[NameResolved, NameResolved] {
5252
case v: Var => v.definition match {
5353
// TODO maybe we should synthesize a call to get here already?
5454
case sym: (ValueSymbol | symbols.RefBinder) => v
55-
case sym: BlockSymbol => v //Box(Maybe.None(v.span.emptyAfter), v, v.span.synthesized).inheritPosition(v)
55+
case sym: BlockSymbol =>
56+
C.error(pp"Computation ${sym} is used in an expression position, which requires boxing (e.g. `box ${sym}`")
57+
v
5658
}
5759

58-
case n: New => rewriteAsBlock(n) // Box(Maybe.None(n.span.emptyAfter), rewriteAsBlock(n), n.span.synthesized).inheritPosition(n)
60+
case n: New =>
61+
C.error(pp"Creating an instance in an expression requires boxing (e.g. `box new ${n.impl.id}[...] { ... }`")
62+
rewriteAsBlock(n)
5963

60-
case b: BlockLiteral => rewriteAsBlock(b) // Box(Maybe.None(b.span.emptyAfter), rewriteAsBlock(b), b.span.synthesized).inheritPosition(b)
64+
case b: BlockLiteral =>
65+
C.error(pp"Function literals in expression position require boxing (e.g. `box { (${b.vparams.map(_.id).mkString(", ")}) => ... `")
66+
rewriteAsBlock(b)
6167

6268
case l: Literal => l
6369

examples/neg/lambdas/closure.effekt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
def twice { someBlock: () => Unit / {} } = {
2-
fun() { someBlock(); someBlock() }
2+
box { someBlock(); someBlock() }
33
}
44
effect Yield(): Unit
55
def main() = {
66
val f = try { // @Yield =>
7-
val g = fun(){ do Yield() }
7+
val g = box { do Yield() }
88
twice {
99
def unboxed() = { g() };
1010
unboxed()// (@Yield)

examples/neg/lambdas/inference.effekt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ def main() = {
55
def hof1(f: (Int) => String at {}): Unit = ()
66
def hof2(f: ((Int) => Bool at {}) => String at {}): Unit = ()
77

8-
hof2(fun (f: (Int) => Bool at {}) {
8+
hof2(box { (f: (Int) => Bool at {}) =>
99
f(3);
1010
""
1111
})
1212

13-
hof2(fun(f: (Int) => Unit at {}) { "" })
14-
hof1(fun(b: Bool) { () })
15-
}
13+
hof2(box { (f: (Int) => Unit at {}) => "" })
14+
hof1(box { (b: Bool) => () })
15+
}

examples/pos/bidirectional/scheduler.effekt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ def scheduler { prog: => Unit / Process } = region this {
1818
}
1919
try { prog() } with Process {
2020
def yield() = {
21-
queue = queue.pushFront(fun() { resume(()) })
21+
queue = queue.pushFront(box { resume(()) })
2222
}
2323
def fork() /* {{() => Unit} => Unit} => Unit */ = {
2424
queue = queue
25-
.pushFront(fun() { resume { {prog: () => Unit} => prog() /* FIX do abort() */ } })
26-
.pushFront(fun() { resume { {prog: () => Unit} => () } })
25+
.pushFront(box { resume { {prog: () => Unit} => prog() /* FIX do abort() */ } })
26+
.pushFront(box { resume { {prog: () => Unit} => () } })
2727
}
2828
def exit() /* Nothing => Unit */ = ()
2929
}
@@ -51,4 +51,4 @@ def main() = {
5151
do yield()
5252
println(6)
5353
}
54-
}
54+
}

examples/pos/capture/defdef.effekt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ def myModule { eff : Eff } = region this {
33

44
def outer = this;
55

6-
val e1 = fun() { eff.use(); () };
6+
val e1 = box { eff.use(); () };
77
def x = e1;
88

99
def test1() = x();
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
type NumberThunk = () => Int at {}
22
def force(t: NumberThunk): Int = t()
3-
def init(n: Int): NumberThunk = fun() { n }
4-
def test(): NumberThunk = fun() {
3+
def init(n: Int): NumberThunk = box { n }
4+
def test(): NumberThunk = box {
55
val num: Int = (init(42))()
66
num
77
}
88

9-
def main() = println(test()())
9+
def main() = println(test()())

examples/pos/capture/optimizing_unbox.effekt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ effect Yield(): Unit
33
def main() = try {
44

55
val make = {
6-
val f = fun() { y.Yield() }
6+
val f = box { y.Yield() }
77
f
88
}
99
// here we had the problem that we perform the direct-style "run-optimization", even though make obviously has capture set {y}
1010
val res = make();
1111
println(res)
1212

13-
} with y: Yield { () }
13+
} with y: Yield { () }

examples/pos/capture/selfregion.effekt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
def bar {r: Region} = {
22
var x in r = 42
3-
fun() { x = x + 1; x }
3+
box { x = x + 1; x }
44
}
55

66
def ex1() = region this {
@@ -57,4 +57,4 @@ def main() = {
5757
ex4();
5858
ex5();
5959
ex6()
60-
}
60+
}

0 commit comments

Comments
 (0)