Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.

Commit 59a3ca9

Browse files
author
Mikhail Arkhipov
committed
Revert "Remove deque & limit analysis passes"
This reverts commit 821e0c5.
1 parent 3c3a68a commit 59a3ca9

8 files changed

Lines changed: 431 additions & 34 deletions

File tree

src/Analysis/Engine/Impl/AnalysisLog.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
// permissions and limitations under the License.
1616

1717
using System;
18-
using System.Collections.Generic;
1918
using Microsoft.PythonTools.Analysis.Values;
2019

2120
namespace Microsoft.PythonTools.Analysis {
@@ -77,13 +76,13 @@ public static void Reset() {
7776
LastDisplayedTime = null;
7877
}
7978

80-
public static void Enqueue(Queue<AnalysisUnit> deque, AnalysisUnit unit) {
79+
public static void Enqueue(Deque<AnalysisUnit> deque, AnalysisUnit unit) {
8180
if (Active) {
8281
Add("E", IdDispenser.GetId(unit), deque.Count);
8382
}
8483
}
8584

86-
public static void Dequeue(Queue<AnalysisUnit> deque, AnalysisUnit unit) {
85+
public static void Dequeue(Deque<AnalysisUnit> deque, AnalysisUnit unit) {
8786
if (Active) {
8887
Add("D", IdDispenser.GetId(unit), deque.Count);
8988
}
@@ -109,7 +108,7 @@ public static void ExceedsTypeLimit(string variableDefType, int total, string co
109108
Add("X", variableDefType, total, contents);
110109
}
111110

112-
public static void Cancelled(Queue<AnalysisUnit> queue) {
111+
public static void Cancelled(Deque<AnalysisUnit> queue) {
113112
Add("Cancel", queue.Count);
114113
}
115114

src/Analysis/Engine/Impl/AnalysisUnit.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public AnalysisUnit CopyForEval() {
109109
}
110110

111111
internal void Enqueue() {
112-
if (!ForEval && !IsInQueue && !_suppressEnqueue && NeedsAnalysis()) {
112+
if (!ForEval && !IsInQueue && !_suppressEnqueue) {
113113
State.Queue.Append(this);
114114
AnalysisLog.Enqueue(State.Queue, this);
115115
IsInQueue = true;
@@ -120,10 +120,6 @@ internal void Enqueue() {
120120
}
121121
}
122122

123-
private bool NeedsAnalysis()
124-
=> _analysisCount == 0 || _scope != null && _scope.AllVariables.Select(k => k.Value).Any(v => !v.HasTypes);
125-
126-
127123
/// <summary>
128124
/// The AST which will be analyzed when this node is analyzed
129125
/// </summary>
@@ -365,7 +361,8 @@ public ClassAnalysisUnit(ClassDefinition node, InterpreterScope declScope, Analy
365361
public new ClassDefinition Ast => (ClassDefinition)base.Ast;
366362

367363
internal override void AnalyzeWorker(DDG ddg, CancellationToken cancel) {
368-
if (!ddg.Scope.TryGetNodeScope(Ast, out var scope)) {
364+
InterpreterScope scope;
365+
if (!ddg.Scope.TryGetNodeScope(Ast, out scope)) {
369366
return;
370367
}
371368

@@ -421,7 +418,8 @@ private IAnalysisSet ProcessClassDecorators(DDG ddg, ClassInfo classInfo) {
421418
foreach (var d in Ast.Decorators.Decorators.ExcludeDefault()) {
422419
var decorator = ddg._eval.Evaluate(d);
423420

424-
if (!_decoratorCalls.TryGetValue(d, out var nextExpr)) {
421+
Expression nextExpr;
422+
if (!_decoratorCalls.TryGetValue(d, out nextExpr)) {
425423
nextExpr = _decoratorCalls[d] = new CallExpression(d, new[] { new Arg(expr) });
426424
nextExpr.SetLoc(d.IndexSpan);
427425
}

src/Analysis/Engine/Impl/Analyzer/DDG.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ internal class DDG : PythonWalker {
3030
private SuiteStatement _curSuite;
3131
public readonly HashSet<IPythonProjectEntry> AnalyzedEntries = new HashSet<IPythonProjectEntry>();
3232

33-
public void Analyze(Queue<AnalysisUnit> queue, CancellationToken cancel, Action<int> reportQueueSize = null, int reportQueueInterval = 1) {
33+
public void Analyze(Deque<AnalysisUnit> queue, CancellationToken cancel, Action<int> reportQueueSize = null, int reportQueueInterval = 1) {
3434
if (cancel.IsCancellationRequested) {
3535
return;
3636
}
@@ -46,7 +46,7 @@ public void Analyze(Queue<AnalysisUnit> queue, CancellationToken cancel, Action<
4646
}
4747

4848
while (queue.Count > 0 && !cancel.IsCancellationRequested) {
49-
_unit = queue.Dequeue();
49+
_unit = queue.PopLeft();
5050

5151
if (_unit == endOfQueueMarker) {
5252
AnalysisLog.EndOfQueue(queueCountAtStart, queue.Count);
@@ -107,9 +107,10 @@ public InterpreterScope Scope {
107107
public PythonAnalyzer ProjectState => _unit.State;
108108

109109
public override bool Walk(PythonAst node) {
110+
ModuleReference existingRef;
110111
Debug.Assert(node == _unit.Ast);
111112

112-
if (!ProjectState.Modules.TryImport(_unit.DeclaringModule.Name, out var existingRef)) {
113+
if (!ProjectState.Modules.TryImport(_unit.DeclaringModule.Name, out existingRef)) {
113114
// publish our module ref now so that we don't collect dependencies as we'll be fully processed
114115
if (existingRef == null) {
115116
ProjectState.Modules[_unit.DeclaringModule.Name] = new ModuleReference(_unit.DeclaringModule, _unit.DeclaringModule.Name);
@@ -470,7 +471,8 @@ internal List<AnalysisValue> LookupBaseMethods(string name, IEnumerable<IAnalysi
470471
}
471472

472473
public override bool Walk(FunctionDefinition node) {
473-
if (_unit.InterpreterScope.TryGetNodeScope(node, out var funcScope)) {
474+
InterpreterScope funcScope;
475+
if (_unit.InterpreterScope.TryGetNodeScope(node, out funcScope)) {
474476
var function = ((FunctionScope)funcScope).Function;
475477
var analysisUnit = (FunctionAnalysisUnit)((FunctionScope)funcScope).Function.AnalysisUnit;
476478

@@ -630,7 +632,8 @@ public override bool Walk(AssertStatement node) {
630632
}
631633

632634
private void TryPushIsInstanceScope(Node node, Expression test) {
633-
if (Scope.TryGetNodeScope(node, out var newScope)) {
635+
InterpreterScope newScope;
636+
if (Scope.TryGetNodeScope(node, out newScope)) {
634637
var outerScope = Scope;
635638
var isInstanceScope = (IsInstanceScope)newScope;
636639

src/Analysis/Engine/Impl/Analyzer/DependentKeyValue.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,13 @@ public bool AddTypes(IProjectEntry projectEntry, PythonAnalyzer projectState, IE
5151

5252
bool anyAdded = false;
5353
foreach (var key in keyTypes) {
54-
if (!dependencies.KeyValues.TryGetValue(key, out var values)) {
54+
IAnalysisSet values;
55+
if (!dependencies.KeyValues.TryGetValue(key, out values)) {
5556
values = AnalysisSet.Create(valueTypes);
5657
anyAdded = true;
5758
} else {
58-
values = values.Union(valueTypes, out var added);
59+
bool added;
60+
values = values.Union(valueTypes, out added);
5961
anyAdded |= added;
6062
}
6163
if (anyAdded && values.Count > projectState.Limits.DictValueTypes) {
@@ -161,7 +163,8 @@ public Dictionary<AnalysisValue, IAnalysisSet> KeyValueTypes {
161163
}
162164
} else {
163165
foreach (var keyValue in mod.KeyValues) {
164-
if (!res.TryGetValue(keyValue.Key, out var existing)) {
166+
IAnalysisSet existing;
167+
if (!res.TryGetValue(keyValue.Key, out existing)) {
165168
res[keyValue.Key] = keyValue.Value;
166169
} else {
167170
res[keyValue.Key] = existing.Union(keyValue.Value, canMutate: false);
@@ -191,11 +194,13 @@ internal bool CopyFrom(DependentKeyValue dependentKeyValue, bool enqueue = true)
191194
}
192195

193196
foreach (var keyValue in otherDependency.Value.KeyValues) {
194-
if (!deps.KeyValues.TryGetValue(keyValue.Key, out var union)) {
197+
IAnalysisSet union;
198+
if (!deps.KeyValues.TryGetValue(keyValue.Key, out union)) {
195199
deps.KeyValues[keyValue.Key] = union = keyValue.Value;
196200
anyAdded = true;
197201
} else {
198-
deps.KeyValues[keyValue.Key] = union.Union(keyValue.Value, out var added, canMutate: false);
202+
bool added;
203+
deps.KeyValues[keyValue.Key] = union.Union(keyValue.Value, out added, canMutate: false);
199204
anyAdded |= added;
200205
}
201206
}

0 commit comments

Comments
 (0)