Conversation
There was a problem hiding this comment.
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
representsintorepresents_no_getsvsrepresents_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
EffVarEnvmodule usage withEffect.Mapacross several compiler components and updates theEFFECTAPI.
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.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR updates MLKit’s storage mode analysis to be more modular across compilation units, avoiding globally penalizing exported functions while still maintaining soundness. It also adds a regression test for issue #208 and updates the runtime to opportunistically reset regions when safe under the new analysis assumptions.
Changes:
- Implement modular storage-mode decisions at non-local call sites (and adjust region-flow/effect handling to account for GET effects where needed).
- Introduce
maybeResetRegionand use it in multiple runtime primitives to enable safe region resetting when atbot+inf is set. - Add regression test
test/sma.smlfor issue #208 and wire it into the test suite.
Reviewed changes
Copilot reviewed 24 out of 24 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| test/sma.sml | New regression reproducer for issue #208. |
| test/sma.sml.out.ok | Expected output for the new regression test. |
| test/all.tst | Registers the new test in the suite. |
| src/Runtime/Region.h | Declares maybeResetRegion. |
| src/Runtime/Region.c | Implements maybeResetRegion. |
| src/Runtime/String.c | Uses maybeResetRegion in string primitives; refactors concat/implode/explode paths. |
| src/Runtime/Posix.c | Uses maybeResetRegion and refactors local search logic types. |
| src/Runtime/IO.c | Uses maybeResetRegion for region-reset opportunities. |
| src/Runtime/Math.c | Uses maybeResetRegion before allocating result strings. |
| src/Compiler/regions.mlb | Removes EffVarEnv.sml from the build. |
| src/Compiler/Regions/EffVarEnv.sml | Deletes standalone map wrapper; replaced by Effect.Map. |
| src/Compiler/Regions/Effect.sml | Renames map to Map; splits represents into with/without GETs; includes GET in evaluation where needed. |
| src/Compiler/Regions/EFFECT.sig | Updates signature for new represents_* and Map. |
| src/Compiler/Regions/RegFlow.sml | Adjusts region-flow graph construction and removes global-connecting behavior for exported functions. |
| src/Compiler/Regions/AtInf.sml | Implements modular call-site storage-mode assignment (sma_modular_call) and related env changes. |
| src/Compiler/Regions/RegionStatEnv.sml | Switches to represents_no_gets in cone/closure computations. |
| src/Compiler/Regions/Mul.sml | Switches to Effect.Map and represents_no_gets. |
| src/Compiler/Regions/MulInf.sml | Switches to represents_no_gets. |
| src/Compiler/Regions/PhysSizeInf.sml | Switches to Effect.Map. |
| src/Compiler/Regions/DropRegions.sml | Switches to Effect.Map and represents_no_gets. |
| src/Compiler/Regions/LocallyLiveVariables.sml | Removes no-op normalization plumbing and simplifies liveset propagation. |
| src/Compiler/Backend/SubstAndSimplify.sml | Switches to Effect.Map. |
| src/Compiler/Backend/ClosConvEnv.sml | Switches to Effect.Map. |
| doc/manual/mlkit.tex | Expands documentation text for allocation points and CASE A wording. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This PR provides a modular version of the storage mode analysis where simple functions may be passed regions with storage mode
atbotacross 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 ($\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.
attop,atbot, orsat). 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 passattopfor all region parameters, for simple functions that are not higher-order, we can passatbotfor a region parameterThe PR also fixes issue #208 .