Incremental compilation: set up inheritance.

R=johnniwinther@google.com

Review URL: https://codereview.chromium.org//719443002

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@41769 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
ahe@google.com
2014-11-17 09:56:14 +00:00
parent 96d8115f02
commit 1e9928766c
6 changed files with 82 additions and 4 deletions
@@ -304,8 +304,8 @@ class OldEmitter implements Emitter {
/** Needs defineClass to be defined. */
jsAst.Expression buildInheritFrom() {
return js(r'''
var inheritFrom = function() {
jsAst.Expression result = js(r'''
function() {
function tmp() {}
var hasOwnProperty = Object.prototype.hasOwnProperty;
return function (constructor, superConstructor) {
@@ -323,6 +323,10 @@ class OldEmitter implements Emitter {
};
}()
''');
if (compiler.hasIncrementalSupport) {
result = js(r'self.$dart_unsafe_eval.inheritFrom = #', [result]);
}
return js(r'var inheritFrom = #', [result]);
}
/// Code that needs to be run before first invocation of
@@ -747,6 +747,13 @@ class TypedSelector extends Selector {
new Map<Selector, Map<TypeMask, TypedSelector>>();
factory TypedSelector(TypeMask mask, Selector selector, World world) {
if (!world.hasClosedWorldAssumption) {
bool isNullable = mask.isNullable;
mask = world.compiler.typesTask.dynamicType;
if (isNullable) {
mask = mask.nullable();
}
}
// TODO(johnniwinther): Allow more TypeSelector kinds during resoluton.
assert(world.isClosed || mask.isExact);
if (selector.mask == mask) return selector;
+1 -1
View File
@@ -4,7 +4,7 @@
part of dart2js;
const DONT_KNOW_HOW_TO_FIX = "";
const DONT_KNOW_HOW_TO_FIX = "Computer says no!";
/**
* The messages in this file should meet the following guide lines:
+6
View File
@@ -96,6 +96,10 @@ abstract class ClassWorld {
/// Returns `true` if any subclass of [superclass] implements [type].
bool hasAnySubclassThatImplements(ClassElement superclass, ClassElement type);
/// Returns `true` if closed-world assumptions can be made, that is,
/// incremental compilation isn't enabled.
bool get hasClosedWorldAssumption;
}
class World implements ClassWorld {
@@ -521,4 +525,6 @@ class World implements ClassWorld {
}
return functionsThatMightBePassedToApply.contains(element);
}
bool get hasClosedWorldAssumption => !compiler.hasIncrementalSupport;
}
@@ -417,7 +417,14 @@ class LibraryUpdater extends JsFeatures {
}
for (ClassElementX cls in newClasses) {
// TODO(ahe): Set up superclasses.
if (cls.isObject) continue;
jsAst.Node classAccess = namer.elementAccess(cls);
jsAst.Node superAccess = namer.elementAccess(cls.superclass);
updates.add(
js.statement(
r'self.$dart_unsafe_eval.inheritFrom(#, #)',
[classAccess, superAccess]));
}
for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) {
@@ -482,6 +482,60 @@ main() {
""",
const <String>['a', 'b', 'c']),
],
// Test that a newly instantiated class is handled.
const <ProgramResult>[
const ProgramResult(
r"""
class A {
get name => 'A.m';
m() {
print('Called $name');
}
}
class B extends A {
get name => 'B.m';
}
var instance;
main() {
if (instance == null) {
instance = new A();
// } else {
// instance = new B();
}
instance.m();
}
""",
const <String>['Called A.m']),
const ProgramResult(
r"""
class A {
get name => 'A.m';
m() {
print('Called $name');
}
}
class B extends A {
get name => 'B.m';
}
var instance;
main() {
if (instance == null) {
instance = new A();
} else {
instance = new B();
}
instance.m();
}
""",
const <String>['Called B.m']),
],
];
void main() {