Avoid unnecessary work when checking deferred functions#20860
Avoid unnecessary work when checking deferred functions#20860ilevkivskyi merged 3 commits intopython:masterfrom
Conversation
This comment has been minimized.
This comment has been minimized.
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
|
If there are no objections on this, I would propose to try this. |
|
Eh, this broke self-check. I guess there are still some weird edge cases where we would give false positives if we would return soon. I am going to only keep the fix part of this PR and revert the perf optimization. |
|
Well, it looks like it is not the performance optimization part actually. It looks like this may have exposed some bug in |
|
Anyway, I will revert the problematic part and the optimization. It already caused troubles so it looks risky. I am going to keep the tests and a related fix. |
This fixes a self-check regression caused by #20860 It looks like we are not ready for this yet.
As I was looking more I noticed that we widen the inferred types during redefinition even if current function is deferred. It turned out that this doesn't seem to have any user visible effect (mostly because
set_inferred_type()already guards against this). But we still do a bunch of pointless work (like few extra calls tomake_simplified_union()per assignment), so we should bail out early.But then I thought why do we even continuing to type-check the current function if:
ExpressionChecker.accept()returnsAnyfor every expressionIf all tests pass, and there is nothing in primer, I think we should stop type-checking soon after deferral, as this will probably save ~1-2% of time (maybe more for code bases with many import cycles etc).
Added test already passes on master, I added it to avoid regressions as I didn't find any similar tests for
--allow-redefinition-new.