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
Review
- Why also guard
Js.Null.toOption(x)bindings? They recordxthe same way, and the unwrap and thenulltest read it later just like aSome(x)payload; no repro was found there, the guard keeps it sound.