npm create rescript-app@latest
> select Command Line
> select rescript12-beta3
Add src/Foo.res:
@inline let a=(x, y)=>x+y
@inline let b=(x, y, z)=>a(a(x, y), z)
Add src/Foo.resi:
@inline let a:(int, int)=>int
@inline let b:(int, int, int)=>int
Modify src/Demo.res:
Console.log("Hello, world!")
let foo = Foo.b(1, 2, 3)
Inspect .res.mjs files:
File Foo.res.mjs:
// Generated by ReScript, PLEASE EDIT WITH CARE
function a(x, y) {
return x + y | 0;
}
function b(x, y, z) {
return (x + y | 0) + z | 0;
}
export {
a,
b,
}
/* No side effect */
Notice how a has be inlined inside b correctly
File Demo.res.mjs:
// Generated by ReScript, PLEASE EDIT WITH CARE
import * as Foo from "./Foo.res.mjs";
console.log("Hello, world!");
let foo = Foo.b(1, 2, 3);
export {
foo,
}
/* Not a pure module */
Notice how Foo.b has not be inlined
- Adding
-bs-cross-module-optdoes nothing - Removing @inline from
Foo.resioptimizesDemo.res.mjsto saylet foo = 6(so the @inline directive actually prevents optimization in this case, in my codebase it does nothing because i’m not using constants) - Removing @inline from
Foo.resapparently does nothing in this example, but in my codebase, it prevents a from being inlined into b