8000 Add a flag to class level info for dynamic import · scala-js/scala-js@a54c022 · GitHub
[go: up one dir, main page]

Skip to content

Commit a54c022

Browse files
committed
Add a flag to class level info for dynamic import
This allows us to remove a field from `ReachabilityInfoInClass` which reduces the retained size on the test suite for the infos as follows: BaseLinker: 24MB -> 23MB Refiner: 20MB -> 20MB (within rounding error)
1 parent 6dcd1b7 commit a54c022

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

linker/shared/src/main/scala/org/scalajs/linker/analyzer/Analyzer.scala

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,6 +1432,13 @@ private class AnalyzerRun(config: CommonPhaseConfig, initial: Boolean,
14321432
if ((flags & ReachabilityInfoInClass.FlagStaticallyReferenced) != 0) {
14331433
moduleUnit.addStaticDependency(className)
14341434
}
1435+
1436+
if ((flags & ReachabilityInfoInClass.FlagDynamicallyReferenced) != 0) {
1437+
if (isNoModule)
1438+
_errors ::= DynamicImportWithoutModuleSupport(from)
1439+
else
1440+
moduleUnit.addDynamicDependency(className)
1441+
}
14351442
}
14361443

14371444
/* Since many of the lists below are likely to be empty, we always
@@ -1467,17 +1474,6 @@ private class AnalyzerRun(config: CommonPhaseConfig, initial: Boolean,
14671474
clazz.callMethodStatically(methodName)
14681475
}
14691476

1470-
if (!dataInClass.methodsCalledDynamicImport.isEmpty) {
1471-
if (isNoModule) {
1472-
_errors ::= DynamicImportWithoutModuleSupport(from)
1473-
} else {
1474-
moduleUnit.addDynamicDependency(className)
1475-
// In terms of reachability, a dynamic import call is just a static call.
1476-
for (methodName <- dataInClass.methodsCalledDynamicImport)
1477-
clazz.callMethodStatically(methodName)
1478-
}
1479-
}
1480-
14811477
if (!dataInClass.jsNativeMembersUsed.isEmpty) {
14821478
for (member <- dataInClass.jsNativeMembersUsed)
14831479
clazz.useJSNativeMember(member)

linker/shared/src/main/scala/org/scalajs/linker/analyzer/Infos.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ object Infos {
115115
val staticFieldsWritten: List[FieldName],
116116
val methodsCalled: List[MethodName],
117117
val methodsCalledStatically: List[NamespacedMethodName],
118-
val methodsCalledDynamicImport: List[NamespacedMethodName],
119118
val jsNativeMembersUsed: List[MethodName],
120119
val flags: ReachabilityInfoInClass.Flags
121120
)
@@ -132,6 +131,7 @@ object Infos {
132131
final val FlagInstanceTestsUsed = 1 << 2
133132
final val FlagClassDataAccessed = 1 << 3
134133
final val FlagStaticallyReferenced = 1 << 4
134+
final val FlagDynamicallyReferenced = 1 << 5
135135
}
136136

137137
final class ClassInfoBuilder(
@@ -384,7 +384,6 @@ object Infos {
384384
private val staticFieldsWritten = mutable.Set.empty[FieldName]
385385
private val methodsCalled = mutable.Set.empty[MethodName]
386386
private val methodsCalledStatically = mutable.Set.empty[NamespacedMethodName]
387-
private val methodsCalledDynamicImport = mutable.Set.empty[NamespacedMethodName]
388387
private val jsNativeMembersUsed = mutable.Set.empty[MethodName]
389388
private var flags: ReachabilityInfoInClass.Flags = 0
390389

@@ -423,7 +422,9 @@ object Infos {
423422
}
424423

425424
def addMethodCalledDynamicImport(method: NamespacedMethodName): this.type = {
426-
methodsCalledDynamicImport += method
425+
// In terms of reachability, a dynamic import call is just a static call.
426+
methodsCalledStatically += method
427+
setFlag(ReachabilityInfoInClass.FlagDynamicallyReferenced)
427428
this
428429
}
429430

@@ -461,7 +462,6 @@ object Infos {
461462
staticFieldsWritten = toLikelyEmptyList(staticFieldsWritten),
462463
methodsCalled = toLikelyEmptyList(methodsCalled),
463464
methodsCalledStatically = toLikelyEmptyList(methodsCalledStatically),
464-
methodsCalledDynamicImport = toLikelyEmptyList(methodsCalledDynamicImport),
465465
jsNativeMembersUsed = toLikelyEmptyList(jsNativeMembersUsed),
466466
flags = flags
467467
)

0 commit comments

Comments
 (0)
0