Skip to content

Commit 1c0759a

Browse files
author
John Messerly
committed
DDC changes for Analyzer src/task/strong/info.dart refactor
Review CL: https://codereview.chromium.org/2057373003/
1 parent e68cee4 commit 1c0759a

File tree

4 files changed

+58
-62
lines changed

4 files changed

+58
-62
lines changed

pkg/dev_compiler/lib/src/compiler/code_generator.dart

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import 'package:analyzer/src/generated/type_system.dart'
2121
show StrongTypeSystemImpl;
2222
import 'package:analyzer/src/summary/summarize_elements.dart'
2323
show PackageBundleAssembler;
24-
import 'package:analyzer/src/task/strong/info.dart' show DynamicInvoke;
24+
import 'package:analyzer/src/task/strong/ast_properties.dart'
25+
show isDynamicInvoke, setIsDynamicInvoke;
2526
import 'package:source_maps/source_maps.dart';
2627
import 'package:path/path.dart' show separator;
2728

@@ -2729,7 +2730,7 @@ class CodeGenerator extends GeneralizingAstVisitor
27292730
id = lhs.identifier;
27302731
}
27312732

2732-
if (target != null && DynamicInvoke.get(target)) {
2733+
if (target != null && isDynamicInvoke(target)) {
27332734
if (_inWhitelistCode(lhs)) {
27342735
var vars = <JS.MetaLetVariable, JS.Expression>{};
27352736
var l = _visit(_bindValue(vars, 'l', target));
@@ -2868,7 +2869,7 @@ class CodeGenerator extends GeneralizingAstVisitor
28682869
var memberName = _emitMemberName(name, type: type, isStatic: isStatic);
28692870

28702871
JS.Expression jsTarget = _visit(target);
2871-
if (DynamicInvoke.get(target) || DynamicInvoke.get(node.methodName)) {
2872+
if (isDynamicInvoke(target) || isDynamicInvoke(node.methodName)) {
28722873
if (_inWhitelistCode(target)) {
28732874
var vars = <JS.MetaLetVariable, JS.Expression>{};
28742875
var l = _visit(_bindValue(vars, 'l', target));
@@ -2902,7 +2903,7 @@ class CodeGenerator extends GeneralizingAstVisitor
29022903
JS.Expression _emitFunctionCall(InvocationExpression node) {
29032904
var fn = _visit(node.function);
29042905
var args = _visit(node.argumentList) as List<JS.Expression>;
2905-
if (DynamicInvoke.get(node.function)) {
2906+
if (isDynamicInvoke(node.function)) {
29062907
var typeArgs = _emitInvokeTypeArguments(node);
29072908
if (typeArgs != null) {
29082909
return js.call('dart.dgcall(#, #, #)',
@@ -3778,7 +3779,7 @@ class CodeGenerator extends GeneralizingAstVisitor
37783779

37793780
id.staticElement = new TemporaryVariableElement.forNode(id, variable);
37803781
id.staticType = type;
3781-
DynamicInvoke.set(id, type.isDynamic);
3782+
setIsDynamicInvoke(id, type.isDynamic);
37823783
addTemporaryVariable(id.staticElement, nullable: nullable);
37833784
return id;
37843785
}
@@ -3852,7 +3853,7 @@ class CodeGenerator extends GeneralizingAstVisitor
38523853
return expr as SimpleIdentifier;
38533854
}
38543855
result.staticType = expr.staticType;
3855-
DynamicInvoke.set(result, DynamicInvoke.get(expr));
3856+
setIsDynamicInvoke(result, isDynamicInvoke(expr));
38563857
return result;
38573858
}
38583859

@@ -4147,7 +4148,7 @@ class CodeGenerator extends GeneralizingAstVisitor
41474148
bool isStatic = member is ClassMemberElement && member.isStatic;
41484149
var name = _emitMemberName(memberName,
41494150
type: getStaticType(target), isStatic: isStatic);
4150-
if (DynamicInvoke.get(target)) {
4151+
if (isDynamicInvoke(target)) {
41514152
if (_inWhitelistCode(target)) {
41524153
var vars = <JS.MetaLetVariable, JS.Expression>{};
41534154
var l = _visit(_bindValue(vars, 'l', target));
@@ -4199,7 +4200,7 @@ class CodeGenerator extends GeneralizingAstVisitor
41994200
Expression target, String name, List<Expression> args) {
42004201
var type = getStaticType(target);
42014202
var memberName = _emitMemberName(name, unary: args.isEmpty, type: type);
4202-
if (DynamicInvoke.get(target)) {
4203+
if (isDynamicInvoke(target)) {
42034204
if (_inWhitelistCode(target)) {
42044205
var vars = <JS.MetaLetVariable, JS.Expression>{};
42054206
var l = _visit(_bindValue(vars, 'l', target));

pkg/dev_compiler/lib/src/compiler/reify_coercions.dart

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ import 'package:analyzer/src/dart/ast/ast.dart' show FunctionBodyImpl;
99
import 'package:analyzer/src/dart/ast/utilities.dart' show NodeReplacer;
1010
import 'package:analyzer/src/dart/element/type.dart' show DynamicTypeImpl;
1111
import 'package:analyzer/src/generated/parser.dart' show ResolutionCopier;
12-
import 'package:analyzer/src/task/strong/info.dart'
13-
show CoercionInfo, DownCast, DynamicInvoke;
12+
import 'package:analyzer/src/task/strong/ast_properties.dart' as ast_properties;
1413
import 'package:logging/logging.dart' as logger;
1514

1615
import 'ast_builder.dart' show AstBuilder, RawAstBuilder;
@@ -29,19 +28,36 @@ class CoercionReifier extends analyzer.GeneralizingAstVisitor<Object> {
2928
/// explicit coercion nodes in appropriate places.
3029
static List<CompilationUnit> reify(List<CompilationUnit> units) {
3130
var cr = new CoercionReifier._();
32-
// Clone compilation units, so we don't modify the originals.
33-
units = units.map(cr._clone).toList(growable: false);
34-
units.forEach(cr.visitCompilationUnit);
35-
return units;
31+
return units.map(cr.visitCompilationUnit).toList(growable: false);
32+
}
33+
34+
@override
35+
CompilationUnit visitCompilationUnit(CompilationUnit node) {
36+
if (ast_properties.hasImplicitCasts(node)) {
37+
// Clone compilation unit, so we don't modify the originals.
38+
node = _clone(node);
39+
super.visitCompilationUnit(node);
40+
}
41+
return node;
3642
}
3743

3844
@override
3945
visitExpression(Expression node) {
40-
var coercion = CoercionInfo.get(node);
41-
if (coercion is DownCast) {
42-
return _visitDownCast(coercion, node);
46+
node.visitChildren(this);
47+
48+
var castType = ast_properties.getImplicitCast(node);
49+
if (castType != null) {
50+
_replaceNode(node.parent, node, _castExpression(node, castType));
4351
}
44-
return super.visitExpression(node);
52+
}
53+
54+
@override
55+
visitMethodInvocation(MethodInvocation node) {
56+
if (isInlineJS(node.methodName.staticElement)) {
57+
// Don't cast our inline-JS code in SDK.
58+
ast_properties.setImplicitCast(node, null);
59+
}
60+
visitExpression(node);
4561
}
4662

4763
@override
@@ -58,14 +74,13 @@ class CoercionReifier extends analyzer.GeneralizingAstVisitor<Object> {
5874

5975
// If needed, assert a cast inside the body before the variable is read.
6076
var variable = node.identifier ?? node.loopVariable.identifier;
61-
var coercion = CoercionInfo.get(variable);
62-
if (coercion is DownCast) {
77+
var castType = ast_properties.getImplicitCast(variable);
78+
if (castType != null) {
6379
// Build the cast. We will place this cast in the body, so need to clone
6480
// the variable's AST node and clear out its static type (otherwise we
6581
// will optimize away the cast).
6682
var cast = _castExpression(
67-
_clone(variable)..staticType = DynamicTypeImpl.instance,
68-
coercion.convertedType);
83+
_clone(variable)..staticType = DynamicTypeImpl.instance, castType);
6984

7085
var body = node.body;
7186
var blockBody = <Statement>[RawAstBuilder.expressionStatement(cast)];
@@ -78,11 +93,6 @@ class CoercionReifier extends analyzer.GeneralizingAstVisitor<Object> {
7893
}
7994
}
8095

81-
void _visitDownCast(DownCast node, Expression expr) {
82-
expr.visitChildren(this);
83-
_replaceNode(expr.parent, expr, coerceExpression(expr, node));
84-
}
85-
8696
void _replaceNode(AstNode parent, AstNode oldNode, AstNode newNode) {
8797
if (!identical(oldNode, newNode)) {
8898
var replaced = parent.accept(new NodeReplacer(oldNode, newNode));
@@ -92,19 +102,6 @@ class CoercionReifier extends analyzer.GeneralizingAstVisitor<Object> {
92102
}
93103
}
94104

95-
/// Coerce [e] using [c], returning a new expression.
96-
Expression coerceExpression(Expression e, DownCast node) {
97-
if (e is NamedExpression) {
98-
Expression inner = coerceExpression(e.expression, node);
99-
return new NamedExpression(e.name, inner);
100-
}
101-
if (e is MethodInvocation && isInlineJS(e.methodName.staticElement)) {
102-
// Inline JS code should not need casts.
103-
return e;
104-
}
105-
return _castExpression(e, node.convertedType);
106-
}
107-
108105
Expression _castExpression(Expression e, DartType toType) {
109106
// We use an empty name in the AST, because the JS code generator only cares
110107
// about the target type. It does not look at the AST name.
@@ -124,9 +121,11 @@ class CoercionReifier extends analyzer.GeneralizingAstVisitor<Object> {
124121

125122
class _TreeCloner extends analyzer.AstCloner {
126123
void _cloneProperties(AstNode clone, AstNode node) {
127-
if (clone != null) {
128-
CoercionInfo.set(clone, CoercionInfo.get(node));
129-
DynamicInvoke.set(clone, DynamicInvoke.get(node));
124+
if (clone is Expression) {
125+
ast_properties.setImplicitCast(
126+
clone, ast_properties.getImplicitCast(node));
127+
ast_properties.setIsDynamicInvoke(
128+
clone, ast_properties.isDynamicInvoke(node));
130129
}
131130
}
132131

pkg/dev_compiler/pubspec.lock

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ packages:
66
name: analyzer
77
url: "https://pub.dartlang.org"
88
source: hosted
9-
version: "0.27.4-alpha.7"
9+
version: "0.27.4-alpha.11"
1010
args:
1111
description:
1212
name: args
@@ -54,19 +54,19 @@ packages:
5454
name: collection
5555
url: "https://pub.dartlang.org"
5656
source: hosted
57-
version: "1.7.0"
57+
version: "1.8.0"
5858
convert:
5959
description:
6060
name: convert
6161
url: "https://pub.dartlang.org"
6262
source: hosted
63-
version: "1.1.1"
63+
version: "2.0.0"
6464
crypto:
6565
description:
6666
name: crypto
6767
url: "https://pub.dartlang.org"
6868
source: hosted
69-
version: "0.9.2+1"
69+
version: "2.0.1"
7070
csslib:
7171
description:
7272
name: csslib
@@ -144,7 +144,7 @@ packages:
144144
name: package_config
145145
url: "https://pub.dartlang.org"
146146
source: hosted
147-
version: "0.1.3"
147+
version: "0.1.5"
148148
path:
149149
description:
150150
name: path
@@ -168,13 +168,13 @@ packages:
168168
name: protobuf
169169
url: "https://pub.dartlang.org"
170170
source: hosted
171-
version: "0.5.1+2"
171+
version: "0.5.1+4"
172172
pub_semver:
173173
description:
174174
name: pub_semver
175175
url: "https://pub.dartlang.org"
176176
source: hosted
177-
version: "1.2.4"
177+
version: "1.3.0"
178178
shelf:
179179
description:
180180
name: shelf
@@ -210,7 +210,7 @@ packages:
210210
name: source_span
211211
url: "https://pub.dartlang.org"
212212
source: hosted
213-
version: "1.2.2"
213+
version: "1.2.3"
214214
stack_trace:
215215
description:
216216
name: stack_trace
@@ -222,19 +222,19 @@ packages:
222222
name: stream_channel
223223
url: "https://pub.dartlang.org"
224224
source: hosted
225-
version: "1.4.0"
225+
version: "1.5.0"
226226
string_scanner:
227227
description:
228228
name: string_scanner
229229
url: "https://pub.dartlang.org"
230230
source: hosted
231-
version: "0.1.4+1"
231+
version: "0.1.5"
232232
test:
233233
description:
234234
name: test
235235
url: "https://pub.dartlang.org"
236236
source: hosted
237-
version: "0.12.13+4"
237+
version: "0.12.13+5"
238238
typed_data:
239239
description:
240240
name: typed_data
@@ -264,13 +264,13 @@ packages:
264264
name: web_socket_channel
265265
url: "https://pub.dartlang.org"
266266
source: hosted
267-
version: "1.0.3"
267+
version: "1.0.4"
268268
webdriver:
269269
description:
270270
name: webdriver
271271
url: "https://pub.dartlang.org"
272272
source: hosted
273-
version: "0.8.8"
273+
version: "1.1.1"
274274
when:
275275
description:
276276
name: when
@@ -289,4 +289,4 @@ packages:
289289
url: "https://pub.dartlang.org"
290290
source: hosted
291291
version: "2.1.9"
292-
sdk: ">=1.16.0 <2.0.0"
292+
sdk: ">=1.17.0-dev.6.2 <1.19.0"

pkg/dev_compiler/pubspec.yaml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,7 @@ dev_dependencies:
2727
dart_style: 0.2.4
2828
test: ^0.12.0
2929
unittest: ^0.11.6
30-
webdriver: ^0.8.8
31-
32-
dependency_overrides:
33-
# Remove once there is a package:test that allows 1.18 SDKs in its contraint.
34-
test: ^0.12.0
30+
webdriver: ^1.1.0
3531

3632
environment:
3733
sdk: ">=1.12.0 <2.0.0"

0 commit comments

Comments
 (0)