Semantic Diff

#9022 Unwrap a known Some(x) without the runtime when x is a variable

1 commit

d8db3c6ebb93d50ae095b58c670b79cd388988b4..pr-9022

ac95bf47b · cknitt + Claude · Oct 24, 2026, 16:30 UTC

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.