Add tryTo evalue accessors#19039
Conversation
|
Stack from ghstack (oldest at bottom): |
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/19039
Note: Links to docs will display an error until the docs builds have been completed. ❗ 1 Active SEVsThere are 1 currently active SEVs. If your PR is affected, please view them below: ❌ 1 Cancelled Job, 1 Unrelated FailureAs of commit 5c4e010 with merge base 069a793 ( CANCELLED JOB - The following job was cancelled. Please retry:
BROKEN TRUNK - The following job failed but were present on the merge base:👉 Rebase onto the `viable/strict` branch to avoid these failures
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This PR needs a
|
There was a problem hiding this comment.
Pull request overview
Adds a non-fatal, Result-returning “tryTo” API surface to executorch::runtime::EValue so callers can safely handle tag mismatches (and some invalid internal states) without ET_CHECK_MSG aborting—intended for paths that may process untrusted .pte inputs.
Changes:
- Introduce
tryToX()accessors for most EValue payloads (primitives, Scalar, Tensor, string, lists, and int-backed enums) plus a templatedtryTo<T>()dispatcher. - Generalize
tryToOptional<T>()to work for any supportedTby delegating totryTo<T>(). - Add unit tests exercising a subset of the new APIs (mainly primitives/Tensor/Scalar/ScalarType and some mismatch paths).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
runtime/core/evalue.h |
Adds Result-returning tryTo* accessors + templated dispatcher + generic tryToOptional<T>(). |
runtime/core/test/evalue_test.cpp |
Adds new tests for several tryTo* accessors and the generalized tryToOptional<T>(). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@claude review |
|
@claude review |
|
Claude finished @lucylq's task in 1m 34s —— View job Review of PR #19039: Add tryTo EValue accessors
Overall this is a well-structured addition. The approach of mirroring each Design
Issues
Test coverage gapsThe test file has solid coverage for primitives, Scalar, Tensor, and the templated
SummaryThe core implementation is correct and well-motivated. The |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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>
Add tryTo accessors for each value. Previously,
toTensoretc. abort with ET_CHECK_MSG when the type mismatches.API additions:
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.
EVALUE_DEFINE_TRY_TO macro kept adjacent to EVALUE_DEFINE_TO so drift
between the two surfaces is visible at review time.
to tryTo() so it works for any supported payload type.
Tests cover success + mismatch paths for each new accessor, plus the
widened tryToOptional() path.
Authored-with: Claude