Inline util functions renaming

This commit is contained in:
Michael Bogdanov
2015-04-28 17:28:55 +03:00
parent fe23f23664
commit 49f063522c
14 changed files with 55 additions and 58 deletions
@@ -152,7 +152,7 @@ public class ClosureCodegen extends MemberCodegen<JetElement> {
@Nullable
@Override
protected ClassDescriptor classForInnerClassRecord() {
return JvmCodegenUtil.isLambdaWhichWillBeInlined(bindingContext, funDescriptor) ? null : classDescriptor;
return JvmCodegenUtil.isArgumentWhichWillBeInlined(bindingContext, funDescriptor) ? null : classDescriptor;
}
@Override
@@ -1849,7 +1849,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
if (isFunctionLiteral(descriptor)) {
//non labeled return couldn't be local in lambda
FunctionDescriptor containingFunction =
BindingContextUtils.getContainingFunctionSkipFunctionLiterals(descriptor, false).getFirst();
BindingContextUtils.getContainingFunctionSkipFunctionLiterals(descriptor, true).getFirst();
//FIRST_FUN_LABEL to prevent clashing with existing labels
return new NonLocalReturnInfo(typeMapper.mapReturnType(containingFunction), InlineCodegenUtil.FIRST_FUN_LABEL);
} else {
@@ -230,10 +230,10 @@ public class JvmCodegenUtil {
: descriptor;
}
public static boolean isLambdaWhichWillBeInlined(@NotNull BindingContext bindingContext, @NotNull DeclarationDescriptor descriptor) {
public static boolean isArgumentWhichWillBeInlined(@NotNull BindingContext bindingContext, @NotNull DeclarationDescriptor descriptor) {
PsiElement declaration = DescriptorToSourceUtils.descriptorToDeclaration(descriptor);
return InlineUtil.isFunctionalExpression(declaration) &&
InlineUtil.isInlineLambda((JetFunction)declaration, bindingContext, false);
return InlineUtil.canBeInlineArgument(declaration) &&
InlineUtil.isInlinedArgument((JetFunction) declaration, bindingContext, false);
}
@Nullable
@@ -174,7 +174,7 @@ public class CodegenBinding {
// Note: at the moment this is needed for light classes only
// TODO: refactor this out
if (enclosing != null && !JvmCodegenUtil.isLambdaWhichWillBeInlined(trace.getBindingContext(), classDescriptor)) {
if (enclosing != null && !JvmCodegenUtil.isArgumentWhichWillBeInlined(trace.getBindingContext(), classDescriptor)) {
recordInnerClass(trace, enclosing, classDescriptor);
}
}
@@ -16,7 +16,6 @@
package org.jetbrains.kotlin.codegen.inline;
import com.google.common.collect.ImmutableSet;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
@@ -60,7 +59,6 @@ import java.util.*;
import static org.jetbrains.kotlin.codegen.AsmUtil.getMethodAsmFlags;
import static org.jetbrains.kotlin.codegen.AsmUtil.isPrimitive;
import static org.jetbrains.kotlin.codegen.inline.InlineCodegenUtil.addInlineMarker;
import static org.jetbrains.kotlin.resolve.DescriptorUtils.isFunctionExpression;
import static org.jetbrains.kotlin.resolve.DescriptorUtils.isFunctionLiteral;
import static org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilPackage.getResolvedCallWithAssert;
@@ -69,9 +69,9 @@ class CapturingInClosureChecker : CallChecker {
context: BindingContext, scopeContainer: DeclarationDescriptor, variableParent: DeclarationDescriptor
): Boolean {
val scopeDeclaration = DescriptorToSourceUtils.descriptorToDeclaration(scopeContainer)
if (!InlineUtil.isFunctionalExpression(scopeDeclaration)) return false
if (!InlineUtil.canBeInlineArgument(scopeDeclaration)) return false
if (InlineUtil.isInlineLambda(scopeDeclaration as JetFunction, context, false)) {
if (InlineUtil.isInlinedArgument(scopeDeclaration as JetFunction, context, false)) {
val scopeContainerParent = scopeContainer.getContainingDeclaration()
assert(scopeContainerParent != null) { "parent is null for " + scopeContainer }
return !isCapturedVariable(variableParent, scopeContainerParent) || isCapturedInInline(context, scopeContainerParent, variableParent)
@@ -102,8 +102,8 @@ public class InlineUtil {
BindingContext bindingContext = trace.getBindingContext();
while (isFunctionalExpression(containingFunction) && fromFunction != containingFunctionDescriptor) {
if (!isInlineLambda((JetFunction) containingFunction, bindingContext, true)) {
while (canBeInlineArgument(containingFunction) && fromFunction != containingFunctionDescriptor) {
if (!isInlinedArgument((JetFunction) containingFunction, bindingContext, true)) {
return false;
}
@@ -117,20 +117,20 @@ public class InlineUtil {
return fromFunction == containingFunctionDescriptor;
}
public static boolean isInlineLambda(
@NotNull JetFunction functionalExpression,
public static boolean isInlinedArgument(
@NotNull JetFunction argument,
@NotNull BindingContext bindingContext,
boolean checkNonLocalReturn
) {
if (!isFunctionalExpression(functionalExpression)) return false;
if (!canBeInlineArgument(argument)) return false;
JetExpression call = JetPsiUtil.getParentCallIfPresent(functionalExpression);
JetExpression call = JetPsiUtil.getParentCallIfPresent(argument);
if (call != null) {
ResolvedCall<?> resolvedCall = CallUtilPackage.getResolvedCall(call, bindingContext);
if (resolvedCall != null && isInline(resolvedCall.getResultingDescriptor())) {
ValueArgument argument = CallUtilPackage.getValueArgumentForExpression(resolvedCall.getCall(), functionalExpression);
if (argument != null) {
ArgumentMapping mapping = resolvedCall.getArgumentMapping(argument);
ValueArgument valueArgument = CallUtilPackage.getValueArgumentForExpression(resolvedCall.getCall(), argument);
if (valueArgument != null) {
ArgumentMapping mapping = resolvedCall.getArgumentMapping(valueArgument);
if (mapping instanceof ArgumentMatch) {
ValueParameterDescriptor parameter = ((ArgumentMatch) mapping).getValueParameter();
if (isInlineLambdaParameter(parameter)) {
@@ -143,7 +143,7 @@ public class InlineUtil {
return false;
}
public static boolean isFunctionalExpression(@Nullable PsiElement functionalExpression) {
public static boolean canBeInlineArgument(@Nullable PsiElement functionalExpression) {
return functionalExpression instanceof JetFunctionLiteral || functionalExpression instanceof JetNamedFunction;
}