Download presentation
Presentation is loading. Please wait.
1
AN EXCEPTION AWARE BEHAVIORAL TYPE SYSTEM FOR OBJECT-ORIENTED PROGRAMS Filipe Militão and Luís Caires CITI / Departamento de Informática Universidade Nova de Lisboa - Portugal CoRTA 2009
2
TravelOrder Class class TravelOrder { void flight(){ … } void hotel(){ … } void buy(){ … } void cancel(){ … } string show(){ … } }
3
TravelOrder Documentation /** * A TravelOrder requires the selection of * a flight and an hotel before it can be bought * or canceled. */
4
TravelOrder Class class TravelOrder { void flight(){ … } void hotel(){ … } void buy(){ … } void cancel(){ … } string show(){ … } } only available on specific situations can be called freely
5
Background Increasing software complexity Effort to eliminate bugs Faster feedback on errors (static detection)
6
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
7
Checking call sequences TravelOrder object TravelOrder object flight(…) hotel(…) buy() flight. hotel. buy → Hidden internal state (like in regular expressions) → Tracks observable calls (i.e., the behavior), not states → Hidden internal state (like in regular expressions) → Tracks observable calls (i.e., the behavior), not states
8
What is a Behavioral Type? void hotel() void flight() void order() void cancel() string show() 1 st flight 2 nd hotel 3 rd buy or cancel T RAVEL O RDER T YPE T RAVEL O RDER B EHAVIOR + B EHAVIORAL T YPE
9
Describing the Behavior What about “ string show() ” ? free / non-behavioral, can be called at any time... 1 st flight 2 nd hotel 3 rd buy or cancel T RAVEL O RDER B EHAVIOR. (buy + cancel) Regular expression-like protocol: flight. hotel
10
TravelOrder Class class TravelOrder { usage flight.hotel.(buy+cancel) void flight(){ … } void hotel(){ … } void buy(){ … } void cancel(){ … } string show(){ … } }
11
Example let t in t = new TravelOrder(); t.flight(); t.show(); t.hotel(); if( … ) t.buy() else t.cancel() flight. hotel. ( buy + cancel )stop
12
The rest of this talk… Introduction Type System Exceptions Linear Ownership Borrowing Subtyping Consistency check Related work Future work
13
Basic typing judgement environment (before) expression type of expression environment (after)
14
Sequence e0e0 e1e1 T0T0 T1T1 Will be lost!
15
Example (try branch) void method(N#buy[Error: undo] v){ try v.buy() catch(Error excp) v.undo() } buy [Error: undo] v stop on Error { v undo }
16
Example (catch branch) void method(N#buy[Error: undo] v){ try v.buy() catch(Error excp) v.undo() } undo v stop on Error { v undo }
17
Exceptions - throw expression produces compatible environment Runtime is behavior agnostic, so thrown object must be stopped Exception handler for N
18
Exceptions - try catch Try branch with new exception handler Catch branch restores old handler e try e catch T throw “N”
19
Linear Ownership Only one owner at a time* ( *unless the object was borrowed… ) let t0 in let t1 in t0 = new TravelOrder(); t1 = t0 ; t1.flight(); t0.hotel() t0 t1 stop flight.hotel.(buy+cancel) Type Error !
20
Borrowing Checking call-by-reference let t in t = new TravelOrder(); orderStuff(t); t.buy() void orderStuff(TravelOrder#flight.hotel x) Storing values requires owned permission t flight.hotel.(buy+cancel)
21
The rest of this talk… Introduction Type System Exceptions Linear Ownership Borrowing Subtyping Consistency check Related work Future work
22
Subtyping Structural subtyping Requires compatible behavior Subtype must accept same behavior as super… flight.hotel (flight+swim).hotel <: <: flight[Full: cancel].hotel
23
Consistency check class ABC { usage a.b.c TravelOrder t; void a(){ t = new TravelOrder(); } void b(){ t.flight(); } void c(){ t.buy(); } } Type Error ! Server code must also obey protocols
24
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. …
25
Future work Concurrency
26
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:
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.