-
Notifications
You must be signed in to change notification settings - Fork 26
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
Extended forward() for using in closure #805
Extended forward() for using in closure #805
Conversation
|
||
active class Foo | ||
def foo(arg : Fut[int]) : int | ||
forward(arg ~~> fun(x : int) : int => forward((new Base) ! base())) |
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.
Why double forward in all the tests?
Here is the basis for the key test case:
This is the function that asynchronously flattens a future of futures. Could be used like:
Make it so. |
Here is another test case to consider (it can probably be simplified):
The point of this is that the return type of the method within which A similar example should be devised for |
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.
Some small comments.
src/back/CodeGen/Expr.hs
Outdated
let bound = map (ID.qLocal . A.pname) eparams | ||
freeVars = filter (ID.isLocalQName . fst) $ | ||
Util.freeVariables bound body | ||
isIdClosure = not . null $ filter (isIdFun . A.pname) eparams |
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.
Why are you checking for the identity function?
This suggests to me that the design is broken somewhere.
The following case does not compile (when used in a larger context):
Error is:
But this is a forward inside a closure inside a future chain, which is valid. |
If I modify
I get the error
which suggests that something is wrong in the type checker. |
It seems that I get a similar error if I try to use For instance,
will succeed, but if I change the
results in error:
|
261ea83
to
84b763f
Compare
219fc4b
to
d663d81
Compare
@supercooldave I have fixed the issues and included your test cases. This PR is ready for review, IMO. |
I'll have a look. |
Have you addressed issue #816? |
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.
A first batch of comments.
src/back/CodeGen/Expr.hs
Outdated
@@ -1019,26 +1020,38 @@ instance Translatable A.Expr (State Ctx.Context (CCode Lval, CCode Stat)) where | |||
callTheMethodOneway | |||
ntarget targetType name args typeArguments Ty.unitType | |||
|
|||
let nullCheck = targetNullCheck ntarget target name emeta "." | |||
let nullCheck = targetNullCheck ntarget target name emeta "!" |
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.
Why is this changed from "." to "!"?
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.
"!" is used for my own test, but I forgot to recover before pushing the code. It has been fixed in the next commit.
@@ -0,0 +1,58 @@ | |||
-- Error related to unknown _enc_type_t in method produce() |
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.
clean up the comments in these files = remove them.
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.
This test is irrelevant to the forward. It's accidentally committed.
"This message should never be appeared when calling method green()" | ||
end | ||
end | ||
-- active class Pepper |
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.
Remove commented out code, please.
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.
This test is for debugging, be removed. Thanks Dave.
The following test cases don't have a
|
The follow code should print 10 three times, but it prints 10 only once.
|
d663d81
to
d99c78e
Compare
@supercooldave : The |
The fix of issue #816 (Forward-Return) has been included in this PR. |
Are you saying that you won't allow the following?
The test seems to suggest that this is prohibited. If you look at the semantics of
Now the semantics are that the future associated with the outer |
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.
Forward inside chaining or inside async
should always work, regardless of where the forwarding or chaining occurs.
@@ -0,0 +1,26 @@ | |||
fun join[t](ff : Fut[Fut[t]]) : Fut[t] | |||
ff ~~> (fun (f : Fut[t]) : t => forward(f)) | |||
end |
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.
This should be allowed.
|
||
fun intJoin(ff : Fut[Fut[int]]) : Fut[int] | ||
ff ~~> (fun (f : Fut[int]) : int => forward(f)) | ||
end |
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.
This should be allowed.
It's unclear whether this will be finished. |
Does this mean that you will maintain |
In the absence of other maintainers, yes. |
I am interested in |
Forward is useful for Encore. Don't worry @kikofernandez, I won't ask you to maintain this. |
Introduction
To recall, the
forward
is designed to delegate the future and to be fulfilled by other delegated method. In summary,forward
can be used in the following four cases.In this PR, the
forward()
can be used in closure.Syntax
Semantics
4.
forward in closure's body
where
f
andg
are preexisting futures.Examples
You can find many examples in the src/tests/encore/forward folder.