[RNE Rewrite] Deduplicate tokenizer result-unwrapping with a local unwrap helper - #1320
Merged
Conversation
…helper The five tokenizer host-object methods each hand-rolled the same `if (!result.ok()) throw` block around a tokenizers::Result. Replace them with a local `unwrap` helper, mirroring the one in core/model.cpp (that one is file-local and typed to executorch::runtime::Result, so it cannot be reused for tokenizers::Result).
12 tasks
barhanc
approved these changes
Jul 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The five
TokenizerHostObjectmethods (encode,decode,idToToken,tokenToId, and the encode path) each hand-rolled the same block around atokenizers::Result:Replaced with a local
unwraphelper in the file's anonymous namespace, mirroring the one already incore/model.cpp. That existing helper is file-local and typed toexecutorch::runtime::Result, so it cannot be reused here — the tokenizer returnstokenizers::Resultcarrying a distincttokenizers::Error(which is why this file already has its owntoString). Following the established per-file convention rather than hoisting a shared helper into core keeps the change scoped and leaves core untouched.Behaviour is identical: same error messages, same exceptions.
Split out of #1319 so the
std::spanrefactor and this cleanup can be reviewed independently. Part of the broader tokenizer host-object cleanup tracked in #1316.Introduces a breaking change?
Type of change
Tested on
Testing instructions
Behaviour-preserving; verification is compile-only, not yet run on a device.
tokenizer.cppcompiles clean under the project's strict warning set from.clangd:To exercise at runtime: the tokenizer screen in
apps/nlp.Related issues
Part of #1316
Checklist