Qualify type and event names - #1970
leighmcculloch wants to merge 14 commits into
Conversation
|
semver:minor — the macros now generate two new public
Worth reviewer attention: UDT spec names now include the module path (e.g. This classification is advisory; the author and reviewer decide the release type.
|
|
Minor — the macros now emit new public inherent methods on every
This classification is advisory; the author and reviewer decide the release type.
|
|
semver:minor — the macros now generate new public inherent methods on every
No removals, renames, or signature changes to existing public items were found. This classification is advisory; the author and reviewer decide the final release type.
|
89d152f to
c2f3b14
Compare
|
semver:minor — the macros now emit two new public methods on every
Unsure: whether renaming the UDT name source from a hard-coded This classification is advisory; the author and reviewer decide the release type.
|
c2f3b14 to
f527fc9
Compare
|
semver:minor — the highest-impact single change is adding the public inherent method
This classification is advisory; the author and reviewer decide the release type.
|
|
Minor — the macros now generate a new
This classification is advisory; the author and reviewer decide the release type.
|
|
Classification: minor — the PR adds new public items to
Note: This classification is advisory; the author and reviewer decide the release type.
|
0a749fc to
89ce58f
Compare
7fc76f9 to
230b718
Compare
c68e1af to
bbf63e6
Compare
05771ce to
86fda69
Compare
9c4db5d to
fad3c8a
Compare
72c3689 to
20e9cab
Compare
b5e38e1 to
1e8cb2d
Compare
20e9cab to
6d052e1
Compare
1e8cb2d to
db078a5
Compare
db078a5 to
7093a64
Compare
ee8ba41 to
44ae8ca
Compare
…-names # Conflicts: # Cargo.lock # Cargo.toml # soroban-sdk-macros/src/derive_event.rs # soroban-sdk/src/tests/contract_udt_raw_identifier.rs # tests-expanded/test_attributes_tests.rs # tests-expanded/test_attributes_wasm32v1-none.rs # tests-expanded/test_events_ref_tests.rs # tests-expanded/test_events_ref_wasm32v1-none.rs # tests-expanded/test_events_tests.rs # tests-expanded/test_events_wasm32v1-none.rs # tests-expanded/test_spec_lib_tests.rs # tests-expanded/test_spec_lib_wasm32v1-none.rs # tests-expanded/test_spec_shaking_v2_tests.rs # tests-expanded/test_spec_shaking_v2_wasm32v1-none.rs # tests/fuzz/fuzz/Cargo.lock # tests/fuzz/fuzz/Cargo.toml # tests/fuzz_afl/fuzz/Cargo.lock # tests/fuzz_afl/fuzz/Cargo.toml
Note
Part of a stack of PRs that must merge in this order.
A first group of PRs change contract specs so that they are produced at compile time instead of at proc-macro execution time. This provides the foundation to construct the specs from information that is only known at compile time, like the fully qualified name of a type:
A second group of PRs changes the type names that the sdk stores in specs are fully qualified type names, and then the cli reduces them down to unique simple identifiers. During the contract build the types are given names like
::mycrate::mymod::MyTypeinstead ofMyType. Then the cli reduces them back down to simple names after spec shaking. Qualified type names make it possible to uniquely identify types in the spec, even when they have the same name. This resolves several problems with contract specs the type identify problem (#1570), type aliases limitations (#1857 #1063), and optimise spec shaking data section size (#1978):Note that downstream clients and SDKs should see no, or little, change because the cli will during the build process reduce the fully qualified names back to simple unique names. Contracts that had colliding type names, which meant they could not be used with clients, will now work.
A third group of PRs are an optimisation to spec shaking v2, and will use the new unique type names to shake type specs by reachability, producing a dependency graph (thanks @mootz12), so that only spec entries that can't be reached from fns, like errors and events, get spec markers from dead-code-elimination:
What
Name a user-defined type in the contract spec by its Rust path rather than by its identifier. Each type gains a
spec_type_nameconst fn returningmodule_path!()then its own name, and both the type's own definition entry and every reference to it take the name from that fn.Examples
Generated Type Qualified Names and Spec XDR
Why
A bare name is not enough to tell two user-defined types apart: two crates, or two modules of one crate, can each define a type with the same name, and a spec that names both simply cannot distinguish between them.
This was once rare, but as contracts on Soroban are getting larger, and as libraries are showing up in the ecosystem, this is becoming more common. This does happen with error types more frequently but the impact has been minimal to none in practice.
Close #1570
Close #1857
Close #1063
Close #1978