Skip to content

Commit 7974f3f

Browse files
nshahancommit-bot@chromium.org
authored andcommitted
[dartdevc] Reduce the number of SDK libraries in the platform
We are temporarily building a smaller SDK platform to make progress building applications against the forked sdk_nnbd sources. This is because some of the libraries have not yet been ported and they don't compose well. I needed to thread the status of the non-nullable experiment through the front end entry point and into the target options, and native types. Also includes some standardization of the flag name in DDC. #39698 Change-Id: I4bdd503be694b28d7f95828d4af28d1d5fb3691f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/127486 Commit-Queue: Nicholas Shahan <nshahan@google.com> Reviewed-by: Sigmund Cherem <sigmund@google.com> Reviewed-by: Johnni Winther <johnniwinther@google.com>
1 parent b296d55 commit 7974f3f

File tree

9 files changed

+111
-91
lines changed

9 files changed

+111
-91
lines changed

pkg/dev_compiler/lib/src/analyzer/code_generator.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@ class CodeGenerator extends Object
905905
// * There isn't an obvious place in dart:_runtime were we could place a
906906
// method that adds these type tests (similar to addTypeTests()) because
907907
// in the bootstrap ordering the Future class hasn't been defined yet.
908-
if (options.nonNullableEnabled) {
908+
if (options.enableNullSafety) {
909909
// TODO(nshahan) Update FutureOr type tests for NNBD.
910910
var typeParamT =
911911
getLegacyTypeParameterType(classElem.typeParameters[0]);

pkg/dev_compiler/lib/src/compiler/shared_command.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ class SharedCompilerOptions {
196196
}
197197

198198
// TODO(nshahan) Cleanup when NNBD graduates experimental status.
199-
bool get nonNullableEnabled => experiments['non-nullable'] ?? false;
199+
bool get enableNullSafety => experiments['non-nullable'] ?? false;
200200
}
201201

202202
/// Finds explicit module names of the form `path=name` in [summaryPaths],

pkg/dev_compiler/lib/src/kernel/command.dart

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,9 @@ Future<CompilerResult> _compile(List<String> args,
266266
sourcePathToUri(packageFile),
267267
sourcePathToUri(librarySpecPath),
268268
inputSummaries,
269-
DevCompilerTarget(
270-
TargetFlags(trackWidgetCreation: trackWidgetCreation)),
269+
DevCompilerTarget(TargetFlags(
270+
trackWidgetCreation: trackWidgetCreation,
271+
enableNullSafety: options.enableNullSafety)),
271272
fileSystem: fileSystem,
272273
experiments: experiments,
273274
environmentDefines: declaredVariables);
@@ -302,8 +303,9 @@ Future<CompilerResult> _compile(List<String> args,
302303
sourcePathToUri(librarySpecPath),
303304
inputSummaries,
304305
inputDigests,
305-
DevCompilerTarget(
306-
TargetFlags(trackWidgetCreation: trackWidgetCreation)),
306+
DevCompilerTarget(TargetFlags(
307+
trackWidgetCreation: trackWidgetCreation,
308+
enableNullSafety: options.enableNullSafety)),
307309
fileSystem: fileSystem,
308310
experiments: experiments,
309311
environmentDefines: declaredVariables,

pkg/dev_compiler/lib/src/kernel/compiler.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,8 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
222222
coreTypes ??= CoreTypes(component);
223223
var types = TypeEnvironment(coreTypes, hierarchy);
224224
var constants = DevCompilerConstants();
225-
var nativeTypes = NativeTypeSet(coreTypes, constants);
225+
var nativeTypes = NativeTypeSet(coreTypes, constants,
226+
enableNullSafety: options.enableNullSafety);
226227
var jsTypeRep = JSTypeRep(types, hierarchy);
227228
var staticTypeContext = StatefulStaticTypeContext.stacked(types);
228229
return ProgramCompiler._(
@@ -1003,7 +1004,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
10031004
// * There isn't an obvious place in dart:_runtime were we could place a
10041005
// method that adds these type tests (similar to addTypeTests()) because
10051006
// in the bootstrap ordering the Future class hasn't been defined yet.
1006-
if (_options.nonNullableEnabled) {
1007+
if (_options.enableNullSafety) {
10071008
// TODO(nshahan) Update FutureOr type tests for NNBD
10081009
var typeParam =
10091010
TypeParameterType(c.typeParameters[0], Nullability.legacy);

pkg/dev_compiler/lib/src/kernel/native_types.dart

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ class NativeTypeSet {
3737
final _nativeTypes = HashSet<Class>.identity();
3838
final _pendingLibraries = HashSet<Library>.identity();
3939

40-
NativeTypeSet(this.coreTypes, this.constants) {
40+
NativeTypeSet(this.coreTypes, this.constants,
41+
{bool enableNullSafety = false}) {
4142
// First, core types:
4243
// TODO(vsm): If we're analyzing against the main SDK, those
4344
// types are not explicitly annotated.
@@ -61,12 +62,16 @@ class NativeTypeSet {
6162
// listed below).
6263

6364
// Second, html types - these are only searched if we use dart:html, etc.:
64-
_addPendingExtensionTypes(sdk.getLibrary('dart:html'));
65-
_addPendingExtensionTypes(sdk.getLibrary('dart:indexed_db'));
66-
_addPendingExtensionTypes(sdk.getLibrary('dart:svg'));
67-
_addPendingExtensionTypes(sdk.getLibrary('dart:web_audio'));
68-
_addPendingExtensionTypes(sdk.getLibrary('dart:web_gl'));
69-
_addPendingExtensionTypes(sdk.getLibrary('dart:web_sql'));
65+
// TODO(39698) Remove this check and the named parameter once we don't have
66+
// to exclude libraries from the forked NNBD sdk.
67+
if (!enableNullSafety) {
68+
_addPendingExtensionTypes(sdk.getLibrary('dart:html'));
69+
_addPendingExtensionTypes(sdk.getLibrary('dart:indexed_db'));
70+
_addPendingExtensionTypes(sdk.getLibrary('dart:svg'));
71+
_addPendingExtensionTypes(sdk.getLibrary('dart:web_audio'));
72+
_addPendingExtensionTypes(sdk.getLibrary('dart:web_gl'));
73+
_addPendingExtensionTypes(sdk.getLibrary('dart:web_sql'));
74+
}
7075
}
7176

7277
void _addExtensionType(Class c, [bool mustBeNative = false]) {

pkg/dev_compiler/lib/src/kernel/target.dart

Lines changed: 58 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,62 @@ import 'kernel_helpers.dart';
1414

1515
/// A kernel [Target] to configure the Dart Front End for dartdevc.
1616
class DevCompilerTarget extends Target {
17-
DevCompilerTarget(this.flags);
17+
// TODO(39698) Turn these back into const lists returned from the getters
18+
// once we don't have to exclude libraries from the forked NNBD sdk.
19+
List<String> _extraRequiredLibraries;
20+
List<String> _extraIndexedLibraries;
21+
22+
DevCompilerTarget(this.flags)
23+
: _extraRequiredLibraries = [
24+
'dart:_runtime',
25+
'dart:_debugger',
26+
'dart:_foreign_helper',
27+
'dart:_interceptors',
28+
'dart:_internal',
29+
'dart:_isolate_helper',
30+
'dart:_js_helper',
31+
'dart:_js_mirrors',
32+
'dart:_js_primitives',
33+
'dart:_metadata',
34+
'dart:_native_typed_data',
35+
'dart:async',
36+
'dart:collection',
37+
'dart:convert',
38+
if (!flags.enableNullSafety) ...[
39+
'dart:developer',
40+
'dart:io',
41+
'dart:isolate'
42+
],
43+
'dart:js',
44+
'dart:js_util',
45+
'dart:math',
46+
'dart:mirrors',
47+
'dart:typed_data',
48+
if (!flags.enableNullSafety) ...[
49+
'dart:indexed_db',
50+
'dart:html',
51+
'dart:html_common',
52+
'dart:svg',
53+
'dart:web_audio',
54+
'dart:web_gl',
55+
'dart:web_sql'
56+
]
57+
],
58+
_extraIndexedLibraries = [
59+
'dart:async',
60+
'dart:collection',
61+
if (!flags.enableNullSafety) ...['dart:html', 'dart:indexed_db'],
62+
'dart:math',
63+
if (!flags.enableNullSafety) ...[
64+
'dart:svg',
65+
'dart:web_audio',
66+
'dart:web_gl',
67+
'dart:web_sql'
68+
],
69+
'dart:_interceptors',
70+
'dart:_js_helper',
71+
'dart:_native_typed_data',
72+
];
1873

1974
final TargetFlags flags;
2075

@@ -30,54 +85,11 @@ class DevCompilerTarget extends Target {
3085
String get name => 'dartdevc';
3186

3287
@override
33-
List<String> get extraRequiredLibraries => const [
34-
'dart:_runtime',
35-
'dart:_debugger',
36-
'dart:_foreign_helper',
37-
'dart:_interceptors',
38-
'dart:_internal',
39-
'dart:_isolate_helper',
40-
'dart:_js_helper',
41-
'dart:_js_mirrors',
42-
'dart:_js_primitives',
43-
'dart:_metadata',
44-
'dart:_native_typed_data',
45-
'dart:async',
46-
'dart:collection',
47-
'dart:convert',
48-
'dart:developer',
49-
'dart:io',
50-
'dart:isolate',
51-
'dart:js',
52-
'dart:js_util',
53-
'dart:math',
54-
'dart:mirrors',
55-
'dart:typed_data',
56-
'dart:indexed_db',
57-
'dart:html',
58-
'dart:html_common',
59-
'dart:svg',
60-
'dart:web_audio',
61-
'dart:web_gl',
62-
'dart:web_sql'
63-
];
88+
List<String> get extraRequiredLibraries => _extraRequiredLibraries;
6489

6590
// The libraries required to be indexed via CoreTypes.
6691
@override
67-
List<String> get extraIndexedLibraries => const [
68-
'dart:async',
69-
'dart:collection',
70-
'dart:html',
71-
'dart:indexed_db',
72-
'dart:math',
73-
'dart:svg',
74-
'dart:web_audio',
75-
'dart:web_gl',
76-
'dart:web_sql',
77-
'dart:_interceptors',
78-
'dart:_js_helper',
79-
'dart:_native_typed_data',
80-
];
92+
List<String> get extraIndexedLibraries => _extraIndexedLibraries;
8193

8294
@override
8395
bool mayDefineRestrictedType(Uri uri) =>

pkg/front_end/tool/_fasta/command_line.dart

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,16 @@ ProcessedOptions analyzeCommandLine(
305305

306306
final String targetName = options["--target"] ?? "vm";
307307

308+
Map<ExperimentalFlag, bool> experimentalFlags = parseExperimentalFlags(
309+
parseExperimentalArguments(options["--enable-experiment"]),
310+
onError: throwCommandLineProblem,
311+
onWarning: print);
312+
308313
final TargetFlags flags = new TargetFlags(
309-
forceLateLoweringForTesting: options["--force-late-lowering"]);
314+
forceLateLoweringForTesting: options["--force-late-lowering"],
315+
enableNullSafety:
316+
experimentalFlags.containsKey(ExperimentalFlag.nonNullable) &&
317+
experimentalFlags[ExperimentalFlag.nonNullable]);
310318

311319
final Target target = getTarget(targetName, flags);
312320
if (target == null) {
@@ -356,11 +364,6 @@ ProcessedOptions analyzeCommandLine(
356364
});
357365
}
358366

359-
Map<ExperimentalFlag, bool> experimentalFlags = parseExperimentalFlags(
360-
parseExperimentalArguments(options["--enable-experiment"]),
361-
onError: throwCommandLineProblem,
362-
onWarning: print);
363-
364367
if (programName == "compile_platform") {
365368
if (arguments.length != 5) {
366369
return throw new CommandLineProblem.deprecated(

pkg/kernel/lib/target/targets.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ final List<String> targetNames = targets.keys.toList();
1212
class TargetFlags {
1313
final bool trackWidgetCreation;
1414
final bool forceLateLoweringForTesting;
15+
final bool enableNullSafety;
1516

1617
TargetFlags(
1718
{this.trackWidgetCreation = false,
18-
this.forceLateLoweringForTesting = false});
19+
this.forceLateLoweringForTesting = false,
20+
this.enableNullSafety = false});
1921
}
2022

2123
typedef Target _TargetBuilder(TargetFlags flags);

utils/dartdevc/BUILD.gn

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -210,15 +210,25 @@ create_timestamp_file("dartdevc_sdk_patch_stamp") {
210210
group("dartdevc_test_kernel_pkg") {
211211
deps = [
212212
":async_helper_js",
213-
":collection_js",
214213
":expect_js",
215214
":js_js",
216-
":matcher_js",
217215
":meta_js",
218-
":path_js",
219-
":stack_trace_js",
220-
":unittest_js",
221216
]
217+
218+
# TODO(38701): Cleanup after merging the forked SDK into mainline.
219+
if (!use_nnbd) {
220+
# TODO(sigmund): Merge this list into above. We turned this off temporarily
221+
# while the migration of libraries is in flux, this step otherwise fails
222+
# with many nnbd-related compile-time errors because the packages are
223+
# assumed to be nnbd compilant.
224+
deps += [
225+
":collection_js",
226+
":matcher_js",
227+
":path_js",
228+
":stack_trace_js",
229+
":unittest_js",
230+
]
231+
}
222232
}
223233

224234
template("dartdevc_kernel_compile") {
@@ -232,10 +242,6 @@ template("dartdevc_kernel_compile") {
232242
# * package_dependencies: the name of other packages this package depends
233243
# on. When providing `name`, a separate `dartdevc_kernel_compile` target
234244
# named `${name}_js` must exist.
235-
# * nnbd_disabled: whether to disable the non-nullable experiment under the
236-
# NNBD build. This is used temporariy until we either migrate the packages
237-
# or add support to read the language version information from the package
238-
# itself.
239245
# * args: additional args to pass to dartdevc
240246

241247
prebuilt_dart_action(target_name) {
@@ -288,15 +294,9 @@ template("dartdevc_kernel_compile") {
288294
args += invoker.args
289295
}
290296

291-
# TODO(sigmund): remove nnbd_disabled. We turned this off temporarily while
292-
# the migration of libraries is in flux, this step otherwise fails with many
293-
# nnbd-related compile-time errors because the packages are assumed to be
294-
# nnbd compilant.
295-
if (!defined(invoker.nnbd_disabled) || !invoker.nnbd_disabled) {
296-
# TODO(38701): Cleanup after merging the forked SDK into mainline.
297-
if (use_nnbd) {
298-
args += [ "--enable-experiment=non-nullable" ]
299-
}
297+
# TODO(38701): Cleanup after merging the forked SDK into mainline.
298+
if (use_nnbd) {
299+
args += [ "--enable-experiment=non-nullable" ]
300300
}
301301
}
302302
}
@@ -307,7 +307,6 @@ dartdevc_kernel_compile("async_helper_js") {
307307

308308
dartdevc_kernel_compile("collection_js") {
309309
package = "collection"
310-
nnbd_disabled = true
311310
}
312311

313312
dartdevc_kernel_compile("expect_js") {
@@ -323,7 +322,6 @@ dartdevc_kernel_compile("js_js") {
323322
dartdevc_kernel_compile("matcher_js") {
324323
package = "matcher"
325324
package_dependencies = [ "stack_trace" ]
326-
nnbd_disabled = true
327325
}
328326

329327
dartdevc_kernel_compile("meta_js") {
@@ -332,13 +330,11 @@ dartdevc_kernel_compile("meta_js") {
332330

333331
dartdevc_kernel_compile("path_js") {
334332
package = "path"
335-
nnbd_disabled = true
336333
}
337334

338335
dartdevc_kernel_compile("stack_trace_js") {
339336
package = "stack_trace"
340337
package_dependencies = [ "path" ]
341-
nnbd_disabled = true
342338
}
343339

344340
# TODO(rnystrom): Remove this when unittest is no longer used. Also remove
@@ -354,7 +350,6 @@ dartdevc_kernel_compile("unittest_js") {
354350
"html_individual_config",
355351
"html_enhanced_config",
356352
]
357-
nnbd_disabled = true
358353
}
359354

360355
compile_platform("dartdevc_platform") {

0 commit comments

Comments
 (0)