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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/ssa/builder.dart

Issue 17262003: Fix type variables in closures. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 6 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 | Annotate | Revision Log
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 /** 7 /**
8 * A special element for the extra parameter taken by intercepted 8 * A special element for the extra parameter taken by intercepted
9 * methods. We need to override [Element.computeType] because our 9 * methods. We need to override [Element.computeType] because our
10 * optimizers may look at its declared type. 10 * optimizers may look at its declared type.
(...skipping 3237 matching lines...) Expand 10 before | Expand all | Expand 10 after
3248 * Helper to create an instruction that gets the value of a type variable. 3248 * Helper to create an instruction that gets the value of a type variable.
3249 */ 3249 */
3250 HInstruction addTypeVariableReference(TypeVariableType type) { 3250 HInstruction addTypeVariableReference(TypeVariableType type) {
3251 Element member = currentElement; 3251 Element member = currentElement;
3252 bool isClosure = member.enclosingElement.isClosure(); 3252 bool isClosure = member.enclosingElement.isClosure();
3253 if (isClosure) { 3253 if (isClosure) {
3254 ClosureClassElement closureClass = member.enclosingElement; 3254 ClosureClassElement closureClass = member.enclosingElement;
3255 member = closureClass.methodElement; 3255 member = closureClass.methodElement;
3256 member = member.getOutermostEnclosingMemberOrTopLevel(); 3256 member = member.getOutermostEnclosingMemberOrTopLevel();
3257 } 3257 }
3258 if (isClosure && member.isFactoryConstructor()) { 3258 bool isInConstructorContext = member.isConstructor() ||
3259 // The type variable is used from a closure in a factory constructor. The 3259 member.isGenerativeConstructorBody() ||
3260 // value of the type argument is stored as a local on the closure itself. 3260 member.isField();
3261 return localsHandler.readLocal(type.element); 3261 if (isClosure) {
3262 } else if (member.isConstructor() || 3262 if (member.isFactoryConstructor()) {
3263 member.isGenerativeConstructorBody() || 3263 // The type variable is used from a closure in a factory constructor.
3264 member.isField()) { 3264 // The value of the type argument is stored as a local on the closure
3265 // itself.
3266 return localsHandler.readLocal(type.element);
3267 } else if (member.isFunction() ||
3268 member.isGetter() ||
3269 member.isSetter() ||
3270 member.isConstructor() ||
3271 member.isGenerativeConstructorBody()) {
3272 // The type variable is stored on the "enclosing object" and needs to be
3273 // accessed using the this-reference in the closure.
3274 return readTypeVariable(member.getEnclosingClass(), type.element);
3275 } else {
3276 assert(member.isField());
3277 // The type variable is stored in a parameter of the method.
3278 return localsHandler.readLocal(type.element);
3279 }
3280 } else if (isInConstructorContext) {
3265 // The type variable is stored in a parameter of the method. 3281 // The type variable is stored in a parameter of the method.
3266 return localsHandler.readLocal(type.element); 3282 return localsHandler.readLocal(type.element);
3267 } else if (member.isInstanceMember()) { 3283 } else if (member.isInstanceMember()) {
3268 // The type variable is stored on the object. 3284 // The type variable is stored on the object.
3269 return readTypeVariable(member.getEnclosingClass(), 3285 return readTypeVariable(member.getEnclosingClass(),
3270 type.element); 3286 type.element);
3271 } else { 3287 } else {
3272 // TODO(ngeoffray): Match the VM behavior and throw an 3288 // TODO(ngeoffray): Match the VM behavior and throw an
3273 // exception at runtime. 3289 // exception at runtime.
3274 compiler.cancel('Unimplemented unresolved type variable', 3290 compiler.cancel('Unimplemented unresolved type variable',
(...skipping 2122 matching lines...) Expand 10 before | Expand all | Expand 10 after
5397 new HSubGraphBlockInformation(elseBranch.graph)); 5413 new HSubGraphBlockInformation(elseBranch.graph));
5398 5414
5399 HBasicBlock conditionStartBlock = conditionBranch.block; 5415 HBasicBlock conditionStartBlock = conditionBranch.block;
5400 conditionStartBlock.setBlockFlow(info, joinBlock); 5416 conditionStartBlock.setBlockFlow(info, joinBlock);
5401 SubGraph conditionGraph = conditionBranch.graph; 5417 SubGraph conditionGraph = conditionBranch.graph;
5402 HIf branch = conditionGraph.end.last; 5418 HIf branch = conditionGraph.end.last;
5403 assert(branch is HIf); 5419 assert(branch is HIf);
5404 branch.blockInformation = conditionStartBlock.blockFlow; 5420 branch.blockInformation = conditionStartBlock.blockFlow;
5405 } 5421 }
5406 } 5422 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/closure.dart ('k') | sdk/lib/_internal/compiler/implementation/tree/nodes.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698