Skip to content

Commit

Permalink
Add a flag to class level info for dynamic import
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
gzm0 committed Apr 13, 2024
1 parent 6dcd1b7 commit a54c022
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1432,6 +1432,13 @@ private class AnalyzerRun(config: CommonPhaseConfig, initial: Boolean,
if ((flags & ReachabilityInfoInClass.FlagStaticallyReferenced) != 0) {
moduleUnit.addStaticDependency(className)
}

if ((flags & ReachabilityInfoInClass.FlagDynamicallyReferenced) != 0) {
if (isNoModule)
_errors ::= DynamicImportWithoutModuleSupport(from)
else
moduleUnit.addDynamicDependency(className)
}
}

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

if (!dataInClass.methodsCalledDynamicImport.isEmpty) {
if (isNoModule) {
_errors ::= DynamicImportWithoutModuleSupport(from)
} else {
moduleUnit.addDynamicDependency(className)
// In terms of reachability, a dynamic import call is just a static call.
for (methodName <- dataInClass.methodsCalledDynamicImport)
clazz.callMethodStatically(methodName)
}
}

if (!dataInClass.jsNativeMembersUsed.isEmpty) {
for (member <- dataInClass.jsNativeMembersUsed)
clazz.useJSNativeMember(member)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ object Infos {
val staticFieldsWritten: List[FieldName],
val methodsCalled: List[MethodName],
val methodsCalledStatically: List[NamespacedMethodName],
val methodsCalledDynamicImport: List[NamespacedMethodName],
val jsNativeMembersUsed: List[MethodName],
val flags: ReachabilityInfoInClass.Flags
)
Expand All @@ -132,6 +131,7 @@ object Infos {
final val FlagInstanceTestsUsed = 1 << 2
final val FlagClassDataAccessed = 1 << 3
final val FlagStaticallyReferenced = 1 << 4
final val FlagDynamicallyReferenced = 1 << 5
}

final class ClassInfoBuilder(
Expand Down Expand Up @@ -384,7 +384,6 @@ object Infos {
private val staticFieldsWritten = mutable.Set.empty[FieldName]
private val methodsCalled = mutable.Set.empty[MethodName]
private val methodsCalledStatically = mutable.Set.empty[NamespacedMethodName]
private val methodsCalledDynamicImport = mutable.Set.empty[NamespacedMethodName]
private val jsNativeMembersUsed = mutable.Set.empty[MethodName]
private var flags: ReachabilityInfoInClass.Flags = 0

Expand Down Expand Up @@ -423,7 +422,9 @@ object Infos {
}

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

Expand Down Expand Up @@ -461,7 +462,6 @@ object Infos {
staticFieldsWritten = toLikelyEmptyList(staticFieldsWritten),
methodsCalled = toLikelyEmptyList(methodsCalled),
methodsCalledStatically = toLikelyEmptyList(methodsCalledStatically),
methodsCalledDynamicImport = toLikelyEmptyList(methodsCalledDynamicImport),
jsNativeMembersUsed = toLikelyEmptyList(jsNativeMembersUsed),
flags = flags
)
Expand Down

0 comments on commit a54c022

Please sign in to comment.