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.

  • JankoA

    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.

  • github

    This topic has been closed.