swiftlang/swift

[SR-10506] Formalize getType closure pattern

Open

#52,906 创建于 2019年4月18日

在 GitHub 查看
 (1 评论) (0 反应) (0 负责人)Swift (10,719 fork)batch import
compilergood first issuetype checker

仓库指标

Star
 (69,989 star)
PR 合并指标
 (平均合并 8天 17小时) (30 天内合并 510 个 PR)

描述

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.

贡献者指南