Type as Obligations
Migratory Typing · Interoperability · Type Obligations · Blame Theorems · Bisimulation · Vigilance · Formal Verification
Mechanized proofs in Rocq complete; manuscript in preparation.
Languages that combine static and dynamic typing use different runtime enforcement strategies: some wrap values in contracts, some merge casts, and others insert shallow checks. These choices affect not only type safety but also which boundary violations are detected and whether blame identifies the responsible boundaries. Comparing these guarantees is difficult when each semantics is analyzed using different definitions and proof techniques.
My work develops Type as Obligations (TAO), a common framework for formalizing these guarantees. Its central idea is to distinguish what a program owes to its types from how a particular semantics enforces those requirements.
Previous work on vigilance provides a related perspective: values should respect their runtime typing histories, not merely their final types. However, vigilance characterizes this requirement through a logical relation indexed by a proof-level typing history, leaving blame outside its analysis. My framework reifies typing-history obligations into an explicit obligation store, maintained by an executable profiler semantics. This makes the propagation and violation of obligations directly inspectable and brings type enforcement and blame into the same analysis.
Core Contributions
1. A uniform, executable profiler semantics for type obligations.
I introduce a profiler semantics that records the typing history of values, i.e., the type-induced boundaries they have crossed. Type obligations originate at these typed–untyped boundaries and propagate through function arguments, results, and pair projections, including higher-order interactions where runtime proxies are created, merged, or discarded. This provides a common basis for defining obligation soundness and blame correctness independently of a particular enforcement mechanism.
The profiler also makes counterexamples operationally explainable. A language designer can execute a program and inspect which requirements were violated, how they reached the affected value, and whether the reported blame matches the violated obligations. This exposes enforcement failures even when ordinary evaluation returns successfully.
2. Mechanical construction of the profiler semantics, with a proof of bidirectional correspondence.
For ordinary semantics expressed through TAO’s common interface, TAO mechanically constructs the corresponding profiler semantics by intercepting reduction steps, inserting profiling commands at appropriate points, and delegating the computational reductions back to the ordinary semantics. Individual programs require no manual instrumentation; the framework determines where obligations must be recorded and propagated.
Moreover, I prove a bidirectional correspondence between ordinary and profiler evaluation. The correspondence accommodates additional obligation-bookkeeping steps and differences in allocated locations between the two semantics. In particular, a well-typed, uniquely labeled source program terminates with a resolved value in the ordinary semantics exactly when it terminates with that same value in the profiler semantics.
This bidirectional correspondence theorem justifies using the profiler semantics to reason about ordinary evaluation. On the one hand, “profiler evaluation implies ordinary evaluation” shows that the profiler faithfully simulates ordinary evaluation without introducing behavior, apart from additional obligation-bookkeeping steps. On the other hand, “ordinary evaluation implies profiler evaluation” ensures that the profiler captures ordinary evaluation without omitting behavior; such omissions would limit the conclusions drawn from the profiler. Thus, the profiler supports reasoning about the original semantics rather than replacing it with a different computation.
3. Obligation soundness: a new enforcement criterion that implies type soundness.
We propose obligation soundness for ordinary migratory typing semantics: throughout the profiler evaluation of any valid input program, no intermediate value may violate its type obligations. Although obligation soundness is a property of the ordinary semantics, it is defined using the type obligations recorded across all possible profiler evaluations. This definition is supported by the bidirectional correspondence theorem, which connects ordinary and profiler evaluation in both directions.
I prove that obligation soundness implies type soundness. The converse does not hold: a type-sound semantics may preserve a value’s final type while discarding that value’s typing history. This distinguishes returning a correctly typed result from respecting the requirements imposed throughout execution.
4. Blame correctness: a new ground truth for blame theorems.
We also propose a new criterion for blame theorems, using violated obligations as the ground truth for blame assignment.
An obligation violation represents an unfulfilled duty; its recorded boundary provenance identifies a candidate for blame. Accordingly, blame soundness means that blamed boundaries correspond to a subsequence of violated obligations, while blame completeness means that violated obligations correspond to a subsequence of the blamed boundaries. An ordinary semantics is blame correct if and only if it is both blame sound and blame complete.
5. A formal comparison of four enforcement strategies.
We apply TAO to four enforcement strategies for migratory typing: Natural, Threesomes, Forgetful, and Transient. Using the same property definitions, we establish both positive results and explicit counterexamples for the modeled semantics:
| Strategy | Type Soundness | Obligation Soundness | Blame Soundness | Blame Completeness |
|---|---|---|---|---|
| Natural | Yes | Yes | Yes | Yes |
| Threesomes | Yes | Yes | No | Yes |
| Forgetful | Yes | No | Yes | No |
| Transient | No | No | Yes | No |
These results reveal substantive differences. Natural, a standard proxy-based strategy, enforces all type obligations and assigns blame correctly. Threesomes’ cast merging can report a conflict before an obligation is actually violated. Forgetful preserves result typing but loses obligation enforcement and blame completeness because it discards intermediate proxies. Transient does not use proxies to project untyped values or record their typing histories, which weakens its enforcement.
6. Mechanized metatheory and an executable model.
The framework, metatheory, and counterexamples are formalized in Rocq/Coq, with an accompanying executable Racket/Redex model. The broader contribution is a common semantic account that makes the guarantees of different enforcement strategies explicit, comparable, and machine-checked, while making their failures accessible through execution.