Skip to content

Commit ddbcf57

Browse files
committed
Merge pull request #14730 from ethereum/new-analysis-rename-type-annotation-to-type
Rename `TypeInference::typeAnnotation()` back to `type()`
2 parents 82df9e5 + 105264f commit ddbcf57

File tree

2 files changed

+30
-30
lines changed

2 files changed

+30
-30
lines changed

Diff for: libsolidity/experimental/analysis/TypeInference.cpp

+29-29
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,14 @@ bool TypeInference::visit(FunctionDefinition const& _functionDefinition)
146146

147147

148148
_functionDefinition.parameterList().accept(*this);
149-
unify(argumentsType, typeAnnotation(_functionDefinition.parameterList()), _functionDefinition.parameterList().location());
149+
unify(argumentsType, type(_functionDefinition.parameterList()), _functionDefinition.parameterList().location());
150150
if (_functionDefinition.experimentalReturnExpression())
151151
{
152152
ScopedSaveAndRestore expressionContext{m_expressionContext, ExpressionContext::Type};
153153
_functionDefinition.experimentalReturnExpression()->accept(*this);
154154
unify(
155155
returnType,
156-
typeAnnotation(*_functionDefinition.experimentalReturnExpression()),
156+
type(*_functionDefinition.experimentalReturnExpression()),
157157
_functionDefinition.experimentalReturnExpression()->location()
158158
);
159159
}
@@ -171,7 +171,7 @@ void TypeInference::endVisit(Return const& _return)
171171
solAssert(m_currentFunctionType);
172172
Type functionReturnType = std::get<1>(TypeSystemHelpers{m_typeSystem}.destFunctionType(*m_currentFunctionType));
173173
if (_return.expression())
174-
unify(functionReturnType, typeAnnotation(*_return.expression()), _return.location());
174+
unify(functionReturnType, type(*_return.expression()), _return.location());
175175
else
176176
unify(functionReturnType, m_unitType, _return.location());
177177
}
@@ -181,7 +181,7 @@ void TypeInference::endVisit(ParameterList const& _parameterList)
181181
auto& listAnnotation = annotation(_parameterList);
182182
solAssert(!listAnnotation.type);
183183
listAnnotation.type = TypeSystemHelpers{m_typeSystem}.tupleType(
184-
_parameterList.parameters() | ranges::views::transform([&](auto _arg) { return typeAnnotation(*_arg); }) | ranges::to<std::vector<Type>>
184+
_parameterList.parameters() | ranges::views::transform([&](auto _arg) { return type(*_arg); }) | ranges::to<std::vector<Type>>
185185
);
186186
}
187187

@@ -211,7 +211,7 @@ bool TypeInference::visit(TypeClassDefinition const& _typeClassDefinition)
211211
subNode->accept(*this);
212212
auto const* functionDefinition = dynamic_cast<FunctionDefinition const*>(subNode.get());
213213
solAssert(functionDefinition);
214-
auto functionType = typeAnnotation(*functionDefinition);
214+
auto functionType = type(*functionDefinition);
215215
if (!functionTypes.emplace(functionDefinition->name(), functionType).second)
216216
m_errorReporter.fatalTypeError(3195_error, functionDefinition->location(), "Function in type class declared multiple times.");
217217
auto typeVars = TypeEnvironmentHelpers{*m_env}.typeVars(functionType);
@@ -235,7 +235,7 @@ bool TypeInference::visit(TypeClassDefinition const& _typeClassDefinition)
235235
m_errorReporter.typeError(1807_error, _typeClassDefinition.location(), "Function " + functionName + " depends on invalid type variable.");
236236
}
237237

238-
unify(typeAnnotation(_typeClassDefinition.typeVariable()), m_typeSystem.freshTypeVariable({{typeClass}}), _typeClassDefinition.location());
238+
unify(type(_typeClassDefinition.typeVariable()), m_typeSystem.freshTypeVariable({{typeClass}}), _typeClassDefinition.location());
239239
for (auto instantiation: m_analysis.annotation<TypeRegistration>(_typeClassDefinition).instantiations | ranges::views::values)
240240
// TODO: recursion-safety? Order of instantiation?
241241
instantiation->accept(*this);
@@ -268,7 +268,7 @@ bool TypeInference::visit(InlineAssembly const& _inlineAssembly)
268268
solAssert(!!declaration, "");
269269
solAssert(identifierInfo->suffix == "", "");
270270

271-
unify(typeAnnotation(*declaration), m_wordType, originLocationOf(_identifier));
271+
unify(type(*declaration), m_wordType, originLocationOf(_identifier));
272272
identifierInfo->valueSize = 1;
273273
return true;
274274
};
@@ -302,7 +302,7 @@ bool TypeInference::visit(BinaryOperation const& _binaryOperation)
302302
_binaryOperation.leftExpression().accept(*this);
303303
_binaryOperation.rightExpression().accept(*this);
304304

