Support inlining 'arrayOf' and 'emptyArray' with no stdlib in classpath
Previously an exception was thrown on trying to inline arrayOf/emptyArray when compiling with "-no-stdlib" (or in tests without a dependency on the stdlib), because these functions were found in a built-in package fragment which does not have the bytecode associated with it
This commit is contained in:
committed by
Alexander Udalov
parent
bb4397612d
commit
54a615fcd3
@@ -22,6 +22,7 @@ import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.backend.common.CodegenUtil;
|
||||
import org.jetbrains.kotlin.builtins.BuiltinsPackageFragment;
|
||||
import org.jetbrains.kotlin.codegen.*;
|
||||
import org.jetbrains.kotlin.codegen.context.*;
|
||||
import org.jetbrains.kotlin.codegen.intrinsics.IntrinsicArrayConstructorsKt;
|
||||
@@ -195,7 +196,7 @@ public class InlineCodegen extends CallGenerator {
|
||||
: jvmSignature.getAsmMethod();
|
||||
|
||||
SMAPAndMethodNode nodeAndSMAP;
|
||||
if (functionDescriptor instanceof FictitiousArrayConstructor) {
|
||||
if (isBuiltInArrayIntrinsic(functionDescriptor)) {
|
||||
nodeAndSMAP = InlineCodegenUtil.getMethodNode(
|
||||
IntrinsicArrayConstructorsKt.getBytecode(),
|
||||
asmMethod.getName(),
|
||||
@@ -267,6 +268,13 @@ public class InlineCodegen extends CallGenerator {
|
||||
return nodeAndSMAP;
|
||||
}
|
||||
|
||||
private static boolean isBuiltInArrayIntrinsic(@NotNull FunctionDescriptor functionDescriptor) {
|
||||
if (functionDescriptor instanceof FictitiousArrayConstructor) return true;
|
||||
String name = functionDescriptor.getName().asString();
|
||||
return (name.equals("arrayOf") || name.equals("emptyArray")) &&
|
||||
functionDescriptor.getContainingDeclaration() instanceof BuiltinsPackageFragment;
|
||||
}
|
||||
|
||||
private InlineResult inlineCall(SMAPAndMethodNode nodeAndSmap) {
|
||||
MethodNode node = nodeAndSmap.getNode();
|
||||
ReifiedTypeParametersUsages reificationResult = reifiedTypeInliner.reifyInstructions(node);
|
||||
|
||||
+5
-1
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
@file:Suppress("unused")
|
||||
@file:Suppress("unused", "UNCHECKED_CAST", "CAST_NEVER_SUCCEEDS")
|
||||
|
||||
package org.jetbrains.kotlin.codegen.intrinsics
|
||||
|
||||
@@ -34,6 +34,10 @@ internal val bytecode: ByteArray by lazy {
|
||||
}
|
||||
}
|
||||
|
||||
private inline fun <reified T> emptyArray(): Array<T> = arrayOfNulls<T>(0) as Array<T>
|
||||
|
||||
private inline fun <reified T> arrayOf(vararg elements: T): Array<T> = elements as Array<T>
|
||||
|
||||
private inline fun <reified T> Array(size: Int, init: (Int) -> T): Array<T> {
|
||||
val result = arrayOfNulls<T>(size)
|
||||
for (i in 0..size - 1) {
|
||||
|
||||
Reference in New Issue
Block a user