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

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

Issue 11360228: Simplify runtime type support. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove test again. Created 8 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 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 6c1ae5d4a49a3f4270d55008ef8e0ac68a7435e5..c9171b74ea8ae3df9ffd1776c880f6ff946ccfb9 100644
--- a/sdk/lib/_internal/compiler/implementation/ssa/builder.dart
+++ b/sdk/lib/_internal/compiler/implementation/ssa/builder.dart
@@ -2495,7 +2495,7 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
DartType type = elements.getType(typeAnnotation);
HInstruction typeInfo = null;
- if (compiler.codegenWorld.rti.hasTypeArguments(type)) {
+ if (RuntimeTypeInformation.hasTypeArguments(type)) {
pushInvokeHelper1(interceptors.getGetRuntimeTypeInfo(), expression);
typeInfo = pop();
}
@@ -2961,8 +2961,9 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
localsHandler.readThis());
typeInfo = pop();
}
+ int index = RuntimeTypeInformation.getTypeVariableIndex(type);
HInstruction foreign = new HForeign(
- new LiteralDartString('#.${type.name.slowToString()}'),
+ new LiteralDartString('#[$index]'),
new LiteralDartString('String'),
<HInstruction>[typeInfo]);
add(foreign);
@@ -2995,7 +2996,8 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
InterfaceType interfaceType = type;
bool hasTypeArguments = !interfaceType.arguments.isEmpty;
if (!isInQuotes) template.add("'");
- template.add(rti.getName(type.element));
+ template.add(backend.namer.getName(type.element,
+ allowUnsafeName: true));
if (hasTypeArguments) {
template.add("<");
for (DartType argument in interfaceType.arguments) {
@@ -3012,7 +3014,8 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
} else {
assert(type is TypedefType);
if (!isInQuotes) template.add("'");
- template.add(rti.getName(argument.element));
+ template.add(backend.namer.getName(argument.element,
+ allowUnsafeName: true));
if (!isInQuotes) template.add("'");
}
}
@@ -3040,49 +3043,19 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
void callSetRuntimeTypeInfo(ClassElement element,
List<HInstruction> rtiInputs,
HInstruction newObject) {
- bool needsRti = compiler.world.needsRti(element) && !rtiInputs.isEmpty;
- bool runtimeTypeIsUsed = compiler.enabledRuntimeType;
- if (!needsRti && !runtimeTypeIsUsed) return;
-
- HInstruction createForeign(String template,
- List<HInstruction> arguments,
- [String type = 'String']) {
- return new HForeign(new LiteralDartString(template),
- new LiteralDartString(type),
- arguments);
- }
-
- // Construct the runtime type information.
- StringBuffer runtimeCode = new StringBuffer();
- List<HInstruction> runtimeCodeInputs = <HInstruction>[];
- if (runtimeTypeIsUsed) {
- String runtimeTypeString =
- rti.generateRuntimeTypeString(element, rtiInputs.length);
- HInstruction runtimeType = createForeign(runtimeTypeString, rtiInputs);
- add(runtimeType);
- runtimeCodeInputs.add(runtimeType);
- runtimeCode.add("runtimeType: '#'");
- }
- if (needsRti) {
- if (runtimeTypeIsUsed) runtimeCode.add(', ');
- String typeVariablesString =
- RuntimeTypeInformation.generateTypeVariableString(element,
- rtiInputs.length);
- HInstruction typeInfo = createForeign(typeVariablesString, rtiInputs);
- add(typeInfo);
- runtimeCodeInputs.add(typeInfo);
- runtimeCode.add('#');
- }
- HInstruction runtimeInfo =
- createForeign("{$runtimeCode}", runtimeCodeInputs, 'Object');
- add(runtimeInfo);
+ if (!compiler.world.needsRti(element) || element.typeVariables.isEmpty) {
+ return;
+ }
+
+ HInstruction typeInfo = new HLiteralList(rtiInputs);
+ add(typeInfo);
// Set the runtime type information on the object.
Element typeInfoSetterElement = interceptors.getSetRuntimeTypeInfo();
HInstruction typeInfoSetter = new HStatic(typeInfoSetterElement);
add(typeInfoSetter);
add(new HInvokeStatic(
- <HInstruction>[typeInfoSetter, newObject, runtimeInfo]));
+ <HInstruction>[typeInfoSetter, newObject, typeInfo]));
}
visitNewSend(Send node, InterfaceType type) {
@@ -3137,18 +3110,6 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
type.arguments.forEach((DartType argument) {
inputs.add(analyzeTypeArgument(argument, node));
});
- } else if (compiler.enabledRuntimeType) {
- Link<DartType> variables =
- constructor.getEnclosingClass().typeVariables;
- if (!variables.isEmpty) {
- // If the class has type variables but no type arguments have been
- // provided, add [:dynamic:] as argument for all type variables.
- DartString stringDynamic = new DartString.literal('dynamic');
- HInstruction input = graph.addConstantString(stringDynamic,
- node,
- constantSystem);
- variables.forEach((_) => inputs.add(input));
- }
}
}
@@ -3233,11 +3194,18 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
Element helper =
compiler.findHelper(RuntimeTypeInformation.CACHE_HELPER_NAME);
if (element.isClass()) {
- String string = rti.generateRuntimeTypeString(element, 0);
+ ClassElement classElement = element;
+ String string = backend.namer.getName(classElement,
+ allowUnsafeName: true);
+ if (!classElement.typeVariables.isEmpty) {
+ String arguments =
+ RuntimeTypeInformation.buildRawArguments(classElement);
+ string = "$string<$arguments>";
+ }
name = addConstantString(node.selector, string);
} else if (element.isTypedef()) {
// TODO(karlklose): implement support for type variables in typedefs.
- name = addConstantString(node.selector, rti.getName(element));
+ name = addConstantString(node.selector, backend.namer.getName(element));
} else if (element.isTypeVariable()) {
// TODO(6248): implement support for type variables.
compiler.unimplemented('first class type for type variable', node: node);

Powered by Google App Engine
This is Rietveld 408576698