Skip to content

Commit

Permalink
Version 2.14.0-368.0.dev
Browse files Browse the repository at this point in the history
Merge commit 'b05892efa124ed8325b2537e16aefb1c0e8a396b' into 'dev'
  • Loading branch information
Dart CI committed Jul 30, 2021
2 parents a325ab0 + b05892e commit fa72449
Show file tree
Hide file tree
Showing 67 changed files with 2,061 additions and 51 deletions.
19 changes: 19 additions & 0 deletions pkg/_fe_analyzer_shared/lib/src/messages/codes_generated.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1327,6 +1327,25 @@ const MessageCode messageConstEvalExtension = const MessageCode(
message:
r"""Extension operations can't be used in constant expressions.""");

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const Code<Null> codeConstEvalExternalConstructor =
messageConstEvalExternalConstructor;

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const MessageCode messageConstEvalExternalConstructor = const MessageCode(
"ConstEvalExternalConstructor",
message:
r"""External constructors can't be evaluated in constant expressions.""");

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const Code<Null> codeConstEvalExternalFactory = messageConstEvalExternalFactory;

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const MessageCode messageConstEvalExternalFactory = const MessageCode(
"ConstEvalExternalFactory",
message:
r"""External factory constructors can't be evaluated in constant expressions.""");

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const Code<Null> codeConstEvalFailedAssertion = messageConstEvalFailedAssertion;

Expand Down
12 changes: 10 additions & 2 deletions pkg/front_end/lib/src/compute_platform_binaries_location.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,17 @@ String? computePlatformDillName(
case 'dartdevc':
switch (nnbdMode) {
case NnbdMode.Strong:
return 'ddc_platform_sound.dill';
// DDC is always compiled against the outline so we use it here by
// default.
return 'ddc_outline_sound.dill';
//TODO(johnniwinther): Support using the full dill.
//return 'ddc_platform_sound.dill';
case NnbdMode.Weak:
return 'ddc_platform.dill';
// DDC is always compiled against the outline so we use it here by
// default.
return 'ddc_outline.dill';
//TODO(johnniwinther): Support using the full dill.
//return 'ddc_platform.dill';
case NnbdMode.Agnostic:
break;
}
Expand Down
24 changes: 19 additions & 5 deletions pkg/front_end/lib/src/fasta/builder/constructor_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,19 @@ class ConstructorBuilderImpl extends FunctionBuilderImpl
}
}

bool _hasBuiltOutlines = false;

@override
void buildOutlineExpressions(
SourceLibraryBuilder library,
CoreTypes coreTypes,
List<DelayedActionPerformer> delayedActionPerformers,
List<SynthesizedFunctionNode> synthesizedFunctionNodes) {
if (_hasBuiltOutlines) return;
if (isConst && isPatch) {
origin.buildOutlineExpressions(library, coreTypes,
delayedActionPerformers, synthesizedFunctionNodes);
}
super.buildOutlineExpressions(
library, coreTypes, delayedActionPerformers, synthesizedFunctionNodes);

Expand All @@ -267,6 +274,10 @@ class ConstructorBuilderImpl extends FunctionBuilderImpl
bodyBuilder.resolveRedirectingFactoryTargets();
}
beginInitializers = null;
if (isConst && isPatch) {
_finishPatch();
}
_hasBuiltOutlines = true;
}

@override
Expand Down Expand Up @@ -388,10 +399,7 @@ class ConstructorBuilderImpl extends FunctionBuilderImpl
return null;
}

