Expand description
Capture Analysis for Closures
This module handles the analysis of closure captures - determining which values from the creation site need to be captured in a closure’s environment.
The key insight is that closures bridge two stack effects:
- Body effect: what the quotation body actually needs to execute
- Call effect: what the call site will provide when the closure is invoked
The difference between these determines what must be captured at creation time.
§Example
: add-to ( Int -- [Int -- Int] )
[ add ] ;Here:
- Body needs:
(Int Int -- Int)(add requires two integers) - Call provides:
(Int -- Int)(caller provides one integer) - Captures:
[Int](one integer captured from creation site)
Functions§
- calculate_
captures - Calculate capture types for a closure
- extract_
concrete_ types - Extract concrete types from a stack type (bottom to top order)