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

Side by Side Diff: pkg/compiler/lib/src/ssa/builder.dart

Issue 1431513012: Fix for 23806 - don't optimize out Array allocation that may throw (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 1 month 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 | « no previous file | 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 part of ssa; 5 part of ssa;
6 6
7 class SsaFunctionCompiler implements FunctionCompiler { 7 class SsaFunctionCompiler implements FunctionCompiler {
8 final SsaCodeGeneratorTask generator; 8 final SsaCodeGeneratorTask generator;
9 final SsaBuilderTask builder; 9 final SsaBuilderTask builder;
10 final SsaOptimizerTask optimizer; 10 final SsaOptimizerTask optimizer;
(...skipping 5141 matching lines...) Expand 10 before | Expand all | Expand 10 after
5152 if (!inputs[0].isNumber(compiler)) { 5152 if (!inputs[0].isNumber(compiler)) {
5153 HTypeConversion conversion = new HTypeConversion( 5153 HTypeConversion conversion = new HTypeConversion(
5154 null, HTypeConversion.ARGUMENT_TYPE_CHECK, backend.numType, 5154 null, HTypeConversion.ARGUMENT_TYPE_CHECK, backend.numType,
5155 inputs[0], null); 5155 inputs[0], null);
5156 add(conversion); 5156 add(conversion);
5157 inputs[0] = conversion; 5157 inputs[0] = conversion;
5158 } 5158 }
5159 js.Template code = js.js.parseForeignJS('new Array(#)'); 5159 js.Template code = js.js.parseForeignJS('new Array(#)');
5160 var behavior = new native.NativeBehavior(); 5160 var behavior = new native.NativeBehavior();
5161 behavior.typesReturned.add(expectedType); 5161 behavior.typesReturned.add(expectedType);
5162 // The allocation can throw only if the given length is a double 5162 // The allocation can throw only if the given length is a double or
5163 // or negative. 5163 // outside the unsigned 32 bit range.
5164 // TODO(sra): Array allocation should be an instruction so that canThrow
5165 // can depend on a length type discovered in optimization.
5164 bool canThrow = true; 5166 bool canThrow = true;
5165 if (inputs[0].isInteger(compiler) && inputs[0] is HConstant) { 5167 if (inputs[0].isInteger(compiler) && inputs[0] is HConstant) {
5166 var constant = inputs[0]; 5168 var constant = inputs[0];
5167 if (constant.constant.primitiveValue >= 0) canThrow = false; 5169 int value = constant.constant.primitiveValue;
5170 if (0 <= value && value < 0x100000000) canThrow = false;
5168 } 5171 }
5169 HForeignCode foreign = new HForeignCode(code, elementType, inputs, 5172 HForeignCode foreign = new HForeignCode(code, elementType, inputs,
5170 nativeBehavior: behavior, 5173 nativeBehavior: behavior,
5171 throwBehavior: canThrow 5174 throwBehavior: canThrow
5172 ? native.NativeThrowBehavior.MAY 5175 ? native.NativeThrowBehavior.MAY
5173 : native.NativeThrowBehavior.NEVER); 5176 : native.NativeThrowBehavior.NEVER);
5174 push(foreign); 5177 push(foreign);
5175 TypesInferrer inferrer = compiler.typesTask.typesInferrer; 5178 TypesInferrer inferrer = compiler.typesTask.typesInferrer;
5176 if (inferrer.isFixedArrayCheckedForGrowable(send)) { 5179 if (inferrer.isFixedArrayCheckedForGrowable(send)) {
5177 js.Template code = js.js.parseForeignJS(r'#.fixed$length = Array'); 5180 js.Template code = js.js.parseForeignJS(r'#.fixed$length = Array');
(...skipping 3970 matching lines...) Expand 10 before | Expand all | Expand 10 after
9148 if (unaliased is TypedefType) throw 'unable to unalias $type'; 9151 if (unaliased is TypedefType) throw 'unable to unalias $type';
9149 unaliased.accept(this, builder); 9152 unaliased.accept(this, builder);
9150 } 9153 }
9151 9154
9152 void visitDynamicType(DynamicType type, SsaBuilder builder) { 9155 void visitDynamicType(DynamicType type, SsaBuilder builder) {
9153 JavaScriptBackend backend = builder.compiler.backend; 9156 JavaScriptBackend backend = builder.compiler.backend;
9154 ClassElement cls = backend.helpers.DynamicRuntimeType; 9157 ClassElement cls = backend.helpers.DynamicRuntimeType;
9155 builder.push(new HDynamicType(type, new TypeMask.exact(cls, classWorld))); 9158 builder.push(new HDynamicType(type, new TypeMask.exact(cls, classWorld)));
9156 } 9159 }
9157 } 9160 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698