@override
int finishPatch() {
if (!isPatch) return 0;

void _finishPatch() {
// TODO(ahe): restore file-offset once we track both origin and patch file
// URIs. See https://github.com/dart-lang/sdk/issues/31579
origin.constructor.fileUri = fileUri;
Expand All @@ -406,6 +414,12 @@ class ConstructorBuilderImpl extends FunctionBuilderImpl
origin.constructor.function.parent = origin.constructor;
origin.constructor.initializers = _constructor.initializers;
setParents(origin.constructor.initializers, origin.constructor);
}

@override
int finishPatch() {
if (!isPatch) return 0;
_finishPatch();
return 1;
}

Expand Down Expand Up @@ -438,7 +452,7 @@ class ConstructorBuilderImpl extends FunctionBuilderImpl
// compile), and so we also clear them.
// Note: this method clears both initializers from the target Kernel node
// and internal state associated with parsing initializers.
_constructor.initializers.length = 0;
_constructor.initializers = [];
redirectingInitializer = null;
superInitializer = null;
hasMovedSuperInitializer = false;
Expand Down
47 changes: 35 additions & 12 deletions pkg/front_end/lib/src/fasta/builder/factory_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,20 @@ class SourceFactoryBuilder extends FunctionBuilderImpl {
return _procedureInternal;
}

bool _hasBuiltOutlines = false;

@override
void buildOutlineExpressions(
SourceLibraryBuilder library,
CoreTypes coreTypes,
List<DelayedActionPerformer> delayedActionPerformers,
List<SynthesizedFunctionNode> synthesizedFunctionNodes) {
if (_hasBuiltOutlines) return;
super.buildOutlineExpressions(
library, coreTypes, delayedActionPerformers, synthesizedFunctionNodes);
_hasBuiltOutlines = true;
}

@override
VariableDeclaration? getTearOffParameter(int index) {
if (_factoryTearOff != null) {
Expand Down Expand Up @@ -213,10 +227,7 @@ class SourceFactoryBuilder extends FunctionBuilderImpl {
}
}

@override
int finishPatch() {
if (!isPatch) return 0;

void _finishPatch() {
// TODO(ahe): restore file-offset once we track both origin and patch file
// URIs. See https://github.com/dart-lang/sdk/issues/31579
origin._procedure.fileUri = fileUri;
Expand All @@ -232,6 +243,12 @@ class SourceFactoryBuilder extends FunctionBuilderImpl {
origin._procedure.function.parent = origin._procedure;
origin._procedure.isRedirectingFactory =
_procedureInternal.isRedirectingFactory;
}

@override
int finishPatch() {
if (!isPatch) return 0;
_finishPatch();
return 1;
}
}
Expand Down Expand Up @@ -347,16 +364,23 @@ class RedirectingFactoryBuilder extends SourceFactoryBuilder {
return _procedureInternal;
}

bool _hasBuiltOutlines = false;

@override
void buildOutlineExpressions(
SourceLibraryBuilder library,
CoreTypes coreTypes,
List<DelayedActionPerformer> delayedActionPerformers,
List<SynthesizedFunctionNode> synthesizedFunctionNodes) {
if (_hasBuiltOutlines) return;
if (isConst && isPatch) {
origin.buildOutlineExpressions(library, coreTypes,
delayedActionPerformers, synthesizedFunctionNodes);
}
super.buildOutlineExpressions(
library, coreTypes, delayedActionPerformers, synthesizedFunctionNodes);
RedirectingFactoryBody redirectingFactoryBody =
_procedure.function.body as RedirectingFactoryBody;
_procedureInternal.function.body as RedirectingFactoryBody;
List<DartType>? typeArguments = redirectingFactoryBody.typeArguments;
Member? target = redirectingFactoryBody.target;
if (typeArguments != null && typeArguments.any((t) => t is UnknownType)) {
Expand Down Expand Up @@ -422,20 +446,19 @@ class RedirectingFactoryBuilder extends SourceFactoryBuilder {
typeArguments ?? [],
_tearOffTypeParameters!));
}
if (isConst && isPatch) {
_finishPatch();
}
_hasBuiltOutlines = true;
}

@override
int finishPatch() {
if (!isPatch) return 0;

super.finishPatch();
void _finishPatch() {
super._finishPatch();

SourceFactoryBuilder redirectingOrigin = origin;
if (redirectingOrigin is RedirectingFactoryBuilder) {
redirectingOrigin.typeArguments = typeArguments;
}

return 1;
}

List<DartType>? getTypeArguments() {
Expand Down
2 changes: 1 addition & 1 deletion pkg/front_end/lib/src/fasta/incremental_compiler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1918,7 +1918,7 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
if (cls == null) return null;
}

userCode!.loader.seenMessages.clear();
userCode!.loader.resetSeenMessages();

for (TypeParameter typeParam in typeDefinitions) {
if (!isLegalIdentifier(typeParam.name!)) {
Expand Down
51 changes: 29 additions & 22 deletions pkg/front_end/lib/src/fasta/kernel/constant_evaluator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ import '../fasta_codes.dart'
messageConstEvalCircularity,
messageConstEvalContext,
messageConstEvalExtension,
messageConstEvalExternalConstructor,
messageConstEvalExternalFactory,
messageConstEvalFailedAssertion,
messageConstEvalNotListOrSetInSpread,
messageConstEvalNotMapInSpread,
Expand Down Expand Up @@ -1652,6 +1654,8 @@ class ConstantEvaluator implements ExpressionVisitor<Constant> {
node,
'Constructor "$node" has non-trivial body '
'"${constructor.function.body.runtimeType}".');
} else if (constructor.isExternal) {
return createErrorConstant(node, messageConstEvalExternalConstructor);
}
return null;
}
Expand Down Expand Up @@ -3012,30 +3016,33 @@ class ConstantEvaluator implements ExpressionVisitor<Constant> {
isConst: true));
}
if (target.kind == ProcedureKind.Factory) {
if (target.isConst &&
target.enclosingLibrary == coreTypes.coreLibrary &&
positionals.length == 1 &&
(target.name.text == "fromEnvironment" ||
target.name.text == "hasEnvironment")) {
if (environmentDefines != null) {
// Evaluate environment constant.
Constant name = positionals.single;
if (name is StringConstant) {
if (target.name.text == "fromEnvironment") {
return _handleFromEnvironment(target, name, named);
} else {
return _handleHasEnvironment(name);
if (target.isConst) {
if (target.enclosingLibrary == coreTypes.coreLibrary &&
positionals.length == 1 &&
(target.name.text == "fromEnvironment" ||
target.name.text == "hasEnvironment")) {
if (environmentDefines != null) {
// Evaluate environment constant.
Constant name = positionals.single;
if (name is StringConstant) {
if (target.name.text == "fromEnvironment") {
return _handleFromEnvironment(target, name, named);
} else {
return _handleHasEnvironment(name);
}
} else if (name is NullConstant) {
return createErrorConstant(node, messageConstEvalNullValue);
}
} else if (name is NullConstant) {
return createErrorConstant(node, messageConstEvalNullValue);
} else {
// Leave environment constant unevaluated.
return unevaluated(
node,
new StaticInvocation(target,
unevaluatedArguments(positionals, named, arguments.types),
isConst: true));
}
} else {
// Leave environment constant unevaluated.
return unevaluated(
node,
new StaticInvocation(target,
unevaluatedArguments(positionals, named, arguments.types),
isConst: true));
} else if (target.isExternal) {
return createErrorConstant(node, messageConstEvalExternalFactory);
}
}
} else if (target.name.text == 'identical') {
Expand Down
11 changes: 11 additions & 0 deletions pkg/front_end/lib/src/fasta/kernel/kernel_constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ class KernelConstantErrorReporter extends ErrorReporter {

@override
void reportInvalidExpression(InvalidExpression node) {
// TODO(johnniwinther): Improve the precision of this assertion. Do we
// for instance allow warnings only to have been reported in previous
// compilations.
assert(
// Either we have already reported an error
loader.hasSeenError ||
// or we have reported an error in a previous compilation.
loader.builders.values.any((builder) =>
builder.library.problemsAsJson?.isNotEmpty ?? false),
"No error reported before seeing: "
"${node.message}");
// Assumed to be already reported.
}
}
12 changes: 12 additions & 0 deletions pkg/front_end/lib/src/fasta/loader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ abstract class Loader {
final List<FormattedMessage> allComponentProblems = <FormattedMessage>[];

final Set<String> seenMessages = new Set<String>();
bool _hasSeenError = false;

void resetSeenMessages() {
seenMessages.clear();
_hasSeenError = false;
}

/// Returns `true` if a compile time error has been reported.
bool get hasSeenError => _hasSeenError;

LibraryBuilder? _coreLibrary;
LibraryBuilder? typedDataLibrary;
Expand Down Expand Up @@ -362,6 +371,9 @@ fileUri: $fileUri
severity: $severity
""";
if (!seenMessages.add(trace)) return null;
if (message.code.severity == Severity.error) {
_hasSeenError = true;
}
if (message.code.severity == Severity.context) {
internalProblem(
templateInternalProblemContextSeverity
Expand Down
4 changes: 4 additions & 0 deletions pkg/front_end/messages.status
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ ConstEvalDuplicateElement/example: Fail
ConstEvalDuplicateKey/example: Fail
ConstEvalElementImplementsEqual/example: Fail
ConstEvalExtension/example: Fail
ConstEvalExternalConstructor/analyzerCode: Fail
ConstEvalExternalConstructor/example: Fail
ConstEvalExternalFactory/analyzerCode: Fail
ConstEvalExternalFactory/example: Fail
ConstEvalFailedAssertion/example: Fail
ConstEvalFailedAssertionWithMessage/example: Fail
ConstEvalFreeTypeParameter/analyzerCode: Fail
Expand Down
6 changes: 6 additions & 0 deletions pkg/front_end/messages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,12 @@ ConstEvalExtension:
template: "Extension operations can't be used in constant expressions."
analyzerCode: NOT_CONSTANT_EXPRESSION

ConstEvalExternalConstructor:
template: "External constructors can't be evaluated in constant expressions."

ConstEvalExternalFactory:
template: "External factory constructors can't be evaluated in constant expressions."

ConstEvalUnevaluated:
template: "Couldn't evaluate constant expression."

Expand Down
2 changes: 2 additions & 0 deletions pkg/front_end/test/spell_checking_list_code.txt
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ casted
casts
categorized
ce
ceil
cfe
ch
channel
Expand Down Expand Up @@ -220,6 +221,7 @@ combine2
combiner
compared
compares
compilations
completes
complicating
component's
Expand Down
1 change: 1 addition & 0 deletions pkg/front_end/test/spell_checking_list_tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,7 @@ ox
pack
paging
paint
parallax
parameterized
party
pause
Expand Down
5 changes: 5 additions & 0 deletions pkg/front_end/testcases/dartdevc/symbol.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Copyright (c) 2021, 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.

main() => const Symbol('a');
Loading

0 comments on commit fa72449

Please sign in to comment.