|
| 1 | +//! The `export` argument is deprecated under the [`experimental_spec_shaking_v2`] feature. |
| 2 | +//! |
| 3 | +//! The `export` argument on [`contracttype`], [`contracterror`], and [`contractevent`] controls |
| 4 | +//! whether a type contributes a contract spec entry. Under spec shaking v1 (the default), it is a |
| 5 | +//! retention hint: `export = false` suppresses the entry, hiding the type from the contract spec, |
| 6 | +//! and `export = true` forces one to be emitted. |
| 7 | +//! |
| 8 | +//! Under spec shaking v2, the final spec is instead determined by *reachability* from the contract |
| 9 | +//! boundary. The macros emit a spec entry and a marker for every type, and post-build tooling |
| 10 | +//! removes the entries for types that are not reachable from any public contract function. As a |
| 11 | +//! result, `export` no longer has any effect: it cannot hide a type that remains reachable from a |
| 12 | +//! public boundary (the entry is kept regardless), and it is redundant for a type that is already |
| 13 | +//! reachable. Worse, `export = false` can conflict with exact spec shaking by dropping a marker |
| 14 | +//! for an entry that is still reachable, leading to missing coverage. |
| 15 | +//! |
| 16 | +//! Setting `export` therefore now emits a deprecation warning at the macro call site, and the |
| 17 | +//! argument will be removed entirely in a future release. Default (v1) builds are unaffected. |
| 18 | +//! |
| 19 | +//! ## Migrating |
| 20 | +//! |
| 21 | +//! Remove the `export` argument from `contracttype`, `contracterror`, and `contractevent` |
| 22 | +//! annotations. A type that was hidden with `export = false` is filtered from the spec |
| 23 | +//! automatically when it is unused, and a type that was forced in with `export = true` is included |
| 24 | +//! whenever it is reachable. |
| 25 | +//! |
| 26 | +//! For example, a type used only inside a contract — never at a function boundary — was previously |
| 27 | +//! hidden from the spec with `export = false`: |
| 28 | +//! |
| 29 | +//! ``` |
| 30 | +//! use soroban_sdk::contracttype; |
| 31 | +//! |
| 32 | +//! #[contracttype(export = false)] // 👈 👀 hint to hide the unused type from the spec |
| 33 | +//! pub struct InternalState { |
| 34 | +//! pub counter: u32, |
| 35 | +//! } |
| 36 | +//! # fn main() {} |
| 37 | +//! ``` |
| 38 | +//! |
| 39 | +//! Under spec shaking v2, drop the argument. Because `InternalState` is never reachable from a |
| 40 | +//! public contract function, post-build tooling strips its spec entry automatically: |
| 41 | +//! |
| 42 | +//! ``` |
| 43 | +//! use soroban_sdk::contracttype; |
| 44 | +//! |
| 45 | +//! #[contracttype] // 👈 👀 no export argument; reachability determines the final spec |
| 46 | +//! pub struct InternalState { |
| 47 | +//! pub counter: u32, |
| 48 | +//! } |
| 49 | +//! # fn main() {} |
| 50 | +//! ``` |
| 51 | +//! |
| 52 | +//! [`contracttype`]: crate::contracttype |
| 53 | +//! [`contracterror`]: crate::contracterror |
| 54 | +//! [`contractevent`]: crate::contractevent |
| 55 | +//! [`experimental_spec_shaking_v2`]: crate::_features#experimental_spec_shaking_v2 |
0 commit comments