[SR-10506] Formalize getType closure pattern #52906
Labels
compiler
The Swift compiler itself
good first issue
Good for newcomers
task
type checker
Area → compiler: Semantic analysis
Additional Detail from JIRA
md5: dd815550dade98eb89026bfbc9fc1d2f
Issue Description:
Various methods in the compiler from swiftAST up take one or more closure parameters which are used to override how the types of AST nodes (mainly expressions) are accessed. In practice, these are mainly used to make a function look up types in a ConstraintSystem during type checking instead of using the values in the nodes themselves. A non-exhaustive list of examples:
AbstractClosureExpr::getResultType() and CallExpr::create() take a "getType" closure.
TypeExpr::getInstanceType() takes two closures for "hasType" and "getType".
LiteralExpr::shallowClone() takes two closures for "getType" and "setType".
Expr::dump() takes three closures for "getType", "getTypeOfTypeLoc", and "getTypeOfKeyPathComponent". These are plumbed through to various internal types in ASTDumper.cpp.
Rather than continuing to pass around ad-hoc closures, we should formalize this interface into a class that we can pass around. For example, we might declare an "ExprTypeMap" class in AST which declares all of the hasType()/getType()/setType() methods from ConstraintSystem and simply calls through to the equivalent methods on the AST nodes; then we can have ConstraintSystem inherit from this class and override these methods.
The text was updated successfully, but these errors were encountered: