Skip to content

Commit 6f85eb0

Browse files
author
John Messerly
authored
Merge pull request #589 from dart-lang/rm_strong_info
DDC changes for Analyzer src/task/strong/info.dart refactor
2 parents 3e5d1d8 + d41215c commit 6f85eb0

File tree

4 files changed

+55
-59
lines changed

4 files changed

+55
-59
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

@@ -2743,7 +2744,7 @@ class CodeGenerator extends GeneralizingAstVisitor
27432744
return _emitSetSuper(lhs, target, id, rhs);
27442745
}
27452746

2746-
if (DynamicInvoke.get(target)) {
2747+
if (target != null && isDynamicInvoke(target)) {
27472748
if (_inWhitelistCode(lhs)) {
27482749
var vars = <JS.MetaLetVariable, JS.Expression>{};
27492750
var l = _visit(_bindValue(vars, 'l', target));
@@ -3014,7 +3015,7 @@ class CodeGenerator extends GeneralizingAstVisitor
30143015
var memberName = _emitMemberName(name, type: type, isStatic: isStatic);
30153016

30163017
JS.Expression jsTarget = _visit(target);
3017-
if (DynamicInvoke.get(target) || DynamicInvoke.get(node.methodName)) {
3018+
if (isDynamicInvoke(target) || isDynamicInvoke(node.methodName)) {
30183019
if (_inWhitelistCode(target)) {
30193020
var vars = <JS.MetaLetVariable, JS.Expression>{};
30203021
var l = _visit(_bindValue(vars, 'l', target));
@@ -3048,7 +3049,7 @@ class CodeGenerator extends GeneralizingAstVisitor
30483049
JS.Expression _emitFunctionCall(InvocationExpression node) {
30493050
var fn = _visit(node.function);
30503051
var args = _visit(node.argumentList) as List<JS.Expression>;
3051-
if (DynamicInvoke.get(node.function)) {
3052+
if (isDynamicInvoke(node.function)) {
30523053
var typeArgs = _emitInvokeTypeArguments(node);
30533054
if (typeArgs != null) {
30543055
return js.call('dart.dgcall(#, #, #)',
@@ -3924,7 +3925,7 @@ class CodeGenerator extends GeneralizingAstVisitor
39243925

39253926
id.staticElement = new TemporaryVariableElement.forNode(id, variable);
39263927
id.staticType = type;
3927-
DynamicInvoke.set(id, type.isDynamic);
3928+
setIsDynamicInvoke(id, type.isDynamic);
39283929
addTemporaryVariable(id.staticElement, nullable: nullable);
39293930
return id;
39303931
}
@@ -3998,7 +3999,7 @@ class CodeGenerator extends GeneralizingAstVisitor
39983999
return expr as SimpleIdentifier;
39994000
}
40004001
result.staticType = expr.staticType;
4001-
DynamicInvoke.set(result, DynamicInvoke.get(expr));
4002+
setIsDynamicInvoke(result, isDynamicInvoke(expr));
40024003
return result;
40034004
}
40044005

@@ -4293,7 +4294,7 @@ class CodeGenerator extends GeneralizingAstVisitor
42934294
bool isStatic = member is ClassMemberElement && member.isStatic;
42944295
var name = _emitMemberName(memberName,
42954296
type: getStaticType(target), isStatic: isStatic);
4296-
if (DynamicInvoke.get(target)) {
4297+
if (isDynamicInvoke(target)) {
42974298
if (_inWhitelistCode(target)) {
42984299
var vars = <JS.MetaLetVariable, JS.Expression>{};
42994300
var l = _visit(_bindValue(vars, 'l', target));
@@ -4345,7 +4346,7 @@ class CodeGenerator extends GeneralizingAstVisitor
43454346
Expression target, String name, List<Expression> args) {
43464347
var type = getStaticType(target);
43474348
var memberName = _emitMemberName(name, unary: args.isEmpty, type: type);
4348-
if (DynamicInvoke.get(target)) {
4349+
if (isDynamicInvoke(target)) {
43494350
if (_inWhitelistCode(target)) {
43504351
var vars = <JS.MetaLetVariable, JS.Expression>{};
43514352
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: 10 additions & 10 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.11"
9+
version: "0.27.4-alpha.12"
1010
args:
1111
description:
1212
name: args
@@ -54,13 +54,13 @@ 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
@@ -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
@@ -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: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ author: Dart Dev Compiler team <[email protected]>
88
homepage: https://github.com/dart-lang/dev_compiler
99

1010
dependencies:
11-
analyzer: ^0.27.4-alpha.11
11+
analyzer: ^0.27.4-alpha.12
1212
args: ^0.13.0
1313
bazel_worker: ^0.1.0
1414
cli_util: ^0.0.1
@@ -27,11 +27,7 @@ dev_dependencies:
2727
dart_style: 0.2.4
2828
test: ^0.12.0
2929
unittest: ^0.11.6
30-
webdriver: ^1.0.0
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)