Hostname: page-component-5db58dd55d-8mwbx Total loading time: 0 Render date: 2026-05-25T22:16:43.115Z Has data issue: false hasContentIssue false

Is sized typing for Coq practical?

Published online by Cambridge University Press:  24 January 2023

JONATHAN CHAN
Affiliation:
University of British Columbia (e-mails: jcxz@cs.ubc.ca, jcxz@seas.upenn.edu)
YUFENG LI
Affiliation:
University of Waterloo (e-mails: yufeng.li@uwaterloo.ca, yufeng.li@mail.mcgill.ca)
WILLIAM J. BOWMAN
Affiliation:
University of British Columbia (e-mail: wjb@williamjbowman.com)
Rights & Permissions [Opens in a new window]

Abstract

Contemporary proof assistants such as Coq require that recursive functions be terminating and corecursive functions be productive to maintain logical consistency of their type theories, and some ensure these properties using syntactic checks. However, being syntactic, they are inherently delicate and restrictive, preventing users from easily writing obviously terminating or productive functions at their whim.

Meanwhile, there exist many sized type theories that perform type-based termination and productivity checking, including theories based on the Calculus of (Co)Inductive Constructions (CIC), the core calculus underlying Coq. These theories are more robust and compositional in comparison. So why haven’t they been adapted to Coq?

In this paper, we venture to answer this question with CIC$\widehat{\ast}$, a sized type theory based on CIC. It extends past work on sized types in CIC with additional Coq features such as global and local definitions. We also present a corresponding size inference algorithm and implement it within Coq’s kernel; for maximal backward compatibility with existing Coq developments, it requires no additional annotations from the user.

In our evaluation of the implementation, we find a severe performance degradation when compiling parts of the Coq standard library, inherent to the algorithm itself. We conclude that if we wish to maintain backward compatibility, using size inference as a replacement for syntactic checking is impractical in terms of performance.

Information

Type
Research Article
Creative Commons
Creative Common License - CCCreative Common License - BY
This is an Open Access article, distributed under the terms of the Creative Commons Attribution licence (https://creativecommons.org/licenses/by/4.0/), which permits unrestricted re-use, distribution and reproduction, provided the original article is properly cited.
Copyright
© The Author(s), 2023. Published by Cambridge University Press
Figure 0

Table 1. Comparison of the features in CIC$\widehat{~}$, CIC$\widehat{_-}$, Coq, and CIC$\widehat{\ast}$

Figure 1

Figure 1. Syntax of CIC$\widehat{\ast}$ terms, environments, and signatures.

Figure 2

Figure 2. Reduction rules

Figure 3

Figure 3. Multi-step reduction rules.

Figure 4

Figure 4. Convertibility rules.

Figure 5

Figure 5. Subsizing rules.

Figure 6

Figure 6. Subtyping rules.

Figure 7

Figure 7. Positivity/negativity of size variables in terms.

Figure 8

Figure 8. Well-formedness of environments.

Figure 9

Figure 9. Universe relations: Axioms, Rules, and Eliminations.

Figure 10

Figure 10. Metafunctions for typing rules.

Figure 11

Figure 11. Typing rules.

Figure 12

Figure 12. Reduction rules with unrestricted cofixpoint reduction.

Figure 13

Figure 13. Size inference algorithm: Checking.

Figure 14

Figure 14. Size inference algorithm: Algorithmic subtyping (excerpt).

Figure 15

Figure 15. Size inference algorithm: Inference (1/2).

Figure 16

Figure 16. Size inference algorithm: Inference (2/2).

Figure 17

Figure 17. Illustration of simplification of RecCheckLoop.

Figure 18

Figure 18. Pseudocode implementation of RecCheckLoop.

Figure 19

Figure 19. Size inference algorithm: Well-formedness.

Figure 20

Figure 20. Selected excerpts of the Coq codebase structure.

Figure 21

Table 2. Relevant function runtimes when compiling MSetList vs. MSetList_sized

Figure 22

Figure 21. Execution vs. $\lVert{V}\rVert\lVert{C}\rVert$, residuals, $\lVert{V}\rVert\lVert{C}\rVert$ distributions for solve and RecCheck.

Figure 23

Table 3. Size variables and time elapsed for definitions in fig:nats

Figure 24

Figure 22. Coq definitions with an explosion in size variables and in elapsed time.

Submit a response

Discussions

No Discussions have been published for this article.