Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix capability passing for extern definitions #633

Merged
merged 3 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import effekt.context.{ Annotations, Context, ContextOps }
import effekt.symbols.*
import effekt.context.assertions.*
import effekt.source.Tree.Rewrite
import effekt.source.ExternBody.EffektExternBody
import effekt.source.ExternBody.StringExternBody


/**
Expand Down Expand Up @@ -34,6 +36,20 @@ object ExplicitCapabilities extends Phase[Typechecked, Typechecked], Rewrite {
val capabilities = Context.annotation(Annotations.BoundCapabilities, f)
val capParams = capabilities.map(definitionFor)
f.copy(bparams = bps ++ capParams, body = rewrite(body))
case extDef @ ExternDef(capture, id, tparams, vparams, bparams, ret, bodies) =>
val rewrittenBodies = bodies.map {
case b @ source.ExternBody.StringExternBody(ff, body) =>
val rewrittenTemplate =
body.copy(
args = body.args.map { rewrite }
)
b.copy(template = rewrittenTemplate)
case b @ source.ExternBody.EffektExternBody(ff, body) =>
val rewrittenBody = rewrite(body)
b.copy(body = rewrittenBody)
case u: source.ExternBody.Unsupported => u
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd factor this into a separate function rewrite(ExternBody).

extDef.copy(bodies = rewrittenBodies)
}

override def expr(using Context) = {
Expand Down
1 change: 1 addition & 0 deletions examples/pos/extern-cap-passing.check
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
typechecks
7 changes: 7 additions & 0 deletions examples/pos/extern-cap-passing.effekt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
effect IOException(msg: String): Nothing
extern io def three: Nothing =
js "${box { (msg: String) => do IOException(msg) }}('oops')}"

def main() = {
println("typechecks")
}