Skip to main content

collect_const_names

Function collect_const_names 

Source
pub fn collect_const_names(modules: &[(&AIRModule, &Path)]) -> HashSet<String>
Expand description

Pre-scan every reached module and collect the declared names of all module-scope consts.

A const’s identifier must be spelled identically at its declaration and at every use site, across all backends. Each backend’s value-identifier transform (to_camel_case on JS/TS, to_snake_case on Python, to_pascal_case on Go) mangles a SCREAMING_SNAKE const name differently at the use site than the declaration emits it (def FIZZ_NUM vs use fizzNUM on JS/TS; def fizz_num vs use FIZZ_NUM on Python; def FIZZNUM vs use fizzNUM on Go), producing a “not defined”/NameError at the target. The backends consult this registry at both the ConstDecl and Identifier arms to emit the const’s verbatim declared name in both places — SCREAMING_SNAKE is a valid identifier in every target. A pre-scan (rather than recording consts as their decls are emitted) is required because a use site may precede its const’s declaration in source order, and because a used const can live in a different module than its use. Mirrors collect_record_names / collect_enum_variants.