8c13fa841e
Simple calls to `List.generate` are expanded into a list allocation and a loop. This generates better code for several reasons: - There is no overhead for the function argument (closure allocation, closure type, closure class) - Global type inference is more precise since each List.generate list is tracked separately, and the assignments in the loop give better inference to the collection's element type. To get precise element type inference, there are two new JSArray constructors. Global type inference starts with the element type being bottom for these elements, avoiding spurious nulls in the inferred type. Change-Id: I5efb90651ae3f9eb2e81af556704960cdf0b75c5 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/168770 Commit-Queue: Stephen Adams <sra@google.com> Reviewed-by: Johnni Winther <johnniwinther@google.com>
47 lines
1.6 KiB
Dart
47 lines
1.6 KiB
Dart
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
import 'dart:io';
|
|
|
|
import 'package:kernel/target/targets.dart';
|
|
import 'package:kernel/ast.dart';
|
|
import 'package:kernel/kernel.dart';
|
|
import 'package:test/test.dart';
|
|
|
|
import 'common_test_utils.dart';
|
|
|
|
final String testRootDir = Platform.script.resolve('.').toFilePath();
|
|
|
|
runTestCase(
|
|
Uri source, List<String> experimentalFlags, bool enableNullSafety) async {
|
|
final target =
|
|
TestingDart2jsTarget(TargetFlags(enableNullSafety: enableNullSafety));
|
|
Component component = await compileTestCaseToKernelProgram(source,
|
|
target: target, experimentalFlags: experimentalFlags);
|
|
|
|
String actual = kernelLibraryToString(component.mainMethod.enclosingLibrary);
|
|
|
|
compareResultWithExpectationsFile(source, actual);
|
|
}
|
|
|
|
main() {
|
|
group('goldens', () {
|
|
final testCasesDir = new Directory(testRootDir + '/data');
|
|
|
|
for (var entry
|
|
in testCasesDir.listSync(recursive: true, followLinks: false)) {
|
|
final path = entry.path;
|
|
if (path.endsWith('.dart')) {
|
|
final bool enableNullSafety = path.endsWith('_nnbd_strong.dart');
|
|
final bool enableNNBD = enableNullSafety || path.endsWith('_nnbd.dart');
|
|
final List<String> experimentalFlags = [
|
|
if (enableNNBD) 'non-nullable',
|
|
];
|
|
test(path,
|
|
() => runTestCase(entry.uri, experimentalFlags, enableNullSafety));
|
|
}
|
|
}
|
|
}, timeout: Timeout.none);
|
|
}
|