Qualify user-defined type names - #1970
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.
|
| type_: ScSpecTypeDef::Udt(ScSpecTypeUdt { | ||
| // See module doc comment: resolved through the type | ||
| // system to the referenced type's fully qualified | ||
| // definition path — the alias `Renamed` never appears. | ||
| name: "soroban_sdk::tests::contract_udt_struct_aliased_import::inner::Inner" | ||
| .try_into() | ||
| .unwrap(), |
There was a problem hiding this comment.
@mootz12 Using type_name means that this PR also fixes the type aliasing issue demonstrated in the following PR that you pointed out:
|
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
Note
Part of a stack of PRs that must merge in this order.
A first group of PRs deliver const-encoded contract specs, so that contract specs are produced at compile time instead of at proc-macro execution time. This provides the foundation for the capability to construct the specs from information that is not known at proc-macro execution and only known at compile time, like the fully qualified name of a type:
A second group of PRs deliver fully qualified type names in contract specs. Instead of a type having the name
Contextit will have the namesoroban_sdk::auth::Context. 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):What
Name a user-defined type in the contract spec by its Rust path rather than by its bare name. 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. Client generation derives an identifier from the last segment of a qualified name.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
Flag, and a spec that names both simplyFlagcannot say which is which. This was once rare, but as contracts on Soroban are getting larger, and as libraries are showing up in the ecosystem, this is becoming much more common. The module path is the part that distinguishes them, and only the compiler knows it, because a proc macro sees the tokens of the type it expands and not the module those tokens sit in. Emittingmodule_path!()for expansion where the type is defined is what makes the path reachable at all, and it is why the name is assembled at const evaluation rather than in the macro. That is also why this depends on #1974: once the name is only resolved at const evaluation, a spec shaking marker hashed in the macro no longer matches the entry the wasm actually carries, and every user-defined entry gets shaken out.Close #1570
Close #1857
Close #1063
Close #1978
Known limitations
A spike in a client demonstrating how to handle the new fully qualified names is required.