Unwrap a known Some(x) without the runtime when x is a variable
Matching on a variable bound to Some(x) emitted Primitive_option.some(x) followed by valFromOption, although that pair always gives back x.
modifiedLambda simplify_alias
lambda
Before
After
let a = Psome(y) in ... Pval_from_option(a) let a = Psome(y) in ... ywhen: y is a variable or a non-allocating constant
modifiedJS matching on Some of a variable
let nested = (y: option<int>) => switch Some(y) { | Some(Some(n)) => n | Some(None) => 0 | None => -1 }
js
Before
After
function nested(y) {function nested(y) { let n = Primitive_option.some(y); let n$1 = Primitive_option.valFromOption(n); if (n$1 !== undefined) { return n$1; if (y !== undefined) { return y; } else { } else { return 0; return 0; } }}}
Review
- Why only variables and constants? Using any other payload directly would evaluate it twice; Some(f()) keeps the calls.