Commit 95914bb
authored
Retain panic-only error enums in spec shaking v2 (#1852)
### What
Add a `SpecShakingMarker` bound to `Env::panic_with_error` under
`experimental_spec_shaking_v2` and call `I::spec_shaking_marker()`
before erasing the user's type via `.into()`. Share the body with the
non-feature build via a private `panic_with_error_inner` that takes the
already-converted `internal::Error`.
Add tests in `tests/spec_shaking_v2/`:
- `with_panic_error` + `UsedPanicErrorEnum` — error enum used only via
`panic_with_error!`; asserts the spec entry is retained.
- `with_assert_error` + `UsedAssertErrorEnum` — same, via
`assert_with_error!`.
- `with_panic_raw_error` — passes a raw `soroban_sdk::Error` to
`panic_with_error!`; regression check that the new bound does not break
callers using the un-typed error.
- `UnusedPubError` — a `#[contracterror]` enum referenced nowhere;
asserts it is correctly shaken out of filtered entries.
### Why
Closes #1817.
Spec shaking v2 keeps a type's `contractspecv0` entry only if its
`SpecShakingMarker::spec_shaking_marker()` survives DCE, and the only
paths that call the marker are the v2 blanket impls of
`IntoValForContractFn` (return values) and `TryFromValForContractFn`
(parameters). A contract that defined a `#[contracterror]` enum and used
it only via `panic_with_error!` or `assert_with_error!` — without ever
appearing in a `Result<_, E>` return type — had no live caller for the
marker, so the marker function was eliminated and the spec entry
stripped from the WASM, even though the enum is part of the contract's
observable error interface.1 parent 4c4831e commit 95914bb
7 files changed
Lines changed: 3388 additions & 83 deletions
File tree
- soroban-sdk/src
- tests-expanded
- tests/spec_shaking_v2/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
290 | 290 | | |
291 | 291 | | |
292 | 292 | | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
293 | 308 | | |
294 | 309 | | |
295 | | - | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
296 | 316 | | |
297 | 317 | | |
298 | 318 | | |
| |||
0 commit comments