Use native types for inlined native fields.

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

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@22000 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
sra@google.com
2013-04-25 06:38:40 +00:00
parent 5fe5359cfa
commit e289575ce0
2 changed files with 21 additions and 18 deletions
@@ -690,8 +690,9 @@ class SsaConstantFolder extends HBaseVisitor implements OptimizationPhase {
field, receiver, isAssignable: isAssignable);
if (field.getEnclosingClass().isNative()) {
result.instructionType =
new HType.subtype(field.computeType(compiler), compiler);
result.instructionType = new HType.fromNativeBehavior(
native.NativeBehavior.ofFieldLoad(field, compiler),
compiler);
} else {
HType type = new HType.inferredTypeForElement(field, compiler);
if (type.isUnknown()) {
@@ -121,36 +121,38 @@ abstract class HType {
compiler);
}
factory HType.fromNativeBehavior(native.NativeBehavior nativeBehavior,
Compiler compiler) {
if (nativeBehavior.typesReturned.isEmpty) return HType.UNKNOWN;
HType result = nativeBehavior.typesReturned
.map((type) => fromNativeType(type, compiler))
.reduce((t1, t2) => t1.union(t2, compiler));
assert(!result.isConflicting());
return result;
}
// [type] is either an instance of [DartType] or special objects
// like [native.SpecialType.JsObject], or [native.SpecialType.JsArray].
factory HType.fromNativeType(type, Compiler compiler) {
static HType fromNativeType(type, Compiler compiler) {
if (type == native.SpecialType.JsObject) {
return new HType.nonNullExact(
compiler.objectClass.computeType(compiler), compiler);
} else if (type == native.SpecialType.JsArray) {
return HType.READABLE_ARRAY;
} else if (type.isVoid) {
return HType.UNKNOWN; // Maybe use HType.NULL.
return HType.NULL;
} else if (type.element == compiler.nullClass) {
return HType.NULL;
} else {
} else if (compiler.world.hasAnySubtype(type.element)) {
return new HType.nonNullSubtype(type, compiler);
} else if (compiler.world.hasAnySubclass(type.element)) {
return new HType.nonNullSubclass(type, compiler);
} else {
return new HType.nonNullExact(type, compiler);
}
}
factory HType.fromNativeBehavior(native.NativeBehavior nativeBehavior,
Compiler compiler) {
if (nativeBehavior.typesReturned.isEmpty) return HType.UNKNOWN;
HType ssaType = HType.CONFLICTING;
for (final type in nativeBehavior.typesReturned) {
ssaType = ssaType.union(
new HType.fromNativeType(type, compiler), compiler);
}
assert(!ssaType.isConflicting());
return ssaType;
}
static const HType CONFLICTING = const HConflictingType();
static const HType UNKNOWN = const HUnknownType();
static const HType NON_NULL = const HNonNullType();