Skip to content

Commit defd2ae

Browse files
author
Dart CI
committed
Version 2.14.0-390.0.dev
Merge commit '0b1ddaa598d4fcc2fdf2eb750623d30326191d46' into 'dev'
2 parents fa8a1d0 + 0b1ddaa commit defd2ae

115 files changed

Lines changed: 1369 additions & 302 deletions

File tree

Some content is hidden

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

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
- `convertNativeToDart_Dictionary()` now converts objects recursively, this
8383
fixes APIs like MediaStreamTrack.getCapabilities that convert between Maps and
8484
browser Dictionaries. [#44319]
85+
- Added some access-control HTTP header names to `HttpHeaders`.
8586

8687
[#44319]: https://github.com/dart-lang/sdk/issues/44319
8788

@@ -90,6 +91,7 @@
9091
- BREAKING CHANGE (for pre-migrated null safe code): `HttpClient`'s
9192
`.authenticate` and `.authenticateProxy` setter callbacks must now accept a
9293
nullable `realm` argument.
94+
- Added some access-control HTTP header names to `HttpHeaders`.
9395

9496
#### `dart:typed_data`
9597

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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+
import 'dart:async';
6+
import 'dart:io';
7+
import 'dart:isolate';
8+
import 'dart:math';
9+
10+
import 'package:expect/expect.dart';
11+
12+
// Implements recursive summation via tail calls:
13+
// fib(n) => n <= 1 ? 1
14+
// : fib(n-1) + fib(n-2);
15+
Future fibonacciRecursive(List args) async {
16+
final SendPort port = args[0];
17+
final n = args[1];
18+
if (n <= 1) {
19+
port.send(1);
20+
return;
21+
}
22+
final left = ReceivePort();
23+
final right = ReceivePort();
24+
await Future.wait([
25+
Isolate.spawn(fibonacciRecursive, [left.sendPort, n - 1]),
26+
Isolate.spawn(fibonacciRecursive, [right.sendPort, n - 2]),
27+
]);
28+
final results = await Future.wait([left.first, right.first]);
29+
port.send(results[0] + results[1]);
30+
}
31+
32+
Future<void> main() async {
33+
final rpWarmup = ReceivePort();
34+
final rpRun = ReceivePort();
35+
final int nWarmup = 17; // enough runs to trigger optimized compilation
36+
final int nWarmupFactorial = 2584;
37+
// With --enable-isolate-groups runs for about 8 seconds.
38+
// Should not be run witout --enable-isolate-groups as it would be too slow.
39+
final int n = 21;
40+
final int nFactorial = 17711;
41+
final beforeRss = ProcessInfo.currentRss;
42+
43+
int maxRss = beforeRss;
44+
final rssTimer = Timer.periodic(const Duration(milliseconds: 10), (_) {
45+
maxRss = max(ProcessInfo.currentRss, maxRss);
46+
});
47+
48+
final watch = Stopwatch();
49+
watch.start();
50+
51+
// For the benefit of enable-isolate-groups configuration, warm up target
52+
// isolate code by running couple iterations in the main isolate.
53+
await Isolate.spawn(fibonacciRecursive, [rpWarmup.sendPort, nWarmup]);
54+
Expect.equals(nWarmupFactorial, await rpWarmup.first);
55+
56+
final warmup = watch.elapsedMicroseconds;
57+
58+
await Isolate.spawn(fibonacciRecursive, [rpRun.sendPort, n]);
59+
Expect.equals(nFactorial, await rpRun.first);
60+
61+
final done = watch.elapsedMicroseconds;
62+
63+
print('IsolateFibonacci_$n.Calculation(RunTimeRaw): ${done-warmup} us.');
64+
print('IsolateFibonacci_$n.DeltaPeak(MemoryUse): ${maxRss-beforeRss}');
65+
rssTimer.cancel();
66+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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+
import 'dart:async';
6+
import 'dart:io';
7+
import 'dart:isolate';
8+
import 'dart:math';
9+
10+
import 'package:expect/expect.dart';
11+
12+
// Implements recursive summation via tail calls:
13+
// fib(n) => n <= 1 ? 1
14+
// : fib(n-1) + fib(n-2);
15+
Future fibonacciRecursive(List args) async {
16+
final SendPort port = args[0];
17+
final n = args[1];
18+
if (n <= 1) {
19+
port.send(1);
20+
return;
21+
}
22+
final left = ReceivePort();
23+
final right = ReceivePort();
24+
await Future.wait([
25+
Isolate.spawn(fibonacciRecursive, [left.sendPort, n - 1]),
26+
Isolate.spawn(fibonacciRecursive, [right.sendPort, n - 2]),
27+
]);
28+
final results = await Future.wait([left.first, right.first]);
29+
port.send(results[0] + results[1]);
30+
}
31+
32+
Future<void> main() async {
33+
final rpWarmup = ReceivePort();
34+
final rpRun = ReceivePort();
35+
final int nWarmup = 17; // enough runs to trigger optimized compilation
36+
final int nWarmupFactorial = 2584;
37+
// With --enable-isolate-groups runs for about 8 seconds.
38+
// Should not be run witout --enable-isolate-groups as it would be too slow.
39+
final int n = 21;
40+
final int nFactorial = 17711;
41+
final beforeRss = ProcessInfo.currentRss;
42+
43+
int maxRss = beforeRss;
44+
final rssTimer = Timer.periodic(const Duration(milliseconds: 10), (_) {
45+
maxRss = max(ProcessInfo.currentRss, maxRss);
46+
});
47+
48+
final watch = Stopwatch();
49+
watch.start();
50+
51+
// For the benefit of enable-isolate-groups configuration, warm up target
52+
// isolate code by running couple iterations in the main isolate.
53+
await Isolate.spawn(fibonacciRecursive, [rpWarmup.sendPort, nWarmup]);
54+
Expect.equals(nWarmupFactorial, await rpWarmup.first);
55+
56+
final warmup = watch.elapsedMicroseconds;
57+
58+
await Isolate.spawn(fibonacciRecursive, [rpRun.sendPort, n]);
59+
Expect.equals(nFactorial, await rpRun.first);
60+
61+
final done = watch.elapsedMicroseconds;
62+
63+
print('IsolateFibonacci_$n.Calculation(RunTimeRaw): ${done-warmup} us.');
64+
print('IsolateFibonacci_$n.DeltaPeak(MemoryUse): ${maxRss-beforeRss}');
65+
rssTimer.cancel();
66+
}

pkg/analyzer/lib/error/error.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ const List<ErrorCode> errorCodeValues = [
141141
CompileTimeErrorCode.CONST_WITH_TYPE_PARAMETERS,
142142
CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR,
143143
CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT,
144+
CompileTimeErrorCode.CONSTRUCTOR_TEAROFFS_NOT_ENABLED,
144145
CompileTimeErrorCode.CONTINUE_LABEL_ON_SWITCH,
145146
CompileTimeErrorCode.COULD_NOT_INFER,
146147
CompileTimeErrorCode.DEFAULT_LIST_CONSTRUCTOR,

pkg/analyzer/lib/src/dart/analysis/feature_set_provider.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ import 'package:analyzer/src/util/uri.dart';
1212
import 'package:pub_semver/pub_semver.dart';
1313

1414
class FeatureSetProvider {
15-
/// This flag will be turned to `true` and inlined when we un-fork SDK,
16-
/// so that the only SDK is the Null Safe SDK.
17-
static const isNullSafetySdk = true;
18-
1915
final Version _sdkLanguageVersion;
2016
final AllowedExperiments _allowedExperiments;
2117
final ResourceProvider _resourceProvider;

pkg/analyzer/lib/src/dart/resolver/ast_rewrite.dart

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ class AstRewriter {
1919

2020
AstRewriter(this._errorReporter);
2121

22+
/// Possibly rewrites [node] as an [ExtensionOverride] or as an
23+
/// [InstanceCreationExpression].
2224
AstNode methodInvocation(Scope nameScope, MethodInvocation node) {
2325
SimpleIdentifier methodName = node.methodName;
2426
if (methodName.isSynthetic) {
@@ -140,6 +142,44 @@ class AstRewriter {
140142
return node;
141143
}
142144

145+
/// Possibly rewrites [node] as a [ConstructorReference].
146+
AstNode prefixedIdentifier(Scope nameScope, PrefixedIdentifier node) {
147+
if (node.parent is Annotation) {
148+
// An annotations which is a const constructor invocation can initially be
149+
// represented with a [PrefixedIdentifier]. Do not rewrite such nodes.
150+
return node;
151+
}
152+
if (node.parent is CommentReference) {
153+
// TODO(srawlins): This probably should be rewritten to a
154+
// [ConstructorReference] at some point.
155+
return node;
156+
}
157+
var identifier = node.identifier;
158+
if (identifier.isSynthetic) {
159+
// This isn't a constructor reference.
160+
return node;
161+
}
162+
var prefix = node.prefix;
163+
var element = nameScope.lookup(prefix.name).getter;
164+
if (element is ClassElement) {
165+
// Example:
166+
// class C { C.named(); }
167+
// C.named
168+
return _toConstructorReference(node: node, classElement: element);
169+
} else if (element is TypeAliasElement) {
170+
var aliasedType = element.aliasedType;
171+
if (aliasedType is InterfaceType) {
172+
// Example:
173+
// class C { C.named(); }
174+
// typedef X = C;
175+
// X.named
176+
return _toConstructorReference(
177+
node: node, classElement: aliasedType.element);
178+
}
179+
}
180+
return node;
181+
}
182+
143183
AstNode _instanceCreation_prefix_type_name({
144184
required MethodInvocation node,
145185
required PrefixedIdentifier typeNameIdentifier,
@@ -170,6 +210,25 @@ class AstRewriter {
170210
return instanceCreationExpression;
171211
}
172212

213+
AstNode _toConstructorReference(
214+
{required PrefixedIdentifier node, required ClassElement classElement}) {
215+
var name = node.identifier.name;
216+
var constructorElement = name == 'new'
217+
? classElement.unnamedConstructor
218+
: classElement.getNamedConstructor(name);
219+
if (constructorElement == null) {
220+
return node;
221+
}
222+
223+
var typeName = astFactory.typeName(node.prefix, null);
224+
var constructorName =
225+
astFactory.constructorName(typeName, node.period, node.identifier);
226+
var constructorReference =
227+
astFactory.constructorReference(constructorName: constructorName);
228+
NodeReplacer.replace(node, constructorReference);
229+
return constructorReference;
230+
}
231+
173232
InstanceCreationExpression _toInstanceCreation_prefix_type({
174233
required MethodInvocation node,
175234
required SimpleIdentifier prefixIdentifier,
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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+
import 'package:analyzer/dart/ast/ast.dart';
6+
import 'package:analyzer/dart/element/type.dart';
7+
import 'package:analyzer/src/dart/ast/ast.dart';
8+
import 'package:analyzer/src/dart/element/member.dart';
9+
import 'package:analyzer/src/error/codes.dart';
10+
import 'package:analyzer/src/generated/resolver.dart';
11+
12+
/// A resolver for [ConstructorReference] nodes.
13+
class ConstructorReferenceResolver {
14+
/// The resolver driving this participant.
15+
final ResolverVisitor _resolver;
16+
17+
ConstructorReferenceResolver(this._resolver);
18+
19+
void resolve(ConstructorReferenceImpl node) {
20+
if (!_resolver.isConstructorTearoffsEnabled) {
21+
_resolver.errorReporter.reportErrorForNode(
22+
CompileTimeErrorCode.CONSTRUCTOR_TEAROFFS_NOT_ENABLED, node, []);
23+
}
24+
node.constructorName.accept(_resolver);
25+
_inferArgumentTypes(node);
26+
}
27+
28+
void _inferArgumentTypes(ConstructorReferenceImpl node) {
29+
var constructorName = node.constructorName;
30+
var typeName = constructorName.type;
31+
var elementToInfer = _resolver.inferenceHelper.constructorElementToInfer(
32+
constructorName: constructorName,
33+
definingLibrary: _resolver.definingLibrary,
34+
);
35+
36+
// If the constructor is generic, we'll have a ConstructorMember that
37+
// substitutes in type arguments (possibly `dynamic`) from earlier in
38+
// resolution.
39+
//
40+
// Otherwise we'll have a ConstructorElement, and we can skip inference
41+
// because there's nothing to infer in a non-generic type.
42+
if (elementToInfer != null) {
43+
// TODO(leafp): Currently, we may re-infer types here, since we
44+
// sometimes resolve multiple times. We should really check that we
45+
// have not already inferred something. However, the obvious ways to
46+
// check this don't work, since we may have been instantiated
47+
// to bounds in an earlier phase, and we *do* want to do inference
48+
// in that case.
49+
50+
// Get back to the uninstantiated generic constructor.
51+
// TODO(jmesserly): should we store this earlier in resolution?
52+
// Or look it up, instead of jumping backwards through the Member?
53+
var rawElement = elementToInfer.element;
54+
var constructorType = elementToInfer.asType;
55+
56+
var inferred = _resolver.inferenceHelper.inferTearOff(
57+
node, constructorName.name!, constructorType) as FunctionType?;
58+
59+
if (inferred != null) {
60+
typeName.type = inferred.returnType;
61+
62+
// Update the static element as well. This is used in some cases, such
63+
// as computing constant values. It is stored in two places.
64+
var constructorElement = ConstructorMember.from(
65+
rawElement,
66+
inferred.returnType as InterfaceType,
67+
);
68+
constructorName.staticElement = constructorElement;
69+
constructorName.name?.staticElement = constructorElement;
70+
node.staticType = inferred;
71+
}
72+
} else {
73+
node.staticType = node.constructorName.staticElement!.type;
74+
}
75+
}
76+
}

pkg/analyzer/lib/src/dart/resolver/exit_detector.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ class ExitDetector extends GeneralizingAstVisitor<bool> {
128128
return thenExpression.accept(this)! && elseExpression.accept(this)!;
129129
}
130130

131+
@override
132+
bool visitConstructorReference(ConstructorReference node) => false;
133+
131134
@override
132135
bool visitContinueStatement(ContinueStatement node) {
133136
_enclosingBlockContainsContinue = true;

pkg/analyzer/lib/src/dart/resolver/invocation_inference_helper.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class ConstructorElementToInfer {
5050
typeFormals: typeParameters,
5151
parameters: element.parameters,
5252
returnType: element.returnType,
53-
nullabilitySuffix: NullabilitySuffix.star,
53+
nullabilitySuffix: NullabilitySuffix.none,
5454
);
5555
}
5656
}

pkg/analyzer/lib/src/dart/resolver/resolution_visitor.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,16 @@ class ResolutionVisitor extends RecursiveAstVisitor<void> {
859859
super.visitPartOfDirective(node);
860860
}
861861

862+
@override
863+
void visitPrefixedIdentifier(PrefixedIdentifier node) {
864+
var newNode = _astRewriter.prefixedIdentifier(_nameScope, node);
865+
if (newNode != node) {
866+
return newNode.accept(this);
867+
}
868+
869+
super.visitPrefixedIdentifier(node);
870+
}
871+
862872
@override
863873
void visitSimpleFormalParameter(covariant SimpleFormalParameterImpl node) {
864874
ParameterElementImpl element;

0 commit comments

Comments
 (0)