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

Prevent removal of inlined mutable vars from optimized AST #6333

Merged
merged 2 commits into from
Apr 11, 2019

Conversation

ncave
Copy link
Contributor

@ncave ncave commented Mar 14, 2019

This prevents inlined mutable vars to be removed from optimized AST.

@ncave ncave changed the title Restrict removal of inlined mutable vars from optimized AST Prevent removal of inlined mutable vars from optimized AST Mar 14, 2019
@TIHan
Copy link
Contributor

TIHan commented Mar 28, 2019

Can you give more context on this? What is this solving?

@dsyme
Copy link
Contributor

dsyme commented Mar 28, 2019

Can you give more context on this? What is this solving?

I do get why this is needed.

The compiler inserts various compiler-generated bindings during type checking, but we make an effort to remove these when revealing the TAST via quotations and FCS expression trees, to make the public form of the expression trees less sensitive to compiler changes and less revealing of compiler internals. We do this by simply substituting let compgen = e1 in e2 away replacing all compgen in e2 with copies of e1.

However, this may be incorrect when a compiler-generated intermediate value is mutable. I'd imagine the mutability is relevant in some situation related to Fable

@ncave two things

  1. Can you measure the impact of making the corresponding change in quotations.fs please?
  2. Can you add some tests please? I'd like to understand the situations where this matters, particularly w.r.t. quotations.

@ncave
Copy link
Contributor Author

ncave commented Mar 28, 2019

Can you give more context on this? What is this solving?

@TIHan
This prevents incorrect removal of mutable variables after inlining functions that use them (in optimized AST), e.g. List.average, etc.

@dsyme
Copy link
Contributor

dsyme commented Mar 28, 2019

@TIHan This prevents incorrect removal of mutable variables after inlining functions that use them (in optimized AST), e.g. List.average, etc.

That is, in the context of FCS clients like Fable who look at optimized expression trees.

It sounds like this doesn't affect quotations as yet, since they don't reveal expression trees after inlining.

@ncave
Copy link
Contributor Author

ncave commented Mar 28, 2019

@dsyme That's right, as stated, in optimized AST only. And it's perfectly fine to keep it downstream (Fable-only), I just wanted to bring it up to see if anything can be done here.

Basically, is that optimization (extra variable removal) worth applying unconditionally, if there are (not so edge) cases where it impacts (breaks) simple code that just uses FSharp.Core functions (e.g. List.average etc.). Again, just in the optimized AST, not the generated IL, but still.

@dsyme
Copy link
Contributor

dsyme commented Mar 28, 2019

@dsyme That's right, as stated, in optimized AST only. And it's perfectly fine to keep it downstream (Fable-only), I just wanted to bring it up to see if anything can be done here.

Your fix is good. Can you add a test case please?

thanks

@TIHan
Copy link
Contributor

TIHan commented Mar 28, 2019

Thank you both. It makes sense to me.

@ncave
Copy link
Contributor Author

ncave commented Apr 5, 2019

@dsyme Added some tests.

@KevinRansom KevinRansom merged commit 9564307 into dotnet:master Apr 11, 2019
@cartermp cartermp added this to the 16.1 milestone Apr 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants