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

Unified Diff: sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart

Issue 12210142: Implement is-checks against type variables. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove some obsolete code. Created 7 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/js_backend/emitter.dart
diff --git a/sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart b/sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart
index f805355f634bccc366b0574aedde8def7f8eedd6..c7dc30e651f1ad1fae357e73a23ba568bab5beba 100644
--- a/sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart
+++ b/sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart
@@ -107,6 +107,18 @@ class CodeEmitterTask extends CompilerTask {
final bool generateSourceMap;
+ Iterable<ClassElement> cachedClassesUsingTypeVariableTests;
+
+ Iterable<ClassElement> get classesUsingTypeVariableTests {
+ if (cachedClassesUsingTypeVariableTests == null) {
+ cachedClassesUsingTypeVariableTests = compiler.codegenWorld.isChecks
+ .where((DartType t) => t is TypeVariableType)
+ .map((TypeVariableType v) => v.element.getEnclosingClass())
+ .toList();
+ }
+ return cachedClassesUsingTypeVariableTests;
+ }
+
CodeEmitterTask(Compiler compiler, Namer namer, this.generateSourceMap)
: boundClosureBuffer = new CodeBuffer(),
mainBuffer = new CodeBuffer(),
@@ -119,7 +131,10 @@ class CodeEmitterTask extends CompilerTask {
}
void computeRequiredTypeChecks() {
- assert(checkedClasses == null);
+ assert(checkedClasses == null &&
+ checkedTypedefs == null);
ngeoffray 2013/02/26 14:11:37 Fits in one line.
karlklose 2013/02/27 10:12:58 Done.
+ compiler.codegenWorld.addImplicitChecks(classesUsingTypeVariableTests);
+
checkedClasses = new Set<ClassElement>();
checkedTypedefs = new Set<TypedefElement>();
compiler.codegenWorld.isChecks.forEach((DartType t) {
@@ -1075,7 +1090,7 @@ class CodeEmitterTask extends CompilerTask {
void generateIsTest(Element other) {
jsAst.Expression code;
- if (compiler.objectClass == other) return;
+ if (other == compiler.objectClass && other != classElement) return;
ngeoffray 2013/02/26 14:11:37 Why did you add it back now? This deserves a comme
karlklose 2013/02/27 10:12:58 We need Object.$isObject. Comment added.
if (nativeEmitter.requiresNativeIsCheck(other)) {
code = js.fun([], [js.return_(true)]);
} else {
@@ -1136,13 +1151,12 @@ class CodeEmitterTask extends CompilerTask {
}
}
- void emitRuntimeClassesAndTests(CodeBuffer buffer) {
+ void emitRuntimeTypeSupport(CodeBuffer buffer) {
RuntimeTypeInformation rti = backend.rti;
TypeChecks typeChecks = rti.getRequiredChecks();
bool needsHolder(ClassElement cls) {
ngeoffray 2013/02/26 14:11:37 Please add a comment on who needs a holder.
karlklose 2013/02/27 10:12:58 Done.
- return !neededClasses.contains(cls) || cls.isNative() ||
- rti.isJsNative(cls);
+ return !neededClasses.contains(cls) || cls.isNative();
}
/**
@@ -1565,6 +1579,11 @@ class CodeEmitterTask extends CompilerTask {
emitted.add(superclass);
}
for (DartType supertype in cls.allSupertypes) {
+ ClassElement superclass = supertype.element;
+ if (classesUsingTypeVariableTests.contains(superclass)) {
+ emitSubstitution(superclass, emitNull: true);
+ emitted.add(superclass);
+ }
for (ClassElement check in checkedClasses) {
if (supertype.element == check && !emitted.contains(check)) {
// Generate substitution. If no substitution is necessary, emit
@@ -2582,7 +2601,6 @@ if (typeof document !== 'undefined' && document.readyState !== 'complete') {
String assembleProgram() {
measure(() {
computeNeededClasses();
-
mainBuffer.add(GENERATED_BY);
if (!compiler.enableMinification) mainBuffer.add(HOOKS_API_USAGE);
mainBuffer.add('function ${namer.isolateName}()$_{}\n');
@@ -2603,7 +2621,7 @@ if (typeof document !== 'undefined' && document.readyState !== 'complete') {
// We need to finish the classes before we construct compile time
// constants.
emitFinishClassesInvocationIfNecessary(mainBuffer);
- emitRuntimeClassesAndTests(mainBuffer);
+ emitRuntimeTypeSupport(mainBuffer);
emitCompileTimeConstants(mainBuffer);
// Static field initializations require the classes and compile-time
// constants to be set up.

Powered by Google App Engine
This is Rietveld 408576698