Skip to content

Commit 2cbe367

Browse files
committed
Wasm: Remove the isEffectivelyFinal analysis and its use for Apply.
The optimizer already replaces `Apply` nodes that can be statically resolved by `ApplyStatically`. The `isEffectivelyFinal` analysis is therefore not useful anymore. Technically, it was still applicable to JS property/method *names* that are not string constants, but that is too niche to justify keeping the analysis. Also, arguably the correct fix for that would be to make the optimizer also optimize JS property/method names, since it would also benefit the JS backend.
1 parent bae4c82 commit 2cbe367

File tree

3 files changed

+12
-32
lines changed

3 files changed

+12
-32
lines changed

linker/shared/src/main/scala/org/scalajs/linker/backend/wasmemitter/FunctionEmitter.scala

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -648,26 +648,20 @@ private class FunctionEmitter private (
648648
}
649649
val receiverClassInfo = ctx.getClassInfo(receiverClassName)
650650

651-
/* If possible, "optimize" this Apply node as an ApplyStatically call.
652-
* We can do this if the receiver's class is a hijacked class or an
653-
* array type (because they are known to be final) or if the target
654-
* method is effectively final.
651+
/* Hijacked classes do not receive tables at all, and `Apply`s on array
652+
* types are considered to be statically resolved by the `Analyzer`.
653+
* Therefore, if the receiver's static type is a prim type, hijacked
654+
* class or array type, we must use static dispatch instead.
655655
*
656-
* The latter condition is nothing but an optimization, and should be
657-
* done by the optimizer instead. We will remove it once we can run the
658-
* optimizer with Wasm.
659-
*
660-
* The former condition (being a hijacked class or an array type) will
661-
* also never happen after we have the optimizer. But if we do not have
662-
* the optimizer, we must still do it now because the preconditions of
663-
* `genApplyWithDispatch` would not be met.
656+
* This never happens when we use the optimizer, since it already turns
657+
* any such `Apply` into an `ApplyStatically` (when it does not inline
658+
* it altogether).
664659
*/
665-
val canUseStaticallyResolved = {
660+
val useStaticDispatch = {
666661
receiverClassInfo.kind == ClassKind.HijackedClass ||
667-
receiver.tpe.isInstanceOf[ArrayType] ||
668-
receiverClassInfo.resolvedMethodInfos.get(method.name).exists(_.isEffectivelyFinal)
662+
receiver.tpe.isInstanceOf[ArrayType]
669663
}
670-
if (canUseStaticallyResolved) {
664+
if (useStaticDispatch) {
671665
genApplyStatically(ApplyStatically(
672666
flags, receiver, receiverClassName, method, args)(tree.tpe)(tree.pos))
673667
} else {

linker/shared/src/main/scala/org/scalajs/linker/backend/wasmemitter/Preprocessor.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,6 @@ object Preprocessor {
175175
m.methodName
176176
}
177177

178-
for (methodName <- concretePublicMethodNames)
179-
inherited.get(methodName).foreach(_.markOverridden())
180-
181178
concretePublicMethodNames.foldLeft(inherited) { (prev, methodName) =>
182179
prev.updated(methodName, new ConcreteMethodInfo(className, methodName))
183180
}

linker/shared/src/main/scala/org/scalajs/linker/backend/wasmemitter/WasmContext.scala

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -260,14 +260,11 @@ object WasmContext {
260260
val superTableEntries = superClass.fold[List[MethodName]](Nil)(_.tableEntries)
261261
val superTableEntrySet = superTableEntries.toSet
262262

263-
/* When computing the table entries to add for this class, exclude:
264-
* - methods that are already in the super class' table entries, and
265-
* - methods that are effectively final, since they will always be
266-
* statically resolved instead of using the table dispatch.
263+
/* When computing the table entries to add for this class, exclude
264+
* methods that are already in the super class' table entries.
267265
*/
268266
val newTableEntries = methodsCalledDynamically
269267
.filter(!superTableEntrySet.contains(_))
270-
.filterNot(m => resolvedMethodInfos.get(m).exists(_.isEffectivelyFinal))
271268
.sorted // for stability
272269

273270
_tableEntries = superTableEntries ::: newTableEntries
@@ -289,13 +286,5 @@ object WasmContext {
289286

290287
final class ConcreteMethodInfo(val ownerClass: ClassName, val methodName: MethodName) {
291288
val tableEntryID = genFunctionID.forTableEntry(ownerClass, methodName)
292-
293-
private var effectivelyFinal: Boolean = true
294-
295-
/** For use by `Preprocessor`. */
296-
private[wasmemitter] def markOverridden(): Unit =
297-
effectivelyFinal = false
298-
299-
def isEffectivelyFinal: Boolean = effectivelyFinal
300289
}
301290
}

0 commit comments

Comments
 (0)