Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Side by Side Diff: lib/src/codegen/side_effect_analysis.dart

Issue 1117373002: fixes #147, add more cases to isStateless (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/runtime/dart/convert.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library dev_compiler.src.codegen.side_effect_analysis; 5 library dev_compiler.src.codegen.side_effect_analysis;
6 6
7 import 'package:analyzer/src/generated/ast.dart'; 7 import 'package:analyzer/src/generated/ast.dart';
8 import 'package:analyzer/src/generated/element.dart'; 8 import 'package:analyzer/src/generated/element.dart';
9 9
10 /// True is the expression can be evaluated multiple times without causing 10 /// True is the expression can be evaluated multiple times without causing
(...skipping 10 matching lines...) Expand all
21 /// 21 ///
22 /// This method is used to avoid creating temporaries in cases where we know 22 /// This method is used to avoid creating temporaries in cases where we know
23 /// we can safely re-evaluate [node] multiple times in [context]. This lets 23 /// we can safely re-evaluate [node] multiple times in [context]. This lets
24 /// us generate prettier code. 24 /// us generate prettier code.
25 /// 25 ///
26 /// This method is conservative: it should never return `true` unless it is 26 /// This method is conservative: it should never return `true` unless it is
27 /// certain the [node] is stateless, because generated code may rely on the 27 /// certain the [node] is stateless, because generated code may rely on the
28 /// correctness of a `true` value. However it may return `false` for things 28 /// correctness of a `true` value. However it may return `false` for things
29 /// that are in fact, stateless. 29 /// that are in fact, stateless.
30 bool isStateless(Expression node, [AstNode context]) { 30 bool isStateless(Expression node, [AstNode context]) {
31 // `this` and `super` cannot be reassigned.
32 if (node is ThisExpression || node is SuperExpression) return true;
31 if (node is SimpleIdentifier) { 33 if (node is SimpleIdentifier) {
32 var e = node.staticElement; 34 var e = node.staticElement;
33 if (e is PropertyAccessorElement) e = e.variable; 35 if (e is PropertyAccessorElement) e = e.variable;
34 if (e is VariableElement && !e.isSynthetic) { 36 if (e is VariableElement && !e.isSynthetic) {
35 if (e.isFinal) return true; 37 if (e.isFinal) return true;
36 if (e is LocalVariableElement || e is ParameterElement) { 38 if (e is LocalVariableElement || e is ParameterElement) {
37 // make sure the local isn't mutated in the context. 39 // make sure the local isn't mutated in the context.
38 return !_isPotentiallyMutated(e, context); 40 return !_isPotentiallyMutated(e, context);
39 } 41 }
40 } 42 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 if (parent is MethodInvocation && 79 if (parent is MethodInvocation &&
78 identical(parent.methodName, node)) return; 80 identical(parent.methodName, node)) return;
79 if (parent is ConstructorName) return; 81 if (parent is ConstructorName) return;
80 if (parent is Label) return; 82 if (parent is Label) return;
81 83
82 if (node.inSetterContext() && node.staticElement == _variable) { 84 if (node.inSetterContext() && node.staticElement == _variable) {
83 _potentiallyMutated = true; 85 _potentiallyMutated = true;
84 } 86 }
85 } 87 }
86 } 88 }
OLDNEW
« no previous file with comments | « lib/runtime/dart/convert.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698