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 F# tupled and curried arguments and local functions #648

Closed
Jand42 opened this issue Feb 6, 2017 · 1 comment
Closed

Optimize F# tupled and curried arguments and local functions #648

Jand42 opened this issue Feb 6, 2017 · 1 comment

Comments

@Jand42
Copy link
Member

Jand42 commented Feb 6, 2017

A lot of FSharp.Core functions like Seq.map2 take a curried function parameter, but implementation always applies it fully. Adding an optimization is possible that JS translation will take a flat 2-argument function. Same for tupled function arguments. Information about tuple/curried function argument optimization is added to metadata.

Further, local tupled/curried functions can be optimized to flat form not only if they are only used locally, but when they are also passed to functions that are accepting the optimized form.

@Jand42
Copy link
Member Author

Jand42 commented Feb 9, 2017

A new component is ArgCurrying module in WS.Compiler.FSharp. It is analyzing methods/constructors with function arguments to check what length do they apply them and where they are passed around. A curried function can be optimized to flat but not the other way around to keep semantics.

Metadata contains purity and currying information in a new Optimizations class.

Local curried/tupled functions are converted to flat and currying/decurrying and tupling/detupling pairs are erased.

Optimizations are now run in a few more steps:

  • simplify let expressions (inlining when possible)
  • erase calls to Runtime.x functions where possible (needs the inlining so argument is in correct place)
  • recursive simplify optimizations
  • break to statement-based form (remove forms not compatible with JS.Writer) - skip this for inlines
  • use Runtime.Curried helper when curried forms remained

Added some tests for compilation in WS.Tests\Compiler.fs. These look at metadata (all expressions now retained in memory) to check for optimizations taking place.

@Jand42 Jand42 closed this as completed in e2ad2cc Feb 9, 2017
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

No branches or pull requests

1 participant