- The paper presents a unified framework that formalizes graded modalities and erasure to enforce resource discipline in dependent type theory.
- It introduces system extensions such as graded Σ-types and security typing with formal proofs of normalization, subject reduction, and decidable equality.
- The mechanization in Agda validates extraction soundness, ensuring erasable code does not impact program outcomes across different evaluation strategies.
Introduction and Motivation
The paper presents a fully formalized dependent type theory incorporating graded modalities, supporting resource-aware programming disciplines such as erasure, linearity, and information flow via type- and term-level usage annotations. The gradings are parameterized by an algebraic modality structure, typically a partially ordered semiring, used to encode and statically enforce discipline on resource/variable usage. This generalizes and subsumes previous approaches such as Quantitative Type Theory (QTT) and provides a unifying semantic framework for resource-sensitive dependent type systems.
The primary focus of the study is the incorporation and meta-theoretical justification of erasure, enabling static non-computational (proof-irrelevant) portions of programs to be marked and removed at extraction/compilation time without affecting program outcomes. The system integrates grades throughout dependent types and terms, defines precise grading inference and checking mechanisms, and formalizes meta-theoretical results in Agda, including normalization, subject reduction, substitution, and decidability of definitional equality.
Modality Structure and Graded Judgements
Modalities as Algebraic Structures
The resource modalities are modeled as semirings (addition +, multiplication â‹…, distinguished zero and one elements, with partial order via a meet operation), general enough to capture common patterns:
- Erasure: M={0,ω}; $0$ (erasable), ω (computationally relevant).
- Affineness/Linearity: M={0,1,ω} or further refinements.
- Information Flow: Distributive lattices; e.g., low (L) and high (H) security levels.
The meta-theory is parameterized over these structures, facilitating proofs and mechanization for a broad class of resource-aware systems.
Graded Dependent Type System
- Syntax: Dependent Π- and Σ-types, ⋅0, universe, empty type, weak/strong unit types, graded pairing/abstraction/application. ⋅1 and ⋅2 binders and related constructors/case analyses are annotated with grades, controlling resource tracking.
- Graded Contexts: Usage contexts (mapping variables to grades) are maintained in parallel to typing contexts.
- Judgement Separation: The system separates usage checking from typing:
- Typing: â‹…3.
- Grading: â‹…4, where â‹…5 is a usage context.
- This supports more flexible resource tracking and is crucial for sound treatment of dependent types.
Erasure Tracking and Well-Behaved Zero Grades
A central technical requirement is a well-behaved zero in the modality, supporting static reasoning about erasability. Multiple positivity conditions (addition, meet, natural number recursion, zero-product) ensure that variables marked as erasable cannot affect computation or values without the programmer’s intent.
Usage Inference and Decidability
The system provides an algorithmic grading relation, supporting bottom-up inference of the most precise context (principal usage) for a term. Decidability follows by finiteness of grades and contexts (for the common instances) and by design of checking rules.
Substitution, Subject Reduction, and Normalization
The substitution lemma and subject reduction (for both typing and grading) are proved using graded substitutions modeled as matrices (linear maps between contexts), extending fundamental properties of dependent type theories to the resource-aware graded setting. All fundamental meta-theorems, including normalization and decidable equality, are fully mechanized in Agda (by extending prior formalizations [DBLP:journals/pacmpl/0001OV18]).
Extraction and Erasure Soundness
A parameterized extraction function (â‹…6) compiles to erasure-aware untyped â‹…7-calculus, with rules varying for strict/non-strict (CBV/CBN) target semantics. Strong invariants are established:
- Completeness: Every variable with grade 0 is absent from the extracted code.
- Soundness: For closed terms of base types (â‹…8), execution (i.e., reduction to numeral) is preserved post-erasure.
- Open Terms: Soundness holds for open terms under erasable (zero-typed) contexts, provided the context is consistent and erased matches are suitably restricted.
A nontrivial logical relations argument (syntactic Kripke logical relation, formalized in Agda) is employed, proving value- and reduction-preservation under erasure for all supported modalities satisfying the 'well-behaved zero' constraints.
System Extensions and Additional Contributions
Graded â‹…9-Types and Modes
The system supports graded M={0,ω}0-types with first components at (possibly erasable) grades, enabling erased fields in records. To handle resource safety, modes (present/erased) are introduced; e.g., projections from erased first components are restricted to erased context. The semantics extends Atkey-style tensor products and allows fine-grained control analogous to dependent tuples with mixed resource requirements.
Weak/Strong Unit Types
Both the multiplicative and additive unit types (from linear logic) are included, with corresponding eliminators/rules, and the system allows flexibility in their resource behavior (e.g., strong units being usable in arbitrary context).
The generality of the modality framework enables the system to encode and enforce multi-level information flow policies (e.g., secrecy, clearance) using lattice-based modalities. Noninterference is supported as a corollary of the erasure soundness theorem instantiated for security lattices.
Design Decisions and Comparisons
- Separation of Usage and Typing: Unlike classical QTT or resource-aware systems with paired grade/type contexts, usage is tracked orthogonally to typing, which enables precise resource analysis especially in the presence of dependency in types.
- Resource Preservation in Types: Usage annotations are permitted in types as well as in terms, a feature necessary (and shown to be sound) for settings with advanced type-level computation (e.g., cubical/univalent settings).
- Choice of Grading Mechanisms for Recursors: The system generalizes previous approaches to usage in M={0,ω}1-recursion, allowing user-specified combination functions for grade calculation, which increases expressivity and soundness guarantees.
- Configurability of Erased Matches: The system can enable or restrict erased pattern matching in weak M={0,ω}2 or unit eliminators, highlighting subtle interactions with canonicity and open term soundness.
- The system is mechanized in ~110,000 lines of Agda, representing the largest and most expressive formalization of a graded dependent type theory (with universe and large elimination).
- Subject reduction, normalization, and decidability of equality are fully formalized for the class of modality structures described.
- The extraction function is proved sound for any modality with a well-behaved zero, supporting both call-by-name and call-by-value, and for open or closed terms under graded contexts.
Practical and Theoretical Implications
Graded (modal) dependent type theory subsumes a wide range of practical resource policies, providing a robust meta-theoretical foundation for systems such as Agda, Idris, and experimental resource-aware dependently typed languages. These results also facilitate verified program extraction and optimizations (e.g., dead code erasure, safe result-ignoring) and provide extensibility to richer type-theoretic settings (cubical, univalent foundations) and application domains (security, quantum programming).
The formal framework paves the way for future mechanized, sound type-checkers for graded systems, incorporation of type-based constraint solving for automated grade inference, and deeper semantic analysis for advanced type dependency and categorical models.
Conclusion
The paper achieves a substantial advancement in the theory and mechanization of resource-aware dependent type systems, providing a generic, extensible, and fully formalized framework for modalities with strong guarantees. It validates the practical utility and meta-theoretical soundness of erasure, affineness, linearity, and information flow analyses within dependent type theory, and demonstrates how high-level resource properties can be robustly tracked and preserved across compilation and execution. The work sets the stage for future developments in verified compilation, refined program extraction, and type-theoretic models of computation-aware properties.
References: For details on mechanized proofs and theorem statements, see (2603.29716).