Skip to content

Need a new strategy for dealing with conflicted identifiers #389

Description

@underfin

pub fn add_top_level_symbol(&mut self, symbol_ref: SymbolRef) {
let canonical_ref = self.symbols.par_canonical_ref_for(symbol_ref);
let original_name: Cow<'_, Rstr> =
Cow::Owned(self.symbols.get_original_name(canonical_ref).to_rstr());
match self.canonical_names.entry(canonical_ref) {
std::collections::hash_map::Entry::Vacant(vacant) => {
let mut count = 0;
let mut candidate_name = original_name.clone();
while self.used_canonical_names.contains(&candidate_name) {
count += 1;
candidate_name = Cow::Owned(format!("{original_name}${count}").into());
}
self.used_canonical_names.insert(candidate_name.clone());
vacant.insert(candidate_name.into_owned());
}
std::collections::hash_map::Entry::Occupied(_) => {
// The symbol is already renamed
}
}
}

The current algorithm counts from 0 and may end up with a huge number of allocations and hashes for candidate_name.

The challenge is to come up with the most efficient strategy for finding the new name.

One possible solution is to follow esbuild - the assigned new name is a new name on the scope

The original discussion is #365.

Metadata

Metadata

Type

No type

Fields

Priority

None yet

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions