From 622e01b87bb88d6fc2520e9b7adb96bc206282ec Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Wed, 11 Jul 2012 17:07:01 +0400 Subject: [PATCH] rename --- .../lang/diagnostics/rendering/Renderers.java | 18 ++--- .../jet/lang/resolve/calls/CallResolver.java | 57 +++++++------- .../lang/resolve/calls/ResolvedCallImpl.java | 14 ++-- ...ntsBuilder.java => ConstraintsSystem.java} | 6 +- ...erImpl.java => ConstraintsSystemImpl.java} | 78 +++++++++---------- .../calls/inference/ConstraintsUtil.java | 28 +++---- .../calls/inference/InferenceErrorData.java | 14 ++-- .../expressions/ExpressionTypingUtils.java | 2 +- 8 files changed, 109 insertions(+), 108 deletions(-) rename compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/{ConstraintsBuilder.java => ConstraintsSystem.java} (91%) rename compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/{ConstraintsBuilderImpl.java => ConstraintsSystemImpl.java} (74%) diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/rendering/Renderers.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/rendering/Renderers.java index 38ecf8bba10..46ac62c9fae 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/rendering/Renderers.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/rendering/Renderers.java @@ -168,17 +168,17 @@ public class Renderers { public static TabledDescriptorRenderer renderConflictingSubstitutionsInferenceError(InferenceErrorData inferenceErrorData, TabledDescriptorRenderer result) { - assert inferenceErrorData.constraintsBuilder.hasConflictingParameters(); + assert inferenceErrorData.constraintsSystem.hasConflictingParameters(); Collection substitutedDescriptors = Lists.newArrayList(); Collection substitutors = ConstraintsUtil.getSubstitutorsForConflictingParameters( - inferenceErrorData.constraintsBuilder); + inferenceErrorData.constraintsSystem); for (TypeSubstitutor substitutor : substitutors) { CallableDescriptor substitutedDescriptor = inferenceErrorData.descriptor.substitute(substitutor); substitutedDescriptors.add(substitutedDescriptor); } - TypeParameterDescriptor firstConflictingParameter = ConstraintsUtil.getFirstConflictingParameter(inferenceErrorData.constraintsBuilder); + TypeParameterDescriptor firstConflictingParameter = ConstraintsUtil.getFirstConflictingParameter(inferenceErrorData.constraintsSystem); assert firstConflictingParameter != null; result.text(newText() @@ -226,15 +226,15 @@ public class Renderers { .functionArgumentTypeList( inferenceErrorData.receiverArgumentType, inferenceErrorData.valueArgumentsTypes, - inferenceErrorData.constraintsBuilder + inferenceErrorData.constraintsSystem .getTypeConstructorMismatchConstraintPositions())); } public static TabledDescriptorRenderer renderNoInformationForParameterError(InferenceErrorData inferenceErrorData, TabledDescriptorRenderer renderer) { TypeParameterDescriptor firstUnknownParameter = null; - for (TypeParameterDescriptor typeParameter : inferenceErrorData.constraintsBuilder.getTypeParameters()) { - if (inferenceErrorData.constraintsBuilder.getTypeConstraints(typeParameter).isEmpty()) { + for (TypeParameterDescriptor typeParameter : inferenceErrorData.constraintsSystem.getTypeVariables()) { + if (inferenceErrorData.constraintsSystem.getTypeConstraints(typeParameter).isEmpty()) { firstUnknownParameter = typeParameter; break; } @@ -253,7 +253,7 @@ public class Renderers { public static TabledDescriptorRenderer renderUpperBoundViolatedInferenceError(InferenceErrorData inferenceErrorData, TabledDescriptorRenderer result) { TypeParameterDescriptor typeParameterDescriptor = null; for (TypeParameterDescriptor typeParameter : inferenceErrorData.descriptor.getTypeParameters()) { - if (!ConstraintsUtil.checkUpperBoundIsSatisfied(inferenceErrorData.constraintsBuilder, typeParameter)) { + if (!ConstraintsUtil.checkUpperBoundIsSatisfied(inferenceErrorData.constraintsSystem, typeParameter)) { typeParameterDescriptor = typeParameter; break; } @@ -264,9 +264,9 @@ public class Renderers { .table(newTable(). descriptor(inferenceErrorData.descriptor)); - JetType type = inferenceErrorData.constraintsBuilder.getValue(typeParameterDescriptor); + JetType type = inferenceErrorData.constraintsSystem.getValue(typeParameterDescriptor); JetType upperBound = typeParameterDescriptor.getUpperBoundsAsType(); - JetType substitute = inferenceErrorData.constraintsBuilder.getSubstitutor().substitute(upperBound, Variance.INVARIANT); + JetType substitute = inferenceErrorData.constraintsSystem.getSubstitutor().substitute(upperBound, Variance.INVARIANT); result.text(newText() .normal(" is not satisfied: inferred type ") diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java index 9bc971fc889..d345630389e 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java @@ -335,10 +335,10 @@ public class CallResolver { Set> failed) { assert resolvedCall.hasUnknownTypeParameters(); D descriptor = resolvedCall.getCandidateDescriptor(); - ConstraintsBuilder constraintsBuilder = resolvedCall.getConstraintsBuilder(); - assert constraintsBuilder != null; + ConstraintsSystem constraintsSystem = resolvedCall.getConstraintsSystem(); + assert constraintsSystem != null; - constraintsBuilder.addSupertypeConstraint(context.expectedType, descriptor.getReturnType(), ConstraintPosition.EXPECTED_TYPE_POSITION); + constraintsSystem.addSupertypeConstraint(context.expectedType, descriptor.getReturnType(), ConstraintPosition.EXPECTED_TYPE_POSITION); // constraints for function literals // Value parameters @@ -349,24 +349,24 @@ public class CallResolver { for (ValueArgument valueArgument : resolvedValueArgument.getArguments()) { if (!JetPsiUtil.isFunctionLiteralWithoutDeclaredParameterTypes(valueArgument.getArgumentExpression())) continue; - addConstraintForValueArgument(valueArgument, valueParameterDescriptor, constraintsBuilder.getSubstitutor(), - constraintsBuilder, context); + addConstraintForValueArgument(valueArgument, valueParameterDescriptor, constraintsSystem.getSubstitutor(), + constraintsSystem, context); } } - if (!constraintsBuilder.isSuccessful()) { + if (!constraintsSystem.isSuccessful()) { List argumentTypes = Lists.newArrayList(); checkValueArgumentTypes(context, resolvedCall, context.trace, argumentTypes); JetType receiverType = resolvedCall.getReceiverArgument().exists() ? resolvedCall.getReceiverArgument().getType() : null; - reportTypeInferenceFailed(context.trace, context.call, InferenceErrorData.create(descriptor, constraintsBuilder, + reportTypeInferenceFailed(context.trace, context.call, InferenceErrorData.create(descriptor, constraintsSystem, argumentTypes, receiverType)); resolvedCall.addStatus(ResolutionStatus.TYPE_INFERENCE_ERROR); failed.add(resolvedCall); return; } - D substitute = (D) descriptor.substitute(constraintsBuilder.getSubstitutor()); + D substitute = (D) descriptor.substitute(constraintsSystem.getSubstitutor()); assert substitute != null; replaceValueParametersWithSubstitutedOnes(resolvedCall, substitute); resolvedCall.setResultingDescriptor(substitute); //replacement @@ -374,7 +374,7 @@ public class CallResolver { // Here we type check the arguments with inferred types expected checkValueArgumentTypes(context, resolvedCall, context.trace, null); - checkBounds(resolvedCall, constraintsBuilder, context); + checkBounds(resolvedCall, constraintsSystem, context); resolvedCall.setHasUnknownTypeParameters(false); if (resolvedCall.getStatus().isSuccess() || resolvedCall.getStatus() == ResolutionStatus.UNKNOWN_STATUS) { resolvedCall.addStatus(ResolutionStatus.SUCCESS); @@ -386,26 +386,26 @@ public class CallResolver { } private void reportTypeInferenceFailed(@NotNull BindingTrace trace, @NotNull Call call, @NotNull InferenceErrorData inferenceErrorData) { - assert !inferenceErrorData.constraintsBuilder.isSuccessful(); + assert !inferenceErrorData.constraintsSystem.isSuccessful(); JetExpression calleeExpression = call.getCalleeExpression(); PsiElement element = calleeExpression != null ? calleeExpression : call.getCallElement(); - if (inferenceErrorData.constraintsBuilder.hasTypeConstructorMismatch()) { + if (inferenceErrorData.constraintsSystem.hasTypeConstructorMismatch()) { trace.report(TYPE_INFERENCE_TYPE_CONSTRUCTOR_MISMATCH.on(element, inferenceErrorData)); } - else if (inferenceErrorData.constraintsBuilder.hasConflictingParameters()) { + else if (inferenceErrorData.constraintsSystem.hasConflictingParameters()) { trace.report(TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS.on(element, inferenceErrorData)); } else { - assert inferenceErrorData.constraintsBuilder.hasUnknownParameters(); + assert inferenceErrorData.constraintsSystem.hasUnknownParameters(); trace.report(TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER.on(element, inferenceErrorData)); } } - private void checkBounds(ResolvedCallImpl call, ConstraintsBuilder constraintsBuilder, BasicResolutionContext context) { + private void checkBounds(ResolvedCallImpl call, ConstraintsSystem constraintsSystem, BasicResolutionContext context) { for (TypeParameterDescriptor typeParameter : call.getCandidateDescriptor().getTypeParameters()) { - if (!ConstraintsUtil.checkUpperBoundIsSatisfied(constraintsBuilder, typeParameter)) { + if (!ConstraintsUtil.checkUpperBoundIsSatisfied(constraintsSystem, typeParameter)) { context.trace.report(Errors.TYPE_INFERENCE_UPPER_BOUND_VIOLATED.on(context.call.getCallElement(), InferenceErrorData - .create(call.getCandidateDescriptor(), constraintsBuilder))); + .create(call.getCandidateDescriptor(), constraintsSystem))); } } } @@ -700,7 +700,7 @@ public class CallResolver { ResolutionDebugInfo.Data debugInfo = context.trace.get(ResolutionDebugInfo.RESOLUTION_DEBUG_INFO, context.call.getCallElement()); - ConstraintsBuilder constraintsBuilder = new ConstraintsBuilderImpl(); + ConstraintsSystem constraintsSystem = new ConstraintsSystemImpl(); // If the call is recursive, e.g. // fun foo(t : T) : T = foo(t) @@ -712,11 +712,11 @@ public class CallResolver { for (TypeParameterDescriptor typeParameterDescriptor : candidateWithFreshVariables.getTypeParameters()) { - constraintsBuilder.registerTypeVariable(typeParameterDescriptor, Variance.INVARIANT); // TODO: variance of the occurrences + constraintsSystem.registerTypeVariable(typeParameterDescriptor, Variance.INVARIANT); // TODO: variance of the occurrences } TypeSubstitutor substituteDontCare = ConstraintSystemWithPriorities - .makeConstantSubstitutor(candidateWithFreshVariables.getTypeParameters(), ConstraintsBuilderImpl.DONT_CARE); + .makeConstantSubstitutor(candidateWithFreshVariables.getTypeParameters(), ConstraintsSystemImpl.DONT_CARE); // Value parameters for (Map.Entry entry : candidateCall.getValueArguments().entrySet()) { @@ -731,7 +731,8 @@ public class CallResolver { // Here we type check expecting an error type (DONT_CARE, substitution with substituteDontCare) // and throw the results away // We'll type check the arguments later, with the inferred types expected - boolean success = addConstraintForValueArgument(valueArgument, valueParameterDescriptor, substituteDontCare, constraintsBuilder, context); + boolean success = addConstraintForValueArgument(valueArgument, valueParameterDescriptor, substituteDontCare, + constraintsSystem, context); if (!success) { candidateCall.argumentHasNoType(); } @@ -743,21 +744,21 @@ public class CallResolver { ReceiverDescriptor receiverArgument = candidateCall.getReceiverArgument(); ReceiverDescriptor receiverParameter = candidateWithFreshVariables.getReceiverParameter(); if (receiverArgument.exists() && receiverParameter.exists()) { - constraintsBuilder.addSubtypingConstraint(receiverArgument.getType(), receiverParameter.getType(), ConstraintPosition.RECEIVER_POSITION); + constraintsSystem.addSubtypingConstraint(receiverArgument.getType(), receiverParameter.getType(), ConstraintPosition.RECEIVER_POSITION); } - ConstraintsBuilderImpl constraintsBuilderWithRightTypeParameters = new ConstraintsBuilderImpl(constraintsBuilder.hasTypeConstructorMismatch(), constraintsBuilder + ConstraintsSystemImpl constraintsBuilderWithRightTypeParameters = new ConstraintsSystemImpl(constraintsSystem.hasTypeConstructorMismatch(), constraintsSystem .getTypeConstructorMismatchConstraintPositions()); for (TypeParameterDescriptor typeParameterDescriptor : candidate.getTypeParameters()) { - TypeConstraints typeConstraints = constraintsBuilder.getTypeConstraints( + TypeConstraints typeConstraints = constraintsSystem.getTypeConstraints( candidateWithFreshVariables.getTypeParameters().get(typeParameterDescriptor.getIndex())); constraintsBuilderWithRightTypeParameters.registerTypeVariable(typeParameterDescriptor, typeConstraints); } - candidateCall.setConstraintsBuilder(constraintsBuilderWithRightTypeParameters); + candidateCall.setConstraintsSystem(constraintsBuilderWithRightTypeParameters); // Solution - if (!constraintsBuilder.hasContradiction()) { + if (!constraintsSystem.hasContradiction()) { candidateCall.setHasUnknownTypeParameters(true); return SUCCESS; } @@ -774,7 +775,7 @@ public class CallResolver { private boolean addConstraintForValueArgument(ValueArgument valueArgument, @NotNull ValueParameterDescriptor valueParameterDescriptor, @NotNull TypeSubstitutor substitutor, - @NotNull ConstraintsBuilder constraintsBuilder, + @NotNull ConstraintsSystem constraintsSystem, @NotNull ResolutionContext context) { JetType effectiveExpectedType = getEffectiveExpectedType(valueParameterDescriptor, valueArgument); @@ -784,7 +785,7 @@ public class CallResolver { context.scope, argumentExpression, substitutor.substitute(valueParameterDescriptor.getType(), Variance.INVARIANT), context.dataFlowInfo, traceForUnknown) : null; if (type == null || ErrorUtils.isErrorType(type)) return false; - constraintsBuilder.addSubtypingConstraint(type, effectiveExpectedType, ConstraintPosition.getValueParameterPosition( + constraintsSystem.addSubtypingConstraint(type, effectiveExpectedType, ConstraintPosition.getValueParameterPosition( valueParameterDescriptor.getIndex())); return true; } @@ -972,7 +973,7 @@ public class CallResolver { if (argument.getSpreadElement() != null) { if (parameterDescriptor.getVarargElementType() == null) { // Spread argument passed to a non-vararg parameter, an error is already reported by ValueArgumentsToParametersMapper - return ConstraintsBuilderImpl.DONT_CARE; + return ConstraintsSystemImpl.DONT_CARE; } else { return parameterDescriptor.getType(); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/ResolvedCallImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/ResolvedCallImpl.java index 67aefa89bb0..387e88b7e05 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/ResolvedCallImpl.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/ResolvedCallImpl.java @@ -24,9 +24,7 @@ import org.jetbrains.jet.lang.descriptors.CallableDescriptor; import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor; import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor; import org.jetbrains.jet.lang.resolve.TemporaryBindingTrace; -import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintsBuilder; -import org.jetbrains.jet.lang.resolve.calls.inference.TypeConstraints; -import org.jetbrains.jet.lang.resolve.calls.inference.TypeConstraintsImpl; +import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintsSystem; import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor; import org.jetbrains.jet.lang.types.JetType; @@ -74,7 +72,7 @@ public class ResolvedCallImpl implements ResolvedC private TemporaryBindingTrace trace; private ResolutionStatus status = UNKNOWN_STATUS; private boolean hasUnknownTypeParameters = false; - private ConstraintsBuilder constraintsBuilder = null; + private ConstraintsSystem constraintsSystem = null; private ResolvedCallImpl(@NotNull ResolutionCandidate candidate, @NotNull TemporaryBindingTrace trace) { this.candidateDescriptor = candidate.getDescriptor(); @@ -132,13 +130,13 @@ public class ResolvedCallImpl implements ResolvedC typeArguments.put(typeParameter, typeArgument); } - public void setConstraintsBuilder(@NotNull ConstraintsBuilder constraintsBuilder) { - this.constraintsBuilder = constraintsBuilder; + public void setConstraintsSystem(@NotNull ConstraintsSystem constraintsSystem) { + this.constraintsSystem = constraintsSystem; } @Nullable - public ConstraintsBuilder getConstraintsBuilder() { - return constraintsBuilder; + public ConstraintsSystem getConstraintsSystem() { + return constraintsSystem; } public void recordValueArgument(@NotNull ValueParameterDescriptor valueParameter, @NotNull ResolvedValueArgument valueArgument) { diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintsBuilder.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintsSystem.java similarity index 91% rename from compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintsBuilder.java rename to compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintsSystem.java index 001c1a69345..cf8e1f20779 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintsBuilder.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintsSystem.java @@ -30,15 +30,17 @@ import java.util.Set; /** * @author svtk */ -public interface ConstraintsBuilder { +public interface ConstraintsSystem { void registerTypeVariable(@NotNull TypeParameterDescriptor typeParameterDescriptor, @NotNull Variance positionVariance); @NotNull - Set getTypeParameters(); + Set getTypeVariables(); + // only subject type might contain type variables void addSubtypingConstraint(@NotNull JetType subjectType, @NotNull JetType constrainingType, @NotNull ConstraintPosition constraintPosition); + // only subject type might contain type variables void addSupertypeConstraint(@NotNull JetType subjectType, @NotNull JetType constrainingType, @NotNull ConstraintPosition constraintPosition); boolean isSuccessful(); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintsBuilderImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintsSystemImpl.java similarity index 74% rename from compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintsBuilderImpl.java rename to compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintsSystemImpl.java index fbca107cbbf..b174c2a3476 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintsBuilderImpl.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintsSystemImpl.java @@ -33,22 +33,22 @@ import java.util.*; /** * @author svtk */ -public class ConstraintsBuilderImpl implements ConstraintsBuilder { +public class ConstraintsSystemImpl implements ConstraintsSystem { public static final JetType DONT_CARE = ErrorUtils.createErrorTypeWithCustomDebugName("DONT_CARE"); - enum ConstraintType { + enum ConstraintKind { SUB_TYPE, SUPER_TYPE, EQUAL } - public static ConstraintType varianceToConstraintType(Variance variance) { + public static ConstraintKind varianceToConstraintKind(Variance variance) { if (variance == Variance.INVARIANT) { - return ConstraintType.EQUAL; + return ConstraintKind.EQUAL; } if (variance == Variance.OUT_VARIANCE) { - return ConstraintType.SUB_TYPE; + return ConstraintKind.SUB_TYPE; } - return ConstraintType.SUPER_TYPE; + return ConstraintKind.SUPER_TYPE; } private final Map typeParameterConstraints = Maps.newLinkedHashMap(); @@ -56,11 +56,11 @@ public class ConstraintsBuilderImpl implements ConstraintsBuilder { private final Collection errorConstraintPositions; private boolean typeConstructorMismatch; - public ConstraintsBuilderImpl() { + public ConstraintsSystemImpl() { this(false, Lists.newArrayList()); } - public ConstraintsBuilderImpl(boolean typeConstructorMismatch, Collection errorConstraintPositions) { + public ConstraintsSystemImpl(boolean typeConstructorMismatch, Collection errorConstraintPositions) { this.typeConstructorMismatch = typeConstructorMismatch; this.errorConstraintPositions = errorConstraintPositions; this.typeSubstitutor = TypeSubstitutor.create(new TypeSubstitution() { @@ -115,70 +115,70 @@ public class ConstraintsBuilderImpl implements ConstraintsBuilder { @Override public void addSubtypingConstraint(@NotNull JetType subjectType, @NotNull JetType constrainingType, @NotNull ConstraintPosition constraintPosition) { - addConstraint(ConstraintType.SUB_TYPE, subjectType, constrainingType, constraintPosition); + addConstraint(ConstraintKind.SUB_TYPE, subjectType, constrainingType, constraintPosition); } @Override public void addSupertypeConstraint(@NotNull JetType subjectType, @NotNull JetType constrainingType, @NotNull ConstraintPosition constraintPosition) { - addConstraint(ConstraintType.SUPER_TYPE, subjectType, constrainingType, constraintPosition); + addConstraint(ConstraintKind.SUPER_TYPE, subjectType, constrainingType, constraintPosition); } - public void addConstraint(@NotNull ConstraintType constraintType, @NotNull JetType exactType, @NotNull JetType expectedType, + public void addConstraint(@NotNull ConstraintKind constraintKind, @NotNull JetType subjectType, @NotNull JetType constrainingType, @NotNull ConstraintPosition constraintPosition) { - if (exactType == DONT_CARE || expectedType == DONT_CARE || exactType == TypeUtils.NO_EXPECTED_TYPE - || expectedType == TypeUtils.NO_EXPECTED_TYPE) { + if (subjectType == DONT_CARE || constrainingType == DONT_CARE || subjectType == TypeUtils.NO_EXPECTED_TYPE + || constrainingType == TypeUtils.NO_EXPECTED_TYPE) { return; } - DeclarationDescriptor expectedTypeDescriptor = expectedType.getConstructor().getDeclarationDescriptor(); - DeclarationDescriptor exactTypeDescriptor = exactType.getConstructor().getDeclarationDescriptor(); + DeclarationDescriptor constrainingTypeDescriptor = constrainingType.getConstructor().getDeclarationDescriptor(); + DeclarationDescriptor subjectTypeDescriptor = subjectType.getConstructor().getDeclarationDescriptor(); - if (expectedTypeDescriptor instanceof TypeParameterDescriptor) { - if (TypeUtils.dependsOnTypeParameterConstructors(exactType, Collections.singleton(DONT_CARE.getConstructor()))) return; - if (expectedType.isNullable()) { - exactType = TypeUtils.makeNotNullable(exactType); + if (constrainingTypeDescriptor instanceof TypeParameterDescriptor) { + if (TypeUtils.dependsOnTypeParameterConstructors(subjectType, Collections.singleton(DONT_CARE.getConstructor()))) return; + if (constrainingType.isNullable()) { + subjectType = TypeUtils.makeNotNullable(subjectType); } - TypeParameterDescriptor typeParameter = (TypeParameterDescriptor) expectedTypeDescriptor; - if (constraintType == ConstraintType.SUB_TYPE) { - typeParameterConstraints.get(typeParameter).addLowerConstraint(exactType); + TypeParameterDescriptor typeParameter = (TypeParameterDescriptor) constrainingTypeDescriptor; + if (constraintKind == ConstraintKind.SUB_TYPE) { + typeParameterConstraints.get(typeParameter).addLowerConstraint(subjectType); } - else if (constraintType == ConstraintType.SUPER_TYPE) { - typeParameterConstraints.get(typeParameter).addUpperConstraint(exactType); + else if (constraintKind == ConstraintKind.SUPER_TYPE) { + typeParameterConstraints.get(typeParameter).addUpperConstraint(subjectType); } else { - typeParameterConstraints.get(typeParameter).addEqualConstraint(exactType); + typeParameterConstraints.get(typeParameter).addEqualConstraint(subjectType); } return; } - if (exactTypeDescriptor instanceof ClassDescriptor && expectedTypeDescriptor instanceof ClassDescriptor) { - if (constraintType != ConstraintType.SUPER_TYPE) { - JetType correspondingSupertype = TypeCheckingProcedure.findCorrespondingSupertype(exactType, expectedType); + if (subjectTypeDescriptor instanceof ClassDescriptor && constrainingTypeDescriptor instanceof ClassDescriptor) { + if (constraintKind != ConstraintKind.SUPER_TYPE) { + JetType correspondingSupertype = TypeCheckingProcedure.findCorrespondingSupertype(subjectType, constrainingType); if (correspondingSupertype != null) { - exactType = correspondingSupertype; + subjectType = correspondingSupertype; } } else { - JetType correspondingSupertype = TypeCheckingProcedure.findCorrespondingSupertype(expectedType, exactType); + JetType correspondingSupertype = TypeCheckingProcedure.findCorrespondingSupertype(constrainingType, subjectType); if (correspondingSupertype != null) { - expectedType = correspondingSupertype; + constrainingType = correspondingSupertype; } } - if (exactType.getConstructor().getParameters().size() != expectedType.getConstructor().getParameters().size()) { + if (subjectType.getConstructor().getParameters().size() != constrainingType.getConstructor().getParameters().size()) { errorConstraintPositions.add(constraintPosition); typeConstructorMismatch = true; return; } - ClassDescriptor subClass = (ClassDescriptor) exactType.getConstructor().getDeclarationDescriptor(); - ClassDescriptor superClass = (ClassDescriptor) expectedType.getConstructor().getDeclarationDescriptor(); + ClassDescriptor subClass = (ClassDescriptor) subjectType.getConstructor().getDeclarationDescriptor(); + ClassDescriptor superClass = (ClassDescriptor) constrainingType.getConstructor().getDeclarationDescriptor(); if (DescriptorUtils.isSubclass(subClass, superClass)) { - List subArguments = exactType.getArguments(); - List superArguments = expectedType.getArguments(); - List superParameters = expectedType.getConstructor().getParameters(); + List subArguments = subjectType.getArguments(); + List superArguments = constrainingType.getArguments(); + List superParameters = constrainingType.getConstructor().getParameters(); for (int i = 0; i < superArguments.size(); i++) { - addConstraint(varianceToConstraintType(superParameters.get(i).getVariance()), subArguments.get(i).getType(), superArguments.get(i).getType(), + addConstraint(varianceToConstraintKind(superParameters.get(i).getVariance()), subArguments.get(i).getType(), superArguments.get(i).getType(), constraintPosition); } return; @@ -209,7 +209,7 @@ public class ConstraintsBuilderImpl implements ConstraintsBuilder { @NotNull @Override - public Set getTypeParameters() { + public Set getTypeVariables() { return typeParameterConstraints.keySet(); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintsUtil.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintsUtil.java index c4ba3893aad..ce511bd4c4a 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintsUtil.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintsUtil.java @@ -35,9 +35,9 @@ import java.util.Map; public class ConstraintsUtil { @Nullable - public static TypeParameterDescriptor getFirstConflictingParameter(@NotNull ConstraintsBuilder constraintsBuilder) { - for (TypeParameterDescriptor typeParameter : constraintsBuilder.getTypeParameters()) { - TypeConstraints constraints = constraintsBuilder.getTypeConstraints(typeParameter); + public static TypeParameterDescriptor getFirstConflictingParameter(@NotNull ConstraintsSystem constraintsSystem) { + for (TypeParameterDescriptor typeParameter : constraintsSystem.getTypeVariables()) { + TypeConstraints constraints = constraintsSystem.getTypeConstraints(typeParameter); if (!constraints.getConflicts().isEmpty()) { return typeParameter; } @@ -46,11 +46,11 @@ public class ConstraintsUtil { } @NotNull - public static Collection getSubstitutorsForConflictingParameters(@NotNull ConstraintsBuilder constraintsBuilder) { - TypeParameterDescriptor firstConflictingParameter = getFirstConflictingParameter(constraintsBuilder); + public static Collection getSubstitutorsForConflictingParameters(@NotNull ConstraintsSystem constraintsSystem) { + TypeParameterDescriptor firstConflictingParameter = getFirstConflictingParameter(constraintsSystem); if (firstConflictingParameter == null) return Collections.emptyList(); - Collection conflictingTypes = constraintsBuilder.getTypeConstraints(firstConflictingParameter).getConflicts(); + Collection conflictingTypes = constraintsSystem.getTypeConstraints(firstConflictingParameter).getConflicts(); ArrayList> substitutionContexts = Lists.newArrayList(); for (JetType type : conflictingTypes) { @@ -59,10 +59,10 @@ public class ConstraintsUtil { substitutionContexts.add(context); } - for (TypeParameterDescriptor typeParameter : constraintsBuilder.getTypeParameters()) { + for (TypeParameterDescriptor typeParameter : constraintsSystem.getTypeVariables()) { if (typeParameter == firstConflictingParameter) continue; - JetType safeType = getSafeValue(constraintsBuilder, typeParameter); + JetType safeType = getSafeValue(constraintsSystem, typeParameter); for (Map context : substitutionContexts) { TypeProjection typeProjection = new TypeProjection(safeType); context.put(typeParameter.getTypeConstructor(), typeProjection); @@ -76,8 +76,8 @@ public class ConstraintsUtil { } @NotNull - public static JetType getSafeValue(@NotNull ConstraintsBuilder constraintsBuilder, @NotNull TypeParameterDescriptor typeParameter) { - JetType type = constraintsBuilder.getValue(typeParameter); + public static JetType getSafeValue(@NotNull ConstraintsSystem constraintsSystem, @NotNull TypeParameterDescriptor typeParameter) { + JetType type = constraintsSystem.getValue(typeParameter); if (type != null) { return type; } @@ -85,12 +85,12 @@ public class ConstraintsUtil { return typeParameter.getUpperBoundsAsType(); } - public static boolean checkUpperBoundIsSatisfied(@NotNull ConstraintsBuilder constraintsBuilder, + public static boolean checkUpperBoundIsSatisfied(@NotNull ConstraintsSystem constraintsSystem, @NotNull TypeParameterDescriptor typeParameter) { - assert constraintsBuilder.getTypeConstraints(typeParameter) != null; - JetType type = constraintsBuilder.getValue(typeParameter); + assert constraintsSystem.getTypeConstraints(typeParameter) != null; + JetType type = constraintsSystem.getValue(typeParameter); JetType upperBound = typeParameter.getUpperBoundsAsType(); - JetType substitute = constraintsBuilder.getSubstitutor().substitute(upperBound, Variance.INVARIANT); + JetType substitute = constraintsSystem.getSubstitutor().substitute(upperBound, Variance.INVARIANT); if (type != null) { if (substitute == null || !JetTypeChecker.INSTANCE.isSubtypeOf(type, substitute)) { diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/InferenceErrorData.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/InferenceErrorData.java index e76c1e95698..7d44eef2367 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/InferenceErrorData.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/InferenceErrorData.java @@ -28,24 +28,24 @@ import java.util.List; */ public class InferenceErrorData { public final CallableDescriptor descriptor; - public final ConstraintsBuilder constraintsBuilder; + public final ConstraintsSystem constraintsSystem; public final JetType receiverArgumentType; public final List valueArgumentsTypes; - private InferenceErrorData(@NotNull CallableDescriptor descriptor, @NotNull ConstraintsBuilder constraintsBuilder, + private InferenceErrorData(@NotNull CallableDescriptor descriptor, @NotNull ConstraintsSystem constraintsSystem, @Nullable List valueArgumentsTypes, @Nullable JetType receiverArgumentType) { this.descriptor = descriptor; - this.constraintsBuilder = constraintsBuilder; + this.constraintsSystem = constraintsSystem; this.receiverArgumentType = receiverArgumentType; this.valueArgumentsTypes = valueArgumentsTypes; } - public static InferenceErrorData create(@NotNull CallableDescriptor descriptor, @NotNull ConstraintsBuilder constraintsBuilder, + public static InferenceErrorData create(@NotNull CallableDescriptor descriptor, @NotNull ConstraintsSystem constraintsSystem, @NotNull List valueArgumentsTypes, @Nullable JetType receiverArgumentType) { - return new InferenceErrorData(descriptor, constraintsBuilder, valueArgumentsTypes, receiverArgumentType); + return new InferenceErrorData(descriptor, constraintsSystem, valueArgumentsTypes, receiverArgumentType); } - public static InferenceErrorData create(@NotNull CallableDescriptor descriptor, @NotNull ConstraintsBuilder constraintsBuilder) { - return new InferenceErrorData(descriptor, constraintsBuilder, null, null); + public static InferenceErrorData create(@NotNull CallableDescriptor descriptor, @NotNull ConstraintsSystem constraintsSystem) { + return new InferenceErrorData(descriptor, constraintsSystem, null, null); } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingUtils.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingUtils.java index 1f377abf7c4..0faf2108fe2 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingUtils.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingUtils.java @@ -232,7 +232,7 @@ public class ExpressionTypingUtils { @NotNull JetType receiverType, @NotNull CallableDescriptor receiverArgument ) { - ConstraintsBuilderImpl constraintsBuilder = new ConstraintsBuilderImpl(); + ConstraintsSystemImpl constraintsBuilder = new ConstraintsSystemImpl(); for (TypeParameterDescriptor typeParameterDescriptor : receiverArgument.getTypeParameters()) { constraintsBuilder.registerTypeVariable(typeParameterDescriptor, Variance.INVARIANT); }