Reference. Incremental Bidirectional Typing via Order Maintenance

Live programming environments provide various semantic services, including type checking and evaluation, continuously as the user is editing the program. The live paradigm promises to improve the developer experience, but liveness is an implementation challenge, particularly when working with large programs. This paper specifies and efficiently implements a system that is able to incrementally update type information for a live program in response to fine-grained program edits. This information includes type error marks and information about the expected and actual type of every expression. The system is specified type-theoretically as a small-step dynamics that propagates updates through the marked and annotated program. Most updates flow according to a base bidirectional type system. Additional pointers are maintained to connect bound variables to their binding locations, with type updates traversing these pointers directly. Order maintenance data structures are employed to efficiently maintain these pointers and to prioritize the order of update propagation. We prove this system is equivalent to naive reanalysis in the Agda theorem prover, along with other important metatheoretic properties. We then provide an efficient OCaml implementation, detailing a number of impactful optimizations. We evaluate this implementation’s performance with a large stress-test and find that it is able to achieve multiple orders of magnitude speed-up compared to from-scratch reanalysis.

Cite

Cite as @porter-2025-incremental (helia, typst) · \cite{porter-2025-incremental} (LaTeX)
BibTeX
bibtex · 1 line
@article{porter-2025-incremental, title={Incremental Bidirectional Typing via Order Maintenance}, volume={9}, ISSN={2475-1421}, url={http://dx.doi.org/10.1145/3763117}, DOI={10.1145/3763117}, number={OOPSLA2}, journal={Proceedings of the ACM on Programming Languages}, publisher={Association for Computing Machinery (ACM)}, author={Porter, Thomas J. and Kirisame, Marisa and Wei, Ivan and Panchekha, Pavel and Omar, Cyrus}, year={2025}, month=Oct, pages={1865–1892} }
hayagriva YAML (typst)
yaml · 21 lines
porter-2025-incremental:
  type: article
  title: Incremental Bidirectional Typing via Order Maintenance
  author:
  - Porter, Thomas J.
  - Kirisame, Marisa
  - Wei, Ivan
  - Panchekha, Pavel
  - Omar, Cyrus
  date: 2025-10
  page-range: 1865-1892
  url: http://dx.doi.org/10.1145/3763117
  serial-number:
    doi: 10.1145/3763117
    issn: 2475-1421
  parent:
    type: periodical
    title: Proceedings of the ACM on Programming Languages
    publisher: Association for Computing Machinery (ACM)
    issue: OOPSLA2
    volume: 9
Cites 48 works (3 here)
With notes (3)

Total Type Error Localization and Recovery with Holes zhao-2024-total

Type systems typically only define the conditions under which an expression is well-typed, leaving ill-typed expressions formally meaningless. This approach is insufficient as the basis for language servers driving modern programming environments, which are expected to recover from simultaneously localized errors and continue to provide a variety of downstream semantic services. This paper addresses this problem, contributing the first comprehensive formal account of total type error localization and recovery: the marked lambda calculus. In particular, we define a gradual type system for expressions with marked errors, which operate as non-empty holes, together with a total procedure for marking arbitrary unmarked expressions. We mechanize the metatheory of the marked lambda calculus in Agda and implement it, scaled up, as the new basis for Hazel, a full-scale live functional programming environment with, uniquely, no meaningless editor states. The marked lambda calculus is bidirectionally typed, so localization decisions are systematically predictable based on a local flow of typing information. Constraint-based type inference can bring more distant information to bear in discovering inconsistencies but this notoriously complicates error localization. We approach this problem by deploying constraint solving as a type-hole-filling layer atop this gradual bidirectionally typed core. Errors arising from inconsistent unification constraints are localized exclusively to type and expression holes, i.e., the system identifies unfillable holes using a system of traced provenances, rather than localized in an ad hoc manner to particular expressions. The user can then interactively shift these errors to particular downstream expressions by selecting from suggested partially consistent type hole fillings, which returns control back to the bidirectional system. We implement this type hole inference system in Hazel.
PDF · DOI · pldb

Bidirectional Typing dunfield-2021-bidirectional

Bidirectional typing combines two modes of typing: type checking, which checks that a program satisfies a known type, and type synthesis, which determines a type from the program. Using checking enables bidirectional typing to support features for which inference is undecidable; using synthesis enables bidirectional typing to avoid the large annotation burden of explicitly typed languages. In addition, bidirectional typing improves error locality. We highlight the design principles that underlie bidirectional type systems, survey the development of bidirectional typing from the prehistoric period before Pierce and Turner’s local type inference to the present day, and provide guidance for future investigations.
DOI · arXiv

Hazelnut: a bidirectionally typed structure editor calculus omar-2017-hazelnut

PDF · DOI · arXiv · pldb
External (45)
porter-2025-incremental reference entries/refs/porter-2025-incremental/porter-2025-incremental.hel