Skip to content

Commit fa303eb

Browse files
scheglovcommit-bot@chromium.org
authored andcommitted
Keep libraries after linking, don't reload from bytes.
Presubmit in google3 looks green. https://test.corp.google.com/ui#id=OCL:376412203:BASE:379875911:1623903883365:2a59d852 Change-Id: I344d49fa12e2f07aa00623ea08e7530872ca2eec Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/201661 Reviewed-by: Samuel Rawlins <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent d2e4606 commit fa303eb

File tree

4 files changed

+46
-36
lines changed

4 files changed

+46
-36
lines changed

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

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -183,21 +183,18 @@ class LibraryContext {
183183
counterUnlinkedLinkedBytes += resolutionBytes.length;
184184

185185
librariesLinkedTimer.stop();
186-
// TODO(scheglov) Uncomment to keep linking elements.
187-
// return;
188186
} else {
189187
// TODO(scheglov) Take / clear parsed units in files.
190188
bytesGet += resolutionBytes.length;
191189
librariesLoaded += cycle.libraries.length;
190+
elementFactory.addBundle(
191+
BundleReader(
192+
elementFactory: elementFactory,
193+
unitsInformativeBytes: unitsInformativeBytes,
194+
resolutionBytes: resolutionBytes,
195+
),
196+
);
192197
}
193-
194-
elementFactory.addBundle(
195-
BundleReader(
196-
elementFactory: elementFactory,
197-
unitsInformativeBytes: unitsInformativeBytes,
198-
resolutionBytes: resolutionBytes,
199-
),
200-
);
201198
}
202199

203200
logger.run('Prepare linked bundles', () {

pkg/analyzer/lib/src/dart/micro/resolve_file.dart

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -908,17 +908,16 @@ class _LibraryContext {
908908
} else {
909909
performance.getDataInt('bytesGet').add(resolutionBytes.length);
910910
performance.getDataInt('libraryLoadCount').add(cycle.libraries.length);
911+
elementFactory.addBundle(
912+
BundleReader(
913+
elementFactory: elementFactory,
914+
unitsInformativeBytes: unitsInformativeBytes,
915+
resolutionBytes: resolutionBytes as Uint8List,
916+
),
917+
);
911918
}
912919
cycle.resolutionId = resolutionData!.id;
913920

914-
elementFactory.addBundle(
915-
BundleReader(
916-
elementFactory: elementFactory,
917-
unitsInformativeBytes: unitsInformativeBytes,
918-
resolutionBytes: resolutionBytes as Uint8List,
919-
),
920-
);
921-
922921
// We might have just linked dart:core, ensure the type provider.
923922
_createElementFactoryTypeProvider();
924923
}

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import 'package:analyzer/src/summary2/types_builder.dart';
2424
import 'package:analyzer/src/summary2/variance_builder.dart';
2525

2626
var timerLinkingLinkingBundle = Stopwatch();
27-
var timerLinkingRemoveBundle = Stopwatch();
2827

2928
/// Note that AST units and tokens of [inputLibraries] will be damaged.
3029
///
@@ -81,13 +80,6 @@ class Linker {
8180
timerLinkingLinkingBundle.start();
8281
_writeLibraries();
8382
timerLinkingLinkingBundle.stop();
84-
85-
// TODO(scheglov) Remove to keep linking elements.
86-
timerLinkingRemoveBundle.start();
87-
elementFactory.removeBundle(
88-
inputLibraries.map((e) => e.uriStr).toSet(),
89-
);
90-
timerLinkingRemoveBundle.stop();
9183
}
9284

9385
void _buildEnumChildren() {

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

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ import 'test_strategies.dart';
2626

2727
main() {
2828
defineReflectiveSuite(() {
29-
defineReflectiveTests(ResynthesizeAst2Test);
29+
defineReflectiveTests(ResynthesizeAstKeepLinkingTest);
30+
defineReflectiveTests(ResynthesizeAstFromBytesTest);
3031
// defineReflectiveTests(ApplyCheckElementTextReplacements);
3132
});
3233
}
@@ -39,11 +40,16 @@ class ApplyCheckElementTextReplacements {
3940
}
4041

4142
@reflectiveTest
42-
class ResynthesizeAst2Test extends AbstractResynthesizeTest
43+
abstract class ResynthesizeAst2Test extends AbstractResynthesizeTest
4344
with ResynthesizeTestCases {
4445
/// The shared SDK bundle, computed once and shared among test invocations.
4546
static _SdkBundle? _sdkBundle;
4647

48+
/// We need to test both cases - when we keep linking libraries (happens for
49+
/// new or invalidated libraries), and when we load libraries from bytes
50+
/// (happens internally in Blaze or when we have cached summaries).
51+
bool get keepLinkingLibraries;
52+
4753
_SdkBundle get sdkBundle {
4854
if (_sdkBundle != null) {
4955
return _sdkBundle!;
@@ -124,14 +130,18 @@ class ResynthesizeAst2Test extends AbstractResynthesizeTest
124130

125131
var linkResult = link(elementFactory, inputLibraries, true);
126132

127-
// TODO(scheglov) Remove to keep linking elements.
128-
elementFactory.addBundle(
129-
BundleReader(
130-
elementFactory: elementFactory,
131-
unitsInformativeBytes: unitsInformativeBytes,
132-
resolutionBytes: linkResult.resolutionBytes,
133-
),
134-
);
133+
if (!keepLinkingLibraries) {
134+
elementFactory.removeBundle(
135+
inputLibraries.map((e) => e.uriStr).toSet(),
136+
);
137+
elementFactory.addBundle(
138+
BundleReader(
139+
elementFactory: elementFactory,
140+
unitsInformativeBytes: unitsInformativeBytes,
141+
resolutionBytes: linkResult.resolutionBytes,
142+
),
143+
);
144+
}
135145

136146
return elementFactory.libraryOfUri('${source.uri}')!;
137147
}
@@ -232,6 +242,18 @@ class ResynthesizeAst2Test extends AbstractResynthesizeTest
232242
}
233243
}
234244

245+
@reflectiveTest
246+
class ResynthesizeAstFromBytesTest extends ResynthesizeAst2Test {
247+
@override
248+
bool get keepLinkingLibraries => false;
249+
}
250+
251+
@reflectiveTest
252+
class ResynthesizeAstKeepLinkingTest extends ResynthesizeAst2Test {
253+
@override
254+
bool get keepLinkingLibraries => true;
255+
}
256+
235257
class _AnalysisSessionForLinking implements AnalysisSessionImpl {
236258
@override
237259
final ClassHierarchy classHierarchy = ClassHierarchy();

0 commit comments

Comments
 (0)