Add test for unordered indexing in serialization.

This test catches an issue previously uncaught by tests where offsets for indices were written incorrectly and could therefore lead to errors when deserializingelements in deferred mode.

Change-Id: I14bf80bbe4fa47c12e543679803c7be38582a0e5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/252300
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
This commit is contained in:
Nate Biggs 2022-07-21 03:59:25 +00:00 committed by Commit Bot
parent 2c891cda56
commit 8b3e9a84e7
3 changed files with 63 additions and 7 deletions

View file

@ -0,0 +1,19 @@
// @dart=2.7
// @doCodegen
// Introduce a named parameter with a given string name.
typedef Bar = String Function({String someString});
class Foo {
Bar _bar;
Foo(this._bar);
}
void main() {
// Create a String constant that matches the name of the above named param.
print("someString");
// Include an expression whose static type involves the named param above. But
// importantly do not create an instance of the type.
final x = Foo(null)._bar;
}

View file

@ -64,6 +64,7 @@ Future checkTests(Directory dataDir,
Uri.parse('memory:$commonTestPath/dart2js_native/main.dart'); Uri.parse('memory:$commonTestPath/dart2js_native/main.dart');
String mainCode = await new File.fromUri(entity.uri).readAsString(); String mainCode = await new File.fromUri(entity.uri).readAsString();
Map<String, String> memorySourceFiles = {entryPoint.path: mainCode}; Map<String, String> memorySourceFiles = {entryPoint.path: mainCode};
final doCodegen = mainCode.contains('@doCodegen');
if (libDirectory != null) { if (libDirectory != null) {
print('Supporting libraries:'); print('Supporting libraries:');
@ -84,7 +85,8 @@ Future checkTests(Directory dataDir,
entryPoint: entryPoint, entryPoint: entryPoint,
memorySourceFiles: memorySourceFiles, memorySourceFiles: memorySourceFiles,
options: testOptions, options: testOptions,
strategy: strategy); strategy: strategy,
doCodegen: doCodegen);
} }
Expect.isFalse(hasFailures, 'Errors found.'); Expect.isFalse(hasFailures, 'Errors found.');
Expect.isTrue(testCount > 0, "No files were tested."); Expect.isTrue(testCount > 0, "No files were tested.");

View file

@ -107,7 +107,8 @@ runTest(
Uri librariesSpecificationUri, Uri librariesSpecificationUri,
List<String> options, List<String> options,
SerializationStrategy strategy: const BytesInMemorySerializationStrategy(), SerializationStrategy strategy: const BytesInMemorySerializationStrategy(),
bool useDataKinds: false}) async { bool useDataKinds: false,
bool doCodegen: false}) async {
var commonOptions = options + ['--out=out.js']; var commonOptions = options + ['--out=out.js'];
OutputCollector collector = new OutputCollector(); OutputCollector collector = new OutputCollector();
CompilationResult result = await runCompiler( CompilationResult result = await runCompiler(
@ -157,10 +158,11 @@ runTest(
Directory dir = Directory dir =
await Directory.systemTemp.createTemp('serialization_test_helper'); await Directory.systemTemp.createTemp('serialization_test_helper');
var dillFileUri = dir.uri.resolve('out.dill'); final dillFileUri = dir.uri.resolve('out.dill');
var closedWorldFileUri = dir.uri.resolve('world.data'); final closedWorldFileUri = dir.uri.resolve('world.data');
var dillBytes = collector3a.binaryOutputMap[dillUri].list; final globalDataUri = Uri.parse('global.data');
var closedWorldBytes = collector3a.binaryOutputMap[closedWorldUri].list; final dillBytes = collector3a.binaryOutputMap[dillUri].list;
final closedWorldBytes = collector3a.binaryOutputMap[closedWorldUri].list;
File(dillFileUri.path).writeAsBytesSync(dillBytes); File(dillFileUri.path).writeAsBytesSync(dillBytes);
File(closedWorldFileUri.path).writeAsBytesSync(closedWorldBytes); File(closedWorldFileUri.path).writeAsBytesSync(closedWorldBytes);
OutputCollector collector3b = new OutputCollector(); OutputCollector collector3b = new OutputCollector();
@ -173,7 +175,7 @@ runTest(
[ [
'${Flags.inputDill}=$dillFileUri', '${Flags.inputDill}=$dillFileUri',
'${Flags.readClosedWorld}=$closedWorldFileUri', '${Flags.readClosedWorld}=$closedWorldFileUri',
'${Flags.writeData}=global.data' '${Flags.writeData}=$globalDataUri'
], ],
outputProvider: collector3b, outputProvider: collector3b,
beforeRun: (Compiler compiler) { beforeRun: (Compiler compiler) {
@ -182,12 +184,45 @@ runTest(
}); });
Expect.isTrue(result3b.isSuccess); Expect.isTrue(result3b.isSuccess);
final globalDataFileUri = dir.uri.resolve('global.data');
// We must write the global data bytes before calling
// `finishCompileAndCompare` below as that clears the collector.
if (doCodegen) {
Expect.isTrue(collector3b.binaryOutputMap.containsKey(globalDataUri));
final globalDataBytes = collector3b.binaryOutputMap[globalDataUri].list;
File(globalDataFileUri.path).writeAsBytesSync(globalDataBytes);
}
await finishCompileAndCompare( await finishCompileAndCompare(
expectedOutput, collector2, result2.compiler, strategy, expectedOutput, collector2, result2.compiler, strategy,
stoppedAfterClosedWorld: true); stoppedAfterClosedWorld: true);
await finishCompileAndCompare( await finishCompileAndCompare(
expectedOutput, collector3b, result3b.compiler, strategy, expectedOutput, collector3b, result3b.compiler, strategy,
stoppedAfterTypeInference: true); stoppedAfterTypeInference: true);
if (doCodegen) {
OutputCollector collector4 = new OutputCollector();
CompilationResult result4 = await runCompiler(
entryPoint: entryPoint,
memorySourceFiles: memorySourceFiles,
packageConfig: packageConfig,
librariesSpecificationUri: librariesSpecificationUri,
options: commonOptions +
[
'${Flags.inputDill}=$dillFileUri',
'${Flags.readClosedWorld}=$closedWorldFileUri',
'${Flags.readData}=$globalDataFileUri',
'--out=out.js'
],
outputProvider: collector4,
beforeRun: (Compiler compiler) {
compiler.forceSerializationForTesting = true;
});
Expect.isTrue(result4.isSuccess);
}
await dir.delete(recursive: true); await dir.delete(recursive: true);
} }