305-
Type argTuple = helper.tupleType({typeAnnotation(_binaryOperation.leftExpression()), typeAnnotation(_binaryOperation.rightExpression())});
305+
Type argTuple = helper.tupleType({type(_binaryOperation.leftExpression()), type(_binaryOperation.rightExpression())});
306306
Type resultType = m_typeSystem.freshTypeVariable({});
307307
Type genericFunctionType = helper.functionType(argTuple, resultType);
308308
unify(functionType, genericFunctionType, _binaryOperation.location());
@@ -316,8 +316,8 @@ bool TypeInference::visit(BinaryOperation const& _binaryOperation)
316316
ScopedSaveAndRestore expressionContext{m_expressionContext, ExpressionContext::Type};
317317
_binaryOperation.rightExpression().accept(*this);
318318
}
319-
Type leftType = typeAnnotation(_binaryOperation.leftExpression());
320-
unify(leftType, typeAnnotation(_binaryOperation.rightExpression()), _binaryOperation.location());
319+
Type leftType = type(_binaryOperation.leftExpression());
320+
unify(leftType, type(_binaryOperation.rightExpression()), _binaryOperation.location());
321321
operationAnnotation.type = leftType;
322322
}
323323
else
@@ -334,21 +334,21 @@ bool TypeInference::visit(BinaryOperation const& _binaryOperation)
334334
ScopedSaveAndRestore expressionContext{m_expressionContext, ExpressionContext::Sort};
335335
_binaryOperation.rightExpression().accept(*this);
336336
}
337-
Type leftType = typeAnnotation(_binaryOperation.leftExpression());
338-
unify(leftType, typeAnnotation(_binaryOperation.rightExpression()), _binaryOperation.location());
337+
Type leftType = type(_binaryOperation.leftExpression());
338+
unify(leftType, type(_binaryOperation.rightExpression()), _binaryOperation.location());
339339
operationAnnotation.type = leftType;
340340
}
341341
else if (_binaryOperation.getOperator() == Token::RightArrow)
342342
{
343343
_binaryOperation.leftExpression().accept(*this);
344344
_binaryOperation.rightExpression().accept(*this);
345-
operationAnnotation.type = helper.functionType(typeAnnotation(_binaryOperation.leftExpression()), typeAnnotation(_binaryOperation.rightExpression()));
345+
operationAnnotation.type = helper.functionType(type(_binaryOperation.leftExpression()), type(_binaryOperation.rightExpression()));
346346
}
347347
else if (_binaryOperation.getOperator() == Token::BitOr)
348348
{
349349
_binaryOperation.leftExpression().accept(*this);
350350
_binaryOperation.rightExpression().accept(*this);
351-
operationAnnotation.type = helper.sumType({typeAnnotation(_binaryOperation.leftExpression()), typeAnnotation(_binaryOperation.rightExpression())});
351+
operationAnnotation.type = helper.sumType({type(_binaryOperation.leftExpression()), type(_binaryOperation.rightExpression())});
352352
}
353353
else
354354
{
@@ -372,9 +372,9 @@ void TypeInference::endVisit(VariableDeclarationStatement const& _variableDeclar
372372
m_errorReporter.typeError(2655_error, _variableDeclarationStatement.location(), "Multi variable declaration not supported.");
373373
return;
374374
}
375-
Type variableType = typeAnnotation(*_variableDeclarationStatement.declarations().front());
375+
Type variableType = type(*_variableDeclarationStatement.declarations().front());
376376
if (_variableDeclarationStatement.initialValue())
377-
unify(variableType, typeAnnotation(*_variableDeclarationStatement.initialValue()), _variableDeclarationStatement.location());
377+
unify(variableType, type(*_variableDeclarationStatement.initialValue()), _variableDeclarationStatement.location());
378378
}
379379

380380
bool TypeInference::visit(VariableDeclaration const& _variableDeclaration)
@@ -390,7 +390,7 @@ bool TypeInference::visit(VariableDeclaration const& _variableDeclaration)
390390
{
391391
ScopedSaveAndRestore expressionContext{m_expressionContext, ExpressionContext::Type};
392392
_variableDeclaration.typeExpression()->accept(*this);
393-
variableAnnotation.type = typeAnnotation(*_variableDeclaration.typeExpression());
393+
variableAnnotation.type = type(*_variableDeclaration.typeExpression());
394394
return false;
395395
}
396396
variableAnnotation.type = m_typeSystem.freshTypeVariable({});
@@ -401,7 +401,7 @@ bool TypeInference::visit(VariableDeclaration const& _variableDeclaration)
401401
{
402402
ScopedSaveAndRestore expressionContext{m_expressionContext, ExpressionContext::Sort};
403403
_variableDeclaration.typeExpression()->accept(*this);
404-
unify(*variableAnnotation.type, typeAnnotation(*_variableDeclaration.typeExpression()), _variableDeclaration.typeExpression()->location());
404+
unify(*variableAnnotation.type, type(*_variableDeclaration.typeExpression()), _variableDeclaration.typeExpression()->location());
405405
}
406406
return false;
407407
case ExpressionContext::Sort:
@@ -424,7 +424,7 @@ void TypeInference::endVisit(IfStatement const& _ifStatement)
424424
return;
425425
}
426426

