Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

semantic!: Remove SymbolTable::get_symbol_id_from_name and SymbolTable::get_scope_id_from_name #5456

Closed
overlookmotel opened this issue Sep 4, 2024 · 2 comments · Fixed by #5480
Assignees
Labels
A-semantic Area - Semantic

Comments

@overlookmotel
Copy link
Contributor

overlookmotel commented Sep 4, 2024

These methods are in my opinion a footgun because they don't do what you might think they do. Worse still, minimal test cases often won't reveal that.

We use get_symbol_id_from_name to get the SymbolId for a reference, but actually that's not what it's doing - it will give you the SymbolId of the first binding with this variable name anywhere in the AST.

They are not the same. e.g. in this case:

{
    let foo;
}
let bar = foo;

If we want to know if foo in let bar = foo; refers to a local variable, get_symbol_id_from_name("foo").is_some() says "yes it does". But that's wrong.

Instead we should use symbol_table.is_global_reference(ident.reference_id().unwrap()).

As well as being correct, this is also much more performant, as it doesn't iterate through every single symbol in the entire AST the way get_symbol_id_from_name does.

Current API usage

get_symbol_id_from_name

get_scope_id_from_name

This method is not used anywhere in Oxc.

@overlookmotel overlookmotel added the A-semantic Area - Semantic label Sep 4, 2024
@overlookmotel overlookmotel self-assigned this Sep 4, 2024
@Boshen Boshen changed the title Remove SymbolTable::get_symbol_id_from_name and SymbolTable::get_scope_id_from_name semantic!: Remove SymbolTable::get_symbol_id_from_name and SymbolTable::get_scope_id_from_name Sep 5, 2024
@overlookmotel
Copy link
Contributor Author

#5467 removed the last remaining use of get_symbol_id_from_name.

@overlookmotel
Copy link
Contributor Author

Closed in #5480.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-semantic Area - Semantic
Projects
None yet
1 participant