Overview

APIs often come with temporal constraints, such as ‘method x.foo(y) must be called only after y.bar()’.
Sometimes these are enforced at runtime:
The library throws an exception if a constraint is broken.
Sometimes the checks don't catch all bad usages, because that would be too slow.

TOPL is a language that can express many temporal constraints.
It is understood by a compiler that automatically inserts the appropriate checks in the bytecode of the library.
The main advantages of this approach are the following:

The description of the illegal usage patterns is almost as concise as the English prose of comments, but has a precise meaning.

The API designer needs not write code to detect illegal sequences of calls.
This code is generated automatically by the TOPL compiler.

The user of the library can choose to use the non-instrumented and faster version of the library, after testing is completed.

The main disadvantage is that carefully hand-written checks will most likely be more efficient than the checks generated by the TOPL compiler.
This disadvantage is important when (1) the checks must always be active, even in deployment, and (2) the library authors have enough resources to devote to detecting bad usages, in addition to developing the core functions.

TOPL is based on register automata, which were initially defined and studied in 1994 under the name ‘finite-memory automata’ by Kaminski and Francez.