swiftlang/swift

[SR-10506] Formalize getType closure pattern

Open

#52.906 aperta il 18 apr 2019

Vedi su GitHub
 (1 commento) (0 reazioni) (0 assegnatari)Swift (10.719 fork)batch import
compilergood first issuetype checker

Metriche repository

Star
 (69.989 star)
Metriche merge PR
 (Merge medio 8g 17h) (510 PR mergiate in 30 g)

Descrizione

Previous ID SR-10506
Radar None
Original Reporter @beccadax
Type Task
Votes 0
Component/s Compiler
Labels Task, StarterBug, TypeChecker
Assignee None
Priority Medium

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.

Guida contributor