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

Unified Diff: runtime/vm/flow_graph_type_propagator.cc

Issue 2855173002: Revert "Void is not required to be `null` anymore." (Closed)
Patch Set: Created 3 years, 8 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
« no previous file with comments | « runtime/vm/flow_graph_compiler_x64.cc ('k') | runtime/vm/object.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/flow_graph_type_propagator.cc
diff --git a/runtime/vm/flow_graph_type_propagator.cc b/runtime/vm/flow_graph_type_propagator.cc
index be1366cdbf26d777d90435cf2861f4d09008583e..9617c03b3480e0c38da4ba21e4a48e71c1708757 100644
--- a/runtime/vm/flow_graph_type_propagator.cc
+++ b/runtime/vm/flow_graph_type_propagator.cc
@@ -597,7 +597,7 @@ intptr_t CompileType::ToNullableCid() {
} else if (type_->IsMalformed()) {
cid_ = kDynamicCid;
} else if (type_->IsVoidType()) {
- cid_ = kDynamicCid;
+ cid_ = kNullCid;
} else if (type_->IsFunctionType() || type_->IsDartFunctionType()) {
cid_ = kClosureCid;
} else if (type_->HasResolvedTypeClass()) {
@@ -684,7 +684,7 @@ bool CompileType::CanComputeIsInstanceOf(const AbstractType& type,
return false;
}
- if (type.IsDynamicType() || type.IsObjectType() || type.IsVoidType()) {
+ if (type.IsDynamicType() || type.IsObjectType()) {
*is_instance = true;
return true;
}
@@ -696,6 +696,11 @@ bool CompileType::CanComputeIsInstanceOf(const AbstractType& type,
// Consider the compile type of the value.
const AbstractType& compile_type = *ToAbstractType();
+ // The compile-type of a value should never be void. The result of a void
+ // function must always be null, which was checked to be null at the return
+ // statement inside the function.
+ ASSERT(!compile_type.IsVoidType());
+
if (compile_type.IsMalformedOrMalbounded()) {
return false;
}
@@ -710,6 +715,12 @@ bool CompileType::CanComputeIsInstanceOf(const AbstractType& type,
return true;
}
+ // A non-null value is not an instance of void.
+ if (type.IsVoidType()) {
+ *is_instance = IsNull();
+ return HasDecidableNullability();
+ }
+
// If the value can be null then we can't eliminate the
// check unless null is allowed.
if (is_nullable_ && !is_nullable) {
@@ -726,6 +737,11 @@ bool CompileType::IsMoreSpecificThan(const AbstractType& other) {
return false;
}
+ if (other.IsVoidType()) {
+ // The only value assignable to void is null.
+ return IsNull();
+ }
+
return ToAbstractType()->IsMoreSpecificThan(other, NULL, NULL, Heap::kOld);
}
@@ -927,6 +943,11 @@ CompileType AssertAssignableInstr::ComputeType() const {
return *value_type;
}
+ if (dst_type().IsVoidType()) {
+ // The only value assignable to void is null.
+ return CompileType::Null();
+ }
+
return CompileType::Create(value_type->ToCid(), dst_type());
}
@@ -1017,9 +1038,13 @@ CompileType StaticCallInstr::ComputeType() const {
}
if (Isolate::Current()->type_checks()) {
+ // Void functions are known to return null, which is checked at the return
+ // from the function.
const AbstractType& result_type =
AbstractType::ZoneHandle(function().result_type());
- return CompileType::FromAbstractType(result_type);
+ return CompileType::FromAbstractType(
+ result_type.IsVoidType() ? AbstractType::ZoneHandle(Type::NullType())
+ : result_type);
}
return CompileType::Dynamic();
« no previous file with comments | « runtime/vm/flow_graph_compiler_x64.cc ('k') | runtime/vm/object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698