Fold 5 StringId accessors into get<Tag> with role tags#46
Merged
Conversation
Introduce get_storage<Tag>::type trait to disambiguate tag-based get<> specializations. Add role tags Name/Display/SourceDir/ InstructionPattern (storage type StringId) and their specializations. Delete 5 named accessors now covered by the template: - get_name / get_display_str / get_source_dir / get_instruction_pattern (these returned string_view via pool.get) - get_display_id (returned StringId directly) Callers that want string_view wrap via global_pool().get(...); callers that want StringId use the template result directly. Four call sites in cmd_build.cpp (pool.intern(pool.get(stored_id))) become direct StringId access, eliminating the idempotent round-trip. Binary text drops 264 bytes (435,278 → 435,014). The round-trip elimination in cmd_build.cpp serialization removes real work. Public API: 39 → 34 named functions + 2 templates (8 scalar + 3 view specializations). Down from 57 original. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
Extend
get<Tag>to cover StringId-returning scalar properties by introducing aget_storage<Tag>::typetrait (mirroringview<Tag>'s design). Add 4 role tags (Name,Display,SourceDir,InstructionPattern), specialize them to returnStringId, and delete the 5 named accessors they replace.Deleted:
get_name,get_display_str,get_source_dir,get_instruction_pattern(all returnedstring_viewvia pool lookup)get_display_id(returned rawStringId)Principle:
view<Tag>is for arrays of semantic values; string-as-char-range doesn't fit. But storage-honest StringId access fitsget<Tag>cleanly — the tag disambiguates by role, and callers that wantstring_viewadd an explicitglobal_pool().get(...).Mechanism
get<T>was previously "T = return type" dispatch (worked because the 4 tags were unique scalar types). This PR generalizes to trait-based dispatch:Existing 4 specializations (
NodeType,NodeFlags,Hash256,OutputAction) are unchanged at call sites — their trait entries map the tag to itself. New 4 specializations use role tags mapping toStringId.Free win: round-trip elimination
Four call sites in
cmd_build.cppwere doingpool.intern(pool.get(stored_id)):That's removing a pool lookup + re-intern per file-node and per command during serialization.
Size impact
putupbinary text: 435,278 → 435,014 bytes (-264 bytes)Public API
Before: 39 named functions + 2 templates (4 + 3 specializations)
After: 34 named functions + 2 templates (8 + 3 specializations)
Original starting point was 57 named functions. This is -5 named, +4 specializations net.
Test plan
make test— 23592 assertions passmake formatcleanmake iwyu— no dead includes🤖 Generated with Claude Code