View
216
Download
1
Tags:
Embed Size (px)
Citation preview
Type System, March 12, 2002 - 1
Data Types and Behavioral Types
Yuhong XiongEdward A. Lee
Department of Electrical Engineering and Computer Sciences
University of California at Berkeley
Type System, March 12, 2002 - 2
Component Interfacing
• Two levels of interface:– data types and– dynamic interaction: communication & execution
• Dynamic behavior defined by models of computation (MoC)
Type System, March 12, 2002 - 3
Capturing Dynamic Behavior
• Dynamic behavior in each MoC can be described formally, using type systems
• Success of type systems:– Safety through type checking– Polymorphism supports reuse (flexible
components)– Type conversion– Program optimization– Interface documentation, clarification– Run-time reflection of component interfaces
Type System, March 12, 2002 - 4
Data Types in Ptolemy II
• Lattice-based infrastructure
• Support polymorphism, type conversion, and structured types
General
String
ScalarBoolean
Complex
Double
Long
Int
Unknown
Type System, March 12, 2002 - 5
Behavioral Type
• Data types only specify static aspects of interface
• Proposal:– Capture the dynamic interaction of
components in types– Obtain benefits analogous to data typing– Call the result behavioral types
Type System, March 12, 2002 - 6
Interaction Semantics
• Flow of control issues – in Ptolemy II, these are defined by a Director class
• Communication between components– in Ptolemy II, this is defined by a Receiver class
produceractor
consumeractor
IOPort
Receiver
Director
Actor interface for execution: fireReceiver interface for communication: put, get, hasToken
Type System, March 12, 2002 - 7
IOPort
FIFOQueue
1..1
1..1
«Interface»Receiver
+get() : Token+getContainer() : IOPort+hasRoom() : boolean+hasToken() : boolean+put(t : Token)+setContainer(port : IOPort)
0..1 0..n
QueueReceiver
NoRoomException
throws
NoTokenExceptionthrows
PNReceiver
«Interface»ProcessReceiver
CSPReceiver
SDFReceiver
ArrayFIFOQueue
1..11..1
DEReceiverMailbox
CTReceiver
Receiver Object Model
Type System, March 12, 2002 - 8
Models of Computation
• Define the interaction semantics• Implemented in Ptolemy II by a domain
– Receiver + Director
• Examples:– Communicating Sequential Processes (CSP):
rendezvous-style communication– Process Networks (PN):
asynchronous communication– Synchronous Data Flow (SDF):
stream-based communication, statically scheduled– Discrete Event (DE):
event-based communication– Synchronous/Reactive (SR):
synchronous, fixed point semantics
Type System, March 12, 2002 - 9
Formal Interaction Semantics:
Use Interface Automata• Based on interface automata
– Proposed by de Alfaro and Henzinger– Concise composition (vs. standard automata)– Alternating simulation provides contravariance
• Compatibility checking– Done by automata composition– Captures the notion “components can work together”
• Alternating simulation (from Q to P)– All input steps of P can be simulated by Q, and– All output steps of Q can be simulated by P.– Provides the ordering we need for subtyping &
polymorphism
• Key theorem about compatibility and alternating simulation
Type System, March 12, 2002 - 10
Example: Synchronous Dataflow (SDF) Consumer Actor Type
Definition
fR Return from fire
g get
hT hasToken
f fire
t Token
hTT Return True from hasToken
hTF Return False from hasToken
Inputs:Outputs:
Such actors are passive, and assume that input is available when they fire.
executioninterface
communicationinterface
Type System, March 12, 2002 - 11
Type Definition – Synchronous Dataflow (SDF)
Domain
produceractor
consumeractor
IOPort
Receiver
Directorreceiverinterface
directorinterface
Type System, March 12, 2002 - 12
Type Checking – Compose SDF Consumer Actor with SDF Domain
ComposeSDF Domain SDF Consumer Actor
Type System, March 12, 2002 - 13
Type Definition – SDF Consumer Actor in SDF
Domain
1. receives token from producer
interface toproducer actor
2. accept token
3. internal action: fire consumer
4. internal action: call get()
5. internal action: get token
6. internal action: return from fire
Type System, March 12, 2002 - 14
Type Definition –Discrete Event (DE) Domain
This domain may fire actors without first providing inputs
Type System, March 12, 2002 - 15
Recall Component BehaviorSDF Consumer Actor
1. is fired2. calls get()3. gets a token4. returns
Type System, March 12, 2002 - 16
Type Checking – Compose SDF Consumer Actor with DE
Domain
• Empty automaton indicates incompatibility• Composition type has no behaviors
ComposeDE Domain SDF Consumer Actor
Type System, March 12, 2002 - 17
Subtyping RelationAlternating Simulation: SDF
DE
SDF Domain DE Domain
Type System, March 12, 2002 - 18
System-Level Type Lattice –Defined by Alternating
Simulation• Subtyping relation• Shown here for a few
Ptolemy II domains
If an actor is compatible with a certain type, it is also compatible with the subtypes
unknown
PN
SDF
DE
CSP
DP
discreteevents
synchronousdataflow
unknown
processnetworks
communicatingsequentialprocesses
domainpolymorphic
Type System, March 12, 2002 - 19
Type Definition – Domain Polymorphic Consumer Actor
1. is fired 2. calls hasToken()
3. true
3. false
4. return
4. call get()
5. get token
6. return
This actor checks for token availability before attempting to get the token.
Type System, March 12, 2002 - 20
Domain Polymorphic ActorComposes with the DE
Domain
ComposeDE Domain Poly Actor
Type System, March 12, 2002 - 21
Domain Polymorphic Actor Also
Composes with the SDF Domain
ComposePoly ActorSDF Domain
Type System, March 12, 2002 - 22
Conclusion• Data types
– Lattice-based infrastructure– Support polymorphism, type conversion,
and structured types
• Behavioral types– Formally captures the structure of MoCs– Describe interaction types and component
behavior using interface automata– Perform type checking through automata
composition– Subtyping order is given by the alternating
simulation relation, supporting polymorphism