Skip to content

Fix effect aliasing and provider selection - #1987

Merged
sbillig merged 10 commits into
argotorg:masterfrom
sbillig:effects/provider-aliasing
Nov 12, 2026
Merged

sbillig merged 10 commits into
argotorg:masterfrom
sbillig:effects/provider-aliasing

Conversation

@sbillig

@sbillig sbillig commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator

A call checked its arguments against each other and against its effects, but not its effects against each other. A caller could give one call overlapping effects (with (ledger.log, mut ledger) { f() }), while lowering marked every effect noalias, held a packed lane copy per effect and passed read-only snapshot effects by value, so checked programs lost storage writes or read stale values. Providers were also tie-broken by matching binding names to the callee's effect labels.

  • A call's effects now conflict as its arguments do, and the error names both. A function takes its distinct effects to be disjoint, as its parameters are. Effects whose keys one provider may satisfy (generic keys that may be one type, trait keys) may share a place: they lose noalias, and a call holds one lane copy per place.
  • A read-only effect of a snapshot type is a copy taken at the call, as a snapshot argument is.
  • One provider per key per scope: the name tie-break is gone, and with (Key = value) chooses between providers. A uses list names each key and binds each name once, and a with binds each key once.

Newly rejected: overlapping providers such as with (x.log, mut x), a storage effect beside a capability that reaches all state, and a key or name listed twice in uses. The rules are in docs/language/effects.md.

An effect is identified by its key: a caller provides one value per key,
so `uses (x: mut u256, y: mut u256)` gave both effects one provider, or
picked them by name. A function's `uses` list, with its implementation's
row spliced in, and an implementation's row now name each key once.
Distinct generic keys (`T`, `U`) and distinct rows stay allowed.
When two providers in one frame satisfied an effect, the one whose
binding name matched the callee's effect label won, so renaming a local
or a label silently changed the provider. Two providers of one key in a
frame are now ambiguous; `with (Key = value)` chooses one, and the
ambiguity error says so. Two keyed bindings of one key in one `with` are
rejected.
A call checked its arguments against each other and against its
effects, but not its effects against each other, so
`with (ledger.log, mut ledger) { f() }` was accepted, and the callee had
to treat any two of its effects as overlapping. That rejected iterating
a view of one effect while writing another of an unrelated type.

A call's effects now conflict as its arguments do, and the error names
both. A callee takes distinct effects to be disjoint, except effects
whose keys one provider may satisfy (generic keys that may be one type,
trait keys): those are one place, whole, or disjoint, and a caller may
give them one provider. Fixtures that provided a storage place beside a
reentrant or raw storage capability, or two raw storage places, now
copy or split them.
An instance's effects whose keys one provider may satisfy (two of one
key from composed rows, generic keys that are one type, trait keys) may
be one place. Lowering still marked each `noalias` (and `readonly` when
read-only), copied a read-only snapshot one by value, and held a lane
copy per argument, so a write through one effect was lost or invisible
through another:

    fn pair<T: Bump, U: Bump>() uses (x: mut T, y: mut U)
    with (packed_field) { pair<u8, u8>() }   // y's copy overwrote x's

Such effects now get neither attribute, are passed by place, and a call
holds one lane copy per place it passes.
Add `docs/language/effects.md`: keys, one provider per key per scope, and
the call's effects following the arguments' aliasing rule. Update the
access checker architecture notes on domains and lowering.
A packed field provided as a `mut` effect beside `RawStorage` or `RawOps` is rejected at the call; a memory copy of it is accepted.
A read-only effect of a snapshot type was a copy only from memory, and
it conflicted with an overlapping `mut` effect of the same call, unlike a
snapshot view argument: `f(c.n, mut c)` is accepted. Such an effect of a
called function or closure is now a copy taken at the call in every
space. The call checks its read against open accesses only, a session
does not reserve its place, and it is never a shared place. So
`with (C = c, u256 = c.n)` satisfies `uses (n: u256, c: mut C)`, and the
callee reads `c.n` as it was at the call; a storage `Address` is provided
beside `mut Call` again.
`uses (s: Store, s: Log)` was accepted, and the body saw only the last
`s`, though callers still provided both. A function's `uses` list with its
implementation's row spliced in, a row, a contract's, an `init`'s and a
recv arm's now bind each name once (3-0093). Row entries bind no name; a
declaration without a body is not checked, as an effect hiding a
parameter (8-0134) is not.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-12T01:32:29.158725Z b2ee8be New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fc479349d8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/mir/src/runtime/lower/body.rs Resolved
Effects that are one place share one lane copy, and every effect after
the first took the address of the whole copy. With a provider inside a
packed element, `with (mut arr[1].val) { pair<u32, u32>() }` for
`arr: SolArray<Uint24>`, the second effect got the `Uint24` copy, and
its coercion to a `u32` reference panicked. Cache the place the first
effect resolved in the copy, and address it for each effect.
@sbillig
sbillig merged commit aa0a5d8 into argotorg:master Nov 12, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant