Multiple GC roots per compilation unit #262
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This patch is a subset of #178.
At present, there is a single GC root per compilation unit (corresponding to the toplevel module block), and the [caml_globals] array lists all such roots.
This patch permits there to be more than one root per compilation unit by turning the members of [caml_globals] themselves into lists.
The motivation without flambda is to be able to statically allocate mutable values.
With flambda, this patch is essential. Flambda does not use the existing "native code" compilation strategy for modules as it is not well-suited for optimization (scattered side effects, "global" table of globals, etc). Instead, the bytecode compilation strategy is used, and values required to be assigned symbols (for example, fields of a toplevel module, to avoid them appearing in closures) are lifted out. In the case where such values are non-constant they are handled by pre-allocating a one-field block (assigned to a symbol) using an "initialize symbol" construction; the block is filled in after evaluation of the (potentially side-effecting) defining expression. Such blocks must be registered with the GC; hence the need for this patch. (For those who are wondering, this method of compilation also circumvents the previously-seen problem of excessive register pressure if the bytecode strategy is applied to large modules.)