DS identifiers over Unicode#
Prefix LNAM. The identifier surface: which characters an identifier may
contain, when two identifiers denote the same name, Unicode normalization, script
security, bidirectional-text safety, and the wire / determinism contract for names.
Paired with: positional type classification — how a NAME is classified as a
type reference or a binding by grammatical position — in [LGRA];
and the :: conversion operator in [LCST]. The lexer/LALR
realization of the NAME / TYPE_SYM terminals is [LLEX]'s. This
doc owns LNAM.1, LNAM.2, and LNAM.7.
Depends on: [LDET] (the version series that keeps artefacts of different Unicode pins apart), [LNUL.6], [RFCS] (schema names on the wire).
1. Scope and terminology [LNAM.1]#
[LNAM.1.1] DS identifiers are drawn from full Unicode. Three coupled surfaces move
together: (a) identifiers over Unicode (this doc); (b) classification of an
identifier as a type reference or a binding by grammatical position rather
than by case ([LGRA]); (c) the postfix conversion operator ::
([LCST]). (b) is a precondition of (a) for caseless scripts.
[LNAM.1.2] Terminology. Identifier — a NAME token. Type reference — a
NAME in a grammatical slot that names a schema or type. Binding — a NAME that
names a pattern binding or a let. Conversions are defined in [LCST].
[LNAM.1.3] Unicode identifiers need no per-source selector, because the
artefact's version series already gates the boundary whole ([LDET.1.10]): a
runtime reads only what its own series wrote, so a use-declaration pin
would gate per file what is already gated per artefact. The version pin
interacts with the pinned Unicode version ([LNAM.2.2.5]).
The feature is unconditional within a series, which is why every ASCII
identifier remains legal ([LNAM.2.2.2]) and why NAME is defined over the
full XID class with no further condition ([LGRA.2.5.1], [LNAM.2.2.1]).
see also: LDET.1.10, LGRA.2.5.1, LNAM.2.2.1, LNAM.2.2.2, LNAM.2.2.5
2. Identifiers over Unicode [LNAM.2]#
2.1 Classification versus identity [LNAM.2.1]#
[LNAM.2.1.1] An identifier carries two independent properties. Classification —
whether it denotes a type reference or a binding — is by grammatical position
([LGRA]); case must not affect it. Identity — whether two identifiers
denote the same name — is case-sensitive and NFC-based ([LNAM.2.3]). Case
does not classify, and it does distinguish: Reading and reading are
two distinct identifiers, each legal in any position. The author may use case as
convention; the compiler must not require any case anywhere.
checks: alloy×3 — see also: LNAM.2.3
2.2 Characters [LNAM.2.2]#
[LNAM.2.2.1] Legal set. The first character of an identifier must be in
(XID_Start ∪ U+005F LOW LINE) ∩ Identifier_Status=Allowed. Each subsequent
character must be in XID_Continue ∩ Identifier_Status=Allowed. (UAX #31 base,
narrowed by the UAX #39 recommended set.)
ratified
[LNAM.2.2.2] Exclusions. ZWJ (U+200D) and ZWNJ (U+200C) must not appear in
an identifier — they are invisible and a confusability hazard, and DS does not opt
into the UAX #31 medial-joiner exception. Emoji and other non-XID symbols must not
appear. Every ASCII identifier of the form [A-Za-z_][A-Za-z0-9_]* is legal; _ alone is one, and [LLEX.9.5] reserves it.
see also: LLEX.9.5
[LNAM.2.2.3] NFC-closure. The Allowed set is closed under NFC, so normalization ([LNAM.2.4]) never turns a legal identifier illegal. The compiler must validate the normalized form.
see also: LNAM.2.4
[LNAM.2.2.4] Identifier / unit-symbol boundary. A letter in [LNAM.2.2.1]'s legal set, such as μ
(U+03BC GREEK SMALL LETTER MU), may appear in an identifier. A character outside
it appears only in a type/unit position via the TYPE_SYM terminal ([LGRA] /
[LLEX]), never in an identifier: µ (U+00B5 MICRO SIGN), which is XID and not
Allowed, and ° (U+00B0 DEGREE SIGN), which is not XID. In a unit position
the lexer folds μ to µ ([LLEX.12.2.1]).
see also: LLEX.12.2.1, LNAM.2.2.1
[LNAM.2.2.5] Pinned Unicode version — 16.0; the runtime is Unicode-free.
XID_Start / XID_Continue, Identifier_Status, the NFC mapping ([LNAM.2.4]), and
the script sets ([LNAM.2.5.1]) are defined against a specific Unicode version and
change across versions. The language pins Unicode 16.0. All Unicode processing — legality and normalization — is
compile-time. The compiler applies the pinned version and emits NFC; the runtime
carries no Unicode tables and compares already-NFC-normalized names byte-for-byte
([LNAM.2.8], [LNAM.7.1]).
The compiler's version implies the pin, and nothing else carries it. Neither the artefact nor the platform signature records a Unicode version. Advancing the pin is a language-version change, made only at a minor release, so artefacts compiled against different pins belong to different version series, which a runtime already keeps apart ([LDET.1.10]).
see also: LDET.1.10, LNAM.2.4, LNAM.2.5.1, LNAM.2.8, LNAM.7.1
2.3 Identity [LNAM.2.3]#
[LNAM.2.3.1] Two identifiers denote the same name if and only if their NFC forms are codepoint-equal. Comparison is case-sensitive.
checks: alloy
[LNAM.2.3.2] Confusability is not identity. Distinct identifiers that render
similarly (e.g. Latin A and Cyrillic А) are never merged; the compiler rejects
the mixed-script case ([LNAM.2.5.1]) but must not treat two distinct names as one.
see also: LNAM.2.5.1
2.4 Normalization [LNAM.2.4]#
[LNAM.2.4.1] The compiler must normalize every identifier to NFC (UAX #15) at
lex time, before interning, comparison, and emission. Source text may arrive in any
normalization form. (NFC, not NFKC. NFC answers "same name" for encoding
differences; it does not fold compatibility variants — ²→2, fi→fi, full-width
→ half-width — which NFKC would, silently merging visually-distinct names. The
dangerous cross-script look-alikes NFKC cannot fold anyway are handled by the
mixed-script reject [LNAM.2.5.1].)
see also: LNAM.2.5.1
[LNAM.2.4.2] The compiler must not normalize string-literal content ([LNAM.2.7]).
see also: LNAM.2.7
2.5 Script security [LNAM.2.5]#
[LNAM.2.5.1] Mixed-script — reject. An identifier must satisfy UAX #39 Highly
Restrictive: it must be single-script, or use one of the recognized augmented sets
(Latin + Han + Hiragana + Katakana; Latin + Han + Bopomofo; Latin + Han + Hangul),
with script-neutral characters (digits, _) permitted throughout. The compiler must
reject an identifier that violates this. A conforming compiler may implement Highly
Restrictive conservatively: over-rejecting a multi-script identifier that a full
UAX #39 per-character set-cover would admit is permitted (it errs toward the
security-safe direction), but it must never admit a mixed-script identifier Highly
Restrictive forbids. Full set-cover is a v1.x refinement (D-B1-1). (This admits legitimate CJK, which mixes
Han and kana, and blocks Latin/Cyrillic homoglyph names such as pаypal. It is the
whole script-security surface: DS carries no cross-identifier confusable-skeleton
lint.)
ratified
[LNAM.2.5.3] Compilation-unit scope. For [LNAM.2.5.1], "compilation unit" is the full set of sources compiled together, including every transitively imported library. Mixed-script is a per-identifier check and is independent of scope.
see also: LNAM.2.5.1
[LNAM.2.5.4] Case differences are same-script and visually distinct; the compiler
must not flag them under [LNAM.2.5.1]. Reading and reading coexist freely.
see also: LNAM.2.5.1
2.6 Bidirectional text [LNAM.2.6]#
[LNAM.2.6.1] Letters versus controls — the load-bearing distinction. "Bidi"
names two disjoint things: strong right-to-left letters (Arabic, Hebrew, … —
ordinary script letters with inherent directionality) and bidi control
characters (invisible format codepoints U+202A–202E, U+2066–2069,
U+200E/200F, U+061C). The rules in this section constrain only the control
characters. Strong RTL letters are ordinary identifier ([LNAM.2.2]) and string
([LNAM.2.7]) characters and are unrestricted: schema مستشعر: is legal, and its
display ordering is produced by the implicit Unicode Bidirectional Algorithm (UAX #9)
with no control characters required.
[LNAM.2.6.2] Controls in identifiers — reject. An identifier must not contain a
bidi control character. (Redundant with [LNAM.2.2] — controls are Cf, not XID —
and named here as an explicit contract: a control inside a name has no legitimate use
and is an invisible-confusable vector.)
see also: LNAM.2.2
[LNAM.2.6.3] Controls in strings and comments — balance or reject. Within a
string literal or a comment, every bidi embedding, override, or isolate the author
opens must be closed before that literal or comment ends. The compiler must reject an
unbalanced or unterminated bidi control sequence in a string literal or a comment.
The non-scoping marks LRM/RLM (U+200E/200F) and ALM (U+061C) open no
scope and so cannot spill; the compiler may permit them in string literals and
comments (they remain rejected in identifiers, [LNAM.2.6.2]). (Trojan Source,
CVE-2021-42574: an unbalanced scoping control spills its reordering into the
surrounding source, so displayed code can differ from parsed code — pointed for a
rules engine, where a reordered where guard or a hidden negation passes human
review. A balanced scoping control is contained within the literal and remains the
legitimate way to embed an LTR run inside RTL string data.)
see also: LNAM.2.6.2
2.7 String literals [LNAM.2.7]#
[LNAM.2.7.1] A string literal may contain any well-formed UTF-8, including RTL text. The compiler must validate string-literal content as well-formed UTF-8 and must not normalize it (a string is data, not a name). Bidi controls within a string are governed by [LNAM.2.6.3].
see also: LNAM.2.6.3
2.8 Wire normalization [LNAM.2.8]#
[LNAM.2.8.1] The compiler must emit schema names in NFC on every wire and on-disk encoding; the runtime must treat an incoming schema name as NFC and must not re-normalize. A producer and consumer that disagree on the normalized form of a schema name does not decode a fact body ([LNAM.7.1]).
see also: LNAM.7.1
7. Wire, encoding, determinism [LNAM.7]#
[LNAM.7.1] Schema names on the wire. A schema's own name ([LIMP.13.1]) crosses the FactAssert wire
(FactAssert.schema_name, [RFCS.6]) and both tiers decode a fact body against the schema,
so a producer and consumer must share the NFC-normalized name, each segment of a
library's path included. The compiler must emit
NFC; the runtime must not re-normalize (it compares the bytes).
[LNAM.7.2] The :: operator is a compile-time construct producing
already-converted runtime values and does not change the wire encoding.
NFC identifier bytes do not change it either: ASCII identifiers are
NFC-invariant, and a non-ASCII NFC schema name is an opaque interned string
to any runtime — the correctness gate is the compiler version that implies
the pinned Unicode version ([LNAM.2.2.5], [LNAM.7.3]), not the DSC format; consistent with the base container contract
(RDSC.10.4/10.5 — accept-any-minor / skip-unknown).
see also: LNAM.2.2.5, LNAM.7.3
[LNAM.7.3] Determinism. NFC is a fixed function given the pinned Unicode version
([LNAM.2.2.5]). The compiler applies it and emits NFC names; the runtime compares them
byte-for-byte, so identifier identity is deterministic across engines with no runtime
Unicode dependency. null from a fallible conversion is the single canonical null
([LNUL.6]), so it hashes, orders, and encodes identically. The one new determinism
obligation is the pinned Unicode version, which the compiler's version implies
([LNAM.2.2.5]): artefacts compiled against different pins belong to different
version series, which a runtime keeps apart ([LDET.1.10]).
see also: LDET.1.10, LNAM.2.1, LNAM.2.2.5, LNAM.2.4, LNAM.2.5.1, LNAM.7.2, LNUL.6