JS: fix fragment info loading
The very first fragment didn't got processed, thus inline cycle reporter was not failing tests
This commit is contained in:
committed by
Anton Bannykh
parent
370194796e
commit
b7bea3242e
+21
-18
@@ -70,7 +70,7 @@ class FunctionDefinitionLoader(
|
|||||||
*/
|
*/
|
||||||
private fun getFunctionDefinitionImpl(call: JsInvocation, scope: InliningScope): InlineFunctionDefinition? {
|
private fun getFunctionDefinitionImpl(call: JsInvocation, scope: InliningScope): InlineFunctionDefinition? {
|
||||||
// Ensure we have the local function information
|
// Ensure we have the local function information
|
||||||
loadFragment(scope.fragment)
|
assert(scope.fragment in fragmentInfo)
|
||||||
|
|
||||||
return lookUpFunctionDirect(call, scope) ?: lookUpFunctionIndirect(call, scope) ?: lookUpFunctionExternal(call, scope.fragment)
|
return lookUpFunctionDirect(call, scope) ?: lookUpFunctionIndirect(call, scope) ?: lookUpFunctionExternal(call, scope.fragment)
|
||||||
}
|
}
|
||||||
@@ -80,9 +80,22 @@ class FunctionDefinitionLoader(
|
|||||||
private data class FragmentInfo(
|
private data class FragmentInfo(
|
||||||
val functions: Map<JsName, FunctionWithWrapper>,
|
val functions: Map<JsName, FunctionWithWrapper>,
|
||||||
val accessors: Map<String, FunctionWithWrapper>,
|
val accessors: Map<String, FunctionWithWrapper>,
|
||||||
val localAccessors: Map<CallableDescriptor, FunctionWithWrapper>)
|
val localAccessors: Map<CallableDescriptor, FunctionWithWrapper>
|
||||||
|
)
|
||||||
|
|
||||||
private val fragmentInfo = mutableMapOf<JsProgramFragment, FragmentInfo>()
|
private fun JsProgramFragment.loadInfo(): FragmentInfo {
|
||||||
|
return FragmentInfo(
|
||||||
|
collectNamedFunctionsAndWrappers(listOf(this)),
|
||||||
|
collectAccessors(listOf(this)),
|
||||||
|
collectLocalFunctions(listOf(this))
|
||||||
|
).also { (functions, accessors) ->
|
||||||
|
(functions.values.asSequence() + accessors.values.asSequence()).forEach { f ->
|
||||||
|
functionsByFunctionNodes[f.function] = f
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private val fragmentInfo = inliner.translationResult.newFragments.associateTo(mutableMapOf()) { it to it.loadInfo() }
|
||||||
|
|
||||||
private fun lookUpStaticFunction(functionName: JsName?, fragment: JsProgramFragment): FunctionWithWrapper? =
|
private fun lookUpStaticFunction(functionName: JsName?, fragment: JsProgramFragment): FunctionWithWrapper? =
|
||||||
fragmentInfo[fragment]?.run { functions[functionName] }
|
fragmentInfo[fragment]?.run { functions[functionName] }
|
||||||
@@ -134,23 +147,13 @@ class FunctionDefinitionLoader(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadFragment(fragment: JsProgramFragment) {
|
|
||||||
fragmentInfo.computeIfAbsent(fragment) {
|
|
||||||
FragmentInfo(
|
|
||||||
collectNamedFunctionsAndWrappers(listOf(fragment)),
|
|
||||||
collectAccessors(listOf(fragment)),
|
|
||||||
collectLocalFunctions(listOf(fragment))
|
|
||||||
).also { (functions, accessors) ->
|
|
||||||
(functions.values.asSequence() + accessors.values.asSequence()).forEach { f ->
|
|
||||||
functionsByFunctionNodes[f.function] = f
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun fragmentByTag(tag: String): JsProgramFragment? {
|
private fun fragmentByTag(tag: String): JsProgramFragment? {
|
||||||
return inliner.translationResult.inlineFunctionTagMap[tag]?.let { unit ->
|
return inliner.translationResult.inlineFunctionTagMap[tag]?.let { unit ->
|
||||||
inliner.translationResult.getTranslationResult(unit).fragment.also { loadFragment(it) }
|
inliner.translationResult.getTranslationResult(unit).fragment.also { fragment ->
|
||||||
|
fragmentInfo.computeIfAbsent(fragment) {
|
||||||
|
fragment.loadInfo()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user