Remove unnecessary getAllTypeArguments method from Stack class
This commit is contained in:
+7
-6
@@ -32,7 +32,7 @@ import java.lang.invoke.MethodHandle
|
|||||||
private const val MAX_STACK_SIZE = 10_000
|
private const val MAX_STACK_SIZE = 10_000
|
||||||
private const val MAX_COMMANDS = 500_000
|
private const val MAX_COMMANDS = 500_000
|
||||||
|
|
||||||
class IrInterpreter(irModule: IrModuleFragment, private val declarationsMap: Map<IdSignature, IrBody> = emptyMap()) {
|
class IrInterpreter(irModule: IrModuleFragment, private val bodyMap: Map<IdSignature, IrBody> = emptyMap()) {
|
||||||
private val irBuiltIns = irModule.irBuiltins
|
private val irBuiltIns = irModule.irBuiltins
|
||||||
private val irExceptions = irModule.files.flatMap { it.declarations }.filterIsInstance<IrClass>()
|
private val irExceptions = irModule.files.flatMap { it.declarations }.filterIsInstance<IrClass>()
|
||||||
.filter { it.isSubclassOf(irBuiltIns.throwableClass.owner) }
|
.filter { it.isSubclassOf(irBuiltIns.throwableClass.owner) }
|
||||||
@@ -301,14 +301,15 @@ class IrInterpreter(irModule: IrModuleFragment, private val declarationsMap: Map
|
|||||||
dispatchReceiver is Wrapper && !isInlineOnly -> dispatchReceiver.getMethod(irFunction).invokeMethod(irFunction)
|
dispatchReceiver is Wrapper && !isInlineOnly -> dispatchReceiver.getMethod(irFunction).invokeMethod(irFunction)
|
||||||
irFunction.hasAnnotation(evaluateIntrinsicAnnotation) -> Wrapper.getStaticMethod(irFunction).invokeMethod(irFunction)
|
irFunction.hasAnnotation(evaluateIntrinsicAnnotation) -> Wrapper.getStaticMethod(irFunction).invokeMethod(irFunction)
|
||||||
dispatchReceiver is Primitive<*> -> calculateBuiltIns(irFunction) // 'is Primitive' check for js char and js long
|
dispatchReceiver is Primitive<*> -> calculateBuiltIns(irFunction) // 'is Primitive' check for js char and js long
|
||||||
irFunction.body == null -> irFunction.substituteFunctionBody()
|
irFunction.body == null -> irFunction.trySubstituteFunctionBody() ?: calculateBuiltIns(irFunction)
|
||||||
else -> irFunction.interpret()
|
else -> irFunction.interpret()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun IrFunction.substituteFunctionBody(): ExecutionResult {
|
private suspend fun IrFunction.trySubstituteFunctionBody(): ExecutionResult? {
|
||||||
val body = declarationsMap[this.symbol.signature]
|
if (!this.symbol.isPublicApi) return null
|
||||||
|
val body = bodyMap[this.symbol.signature]
|
||||||
|
|
||||||
return body?.let {
|
return body?.let {
|
||||||
try {
|
try {
|
||||||
@@ -317,7 +318,7 @@ class IrInterpreter(irModule: IrModuleFragment, private val declarationsMap: Map
|
|||||||
} finally {
|
} finally {
|
||||||
this.body = null
|
this.body = null
|
||||||
}
|
}
|
||||||
} ?: calculateBuiltIns(this)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun interpretInstanceInitializerCall(call: IrInstanceInitializerCall): ExecutionResult {
|
private suspend fun interpretInstanceInitializerCall(call: IrInstanceInitializerCall): ExecutionResult {
|
||||||
@@ -349,7 +350,7 @@ class IrInterpreter(irModule: IrModuleFragment, private val declarationsMap: Map
|
|||||||
interpretValueParameters(constructorCall, owner, valueArguments).check { return it }
|
interpretValueParameters(constructorCall, owner, valueArguments).check { return it }
|
||||||
|
|
||||||
val irClass = owner.parent as IrClass
|
val irClass = owner.parent as IrClass
|
||||||
val typeArguments = getTypeArguments(irClass, constructorCall) { stack.getVariableState(it) } + stack.getAllTypeArguments()
|
val typeArguments = getTypeArguments(irClass, constructorCall) { stack.getVariableState(it) }
|
||||||
if (irClass.hasAnnotation(evaluateIntrinsicAnnotation) || irClass.fqNameWhenAvailable!!.startsWith(Name.identifier("java"))) {
|
if (irClass.hasAnnotation(evaluateIntrinsicAnnotation) || irClass.fqNameWhenAvailable!!.startsWith(Name.identifier("java"))) {
|
||||||
return stack.newFrame(initPool = valueArguments) { Wrapper.getConstructorMethod(owner).invokeMethod(owner) }
|
return stack.newFrame(initPool = valueArguments) { Wrapper.getConstructorMethod(owner).invokeMethod(owner) }
|
||||||
.apply { (stack.peekReturnValue() as? Wrapper)?.typeArguments?.addAll(typeArguments) } // 'as?' because can be exception
|
.apply { (stack.peekReturnValue() as? Wrapper)?.typeArguments?.addAll(typeArguments) } // 'as?' because can be exception
|
||||||
|
|||||||
-5
@@ -17,7 +17,6 @@ interface Frame {
|
|||||||
fun getVariableState(variableDescriptor: DeclarationDescriptor): State
|
fun getVariableState(variableDescriptor: DeclarationDescriptor): State
|
||||||
fun tryGetVariableState(variableDescriptor: DeclarationDescriptor): State?
|
fun tryGetVariableState(variableDescriptor: DeclarationDescriptor): State?
|
||||||
fun getAll(): List<Variable>
|
fun getAll(): List<Variable>
|
||||||
fun getAllTypeArguments(): List<Variable> // TODO try to get rid of this method; possibly by finding all type arguments in local class
|
|
||||||
fun contains(descriptor: DeclarationDescriptor): Boolean
|
fun contains(descriptor: DeclarationDescriptor): Boolean
|
||||||
fun pushReturnValue(state: State)
|
fun pushReturnValue(state: State)
|
||||||
fun pushReturnValue(frame: Frame) // TODO rename to getReturnValueFrom
|
fun pushReturnValue(frame: Frame) // TODO rename to getReturnValueFrom
|
||||||
@@ -55,10 +54,6 @@ class InterpreterFrame(
|
|||||||
return pool
|
return pool
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getAllTypeArguments(): List<Variable> {
|
|
||||||
return typeArguments
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun contains(descriptor: DeclarationDescriptor): Boolean {
|
override fun contains(descriptor: DeclarationDescriptor): Boolean {
|
||||||
return (typeArguments + pool).any { it.descriptor == descriptor }
|
return (typeArguments + pool).any { it.descriptor == descriptor }
|
||||||
}
|
}
|
||||||
|
|||||||
-6
@@ -30,7 +30,6 @@ interface Stack {
|
|||||||
fun addAll(variables: List<Variable>)
|
fun addAll(variables: List<Variable>)
|
||||||
fun getVariableState(variableDescriptor: DeclarationDescriptor): State
|
fun getVariableState(variableDescriptor: DeclarationDescriptor): State
|
||||||
fun getAll(): List<Variable>
|
fun getAll(): List<Variable>
|
||||||
fun getAllTypeArguments(): List<Variable>
|
|
||||||
|
|
||||||
fun contains(descriptor: DeclarationDescriptor): Boolean
|
fun contains(descriptor: DeclarationDescriptor): Boolean
|
||||||
fun hasReturnValue(): Boolean
|
fun hasReturnValue(): Boolean
|
||||||
@@ -95,10 +94,6 @@ class StackImpl : Stack {
|
|||||||
return getCurrentFrame().getAll()
|
return getCurrentFrame().getAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getAllTypeArguments(): List<Variable> {
|
|
||||||
return getCurrentFrame().getAllTypeArguments()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun contains(descriptor: DeclarationDescriptor): Boolean {
|
override fun contains(descriptor: DeclarationDescriptor): Boolean {
|
||||||
return getCurrentFrame().contains(descriptor)
|
return getCurrentFrame().contains(descriptor)
|
||||||
}
|
}
|
||||||
@@ -137,7 +132,6 @@ private class FrameContainer(current: Frame = InterpreterFrame()) {
|
|||||||
fun addVar(variable: Variable) = getTopFrame().addVar(variable)
|
fun addVar(variable: Variable) = getTopFrame().addVar(variable)
|
||||||
fun addAll(variables: List<Variable>) = getTopFrame().addAll(variables)
|
fun addAll(variables: List<Variable>) = getTopFrame().addAll(variables)
|
||||||
fun getAll() = innerStack.flatMap { it.getAll() }
|
fun getAll() = innerStack.flatMap { it.getAll() }
|
||||||
fun getAllTypeArguments() = innerStack.flatMap { it.getAllTypeArguments() }
|
|
||||||
fun getVariableState(variableDescriptor: DeclarationDescriptor): State {
|
fun getVariableState(variableDescriptor: DeclarationDescriptor): State {
|
||||||
return innerStack.firstNotNullResult { it.tryGetVariableState(variableDescriptor) }
|
return innerStack.firstNotNullResult { it.tryGetVariableState(variableDescriptor) }
|
||||||
?: throw InterpreterException("$variableDescriptor not found") // TODO better message
|
?: throw InterpreterException("$variableDescriptor not found") // TODO better message
|
||||||
|
|||||||
Reference in New Issue
Block a user