Temporal Verification with Answer-Effect Modification

Taro Sekiyama, Hiroshi UnnoarXiv 2022

This paper, presented at ICFP 2018, tackles one of the "final bosses" of program verification: reasoning about the temporal behavior of programs that use delimited control operators.

TL;DR

The authors introduce a new type-and-effect system that can formally verify the event sequences (traces) produced by programs using shift0 and reset0. By introducing the concept of Answer-Effect Modification (AEM) and supporting dependently-typed continuations, they provide a framework to prove both safety and liveness properties for highly complex control flows.

What Problem Does This Paper Address?

In the world of formal verification, we want to know not just what a program returns, but how it behaves over time. This behavior is often described as a "trace"—a sequence of events like "opening a file," "sending a packet," or "waiting for a signal."

Type-and-effect systems are great at tracking these traces for standard recursive functions. However, they usually break down when faced with delimited control operators (like shift0 and reset0). These operators are incredibly powerful—they allow a program to capture its own "future" (a continuation), suspend it, resume it later, discard it entirely (like an exception), or even run it multiple times (like nondeterministic backtracking).

Because these operators can manipulate the execution context so drastically, it becomes a nightmare to track the order of events. If a program captures a continuation that contains a "send message" event but then discards that continuation, the event never happens. If it runs it twice, the event happens twice. Existing systems simply couldn't handle this "modification" of the context's behavior precisely.

Methods

The authors extend a dependent temporal effect system with several novel features:

  1. Answer-Effect Modification (AEM): This is the paper's namesake. It is inspired by "Answer-Type Modification," which tracks how control operators change the return type of a context. AEM tracks how these operators change the temporal effect (the trace) of the context.
  2. Require-and-Guarantee View: The system treats answer effects as a contract. An effect before modification represents what a context requires to happen, while the effect after modification represents what the program guarantees to the outer "meta-context."
  3. Dependently-Typed Continuations: This is a major technical leap. It allows the type of a captured continuation to depend on the values passed to it. For example, you can now say: "If I resume this continuation with true, it will produce trace $A$; if I resume it with false, it will produce trace $B$."
  4. Fixpoint Logic: The system uses a first-order fixpoint logic to describe sets of finite and infinite traces, allowing it to reason about liveness (e.g., "this loop will eventually terminate" or "this server will always eventually respond").

Datasets

Not discussed in the paper. As a theoretical research paper in programming languages, the evaluation is based on formal proofs of soundness and illustrative code examples rather than empirical datasets.

Key Insights and Ideas

  • The "Aha!" Moment on AEM: The researchers realized that the complexity of delimited control isn't just about the continuation itself, but how the act of capturing it modifies the "answer" (the total behavior) of the surrounding block. By enriching typing judgments to track this modification, the complexity becomes manageable.
  • Infinite Traces are Global: A subtle but critical insight is that an infinite trace (divergence) is observable at the top level of a program regardless of how many delimiters (reset0) it is buried under. This required a specialized "logical relation" proof technique to ensure the system was sound for liveness properties.
  • Systematic Dependency: The authors show that adding dependency to control effects isn't just an ad-hoc fix; it arises naturally if you look at the Continuation Passing Style (CPS) translation of these operators.

Key Results

  • Formal Soundness: The authors provide a rigorous proof that their system is sound. For finite traces, they use standard type safety (progress and subject reduction). For infinite traces, they use a complex logical relation.
  • Expressivity: They demonstrate that the system can verify programs that were previously out of reach, such as complex wait/send protocols, nondeterministic choice implementations, and exception handling that discards future events.
  • Tool Implementation: They implemented the system as a prototype tool that can automatically generate temporal effect constraints and solve them using existing refinement type solvers.

Limitations and Future Work

  • Automation: While they have a prototype, the authors admit that the current level of automation for "reconstructing" these complex types and effects is low. They plan to leverage recent advances in fixpoint logic solvers to make the verification more "push-button."
  • Broader Operator Support: The current work is specific to shift0/reset0. The authors want to extend AEM to other control structures, such as tagged control operators and the increasingly popular algebraic effect handlers.
  • State and Recursion: The system currently lacks support for recursive types and higher-order state, which are common in real-world functional languages like OCaml or Haskell.

Summary updated

BibTeX
@misc{sekiyama2022temporal,
  author = {Taro Sekiyama and Hiroshi Unno},
  title = {{Temporal Verification with Answer-Effect Modification}},
  year = {2022},
  eprint = {2207.10386},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2207.10386},
}
Figure