Semantic Diff

#9531 Keep a Some or tuple payload read before its variable is assigned

1 commit

2796a446117a261c37df1766640dabc473626473..pr-9531

a507341c7 · cknitt + Claude · Dec 04, 2026, 21:39 UTC

Keep a Some or tuple payload read before its variable is assigned

Why

The alias pass replaced the payload of a variable known to be Some(x), and a field of one known to be (x, _), with x itself. When x is assigned between the binding and the read, the read gets the new value. Since #9022 substituted Some(x) payloads, this is reachable through cross-module @inline bodies, which are stored after Lam_pass_sroa turned their refs into assigned variables. The pass now keeps the binding when the variable is assigned.

modifiedJS cross-module @inline

// Other.res@inlinelet f = (n: int, q: 'a, q2: 'a) => {  let s = ref(q)  let o = Some(s.contents)  for _ in 0 to n {    s := q2  }  switch o {  | Some(v) => Some((v, s.contents))  | None => None  }}@inlinelet g = (n: int, q: 'a, q2: 'a) => {  let s = ref(q)  let t = (s.contents, 1)  for _ in 0 to n {    s := q2  }  let (a, _) = t  (a, s.contents)} // Main.reslet viaAlias = () => Other.f(3, "a", "b")let viaField = () => Other.g(3, "a", "b")
js
Before both return ["b", "b"]
After both return ["a", "b"]
function viaAlias() {function viaAlias() { let s = "a"; let s = "a"; let o = Primitive_option.some(s); for (let _for = 0; _for <= 3; ++_for) { for (let _for = 0; _for <= 3; ++_for) { s = "b"; s = "b"; } } return [ return [ s, Primitive_option.valFromOption(o), s s ]; ];}}… viaField compiles to the same function viaField() { let s = "a"; let t_0 = s; for (let _for = 0; _for <= 3; ++_for) { s = "b"; } return [ t_0, s ];}

Review

  • Why also guard Js.Null.toOption(x) bindings? They record x the same way, and the unwrap and the null test read it later just like a Some(x) payload; no repro was found there, the guard keeps it sound.