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

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

Issue 177963002: Use List instead of Link in the type system. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 10 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
Index: sdk/lib/_internal/compiler/implementation/ssa/builder.dart
diff --git a/sdk/lib/_internal/compiler/implementation/ssa/builder.dart b/sdk/lib/_internal/compiler/implementation/ssa/builder.dart
index 17c97060946dbe7e77c8323385b64c6a03fa869f..38e3d81098c452c0d05b9b82c13edc1ee2fc3000 100644
--- a/sdk/lib/_internal/compiler/implementation/ssa/builder.dart
+++ b/sdk/lib/_internal/compiler/implementation/ssa/builder.dart
@@ -1827,21 +1827,24 @@ abstract class SsaFromAstMixin
// the current type. [InterfaceType.asInstanceOf] takes care
// of both.
InterfaceType type = currentClass.thisType.asInstanceOf(enclosingClass);
- Link<DartType> typeVariables = enclosingClass.typeVariables;
- type.typeArguments.forEach((DartType argument) {
- localsHandler.updateLocal(
- typeVariables.head.element,
- analyzeTypeArgument(argument));
- typeVariables = typeVariables.tail;
- });
- // If the supertype is a raw type, we need to set to null the
- // type variables.
- assert(typeVariables.isEmpty
- || enclosingClass.typeVariables == typeVariables);
- while (!typeVariables.isEmpty) {
- localsHandler.updateLocal(typeVariables.head.element,
- graph.addConstantNull(compiler));
- typeVariables = typeVariables.tail;
+ List<DartType> arguments = type.typeArguments;
+ List<DartType> typeVariables = enclosingClass.typeVariables;
+ if (!type.isRaw) {
+ assert(arguments.length == typeVariables.length);
+ Iterator<DartType> variables = typeVariables.iterator;
+ type.typeArguments.forEach((DartType argument) {
+ variables.moveNext();
+ localsHandler.updateLocal(
+ variables.current.element,
+ analyzeTypeArgument(argument));
+ });
+ } else {
+ // If the supertype is a raw type, we need to set to null the
+ // type variables.
+ for (DartType variable in typeVariables) {
+ localsHandler.updateLocal(variable.element,
+ graph.addConstantNull(compiler));
+ }
}
}
@@ -2141,7 +2144,8 @@ abstract class SsaFromAstMixin
bool allIndexed = true;
int expectedIndex = 0;
ClassElement contextClass; // The class of `this`.
- Link typeVariables; // The list of 'remaining type variables' of `this`.
+ int remainingTypeVariables; // The number of 'remaining type variables'
+ //of `this`.
Johnni Winther 2014/02/26 14:01:54 Add space after //
karlklose 2014/02/27 09:31:41 Done.
/// Helper to identify instructions that read a type variable without
/// substitution (that is, directly use the index). These instructions
@@ -2167,15 +2171,15 @@ abstract class SsaFromAstMixin
// many arguments we need to process.
source = newSource;
contextClass = source.sourceElement.getEnclosingClass();
- typeVariables = contextClass.typeVariables;
+ remainingTypeVariables = contextClass.typeVariables.length;
} else {
assert(source == newSource);
}
// If there are no more type variables, then there are more type
// arguments for the new object than the source has, and it can't be
// a copy. Otherwise remove one argument.
- if (typeVariables.isEmpty) return false;
- typeVariables = typeVariables.tail;
+ if (remainingTypeVariables == 0) return false;
+ remainingTypeVariables--;
// Check that the index is the one we expect.
IntConstant constant = index.constant;
return constant.value == expectedIndex++;
@@ -2190,7 +2194,7 @@ abstract class SsaFromAstMixin
typeArguments.add(argument);
});
- if (source != null && allIndexed && typeVariables.isEmpty) {
+ if (source != null && allIndexed && remainingTypeVariables == 0) {
copyRuntimeTypeInfo(source, newObject);
} else {
newObject =
@@ -4141,14 +4145,7 @@ abstract class SsaFromAstMixin
generateAbstractClassInstantiationError(send, cls.name);
return;
}
- if (backend.classNeedsRti(cls)) {
- Link<DartType> typeVariable = cls.typeVariables;
- expectedType.typeArguments.forEach((DartType argument) {
- inputs.add(analyzeTypeArgument(argument));
- typeVariable = typeVariable.tail;
- });
- assert(typeVariable.isEmpty);
- }
+ potentiallyAddTypeArguments(inputs, cls, expectedType);
addInlinedInstantiation(expectedType);
pushInvokeStatic(node, constructor, inputs, elementType);
@@ -4184,6 +4181,16 @@ abstract class SsaFromAstMixin
}
}
+ void potentiallyAddTypeArguments(List<HInstruction> inputs, ClassElement cls,
+ InterfaceType expectedType) {
+ if (!backend.classNeedsRti(cls)) return;
+ assert(expectedType.typeArguments.isEmpty ||
Johnni Winther 2014/02/26 14:01:54 `expectedType.typeArguments.isEmpty ||` should not
karlklose 2014/02/27 09:31:41 If cls is expectedType.element, this assertion is
Johnni Winther 2014/02/27 09:48:23 Shouldn't we then just assert `cls == expectedType
+ cls.typeVariables.length == expectedType.typeArguments.length);
+ expectedType.typeArguments.forEach((DartType argument) {
+ inputs.add(analyzeTypeArgument(argument));
+ });
+ }
+
/// In checked mode checks the [type] of [node] to be well-bounded. The method
/// returns [:true:] if an error can be statically determined.
bool checkTypeVariableBounds(ast.NewExpression node, InterfaceType type) {
@@ -4866,17 +4873,8 @@ abstract class SsaFromAstMixin
for (; i < calleeOptionals.length; i++) {
inputs.add(handleConstantForOptionalParameter(calleeOptionals[i]));
}
-
- if (backend.classNeedsRti(element.getEnclosingClass())) {
- ClassElement cls = function.getEnclosingClass();
- Link<DartType> typeVariable = cls.typeVariables;
- InterfaceType type = elements.getType(node.expression);
- type.typeArguments.forEach((DartType argument) {
- inputs.add(analyzeTypeArgument(argument));
- typeVariable = typeVariable.tail;
- });
- assert(typeVariable.isEmpty);
- }
+ potentiallyAddTypeArguments(inputs, element.getEnclosingClass(),
+ elements.getType(node.expression));
pushInvokeStatic(node, element, inputs);
value = pop();
} else if (node.expression == null) {
@@ -6362,14 +6360,14 @@ class TypeBuilder implements DartTypeVisitor<dynamic, SsaFromAstMixin> {
inputs.add(builder.pop());
}
- Link<DartType> namedParameterTypes = type.namedParameterTypes;
- for (String name in type.namedParameters) {
- ast.DartString dartString = new ast.DartString.literal(name);
+ List<DartType> namedParameterTypes = type.namedParameterTypes;
+ List<String> names = type.namedParameters;
+ for (int index = 0; index < names.length; index++) {
+ ast.DartString dartString = new ast.DartString.literal(names[index]);
inputs.add(
builder.graph.addConstantString(dartString, builder.compiler));
- namedParameterTypes.head.accept(this, builder);
+ namedParameterTypes[index].accept(this, builder);
inputs.add(builder.pop());
- namedParameterTypes = namedParameterTypes.tail;
}
ClassElement cls = builder.compiler.findHelper('RuntimeFunctionType');

Powered by Google App Engine
This is Rietveld 408576698