Convertibility Soundness Theorem
- Convertibility Soundness Theorem is a formal framework that rigorously defines reliable type conversions across languages using well-defined conversion rules.
- It specifies declarative convertibility judgments and target-level glue code to mediate cross-language type conversions, handling dynamic conversion errors.
- The theorem is validated with a step-indexed logical relation, establishing foundational semantic soundness for interoperable multi-language systems.
The Convertibility Soundness Theorem provides a rigorous basis for reasoning about type soundness when multiple programming languages interoperate after compilation to a shared, untyped target. The theorem formalizes the reliability of type conversions across language boundaries, ensuring that target-level glue code correctly mediates types as specified by an interoperability relation, and that any dynamic errors are well-defined. Originally introduced in the context of the semantic framework for language interoperability, the theorem establishes that for any pair of source types declared convertible, the realized conversions preserve intended behaviors and invariants up to dynamically signaled conversion errors, providing the foundation for semantic type soundness of multi-language systems (Patterson et al., 2022).
1. Declarative Convertibility Judgment
Type conversions across language boundaries are formalized by a declarative convertibility judgment. Given two types, and , the relation specifies they are mutually convertible, possibly with certain well-defined dynamic failures. Typing rules for conversion are:
- If and , then .
- The symmetric rule holds for conversion from to .
The specific convertibility rules are defined by the interoperator and depend on the types and languages. In the shared-memory case study—using RefHL and RefLL, both compiling to StackLang—examples include:
| Convertibility Rule | Description | Special Notes |
|---|---|---|
| Bool Int | Boolean Integer | Same representation |
| Ref Bool 0 Ref Int | Reference to Bool 1 Reference to Int | Identical pointers |
| 2 | Sums 3 2-tagged Int arrays | Requires payload conversion |
All such rules are made explicit in the system [(Patterson et al., 2022), Fig. 4].
2. Target-Level Glue Code
For every declarative convertibility rule 4, a pair of target-level glue-code sequences 5 and 6 implement the actual conversions in the compiled, untyped target language. Representative glue-code implementations in the shared-memory case study include:
- 7 (no-op, as Bool and Int are identical),
- 8 (identical pointers),
- 9 involves tagging arrays and recursively converting payloads,
- 0 performs tag inspection, array length checks, payload conversion, or issues a dynamic error
fail Convon out-of-range cases.
These glue-code mappings constitute the operational mechanism for cross-language type conversions at the target level (Patterson et al., 2022).
3. Semantic/Realizability Model
Type soundness is justified by interpreting source types and terms semantically over target terms using a step-indexed logical relation.
- Worlds 1 pair a step-budget 2 with a heap typing 3, allowing for resource-aware semantics.
- Value interpretation 4 defines the set of target representations of source type 5 in world 6. For example:
- 7,
- 8,
- 9.
- Expression interpretation 0 comprises pairs 1 such that running program 2 in any heap 3 either diverges safely or terminates within 4 steps, carrying a value in 5 or a conversion error.
The Fundamental Property states that any well-typed source-term 6 compiles to 7 with 8.
4. Statement and Proof of Convertibility Soundness Theorem
The Convertibility Soundness Theorem asserts the semantic validity of all specified conversions:
Theorem (Convertibility Soundness):
If 9 then:
- For all 0, 1;
- For all 2, 3.
Formally,
4
Proof is by induction on the derivation of 5, proceeding case-by-case over the conversion rules. Each case uses the correctness of glue-code, the realizability model, and often the monotonicity of interpretations under world extension. A critical case is 6, justifying the correctness of the no-op glue-code for references since 7.
5. Illustrative Examples
The Shared-Memory case study concretely demonstrates the theorem's operation:
- Sums and Arrays: For 8, execution yields either 9 with 0 or 1 with 2. The glue-code 3 ensures correct tagging and recursive payload conversion, so the final result is a valid 4 in 5.
- References: If 6, the pointer 7 satisfies 8; since 9, the same pointer is valid for 0. No-op glue-code suffices for correctness.
- Dynamic Failures: If a value is not convertible (e.g., out-of-range array), the glue-code triggers the dynamic error
fail Conv. The model explicitly allows for such failures, maintaining the soundness property.
6. Corollary: Full Semantic Soundness of the Multi-Language
Upon establishing Convertibility Soundness, compatibility lemmas for all typing rules—especially boundaries and conversions—yield full semantic soundness for AB-programs: every well-typed program 1 compiles to 2. Consequently, execution of multi-language systems cannot “go wrong” except through conversion errors that are precisely specified by the declared convertibility relation. This constraint provides robust guarantees about the safe composition of multi-language systems, as validated semantically via the logical relation (Patterson et al., 2022).