Skip to content

Commit

Permalink
refactor: use indexmap instead of fxhash
Browse files Browse the repository at this point in the history
  • Loading branch information
Dunqing committed Jul 12, 2024
1 parent 1ff391e commit 1191d63
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 116 deletions.
6 changes: 4 additions & 2 deletions crates/oxc_semantic/src/symbol.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#![allow(non_snake_case)] // Silence erroneous warnings from Rust Analyser for `#[derive(Tsify)]`

use indexmap::IndexMap;
use oxc_ast::ast::Expression;
use oxc_index::IndexVec;
use oxc_span::{CompactStr, Span};
pub use oxc_syntax::{
scope::ScopeId,
symbol::{SymbolFlags, SymbolId},
};
use rustc_hash::FxHashMap;
use rustc_hash::FxHasher;
use std::hash::BuildHasherDefault;

#[cfg(feature = "serialize")]
use serde::Serialize;
Expand Down Expand Up @@ -37,7 +39,7 @@ pub struct SymbolTable {
pub scope_ids: IndexVec<SymbolId, Option<ScopeId>>,
/// Pointer to the AST Node where this symbol is declared
pub declarations: IndexVec<SymbolId, AstNodeId>,
pub declaration_symbol: FxHashMap<AstNodeId, SymbolId>,
pub declaration_symbol: IndexMap<AstNodeId, SymbolId, BuildHasherDefault<FxHasher>>,
pub resolved_references: IndexVec<SymbolId, Vec<ReferenceId>>,
pub references: IndexVec<ReferenceId, Reference>,
pub redeclare_variables: IndexVec<SymbolId, Vec<Span>>,
Expand Down
58 changes: 57 additions & 1 deletion tasks/coverage/parser_test262.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,60 @@ commit: a1587416

parser_test262 Summary:
AST Parsed : 45859/45859 (100.00%)
Positive Passed: 45859/45859 (100.00%)
Positive Passed: 45853/45859 (99.99%)
Negative Passed: 3925/3929 (99.90%)
Expect Syntax Error: "language/import/import-assertions/json-invalid.js"
Expect Syntax Error: "language/import/import-assertions/json-named-bindings.js"
Expect Syntax Error: "language/import/import-attributes/json-invalid.js"
Expect Syntax Error: "language/import/import-attributes/json-named-bindings.js"
Expect to Parse: "language/expressions/class/decorator/syntax/valid/decorator-call-expr-identifier-reference-yield.js"

× The keyword 'yield' is reserved
╭─[language/expressions/class/decorator/syntax/valid/decorator-call-expr-identifier-reference-yield.js:44:10]
43 │
44 │ var C = @yield() class {};
· ─────
╰────
Expect to Parse: "language/expressions/class/decorator/syntax/valid/decorator-member-expr-identifier-reference-yield.js"

× The keyword 'yield' is reserved
╭─[language/expressions/class/decorator/syntax/valid/decorator-member-expr-identifier-reference-yield.js:33:10]
32 │
33 │ var C = @yield class {};
· ─────
╰────
Expect to Parse: "language/expressions/class/decorator/syntax/valid/decorator-parenthesized-expr-identifier-reference-yield.js"

× The keyword 'yield' is reserved
╭─[language/expressions/class/decorator/syntax/valid/decorator-parenthesized-expr-identifier-reference-yield.js:51:11]
50 │
51 │ var C = @(yield) class {};
· ─────
╰────
Expect to Parse: "language/statements/class/decorator/syntax/valid/decorator-call-expr-identifier-reference-yield.js"

× The keyword 'yield' is reserved
╭─[language/statements/class/decorator/syntax/valid/decorator-call-expr-identifier-reference-yield.js:45:2]
44 │
45 │ @yield() class C {}
· ─────
╰────
Expect to Parse: "language/statements/class/decorator/syntax/valid/decorator-member-expr-identifier-reference-yield.js"

× The keyword 'yield' is reserved
╭─[language/statements/class/decorator/syntax/valid/decorator-member-expr-identifier-reference-yield.js:34:2]
33 │
34 │ @yield class C {}
· ─────
╰────
Expect to Parse: "language/statements/class/decorator/syntax/valid/decorator-parenthesized-expr-identifier-reference-yield.js"

× The keyword 'yield' is reserved
╭─[language/statements/class/decorator/syntax/valid/decorator-parenthesized-expr-identifier-reference-yield.js:52:3]
51 │
52 │ @(yield) class C {}
· ─────
╰────

× '0'-prefixed octal literals and octal escape sequences are deprecated
╭─[annexB/language/expressions/template-literal/legacy-octal-escape-sequence-strict.js:18:4]
Expand Down Expand Up @@ -12629,6 +12677,14 @@ Expect Syntax Error: "language/import/import-attributes/json-named-bindings.js"
× Cannot use `await` as an identifier in an async context
╭─[language/expressions/class/static-init-await-binding.js:21:12]
20 │ static {
21 │ (class await {});
· ─────
22 │ }
╰────

× Cannot use await in class static initialization block
╭─[language/expressions/class/static-init-await-binding.js:21:12]
20 │ static {
21 │ (class await {});
· ─────
22 │ }
Expand Down
142 changes: 29 additions & 113 deletions tasks/coverage/parser_typescript.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ commit: d8086f14

parser_typescript Summary:
AST Parsed : 5279/5283 (99.92%)
Positive Passed: 5256/5283 (99.49%)
Negative Passed: 1103/4875 (22.63%)
Positive Passed: 5258/5283 (99.53%)
Negative Passed: 1100/4875 (22.56%)
Expect Syntax Error: "compiler/ClassDeclaration10.ts"
Expect Syntax Error: "compiler/ClassDeclaration11.ts"
Expect Syntax Error: "compiler/ClassDeclaration13.ts"
Expand Down Expand Up @@ -469,6 +469,7 @@ Expect Syntax Error: "compiler/decoratorInJsFile.ts"
Expect Syntax Error: "compiler/decoratorInJsFile1.ts"
Expect Syntax Error: "compiler/decoratorMetadataGenericTypeVariable.ts"
Expect Syntax Error: "compiler/decoratorMetadataGenericTypeVariableDefault.ts"
Expect Syntax Error: "compiler/decoratorMetadataGenericTypeVariableInScope.ts"
Expect Syntax Error: "compiler/decoratorMetadataNoLibIsolatedModulesTypes.ts"
Expect Syntax Error: "compiler/decoratorsOnComputedProperties.ts"
Expect Syntax Error: "compiler/deduplicateImportsInSystem.ts"
Expand Down Expand Up @@ -888,6 +889,7 @@ Expect Syntax Error: "compiler/importedModuleAddToGlobal.ts"
Expect Syntax Error: "compiler/inDoesNotOperateOnPrimitiveTypes.ts"
Expect Syntax Error: "compiler/inKeywordAndUnknown.ts"
Expect Syntax Error: "compiler/inOperator.ts"
Expect Syntax Error: "compiler/incompatibleAssignmentOfIdenticallyNamedTypes.ts"
Expect Syntax Error: "compiler/incompatibleExports1.ts"
Expect Syntax Error: "compiler/incompatibleExports2.ts"
Expect Syntax Error: "compiler/incompatibleGenericTypes.ts"
Expand Down Expand Up @@ -2625,6 +2627,7 @@ Expect Syntax Error: "conformance/expressions/contextualTyping/parenthesizedCont
Expect Syntax Error: "conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts"
Expect Syntax Error: "conformance/expressions/contextualTyping/superCallParameterContextualTyping2.ts"
Expect Syntax Error: "conformance/expressions/functionCalls/callOverload.ts"
Expect Syntax Error: "conformance/expressions/functionCalls/callWithMissingVoid.ts"
Expect Syntax Error: "conformance/expressions/functionCalls/callWithSpread2.ts"
Expect Syntax Error: "conformance/expressions/functionCalls/callWithSpread3.ts"
Expect Syntax Error: "conformance/expressions/functionCalls/callWithSpread4.ts"
Expand Down Expand Up @@ -3799,20 +3802,6 @@ Expect to Parse: "compiler/bom-utf16be.ts"
1 │ ￾瘀愀爀 砀㴀㄀ 㬀ഀ਀
· ─
╰────
Expect to Parse: "compiler/decoratorReferences.ts"

× Identifier `T` has already been declared
╭─[compiler/decoratorReferences.ts:2:6]
1 │ declare function y(...args: any[]): any;
2 │ type T = number;
· ┬
· ╰── `T` has already been declared here
3 │ @y(1 as T, () => C) // <-- T should be resolved to the type alias, not the type parameter of the class; C should resolve to the class
4 │ class C<T> {
· ┬
· ╰── It can not be redeclared here
5 │ @y(null as T) // <-- y should resolve to the function declaration, not the parameter; T should resolve to the type parameter of the class
╰────
Expect to Parse: "compiler/deferredConditionalTypes.ts"

× Identifier `A` has already been declared
Expand Down Expand Up @@ -4090,21 +4079,6 @@ Expect to Parse: "compiler/unusedTypeParametersNotCheckedByNoUnusedLocals.ts"
· ╰── It can not be redeclared here
6 │
╰────

× Identifier `T` has already been declared
╭─[compiler/unusedTypeParametersNotCheckedByNoUnusedLocals.ts:3:6]
2 │
3 │ type T<T> = { };
· ┬
· ╰── `T` has already been declared here
4 │
5 │ interface I<T> { };
6 │
7 │ class C<T> {
· ┬
· ╰── It can not be redeclared here
8 │ public m<V>() { }
╰────
Expect to Parse: "compiler/withStatementInternalComments.ts"

× 'with' statements are not allowed
Expand Down Expand Up @@ -4204,17 +4178,6 @@ Expect to Parse: "conformance/esDecorators/esDecorators-decoratorExpression.1.ts
14 │
╰────
help: Try insert a semicolon here
Expect to Parse: "conformance/expressions/newOperator/newOperatorConformance.ts"

× Identifier `T` has already been declared
╭─[conformance/expressions/newOperator/newOperatorConformance.ts:8:7]
7 │
8 │ class T<T> {
· ┬ ┬
· │ ╰── It can not be redeclared here
· ╰── `T` has already been declared here
9 │ constructor(n?: T) { }
╰────
Expect to Parse: "conformance/externalModules/topLevelAwait.2.ts"

× Cannot use `await` as an identifier in an async context
Expand Down Expand Up @@ -6347,19 +6310,6 @@ Expect to Parse: "conformance/types/typeRelationships/typeAndMemberIdentity/obje
╰────
help: Remove the duplicate modifier.

× Identifier `TypeVariable` has already been declared
╭─[compiler/decoratorMetadataGenericTypeVariableInScope.ts:2:7]
1 │ // Unused, but could collide with the named type argument below.
2 │ class TypeVariable {}
· ──────┬─────
· ╰── `TypeVariable` has already been declared here
3 │
4 │ export class C<TypeVariable> {
· ──────┬─────
· ╰── It can not be redeclared here
5 │ @Decorate
╰────

× Cannot assign to this expression
╭─[compiler/decrementAndIncrementOperators.ts:4:1]
3 │ // errors
Expand Down Expand Up @@ -7419,18 +7369,6 @@ Expect to Parse: "conformance/types/typeRelationships/typeAndMemberIdentity/obje
2 │
╰────

× Identifier `T` has already been declared
╭─[compiler/incompatibleAssignmentOfIdenticallyNamedTypes.ts:1:11]
1 │ interface T { }
· ┬
· ╰── `T` has already been declared here
2 │ declare const a: T;
3 │ class Foo<T> {
· ┬
· ╰── It can not be redeclared here
4 │ x: T;
╰────

× Unexpected token
╭─[compiler/incompleteDottedExpressionAtEOF.ts:2:18]
1 │ // used to leak __missing into error message
Expand Down Expand Up @@ -10298,21 +10236,6 @@ Expect to Parse: "conformance/types/typeRelationships/typeAndMemberIdentity/obje
16 │ }
╰────

× Identifier `public` has already been declared
╭─[compiler/strictModeReservedWordInClassDeclaration.ts:1:11]
1 │ interface public { }
· ───┬──
· ╰── `public` has already been declared here
2 │
╰────
╭─[compiler/strictModeReservedWordInClassDeclaration.ts:21:9]
20 │
21 │ class D<public, private>{ }
· ───┬──
· ╰── It can not be redeclared here
22 │
╰────

× The keyword 'public' is reserved
╭─[compiler/strictModeReservedWordInClassDeclaration.ts:21:9]
20 │
Expand All @@ -10329,6 +10252,30 @@ Expect to Parse: "conformance/types/typeRelationships/typeAndMemberIdentity/obje
22 │
╰────

× The keyword 'public' is reserved
╭─[compiler/strictModeReservedWordInClassDeclaration.ts:23:20]
22 │
23 │ class E implements public { }
· ──────
24 │
╰────

× The keyword 'public' is reserved
╭─[compiler/strictModeReservedWordInClassDeclaration.ts:25:20]
24 │
25 │ class F implements public.private.B { }
· ──────
26 │ class F1 implements public.private.implements { }
╰────

× The keyword 'public' is reserved
╭─[compiler/strictModeReservedWordInClassDeclaration.ts:26:21]
25 │ class F implements public.private.B { }
26 │ class F1 implements public.private.implements { }
· ──────
27 │ class G extends package { }
╰────

× The keyword 'package' is reserved
╭─[compiler/strictModeReservedWordInClassDeclaration.ts:27:17]
26 │ class F1 implements public.private.implements { }
Expand Down Expand Up @@ -11235,21 +11182,6 @@ Expect to Parse: "conformance/types/typeRelationships/typeAndMemberIdentity/obje
6 │
╰────

× Identifier `T` has already been declared
╭─[compiler/unusedTypeParametersCheckedByNoUnusedParameters.ts:3:6]
2 │
3 │ type T<T> = { };
· ┬
· ╰── `T` has already been declared here
4 │
5 │ interface I<T> { };
6 │
7 │ class C<T> {
· ┬
· ╰── It can not be redeclared here
8 │ public m<V>() { }
╰────

× Expected a semicolon or an implicit semicolon after a statement, but found none
╭─[compiler/validRegexp.ts:1:23]
1 │ var x = / [a - z /]$ / i;
Expand Down Expand Up @@ -16494,22 +16426,6 @@ Expect to Parse: "conformance/types/typeRelationships/typeAndMemberIdentity/obje
10 │ (BOOLEAN, );
╰────

× Identifier `X` has already been declared
╭─[conformance/expressions/functionCalls/callWithMissingVoid.ts:2:7]
1 │ // From #4260
2 │ class X<T> {
· ┬
· ╰── `X` has already been declared here
3 │ f(t: T) {
╰────
╭─[conformance/expressions/functionCalls/callWithMissingVoid.ts:27:17]
26 │
27 │ class MyPromise<X> {
· ┬
· ╰── It can not be redeclared here
28 │ constructor(executor: (resolve: (value: X) => void) => void) {
╰────

× 'with' statements are not allowed
╭─[conformance/expressions/functions/arrowFunctionContexts.ts:2:1]
1 │ // Arrow function used in with statement
Expand Down

0 comments on commit 1191d63

Please sign in to comment.