Revert "Revert "Keep libraries after linking, don't reload from bytes.""

This reverts commit b3a688a9c6.

Initial: https://dart-review.googlesource.com/c/sdk/+/201661
Reverted: https://dart-review.googlesource.com/c/sdk/+/204263
Change-Id: I9505962caf6ce0244ae68c3d97e6f6629f95fadc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/205142
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
Konstantin Shcheglov
2021-06-29 18:00:48 +00:00
committed by commit-bot@chromium.org
parent 1415c2195d
commit 8a8ebe34bc
4 changed files with 46 additions and 36 deletions
@@ -183,21 +183,18 @@ class LibraryContext {
counterUnlinkedLinkedBytes += resolutionBytes.length;
librariesLinkedTimer.stop();
// TODO(scheglov) Uncomment to keep linking elements.
// return;
} else {
// TODO(scheglov) Take / clear parsed units in files.
bytesGet += resolutionBytes.length;
librariesLoaded += cycle.libraries.length;
elementFactory.addBundle(
BundleReader(
elementFactory: elementFactory,
unitsInformativeBytes: unitsInformativeBytes,
resolutionBytes: resolutionBytes,
),
);
}
elementFactory.addBundle(
BundleReader(
elementFactory: elementFactory,
unitsInformativeBytes: unitsInformativeBytes,
resolutionBytes: resolutionBytes,
),
);
}
logger.run('Prepare linked bundles', () {
@@ -908,17 +908,16 @@ class _LibraryContext {
} else {
performance.getDataInt('bytesGet').add(resolutionBytes.length);
performance.getDataInt('libraryLoadCount').add(cycle.libraries.length);
elementFactory.addBundle(
BundleReader(
elementFactory: elementFactory,
unitsInformativeBytes: unitsInformativeBytes,
resolutionBytes: resolutionBytes as Uint8List,
),
);
}
cycle.resolutionId = resolutionData!.id;
elementFactory.addBundle(
BundleReader(
elementFactory: elementFactory,
unitsInformativeBytes: unitsInformativeBytes,
resolutionBytes: resolutionBytes as Uint8List,
),
);
// We might have just linked dart:core, ensure the type provider.
_createElementFactoryTypeProvider();
}
-8
View File
@@ -24,7 +24,6 @@ import 'package:analyzer/src/summary2/types_builder.dart';
import 'package:analyzer/src/summary2/variance_builder.dart';
var timerLinkingLinkingBundle = Stopwatch();
var timerLinkingRemoveBundle = Stopwatch();
/// Note that AST units and tokens of [inputLibraries] will be damaged.
///
@@ -81,13 +80,6 @@ class Linker {
timerLinkingLinkingBundle.start();
_writeLibraries();
timerLinkingLinkingBundle.stop();
// TODO(scheglov) Remove to keep linking elements.
timerLinkingRemoveBundle.start();
elementFactory.removeBundle(
inputLibraries.map((e) => e.uriStr).toSet(),
);
timerLinkingRemoveBundle.stop();
}
void _buildEnumChildren() {
@@ -26,7 +26,8 @@ import 'test_strategies.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(ResynthesizeAst2Test);
defineReflectiveTests(ResynthesizeAstKeepLinkingTest);
defineReflectiveTests(ResynthesizeAstFromBytesTest);
// defineReflectiveTests(ApplyCheckElementTextReplacements);
});
}
@@ -39,11 +40,16 @@ class ApplyCheckElementTextReplacements {
}
@reflectiveTest
class ResynthesizeAst2Test extends AbstractResynthesizeTest
abstract class ResynthesizeAst2Test extends AbstractResynthesizeTest
with ResynthesizeTestCases {
/// The shared SDK bundle, computed once and shared among test invocations.
static _SdkBundle? _sdkBundle;
/// We need to test both cases - when we keep linking libraries (happens for
/// new or invalidated libraries), and when we load libraries from bytes
/// (happens internally in Blaze or when we have cached summaries).
bool get keepLinkingLibraries;
_SdkBundle get sdkBundle {
if (_sdkBundle != null) {
return _sdkBundle!;
@@ -124,14 +130,18 @@ class ResynthesizeAst2Test extends AbstractResynthesizeTest
var linkResult = link(elementFactory, inputLibraries, true);
// TODO(scheglov) Remove to keep linking elements.
elementFactory.addBundle(
BundleReader(
elementFactory: elementFactory,
unitsInformativeBytes: unitsInformativeBytes,
resolutionBytes: linkResult.resolutionBytes,
),
);
if (!keepLinkingLibraries) {
elementFactory.removeBundle(
inputLibraries.map((e) => e.uriStr).toSet(),
);
elementFactory.addBundle(
BundleReader(
elementFactory: elementFactory,
unitsInformativeBytes: unitsInformativeBytes,
resolutionBytes: linkResult.resolutionBytes,
),
);
}
return elementFactory.libraryOfUri('${source.uri}')!;
}
@@ -232,6 +242,18 @@ class ResynthesizeAst2Test extends AbstractResynthesizeTest
}
}
@reflectiveTest
class ResynthesizeAstFromBytesTest extends ResynthesizeAst2Test {
@override
bool get keepLinkingLibraries => false;
}
@reflectiveTest
class ResynthesizeAstKeepLinkingTest extends ResynthesizeAst2Test {
@override
bool get keepLinkingLibraries => true;
}
class _AnalysisSessionForLinking implements AnalysisSessionImpl {
@override
final ClassHierarchy classHierarchy = ClassHierarchy();