From 8871c3cea2818f64ad67c91381cc9ed480e01b32 Mon Sep 17 00:00:00 2001 From: Devon Carew Date: Mon, 14 Jun 2021 16:14:43 +0000 Subject: [PATCH] Add Widget names to the information collected by the widget transformer. Change-Id: I3401f22e907cddb12f8a122b1c824bc06372c42a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/203291 Commit-Queue: Devon Carew Reviewed-by: Jacob Richman --- ...widget_transform_const.yaml.world.1.expect | 65 +++++++++---------- ...widget_transform_const.yaml.world.2.expect | 22 ++++--- ...widget_transform_const.yaml.world.3.expect | 65 +++++++++---------- ..._widget_transform_nnbd.yaml.world.2.expect | 4 +- ..._transformer_non_const.yaml.world.2.expect | 9 +-- .../track_widget_constructor_locations.dart | 53 +++------------ 6 files changed, 89 insertions(+), 129 deletions(-) diff --git a/pkg/front_end/testcases/incremental/flutter_widget_transform_const.yaml.world.1.expect b/pkg/front_end/testcases/incremental/flutter_widget_transform_const.yaml.world.1.expect index 4d7e73bafa5..7d948ed493d 100644 --- a/pkg/front_end/testcases/incremental/flutter_widget_transform_const.yaml.world.1.expect +++ b/pkg/front_end/testcases/incremental/flutter_widget_transform_const.yaml.world.1.expect @@ -58,7 +58,7 @@ library from "org-dartlang-test:///foo.dart" as foo { : super fra::Widget::•($creationLocationd_0dea112b090073317d4: $creationLocationd_0dea112b090073317d4) ; static factory •({wid::_Location? $creationLocationd_0dea112b090073317d4 = #C1}) → foo::Baz - return #C10; + return #C11; static factory _({wid::_Location? $creationLocationd_0dea112b090073317d4 = #C1}) → foo::Baz let dynamic #redirecting_factory = foo::Baz::__ in invalid-expression; } @@ -71,7 +71,7 @@ library from "org-dartlang-test:///foo.dart" as foo { return new foo::Boz::_($creationLocationd_0dea112b090073317d4: $creationLocationd_0dea112b090073317d4); } else { - return #C14; + return #C16; } } } @@ -80,47 +80,44 @@ library from "org-dartlang-test:///main.dart" as main { import "org-dartlang-test:///foo.dart"; - static field foo::Foo newFoo = foo::Foo::•($creationLocationd_0dea112b090073317d4: #C17); - static field foo::Bar newBar = new foo::Bar::_($creationLocationd_0dea112b090073317d4: #C19); - static field foo::Bar constBar = #C23; - static field foo::Baz newBaz = foo::Baz::•($creationLocationd_0dea112b090073317d4: #C25); + static field foo::Foo newFoo = foo::Foo::•($creationLocationd_0dea112b090073317d4: #C19); + static field foo::Bar newBar = new foo::Bar::_($creationLocationd_0dea112b090073317d4: #C22); + static field foo::Bar constBar = #C26; + static field foo::Baz newBaz = foo::Baz::•($creationLocationd_0dea112b090073317d4: #C28); static field foo::Boz newBoz = foo::Boz::•(createNew: true, $creationLocationd_0dea112b090073317d4: #C29); - static field foo::Boz constBoz = foo::Boz::•(createNew: false, $creationLocationd_0dea112b090073317d4: #C35); + static field foo::Boz constBoz = foo::Boz::•(createNew: false, $creationLocationd_0dea112b090073317d4: #C32); } constants { #C1 = null #C2 = "org-dartlang-test:///foo.dart" #C3 = 2.0 #C4 = 51.0 - #C5 = [] - #C6 = wid::_Location {file:#C2, line:#C3, column:#C4, name:#C1, parameterLocations:#C5} + #C5 = "Foo" + #C6 = wid::_Location {file:#C2, line:#C3, column:#C4, name:#C5, parameterLocations:#C1} #C7 = foo::Foo {_location:#C6} #C8 = 6.0 - #C9 = wid::_Location {file:#C2, line:#C8, column:#C4, name:#C1, parameterLocations:#C5} - #C10 = foo::Baz {_location:#C9} - #C11 = 9.0 - #C12 = 128.0 - #C13 = wid::_Location {file:#C2, line:#C11, column:#C12, name:#C1, parameterLocations:#C5} - #C14 = foo::Boz {_location:#C13} - #C15 = "org-dartlang-test:///main.dart" - #C16 = 18.0 - #C17 = wid::_Location {file:#C15, line:#C3, column:#C16, name:#C1, parameterLocations:#C5} - #C18 = 3.0 - #C19 = wid::_Location {file:#C15, line:#C18, column:#C16, name:#C1, parameterLocations:#C5} - #C20 = 4.0 - #C21 = 22.0 - #C22 = wid::_Location {file:#C15, line:#C20, column:#C21, name:#C1, parameterLocations:#C5} - #C23 = foo::Bar {_location:#C22} - #C24 = 5.0 - #C25 = wid::_Location {file:#C15, line:#C24, column:#C16, name:#C1, parameterLocations:#C5} - #C26 = "createNew" - #C27 = wid::_Location {file:#C1, line:#C8, column:#C21, name:#C26, parameterLocations:#C1} - #C28 = [#C27] - #C29 = wid::_Location {file:#C15, line:#C8, column:#C16, name:#C1, parameterLocations:#C28} + #C9 = "Baz" + #C10 = wid::_Location {file:#C2, line:#C8, column:#C4, name:#C9, parameterLocations:#C1} + #C11 = foo::Baz {_location:#C10} + #C12 = 9.0 + #C13 = 128.0 + #C14 = "Boz" + #C15 = wid::_Location {file:#C2, line:#C12, column:#C13, name:#C14, parameterLocations:#C1} + #C16 = foo::Boz {_location:#C15} + #C17 = "org-dartlang-test:///main.dart" + #C18 = 18.0 + #C19 = wid::_Location {file:#C17, line:#C3, column:#C18, name:#C5, parameterLocations:#C1} + #C20 = 3.0 + #C21 = "Bar" + #C22 = wid::_Location {file:#C17, line:#C20, column:#C18, name:#C21, parameterLocations:#C1} + #C23 = 4.0 + #C24 = 22.0 + #C25 = wid::_Location {file:#C17, line:#C23, column:#C24, name:#C21, parameterLocations:#C1} + #C26 = foo::Bar {_location:#C25} + #C27 = 5.0 + #C28 = wid::_Location {file:#C17, line:#C27, column:#C18, name:#C9, parameterLocations:#C1} + #C29 = wid::_Location {file:#C17, line:#C8, column:#C18, name:#C14, parameterLocations:#C1} #C30 = 7.0 #C31 = 20.0 - #C32 = 24.0 - #C33 = wid::_Location {file:#C1, line:#C30, column:#C32, name:#C26, parameterLocations:#C1} - #C34 = [#C33] - #C35 = wid::_Location {file:#C15, line:#C30, column:#C31, name:#C1, parameterLocations:#C34} + #C32 = wid::_Location {file:#C17, line:#C30, column:#C31, name:#C14, parameterLocations:#C1} } diff --git a/pkg/front_end/testcases/incremental/flutter_widget_transform_const.yaml.world.2.expect b/pkg/front_end/testcases/incremental/flutter_widget_transform_const.yaml.world.2.expect index f3b91999233..b101e36b4dc 100644 --- a/pkg/front_end/testcases/incremental/flutter_widget_transform_const.yaml.world.2.expect +++ b/pkg/front_end/testcases/incremental/flutter_widget_transform_const.yaml.world.2.expect @@ -58,7 +58,7 @@ library from "org-dartlang-test:///foo.dart" as foo { : super fra::Widget::•($creationLocationd_0dea112b090073317d4: $creationLocationd_0dea112b090073317d4) ; static factory •({wid::_Location? $creationLocationd_0dea112b090073317d4 = #C1}) → foo::Baz - return #C10; + return #C11; static factory _({wid::_Location? $creationLocationd_0dea112b090073317d4 = #C1}) → foo::Baz let dynamic #redirecting_factory = foo::Baz::__ in invalid-expression; } @@ -71,7 +71,7 @@ library from "org-dartlang-test:///foo.dart" as foo { return new foo::Boz::_($creationLocationd_0dea112b090073317d4: $creationLocationd_0dea112b090073317d4); } else { - return #C14; + return #C16; } } } @@ -86,14 +86,16 @@ constants { #C2 = "org-dartlang-test:///foo.dart" #C3 = 2.0 #C4 = 51.0 - #C5 = [] - #C6 = wid::_Location {file:#C2, line:#C3, column:#C4, name:#C1, parameterLocations:#C5} + #C5 = "Foo" + #C6 = wid::_Location {file:#C2, line:#C3, column:#C4, name:#C5, parameterLocations:#C1} #C7 = foo::Foo {_location:#C6} #C8 = 6.0 - #C9 = wid::_Location {file:#C2, line:#C8, column:#C4, name:#C1, parameterLocations:#C5} - #C10 = foo::Baz {_location:#C9} - #C11 = 9.0 - #C12 = 128.0 - #C13 = wid::_Location {file:#C2, line:#C11, column:#C12, name:#C1, parameterLocations:#C5} - #C14 = foo::Boz {_location:#C13} + #C9 = "Baz" + #C10 = wid::_Location {file:#C2, line:#C8, column:#C4, name:#C9, parameterLocations:#C1} + #C11 = foo::Baz {_location:#C10} + #C12 = 9.0 + #C13 = 128.0 + #C14 = "Boz" + #C15 = wid::_Location {file:#C2, line:#C12, column:#C13, name:#C14, parameterLocations:#C1} + #C16 = foo::Boz {_location:#C15} } diff --git a/pkg/front_end/testcases/incremental/flutter_widget_transform_const.yaml.world.3.expect b/pkg/front_end/testcases/incremental/flutter_widget_transform_const.yaml.world.3.expect index 4d7e73bafa5..7d948ed493d 100644 --- a/pkg/front_end/testcases/incremental/flutter_widget_transform_const.yaml.world.3.expect +++ b/pkg/front_end/testcases/incremental/flutter_widget_transform_const.yaml.world.3.expect @@ -58,7 +58,7 @@ library from "org-dartlang-test:///foo.dart" as foo { : super fra::Widget::•($creationLocationd_0dea112b090073317d4: $creationLocationd_0dea112b090073317d4) ; static factory •({wid::_Location? $creationLocationd_0dea112b090073317d4 = #C1}) → foo::Baz - return #C10; + return #C11; static factory _({wid::_Location? $creationLocationd_0dea112b090073317d4 = #C1}) → foo::Baz let dynamic #redirecting_factory = foo::Baz::__ in invalid-expression; } @@ -71,7 +71,7 @@ library from "org-dartlang-test:///foo.dart" as foo { return new foo::Boz::_($creationLocationd_0dea112b090073317d4: $creationLocationd_0dea112b090073317d4); } else { - return #C14; + return #C16; } } } @@ -80,47 +80,44 @@ library from "org-dartlang-test:///main.dart" as main { import "org-dartlang-test:///foo.dart"; - static field foo::Foo newFoo = foo::Foo::•($creationLocationd_0dea112b090073317d4: #C17); - static field foo::Bar newBar = new foo::Bar::_($creationLocationd_0dea112b090073317d4: #C19); - static field foo::Bar constBar = #C23; - static field foo::Baz newBaz = foo::Baz::•($creationLocationd_0dea112b090073317d4: #C25); + static field foo::Foo newFoo = foo::Foo::•($creationLocationd_0dea112b090073317d4: #C19); + static field foo::Bar newBar = new foo::Bar::_($creationLocationd_0dea112b090073317d4: #C22); + static field foo::Bar constBar = #C26; + static field foo::Baz newBaz = foo::Baz::•($creationLocationd_0dea112b090073317d4: #C28); static field foo::Boz newBoz = foo::Boz::•(createNew: true, $creationLocationd_0dea112b090073317d4: #C29); - static field foo::Boz constBoz = foo::Boz::•(createNew: false, $creationLocationd_0dea112b090073317d4: #C35); + static field foo::Boz constBoz = foo::Boz::•(createNew: false, $creationLocationd_0dea112b090073317d4: #C32); } constants { #C1 = null #C2 = "org-dartlang-test:///foo.dart" #C3 = 2.0 #C4 = 51.0 - #C5 = [] - #C6 = wid::_Location {file:#C2, line:#C3, column:#C4, name:#C1, parameterLocations:#C5} + #C5 = "Foo" + #C6 = wid::_Location {file:#C2, line:#C3, column:#C4, name:#C5, parameterLocations:#C1} #C7 = foo::Foo {_location:#C6} #C8 = 6.0 - #C9 = wid::_Location {file:#C2, line:#C8, column:#C4, name:#C1, parameterLocations:#C5} - #C10 = foo::Baz {_location:#C9} - #C11 = 9.0 - #C12 = 128.0 - #C13 = wid::_Location {file:#C2, line:#C11, column:#C12, name:#C1, parameterLocations:#C5} - #C14 = foo::Boz {_location:#C13} - #C15 = "org-dartlang-test:///main.dart" - #C16 = 18.0 - #C17 = wid::_Location {file:#C15, line:#C3, column:#C16, name:#C1, parameterLocations:#C5} - #C18 = 3.0 - #C19 = wid::_Location {file:#C15, line:#C18, column:#C16, name:#C1, parameterLocations:#C5} - #C20 = 4.0 - #C21 = 22.0 - #C22 = wid::_Location {file:#C15, line:#C20, column:#C21, name:#C1, parameterLocations:#C5} - #C23 = foo::Bar {_location:#C22} - #C24 = 5.0 - #C25 = wid::_Location {file:#C15, line:#C24, column:#C16, name:#C1, parameterLocations:#C5} - #C26 = "createNew" - #C27 = wid::_Location {file:#C1, line:#C8, column:#C21, name:#C26, parameterLocations:#C1} - #C28 = [#C27] - #C29 = wid::_Location {file:#C15, line:#C8, column:#C16, name:#C1, parameterLocations:#C28} + #C9 = "Baz" + #C10 = wid::_Location {file:#C2, line:#C8, column:#C4, name:#C9, parameterLocations:#C1} + #C11 = foo::Baz {_location:#C10} + #C12 = 9.0 + #C13 = 128.0 + #C14 = "Boz" + #C15 = wid::_Location {file:#C2, line:#C12, column:#C13, name:#C14, parameterLocations:#C1} + #C16 = foo::Boz {_location:#C15} + #C17 = "org-dartlang-test:///main.dart" + #C18 = 18.0 + #C19 = wid::_Location {file:#C17, line:#C3, column:#C18, name:#C5, parameterLocations:#C1} + #C20 = 3.0 + #C21 = "Bar" + #C22 = wid::_Location {file:#C17, line:#C20, column:#C18, name:#C21, parameterLocations:#C1} + #C23 = 4.0 + #C24 = 22.0 + #C25 = wid::_Location {file:#C17, line:#C23, column:#C24, name:#C21, parameterLocations:#C1} + #C26 = foo::Bar {_location:#C25} + #C27 = 5.0 + #C28 = wid::_Location {file:#C17, line:#C27, column:#C18, name:#C9, parameterLocations:#C1} + #C29 = wid::_Location {file:#C17, line:#C8, column:#C18, name:#C14, parameterLocations:#C1} #C30 = 7.0 #C31 = 20.0 - #C32 = 24.0 - #C33 = wid::_Location {file:#C1, line:#C30, column:#C32, name:#C26, parameterLocations:#C1} - #C34 = [#C33] - #C35 = wid::_Location {file:#C15, line:#C30, column:#C31, name:#C1, parameterLocations:#C34} + #C32 = wid::_Location {file:#C17, line:#C30, column:#C31, name:#C14, parameterLocations:#C1} } diff --git a/pkg/front_end/testcases/incremental/flutter_widget_transform_nnbd.yaml.world.2.expect b/pkg/front_end/testcases/incremental/flutter_widget_transform_nnbd.yaml.world.2.expect index 5a5826d2562..178186e2fb4 100644 --- a/pkg/front_end/testcases/incremental/flutter_widget_transform_nnbd.yaml.world.2.expect +++ b/pkg/front_end/testcases/incremental/flutter_widget_transform_nnbd.yaml.world.2.expect @@ -54,7 +54,7 @@ constants { #C2 = "org-dartlang-test:///main.dart" #C3 = 3.0 #C4 = 17.0 - #C5 = [] - #C6 = wid::_Location {file:#C2, line:#C3, column:#C4, name:#C1, parameterLocations:#C5} + #C5 = "Foo" + #C6 = wid::_Location {file:#C2, line:#C3, column:#C4, name:#C5, parameterLocations:#C1} #C7 = foo::Foo {_location:#C6} } diff --git a/pkg/front_end/testcases/incremental/flutter_widget_transformer_non_const.yaml.world.2.expect b/pkg/front_end/testcases/incremental/flutter_widget_transformer_non_const.yaml.world.2.expect index ec9e6677ffc..8d1b8cf19f5 100644 --- a/pkg/front_end/testcases/incremental/flutter_widget_transformer_non_const.yaml.world.2.expect +++ b/pkg/front_end/testcases/incremental/flutter_widget_transformer_non_const.yaml.world.2.expect @@ -48,16 +48,13 @@ library from "org-dartlang-test:///main.dart" as main { import "org-dartlang-test:///foo.dart"; - static field foo::Foo foo = new foo::Foo::•(name: "foo", $creationLocationd_0dea112b090073317d4: #C9); + static field foo::Foo foo = new foo::Foo::•(name: "foo", $creationLocationd_0dea112b090073317d4: #C6); } constants { #C1 = null #C2 = "org-dartlang-test:///main.dart" #C3 = 2.0 #C4 = 15.0 - #C5 = 19.0 - #C6 = "name" - #C7 = wid::_Location {file:#C1, line:#C3, column:#C5, name:#C6, parameterLocations:#C1} - #C8 = [#C7] - #C9 = wid::_Location {file:#C2, line:#C3, column:#C4, name:#C1, parameterLocations:#C8} + #C5 = "Foo" + #C6 = wid::_Location {file:#C2, line:#C3, column:#C4, name:#C5, parameterLocations:#C1} } diff --git a/pkg/kernel/lib/transformations/track_widget_constructor_locations.dart b/pkg/kernel/lib/transformations/track_widget_constructor_locations.dart index 74461fa6ab3..cc4d1387419 100644 --- a/pkg/kernel/lib/transformations/track_widget_constructor_locations.dart +++ b/pkg/kernel/lib/transformations/track_widget_constructor_locations.dart @@ -155,24 +155,14 @@ class _WidgetCallSiteTransformer extends Transformer { ConstructorInvocation _constructLocation( Location location, { String? name, - ListLiteral? parameterLocations, - bool showFile: true, }) { final List arguments = [ + new NamedExpression('file', new StringLiteral(location.file.toString())), new NamedExpression('line', new IntLiteral(location.line)), new NamedExpression('column', new IntLiteral(location.column)), + if (name != null) new NamedExpression('name', new StringLiteral(name)) ]; - if (showFile) { - arguments.add(new NamedExpression( - 'file', new StringLiteral(location.file.toString()))); - } - if (name != null) { - arguments.add(new NamedExpression('name', new StringLiteral(name))); - } - if (parameterLocations != null) { - arguments - .add(new NamedExpression('parameterLocations', parameterLocations)); - } + return new ConstructorInvocation( _locationClass.constructors.first, new Arguments([], named: arguments), @@ -240,8 +230,11 @@ class _WidgetCallSiteTransformer extends Transformer { } Expression _computeLocation( - InvocationExpression node, FunctionNode function, Class constructedClass, - {bool isConst: false}) { + InvocationExpression node, + FunctionNode function, + Class constructedClass, { + bool isConst: false, + }) { // For factory constructors we need to use the location specified as an // argument to the factory constructor rather than the location if (_currentFactory != null && @@ -260,35 +253,9 @@ class _WidgetCallSiteTransformer extends Transformer { } } - final Arguments arguments = node.arguments; - final Location location = node.location!; - final List parameterLocations = - []; - final List parameters = function.positionalParameters; - for (int i = 0; i < arguments.positional.length; ++i) { - final Expression expression = arguments.positional[i]; - final VariableDeclaration parameter = parameters[i]; - parameterLocations.add(_constructLocation( - expression.location!, - name: parameter.name, - showFile: false, - )); - } - for (NamedExpression expression in arguments.named) { - parameterLocations.add(_constructLocation( - expression.location!, - name: expression.name, - showFile: false, - )); - } return _constructLocation( - location, - parameterLocations: new ListLiteral( - parameterLocations, - typeArgument: - new InterfaceType(_locationClass, _currentLibrary!.nonNullable), - isConst: true, - ), + node.location!, + name: constructedClass.name, ); }