2.6 KiB
vanity
executable artefact about parametricity failure under specialisation and inlining with representation lowering
this project models a small typed source calculus and then lowers it into an explicit representation calculus and audits whether the source observation and target observation remain related. the surface is semantic rather than structural as its about abstraction theorems, representation relations, strictness shifts, and the proof obligations that an optimiser assumes when it rewrites polymorphic code
the target language makes representation explicit and forces each transition to be spelled out in the term. values are either boxed or unboxed and can be projected from products or injected into sums as well as unpacked when needed and moved across worker wrapper boundaries as part of calling convention shifts
the target calculus is intentionally lower level than the source and trades abstraction for control over layout and calling. it has decent tuple and sum representations and uses explicit box and unbox operations to mediate between them. equality on integers and booleans is primitive rather than encoded as well as recursive binding being built in rather than derived
the audit path now records pass-boundary observations for source, specialisation, inlining, effect rewriting, and representation lowering. each corpus case is checked against relation preservation, target arity/shape validation, termination class preservation, and effect trace preservation. unsafe profiles intentionally refute these invariants so optimiser bugs show up as small source/target deltas rather than vague failures.
the source calculus also has an explicit tick effect. this is enough to expose unsound dce-style rewrites: eliminating a dead binding is only valid when the eliminated term is effect free.
example(s)
a representation exposure witness starts from a polymorphic constant false term
forall a. function a function a bool
under a safe profile instantiating this term at bool preserves the baseline relation. under an unsafe inline profile instantiating at int can expose integer equality and refute the abstraction theorem
a strictness witness places a divergent recursive computation under roll
roll mu a. int loop
the source observation can keep the recursive payload latent. a strict lowering path may force it during construction and change termination.
a worker wrapper witness uses the explicit source type representation
TArrow (TPair (TInt, TBool), TPair (TInt, TBool))
the target worker receives RInt and RBool while the wrapper preserves the boxed source interface