Skip to content
This repository was archived by the owner on Jul 12, 2024. It is now read-only.

Commit edeea5f

Browse files
committed
Use namespacing conventions in Preprocessor.
The Preprocessor never manipulates any WebAssembly things, so we can import IR things without namespace.
1 parent 7bf7c44 commit edeea5f

1 file changed

Lines changed: 16 additions & 21 deletions

File tree

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

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
package org.scalajs.linker.backend.wasmemitter
22

3-
import org.scalajs.ir.{Trees => IRTrees}
4-
import org.scalajs.ir.{Types => IRTypes}
5-
import org.scalajs.ir.{Names => IRNames}
6-
import org.scalajs.ir.ClassKind
7-
import org.scalajs.ir.Traversers
3+
import org.scalajs.ir.Names._
4+
import org.scalajs.ir.Trees._
5+
import org.scalajs.ir.Types._
6+
import org.scalajs.ir.{ClassKind, Traversers}
87

98
import org.scalajs.linker.standard.{LinkedClass, LinkedTopLevelExport}
109

11-
import org.scalajs.linker.backend.webassembly._
12-
1310
import EmbeddedConstants._
1411
import WasmContext._
1512

@@ -35,16 +32,16 @@ object Preprocessor {
3532
private def preprocess(clazz: LinkedClass)(implicit ctx: WasmContext): Unit = {
3633
val kind = clazz.kind
3734

38-
val allFieldDefs: List[IRTrees.FieldDef] =
35+
val allFieldDefs: List[FieldDef] =
3936
if (kind.isClass) {
4037
val inheritedFields = clazz.superClass match {
4138
case None => Nil
4239
case Some(sup) => ctx.getClassInfo(sup.name).allFieldDefs
4340
}
4441
val myFieldDefs = clazz.fields.collect {
45-
case fd: IRTrees.FieldDef if !fd.flags.namespace.isStatic =>
42+
case fd: FieldDef if !fd.flags.namespace.isStatic =>
4643
fd
47-
case fd: IRTrees.JSFieldDef =>
44+
case fd: JSFieldDef =>
4845
throw new AssertionError(s"Illegal $fd in Scala class ${clazz.className}")
4946
}
5047
inheritedFields ::: myFieldDefs
@@ -56,7 +53,7 @@ object Preprocessor {
5653
if (kind.isClass || kind == ClassKind.HijackedClass) {
5754
for {
5855
m <- clazz.methods
59-
if m.body.isDefined && m.flags.namespace == IRTrees.MemberNamespace.Public
56+
if m.body.isDefined && m.flags.namespace == MemberNamespace.Public
6057
} yield {
6158
m.methodName
6259
}
@@ -109,14 +106,14 @@ object Preprocessor {
109106
clazz.ancestors.foreach(ctx.getClassInfo(_).addSpecialInstanceType(jsValueType))
110107

111108
clazz.className match {
112-
case IRNames.BoxedBooleanClass =>
109+
case BoxedBooleanClass =>
113110
addSpecialInstanceTypeOnAllAncestors(JSValueTypeFalse)
114111
addSpecialInstanceTypeOnAllAncestors(JSValueTypeTrue)
115-
case IRNames.BoxedStringClass =>
112+
case BoxedStringClass =>
116113
addSpecialInstanceTypeOnAllAncestors(JSValueTypeString)
117-
case IRNames.BoxedDoubleClass =>
114+
case BoxedDoubleClass =>
118115
addSpecialInstanceTypeOnAllAncestors(JSValueTypeNumber)
119-
case IRNames.BoxedUnitClass =>
116+
case BoxedUnitClass =>
120117
addSpecialInstanceTypeOnAllAncestors(JSValueTypeUndefined)
121118
case _ =>
122119
()
@@ -151,8 +148,6 @@ object Preprocessor {
151148
* we have val `x: C` and we call `x.c`, we don't find the method at all.
152149
*/
153150
private class AbstractMethodCallCollector(ctx: WasmContext) extends Traversers.Traverser {
154-
import IRTrees._
155-
156151
def collectAbstractMethodCalls(clazz: LinkedClass): Unit = {
157152
for (method <- clazz.methods)
158153
traverseMethodDef(method)
@@ -164,7 +159,7 @@ object Preprocessor {
164159

165160
def collectAbstractMethodCalls(tle: LinkedTopLevelExport): Unit = {
166161
tle.tree match {
167-
case IRTrees.TopLevelMethodExportDef(_, jsMethodDef) =>
162+
case TopLevelMethodExportDef(_, jsMethodDef) =>
168163
traverseJSMethodPropDef(jsMethodDef)
169164
case _ =>
170165
()
@@ -177,12 +172,12 @@ object Preprocessor {
177172
tree match {
178173
case Apply(flags, receiver, methodName, _) if !methodName.name.isReflectiveProxy =>
179174
receiver.tpe match {
180-
case IRTypes.ClassType(className) =>
175+
case ClassType(className) =>
181176
val classInfo = ctx.getClassInfo(className)
182177
if (classInfo.hasInstances)
183178
classInfo.registerDynamicCall(methodName.name)
184-
case IRTypes.AnyType =>
185-
ctx.getClassInfo(IRNames.ObjectClass).registerDynamicCall(methodName.name)
179+
case AnyType =>
180+
ctx.getClassInfo(ObjectClass).registerDynamicCall(methodName.name)
186181
case _ =>
187182
// For all other cases, including arrays, we will always perform a static dispatch
188183
()

0 commit comments

Comments
 (0)