mirror of
https://github.com/microsoft/pyright.git
synced 2024-10-26 10:55:06 +03:00
Fixed performance issue that occurred in certain situations involving deeply nested loops and many unannotated variables that are dependent on each other.
This commit is contained in:
parent
bd467644e5
commit
5932ef4efd
@ -156,11 +156,11 @@ export function getCodeFlowEngine(
|
||||
): FlowNodeTypeResult {
|
||||
if (!isIncomplete) {
|
||||
flowIncompleteGeneration++;
|
||||
} else {
|
||||
} else if (type) {
|
||||
const prevEntry = flowNodeTypeCache!.get(flowNode.id);
|
||||
if (prevEntry === undefined) {
|
||||
flowIncompleteGeneration++;
|
||||
} else if (type && (prevEntry as IncompleteType).isIncompleteType) {
|
||||
} else if ((prevEntry as IncompleteType).isIncompleteType) {
|
||||
const prevIncompleteType = prevEntry as IncompleteType;
|
||||
if (prevIncompleteType.type && !isTypeSame(prevIncompleteType.type, type)) {
|
||||
flowIncompleteGeneration++;
|
||||
|
@ -2,8 +2,11 @@
|
||||
# recursion within the code flow engine and type narrowing logic.
|
||||
|
||||
|
||||
from typing import Any
|
||||
|
||||
|
||||
def func():
|
||||
c = None
|
||||
c: Any = None
|
||||
|
||||
while True:
|
||||
if a: # type: ignore
|
||||
|
45
packages/pyright-internal/src/tests/samples/loops25.py
Normal file
45
packages/pyright-internal/src/tests/samples/loops25.py
Normal file
@ -0,0 +1,45 @@
|
||||
# This sample tests a series of nested loops containing variables
|
||||
# with significant dependencies.
|
||||
|
||||
for val1 in range(10):
|
||||
cnt1 = 4
|
||||
for val2 in range(10 - val1):
|
||||
cnt2 = 4
|
||||
if val2 == val1:
|
||||
cnt2 -= 1
|
||||
for val3 in range(10 - val1 - val2):
|
||||
cnt3 = 4
|
||||
if val3 == val1:
|
||||
cnt3 -= 1
|
||||
if val3 == val2:
|
||||
cnt3 -= 1
|
||||
for val4 in range(10 - val1 - val2 - val3):
|
||||
cnt4 = 4
|
||||
if val4 == val1:
|
||||
cnt4 -= 1
|
||||
if val4 == val2:
|
||||
cnt4 -= 1
|
||||
if val4 == val3:
|
||||
cnt4 -= 1
|
||||
for val5 in range(10 - val1 - val2 - val3 - val4):
|
||||
cnt5 = 4
|
||||
if val5 == val1:
|
||||
cnt5 -= 1
|
||||
if val5 == val2:
|
||||
cnt5 -= 1
|
||||
if val5 == val3:
|
||||
cnt5 -= 1
|
||||
if val5 == val4:
|
||||
cnt5 -= 1
|
||||
val6 = 10 - val1 - val2 - val3 - val4 - val5
|
||||
cnt6 = 4
|
||||
if val6 == val1:
|
||||
cnt6 -= 1
|
||||
if val6 == val2:
|
||||
cnt6 -= 1
|
||||
if val6 == val3:
|
||||
cnt6 -= 1
|
||||
if val6 == val4:
|
||||
cnt6 -= 1
|
||||
if val6 == val5:
|
||||
cnt6 -= 1
|
@ -293,6 +293,12 @@ test('Loops24', () => {
|
||||
TestUtils.validateResults(analysisResults, 0);
|
||||
});
|
||||
|
||||
test('Loops25', () => {
|
||||
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['loops25.py']);
|
||||
|
||||
TestUtils.validateResults(analysisResults, 0);
|
||||
});
|
||||
|
||||
test('ForLoop1', () => {
|
||||
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['forLoop1.py']);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user