Skip to content

Commit ccdddd2

Browse files
scheglovcommit-bot@chromium.org
authored andcommitted
Parallel build-mode and DDC changes for summary2.
It does not enable summary2 yet, but makes it possible to flip one flag AnalysisDriver.useSummary2 to switch between summary1 and summary2. I run presubmit scripts, and it seems that it works for both. https://test.corp.google.com/ui#id=OCL:255717824:BASE:259228828:1563746330268:5481d33a https://test.corp.google.com/ui#id=OCL:255717824:BASE:258892260:1563515248201:2d5ce329 One thing that is not implemented yet is tracking used dependencies for summary2. So, //dart/bazel_codegen_tests:dependencies_test_run fails. Change-Id: Iec9f3852e9b91236ce98e87041031daa0cc71a88 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107689 Reviewed-by: Paul Berry <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Reviewed-by: Vijay Menon <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent ae5d497 commit ccdddd2

File tree

8 files changed

+242
-75
lines changed

8 files changed

+242
-75
lines changed

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

Lines changed: 108 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import 'package:analyzer/src/summary/package_bundle_reader.dart';
2020
import 'package:analyzer/src/summary/resynthesize.dart';
2121
import 'package:analyzer/src/summary/summarize_ast.dart';
2222
import 'package:analyzer/src/summary/summarize_elements.dart';
23+
import 'package:analyzer/src/summary/summary_sdk.dart';
24+
import 'package:analyzer/src/summary2/informative_data.dart';
2325
import 'package:analyzer/src/summary2/link.dart' as summary2;
2426
import 'package:analyzer/src/summary2/linked_bundle_context.dart' as summary2;
2527
import 'package:analyzer/src/summary2/linked_element_factory.dart' as summary2;
@@ -36,6 +38,8 @@ class DevCompilerResynthesizerBuilder {
3638

3739
_SourceCrawler _fileCrawler;
3840

41+
final List<_UnitInformativeData> _informativeData = [];
42+
3943
final PackageBundleAssembler _assembler;
4044
List<int> summaryBytes;
4145

@@ -83,17 +87,21 @@ class DevCompilerResynthesizerBuilder {
8387
);
8488
context = RestrictedAnalysisContext(synchronousSession, _sourceFactory);
8589

86-
resynthesizer = StoreBasedSummaryResynthesizer(
87-
context,
88-
null,
89-
context.sourceFactory,
90-
/*strongMode*/ true,
91-
SummaryDataStore([])
92-
..addStore(_summaryData)
93-
..addBundle(null, bundle),
94-
);
95-
resynthesizer.finishCoreAsyncLibraries();
96-
context.typeProvider = resynthesizer.typeProvider;
90+
if (AnalysisDriver.useSummary2) {
91+
_createElementFactory(bundle);
92+
} else {
93+
resynthesizer = StoreBasedSummaryResynthesizer(
94+
context,
95+
null,
96+
context.sourceFactory,
97+
/*strongMode*/ true,
98+
SummaryDataStore([])
99+
..addStore(_summaryData)
100+
..addBundle(null, bundle),
101+
);
102+
resynthesizer.finishCoreAsyncLibraries();
103+
context.typeProvider = resynthesizer.typeProvider;
104+
}
97105
}
98106

