Skip to content

Emit std::string_view/std::optional from codegen#21000

Open
cyyever wants to merge 1 commit into
pytorch:mainfrom
cyyever:codegen-std-string-view
Open

Emit std::string_view/std::optional from codegen#21000
cyyever wants to merge 1 commit into
pytorch:mainfrom
cyyever:codegen-std-string-view

Conversation

@cyyever

@cyyever cyyever commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Codegen still emitted the deprecated torch::executor::string_view/optional aliases; emit std::string_view/std::optional directly. Verified by building optimized_ops_lib and portable_ops_lib locally.

Authored with Claude.

@cyyever
cyyever requested a review from larryliu0820 as a code owner July 17, 2026 01:52
@pytorch-bot

pytorch-bot Bot commented Jul 17, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/21000

Note: Links to docs will display an error until the docs builds have been completed.

❗ 2 Active SEVs

There are 2 currently active SEVs. If your PR is affected, please view them below:

✅ No Failures

As of commit 5a8d13f with merge base 5c9cd91 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 17, 2026
@github-actions

Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

@nil-is-all nil-is-all added the enhancement Not as big of a feature, but technically not a bug. Should be easy to fix label Jul 17, 2026
@psiddh

psiddh commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

@claude review

@claude

claude Bot commented Jul 17, 2026

Copy link
Copy Markdown

Claude finished @psiddh's task in 53s —— View job


PR Review — Emit std::string_view/std::optional from codegen

  • Read changed file & diff
  • Analyze correctness & impact
  • Post review

Verdict: LGTM ✅ — small, well-scoped, and correct.

What changed

codegen/api/types/types.py:

  • stringT: torch::executor::string_viewstd::string_view
  • optionalT: torch::executor::optionalstd::optional

Correctness

This aligns codegen with the rest of the runtime, which already treats these as std types:

  • runtime/core/portable_type/string_view.h:19,29 and optional.h:20,33 define the torch::executor/executorch aliases as ET_DEPRECATED (= std::string_view / std::optional<T>). Emitting std:: directly is exactly the intended migration off those deprecated aliases.
  • The nearby OptionalCType.cpp_type() (types.py:61) already emits std::optional<...>, so this makes optionalT internally consistent with it.
  • The generated headers (codegen/templates/Functions.h:14, RegisterKernels.h:12) include exec_aten.h, which brings in <string_view>/<optional> and using std::string_view;, so the symbols resolve without extra includes.

Notes / nits

  • <optional> reaches generated code transitively (via exec_aten.hoptional.h). That's fine and matches how it worked before, so no include change is needed here.
  • Verification claim (building optimized_ops_lib + portable_ops_lib) is the right smoke test for this since it exercises the generated RegisterCodegenUnboxedKernels.cpp path. Worth also confirming any out-of-tree consumers that still reference torch::executor::string_view in codegen-generated signatures aren't broken — but within this repo the deprecated aliases remain defined, so ABI/source compatibility is preserved.

No blocking issues.
· branch codegen-std-string-view

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. enhancement Not as big of a feature, but technically not a bug. Should be easy to fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants