Remove duplicate parameter null checks in JvmStatic delegate methods.
Remove unnecessary non-null parameter checks inside static delegate methods created for @JvmStatic companion object methods. Allows function generation strategy decide if such checks need to be injected. #KT-7188 Fixed
This commit is contained in:
committed by
Dmitry Petrov
parent
9e82ab38f0
commit
52ccd67ec1
@@ -558,7 +558,7 @@ public class FunctionCodegen {
|
||||
mv.visitLabel(methodEntry);
|
||||
context.setMethodStartLabel(methodEntry);
|
||||
|
||||
if (!KotlinTypeMapper.isAccessor(functionDescriptor)) {
|
||||
if (!strategy.skipNotNullAssertionsForParameters()) {
|
||||
genNotNullAssertionsForParameters(new InstructionAdapter(mv), parentCodegen.state, functionDescriptor, frameMap);
|
||||
}
|
||||
|
||||
@@ -1383,6 +1383,11 @@ public class FunctionCodegen {
|
||||
|
||||
iv.areturn(delegateMethod.getReturnType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean skipNotNullAssertionsForParameters() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -34,6 +34,8 @@ public abstract class FunctionGenerationStrategy {
|
||||
@NotNull MemberCodegen<?> parentCodegen
|
||||
);
|
||||
|
||||
public abstract boolean skipNotNullAssertionsForParameters();
|
||||
|
||||
public MethodVisitor wrapMethodVisitor(@NotNull MethodVisitor mv, int access, @NotNull String name, @NotNull String desc) {
|
||||
return mv;
|
||||
}
|
||||
@@ -76,6 +78,12 @@ public abstract class FunctionGenerationStrategy {
|
||||
doGenerateBody(codegen, signature);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean skipNotNullAssertionsForParameters() {
|
||||
// Assume the strategy injects non-null checks for parameters by default
|
||||
return false;
|
||||
}
|
||||
|
||||
public abstract void doGenerateBody(@NotNull ExpressionCodegen codegen, @NotNull JvmMethodSignature signature);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -671,6 +671,11 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
}
|
||||
iv.areturn(componentType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean skipNotNullAssertionsForParameters() {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -719,6 +724,11 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
iv.areturn(thisDescriptorType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean skipNotNullAssertionsForParameters() {
|
||||
return false;
|
||||
}
|
||||
|
||||
private void pushCapturedFieldsOnStack(InstructionAdapter iv, MutableClosure closure) {
|
||||
ClassDescriptor captureThis = closure.getCaptureThis();
|
||||
if (captureThis != null) {
|
||||
|
||||
+2
@@ -44,6 +44,8 @@ class JvmStaticInCompanionObjectGenerator(
|
||||
Synthetic(originElement, staticFunctionDescriptor),
|
||||
staticFunctionDescriptor,
|
||||
object : FunctionGenerationStrategy.CodegenBased(state) {
|
||||
override fun skipNotNullAssertionsForParameters(): Boolean = true
|
||||
|
||||
override fun doGenerateBody(codegen: ExpressionCodegen, signature: JvmMethodSignature) {
|
||||
val iv = codegen.v
|
||||
val classDescriptor = descriptor.containingDeclaration as ClassDescriptor
|
||||
|
||||
@@ -719,6 +719,11 @@ public abstract class MemberCodegen<T extends KtPureElement/* TODO: & KtDeclarat
|
||||
functionCodegen.generateMethod(
|
||||
Synthetic(null, original), accessor,
|
||||
new FunctionGenerationStrategy.CodegenBased(state) {
|
||||
@Override
|
||||
public boolean skipNotNullAssertionsForParameters() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doGenerateBody(@NotNull ExpressionCodegen codegen, @NotNull JvmMethodSignature signature) {
|
||||
markLineNumberForElement(element.getPsiOrParent(), codegen.v);
|
||||
@@ -779,6 +784,11 @@ public abstract class MemberCodegen<T extends KtPureElement/* TODO: & KtDeclarat
|
||||
|
||||
iv.areturn(signature.getReturnType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean skipNotNullAssertionsForParameters() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (accessor.isWithSyntheticGetterAccessor()) {
|
||||
|
||||
@@ -312,6 +312,10 @@ class MultifileClassCodegenImpl(
|
||||
}
|
||||
|
||||
object DelegateToCompiledMemberGenerationStrategy : FunctionGenerationStrategy() {
|
||||
override fun skipNotNullAssertionsForParameters(): kotlin.Boolean {
|
||||
throw IllegalStateException("shouldn't be called")
|
||||
}
|
||||
|
||||
override fun generateBody(mv: MethodVisitor, frameMap: FrameMap, signature: JvmMethodSignature, context: MethodContext, parentCodegen: MemberCodegen<*>) {
|
||||
throw IllegalStateException("shouldn't be called")
|
||||
}
|
||||
|
||||
@@ -531,6 +531,10 @@ class CoroutineCodegenForNamedFunction private constructor(
|
||||
private const val COROUTINE_LAMBDA_PARAMETER_PREFIX = "p$"
|
||||
|
||||
private object FailingFunctionGenerationStrategy : FunctionGenerationStrategy() {
|
||||
override fun skipNotNullAssertionsForParameters(): kotlin.Boolean {
|
||||
error("This functions must not be called")
|
||||
}
|
||||
|
||||
override fun generateBody(
|
||||
mv: MethodVisitor,
|
||||
frameMap: FrameMap,
|
||||
|
||||
Reference in New Issue
Block a user