99107
void _buildPackageBundleBytes() {
@@ -126,31 +134,62 @@ class DevCompilerResynthesizerBuilder {
126134
var inputLibraries = <summary2.LinkInputLibrary>[];
127135

128136
var sourceToUnit = _fileCrawler.sourceToUnit;
129-
for (var librarySource in sourceToUnit.keys) {
137+
for (var librarySource in _fileCrawler.librarySources) {
138+
var libraryUriStr = '${librarySource.uri}';
130139
var unit = sourceToUnit[librarySource];
131140

132-
if (_explicitSources.contains(librarySource.uri)) {
133-
var isPart = unit.directives.any((d) => d is PartOfDirective);
134-
if (isPart) {
135-
continue;
136-
}
137-
}
138-
139141
var inputUnits = <summary2.LinkInputUnit>[];
140142
inputUnits.add(
141143
summary2.LinkInputUnit(null, librarySource, false, unit),
142144
);
143145

146+
_informativeData.add(
147+
_UnitInformativeData(
148+
libraryUriStr,
149+
libraryUriStr,
150+
createInformativeData(unit),
151+
),
152+
);
153+
144154
for (var directive in unit.directives) {
145155
if (directive is PartDirective) {
146-
var partUri = directive.uri.stringValue;
147-
var partSource = _sourceFactory.resolveUri(librarySource, partUri);
148-
if (partSource != null) {
149-
var partUnit = sourceToUnit[partSource];
156+
var partRelativeUriStr = directive.uri.stringValue;
157+
var partSource = _sourceFactory.resolveUri(
158+
librarySource,
159+
partRelativeUriStr,
160+
);
161+
162+
// Add empty synthetic units for unresolved `part` URIs.
163+
if (partSource == null) {
150164
inputUnits.add(
151-
summary2.LinkInputUnit(partUri, partSource, false, partUnit),
165+
summary2.LinkInputUnit(
166+
partRelativeUriStr,
167+
null,
168+
true,
169+
_fsState.unresolvedFile.parse(),
170+
),
152171
);
172+
continue;
153173
}
174+
175+
var partUnit = sourceToUnit[partSource];
176+
inputUnits.add(
177+
summary2.LinkInputUnit(
178+
partRelativeUriStr,
179+
partSource,
180+
partSource == null,
181+
partUnit,
182+
),
183+
);
184+
185+
var unitUriStr = '${partSource.uri}';
186+
_informativeData.add(
187+
_UnitInformativeData(
188+
libraryUriStr,
189+
unitUriStr,
190+
createInformativeData(partUnit),
191+
),
192+
);
154193
}
155194
}
156195

@@ -179,6 +218,40 @@ class DevCompilerResynthesizerBuilder {
179218
var linkResult = summary2.link(elementFactory, inputLibraries);
180219
_assembler.setBundle2(linkResult.bundle);
181220
}
221+
222+
void _createElementFactory(PackageBundle newBundle) {
223+
elementFactory = summary2.LinkedElementFactory(
224+
context,
225+
null,
226+
summary2.Reference.root(),
227+
);
228+
for (var bundle in _summaryData.bundles) {
229+
elementFactory.addBundle(
230+
summary2.LinkedBundleContext(elementFactory, bundle.bundle2),
231+
);
232+
}
233+
elementFactory.addBundle(
234+
summary2.LinkedBundleContext(elementFactory, newBundle.bundle2),
235+
);
236+
237+
for (var unitData in _informativeData) {
238+
elementFactory.setInformativeData(
239+
unitData.libraryUriStr,
240+
unitData.unitUriStr,
241+
unitData.data,
242+
);
243+
}
244+
245+
var dartCore = elementFactory.libraryOfUri('dart:core');
246+
var dartAsync = elementFactory.libraryOfUri('dart:async');
247+
var typeProvider = SummaryTypeProvider()
248+
..initializeCore(dartCore)
249+
..initializeAsync(dartAsync);
250+
context.typeProvider = typeProvider;
251+
252+
dartCore.createLoadLibraryFunction(typeProvider);
253+
dartAsync.createLoadLibraryFunction(typeProvider);
254+
}
182255
}
183256

184257
class _SourceCrawler {
@@ -198,6 +271,7 @@ class _SourceCrawler {
198271
final Map<String, UnlinkedUnitBuilder> uriToUnlinkedUnit = {};
199272
final Map<Source, CompilationUnit> sourceToUnit = {};
200273
final List<String> libraryUris = [];
274+
final List<Source> librarySources = [];
201275

202276
_SourceCrawler(
203277
this._fsState,
@@ -230,7 +304,7 @@ class _SourceCrawler {
230304
var uriStr = uri.toString();
231305

232306
// Maybe an input package contains the source.
233-
if (_summaryData.unlinkedMap[uriStr] != null) {
307+
if (_summaryData.hasUnlinkedUnit(uriStr)) {
234308
return;
235309
}
236310

@@ -273,6 +347,15 @@ class _SourceCrawler {
273347
// Remember library URIs, for linking and compiling.
274348
if (!isPart) {
275349
libraryUris.add(uriStr);
350+
librarySources.add(source);
276351
}
277352
}
278353
}
354+
355+
class _UnitInformativeData {
356+
final String libraryUriStr;
357+
final String unitUriStr;
358+
final List<UnlinkedInformativeData> data;
359+
360+
_UnitInformativeData(this.libraryUriStr, this.unitUriStr, this.data);
361+
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ class FileState {
244244
*/
245245
bool get isExternalLibrary {
246246
return _fsState.externalSummaries != null &&
247-
_fsState.externalSummaries.linkedMap.containsKey(uriStr);
247+
_fsState.externalSummaries.hasLinkedLibrary(uriStr);
248248
}
249249

250250
/**
@@ -253,8 +253,8 @@ class FileState {
253253
*/
254254
bool get isPart {
255255
if (_fsState.externalSummaries != null &&
256-
_fsState.externalSummaries.unlinkedMap.containsKey(uriStr)) {
257-
return !_fsState.externalSummaries.linkedMap.containsKey(uriStr);
256+
_fsState.externalSummaries.hasUnlinkedUnit(uriStr)) {
257+
return _fsState.externalSummaries.isPartUnit(uriStr);
258258
}
259259
if (_unlinked2 != null) {
260260
return !_unlinked2.hasLibraryDirective && _unlinked2.hasPartOfDirective;

pkg/analyzer/lib/src/summary/package_bundle_reader.dart

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'dart:math' show min;
77

88
import 'package:analyzer/dart/analysis/session.dart';
99
import 'package:analyzer/file_system/file_system.dart';
10+
import 'package:analyzer/src/dart/analysis/driver.dart';
1011
import 'package:analyzer/src/generated/engine.dart';
1112
import 'package:analyzer/src/generated/source.dart';
1213
import 'package:analyzer/src/generated/source_io.dart';
@@ -130,10 +131,17 @@ class InSummaryUriResolver extends UriResolver {
130131
Source resolveAbsolute(Uri uri, [Uri actualUri]) {
131132
actualUri ??= uri;
132133
String uriString = uri.toString();
133-
UnlinkedUnit unit = _dataStore.unlinkedMap[uriString];
134-
if (unit != null) {
134+
if (AnalysisDriver.useSummary2) {
135135
String summaryPath = _dataStore.uriToSummaryPath[uriString];
136-
return new InSummarySource(actualUri, summaryPath);
136+
if (summaryPath != null) {
137+
return new InSummarySource(actualUri, summaryPath);
138+
}
139+
} else {
140+
UnlinkedUnit unit = _dataStore.unlinkedMap[uriString];
141+
if (unit != null) {
142+
String summaryPath = _dataStore.uriToSummaryPath[uriString];
143+
return new InSummarySource(actualUri, summaryPath);
144+
}
137145
}
138146
return null;
139147
}
@@ -193,10 +201,13 @@ class SummaryDataStore {
193201
final Map<String, LinkedLibrary> linkedMap = <String, LinkedLibrary>{};
194202

195203
/**
196-
* Map from the URI of a library to the summary path that contained it.
204+
* Map from the URI of a unit to the summary path that contained it.
197205
*/
198206
final Map<String, String> uriToSummaryPath = <String, String>{};
199207

208+
final Set<String> _libraryUris = Set<String>();
209+
final Set<String> _partUris = Set<String>();
210+
200211
/**
201212
* List of summary paths.
202213
*/
@@ -224,6 +235,7 @@ class SummaryDataStore {
224235
*/
225236
void addBundle(String path, PackageBundle bundle) {
226237
bundles.add(bundle);
238+
227239
for (int i = 0; i < bundle.unlinkedUnitUris.length; i++) {
228240
String uri = bundle.unlinkedUnitUris[i];
229241
if (_disallowOverlappingSummaries &&
@@ -239,6 +251,20 @@ class SummaryDataStore {
239251
String uri = bundle.linkedLibraryUris[i];
240252
addLinkedLibrary(uri, bundle.linkedLibraries[i]);
241253
}
254+
255+
if (bundle.bundle2 != null) {
256+
for (var library in bundle.bundle2.libraries) {
257+
var libraryUri = library.uriStr;
258+
_libraryUris.add(libraryUri);
259+
for (var unit in library.units) {
260+
var unitUri = unit.uriStr;
261+
uriToSummaryPath[unitUri] = path;
262+
if (unitUri != libraryUri) {
263+
_partUris.add(unitUri);
264+
}
265+
}
266+
}
267+
}
242268
}
243269

244270
/**
@@ -293,15 +319,34 @@ class SummaryDataStore {
293319
* with the given absolute [uri].
294320
*/
295321
bool hasLinkedLibrary(String uri) {
296-
return linkedMap.containsKey(uri);
322+
if (AnalysisDriver.useSummary2) {
323+
return _libraryUris.contains(uri);
324+
} else {
325+
return linkedMap.containsKey(uri);
326+
}
297327
}
298328

299329
/**
300330
* Return `true` if the store contains the unlinked summary for the unit
301331
* with the given absolute [uri].
302332
*/
303333
bool hasUnlinkedUnit(String uri) {
304-
return unlinkedMap.containsKey(uri);
334+
if (AnalysisDriver.useSummary2) {
335+
return uriToSummaryPath.containsKey(uri);
336+
} else {
337+
return unlinkedMap.containsKey(uri);
338+
}
339+
}
340+
341+
/**
342+
* Return `true` if the unit with the [uri] is a part unit in the store.
343+
*/
344+
bool isPartUnit(String uri) {
345+
if (AnalysisDriver.useSummary2) {
346+
return _partUris.contains(uri);
347+
} else {
348+
return !linkedMap.containsKey(uri);
349+
}
305350
}
306351

307352
void _fillMaps(String path, ResourceProvider resourceProvider) {

pkg/analyzer/test/src/summary/package_bundle_reader_test.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ class _PackageBundleMock implements PackageBundle {
186186
@override
187187
List<String> unlinkedUnitUris;
188188

189+
@override
190+
LinkedNodeBundle bundle2;
191+
189192
@override
190193
noSuchMethod(Invocation invocation) {
191194
throw new StateError('Unexpected invocation of ${invocation.memberName}');

0 commit comments

Comments
 (0)