Repository navigation
Fix effect aliasing and provider selection - #1987
Merged
Merged
Conversation
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.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 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".
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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 effectnoalias, 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.noalias, and a call holds one lane copy per place.with (Key = value)chooses between providers. Auseslist names each key and binds each name once, and awithbinds 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 inuses. The rules are indocs/language/effects.md.