diff --git a/nac3artiq/Cargo.toml b/nac3artiq/Cargo.toml index 10d7b0b3f..e0803319a 100644 --- a/nac3artiq/Cargo.toml +++ b/nac3artiq/Cargo.toml @@ -24,3 +24,4 @@ features = ["llvm14-0", "target-x86", "target-arm", "target-riscv", "no-libffi-l [features] init-llvm-profile = [] +no-escape-analysis = ["nac3core/no-escape-analysis"] diff --git a/nac3core/Cargo.toml b/nac3core/Cargo.toml index 724e0c8cc..a25763bd2 100644 --- a/nac3core/Cargo.toml +++ b/nac3core/Cargo.toml @@ -4,6 +4,9 @@ version = "0.1.0" authors = ["M-Labs"] edition = "2021" +[features] +no-escape-analysis = [] + [dependencies] itertools = "0.13" crossbeam = "0.8" diff --git a/nac3core/src/typecheck/function_check.rs b/nac3core/src/typecheck/function_check.rs index b37909942..be2d1dce6 100644 --- a/nac3core/src/typecheck/function_check.rs +++ b/nac3core/src/typecheck/function_check.rs @@ -212,19 +212,23 @@ impl<'a> Inferencer<'a> { /// This is a workaround preventing the caller from using a variable `alloca`-ed in the body, which /// is freed when the function returns. fn check_return_value_ty(&mut self, ret_ty: Type) -> bool { - match &*self.unifier.get_ty_immutable(ret_ty) { - TypeEnum::TObj { .. } => [ - self.primitives.int32, - self.primitives.int64, - self.primitives.uint32, - self.primitives.uint64, - self.primitives.float, - self.primitives.bool, - ] - .iter() - .any(|allowed_ty| self.unifier.unioned(ret_ty, *allowed_ty)), - TypeEnum::TTuple { ty, .. } => ty.iter().all(|t| self.check_return_value_ty(*t)), - _ => false, + if cfg!(feature = "no-escape-analysis") { + true + } else { + match &*self.unifier.get_ty_immutable(ret_ty) { + TypeEnum::TObj { .. } => [ + self.primitives.int32, + self.primitives.int64, + self.primitives.uint32, + self.primitives.uint64, + self.primitives.float, + self.primitives.bool, + ] + .iter() + .any(|allowed_ty| self.unifier.unioned(ret_ty, *allowed_ty)), + TypeEnum::TTuple { ty, .. } => ty.iter().all(|t| self.check_return_value_ty(*t)), + _ => false, + } } } diff --git a/nac3standalone/Cargo.toml b/nac3standalone/Cargo.toml index a55a26b94..4d43a7639 100644 --- a/nac3standalone/Cargo.toml +++ b/nac3standalone/Cargo.toml @@ -4,6 +4,9 @@ version = "0.1.0" authors = ["M-Labs"] edition = "2021" +[features] +no-escape-analysis = ["nac3core/no-escape-analysis"] + [dependencies] parking_lot = "0.12" nac3parser = { path = "../nac3parser" }