Use std::optional/string_view #20213
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/20213
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: This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@pytorchbot label "release notes: none" |
|
Thanks for making this change! Does this remove all uses of There are a few clang-format errors coming from lintrunner that need to be cleaned up. |
|
@rascani I added more cleanup and fixed the linters. |
|
I'm sorry @cyyever, I gave you bad advice. We won't be able to remove the type aliases or header files as they are part of the public API and are subject to the API Life Cycle and Deprecation Policy. We'll need to mark them as deprecated first, and cannot remove them for 2 minor releases. Here's an example of how the optional aliases would look: I'll put up a separate PR for adding message support to ET_DEPRECATED, so ideally we could do: |
Hi @rascani, in that case do we close this PR for now? |
No, not unless any other maintainer objects to deprecating the optional/string_view aliases. When we add the ET_DEPRECATED macro, we'll start getting compiler warnings on all uses in the executorch codebase. The bulk of this PR is the migration of those uses to the std:: equivalents. We just need to revert the header file removals and add the ET_DEPRECATED macros. |
Migrate the remaining executorch::aten::optional callers (mostly the Cadence operators) to std::optional, then delete the deprecated torch::executor and executorch::runtime::etensor optional/nullopt aliases so they can't be reintroduced. portable_type/optional.h held only those aliases and is removed; exec_aten.h now includes <optional> directly. optional_test.cpp covered only the alias (now plain std::optional) and is dropped along with its build targets. The substantive changes are in runtime/core/exec_aten/exec_aten.h and the removal of runtime/core/portable_type/optional.h; everything under backends/cadence and kernels/ is the mechanical caller migration.
…_view Migrate the remaining executorch::aten::string_view callers (the data-map APIs and op_linalg_svd) to std::string_view, then delete the deprecated torch::executor and executorch::runtime::etensor string_view aliases. portable_type/string_view.h held only those aliases and is removed; exec_aten.h and scalar_type_util.h now include <string_view> directly. This parallels the optional cleanup in the previous commit. The data-map header signatures (NamedDataMap and its overrides) move together since the underlying type is unchanged.
The optional/string_view type aliases and their headers are public API under the API Life Cycle and Deprecation Policy, so they cannot be removed until two minor releases after being deprecated. Restore portable_type/optional.h and string_view.h (and their buck targets), now aliasing the etensor and legacy torch::executor names to std:: behind ET_DEPRECATED. The caller migration to std:: is kept; exec_aten.h and scalar_type_util.h retain the migrated std:: usages while re-including the restored headers so external users still resolve the deprecated names.
|
@rascani @nil-is-all Restored them and added ET_DEPRECATED |
Summary
This PR changes callers to use std::optional/string_view.
Test plan
Check whether the system can build.