Skip to content

Unify callSiteTypeSubst and LFunc.computeTypeSubst into a single parameterised helper #1298

@PROgram52bc

Description

@PROgram52bc

Summary

Strata/DL/Lambda/Preconditions.lean::callSiteTypeSubst (added in #1205) and Strata/DL/Lambda/Factory.lean::LFunc.computeTypeSubst perform structurally identical unification at a call site, but with the priority of inputs reversed:

  • LFunc.computeTypeSubst (Factory.lean:653–666) — prefers the operator's .op annotation, falls back to argument types. Used after type inference, where .op always carries the instantiated arrow type.
  • callSiteTypeSubst (Preconditions.lean:77–90) — prefers argument types, falls back to the .op annotation. Used by PrecondElim, which runs before type checking, so the .op may still carry the generic type and argument types are the more reliable source.

Why we didn't unify them in #1205

Several proofs in Strata/DL/Lambda/Semantics.lean depend on the current computeTypeSubst shape (computeTypeSubst_of_opTypeSubst, computeTypeSubst_eraseMetadata_congr, and the callOfLFunc correctness lemmas around lines 2393–2563). Refactoring computeTypeSubst into a (preferOp : Bool)-parameterised helper requires re-establishing those proofs, which was out of scope for the bug fix.

Suggested approach

  1. Introduce LFunc.computeTypeSubstWith (preferOp : Bool) in Factory.lean containing the shared unification body.
  2. Define LFunc.computeTypeSubst := computeTypeSubstWith (preferOp := true) and LFunc.callSiteTypeSubst := computeTypeSubstWith (preferOp := false) (the latter currently lives in Preconditions.lean and would move to Factory.lean).
  3. Update Semantics.lean proofs to unfold through the parameterised helper. The post-type-inference lemmas should still hold because they only invoke the preferOp := true instantiation.

When to do this

Naturally pairs with the next unrelated touch to Semantics.lean::computeTypeSubst_* proofs.

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions