Introduce inline-only functions
They have private visibility in bytecode
This commit is contained in:
@@ -323,6 +323,8 @@ public class AsmUtil {
|
||||
DeclarationDescriptor containingDeclaration = memberDescriptor.getContainingDeclaration();
|
||||
Visibility memberVisibility = memberDescriptor.getVisibility();
|
||||
|
||||
if (AnnotationUtilKt.isInlineOnly(memberDescriptor)) return ACC_PRIVATE;
|
||||
|
||||
if (memberVisibility == Visibilities.LOCAL && memberDescriptor instanceof CallableMemberDescriptor) {
|
||||
return ACC_PUBLIC;
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.load.java.JavaVisibilities;
|
||||
import org.jetbrains.kotlin.load.java.descriptors.SamConstructorDescriptor;
|
||||
import org.jetbrains.kotlin.psi.KtFile;
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||
import org.jetbrains.kotlin.resolve.annotations.AnnotationUtilKt;
|
||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager;
|
||||
import org.jetbrains.kotlin.storage.NullableLazyValue;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
@@ -609,6 +610,8 @@ public abstract class CodegenContext<T extends DeclarationDescriptor> {
|
||||
boolean withinInline,
|
||||
boolean isSuperCall
|
||||
) {
|
||||
if (AnnotationUtilKt.isInlineOnly(unwrappedDescriptor)) return false;
|
||||
|
||||
return isSuperCall && withinInline ||
|
||||
(accessFlag & ACC_PRIVATE) != 0 ||
|
||||
((accessFlag & ACC_PROTECTED) != 0 &&
|
||||
|
||||
@@ -16,9 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.resolve.annotations
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PropertyAccessorDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
@@ -62,4 +60,11 @@ fun AnnotationDescriptor.argumentValue(parameterName: String): Any? {
|
||||
return null
|
||||
|
||||
return constant.value
|
||||
}
|
||||
}
|
||||
|
||||
private val INLINE_ONLY_ANNOTATION_FQ_NAME = FqName("kotlin.jvm.internal.InlineOnly")
|
||||
|
||||
fun MemberDescriptor.isInlineOnly(): Boolean {
|
||||
if (this !is FunctionDescriptor) return false
|
||||
return typeParameters.any { it.isReified } || annotations.hasAnnotation(INLINE_ONLY_ANNOTATION_FQ_NAME)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
@kotlin.jvm.internal.InlineOnly
|
||||
inline fun foo() { }
|
||||
|
||||
inline fun <T> bar() { }
|
||||
|
||||
inline fun <U, reified V> baz() {}
|
||||
|
||||
class Foo {
|
||||
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
@kotlin.jvm.internal.InlineOnly
|
||||
inline fun foo() { }
|
||||
|
||||
inline fun <T> bar() { }
|
||||
|
||||
inline fun <U, reified V> baz() {}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
@kotlin.jvm.internal.KotlinClass
|
||||
public final class Foo {
|
||||
public method <init>(): void
|
||||
public final method bar(): void
|
||||
private final method baz(): void
|
||||
private final @kotlin.jvm.internal.InlineOnly method foo(): void
|
||||
}
|
||||
|
||||
@kotlin.jvm.internal.KotlinFileFacade
|
||||
public final class InlineOnlyKt {
|
||||
public final static method bar(): void
|
||||
private final static method baz(): void
|
||||
private final static @kotlin.jvm.internal.InlineOnly method foo(): void
|
||||
}
|
||||
@@ -41,6 +41,12 @@ public class BytecodeListingTestGenerated extends AbstractBytecodeListingTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("inlineOnly.kt")
|
||||
public void testInlineOnly() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeListing/inlineOnly.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/bytecodeListing/annotations")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package kotlin.jvm.internal
|
||||
|
||||
@Target(AnnotationTarget.FUNCTION)
|
||||
@Retention(AnnotationRetention.BINARY)
|
||||
internal annotation class InlineOnly
|
||||
Reference in New Issue
Block a user