Commit c3f3d12
Add tryTo evalue accessors (#19039)
Add tryTo accessors for each value. Previously, `toTensor` etc. abort
with ET_CHECK_MSG when the type mismatches.
API additions:
- Per-type: tryToInt, tryToDouble, tryToBool, tryToScalar, tryToString,
tryToTensor (already present, kept), tryToIntList, tryToBoolList,
tryToDoubleList, tryToTensorList, tryToListOptionalTensor,
tryToScalarType, tryToMemoryFormat, tryToLayout, tryToDevice.
Tag mismatch returns Error::InvalidType; null list/string payload
returns Error::InvalidState.
- Templated tryTo<T>() dispatcher mirroring to<T>(), via a new
EVALUE_DEFINE_TRY_TO macro kept adjacent to EVALUE_DEFINE_TO so drift
between the two surfaces is visible at review time.
- tryToOptional<T>() widened from Tensor-only to generic, delegating
to tryTo<T>() so it works for any supported payload type.
Tests cover success + mismatch paths for each new accessor, plus the
widened tryToOptional<T>() path.
Authored-with: Claude
---------
Co-authored-by: Github Executorch <github_executorch@arm.com>1 parent 75b31bb commit c3f3d12
3 files changed
Lines changed: 444 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
13 | 17 | | |
14 | 18 | | |
15 | 19 | | |
| |||
27 | 31 | | |
28 | 32 | | |
29 | 33 | | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
30 | 55 | | |
31 | 56 | | |
0 commit comments