427-
unify(typeAnnotation(_ifStatement.condition()), m_boolType, _ifStatement.condition().location());
427+
unify(type(_ifStatement.condition()), m_boolType, _ifStatement.condition().location());
428428

429429
ifAnnotation.type = m_unitType;
430430
}
@@ -441,8 +441,8 @@ void TypeInference::endVisit(Assignment const& _assignment)
441441
return;
442442
}
443443

444-
Type leftType = typeAnnotation(_assignment.leftHandSide());
445-
unify(leftType, typeAnnotation(_assignment.rightHandSide()), _assignment.location());
444+
Type leftType = type(_assignment.leftHandSide());
445+
unify(leftType, type(_assignment.rightHandSide()), _assignment.location());
446446
assignmentAnnotation.type = leftType;
447447
}
448448

@@ -676,7 +676,7 @@ bool TypeInference::visit(TypeClassInstantiation const& _typeClassInstantiation)
676676
}
677677
}
678678

679-
Type type{TypeConstant{*typeConstructor, arguments}};
679+
Type instanceType{TypeConstant{*typeConstructor, arguments}};
680680

681681
std::map<std::string, Type> functionTypes;
682682

@@ -685,17 +685,17 @@ bool TypeInference::visit(TypeClassInstantiation const& _typeClassInstantiation)
685685
auto const* functionDefinition = dynamic_cast<FunctionDefinition const*>(subNode.get());
686686
solAssert(functionDefinition);
687687
subNode->accept(*this);
688-
if (!functionTypes.emplace(functionDefinition->name(), typeAnnotation(*functionDefinition)).second)
688+
if (!functionTypes.emplace(functionDefinition->name(), type(*functionDefinition)).second)
689689
m_errorReporter.typeError(3654_error, subNode->location(), "Duplicate definition of function " + functionDefinition->name() + " during type class instantiation.");
690690
}
691691

692-
if (auto error = m_typeSystem.instantiateClass(type, arity))
692+
if (auto error = m_typeSystem.instantiateClass(instanceType, arity))
693693
m_errorReporter.typeError(5094_error, _typeClassInstantiation.location(), *error);
694694

695695
auto const& classFunctions = annotation().typeClassFunctions.at(*typeClass);
696696

697697
TypeEnvironment newEnv = m_env->clone();
698-
if (!newEnv.unify(m_typeSystem.typeClassVariable(*typeClass), type).empty())
698+
if (!newEnv.unify(m_typeSystem.typeClassVariable(*typeClass), instanceType).empty())
699699
{
700700
m_errorReporter.typeError(4686_error, _typeClassInstantiation.location(), "Unification of class and instance variable failed.");
701701
return false;
@@ -758,7 +758,7 @@ void TypeInference::endVisit(MemberAccess const& _memberAccess)
758758
{
759759
auto& memberAccessAnnotation = annotation(_memberAccess);
760760
solAssert(!memberAccessAnnotation.type);
761-
Type expressionType = typeAnnotation(_memberAccess.expression());
761+
Type expressionType = type(_memberAccess.expression());
762762
memberAccessAnnotation.type = memberType(expressionType, _memberAccess.memberName(), _memberAccess.location());
763763
}
764764

@@ -824,7 +824,7 @@ void TypeInference::endVisit(FunctionCall const& _functionCall)
824824
auto& functionCallAnnotation = annotation(_functionCall);
825825
solAssert(!functionCallAnnotation.type);
826826

827-
Type functionType = typeAnnotation(_functionCall.expression());
827+
Type functionType = type(_functionCall.expression());
828828

829829
TypeSystemHelpers helper{m_typeSystem};
830830
std::vector<Type> argTypes;
@@ -834,7 +834,7 @@ void TypeInference::endVisit(FunctionCall const& _functionCall)
834834
{
835835
case ExpressionContext::Term:
836836
case ExpressionContext::Type:
837-
argTypes.emplace_back(typeAnnotation(*arg));
837+
argTypes.emplace_back(type(*arg));
838838
break;
839839
case ExpressionContext::Sort:
840840
m_errorReporter.typeError(9173_error, _functionCall.location(), "Function call in sort context.");
@@ -1171,7 +1171,7 @@ void TypeInference::unify(Type _a, Type _b, langutil::SourceLocation _location)
11711171
}
11721172
}
11731173

1174-
experimental::Type TypeInference::typeAnnotation(ASTNode const& _node) const
1174+
experimental::Type TypeInference::type(ASTNode const& _node) const
11751175
{
11761176
auto result = annotation(_node).type;
11771177
solAssert(result);

Diff for: libsolidity/experimental/analysis/TypeInference.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class TypeInference: public ASTConstVisitor
103103
Type m_boolType;
104104
std::optional<Type> m_currentFunctionType;
105105

106-
Type typeAnnotation(ASTNode const& _node) const;
106+
Type type(ASTNode const& _node) const;
107107

108108
Annotation& annotation(ASTNode const& _node);
109109
Annotation const& annotation(ASTNode const& _node) const;

0 commit comments

Comments
 (0)