Skip to content

Commit 6294c73

Browse files
scheglovcommit-bot@chromium.org
authored and
commit-bot@chromium.org
committed
Deprecate 'typeSystem' parameter for InheritanceManager3.
Change-Id: If14eb8900b0fb5cac5e49cf865f2e6e3a0a0263d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/126083 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
1 parent f196196 commit 6294c73

File tree

13 files changed

+51
-33
lines changed

13 files changed

+51
-33
lines changed

pkg/analysis_server/lib/src/domain_kythe.dart

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,11 @@ class KytheDomainHandler extends AbstractRequestHandler {
5757
<KytheGetKytheEntriesResult>[];
5858
ResolvedUnitResult result = await server.getResolvedUnit(file);
5959
if (result?.state == ResultState.VALID) {
60-
var typeSystem = await result.libraryElement.session.typeSystem;
6160
List<KytheEntry> entries = <KytheEntry>[];
6261
// TODO(brianwilkerson) Figure out how to get the list of files.
6362
List<String> files = <String>[];
64-
result.unit.accept(new KytheDartVisitor(
65-
server.resourceProvider,
66-
entries,
67-
file,
68-
new InheritanceManager3(typeSystem),
69-
result.content));
63+
result.unit.accept(new KytheDartVisitor(server.resourceProvider,
64+
entries, file, new InheritanceManager3(), result.content));
7065
allResults.add(new KytheGetKytheEntriesResult(entries, files));
7166
}
7267
//

pkg/analysis_server/lib/src/services/completion/dart/override_contributor.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class OverrideContributor implements DartCompletionContributor {
3939
return const <CompletionSuggestion>[];
4040
}
4141

42-
var inheritance = new InheritanceManager3(request.result.typeSystem);
42+
var inheritance = new InheritanceManager3();
4343

4444
// Generate a collection of inherited members
4545
var classElem = classDecl.declaredElement;

pkg/analyzer/lib/src/dart/analysis/library_context.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class LibraryContext {
7979
_createElementFactory();
8080
load2(targetLibrary);
8181

82-
inheritanceManager = new InheritanceManager3(analysisContext.typeSystem);
82+
inheritanceManager = new InheritanceManager3();
8383
}
8484

8585
/**

pkg/analyzer/lib/src/dart/element/inheritance_manager3.dart

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,14 @@ class Conflict {
3333
class InheritanceManager3 {
3434
static final _noSuchMethodName = Name(null, 'noSuchMethod');
3535

36-
final TypeSystemImpl _typeSystem;
37-
3836
/// Cached instance interfaces for [InterfaceType].
3937
final Map<InterfaceType, Interface> _interfaces = {};
4038

4139
/// The set of classes that are currently being processed, used to detect
4240
/// self-referencing cycles.
4341
final Set<ClassElement> _processingClasses = new Set<ClassElement>();
4442

45-
InheritanceManager3(TypeSystem typeSystem) : _typeSystem = typeSystem;
43+
InheritanceManager3([@deprecated TypeSystem typeSystem]);
4644

4745
/// Return the most specific signature of the member with the given [name]
4846
/// that the [type] inherits from the mixins, superclasses, or interfaces;
@@ -70,6 +68,7 @@ class InheritanceManager3 {
7068
if (interface._inheritedMap == null) {
7169
interface._inheritedMap = {};
7270
_findMostSpecificFromNamedCandidates(
71+
type.element.library.typeSystem,
7372
interface._inheritedMap,
7473
interface._overridden,
7574
);
@@ -95,6 +94,8 @@ class InheritanceManager3 {
9594
return Interface._empty;
9695
}
9796

97+
var typeSystem = classElement.library.typeSystem;
98+
9899
Map<Name, List<ExecutableElement>> namedCandidates = {};
99100
List<Map<Name, ExecutableElement>> superImplemented = [];
100101
Map<Name, ExecutableElement> declared;
@@ -124,7 +125,11 @@ class InheritanceManager3 {
124125
// `mixin M on S1, S2 {}` can call using `super` any instance member
125126
// from its superclass constraints, whether it is abstract or concrete.
126127
var superClass = <Name, ExecutableElement>{};
127-
_findMostSpecificFromNamedCandidates(superClass, superClassCandidates);
128+
_findMostSpecificFromNamedCandidates(
129+
typeSystem,
130+
superClass,
131+
superClassCandidates,
132+
);
128133
superImplemented.add(superClass);
129134
} else {
130135
if (type.superclass != null) {
@@ -173,6 +178,7 @@ class InheritanceManager3 {
173178
// signature becomes the signature of the class's interface.
174179
Map<Name, ExecutableElement> map = new Map.of(declared);
175180
List<Conflict> conflicts = _findMostSpecificFromNamedCandidates(
181+
typeSystem,
176182
map,
177183
namedCandidates,
178184
);
@@ -341,6 +347,7 @@ class InheritanceManager3 {
341347
/// such single most specific signature (i.e. no valid override), then add a
342348
/// new conflict description.
343349
List<Conflict> _findMostSpecificFromNamedCandidates(
350+
TypeSystemImpl typeSystem,
344351
Map<Name, ExecutableElement> map,
345352
Map<Name, List<ExecutableElement>> namedCandidates) {
346353
List<Conflict> conflicts;
@@ -375,7 +382,7 @@ class InheritanceManager3 {
375382
validOverride = candidates[i];
376383
for (var j = 0; j < candidates.length; j++) {
377384
var candidate = candidates[j];
378-
if (!_typeSystem.isOverrideSubtypeOf(
385+
if (!typeSystem.isOverrideSubtypeOf(
379386
validOverride.type, candidate.type)) {
380387
validOverride = null;
381388
break;

pkg/analyzer/lib/src/summary2/link.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,15 +205,15 @@ class Linker {
205205

206206
void _createTypeSystem() {
207207
if (typeProvider != null) {
208-
inheritance = InheritanceManager3(typeSystem);
208+
inheritance = InheritanceManager3();
209209
return;
210210
}
211211

212212
var coreLib = elementFactory.libraryOfUri('dart:core');
213213
var asyncLib = elementFactory.libraryOfUri('dart:async');
214214
elementFactory.createTypeProviders(coreLib, asyncLib);
215215

216-
inheritance = InheritanceManager3(typeSystem);
216+
inheritance = InheritanceManager3();
217217
}
218218

219219
void _performTopLevelInference() {

pkg/analyzer/lib/src/summary2/linked_element_factory.dart

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,14 @@ class LinkedElementFactory {
7979
),
8080
);
8181

82-
setLibraryTypeSystem(dartCore);
83-
setLibraryTypeSystem(dartAsync);
82+
// During linking we create libraries when typeProvider is not ready.
83+
// Update these libraries now, when typeProvider is ready.
84+
for (var reference in rootReference.children) {
85+
var libraryElement = reference.element as LibraryElementImpl;
86+
if (libraryElement != null && libraryElement.typeProvider == null) {
87+
_setLibraryTypeSystem(libraryElement);
88+
}
89+
}
8490

8591
dartCore.createLoadLibraryFunction(dartCore.typeProvider);
8692
dartAsync.createLoadLibraryFunction(dartAsync.typeProvider);
@@ -155,10 +161,11 @@ class LinkedElementFactory {
155161
}
156162
}
157163

158-
void setLibraryTypeSystem(LibraryElementImpl libraryElement) {
159-
// During dart:core and dart:async linking we don't have it yet.
160-
// It will be set later, once linking of these two is done.
161-
if (analysisContext.typeProvider == null) {
164+
void _setLibraryTypeSystem(LibraryElementImpl libraryElement) {
165+
// During linking we create libraries when typeProvider is not ready.
166+
// And if we link dart:core and dart:async, we cannot create it.
167+
// We will set typeProvider later, during [createTypeProviders].
168+
if (analysisContext.typeProviderLegacy == null) {
162169
return;
163170
}
164171

@@ -344,7 +351,7 @@ class _ElementRequest {
344351
reference,
345352
definingUnitContext.unit_withDeclarations,
346353
);
347-
elementFactory.setLibraryTypeSystem(libraryElement);
354+
elementFactory._setLibraryTypeSystem(libraryElement);
348355

349356
var units = <CompilationUnitElementImpl>[];
350357
var unitContainerRef = reference.getChild('@unit');

pkg/analyzer/test/generated/element_resolver_test.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1122,13 +1122,17 @@ class ElementResolverTest with ResourceProviderMixin, ElementsTypesMixin {
11221122
AnalysisContext context = TestAnalysisContext();
11231123
_typeProvider = context.typeProvider;
11241124

1125-
var inheritance = new InheritanceManager3(context.typeSystem);
11261125
Source source = new FileSource(getFile("/test.dart"));
11271126
CompilationUnitElementImpl unit = new CompilationUnitElementImpl();
11281127
unit.librarySource = unit.source = source;
11291128
_definingLibrary =
11301129
ElementFactory.library(context, "test", isNonNullableByDefault: false);
11311130
_definingLibrary.definingCompilationUnit = unit;
1131+
1132+
_definingLibrary.typeProvider = context.typeProvider;
1133+
_definingLibrary.typeSystem = context.typeSystem;
1134+
var inheritance = new InheritanceManager3();
1135+
11321136
_visitor = new ResolverVisitor(
11331137
inheritance, _definingLibrary, source, _typeProvider, _listener,
11341138
featureSet: FeatureSet.forTesting(),

pkg/analyzer/test/generated/static_type_analyzer_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1314,7 +1314,7 @@ class StaticTypeAnalyzerTest with ResourceProviderMixin, ElementsTypesMixin {
13141314
*/
13151315
StaticTypeAnalyzer _createAnalyzer() {
13161316
var context = TestAnalysisContext();
1317-
var inheritance = new InheritanceManager3(context.typeSystem);
1317+
var inheritance = new InheritanceManager3();
13181318
Source source = new FileSource(getFile("/lib.dart"));
13191319
CompilationUnitElementImpl definingCompilationUnit =
13201320
new CompilationUnitElementImpl();

pkg/analyzer/test/generated/test_analysis_context.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import 'package:analyzer/dart/analysis/features.dart';
66
import 'package:analyzer/dart/element/nullability_suffix.dart';
7+
import 'package:analyzer/src/dart/element/element.dart';
78
import 'package:analyzer/src/dart/element/type_provider.dart';
89
import 'package:analyzer/src/generated/engine.dart';
910
import 'package:analyzer/src/generated/resolver.dart';
@@ -45,6 +46,9 @@ class TestAnalysisContext implements AnalysisContext {
4546
strictInference: false,
4647
typeProvider: typeProvider,
4748
);
49+
50+
_setLibraryTypeSystem(sdkElements.coreLibrary);
51+
_setLibraryTypeSystem(sdkElements.asyncLibrary);
4852
}
4953

5054
@override
@@ -57,6 +61,11 @@ class TestAnalysisContext implements AnalysisContext {
5761
TypeSystemImpl get typeSystem => _typeSystem;
5862

5963
noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
64+
65+
void _setLibraryTypeSystem(LibraryElementImpl libraryElement) {
66+
libraryElement.typeProvider = _typeProvider;
67+
libraryElement.typeSystem = _typeSystem;
68+
}
6069
}
6170

6271
class _MockSource implements Source {

pkg/analyzer/test/src/dart/element/inheritance_manager3_test.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,9 +1114,7 @@ class _InheritanceManager3Base extends DriverResolutionTest {
11141114
@override
11151115
Future<void> resolveTestFile() async {
11161116
await super.resolveTestFile();
1117-
manager = new InheritanceManager3(
1118-
result.unit.declaredElement.context.typeSystem,
1119-
);
1117+
manager = new InheritanceManager3();
11201118
}
11211119

11221120
void _assertExecutable(ExecutableElement element, String expected) {

pkg/analyzer/test/src/lint/linter/linter_context_impl_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ abstract class AbstractLinterContextTest extends DriverResolutionTest {
4242
result.session.declaredVariables,
4343
result.typeProvider,
4444
result.typeSystem,
45-
InheritanceManager3(result.typeSystem),
45+
InheritanceManager3(),
4646
analysisOptions,
4747
// todo (pq): test package or consider passing in null
4848
workspacePackage,

pkg/analyzer_plugin/test/src/utilities/change_builder/change_builder_dart_test.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import 'package:analyzer/dart/ast/ast.dart';
99
import 'package:analyzer/dart/element/element.dart';
1010
import 'package:analyzer/dart/element/nullability_suffix.dart';
1111
import 'package:analyzer/dart/element/type.dart';
12-
import 'package:analyzer/dart/element/type_system.dart';
1312
import 'package:analyzer/src/dart/element/inheritance_manager3.dart';
1413
import 'package:analyzer/src/generated/source.dart';
1514
import 'package:analyzer/src/test_utilities/find_node.dart';
@@ -2831,8 +2830,7 @@ class B extends A {
28312830
nullabilitySuffix: NullabilitySuffix.star,
28322831
);
28332832

2834-
TypeSystem typeSystem = await session.typeSystem;
2835-
var inherited = new InheritanceManager3(typeSystem).getInherited(
2833+
var inherited = new InheritanceManager3().getInherited(
28362834
targetType,
28372835
new Name(null, nameToOverride),
28382836
);

pkg/nnbd_migration/lib/src/edge_builder.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ class EdgeBuilder extends GeneralizingAstVisitor<DecoratedType>
192192
EdgeBuilder(this.typeProvider, this._typeSystem, this._variables, this._graph,
193193
this.source, this.listener, this._decoratedClassHierarchy,
194194
{this.instrumentation})
195-
: _inheritanceManager = InheritanceManager3(_typeSystem);
195+
: _inheritanceManager = InheritanceManager3();
196196

197197
/// Gets the decorated type of [element] from [_variables], performing any
198198
/// necessary substitutions.

0 commit comments

Comments
 (0)