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

Unified Diff: pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart

Issue 1642493002: Add type info to JSArray. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: array changes Created 4 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/compiler/lib/src/cps_ir/cps_ir_builder.dart ('k') | pkg/compiler/lib/src/cps_ir/cps_ir_nodes.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart
diff --git a/pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart b/pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart
index 550cc634c2e4bc5634da80fc64a9c44652c52f2a..919008efaa95e663c748ccf5770a883463ada1d7 100644
--- a/pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart
+++ b/pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart
@@ -382,7 +382,7 @@ class IrBuilderVisitor extends ast.Visitor<ir.Primitive>
IrBuilder builder = getBuilderFor(constructor);
final bool requiresTypeInformation =
- builder.program.requiresRuntimeTypesFor(classElement);
+ builder.program.requiresRuntimeTypesFor(classElement);
return withBuilder(builder, () {
// Setup parameters and create a box if anything is captured.
@@ -410,11 +410,15 @@ class IrBuilderVisitor extends ast.Visitor<ir.Primitive>
closureScope: getClosureScopeForFunction(constructor));
// Create a list of the values of all type argument parameters, if any.
- List<ir.Primitive> typeInformation;
+ ir.Primitive typeInformation;
if (requiresTypeInformation) {
- typeInformation = irParameters.sublist(firstTypeArgumentParameterIndex);
+ typeInformation = new ir.TypeExpression(
+ ir.TypeExpressionKind.INSTANCE,
+ classElement.thisType,
+ irParameters.sublist(firstTypeArgumentParameterIndex));
+ irBuilder.add(new ir.LetPrim(typeInformation));
} else {
- typeInformation = const <ir.Primitive>[];
+ typeInformation = null;
}
// -- Load values for type variables declared on super classes --
@@ -753,7 +757,8 @@ class IrBuilderVisitor extends ast.Visitor<ir.Primitive>
TryBoxedVariables variables = _analyzeTryBoxedVariables(node);
tryStatements = variables.tryStatements;
IrBuilder builder = getBuilderFor(element);
- return withBuilder(builder, () => _makeFunctionBody(element, node));
+ return withBuilder(builder,
+ () => _makeFunctionBody(builder, element, node));
}
ir.FunctionDefinition buildStaticFieldInitializer(FieldElement element) {
@@ -875,17 +880,24 @@ class IrBuilderVisitor extends ast.Visitor<ir.Primitive>
}
}
- ir.FunctionDefinition _makeFunctionBody(FunctionElement element,
- ast.FunctionExpression node) {
+ ir.FunctionDefinition _makeFunctionBody(
+ IrBuilder builder,
+ FunctionElement element,
+ ast.FunctionExpression node) {
FunctionSignature signature = element.functionSignature;
List<Local> parameters = <Local>[];
signature.orderedForEachParameter(
(LocalParameterElement e) => parameters.add(e));
+ bool requiresRuntimeTypes = false;
if (element.isFactoryConstructor) {
- // Type arguments are passed in as extra parameters.
- for (DartType typeVariable in element.enclosingClass.typeVariables) {
- parameters.add(new closure.TypeVariableLocal(typeVariable, element));
+ requiresRuntimeTypes =
+ builder.program.requiresRuntimeTypesFor(element.enclosingElement);
+ if (requiresRuntimeTypes) {
sra1 2016/01/27 07:06:08 This caused a mismatch between call site and calle
+ // Type arguments are passed in as extra parameters.
+ for (DartType typeVariable in element.enclosingClass.typeVariables) {
+ parameters.add(new closure.TypeVariableLocal(typeVariable, element));
+ }
}
}
@@ -893,7 +905,44 @@ class IrBuilderVisitor extends ast.Visitor<ir.Primitive>
closureScope: getClosureScopeForNode(node),
env: getClosureEnvironment());
- visit(node.body);
+ if (element == helpers.jsArrayTypedConstructor) {
+ // Generate a body for JSArray<E>.typed(allocation):
+ //
+ // t1 = setRuntimeTypeInfo(allocation, TypeExpression($E));
+ // return Refinement(t1, <JSArray>);
+ //
+ assert(parameters.length == 1 || parameters.length == 2);
+ ir.Primitive allocation = irBuilder.buildLocalGet(parameters[0]);
+ ClassElement classElement = element.enclosingElement;
+
+ // Only call setRuntimeTypeInfo if JSArray requires the type parameter.
+ if (requiresRuntimeTypes) {
+ assert(parameters.length == 2);
+ ir.Primitive typeArgument =
+ irBuilder.buildTypeVariableAccess(parameters[1].typeVariable);
+
+ ir.Primitive typeInformation = irBuilder.addPrimitive(
+ new ir.TypeExpression(ir.TypeExpressionKind.INSTANCE,
+ element.enclosingClass.thisType,
+ <ir.Primitive>[typeArgument]));
+
+ Element helper = helpers.setRuntimeTypeInfo;
+ CallStructure callStructure = CallStructure.TWO_ARGS;
+ Selector selector = new Selector.call(helper.memberName, callStructure);
+ allocation = irBuilder.buildInvokeStatic(
+ helper, selector, <ir.Primitive>[allocation, typeInformation],
+ sourceInformationBuilder.buildGeneric(node));
+ }
+
+ ir.Primitive refinement = irBuilder.addPrimitive(
+ new ir.Refinement(allocation, typeMaskSystem.arrayType));
+
+ irBuilder.buildReturn(value: refinement,
+ sourceInformation:
+ sourceInformationBuilder.buildImplicitReturn(element));
+ } else {
+ visit(node.body);
+ }
return irBuilder.makeFunctionDefinition();
}
@@ -1551,8 +1600,17 @@ class IrBuilderVisitor extends ast.Visitor<ir.Primitive>
}
List<ir.Primitive> values = node.elements.nodes.mapToList(visit);
InterfaceType type = elements.getType(node);
- return irBuilder.buildListLiteral(type, values,
- allocationSiteType: getAllocationSiteType(node));
+ ir.Primitive list = irBuilder.buildListLiteral(type, values,
+ allocationSiteType: getAllocationSiteType(node));
+ if (type.treatAsRaw) return list;
+ // Call JSArray<E>.typed(allocation) to install the reified type.
+ ConstructorElement constructor = helpers.jsArrayTypedConstructor;
sra1 2016/01/27 07:06:08 There is a small issue here with losing type preci
+ return irBuilder.buildConstructorInvocation(
+ constructor.effectiveTarget,
+ CallStructure.ONE_ARG,
+ constructor.computeEffectiveTargetType(type),
+ <ir.Primitive>[list],
+ sourceInformationBuilder.buildNew(node));
}
ir.Primitive visitLiteralMap(ast.LiteralMap node) {
« no previous file with comments | « pkg/compiler/lib/src/cps_ir/cps_ir_builder.dart ('k') | pkg/compiler/lib/src/cps_ir/cps_ir_nodes.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698