-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WASM] Change PropagateConstants to process JsEnum constants separately.
There is an issue around ordering of PropagateConstants, string concatenation passes, and JsEnum boxing/unboxing passes: - PropagateConstants must run before StaticallyEvaluateStringConcatenation, which must run before ImplementStringConcatenation. - InsertJsEnumBoxingAndUnboxingConversions must run after ImplementStringConcatenation but before PropagateConstants, because PropagateConstants removes type information around JsEnums. To account for this, we split PropagateConstants to handle JsEnums separately, so that we can run the non-JsEnum part before JsEnum boxing/unboxing, and the JsEnum part afterwards. Note: This change is a no-op for the output PiperOrigin-RevId: 570753214
- Loading branch information
1 parent
d92d143
commit 2a511c2
Showing
5 changed files
with
77 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
transpiler/java/com/google/j2cl/transpiler/passes/PropagateJsEnumConstants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright 2023 Google Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package com.google.j2cl.transpiler.passes; | ||
|
||
import com.google.j2cl.transpiler.ast.AstUtils; | ||
import com.google.j2cl.transpiler.ast.FieldAccess; | ||
import com.google.j2cl.transpiler.ast.FieldDescriptor; | ||
|
||
// TODO(b/303316598): This approach needs more thought for modular. With modular transpilation, we | ||
// don't have enough information about JsEnum to propagate, in particular, the AST which includes | ||
// the constant field values. | ||
/** Propagates JsEnum constant fields. */ | ||
public class PropagateJsEnumConstants extends PropagateConstants { | ||
|
||
@Override | ||
protected boolean shouldPropagateConstant(FieldDescriptor fieldDescriptor) { | ||
return fieldDescriptor.isEnumConstant() | ||
&& AstUtils.isNonNativeJsEnum(fieldDescriptor.getEnclosingTypeDescriptor()); | ||
} | ||
|
||
// TODO(b/303309109) This is a workaround for NormalizeJsEnums not updating field references to | ||
// point to the correct descriptor. Ideally, this shouldn't be needed. Clean up after rethinking | ||
// JsEnum normalization passes. | ||
@Override | ||
protected FieldDescriptor getConstantFieldDescriptor(FieldAccess fieldAccess) { | ||
return AstUtils.createJsEnumConstantFieldDescriptor(fieldAccess.getTarget()); | ||
} | ||
} |