Problem
A bare-Ref alias to an @inline always binding is deliberately never dissolved (#171): substituting the alias would multiply the target's use sites right before the always-directive pastes its body into every one of them, so the alias is kept as the better materialization point. But the protection is applied so broadly that call sites through the alias never meet the target's body either: an application whose head is the alias stays a runtime call even when pasting would collapse it entirely. Golden.ProfunctorDictLens.Test shows the residue after #236/PR #304 erased the direct unsafeCoerce sites, verbatim from golden.lua: local Data_Newtype_coerce = function(x_S_262) return x_S_262 end, local Golden_ProfunctorDictLens_Test_unwrap = Data_Newtype_coerce, and then Golden_ProfunctorDictLens_Test_unwrap(Golden_ProfunctorDictLens_Test_unwrap(10) + 1) — two runtime calls of an identity function that beta reduction would erase to 10 + 1 had the head not been hidden behind the alias.
Approach
Teach the saturated-call-site inliner (#180's inlineSaturatedCall, or a sibling rule) to resolve a bare-Ref alias chain at the head position of an application through to its target, and when the target is an @inline always binding, paste the target's body at that site so beta reduction fires — without dissolving the alias binding itself, which preserves #171's materialization decision for the unapplied uses (the alias handed to dimap in the same golden must survive as a function value). The narrow fallback, if chain resolution proves too eager: collapse only applications of unary identity lambdas (App (AbsN [x] (Ref x)) a → a-shaped after alias resolution), which covers the coercion family that motivates this.
Prerequisites / Relations
Independent. Refines the boundary of the #171 alias-keeping rule (its veto should guard the alias binding, not the alias's call sites); the residue became visible after #236 (PR #304) erased direct identity-coercion sites; the site-paste machinery is #180's call-site inliner.
Verification / Measurement
Golden.ProfunctorDictLens.Test/golden.lua loses the identity calls — unwrap(unwrap(10) + 1) folds to a constant while unwrap survives as dimap's argument — with the eval oracle byte-identical; no golden regresses in size; the fnew/tnew censuses of the bench corpus are unchanged (the rewrite erases calls, not allocations).
Problem
A bare-Ref alias to an
@inline alwaysbinding is deliberately never dissolved (#171): substituting the alias would multiply the target's use sites right before the always-directive pastes its body into every one of them, so the alias is kept as the better materialization point. But the protection is applied so broadly that call sites through the alias never meet the target's body either: an application whose head is the alias stays a runtime call even when pasting would collapse it entirely.Golden.ProfunctorDictLens.Testshows the residue after #236/PR #304 erased the directunsafeCoercesites, verbatim fromgolden.lua:local Data_Newtype_coerce = function(x_S_262) return x_S_262 end,local Golden_ProfunctorDictLens_Test_unwrap = Data_Newtype_coerce, and thenGolden_ProfunctorDictLens_Test_unwrap(Golden_ProfunctorDictLens_Test_unwrap(10) + 1)— two runtime calls of an identity function that beta reduction would erase to10 + 1had the head not been hidden behind the alias.Approach
Teach the saturated-call-site inliner (#180's
inlineSaturatedCall, or a sibling rule) to resolve a bare-Ref alias chain at the head position of an application through to its target, and when the target is an@inline alwaysbinding, paste the target's body at that site so beta reduction fires — without dissolving the alias binding itself, which preserves #171's materialization decision for the unapplied uses (the alias handed todimapin the same golden must survive as a function value). The narrow fallback, if chain resolution proves too eager: collapse only applications of unary identity lambdas (App (AbsN [x] (Ref x)) a → a-shaped after alias resolution), which covers the coercion family that motivates this.Prerequisites / Relations
Independent. Refines the boundary of the #171 alias-keeping rule (its veto should guard the alias binding, not the alias's call sites); the residue became visible after #236 (PR #304) erased direct identity-coercion sites; the site-paste machinery is #180's call-site inliner.
Verification / Measurement
Golden.ProfunctorDictLens.Test/golden.lualoses the identity calls —unwrap(unwrap(10) + 1)folds to a constant whileunwrapsurvives asdimap's argument — with the eval oracle byte-identical; no golden regresses in size; thefnew/tnewcensuses of the bench corpus are unchanged (the rewrite erases calls, not allocations).