Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit fa72449

Browse files
author
Dart CI
committed
Version 2.14.0-368.0.dev
Merge commit 'b05892efa124ed8325b2537e16aefb1c0e8a396b' into 'dev'
2 parents a325ab0 + b05892e commit fa72449

File tree

67 files changed

+2061
-51
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+2061
-51
lines changed

pkg/_fe_analyzer_shared/lib/src/messages/codes_generated.dart

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,6 +1327,25 @@ const MessageCode messageConstEvalExtension = const MessageCode(
13271327
message:
13281328
r"""Extension operations can't be used in constant expressions.""");
13291329

1330+
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
1331+
const Code<Null> codeConstEvalExternalConstructor =
1332+
messageConstEvalExternalConstructor;
1333+
1334+
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
1335+
const MessageCode messageConstEvalExternalConstructor = const MessageCode(
1336+
"ConstEvalExternalConstructor",
1337+
message:
1338+
r"""External constructors can't be evaluated in constant expressions.""");
1339+
1340+
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
1341+
const Code<Null> codeConstEvalExternalFactory = messageConstEvalExternalFactory;
1342+
1343+
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
1344+
const MessageCode messageConstEvalExternalFactory = const MessageCode(
1345+
"ConstEvalExternalFactory",
1346+
message:
1347+
r"""External factory constructors can't be evaluated in constant expressions.""");
1348+
13301349
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
13311350
const Code<Null> codeConstEvalFailedAssertion = messageConstEvalFailedAssertion;
13321351

pkg/front_end/lib/src/compute_platform_binaries_location.dart

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,17 @@ String? computePlatformDillName(
2323
case 'dartdevc':
2424
switch (nnbdMode) {
2525
case NnbdMode.Strong:
26-
return 'ddc_platform_sound.dill';
26+
// DDC is always compiled against the outline so we use it here by
27+
// default.
28+
return 'ddc_outline_sound.dill';
29+
//TODO(johnniwinther): Support using the full dill.
30+
//return 'ddc_platform_sound.dill';
2731
case NnbdMode.Weak:
28-
return 'ddc_platform.dill';
32+
// DDC is always compiled against the outline so we use it here by
33+
// default.
34+
return 'ddc_outline.dill';
35+
//TODO(johnniwinther): Support using the full dill.
36+
//return 'ddc_platform.dill';
2937
case NnbdMode.Agnostic:
3038
break;
3139
}

pkg/front_end/lib/src/fasta/builder/constructor_builder.dart

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,12 +247,19 @@ class ConstructorBuilderImpl extends FunctionBuilderImpl
247247
}
248248
}
249249

250+
bool _hasBuiltOutlines = false;
251+
250252
@override
251253
void buildOutlineExpressions(
252254
SourceLibraryBuilder library,
253255
CoreTypes coreTypes,
254256
List<DelayedActionPerformer> delayedActionPerformers,
255257
List<SynthesizedFunctionNode> synthesizedFunctionNodes) {
258+
if (_hasBuiltOutlines) return;
259+
if (isConst && isPatch) {
260+
origin.buildOutlineExpressions(library, coreTypes,
261+
delayedActionPerformers, synthesizedFunctionNodes);
262+
}
256263
super.buildOutlineExpressions(
257264
library, coreTypes, delayedActionPerformers, synthesizedFunctionNodes);
258265

@@ -267,6 +274,10 @@ class ConstructorBuilderImpl extends FunctionBuilderImpl
267274
bodyBuilder.resolveRedirectingFactoryTargets();
268275
}
269276
beginInitializers = null;
277+
if (isConst && isPatch) {
278+
_finishPatch();
279+
}
280+
_hasBuiltOutlines = true;
270281
}
271282

272283
@override
@@ -388,10 +399,7 @@ class ConstructorBuilderImpl extends FunctionBuilderImpl
388399
return null;
389400
}
390401

