1.47k likes | 1.56k Views
A Step-Indexed Model of Substructural State. Matthew Fluet Cornell University Amal Ahmed Greg Morrisett Harvard University. A Step-Indexed Model of Substructural State. Matthew Fluet Cornell University Amal Ahmed Greg Morrisett Harvard University. Introduction.
E N D
A Step-Indexed Model of Substructural State Matthew Fluet Cornell University Amal Ahmed Greg Morrisett Harvard University
A Step-Indexed Model ofSubstructural State Matthew Fluet Cornell University Amal Ahmed Greg Morrisett Harvard University
Introduction • Mutable state is here to stay
Introduction • Mutable state is here to stay • high-level – I/O, data structures • low-level – virtual machines, garbage collector
Introduction • Mutable state is hard to control
Introduction • Mutable state is hard to control • C / Java / SML – unrestricted objects
Introduction • Mutable state is hard to control • Various forms of uniqueness have appeared as a means to “tame” state
Introduction • Mutable state is hard to control • Various forms of uniqueness have appeared as a means to “tame” state • Clean – uniqueness types • I/O operations in a purely-functional language • Cyclone – unique pointers • fine-grained memory management • Vault – unique keys • resource management protocols
Introduction • Mutable state is hard to control • Various forms of uniqueness have appeared as a means to “tame” state • Clean – uniqueness types • I/O operations in a purely-functional language • Cyclone – unique pointers • fine-grained memory management • Vault – unique keys • resource management protocols
Introduction • Mutable state is hard to control • Unique objects alone are too restrictive
Introduction • Mutable state is hard to control • Unique objects alone are too restrictive • Only tree-like data structures • Only single paths to a unique object
Introduction • Mutable state is hard to control • Unique objects alone are too restrictive • Only tree-like data structures • Only single paths to a unique object fun f () = … lr … fun g () = … lr … lr -- unique resource
Introduction • Mutable state is hard to control • Unique objects alone are too restrictive • Only tree-like data structures • Only single paths to a unique object fun f () = … lr … fun g () = … lr … lr -- unique resource
Introduction • Mutable state is hard to control • Unique objects alone are too restrictive • Cyclone and Vault allow programs to store unique objects in shared objects
Introduction • Mutable state is hard to control • Unique objects alone are too restrictive • Cyclone and Vault allow programs to store unique objects in shared objects fun f () = … ls … fun g () = … ls … ls lr -- shared object lr -- unique resource
Introduction • Mutable state is hard to control • Unique objects alone are too restrictive • Cyclone and Vault allow programs to store unique objects in shared objects • Safety of mixed objects requires some restrictions
Introduction • Mutable state is hard to control • Unique objects alone are too restrictive • Cyclone and Vault allow programs to store unique objects in shared objects • Safety of mixed objects requires some restrictions Cyclone and Vault have different interpretations of “unique” and “shared”
Introduction • Mutable state is hard to control • Unique objects alone are too restrictive • Cyclone and Vault allow programs to store unique objects in shared objects • Safety of mixed objects requires some restrictions Cyclone and Vault have different interpretations of “unique” and “shared” So, they have different sets of restrictions(i.e., type-systems)
Introduction How do we compare and evaluate these languages? • Mutable state is hard to control • Unique objects alone are too restrictive • Cyclone and Vault allow programs to store unique objects in shared objects • Safety of mixed objects requires some restrictions Cyclone and Vault have different interpretations of “unique” and “shared” So, they have different sets of restrictions(i.e., type-systems)
Introduction Can we generalize the interpretations and restrictions? • Mutable state is hard to control • Unique objects alone are too restrictive • Cyclone and Vault allow programs to store unique objects in shared objects • Safety of mixed objects requires some restrictions Cyclone and Vault have different interpretations of “unique” and “shared” So, they have different sets of restrictions(i.e., type-systems)
Introduction Can we definean expressivetarget language? • Mutable state is hard to control • Unique objects alone are too restrictive • Cyclone and Vault allow programs to store unique objects in shared objects • Safety of mixed objects requires some restrictions Cyclone and Vault have different interpretations of “unique” and “shared” So, they have different sets of restrictions(i.e., type-systems)
Introduction • We study a core language with mutable references
Introduction • We study a core language with mutable references • deallocation of references • strong (type-varying) updates • storage of unique objects in shared references
Introduction • We study a core language with mutable references of all qualifiers
Introduction • We study a core language with mutable references of all qualifiers • Unrestricted – like C / Java / SML • Affine – like Clean and Cyclone • Linear – like Vault
Introduction • We study a core language with mutable references of all qualifiers • Unrestricted – like C / Java / SML • Relevant • Affine – like Clean and Cyclone • Linear – like Vault
Introduction • We study a core language with mutable references of all qualifiers • Unrestricted – like C / Java / SML • Relevant • Affine – like Clean and Cyclone • Linear – like Vault
Outline • A Substructural Type System • … with References • Model Teaser
Structural Properties • Conventional type systems satisfy • Exchange • use typing assumptions in any order • Contraction • use typing assumptions more than once • Weakening • use typing assumptions less than once
Structural Properties • Conventional type systems satisfy • Exchange • use typing assumptions in any order • Contraction – Copy • use typing assumptions more than once • Weakening – Drop • use typing assumptions less than once
Structural Properties • Substructural type systems fail to satisfy • Exchange • use typing assumptions in any order • Contraction – Copy • use typing assumptions more than once • Weakening – Drop • use typing assumptions less than once
Structural Properties • Substructural type systems fail to satisfy • Exchange • use typing assumptions in any order • Contraction – Copy • use typing assumptions more than once • Weakening – Drop • use typing assumptions less than once
Substructural Qualifiers Linear Affine Drop Relevant Copy Unrestricted Drop Copy
Substructural Qualifiers Unique objects – may be “used”at most once Linear Affine Drop Relevant Copy Unrestricted Drop Copy Shared objects – may be “used” more than once
Substructural Qualifiers Unique objects – may be “used”at most once Linear Affine Drop Relevant Copy Unrestricted Drop Copy Shared objects – may be “used” more than once
Substructural Qualifiers Unique objects – may be “used”at most once Linear Affine Drop Relevant Copy Unrestricted Drop Copy Shared objects – may be “used” more than once
Substructural Qualifiers Unique objects – may be “used”at most once Linear Affine Drop Relevant Copy Unrestricted Drop Copy Shared objects – may be “used” more than once
Substructural Qualifiers Essential objects – must be “used”at least once Linear Affine Drop Relevant Copy Inessential objects – may be “used” less than once Unrestricted Drop Copy
Substructural Qualifiers Essential objects – must be “used”at least once Linear Affine Drop Relevant Copy Inessential objects – may be “used” less than once Unrestricted Drop Copy
Substructural Qualifiers Essential objects – must be “used”at least once Linear Affine Drop Relevant Copy Inessential objects – may be “used” less than once Unrestricted Drop Copy
Substructural Qualifiers Essential objects – must be “used”at least once Linear Affine Drop Relevant Copy Inessential objects – may be “used” less than once Unrestricted DropCopy
A Substructural Type System • Qualifiers q ::= U j R j A j L • PreTypes t::= 1jt1t2jt1(t2 • Types t::= qt
A Substructural Type System • Qualifiers q ::= U j R j A j L • PreTypes t::= 1jt1t2jt1(t2 • Types t::= qt How maythe value be used?
A Substructural Type System • Qualifiers q ::= U j R j A j L • PreTypes t::= 1jt1t2jt1(t2 • Types t::= qt How often maythe value be used? How maythe value be used?
Copy with Pairs copyUhLv1,Lv2i!hUhLv1,Lv2i, UhLv1,Lv2ii U(Lt1Lt2) U(At1At2)
Copy with Pairs copyUhLv1,Lv2i!hUhLv1,Lv2i, UhLv1,Lv2ii U(Lt1Lt2) U(At1At2) hv1, v2i may be used more than once
Copy with Pairs copyUhLv1,Lv2i!hUhLv1,Lv2i, UhLv1,Lv2ii U(Lt1Lt2) U(At1At2) hv1, v2i may be used more than once
Copy with Pairs copyUhLv1,Lv2i!hUhLv1,Lv2i, UhLv1,Lv2ii U(Lt1Lt2) U(At1At2) v1 and v2 may be used more than once
Copy with Pairs copyUhLv1,Lv2i!hUhLv1,Lv2i, UhLv1,Lv2ii U(Lt1Lt2) U(At1At2) v1 and v2 may be used more than once
Copy with Pairs copyUhLv1,Lv2i!hUhLv1,Lv2i, UhLv1,Lv2ii U(Lt1Lt2)U(At1At2)