🤖 AI Summary
To address high latency in type checking during fine-grained editing of large programs in real-time programming environments, this paper proposes an incremental bidirectional type checking method. The approach introduces order-maintenance data structures into the type propagation mechanism for the first time, integrating a binding-pointer–augmented annotated program model with a priority-based scheduling strategy to achieve constant amortized-time complexity for dynamic type information updates. Semantic equivalence and metatheoretic properties are formally verified in Agda. The system builds a type dynamics model based on small-step semantics, enabling real-time maintenance of expression-level types, expected/actual types, and error annotations. Experimental evaluation demonstrates a 275.96× speedup over full reanalysis under large-scale stress testing, significantly enhancing real-time type feedback capability for large programs.
📝 Abstract
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 the 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 on 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 edits 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 re-analysis in the Agda theorem prover, along with other important metatheoretic properties. We then implement it efficiently in OCaml, 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 dramatic speed-ups of 275.96$ imes$ compared to from-scratch reanalysis.