Note [Arity trimming]
Invariant (1) of Note [Arity invariants for bindings] is upheld by findRhsArity, which calls trimArityType to trim the ArityType to match the Arity of the binding. Failing to do so, and hence breaking invariant (1) led to #5441. How to trim? If we end in topDiv, it's easy. But we must take great care with dead ends (i.e. botDiv). Suppose the expression was (\x y. error "urk"), we'll get \??.⊥. We absolutely must not trim that to \?.⊥, because that claims that ((\x y. error "urk") |> co) diverges when given one argument, which it absolutely does not. And Bad Things happen if we think something returns bottom when it doesn't (#16066). So, if we need to trim a dead-ending arity type, switch (conservatively) to topDiv. Historical note: long ago, we unconditionally switched to topDiv when we encountered a cast, but that is far too conservative: see #5475
References 1
- Arity invariants for bindings GHC.Core.Opt.Arity
Referenced by 4
- GHC.Core.Opt.Arity call site ×3
- Arity invariants for bindings GHC.Core.Opt.Arity