Environmental Acquisition Revisited
Richard Cobbe and Matthias Felleisen Northeastern University
Environmental Acquisition Revisited — POPL 2005 – p.1/30
Environmental Acquisition Revisited Richard Cobbe and Matthias - - PowerPoint PPT Presentation
Environmental Acquisition Revisited Richard Cobbe and Matthias Felleisen Northeastern University Environmental Acquisition Revisited POPL 2005 p.1/30 What is Acquisition? Environmental Acquisition Revisited POPL 2005 p.2/30
Richard Cobbe and Matthias Felleisen Northeastern University
Environmental Acquisition Revisited — POPL 2005 – p.1/30
Environmental Acquisition Revisited — POPL 2005 – p.2/30
JDialog JRootPane JPanel JPanel JPanel JButton
located only at top level
must chase pointers to access root pane
Environmental Acquisition Revisited — POPL 2005 – p.3/30
TaxInfo getTaxPolicy() { ... } Fund funds TaxInfo taxPolicy MutualFund Fund Account TaxInfo taxPolicy Fund funds int fundID int balance FundGroup
Operations on
s must know tax policy
Environmental Acquisition Revisited — POPL 2005 – p.4/30
contains acquires contains MutualFund Account TaxInfo taxPolicy int fundID int balance TaxInfo taxPolicy Fund funds Fund funds FundGroup TaxInfo taxPolicy Fund
Operations on
s must know tax policy With acquisition, no longer need to maintain and chase parent refs
Environmental Acquisition Revisited — POPL 2005 – p.4/30
errorMessage( ) UnionInfo vPanel HorizontalPanel ... Dialog ClassUnionWizard errorMessage( ) produce( ) add( ) VariantPanel produce( )
Environmental Acquisition Revisited — POPL 2005 – p.5/30
acquires errorMessage( ) UnionInfo vPanel HorizontalPanel ... Dialog ClassUnionWizard errorMessage( ) produce( ) add( ) VariantPanel produce( )
Environmental Acquisition Revisited — POPL 2005 – p.6/30
Invariants ensured by language support for acquisition:
Environmental Acquisition Revisited — POPL 2005 – p.7/30
Invariants ensured by language support for acquisition:
Environmental Acquisition Revisited — POPL 2005 – p.7/30
Invariants ensured by language support for acquisition:
Environmental Acquisition Revisited — POPL 2005 – p.7/30
relationship
Environmental Acquisition Revisited — POPL 2005 – p.8/30
Environmental Acquisition Revisited — POPL 2005 – p.9/30
Based on ClassicJava, formal model of Java by Flatt, Krishnamurthi, and Felleisen (1998). Supported features:
Environmental Acquisition Revisited — POPL 2005 – p.10/30
Based on ClassicJava, formal model of Java by Flatt, Krishnamurthi, and Felleisen (1998). Supported features:
Environmental Acquisition Revisited — POPL 2005 – p.10/30
Environmental Acquisition Revisited — POPL 2005 – p.11/30
Environmental Acquisition Revisited — POPL 2005 – p.12/30
C : contained B contains D d B : contained A int fd contains C c A bool fd contains B b acquires int fd D : contained C
Environmental Acquisition Revisited — POPL 2005 – p.13/30
C : contained B contains D d B : contained A int fd contains C c A bool fd contains B b acquires int fd D : contained C
from
✟, and types match. Program is well-typed.
Environmental Acquisition Revisited — POPL 2005 – p.13/30
bool fd B : contained A int fd contains C c acquires int fd D : contained C C : contained B A bool fd contains B b contains D d
Environmental Acquisition Revisited — POPL 2005 – p.14/30
bool fd B : contained A int fd contains C c acquires int fd D : contained C C : contained B A bool fd contains B b contains D d
from
✠, and types are not compatible. Program is not well-typed.
Environmental Acquisition Revisited — POPL 2005 – p.14/30
Environmental Acquisition Revisited — POPL 2005 – p.15/30
... ... ... Prop1 meth(Property p) { ... } acquires Property fd acquires Property meth(Prop2) Prop1 Ctnr1 Prop2 Prop1 fd Property Property meth(Prop2 x) { ... } Ctnr2 Prop2 fd contains Item it contains Item it Item : contained Ctnr1, Ctnr2
Environmental Acquisition Revisited — POPL 2005 – p.16/30
anItem : Item acquires Property fd contains Item it aCtnr1 : Ctnr1 Prop1 fd contains Item it aCtnr2 : Ctnr2 Prop2 fd
When does
✆ ✝ ✆ ✄ ✞ ✚acquire
✝ ✟’s value?
Environmental Acquisition Revisited — POPL 2005 – p.17/30
anItem : Item acquires Property fd contains Item it aCtnr1 : Ctnr1 Prop1 fd contains Item it aCtnr2 : Ctnr2 Prop2 fd
When does
✆ ✝ ✆ ✄ ✞ ✚acquire
✝ ✟’s value?
is placed into
✆ ✠ ✄ ✝ ☞Environmental Acquisition Revisited — POPL 2005 – p.17/30
anItem : Item acquires Property fd contains Item it aCtnr1 : Ctnr1 Prop1 fd contains Item it aCtnr2 : Ctnr2 Prop2 fd
When does
✆ ✝ ✆ ✄ ✞ ✚acquire
✝ ✟’s value?
is placed into
✆ ✠ ✄ ✝ ☞is referenced.
Environmental Acquisition Revisited — POPL 2005 – p.17/30
anItem : Item acquires Property fd contains Item it aCtnr1 : Ctnr1 Prop1 fd contains Item it aCtnr2 : Ctnr2 Prop2 fd
When does
✆ ✝ ✆ ✄ ✞ ✚acquire
✝ ✟’s value?
is placed into
✆ ✠ ✄ ✝ ☞is referenced. Both are sound; primarily affects visibility of assignments.
Environmental Acquisition Revisited — POPL 2005 – p.17/30
anItem : Item acquires Property fd contains Item it aCtnr1 : Ctnr1 Prop1 fd contains Item it aCtnr2 : Ctnr2 Prop2 fd
Two questions with acquisition-by-value:
Environmental Acquisition Revisited — POPL 2005 – p.18/30
anItem : Item acquires Property fd contains Item it aCtnr1 : Ctnr1 Prop1 fd contains Item it aCtnr2 : Ctnr2 Prop2 fd
Two questions with acquisition-by-value: 1.
✆ ✠ ✄ ✝ ☞:
: previous value or undefined?
Environmental Acquisition Revisited — POPL 2005 – p.18/30
anItem : Item acquires Property fd contains Item it aCtnr1 : Ctnr1 Prop1 fd contains Item it aCtnr2 : Ctnr2 Prop2 fd
Two questions with acquisition-by-value: 1.
✆ ✠ ✄ ✝ ☞:
: previous value or undefined? 2.
✆ ✠ ✄ ✝ ☞:
: previous value, or value of
✆ ✠ ✄ ✝ ☞?
Environmental Acquisition Revisited — POPL 2005 – p.18/30
anItem : Item acquires Property fd contains Item it aCtnr1 : Ctnr1 Prop1 fd contains Item it aCtnr2 : Ctnr2 Prop2 fd
Two questions with acquisition-by-value: 1.
✆ ✠ ✄ ✝ ☞:
: previous value or undefined? 2.
✆ ✠ ✄ ✝ ☞:
: previous value, or value of
✆ ✠ ✄ ✝ ☞? We implement acquisition-by-name; it avoids both issues.
Environmental Acquisition Revisited — POPL 2005 – p.18/30
Property :> Prop2 Item : contained Ctnr1, ... contains Item it Property meth(Prop1 p) { ... } Prop1 fd acquires Property fd acquires Prop2 meth(Property) Ctnr1
Gil and Lorenz claim that the above program is type-safe, because of normal method-type co/contravariance.
Environmental Acquisition Revisited — POPL 2005 – p.19/30
Prop1 <: Property Item : contained Ctnr1, ... contains Item it Property meth(Prop1 p) { ... } Prop1 fd acquires Property fd acquires Prop2 meth(Property) Ctnr1
Gil and Lorenz claim that the above program is type-safe, because of normal method-type co/contravariance.
Environmental Acquisition Revisited — POPL 2005 – p.19/30
Property :> Prop2 Item : contained Ctnr1, ... contains Item it Property meth(Prop1 p) { ... } Prop1 fd acquires Property fd acquires Prop2 meth(Property) Ctnr1
Gil and Lorenz claim that the above program is type-safe, because of normal method-type co/contravariance.
Environmental Acquisition Revisited — POPL 2005 – p.19/30
Property :> Prop2 Item : contained Ctnr1, ... contains Item it Property meth(Prop1 p) { ... } Prop1 fd acquires Property fd acquires Prop2 meth(Property) Ctnr1
Gil and Lorenz claim that the above program is type-safe, because of normal method-type co/contravariance. Unsafe!
Environmental Acquisition Revisited — POPL 2005 – p.19/30
Property :> Prop2 Item : contained Ctnr1, ... contains Item it Property meth(Prop1 p) { ... } Prop1 fd acquires Property fd acquires Prop2 meth(Property) Ctnr1
Gil and Lorenz claim that the above program is type-safe, because of normal method-type co/contravariance. Unsafe! Co/contravariance don’t apply.
Environmental Acquisition Revisited — POPL 2005 – p.19/30
Prop1 meth(Property p) { ... } acquires Property meth(Prop2) Ctnr1 Prop1 fd contains Item it Item : contained Ctnr1, ... acquires Property fd
Variance is still possible. Acquiring class may expect more general type.
Environmental Acquisition Revisited — POPL 2005 – p.20/30
anItem : Item acquires Property fd contains Item it aCtnr1 : Ctnr1 Prop1 fd Prop2
Environmental Acquisition Revisited — POPL 2005 – p.21/30
Prop2 anItem : Item acquires Property fd contains Item it aCtnr1 : Ctnr1 Prop1 fd
In a naïve system, anItem.fd :
type-checks.
Environmental Acquisition Revisited — POPL 2005 – p.21/30
anItem : Item acquires Property fd contains Item it aCtnr1 : Ctnr1 Prop1 fd Prop2
In a naïve system, anItem.fd :
type-checks. But
✆ ✝ ✆ ✄ ✞ ✚ ✑ ✝ ✟is an alias to
✆ ✠ ✄ ✝ ☞.
Environmental Acquisition Revisited — POPL 2005 – p.21/30
anItem : Item acquires Property fd contains Item it aCtnr1 : Ctnr1 Prop1 fd Prop2
In a naïve system, anItem.fd :
type-checks. But
✆ ✝ ✆ ✄ ✞ ✚ ✑ ✝ ✟is an alias to
✆ ✠ ✄ ✝ ☞. Unsafe:
✆ ✠ ✄ ✝ ☞is no longer a
☎ ☞ ✂ ✖Environmental Acquisition Revisited — POPL 2005 – p.21/30
Three possible solutions:
assignments to acquired fields.
Environmental Acquisition Revisited — POPL 2005 – p.22/30
Three possible solutions:
assignments to acquired fields. Introduces bad asymmetry into language.
Environmental Acquisition Revisited — POPL 2005 – p.22/30
Three possible solutions:
assignments to acquired fields. Introduces bad asymmetry into language.
Environmental Acquisition Revisited — POPL 2005 – p.22/30
Three possible solutions:
assignments to acquired fields. Introduces bad asymmetry into language.
Too inflexible.
Environmental Acquisition Revisited — POPL 2005 – p.22/30
Three possible solutions:
assignments to acquired fields. Introduces bad asymmetry into language.
Too inflexible.
Environmental Acquisition Revisited — POPL 2005 – p.22/30
Three possible solutions:
assignments to acquired fields. Introduces bad asymmetry into language.
Too inflexible.
Jacques implements option 3: right balance between flexibility and safety.
Environmental Acquisition Revisited — POPL 2005 – p.22/30
anItem : Item acquires Property fd contains Item it aCtnr1 : Ctnr1 Prop1 fd contains Item it aCtnr2 : Ctnr2 Prop2 fd
Environmental Acquisition Revisited — POPL 2005 – p.23/30
anItem : Item acquires Property fd contains Item it aCtnr1 : Ctnr1 Prop1 fd contains Item it aCtnr2 : Ctnr2 Prop2 fd
Assignment
✆ ✠ ✄ ✝ ☞:
automatically updates hidden parent ref.
Environmental Acquisition Revisited — POPL 2005 – p.23/30
anItem : Item acquires Property fd contains Item it aCtnr1 : Ctnr1 Prop1 fd contains Item it aCtnr2 : Ctnr2 Prop2 fd
Assignment
✆ ✠ ✄ ✝ ☞:
automatically updates hidden parent ref. Can change existing containment tree: aCtnr2.it :
Violates two-way reference invariant.
Environmental Acquisition Revisited — POPL 2005 – p.23/30
anItem : Item acquires Property fd contains Item it aCtnr1 : Ctnr1 Prop1 fd contains Item it aCtnr2 : Ctnr2 Prop2 fd
Assignment
✆ ✠ ✄ ✝ ☞:
automatically updates hidden parent ref. Can change existing containment tree: aCtnr2.it :
Violates two-way reference invariant. So we forbid this assignment.
Environmental Acquisition Revisited — POPL 2005 – p.23/30
Item : contained Ctnr1, ... acquires Property fd acquires Property meth(Prop2) Ctnr1 Prop1 fd contains Item it Prop1 meth(Property p) { ... }
What is this when executing acquired method
✆ ✝ ✆ ✄ ✞ ✚ ✑ ✚ ✞ ✄?
)
Environmental Acquisition Revisited — POPL 2005 – p.24/30
Item : contained Ctnr1, ... acquires Property fd acquires Property meth(Prop2) Ctnr1 Prop1 fd contains Item it Prop1 meth(Property p) { ... }
What is this when executing acquired method
✆ ✝ ✆ ✄ ✞ ✚ ✑ ✚ ✞ ✄?
)
Delegation unsafe: body of
✠ ✄ ✝ ☞assumption that this : Ctnr1.
Environmental Acquisition Revisited — POPL 2005 – p.24/30
Environmental Acquisition Revisited — POPL 2005 – p.25/30
If program P has type t, then evaluating P has one of the following results:
Environmental Acquisition Revisited — POPL 2005 – p.26/30
If program P has type t, then evaluating P has one of the following results:
Environmental Acquisition Revisited — POPL 2005 – p.26/30
Environmental Acquisition Revisited — POPL 2005 – p.27/30
We have placed demonstrated acquisition’s technical feasibility and placed it on a firm theoretical foundation.
acquisition in the context of a Java-like language.
conclusions about type safety.
assignment.
Environmental Acquisition Revisited — POPL 2005 – p.28/30
“incomplete context” exception is never generated?
Environmental Acquisition Revisited — POPL 2005 – p.29/30
Ownership types (Clarke et al):
Environmental Acquisition Revisited — POPL 2005 – p.30/30
Ownership types (Clarke et al):
aliasing
Environmental Acquisition Revisited — POPL 2005 – p.30/30
Ownership types (Clarke et al):
aliasing
Environmental Acquisition Revisited — POPL 2005 – p.30/30
Ownership types (Clarke et al):
aliasing
Environmental Acquisition Revisited — POPL 2005 – p.30/30
Ownership types (Clarke et al):
aliasing
exceptions
Environmental Acquisition Revisited — POPL 2005 – p.30/30
Thank you.
cobbe@ccs.neu.edu
Environmental Acquisition Revisited — POPL 2005 – p.31/30