|
1 |
| -"""Top-level logic for the new semantic analyzer.""" |
| 1 | +"""Top-level logic for the new semantic analyzer. |
| 2 | +
|
| 3 | +The semantic analyzer binds names, resolves imports, detects various |
| 4 | +special constructs that don't have dedicated AST nodes after parse |
| 5 | +(such as 'cast' which looks like a call), and performs various simple |
| 6 | +consistency checks. |
| 7 | +
|
| 8 | +Semantic analysis of each SCC (strongly connected component; import |
| 9 | +cycle) is performed in one unit. Each module is analyzed as multiple |
| 10 | +separate *targets*; the module top level is one target and each function |
| 11 | +is a target. Nested functions are not separate targets, however. This is |
| 12 | +mostly identical to targets used by mypy daemon (but classes aren't |
| 13 | +targets in semantic analysis). |
| 14 | +
|
| 15 | +We first analyze each module top level in an SCC. If we encounter some |
| 16 | +names that we can't bind because the target of the name may not have |
| 17 | +been processed yet, we *defer* the current target for further |
| 18 | +processing. Deferred targets will be analyzed additional times until |
| 19 | +everything can be bound, or we reach a maximum number of iterations. |
| 20 | +
|
| 21 | +We keep track of a set of incomplete namespaces, i.e. namespaces that we |
| 22 | +haven't finished populating yet. References to these namespaces cause a |
| 23 | +deferral if they can't be satisfied. Initially every module in the SCC |
| 24 | +will be incomplete. |
| 25 | +""" |
2 | 26 |
|
3 | 27 | from typing import List, Tuple, Optional, Union
|
4 | 28 |
|
|
0 commit comments