From e64861327439902dd40b0e2bc3b1d7bfc91da7ef Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 4 Oct 2023 12:03:18 -0700 Subject: [PATCH] [WASM] Reorder some passes for Wasm in preparation for non-native JsEnum optimization. In particular: - NormalizeJsEnums needs to run after NormalizeEnumClasses and before NormalizeOverlayMembers. Moved NormalizeEnumClasses above. - InsertJsEnumBoxingAndUnboxingConversions needs to run after NormalizeSwitchStatements and ImplementStringConcatenation and before RewriteReferenceEqualityOperations. PiperOrigin-RevId: 570762555 --- .../j2cl/transpiler/backend/Backend.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/transpiler/java/com/google/j2cl/transpiler/backend/Backend.java b/transpiler/java/com/google/j2cl/transpiler/backend/Backend.java index ed80882460..0f1a536b31 100644 --- a/transpiler/java/com/google/j2cl/transpiler/backend/Backend.java +++ b/transpiler/java/com/google/j2cl/transpiler/backend/Backend.java @@ -395,9 +395,9 @@ public ImmutableList> getPassFactories(BackendOption () -> new ImplementSystemGetProperty(options.getDefinesForWasm()), NormalizeTryWithResources::new, NormalizeCatchClauses::new, + () -> new NormalizeEnumClasses(/* useMakeEnumNameIndirection= */ false), NormalizeOverlayMembers::new, NormalizeInstanceCompileTimeConstants::new, - () -> new NormalizeEnumClasses(/* useMakeEnumNameIndirection= */ false), () -> new NormalizeShifts(/* narrowAllToInt= */ false), NormalizeStaticMemberQualifiers::new, NormalizeMultiExpressions::new, @@ -405,8 +405,6 @@ public ImmutableList> getPassFactories(BackendOption // Rewrite operations that do not have direct support in wasm into ones that have. () -> new ExpandCompoundAssignments(/* expandAll= */ true), InsertErasureTypeSafetyCasts::new, - // Rewrite 'a != b' to '!(a == b)' - RewriteReferenceEqualityOperations::new, RewriteUnaryExpressions::new, NormalizeSwitchStatements::new, // Propagate constants needs to run after NormalizeSwitchStatements since it introduces @@ -416,6 +414,11 @@ public ImmutableList> getPassFactories(BackendOption StaticallyEvaluateStringConcatenation::new, StaticallyEvaluateStringComparison::new, ImplementStringConcatenation::new, + // TODO(b/288145845): Add InsertJsEnumBoxingAndUnboxingConversions here. + // Rewrite 'a != b' to '!(a == b)' + // Must run after InsertJsEnumBoxingAndUnboxingConversions. + RewriteReferenceEqualityOperations::new, + PropagateJsEnumConstants::new, InsertNarrowingReferenceConversions::new, () -> new InsertUnboxingConversions(/* areBooleanAndDoubleBoxed= */ true), () -> new InsertBoxingConversions(/* areBooleanAndDoubleBoxed= */ true), @@ -529,9 +532,9 @@ public ImmutableList> getPassFactories(BackendOption // () -> new ImplementSystemGetProperty(options.getDefinesForWasm()), NormalizeTryWithResources::new, NormalizeCatchClauses::new, + () -> new NormalizeEnumClasses(/* useMakeEnumNameIndirection= */ false), NormalizeOverlayMembers::new, NormalizeInstanceCompileTimeConstants::new, - () -> new NormalizeEnumClasses(/* useMakeEnumNameIndirection= */ false), () -> new NormalizeShifts(/* narrowAllToInt= */ false), NormalizeStaticMemberQualifiers::new, NormalizeMultiExpressions::new, @@ -539,8 +542,6 @@ public ImmutableList> getPassFactories(BackendOption // Rewrite operations that do not have direct support in wasm into ones that have. () -> new ExpandCompoundAssignments(/* expandAll= */ true), InsertErasureTypeSafetyCasts::new, - // Rewrite 'a != b' to '!(a == b)' - RewriteReferenceEqualityOperations::new, RewriteUnaryExpressions::new, NormalizeSwitchStatements::new, // Propagate constants needs to run after NormalizeSwitchStatements since it introduces @@ -550,6 +551,11 @@ public ImmutableList> getPassFactories(BackendOption StaticallyEvaluateStringConcatenation::new, StaticallyEvaluateStringComparison::new, ImplementStringConcatenation::new, + // TODO(b/288145845): Add InsertJsEnumBoxingAndUnboxingConversions here. + // Rewrite 'a != b' to '!(a == b)' + // Must run after InsertJsEnumBoxingAndUnboxingConversions. + RewriteReferenceEqualityOperations::new, + PropagateJsEnumConstants::new, InsertNarrowingReferenceConversions::new, () -> new InsertUnboxingConversions(/* areBooleanAndDoubleBoxed= */ true), () -> new InsertBoxingConversions(/* areBooleanAndDoubleBoxed= */ true),