-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Create boxed environments only for references and function values #16136
Conversation
521206f
to
94fde59
Compare
Note on limitation: ideally we should allow the following code snippet to typecheck: val op1: {io} Unit -> Unit = (x: Unit) => // error // limitation
expect[{*} Cap] {
io.use()
fs
} Since |
94fde59
to
1bbc604
Compare
Do we still need this one after #16141 is merged? If yes it needs to be rebased. |
The result should capture {f}, since the expression `box(f(x))` should be translated as: let z = f(x) in let y = □ z in box(y) Denoting the above term as `t`, we can see that `f ∈ cv(t)`.
1bbc604
to
e3829f5
Compare
9e20cf2
to
8bab429
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, it's better to push PRs to dotty-staging. Then they are easier to find, and we can collaborate on them.
case _ => | ||
false | ||
|
||
private def isRefTree: Boolean = tree match |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just use isInstanceOf[RefTree]
instead, that avoids having to define a new function.
@@ -507,14 +507,29 @@ class CheckCaptures extends Recheck, SymTransformer: | |||
recheckFinish(result, arg, pt) | |||
*/ | |||
|
|||
/** If expected type `pt` is boxed, don't propagate free variables. | |||
extension (tree: Tree) | |||
private def isFunctionLiteral(using Context): Boolean = tree match |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TreeInfo has a closure
extractor, which could be used instead of defining a new function here.
* Otherwise, if the result type is boxed, simulate an unboxing by | ||
* adding all references in the boxed capture set to the current environment. | ||
*/ | ||
override def recheck(tree: Tree, pt: Type = WildcardType)(using Context): Type = | ||
if tree.isTerm && pt.isBoxedCapturing then | ||
val saved = curEnv | ||
curEnv = Env(curEnv.owner, nestedInOwner = false, CaptureSet.Var(), isBoxed = true, curEnv) | ||
if tree.isRefTree || tree.isFunctionLiteral then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this could be:
tree match
case _: RefTree | closure(_, _, _) => ...
Thanks for your comment! I have refactored the code to use pattern match and the extractors in
But what we want to match here is only function values. Regarding dotty-staging, I have not obtained the write access to it yet. Could you possibly grant me the access? I would create all future PRs from the staging repo. :) |
Hi Yichen, I just added you to dotty-staging.
- Martin
…On Sun, Oct 16, 2022 at 8:07 PM Yichen Xu ***@***.***> wrote:
@Linyxus <https://github.com/Linyxus> requested your review on: #16136
<#16136> Create boxed environments
only for references and function values.
—
Reply to this email directly, view it on GitHub
<#16136 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAGCKVRA5JY4IFMM3MXESDLWDQ76FANCNFSM6AAAAAAQ3TIBXA>
.
You are receiving this because your review was requested.Message ID:
***@***.***>
--
Martin Odersky
Professor, Programming Methods Group (LAMP)
Faculty IC, EPFL
Station 14, Lausanne, Switzerland
|
Thanks! I've joined dotty-staging and will create future PRs from there. |
Fixes #16114.
According to the comment in the issue, only create boxed environment when the rechecked tree is a reference or a function value.
This PR also fixes a testcase, as explained in this commit.