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

Unified Diff: pkg/compiler/lib/src/ssa/builder_kernel.dart

Issue 2588263004: Kernel-ify buildIsNode logic and add generics type variable checking in buildIsNode. (Closed)
Patch Set: . Created 4 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/ssa/builder_kernel.dart
diff --git a/pkg/compiler/lib/src/ssa/builder_kernel.dart b/pkg/compiler/lib/src/ssa/builder_kernel.dart
index 7c92668d3bc5630a4107d735214fef475073b9ce..710b4d521005e8670fc73cb839c58deec5eb567d 100644
--- a/pkg/compiler/lib/src/ssa/builder_kernel.dart
+++ b/pkg/compiler/lib/src/ssa/builder_kernel.dart
@@ -1942,49 +1942,71 @@ class KernelSsaBuilder extends ir.Visitor with GraphBuilder {
}
HInstruction buildIsNode(
- ir.Node node, ir.DartType dart_type, HInstruction expression) {
- // TODO(sra): Convert the type testing logic here to use ir.DartType.
- DartType type = astAdapter.getDartType(dart_type);
-
- type = localsHandler.substInContext(type).unaliased;
Siggi Cherem (dart-lang) 2016/12/20 22:37:29 Are the kernel type-variables substituted by the t
-
- if (type is MethodTypeVariableType) {
- return graph.addConstantBool(true, closedWorld);
- }
-
- if (type is MalformedType) {
- ErroneousElement element = type.element;
- generateTypeError(node, element.message);
- return new HIs.compound(type, expression, pop(), commonMasks.boolType);
- }
-
- if (type.isFunctionType) {
- List arguments = <HInstruction>[buildFunctionType(type), expression];
- _pushDynamicInvocation(node, commonMasks.boolType, arguments,
+ ir.Node node, ir.DartType type, HInstruction expression) {
+ if (type is ir.InvalidType) {
+ generateTypeError(node,
+ (astAdapter.getDartType(type).element as ErroneousElement).message);
Siggi Cherem (dart-lang) 2016/12/20 22:37:30 we call astAdapter.getDartType on all branches her
Emily Fortuna 2016/12/22 19:22:12 Done.
+ return new HIs.compound(astAdapter.getDartType(type), expression, pop(),
+ commonMasks.boolType);
+ } else if (type is ir.FunctionType) {
Siggi Cherem (dart-lang) 2016/12/20 22:37:30 style nit (here and below): I know this comes from
Emily Fortuna 2016/12/22 19:22:12 ah, I didn't know this was the preferred style. Fi
+ List arguments = [
+ buildFunctionType(astAdapter.getDartType(type)),
+ expression
+ ];
+ _pushDynamicInvocation(node, null, arguments,
selector: new Selector.call(
- new PrivateName('_isTest', astAdapter.jsHelperLibrary),
+ new PrivateName('_isTest', backend.helpers.jsHelperLibrary),
CallStructure.ONE_ARG));
- return new HIs.compound(type, expression, pop(), commonMasks.boolType);
- }
-
- if (type.isTypeVariable) {
- HInstruction runtimeType =
- typeBuilder.addTypeVariableReference(type, sourceElement);
+ return new HIs.compound(astAdapter.getDartType(type), expression, pop(),
+ commonMasks.boolType);
+ } else if (type is ir.TypeParameterType) {
+ HInstruction runtimeType = typeBuilder.addTypeVariableReference(
+ astAdapter.getDartType(type), sourceElement);
_pushStaticInvocation(astAdapter.checkSubtypeOfRuntimeType,
<HInstruction>[expression, runtimeType], commonMasks.boolType);
- return new HIs.variable(type, expression, pop(), commonMasks.boolType);
- }
-
- // TODO(sra): Type with type parameters.
-
- if (backend.hasDirectCheckFor(type)) {
- return new HIs.direct(type, expression, commonMasks.boolType);
+ return new HIs.variable(astAdapter.getDartType(type), expression, pop(),
+ commonMasks.boolType);
+ } else if (_isInterfaceWithNoRawTypes(type)) {
+ HInstruction representations =
+ typeBuilder.buildTypeArgumentRepresentations(
+ astAdapter.getDartType(type), sourceElement);
+ add(representations);
+ ClassElement element = astAdapter.getDartType(type).element;
+ js.Name operator = backend.namer.operatorIs(element);
+ HInstruction isFieldName =
+ graph.addConstantStringFromName(operator, closedWorld);
+ HInstruction asFieldName =
+ closedWorld.hasAnyStrictSubtype(element)
+ ? graph.addConstantStringFromName(
+ backend.namer.substitutionName(element), closedWorld)
+ : graph.addConstantNull(closedWorld);
+ List<HInstruction> inputs = <HInstruction>[
+ expression,
+ isFieldName,
+ representations,
+ asFieldName
+ ];
+ _pushStaticInvocation(
+ astAdapter.checkSubtype, inputs, commonMasks.boolType);
+ return new HIs.compound(astAdapter.getDartType(type), expression, pop(),
+ commonMasks.boolType);
+ } else {
+ if (backend.hasDirectCheckFor(astAdapter.getDartType(type))) {
+ return new HIs.direct(
+ astAdapter.getDartType(type), expression, commonMasks.boolType);
+ }
+ // The interceptor is not always needed. It is removed by optimization
+ // when the receiver type or tested type permit.
+ return new HIs.raw(astAdapter.getDartType(type), expression,
+ _interceptorFor(expression), commonMasks.boolType);
}
+ }
- // The interceptor is not always needed. It is removed by optimization
- // when the receiver type or tested type permit.
- HInterceptor interceptor = _interceptorFor(expression);
- return new HIs.raw(type, expression, interceptor, commonMasks.boolType);
+ bool _isInterfaceWithNoRawTypes(ir.DartType type) {
Siggi Cherem (dart-lang) 2016/12/20 22:37:30 nit: we might need a different name here. One idea
Emily Fortuna 2016/12/22 19:22:12 Done.
+ return type is ir.InterfaceType &&
+ (type as ir.InterfaceType)
+ .typeArguments
+ .any((ir.DartType typeArgType) => typeArgType is! ir.DynamicType);
Siggi Cherem (dart-lang) 2016/12/20 22:37:30 I believe we should also exclude a couple other ca
Emily Fortuna 2016/12/22 19:22:12 Done.
}
@override
« 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