Skip to content

Audit §29.11's reserved words: every word that only opens a declaration becomes contextual (candidates: module, union, opaque, global, extend, select, spawn) #3132

Done

Description

@ehartford

Part of #3115; follows the error issue.

A reserved word costs every user a name. It earns its place only when an expression position needs it (if, match, move, not, it, ...). Words that only ever start a declaration can be read from the text at that position, as c facade, newaxis and implicit are. Candidates from the §29.11 table, each to be checked for any expression-position use before it moves: module, union, opaque, global, extend, select, spawn (reserved with no construct at all, per §29.11's own note), asm, gen.

Deliverable: a table of the reserved words with, for each, "needed in an expression position: where" or "declaration-only: make contextual"; then one change per word that moves, with a fixture using it as a name. Spec words for §29.11 need Eric.

Activity

  1. ehartford commented on Nov 24, 2026

    @ehartford
    ContributorAuthor

    The audit

    Read from src/Parser.with at 9a0cb8a: for each reserved word, every parser function that tests for its token. "Expression" means parse_primary or a statement parser reaches it, so a name there would be ambiguous.

    Needed where an expression or statement can start (stay reserved): and as async await break comptime const continue copy defer do else errdefer false fn for goto if in it let loop match move mut no_suspend not null or return true unsafe var while with yield, and asm and select (both are primaries: asm(...), select await).

    Only ever open or modify a declaration:

    word where the parser reads it ambiguity if it were a name elsewhere
    c_import inside use c_import(...) only none
    ephemeral after a type's name in type / enum none
    union, opaque after a type's name in type none (already accepted as a member name after .)
    where after a signature none
    dyn in a type expression, before a trait none
    gen before fn none
    module the file's first line, before a name as error: before a name it opens the declaration
    global, extend start of a declaration, before a name as error
    spawn nowhere: no parser function tests for it none; it is reserved for nothing
    enum, trait, impl, type, use, extern, pub start of a declaration (impl, extern also in type expressions) as error, but these are the words every file uses

    What a reserved word costs today, measured. None of the 24 words I tried can be a binding or a field of a With type. For C the cost is higher than a lost name: a C field or function with one of these names is imported with a trailing underscore (ev.type_, select_(…), spawn_(…)), and nothing told the user. e.type said "unknown field 'type'" and spawn(1) said "expected expression". POSIX select is one of these. The two diagnostics are fixed in the PR that follows (they now name the keyword and the imported spelling); that part needed no ruling.

    The question for Eric

    Proposed: make contextual the ten words whose position decides them: c_import, ephemeral, union, opaque, where, dyn, gen, module, global, extend; and drop spawn from the list until it has a construct. Keep enum, trait, impl, type, use, extern, pub reserved: they could be read the same way, but they are the declaration words of every file and impl/extern also appear in type expressions.

    • What the others do. Rust reserves all of its declaration words (with a few weak keywords, union among them, for the same reason as here). Zig reserves all of them and offers @"type" as an escape. Swift and C# make declaration modifiers contextual. Go reserves 25 words and nothing else.
    • What the spec says. §29.11 already has three contextual words (newaxis, implicit, error) and says of spawn that it has no construct.
    • Mission fit. A word the position already determines is a name the user is refused for nothing (law: do not make the user write around what the compiler knows). The one cost is that a mistyped declaration reads as an expression and the error moves; error has carried that since v7.51.
    • Open sub-question. type is the word C programs most often use as a field name. It stays reserved in this proposal; say so if you want it contextual too.
    • Prediction: you approve the ten and the removal of spawn, and keep type reserved. 75%.

    Needs from you: the §29.11 words (the list minus eleven, and one note naming the contextual ones). Then it is one change per word with a fixture using it as a name, as the issue asks.

  2. ehartford commented on Nov 25, 2026

    @ehartford
    ContributorAuthor

    Ruled by Eric, 2026-11-25 (answers to briefs.md).

    Yes to the ten (c_import ephemeral union opaque where dyn gen module global extend) becoming contextual; spawn is dropped; type stays reserved. To check on type: a member name after . may already be a keyword, yet e.type is refused and the C field is imported as type_. If so, the cheap fix is to import the C field as type and allow it in field position only. I bring the §29.11 words as exact text. Label removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions