Version 2.12.0-275.0.dev
Merge commit '0c3696d76a4431e90216fb28453ad4fe693aa83d' into 'dev'
diff --git a/pkg/analysis_server/lib/src/services/refactoring/extract_widget.dart b/pkg/analysis_server/lib/src/services/refactoring/extract_widget.dart
index 389b739..9570680 100644
--- a/pkg/analysis_server/lib/src/services/refactoring/extract_widget.dart
+++ b/pkg/analysis_server/lib/src/services/refactoring/extract_widget.dart
@@ -428,8 +428,12 @@
// Add parameters for fields, local, and method parameters.
for (var parameter in _parameters) {
builder.write(' ');
- builder.write('@');
- builder.writeReference(accessorRequired);
+ if (_isNonNullable) {
+ builder.write('required');
+ } else {
+ builder.write('@');
+ builder.writeReference(accessorRequired);
+ }
builder.write(' ');
if (parameter.constructorName != parameter.name) {
builder.writeType(parameter.type);
diff --git a/pkg/analysis_server/test/services/refactoring/abstract_refactoring.dart b/pkg/analysis_server/test/services/refactoring/abstract_refactoring.dart
index 2338885..82eca0f 100644
--- a/pkg/analysis_server/test/services/refactoring/abstract_refactoring.dart
+++ b/pkg/analysis_server/test/services/refactoring/abstract_refactoring.dart
@@ -12,6 +12,7 @@
show RefactoringProblemSeverity, SourceChange, SourceEdit;
import 'package:test/test.dart';
+import '../../abstract_context.dart';
import '../../abstract_single_unit.dart';
int findIdentifierLength(String search) {
@@ -29,7 +30,8 @@
}
/// The base class for all [Refactoring] tests.
-abstract class RefactoringTest extends AbstractSingleUnitTest {
+abstract class RefactoringTest extends AbstractSingleUnitTest
+ with WithNonFunctionTypeAliasesMixin {
SearchEngine searchEngine;
SourceChange refactoringChange;
diff --git a/pkg/analysis_server/test/services/refactoring/convert_getter_to_method_test.dart b/pkg/analysis_server/test/services/refactoring/convert_getter_to_method_test.dart
index aa6c028..17c7103 100644
--- a/pkg/analysis_server/test/services/refactoring/convert_getter_to_method_test.dart
+++ b/pkg/analysis_server/test/services/refactoring/convert_getter_to_method_test.dart
@@ -56,7 +56,7 @@
class D extends A {
int get test => 4;
}
-main(A a, B b, C c, D d) {
+void f(A a, B b, C c, D d) {
var va = a.test;
var vb = b.test;
var vc = c.test;
@@ -79,7 +79,7 @@
class D extends A {
int test() => 4;
}
-main(A a, B b, C c, D d) {
+void f(A a, B b, C c, D d) {
var va = a.test();
var vb = b.test();
var vc = c.test();
@@ -99,7 +99,7 @@
class B extends A {
int get test => 2;
}
-main(A a, B b) {
+void f(A a, B b) {
a.test;
b.test;
}
@@ -112,7 +112,7 @@
class B extends A {
int test() => 2;
}
-main(A a, B b) {
+void f(A a, B b) {
a.test();
b.test();
}
diff --git a/pkg/analysis_server/test/services/refactoring/convert_method_to_getter_test.dart b/pkg/analysis_server/test/services/refactoring/convert_method_to_getter_test.dart
index 95e8ed2..7afbb5d 100644
--- a/pkg/analysis_server/test/services/refactoring/convert_method_to_getter_test.dart
+++ b/pkg/analysis_server/test/services/refactoring/convert_method_to_getter_test.dart
@@ -55,7 +55,7 @@
class D extends A {
int test() => 4;
}
-main(A a, B b, C c, D d) {
+void f(A a, B b, C c, D d) {
var va = a.test();
var vb = b.test();
var vc = c.test();
@@ -78,7 +78,7 @@
class D extends A {
int get test => 4;
}
-main(A a, B b, C c, D d) {
+void f(A a, B b, C c, D d) {
var va = a.test;
var vb = b.test;
var vc = c.test;
@@ -98,7 +98,7 @@
class B extends A {
int test() => 2;
}
-main(A a, B b) {
+void f(A a, B b) {
a.test();
b.test();
}
@@ -111,7 +111,7 @@
class B extends A {
int get test => 2;
}
-main(A a, B b) {
+void f(A a, B b) {
a.test;
b.test;
}
diff --git a/pkg/analysis_server/test/services/refactoring/extract_local_test.dart b/pkg/analysis_server/test/services/refactoring/extract_local_test.dart
index 4ffad65..4d5d5bf 100644
--- a/pkg/analysis_server/test/services/refactoring/extract_local_test.dart
+++ b/pkg/analysis_server/test/services/refactoring/extract_local_test.dart
@@ -245,7 +245,7 @@
await indexTestUnit('''
main() {
int a = 1 + 2;
- Res b = null;
+ Res? b = null;
}
class Res {}
@@ -698,7 +698,7 @@
Future<void> test_guessNames_singleExpression() async {
await indexTestUnit('''
class TreeItem {}
-TreeItem getSelectedItem() => null;
+TreeItem? getSelectedItem() => null;
process(my) {}
main() {
process(getSelectedItem()); // marker
@@ -760,21 +760,21 @@
Future<void> test_occurrences_differentName_samePrefix() async {
await indexTestUnit('''
-void main(A a) {
+void f(A a) {
if (a.foo != 1) {
} else if (a.foo2 != 2) {
}
}
class A {
- int foo;
- int foo2;
+ int? foo;
+ int? foo2;
}
''');
_createRefactoringWithSuffix('a.foo', ' != 1');
// apply refactoring
await _assertSuccessfulRefactoring('''
-void main(A a) {
+void f(A a) {
var res = a.foo;
if (res != 1) {
} else if (a.foo2 != 2) {
@@ -782,8 +782,8 @@
}
class A {
- int foo;
- int foo2;
+ int? foo;
+ int? foo2;
}
''');
}
@@ -1068,7 +1068,7 @@
Future<void> test_singleExpression_inExpressionBody_ofFunction() async {
await indexTestUnit('''
foo(Point p) => p.x * p.x + p.y * p.y;
-class Point {int x; int y;}
+class Point {int x = 0; int y = 0;}
''');
_createRefactoringForString('p.x');
// apply refactoring
@@ -1077,7 +1077,7 @@
var res = p.x;
return res * res + p.y * p.y;
}
-class Point {int x; int y;}
+class Point {int x = 0; int y = 0;}
''');
_assertSingleLinkedEditGroup(
length: 3, offsets: [21, 41, 47], names: ['x', 'i']);
@@ -1088,7 +1088,7 @@
class A {
foo(Point p) => p.x * p.x + p.y * p.y;
}
-class Point {int x; int y;}
+class Point {int x = 0; int y = 0;}
''');
_createRefactoringForString('p.x');
// apply refactoring
@@ -1099,7 +1099,7 @@
return res * res + p.y * p.y;
}
}
-class Point {int x; int y;}
+class Point {int x = 0; int y = 0;}
''');
_assertSingleLinkedEditGroup(
length: 3, offsets: [35, 57, 63], names: ['x', 'i']);
@@ -1107,7 +1107,7 @@
Future<void> test_singleExpression_inIfElseIf() async {
await indexTestUnit('''
-main(int p) {
+void f(int p) {
if (p == 1) {
print(1);
} else if (p == 2) {
@@ -1118,7 +1118,7 @@
_createRefactoringForString('2');
// apply refactoring
return _assertSuccessfulRefactoring('''
-main(int p) {
+void f(int p) {
var res = 2;
if (p == 1) {
print(1);
diff --git a/pkg/analysis_server/test/services/refactoring/extract_method_test.dart b/pkg/analysis_server/test/services/refactoring/extract_method_test.dart
index ff277f5..2396564 100644
--- a/pkg/analysis_server/test/services/refactoring/extract_method_test.dart
+++ b/pkg/analysis_server/test/services/refactoring/extract_method_test.dart
@@ -318,8 +318,8 @@
class A {
var fff;
}
-main() {
- A a;
+
+void f(A a) {
a.fff = 1;
}
''');
@@ -471,7 +471,7 @@
Future<void> test_bad_statements_exit_notAllExecutionFlows() async {
await indexTestUnit('''
-main(int p) {
+void f(int p) {
// start
if (p == 0) {
return;
@@ -704,7 +704,7 @@
Future<void> test_canExtractGetter_false_hasParameters() async {
await indexTestUnit('''
-main(int p) {
+void f(int p) {
int a = p + 1;
}
''');
@@ -718,7 +718,7 @@
Future<void> test_canExtractGetter_false_returnNotUsed_assignment() async {
await indexTestUnit('''
var topVar = 0;
-f(int p) {
+void f(int p) {
topVar = 5;
}
''');
@@ -897,7 +897,7 @@
Future<void> test_closure_atArgumentName() async {
await indexTestUnit('''
-void process({int fff(int x)}) {}
+void process({int fff(int x)?}) {}
class C {
main() {
process(fff: (int x) => x * 2);
@@ -907,7 +907,7 @@
_createRefactoring(findOffset('ff: (int x)'), 0);
// apply refactoring
return _assertSuccessfulRefactoring('''
-void process({int fff(int x)}) {}
+void process({int fff(int x)?}) {}
class C {
main() {
process(fff: res);
@@ -960,7 +960,7 @@
Future<void> test_closure_bad_referencesParameter() async {
await indexTestUnit('''
process(f(x)) {}
-main(int k) {
+void f(int k) {
process((x) => x * k);
}
''');
@@ -1114,7 +1114,7 @@
Future<void> test_names_singleExpression() async {
await indexTestUnit('''
class TreeItem {}
-TreeItem getSelectedItem() => null;
+TreeItem getSelectedItem() => throw 0;
process(my) {}
main() {
process(getSelectedItem()); // marker
@@ -1203,7 +1203,7 @@
Future<void> test_returnType_statements_nullMix() async {
await indexTestUnit('''
-main(bool p) {
+f(bool p) {
// start
if (p) {
return 42;
@@ -1291,7 +1291,7 @@
Future<void> test_singleExpression_coveringExpression() async {
await indexTestUnit('''
-main(int n) {
+void f(int n) {
var v = new FooBar(n);
}
@@ -1301,7 +1301,7 @@
''');
_createRefactoringForStringOffset('Bar(n);');
return _assertSuccessfulRefactoring('''
-main(int n) {
+void f(int n) {
var v = res(n);
}
@@ -1535,7 +1535,7 @@
Future<void> test_singleExpression_parameter_functionTypeAlias() async {
await indexTestUnit('''
typedef R Foo<S, R>(S s);
-void main(Foo<String, int> foo, String s) {
+void f(Foo<String, int> foo, String s) {
int a = foo(s);
}
''');
@@ -1543,7 +1543,7 @@
// apply refactoring
return _assertSuccessfulRefactoring('''
typedef R Foo<S, R>(S s);
-void main(Foo<String, int> foo, String s) {
+void f(Foo<String, int> foo, String s) {
int a = res(foo, s);
}
@@ -2298,7 +2298,7 @@
Future<void> test_statements_exit_throws() async {
await indexTestUnit('''
-main(int p) {
+void f(int p) {
// start
if (p == 0) {
return;
@@ -2376,7 +2376,7 @@
Future<void> test_statements_hasAwait_forEach() async {
await indexTestUnit('''
import 'dart:async';
-Stream<int> getValueStream() => null;
+Stream<int> getValueStream() => throw 0;
main() async {
// start
int sum = 0;
@@ -2391,7 +2391,7 @@
// apply refactoring
return _assertSuccessfulRefactoring('''
import 'dart:async';
-Stream<int> getValueStream() => null;
+Stream<int> getValueStream() => throw 0;
main() async {
// start
int sum = await res();
@@ -2672,7 +2672,7 @@
Future<void> test_statements_return_multiple_ifElse() async {
await indexTestUnit('''
-num main(bool b) {
+num f(bool b) {
// start
if (b) {
return 1;
@@ -2685,7 +2685,7 @@
_createRefactoringForStartEndComments();
// apply refactoring
return _assertSuccessfulRefactoring('''
-num main(bool b) {
+num f(bool b) {
// start
return res(b);
// end
@@ -2703,7 +2703,7 @@
Future<void> test_statements_return_multiple_ifThen() async {
await indexTestUnit('''
-num main(bool b) {
+num f(bool b) {
// start
if (b) {
return 1;
@@ -2715,7 +2715,7 @@
_createRefactoringForStartEndComments();
// apply refactoring
return _assertSuccessfulRefactoring('''
-num main(bool b) {
+num f(bool b) {
// start
return res(b);
// end
@@ -2761,7 +2761,7 @@
Future<void> test_statements_return_multiple_interfaceFunction() async {
await indexTestUnit('''
-main(bool b) {
+f(bool b) {
// start
if (b) {
return 1;
@@ -2773,7 +2773,7 @@
_createRefactoringForStartEndComments();
// apply refactoring
return _assertSuccessfulRefactoring('''
-main(bool b) {
+f(bool b) {
// start
return res(b);
// end
@@ -2791,7 +2791,7 @@
Future<void>
test_statements_return_multiple_sameElementDifferentTypeArgs() async {
await indexTestUnit('''
-main(bool b) {
+f(bool b) {
// start
if (b) {
print(true);
@@ -2806,7 +2806,7 @@
_createRefactoringForStartEndComments();
// apply refactoring
return _assertSuccessfulRefactoring('''
-main(bool b) {
+f(bool b) {
// start
return res(b);
// end
diff --git a/pkg/analysis_server/test/services/refactoring/extract_widget_test.dart b/pkg/analysis_server/test/services/refactoring/extract_widget_test.dart
index be25023..23d0d92 100644
--- a/pkg/analysis_server/test/services/refactoring/extract_widget_test.dart
+++ b/pkg/analysis_server/test/services/refactoring/extract_widget_test.dart
@@ -133,7 +133,7 @@
class Test extends StatelessWidget {
const Test({
- Key key,
+ Key? key,
}) : super(key: key);
@override
@@ -184,7 +184,7 @@
class Test extends StatelessWidget {
const Test({
- Key key,
+ Key? key,
}) : super(key: key);
@override
@@ -220,7 +220,7 @@
class Test extends StatelessWidget {
const Test({
- Key key,
+ Key? key,
}) : super(key: key);
@override
@@ -253,7 +253,7 @@
class Test extends StatelessWidget {
const Test({
- Key key,
+ Key? key,
}) : super(key: key);
@override
@@ -307,7 +307,7 @@
class Test extends StatelessWidget {
const Test({
- Key key,
+ Key? key,
}) : super(key: key);
@override
@@ -410,8 +410,8 @@
class Test extends StatelessWidget {
const Test({
- Key key,
- @required this.c,
+ Key? key,
+ required this.c,
}) : super(key: key);
final C c;
@@ -462,7 +462,7 @@
class Test extends StatelessWidget {
const Test({
- Key key,
+ Key? key,
}) : super(key: key);
@override
@@ -482,7 +482,7 @@
import 'package:flutter/material.dart';
class MyWidget extends StatelessWidget {
- String foo;
+ String foo = '';
@override
Widget build(BuildContext context) {
@@ -510,7 +510,7 @@
import 'package:flutter/material.dart';
class MyWidget extends StatelessWidget {
- String foo;
+ String foo = '';
@override
Widget build(BuildContext context) {
@@ -526,10 +526,10 @@
class Test extends StatelessWidget {
const Test({
- Key key,
- @required this.foo,
- @required this.p1,
- @required this.p2,
+ Key? key,
+ required this.foo,
+ required this.p1,
+ required this.p2,
}) : super(key: key);
final String foo;
@@ -548,12 +548,14 @@
''');
}
- Future<void> test_method_parameters_named() async {
+ Future<void> test_method_parameters_namedRequired() async {
await indexTestUnit(r'''
import 'package:flutter/material.dart';
class MyWidget extends StatelessWidget {
- String foo;
+ final String foo;
+
+ MyWidget(this.foo);
@override
Widget build(BuildContext context) {
@@ -566,7 +568,7 @@
);
}
- Widget createColumn({String p1, int p2}) {
+ Widget createColumn({required String p1, required int p2}) {
var a = new Text('$foo $p1');
var b = new Text('$p2');
return new Column(
@@ -575,13 +577,15 @@
}
}
''');
- _createRefactoringForStringOffset('createColumn({String');
+ _createRefactoringForStringOffset('createColumn({');
await _assertSuccessfulRefactoring(r'''
import 'package:flutter/material.dart';
class MyWidget extends StatelessWidget {
- String foo;
+ final String foo;
+
+ MyWidget(this.foo);
@override
Widget build(BuildContext context) {
@@ -597,10 +601,10 @@
class Test extends StatelessWidget {
const Test({
- Key key,
- @required this.foo,
- @required this.p1,
- @required this.p2,
+ Key? key,
+ required this.foo,
+ required this.p1,
+ required this.p2,
}) : super(key: key);
final String foo;
@@ -624,7 +628,9 @@
import 'package:flutter/material.dart';
class MyWidget extends StatelessWidget {
- String field;
+ final String field;
+
+ MyWidget(this.field);
@override
Widget build(BuildContext context) {
@@ -638,7 +644,9 @@
import 'package:flutter/material.dart';
class MyWidget extends StatelessWidget {
- String field;
+ final String field;
+
+ MyWidget(this.field);
@override
Widget build(BuildContext context) {
@@ -648,8 +656,8 @@
class Test extends StatelessWidget {
const Test({
- Key key,
- @required this.field,
+ Key? key,
+ required this.field,
}) : super(key: key);
final String field;
@@ -667,7 +675,7 @@
import 'package:flutter/material.dart';
class C {
- String field;
+ String field = '';
}
class MyWidget extends StatelessWidget {
@@ -685,7 +693,7 @@
import 'package:flutter/material.dart';
class C {
- String field;
+ String field = '';
}
class MyWidget extends StatelessWidget {
@@ -699,8 +707,8 @@
class Test extends StatelessWidget {
const Test({
- Key key,
- @required this.c,
+ Key? key,
+ required this.c,
}) : super(key: key);
final C c;
@@ -717,7 +725,7 @@
await indexTestUnit(r'''
import 'package:flutter/material.dart';
-String field;
+String field = '';
class MyWidget extends StatelessWidget {
@override
@@ -731,7 +739,7 @@
await _assertSuccessfulRefactoring('''
import 'package:flutter/material.dart';
-String field;
+String field = '';
class MyWidget extends StatelessWidget {
@override
@@ -742,7 +750,7 @@
class Test extends StatelessWidget {
const Test({
- Key key,
+ Key? key,
}) : super(key: key);
@override
@@ -759,6 +767,8 @@
class MyWidget extends StatelessWidget {
String field;
+
+ MyWidget(this.field);
@override
Widget build(BuildContext context) {
@@ -782,7 +792,7 @@
import 'package:flutter/material.dart';
abstract class MySuperWidget extends StatelessWidget {
- String field;
+ String field = '';
}
class MyWidget extends MySuperWidget {
@@ -808,7 +818,7 @@
import 'package:flutter/material.dart';
class C {
- String field;
+ String field = '';
}
class MyWidget extends StatelessWidget {
@@ -831,7 +841,7 @@
import 'package:flutter/material.dart';
class C {
- String field;
+ String field = '';
}
class MyWidget extends StatelessWidget {
@@ -845,8 +855,8 @@
class Test extends StatelessWidget {
const Test({
- Key key,
- @required this.c,
+ Key? key,
+ required this.c,
}) : super(key: key);
final C c;
@@ -871,7 +881,7 @@
class MyWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
- String key;
+ String key = '';
return new Text('$key $key');
}
}
@@ -889,7 +899,7 @@
class MyWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
- String local;
+ String local = '';
return new Text('$local $local');
}
}
@@ -902,15 +912,15 @@
class MyWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
- String local;
+ String local = '';
return Test(local: local);
}
}
class Test extends StatelessWidget {
const Test({
- Key key,
- @required this.local,
+ Key? key,
+ required this.local,
}) : super(key: key);
final String local;
@@ -951,7 +961,9 @@
import 'package:flutter/material.dart';
class MyWidget extends StatelessWidget {
- String _field;
+ final String _field;
+
+ MyWidget(this._field);
@override
Widget build(BuildContext context) {
@@ -965,7 +977,9 @@
import 'package:flutter/material.dart';
class MyWidget extends StatelessWidget {
- String _field;
+ final String _field;
+
+ MyWidget(this._field);
@override
Widget build(BuildContext context) {
@@ -975,8 +989,8 @@
class Test extends StatelessWidget {
const Test({
- Key key,
- @required String field,
+ Key? key,
+ required String field,
}) : _field = field, super(key: key);
final String _field;
@@ -994,8 +1008,10 @@
import 'package:flutter/material.dart';
class MyWidget extends StatelessWidget {
- int field;
- String _field;
+ final int field;
+ final String _field;
+
+ MyWidget(this.field, this._field);
@override
Widget build(BuildContext context) {
@@ -1009,8 +1025,10 @@
import 'package:flutter/material.dart';
class MyWidget extends StatelessWidget {
- int field;
- String _field;
+ final int field;
+ final String _field;
+
+ MyWidget(this.field, this._field);
@override
Widget build(BuildContext context) {
@@ -1020,9 +1038,9 @@
class Test extends StatelessWidget {
const Test({
- Key key,
- @required this.field,
- @required String field2,
+ Key? key,
+ required this.field,
+ required String field2,
}) : _field = field2, super(key: key);
final int field;
@@ -1041,11 +1059,13 @@
import 'package:flutter/material.dart';
class MyWidget extends StatelessWidget {
- String field;
+ final String field;
+
+ MyWidget(this.field);
@override
Widget build(BuildContext context) {
- String local;
+ String local = '';
return new Column(
children: <Widget>[
new Text(field),
@@ -1061,20 +1081,22 @@
import 'package:flutter/material.dart';
class MyWidget extends StatelessWidget {
- String field;
+ final String field;
+
+ MyWidget(this.field);
@override
Widget build(BuildContext context) {
- String local;
+ String local = '';
return Test(field: field, local: local);
}
}
class Test extends StatelessWidget {
const Test({
- Key key,
- @required this.field,
- @required this.local,
+ Key? key,
+ required this.field,
+ required this.local,
}) : super(key: key);
final String field;
@@ -1141,9 +1163,9 @@
class Test extends StatelessWidget {
const Test({
- Key key,
- @required this.index,
- @required this.a,
+ Key? key,
+ required this.index,
+ required this.a,
}) : super(key: key);
final int index;
diff --git a/pkg/analysis_server/test/services/refactoring/inline_local_test.dart b/pkg/analysis_server/test/services/refactoring/inline_local_test.dart
index e60b02b..6409980 100644
--- a/pkg/analysis_server/test/services/refactoring/inline_local_test.dart
+++ b/pkg/analysis_server/test/services/refactoring/inline_local_test.dart
@@ -50,7 +50,7 @@
Future<void> test_bad_selectionParameter() async {
await indexTestUnit(r'''
-main(int test) {
+void f(int test) {
}
''');
_createRefactoring('test) {');
@@ -157,7 +157,7 @@
Future<void> test_OK_inSwitchCase() async {
await indexTestUnit('''
-main(int p) {
+void f(int p) {
switch (p) {
case 0:
int test = 42;
@@ -169,7 +169,7 @@
_createRefactoring('test =');
// validate change
return assertSuccessfulRefactoring('''
-main(int p) {
+void f(int p) {
switch (p) {
case 0:
print(42);
diff --git a/pkg/analysis_server/test/services/refactoring/inline_method_test.dart b/pkg/analysis_server/test/services/refactoring/inline_method_test.dart
index 04f61a5..0f5d160 100644
--- a/pkg/analysis_server/test/services/refactoring/inline_method_test.dart
+++ b/pkg/analysis_server/test/services/refactoring/inline_method_test.dart
@@ -203,10 +203,10 @@
Future<void> test_bad_propertyAccessor_synthetic() async {
await indexTestUnit(r'''
class A {
- int fff;
+ int fff = 0;
}
-main(A a) {
+void f(A a) {
print(a.fff);
}
''');
@@ -252,12 +252,12 @@
Future<void> test_cascadeInCascade() async {
await indexTestUnit(r'''
class Inner {
- String a;
- String b;
+ String a = '';
+ String b = '';
}
class Outer {
- Inner inner;
+ Inner inner = Inner();
}
void main() {
@@ -273,12 +273,12 @@
// validate change
return _assertSuccessfulRefactoring(r'''
class Inner {
- String a;
- String b;
+ String a = '';
+ String b = '';
}
class Outer {
- Inner inner;
+ Inner inner = Inner();
}
void main() {
@@ -923,10 +923,10 @@
Future<void> test_getter_classMember_instance() async {
await indexTestUnit(r'''
class A {
- int f;
+ int f = 0;
int get result => f + 1;
}
-main(A a) {
+void f(A a) {
print(a.result);
}
''');
@@ -934,9 +934,9 @@
// validate change
return _assertSuccessfulRefactoring(r'''
class A {
- int f;
+ int f = 0;
}
-main(A a) {
+void f(A a) {
print(a.f + 1);
}
''');
@@ -1063,7 +1063,7 @@
abstract class A {
test();
}
-main(A a) {
+void f(A a) {
print(a.test());
}
''');
@@ -1182,7 +1182,7 @@
}
mb() {}
}
-main(B b) {
+void f(B b) {
b.test();
}
''');
@@ -1199,7 +1199,7 @@
}
mb() {}
}
-main(B b) {
+void f(B b) {
b.ma();
b.mb();
}
@@ -1219,7 +1219,7 @@
B.mb();
}
}
-main(B b) {
+void f(B b) {
b.test();
}
''');
@@ -1237,7 +1237,7 @@
B.mb();
}
}
-main(B b) {
+void f(B b) {
B.mb();
A.ma();
B.mb();
@@ -1559,12 +1559,12 @@
Future<void> test_setter_classMember_instance() async {
await indexTestUnit(r'''
class A {
- int f;
+ int f = 0;
void set result(x) {
f = x + 1;
}
}
-main(A a) {
+void f(A a) {
a.result = 5;
}
''');
@@ -1572,9 +1572,9 @@
// validate change
return _assertSuccessfulRefactoring(r'''
class A {
- int f;
+ int f = 0;
}
-main(A a) {
+void f(A a) {
a.f = 5 + 1;
}
''');
@@ -1725,7 +1725,7 @@
test(bool a, bool b) {
return a || b;
}
-main(bool p, bool p2, bool p3) {
+void f(bool p, bool p2, bool p3) {
var res1 = p && test(p2, p3);
var res2 = p || test(p2, p3);
}
@@ -1733,7 +1733,7 @@
_createRefactoring('test(bool a, bool b)');
// validate change
return _assertSuccessfulRefactoring(r'''
-main(bool p, bool p2, bool p3) {
+void f(bool p, bool p2, bool p3) {
var res1 = p && (p2 || p3);
var res2 = p || p2 || p3;
}
diff --git a/pkg/analysis_server/test/services/refactoring/rename_class_member_test.dart b/pkg/analysis_server/test/services/refactoring/rename_class_member_test.dart
index 97731a6..24223d8 100644
--- a/pkg/analysis_server/test/services/refactoring/rename_class_member_test.dart
+++ b/pkg/analysis_server/test/services/refactoring/rename_class_member_test.dart
@@ -107,7 +107,7 @@
Future<void> test_checkFinalConditions_OK_noShadow() async {
await indexTestUnit('''
class A {
- int newName;
+ int newName = 0;
}
class B {
test() {}
@@ -128,7 +128,7 @@
Future<void> test_checkFinalConditions_OK_noShadow_nullVisibleRange() async {
await indexTestUnit('''
class A {
- int foo;
+ int foo = 0;
A(this.foo);
}
@@ -161,7 +161,7 @@
library my.lib;
import 'test.dart';
-main(A a) {
+void f(A a) {
a.test();
}
''');
@@ -184,7 +184,7 @@
await indexUnit('/home/test/lib/lib.dart', '''
import 'test.dart';
-main(A a) {
+void f(A a) {
print(a.foo);
}
''');
@@ -342,7 +342,7 @@
Future<void> test_checkFinalConditions_shadowsSuper_FieldElement() async {
await indexTestUnit('''
class A {
- int newName; // marker
+ int newName = 0; // marker
}
class B extends A {
test() {}
@@ -359,7 +359,7 @@
var status = await refactoring.checkFinalConditions();
assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR,
expectedMessage: "Renamed method will shadow field 'A.newName'.",
- expectedContextSearch: 'newName; // marker');
+ expectedContextSearch: 'newName = 0; // marker');
}
Future<void> test_checkFinalConditions_shadowsSuper_MethodElement() async {
@@ -435,10 +435,10 @@
Future<void> test_checkNewName_FieldElement() async {
await indexTestUnit('''
class A {
- int test;
+ int test = 0;
}
''');
- createRenameRefactoringAtString('test;');
+ createRenameRefactoringAtString('test = 0;');
// null
refactoring.newName = null;
assertRefactoringStatus(
@@ -480,7 +480,7 @@
Future<void> test_createChange_FieldElement() async {
await indexTestUnit('''
class A {
- int test; // marker
+ int test = 0; // marker
main() {
print(test);
test = 1;
@@ -507,7 +507,7 @@
}
''');
// configure refactoring
- createRenameRefactoringAtString('test; // marker');
+ createRenameRefactoringAtString('test = 0; // marker');
expect(refactoring.refactoringName, 'Rename Field');
expect(refactoring.elementKindName, 'field');
expect(refactoring.oldName, 'test');
@@ -515,7 +515,7 @@
// validate change
return assertSuccessfulRefactoring('''
class A {
- int newName; // marker
+ int newName = 0; // marker
main() {
print(newName);
newName = 1;
@@ -618,13 +618,13 @@
await indexTestUnit('''
typedef F(a);
class A {
- F test;
+ final F test;
+ A(this.test);
main() {
test(1);
}
}
-main() {
- A a = new A();
+void f(A a) {
a.test(2);
}
''');
@@ -637,13 +637,13 @@
return assertSuccessfulRefactoring('''
typedef F(a);
class A {
- F newName;
+ final F newName;
+ A(this.newName);
main() {
newName(1);
}
}
-main() {
- A a = new A();
+void f(A a) {
a.newName(2);
}
''');
@@ -850,7 +850,7 @@
void test() {}
}
-main(A a, B b) {
+void f(A a, B b) {
a.test();
b.test();
}
@@ -865,7 +865,7 @@
void newName() {}
}
-main(A a, B b) {
+void f(A a, B b) {
a.newName();
b.newName();
}
@@ -896,7 +896,7 @@
void test() {}
}
-main(A a) {
+void f(A a) {
a.test();
}
''');
@@ -912,7 +912,7 @@
void newName() {}
}
-main(A a) {
+void f(A a) {
a.newName();
}
''');
@@ -1035,8 +1035,9 @@
await indexTestUnit('''
class A<Test> {
Test field;
- List<Test> items;
- Test method(Test p) => null;
+ List<Test> items = [];
+ A(this.field);
+ Test method(Test p) => field;
}
''');
// configure refactoring
@@ -1049,8 +1050,9 @@
return assertSuccessfulRefactoring('''
class A<NewName> {
NewName field;
- List<NewName> items;
- NewName method(NewName p) => null;
+ List<NewName> items = [];
+ A(this.field);
+ NewName method(NewName p) => field;
}
''');
}
diff --git a/pkg/analysis_server/test/services/refactoring/rename_extension_member_test.dart b/pkg/analysis_server/test/services/refactoring/rename_extension_member_test.dart
index ddff7c5..8490802 100644
--- a/pkg/analysis_server/test/services/refactoring/rename_extension_member_test.dart
+++ b/pkg/analysis_server/test/services/refactoring/rename_extension_member_test.dart
@@ -312,9 +312,9 @@
Future<void> test_createChange_named_TypeParameterElement() async {
await indexTestUnit('''
extension E<Test> on int {
- Test get g1 => null;
- List<Test> get g2 => null;
- Test m(Test p) => null;
+ Test get g1 => throw 0;
+ List<Test> get g2 => throw 0;
+ Test m(Test p) => throw 0;
}
''');
// configure refactoring
@@ -326,9 +326,9 @@
// validate change
return assertSuccessfulRefactoring('''
extension E<NewName> on int {
- NewName get g1 => null;
- List<NewName> get g2 => null;
- NewName m(NewName p) => null;
+ NewName get g1 => throw 0;
+ List<NewName> get g2 => throw 0;
+ NewName m(NewName p) => throw 0;
}
''');
}
diff --git a/pkg/analysis_server/test/services/refactoring/rename_local_test.dart b/pkg/analysis_server/test/services/refactoring/rename_local_test.dart
index e13ea89..0e6b663 100644
--- a/pkg/analysis_server/test/services/refactoring/rename_local_test.dart
+++ b/pkg/analysis_server/test/services/refactoring/rename_local_test.dart
@@ -420,7 +420,7 @@
Future<void> test_createChange_parameter_named() async {
await indexTestUnit('''
-myFunction({int test}) {
+myFunction({required int test}) {
test = 1;
test += 2;
print(test);
@@ -436,7 +436,7 @@
refactoring.newName = 'newName';
// validate change
return assertSuccessfulRefactoring('''
-myFunction({int newName}) {
+myFunction({required int newName}) {
newName = 1;
newName += 2;
print(newName);
@@ -490,7 +490,7 @@
test_createChange_parameter_named_ofConstructor_genericClass() async {
await indexTestUnit('''
class A<T> {
- A({T test});
+ A({required T test});
}
main() {
@@ -505,7 +505,7 @@
// validate change
return assertSuccessfulRefactoring('''
class A<T> {
- A({T newName});
+ A({required T newName});
}
main() {
@@ -517,10 +517,10 @@
Future<void> test_createChange_parameter_named_ofMethod_genericClass() async {
await indexTestUnit('''
class A<T> {
- void foo({T test}) {}
+ void foo({required T test}) {}
}
-main(A<int> a) {
+void f(A<int> a) {
a.foo(test: 0);
}
''');
@@ -532,10 +532,10 @@
// validate change
return assertSuccessfulRefactoring('''
class A<T> {
- void foo({T newName}) {}
+ void foo({required T newName}) {}
}
-main(A<int> a) {
+void f(A<int> a) {
a.foo(newName: 0);
}
''');
@@ -545,12 +545,12 @@
await indexUnit('/home/test/lib/test2.dart', '''
library test2;
class A {
- void foo({int test}) {
+ void foo({int? test}) {
print(test);
}
}
class B extends A {
- void foo({int test}) {
+ void foo({int? test}) {
print(test);
}
}
@@ -563,7 +563,7 @@
new C().foo(test: 30);
}
class C extends A {
- void foo({int test}) {
+ void foo({int? test}) {
print(test);
}
}
@@ -581,7 +581,7 @@
new C().foo(newName: 30);
}
class C extends A {
- void foo({int newName}) {
+ void foo({int? newName}) {
print(newName);
}
}
@@ -589,12 +589,12 @@
assertFileChangeResult('/home/test/lib/test2.dart', '''
library test2;
class A {
- void foo({int newName}) {
+ void foo({int? newName}) {
print(newName);
}
}
class B extends A {
- void foo({int newName}) {
+ void foo({int? newName}) {
print(newName);
}
}
@@ -603,7 +603,7 @@
Future<void> test_createChange_parameter_optionalPositional() async {
await indexTestUnit('''
-myFunction([int test]) {
+myFunction([int? test]) {
test = 1;
test += 2;
print(test);
@@ -619,7 +619,7 @@
refactoring.newName = 'newName';
// validate change
return assertSuccessfulRefactoring('''
-myFunction([int newName]) {
+myFunction([int? newName]) {
newName = 1;
newName += 2;
print(newName);
diff --git a/pkg/analysis_server/test/services/refactoring/rename_unit_member_test.dart b/pkg/analysis_server/test/services/refactoring/rename_unit_member_test.dart
index 5aa122f..c2afbdc 100644
--- a/pkg/analysis_server/test/services/refactoring/rename_unit_member_test.dart
+++ b/pkg/analysis_server/test/services/refactoring/rename_unit_member_test.dart
@@ -6,7 +6,6 @@
import 'package:test/test.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
-import '../../abstract_context.dart';
import 'abstract_rename.dart';
void main() {
@@ -16,8 +15,7 @@
}
@reflectiveTest
-class RenameUnitMemberTest extends RenameRefactoringTest
- with WithNonFunctionTypeAliasesMixin {
+class RenameUnitMemberTest extends RenameRefactoringTest {
Future<void> test_checkFinalConditions_hasTopLevel_ClassElement() async {
await indexTestUnit('''
class Test {}
diff --git a/pkg/analyzer/lib/src/dart/analysis/search.dart b/pkg/analyzer/lib/src/dart/analysis/search.dart
index 3074d5b..ba8695d 100644
--- a/pkg/analyzer/lib/src/dart/analysis/search.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/search.dart
@@ -456,7 +456,7 @@
},
searchedFiles,
));
- if (parameter.isOptional) {
+ if (parameter.isNamed || parameter.isOptionalPositional) {
results.addAll(await _searchReferences(parameter, searchedFiles));
}
return results;
diff --git a/pkg/analyzer/lib/src/dart/resolver/assignment_expression_resolver.dart b/pkg/analyzer/lib/src/dart/resolver/assignment_expression_resolver.dart
index 25c3137..a71a826 100644
--- a/pkg/analyzer/lib/src/dart/resolver/assignment_expression_resolver.dart
+++ b/pkg/analyzer/lib/src/dart/resolver/assignment_expression_resolver.dart
@@ -12,7 +12,6 @@
import 'package:analyzer/src/dart/ast/token.dart';
import 'package:analyzer/src/dart/element/type.dart';
import 'package:analyzer/src/dart/element/type_system.dart';
-import 'package:analyzer/src/dart/resolver/flow_analysis_visitor.dart';
import 'package:analyzer/src/dart/resolver/invocation_inference_helper.dart';
import 'package:analyzer/src/dart/resolver/type_property_resolver.dart';
import 'package:analyzer/src/error/codes.dart';
@@ -22,21 +21,17 @@
/// Helper for resolving [AssignmentExpression]s.
class AssignmentExpressionResolver {
final ResolverVisitor _resolver;
- final FlowAnalysisHelper _flowAnalysis;
final TypePropertyResolver _typePropertyResolver;
final InvocationInferenceHelper _inferenceHelper;
final AssignmentExpressionShared _assignmentShared;
AssignmentExpressionResolver({
@required ResolverVisitor resolver,
- @required FlowAnalysisHelper flowAnalysis,
}) : _resolver = resolver,
- _flowAnalysis = flowAnalysis,
_typePropertyResolver = resolver.typePropertyResolver,
_inferenceHelper = resolver.inferenceHelper,
_assignmentShared = AssignmentExpressionShared(
resolver: resolver,
- flowAnalysis: flowAnalysis,
);
ErrorReporter get _errorReporter => _resolver.errorReporter;
@@ -80,7 +75,7 @@
_setRhsContext(node, leftType, operator, right);
}
- var flow = _flowAnalysis?.flow;
+ var flow = _resolver.flowAnalysis?.flow;
if (flow != null && isIfNull) {
flow.ifNullExpression_rightBegin(left, node.readType);
}
@@ -276,23 +271,22 @@
class AssignmentExpressionShared {
final ResolverVisitor _resolver;
- final FlowAnalysisHelper _flowAnalysis;
AssignmentExpressionShared({
@required ResolverVisitor resolver,
- @required FlowAnalysisHelper flowAnalysis,
- }) : _resolver = resolver,
- _flowAnalysis = flowAnalysis;
+ }) : _resolver = resolver;
ErrorReporter get _errorReporter => _resolver.errorReporter;
void checkFinalAlreadyAssigned(Expression left) {
- var flow = _flowAnalysis?.flow;
+ var flow = _resolver.flowAnalysis?.flow;
if (flow != null && left is SimpleIdentifier) {
var element = left.staticElement;
if (element is VariableElement) {
- var assigned = _flowAnalysis.isDefinitelyAssigned(left, element);
- var unassigned = _flowAnalysis.isDefinitelyUnassigned(left, element);
+ var assigned =
+ _resolver.flowAnalysis.isDefinitelyAssigned(left, element);
+ var unassigned =
+ _resolver.flowAnalysis.isDefinitelyUnassigned(left, element);
if (element.isFinal) {
if (element.isLate) {
diff --git a/pkg/analyzer/lib/src/dart/resolver/binary_expression_resolver.dart b/pkg/analyzer/lib/src/dart/resolver/binary_expression_resolver.dart
index 92bb29d..603b9d1 100644
--- a/pkg/analyzer/lib/src/dart/resolver/binary_expression_resolver.dart
+++ b/pkg/analyzer/lib/src/dart/resolver/binary_expression_resolver.dart
@@ -11,7 +11,6 @@
import 'package:analyzer/src/dart/ast/ast.dart';
import 'package:analyzer/src/dart/element/type.dart';
import 'package:analyzer/src/dart/element/type_system.dart';
-import 'package:analyzer/src/dart/resolver/flow_analysis_visitor.dart';
import 'package:analyzer/src/dart/resolver/invocation_inference_helper.dart';
import 'package:analyzer/src/dart/resolver/resolution_result.dart';
import 'package:analyzer/src/dart/resolver/type_property_resolver.dart';
@@ -24,17 +23,14 @@
class BinaryExpressionResolver {
final ResolverVisitor _resolver;
final TypePromotionManager _promoteManager;
- final FlowAnalysisHelper _flowAnalysis;
final TypePropertyResolver _typePropertyResolver;
final InvocationInferenceHelper _inferenceHelper;
BinaryExpressionResolver({
@required ResolverVisitor resolver,
@required TypePromotionManager promoteManager,
- @required FlowAnalysisHelper flowAnalysis,
}) : _resolver = resolver,
_promoteManager = promoteManager,
- _flowAnalysis = flowAnalysis,
_typePropertyResolver = resolver.typePropertyResolver,
_inferenceHelper = resolver.inferenceHelper;
@@ -111,7 +107,7 @@
left.accept(_resolver);
left = node.leftOperand;
- var flow = _flowAnalysis?.flow;
+ var flow = _resolver.flowAnalysis?.flow;
var leftExtensionOverride = left is ExtensionOverride;
if (!leftExtensionOverride) {
flow?.equalityOp_rightBegin(left, left.staticType);
@@ -136,7 +132,7 @@
void _resolveIfNull(BinaryExpressionImpl node) {
var left = node.leftOperand;
var right = node.rightOperand;
- var flow = _flowAnalysis?.flow;
+ var flow = _resolver.flowAnalysis?.flow;
var leftContextType = InferenceContext.getContext(node);
if (leftContextType != null && _isNonNullableByDefault) {
@@ -171,7 +167,7 @@
void _resolveLogicalAnd(BinaryExpressionImpl node) {
var left = node.leftOperand;
var right = node.rightOperand;
- var flow = _flowAnalysis?.flow;
+ var flow = _resolver.flowAnalysis?.flow;
InferenceContext.setType(left, _typeProvider.boolType);
InferenceContext.setType(right, _typeProvider.boolType);
@@ -180,7 +176,7 @@
left.accept(_resolver);
left = node.leftOperand;
- if (_flowAnalysis != null) {
+ if (_resolver.flowAnalysis != null) {
flow?.logicalBinaryOp_rightBegin(left, node, isAnd: true);
_resolver.checkUnreachableNode(right);
@@ -209,7 +205,7 @@
void _resolveLogicalOr(BinaryExpressionImpl node) {
var left = node.leftOperand;
var right = node.rightOperand;
- var flow = _flowAnalysis?.flow;
+ var flow = _resolver.flowAnalysis?.flow;
InferenceContext.setType(left, _typeProvider.boolType);
InferenceContext.setType(right, _typeProvider.boolType);
diff --git a/pkg/analyzer/lib/src/dart/resolver/for_resolver.dart b/pkg/analyzer/lib/src/dart/resolver/for_resolver.dart
index b4f7848..5c977b9 100644
--- a/pkg/analyzer/lib/src/dart/resolver/for_resolver.dart
+++ b/pkg/analyzer/lib/src/dart/resolver/for_resolver.dart
@@ -10,7 +10,6 @@
import 'package:analyzer/src/dart/element/type.dart';
import 'package:analyzer/src/dart/element/type_schema.dart';
import 'package:analyzer/src/dart/resolver/assignment_expression_resolver.dart';
-import 'package:analyzer/src/dart/resolver/flow_analysis_visitor.dart';
import 'package:analyzer/src/error/codes.dart';
import 'package:analyzer/src/generated/resolver.dart';
import 'package:meta/meta.dart';
@@ -18,13 +17,10 @@
/// Helper for resolving [ForStatement]s and [ForElement]s.
class ForResolver {
final ResolverVisitor _resolver;
- final FlowAnalysisHelper _flowAnalysis;
ForResolver({
@required ResolverVisitor resolver,
- @required FlowAnalysisHelper flowAnalysis,
- }) : _resolver = resolver,
- _flowAnalysis = flowAnalysis;
+ }) : _resolver = resolver;
void resolveElement(ForElementImpl node) {
var forLoopParts = node.forLoopParts;
@@ -89,7 +85,6 @@
identifier?.accept(_resolver);
AssignmentExpressionShared(
resolver: _resolver,
- flowAnalysis: _flowAnalysis,
).checkFinalAlreadyAssigned(identifier);
}
@@ -134,10 +129,10 @@
}
if (loopVariable != null) {
- _flowAnalysis?.flow?.declare(loopVariable.declaredElement, true);
+ _resolver.flowAnalysis?.flow?.declare(loopVariable.declaredElement, true);
}
- _flowAnalysis?.flow?.forEach_bodyBegin(
+ _resolver.flowAnalysis?.flow?.forEach_bodyBegin(
node,
identifierElement is VariableElement
? identifierElement
@@ -147,7 +142,7 @@
_resolveBody(body);
- _flowAnalysis?.flow?.forEach_end();
+ _resolver.flowAnalysis?.flow?.forEach_end();
}
void _forParts(AstNode node, ForParts forParts, AstNode body) {
@@ -157,7 +152,7 @@
forParts.initialization?.accept(_resolver);
}
- _flowAnalysis?.for_conditionBegin(node);
+ _resolver.flowAnalysis?.for_conditionBegin(node);
var condition = forParts.condition;
if (condition != null) {
@@ -167,13 +162,13 @@
_resolver.boolExpressionVerifier.checkForNonBoolCondition(condition);
}
- _flowAnalysis?.for_bodyBegin(node, condition);
+ _resolver.flowAnalysis?.for_bodyBegin(node, condition);
_resolveBody(body);
- _flowAnalysis?.flow?.for_updaterBegin();
+ _resolver.flowAnalysis?.flow?.for_updaterBegin();
forParts.updaters.accept(_resolver);
- _flowAnalysis?.flow?.for_end();
+ _resolver.flowAnalysis?.flow?.for_end();
}
void _resolveBody(AstNode body) {
diff --git a/pkg/analyzer/lib/src/dart/resolver/function_expression_resolver.dart b/pkg/analyzer/lib/src/dart/resolver/function_expression_resolver.dart
index 56332a4..cc7c606 100644
--- a/pkg/analyzer/lib/src/dart/resolver/function_expression_resolver.dart
+++ b/pkg/analyzer/lib/src/dart/resolver/function_expression_resolver.dart
@@ -9,7 +9,6 @@
import 'package:analyzer/src/dart/element/type.dart';
import 'package:analyzer/src/dart/element/type_system.dart';
import 'package:analyzer/src/dart/resolver/body_inference_context.dart';
-import 'package:analyzer/src/dart/resolver/flow_analysis_visitor.dart';
import 'package:analyzer/src/dart/resolver/invocation_inference_helper.dart';
import 'package:analyzer/src/generated/migration.dart';
import 'package:analyzer/src/generated/resolver.dart';
@@ -20,18 +19,15 @@
final ResolverVisitor _resolver;
final MigrationResolutionHooks _migrationResolutionHooks;
final InvocationInferenceHelper _inferenceHelper;
- final FlowAnalysisHelper _flowAnalysis;
final TypePromotionManager _promoteManager;
FunctionExpressionResolver({
@required ResolverVisitor resolver,
@required MigrationResolutionHooks migrationResolutionHooks,
- @required FlowAnalysisHelper flowAnalysis,
@required TypePromotionManager promoteManager,
}) : _resolver = resolver,
_migrationResolutionHooks = migrationResolutionHooks,
_inferenceHelper = resolver.inferenceHelper,
- _flowAnalysis = flowAnalysis,
_promoteManager = promoteManager;
bool get _isNonNullableByDefault => _typeSystem.isNonNullableByDefault;
@@ -42,9 +38,10 @@
var isFunctionDeclaration = node.parent is FunctionDeclaration;
var body = node.body;
- if (_flowAnalysis != null) {
- if (_flowAnalysis.flow != null && !isFunctionDeclaration) {
- _flowAnalysis.executableDeclaration_enter(node, node.parameters, true);
+ if (_resolver.flowAnalysis != null) {
+ if (_resolver.flowAnalysis.flow != null && !isFunctionDeclaration) {
+ _resolver.flowAnalysis
+ .executableDeclaration_enter(node, node.parameters, true);
}
} else {
_promoteManager.enterFunctionBody(body);
@@ -65,15 +62,15 @@
node.visitChildren(_resolver);
_resolve2(node);
- if (_flowAnalysis != null) {
- if (_flowAnalysis.flow != null && !isFunctionDeclaration) {
+ if (_resolver.flowAnalysis != null) {
+ if (_resolver.flowAnalysis.flow != null && !isFunctionDeclaration) {
var bodyContext = BodyInferenceContext.of(node.body);
_resolver.checkForBodyMayCompleteNormally(
returnType: bodyContext?.contextType,
body: body,
errorNode: body,
);
- _flowAnalysis.flow?.functionExpression_end();
+ _resolver.flowAnalysis.flow?.functionExpression_end();
_resolver.nullSafetyDeadCodeVerifier?.flowEnd(node);
}
} else {
diff --git a/pkg/analyzer/lib/src/dart/resolver/invocation_inference_helper.dart b/pkg/analyzer/lib/src/dart/resolver/invocation_inference_helper.dart
index a07074f..e5edabb 100644
--- a/pkg/analyzer/lib/src/dart/resolver/invocation_inference_helper.dart
+++ b/pkg/analyzer/lib/src/dart/resolver/invocation_inference_helper.dart
@@ -10,7 +10,6 @@
import 'package:analyzer/src/dart/element/type.dart';
import 'package:analyzer/src/dart/element/type_algebra.dart';
import 'package:analyzer/src/dart/element/type_system.dart';
-import 'package:analyzer/src/dart/resolver/flow_analysis_visitor.dart';
import 'package:analyzer/src/error/codes.dart';
import 'package:analyzer/src/generated/migration.dart';
import 'package:analyzer/src/generated/resolver.dart';
@@ -19,7 +18,6 @@
class InvocationInferenceHelper {
final ResolverVisitor _resolver;
final ErrorReporter _errorReporter;
- final FlowAnalysisHelper _flowAnalysis;
final TypeSystemImpl _typeSystem;
final MigrationResolutionHooks _migrationResolutionHooks;
@@ -29,13 +27,11 @@
InvocationInferenceHelper(
{@required ResolverVisitor resolver,
@required ErrorReporter errorReporter,
- @required FlowAnalysisHelper flowAnalysis,
@required TypeSystemImpl typeSystem,
@required MigrationResolutionHooks migrationResolutionHooks})
: _resolver = resolver,
_errorReporter = errorReporter,
_typeSystem = typeSystem,
- _flowAnalysis = flowAnalysis,
_migrationResolutionHooks = migrationResolutionHooks;
/// Compute the return type of the method or function represented by the given
@@ -200,7 +196,7 @@
} else {
expression.staticType = type;
if (_typeSystem.isBottom(type)) {
- _flowAnalysis?.flow?.handleExit();
+ _resolver.flowAnalysis?.flow?.handleExit();
}
}
}
diff --git a/pkg/analyzer/lib/src/dart/resolver/postfix_expression_resolver.dart b/pkg/analyzer/lib/src/dart/resolver/postfix_expression_resolver.dart
index 3a8cef1..322b65c 100644
--- a/pkg/analyzer/lib/src/dart/resolver/postfix_expression_resolver.dart
+++ b/pkg/analyzer/lib/src/dart/resolver/postfix_expression_resolver.dart
@@ -12,7 +12,6 @@
import 'package:analyzer/src/dart/element/type_system.dart';
import 'package:analyzer/src/dart/error/syntactic_errors.dart';
import 'package:analyzer/src/dart/resolver/assignment_expression_resolver.dart';
-import 'package:analyzer/src/dart/resolver/flow_analysis_visitor.dart';
import 'package:analyzer/src/dart/resolver/invocation_inference_helper.dart';
import 'package:analyzer/src/dart/resolver/type_property_resolver.dart';
import 'package:analyzer/src/error/codes.dart';
@@ -22,21 +21,17 @@
/// Helper for resolving [PostfixExpression]s.
class PostfixExpressionResolver {
final ResolverVisitor _resolver;
- final FlowAnalysisHelper _flowAnalysis;
final TypePropertyResolver _typePropertyResolver;
final InvocationInferenceHelper _inferenceHelper;
final AssignmentExpressionShared _assignmentShared;
PostfixExpressionResolver({
@required ResolverVisitor resolver,
- @required FlowAnalysisHelper flowAnalysis,
}) : _resolver = resolver,
- _flowAnalysis = flowAnalysis,
_typePropertyResolver = resolver.typePropertyResolver,
_inferenceHelper = resolver.inferenceHelper,
_assignmentShared = AssignmentExpressionShared(
resolver: resolver,
- flowAnalysis: flowAnalysis,
);
ErrorReporter get _errorReporter => _resolver.errorReporter;
@@ -180,7 +175,8 @@
if (operand is SimpleIdentifier) {
var element = operand.staticElement;
if (element is PromotableElement) {
- _flowAnalysis?.flow?.write(element, operatorReturnType, null);
+ _resolver.flowAnalysis?.flow
+ ?.write(element, operatorReturnType, null);
}
}
}
@@ -219,6 +215,6 @@
_inferenceHelper.recordStaticType(node, type);
_resolver.nullShortingTermination(node);
- _flowAnalysis?.flow?.nonNullAssert_end(operand);
+ _resolver.flowAnalysis?.flow?.nonNullAssert_end(operand);
}
}
diff --git a/pkg/analyzer/lib/src/dart/resolver/prefix_expression_resolver.dart b/pkg/analyzer/lib/src/dart/resolver/prefix_expression_resolver.dart
index a88e693..6a060aa 100644
--- a/pkg/analyzer/lib/src/dart/resolver/prefix_expression_resolver.dart
+++ b/pkg/analyzer/lib/src/dart/resolver/prefix_expression_resolver.dart
@@ -12,7 +12,6 @@
import 'package:analyzer/src/dart/element/type.dart';
import 'package:analyzer/src/dart/element/type_system.dart';
import 'package:analyzer/src/dart/resolver/assignment_expression_resolver.dart';
-import 'package:analyzer/src/dart/resolver/flow_analysis_visitor.dart';
import 'package:analyzer/src/dart/resolver/invocation_inference_helper.dart';
import 'package:analyzer/src/dart/resolver/type_property_resolver.dart';
import 'package:analyzer/src/error/codes.dart';
@@ -22,21 +21,17 @@
/// Helper for resolving [PrefixExpression]s.
class PrefixExpressionResolver {
final ResolverVisitor _resolver;
- final FlowAnalysisHelper _flowAnalysis;
final TypePropertyResolver _typePropertyResolver;
final InvocationInferenceHelper _inferenceHelper;
final AssignmentExpressionShared _assignmentShared;
PrefixExpressionResolver({
@required ResolverVisitor resolver,
- @required FlowAnalysisHelper flowAnalysis,
}) : _resolver = resolver,
- _flowAnalysis = flowAnalysis,
_typePropertyResolver = resolver.typePropertyResolver,
_inferenceHelper = resolver.inferenceHelper,
_assignmentShared = AssignmentExpressionShared(
resolver: resolver,
- flowAnalysis: flowAnalysis,
);
ErrorReporter get _errorReporter => _resolver.errorReporter;
@@ -217,7 +212,7 @@
if (operand is SimpleIdentifier) {
var element = operand.staticElement;
if (element is PromotableElement) {
- _flowAnalysis?.flow?.write(element, staticType, null);
+ _resolver.flowAnalysis?.flow?.write(element, staticType, null);
}
}
}
@@ -237,6 +232,6 @@
_recordStaticType(node, _typeProvider.boolType);
- _flowAnalysis?.flow?.logicalNot_end(node, operand);
+ _resolver.flowAnalysis?.flow?.logicalNot_end(node, operand);
}
}
diff --git a/pkg/analyzer/lib/src/dart/resolver/variable_declaration_resolver.dart b/pkg/analyzer/lib/src/dart/resolver/variable_declaration_resolver.dart
index 91c8cba..10da629 100644
--- a/pkg/analyzer/lib/src/dart/resolver/variable_declaration_resolver.dart
+++ b/pkg/analyzer/lib/src/dart/resolver/variable_declaration_resolver.dart
@@ -9,7 +9,6 @@
import 'package:analyzer/src/dart/constant/utilities.dart';
import 'package:analyzer/src/dart/element/element.dart';
import 'package:analyzer/src/dart/element/type.dart';
-import 'package:analyzer/src/dart/resolver/flow_analysis_visitor.dart';
import 'package:analyzer/src/error/codes.dart';
import 'package:analyzer/src/generated/resolver.dart';
import 'package:meta/meta.dart';
@@ -17,15 +16,12 @@
/// Helper for resolving [VariableDeclaration]s.
class VariableDeclarationResolver {
final ResolverVisitor _resolver;
- final FlowAnalysisHelper _flowAnalysis;
final bool _strictInference;
VariableDeclarationResolver({
@required ResolverVisitor resolver,
- @required FlowAnalysisHelper flowAnalysis,
@required bool strictInference,
}) : _resolver = resolver,
- _flowAnalysis = flowAnalysis,
_strictInference = strictInference;
void resolve(VariableDeclarationImpl node) {
@@ -50,9 +46,9 @@
InferenceContext.setTypeFromNode(initializer, node);
if (isTopLevel) {
- _flowAnalysis?.topLevelDeclaration_enter(node, null, null);
+ _resolver.flowAnalysis?.topLevelDeclaration_enter(node, null, null);
} else if (element.isLate) {
- _flowAnalysis?.flow?.lateInitializer_begin(node);
+ _resolver.flowAnalysis?.flow?.lateInitializer_begin(node);
}
initializer.accept(_resolver);
@@ -63,9 +59,9 @@
}
if (isTopLevel) {
- _flowAnalysis?.topLevelDeclaration_exit();
+ _resolver.flowAnalysis?.topLevelDeclaration_exit();
} else if (element.isLate) {
- _flowAnalysis?.flow?.lateInitializer_end();
+ _resolver.flowAnalysis?.flow?.lateInitializer_end();
}
// Note: in addition to cloning the initializers for const variables, we
diff --git a/pkg/analyzer/lib/src/generated/resolver.dart b/pkg/analyzer/lib/src/generated/resolver.dart
index b960315..949d7d3 100644
--- a/pkg/analyzer/lib/src/generated/resolver.dart
+++ b/pkg/analyzer/lib/src/generated/resolver.dart
@@ -93,7 +93,7 @@
void popFunctionBodyContext(FunctionBody node) {
var context = _bodyContexts.removeLast();
- var flow = _resolver._flowAnalysis?.flow;
+ var flow = _resolver.flowAnalysis?.flow;
var resultType = context.computeInferredReturnType(
endOfBlockIsReachable: flow == null || flow.isReachable,
@@ -226,7 +226,7 @@
/// The object keeping track of which elements have had their types promoted.
TypePromotionManager _promoteManager;
- final FlowAnalysisHelper _flowAnalysis;
+ final FlowAnalysisHelper flowAnalysis;
/// A comment before a function should be resolved in the context of the
/// function. But when we incrementally resolve a comment, we don't want to
@@ -296,7 +296,7 @@
FeatureSet featureSet,
Scope nameScope,
bool reportConstEvaluationErrors,
- this._flowAnalysis,
+ this.flowAnalysis,
this._migratableAstInfoProvider,
MigrationResolutionHooks migrationResolutionHooks)
: _featureSet = featureSet,
@@ -325,18 +325,15 @@
typePropertyResolver = TypePropertyResolver(this);
inferenceHelper = InvocationInferenceHelper(
resolver: this,
- flowAnalysis: _flowAnalysis,
errorReporter: errorReporter,
typeSystem: typeSystem,
migrationResolutionHooks: migrationResolutionHooks);
_assignmentExpressionResolver = AssignmentExpressionResolver(
resolver: this,
- flowAnalysis: _flowAnalysis,
);
_binaryExpressionResolver = BinaryExpressionResolver(
resolver: this,
promoteManager: _promoteManager,
- flowAnalysis: _flowAnalysis,
);
_functionExpressionInvocationResolver =
FunctionExpressionInvocationResolver(
@@ -345,25 +342,20 @@
_functionExpressionResolver = FunctionExpressionResolver(
resolver: this,
migrationResolutionHooks: migrationResolutionHooks,
- flowAnalysis: _flowAnalysis,
promoteManager: _promoteManager,
);
_forResolver = ForResolver(
resolver: this,
- flowAnalysis: _flowAnalysis,
);
_postfixExpressionResolver = PostfixExpressionResolver(
resolver: this,
- flowAnalysis: _flowAnalysis,
);
_prefixedIdentifierResolver = PrefixedIdentifierResolver(this);
_prefixExpressionResolver = PrefixExpressionResolver(
resolver: this,
- flowAnalysis: _flowAnalysis,
);
_variableDeclarationResolver = VariableDeclarationResolver(
resolver: this,
- flowAnalysis: _flowAnalysis,
strictInference: analysisOptions.strictInference,
);
_yieldStatementResolver = YieldStatementResolver(
@@ -372,14 +364,13 @@
nullSafetyDeadCodeVerifier = NullSafetyDeadCodeVerifier(
typeSystem,
errorReporter,
- _flowAnalysis,
+ flowAnalysis,
);
elementResolver = ElementResolver(this,
reportConstEvaluationErrors: reportConstEvaluationErrors,
migratableAstInfoProvider: _migratableAstInfoProvider);
inferenceContext = InferenceContext._(this);
- typeAnalyzer =
- StaticTypeAnalyzer(this, _flowAnalysis, migrationResolutionHooks);
+ typeAnalyzer = StaticTypeAnalyzer(this, migrationResolutionHooks);
}
/// Return the element representing the function containing the current node,
@@ -390,8 +381,8 @@
/// Return the object providing promoted or declared types of variables.
LocalVariableTypeProvider get localVariableTypeProvider {
- if (_flowAnalysis != null) {
- return _flowAnalysis.localVariableTypeProvider;
+ if (flowAnalysis != null) {
+ return flowAnalysis.localVariableTypeProvider;
} else {
return _promoteManager.localVariableTypeProvider;
}
@@ -422,7 +413,7 @@
@required FunctionBody body,
@required AstNode errorNode,
}) {
- if (!_flowAnalysis.flow.isReachable) {
+ if (!flowAnalysis.flow.isReachable) {
return;
}
@@ -460,7 +451,7 @@
SimpleIdentifier node,
Element element,
) {
- if (_flowAnalysis?.flow == null) {
+ if (flowAnalysis?.flow == null) {
return;
}
@@ -469,9 +460,9 @@
}
if (element is VariableElement) {
- var assigned = _flowAnalysis.isDefinitelyAssigned(
- node, element as PromotableElement);
- var unassigned = _flowAnalysis.isDefinitelyUnassigned(node, element);
+ var assigned =
+ flowAnalysis.isDefinitelyAssigned(node, element as PromotableElement);
+ var unassigned = flowAnalysis.isDefinitelyUnassigned(node, element);
if (element.isLate) {
if (unassigned) {
@@ -550,7 +541,7 @@
if (identical(_unfinishedNullShorts.last, node)) {
do {
_unfinishedNullShorts.removeLast();
- _flowAnalysis.flow.nullAwareAccess_end();
+ flowAnalysis.flow.nullAwareAccess_end();
} while (identical(_unfinishedNullShorts.last, node));
if (node is! CascadeExpression && !discardType) {
node.staticType = typeSystem.makeNullable(node.staticType as TypeImpl);
@@ -777,7 +768,7 @@
void startNullAwareIndexExpression(IndexExpression node) {
if (_migratableAstInfoProvider.isIndexExpressionNullAware(node)) {
- var flow = _flowAnalysis?.flow;
+ var flow = flowAnalysis?.flow;
if (flow != null) {
flow.nullAwareAccess_rightBegin(node.target,
node.realTarget.staticType ?? typeProvider.dynamicType);
@@ -788,7 +779,7 @@
void startNullAwarePropertyAccess(PropertyAccess node) {
if (_migratableAstInfoProvider.isPropertyAccessNullAware(node)) {
- var flow = _flowAnalysis?.flow;
+ var flow = flowAnalysis?.flow;
if (flow != null) {
var target = node.target;
if (target is SimpleIdentifier &&
@@ -886,14 +877,14 @@
for (var i = 0; i < length; i++) {
if (isIdentical && length > 1 && i == 1) {
var firstArg = arguments[0];
- _flowAnalysis?.flow
+ flowAnalysis?.flow
?.equalityOp_rightBegin(firstArg, firstArg.staticType);
}
arguments[i].accept(this);
}
if (isIdentical && length > 1) {
var secondArg = arguments[1];
- _flowAnalysis?.flow
+ flowAnalysis?.flow
?.equalityOp_end(node.parent, secondArg, secondArg.staticType);
}
node.accept(elementResolver);
@@ -903,35 +894,35 @@
@override
void visitAsExpression(AsExpression node) {
super.visitAsExpression(node);
- _flowAnalysis?.asExpression(node);
+ flowAnalysis?.asExpression(node);
}
@override
void visitAssertInitializer(AssertInitializer node) {
InferenceContext.setType(node.condition, typeProvider.boolType);
- _flowAnalysis?.flow?.assert_begin();
+ flowAnalysis?.flow?.assert_begin();
node.condition?.accept(this);
boolExpressionVerifier.checkForNonBoolExpression(
node.condition,
errorCode: CompileTimeErrorCode.NON_BOOL_EXPRESSION,
);
- _flowAnalysis?.flow?.assert_afterCondition(node.condition);
+ flowAnalysis?.flow?.assert_afterCondition(node.condition);
node.message?.accept(this);
- _flowAnalysis?.flow?.assert_end();
+ flowAnalysis?.flow?.assert_end();
}
@override
void visitAssertStatement(AssertStatement node) {
InferenceContext.setType(node.condition, typeProvider.boolType);
- _flowAnalysis?.flow?.assert_begin();
+ flowAnalysis?.flow?.assert_begin();
node.condition?.accept(this);
boolExpressionVerifier.checkForNonBoolExpression(
node.condition,
errorCode: CompileTimeErrorCode.NON_BOOL_EXPRESSION,
);
- _flowAnalysis?.flow?.assert_afterCondition(node.condition);
+ flowAnalysis?.flow?.assert_afterCondition(node.condition);
node.message?.accept(this);
- _flowAnalysis?.flow?.assert_end();
+ flowAnalysis?.flow?.assert_end();
}
@override
@@ -968,7 +959,7 @@
@override
void visitBooleanLiteral(BooleanLiteral node) {
- _flowAnalysis?.flow?.booleanLiteral(node, node.value);
+ flowAnalysis?.flow?.booleanLiteral(node, node.value);
super.visitBooleanLiteral(node);
}
@@ -981,7 +972,7 @@
checkUnreachableNode(node);
node.accept(elementResolver);
node.accept(typeAnalyzer);
- _flowAnalysis?.breakStatement(node);
+ flowAnalysis?.breakStatement(node);
}
@override
@@ -989,8 +980,8 @@
InferenceContext.setTypeFromNode(node.target, node);
node.target.accept(this);
- if (node.isNullAware && _flowAnalysis != null) {
- _flowAnalysis.flow.nullAwareAccess_rightBegin(
+ if (node.isNullAware && flowAnalysis != null) {
+ flowAnalysis.flow.nullAwareAccess_rightBegin(
node.target, node.target.staticType ?? typeProvider.dynamicType);
_unfinishedNullShorts.add(node.nullShortingTermination);
}
@@ -1102,7 +1093,7 @@
@override
void visitConditionalExpression(ConditionalExpression node) {
Expression condition = node.condition;
- var flow = _flowAnalysis?.flow;
+ var flow = flowAnalysis?.flow;
flow?.conditional_conditionBegin();
// TODO(scheglov) Do we need these checks for null?
@@ -1113,7 +1104,7 @@
Expression thenExpression = node.thenExpression;
InferenceContext.setTypeFromNode(thenExpression, node);
- if (_flowAnalysis != null) {
+ if (flowAnalysis != null) {
if (flow != null) {
flow.conditional_thenBegin(condition, node);
checkUnreachableNode(thenExpression);
@@ -1158,9 +1149,9 @@
ExecutableElement outerFunction = _enclosingFunction;
_enclosingFunction = node.declaredElement;
- if (_flowAnalysis != null) {
- _flowAnalysis.topLevelDeclaration_enter(node, node.parameters, node.body);
- _flowAnalysis.executableDeclaration_enter(node, node.parameters, false);
+ if (flowAnalysis != null) {
+ flowAnalysis.topLevelDeclaration_enter(node, node.parameters, node.body);
+ flowAnalysis.executableDeclaration_enter(node, node.parameters, false);
} else {
_promoteManager.enterFunctionBody(node.body);
}
@@ -1170,7 +1161,7 @@
super.visitConstructorDeclaration(node);
- if (_flowAnalysis != null) {
+ if (flowAnalysis != null) {
if (node.factoryKeyword != null) {
var bodyContext = BodyInferenceContext.of(node.body);
checkForBodyMayCompleteNormally(
@@ -1179,8 +1170,8 @@
errorNode: node,
);
}
- _flowAnalysis.executableDeclaration_exit(node.body, false);
- _flowAnalysis.topLevelDeclaration_exit();
+ flowAnalysis.executableDeclaration_exit(node.body, false);
+ flowAnalysis.topLevelDeclaration_exit();
nullSafetyDeadCodeVerifier?.flowEnd(node);
} else {
_promoteManager.exitFunctionBody();
@@ -1238,7 +1229,7 @@
checkUnreachableNode(node);
node.accept(elementResolver);
node.accept(typeAnalyzer);
- _flowAnalysis?.continueStatement(node);
+ flowAnalysis?.continueStatement(node);
}
@override
@@ -1263,16 +1254,16 @@
var body = node.body;
var condition = node.condition;
- _flowAnalysis?.flow?.doStatement_bodyBegin(node);
+ flowAnalysis?.flow?.doStatement_bodyBegin(node);
visitStatementInScope(body);
- _flowAnalysis?.flow?.doStatement_conditionBegin();
+ flowAnalysis?.flow?.doStatement_conditionBegin();
InferenceContext.setType(condition, typeProvider.boolType);
condition.accept(this);
condition = node.condition;
boolExpressionVerifier.checkForNonBoolCondition(condition);
- _flowAnalysis?.flow?.doStatement_end(condition);
+ flowAnalysis?.flow?.doStatement_end(condition);
}
@override
@@ -1329,7 +1320,7 @@
super.visitExpressionFunctionBody(node);
- _flowAnalysis?.flow?.handleExit();
+ flowAnalysis?.flow?.handleExit();
inferenceContext.bodyContext.addReturnExpression(node.expression);
} finally {
@@ -1390,17 +1381,17 @@
bool isLocal = node.parent is FunctionDeclarationStatement;
- if (_flowAnalysis != null) {
+ if (flowAnalysis != null) {
if (isLocal) {
- _flowAnalysis.flow.functionExpression_begin(node);
+ flowAnalysis.flow.functionExpression_begin(node);
} else {
- _flowAnalysis.topLevelDeclaration_enter(
+ flowAnalysis.topLevelDeclaration_enter(
node,
node.functionExpression.parameters,
node.functionExpression.body,
);
}
- _flowAnalysis.executableDeclaration_enter(
+ flowAnalysis.executableDeclaration_enter(
node,
node.functionExpression.parameters,
isLocal,
@@ -1414,7 +1405,7 @@
super.visitFunctionDeclaration(node);
- if (_flowAnalysis != null) {
+ if (flowAnalysis != null) {
// TODO(scheglov) encapsulate
var bodyContext = BodyInferenceContext.of(
node.functionExpression.body,
@@ -1424,14 +1415,14 @@
body: node.functionExpression.body,
errorNode: node.name,
);
- _flowAnalysis.executableDeclaration_exit(
+ flowAnalysis.executableDeclaration_exit(
node.functionExpression.body,
isLocal,
);
if (isLocal) {
- _flowAnalysis.flow.functionExpression_end();
+ flowAnalysis.flow.functionExpression_end();
} else {
- _flowAnalysis.topLevelDeclaration_exit();
+ flowAnalysis.topLevelDeclaration_exit();
}
nullSafetyDeadCodeVerifier?.flowEnd(node);
} else {
@@ -1511,7 +1502,7 @@
@override
void visitIfElement(IfElement node) {
- _flowAnalysis?.flow?.ifStatement_conditionBegin();
+ flowAnalysis?.flow?.ifStatement_conditionBegin();
Expression condition = node.condition;
InferenceContext.setType(condition, typeProvider.boolType);
// TODO(scheglov) Do we need these checks for null?
@@ -1521,8 +1512,8 @@
boolExpressionVerifier.checkForNonBoolCondition(condition);
CollectionElement thenElement = node.thenElement;
- if (_flowAnalysis != null) {
- _flowAnalysis.flow?.ifStatement_thenBegin(condition, node);
+ if (flowAnalysis != null) {
+ flowAnalysis.flow?.ifStatement_thenBegin(condition, node);
thenElement.accept(this);
} else {
_promoteManager.visitIfElement_thenElement(
@@ -1536,11 +1527,11 @@
var elseElement = node.elseElement;
if (elseElement != null) {
- _flowAnalysis?.flow?.ifStatement_elseBegin();
+ flowAnalysis?.flow?.ifStatement_elseBegin();
elseElement.accept(this);
}
- _flowAnalysis?.flow?.ifStatement_end(elseElement != null);
+ flowAnalysis?.flow?.ifStatement_end(elseElement != null);
node.accept(elementResolver);
node.accept(typeAnalyzer);
@@ -1549,7 +1540,7 @@
@override
void visitIfStatement(IfStatement node) {
checkUnreachableNode(node);
- _flowAnalysis?.flow?.ifStatement_conditionBegin();
+ flowAnalysis?.flow?.ifStatement_conditionBegin();
Expression condition = node.condition;
@@ -1561,8 +1552,8 @@
boolExpressionVerifier.checkForNonBoolCondition(condition);
Statement thenStatement = node.thenStatement;
- if (_flowAnalysis != null) {
- _flowAnalysis.flow?.ifStatement_thenBegin(condition, node);
+ if (flowAnalysis != null) {
+ flowAnalysis.flow?.ifStatement_thenBegin(condition, node);
visitStatementInScope(thenStatement);
nullSafetyDeadCodeVerifier?.flowEnd(thenStatement);
} else {
@@ -1577,12 +1568,12 @@
Statement elseStatement = node.elseStatement;
if (elseStatement != null) {
- _flowAnalysis?.flow?.ifStatement_elseBegin();
+ flowAnalysis?.flow?.ifStatement_elseBegin();
visitStatementInScope(elseStatement);
nullSafetyDeadCodeVerifier?.flowEnd(elseStatement);
}
- _flowAnalysis?.flow?.ifStatement_end(elseStatement != null);
+ flowAnalysis?.flow?.ifStatement_end(elseStatement != null);
node.accept(elementResolver);
node.accept(typeAnalyzer);
@@ -1631,7 +1622,7 @@
@override
void visitIsExpression(IsExpression node) {
super.visitIsExpression(node);
- _flowAnalysis?.isExpression(node);
+ flowAnalysis?.isExpression(node);
}
@override
@@ -1639,9 +1630,9 @@
@override
void visitLabeledStatement(LabeledStatement node) {
- _flowAnalysis?.labeledStatement_enter(node);
+ flowAnalysis?.labeledStatement_enter(node);
super.visitLabeledStatement(node);
- _flowAnalysis?.labeledStatement_exit(node);
+ flowAnalysis?.labeledStatement_exit(node);
}
@override
@@ -1658,9 +1649,9 @@
ExecutableElement outerFunction = _enclosingFunction;
_enclosingFunction = node.declaredElement;
- if (_flowAnalysis != null) {
- _flowAnalysis.topLevelDeclaration_enter(node, node.parameters, node.body);
- _flowAnalysis.executableDeclaration_enter(node, node.parameters, false);
+ if (flowAnalysis != null) {
+ flowAnalysis.topLevelDeclaration_enter(node, node.parameters, node.body);
+ flowAnalysis.executableDeclaration_enter(node, node.parameters, false);
} else {
_promoteManager.enterFunctionBody(node.body);
}
@@ -1670,7 +1661,7 @@
super.visitMethodDeclaration(node);
- if (_flowAnalysis != null) {
+ if (flowAnalysis != null) {
// TODO(scheglov) encapsulate
var bodyContext = BodyInferenceContext.of(node.body);
checkForBodyMayCompleteNormally(
@@ -1678,8 +1669,8 @@
body: node.body,
errorNode: node.name,
);
- _flowAnalysis.executableDeclaration_exit(node.body, false);
- _flowAnalysis.topLevelDeclaration_exit();
+ flowAnalysis.executableDeclaration_exit(node.body, false);
+ flowAnalysis.topLevelDeclaration_exit();
nullSafetyDeadCodeVerifier?.flowEnd(node);
} else {
_promoteManager.exitFunctionBody();
@@ -1694,7 +1685,7 @@
target?.accept(this);
if (_migratableAstInfoProvider.isMethodInvocationNullAware(node)) {
- var flow = _flowAnalysis?.flow;
+ var flow = flowAnalysis?.flow;
if (flow != null) {
if (target is SimpleIdentifier &&
target.staticElement is ClassElement) {
@@ -1759,7 +1750,7 @@
@override
void visitNullLiteral(NullLiteral node) {
- _flowAnalysis?.flow?.nullLiteral(node);
+ flowAnalysis?.flow?.nullLiteral(node);
super.visitNullLiteral(node);
}
@@ -1767,7 +1758,7 @@
void visitParenthesizedExpression(ParenthesizedExpression node) {
InferenceContext.setTypeFromNode(node.expression, node);
super.visitParenthesizedExpression(node);
- _flowAnalysis?.flow?.parenthesizedExpression(node, node.expression);
+ flowAnalysis?.flow?.parenthesizedExpression(node, node.expression);
}
@override
@@ -1838,7 +1829,7 @@
@override
void visitRethrowExpression(RethrowExpression node) {
super.visitRethrowExpression(node);
- _flowAnalysis?.flow?.handleExit();
+ flowAnalysis?.flow?.handleExit();
}
@override
@@ -1851,7 +1842,7 @@
super.visitReturnStatement(node);
inferenceContext.bodyContext?.addReturnExpression(node.expression);
- _flowAnalysis?.flow?.handleExit();
+ flowAnalysis?.flow?.handleExit();
}
@override
@@ -1865,7 +1856,7 @@
@override
void visitSimpleIdentifier(SimpleIdentifier node) {
- SimpleIdentifierResolver(this, _flowAnalysis).resolve(node);
+ SimpleIdentifierResolver(this, flowAnalysis).resolve(node);
}
@override
@@ -1900,7 +1891,7 @@
node.expression, _enclosingSwitchStatementExpressionType);
super.visitSwitchCase(node);
- var flow = _flowAnalysis?.flow;
+ var flow = flowAnalysis?.flow;
if (flow != null && flow.isReachable) {
var switchStatement = node.parent as SwitchStatement;
if (switchStatement.members.last != node && node.statements.isNotEmpty) {
@@ -1930,8 +1921,8 @@
expression.accept(this);
_enclosingSwitchStatementExpressionType = expression.staticType;
- if (_flowAnalysis != null) {
- var flow = _flowAnalysis.flow;
+ if (flowAnalysis != null) {
+ var flow = flowAnalysis.flow;
flow.switchStatement_expressionEnd(node);
@@ -1959,17 +1950,17 @@
@override
void visitThrowExpression(ThrowExpression node) {
super.visitThrowExpression(node);
- _flowAnalysis?.flow?.handleExit();
+ flowAnalysis?.flow?.handleExit();
}
@override
void visitTryStatement(TryStatement node) {
- if (_flowAnalysis == null) {
+ if (flowAnalysis == null) {
return super.visitTryStatement(node);
}
checkUnreachableNode(node);
- var flow = _flowAnalysis.flow;
+ var flow = flowAnalysis.flow;
var body = node.body;
var catchClauses = node.catchClauses;
@@ -2032,11 +2023,11 @@
var initializerStaticType = initializer.staticType;
if (declaredType == null) {
if (initializerStaticType is TypeParameterType) {
- _flowAnalysis?.flow?.promote(
+ flowAnalysis?.flow?.promote(
declaredElement as PromotableElement, initializerStaticType);
}
} else {
- _flowAnalysis?.flow?.initialize(declaredElement as PromotableElement,
+ flowAnalysis?.flow?.initialize(declaredElement as PromotableElement,
initializerStaticType, initializer,
isFinal: parent.isFinal, isLate: parent.isLate);
}
@@ -2045,7 +2036,7 @@
@override
void visitVariableDeclarationList(VariableDeclarationList node) {
- _flowAnalysis?.variableDeclarationList(node);
+ flowAnalysis?.variableDeclarationList(node);
for (VariableDeclaration decl in node.variables) {
VariableElement variableElement = decl.declaredElement;
InferenceContext.setType(decl, variableElement?.type);
@@ -2066,16 +2057,16 @@
Expression condition = node.condition;
InferenceContext.setType(condition, typeProvider.boolType);
- _flowAnalysis?.flow?.whileStatement_conditionBegin(node);
+ flowAnalysis?.flow?.whileStatement_conditionBegin(node);
condition?.accept(this);
boolExpressionVerifier.checkForNonBoolCondition(node.condition);
Statement body = node.body;
if (body != null) {
- _flowAnalysis?.flow?.whileStatement_bodyBegin(node, condition);
+ flowAnalysis?.flow?.whileStatement_bodyBegin(node, condition);
visitStatementInScope(body);
- _flowAnalysis?.flow?.whileStatement_end();
+ flowAnalysis?.flow?.whileStatement_end();
nullSafetyDeadCodeVerifier?.flowEnd(node.body);
}
} finally {
@@ -2203,7 +2194,7 @@
if (target is SimpleIdentifier && target.staticElement is ClassElement) {
// `?.` to access static methods is equivalent to `.`, so do nothing.
} else {
- _flowAnalysis.flow.nullAwareAccess_rightBegin(function,
+ flowAnalysis.flow.nullAwareAccess_rightBegin(function,
function.realTarget.staticType ?? typeProvider.dynamicType);
_unfinishedNullShorts.add(node.nullShortingTermination);
}
diff --git a/pkg/analyzer/lib/src/generated/static_type_analyzer.dart b/pkg/analyzer/lib/src/generated/static_type_analyzer.dart
index a51dcbc..036e46d 100644
--- a/pkg/analyzer/lib/src/generated/static_type_analyzer.dart
+++ b/pkg/analyzer/lib/src/generated/static_type_analyzer.dart
@@ -12,7 +12,6 @@
import 'package:analyzer/src/dart/element/type.dart';
import 'package:analyzer/src/dart/element/type_provider.dart';
import 'package:analyzer/src/dart/element/type_system.dart';
-import 'package:analyzer/src/dart/resolver/flow_analysis_visitor.dart';
import 'package:analyzer/src/generated/migration.dart';
import 'package:analyzer/src/generated/resolver.dart';
@@ -38,14 +37,11 @@
/// The type representing the type 'dynamic'.
DartType _dynamicType;
- final FlowAnalysisHelper _flowAnalysis;
-
/// Initialize a newly created static type analyzer to analyze types for the
/// [_resolver] based on the
///
/// @param resolver the resolver driving this participant
- StaticTypeAnalyzer(
- this._resolver, this._flowAnalysis, this._migrationResolutionHooks) {
+ StaticTypeAnalyzer(this._resolver, this._migrationResolutionHooks) {
_typeProvider = _resolver.typeProvider;
_typeSystem = _resolver.typeSystem;
_dynamicType = _typeProvider.dynamicType;
@@ -94,7 +90,7 @@
} else {
expression.staticType = type;
if (_typeSystem.isBottom(type)) {
- _flowAnalysis?.flow?.handleExit();
+ _resolver.flowAnalysis?.flow?.handleExit();
}
}
}
diff --git a/pkg/analyzer/test/src/dart/analysis/search_test.dart b/pkg/analyzer/test/src/dart/analysis/search_test.dart
index 646bada..c788f13 100644
--- a/pkg/analyzer/test/src/dart/analysis/search_test.dart
+++ b/pkg/analyzer/test/src/dart/analysis/search_test.dart
@@ -14,8 +14,6 @@
main() {
defineReflectiveSuite(() {
defineReflectiveTests(SearchTest);
- defineReflectiveTests(SearchWithNullSafetyTest);
- defineReflectiveTests(SearchWithNonFunctionTypeAliasesTest);
});
}
@@ -62,7 +60,8 @@
}
@reflectiveTest
-class SearchTest extends PubPackageResolutionTest {
+class SearchTest extends PubPackageResolutionTest
+ with WithNonFunctionTypeAliasesMixin {
AnalysisDriver get driver => driverFor(testFilePath);
CompilationUnitElement get resultUnitElement => result.unit.declaredElement;
@@ -387,6 +386,27 @@
await _verifyReferences(element, expected);
}
+ test_searchReferences_ConstructorElement_named_viaTypeAlias() async {
+ await resolveTestCode('''
+class A<T> {
+ A.named();
+}
+
+typedef B = A<int>;
+
+void f() {
+ B.named(); // ref
+}
+''');
+
+ var element = findElement.constructor('named');
+ var f = findElement.topFunction('f');
+ await _verifyReferences(element, [
+ _expectIdQ(f, SearchResultKind.REFERENCE, '.named(); // ref',
+ length: '.named'.length),
+ ]);
+ }
+
test_searchReferences_ConstructorElement_synthetic() async {
await resolveTestCode('''
class A {
@@ -607,6 +627,37 @@
await _verifyReferences(element, expected);
}
+ test_searchReferences_ImportElement_noPrefix_optIn_fromOptOut() async {
+ newFile('$testPackageLibPath/a.dart', content: r'''
+class N1 {}
+void N2() {}
+int get N3 => 0;
+set N4(int _) {}
+''');
+
+ await resolveTestCode('''
+// @dart = 2.7
+import 'a.dart';
+
+main() {
+ N1;
+ N2();
+ N3;
+ N4 = 0;
+}
+''');
+ ImportElement element = findElement.import('package:test/a.dart');
+ var main = findElement.function('main');
+ var kind = SearchResultKind.REFERENCE;
+ var expected = [
+ _expectId(main, kind, 'N1;', length: 0),
+ _expectId(main, kind, 'N2();', length: 0),
+ _expectId(main, kind, 'N3;', length: 0),
+ _expectId(main, kind, 'N4 =', length: 0),
+ ];
+ await _verifyReferences(element, expected);
+ }
+
test_searchReferences_ImportElement_withPrefix() async {
await resolveTestCode('''
import 'dart:math' as math show max, pi, Random hide min;
@@ -660,6 +711,38 @@
}
}
+ test_searchReferences_ImportElement_withPrefix_optIn_fromOptOut() async {
+ newFile('$testPackageLibPath/a.dart', content: r'''
+class N1 {}
+void N2() {}
+int get N3 => 0;
+set N4(int _) {}
+''');
+
+ await resolveTestCode('''
+// @dart = 2.7
+import 'a.dart' as a;
+
+main() {
+ a.N1;
+ a.N2();
+ a.N3;
+ a.N4 = 0;
+}
+''');
+ ImportElement element = findElement.import('package:test/a.dart');
+ var main = findElement.function('main');
+ var kind = SearchResultKind.REFERENCE;
+ var length = 'a.'.length;
+ var expected = [
+ _expectId(main, kind, 'a.N1;', length: length),
+ _expectId(main, kind, 'a.N2()', length: length),
+ _expectId(main, kind, 'a.N3', length: length),
+ _expectId(main, kind, 'a.N4', length: length),
+ ];
+ await _verifyReferences(element, expected);
+ }
+
test_searchReferences_LabelElement() async {
await resolveTestCode('''
main() {
@@ -966,7 +1049,7 @@
await _verifyReferences(method, expected);
}
- test_searchReferences_ParameterElement_named() async {
+ test_searchReferences_ParameterElement_optionalNamed() async {
await resolveTestCode('''
foo({p}) {
p = 1;
@@ -991,7 +1074,57 @@
await _verifyReferences(element, expected);
}
- test_searchReferences_ParameterElement_ofConstructor() async {
+ test_searchReferences_ParameterElement_optionalPositional() async {
+ await resolveTestCode('''
+foo([p]) {
+ p = 1;
+ p += 2;
+ print(p);
+ p();
+}
+main() {
+ foo(42);
+}
+''');
+ var element = findElement.parameter('p');
+ var foo = findElement.function('foo');
+ var main = findElement.function('main');
+ var expected = [
+ _expectId(foo, SearchResultKind.WRITE, 'p = 1;'),
+ _expectId(foo, SearchResultKind.READ_WRITE, 'p += 2;'),
+ _expectId(foo, SearchResultKind.READ, 'p);'),
+ _expectId(foo, SearchResultKind.READ, 'p();'),
+ _expectIdQ(main, SearchResultKind.REFERENCE, '42', length: 0)
+ ];
+ await _verifyReferences(element, expected);
+ }
+
+ test_searchReferences_ParameterElement_requiredNamed() async {
+ await resolveTestCode('''
+foo({required int p}) {
+ p = 1;
+ p += 2;
+ print(p);
+ p();
+}
+main() {
+ foo(p: 42);
+}
+''');
+ var element = findElement.parameter('p');
+ var foo = findElement.function('foo');
+ var main = findElement.function('main');
+ var expected = [
+ _expectId(foo, SearchResultKind.WRITE, 'p = 1;'),
+ _expectId(foo, SearchResultKind.READ_WRITE, 'p += 2;'),
+ _expectId(foo, SearchResultKind.READ, 'p);'),
+ _expectId(foo, SearchResultKind.READ, 'p();'),
+ _expectIdQ(main, SearchResultKind.REFERENCE, 'p: 42')
+ ];
+ await _verifyReferences(element, expected);
+ }
+
+ test_searchReferences_ParameterElement_requiredPositional_ofConstructor() async {
await resolveTestCode('''
class C {
var f;
@@ -1018,7 +1151,7 @@
await _verifyReferences(element, expected);
}
- test_searchReferences_ParameterElement_ofLocalFunction() async {
+ test_searchReferences_ParameterElement_requiredPositional_ofLocalFunction() async {
await resolveTestCode('''
main() {
foo(p) {
@@ -1041,7 +1174,7 @@
await _verifyReferences(element, expected);
}
- test_searchReferences_ParameterElement_ofMethod() async {
+ test_searchReferences_ParameterElement_requiredPositional_ofMethod() async {
await resolveTestCode('''
class C {
foo(p) {
@@ -1066,7 +1199,7 @@
await _verifyReferences(element, expected);
}
- test_searchReferences_ParameterElement_ofTopLevelFunction() async {
+ test_searchReferences_ParameterElement_requiredPositional_ofTopLevelFunction() async {
await resolveTestCode('''
foo(p) {
p = 1;
@@ -1089,31 +1222,6 @@
await _verifyReferences(element, expected);
}
- test_searchReferences_ParameterElement_optionalPositional() async {
- await resolveTestCode('''
-foo([p]) {
- p = 1;
- p += 2;
- print(p);
- p();
-}
-main() {
- foo(42);
-}
-''');
- var element = findElement.parameter('p');
- var foo = findElement.function('foo');
- var main = findElement.function('main');
- var expected = [
- _expectId(foo, SearchResultKind.WRITE, 'p = 1;'),
- _expectId(foo, SearchResultKind.READ_WRITE, 'p += 2;'),
- _expectId(foo, SearchResultKind.READ, 'p);'),
- _expectId(foo, SearchResultKind.READ, 'p();'),
- _expectIdQ(main, SearchResultKind.REFERENCE, '42', length: 0)
- ];
- await _verifyReferences(element, expected);
- }
-
test_searchReferences_PrefixElement() async {
String partCode = r'''
part of my_lib;
@@ -1425,6 +1533,77 @@
await _verifyReferences(variable, expected);
}
+ test_searchReferences_TypeAliasElement() async {
+ await resolveTestCode('''
+class A<T> {
+ static int field = 0;
+ static void method() {}
+}
+
+typedef B = A<int>;
+
+class C extends B {} // extends
+
+void f(B p) {
+ B v;
+ B.field = 1;
+ B.field;
+ B.method();
+}
+''');
+
+ var element = findElement.typeAlias('B');
+ var f = findElement.topFunction('f');
+ await _verifyReferences(element, [
+ _expectId(findElement.class_('C'), SearchResultKind.REFERENCE,
+ 'B {} // extends'),
+ _expectId(findElement.parameter('p'), SearchResultKind.REFERENCE, 'B p'),
+ _expectId(f, SearchResultKind.REFERENCE, 'B v'),
+ _expectId(f, SearchResultKind.REFERENCE, 'B.field ='),
+ _expectId(f, SearchResultKind.REFERENCE, 'B.field;'),
+ _expectId(f, SearchResultKind.REFERENCE, 'B.method();'),
+ ]);
+ }
+
+ test_searchReferences_TypeAliasElement_fromLegacy() async {
+ newFile('$testPackageLibPath/a.dart', content: r'''
+typedef A<T> = Map<int, T>;
+''');
+ await resolveTestCode('''
+// @dart = 2.9
+import 'a.dart';
+
+void f(A<String> a) {}
+''');
+
+ var A = findElement.importFind('package:test/a.dart').typeAlias('A');
+ await _verifyReferences(A, [
+ _expectId(
+ findElement.parameter('a'),
+ SearchResultKind.REFERENCE,
+ 'A<String>',
+ ),
+ ]);
+ }
+
+ test_searchReferences_TypeAliasElement_inConstructorName() async {
+ await resolveTestCode('''
+class A<T> {}
+
+typedef B = A<int>;
+
+void f() {
+ B();
+}
+''');
+
+ var element = findElement.typeAlias('B');
+ var f = findElement.topFunction('f');
+ await _verifyReferences(element, [
+ _expectId(f, SearchResultKind.REFERENCE, 'B();'),
+ ]);
+ }
+
test_searchReferences_TypeParameterElement_ofClass() async {
await resolveTestCode('''
class A<T> {
@@ -1855,165 +2034,3 @@
expect(matches, unorderedEquals(expectedMatches));
}
}
-
-@reflectiveTest
-class SearchWithNonFunctionTypeAliasesTest extends SearchTest
- with WithNonFunctionTypeAliasesMixin {
- test_searchReferences_ConstructorElement_named_viaTypeAlias() async {
- await resolveTestCode('''
-class A<T> {
- A.named();
-}
-
-typedef B = A<int>;
-
-void f() {
- B.named(); // ref
-}
-''');
-
- var element = findElement.constructor('named');
- var f = findElement.topFunction('f');
- await _verifyReferences(element, [
- _expectIdQ(f, SearchResultKind.REFERENCE, '.named(); // ref',
- length: '.named'.length),
- ]);
- }
-
- test_searchReferences_TypeAliasElement() async {
- await resolveTestCode('''
-class A<T> {
- static int field = 0;
- static void method() {}
-}
-
-typedef B = A<int>;
-
-class C extends B {} // extends
-
-void f(B p) {
- B v;
- B.field = 1;
- B.field;
- B.method();
-}
-''');
-
- var element = findElement.typeAlias('B');
- var f = findElement.topFunction('f');
- await _verifyReferences(element, [
- _expectId(findElement.class_('C'), SearchResultKind.REFERENCE,
- 'B {} // extends'),
- _expectId(findElement.parameter('p'), SearchResultKind.REFERENCE, 'B p'),
- _expectId(f, SearchResultKind.REFERENCE, 'B v'),
- _expectId(f, SearchResultKind.REFERENCE, 'B.field ='),
- _expectId(f, SearchResultKind.REFERENCE, 'B.field;'),
- _expectId(f, SearchResultKind.REFERENCE, 'B.method();'),
- ]);
- }
-
- test_searchReferences_TypeAliasElement_fromLegacy() async {
- newFile('$testPackageLibPath/a.dart', content: r'''
-typedef A<T> = Map<int, T>;
-''');
- await resolveTestCode('''
-// @dart = 2.9
-import 'a.dart';
-
-void f(A<String> a) {}
-''');
-
- var A = findElement.importFind('package:test/a.dart').typeAlias('A');
- await _verifyReferences(A, [
- _expectId(
- findElement.parameter('a'),
- SearchResultKind.REFERENCE,
- 'A<String>',
- ),
- ]);
- }
-
- test_searchReferences_TypeAliasElement_inConstructorName() async {
- await resolveTestCode('''
-class A<T> {}
-
-typedef B = A<int>;
-
-void f() {
- B();
-}
-''');
-
- var element = findElement.typeAlias('B');
- var f = findElement.topFunction('f');
- await _verifyReferences(element, [
- _expectId(f, SearchResultKind.REFERENCE, 'B();'),
- ]);
- }
-}
-
-@reflectiveTest
-class SearchWithNullSafetyTest extends SearchTest with WithNullSafetyMixin {
- test_searchReferences_ImportElement_noPrefix_optIn_fromOptOut() async {
- newFile('$testPackageLibPath/a.dart', content: r'''
-class N1 {}
-void N2() {}
-int get N3 => 0;
-set N4(int _) {}
-''');
-
- await resolveTestCode('''
-// @dart = 2.7
-import 'a.dart';
-
-main() {
- N1;
- N2();
- N3;
- N4 = 0;
-}
-''');
- ImportElement element = findElement.import('package:test/a.dart');
- var main = findElement.function('main');
- var kind = SearchResultKind.REFERENCE;
- var expected = [
- _expectId(main, kind, 'N1;', length: 0),
- _expectId(main, kind, 'N2();', length: 0),
- _expectId(main, kind, 'N3;', length: 0),
- _expectId(main, kind, 'N4 =', length: 0),
- ];
- await _verifyReferences(element, expected);
- }
-
- test_searchReferences_ImportElement_withPrefix_optIn_fromOptOut() async {
- newFile('$testPackageLibPath/a.dart', content: r'''
-class N1 {}
-void N2() {}
-int get N3 => 0;
-set N4(int _) {}
-''');
-
- await resolveTestCode('''
-// @dart = 2.7
-import 'a.dart' as a;
-
-main() {
- a.N1;
- a.N2();
- a.N3;
- a.N4 = 0;
-}
-''');
- ImportElement element = findElement.import('package:test/a.dart');
- var main = findElement.function('main');
- var kind = SearchResultKind.REFERENCE;
- var length = 'a.'.length;
- var expected = [
- _expectId(main, kind, 'a.N1;', length: length),
- _expectId(main, kind, 'a.N2()', length: length),
- _expectId(main, kind, 'a.N3', length: length),
- _expectId(main, kind, 'a.N4', length: length),
- ];
- await _verifyReferences(element, expected);
- }
-}
diff --git a/pkg/dev_compiler/lib/src/kernel/expression_compiler.dart b/pkg/dev_compiler/lib/src/kernel/expression_compiler.dart
index 8c47904..212601c 100644
--- a/pkg/dev_compiler/lib/src/kernel/expression_compiler.dart
+++ b/pkg/dev_compiler/lib/src/kernel/expression_compiler.dart
@@ -358,6 +358,7 @@
_log('Scope not found at $libraryUri:$line:$column');
return null;
}
+ _log('DartScope: $dartScope');
// 2. perform necessary variable substitutions
@@ -371,10 +372,15 @@
dartScope.definitions
.removeWhere((variable, type) => !jsScope.containsKey(variable));
+ dartScope.typeParameters
+ .removeWhere((parameter) => !jsScope.containsKey(parameter.name));
+
// map from values from the stack when available (this allows to evaluate
// captured variables optimized away in chrome)
- var localJsScope =
- dartScope.definitions.keys.map((variable) => jsScope[variable]);
+ var localJsScope = [
+ ...dartScope.typeParameters.map((parameter) => jsScope[parameter.name]),
+ ...dartScope.definitions.keys.map((variable) => jsScope[variable])
+ ];
_log('Performed scope substitutions for expression');
diff --git a/pkg/dev_compiler/test/expression_compiler/expression_compiler_test.dart b/pkg/dev_compiler/test/expression_compiler/expression_compiler_test.dart
index 221b698..b335acd 100644
--- a/pkg/dev_compiler/test/expression_compiler/expression_compiler_test.dart
+++ b/pkg/dev_compiler/test/expression_compiler/expression_compiler_test.dart
@@ -2126,6 +2126,72 @@
''');
});
});
+
+ group('Expression compiler tests in generic method:', () {
+ var source = '''
+ ${options.dartLangComment}
+ class A {
+ void generic<TType, KType>(TType a, KType b) {
+ /* evaluation placeholder */
+ print(a);
+ print(b);
+ }
+ }
+
+ void main() => generic<int, String>(0, 'hi');
+ ''';
+
+ TestDriver driver;
+ setUp(() {
+ driver = TestDriver(options, source);
+ });
+
+ tearDown(() {
+ driver.delete();
+ });
+
+ test('evaluate formals', () async {
+ await driver.check(
+ scope: <String, String>{
+ 'TType': 'TType',
+ 'KType': 'KType',
+ 'a': 'a',
+ 'b': 'b'
+ },
+ expression: 'a',
+ expectedResult: '''
+ (function(TType, KType, a, b) {
+ return a;
+ }.bind(this)(
+ TType,
+ KType,
+ a,
+ b
+ ))
+ ''');
+ });
+
+ test('evaluate type parameters', () async {
+ await driver.check(
+ scope: <String, String>{
+ 'TType': 'TType',
+ 'KType': 'KType',
+ 'a': 'a',
+ 'b': 'b'
+ },
+ expression: 'TType',
+ expectedResult: '''
+ (function(TType, KType, a, b) {
+ return dart.wrapType(dart.legacy(TType));
+ }.bind(this)(
+ TType,
+ KType,
+ a,
+ b
+ ))
+ ''');
+ });
+ });
});
group('Sound null safety:', () {
@@ -3868,5 +3934,71 @@
expectedError: "Error: Getter not found: 'z'");
});
});
+
+ group('Expression compiler tests in generic method:', () {
+ var source = '''
+ ${options.dartLangComment}
+ class A {
+ void generic<TType, KType>(TType a, KType b) {
+ /* evaluation placeholder */
+ print(a);
+ print(b);
+ }
+ }
+
+ void main() => generic<int, String>(0, 'hi');
+ ''';
+
+ TestDriver driver;
+ setUp(() {
+ driver = TestDriver(options, source);
+ });
+
+ tearDown(() {
+ driver.delete();
+ });
+
+ test('evaluate formals', () async {
+ await driver.check(
+ scope: <String, String>{
+ 'TType': 'TType',
+ 'KType': 'KType',
+ 'a': 'a',
+ 'b': 'b'
+ },
+ expression: 'a',
+ expectedResult: '''
+ (function(TType, KType, a, b) {
+ return a;
+ }.bind(this)(
+ TType,
+ KType,
+ a,
+ b
+ ))
+ ''');
+ });
+
+ test('evaluate type parameters', () async {
+ await driver.check(
+ scope: <String, String>{
+ 'TType': 'TType',
+ 'KType': 'KType',
+ 'a': 'a',
+ 'b': 'b'
+ },
+ expression: 'TType',
+ expectedResult: '''
+ (function(TType, KType, a, b) {
+ return dart.wrapType(TType);
+ }.bind(this)(
+ TType,
+ KType,
+ a,
+ b
+ ))
+ ''');
+ });
+ });
});
}
diff --git a/pkg/vm_service/CHANGELOG.md b/pkg/vm_service/CHANGELOG.md
index 4bd758c..a9229ae 100644
--- a/pkg/vm_service/CHANGELOG.md
+++ b/pkg/vm_service/CHANGELOG.md
@@ -1,5 +1,8 @@
# Changelog
+## 6.0.1-nullsafety.1
+- Fix issue where some `Instance` properties were not being populated correctly.
+
## 6.0.1-nullsafety.0
- Fix versioning for pub.
diff --git a/pkg/vm_service/lib/src/vm_service.dart b/pkg/vm_service/lib/src/vm_service.dart
index d7d9d48..fa49390 100644
--- a/pkg/vm_service/lib/src/vm_service.dart
+++ b/pkg/vm_service/lib/src/vm_service.dart
@@ -4811,21 +4811,63 @@
Instance._fromJson(Map<String, dynamic> json) : super._fromJson(json) {
kind = json['kind'] ?? '';
+ classRef =
+ createServiceObject(json['class']!, const ['ClassRef']) as ClassRef;
valueAsString = json['valueAsString'];
valueAsStringIsTruncated = json['valueAsStringIsTruncated'];
length = json['length'];
offset = json['offset'];
count = json['count'];
name = json['name'];
+ typeClass =
+ createServiceObject(json['typeClass'], const ['ClassRef']) as ClassRef?;
+ parameterizedClass =
+ createServiceObject(json['parameterizedClass'], const ['ClassRef'])
+ as ClassRef?;
+ fields = json['fields'] == null
+ ? null
+ : List<BoundField>.from(
+ createServiceObject(json['fields'], const ['BoundField'])! as List);
+ elements = json['elements'] == null
+ ? null
+ : List<dynamic>.from(
+ createServiceObject(json['elements'], const ['dynamic'])! as List);
associations = json['associations'] == null
? null
: List<MapAssociation>.from(
_createSpecificObject(json['associations'], MapAssociation.parse));
bytes = json['bytes'];
+ mirrorReferent =
+ createServiceObject(json['mirrorReferent'], const ['InstanceRef'])
+ as InstanceRef?;
+ pattern = createServiceObject(json['pattern'], const ['InstanceRef'])
+ as InstanceRef?;
+ closureFunction =
+ createServiceObject(json['closureFunction'], const ['FuncRef'])
+ as FuncRef?;
+ closureContext =
+ createServiceObject(json['closureContext'], const ['ContextRef'])
+ as ContextRef?;
isCaseSensitive = json['isCaseSensitive'];
isMultiLine = json['isMultiLine'];
+ propertyKey =
+ createServiceObject(json['propertyKey'], const ['InstanceRef'])
+ as InstanceRef?;
+ propertyValue =
+ createServiceObject(json['propertyValue'], const ['InstanceRef'])
+ as InstanceRef?;
+ typeArguments =
+ createServiceObject(json['typeArguments'], const ['TypeArgumentsRef'])
+ as TypeArgumentsRef?;
parameterIndex = json['parameterIndex'];
+ targetType = createServiceObject(json['targetType'], const ['InstanceRef'])
+ as InstanceRef?;
+ bound = createServiceObject(json['bound'], const ['InstanceRef'])
+ as InstanceRef?;
portId = json['portId'];
+ allocationLocation =
+ createServiceObject(json['allocationLocation'], const ['InstanceRef'])
+ as InstanceRef?;
debugName = json['debugName'];
}
diff --git a/pkg/vm_service/pubspec.yaml b/pkg/vm_service/pubspec.yaml
index fc44e80..7bd051f 100644
--- a/pkg/vm_service/pubspec.yaml
+++ b/pkg/vm_service/pubspec.yaml
@@ -3,7 +3,7 @@
A library to communicate with a service implementing the Dart VM
service protocol.
-version: 6.0.1-nullsafety.0
+version: 6.0.1-nullsafety.1
homepage: https://github.com/dart-lang/sdk/tree/master/pkg/vm_service
diff --git a/pkg/vm_service/tool/dart/generate_dart.dart b/pkg/vm_service/tool/dart/generate_dart.dart
index b41d7ab..81b2970 100644
--- a/pkg/vm_service/tool/dart/generate_dart.dart
+++ b/pkg/vm_service/tool/dart/generate_dart.dart
@@ -1556,15 +1556,13 @@
// Special case `Event.extensionData`.
gen.writeln(
"extensionData = ExtensionData.parse(json['extensionData']);");
- } else if (name == 'Instance') {
- if (field.name == 'associations') {
- // Special case `Instance.associations`.
- gen.writeln("associations = json['associations'] == null "
- "? null : List<MapAssociation>.from("
- "_createSpecificObject(json['associations'], MapAssociation.parse));");
- } else if (field.name == 'classRef') {
- // This is populated by `Obj`
- }
+ } else if (name == 'Instance' && field.name == 'associations') {
+ // Special case `Instance.associations`.
+ gen.writeln("associations = json['associations'] == null "
+ "? null : List<MapAssociation>.from("
+ "_createSpecificObject(json['associations'], MapAssociation.parse));");
+ } else if (name == 'Instance' && field.name == 'classRef') {
+ // This is populated by `Obj`
} else if (name == '_CpuProfile' && field.name == 'codes') {
// Special case `_CpuProfile.codes`.
gen.writeln("codes = List<CodeRegion>.from("
diff --git a/runtime/BUILD.gn b/runtime/BUILD.gn
index 9a3074b..fa6cc2a 100644
--- a/runtime/BUILD.gn
+++ b/runtime/BUILD.gn
@@ -133,6 +133,10 @@
include_dirs += [ "../third_party/tcmalloc/gperftools/src" ]
}
+ if (dart_use_compressed_pointers) {
+ defines += [ "DART_COMPRESSED_POINTERS" ]
+ }
+
if (is_fuchsia) {
if (using_fuchsia_gn_sdk) {
lib_dirs = [ root_out_dir + "/lib" ]
diff --git a/runtime/runtime_args.gni b/runtime/runtime_args.gni
index 1c28c78..7e4e9b4 100644
--- a/runtime/runtime_args.gni
+++ b/runtime/runtime_args.gni
@@ -77,6 +77,9 @@
# Whether package:wasm should be enabled.
dart_enable_wasm = false
+
+ # Whether to use compressed pointers.
+ dart_use_compressed_pointers = false
}
declare_args() {
diff --git a/runtime/vm/clustered_snapshot.cc b/runtime/vm/clustered_snapshot.cc
index ef22f90..c52c61f 100644
--- a/runtime/vm/clustered_snapshot.cc
+++ b/runtime/vm/clustered_snapshot.cc
@@ -128,6 +128,7 @@
}
size_ += (stop_size - start_size) + (stop_data - start_data);
num_objects_ += (stop_objects - start_objects);
+ target_memory_size_ += num_objects_ * target_instance_size_;
}
void SerializationCluster::WriteAndMeasureFill(Serializer* serializer) {
@@ -178,7 +179,7 @@
class ClassSerializationCluster : public SerializationCluster {
public:
explicit ClassSerializationCluster(intptr_t num_cids)
- : SerializationCluster("Class"),
+ : SerializationCluster("Class", compiler::target::Class::InstanceSize()),
predefined_(kNumPredefinedCids),
objects_(num_cids) {}
~ClassSerializationCluster() {}
@@ -432,6 +433,8 @@
AutoTraceObject(type_args);
const intptr_t length = Smi::Value(type_args->untag()->length_);
s->WriteUnsigned(length);
+ target_memory_size_ +=
+ compiler::target::TypeArguments::InstanceSize(length);
}
}
@@ -517,7 +520,9 @@
#if !defined(DART_PRECOMPILED_RUNTIME)
class PatchClassSerializationCluster : public SerializationCluster {
public:
- PatchClassSerializationCluster() : SerializationCluster("PatchClass") {}
+ PatchClassSerializationCluster()
+ : SerializationCluster("PatchClass",
+ compiler::target::PatchClass::InstanceSize()) {}
~PatchClassSerializationCluster() {}
void Trace(Serializer* s, ObjectPtr object) {
@@ -587,7 +592,9 @@
#if !defined(DART_PRECOMPILED_RUNTIME)
class FunctionSerializationCluster : public SerializationCluster {
public:
- FunctionSerializationCluster() : SerializationCluster("Function") {}
+ FunctionSerializationCluster()
+ : SerializationCluster("Function",
+ compiler::target::Function::InstanceSize()) {}
~FunctionSerializationCluster() {}
void Trace(Serializer* s, ObjectPtr object) {
@@ -765,7 +772,9 @@
#if !defined(DART_PRECOMPILED_RUNTIME)
class ClosureDataSerializationCluster : public SerializationCluster {
public:
- ClosureDataSerializationCluster() : SerializationCluster("ClosureData") {}
+ ClosureDataSerializationCluster()
+ : SerializationCluster("ClosureData",
+ compiler::target::ClosureData::InstanceSize()) {}
~ClosureDataSerializationCluster() {}
void Trace(Serializer* s, ObjectPtr object) {
@@ -852,7 +861,9 @@
class FfiTrampolineDataSerializationCluster : public SerializationCluster {
public:
FfiTrampolineDataSerializationCluster()
- : SerializationCluster("FfiTrampolineData") {}
+ : SerializationCluster(
+ "FfiTrampolineData",
+ compiler::target::FfiTrampolineData::InstanceSize()) {}
~FfiTrampolineDataSerializationCluster() {}
void Trace(Serializer* s, ObjectPtr object) {
@@ -923,7 +934,9 @@
#if !defined(DART_PRECOMPILED_RUNTIME)
class FieldSerializationCluster : public SerializationCluster {
public:
- FieldSerializationCluster() : SerializationCluster("Field") {}
+ FieldSerializationCluster()
+ : SerializationCluster("Field", compiler::target::Field::InstanceSize()) {
+ }
~FieldSerializationCluster() {}
void Trace(Serializer* s, ObjectPtr object) {
@@ -1106,7 +1119,9 @@
#if !defined(DART_PRECOMPILED_RUNTIME)
class ScriptSerializationCluster : public SerializationCluster {
public:
- ScriptSerializationCluster() : SerializationCluster("Script") {}
+ ScriptSerializationCluster()
+ : SerializationCluster("Script",
+ compiler::target::Script::InstanceSize()) {}
~ScriptSerializationCluster() {}
void Trace(Serializer* s, ObjectPtr object) {
@@ -1187,7 +1202,9 @@
#if !defined(DART_PRECOMPILED_RUNTIME)
class LibrarySerializationCluster : public SerializationCluster {
public:
- LibrarySerializationCluster() : SerializationCluster("Library") {}
+ LibrarySerializationCluster()
+ : SerializationCluster("Library",
+ compiler::target::Library::InstanceSize()) {}
~LibrarySerializationCluster() {}
void Trace(Serializer* s, ObjectPtr object) {
@@ -1266,7 +1283,9 @@
#if !defined(DART_PRECOMPILED_RUNTIME)
class NamespaceSerializationCluster : public SerializationCluster {
public:
- NamespaceSerializationCluster() : SerializationCluster("Namespace") {}
+ NamespaceSerializationCluster()
+ : SerializationCluster("Namespace",
+ compiler::target::Namespace::InstanceSize()) {}
~NamespaceSerializationCluster() {}
void Trace(Serializer* s, ObjectPtr object) {
@@ -1329,7 +1348,9 @@
class KernelProgramInfoSerializationCluster : public SerializationCluster {
public:
KernelProgramInfoSerializationCluster()
- : SerializationCluster("KernelProgramInfo") {}
+ : SerializationCluster(
+ "KernelProgramInfo",
+ compiler::target::KernelProgramInfo::InstanceSize()) {}
~KernelProgramInfoSerializationCluster() {}
void Trace(Serializer* s, ObjectPtr object) {
@@ -1407,7 +1428,8 @@
class CodeSerializationCluster : public SerializationCluster {
public:
explicit CodeSerializationCluster(Heap* heap)
- : SerializationCluster("Code"), array_(Array::Handle()) {}
+ : SerializationCluster("Code", compiler::target::Code::InstanceSize()),
+ array_(Array::Handle()) {}
~CodeSerializationCluster() {}
void Trace(Serializer* s, ObjectPtr object) {
@@ -1873,6 +1895,7 @@
AutoTraceObject(pool);
const intptr_t length = pool->untag()->length_;
s->WriteUnsigned(length);
+ target_memory_size_ += compiler::target::ObjectPool::InstanceSize(length);
}
}
@@ -1975,7 +1998,9 @@
: public SerializationCluster {
public:
WeakSerializationReferenceSerializationCluster(Zone* zone, Heap* heap)
- : SerializationCluster("WeakSerializationReference"),
+ : SerializationCluster(
+ "WeakSerializationReference",
+ compiler::target::WeakSerializationReference::InstanceSize()),
heap_(ASSERT_NOTNULL(heap)),
objects_(zone, 0),
canonical_wsrs_(zone, 0),
@@ -2137,6 +2162,8 @@
AutoTraceObject(desc);
const intptr_t length = desc->untag()->length_;
s->WriteUnsigned(length);
+ target_memory_size_ +=
+ compiler::target::PcDescriptors::InstanceSize(length);
}
}
@@ -2316,6 +2343,8 @@
AutoTraceObject(handlers);
const intptr_t length = handlers->untag()->num_entries_;
s->WriteUnsigned(length);
+ target_memory_size_ +=
+ compiler::target::ExceptionHandlers::InstanceSize(length);
}
}
@@ -2410,6 +2439,7 @@
AutoTraceObject(context);
const intptr_t length = context->untag()->num_variables_;
s->WriteUnsigned(length);
+ target_memory_size_ += compiler::target::Context::InstanceSize(length);
}
}
@@ -2488,6 +2518,8 @@
AutoTraceObject(scope);
const intptr_t length = scope->untag()->num_variables_;
s->WriteUnsigned(length);
+ target_memory_size_ +=
+ compiler::target::ContextScope::InstanceSize(length);
}
}
@@ -2542,7 +2574,9 @@
#if !defined(DART_PRECOMPILED_RUNTIME)
class UnlinkedCallSerializationCluster : public SerializationCluster {
public:
- UnlinkedCallSerializationCluster() : SerializationCluster("UnlinkedCall") {}
+ UnlinkedCallSerializationCluster()
+ : SerializationCluster("UnlinkedCall",
+ compiler::target::UnlinkedCall::InstanceSize()) {}
~UnlinkedCallSerializationCluster() {}
void Trace(Serializer* s, ObjectPtr object) {
@@ -2607,7 +2641,9 @@
#if !defined(DART_PRECOMPILED_RUNTIME)
class ICDataSerializationCluster : public SerializationCluster {
public:
- ICDataSerializationCluster() : SerializationCluster("ICData") {}
+ ICDataSerializationCluster()
+ : SerializationCluster("ICData",
+ compiler::target::ICData::InstanceSize()) {}
~ICDataSerializationCluster() {}
void Trace(Serializer* s, ObjectPtr object) {
@@ -2675,7 +2711,9 @@
class MegamorphicCacheSerializationCluster : public SerializationCluster {
public:
MegamorphicCacheSerializationCluster()
- : SerializationCluster("MegamorphicCache") {}
+ : SerializationCluster(
+ "MegamorphicCache",
+ compiler::target::MegamorphicCache::InstanceSize()) {}
~MegamorphicCacheSerializationCluster() {}
void Trace(Serializer* s, ObjectPtr object) {
@@ -2767,7 +2805,9 @@
class SubtypeTestCacheSerializationCluster : public SerializationCluster {
public:
SubtypeTestCacheSerializationCluster()
- : SerializationCluster("SubtypeTestCache") {}
+ : SerializationCluster(
+ "SubtypeTestCache",
+ compiler::target::SubtypeTestCache::InstanceSize()) {}
~SubtypeTestCacheSerializationCluster() {}
void Trace(Serializer* s, ObjectPtr object) {
@@ -2830,7 +2870,9 @@
#if !defined(DART_PRECOMPILED_RUNTIME)
class LoadingUnitSerializationCluster : public SerializationCluster {
public:
- LoadingUnitSerializationCluster() : SerializationCluster("LoadingUnit") {}
+ LoadingUnitSerializationCluster()
+ : SerializationCluster("LoadingUnit",
+ compiler::target::LoadingUnit::InstanceSize()) {}
~LoadingUnitSerializationCluster() {}
void Trace(Serializer* s, ObjectPtr object) {
@@ -2897,7 +2939,9 @@
#if !defined(DART_PRECOMPILED_RUNTIME)
class LanguageErrorSerializationCluster : public SerializationCluster {
public:
- LanguageErrorSerializationCluster() : SerializationCluster("LanguageError") {}
+ LanguageErrorSerializationCluster()
+ : SerializationCluster("LanguageError",
+ compiler::target::LanguageError::InstanceSize()) {}
~LanguageErrorSerializationCluster() {}
void Trace(Serializer* s, ObjectPtr object) {
@@ -2967,7 +3011,9 @@
class UnhandledExceptionSerializationCluster : public SerializationCluster {
public:
UnhandledExceptionSerializationCluster()
- : SerializationCluster("UnhandledException") {}
+ : SerializationCluster(
+ "UnhandledException",
+ compiler::target::UnhandledException::InstanceSize()) {}
~UnhandledExceptionSerializationCluster() {}
void Trace(Serializer* s, ObjectPtr object) {
@@ -3037,14 +3083,12 @@
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_PRECOMPILED_RUNTIME)
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_;
ASSERT(target_next_field_offset_in_words_ > 0);
ASSERT(target_instance_size_in_words_ > 0);
-#endif // !defined(DART_PRECOMPILED_RUNTIME)
}
~InstanceSerializationCluster() {}
@@ -3073,17 +3117,17 @@
const intptr_t count = objects_.length();
s->WriteUnsigned(count);
-#if !defined(DART_PRECOMPILED_RUNTIME)
s->Write<int32_t>(target_next_field_offset_in_words_);
s->Write<int32_t>(target_instance_size_in_words_);
-#else
- s->Write<int32_t>(host_next_field_offset_in_words_);
-#endif // !defined(DART_PRECOMPILED_RUNTIME)
for (intptr_t i = 0; i < count; i++) {
InstancePtr instance = objects_[i];
s->AssignRef(instance);
}
+
+ const intptr_t instance_size = compiler::target::RoundedAllocationSize(
+ target_instance_size_in_words_ * compiler::target::kWordSize);
+ target_memory_size_ += instance_size * count;
}
void WriteFill(Serializer* s) {
@@ -3118,10 +3162,8 @@
private:
const intptr_t cid_;
intptr_t host_next_field_offset_in_words_;
-#if !defined(DART_PRECOMPILED_RUNTIME)
intptr_t target_next_field_offset_in_words_;
intptr_t target_instance_size_in_words_;
-#endif // !defined(DART_PRECOMPILED_RUNTIME)
GrowableArray<InstancePtr> objects_;
};
#endif // !DART_PRECOMPILED_RUNTIME
@@ -3189,7 +3231,9 @@
#if !defined(DART_PRECOMPILED_RUNTIME)
class LibraryPrefixSerializationCluster : public SerializationCluster {
public:
- LibraryPrefixSerializationCluster() : SerializationCluster("LibraryPrefix") {}
+ LibraryPrefixSerializationCluster()
+ : SerializationCluster("LibraryPrefix",
+ compiler::target::LibraryPrefix::InstanceSize()) {}
~LibraryPrefixSerializationCluster() {}
void Trace(Serializer* s, ObjectPtr object) {
@@ -3261,7 +3305,8 @@
#if !defined(DART_PRECOMPILED_RUNTIME)
class TypeSerializationCluster : public SerializationCluster {
public:
- TypeSerializationCluster() : SerializationCluster("Type") {}
+ TypeSerializationCluster()
+ : SerializationCluster("Type", compiler::target::Type::InstanceSize()) {}
~TypeSerializationCluster() {}
void Trace(Serializer* s, ObjectPtr object) {
@@ -3384,7 +3429,9 @@
#if !defined(DART_PRECOMPILED_RUNTIME)
class FunctionTypeSerializationCluster : public SerializationCluster {
public:
- FunctionTypeSerializationCluster() : SerializationCluster("FunctionType") {}
+ FunctionTypeSerializationCluster()
+ : SerializationCluster("FunctionType",
+ compiler::target::FunctionType::InstanceSize()) {}
~FunctionTypeSerializationCluster() {}
void Trace(Serializer* s, ObjectPtr object) {
@@ -3504,7 +3551,9 @@
#if !defined(DART_PRECOMPILED_RUNTIME)
class TypeRefSerializationCluster : public SerializationCluster {
public:
- TypeRefSerializationCluster() : SerializationCluster("TypeRef") {}
+ TypeRefSerializationCluster()
+ : SerializationCluster("TypeRef",
+ compiler::target::TypeRef::InstanceSize()) {}
~TypeRefSerializationCluster() {}
void Trace(Serializer* s, ObjectPtr object) {
@@ -3585,7 +3634,9 @@
#if !defined(DART_PRECOMPILED_RUNTIME)
class TypeParameterSerializationCluster : public SerializationCluster {
public:
- TypeParameterSerializationCluster() : SerializationCluster("TypeParameter") {}
+ TypeParameterSerializationCluster()
+ : SerializationCluster("TypeParameter",
+ compiler::target::TypeParameter::InstanceSize()) {}
~TypeParameterSerializationCluster() {}
void Trace(Serializer* s, ObjectPtr object) {
@@ -3706,7 +3757,9 @@
#if !defined(DART_PRECOMPILED_RUNTIME)
class ClosureSerializationCluster : public SerializationCluster {
public:
- ClosureSerializationCluster() : SerializationCluster("Closure") {}
+ ClosureSerializationCluster()
+ : SerializationCluster("Closure",
+ compiler::target::Closure::InstanceSize()) {}
~ClosureSerializationCluster() {}
void Trace(Serializer* s, ObjectPtr object) {
@@ -3767,7 +3820,8 @@
#if !defined(DART_PRECOMPILED_RUNTIME)
class MintSerializationCluster : public SerializationCluster {
public:
- MintSerializationCluster() : SerializationCluster("int") {}
+ MintSerializationCluster()
+ : SerializationCluster("int", compiler::target::Mint::InstanceSize()) {}
~MintSerializationCluster() {}
void Trace(Serializer* s, ObjectPtr object) {
@@ -3854,7 +3908,9 @@
#if !defined(DART_PRECOMPILED_RUNTIME)
class DoubleSerializationCluster : public SerializationCluster {
public:
- DoubleSerializationCluster() : SerializationCluster("double") {}
+ DoubleSerializationCluster()
+ : SerializationCluster("double",
+ compiler::target::Double::InstanceSize()) {}
~DoubleSerializationCluster() {}
void Trace(Serializer* s, ObjectPtr object) {
@@ -3915,7 +3971,9 @@
class GrowableObjectArraySerializationCluster : public SerializationCluster {
public:
GrowableObjectArraySerializationCluster()
- : SerializationCluster("GrowableObjectArray") {}
+ : SerializationCluster(
+ "GrowableObjectArray",
+ compiler::target::GrowableObjectArray::InstanceSize()) {}
~GrowableObjectArraySerializationCluster() {}
void Trace(Serializer* s, ObjectPtr object) {
@@ -3994,12 +4052,15 @@
s->WriteCid(cid_);
const intptr_t count = objects_.length();
s->WriteUnsigned(count);
+ const intptr_t element_size = TypedData::ElementSizeInBytes(cid_);
for (intptr_t i = 0; i < count; i++) {
TypedDataPtr data = objects_[i];
s->AssignRef(data);
AutoTraceObject(data);
const intptr_t length = Smi::Value(data->untag()->length_);
s->WriteUnsigned(length);
+ target_memory_size_ +=
+ compiler::target::TypedData::InstanceSize(length * element_size);
}
}
@@ -4065,7 +4126,9 @@
class TypedDataViewSerializationCluster : public SerializationCluster {
public:
explicit TypedDataViewSerializationCluster(intptr_t cid)
- : SerializationCluster("TypedDataView"), cid_(cid) {}
+ : SerializationCluster("TypedDataView",
+ compiler::target::TypedDataView::InstanceSize()),
+ cid_(cid) {}
~TypedDataViewSerializationCluster() {}
void Trace(Serializer* s, ObjectPtr object) {
@@ -4142,7 +4205,10 @@
class ExternalTypedDataSerializationCluster : public SerializationCluster {
public:
explicit ExternalTypedDataSerializationCluster(intptr_t cid)
- : SerializationCluster("ExternalTypedData"), cid_(cid) {}
+ : SerializationCluster(
+ "ExternalTypedData",
+ compiler::target::ExternalTypedData::InstanceSize()),
+ cid_(cid) {}
~ExternalTypedDataSerializationCluster() {}
void Trace(Serializer* s, ObjectPtr object) {
@@ -4220,7 +4286,9 @@
#if !defined(DART_PRECOMPILED_RUNTIME)
class StackTraceSerializationCluster : public SerializationCluster {
public:
- StackTraceSerializationCluster() : SerializationCluster("StackTrace") {}
+ StackTraceSerializationCluster()
+ : SerializationCluster("StackTrace",
+ compiler::target::StackTrace::InstanceSize()) {}
~StackTraceSerializationCluster() {}
void Trace(Serializer* s, ObjectPtr object) {
@@ -4282,7 +4350,9 @@
#if !defined(DART_PRECOMPILED_RUNTIME)
class RegExpSerializationCluster : public SerializationCluster {
public:
- RegExpSerializationCluster() : SerializationCluster("RegExp") {}
+ RegExpSerializationCluster()
+ : SerializationCluster("RegExp",
+ compiler::target::RegExp::InstanceSize()) {}
~RegExpSerializationCluster() {}
void Trace(Serializer* s, ObjectPtr object) {
@@ -4349,7 +4419,9 @@
#if !defined(DART_PRECOMPILED_RUNTIME)
class WeakPropertySerializationCluster : public SerializationCluster {
public:
- WeakPropertySerializationCluster() : SerializationCluster("WeakProperty") {}
+ WeakPropertySerializationCluster()
+ : SerializationCluster("WeakProperty",
+ compiler::target::WeakProperty::InstanceSize()) {}
~WeakPropertySerializationCluster() {}
void Trace(Serializer* s, ObjectPtr object) {
@@ -4413,7 +4485,9 @@
#if !defined(DART_PRECOMPILED_RUNTIME)
class LinkedHashMapSerializationCluster : public SerializationCluster {
public:
- LinkedHashMapSerializationCluster() : SerializationCluster("LinkedHashMap") {}
+ LinkedHashMapSerializationCluster()
+ : SerializationCluster("LinkedHashMap",
+ compiler::target::LinkedHashMap::InstanceSize()) {}
~LinkedHashMapSerializationCluster() {}
void Trace(Serializer* s, ObjectPtr object) {
@@ -4562,6 +4636,7 @@
AutoTraceObject(array);
const intptr_t length = Smi::Value(array->untag()->length_);
s->WriteUnsigned(length);
+ target_memory_size_ += compiler::target::Array::InstanceSize(length);
}
}
@@ -4643,6 +4718,8 @@
AutoTraceObject(str);
const intptr_t length = Smi::Value(str->untag()->length_);
s->WriteUnsigned(length);
+ target_memory_size_ +=
+ compiler::target::OneByteString::InstanceSize(length);
}
}
@@ -4736,6 +4813,8 @@
AutoTraceObject(str);
const intptr_t length = Smi::Value(str->untag()->length_);
s->WriteUnsigned(length);
+ target_memory_size_ +=
+ compiler::target::TwoByteString::InstanceSize(length);
}
}
@@ -4815,10 +4894,12 @@
public:
FakeSerializationCluster(const char* name,
intptr_t num_objects,
- intptr_t size)
+ intptr_t size,
+ intptr_t target_memory_size = 0)
: SerializationCluster(name) {
num_objects_ = num_objects;
size_ = size;
+ target_memory_size_ = target_memory_size;
}
~FakeSerializationCluster() {}
@@ -6146,7 +6227,8 @@
#if !defined(DART_PRECOMPILED_RUNTIME)
if (FLAG_print_snapshot_sizes_verbose) {
OS::PrintErr(
- " Cluster Objs Size Fraction Cumulative\n");
+ " Cluster Objs Size Fraction Cumulative "
+ " HeapSize\n");
GrowableArray<SerializationCluster*> clusters_by_size;
for (intptr_t cid = 1; cid < num_cids_; cid++) {
SerializationCluster* cluster = clusters_by_cid_[cid];
@@ -6191,9 +6273,10 @@
SerializationCluster* cluster = clusters_by_size[i];
double fraction = static_cast<double>(cluster->size()) / total_size;
cumulative_fraction += fraction;
- OS::PrintErr("%25s %6" Pd " %8" Pd " %lf %lf\n", cluster->name(),
- cluster->num_objects(), cluster->size(), fraction,
- cumulative_fraction);
+ OS::PrintErr("%25s %6" Pd " %8" Pd " %lf %lf %8" Pd "\n",
+ cluster->name(), cluster->num_objects(), cluster->size(),
+ fraction, cumulative_fraction,
+ cluster->target_memory_size());
}
}
#endif // !defined(DART_PRECOMPILED_RUNTIME)
diff --git a/runtime/vm/clustered_snapshot.h b/runtime/vm/clustered_snapshot.h
index ac72aed..d69e4443 100644
--- a/runtime/vm/clustered_snapshot.h
+++ b/runtime/vm/clustered_snapshot.h
@@ -80,8 +80,13 @@
class SerializationCluster : public ZoneAllocated {
public:
- explicit SerializationCluster(const char* name)
- : name_(name), size_(0), num_objects_(0) {}
+ explicit SerializationCluster(const char* name,
+ intptr_t target_instance_size = 0)
+ : name_(name),
+ size_(0),
+ num_objects_(0),
+ target_instance_size_(target_instance_size),
+ target_memory_size_(0) {}
virtual ~SerializationCluster() {}
// Add [object] to the cluster and push its outgoing references.
@@ -102,10 +107,21 @@
intptr_t size() const { return size_; }
intptr_t num_objects() const { return num_objects_; }
+ // Returns number of bytes needed for deserialized objects in
+ // this cluster. Printed in --print_snapshot_sizes_verbose statistics.
+ //
+ // In order to calculate this size, clusters of fixed-size objects
+ // can pass instance size as [target_instance_size] constructor parameter.
+ // Otherwise clusters should count [target_memory_size] in
+ // their [WriteAlloc] methods.
+ intptr_t target_memory_size() const { return target_memory_size_; }
+
protected:
const char* name_;
intptr_t size_;
intptr_t num_objects_;
+ const intptr_t target_instance_size_;
+ intptr_t target_memory_size_;
};
class DeserializationCluster : public ZoneAllocated {
diff --git a/runtime/vm/compiler/runtime_api.cc b/runtime/vm/compiler/runtime_api.cc
index a13025f..1e8aa18 100644
--- a/runtime/vm/compiler/runtime_api.cc
+++ b/runtime/vm/compiler/runtime_api.cc
@@ -869,6 +869,10 @@
return -kWordSize;
}
+word ObjectPool::InstanceSize(intptr_t length) {
+ return RoundedAllocationSize(ObjectPool::element_offset(length));
+}
+
word Class::NextFieldOffset() {
return -kWordSize;
}
@@ -898,6 +902,10 @@
TranslateOffsetInWordsToHost(offset_in_bytes));
}
+word Array::InstanceSize(intptr_t length) {
+ return RoundedAllocationSize(Array::element_offset(length));
+}
+
word GrowableObjectArray::NextFieldOffset() {
return -kWordSize;
}
@@ -910,6 +918,10 @@
return -kWordSize;
}
+word TypedData::InstanceSize(intptr_t lengthInBytes) {
+ return RoundedAllocationSize(TypedData::InstanceSize() + lengthInBytes);
+}
+
word ExternalTypedData::NextFieldOffset() {
return -kWordSize;
}
@@ -958,10 +970,20 @@
return -kWordSize;
}
+word OneByteString::InstanceSize(intptr_t length) {
+ return RoundedAllocationSize(OneByteString::InstanceSize() +
+ length * dart::OneByteString::kBytesPerElement);
+}
+
word TwoByteString::NextFieldOffset() {
return -kWordSize;
}
+word TwoByteString::InstanceSize(intptr_t length) {
+ return RoundedAllocationSize(TwoByteString::InstanceSize() +
+ length * dart::TwoByteString::kBytesPerElement);
+}
+
word ExternalOneByteString::NextFieldOffset() {
return -kWordSize;
}
@@ -1030,10 +1052,18 @@
return -kWordSize;
}
+word ExceptionHandlers::InstanceSize(intptr_t length) {
+ return RoundedAllocationSize(ExceptionHandlers::element_offset(length));
+}
+
word ContextScope::NextFieldOffset() {
return -kWordSize;
}
+word ContextScope::InstanceSize(intptr_t length) {
+ return RoundedAllocationSize(ContextScope::element_offset(length));
+}
+
word UnlinkedCall::NextFieldOffset() {
return -kWordSize;
}
@@ -1162,6 +1192,10 @@
return -kWordSize;
}
+word TypeArguments::InstanceSize(intptr_t length) {
+ return RoundedAllocationSize(TypeArguments::type_at_offset(length));
+}
+
word FreeListElement::FakeInstance::NextFieldOffset() {
return -kWordSize;
}
diff --git a/runtime/vm/compiler/runtime_api.h b/runtime/vm/compiler/runtime_api.h
index d690ef4..6ef19fd 100644
--- a/runtime/vm/compiler/runtime_api.h
+++ b/runtime/vm/compiler/runtime_api.h
@@ -440,6 +440,7 @@
public:
// Return offset to the element with the given [index] in the object pool.
static word element_offset(intptr_t index);
+ static word InstanceSize(intptr_t length);
static word InstanceSize();
static word NextFieldOffset();
};
@@ -560,6 +561,7 @@
static word length_offset();
static word element_offset(intptr_t index);
static intptr_t index_at_offset(intptr_t offset_in_bytes);
+ static word InstanceSize(intptr_t length);
static word InstanceSize();
static word NextFieldOffset();
@@ -591,6 +593,7 @@
class TypedData : public AllStatic {
public:
static word data_offset();
+ static word InstanceSize(intptr_t lengthInBytes);
static word InstanceSize();
static word NextFieldOffset();
};
@@ -725,6 +728,7 @@
class OneByteString : public AllStatic {
public:
static word data_offset();
+ static word InstanceSize(intptr_t length);
static word InstanceSize();
static word NextFieldOffset();
};
@@ -732,6 +736,7 @@
class TwoByteString : public AllStatic {
public:
static word data_offset();
+ static word InstanceSize(intptr_t length);
static word InstanceSize();
static word NextFieldOffset();
};
@@ -845,12 +850,16 @@
class ExceptionHandlers : public AllStatic {
public:
+ static word element_offset(intptr_t index);
+ static word InstanceSize(intptr_t length);
static word InstanceSize();
static word NextFieldOffset();
};
class ContextScope : public AllStatic {
public:
+ static word element_offset(intptr_t index);
+ static word InstanceSize(intptr_t length);
static word InstanceSize();
static word NextFieldOffset();
};
@@ -1333,6 +1342,7 @@
static word nullability_offset();
static word type_at_offset(intptr_t i);
static word types_offset();
+ static word InstanceSize(intptr_t length);
static word InstanceSize();
static word NextFieldOffset();
diff --git a/runtime/vm/compiler/runtime_offsets_extracted.h b/runtime/vm/compiler/runtime_offsets_extracted.h
index 5bdddc8..63898cb 100644
--- a/runtime/vm/compiler/runtime_offsets_extracted.h
+++ b/runtime/vm/compiler/runtime_offsets_extracted.h
@@ -22,6 +22,13 @@
76;
static constexpr dart::compiler::target::word
ICData_receivers_static_type_offset = 16;
+static constexpr dart::compiler::target::word
+ ContextScope_elements_start_offset = 12;
+static constexpr dart::compiler::target::word ContextScope_element_size = 32;
+static constexpr dart::compiler::target::word
+ ExceptionHandlers_elements_start_offset = 12;
+static constexpr dart::compiler::target::word ExceptionHandlers_element_size =
+ 12;
static constexpr dart::compiler::target::word ObjectPool_elements_start_offset =
8;
static constexpr dart::compiler::target::word ObjectPool_element_size = 4;
@@ -545,6 +552,13 @@
116;
static constexpr dart::compiler::target::word
ICData_receivers_static_type_offset = 32;
+static constexpr dart::compiler::target::word
+ ContextScope_elements_start_offset = 16;
+static constexpr dart::compiler::target::word ContextScope_element_size = 64;
+static constexpr dart::compiler::target::word
+ ExceptionHandlers_elements_start_offset = 24;
+static constexpr dart::compiler::target::word ExceptionHandlers_element_size =
+ 12;
static constexpr dart::compiler::target::word ObjectPool_elements_start_offset =
16;
static constexpr dart::compiler::target::word ObjectPool_element_size = 8;
@@ -1076,6 +1090,13 @@
76;
static constexpr dart::compiler::target::word
ICData_receivers_static_type_offset = 16;
+static constexpr dart::compiler::target::word
+ ContextScope_elements_start_offset = 12;
+static constexpr dart::compiler::target::word ContextScope_element_size = 32;
+static constexpr dart::compiler::target::word
+ ExceptionHandlers_elements_start_offset = 12;
+static constexpr dart::compiler::target::word ExceptionHandlers_element_size =
+ 12;
static constexpr dart::compiler::target::word ObjectPool_elements_start_offset =
8;
static constexpr dart::compiler::target::word ObjectPool_element_size = 4;
@@ -1596,6 +1617,13 @@
116;
static constexpr dart::compiler::target::word
ICData_receivers_static_type_offset = 32;
+static constexpr dart::compiler::target::word
+ ContextScope_elements_start_offset = 16;
+static constexpr dart::compiler::target::word ContextScope_element_size = 64;
+static constexpr dart::compiler::target::word
+ ExceptionHandlers_elements_start_offset = 24;
+static constexpr dart::compiler::target::word ExceptionHandlers_element_size =
+ 12;
static constexpr dart::compiler::target::word ObjectPool_elements_start_offset =
16;
static constexpr dart::compiler::target::word ObjectPool_element_size = 8;
@@ -2130,6 +2158,13 @@
76;
static constexpr dart::compiler::target::word
ICData_receivers_static_type_offset = 16;
+static constexpr dart::compiler::target::word
+ ContextScope_elements_start_offset = 12;
+static constexpr dart::compiler::target::word ContextScope_element_size = 32;
+static constexpr dart::compiler::target::word
+ ExceptionHandlers_elements_start_offset = 12;
+static constexpr dart::compiler::target::word ExceptionHandlers_element_size =
+ 12;
static constexpr dart::compiler::target::word ObjectPool_elements_start_offset =
8;
static constexpr dart::compiler::target::word ObjectPool_element_size = 4;
@@ -2647,6 +2682,13 @@
116;
static constexpr dart::compiler::target::word
ICData_receivers_static_type_offset = 32;
+static constexpr dart::compiler::target::word
+ ContextScope_elements_start_offset = 16;
+static constexpr dart::compiler::target::word ContextScope_element_size = 64;
+static constexpr dart::compiler::target::word
+ ExceptionHandlers_elements_start_offset = 24;
+static constexpr dart::compiler::target::word ExceptionHandlers_element_size =
+ 12;
static constexpr dart::compiler::target::word ObjectPool_elements_start_offset =
16;
static constexpr dart::compiler::target::word ObjectPool_element_size = 8;
@@ -3172,6 +3214,13 @@
76;
static constexpr dart::compiler::target::word
ICData_receivers_static_type_offset = 16;
+static constexpr dart::compiler::target::word
+ ContextScope_elements_start_offset = 12;
+static constexpr dart::compiler::target::word ContextScope_element_size = 32;
+static constexpr dart::compiler::target::word
+ ExceptionHandlers_elements_start_offset = 12;
+static constexpr dart::compiler::target::word ExceptionHandlers_element_size =
+ 12;
static constexpr dart::compiler::target::word ObjectPool_elements_start_offset =
8;
static constexpr dart::compiler::target::word ObjectPool_element_size = 4;
@@ -3686,6 +3735,13 @@
116;
static constexpr dart::compiler::target::word
ICData_receivers_static_type_offset = 32;
+static constexpr dart::compiler::target::word
+ ContextScope_elements_start_offset = 16;
+static constexpr dart::compiler::target::word ContextScope_element_size = 64;
+static constexpr dart::compiler::target::word
+ ExceptionHandlers_elements_start_offset = 24;
+static constexpr dart::compiler::target::word ExceptionHandlers_element_size =
+ 12;
static constexpr dart::compiler::target::word ObjectPool_elements_start_offset =
16;
static constexpr dart::compiler::target::word ObjectPool_element_size = 8;
@@ -4213,6 +4269,14 @@
#if defined(TARGET_ARCH_ARM)
static constexpr dart::compiler::target::word
+ AOT_ContextScope_elements_start_offset = 12;
+static constexpr dart::compiler::target::word AOT_ContextScope_element_size =
+ 32;
+static constexpr dart::compiler::target::word
+ AOT_ExceptionHandlers_elements_start_offset = 12;
+static constexpr dart::compiler::target::word
+ AOT_ExceptionHandlers_element_size = 12;
+static constexpr dart::compiler::target::word
AOT_ObjectPool_elements_start_offset = 8;
static constexpr dart::compiler::target::word AOT_ObjectPool_element_size = 4;
static constexpr dart::compiler::target::word AOT_Array_kMaxElements =
@@ -4796,6 +4860,14 @@
#if defined(TARGET_ARCH_X64)
static constexpr dart::compiler::target::word
+ AOT_ContextScope_elements_start_offset = 16;
+static constexpr dart::compiler::target::word AOT_ContextScope_element_size =
+ 64;
+static constexpr dart::compiler::target::word
+ AOT_ExceptionHandlers_elements_start_offset = 24;
+static constexpr dart::compiler::target::word
+ AOT_ExceptionHandlers_element_size = 12;
+static constexpr dart::compiler::target::word
AOT_ObjectPool_elements_start_offset = 16;
static constexpr dart::compiler::target::word AOT_ObjectPool_element_size = 8;
static constexpr dart::compiler::target::word AOT_Array_kMaxElements =
@@ -5386,6 +5458,14 @@
#if defined(TARGET_ARCH_ARM64)
static constexpr dart::compiler::target::word
+ AOT_ContextScope_elements_start_offset = 16;
+static constexpr dart::compiler::target::word AOT_ContextScope_element_size =
+ 64;
+static constexpr dart::compiler::target::word
+ AOT_ExceptionHandlers_elements_start_offset = 24;
+static constexpr dart::compiler::target::word
+ AOT_ExceptionHandlers_element_size = 12;
+static constexpr dart::compiler::target::word
AOT_ObjectPool_elements_start_offset = 16;
static constexpr dart::compiler::target::word AOT_ObjectPool_element_size = 8;
static constexpr dart::compiler::target::word AOT_Array_kMaxElements =
@@ -5976,6 +6056,14 @@
#if defined(TARGET_ARCH_ARM)
static constexpr dart::compiler::target::word
+ AOT_ContextScope_elements_start_offset = 12;
+static constexpr dart::compiler::target::word AOT_ContextScope_element_size =
+ 32;
+static constexpr dart::compiler::target::word
+ AOT_ExceptionHandlers_elements_start_offset = 12;
+static constexpr dart::compiler::target::word
+ AOT_ExceptionHandlers_element_size = 12;
+static constexpr dart::compiler::target::word
AOT_ObjectPool_elements_start_offset = 8;
static constexpr dart::compiler::target::word AOT_ObjectPool_element_size = 4;
static constexpr dart::compiler::target::word AOT_Array_kMaxElements =
@@ -6552,6 +6640,14 @@
#if defined(TARGET_ARCH_X64)
static constexpr dart::compiler::target::word
+ AOT_ContextScope_elements_start_offset = 16;
+static constexpr dart::compiler::target::word AOT_ContextScope_element_size =
+ 64;
+static constexpr dart::compiler::target::word
+ AOT_ExceptionHandlers_elements_start_offset = 24;
+static constexpr dart::compiler::target::word
+ AOT_ExceptionHandlers_element_size = 12;
+static constexpr dart::compiler::target::word
AOT_ObjectPool_elements_start_offset = 16;
static constexpr dart::compiler::target::word AOT_ObjectPool_element_size = 8;
static constexpr dart::compiler::target::word AOT_Array_kMaxElements =
@@ -7135,6 +7231,14 @@
#if defined(TARGET_ARCH_ARM64)
static constexpr dart::compiler::target::word
+ AOT_ContextScope_elements_start_offset = 16;
+static constexpr dart::compiler::target::word AOT_ContextScope_element_size =
+ 64;
+static constexpr dart::compiler::target::word
+ AOT_ExceptionHandlers_elements_start_offset = 24;
+static constexpr dart::compiler::target::word
+ AOT_ExceptionHandlers_element_size = 12;
+static constexpr dart::compiler::target::word
AOT_ObjectPool_elements_start_offset = 16;
static constexpr dart::compiler::target::word AOT_ObjectPool_element_size = 8;
static constexpr dart::compiler::target::word AOT_Array_kMaxElements =
diff --git a/runtime/vm/compiler/runtime_offsets_list.h b/runtime/vm/compiler/runtime_offsets_list.h
index 75c72ff..83c84f3 100644
--- a/runtime/vm/compiler/runtime_offsets_list.h
+++ b/runtime/vm/compiler/runtime_offsets_list.h
@@ -40,6 +40,8 @@
#define COMMON_OFFSETS_LIST(FIELD, ARRAY, SIZEOF, PAYLOAD_SIZEOF, RANGE, \
CONSTANT) \
+ ARRAY(ContextScope, element_offset) \
+ ARRAY(ExceptionHandlers, element_offset) \
ARRAY(ObjectPool, element_offset) \
CONSTANT(Array, kMaxElements) \
CONSTANT(Array, kMaxNewSpaceElements) \
diff --git a/runtime/vm/object.h b/runtime/vm/object.h
index 3c228c3..0b8e4ad 100644
--- a/runtime/vm/object.h
+++ b/runtime/vm/object.h
@@ -5792,6 +5792,13 @@
void SetHandledTypes(intptr_t try_index, const Array& handled_types) const;
bool HasCatchAll(intptr_t try_index) const;
+ struct ArrayTraits {
+ static intptr_t elements_start_offset() {
+ return sizeof(UntaggedExceptionHandlers);
+ }
+ static constexpr intptr_t kElementSize = sizeof(ExceptionHandlerInfo);
+ };
+
static intptr_t InstanceSize() {
ASSERT(sizeof(UntaggedExceptionHandlers) ==
OFFSET_OF_RETURNED_VALUE(UntaggedExceptionHandlers, data));
@@ -6670,6 +6677,13 @@
sizeof(UntaggedContextScope::VariableDesc);
static const intptr_t kMaxElements = kSmiMax / kBytesPerElement;
+ struct ArrayTraits {
+ static intptr_t elements_start_offset() {
+ return sizeof(UntaggedContextScope);
+ }
+ static constexpr intptr_t kElementSize = kBytesPerElement;
+ };
+
static intptr_t InstanceSize() {
ASSERT(sizeof(UntaggedContextScope) ==
OFFSET_OF_RETURNED_VALUE(UntaggedContextScope, data));
diff --git a/runtime/vm/runtime_entry.cc b/runtime/vm/runtime_entry.cc
index adce2b7..9c93470 100644
--- a/runtime/vm/runtime_entry.cc
+++ b/runtime/vm/runtime_entry.cc
@@ -2836,7 +2836,11 @@
current_target_code.EntryPoint(),
current_target_code.is_optimized() ? "optimized" : "unoptimized");
}
- ASSERT(!current_target_code.IsDisabled());
+ // With isolate groups enabled, it is possible that the target code
+ // has been deactivated just now(as a result of re-optimizatin for example),
+ // which will result in another run through FixCallersTarget.
+ ASSERT(!current_target_code.IsDisabled() ||
+ IsolateGroup::AreIsolateGroupsEnabled());
arguments.SetReturn(current_target_code);
#else
UNREACHABLE();
@@ -2882,7 +2886,11 @@
current_target_code.EntryPoint(),
current_target_code.is_optimized() ? "optimized" : "unoptimized");
}
- ASSERT(!current_target_code.IsDisabled());
+ // With isolate groups enabled, it is possible that the target code
+ // has been deactivated just now(as a result of re-optimizatin for example),
+ // which will result in another run through FixCallersTarget.
+ ASSERT(!current_target_code.IsDisabled() ||
+ IsolateGroup::AreIsolateGroupsEnabled());
arguments.SetReturn(current_target_code);
#else
UNREACHABLE();
diff --git a/samples/ffi/coordinate.dart b/samples/ffi/coordinate.dart
index 01f8ec3..5a51e33 100644
--- a/samples/ffi/coordinate.dart
+++ b/samples/ffi/coordinate.dart
@@ -4,8 +4,6 @@
import 'dart:ffi';
-import "package:ffi/ffi.dart";
-
/// Sample struct for dart:ffi library.
class Coordinate extends Struct {
@Double()
@@ -15,12 +13,4 @@
external double y;
external Pointer<Coordinate> next;
-
- factory Coordinate.allocate(
- Allocator allocator, double x, double y, Pointer<Coordinate> next) {
- return allocator<Coordinate>().ref
- ..x = x
- ..y = y
- ..next = next;
- }
}
diff --git a/samples/ffi/sample_ffi_functions_callbacks.dart b/samples/ffi/sample_ffi_functions_callbacks.dart
index de6d05a..19b6212 100644
--- a/samples/ffi/sample_ffi_functions_callbacks.dart
+++ b/samples/ffi/sample_ffi_functions_callbacks.dart
@@ -46,13 +46,15 @@
Pointer<NativeFunction<CoordinateTrice>> p2 =
ffiTestFunctions.lookup("CoordinateUnOpTrice");
CoordinateTrice coordinateUnOpTrice = p2.asFunction();
- Coordinate c1 = Coordinate.allocate(calloc, 10.0, 20.0, nullptr);
- c1.next = c1.addressOf;
- Coordinate result =
- coordinateUnOpTrice(transposeCoordinatePointer, c1.addressOf).ref;
+ final c1 = calloc<Coordinate>()
+ ..ref.x = 10.0
+ ..ref.y = 20.0;
+ c1.ref.next = c1;
+ Coordinate result = coordinateUnOpTrice(transposeCoordinatePointer, c1).ref;
print(result.runtimeType);
print(result.x);
print(result.y);
+ calloc.free(c1);
}
{
diff --git a/samples/ffi/sample_ffi_functions_structs.dart b/samples/ffi/sample_ffi_functions_structs.dart
index 9185040..4bcb9c9 100644
--- a/samples/ffi/sample_ffi_functions_structs.dart
+++ b/samples/ffi/sample_ffi_functions_structs.dart
@@ -24,14 +24,19 @@
ffiTestFunctions.lookup("TransposeCoordinate");
NativeCoordinateOp f1 = p1.asFunction();
- Coordinate c1 = Coordinate.allocate(calloc, 10.0, 20.0, nullptr);
- Coordinate c2 = Coordinate.allocate(calloc, 42.0, 84.0, c1.addressOf);
- c1.next = c2.addressOf;
+ final c1 = calloc<Coordinate>()
+ ..ref.x = 10.0
+ ..ref.y = 20.0;
+ final c2 = calloc<Coordinate>()
+ ..ref.x = 42.0
+ ..ref.y = 84.0
+ ..ref.next = c1;
+ c1.ref.next = c2;
- Coordinate result = f1(c1.addressOf).ref;
+ Coordinate result = f1(c1).ref;
- print(c1.x);
- print(c1.y);
+ print(c1.ref.x);
+ print(c1.ref.y);
print(result.runtimeType);
diff --git a/samples/ffi/sample_ffi_structs.dart b/samples/ffi/sample_ffi_structs.dart
index f6de82c..acad174 100644
--- a/samples/ffi/sample_ffi_structs.dart
+++ b/samples/ffi/sample_ffi_structs.dart
@@ -14,20 +14,28 @@
{
// Allocates each coordinate separately in c memory.
- Coordinate c1 = Coordinate.allocate(calloc, 10.0, 10.0, nullptr);
- Coordinate c2 = Coordinate.allocate(calloc, 20.0, 20.0, c1.addressOf);
- Coordinate c3 = Coordinate.allocate(calloc, 30.0, 30.0, c2.addressOf);
- c1.next = c3.addressOf;
+ final c1 = calloc<Coordinate>()
+ ..ref.x = 10.0
+ ..ref.y = 10.0;
+ final c2 = calloc<Coordinate>()
+ ..ref.x = 20.0
+ ..ref.y = 20.0
+ ..ref.next = c1;
+ final c3 = calloc<Coordinate>()
+ ..ref.x = 30.0
+ ..ref.y = 30.0
+ ..ref.next = c2;
+ c1.ref.next = c3;
- Coordinate currentCoordinate = c1;
+ Coordinate currentCoordinate = c1.ref;
for (var i in [0, 1, 2, 3, 4]) {
currentCoordinate = currentCoordinate.next.ref;
print("${currentCoordinate.x}; ${currentCoordinate.y}");
}
- calloc.free(c1.addressOf);
- calloc.free(c2.addressOf);
- calloc.free(c3.addressOf);
+ calloc.free(c1);
+ calloc.free(c2);
+ calloc.free(c3);
}
{
@@ -55,11 +63,12 @@
}
{
- Coordinate c = Coordinate.allocate(calloc, 10, 10, nullptr);
- print(c is Coordinate);
- print(c is Pointer<Void>);
- print(c is Pointer);
- calloc.free(c.addressOf);
+ // Allocating in native memory returns a pointer.
+ final c = calloc<Coordinate>();
+ print(c is Pointer<Coordinate>);
+ // `.ref` returns a reference which gives access to the fields.
+ print(c.ref is Coordinate);
+ calloc.free(c);
}
print("end main");
diff --git a/samples_2/ffi/coordinate.dart b/samples_2/ffi/coordinate.dart
index 4d9d300..bd3f270 100644
--- a/samples_2/ffi/coordinate.dart
+++ b/samples_2/ffi/coordinate.dart
@@ -6,8 +6,6 @@
import 'dart:ffi';
-import "package:ffi/ffi.dart";
-
/// Sample struct for dart:ffi library.
class Coordinate extends Struct {
@Double()
@@ -17,12 +15,4 @@
double y;
Pointer<Coordinate> next;
-
- factory Coordinate.allocate(
- Allocator allocator, double x, double y, Pointer<Coordinate> next) {
- return allocator<Coordinate>().ref
- ..x = x
- ..y = y
- ..next = next;
- }
}
diff --git a/samples_2/ffi/sample_ffi_functions_callbacks.dart b/samples_2/ffi/sample_ffi_functions_callbacks.dart
index 1d9dc12..35d73c4 100644
--- a/samples_2/ffi/sample_ffi_functions_callbacks.dart
+++ b/samples_2/ffi/sample_ffi_functions_callbacks.dart
@@ -48,13 +48,15 @@
Pointer<NativeFunction<CoordinateTrice>> p2 =
ffiTestFunctions.lookup("CoordinateUnOpTrice");
CoordinateTrice coordinateUnOpTrice = p2.asFunction();
- Coordinate c1 = Coordinate.allocate(calloc, 10.0, 20.0, nullptr);
- c1.next = c1.addressOf;
- Coordinate result =
- coordinateUnOpTrice(transposeCoordinatePointer, c1.addressOf).ref;
+ final c1 = calloc<Coordinate>()
+ ..ref.x = 10.0
+ ..ref.y = 20.0;
+ c1.ref.next = c1;
+ Coordinate result = coordinateUnOpTrice(transposeCoordinatePointer, c1).ref;
print(result.runtimeType);
print(result.x);
print(result.y);
+ calloc.free(c1);
}
{
diff --git a/samples_2/ffi/sample_ffi_functions_structs.dart b/samples_2/ffi/sample_ffi_functions_structs.dart
index 41b608d..0d6fa24 100644
--- a/samples_2/ffi/sample_ffi_functions_structs.dart
+++ b/samples_2/ffi/sample_ffi_functions_structs.dart
@@ -26,14 +26,19 @@
ffiTestFunctions.lookup("TransposeCoordinate");
NativeCoordinateOp f1 = p1.asFunction();
- Coordinate c1 = Coordinate.allocate(calloc, 10.0, 20.0, nullptr);
- Coordinate c2 = Coordinate.allocate(calloc, 42.0, 84.0, c1.addressOf);
- c1.next = c2.addressOf;
+ final c1 = calloc<Coordinate>()
+ ..ref.x = 10.0
+ ..ref.y = 20.0;
+ final c2 = calloc<Coordinate>()
+ ..ref.x = 42.0
+ ..ref.y = 84.0
+ ..ref.next = c1;
+ c1.ref.next = c2;
- Coordinate result = f1(c1.addressOf).ref;
+ Coordinate result = f1(c1).ref;
- print(c1.x);
- print(c1.y);
+ print(c1.ref.x);
+ print(c1.ref.y);
print(result.runtimeType);
diff --git a/samples_2/ffi/sample_ffi_structs.dart b/samples_2/ffi/sample_ffi_structs.dart
index 94b19cc..0ce6bca 100644
--- a/samples_2/ffi/sample_ffi_structs.dart
+++ b/samples_2/ffi/sample_ffi_structs.dart
@@ -16,20 +16,28 @@
{
// Allocates each coordinate separately in c memory.
- Coordinate c1 = Coordinate.allocate(calloc, 10.0, 10.0, nullptr);
- Coordinate c2 = Coordinate.allocate(calloc, 20.0, 20.0, c1.addressOf);
- Coordinate c3 = Coordinate.allocate(calloc, 30.0, 30.0, c2.addressOf);
- c1.next = c3.addressOf;
+ final c1 = calloc<Coordinate>()
+ ..ref.x = 10.0
+ ..ref.y = 10.0;
+ final c2 = calloc<Coordinate>()
+ ..ref.x = 20.0
+ ..ref.y = 20.0
+ ..ref.next = c1;
+ final c3 = calloc<Coordinate>()
+ ..ref.x = 30.0
+ ..ref.y = 30.0
+ ..ref.next = c2;
+ c1.ref.next = c3;
- Coordinate currentCoordinate = c1;
+ Coordinate currentCoordinate = c1.ref;
for (var i in [0, 1, 2, 3, 4]) {
currentCoordinate = currentCoordinate.next.ref;
print("${currentCoordinate.x}; ${currentCoordinate.y}");
}
- calloc.free(c1.addressOf);
- calloc.free(c2.addressOf);
- calloc.free(c3.addressOf);
+ calloc.free(c1);
+ calloc.free(c2);
+ calloc.free(c3);
}
{
@@ -57,11 +65,12 @@
}
{
- Coordinate c = Coordinate.allocate(calloc, 10, 10, nullptr);
- print(c is Coordinate);
- print(c is Pointer<Void>);
- print(c is Pointer);
- calloc.free(c.addressOf);
+ // Allocating in native memory returns a pointer.
+ final c = calloc<Coordinate>();
+ print(c is Pointer<Coordinate>);
+ // `.ref` returns a reference which gives access to the fields.
+ print(c.ref is Coordinate);
+ calloc.free(c);
}
print("end main");
diff --git a/tests/ffi/coordinate.dart b/tests/ffi/coordinate.dart
index abd6ecd..080bf18 100644
--- a/tests/ffi/coordinate.dart
+++ b/tests/ffi/coordinate.dart
@@ -5,7 +5,6 @@
library FfiTest;
import 'dart:ffi';
-import "package:ffi/ffi.dart";
/// Sample struct for dart:ffi library.
class Coordinate extends Struct {
@@ -16,12 +15,4 @@
external double y;
external Pointer<Coordinate> next;
-
- factory Coordinate.allocate(
- Allocator allocator, double x, double y, Pointer<Coordinate> next) {
- return allocator<Coordinate>().ref
- ..x = x
- ..y = y
- ..next = next;
- }
}
diff --git a/tests/ffi/coordinate_bare.dart b/tests/ffi/coordinate_bare.dart
deleted file mode 100644
index 09509b7..0000000
--- a/tests/ffi/coordinate_bare.dart
+++ /dev/null
@@ -1,18 +0,0 @@
-// Copyright (c) 2019, 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.
-
-library FfiTestCoordinateBare;
-
-import 'dart:ffi';
-
-/// Stripped down sample struct for dart:ffi library.
-class Coordinate extends Struct {
- @Double()
- external double x;
-
- @Double()
- external double y;
-
- external Pointer<Coordinate> next;
-}
diff --git a/tests/ffi/coordinate_nnbd_workaround.dart b/tests/ffi/coordinate_nnbd_workaround.dart
index abd8dba..42a6683 100644
--- a/tests/ffi/coordinate_nnbd_workaround.dart
+++ b/tests/ffi/coordinate_nnbd_workaround.dart
@@ -1,11 +1,12 @@
// Copyright (c) 2020, 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.
+//
+// Dart test program for testing getters/setters in structs rather than fields.
library FfiTest;
import 'dart:ffi';
-import "package:ffi/ffi.dart";
/// Sample struct for dart:ffi library.
class Coordinate extends Struct {
@@ -19,12 +20,4 @@
external Pointer<Coordinate> get next;
external set next(Pointer<Coordinate> v);
-
- factory Coordinate.allocate(
- Allocator allocator, double x, double y, Pointer<Coordinate> next) {
- return allocator<Coordinate>().ref
- ..x = x
- ..y = y
- ..next = next;
- }
}
diff --git a/tests/ffi/function_callbacks_structs_by_value_test.dart b/tests/ffi/function_callbacks_structs_by_value_test.dart
index 5e9399a..2065bc4 100644
--- a/tests/ffi/function_callbacks_structs_by_value_test.dart
+++ b/tests/ffi/function_callbacks_structs_by_value_test.dart
@@ -24,7 +24,8 @@
}
void recursiveTest(int recursionCounter) {
- final struct = calloc<Struct20BytesHomogeneousInt32>().ref;
+ final pointer = calloc<Struct20BytesHomogeneousInt32>();
+ final struct = pointer.ref;
struct.a0 = 1;
struct.a1 = 2;
struct.a2 = 3;
@@ -36,7 +37,7 @@
Expect.equals(struct.a2, result.a2);
Expect.equals(struct.a3, result.a3);
Expect.equals(struct.a4, result.a4);
- calloc.free(struct.addressOf);
+ calloc.free(pointer);
}
Struct20BytesHomogeneousInt32 dartPassStructRecursive(
@@ -94,7 +95,8 @@
_invokeReceiveStructByValue(_receiveStructByValuePointer);
Expect.isTrue(typedDataBackedStructSet);
- final pointerBackedStruct = calloc<Struct8BytesNestedInt>().ref;
+ final pointer = calloc<Struct8BytesNestedInt>();
+ final pointerBackedStruct = pointer.ref;
void reset() {
pointerBackedStruct.a0.a0 = 1;
@@ -131,5 +133,5 @@
Expect.equals(5, typedDataBackedStruct.a1.a0);
Expect.equals(6, typedDataBackedStruct.a1.a1);
- calloc.free(pointerBackedStruct.addressOf);
+ calloc.free(pointer);
}
diff --git a/tests/ffi/function_structs_test.dart b/tests/ffi/function_structs_test.dart
index ade55fb..24fc982 100644
--- a/tests/ffi/function_structs_test.dart
+++ b/tests/ffi/function_structs_test.dart
@@ -9,13 +9,12 @@
import 'dart:ffi';
-import 'dylib_utils.dart';
-
import "package:expect/expect.dart";
import "package:ffi/ffi.dart";
import 'calloc.dart';
import 'coordinate.dart';
+import 'dylib_utils.dart';
import 'very_large_struct.dart';
typedef NativeCoordinateOp = Pointer<Coordinate> Function(Pointer<Coordinate>);
@@ -34,10 +33,13 @@
ffiTestFunctions.lookup("TransposeCoordinate");
NativeCoordinateOp f1 = p1.asFunction();
- Pointer<Coordinate> c1 =
- Coordinate.allocate(calloc, 10.0, 20.0, nullptr).addressOf;
- Pointer<Coordinate> c2 =
- Coordinate.allocate(calloc, 42.0, 84.0, c1).addressOf;
+ final c1 = calloc<Coordinate>()
+ ..ref.x = 10.0
+ ..ref.y = 20.0;
+ final c2 = calloc<Coordinate>()
+ ..ref.x = 42.0
+ ..ref.y = 84.0
+ ..ref.next = c1;
c1.ref.next = c2;
Coordinate result = f1(c1).ref;
@@ -58,24 +60,25 @@
ffiTestFunctions.lookup("CoordinateElemAt1");
NativeCoordinateOp f1 = p1.asFunction();
- Coordinate c1 = calloc<Coordinate>(3).ref;
- Coordinate c2 = c1.addressOf[1];
- Coordinate c3 = c1.addressOf[2];
+ final coordinateArray = calloc<Coordinate>(3);
+ Coordinate c1 = coordinateArray[0];
+ Coordinate c2 = coordinateArray[1];
+ Coordinate c3 = coordinateArray[2];
c1.x = 10.0;
c1.y = 10.0;
- c1.next = c3.addressOf;
+ c1.next = coordinateArray.elementAt(2);
c2.x = 20.0;
c2.y = 20.0;
- c2.next = c1.addressOf;
+ c2.next = coordinateArray.elementAt(0);
c3.x = 30.0;
c3.y = 30.0;
- c3.next = c2.addressOf;
+ c3.next = coordinateArray.elementAt(1);
- Coordinate result = f1(c1.addressOf).ref;
+ Coordinate result = f1(coordinateArray.elementAt(0)).ref;
Expect.approxEquals(20.0, result.x);
Expect.approxEquals(20.0, result.y);
- calloc.free(c1.addressOf);
+ calloc.free(coordinateArray);
}
typedef VeryLargeStructSum = int Function(Pointer<VeryLargeStruct>);
@@ -86,8 +89,9 @@
ffiTestFunctions.lookup("SumVeryLargeStruct");
VeryLargeStructSum f = p1.asFunction();
- VeryLargeStruct vls1 = calloc<VeryLargeStruct>(2).ref;
- VeryLargeStruct vls2 = vls1.addressOf[1];
+ final vlsArray = calloc<VeryLargeStruct>(2);
+ VeryLargeStruct vls1 = vlsArray[0];
+ VeryLargeStruct vls2 = vlsArray[1];
List<VeryLargeStruct> structs = [vls1, vls2];
for (VeryLargeStruct struct in structs) {
struct.a = 1;
@@ -103,19 +107,19 @@
struct.k = 1024;
struct.smallLastField = 1;
}
- vls1.parent = vls2.addressOf;
+ vls1.parent = vlsArray.elementAt(1);
vls1.numChildren = 2;
- vls1.children = vls1.addressOf;
- vls2.parent = vls2.addressOf;
+ vls1.children = vlsArray.elementAt(0);
+ vls2.parent = vlsArray.elementAt(1);
vls2.parent = nullptr;
vls2.numChildren = 0;
vls2.children = nullptr;
- int result = f(vls1.addressOf);
+ int result = f(vlsArray.elementAt(0));
Expect.equals(2051, result);
- result = f(vls2.addressOf);
+ result = f(vlsArray.elementAt(1));
Expect.equals(2048, result);
- calloc.free(vls1.addressOf);
+ calloc.free(vlsArray);
}
diff --git a/tests/ffi/structs_nested_test.dart b/tests/ffi/structs_nested_test.dart
index 2d5208d..c07750e 100644
--- a/tests/ffi/structs_nested_test.dart
+++ b/tests/ffi/structs_nested_test.dart
@@ -61,10 +61,8 @@
final p = calloc<Struct8BytesNestedInt>();
print(p);
print(p.ref.runtimeType);
- print(p.ref.addressOf);
- print(p.ref.addressOf.address);
+ print(p.address);
print(p.ref.a0.runtimeType);
- print(p.ref.a0.addressOf);
print(p.ref.a0.a0);
calloc.free(p);
print("read");
diff --git a/tests/ffi/structs_nnbd_workaround_test.dart b/tests/ffi/structs_nnbd_workaround_test.dart
index 06c6f29..2b361b6 100644
--- a/tests/ffi/structs_nnbd_workaround_test.dart
+++ b/tests/ffi/structs_nnbd_workaround_test.dart
@@ -2,7 +2,7 @@
// 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.
//
-// Dart test program for testing dart:ffi struct pointers.
+// Dart test program for testing getters/setters in structs rather than fields.
//
// VMOptions=--deterministic --optimization-counter-threshold=50
@@ -26,12 +26,17 @@
/// allocates each coordinate separately in c memory
void testStructAllocate() {
- Pointer<Coordinate> c1 =
- Coordinate.allocate(calloc, 10.0, 10.0, nullptr).addressOf;
- Pointer<Coordinate> c2 =
- Coordinate.allocate(calloc, 20.0, 20.0, c1).addressOf;
- Pointer<Coordinate> c3 =
- Coordinate.allocate(calloc, 30.0, 30.0, c2).addressOf;
+ final c1 = calloc<Coordinate>()
+ ..ref.x = 10.0
+ ..ref.y = 10.0;
+ final c2 = calloc<Coordinate>()
+ ..ref.x = 20.0
+ ..ref.y = 20.0
+ ..ref.next = c1;
+ final c3 = calloc<Coordinate>()
+ ..ref.x = 30.0
+ ..ref.y = 30.0
+ ..ref.next = c2;
c1.ref.next = c3;
Coordinate currentCoordinate = c1.ref;
@@ -79,8 +84,9 @@
}
void testStructWithNulls() {
- Pointer<Coordinate> coordinate =
- Coordinate.allocate(calloc, 10.0, 10.0, nullptr).addressOf;
+ final coordinate = calloc<Coordinate>()
+ ..ref.x = 10.0
+ ..ref.y = 10.0;
Expect.equals(coordinate.ref.next, nullptr);
coordinate.ref.next = coordinate;
Expect.notEquals(coordinate.ref.next, nullptr);
@@ -90,10 +96,12 @@
}
void testTypeTest() {
- Coordinate c = Coordinate.allocate(calloc, 10, 10, nullptr);
+ final pointer = calloc<Coordinate>();
+ Coordinate c = pointer.ref;
Expect.isTrue(c is Struct);
+ // TODO(https://dartbug.com/40667): Remove support for this.
Expect.isTrue(c.addressOf is Pointer<Coordinate>);
- calloc.free(c.addressOf);
+ calloc.free(pointer);
}
void testUtf8() {
diff --git a/tests/ffi/structs_test.dart b/tests/ffi/structs_test.dart
index a38c241..e339437 100644
--- a/tests/ffi/structs_test.dart
+++ b/tests/ffi/structs_test.dart
@@ -4,7 +4,7 @@
//
// Dart test program for testing dart:ffi struct pointers.
//
-// VMOptions=--deterministic --optimization-counter-threshold=50
+// VMOptions=--deterministic --optimization-counter-threshold=50 --enable-inlining-annotations
import 'dart:ffi';
@@ -12,16 +12,13 @@
import "package:ffi/ffi.dart";
import 'calloc.dart';
-import 'coordinate_bare.dart' as bare;
import 'coordinate.dart';
-import 'ffi_test_helpers.dart';
void main() {
for (int i = 0; i < 100; i++) {
testStructAllocate();
testStructFromAddress();
testStructWithNulls();
- testBareStruct();
testTypeTest();
testUtf8();
testDotDotRef();
@@ -30,12 +27,17 @@
/// allocates each coordinate separately in c memory
void testStructAllocate() {
- Pointer<Coordinate> c1 =
- Coordinate.allocate(calloc, 10.0, 10.0, nullptr).addressOf;
- Pointer<Coordinate> c2 =
- Coordinate.allocate(calloc, 20.0, 20.0, c1).addressOf;
- Pointer<Coordinate> c3 =
- Coordinate.allocate(calloc, 30.0, 30.0, c2).addressOf;
+ final c1 = calloc<Coordinate>()
+ ..ref.x = 10.0
+ ..ref.y = 10.0;
+ final c2 = calloc<Coordinate>()
+ ..ref.x = 20.0
+ ..ref.y = 20.0
+ ..ref.next = c1;
+ final c3 = calloc<Coordinate>()
+ ..ref.x = 30.0
+ ..ref.y = 30.0
+ ..ref.next = c2;
c1.ref.next = c3;
Coordinate currentCoordinate = c1.ref;
@@ -83,8 +85,9 @@
}
void testStructWithNulls() {
- Pointer<Coordinate> coordinate =
- Coordinate.allocate(calloc, 10.0, 10.0, nullptr).addressOf;
+ final coordinate = calloc<Coordinate>()
+ ..ref.x = 10.0
+ ..ref.y = 10.0;
Expect.equals(coordinate.ref.next, nullptr);
coordinate.ref.next = coordinate;
Expect.notEquals(coordinate.ref.next, nullptr);
@@ -93,41 +96,13 @@
calloc.free(coordinate);
}
-void testBareStruct() {
- int structSize = sizeOf<Double>() * 2 + sizeOf<IntPtr>();
- bare.Coordinate c1 =
- calloc<Uint8>(structSize * 3).cast<bare.Coordinate>().ref;
- bare.Coordinate c2 =
- c1.addressOf.offsetBy(structSize).cast<bare.Coordinate>().ref;
- bare.Coordinate c3 =
- c1.addressOf.offsetBy(structSize * 2).cast<bare.Coordinate>().ref;
- c1.x = 10.0;
- c1.y = 10.0;
- c1.next = c3.addressOf;
- c2.x = 20.0;
- c2.y = 20.0;
- c2.next = c1.addressOf;
- c3.x = 30.0;
- c3.y = 30.0;
- c3.next = c2.addressOf;
-
- bare.Coordinate currentCoordinate = c1;
- Expect.equals(10.0, currentCoordinate.x);
- currentCoordinate = currentCoordinate.next.ref;
- Expect.equals(30.0, currentCoordinate.x);
- currentCoordinate = currentCoordinate.next.ref;
- Expect.equals(20.0, currentCoordinate.x);
- currentCoordinate = currentCoordinate.next.ref;
- Expect.equals(10.0, currentCoordinate.x);
-
- calloc.free(c1.addressOf);
-}
-
void testTypeTest() {
- Coordinate c = Coordinate.allocate(calloc, 10, 10, nullptr);
+ final pointer = calloc<Coordinate>();
+ Coordinate c = pointer.ref;
Expect.isTrue(c is Struct);
+ // TODO(https://dartbug.com/40667): Remove support for this.
Expect.isTrue(c.addressOf is Pointer<Coordinate>);
- calloc.free(c.addressOf);
+ calloc.free(pointer);
}
void testUtf8() {
diff --git a/tests/ffi_2/coordinate.dart b/tests/ffi_2/coordinate.dart
index 92dfbf0..5e00a76 100644
--- a/tests/ffi_2/coordinate.dart
+++ b/tests/ffi_2/coordinate.dart
@@ -5,7 +5,6 @@
library FfiTest;
import 'dart:ffi';
-import "package:ffi/ffi.dart";
/// Sample struct for dart:ffi library.
class Coordinate extends Struct {
@@ -16,12 +15,4 @@
double y;
Pointer<Coordinate> next;
-
- factory Coordinate.allocate(
- Allocator allocator, double x, double y, Pointer<Coordinate> next) {
- return allocator<Coordinate>().ref
- ..x = x
- ..y = y
- ..next = next;
- }
}
diff --git a/tests/ffi_2/coordinate_bare.dart b/tests/ffi_2/coordinate_bare.dart
deleted file mode 100644
index daaea24..0000000
--- a/tests/ffi_2/coordinate_bare.dart
+++ /dev/null
@@ -1,18 +0,0 @@
-// Copyright (c) 2019, 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.
-
-library FfiTestCoordinateBare;
-
-import 'dart:ffi';
-
-/// Stripped down sample struct for dart:ffi library.
-class Coordinate extends Struct {
- @Double()
- double x;
-
- @Double()
- double y;
-
- Pointer<Coordinate> next;
-}
diff --git a/tests/ffi_2/function_callbacks_structs_by_value_test.dart b/tests/ffi_2/function_callbacks_structs_by_value_test.dart
index 5e9399a..2065bc4 100644
--- a/tests/ffi_2/function_callbacks_structs_by_value_test.dart
+++ b/tests/ffi_2/function_callbacks_structs_by_value_test.dart
@@ -24,7 +24,8 @@
}
void recursiveTest(int recursionCounter) {
- final struct = calloc<Struct20BytesHomogeneousInt32>().ref;
+ final pointer = calloc<Struct20BytesHomogeneousInt32>();
+ final struct = pointer.ref;
struct.a0 = 1;
struct.a1 = 2;
struct.a2 = 3;
@@ -36,7 +37,7 @@
Expect.equals(struct.a2, result.a2);
Expect.equals(struct.a3, result.a3);
Expect.equals(struct.a4, result.a4);
- calloc.free(struct.addressOf);
+ calloc.free(pointer);
}
Struct20BytesHomogeneousInt32 dartPassStructRecursive(
@@ -94,7 +95,8 @@
_invokeReceiveStructByValue(_receiveStructByValuePointer);
Expect.isTrue(typedDataBackedStructSet);
- final pointerBackedStruct = calloc<Struct8BytesNestedInt>().ref;
+ final pointer = calloc<Struct8BytesNestedInt>();
+ final pointerBackedStruct = pointer.ref;
void reset() {
pointerBackedStruct.a0.a0 = 1;
@@ -131,5 +133,5 @@
Expect.equals(5, typedDataBackedStruct.a1.a0);
Expect.equals(6, typedDataBackedStruct.a1.a1);
- calloc.free(pointerBackedStruct.addressOf);
+ calloc.free(pointer);
}
diff --git a/tests/ffi_2/function_structs_test.dart b/tests/ffi_2/function_structs_test.dart
index 6bb3e56..24fc982 100644
--- a/tests/ffi_2/function_structs_test.dart
+++ b/tests/ffi_2/function_structs_test.dart
@@ -33,10 +33,13 @@
ffiTestFunctions.lookup("TransposeCoordinate");
NativeCoordinateOp f1 = p1.asFunction();
- Pointer<Coordinate> c1 =
- Coordinate.allocate(calloc, 10.0, 20.0, nullptr).addressOf;
- Pointer<Coordinate> c2 =
- Coordinate.allocate(calloc, 42.0, 84.0, c1).addressOf;
+ final c1 = calloc<Coordinate>()
+ ..ref.x = 10.0
+ ..ref.y = 20.0;
+ final c2 = calloc<Coordinate>()
+ ..ref.x = 42.0
+ ..ref.y = 84.0
+ ..ref.next = c1;
c1.ref.next = c2;
Coordinate result = f1(c1).ref;
@@ -57,24 +60,25 @@
ffiTestFunctions.lookup("CoordinateElemAt1");
NativeCoordinateOp f1 = p1.asFunction();
- Coordinate c1 = calloc<Coordinate>(3).ref;
- Coordinate c2 = c1.addressOf[1];
- Coordinate c3 = c1.addressOf[2];
+ final coordinateArray = calloc<Coordinate>(3);
+ Coordinate c1 = coordinateArray[0];
+ Coordinate c2 = coordinateArray[1];
+ Coordinate c3 = coordinateArray[2];
c1.x = 10.0;
c1.y = 10.0;
- c1.next = c3.addressOf;
+ c1.next = coordinateArray.elementAt(2);
c2.x = 20.0;
c2.y = 20.0;
- c2.next = c1.addressOf;
+ c2.next = coordinateArray.elementAt(0);
c3.x = 30.0;
c3.y = 30.0;
- c3.next = c2.addressOf;
+ c3.next = coordinateArray.elementAt(1);
- Coordinate result = f1(c1.addressOf).ref;
+ Coordinate result = f1(coordinateArray.elementAt(0)).ref;
Expect.approxEquals(20.0, result.x);
Expect.approxEquals(20.0, result.y);
- calloc.free(c1.addressOf);
+ calloc.free(coordinateArray);
}
typedef VeryLargeStructSum = int Function(Pointer<VeryLargeStruct>);
@@ -85,8 +89,9 @@
ffiTestFunctions.lookup("SumVeryLargeStruct");
VeryLargeStructSum f = p1.asFunction();
- VeryLargeStruct vls1 = calloc<VeryLargeStruct>(2).ref;
- VeryLargeStruct vls2 = vls1.addressOf[1];
+ final vlsArray = calloc<VeryLargeStruct>(2);
+ VeryLargeStruct vls1 = vlsArray[0];
+ VeryLargeStruct vls2 = vlsArray[1];
List<VeryLargeStruct> structs = [vls1, vls2];
for (VeryLargeStruct struct in structs) {
struct.a = 1;
@@ -102,19 +107,19 @@
struct.k = 1024;
struct.smallLastField = 1;
}
- vls1.parent = vls2.addressOf;
+ vls1.parent = vlsArray.elementAt(1);
vls1.numChildren = 2;
- vls1.children = vls1.addressOf;
- vls2.parent = vls2.addressOf;
+ vls1.children = vlsArray.elementAt(0);
+ vls2.parent = vlsArray.elementAt(1);
vls2.parent = nullptr;
vls2.numChildren = 0;
vls2.children = nullptr;
- int result = f(vls1.addressOf);
+ int result = f(vlsArray.elementAt(0));
Expect.equals(2051, result);
- result = f(vls2.addressOf);
+ result = f(vlsArray.elementAt(1));
Expect.equals(2048, result);
- calloc.free(vls1.addressOf);
+ calloc.free(vlsArray);
}
diff --git a/tests/ffi_2/structs_nested_test.dart b/tests/ffi_2/structs_nested_test.dart
index 3a69edb..f48f26c 100644
--- a/tests/ffi_2/structs_nested_test.dart
+++ b/tests/ffi_2/structs_nested_test.dart
@@ -61,10 +61,8 @@
final p = calloc<Struct8BytesNestedInt>();
print(p);
print(p.ref.runtimeType);
- print(p.ref.addressOf);
- print(p.ref.addressOf.address);
+ print(p.address);
print(p.ref.a0.runtimeType);
- print(p.ref.a0.addressOf);
print(p.ref.a0.a0);
calloc.free(p);
print("read");
diff --git a/tests/ffi_2/structs_test.dart b/tests/ffi_2/structs_test.dart
index 57bdbc6..e339437 100644
--- a/tests/ffi_2/structs_test.dart
+++ b/tests/ffi_2/structs_test.dart
@@ -12,16 +12,13 @@
import "package:ffi/ffi.dart";
import 'calloc.dart';
-import 'coordinate_bare.dart' as bare;
import 'coordinate.dart';
-import 'ffi_test_helpers.dart';
void main() {
for (int i = 0; i < 100; i++) {
testStructAllocate();
testStructFromAddress();
testStructWithNulls();
- testBareStruct();
testTypeTest();
testUtf8();
testDotDotRef();
@@ -30,12 +27,17 @@
/// allocates each coordinate separately in c memory
void testStructAllocate() {
- Pointer<Coordinate> c1 =
- Coordinate.allocate(calloc, 10.0, 10.0, nullptr).addressOf;
- Pointer<Coordinate> c2 =
- Coordinate.allocate(calloc, 20.0, 20.0, c1).addressOf;
- Pointer<Coordinate> c3 =
- Coordinate.allocate(calloc, 30.0, 30.0, c2).addressOf;
+ final c1 = calloc<Coordinate>()
+ ..ref.x = 10.0
+ ..ref.y = 10.0;
+ final c2 = calloc<Coordinate>()
+ ..ref.x = 20.0
+ ..ref.y = 20.0
+ ..ref.next = c1;
+ final c3 = calloc<Coordinate>()
+ ..ref.x = 30.0
+ ..ref.y = 30.0
+ ..ref.next = c2;
c1.ref.next = c3;
Coordinate currentCoordinate = c1.ref;
@@ -83,8 +85,9 @@
}
void testStructWithNulls() {
- Pointer<Coordinate> coordinate =
- Coordinate.allocate(calloc, 10.0, 10.0, nullptr).addressOf;
+ final coordinate = calloc<Coordinate>()
+ ..ref.x = 10.0
+ ..ref.y = 10.0;
Expect.equals(coordinate.ref.next, nullptr);
coordinate.ref.next = coordinate;
Expect.notEquals(coordinate.ref.next, nullptr);
@@ -93,41 +96,13 @@
calloc.free(coordinate);
}
-void testBareStruct() {
- int structSize = sizeOf<Double>() * 2 + sizeOf<IntPtr>();
- bare.Coordinate c1 =
- calloc<Uint8>(structSize * 3).cast<bare.Coordinate>().ref;
- bare.Coordinate c2 =
- c1.addressOf.offsetBy(structSize).cast<bare.Coordinate>().ref;
- bare.Coordinate c3 =
- c1.addressOf.offsetBy(structSize * 2).cast<bare.Coordinate>().ref;
- c1.x = 10.0;
- c1.y = 10.0;
- c1.next = c3.addressOf;
- c2.x = 20.0;
- c2.y = 20.0;
- c2.next = c1.addressOf;
- c3.x = 30.0;
- c3.y = 30.0;
- c3.next = c2.addressOf;
-
- bare.Coordinate currentCoordinate = c1;
- Expect.equals(10.0, currentCoordinate.x);
- currentCoordinate = currentCoordinate.next.ref;
- Expect.equals(30.0, currentCoordinate.x);
- currentCoordinate = currentCoordinate.next.ref;
- Expect.equals(20.0, currentCoordinate.x);
- currentCoordinate = currentCoordinate.next.ref;
- Expect.equals(10.0, currentCoordinate.x);
-
- calloc.free(c1.addressOf);
-}
-
void testTypeTest() {
- Coordinate c = Coordinate.allocate(calloc, 10, 10, nullptr);
+ final pointer = calloc<Coordinate>();
+ Coordinate c = pointer.ref;
Expect.isTrue(c is Struct);
+ // TODO(https://dartbug.com/40667): Remove support for this.
Expect.isTrue(c.addressOf is Pointer<Coordinate>);
- calloc.free(c.addressOf);
+ calloc.free(pointer);
}
void testUtf8() {
diff --git a/tools/VERSION b/tools/VERSION
index 0f13953..92676e3 100644
--- a/tools/VERSION
+++ b/tools/VERSION
@@ -27,5 +27,5 @@
MAJOR 2
MINOR 12
PATCH 0
-PRERELEASE 274
+PRERELEASE 275
PRERELEASE_PATCH 0
\ No newline at end of file
diff --git a/tools/gn.py b/tools/gn.py
index 0fd17d8..52ae73b 100755
--- a/tools/gn.py
+++ b/tools/gn.py
@@ -70,7 +70,10 @@
def HostCpuForArch(arch):
if arch in ['ia32', 'arm', 'armv6', 'simarm', 'simarmv6', 'simarm_x64']:
return 'x86'
- if arch in ['x64', 'arm64', 'simarm64', 'arm_x64']:
+ if arch in [
+ 'x64', 'arm64', 'simarm64', 'arm_x64', 'x64_comp_ptr',
+ 'arm64_comp_ptr', 'simarm64_comp_ptr'
+ ]:
return 'x64'
@@ -78,10 +81,14 @@
def TargetCpuForArch(arch, target_os):
if arch in ['ia32', 'simarm', 'simarmv6']:
return 'x86'
- if arch in ['x64', 'simarm64', 'simarm_x64']:
+ if arch in [
+ 'x64', 'simarm64', 'simarm_x64', 'x64_comp_ptr', 'simarm64_comp_ptr'
+ ]:
return 'x64'
if arch == 'arm_x64':
return 'arm'
+ if arch == 'arm64_comp_ptr':
+ return 'arm64'
return arch
@@ -89,17 +96,21 @@
def DartTargetCpuForArch(arch):
if arch in ['ia32']:
return 'ia32'
- if arch in ['x64']:
+ if arch in ['x64', 'x64_comp_ptr']:
return 'x64'
if arch in ['arm', 'simarm', 'simarm_x64', 'arm_x64']:
return 'arm'
if arch in ['armv6', 'simarmv6']:
return 'armv6'
- if arch in ['arm64', 'simarm64']:
+ if arch in ['arm64', 'simarm64', 'arm64_comp_ptr', 'simarm64_comp_ptr']:
return 'arm64'
return arch
+def IsCompressedPointerArch(arch):
+ return arch in ['x64_comp_ptr', 'arm64_comp_ptr', 'simarm64_comp_ptr']
+
+
def HostOsForGn(host_os):
if host_os.startswith('macos'):
return 'mac'
@@ -147,6 +158,7 @@
gn_args['host_cpu'] = HostCpuForArch(arch)
gn_args['target_cpu'] = TargetCpuForArch(arch, target_os)
gn_args['dart_target_arch'] = DartTargetCpuForArch(arch)
+ gn_args['dart_use_compressed_pointers'] = IsCompressedPointerArch(arch)
# Configure Crashpad library if it is used.
gn_args['dart_use_crashpad'] = (args.use_crashpad or
diff --git a/tools/utils.py b/tools/utils.py
index cbd1759..2a5aeac 100644
--- a/tools/utils.py
+++ b/tools/utils.py
@@ -72,6 +72,9 @@
'simarmv6': 'ia32',
'simarm64': 'ia32',
'simarm_x64': 'ia32',
+ 'x64_comp_ptr': 'ia32',
+ 'arm64_comp_ptr': 'arm',
+ 'simarm64_comp_ptr': 'ia32',
}
BASE_DIR = os.path.abspath(os.path.join(os.curdir, '..'))