summaryrefslogtreecommitdiff
path: root/chromium/v8/src/wasm/wasm-subtyping.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/v8/src/wasm/wasm-subtyping.cc')
-rw-r--r--chromium/v8/src/wasm/wasm-subtyping.cc71
1 files changed, 62 insertions, 9 deletions
diff --git a/chromium/v8/src/wasm/wasm-subtyping.cc b/chromium/v8/src/wasm/wasm-subtyping.cc
index b0e8105a605..d2b7e9fe31d 100644
--- a/chromium/v8/src/wasm/wasm-subtyping.cc
+++ b/chromium/v8/src/wasm/wasm-subtyping.cc
@@ -91,6 +91,26 @@ class TypeJudgementCache {
type_equivalence_cache_.erase(
std::make_tuple(type1, type2, module1, module2));
}
+ void delete_module(const WasmModule* module) {
+ for (auto iterator = type_equivalence_cache_.begin();
+ iterator != type_equivalence_cache_.end();) {
+ if (std::get<2>(*iterator) == module ||
+ std::get<3>(*iterator) == module) {
+ iterator = type_equivalence_cache_.erase(iterator);
+ } else {
+ iterator++;
+ }
+ }
+ for (auto iterator = subtyping_cache_.begin();
+ iterator != subtyping_cache_.end();) {
+ if (std::get<2>(*iterator) == module ||
+ std::get<3>(*iterator) == module) {
+ iterator = subtyping_cache_.erase(iterator);
+ } else {
+ iterator++;
+ }
+ }
+ }
private:
Zone zone_;
@@ -258,14 +278,46 @@ bool ArrayIsSubtypeOf(uint32_t subtype_index, uint32_t supertype_index,
}
}
-// TODO(7748): Expand this with function subtyping when it is introduced.
bool FunctionIsSubtypeOf(uint32_t subtype_index, uint32_t supertype_index,
const WasmModule* sub_module,
const WasmModule* super_module) {
- return FunctionEquivalentIndices(subtype_index, supertype_index, sub_module,
- super_module);
-}
+ if (!FLAG_experimental_wasm_gc) {
+ return FunctionEquivalentIndices(subtype_index, supertype_index, sub_module,
+ super_module);
+ }
+ const FunctionSig* sub_func = sub_module->types[subtype_index].function_sig;
+ const FunctionSig* super_func =
+ super_module->types[supertype_index].function_sig;
+
+ if (sub_func->parameter_count() != super_func->parameter_count() ||
+ sub_func->return_count() != super_func->return_count()) {
+ return false;
+ }
+
+ TypeJudgementCache::instance()->cache_subtype(subtype_index, supertype_index,
+ sub_module, super_module);
+
+ for (uint32_t i = 0; i < sub_func->parameter_count(); i++) {
+ // Contravariance for params.
+ if (!IsSubtypeOf(super_func->parameters()[i], sub_func->parameters()[i],
+ super_module, sub_module)) {
+ TypeJudgementCache::instance()->uncache_subtype(
+ subtype_index, supertype_index, sub_module, super_module);
+ return false;
+ }
+ }
+ for (uint32_t i = 0; i < sub_func->return_count(); i++) {
+ // Covariance for returns.
+ if (!IsSubtypeOf(sub_func->returns()[i], super_func->returns()[i],
+ sub_module, super_module)) {
+ TypeJudgementCache::instance()->uncache_subtype(
+ subtype_index, supertype_index, sub_module, super_module);
+ return false;
+ }
+ }
+ return true;
+}
} // namespace
V8_NOINLINE V8_EXPORT_PRIVATE bool IsSubtypeOfImpl(
@@ -403,11 +455,12 @@ V8_NOINLINE bool EquivalentTypes(ValueType type1, ValueType type2,
module2);
}
-ValueType CommonSubtype(ValueType a, ValueType b, const WasmModule* module) {
- if (a == b) return a;
- if (IsSubtypeOf(a, b, module)) return a;
- if (IsSubtypeOf(b, a, module)) return b;
- return kWasmBottom;
+void DeleteCachedTypeJudgementsForModule(const WasmModule* module) {
+ // Accessing the caches for subtyping and equivalence from multiple background
+ // threads is protected by a lock.
+ base::RecursiveMutexGuard type_cache_access(
+ TypeJudgementCache::instance()->type_cache_mutex());
+ TypeJudgementCache::instance()->delete_module(module);
}
} // namespace wasm