Title: What is an Interface
1What is an Interface?
Thomas A. Henzinger University of California,
Berkeley
joint work with Luca de Alfaro
2A Component Specification
x ? Nat
z x?y
y ? Nat\0
Descriptive What does the component do?
3An Interface Specification
x ? Nat
z ? Real
y ? Nat\0
Prescriptive How can the component be put
together with other components?
4Whats the Difference?
5Whats the Difference?
x ? Nat
z x?y
y ? Nat\0
x ? Nat
z ? Real
y ? Nat\0
Language (syntax) No
6Whats the Difference?
x ? Nat
z x?y
y ? Nat\0
x ? Nat
z ? Real
y ? Nat\0
Language (syntax) No Level of detail
7Whats the Difference?
x ? Nat
z x?y
y ? Nat\0
x ? Nat
z ? Real
y ? Nat\0
Language (syntax) No Level of detail No
8Whats the Difference?
x ? Nat
z x?y
y ? Nat\0
x ? Nat
z x?y
y ? Nat\0
Language (syntax) No Level of
detail No Interpretation (semantics) Yes
9The Component Interpretation
x ? Nat ? y? Nat\0 ? z x?y
-(mis)behaves in every environment
-examples circuit executable
10The Component Interpretation
x ? Nat ? y? Nat\0 ? z x?y
-(mis)behaves in every environment
-examples circuit executable
The Interface Interpretation
x ? Nat ? y? Nat\0 ? z x?y
-constrains the environment
---other environments are rejected (by compiler)
-example type declaration of procedure
11Component Specification is Well-formed iff
?x,y. ?z. ( x ? Nat ? y? Nat\0 ? z x?y )
-specification is implementable
-input-universal
12Component Specification is Well-formed iff
?x,y. ?z. ( x ? Nat ? y? Nat\0 ? z x?y )
-specification is implementable
-input-universal
Interface Specification is Well-formed iff
?x,y. ?z. ( x ? Nat ? y? Nat\0 ? z x?y )
-specification is satisfiable
---(i.e., usable in some
environment) -input-existential
13- The logic view ?
- The block-diagram view
- The state-transition view
14Components Total Functions
y 2x
y
x ? Nat
x 2y1
x
y ? Nat
15Components Total Functions
y 2x
y
x ? Nat
x 2y1
y ? Nat
x
Composition always defined.
16Components Total Functions
y 2x
y
x ? Nat
odd
even
x 2y1
y ? Nat
x
17Interfaces Partial Functions
y ? Even
x ? Odd
x ? Odd
y ? Even
Output guarantee
Input assumption
18Interfaces Partial Functions
y ? Even
x ? Odd
x ? Odd
y ? Even
Composition defined Compatible interfaces.
19Interfaces Partial Functions
y ? Nat
x ? Nat
X
x ? Odd
y ? Even
Composition undefined Incompatible interfaces.
20- The logic view ?
- The block-diagram view ?
- The state-transition view
21a!
a
b!
b
a?
b?
22a!
b!
?
a?
23Components, Alternative 1
Be Prepared for Every Input
a!
b!
a?
This is an illegal component, because it is not
prepared to accept input b.
I/O Automata, TLA, Reactive Modules
24Components, Alternative 2
Compose, then Check
a!
a
b!
a?
Composition may lead to deadlocks, and requires
verification if this is undesirable.
CSP/CCS, Statecharts, Esterel
25Interfaces Check, then Compose
a!
These interfaces are incompatible, because the
receiver expects the environment to provide input
b.
b!
a?
Trace Theory, Interface Automata
26Simple interfaces (traditional types)
value constraints Rich interfaces
(types for component interaction) temporal
ordering constraints, real-time constraints, etc.
get_record
close_file
open_file
put_record
open_file?
get_record?
close_file?
put_record!
27Interface specifications are a programmer's task,
in burden between type declarations and invariant
annotations.
Interface compatibility checking is a program
analysis opportunity, in difficulty between type
checking and behavioral verification. (Note
unlike software contracts, interfaces are checked
statically, at compile time.)
28Components
Interfaces
- no environment constraints
environment constraints propagate by composition
29Components
Interfaces
- no environment constraints
- composition is total
- environment constraints
- composition is partial
environment constraints propagate by composition
interface compatibility checking is game solving
30Components
Interfaces
- no environment constraints
- composition is total
- refinement is covariant
- environment constraints
- composition is partial
- refinement is contravariant
environment constraints propagate by composition
interface compatibility checking is game solving
I/O alternating simulation relations
31Components
Interfaces
- no environment constraints
- composition is total
- refinement is covariant
- for compositional analysis
- environment constraints
- composition is partial
- refinement is contravariant
- for compositional design
environment constraints propagate by composition
interface compatibility checking is game solving
I/O alternating simulation relations
32Interface Composition and Propagation of
Environment Constraints The Block-Diagram View
33x
z
y
x0 ? y0
true
34x
z
y
x0 ? y0
true
35x
z
y
x0 ? y0
true
y 0
?x,z. ( true ? xz ? ( x0 ? y0 ))
36y
z
y 0
true
The resulting interface.
37y
z
y 0
true
Illegal connection.
38x
z
y
x0 ? y0
true
39x
z
y
x0 ? y0
true
x ? 0
40x
z
x ? 0
true
The resulting interface.
41x
z
x ? 0
true
Illegal connection.
42Interface Composition is Not Associative.
x
z
y
x0 ? y0
true
true
43Interface Composition and Propagation of
Environment Constraints The State-Transition View
44msg
fail
ok
ok!
ack?
ack?
msg?
send!
send!
nack?
nack?
fail!
ack
nack
send
45msg!
ok?
msg
ok
fail
msg
fail
ok
ok!
ack?
ack?
msg?
send!
send!
nack?
nack?
fail!
ack
nack
send
46ok
ack?
ack?
msg
send!
send!
nack?
nack?
fail!
ack
nack
send
Incompatible product state, but environment can
prevent this state.
47ok
ack?
ack?
msg
send!
send!
nack?
nack?
fail!
ack
nack
send
The Composite Interface.
48Computing the Composite Interface
- Construct product automaton.
- Mark deadlock states as incompatible.
- Until no more incompatible states can be added
mark state q as incompatible if the environment
cannot prevent an incompatible state to be
entered from q. - If the initial state is incompatible, then the
two interfaces are incompatible. Otherwise, the
composite interface is the product automaton
without the incompatible states.
49Computing the Composite Interface
- Construct product automaton.
- Mark deadlock states as incompatible.
- Until no more incompatible states can be added
mark state q as incompatible if the environment
cannot prevent an incompatible state to be
entered from q. - If the initial state is incompatible, then the
two interfaces are incompatible. Otherwise, the
composite interface is the product automaton
without the incompatible states.
50Computing the Composite Interface
- Construct product automaton.
- Mark deadlock states as incompatible.
- Until no more incompatible states can be added
mark state q as incompatible if the environment
cannot prevent an incompatible state to be
entered from q. - If the initial state is incompatible, then the
two interfaces are incompatible. Otherwise, the
composite interface is the product automaton
without the incompatible states.
51Computing the Composite Interface
- Construct product automaton.
- Mark deadlock states as incompatible.
- Until no more incompatible states can be added
mark state q as incompatible if the environment
cannot prevent an incompatible state to be
entered from q. - If the initial state is incompatible, then the
two interfaces are incompatible. Otherwise, the
composite interface is the product automaton
without the incompatible states.
52Computing the Composite Interface
- Construct product automaton.
- Mark deadlock states as incompatible.
- Until no more incompatible states can be added
mark state q as incompatible if the environment
cannot prevent an incompatible state to be
entered from q. - If the initial state is incompatible, then the
two interfaces are incompatible. Otherwise, the
composite interface is the product automaton
without the incompatible states.
This computes the states from which the
environment has a strategy to avoid deadlock.
The propagated environment constraint is that it
will apply such a strategy.
53Interface Compatibility Checking as Game Solving
AND-OR game graph AND player -interface product
OR player -environment
Deadlock states Does the OR player have a
strategy to avoid them?
54Interface Compatibility Checking as Game Solving
AND-OR game graph AND player -interface product
OR player -environment
Deadlock states Does the OR player have a
strategy to avoid them?
55Interface Compatibility Checking as Game Solving
AND-OR game graph AND player -interface product
OR player -environment
Deadlock states Does the OR player have a
strategy to avoid them?
56Interface Compatibility Checking as Game Solving
AND-OR game graph AND player -interface product
OR player -environment
Deadlock states Does the OR player have a
strategy to avoid them?
57Interface Compatibility Checking as Game Solving
AND-OR game graph AND player -interface product
OR player -environment
Deadlock states Does the OR player have a
strategy to avoid them?
58Interface Compatibility Checking as Game Solving
AND-OR game graph AND player -interface product
OR player -environment
Deadlock states Does the OR player have a
strategy to avoid them?
NO
59Interface Compatibility Checking as Game Solving
AND-OR game graph AND player -interface product
OR player -environment
Deadlock states Does the OR player have a
strategy to avoid them?
COMPLEXITY?
60Interface Compatibility Checking as Game Solving
2
AND-OR game graph AND player -interface product
OR player -environment
2
Deadlock states Does the OR player have a
strategy to avoid them?
LINEAR TIME (P-COMPLETE)
61Interface Compatibility Checking as Game Solving
2
AND-OR game graph AND player -interface product
OR player -environment
1
Deadlock states Does the OR player have a
strategy to avoid them?
LINEAR TIME (P-COMPLETE)
62Interface Compatibility Checking as Game Solving
1
AND-OR game graph AND player -interface product
OR player -environment
0
Deadlock states Does the OR player have a
strategy to avoid them?
LINEAR TIME (P-COMPLETE)
63Asynchronous Interfaces lead to Buechi Games
Environment should not block interface moves
Does the OR player have a strategy to hit the
target states infinitely often?
Target
64Asynchronous Interfaces lead to Buechi Games
Hit target once
Environment should not block interface moves
Does the OR player have a strategy to hit the
target states infinitely often?
Target
65Asynchronous Interfaces lead to Buechi Games
Hit original target once
Environment should not block interface moves
Does the OR player have a strategy to hit the
target states infinitely often?
New Target
66Asynchronous Interfaces lead to Buechi Games
Hit original target once
Environment should not block interface moves
Hit original target twice
Does the OR player have a strategy to hit the
target states infinitely often?
New Target
67Asynchronous Interfaces lead to Buechi Games
Hit target once
Environment should not block interface moves
Hit target twice
Does the OR player have a strategy to hit the
target states infinitely often?
Hit target infinitely often
Target
Linear number of finite games QUADRATIC TIME Can
this be improved ???
68Interface Refinement The Block-Diagram View
69Component Refinement
x ? Odd ? y 2x
x ? Nat
y
?
y 2x
y
x ? Nat
Refinement is implication (simulation trace
containment).
70Component Refinement
x ? Odd ? y 2x
x ? Nat
y
more behaviors
?
?
?
y 2x
y
x ? Nat
fewer behaviors
Refinement is implication (simulation trace
containment).
71Interface Refinement
x ? Nat
x ? Even
?
?
?
x ? Odd
x ? Nat
Like subtyping, refinement is I/O contravariant.
72Interface Refinement
x ? Odd
x ? Nat
?
?
X
X
?
x ? Nat
x ? Nat
1. Implementation must obey output guarantee.
73Interface Refinement
x ? Nat
x ? Nat
?
?
X
X
?
x ? Nat
x ? Even
2. Implementation must accept all permissible
inputs.
74Interface Refinement The State-Transition View
75msg
fail
ok
ok!
ack?
ack?
msg?
send!
send!
nack?
nack?
fail!
ack
nack
send
76msg
fail
ok
ok!
ack?
ack?
msg?
send!
send!
nack?
nack?
fail!
ack
nack
send
?
once
msg
fail
ok
ok!
ack?
ok!
ack?
ack?
send!
once?
msg?
send!
send!
nack?
fail!
nack?
nack?
fail!
ack
nack
send
77I/O Alternating Simulation
Q ? q iff 1. for all inputs i, if q i?-gt q ,
then there exists Q such that Q i?-gt Q and
Q ? q , and 2. for all outputs o, if Q o!-gt
Q , then there exists q such that q o!-gt q
and Q ? q .
78I/O Alternating Simulation
Q ? q iff 1. for all inputs i, if q i?-gt q ,
then there exists Q such that Q i?-gt Q and
Q ? q , and 2. for all outputs o, if Q o!-gt
Q , then there exists q such that q o!-gt q
and Q ? q .
If there is a helpful environment at q, then
there is a helpful environment at Q. This can be
checked in quadratic time Alur/Henzinger/Kupferma
n/Vardi '98.
79Compositionality The Interplay between
Composition and Refinement
80Top-down Design
81Top-down Design
82Top-down Design
83Top-down Design
84Top-down Design
85Compositionality for Top-down Design
If ab is defined and A ? a and B ? b , then
AB is defined and AB ? ab.
-enables independent interface implementation
-examples subtypes, interface
automata
86Compositionality for Top-down Design
If ab is defined and A ? a and B ? b , then
AB is defined and AB ? ab.
-enables independent interface implementation
-examples subtypes, interface
automata
Compositionality in Formal Methods
If AB is defined and A ? a and B ? b , then
ab is defined and AB ? ab.
-enables independent component verification
-examples I/O Automata, CSP,
Reactive Modules, etc.
87Compositional Verification
88Compositional Verification
89Compositional Verification
90Compositional Verification
91Compositional Verification
92Compositional Verification
93Compositional Verification
94Compositionality for Bottom-up Verification
If AB is defined and A ? a and B ? b , then
ab is defined and AB ? ab.
(A ? B) ? false A ? a B ? b (a
? b) ? false (A ?B) ? (a ? b)
95"Definition" of Component Formalism
Bottom-up Compositional
If AB is defined and A ? a and B ? b , then
ab is defined and AB ? ab.
"Definition" of Interface Formalism
Top-down Compositional
If ab is defined and A ? a and B ? b , then
AB is defined and AB ? ab.
What is yours?
96Applications of Interfaces, So Far
Software module interfaces -Java
extension with interface compatibility checking
in Jbuilder -interfaces for TinyOS, an OS for
ad-hoc networks Culler Hardware module
interfaces -bidirectional interfaces for PCI bus
and clients
-interfaces with timing constraints for TTA, an
architecture for -safety-critical embedded
systems Kopetz
97References
de Alfaro, Henzinger,
Interface
Automata, Foundations
of Software Engineering (FSE) 2001. de Alfaro,
Henzinger,
Interface Theories
for Component-based Design, Embedded Software
(EMSOFT) 2001. Chakrabarti, de Alfaro, Henzinger,
Jurdzinski, Mang, "Interface
Compatibility Checking for Software Modules",
Computer-Aided Verification (CAV) 2002.
www.eecs.berkeley.edu/tah