Skip to content

transform: materialize attribute schemas as typed structs in attributes loops (custom attributes, rfcs#35) - #31201

Merged
medvednikov merged 15 commits into
vlang:masterfrom
metif12:feat/custom-attrs-typed-materialization
Oct 28, 2026
Merged

medvednikov merged 15 commits into
vlang:masterfrom
metif12:feat/custom-attrs-typed-materialization

Conversation

@metif12

@metif12 metif12 commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

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
VAttribute metadata view.

The review fixes cover generic and shadowed loop variables, imported schemas with matching local
names, and fields named name, arg, has_arg, or kind. Such schema fields take precedence in
a narrowed branch, while metadata methods such as .str() retain their existing behavior.
doc/custom_attributes.md describes 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 self builds exited zero at this exact revision. Every build
replaced ./v, and the following build used that result. An independent reviewer checked the
source, 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 master at 3f4b84544352c0ce0fc8607049b2064e7573e011, 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 9d347414cae98637e346ec454b87602451a2d270 retains its completed performance
comparison 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 self rebuilds 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.

@metif12
metif12 force-pushed the feat/custom-attrs-typed-materialization branch from 0e814a3 to 7fc5659 Compare October 28, 2026 07:12
metif12 and others added 12 commits October 28, 2026 10:42
…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 medvednikov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 medvednikov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@medvednikov
medvednikov merged commit c502d02 into vlang:master Oct 28, 2026
8 of 116 checks passed
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.

2 participants