JPred: Practical Predicate Dispatch for Java
JPred is an extension to
the Java programming language to support predicate dispatch.
With predicate dispatch, each method implementation includes a
predicate guard specifying the conditions under which the method
should be invoked, and
logical implication of predicates determines the method overriding
relation. Predicate dispatch naturally unifies and generalizes
several common forms of dynamic dispatch,
including traditional OO dispatch,
multimethod dispatch, and functional-style pattern
matching.
JPred resolves several limitations in prior approaches to predicate
dispatch. First, JPred retains Java's modular typechecking and
compilation strategies; prior languages with
predicate dispatch have
required the whole program to be available for typechecking and
compilation. Second, JPred
employs general-purpose,
off-the-shelf decision procedures to perform precise reasoning about
predicates at compile time. As a result, JPred's type system
allows several useful programming idioms that are spuriously rejected
by prior languages.
Project Members
Chris Frost
Todd Millstein
Publications
Modularly Typesafe Interface Dispatch in
JPred (FOOL/WOOD 2006)
Christopher Frost and
Todd Millstein
Practical Predicate
Dispatch (OOPSLA 2004)
Todd Millstein
Software
Download the JPred compiler.
The
compiler is implemented in Java, and both source and bytecode versions
of the compiler are included.
An Eclipse plugin for the JPred compiler is available
here.
The JPred compiler is implemented as an extension in the Polyglot
extensible compiler framework. It extends the
Polyglot
for Java 1.5 extension, which allows Polyglot to support the Java
1.5 language features.
The OOPSLA 2004 paper above is currently the best documentation for
the language. However, there have been several small extensions since
then:
-
Predicates can dispatch on interfaces. Documentation for this
feature, and the associated notion of ordered dispatch, can be
found in the FOOL/WOOD 2006 paper above.
- Predicates can manipulate arrays and dispatch on array types.
- Predicates can invoke methods that have the new modifier
pure, which indicates that the method does not have any
visible side effects. The JPred typechecker ensures that a
pure method does not update fields, allocate new objects, or
invoke non-pure methods.