Commit 1125b30
TypeForm: Reorder identifier-string early-reject checks by rejection frequency
Move the unbound-type-variable check ahead of the PlaceholderNode check (and
ahead of the Var-value filter added in the previous commit) in
SemanticAnalyzer.try_parse_as_type_expression(). Final order:
unbound type variable -> value Var -> placeholder
These three checks are mutually exclusive -- a node is at most one of a
TypeVarExpr/ParamSpecExpr, a Var, or a PlaceholderNode -- so reordering cannot
change which expressions are rejected (verified: check-typeform and testsemanal
unchanged). Ordering them by descending rejection frequency, as measured on
mypy's self-check (unbound type vars ~951 >> value Vars ~157 > placeholders
~23), lets the commonest rejections exit first and minimizes total check
evaluations (~2700 -> ~1750 cheap isinstance calls over the self-check).
The win is below perf_compare's noise floor on its own (~10us), but the
reordering is free and behavior-preserving, and it makes the final ordering
self-documenting. A rationale comment is added at the head of the block.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>1 parent 03c7a5a commit 1125b30
1 file changed
Lines changed: 13 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8100 | 8100 | | |
8101 | 8101 | | |
8102 | 8102 | | |
8103 | | - | |
8104 | | - | |
8105 | | - | |
8106 | | - | |
8107 | | - | |
8108 | | - | |
| 8103 | + | |
| 8104 | + | |
| 8105 | + | |
| 8106 | + | |
| 8107 | + | |
| 8108 | + | |
| 8109 | + | |
8109 | 8110 | | |
8110 | 8111 | | |
8111 | 8112 | | |
| |||
8126 | 8127 | | |
8127 | 8128 | | |
8128 | 8129 | | |
| 8130 | + | |
| 8131 | + | |
| 8132 | + | |
| 8133 | + | |
| 8134 | + | |
| 8135 | + | |
8129 | 8136 | | |
8130 | 8137 | | |
8131 | 8138 | | |
| |||
0 commit comments