Skip to content

Modular storage mode analysis#209

Open
melsman wants to merge 3 commits intomasterfrom
modular-sma
Open

Modular storage mode analysis#209
melsman wants to merge 3 commits intomasterfrom
modular-sma

Conversation

@melsman
Copy link
Copy Markdown
Owner

@melsman melsman commented Mar 19, 2026

This PR provides a modular version of the storage mode analysis where simple functions may be passed regions with storage mode atbot across compilation unit boundaries.

Instead of penalising all functions that are exported (by linking their region parameters to global regions in the region flow graph), we make it up to the caller to pass the appropriate storage mode (attop, atbot, or sat). When a call is made to a function in another program unit, we do not have detailed knowledge about the region flow graph related to the body of the function being called. Instead of querying the region flow graph, we shall be less precise in the determination and make use of the instantiation data available at the call site along with a few simple observations. Whereas it is always safe to pass attop for all region parameters, for simple functions that are not higher-order, we can pass atbot for a region parameter $\rho$ if $\rho$ is not locally live and if $\rho$ is not aliased with another parameter. Notice that the "not-aliased" property can be assured across multiple compilation units because top-level region type schemes (those for possibly exported functions) are closed wrt region and effect variables.

The PR also fixes issue #208 .

Copilot AI review requested due to automatic review settings March 19, 2026 16:16
@melsman melsman self-assigned this Mar 19, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the region/storage-mode analysis to better support modular compilation (allowing some region arguments to remain atbot across compilation-unit boundaries for “simple” functions) and addresses the storage-mode analysis miscompilation described in issue #208.

Changes:

  • Refactors effect “representation” queries by splitting represents into represents_no_gets vs represents_with_gets, and adjusts flow/analysis consumers accordingly.
  • Updates region-flow graph construction to incorporate GET effects (key to fixing the #208 scenario) and adjusts storage-mode inference for non-local function calls.
  • Replaces the removed EffVarEnv module usage with Effect.Map across several compiler components and updates the EFFECT API.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
src/Compiler/regions.mlb Removes Regions/EffVarEnv.sml from the regions MLB build.
src/Compiler/Regions/RegionStatEnv.sml Switches cone-closure traversal to represents_no_gets.
src/Compiler/Regions/RegFlow.sml Changes region-flow graph construction to use represents_with_gets and normalizes GET/PUT/MUT to regions.
src/Compiler/Regions/PhysSizeInf.sml Replaces EffVarEnv with Effect.Map.
src/Compiler/Regions/MulInf.sml Uses represents_no_gets when building multiplicity Phi.
src/Compiler/Regions/Mul.sml Uses Eff.Map and represents_no_gets for initial multiplicity data.
src/Compiler/Regions/LocallyLiveVariables.sml Removes no-op normalization plumbing; propagates livesets directly.
src/Compiler/Regions/Effect.sml Renames map type to Map; implements represents_no_gets / represents_with_gets; includes GET nodes in relevant traversals.
src/Compiler/Regions/EffVarEnv.sml Deletes the standalone EffVarEnv map module.
src/Compiler/Regions/EFFECT.sig Updates API: adds represents_no_gets/represents_with_gets, renames PlaceOrEffectMap to Map.
src/Compiler/Regions/DropRegions.sml Updates map usage to Eff.Map and uses represents_no_gets.
src/Compiler/Regions/AtInf.sml Adjusts non-local call handling to allow selective atbot across units; switches internal env maps to Eff.Map/Lvars.Map.
src/Compiler/Backend/SubstAndSimplify.sml Replaces EffVarEnv with Effect.Map.
src/Compiler/Backend/ClosConvEnv.sml Replaces EffVarEnv with Effect.Map.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

melsman and others added 2 commits March 19, 2026 17:30
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants