Repository navigation
transform: materialize attribute schemas as typed structs in attributes loops (custom attributes, rfcs#35) - #31201
Conversation
… values (custom attributes, rfcs#35)
…es loops (custom attributes, rfcs#35)
0e814a3 to
7fc5659
Compare
…tions `$for a in field.attributes` inside `$for field in T.fields` was expanded over the attributes of the field's type, and `$for a in value.attributes` over nothing: the field clone rewrote the loop source to the field type, and the value clone left a source that names no declaration. Both clones now unroll such a loop over the attributes of the field or enum value being unrolled. Field and enum value attributes were also built from the legacy strings alone, which unquote whole-string attributes, so `@['a: b']` read as `a` with argument `b`, `@['x\x41y']` kept its escape and `@['legacy']` or `r'...'` arguments had the plain kind. The parser now keeps the attribute kinds of struct, anonymous struct and enum fields next to those strings (a new NodePayload.attribute_kinds slot, which fits in existing padding), and the transform passes them to comptime_attribute_metas_from_raw like the declaration path does. The legacy `.attrs` strings and vfmt output do not change. Add comptime_field_attributes_view_test.v, update the field attributes characterization test, and fix the doc example and trailing newline.
medvednikov
left a comment
There was a problem hiding this comment.
Separate independent source review and exact-head three-self audit approve this change under the maintainer's requested build-only premerge policy. Three consecutive plain ./v self rebuilds passed, each invoking the preceding output compiler under normal vself policy. Review findings are addressed. Larger correctness and performance suites are deferred until this PR batch merges; no new performance measurement is claimed.
medvednikov
left a comment
There was a problem hiding this comment.
The current-master integration and original typed-attribute fixes are independently approved at this exact commit. A separate actual audit verified three NEW consecutive plain ./v self rebuilds of this integrated head, with raw zero-exit logs, source/runtime identities and executable chaining under normal vself policy. The original source branch and fast-forward push are independently verified. Dependency #31200 is merged. Larger correctness and performance suites are deferred at the maintainer's request; prior measurements remain qualified to their recorded older heads.
Materialize a registered attribute schema as its typed struct inside a narrowed compile-time
attribute loop. Positional, named, and grouped arguments keep their schema identity; lookup uses
the schema's defining module. Legacy attributes and copies of loop variables retain the existing
VAttributemetadata view.The review fixes cover generic and shadowed loop variables, imported schemas with matching local
names, and fields named
name,arg,has_arg, orkind. Such schema fields take precedence ina narrowed branch, while metadata methods such as
.str()retain their existing behavior.doc/custom_attributes.mddescribes the supported scalar field types and narrowing rules.The follow-up fixes reset enum reflection's module at file boundaries and retain compact raw
attribute metadata until a typed view is consumed. The composition regression checks imported
enums and schema identity together with legacy metadata.
The final representation keeps schema payloads cold and uses compact module identities. Schema
state remains private to each worker, while immutable schema instances can be shared by reflected
values without changing narrowing or legacy metadata behavior.
Depends on #31200. Current revision:
9b90e5884d873440408429d82b82618711388cee.Three consecutive normal
./v selfbuilds exited zero at this exact revision. Every buildreplaced
./v, and the following build used that result. An independent reviewer checked thesource, raw build logs, executable chain, runtime files, environment, and original public branch.
The normal self-build policy includes its existing internal bootstrap behavior.
Broad compiler suites are deferred to the combined run after the PR batch is merged. No broad
suite or matched production/performance result is claimed for this revision.
This head integrates actual
masterat3f4b84544352c0ce0fc8607049b2064e7573e011, including#31200, #31230, and #31231. Independent source review verified the complete resulting tree against
that base plus the approved typed-attribute changes, preserving all unrelated master changes.
The three self-builds above ran on this integrated head.
The earlier revision
9d347414cae98637e346ec454b87602451a2d270retains its completed performancecomparison and HOLD: on the fixed 562-file, 559,990-line workload, median instructions increased
0.1914379778%, median paired instructions increased 28,056,122, and six of ten pairs were worse.
That result prompted this representation correction; the correction has not been measured.
Earlier focused test and output results remain evidence only for their exact recorded revisions.
This is part of the custom-attribute work in vlang/rfcs#35.
Pre-merge validation at
9b90e5884d873440408429d82b82618711388cee: three consecutive./v selfrebuilds passed, each invoking the preceding output compiler under normal vself policy. The maintainer requested larger suites after this PR batch merges; any earlier pending suite lists above are deferred coverage rather than merge prerequisites.