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

Optimize variants of getRef ref >>= body #139

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

emwap
Copy link
Member

@emwap emwap commented Jan 29, 2015

These optimizations will rewrite expressions binding the result of getRef
by substituting the reference for the bound variable when it is morally safe to do so.

The rewrite is not possible in the typed representation since the reference
and the bound variable have different types.

/cc @pjonsson, @emilaxelsson

These optimizations will rewrite expressions binding the result of `getRef`
by substituting the reference for the bound variable when it is morally safe to do so.
The rewrite is not possible in the typed representation since the reference
and the bound variable have different types.
@pjonsson
Copy link
Member

I spent 10 minutes looking at the patch and thinking about this and I don't feel good about it. I don't have time to figure this out on my own this week so can you specify the intuition for when the substitution is morally safe?

The code uses fv and the comment talks about free. Using "not in" instead of "free" in the comment would be more clear.

@emwap
Copy link
Member Author

emwap commented Jan 29, 2015

You are absolutely correct. I will update to "not used in".

These optimizations will rewrite expressions binding the result of `getRef`
by substituting the reference for the bound variable when it is morally safe to do so.
The rewrite is not possible in the typed representation since the reference
and the bound variable have different types.
@emwap
Copy link
Member Author

emwap commented Jan 30, 2015

I have updated the comments. The reasoning is that if the reference itself is not used in the body the we do not need to copy the data into a new variable.

@pjonsson
Copy link
Member

cc @josefs

Oh, uhm, a syntactic condition for approximating single use. I cc'd the resident linear typist. "What about scope extrusion?" was the first thing that came to my mind. Either way, I'm swamped right now so instead of stalling you--go ahead and merge unless you find something else that is wrong with these patches. We'll keep an eye out for weird behaviour with mutable references.

@josefs
Copy link
Contributor

josefs commented Jan 31, 2015

@pjonsson not sure what you mean wrt scope extrusion here. I don't see how that comes in to play at all.

As for having an intermediate language which somehow tracked linearity/affinity, that would be awesome. But I have yet to see a compelling design which is practical.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants