Drop annotations from stdlib and compiler

This commit is contained in:
Alexey Tsvetkov
2015-10-16 18:14:24 +03:00
parent c50aab6a75
commit df8066b1e4
14 changed files with 34 additions and 216 deletions
-19
View File
@@ -80,16 +80,6 @@ public annotation class Extension
@Retention(SOURCE)
public annotation class Suppress(vararg val names: String)
/**
* Enables the tail call optimization for the annotated function. If the annotated function
* calls itself recursively as the last operation it performs, it will be executed without
* growing the stack depth. Tail call optimization is currently only supported by the JVM
* backend.
*/
@Target(FUNCTION)
@Retention(SOURCE)
private annotation class tailrec
/**
* Hides the annotated function, property or constructor from the overload resolution,
* thus preventing its usages from newly compiled code, but keeps compiling it
@@ -101,15 +91,6 @@ private annotation class tailrec
@Deprecated("Use @Deprecated(\"...\", level = DeprecationLevel.HIDDEN) instead", replaceWith = ReplaceWith("@Deprecated(, level = DeprecationLevel.HIDDEN)"))
public annotation class HiddenDeclaration
/**
* Marks annotated function as `external`, meaning that it's not implemented
* in Kotlin but rather in a different language (for example, in C/C++ using JNI or JavaScript).
*/
@Target(FUNCTION, PROPERTY_GETTER, PROPERTY_SETTER)
@Retention(SOURCE)
@MustBeDocumented
private annotation class external
/**
* Suppresses errors about variance conflict
*/
-48
View File
@@ -1,48 +0,0 @@
/*
* Copyright 2010-2015 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
/**
* Annotates the parameter of a function annotated as [inline] and forbids inlining of
* function literals passed as arguments for this parameter.
*/
@Target(AnnotationTarget.VALUE_PARAMETER)
@Retention(AnnotationRetention.RUNTIME)
@MustBeDocumented
private annotation class noinline
/**
* Enables inlining of the annotated function and the function literals that it takes as parameters into the
* calling functions. Inline functions can use reified type parameters, and lambdas passed to inline
* functions can contain non-local returns.
* See the [Kotlin language documentation](http://kotlinlang.org/docs/reference/inline-functions.html) for more information.
*
* @see noinline
* @see crossinline
*/
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY)
@Retention(AnnotationRetention.RUNTIME)
@MustBeDocumented
private annotation class inline
/**
* Forbids use of non-local control flow statements within lambdas passed as arguments for this parameter.
*/
@Target(AnnotationTarget.VALUE_PARAMETER)
@Retention(AnnotationRetention.RUNTIME)
@MustBeDocumented
private annotation class crossinline
@@ -140,9 +140,6 @@ public abstract class KotlinBuiltIns {
public final FqName deprecated = fqName("Deprecated");
public final FqName tailRecursive = fqName("tailrec");
public final FqName inline = fqName("inline");
public final FqName noinline = fqName("noinline");
public final FqName crossinline = fqName("crossinline");
public final FqName extension = fqName("Extension");
public final FqName target = annotationName("Target");
public final FqName annotationTarget = annotationName("AnnotationTarget");
@@ -1025,15 +1022,6 @@ public abstract class KotlinBuiltIns {
return containsAnnotation(declarationDescriptor, FQ_NAMES.deprecated);
}
public static boolean isTailRecursive(@NotNull DeclarationDescriptor declarationDescriptor) {
return containsAnnotation(declarationDescriptor, FQ_NAMES.tailRecursive);
}
/** Checks that the symbol represented by the descriptor is annotated with the {@code kotlin.noinline} annotation */
public static boolean isNoinline(@NotNull DeclarationDescriptor descriptor) {
return containsAnnotation(descriptor, FQ_NAMES.noinline);
}
public static boolean isSuppressAnnotation(@NotNull AnnotationDescriptor annotationDescriptor) {
return isConstructedFromGivenClass(annotationDescriptor.getType(), FQ_NAMES.suppress);
}
@@ -19,17 +19,12 @@ package org.jetbrains.kotlin.descriptors.annotations
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.SourceElement
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.constants.AnnotationValue
import org.jetbrains.kotlin.resolve.constants.ArrayValue
import org.jetbrains.kotlin.resolve.constants.StringValue
import org.jetbrains.kotlin.types.Variance
// Please synchronize this set with JetTokens.ANNOTATION_MODIFIERS_KEYWORDS_ARRAY
public val ANNOTATION_MODIFIERS_FQ_NAMES: Set<FqName> =
arrayOf("inline", "noinline", "tailrec", "external", "crossinline").map { FqName("kotlin.$it") }.toSet()
public fun KotlinBuiltIns.createDeprecatedAnnotation(message: String, replaceWith: String): AnnotationDescriptor {
val deprecatedAnnotation = deprecatedAnnotation
val parameters = deprecatedAnnotation.unsubstitutedPrimaryConstructor!!.valueParameters
@@ -18,7 +18,6 @@ package org.jetbrains.kotlin.renderer
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.annotations.ANNOTATION_MODIFIERS_FQ_NAMES
import org.jetbrains.kotlin.descriptors.annotations.Annotated
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget
@@ -31,7 +30,6 @@ import org.jetbrains.kotlin.resolve.constants.AnnotationValue
import org.jetbrains.kotlin.resolve.constants.ArrayValue
import org.jetbrains.kotlin.resolve.constants.ConstantValue
import org.jetbrains.kotlin.resolve.constants.KClassValue
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
import org.jetbrains.kotlin.resolve.descriptorUtil.hasDefaultValue
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.ErrorUtils.UninferredParameterTypeConstructor
@@ -347,7 +345,7 @@ internal class DescriptorRendererImpl(
// See AnnotationResolver.resolveAndAppendAnnotationsFromModifiers for clarification
// This hack can be removed when modifiers will be resolved without annotations
val sortedAnnotations = annotated.getAnnotations().getAllAnnotations().sortedBy { p -> p.annotation.isBuiltinModifier() }
val sortedAnnotations = annotated.getAnnotations().getAllAnnotations()
for ((annotation, target) in sortedAnnotations) {
val annotationClass = annotation.getType().getConstructor().getDeclarationDescriptor() as ClassDescriptor
@@ -360,9 +358,6 @@ internal class DescriptorRendererImpl(
builder.append(annotationsBuilder)
}
private fun AnnotationDescriptor.isBuiltinModifier()
= (type.constructor.declarationDescriptor as ClassDescriptor).fqNameSafe in ANNOTATION_MODIFIERS_FQ_NAMES
override fun renderAnnotation(annotation: AnnotationDescriptor, target: AnnotationUseSiteTarget?): String {
return StringBuilder {
append('@')