Skip to content

[codex] Add opt-in struct tag field resolution#11

Merged
myzie merged 1 commit into
mainfrom
codex/struct-tag-field-resolution
May 8, 2026
Merged

[codex] Add opt-in struct tag field resolution#11
myzie merged 1 commit into
mainfrom
codex/struct-tag-field-resolution

Conversation

@myzie
Copy link
Copy Markdown
Contributor

@myzie myzie commented May 8, 2026

Summary

Adds opt-in struct tag based field resolution with expr.WithStructTags(...) and the WithFieldTags(...) alias. When configured, struct fields resolve by tag names in priority order before falling back to Go exported field names, while default behavior remains unchanged.

Details

  • Supports comma-delimited tag names such as json:"email,omitempty".
  • Implements strict per-field precedence, expr:"-" hiding, tag-specific "-" behavior, and ambiguity errors for duplicate resolved names.
  • Wires tag-aware lookup through identifiers, selectors, selector-chain fast paths, callable struct fields, and suggestion hints.
  • Caches tag field plans per compiled program and struct type to avoid repeated reflect.VisibleFields scans.
  • Updates reference docs, examples, README, and LLM reference.

Performance

Focused benchmarks showed uncached tagged lookup was measurable, so this PR includes a cache:

  • Nested tagged selector: from ~630 ns/op and 14 allocs to ~76 ns/op and 0 allocs.
  • 32-field tagged struct: from ~9.4 us/op and 91 allocs to ~144 ns/op and 1 alloc.

Validation

  • go test ./...
  • go test -run '^$' -bench 'Benchmark_structTags' -benchmem -count=3
  • git diff --check

@myzie myzie force-pushed the codex/struct-tag-field-resolution branch from ffb8eb4 to 77546a3 Compare May 8, 2026 11:37
@myzie myzie merged commit ce16b4d into main May 8, 2026
@myzie myzie deleted the codex/struct-tag-field-resolution branch May 8, 2026 11:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant