Region Inference for an Object-Oriented Language Wei Ngan Chin 1,2 Joint work with Florin Craciun 1 , Shengchao Qin 1,2 , Martin Rinard 3 1 National University of Singapore 2 Singapore-MIT Alliance 3 MIT
Region-Annotated Core-Java region parameters for polymorphism constraint abstractions class invariant method precondition region constraint s
Inferring for Class Step 4 : Inherit constraint of superclass. Step 1 : Reserve first region for the receiver object ( this ). Step 2 : Keep regions of fields distinct for precision. Step 3 : No dangling property as class invariant.
Inferring for Class Step 1 : Reserve first region for the receiver object ( this ). Step 2 : Keep regions of fields distinct for precision. Step 3 : No dangling requirement as class invariant.
Inferring for Methods Step 3 : Localise regions that do not escape. Step 4 : Fix-point analysis for recursion. method precondition Step 2 : Gather constraints from method body. Step 1 : Region parameters from method signature.
(Object) Region Subtyping concept pioneered in Cyclone [PLDI02] an object w of type c <r,..> can be passed to a location v of type c <s,..> provided r º s (e.g. in assignment and parameter/result passing)
Example Without region subtyping, regions of a and b are forced to be equal . With region subtyping, these regions may be distinct .
Problem – Recursive Fields Recursive nodes being forced into the same region Some programs work better with recursive nodes in different regions …
(Field) Region Subtyping SOLUTION : Covariance for Read-Only Fields. Example: read-only mutable