From e24f935f489a32439ab811cedf58bce2f73246ea Mon Sep 17 00:00:00 2001 From: Thomas Lively Date: Wed, 12 Nov 2025 14:54:25 -0800 Subject: [PATCH] [Custom Descriptors] Exact imports require CD Validate that exact function imports require custom descriptors. An alternative approach (that we may switch to in the future if necessary) would be to always allow exact imports, but then strip them out in the binary writer when custom descriptors are not enabled. For now take the more explicit what-you-see-is-what-you-get approach. --- src/wasm/wasm-validator.cpp | 7 ++++++- test/lit/validation/exact-import.wast | 9 +++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 test/lit/validation/exact-import.wast diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp index 94d3b137699..0a1df50dbb9 100644 --- a/src/wasm/wasm-validator.cpp +++ b/src/wasm/wasm-validator.cpp @@ -4159,7 +4159,12 @@ void FunctionValidator::visitFunction(Function* curr) { curr->name, "all used types should be allowed"); - if (!curr->imported()) { + if (curr->imported()) { + shouldBeTrue( + curr->type.isInexact() || getModule()->features.hasCustomDescriptors(), + curr->name, + "exact imports require custom descriptors [--enable-custom-descriptors]"); + } else { shouldBeTrue( curr->type.isExact(), curr->name, "defined function should be exact"); } diff --git a/test/lit/validation/exact-import.wast b/test/lit/validation/exact-import.wast new file mode 100644 index 00000000000..318d397cfcb --- /dev/null +++ b/test/lit/validation/exact-import.wast @@ -0,0 +1,9 @@ +;; Test that exact imports require custom descriptors. + +;; RUN: not wasm-opt %s -all --disable-custom-descriptors 2>&1 | filecheck %s + +;; CHECK: exact imports require custom descriptors [--enable-custom-descriptors] + +(module + (import "" "" (func $f (exact))) +)