391-
@override
392-
int finishPatch() {
393-
if (!isPatch) return 0;
394-
402+
void _finishPatch() {
395403
// TODO(ahe): restore file-offset once we track both origin and patch file
396404
// URIs. See https://github.com/dart-lang/sdk/issues/31579
397405
origin.constructor.fileUri = fileUri;
@@ -406,6 +414,12 @@ class ConstructorBuilderImpl extends FunctionBuilderImpl
406414
origin.constructor.function.parent = origin.constructor;
407415
origin.constructor.initializers = _constructor.initializers;
408416
setParents(origin.constructor.initializers, origin.constructor);
417+
}
418+
419+
@override
420+
int finishPatch() {
421+
if (!isPatch) return 0;
422+
_finishPatch();
409423
return 1;
410424
}
411425

@@ -438,7 +452,7 @@ class ConstructorBuilderImpl extends FunctionBuilderImpl
438452
// compile), and so we also clear them.
439453
// Note: this method clears both initializers from the target Kernel node
440454
// and internal state associated with parsing initializers.
441-
_constructor.initializers.length = 0;
455+
_constructor.initializers = [];
442456
redirectingInitializer = null;
443457
superInitializer = null;
444458
hasMovedSuperInitializer = false;

pkg/front_end/lib/src/fasta/builder/factory_builder.dart

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,20 @@ class SourceFactoryBuilder extends FunctionBuilderImpl {
160160
return _procedureInternal;
161161
}
162162

163+
bool _hasBuiltOutlines = false;
164+
165+
@override
166+
void buildOutlineExpressions(
167+
SourceLibraryBuilder library,
168+
CoreTypes coreTypes,
169+
List<DelayedActionPerformer> delayedActionPerformers,
170+
List<SynthesizedFunctionNode> synthesizedFunctionNodes) {
171+
if (_hasBuiltOutlines) return;
172+
super.buildOutlineExpressions(
173+
library, coreTypes, delayedActionPerformers, synthesizedFunctionNodes);
174+
_hasBuiltOutlines = true;
175+
}
176+
163177
@override
164178
VariableDeclaration? getTearOffParameter(int index) {
165179
if (_factoryTearOff != null) {
@@ -213,10 +227,7 @@ class SourceFactoryBuilder extends FunctionBuilderImpl {
213227
}
214228
}
215229

216-
@override
217-
int finishPatch() {
218-
if (!isPatch) return 0;
219-
230+
void _finishPatch() {
220231
// TODO(ahe): restore file-offset once we track both origin and patch file
221232
// URIs. See https://github.com/dart-lang/sdk/issues/31579
222233
origin._procedure.fileUri = fileUri;
@@ -232,6 +243,12 @@ class SourceFactoryBuilder extends FunctionBuilderImpl {
232243
origin._procedure.function.parent = origin._procedure;
233244
origin._procedure.isRedirectingFactory =
234245
_procedureInternal.isRedirectingFactory;
246+
}
247+
248+
@override
249+
int finishPatch() {
250+
if (!isPatch) return 0;
251+
_finishPatch();
235252
return 1;
236253
}
237254
}
@@ -347,16 +364,23 @@ class RedirectingFactoryBuilder extends SourceFactoryBuilder {
347364
return _procedureInternal;
348365
}
349366

367+
bool _hasBuiltOutlines = false;
368+
350369
@override
351370
void buildOutlineExpressions(
352371
SourceLibraryBuilder library,
353372
CoreTypes coreTypes,
354373
List<DelayedActionPerformer> delayedActionPerformers,
355374
List<SynthesizedFunctionNode> synthesizedFunctionNodes) {
375+
if (_hasBuiltOutlines) return;
376+
if (isConst && isPatch) {
377+
origin.buildOutlineExpressions(library, coreTypes,
378+
delayedActionPerformers, synthesizedFunctionNodes);
379+
}
356380
super.buildOutlineExpressions(
357381
library, coreTypes, delayedActionPerformers, synthesizedFunctionNodes);
358382
RedirectingFactoryBody redirectingFactoryBody =
359-
_procedure.function.body as RedirectingFactoryBody;
383+
_procedureInternal.function.body as RedirectingFactoryBody;
360384
List<DartType>? typeArguments = redirectingFactoryBody.typeArguments;
361385
Member? target = redirectingFactoryBody.target;
362386
if (typeArguments != null && typeArguments.any((t) => t is UnknownType)) {
@@ -422,20 +446,19 @@ class RedirectingFactoryBuilder extends SourceFactoryBuilder {
422446
typeArguments ?? [],
423447
_tearOffTypeParameters!));
424448
}
449+
if (isConst && isPatch) {
450+
_finishPatch();
451+
}
452+
_hasBuiltOutlines = true;
425453
}
426454

427-
@override
428-
int finishPatch() {
429-
if (!isPatch) return 0;
430-
431-
super.finishPatch();
455+
void _finishPatch() {
456+
super._finishPatch();
432457

433458
SourceFactoryBuilder redirectingOrigin = origin;
434459
if (redirectingOrigin is RedirectingFactoryBuilder) {
435460
redirectingOrigin.typeArguments = typeArguments;
436461
}
437-
438-
return 1;
439462
}
440463

441464
List<DartType>? getTypeArguments() {

pkg/front_end/lib/src/fasta/incremental_compiler.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1918,7 +1918,7 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
19181918
if (cls == null) return null;
19191919
}
19201920

1921-
userCode!.loader.seenMessages.clear();
1921+
userCode!.loader.resetSeenMessages();
19221922

19231923
for (TypeParameter typeParam in typeDefinitions) {
19241924
if (!isLegalIdentifier(typeParam.name!)) {

pkg/front_end/lib/src/fasta/kernel/constant_evaluator.dart

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ import '../fasta_codes.dart'
4141
messageConstEvalCircularity,
4242
messageConstEvalContext,
4343
messageConstEvalExtension,
44+
messageConstEvalExternalConstructor,
45+
messageConstEvalExternalFactory,
4446
messageConstEvalFailedAssertion,
4547
messageConstEvalNotListOrSetInSpread,
4648
messageConstEvalNotMapInSpread,
@@ -1652,6 +1654,8 @@ class ConstantEvaluator implements ExpressionVisitor<Constant> {
16521654
node,
16531655
'Constructor "$node" has non-trivial body '
16541656
'"${constructor.function.body.runtimeType}".');
1657+
} else if (constructor.isExternal) {
1658+
return createErrorConstant(node, messageConstEvalExternalConstructor);
16551659
}
16561660
return null;
16571661
}
@@ -3012,30 +3016,33 @@ class ConstantEvaluator implements ExpressionVisitor<Constant> {
30123016
isConst: true));
30133017
}
30143018
if (target.kind == ProcedureKind.Factory) {
3015-
if (target.isConst &&
3016-
target.enclosingLibrary == coreTypes.coreLibrary &&
3017-
positionals.length == 1 &&
3018-
(target.name.text == "fromEnvironment" ||
3019-
target.name.text == "hasEnvironment")) {
3020-
if (environmentDefines != null) {
3021-
// Evaluate environment constant.
3022-
Constant name = positionals.single;
3023-
if (name is StringConstant) {
3024-
if (target.name.text == "fromEnvironment") {
3025-
return _handleFromEnvironment(target, name, named);
3026-
} else {
3027-
return _handleHasEnvironment(name);
3019+
if (target.isConst) {
3020+
if (target.enclosingLibrary == coreTypes.coreLibrary &&
3021+
positionals.length == 1 &&
3022+
(target.name.text == "fromEnvironment" ||
3023+
target.name.text == "hasEnvironment")) {
3024+
if (environmentDefines != null) {
3025+
// Evaluate environment constant.
3026+
Constant name = positionals.single;
3027+
if (name is StringConstant) {
3028+
if (target.name.text == "fromEnvironment") {
3029+
return _handleFromEnvironment(target, name, named);
3030+
} else {
3031+
return _handleHasEnvironment(name);
3032+
}
3033+
} else if (name is NullConstant) {
3034+
return createErrorConstant(node, messageConstEvalNullValue);
30283035
}
3029-
} else if (name is NullConstant) {
3030-
return createErrorConstant(node, messageConstEvalNullValue);
3036+
} else {
3037+
// Leave environment constant unevaluated.
3038+
return unevaluated(
3039+
node,
3040+
new StaticInvocation(target,
3041+
unevaluatedArguments(positionals, named, arguments.types),
3042+
isConst: true));
30313043
}
3032-
} else {
3033-
// Leave environment constant unevaluated.
3034-
return unevaluated(
3035-
node,
3036-
new StaticInvocation(target,
3037-
unevaluatedArguments(positionals, named, arguments.types),
3038-
isConst: true));
3044+
} else if (target.isExternal) {
3045+
return createErrorConstant(node, messageConstEvalExternalFactory);
30393046
}
30403047
}
30413048
} else if (target.name.text == 'identical') {

pkg/front_end/lib/src/fasta/kernel/kernel_constants.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,17 @@ class KernelConstantErrorReporter extends ErrorReporter {
4646

4747
@override
4848
void reportInvalidExpression(InvalidExpression node) {
49+
// TODO(johnniwinther): Improve the precision of this assertion. Do we
50+
// for instance allow warnings only to have been reported in previous
51+
// compilations.
52+
assert(
53+
// Either we have already reported an error
54+
loader.hasSeenError ||
55+
// or we have reported an error in a previous compilation.
56+
loader.builders.values.any((builder) =>
57+
builder.library.problemsAsJson?.isNotEmpty ?? false),
58+
"No error reported before seeing: "
59+
"${node.message}");
4960
// Assumed to be already reported.
5061
}
5162
}

pkg/front_end/lib/src/fasta/loader.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@ abstract class Loader {
8181
final List<FormattedMessage> allComponentProblems = <FormattedMessage>[];
8282

8383
final Set<String> seenMessages = new Set<String>();
84+
bool _hasSeenError = false;
85+
86+
void resetSeenMessages() {
87+
seenMessages.clear();
88+
_hasSeenError = false;
89+
}
90+
91+
/// Returns `true` if a compile time error has been reported.
92+
bool get hasSeenError => _hasSeenError;
8493

8594
LibraryBuilder? _coreLibrary;
8695
LibraryBuilder? typedDataLibrary;
@@ -362,6 +371,9 @@ fileUri: $fileUri
362371
severity: $severity
363372
""";
364373
if (!seenMessages.add(trace)) return null;
374+
if (message.code.severity == Severity.error) {
375+
_hasSeenError = true;
376+
}
365377
if (message.code.severity == Severity.context) {
366378
internalProblem(
367379
templateInternalProblemContextSeverity

pkg/front_end/messages.status

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ ConstEvalDuplicateElement/example: Fail
103103
ConstEvalDuplicateKey/example: Fail
104104
ConstEvalElementImplementsEqual/example: Fail
105105
ConstEvalExtension/example: Fail
106+
ConstEvalExternalConstructor/analyzerCode: Fail
107+
ConstEvalExternalConstructor/example: Fail
108+
ConstEvalExternalFactory/analyzerCode: Fail
109+
ConstEvalExternalFactory/example: Fail
106110
ConstEvalFailedAssertion/example: Fail
107111
ConstEvalFailedAssertionWithMessage/example: Fail
108112
ConstEvalFreeTypeParameter/analyzerCode: Fail

pkg/front_end/messages.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,12 @@ ConstEvalExtension:
219219
template: "Extension operations can't be used in constant expressions."
220220
analyzerCode: NOT_CONSTANT_EXPRESSION
221221

222+
ConstEvalExternalConstructor:
223+
template: "External constructors can't be evaluated in constant expressions."
224+
225+
ConstEvalExternalFactory:
226+
template: "External factory constructors can't be evaluated in constant expressions."
227+
222228
ConstEvalUnevaluated:
223229
template: "Couldn't evaluate constant expression."
224230

pkg/front_end/test/spell_checking_list_code.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ casted
167167
casts
168168
categorized
169169
ce
170+
ceil
170171
cfe
171172
ch
172173
channel
@@ -220,6 +221,7 @@ combine2
220221
combiner
221222
compared
222223
compares
224+
compilations
223225
completes
224226
complicating
225227
component's

pkg/front_end/test/spell_checking_list_tests.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,7 @@ ox
702702
pack
703703
paging
704704
paint
705+
parallax
705706
parameterized
706707
party
707708
pause
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
main() => const Symbol('a');

0 commit comments

Comments
 (0)