From 1191d63374a9a43733e619e90f0efa2a270b5a82 Mon Sep 17 00:00:00 2001 From: Dunqing Date: Fri, 12 Jul 2024 12:31:20 +0800 Subject: [PATCH] refactor: use indexmap instead of fxhash --- crates/oxc_semantic/src/symbol.rs | 6 +- tasks/coverage/parser_test262.snap | 58 ++++++++++- tasks/coverage/parser_typescript.snap | 142 ++++++-------------------- 3 files changed, 90 insertions(+), 116 deletions(-) diff --git a/crates/oxc_semantic/src/symbol.rs b/crates/oxc_semantic/src/symbol.rs index 7fe1cbf16aa6a..66ef81a7dd855 100644 --- a/crates/oxc_semantic/src/symbol.rs +++ b/crates/oxc_semantic/src/symbol.rs @@ -1,5 +1,6 @@ #![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}; @@ -7,7 +8,8 @@ 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; @@ -37,7 +39,7 @@ pub struct SymbolTable { pub scope_ids: IndexVec>, /// Pointer to the AST Node where this symbol is declared pub declarations: IndexVec, - pub declaration_symbol: FxHashMap, + pub declaration_symbol: IndexMap>, pub resolved_references: IndexVec>, pub references: IndexVec, pub redeclare_variables: IndexVec>, diff --git a/tasks/coverage/parser_test262.snap b/tasks/coverage/parser_test262.snap index 214a54144fb7c..ad84a4c5b0c87 100644 --- a/tasks/coverage/parser_test262.snap +++ b/tasks/coverage/parser_test262.snap @@ -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] @@ -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 │ } diff --git a/tasks/coverage/parser_typescript.snap b/tasks/coverage/parser_typescript.snap index b0acdb5f6a398..eeaa6aeee9807 100644 --- a/tasks/coverage/parser_typescript.snap +++ b/tasks/coverage/parser_typescript.snap @@ -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" @@ -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" @@ -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" @@ -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" @@ -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 { - · ┬ - · ╰── 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 @@ -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` has already been declared here - 4 │ - 5 │ interface I { }; - 6 │ - 7 │ class C { - · ┬ - · ╰── It can not be redeclared here - 8 │ public m() { } - ╰──── Expect to Parse: "compiler/withStatementInternalComments.ts" × 'with' statements are not allowed @@ -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 { - · ┬ ┬ - · │ ╰── 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 @@ -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 { - · ──────┬───── - · ╰── It can not be redeclared here - 5 │ @Decorate - ╰──── - × Cannot assign to this expression ╭─[compiler/decrementAndIncrementOperators.ts:4:1] 3 │ // errors @@ -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 { - · ┬ - · ╰── It can not be redeclared here - 4 │ x: T; - ╰──── - × Unexpected token ╭─[compiler/incompleteDottedExpressionAtEOF.ts:2:18] 1 │ // used to leak __missing into error message @@ -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{ } - · ───┬── - · ╰── It can not be redeclared here - 22 │ - ╰──── - × The keyword 'public' is reserved ╭─[compiler/strictModeReservedWordInClassDeclaration.ts:21:9] 20 │ @@ -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 { } @@ -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` has already been declared here - 4 │ - 5 │ interface I { }; - 6 │ - 7 │ class C { - · ┬ - · ╰── It can not be redeclared here - 8 │ public m() { } - ╰──── - × Expected a semicolon or an implicit semicolon after a statement, but found none ╭─[compiler/validRegexp.ts:1:23] 1 │ var x = / [a - z /]$ / i; @@ -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 { - · ┬ - · ╰── `X` has already been declared here - 3 │ f(t: T) { - ╰──── - ╭─[conformance/expressions/functionCalls/callWithMissingVoid.ts:27:17] - 26 │ - 27 │ class MyPromise { - · ┬ - · ╰── 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