an exception aware behavioral type system for object-oriented programs
DESCRIPTION
An Exception Aware Behavioral Type System for Object-Oriented Programs . CITI / Departamento de Informática Universidade Nova de Lisboa - Portugal . Filipe Militão and Luís Caires. CoRTA 2009. TravelOrder Class. class TravelOrder { void flight(){ … } void hotel(){ … } - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: An Exception Aware Behavioral Type System for Object-Oriented Programs](https://reader036.vdocuments.mx/reader036/viewer/2022062410/568162ec550346895dd36ccc/html5/thumbnails/1.jpg)
AN EXCEPTION AWARE BEHAVIORAL TYPE SYSTEM
FOR OBJECT-ORIENTED PROGRAMS
Filipe Militão and Luís Caires
CITI / Departamento de InformáticaUniversidade Nova de Lisboa - Portugal
CoRTA 2009
![Page 2: An Exception Aware Behavioral Type System for Object-Oriented Programs](https://reader036.vdocuments.mx/reader036/viewer/2022062410/568162ec550346895dd36ccc/html5/thumbnails/2.jpg)
TravelOrder Classclass TravelOrder {
void flight(){ … } void hotel(){ … }
void buy(){ … } void cancel(){ … } string show(){ … }
}
![Page 3: An Exception Aware Behavioral Type System for Object-Oriented Programs](https://reader036.vdocuments.mx/reader036/viewer/2022062410/568162ec550346895dd36ccc/html5/thumbnails/3.jpg)
TravelOrder Documentation
/** * A TravelOrder requires the selection of * a flight and an hotel before it can be bought * or canceled. */
![Page 4: An Exception Aware Behavioral Type System for Object-Oriented Programs](https://reader036.vdocuments.mx/reader036/viewer/2022062410/568162ec550346895dd36ccc/html5/thumbnails/4.jpg)
TravelOrder Classclass TravelOrder {
void flight(){ … } void hotel(){ … }
void buy(){ … } void cancel(){ … } string show(){ … }
}
only available on specific situations
can be called freely
![Page 5: An Exception Aware Behavioral Type System for Object-Oriented Programs](https://reader036.vdocuments.mx/reader036/viewer/2022062410/568162ec550346895dd36ccc/html5/thumbnails/5.jpg)
Background Increasing software complexity
Effort to eliminate bugs Faster feedback on errors (static detection)
![Page 6: An Exception Aware Behavioral Type System for Object-Oriented Programs](https://reader036.vdocuments.mx/reader036/viewer/2022062410/568162ec550346895dd36ccc/html5/thumbnails/6.jpg)
Objectives and Contributions Statically check the externally
observable behavior of objects(based on formal description)
Guarantee termination (reaches stop) Exceptions (checked) Linear ownership + Borrowing (call-by-ref) Class body consistent with class behavior Working prototype
![Page 7: An Exception Aware Behavioral Type System for Object-Oriented Programs](https://reader036.vdocuments.mx/reader036/viewer/2022062410/568162ec550346895dd36ccc/html5/thumbnails/7.jpg)
Checking call sequences
TravelOrder
object
flight(…)
hotel(…)
buy()
flight . hotel . buy
→ Hidden internal state (like in regular expressions)→Tracks observable calls (i.e., the behavior), not states
![Page 8: An Exception Aware Behavioral Type System for Object-Oriented Programs](https://reader036.vdocuments.mx/reader036/viewer/2022062410/568162ec550346895dd36ccc/html5/thumbnails/8.jpg)
What is a Behavioral Type?
void hotel() void flight() void order() void cancel()string show()
1st flight2nd hotel3rd buy or cancel
TRAVELORDER TYPETRAVELORDER BEHAVIOR
+BEHAVIORAL
TYPE
![Page 9: An Exception Aware Behavioral Type System for Object-Oriented Programs](https://reader036.vdocuments.mx/reader036/viewer/2022062410/568162ec550346895dd36ccc/html5/thumbnails/9.jpg)
Describing the Behavior
What about “string show()” ? free / non-behavioral, can be called at any time...
1st flight2nd hotel3rd buy or cancel
TRAVELORDER BEHAVIOR
. (buy + cancel)
Regular expression-like protocol:flight . hotel
![Page 10: An Exception Aware Behavioral Type System for Object-Oriented Programs](https://reader036.vdocuments.mx/reader036/viewer/2022062410/568162ec550346895dd36ccc/html5/thumbnails/10.jpg)
TravelOrder Classclass TravelOrder {
usage flight.hotel.(buy+cancel) void flight(){ … } void hotel(){ … }
void buy(){ … } void cancel(){ … } string show(){ … }
}
![Page 11: An Exception Aware Behavioral Type System for Object-Oriented Programs](https://reader036.vdocuments.mx/reader036/viewer/2022062410/568162ec550346895dd36ccc/html5/thumbnails/11.jpg)
Examplelet t in
t = new TravelOrder();t.flight();t.show();t.hotel();if( … )
t.buy()else
t.cancel()
flight . hotel . ( buy + cancel )stop
![Page 12: An Exception Aware Behavioral Type System for Object-Oriented Programs](https://reader036.vdocuments.mx/reader036/viewer/2022062410/568162ec550346895dd36ccc/html5/thumbnails/12.jpg)
The rest of this talk… Introduction Type System
Exceptions Linear Ownership Borrowing
Subtyping Consistency check Related work Future work
![Page 13: An Exception Aware Behavioral Type System for Object-Oriented Programs](https://reader036.vdocuments.mx/reader036/viewer/2022062410/568162ec550346895dd36ccc/html5/thumbnails/13.jpg)
Basic typing judgement
environment (before)
expression
type ofexpression
environment (after)
![Page 14: An Exception Aware Behavioral Type System for Object-Oriented Programs](https://reader036.vdocuments.mx/reader036/viewer/2022062410/568162ec550346895dd36ccc/html5/thumbnails/14.jpg)
Sequence
e0 e1
T0 T1Will be lost!
![Page 15: An Exception Aware Behavioral Type System for Object-Oriented Programs](https://reader036.vdocuments.mx/reader036/viewer/2022062410/568162ec550346895dd36ccc/html5/thumbnails/15.jpg)
Example (try branch)
void method(N#buy[Error: undo] v){try
v.buy()catch(Error excp)
v.undo()}
buy [Error: undo]v stopon Error { v undo }
![Page 16: An Exception Aware Behavioral Type System for Object-Oriented Programs](https://reader036.vdocuments.mx/reader036/viewer/2022062410/568162ec550346895dd36ccc/html5/thumbnails/16.jpg)
Example (catch branch)
void method(N#buy[Error: undo] v){try
v.buy()catch(Error excp)
v.undo()}
undov stopon Error { v undo }
![Page 17: An Exception Aware Behavioral Type System for Object-Oriented Programs](https://reader036.vdocuments.mx/reader036/viewer/2022062410/568162ec550346895dd36ccc/html5/thumbnails/17.jpg)
Exceptions - throwexpression produces
compatible environme
nt
Runtime is behavior
agnostic, so thrown object
must be stopped
Exception
handler for N
![Page 18: An Exception Aware Behavioral Type System for Object-Oriented Programs](https://reader036.vdocuments.mx/reader036/viewer/2022062410/568162ec550346895dd36ccc/html5/thumbnails/18.jpg)
Exceptions - try catchTry branch with new exception handler
Catch branch restores old
handler
etry
ecatch
T
throw
“N”
![Page 19: An Exception Aware Behavioral Type System for Object-Oriented Programs](https://reader036.vdocuments.mx/reader036/viewer/2022062410/568162ec550346895dd36ccc/html5/thumbnails/19.jpg)
Linear Ownership Only one owner at a time*
( *unless the object was borrowed… )let t0 in
let t1 int0 = new TravelOrder();t1 = t0 ;t1.flight();t0.hotel()
t0 t1 stop
flight.hotel.(buy+cancel)
TypeError!
![Page 20: An Exception Aware Behavioral Type System for Object-Oriented Programs](https://reader036.vdocuments.mx/reader036/viewer/2022062410/568162ec550346895dd36ccc/html5/thumbnails/20.jpg)
Borrowing Checking call-by-reference
let t int = new TravelOrder();orderStuff(t);t.buy()
void orderStuff(TravelOrder#flight.hotel x)
Storing values requires owned permission
t flight.hotel.(buy+cancel)
![Page 21: An Exception Aware Behavioral Type System for Object-Oriented Programs](https://reader036.vdocuments.mx/reader036/viewer/2022062410/568162ec550346895dd36ccc/html5/thumbnails/21.jpg)
The rest of this talk… Introduction Type System
Exceptions Linear Ownership Borrowing
Subtyping Consistency check Related work Future work
![Page 22: An Exception Aware Behavioral Type System for Object-Oriented Programs](https://reader036.vdocuments.mx/reader036/viewer/2022062410/568162ec550346895dd36ccc/html5/thumbnails/22.jpg)
Subtyping Structural subtyping Requires compatible behavior
Subtype must accept same behavior as super…
flight.hotel
flight.hotel
(flight+swim).hotel <:
<: flight[Full: cancel].hotel
![Page 23: An Exception Aware Behavioral Type System for Object-Oriented Programs](https://reader036.vdocuments.mx/reader036/viewer/2022062410/568162ec550346895dd36ccc/html5/thumbnails/23.jpg)
Consistency check
class ABC {
usage a.b.c
TravelOrder t;
void a(){ t = new TravelOrder(); }void b(){ t.flight(); }
void c(){ t.buy(); }
}
TypeError!
Server code must also obey protocols
![Page 24: An Exception Aware Behavioral Type System for Object-Oriented Programs](https://reader036.vdocuments.mx/reader036/viewer/2022062410/568162ec550346895dd36ccc/html5/thumbnails/24.jpg)
Related work Resource usage analysis (2002)
Atsushi Igarashi and Naoki Kobayashi
Lightweight object specification with typestates (2007)Kevin Bierhoff and Jonathan Aldrich
Dynamic interfaces (2009)Vasco T. Vasconcelos, Simon Gay, António Ravara, Nils Gesbert, and Alexandre Z. Caldeira.
…
![Page 25: An Exception Aware Behavioral Type System for Object-Oriented Programs](https://reader036.vdocuments.mx/reader036/viewer/2022062410/568162ec550346895dd36ccc/html5/thumbnails/25.jpg)
Future work Concurrency
![Page 26: An Exception Aware Behavioral Type System for Object-Oriented Programs](https://reader036.vdocuments.mx/reader036/viewer/2022062410/568162ec550346895dd36ccc/html5/thumbnails/26.jpg)
Questions?
AN EXCEPTION AWARE BEHAVIORAL TYPE SYSTEM FOR OBJECT-ORIENTED PROGRAMS
Filipe Militão and Luís Caires
http://ctp.di.fct.unl.pt/yak/ YAK PROTOTYPE
Paper:
Web site: