lang::name_text
lang/src/name_text.mo
Pure name-text conversions between a source name and its unqualified (or bare) spelling.
This is the ONE boundary both the front end and the compiler backend use.
It deliberately depends on nothing but the ambient String primitives:
lang needs these helpers to judge references, and codegen needs them
to build symbols. Keeping the leaf free of lang::types is what lets
codegen import it without making lang depend on codegen -- the
cycle codegen-mote-extraction Phase 1 cuts.
The byte-wise forms are deliberate, not incidental: String.slice's
third argument is a LENGTH, and symbols.mo records two real bugs from
getting that wrong. String.get scans without allocating.
pub def unqualify_def_name (s : String) : StringThe source name inside a qualified symbol -- init.string::String.beq
back to String.beq. Splits at the LAST ::: a def key has one, and a
constructor key (owner::ctor) has the bare constructor after its last
one. A name that was never qualified (a synthesized or already-flat one)
comes back unchanged, so this is safe to apply anywhere a source-level
name is wanted.
pub def string_matches_bare (s : String) (bare : String) : BoolDoes s equal bare, or spell it qualified (module::bare -- the
part after the LAST ::, exactly what unqualify_def_name keeps)?
The no-allocation twin of String.beq (unqualify_def_name s) bare:
a byte comparison per position instead of a slice per position, for
the hot paths (class_name_eq, carrier_id_eq) that run per
instance/class comparison.
pub def global_key_join (module_text : String) (name_text : String) : StringJoin a module text and a name text into the canonical whole-program key.
:: cannot occur in an identifier, so the LAST :: is the module/name
boundary (global_key_module_text/global_key_name_text split it back).
A module path's own dots are part of module_text; never split on ..
pub def global_key_is_qualified (s : String) : Boolpub def global_key_module_text (s : String) : Option Stringpub def global_key_name_text (s : String) : Option Stringpub def ctor_key_join (owner_key : String) (ctor : String) : StringA constructor key: the owner's canonical key plus the constructor
identifier. Its last :: names the constructor, so ctor_key_join's
output must go to the ctor helpers, never to global_key_module_text.
pub def ctor_arity_key (owner_key : String) (ctor : String) (arity : I64) : StringThe constructor tag-map key: owner + ctor + arity. # cannot occur in an
identifier, so it separates the numeric arity without aliasing an
identifier that ends in digits.