From 5edd1b5ab73868e60d8cdb28fbf6a133065733cb Mon Sep 17 00:00:00 2001 From: losfair Date: Thu, 12 Mar 2020 02:58:36 +0800 Subject: [PATCH 1/2] Enable `DynamicFunc` for closures with environment. --- lib/runtime-core/src/typed_func.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lib/runtime-core/src/typed_func.rs b/lib/runtime-core/src/typed_func.rs index 0b29d54ea..b1d1399e9 100644 --- a/lib/runtime-core/src/typed_func.rs +++ b/lib/runtime-core/src/typed_func.rs @@ -349,11 +349,6 @@ impl<'a> DynamicFunc<'a> { } } - // Disable "fat" closures for possible future changes. - if mem::size_of::() != 0 { - unimplemented!("DynamicFunc with captured environment is not yet supported"); - } - let mut builder = TrampolineBufferBuilder::new(); let ctx: Box = Box::new(PolymorphicContext { arg_types: signature.params().to_vec(), From 6c7f49a223bc750eef91abf46eee5791785febe5 Mon Sep 17 00:00:00 2001 From: losfair Date: Thu, 12 Mar 2020 03:14:57 +0800 Subject: [PATCH 2/2] Put fat `DynamicFunc`s behind a feature flag. --- lib/runtime-core/Cargo.toml | 2 ++ lib/runtime-core/src/typed_func.rs | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/lib/runtime-core/Cargo.toml b/lib/runtime-core/Cargo.toml index 03904ed7c..5242a2bc1 100644 --- a/lib/runtime-core/Cargo.toml +++ b/lib/runtime-core/Cargo.toml @@ -59,3 +59,5 @@ generate-debug-information = ["wasm-debug"] # don't export symbols related to the GDB JIT interafce, LLVM or some other native # code will be providing them generate-debug-information-no-export-symbols = [] +# enable DynamicFunc's for closures with captured environment. +dynamicfunc-fat-closures = [] diff --git a/lib/runtime-core/src/typed_func.rs b/lib/runtime-core/src/typed_func.rs index b1d1399e9..61def512d 100644 --- a/lib/runtime-core/src/typed_func.rs +++ b/lib/runtime-core/src/typed_func.rs @@ -349,6 +349,10 @@ impl<'a> DynamicFunc<'a> { } } + if cfg!(not(feature = "dynamicfunc-fat-closures")) && mem::size_of::() != 0 { + unimplemented!("DynamicFunc with captured environment is disabled"); + } + let mut builder = TrampolineBufferBuilder::new(); let ctx: Box = Box::new(PolymorphicContext { arg_types: signature.params().to_vec(),