JetTypeInferrer refactored to enable transactional traces (needed for multi-trial type inference)
This commit is contained in:
@@ -47,8 +47,8 @@ public class JetSemanticServices {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public JetTypeInferrer getTypeInferrer(@NotNull BindingTrace trace, @NotNull JetFlowInformationProvider flowInformationProvider) {
|
public JetTypeInferrer.Services getTypeInferrerServices(@NotNull BindingTrace trace, @NotNull JetFlowInformationProvider flowInformationProvider) {
|
||||||
return new JetTypeInferrer(trace, flowInformationProvider, this);
|
return new JetTypeInferrer(flowInformationProvider, this).getServices(trace);
|
||||||
}
|
}
|
||||||
|
|
||||||
// @NotNull
|
// @NotNull
|
||||||
|
|||||||
@@ -197,7 +197,7 @@ public class ClassDescriptorResolver {
|
|||||||
@Override
|
@Override
|
||||||
protected JetType compute() {
|
protected JetType compute() {
|
||||||
JetFlowInformationProvider flowInformationProvider = computeFlowData(function, bodyExpression);
|
JetFlowInformationProvider flowInformationProvider = computeFlowData(function, bodyExpression);
|
||||||
return semanticServices.getTypeInferrer(trace, flowInformationProvider).inferFunctionReturnType(scope, function, functionDescriptor);
|
return semanticServices.getTypeInferrerServices(trace, flowInformationProvider).inferFunctionReturnType(scope, function, functionDescriptor);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -525,7 +525,7 @@ public class ClassDescriptorResolver {
|
|||||||
LazyValue<JetType> lazyValue = new LazyValue<JetType>() {
|
LazyValue<JetType> lazyValue = new LazyValue<JetType>() {
|
||||||
@Override
|
@Override
|
||||||
protected JetType compute() {
|
protected JetType compute() {
|
||||||
return semanticServices.getTypeInferrer(trace, JetFlowInformationProvider.THROW_EXCEPTION).safeGetType(scope, initializer, false, JetTypeInferrer.NO_EXPECTED_TYPE);
|
return semanticServices.getTypeInferrerServices(trace, JetFlowInformationProvider.THROW_EXCEPTION).safeGetType(scope, initializer, false, JetTypeInferrer.NO_EXPECTED_TYPE);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (allowDeferred) {
|
if (allowDeferred) {
|
||||||
|
|||||||
@@ -280,7 +280,7 @@ public class TopDownAnalyzer {
|
|||||||
if (importDirective.isAllUnder()) {
|
if (importDirective.isAllUnder()) {
|
||||||
JetExpression importedReference = importDirective.getImportedReference();
|
JetExpression importedReference = importDirective.getImportedReference();
|
||||||
if (importedReference != null) {
|
if (importedReference != null) {
|
||||||
JetType type = semanticServices.getTypeInferrer(trace, JetFlowInformationProvider.THROW_EXCEPTION).getTypeWithNamespaces(namespaceScope, importedReference, false);
|
JetType type = semanticServices.getTypeInferrerServices(trace, JetFlowInformationProvider.THROW_EXCEPTION).getTypeWithNamespaces(namespaceScope, importedReference, false);
|
||||||
if (type != null) {
|
if (type != null) {
|
||||||
namespaceScope.importScope(type.getMemberScope());
|
namespaceScope.importScope(type.getMemberScope());
|
||||||
}
|
}
|
||||||
@@ -293,7 +293,7 @@ public class TopDownAnalyzer {
|
|||||||
JetExpression importedReference = importDirective.getImportedReference();
|
JetExpression importedReference = importDirective.getImportedReference();
|
||||||
if (importedReference instanceof JetDotQualifiedExpression) {
|
if (importedReference instanceof JetDotQualifiedExpression) {
|
||||||
JetDotQualifiedExpression reference = (JetDotQualifiedExpression) importedReference;
|
JetDotQualifiedExpression reference = (JetDotQualifiedExpression) importedReference;
|
||||||
JetType type = semanticServices.getTypeInferrer(trace, JetFlowInformationProvider.THROW_EXCEPTION).getTypeWithNamespaces(namespaceScope, reference.getReceiverExpression(), false);
|
JetType type = semanticServices.getTypeInferrerServices(trace, JetFlowInformationProvider.THROW_EXCEPTION).getTypeWithNamespaces(namespaceScope, reference.getReceiverExpression(), false);
|
||||||
JetExpression selectorExpression = reference.getSelectorExpression();
|
JetExpression selectorExpression = reference.getSelectorExpression();
|
||||||
if (selectorExpression != null) {
|
if (selectorExpression != null) {
|
||||||
referenceExpression = (JetSimpleNameExpression) selectorExpression;
|
referenceExpression = (JetSimpleNameExpression) selectorExpression;
|
||||||
@@ -563,7 +563,7 @@ public class TopDownAnalyzer {
|
|||||||
final JetScope scopeForConstructor = primaryConstructor == null
|
final JetScope scopeForConstructor = primaryConstructor == null
|
||||||
? null
|
? null
|
||||||
: getInnerScopeForConstructor(primaryConstructor, descriptor.getScopeForMemberResolution(), true);
|
: getInnerScopeForConstructor(primaryConstructor, descriptor.getScopeForMemberResolution(), true);
|
||||||
final JetTypeInferrer typeInferrer = semanticServices.getTypeInferrer(traceForConstructors, JetFlowInformationProvider.NONE); // TODO : flow
|
final JetTypeInferrer.Services typeInferrer = semanticServices.getTypeInferrerServices(traceForConstructors, JetFlowInformationProvider.NONE); // TODO : flow
|
||||||
|
|
||||||
for (JetDelegationSpecifier delegationSpecifier : jetClass.getDelegationSpecifiers()) {
|
for (JetDelegationSpecifier delegationSpecifier : jetClass.getDelegationSpecifiers()) {
|
||||||
delegationSpecifier.accept(new JetVisitor() {
|
delegationSpecifier.accept(new JetVisitor() {
|
||||||
@@ -642,7 +642,7 @@ public class TopDownAnalyzer {
|
|||||||
ConstructorDescriptor primaryConstructor = classDescriptor.getUnsubstitutedPrimaryConstructor();
|
ConstructorDescriptor primaryConstructor = classDescriptor.getUnsubstitutedPrimaryConstructor();
|
||||||
assert primaryConstructor != null;
|
assert primaryConstructor != null;
|
||||||
final JetScope scopeForConstructor = getInnerScopeForConstructor(primaryConstructor, classDescriptor.getScopeForMemberResolution(), true);
|
final JetScope scopeForConstructor = getInnerScopeForConstructor(primaryConstructor, classDescriptor.getScopeForMemberResolution(), true);
|
||||||
JetTypeInferrer typeInferrer = semanticServices.getTypeInferrer(traceForConstructors, JetFlowInformationProvider.NONE); // TODO : flow
|
JetTypeInferrer.Services typeInferrer = semanticServices.getTypeInferrerServices(traceForConstructors, JetFlowInformationProvider.NONE); // TODO : flow
|
||||||
for (JetClassInitializer anonymousInitializer : anonymousInitializers) {
|
for (JetClassInitializer anonymousInitializer : anonymousInitializers) {
|
||||||
typeInferrer.getType(scopeForConstructor, anonymousInitializer.getBody(), true, JetTypeInferrer.NO_EXPECTED_TYPE);
|
typeInferrer.getType(scopeForConstructor, anonymousInitializer.getBody(), true, JetTypeInferrer.NO_EXPECTED_TYPE);
|
||||||
}
|
}
|
||||||
@@ -668,7 +668,7 @@ public class TopDownAnalyzer {
|
|||||||
private void resolveSecondaryConstructorBody(JetConstructor declaration, final ConstructorDescriptor descriptor, final JetScope declaringScope) {
|
private void resolveSecondaryConstructorBody(JetConstructor declaration, final ConstructorDescriptor descriptor, final JetScope declaringScope) {
|
||||||
final JetScope functionInnerScope = getInnerScopeForConstructor(descriptor, declaringScope, false);
|
final JetScope functionInnerScope = getInnerScopeForConstructor(descriptor, declaringScope, false);
|
||||||
|
|
||||||
final JetTypeInferrer typeInferrerForInitializers = semanticServices.getTypeInferrer(traceForConstructors, JetFlowInformationProvider.NONE);
|
final JetTypeInferrer.Services typeInferrerForInitializers = semanticServices.getTypeInferrerServices(traceForConstructors, JetFlowInformationProvider.NONE);
|
||||||
|
|
||||||
JetClass containingClass = PsiTreeUtil.getParentOfType(declaration, JetClass.class);
|
JetClass containingClass = PsiTreeUtil.getParentOfType(declaration, JetClass.class);
|
||||||
assert containingClass != null : "This must be guaranteed by the parser";
|
assert containingClass != null : "This must be guaranteed by the parser";
|
||||||
@@ -728,7 +728,7 @@ public class TopDownAnalyzer {
|
|||||||
if (bodyExpression != null) {
|
if (bodyExpression != null) {
|
||||||
classDescriptorResolver.computeFlowData(declaration, bodyExpression);
|
classDescriptorResolver.computeFlowData(declaration, bodyExpression);
|
||||||
JetFlowInformationProvider flowInformationProvider = classDescriptorResolver.computeFlowData(declaration, bodyExpression);
|
JetFlowInformationProvider flowInformationProvider = classDescriptorResolver.computeFlowData(declaration, bodyExpression);
|
||||||
JetTypeInferrer typeInferrer = semanticServices.getTypeInferrer(traceForConstructors, flowInformationProvider);
|
JetTypeInferrer.Services typeInferrer = semanticServices.getTypeInferrerServices(traceForConstructors, flowInformationProvider);
|
||||||
|
|
||||||
typeInferrer.checkFunctionReturnType(functionInnerScope, declaration, descriptor, JetStandardClasses.getUnitType());
|
typeInferrer.checkFunctionReturnType(functionInnerScope, declaration, descriptor, JetStandardClasses.getUnitType());
|
||||||
}
|
}
|
||||||
@@ -859,7 +859,7 @@ public class TopDownAnalyzer {
|
|||||||
|
|
||||||
private void resolvePropertyInitializer(JetProperty property, PropertyDescriptor propertyDescriptor, JetExpression initializer, JetScope scope) {
|
private void resolvePropertyInitializer(JetProperty property, PropertyDescriptor propertyDescriptor, JetExpression initializer, JetScope scope) {
|
||||||
JetFlowInformationProvider flowInformationProvider = classDescriptorResolver.computeFlowData(property, initializer); // TODO : flow JET-15
|
JetFlowInformationProvider flowInformationProvider = classDescriptorResolver.computeFlowData(property, initializer); // TODO : flow JET-15
|
||||||
JetTypeInferrer typeInferrer = semanticServices.getTypeInferrer(traceForConstructors, flowInformationProvider);
|
JetTypeInferrer.Services typeInferrer = semanticServices.getTypeInferrerServices(traceForConstructors, flowInformationProvider);
|
||||||
JetType type = typeInferrer.getType(getPropertyDeclarationInnerScope(scope, propertyDescriptor), initializer, false, JetTypeInferrer.NO_EXPECTED_TYPE);
|
JetType type = typeInferrer.getType(getPropertyDeclarationInnerScope(scope, propertyDescriptor), initializer, false, JetTypeInferrer.NO_EXPECTED_TYPE);
|
||||||
|
|
||||||
JetType expectedType;
|
JetType expectedType;
|
||||||
@@ -902,7 +902,7 @@ public class TopDownAnalyzer {
|
|||||||
|
|
||||||
if (bodyExpression != null) {
|
if (bodyExpression != null) {
|
||||||
JetFlowInformationProvider flowInformationProvider = classDescriptorResolver.computeFlowData(function.asElement(), bodyExpression);
|
JetFlowInformationProvider flowInformationProvider = classDescriptorResolver.computeFlowData(function.asElement(), bodyExpression);
|
||||||
JetTypeInferrer typeInferrer = semanticServices.getTypeInferrer(trace, flowInformationProvider);
|
JetTypeInferrer.Services typeInferrer = semanticServices.getTypeInferrerServices(trace, flowInformationProvider);
|
||||||
|
|
||||||
typeInferrer.checkFunctionReturnType(declaringScope, function, functionDescriptor);
|
typeInferrer.checkFunctionReturnType(declaringScope, function, functionDescriptor);
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -493,14 +493,14 @@ public class JetTypeCheckerTest extends LightDaemonAnalyzerTestCase {
|
|||||||
private void assertType(String expression, JetType expectedType) {
|
private void assertType(String expression, JetType expectedType) {
|
||||||
Project project = getProject();
|
Project project = getProject();
|
||||||
JetExpression jetExpression = JetChangeUtil.createExpression(project, expression);
|
JetExpression jetExpression = JetChangeUtil.createExpression(project, expression);
|
||||||
JetType type = semanticServices.getTypeInferrer(JetTestUtils.DUMMY, JetFlowInformationProvider.NONE).getType(classDefinitions.BASIC_SCOPE, jetExpression, false, JetTypeInferrer.NO_EXPECTED_TYPE);
|
JetType type = semanticServices.getTypeInferrerServices(JetTestUtils.DUMMY, JetFlowInformationProvider.NONE).getType(classDefinitions.BASIC_SCOPE, jetExpression, false, JetTypeInferrer.NO_EXPECTED_TYPE);
|
||||||
assertTrue(type + " != " + expectedType, type.equals(expectedType));
|
assertTrue(type + " != " + expectedType, type.equals(expectedType));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertErrorType(String expression) {
|
private void assertErrorType(String expression) {
|
||||||
Project project = getProject();
|
Project project = getProject();
|
||||||
JetExpression jetExpression = JetChangeUtil.createExpression(project, expression);
|
JetExpression jetExpression = JetChangeUtil.createExpression(project, expression);
|
||||||
JetType type = semanticServices.getTypeInferrer(JetTestUtils.DUMMY, JetFlowInformationProvider.NONE).safeGetType(classDefinitions.BASIC_SCOPE, jetExpression, false, JetTypeInferrer.NO_EXPECTED_TYPE);
|
JetType type = semanticServices.getTypeInferrerServices(JetTestUtils.DUMMY, JetFlowInformationProvider.NONE).safeGetType(classDefinitions.BASIC_SCOPE, jetExpression, false, JetTypeInferrer.NO_EXPECTED_TYPE);
|
||||||
assertTrue("Error type expected but " + type + " returned", ErrorUtils.isErrorType(type));
|
assertTrue("Error type expected but " + type + " returned", ErrorUtils.isErrorType(type));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -523,7 +523,7 @@ public class JetTypeCheckerTest extends LightDaemonAnalyzerTestCase {
|
|||||||
private void assertType(JetScope scope, String expression, String expectedTypeStr) {
|
private void assertType(JetScope scope, String expression, String expectedTypeStr) {
|
||||||
Project project = getProject();
|
Project project = getProject();
|
||||||
JetExpression jetExpression = JetChangeUtil.createExpression(project, expression);
|
JetExpression jetExpression = JetChangeUtil.createExpression(project, expression);
|
||||||
JetType type = semanticServices.getTypeInferrer(JetTestUtils.DUMMY, JetFlowInformationProvider.NONE).getType(scope, jetExpression, false, JetTypeInferrer.NO_EXPECTED_TYPE);
|
JetType type = semanticServices.getTypeInferrerServices(JetTestUtils.DUMMY, JetFlowInformationProvider.NONE).getType(scope, jetExpression, false, JetTypeInferrer.NO_EXPECTED_TYPE);
|
||||||
JetType expectedType = expectedTypeStr == null ? null : makeType(expectedTypeStr);
|
JetType expectedType = expectedTypeStr == null ? null : makeType(expectedTypeStr);
|
||||||
assertEquals(expectedType, type);
|
assertEquals(expectedType, type);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user