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

Treat persistent module as regular specialized #1334

Merged
merged 113 commits into from
Jul 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
113 commits
Select commit Hold shift + click to select a range
b605b76
Remove old qualified name
May 17, 2019
5471ce4
Node storage
May 17, 2019
8a8d847
Class and scope to use AST map
May 17, 2019
89ce2ca
Library analysis
May 17, 2019
7a93bf7
Fix SO
May 18, 2019
2a2bdf8
Keep small AST with imports
May 18, 2019
3edaa73
AST reduction
May 18, 2019
73371e1
Final field
May 18, 2019
7d60edc
Initial
May 20, 2019
02475f4
Reload
May 22, 2019
835eeac
Merge master
May 25, 2019
6b6e928
Ignore post-final requests
May 25, 2019
9692397
Drop AST
May 25, 2019
080beab
Remove local variables
May 25, 2019
93a6915
Test fixes
May 26, 2019
cadd7ce
Fix overload match
May 26, 2019
f61b1a7
Tests
May 26, 2019
1b20326
Add locks
May 27, 2019
d7efdac
Remove local variables
May 25, 2019
98934d4
Drop file content to save memory
May 27, 2019
417ae03
Cache PEP hints
May 28, 2019
ec5605f
Recreate AST
May 28, 2019
713d87f
Fix specialization
May 28, 2019
50e63e6
Fix locations
May 28, 2019
fcd0c06
usings
May 28, 2019
f6a992b
Test fixes
May 28, 2019
acad202
Add options to keep data in memory
May 28, 2019
f176b2f
Merge branch 'master' of https://github.com/microsoft/python-language…
May 28, 2019
4225337
Merge master
May 28, 2019
86e36a6
Fix test
May 28, 2019
ba97e9f
Fix lambda parameters
May 28, 2019
ffed87e
Fix argument set
May 29, 2019
186a9c6
Fix overload doc
May 29, 2019
4196699
Fix stub merge errors
May 29, 2019
93249d4
Fix async issues
May 29, 2019
5e61392
Undo some changes
May 29, 2019
130b95d
Fix test
May 29, 2019
a6676f1
Fix race condition
May 30, 2019
18b61ad
Merge master
Jun 1, 2019
0850544
Merge master
Jun 3, 2019
7d0bf5b
Merge branch 'proxymod' into db
Jun 4, 2019
663dc8f
Partial
Jun 4, 2019
86544a6
Models and views
Jun 4, 2019
67b06c2
Merge branch 'master' of https://github.com/microsoft/python-language…
Jun 4, 2019
9daf4a9
Merge master
Jun 4, 2019
90318e9
Restore log null checks
Jun 4, 2019
b79d918
Merge master
Jun 4, 2019
a02c6f3
Fix merge conflict
Jun 4, 2019
8a6b055
Merge master
Jun 5, 2019
57358eb
Fix merge issue
Jun 5, 2019
41ef00f
Merge branch 'master' of https://github.com/microsoft/python-language…
Jun 5, 2019
814cd64
Merge master
Jun 6, 2019
6ceb9b8
Null check
Jun 6, 2019
74bb061
Merge branch 'noast5' into db
Jun 6, 2019
478ce37
Partial
Jun 6, 2019
cb46e68
Partial
Jun 6, 2019
ef2981c
Partial
Jun 6, 2019
2164ad5
Fix test
Jun 6, 2019
1a48790
Merge branch 'noast5' into db
Jun 6, 2019
319c416
Partial
Jun 6, 2019
86b0ee6
Partial
Jun 7, 2019
1670c9d
First test
Jun 7, 2019
ab69cfd
Baseline comparison
Jun 7, 2019
e00c197
Builtins
Jun 7, 2019
4e1657c
Partial
Jun 7, 2019
ade00f4
Type fixes
Jun 10, 2019
e2fc221
Fix type names, part I
Jun 11, 2019
aaf40bb
Qualified name
Jun 11, 2019
a5b3b20
Properly write variables
Jun 11, 2019
f23a487
Partial
Jun 11, 2019
e6373a7
Construct module from model
Jun 12, 2019
6f6737d
Test
Jun 12, 2019
081f475
Variable creations
Jun 12, 2019
42fa4dc
Factories
Jun 13, 2019
2f03cb9
Factories
Jun 13, 2019
1dc3339
Split construction
Jun 13, 2019
9535bad
Restore
Jun 13, 2019
bec2a82
Save builtins
Jun 13, 2019
80c9b1c
Test passes
Jun 13, 2019
5b372f7
Qualified name
Jun 13, 2019
3066554
Better export detection
Jun 14, 2019
91491d4
Test fixes
Jun 14, 2019
bc4f587
More consistent qualified names
Jun 14, 2019
af69880
Sys test
Jun 14, 2019
5c1a0c3
Demo
Jun 14, 2019
4146690
Complete sys write/read
Jun 17, 2019
48763aa
Partial
Jun 17, 2019
93bece3
Partial
Jun 18, 2019
55b6a3f
Test staility
Jun 18, 2019
5e9bf8e
Perf bug
Jun 18, 2019
c152e67
Merge master
Jun 18, 2019
eadd622
Baseline, remove debug code, deactivate db
Jun 18, 2019
ba87581
Test fixes
Jun 18, 2019
a797593
Test fix
Jun 18, 2019
db6c7fc
Simplify a bit
Jun 19, 2019
f73fed0
Baselines and use : separator
Jun 19, 2019
4054d5a
Baselines
Jun 19, 2019
4ef96d8
PR feedback
Jun 19, 2019
c7436ed
Merge branch 'master' of https://github.com/microsoft/python-language…
Jun 19, 2019
f3860e6
Merge master
Jun 19, 2019
cab0fce
Remove registry reference
Jun 19, 2019
b9c1e14
PR feedback
Jun 19, 2019
4fbdcb9
Merge master
Jul 11, 2019
c7b1a5d
Merge db
Jul 11, 2019
90d1429
PR feedback
Jul 11, 2019
10289c3
Merge branch 'master' of https://github.com/microsoft/python-language…
Jul 12, 2019
facb062
Restore persistence + update test
Jul 12, 2019
d80604a
Better handle persistent module in dependencies
Jul 14, 2019
0705812
Merge master
Jul 15, 2019
96a5b82
Merge master
Jul 15, 2019
360f922
Undo
Jul 15, 2019
57c24c5
Fix merge issue
Jul 15, 2019
8192ff2
Remove debug code
Jul 17, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Analysis/Ast/Impl/Analyzer/AnalysisModuleKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private enum KeyType { Default, Typeshed, LibraryAsDocument }
public AnalysisModuleKey(IPythonModule module) {
Name = module.Name;
FilePath = module.ModuleType == ModuleType.CompiledBuiltin ? null : module.FilePath;
_type = module is StubPythonModule stub && stub.IsTypeshed
_type = module is StubPythonModule stub && stub.IsTypeshed
? KeyType.Typeshed
: module.ModuleType == ModuleType.Library && module is IDocument document && document.IsOpen
? KeyType.LibraryAsDocument
Expand Down
9 changes: 4 additions & 5 deletions src/Analysis/Ast/Impl/Analyzer/PythonAnalyzerEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Python.Analysis.Core.DependencyResolution;
using Microsoft.Python.Analysis.Documents;
using Microsoft.Python.Analysis.Modules;
using Microsoft.Python.Analysis.Types;
using Microsoft.Python.Core;
Expand Down Expand Up @@ -264,8 +263,8 @@ private HashSet<AnalysisModuleKey> FindDependencies(IPythonModule module, Python
return dependencies;
}

private static bool Ignore(IModuleManagement moduleResolution, string name)
=> moduleResolution.BuiltinModuleName.EqualsOrdinal(name) || moduleResolution.GetSpecializedModule(name) != null;
private static bool Ignore(IModuleManagement moduleResolution, string fullName, string modulePath)
=> moduleResolution.BuiltinModuleName.EqualsOrdinal(fullName) || moduleResolution.GetSpecializedModule(fullName, modulePath) != null;

private void UpdateAnalysisTcs(int analysisVersion) {
_analysisVersion = analysisVersion;
Expand Down Expand Up @@ -332,10 +331,10 @@ public override bool Walk(FromImportStatement fromImport) {

private void HandleSearchResults(IImportSearchResult searchResult) {
switch (searchResult) {
case ModuleImport moduleImport when !Ignore(_moduleResolution, moduleImport.FullName):
case ModuleImport moduleImport when !Ignore(_moduleResolution, moduleImport.FullName, moduleImport.ModulePath):
Dependencies.Add(new AnalysisModuleKey(moduleImport.FullName, moduleImport.ModulePath, _isTypeshed));
return;
case PossibleModuleImport possibleModuleImport when !Ignore(_moduleResolution, possibleModuleImport.PrecedingModuleFullName):
case PossibleModuleImport possibleModuleImport when !Ignore(_moduleResolution, possibleModuleImport.PrecedingModuleFullName, possibleModuleImport.PrecedingModulePath):
Dependencies.Add(new AnalysisModuleKey(possibleModuleImport.PrecedingModuleFullName, possibleModuleImport.PrecedingModulePath, _isTypeshed));
return;
default:
Expand Down
9 changes: 7 additions & 2 deletions src/Analysis/Ast/Impl/Analyzer/PythonAnalyzerSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ internal sealed class PythonAnalyzerSession {
private readonly IPythonAnalyzer _analyzer;
private readonly ILogger _log;
private readonly ITelemetryService _telemetry;
private readonly IModuleDatabaseService _moduleDatabaseService;

private State _state;
private bool _isCanceled;
Expand Down Expand Up @@ -86,6 +87,7 @@ public PythonAnalyzerSession(IServiceManager services,
_analyzer = _services.GetService<IPythonAnalyzer>();
_log = _services.GetService<ILogger>();
_telemetry = _services.GetService<ITelemetryService>();
_moduleDatabaseService = _services.GetService<IModuleDatabaseService>();
_progress = progress;
}

Expand Down Expand Up @@ -297,7 +299,6 @@ private void AnalyzeEntry() {
}

var startTime = stopWatch?.Elapsed ?? TimeSpan.Zero;

AnalyzeEntry(null, _entry, module, ast, Version);

LogCompleted(null, module, stopWatch, startTime);
Expand Down Expand Up @@ -383,8 +384,12 @@ private IDocumentAnalysis CreateAnalysis(IDependencyChainNode<PythonAnalyzerEntr

ast.Reduce(x => x is ImportStatement || x is FromImportStatement);
document.SetAst(ast);

var eval = new ExpressionEval(walker.Eval.Services, document, ast);
return new LibraryAnalysis(document, version, walker.GlobalScope, eval, walker.StarImportMemberNames);
var analysis = new LibraryAnalysis(document, version, walker.GlobalScope, eval, walker.StarImportMemberNames);

_moduleDatabaseService?.StoreModuleAnalysisAsync(analysis, CancellationToken.None).DoNotWait();
return analysis;
}

private enum State {
Expand Down
1 change: 0 additions & 1 deletion src/Analysis/Ast/Impl/Extensions/NodeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public static LocationInfo GetLocation(this Node node, IExpressionEvaluator eval

return GetLocation(node, eval.Ast, eval.Module);
}

public static LocationInfo GetLocation(this Node node, IDocumentAnalysis analysis) {
if (node == null || node.StartIndex >= node.EndIndex) {
return LocationInfo.Empty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public interface IModuleManagement: IModuleResolution {
/// <summary>
/// Returns specialized module, if any.
/// </summary>
IPythonModule GetSpecializedModule(string name);
IPythonModule GetSpecializedModule(string name, string modulePath = null);

/// <summary>
/// Root directory of the path resolver.
Expand Down
7 changes: 5 additions & 2 deletions src/Analysis/Ast/Impl/Modules/PythonModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ protected PythonModule(string name, ModuleType moduleType, IServiceContainer ser
Log = services.GetService<ILogger>();
Interpreter = services.GetService<IPythonInterpreter>();
Analysis = new EmptyAnalysis(services, this);
GlobalScope = Analysis.GlobalScope;

_diagnosticsService = services.GetService<IDiagnosticsService>();
SetDeclaringModule(this);
Expand Down Expand Up @@ -150,10 +151,10 @@ public virtual string Documentation {
#endregion

#region IMemberContainer
public virtual IMember GetMember(string name) => Analysis.GlobalScope.Variables[name]?.Value;
public virtual IMember GetMember(string name) => GlobalScope.Variables[name]?.Value;
public virtual IEnumerable<string> GetMemberNames() {
// drop imported modules and typing.
return Analysis.GlobalScope.Variables
return GlobalScope.Variables
.Where(v => {
// Instances are always fine.
if (v.Value is IPythonInstance) {
Expand Down Expand Up @@ -209,6 +210,8 @@ protected virtual void Dispose(bool disposing) {
_disposeToken.TryMarkDisposed();
var analyzer = Services.GetService<IPythonAnalyzer>();
analyzer.RemoveAnalysis(this);
_parseCts?.Dispose();
_linkedParseCts?.Dispose();
}
#endregion

Expand Down
22 changes: 15 additions & 7 deletions src/Analysis/Ast/Impl/Modules/Resolution/MainModuleResolution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
namespace Microsoft.Python.Analysis.Modules.Resolution {
internal sealed class MainModuleResolution : ModuleResolutionBase, IModuleManagement {
private readonly ConcurrentDictionary<string, IPythonModule> _specialized = new ConcurrentDictionary<string, IPythonModule>();
private IModuleDatabaseService _dbService;
private IRunningDocumentTable _rdt;

public MainModuleResolution(string root, IServiceContainer services)
Expand Down Expand Up @@ -76,11 +77,6 @@ protected override IPythonModule CreateModule(string name) {
}
}

var dbs = _services.GetService<IModuleDatabaseService>();
if (dbs != null && dbs.TryCreateModule(name, moduleImport.ModulePath, out var m) != ModuleStorageState.DoesNotExist && m != null) {
return m;
}

// If there is a stub, make sure it is loaded and attached
// First check stub next to the module.
if (!TryCreateModuleStub(name, moduleImport.ModulePath, out var stub)) {
Expand Down Expand Up @@ -156,8 +152,17 @@ public IPythonModule SpecializeModule(string name, Func<string, IPythonModule> s
/// <summary>
/// Returns specialized module, if any.
/// </summary>
public IPythonModule GetSpecializedModule(string name)
=> _specialized.TryGetValue(name, out var module) ? module : null;
public IPythonModule GetSpecializedModule(string fullName, string modulePath = null) {
if (_specialized.TryGetValue(fullName, out var module)) {
return module;
}
var dbs = GetDbService();
if (dbs != null && dbs.TryCreateModule(fullName, modulePath, out module) != ModuleStorageState.DoesNotExist && module != null) {
SpecializeModule(fullName, s => module);
return module;
}
return null;
}

internal async Task LoadBuiltinTypesAsync(CancellationToken cancellationToken = default) {
var analyzer = _services.GetService<IPythonAnalyzer>();
Expand Down Expand Up @@ -237,5 +242,8 @@ private bool TryCreateModuleStub(string name, string modulePath, out IPythonModu

private IRunningDocumentTable GetRdt()
=> _rdt ?? (_rdt = _services.GetService<IRunningDocumentTable>());

private IModuleDatabaseService GetDbService()
=> _dbService ?? (_dbService = _services.GetService<IModuleDatabaseService>());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
using Microsoft.Python.Analysis.Caching;
using Microsoft.Python.Analysis.Core.DependencyResolution;
using Microsoft.Python.Analysis.Core.Interpreter;
using Microsoft.Python.Analysis.Documents;
using Microsoft.Python.Analysis.Types;
using Microsoft.Python.Core;
using Microsoft.Python.Core.IO;
Expand Down
4 changes: 2 additions & 2 deletions src/Analysis/Ast/Impl/Types/PythonPropertyType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ public string Description {
}

public override IMember Call(IPythonInstance instance, string memberName, IArgumentSet args)
=> _getter?.Call(args, instance?.GetPythonType() ?? DeclaringType);
=> _getter.Call(args, instance?.GetPythonType() ?? DeclaringType);

public IMember ReturnType => _getter?.Call(ArgumentSet.WithoutContext, DeclaringType)?.GetPythonType();
public IMember ReturnType => _getter?.Call(ArgumentSet.WithoutContext, DeclaringType);
#endregion

internal void AddOverload(IPythonFunctionOverload overload) => _getter = _getter ?? overload;
Expand Down
2 changes: 1 addition & 1 deletion src/Caching/Test/Files/Requests.json
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@
"Name": "Session"
},
{
"Value": "i:typing:Any",
"Value": "i:requests.structures:LookupDict",
"Id": 753305199,
"Name": "codes"
},
Expand Down