Version 2.14.0-32.0.dev
Merge commit '529e8abc5c46b78f7c97379c78ceb38ae34041a8' into 'dev'
diff --git a/CHANGELOG.md b/CHANGELOG.md
index dbc15dc..a45fa7a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,12 +2,6 @@
### Core libraries
-#### `dart:async`
-
-* The uncaught error handlers of `Zone`s are now run in the parent zone
- of the zone where they were declared. This prevents a throwing handler
- from causing an infinite loop by repeatedly triggering itself.
-
#### `dart:core`
* The native `DateTime` class now better handles local time around
@@ -27,8 +21,14 @@
#### Linter
-Updated the Linter to `1.3.0`, which includes:
+Updated the Linter to `1.4.0`, which includes:
+- `directives_ordering` now checks ordering of `package:` imports in code
+ outside pub packages.
+- simple reachability analysis added to `use_build_context_synchronously` to
+ short-circuit await-discovery in terminating blocks.
+- `use_build_context_synchronously` updated to recognize nullable types when
+ accessed from legacy libraries.
- updated `non_constant_identifier_names` to check local variables, for-loop
initializers and catch clauses.
- updated error range of `lines_longer_than_80_chars` to start at 80 to make
diff --git a/DEPS b/DEPS
index 6d47b79..e9ac972 100644
--- a/DEPS
+++ b/DEPS
@@ -124,7 +124,7 @@
"intl_tag": "0.17.0-nullsafety",
"jinja2_rev": "2222b31554f03e62600cd7e383376a7c187967a1",
"json_rpc_2_rev": "b8dfe403fd8528fd14399dee3a6527b55802dd4d",
- "linter_tag": "1.3.0",
+ "linter_tag": "1.4.0",
"logging_rev": "e2f633b543ef89c54688554b15ca3d7e425b86a2",
"markupsafe_rev": "8f45f5cfa0009d2a70589bcda0349b8cb2b72783",
"markdown_rev": "9c4beaac96d8f008078e00b027915f81b665d2de",
diff --git a/pkg/analysis_server/tool/code_completion/completion_metrics.dart b/pkg/analysis_server/tool/code_completion/completion_metrics.dart
index 4a685e3..596d170 100644
--- a/pkg/analysis_server/tool/code_completion/completion_metrics.dart
+++ b/pkg/analysis_server/tool/code_completion/completion_metrics.dart
@@ -123,16 +123,6 @@
/// Create a parser that can be used to parse the command-line arguments.
ArgParser createArgParser() {
return ArgParser()
- ..addFlag(CompletionMetricsOptions.AVAILABLE_SUGGESTIONS,
- abbr: 'a',
- help:
- 'Use the available suggestions feature in the Analysis Server when '
- 'computing the set of code completions. With this feature enabled, '
- 'completion will match the support in the Dart Plugin for '
- 'IntelliJ, without this enabled the completion support matches the '
- 'support in LSP.',
- defaultsTo: false,
- negatable: false)
..addOption(
'help',
abbr: 'h',
@@ -282,6 +272,10 @@
/// The name associated with this set of metrics.
final String name;
+ /// A flag indicating whether available suggestions should be enabled for this
+ /// run.
+ final bool availableSuggestions;
+
/// The function to be executed when this metrics collector is enabled.
final void Function()? enableFunction;
@@ -336,11 +330,15 @@
final Map<CompletionGroup, List<CompletionResult>> worstResults = {};
- CompletionMetrics(this.name, {this.enableFunction, this.disableFunction});
+ CompletionMetrics(this.name,
+ {required this.availableSuggestions,
+ this.enableFunction,
+ this.disableFunction});
/// Return an instance extracted from the decoded JSON [map].
factory CompletionMetrics.fromJson(Map<String, dynamic> map) {
- var metrics = CompletionMetrics(map['name'] as String);
+ var metrics = CompletionMetrics(map['name'] as String,
+ availableSuggestions: map['availableSuggestions'] as bool);
metrics.completionCounter
.fromJson(map['completionCounter'] as Map<String, dynamic>);
metrics.completionMissedTokenCounter
@@ -467,6 +465,7 @@
Map<String, dynamic> toJson() {
return {
'name': name,
+ 'availableSuggestions': availableSuggestions,
'completionCounter': completionCounter.toJson(),
'completionMissedTokenCounter': completionMissedTokenCounter.toJson(),
'completionKindCounter': completionKindCounter.toJson(),
@@ -583,31 +582,43 @@
CompletionMetricsComputer(this.rootPath, this.options);
/// Compare the metrics when each feature is used in isolation.
- void compareIndividualFeatures() {
+ void compareIndividualFeatures({bool availableSuggestions = false}) {
var featureNames = FeatureComputer.featureNames;
var featureCount = featureNames.length;
for (var i = 0; i < featureCount; i++) {
var weights = List.filled(featureCount, 0.00);
weights[i] = 1.00;
- targetMetrics.add(CompletionMetrics(featureNames[i], enableFunction: () {
- FeatureComputer.featureWeights = weights;
- }, disableFunction: () {
- FeatureComputer.featureWeights = FeatureComputer.defaultFeatureWeights;
- }));
+ targetMetrics.add(CompletionMetrics(
+ featureNames[i],
+ availableSuggestions: availableSuggestions,
+ enableFunction: () {
+ FeatureComputer.featureWeights = weights;
+ },
+ disableFunction: () {
+ FeatureComputer.featureWeights =
+ FeatureComputer.defaultFeatureWeights;
+ },
+ ));
}
}
/// Compare the relevance [tables] to the default relevance tables.
- void compareRelevanceTables(List<RelevanceTables> tables) {
+ void compareRelevanceTables(List<RelevanceTables> tables,
+ {bool availableSuggestions = false}) {
assert(tables.isNotEmpty);
for (var tablePair in tables) {
- targetMetrics.add(CompletionMetrics(tablePair.name, enableFunction: () {
- elementKindRelevance = tablePair.elementKindRelevance;
- keywordRelevance = tablePair.keywordRelevance;
- }, disableFunction: () {
- elementKindRelevance = defaultElementKindRelevance;
- keywordRelevance = defaultKeywordRelevance;
- }));
+ targetMetrics.add(CompletionMetrics(
+ tablePair.name,
+ availableSuggestions: availableSuggestions,
+ enableFunction: () {
+ elementKindRelevance = tablePair.elementKindRelevance;
+ keywordRelevance = tablePair.keywordRelevance;
+ },
+ disableFunction: () {
+ elementKindRelevance = defaultElementKindRelevance;
+ keywordRelevance = defaultKeywordRelevance;
+ },
+ ));
}
}
@@ -616,16 +627,18 @@
// To compare two or more changes to completions, add a `CompletionMetrics`
// object with enable and disable functions to the list of `targetMetrics`.
targetMetrics.add(CompletionMetrics('shipping',
- enableFunction: null, disableFunction: null));
+ availableSuggestions: false,
+ enableFunction: null,
+ disableFunction: null));
// To compare two or more relevance tables, uncomment the line below and
// add the `RelevanceTables` to the list. The default relevance tables
// should not be included in the list.
-// compareRelevanceTables([]);
+// compareRelevanceTables([], availableSuggestions: false);
// To compare the relative benefit from each of the features, uncomment the
// line below.
-// compareIndividualFeatures();
+// compareIndividualFeatures(availableSuggestions: false);
final collection = AnalysisContextCollectionImpl(
includedPaths: [rootPath],
@@ -916,7 +929,10 @@
var computers = sources.toList();
var row = [computers.first.name];
for (var computer in computers) {
- row.add(computer.mean.toStringAsFixed(6));
+ var min = computer.min;
+ var mean = computer.mean.toStringAsFixed(6);
+ var max = computer.max;
+ row.add('$min, $mean, $max');
}
return row;
}
@@ -1097,7 +1113,7 @@
// suggestions if doComputeCompletionsFromAnalysisServer is true.
DeclarationsTracker? declarationsTracker;
protocol.CompletionAvailableSuggestionsParams? availableSuggestionsParams;
- if (options.availableSuggestions) {
+ if (targetMetrics.any((metrics) => metrics.availableSuggestions)) {
declarationsTracker = DeclarationsTracker(
MemoryByteStore(), PhysicalResourceProvider.INSTANCE);
declarationsTracker.addContext(context);
@@ -1177,8 +1193,10 @@
listener,
performance,
request,
- declarationsTracker,
- availableSuggestionsParams,
+ metrics.availableSuggestions ? declarationsTracker : null,
+ metrics.availableSuggestions
+ ? availableSuggestionsParams
+ : null,
);
},
);
@@ -1391,10 +1409,6 @@
/// The options specified on the command-line.
class CompletionMetricsOptions {
- /// A flag that causes the available suggestion sets to be used while
- /// computing suggestions.
- static const String AVAILABLE_SUGGESTIONS = 'available-suggestions';
-
/// An option to control whether and how overlays should be produced.
static const String OVERLAY = 'overlay';
@@ -1438,10 +1452,6 @@
/// that had the worst mrr scores.
static const String PRINT_WORST_RESULTS = 'print-worst-results';
- /// A flag indicating whether available suggestions should be enabled for this
- /// run.
- final bool availableSuggestions;
-
/// The overlay mode that should be used.
final String overlay;
@@ -1474,7 +1484,6 @@
factory CompletionMetricsOptions(results) {
return CompletionMetricsOptions._(
- availableSuggestions: results[AVAILABLE_SUGGESTIONS],
overlay: results[OVERLAY],
printMissedCompletionDetails: results[PRINT_MISSED_COMPLETION_DETAILS],
printMissedCompletionSummary: results[PRINT_MISSED_COMPLETION_SUMMARY],
@@ -1485,8 +1494,7 @@
}
CompletionMetricsOptions._(
- {required this.availableSuggestions,
- required this.overlay,
+ {required this.overlay,
required this.printMissedCompletionDetails,
required this.printMissedCompletionSummary,
required this.printMissingInformation,
diff --git a/pkg/analysis_server/tool/code_completion/metrics_util.dart b/pkg/analysis_server/tool/code_completion/metrics_util.dart
index 00364e9..c3b01717 100644
--- a/pkg/analysis_server/tool/code_completion/metrics_util.dart
+++ b/pkg/analysis_server/tool/code_completion/metrics_util.dart
@@ -2,6 +2,8 @@
// 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:math' as math;
+
import 'package:analysis_server/src/status/pages.dart';
import 'package:analyzer/src/generated/utilities_general.dart';
@@ -10,22 +12,28 @@
/// https://en.wikipedia.org/wiki/Average#Arithmetic_mean
class ArithmeticMeanComputer {
final String name;
- num sum = 0;
+ int sum = 0;
int count = 0;
+ int? min;
+ int? max;
ArithmeticMeanComputer(this.name);
- num get mean => sum / count;
+ double get mean => sum / count;
/// Add the data from the given [computer] to this computer.
void addData(ArithmeticMeanComputer computer) {
sum += computer.sum;
count += computer.count;
+ min = _min(min, computer.min);
+ max = _max(max, computer.max);
}
- void addValue(num val) {
+ void addValue(int val) {
sum += val;
count++;
+ min = _min(min, val);
+ max = _max(max, val);
}
void clear() {
@@ -36,8 +44,10 @@
/// Set the state of this computer to the state recorded in the decoded JSON
/// [map].
void fromJson(Map<String, dynamic> map) {
- sum = map['sum'] as num;
+ sum = map['sum'] as int;
count = map['count'] as int;
+ min = map['min'] as int?;
+ max = map['max'] as int?;
}
void printMean() {
@@ -49,8 +59,30 @@
return {
'sum': sum,
'count': count,
+ if (min != null) 'min': min,
+ if (max != null) 'max': max,
};
}
+
+ int? _max(int? first, int? second) {
+ if (first == null) {
+ return second;
+ } else if (second == null) {
+ return first;
+ } else {
+ return math.max(first, second);
+ }
+ }
+
+ int? _min(int? first, int? second) {
+ if (first == null) {
+ return second;
+ } else if (second == null) {
+ return first;
+ } else {
+ return math.min(first, second);
+ }
+ }
}
/// A simple counter class. A [String] name is passed to name the counter. Each
diff --git a/pkg/front_end/lib/src/fasta/kernel/constant_evaluator.dart b/pkg/front_end/lib/src/fasta/kernel/constant_evaluator.dart
index 57ba7b1..d6e8775 100644
--- a/pkg/front_end/lib/src/fasta/kernel/constant_evaluator.dart
+++ b/pkg/front_end/lib/src/fasta/kernel/constant_evaluator.dart
@@ -2475,6 +2475,13 @@
interfaceTarget: node.interfaceTarget));
} else if (receiver is NullConstant) {
return createErrorConstant(node, messageConstEvalNullValue);
+ } else if (receiver is InstanceConstant && enableConstFunctions) {
+ for (final Reference fieldRef in receiver.fieldValues.keys) {
+ final Field field = fieldRef.asField;
+ if (field.name == node.name) {
+ return receiver.fieldValues[fieldRef];
+ }
+ }
}
return createErrorConstant(
node,
@@ -2588,6 +2595,13 @@
}
return receiver.entries.single;
}
+ } else if (receiver is InstanceConstant && enableConstFunctions) {
+ for (final Reference fieldRef in receiver.fieldValues.keys) {
+ final Field field = fieldRef.asField;
+ if (field.name == node.name) {
+ return receiver.fieldValues[fieldRef];
+ }
+ }
}
return createErrorConstant(
node,
diff --git a/pkg/front_end/testcases/const_functions/const_functions_instance_fields.dart b/pkg/front_end/testcases/const_functions/const_functions_instance_fields.dart
new file mode 100644
index 0000000..10e2d24
--- /dev/null
+++ b/pkg/front_end/testcases/const_functions/const_functions_instance_fields.dart
@@ -0,0 +1,49 @@
+// 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.
+
+// Tests instance field usage with const functions.
+
+import "package:expect/expect.dart";
+
+class A {
+ final int y;
+
+ const A(this.y);
+}
+
+const var1 = fn();
+int fn() => const A(1).y;
+
+const var2 = fn2();
+int fn2() {
+ var x = const A(1);
+ return x.y;
+}
+
+const var3 = const A(1).y;
+
+class B extends A {
+ const B(int x) : super(x);
+}
+
+const var4 = fn4();
+int fn4() => const B(1).y;
+
+class C extends A {
+ @override
+ final int y = 2;
+
+ const C() : super(100);
+}
+
+const var5 = fn5();
+int fn5() => const C().y;
+
+void main() {
+ Expect.equals(var1, 1);
+ Expect.equals(var2, 1);
+ Expect.equals(var3, 1);
+ Expect.equals(var4, 1);
+ Expect.equals(var5, 2);
+}
diff --git a/pkg/front_end/testcases/const_functions/const_functions_instance_fields.dart.strong.expect b/pkg/front_end/testcases/const_functions/const_functions_instance_fields.dart.strong.expect
new file mode 100644
index 0000000..265d81d
--- /dev/null
+++ b/pkg/front_end/testcases/const_functions/const_functions_instance_fields.dart.strong.expect
@@ -0,0 +1,65 @@
+library /*isNonNullableByDefault*/;
+import self as self;
+import "dart:core" as core;
+import "package:expect/expect.dart" as exp;
+
+import "package:expect/expect.dart";
+
+class A extends core::Object /*hasConstConstructor*/ {
+ final field core::int y;
+ const constructor •(core::int y) → self::A
+ : self::A::y = y, super core::Object::•()
+ ;
+}
+class B extends self::A /*hasConstConstructor*/ {
+ const constructor •(core::int x) → self::B
+ : super self::A::•(x)
+ ;
+}
+class C extends self::A /*hasConstConstructor*/ {
+ @#C1
+ final field core::int y = 2;
+ const constructor •() → self::C
+ : super self::A::•(100)
+ ;
+}
+static const field core::int var1 = #C2;
+static const field core::int var2 = #C2;
+static const field core::int var3 = #C2;
+static const field core::int var4 = #C2;
+static const field core::int var5 = #C3;
+static method fn() → core::int
+ return (#C4).{self::A::y};
+static method fn2() → core::int {
+ self::A x = #C4;
+ return x.{self::A::y};
+}
+static method fn4() → core::int
+ return (#C5).{self::A::y};
+static method fn5() → core::int
+ return (#C7).{self::C::y};
+static method main() → void {
+ exp::Expect::equals(#C2, 1);
+ exp::Expect::equals(#C2, 1);
+ exp::Expect::equals(#C2, 1);
+ exp::Expect::equals(#C2, 1);
+ exp::Expect::equals(#C3, 2);
+}
+
+constants {
+ #C1 = core::_Override {}
+ #C2 = 1
+ #C3 = 2
+ #C4 = self::A {y:#C2}
+ #C5 = self::B {y:#C2}
+ #C6 = 100
+ #C7 = self::C {y:#C3, y:#C6}
+}
+
+
+Constructor coverage from constants:
+org-dartlang-testcase:///const_functions_instance_fields.dart:
+- A. (from org-dartlang-testcase:///const_functions_instance_fields.dart:12:9)
+- Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9)
+- B. (from org-dartlang-testcase:///const_functions_instance_fields.dart:27:9)
+- C. (from org-dartlang-testcase:///const_functions_instance_fields.dart:37:9)
diff --git a/pkg/front_end/testcases/const_functions/const_functions_instance_fields.dart.strong.transformed.expect b/pkg/front_end/testcases/const_functions/const_functions_instance_fields.dart.strong.transformed.expect
new file mode 100644
index 0000000..265d81d
--- /dev/null
+++ b/pkg/front_end/testcases/const_functions/const_functions_instance_fields.dart.strong.transformed.expect
@@ -0,0 +1,65 @@
+library /*isNonNullableByDefault*/;
+import self as self;
+import "dart:core" as core;
+import "package:expect/expect.dart" as exp;
+
+import "package:expect/expect.dart";
+
+class A extends core::Object /*hasConstConstructor*/ {
+ final field core::int y;
+ const constructor •(core::int y) → self::A
+ : self::A::y = y, super core::Object::•()
+ ;
+}
+class B extends self::A /*hasConstConstructor*/ {
+ const constructor •(core::int x) → self::B
+ : super self::A::•(x)
+ ;
+}
+class C extends self::A /*hasConstConstructor*/ {
+ @#C1
+ final field core::int y = 2;
+ const constructor •() → self::C
+ : super self::A::•(100)
+ ;
+}
+static const field core::int var1 = #C2;
+static const field core::int var2 = #C2;
+static const field core::int var3 = #C2;
+static const field core::int var4 = #C2;
+static const field core::int var5 = #C3;
+static method fn() → core::int
+ return (#C4).{self::A::y};
+static method fn2() → core::int {
+ self::A x = #C4;
+ return x.{self::A::y};
+}
+static method fn4() → core::int
+ return (#C5).{self::A::y};
+static method fn5() → core::int
+ return (#C7).{self::C::y};
+static method main() → void {
+ exp::Expect::equals(#C2, 1);
+ exp::Expect::equals(#C2, 1);
+ exp::Expect::equals(#C2, 1);
+ exp::Expect::equals(#C2, 1);
+ exp::Expect::equals(#C3, 2);
+}
+
+constants {
+ #C1 = core::_Override {}
+ #C2 = 1
+ #C3 = 2
+ #C4 = self::A {y:#C2}
+ #C5 = self::B {y:#C2}
+ #C6 = 100
+ #C7 = self::C {y:#C3, y:#C6}
+}
+
+
+Constructor coverage from constants:
+org-dartlang-testcase:///const_functions_instance_fields.dart:
+- A. (from org-dartlang-testcase:///const_functions_instance_fields.dart:12:9)
+- Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9)
+- B. (from org-dartlang-testcase:///const_functions_instance_fields.dart:27:9)
+- C. (from org-dartlang-testcase:///const_functions_instance_fields.dart:37:9)
diff --git a/pkg/front_end/testcases/const_functions/const_functions_instance_fields.dart.textual_outline.expect b/pkg/front_end/testcases/const_functions/const_functions_instance_fields.dart.textual_outline.expect
new file mode 100644
index 0000000..2fd2287
--- /dev/null
+++ b/pkg/front_end/testcases/const_functions/const_functions_instance_fields.dart.textual_outline.expect
@@ -0,0 +1,29 @@
+import "package:expect/expect.dart";
+
+class A {
+ final int y;
+ const A(this.y);
+}
+
+const var1 = fn();
+int fn() => const A(1).y;
+const var2 = fn2();
+int fn2() {}
+const var3 = const A(1).y;
+
+class B extends A {
+ const B(int x) : super(x);
+}
+
+const var4 = fn4();
+int fn4() => const B(1).y;
+
+class C extends A {
+ @override
+ final int y = 2;
+ const C() : super(100);
+}
+
+const var5 = fn5();
+int fn5() => const C().y;
+void main() {}
diff --git a/pkg/front_end/testcases/const_functions/const_functions_instance_fields.dart.textual_outline_modelled.expect b/pkg/front_end/testcases/const_functions/const_functions_instance_fields.dart.textual_outline_modelled.expect
new file mode 100644
index 0000000..482e50e
--- /dev/null
+++ b/pkg/front_end/testcases/const_functions/const_functions_instance_fields.dart.textual_outline_modelled.expect
@@ -0,0 +1,27 @@
+import "package:expect/expect.dart";
+
+class A {
+ const A(this.y);
+ final int y;
+}
+
+class B extends A {
+ const B(int x) : super(x);
+}
+
+class C extends A {
+ const C() : super(100);
+ @override
+ final int y = 2;
+}
+
+const var1 = fn();
+const var2 = fn2();
+const var3 = const A(1).y;
+const var4 = fn4();
+const var5 = fn5();
+int fn() => const A(1).y;
+int fn2() {}
+int fn4() => const B(1).y;
+int fn5() => const C().y;
+void main() {}
diff --git a/pkg/front_end/testcases/const_functions/const_functions_instance_fields.dart.weak.expect b/pkg/front_end/testcases/const_functions/const_functions_instance_fields.dart.weak.expect
new file mode 100644
index 0000000..265d81d
--- /dev/null
+++ b/pkg/front_end/testcases/const_functions/const_functions_instance_fields.dart.weak.expect
@@ -0,0 +1,65 @@
+library /*isNonNullableByDefault*/;
+import self as self;
+import "dart:core" as core;
+import "package:expect/expect.dart" as exp;
+
+import "package:expect/expect.dart";
+
+class A extends core::Object /*hasConstConstructor*/ {
+ final field core::int y;
+ const constructor •(core::int y) → self::A
+ : self::A::y = y, super core::Object::•()
+ ;
+}
+class B extends self::A /*hasConstConstructor*/ {
+ const constructor •(core::int x) → self::B
+ : super self::A::•(x)
+ ;
+}
+class C extends self::A /*hasConstConstructor*/ {
+ @#C1
+ final field core::int y = 2;
+ const constructor •() → self::C
+ : super self::A::•(100)
+ ;
+}
+static const field core::int var1 = #C2;
+static const field core::int var2 = #C2;
+static const field core::int var3 = #C2;
+static const field core::int var4 = #C2;
+static const field core::int var5 = #C3;
+static method fn() → core::int
+ return (#C4).{self::A::y};
+static method fn2() → core::int {
+ self::A x = #C4;
+ return x.{self::A::y};
+}
+static method fn4() → core::int
+ return (#C5).{self::A::y};
+static method fn5() → core::int
+ return (#C7).{self::C::y};
+static method main() → void {
+ exp::Expect::equals(#C2, 1);
+ exp::Expect::equals(#C2, 1);
+ exp::Expect::equals(#C2, 1);
+ exp::Expect::equals(#C2, 1);
+ exp::Expect::equals(#C3, 2);
+}
+
+constants {
+ #C1 = core::_Override {}
+ #C2 = 1
+ #C3 = 2
+ #C4 = self::A {y:#C2}
+ #C5 = self::B {y:#C2}
+ #C6 = 100
+ #C7 = self::C {y:#C3, y:#C6}
+}
+
+
+Constructor coverage from constants:
+org-dartlang-testcase:///const_functions_instance_fields.dart:
+- A. (from org-dartlang-testcase:///const_functions_instance_fields.dart:12:9)
+- Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9)
+- B. (from org-dartlang-testcase:///const_functions_instance_fields.dart:27:9)
+- C. (from org-dartlang-testcase:///const_functions_instance_fields.dart:37:9)
diff --git a/pkg/front_end/testcases/const_functions/const_functions_instance_fields.dart.weak.outline.expect b/pkg/front_end/testcases/const_functions/const_functions_instance_fields.dart.weak.outline.expect
new file mode 100644
index 0000000..4d35f82
--- /dev/null
+++ b/pkg/front_end/testcases/const_functions/const_functions_instance_fields.dart.weak.outline.expect
@@ -0,0 +1,45 @@
+library /*isNonNullableByDefault*/;
+import self as self;
+import "dart:core" as core;
+
+import "package:expect/expect.dart";
+
+class A extends core::Object /*hasConstConstructor*/ {
+ final field core::int y;
+ const constructor •(core::int y) → self::A
+ : self::A::y = y, super core::Object::•()
+ ;
+}
+class B extends self::A /*hasConstConstructor*/ {
+ const constructor •(core::int x) → self::B
+ : super self::A::•(x)
+ ;
+}
+class C extends self::A /*hasConstConstructor*/ {
+ @core::override
+ final field core::int y = 2;
+ const constructor •() → self::C
+ : super self::A::•(100)
+ ;
+}
+static const field core::int var1 = self::fn();
+static const field core::int var2 = self::fn2();
+static const field core::int var3 = const self::A::•(1).{self::A::y};
+static const field core::int var4 = self::fn4();
+static const field core::int var5 = self::fn5();
+static method fn() → core::int
+ ;
+static method fn2() → core::int
+ ;
+static method fn4() → core::int
+ ;
+static method fn5() → core::int
+ ;
+static method main() → void
+ ;
+
+
+Extra constant evaluation status:
+Evaluated: StaticGet @ org-dartlang-testcase:///const_functions_instance_fields.dart:34:4 -> InstanceConstant(const _Override{})
+Evaluated: ConstructorInvocation @ org-dartlang-testcase:///const_functions_instance_fields.dart:24:20 -> InstanceConstant(const A{A.y: 1})
+Extra constant evaluation: evaluated: 9, effectively constant: 2
diff --git a/pkg/front_end/testcases/const_functions/const_functions_instance_fields.dart.weak.transformed.expect b/pkg/front_end/testcases/const_functions/const_functions_instance_fields.dart.weak.transformed.expect
new file mode 100644
index 0000000..265d81d
--- /dev/null
+++ b/pkg/front_end/testcases/const_functions/const_functions_instance_fields.dart.weak.transformed.expect
@@ -0,0 +1,65 @@
+library /*isNonNullableByDefault*/;
+import self as self;
+import "dart:core" as core;
+import "package:expect/expect.dart" as exp;
+
+import "package:expect/expect.dart";
+
+class A extends core::Object /*hasConstConstructor*/ {
+ final field core::int y;
+ const constructor •(core::int y) → self::A
+ : self::A::y = y, super core::Object::•()
+ ;
+}
+class B extends self::A /*hasConstConstructor*/ {
+ const constructor •(core::int x) → self::B
+ : super self::A::•(x)
+ ;
+}
+class C extends self::A /*hasConstConstructor*/ {
+ @#C1
+ final field core::int y = 2;
+ const constructor •() → self::C
+ : super self::A::•(100)
+ ;
+}
+static const field core::int var1 = #C2;
+static const field core::int var2 = #C2;
+static const field core::int var3 = #C2;
+static const field core::int var4 = #C2;
+static const field core::int var5 = #C3;
+static method fn() → core::int
+ return (#C4).{self::A::y};
+static method fn2() → core::int {
+ self::A x = #C4;
+ return x.{self::A::y};
+}
+static method fn4() → core::int
+ return (#C5).{self::A::y};
+static method fn5() → core::int
+ return (#C7).{self::C::y};
+static method main() → void {
+ exp::Expect::equals(#C2, 1);
+ exp::Expect::equals(#C2, 1);
+ exp::Expect::equals(#C2, 1);
+ exp::Expect::equals(#C2, 1);
+ exp::Expect::equals(#C3, 2);
+}
+
+constants {
+ #C1 = core::_Override {}
+ #C2 = 1
+ #C3 = 2
+ #C4 = self::A {y:#C2}
+ #C5 = self::B {y:#C2}
+ #C6 = 100
+ #C7 = self::C {y:#C3, y:#C6}
+}
+
+
+Constructor coverage from constants:
+org-dartlang-testcase:///const_functions_instance_fields.dart:
+- A. (from org-dartlang-testcase:///const_functions_instance_fields.dart:12:9)
+- Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9)
+- B. (from org-dartlang-testcase:///const_functions_instance_fields.dart:27:9)
+- C. (from org-dartlang-testcase:///const_functions_instance_fields.dart:37:9)
diff --git a/pkg/vm_snapshot_analysis/CHANGELOG.md b/pkg/vm_snapshot_analysis/CHANGELOG.md
index b011f35..9da6e6a1 100644
--- a/pkg/vm_snapshot_analysis/CHANGELOG.md
+++ b/pkg/vm_snapshot_analysis/CHANGELOG.md
@@ -1,5 +1,9 @@
# Changelog
+## 0.7.0
+
+- Migrate to null-safety.
+
## 0.6.0
- Update to latest args, path, meta dependency.
diff --git a/pkg/vm_snapshot_analysis/pubspec.yaml b/pkg/vm_snapshot_analysis/pubspec.yaml
index 3a37d38..ba6357d 100644
--- a/pkg/vm_snapshot_analysis/pubspec.yaml
+++ b/pkg/vm_snapshot_analysis/pubspec.yaml
@@ -1,6 +1,6 @@
name: vm_snapshot_analysis
description: Utilities for analysing AOT snapshot size.
-version: 0.6.0
+version: 0.7.0
homepage: https://github.com/dart-lang/sdk/tree/master/pkg/vm_snapshot_analysis
diff --git a/runtime/vm/clustered_snapshot.cc b/runtime/vm/clustered_snapshot.cc
index f2047d6..3de7da8 100644
--- a/runtime/vm/clustered_snapshot.cc
+++ b/runtime/vm/clustered_snapshot.cc
@@ -384,24 +384,24 @@
if (!IsInternalVMdefinedClassId(class_id)) {
cls->untag()->host_instance_size_in_words_ = d->Read<int32_t>();
cls->untag()->host_next_field_offset_in_words_ = d->Read<int32_t>();
-#if !defined(DART_PRECOMPILED_RUNTIME)
+#if defined(DART_PRECOMPILER)
// Only one pair is serialized. The target field only exists when
- // DART_PRECOMPILED_RUNTIME is not defined
+ // DART_PRECOMPILER is defined
cls->untag()->target_instance_size_in_words_ =
cls->untag()->host_instance_size_in_words_;
cls->untag()->target_next_field_offset_in_words_ =
cls->untag()->host_next_field_offset_in_words_;
-#endif // !defined(DART_PRECOMPILED_RUNTIME)
+#endif // defined(DART_PRECOMPILER)
} else {
d->Read<int32_t>(); // Skip.
d->Read<int32_t>(); // Skip.
}
cls->untag()->host_type_arguments_field_offset_in_words_ =
d->Read<int32_t>();
-#if !defined(DART_PRECOMPILED_RUNTIME)
+#if defined(DART_PRECOMPILER)
cls->untag()->target_type_arguments_field_offset_in_words_ =
cls->untag()->host_type_arguments_field_offset_in_words_;
-#endif // !defined(DART_PRECOMPILED_RUNTIME)
+#endif // defined(DART_PRECOMPILER)
cls->untag()->num_type_arguments_ = d->Read<int16_t>();
cls->untag()->num_native_fields_ = d->Read<uint16_t>();
#if !defined(DART_PRECOMPILED_RUNTIME)
@@ -435,14 +435,14 @@
cls->untag()->host_next_field_offset_in_words_ = d->Read<int32_t>();
cls->untag()->host_type_arguments_field_offset_in_words_ =
d->Read<int32_t>();
-#if !defined(DART_PRECOMPILED_RUNTIME)
+#if defined(DART_PRECOMPILER)
cls->untag()->target_instance_size_in_words_ =
cls->untag()->host_instance_size_in_words_;
cls->untag()->target_next_field_offset_in_words_ =
cls->untag()->host_next_field_offset_in_words_;
cls->untag()->target_type_arguments_field_offset_in_words_ =
cls->untag()->host_type_arguments_field_offset_in_words_;
-#endif // !defined(DART_PRECOMPILED_RUNTIME)
+#endif // defined(DART_PRECOMPILER)
cls->untag()->num_type_arguments_ = d->Read<int16_t>();
cls->untag()->num_native_fields_ = d->Read<uint16_t>();
#if !defined(DART_PRECOMPILED_RUNTIME)
@@ -3542,10 +3542,16 @@
host_next_field_offset_in_words_ =
cls->untag()->host_next_field_offset_in_words_;
ASSERT(host_next_field_offset_in_words_ > 0);
+#if defined(DART_PRECOMPILER)
target_next_field_offset_in_words_ =
cls->untag()->target_next_field_offset_in_words_;
target_instance_size_in_words_ =
cls->untag()->target_instance_size_in_words_;
+#else
+ target_next_field_offset_in_words_ =
+ cls->untag()->host_next_field_offset_in_words_;
+ target_instance_size_in_words_ = cls->untag()->host_instance_size_in_words_;
+#endif // defined(DART_PRECOMPILER)
ASSERT(target_next_field_offset_in_words_ > 0);
ASSERT(target_instance_size_in_words_ > 0);
}
diff --git a/runtime/vm/compiler/runtime_offsets_extracted.h b/runtime/vm/compiler/runtime_offsets_extracted.h
index 1b857f5..abe8cc9 100644
--- a/runtime/vm/compiler/runtime_offsets_extracted.h
+++ b/runtime/vm/compiler/runtime_offsets_extracted.h
@@ -471,7 +471,7 @@
static constexpr dart::compiler::target::word Array_header_size = 12;
static constexpr dart::compiler::target::word Bool_InstanceSize = 8;
static constexpr dart::compiler::target::word Capability_InstanceSize = 16;
-static constexpr dart::compiler::target::word Class_InstanceSize = 124;
+static constexpr dart::compiler::target::word Class_InstanceSize = 112;
static constexpr dart::compiler::target::word Closure_InstanceSize = 28;
static constexpr dart::compiler::target::word ClosureData_InstanceSize = 24;
static constexpr dart::compiler::target::word CodeSourceMap_HeaderSize = 8;
@@ -1013,7 +1013,7 @@
static constexpr dart::compiler::target::word Array_header_size = 24;
static constexpr dart::compiler::target::word Bool_InstanceSize = 16;
static constexpr dart::compiler::target::word Capability_InstanceSize = 16;
-static constexpr dart::compiler::target::word Class_InstanceSize = 200;
+static constexpr dart::compiler::target::word Class_InstanceSize = 192;
static constexpr dart::compiler::target::word Closure_InstanceSize = 56;
static constexpr dart::compiler::target::word ClosureData_InstanceSize = 48;
static constexpr dart::compiler::target::word CodeSourceMap_HeaderSize = 16;
@@ -1545,7 +1545,7 @@
static constexpr dart::compiler::target::word Array_header_size = 12;
static constexpr dart::compiler::target::word Bool_InstanceSize = 8;
static constexpr dart::compiler::target::word Capability_InstanceSize = 16;
-static constexpr dart::compiler::target::word Class_InstanceSize = 124;
+static constexpr dart::compiler::target::word Class_InstanceSize = 112;
static constexpr dart::compiler::target::word Closure_InstanceSize = 28;
static constexpr dart::compiler::target::word ClosureData_InstanceSize = 24;
static constexpr dart::compiler::target::word CodeSourceMap_HeaderSize = 8;
@@ -2088,7 +2088,7 @@
static constexpr dart::compiler::target::word Array_header_size = 24;
static constexpr dart::compiler::target::word Bool_InstanceSize = 16;
static constexpr dart::compiler::target::word Capability_InstanceSize = 16;
-static constexpr dart::compiler::target::word Class_InstanceSize = 200;
+static constexpr dart::compiler::target::word Class_InstanceSize = 192;
static constexpr dart::compiler::target::word Closure_InstanceSize = 56;
static constexpr dart::compiler::target::word ClosureData_InstanceSize = 48;
static constexpr dart::compiler::target::word CodeSourceMap_HeaderSize = 16;
@@ -2629,7 +2629,7 @@
static constexpr dart::compiler::target::word Array_header_size = 24;
static constexpr dart::compiler::target::word Bool_InstanceSize = 16;
static constexpr dart::compiler::target::word Capability_InstanceSize = 16;
-static constexpr dart::compiler::target::word Class_InstanceSize = 128;
+static constexpr dart::compiler::target::word Class_InstanceSize = 120;
static constexpr dart::compiler::target::word Closure_InstanceSize = 56;
static constexpr dart::compiler::target::word ClosureData_InstanceSize = 32;
static constexpr dart::compiler::target::word CodeSourceMap_HeaderSize = 16;
@@ -3171,7 +3171,7 @@
static constexpr dart::compiler::target::word Array_header_size = 24;
static constexpr dart::compiler::target::word Bool_InstanceSize = 16;
static constexpr dart::compiler::target::word Capability_InstanceSize = 16;
-static constexpr dart::compiler::target::word Class_InstanceSize = 128;
+static constexpr dart::compiler::target::word Class_InstanceSize = 120;
static constexpr dart::compiler::target::word Closure_InstanceSize = 56;
static constexpr dart::compiler::target::word ClosureData_InstanceSize = 32;
static constexpr dart::compiler::target::word CodeSourceMap_HeaderSize = 16;
@@ -3702,7 +3702,7 @@
static constexpr dart::compiler::target::word Array_header_size = 12;
static constexpr dart::compiler::target::word Bool_InstanceSize = 8;
static constexpr dart::compiler::target::word Capability_InstanceSize = 16;
-static constexpr dart::compiler::target::word Class_InstanceSize = 120;
+static constexpr dart::compiler::target::word Class_InstanceSize = 108;
static constexpr dart::compiler::target::word Closure_InstanceSize = 28;
static constexpr dart::compiler::target::word ClosureData_InstanceSize = 24;
static constexpr dart::compiler::target::word CodeSourceMap_HeaderSize = 8;
@@ -4238,7 +4238,7 @@
static constexpr dart::compiler::target::word Array_header_size = 24;
static constexpr dart::compiler::target::word Bool_InstanceSize = 16;
static constexpr dart::compiler::target::word Capability_InstanceSize = 16;
-static constexpr dart::compiler::target::word Class_InstanceSize = 192;
+static constexpr dart::compiler::target::word Class_InstanceSize = 184;
static constexpr dart::compiler::target::word Closure_InstanceSize = 56;
static constexpr dart::compiler::target::word ClosureData_InstanceSize = 48;
static constexpr dart::compiler::target::word CodeSourceMap_HeaderSize = 16;
@@ -4764,7 +4764,7 @@
static constexpr dart::compiler::target::word Array_header_size = 12;
static constexpr dart::compiler::target::word Bool_InstanceSize = 8;
static constexpr dart::compiler::target::word Capability_InstanceSize = 16;
-static constexpr dart::compiler::target::word Class_InstanceSize = 120;
+static constexpr dart::compiler::target::word Class_InstanceSize = 108;
static constexpr dart::compiler::target::word Closure_InstanceSize = 28;
static constexpr dart::compiler::target::word ClosureData_InstanceSize = 24;
static constexpr dart::compiler::target::word CodeSourceMap_HeaderSize = 8;
@@ -5301,7 +5301,7 @@
static constexpr dart::compiler::target::word Array_header_size = 24;
static constexpr dart::compiler::target::word Bool_InstanceSize = 16;
static constexpr dart::compiler::target::word Capability_InstanceSize = 16;
-static constexpr dart::compiler::target::word Class_InstanceSize = 192;
+static constexpr dart::compiler::target::word Class_InstanceSize = 184;
static constexpr dart::compiler::target::word Closure_InstanceSize = 56;
static constexpr dart::compiler::target::word ClosureData_InstanceSize = 48;
static constexpr dart::compiler::target::word CodeSourceMap_HeaderSize = 16;
@@ -5836,7 +5836,7 @@
static constexpr dart::compiler::target::word Array_header_size = 24;
static constexpr dart::compiler::target::word Bool_InstanceSize = 16;
static constexpr dart::compiler::target::word Capability_InstanceSize = 16;
-static constexpr dart::compiler::target::word Class_InstanceSize = 128;
+static constexpr dart::compiler::target::word Class_InstanceSize = 112;
static constexpr dart::compiler::target::word Closure_InstanceSize = 56;
static constexpr dart::compiler::target::word ClosureData_InstanceSize = 32;
static constexpr dart::compiler::target::word CodeSourceMap_HeaderSize = 16;
@@ -6372,7 +6372,7 @@
static constexpr dart::compiler::target::word Array_header_size = 24;
static constexpr dart::compiler::target::word Bool_InstanceSize = 16;
static constexpr dart::compiler::target::word Capability_InstanceSize = 16;
-static constexpr dart::compiler::target::word Class_InstanceSize = 128;
+static constexpr dart::compiler::target::word Class_InstanceSize = 112;
static constexpr dart::compiler::target::word Closure_InstanceSize = 56;
static constexpr dart::compiler::target::word ClosureData_InstanceSize = 32;
static constexpr dart::compiler::target::word CodeSourceMap_HeaderSize = 16;
diff --git a/runtime/vm/dart.cc b/runtime/vm/dart.cc
index 0cc3e19..d389089 100644
--- a/runtime/vm/dart.cc
+++ b/runtime/vm/dart.cc
@@ -132,8 +132,16 @@
CHECK_OFFSET(Class::ArrayTraits::elements_start_offset(), \
Class##_elements_start_offset); \
CHECK_OFFSET(Class::ArrayTraits::kElementSize, Class##_element_size);
+#if defined(DART_PRECOMPILER)
+// Objects in precompiler may have extra fields only used during
+// precompilation (such as Class::target_instance_size_in_words_),
+// so size of objects in precompiler doesn't necessarily match
+// size of objects at run time.
+#define CHECK_SIZEOF(Class, Name, What)
+#else
#define CHECK_SIZEOF(Class, Name, What) \
CHECK_OFFSET(sizeof(What), Class##_##Name);
+#endif // defined(DART_PRECOMPILER)
#define CHECK_RANGE(Class, Getter, Type, First, Last, Filter) \
for (intptr_t i = static_cast<intptr_t>(First); \
i <= static_cast<intptr_t>(Last); i++) { \
diff --git a/runtime/vm/object.h b/runtime/vm/object.h
index 8a6fec2..9ddb727 100644
--- a/runtime/vm/object.h
+++ b/runtime/vm/object.h
@@ -941,23 +941,23 @@
}
intptr_t target_instance_size() const {
ASSERT(is_finalized() || is_prefinalized());
-#if !defined(DART_PRECOMPILED_RUNTIME)
+#if defined(DART_PRECOMPILER)
return (untag()->target_instance_size_in_words_ *
compiler::target::kWordSize);
#else
return host_instance_size();
-#endif // !defined(DART_PRECOMPILED_RUNTIME)
+#endif // defined(DART_PRECOMPILER)
}
static intptr_t host_instance_size(ClassPtr clazz) {
return (clazz->untag()->host_instance_size_in_words_ * kWordSize);
}
static intptr_t target_instance_size(ClassPtr clazz) {
-#if !defined(DART_PRECOMPILED_RUNTIME)
+#if defined(DART_PRECOMPILER)
return (clazz->untag()->target_instance_size_in_words_ *
compiler::target::kWordSize);
#else
return host_instance_size(clazz);
-#endif // !defined(DART_PRECOMPILED_RUNTIME)
+#endif // defined(DART_PRECOMPILER)
}
void set_instance_size(intptr_t host_value_in_bytes,
intptr_t target_value_in_bytes) const {
@@ -970,27 +970,26 @@
intptr_t target_value) const {
ASSERT(Utils::IsAligned((host_value * kWordSize), kObjectAlignment));
StoreNonPointer(&untag()->host_instance_size_in_words_, host_value);
-#if !defined(DART_PRECOMPILER)
- // Could be different only during cross-compilation.
- ASSERT_EQUAL(host_value, target_value);
-#endif // !defined(DART_PRECOMPILER)
-#if !defined(DART_PRECOMPILED_RUNTIME)
+#if defined(DART_PRECOMPILER)
ASSERT(Utils::IsAligned((target_value * compiler::target::kWordSize),
compiler::target::kObjectAlignment));
StoreNonPointer(&untag()->target_instance_size_in_words_, target_value);
-#endif // !defined(DART_PRECOMPILED_RUNTIME)
+#else
+ // Could be different only during cross-compilation.
+ ASSERT_EQUAL(host_value, target_value);
+#endif // defined(DART_PRECOMPILER)
}
intptr_t host_next_field_offset() const {
return untag()->host_next_field_offset_in_words_ * kWordSize;
}
intptr_t target_next_field_offset() const {
-#if !defined(DART_PRECOMPILED_RUNTIME)
+#if defined(DART_PRECOMPILER)
return untag()->target_next_field_offset_in_words_ *
compiler::target::kWordSize;
#else
return host_next_field_offset();
-#endif // !defined(DART_PRECOMPILED_RUNTIME)
+#endif // defined(DART_PRECOMPILER)
}
void set_next_field_offset(intptr_t host_value_in_bytes,
intptr_t target_value_in_bytes) const {
@@ -1006,11 +1005,7 @@
(!Utils::IsAligned((host_value * kWordSize), kObjectAlignment) &&
((host_value + 1) == untag()->host_instance_size_in_words_)));
StoreNonPointer(&untag()->host_next_field_offset_in_words_, host_value);
-#if !defined(DART_PRECOMPILER)
- // Could be different only during cross-compilation.
- ASSERT_EQUAL(host_value, target_value);
-#endif // !defined(DART_PRECOMPILER)
-#if !defined(DART_PRECOMPILED_RUNTIME)
+#if defined(DART_PRECOMPILER)
ASSERT((target_value == -1) ||
(Utils::IsAligned((target_value * compiler::target::kWordSize),
compiler::target::kObjectAlignment) &&
@@ -1019,7 +1014,10 @@
compiler::target::kObjectAlignment) &&
((target_value + 1) == untag()->target_instance_size_in_words_)));
StoreNonPointer(&untag()->target_next_field_offset_in_words_, target_value);
-#endif // !defined(DART_PRECOMPILED_RUNTIME)
+#else
+ // Could be different only during cross-compilation.
+ ASSERT_EQUAL(host_value, target_value);
+#endif // defined(DART_PRECOMPILER)
}
static bool is_valid_id(intptr_t value) {
@@ -1143,7 +1141,7 @@
return untag()->host_type_arguments_field_offset_in_words_ * kWordSize;
}
intptr_t target_type_arguments_field_offset() const {
-#if !defined(DART_PRECOMPILED_RUNTIME)
+#if defined(DART_PRECOMPILER)
ASSERT(is_type_finalized() || is_prefinalized());
if (untag()->target_type_arguments_field_offset_in_words_ ==
compiler::target::Class::kNoTypeArguments) {
@@ -1153,7 +1151,7 @@
compiler::target::kWordSize;
#else
return host_type_arguments_field_offset();
-#endif // !defined(DART_PRECOMPILED_RUNTIME)
+#endif // defined(DART_PRECOMPILER)
}
void set_type_arguments_field_offset(intptr_t host_value_in_bytes,
intptr_t target_value_in_bytes) const {
@@ -1175,14 +1173,13 @@
intptr_t target_value) const {
StoreNonPointer(&untag()->host_type_arguments_field_offset_in_words_,
host_value);
-#if !defined(DART_PRECOMPILER)
- // Could be different only during cross-compilation.
- ASSERT_EQUAL(host_value, target_value);
-#endif // !defined(DART_PRECOMPILER)
-#if !defined(DART_PRECOMPILED_RUNTIME)
+#if defined(DART_PRECOMPILER)
StoreNonPointer(&untag()->target_type_arguments_field_offset_in_words_,
target_value);
-#endif // !defined(DART_PRECOMPILED_RUNTIME)
+#else
+ // Could be different only during cross-compilation.
+ ASSERT_EQUAL(host_value, target_value);
+#endif // defined(DART_PRECOMPILER)
}
static intptr_t host_type_arguments_field_offset_in_words_offset() {
return OFFSET_OF(UntaggedClass, host_type_arguments_field_offset_in_words_);
@@ -1610,11 +1607,11 @@
}
static int32_t target_instance_size_in_words(const ClassPtr cls) {
-#if !defined(DART_PRECOMPILED_RUNTIME)
+#if defined(DART_PRECOMPILER)
return cls->untag()->target_instance_size_in_words_;
#else
return host_instance_size_in_words(cls);
-#endif // !defined(DART_PRECOMPILED_RUNTIME)
+#endif // defined(DART_PRECOMPILER)
}
static int32_t host_next_field_offset_in_words(const ClassPtr cls) {
@@ -1622,11 +1619,11 @@
}
static int32_t target_next_field_offset_in_words(const ClassPtr cls) {
-#if !defined(DART_PRECOMPILED_RUNTIME)
+#if defined(DART_PRECOMPILER)
return cls->untag()->target_next_field_offset_in_words_;
#else
return host_next_field_offset_in_words(cls);
-#endif // !defined(DART_PRECOMPILED_RUNTIME)
+#endif // defined(DART_PRECOMPILER)
}
static int32_t host_type_arguments_field_offset_in_words(const ClassPtr cls) {
@@ -1635,11 +1632,11 @@
static int32_t target_type_arguments_field_offset_in_words(
const ClassPtr cls) {
-#if !defined(DART_PRECOMPILED_RUNTIME)
+#if defined(DART_PRECOMPILER)
return cls->untag()->target_type_arguments_field_offset_in_words_;
#else
return host_type_arguments_field_offset_in_words(cls);
-#endif // !defined(DART_PRECOMPILED_RUNTIME)
+#endif // defined(DART_PRECOMPILER)
}
private:
@@ -9837,12 +9834,12 @@
template <std::memory_order order = std::memory_order_relaxed>
ObjectPtr At(intptr_t index) const {
- return untag()->element(index);
+ return untag()->element<order>(index);
}
template <std::memory_order order = std::memory_order_relaxed>
void SetAt(intptr_t index, const Object& value) const {
// TODO(iposva): Add storing NoSafepointScope.
- untag()->set_element(index, value.ptr());
+ untag()->set_element<order>(index, value.ptr());
}
// Access to the array with acquire release semantics.
diff --git a/runtime/vm/raw_object.h b/runtime/vm/raw_object.h
index 33003af..a50a643 100644
--- a/runtime/vm/raw_object.h
+++ b/runtime/vm/raw_object.h
@@ -1026,7 +1026,7 @@
// Offset of the next instance field.
int32_t host_next_field_offset_in_words_;
-#if !defined(DART_PRECOMPILED_RUNTIME)
+#if defined(DART_PRECOMPILER)
// Size if fixed len or 0 if variable len (target).
int32_t target_instance_size_in_words_;
@@ -1035,7 +1035,9 @@
// Offset of the next instance field (target).
int32_t target_next_field_offset_in_words_;
+#endif // defined(DART_PRECOMPILER)
+#if !defined(DART_PRECOMPILED_RUNTIME)
uint32_t kernel_offset_;
#endif // !defined(DART_PRECOMPILED_RUNTIME)
diff --git a/sdk/lib/async/zone.dart b/sdk/lib/async/zone.dart
index fe6dcf0..9301ce3 100644
--- a/sdk/lib/async/zone.dart
+++ b/sdk/lib/async/zone.dart
@@ -17,15 +17,6 @@
///
/// The [error] and [stackTrace] are the error and stack trace that
/// was uncaught in [zone].
-///
-/// The function must only access zone-related functionality through
-/// [self], [parent] or [zone].
-/// It should not depend on the current zone ([Zone.current]).
-///
-/// If the uncaught error handler throws, the error will be passed
-/// to `parent.handleUncaughtError`. If the thrown object is [error],
-/// the throw is considered a re-throw and the original [stackTrace]
-/// is retained. This allows an asynchronous error to leave the error zone.
typedef HandleUncaughtErrorHandler = void Function(Zone self,
ZoneDelegate parent, Zone zone, Object error, StackTrace stackTrace);
@@ -43,10 +34,6 @@
/// to call [f] in the current zone, [zone].
/// A custom handler can do things before, after or instead of
/// calling [f].
-///
-/// The function must only access zone-related functionality through
-/// [self], [parent] or [zone].
-/// It should not depend on the current zone ([Zone.current]).
typedef RunHandler = R Function<R>(
Zone self, ZoneDelegate parent, Zone zone, R Function() f);
@@ -64,10 +51,6 @@
/// to call [f] with argument [arg] in the current zone, [zone].
/// A custom handler can do things before, after or instead of
/// calling [f].
-///
-/// The function must only access zone-related functionality through
-/// [self], [parent] or [zone].
-/// It should not depend on the current zone ([Zone.current]).
typedef RunUnaryHandler = R Function<R, T>(
Zone self, ZoneDelegate parent, Zone zone, R Function(T arg) f, T arg);
@@ -85,10 +68,6 @@
/// to call [f] with arguments [arg1] and [arg2] in the current zone, [zone].
/// A custom handler can do things before, after or instead of
/// calling [f].
-///
-/// The function must only access zone-related functionality through
-/// [self], [parent] or [zone].
-/// It should not depend on the current zone ([Zone.current]).
typedef RunBinaryHandler = R Function<R, T1, T2>(Zone self, ZoneDelegate parent,
Zone zone, R Function(T1 arg1, T2 arg2) f, T1 arg1, T2 arg2);
@@ -106,10 +85,6 @@
/// or another function replacing [f],
/// typically by wrapping [f] in a function
/// which does something extra before and after invoking [f]
-///
-/// The function must only access zone-related functionality through
-/// [self], [parent] or [zone].
-/// It should not depend on the current zone ([Zone.current]).
typedef RegisterCallbackHandler = ZoneCallback<R> Function<R>(
Zone self, ZoneDelegate parent, Zone zone, R Function() f);
@@ -127,10 +102,6 @@
/// or another function replacing [f],
/// typically by wrapping [f] in a function
/// which does something extra before and after invoking [f]
-///
-/// The function must only access zone-related functionality through
-/// [self], [parent] or [zone].
-/// It should not depend on the current zone ([Zone.current]).
typedef RegisterUnaryCallbackHandler = ZoneUnaryCallback<R, T> Function<R, T>(
Zone self, ZoneDelegate parent, Zone zone, R Function(T arg) f);
@@ -166,12 +137,6 @@
/// to replace the original error and stack trace,
/// or an [AsyncError] containing a replacement error and stack trace
/// which will be used to replace the originals.
-///
-/// The error callback handler must not throw.
-///
-/// The function must only access zone-related functionality through
-/// [self], [parent] or [zone].
-/// It should not depend on the current zone ([Zone.current]).
typedef AsyncError? ErrorCallbackHandler(Zone self, ZoneDelegate parent,
Zone zone, Object error, StackTrace? stackTrace);
@@ -190,10 +155,6 @@
/// and then call `parent.scheduleMicrotask(zone, replacement)`.
/// or it can implement its own microtask scheduling queue, which typically
/// still depends on `parent.scheduleMicrotask` to as a way to get started.
-///
-/// The function must only access zone-related functionality through
-/// [self], [parent] or [zone].
-/// It should not depend on the current zone ([Zone.current]).
typedef void ScheduleMicrotaskHandler(
Zone self, ZoneDelegate parent, Zone zone, void f());
@@ -216,10 +177,6 @@
///
/// The function should return a [Timer] object which can be used
/// to inspect and control the scheduled timer callback.
-///
-/// The function must only access zone-related functionality through
-/// [self], [parent] or [zone].
-/// It should not depend on the current zone ([Zone.current]).
typedef Timer CreateTimerHandler(
Zone self, ZoneDelegate parent, Zone zone, Duration duration, void f());
@@ -242,10 +199,6 @@
///
/// The function should return a [Timer] object which can be used
/// to inspect and control the scheduled timer callbacks.
-///
-/// The function must only access zone-related functionality through
-/// [self], [parent] or [zone].
-/// It should not depend on the current zone ([Zone.current]).
typedef Timer CreatePeriodicTimerHandler(Zone self, ZoneDelegate parent,
Zone zone, Duration period, void f(Timer timer));
@@ -261,10 +214,6 @@
///
/// The custom handler can intercept print operations and
/// redirect them to other targets than the console.
-///
-/// The function must only access zone-related functionality through
-/// [self], [parent] or [zone].
-/// It should not depend on the current zone ([Zone.current]).
typedef void PrintHandler(
Zone self, ZoneDelegate parent, Zone zone, String line);
@@ -286,10 +235,6 @@
/// values before calling `parent.fork(zone, specification, zoneValues)`,
/// but it has to call the [parent]'s [ZoneDelegate.fork] in order
/// to create a valid [Zone] object.
-///
-/// The function must only access zone-related functionality through
-/// [self], [parent] or [zone].
-/// It should not depend on the current zone ([Zone.current]).
typedef Zone ForkHandler(Zone self, ZoneDelegate parent, Zone zone,
ZoneSpecification? specification, Map<Object?, Object?>? zoneValues);
@@ -970,7 +915,10 @@
_ZoneDelegate(this._delegationTarget);
void handleUncaughtError(Zone zone, Object error, StackTrace stackTrace) {
- _delegationTarget._processUncaughtError(zone, error, stackTrace);
+ var implementation = _delegationTarget._handleUncaughtError;
+ _Zone implZone = implementation.zone;
+ HandleUncaughtErrorHandler handler = implementation.function;
+ return handler(implZone, implZone._parentDelegate, zone, error, stackTrace);
}
R run<R>(Zone zone, R f()) {
@@ -1092,28 +1040,6 @@
return identical(this, otherZone) ||
identical(errorZone, otherZone.errorZone);
}
-
- void _processUncaughtError(Zone zone, Object error, StackTrace stackTrace) {
- var implementation = _handleUncaughtError;
- _Zone implZone = implementation.zone;
- if (identical(implZone, _rootZone)) {
- _rootHandleError(error, stackTrace);
- return;
- }
- HandleUncaughtErrorHandler handler = implementation.function;
- ZoneDelegate parentDelegate = implZone._parentDelegate;
- _Zone parentZone = implZone.parent!; // Not null for non-root zones.
- _Zone currentZone = Zone._current;
- try {
- Zone._current = parentZone;
- handler(implZone, parentDelegate, zone, error, stackTrace);
- Zone._current = currentZone;
- } catch (e, s) {
- Zone._current = currentZone;
- parentZone._processUncaughtError(
- implZone, e, identical(error, e) ? stackTrace : s);
- }
- }
}
class _CustomZone extends _Zone {
@@ -1309,7 +1235,11 @@
// Methods that can be customized by the zone specification.
void handleUncaughtError(Object error, StackTrace stackTrace) {
- _processUncaughtError(this, error, stackTrace);
+ var implementation = this._handleUncaughtError;
+ ZoneDelegate parentDelegate = implementation.zone._parentDelegate;
+ HandleUncaughtErrorHandler handler = implementation.function;
+ return handler(
+ implementation.zone, parentDelegate, this, error, stackTrace);
}
Zone fork(
@@ -1405,10 +1335,6 @@
void _rootHandleUncaughtError(Zone? self, ZoneDelegate? parent, Zone zone,
Object error, StackTrace stackTrace) {
- _rootHandleError(error, stackTrace);
-}
-
-void _rootHandleError(Object error, StackTrace stackTrace) {
_schedulePriorityAsyncCallback(() {
_rethrow(error, stackTrace);
});
diff --git a/tests/language/const_functions/const_functions_instance_fields_error_test.dart b/tests/language/const_functions/const_functions_instance_fields_error_test.dart
new file mode 100644
index 0000000..4f0bb9e
--- /dev/null
+++ b/tests/language/const_functions/const_functions_instance_fields_error_test.dart
@@ -0,0 +1,41 @@
+// 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.
+
+// Tests erroneous instance field usage with const functions.
+
+// SharedOptions=--enable-experiment=const-functions
+
+import "package:expect/expect.dart";
+
+class A {
+ final int y;
+
+ const A(this.y);
+}
+
+const var1 = fn();
+// ^^^^
+// [analyzer] COMPILE_TIME_ERROR.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE
+int fn() => const A(1).x;
+// ^
+// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_GETTER
+// [cfe] The getter 'x' isn't defined for the class 'A'.
+
+const var2 = fn2();
+// ^^^^^
+// [analyzer] COMPILE_TIME_ERROR.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE
+int fn2() {
+ var x = const A(1);
+ return x.x;
+ // ^
+ // [analyzer] COMPILE_TIME_ERROR.UNDEFINED_GETTER
+ // [cfe] The getter 'x' isn't defined for the class 'A'.
+}
+
+const var3 = const A(1).x;
+// ^^^^^^^^^^^^
+// [analyzer] COMPILE_TIME_ERROR.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE
+// ^
+// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_GETTER
+// [cfe] The getter 'x' isn't defined for the class 'A'.
diff --git a/tests/language/const_functions/const_functions_instance_fields_test.dart b/tests/language/const_functions/const_functions_instance_fields_test.dart
new file mode 100644
index 0000000..8db86c5
--- /dev/null
+++ b/tests/language/const_functions/const_functions_instance_fields_test.dart
@@ -0,0 +1,61 @@
+// 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.
+
+// Tests instance field usage with const functions.
+
+// SharedOptions=--enable-experiment=const-functions
+
+import "package:expect/expect.dart";
+
+class A {
+ final int y;
+
+ const A(this.y);
+}
+
+const var1 = fn();
+// ^^^^
+// [analyzer] COMPILE_TIME_ERROR.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE
+int fn() => const A(1).y;
+
+const var2 = fn2();
+// ^^^^^
+// [analyzer] COMPILE_TIME_ERROR.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE
+int fn2() {
+ var x = const A(1);
+ return x.y;
+}
+
+const var3 = const A(1).y;
+// ^^^^^^^^^^^^
+// [analyzer] COMPILE_TIME_ERROR.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE
+
+class B extends A {
+ const B(int x) : super(x);
+}
+
+const var4 = fn4();
+// ^^^^^
+// [analyzer] COMPILE_TIME_ERROR.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE
+int fn4() => const B(1).y;
+
+class C extends A {
+ @override
+ final int y = 2;
+
+ const C() : super(100);
+}
+
+const var5 = fn5();
+// ^^^^^
+// [analyzer] COMPILE_TIME_ERROR.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE
+int fn5() => const C().y;
+
+void main() {
+ Expect.equals(var1, 1);
+ Expect.equals(var2, 1);
+ Expect.equals(var3, 1);
+ Expect.equals(var4, 1);
+ Expect.equals(var5, 2);
+}
diff --git a/tests/lib/async/uncaught_error_handler_throws_test.dart b/tests/lib/async/uncaught_error_handler_throws_test.dart
deleted file mode 100644
index f70f098..0000000
--- a/tests/lib/async/uncaught_error_handler_throws_test.dart
+++ /dev/null
@@ -1,76 +0,0 @@
-// 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.
-
-import 'package:expect/expect.dart';
-import 'package:async_helper/async_helper.dart';
-import 'dart:async';
-
-void main() async {
- asyncStart();
- await testThrowSame();
- await testThrowOther();
- asyncEnd();
-}
-
-Future<void> testThrowSame() async {
- asyncStart();
- var object1 = Object();
- var stack1 = StackTrace.current;
- var outerZone = Zone.current;
- var firstZone = Zone.current.fork(specification: onError((error, stack) {
- // Uncaught error handlers run in the parent zone.
- Expect.identical(outerZone, Zone.current);
- Expect.identical(object1, error);
- Expect.identical(stack1, stack); // Get same stack trace.
- asyncEnd();
- }));
- firstZone.run(() async {
- Expect.identical(firstZone, Zone.current);
- var secondZone = Zone.current.fork(specification: onError((error, stack) {
- // Uncaught error handlers run in the parent zone.
- Expect.identical(firstZone, Zone.current);
- Expect.identical(object1, error);
- Expect.identical(stack1, stack);
- throw error; // Throw same object
- }));
- secondZone.run(() async {
- Expect.identical(secondZone, Zone.current);
- Future.error(object1, stack1); // Unhandled async error.
- await Future(() {});
- });
- });
-}
-
-Future<void> testThrowOther() async {
- asyncStart();
- var object1 = Object();
- var object2 = Object();
- var stack1 = StackTrace.current;
- var outerZone = Zone.current;
- var firstZone = Zone.current.fork(specification: onError((error, stack) {
- Expect.identical(outerZone, Zone.current);
- Expect.identical(object2, error);
- Expect.notIdentical(stack1, stack); // Get different stack trace.
- asyncEnd();
- }));
- firstZone.run(() async {
- Expect.identical(firstZone, Zone.current);
- var secondZone = Zone.current.fork(specification: onError((error, stack) {
- Expect.identical(firstZone, Zone.current);
- Expect.identical(object1, error);
- Expect.identical(stack1, stack);
- throw object2; // Throw different object
- }));
- secondZone.run(() async {
- Expect.identical(secondZone, Zone.current);
- Future.error(object1, stack1); // Unhandled async error.
- await Future(() {});
- });
- });
-}
-
-ZoneSpecification onError(void Function(Object, StackTrace) handler) {
- return ZoneSpecification(
- handleUncaughtError: (s, p, z, e, st) => handler(e, st));
-}
diff --git a/tests/lib_2/async/slow_consumer2_test.dart b/tests/lib_2/async/slow_consumer2_test.dart
index 23a001a..de37668 100644
--- a/tests/lib_2/async/slow_consumer2_test.dart
+++ b/tests/lib_2/async/slow_consumer2_test.dart
@@ -88,7 +88,7 @@
listSize -= sentCount - targetCount;
sentCount = targetCount;
}
- controller.add(new List<int>(listSize));
+ controller.add(new List(listSize));
int ms = listSize * 1000 ~/ bytesPerSecond;
Duration duration = new Duration(milliseconds: ms);
if (!controller.isPaused) new Timer(duration, send);
diff --git a/tests/lib_2/async/uncaught_error_handler_throws_test.dart b/tests/lib_2/async/uncaught_error_handler_throws_test.dart
deleted file mode 100644
index f70f098..0000000
--- a/tests/lib_2/async/uncaught_error_handler_throws_test.dart
+++ /dev/null
@@ -1,76 +0,0 @@
-// 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.
-
-import 'package:expect/expect.dart';
-import 'package:async_helper/async_helper.dart';
-import 'dart:async';
-
-void main() async {
- asyncStart();
- await testThrowSame();
- await testThrowOther();
- asyncEnd();
-}
-
-Future<void> testThrowSame() async {
- asyncStart();
- var object1 = Object();
- var stack1 = StackTrace.current;
- var outerZone = Zone.current;
- var firstZone = Zone.current.fork(specification: onError((error, stack) {
- // Uncaught error handlers run in the parent zone.
- Expect.identical(outerZone, Zone.current);
- Expect.identical(object1, error);
- Expect.identical(stack1, stack); // Get same stack trace.
- asyncEnd();
- }));
- firstZone.run(() async {
- Expect.identical(firstZone, Zone.current);
- var secondZone = Zone.current.fork(specification: onError((error, stack) {
- // Uncaught error handlers run in the parent zone.
- Expect.identical(firstZone, Zone.current);
- Expect.identical(object1, error);
- Expect.identical(stack1, stack);
- throw error; // Throw same object
- }));
- secondZone.run(() async {
- Expect.identical(secondZone, Zone.current);
- Future.error(object1, stack1); // Unhandled async error.
- await Future(() {});
- });
- });
-}
-
-Future<void> testThrowOther() async {
- asyncStart();
- var object1 = Object();
- var object2 = Object();
- var stack1 = StackTrace.current;
- var outerZone = Zone.current;
- var firstZone = Zone.current.fork(specification: onError((error, stack) {
- Expect.identical(outerZone, Zone.current);
- Expect.identical(object2, error);
- Expect.notIdentical(stack1, stack); // Get different stack trace.
- asyncEnd();
- }));
- firstZone.run(() async {
- Expect.identical(firstZone, Zone.current);
- var secondZone = Zone.current.fork(specification: onError((error, stack) {
- Expect.identical(firstZone, Zone.current);
- Expect.identical(object1, error);
- Expect.identical(stack1, stack);
- throw object2; // Throw different object
- }));
- secondZone.run(() async {
- Expect.identical(secondZone, Zone.current);
- Future.error(object1, stack1); // Unhandled async error.
- await Future(() {});
- });
- });
-}
-
-ZoneSpecification onError(void Function(Object, StackTrace) handler) {
- return ZoneSpecification(
- handleUncaughtError: (s, p, z, e, st) => handler(e, st));
-}
diff --git a/tools/VERSION b/tools/VERSION
index 0fcf872..e2b1bd9 100644
--- a/tools/VERSION
+++ b/tools/VERSION
@@ -27,5 +27,5 @@
MAJOR 2
MINOR 14
PATCH 0
-PRERELEASE 31
+PRERELEASE 32
PRERELEASE_PATCH 0
\ No newline at end of file