Repository navigation
Feat/abi structs - #1606
Feat/abi structs#1606
Conversation
b78a757 to
df6b13f
Compare
|
@codex review |
Codex Review SummaryThis 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. |
🛡️ Codex Security Review · Automatically triggeredSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: df6b13fe2b
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ecd65c7f7e
ℹ️ 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".
ecd65c7 to
0e33603
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0e33603aa0
ℹ️ 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".
0e33603 to
83ec959
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 83ec959602
ℹ️ 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".
83ec959 to
c1e7bd0
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c1e7bd0cc0
ℹ️ 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".
c1e7bd0 to
31b3930
Compare
|
@cburgdorf I'm going to push a few fixes to this branch |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0cd45445b1
ℹ️ 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".
An `#[abi]` struct is lowered like a `msg` variant: it gets `AbiSize`, `AbiSpan<Sol>`, `Encode<Sol>` and `Decode<Sol>` impls that encode it as the Solidity tuple of its fields, plus `impl StaticAbi for S where <fields>: StaticAbi`. Generic `#[abi]` structs and `#[abi]` combined with `#[event]`/`#[error]` are rejected. `DynArray::get` decodes any element type: multi-word static elements are read at their head size and dynamic ones through their validated tail offset. `MemVec` stores any `StaticAbi` type at its head size; the new public `std::abi::StaticAbi` marker covers one-word values, tuples, fixed arrays and `#[abi]` structs of static types, so a `MemVec` of a dynamic type still fails to compile. `std::abi::dyn_array_from([..])` builds a `DynArray` of any element type from a fixed array, and `canonical_dyn_array` re-encodes a decoded array in canonical layout.
An #[abi] struct can now be an #[event] or #[error] field. The lowering generates impl SolCompat with the Solidity tuple type of the fields, built from std::abi::SolPunctuation literals and each field's <F as SolCompat>::S / SOL_TYPE, nested in chunks like event signatures. Previously such an event failed at MIR lowering with an internal CTFE error for TOPIC0. Generated impl consts must reify to a runtime value; SOL_TYPE is only consumed by CTFE for signature hashes, so the generated one is checked like hand-written impls instead.
A SolCompat value from the generic DynArray impl carries its type as (Item::S, String<2>) with the projection unnormalized, while the aggregate of an #[abi] struct containing DynArray<Item> names the normalized type. The shape check already skips expected types with projections; skip actual ones the same way.
Only the struct validator knew about the new `abi` attribute, so `#[abi]` on functions, enums, traits, modules and other items was silently accepted. Add an unsupported-target rule next to the `event` and `error` ones.
The StaticAbi markers stopped at eight-element tuples while core provides AbiSize and Encode through arity 16, so e.g. a MemVec of a fully static nine-element tuple was rejected. Cover one-element tuples and arities 9 to 16 as well.
…elds The sizing loop in canonical_dyn_array decoded every element only to measure it, and the encoding loop then decoded it again. Static elements now skip the sizing pass, as their size is fixed. Dynamic elements are decoded once and encoded into a scratch tail while sizing; the tails are then copied into place. Keeping the decoded values instead would need `T: Copy`, since the ownership checker cannot see that a loop moves each slot out only once, and `canonical_dyn_array` is meant to accept non-`Copy` elements too. For eight 32-byte `bytes` elements this lowers the gas of the call from 9686 to 8333, and from 1990 to 1683 for eight `uint256` elements. Zero-length fixed arrays are `StaticAbi`, so their decoders now return early instead of decoding a first element. The generated `Decode<Sol>` for `#[abi]` structs only defined `decode_payload`, so `decode_from_bounded` and `decode_from_prechecked_head` fell back to `decode_from`, which checks dynamic fields against the whole input rather than `input_len`. A dynamic field could thus read a tail outside the declared ABI region. The struct impls now pass `input_len` to every field, like the tuple and fixed-array impls. `StaticAbi` cannot be sealed, because `#[abi]` structs in any ingot implement it. A downstream impl for a dynamic type would make `MemVec` under-allocate and encode tails over neighbouring memory, so the `MemVec` constructors now revert with `Panic(0x01)` when `AbiSize::IS_DYNAMIC` is set. The check is constant and folds away for static types. `#![abi]` inside a module body is rejected like `#[abi] mod m`. An indexed fixed array, tuple or `#[abi]` struct event field needs Solidity's hashed topic of its encoding, which `#[event]` does not generate, so it failed with a type error in the generated emit body. Such fields, including ones hidden behind type aliases, are now reported at the field (10-0009), like indexed dynamic fields. Tuples implement `SolCompat` for arities 0 through 16, so `#[abi]` structs with tuple fields no longer fail their generated `SolCompat` bound. `canonical_dyn_array` returns right after the length word for zero-size elements such as `()` or an empty `#[abi]` struct, instead of looping over a length that costs the sender nothing to inflate. The fixed-array ABI codecs need `Copy` elements, as an array element cannot be moved out by index. `StaticAbi` for `[T; N]` now requires `T: Copy` too, and an `#[abi]`, `#[event]` or `#[error]` field holding a fixed array of a non-`Copy` type is reported once at the field (16-0008) instead of as trait errors in the generated code.
Semantic bodies of generic instances are substituted but not normalized, so a local of `impl<T> Tr2 for W<T>` can be typed `(<u8 as Tr>::A, u16)`. CTFE labelled aggregate values with that raw local type, and a concrete aggregate embedding one failed the child-type check with "constant child type differs from its aggregate field type". This was reachable on master without `#[abi]`. `eval_expr` now normalizes the result type against the frame's instance before building a value, and the verifier's actual-side projection skip is removed, since it disabled the check for whole subtrees.
Tuples implemented `AbiSpan` only up to arity 4 and `Decode` up to 12, while `AbiSize`, `Encode`, `SolCompat` and `StaticAbi` go up to 16. The generated `#[abi]` codec needs `AbiSpan` for every field, so a struct with a five-element tuple field failed to compile, and a `DynArray` of such tuples could not be decoded.
`msg`, `#[abi]` and `#[event]` lowering declared their generated type parameters as plain `D`, `I` and `L`. A field type spelled the same, a struct or an alias, then resolved to the parameter inside the generated bodies: an `#[abi]` struct with a field of type `D` failed trait resolution, and a `msg` field aliased to `D` produced internal borrow checking errors. The parameters now use `__fe_` generated names, like the generated value bindings.
The composite-elements fragment claimed `dyn_array_from` takes a fixed array of any element type; it requires `Copy` elements.
`payload_end` now delegates to `payload_end_with_input_len` with `input.len()` instead of repeating the whole field fold, which also drops the duplicate diagnostics of the second body. Generic argument lists are built with a new `GenericArgListId::given_types`, positional calls use `call_expr`, `u256` is built once, the two `Decode` bodies are generated explicitly instead of through a flag loop, and the `StaticAbi` and `SolCompat` impls share one field-bound helper. A desugar snapshot now covers the generated impls, including fields named like the generated parameters, and round-trips them through the analyzer.
`#[abi]` diagnostics were `#[error]` diagnostics (`ErrorLower`), and the non-`Copy` fixed-array field error of `#[event]` fields was reported under `#[error]` as well. `#[abi]` structs now have an `AbiStructLower` pass (18): generic structs are 18-0001, conflicting attributes 18-0002 and non-`Copy` fixed-array fields 18-0003. The fixed-array field error of an `#[event]` or `#[error]` struct is reported by that struct's pass, as 10-0010 or 13-0006. The field scan behind it is now a tracked query shared by the three passes and the body pass.
`abi_struct_event_emits` emitted two events and asserted nothing. The emits move to a test-runner fixture whose snapshot records the logs; their data matches `cast abi-encode` of the same Solidity values. The TOPIC0 comments of `Pair` and `OrdersEvent` are back next to their assertions.
`ErrorLower` and `SemanticBorrowck` once shared pass code 16, so one printed code could name two unrelated errors. A unit test now fails when two passes share a code.
`usize` and `isize` have ABI codecs and map to `uint256` and `int256` in the JSON ABI, but had no `SolCompat`, so an `#[abi]` struct with such a field failed its generated `SolCompat` impl, and they could not be event or error fields. They also lacked `TopicValue` for indexed event fields.
`reify_runtime_const_impl` matched a value's shape against the expected type as given. A trait constant's expected type can be an unnormalized projection, such as `<Key as SolCompat>::S` for `SolCompat::SOL_TYPE`, which is no tuple, so the generated `SOL_TYPE` of an `#[abi]` struct could not be reified. `check_impl_trait_const_bodies` worked around this by exempting any trait named `SolCompat` from the required-value check. The expected type is now normalized against the instance first, and the name-based exemption is removed.
A field whose type lacks an ABI trait made every generated impl report its own failure at the whole struct: ten errors for one field. The `AbiStructLower` pass now checks each field for `AbiSize`, `AbiSpan<Sol>`, `Encode<Sol>` and `Decode<Sol>` and reports the missing traits once at the field (18-0004). The generated impls of such a struct, or of a recursive one, are no longer diagnosed. A field without `SolCompat` no longer rejects the struct: it keeps its codec and just does not implement `SolCompat`, whose generated impl is not diagnosed. Where a Solidity type name is needed, an `#[event]` or `#[error]` field of an ABI-encodable type without `SolCompat` is now reported at the field (10-0011, 13-0007). Before, such an event or error passed checking and failed during MIR lowering with a CTFE error for its TOPIC0 or selector.
Generated names were `__fe_`-prefixed but still valid source identifiers, so a type spelled `__fe_D` or `__fe_I` in a field was captured by the generated type parameter, and a constant spelled like a generated local by that local. `HirBuilder` now collects the identifiers of the `msg`, `#[event]`, `#[error]` or `#[abi]` item it desugars, and generated names take a numeric suffix when the source mentions them. The encode locals `__tail`, `__head_pos`, `__field_N` and the `#[abi]` span fold's `__end` go through the same helper.
Where clauses now also hold const predicates, so the generated `StaticAbi` and `SolCompat` field bounds are `WhereClausePredicate::Type`.
0cd4544 to
e63cf77
Compare
Added the
#[abi]struct attribute. An#[abi]struct getsAbiSize,AbiSpan<Sol>,Encode<Sol>andDecode<Sol>implementations that encode it like the Solidity tuple of its fields, so Solidity structs such asPoolKeycan be used inmsgfields and return types, in arrays and inside other#[abi]structs without hand-written codecs.DynArray::getnow works for every ABI element type, including multi-word static structs and tuples and dynamic elements such asBytes.MemVecaccepts any static ABI element type. The newstd::abi::dyn_array_from([..])builds aDynArrayfrom a fixed array of copyable ABI elements (for example abytes[]), andstd::abi::canonical_dyn_arrayre-encodes a decoded array in canonical layout.