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

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

Comments

Projects
None yet
1 participant
@Jand42
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

This comment has been minimized.

Show comment
Hide comment
@Jand42

Jand42 Feb 9, 2017

Member

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.

Member

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 in e2ad2cc Feb 9, 2017

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