Lecture, Tutorial
Inferring Locality in OCaml | OCaml Unboxed
- The OCaml compiler plans to prefer local allocation for non-escaping variables once inference is finalized post-type checking, anticipating improved future allocation behavior compared to global allocation.
- Future inference logic intends to select the most permissive local parameter choice for function arguments to accept both local and global values, while prioritizing global result types for return values to enhance utility in external contexts.
- Integers are expected to support mode crossing without error due to their immediate value representation, though current mechanisms may not implicitly handle integer mode crossing in operations like
pluswithout explicit annotations, potentially introducing fragility. - Jane Street is developing an improvement to enable finer-grained control over which types can mode cross, addressing the current limitation where local values cannot be automatically converted to global ones without external tools.
- Users may face a specific implementation rejection scenario regarding forgetting local requirements (e.g., assigning
HtoJ) that is currently uncertain but expected to be resolved by the time of future video release. - While the system is designed to automatically determine necessary modes without explicit annotations, the absence of standard library support for locals means operations involving standard functions could inadvertently force values to become global.
- Local annotations impose distinct constraints: return value annotations require the caller to ensure non-escaping behavior, whereas parameter annotations impose requirements on the function implementation.
- Function signature conversions involving modes are expected to have asymmetric safety outcomes: converting a local-returning function to global is safe as it adds an already satisfied caller requirement, while converting a local-parameter function to global is expected to fail as it attempts to remove an implementation requirement that cannot be imposed retroactively.