Introduced ParameterDescriptor type

This commit is contained in:
Michael Bogdanov
2015-04-23 14:00:38 +03:00
parent 53b8a1d56e
commit df2900c4e4
9 changed files with 49 additions and 38 deletions
@@ -22,7 +22,6 @@ 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.KotlinBuiltIns;
import org.jetbrains.kotlin.codegen.*;
import org.jetbrains.kotlin.codegen.context.CodegenContext;
import org.jetbrains.kotlin.codegen.context.FieldOwnerContext;
@@ -463,8 +462,8 @@ public class InlineCodegen extends CallGenerator {
if (field instanceof StackValue.Field) {
DeclarationDescriptor varDescriptor = ((StackValue.Field) field).descriptor;
//check that variable is inline function parameter
return !(varDescriptor instanceof CallableDescriptor &&
InlineUtil.isInlineLambdaParameter((CallableDescriptor) varDescriptor) &&
return !(varDescriptor instanceof ParameterDescriptor &&
InlineUtil.isInlineLambdaParameter((ParameterDescriptor) varDescriptor) &&
InlineUtil.isInline(varDescriptor.getContainingDeclaration()));
}
@@ -218,11 +218,8 @@ class InlineChecker implements CallChecker {
}
}
private static boolean isInlinableParameter(@NotNull CallableDescriptor descriptor) {
JetType type = descriptor.getReturnType();
return type != null &&
InlineUtil.isInlineLambdaParameter(descriptor) &&
!type.isMarkedNullable();
private static boolean isInlinableParameter(@NotNull ParameterDescriptor descriptor) {
return InlineUtil.isInlineLambdaParameter(descriptor) && !descriptor.getType().isMarkedNullable();
}
private static boolean isInvokeOrInlineExtension(@NotNull CallableDescriptor descriptor) {
@@ -132,14 +132,13 @@ public class InlineAnalyzerExtension implements FunctionAnalyzerExtension.Analyz
}
public static boolean checkInlinableParameter(
@NotNull CallableDescriptor parameter,
@NotNull ParameterDescriptor parameter,
@NotNull JetElement expression,
@NotNull CallableDescriptor functionDescriptor,
@Nullable BindingTrace trace
) {
JetType type = parameter.getReturnType();
if (type != null && InlineUtil.isInlineLambdaParameter(parameter)) {
if (type.isMarkedNullable()) {
if (InlineUtil.isInlineLambdaParameter(parameter)) {
if (parameter.getType().isMarkedNullable()) {
if (trace != null) {
trace.report(Errors.NULLABLE_INLINE_PARAMETER.on(expression, expression, functionDescriptor));
}
@@ -35,16 +35,13 @@ import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
import org.jetbrains.kotlin.resolve.constants.ArrayValue;
import org.jetbrains.kotlin.resolve.constants.CompileTimeConstant;
import org.jetbrains.kotlin.resolve.constants.EnumValue;
import org.jetbrains.kotlin.types.JetType;
import static kotlin.KotlinPackage.firstOrNull;
public class InlineUtil {
public static boolean isInlineLambdaParameter(@NotNull CallableDescriptor valueParameterOrReceiver) {
JetType type = valueParameterOrReceiver.getOriginal().getReturnType();
return type != null &&
!KotlinBuiltIns.isNoinline(valueParameterOrReceiver) &&
KotlinBuiltIns.isExactFunctionOrExtensionFunctionType(type);
public static boolean isInlineLambdaParameter(@NotNull ParameterDescriptor valueParameterOrReceiver) {
return !KotlinBuiltIns.isNoinline(valueParameterOrReceiver) &&
KotlinBuiltIns.isExactFunctionOrExtensionFunctionType(valueParameterOrReceiver.getOriginal().getType());
}
public static boolean isInline(@Nullable DeclarationDescriptor descriptor) {
@@ -0,0 +1,33 @@
/*
* 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 org.jetbrains.kotlin.descriptors;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.types.JetType;
public interface ParameterDescriptor extends CallableDescriptor {
@NotNull
JetType getType();
@Override
@NotNull
DeclarationDescriptor getContainingDeclaration();
@NotNull
@Override
ParameterDescriptor getOriginal();
}
@@ -19,25 +19,17 @@ package org.jetbrains.kotlin.descriptors;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
import org.jetbrains.kotlin.types.JetType;
import org.jetbrains.kotlin.types.TypeSubstitutor;
public interface ReceiverParameterDescriptor extends CallableDescriptor {
public interface ReceiverParameterDescriptor extends ParameterDescriptor {
// This field exists for better readability of the client code
@Nullable
ReceiverParameterDescriptor NO_RECEIVER_PARAMETER = null;
@NotNull
JetType getType();
@NotNull
ReceiverValue getValue();
@Override
@NotNull
DeclarationDescriptor getContainingDeclaration();
@Nullable
@Override
ReceiverParameterDescriptor substitute(@NotNull TypeSubstitutor substitutor);
@@ -23,7 +23,7 @@ import org.jetbrains.kotlin.types.JetType;
import java.util.Set;
public interface ValueParameterDescriptor extends VariableDescriptor {
public interface ValueParameterDescriptor extends VariableDescriptor, ParameterDescriptor {
/**
* Returns the 0-based index of the value parameter in the parameter list of its containing function.
*
@@ -48,10 +48,6 @@ public interface ValueParameterDescriptor extends VariableDescriptor {
@Nullable JetType getVarargElementType();
@Override
@NotNull
JetType getType();
@NotNull
@Override
ValueParameterDescriptor getOriginal();
@@ -106,7 +106,7 @@ public abstract class AbstractReceiverParameterDescriptor extends DeclarationDes
@NotNull
@Override
public CallableDescriptor getOriginal() {
public ParameterDescriptor getOriginal() {
return this;
}
@@ -21,10 +21,7 @@ import com.google.gwt.dev.js.ThrowExceptionOnErrorReporter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
import org.jetbrains.kotlin.descriptors.CallableDescriptor;
import org.jetbrains.kotlin.descriptors.FunctionDescriptor;
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor;
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor;
import org.jetbrains.kotlin.descriptors.*;
import org.jetbrains.kotlin.js.parser.ParserPackage;
import org.jetbrains.kotlin.js.translate.callTranslator.CallTranslator;
import org.jetbrains.kotlin.js.translate.context.TranslationContext;
@@ -83,7 +80,8 @@ public final class CallExpressionTranslator extends AbstractCallExpressionTransl
}
if (descriptor instanceof ValueParameterDescriptor) {
return InlineUtil.isInline(descriptor.getContainingDeclaration()) && InlineUtil.isInlineLambdaParameter(descriptor);
return InlineUtil.isInline(descriptor.getContainingDeclaration()) &&
InlineUtil.isInlineLambdaParameter((ParameterDescriptor) descriptor);
}
return false;