From 6230387ee8831ca2d5e584547c74fab72b794ed8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20=C5=A0pa=C4=8Dek?= Date: Wed, 1 Oct 2025 17:05:30 +0200 Subject: [PATCH] cranelift-jit: impl Send for JITModule Send was implemented for JITModule in #8718, but this was (likely intentionally) broken in #10512. This commit implements Send again and adds a test to guard against any future regressions. --- cranelift/jit/src/backend.rs | 17 ++++++++++++++--- cranelift/jit/src/memory/arena.rs | 8 ++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/cranelift/jit/src/backend.rs b/cranelift/jit/src/backend.rs index 18aaf44f5b4e..e320ba75f611 100644 --- a/cranelift/jit/src/backend.rs +++ b/cranelift/jit/src/backend.rs @@ -31,7 +31,7 @@ pub struct JITBuilder { symbols: HashMap>, lookup_symbols: Vec Option<*const u8> + Send>>, libcall_names: Box String + Send + Sync>, - memory: Option>, + memory: Option>, } impl JITBuilder { @@ -150,7 +150,7 @@ impl JITBuilder { /// Set the memory provider for the module. /// /// If unset, defaults to [`SystemMemoryProvider`]. - pub fn memory_provider(&mut self, provider: Box) -> &mut Self { + pub fn memory_provider(&mut self, provider: Box) -> &mut Self { self.memory = Some(provider); self } @@ -172,7 +172,7 @@ pub struct JITModule { symbols: RefCell>>, lookup_symbols: Vec Option<*const u8> + Send>>, libcall_names: Box String + Send + Sync>, - memory: Box, + memory: Box, declarations: ModuleDeclarations, compiled_functions: SecondaryMap>, compiled_data_objects: SecondaryMap>, @@ -762,3 +762,14 @@ fn use_bti(isa_flags: &Vec) -> bool { .find(|&f| f.name == "use_bti") .map_or(false, |f| f.as_bool().unwrap_or(false)) } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_jit_module_is_send() { + fn assert_is_send() {} + assert_is_send::(); + } +} diff --git a/cranelift/jit/src/memory/arena.rs b/cranelift/jit/src/memory/arena.rs index 5a598fcfccb9..1afb93f7cf16 100644 --- a/cranelift/jit/src/memory/arena.rs +++ b/cranelift/jit/src/memory/arena.rs @@ -101,6 +101,8 @@ pub struct ArenaMemoryProvider { segments: Vec, } +unsafe impl Send for ArenaMemoryProvider {} + impl ArenaMemoryProvider { /// Create a new memory region with the given size. pub fn new_with_size(reserve_size: usize) -> Result { @@ -281,4 +283,10 @@ mod tests { let _ = arena.allocate_readwrite(900_000, 1).unwrap(); let _ = arena.allocate_readwrite(200_000, 1).unwrap_err(); } + + #[test] + fn test_is_send() { + fn assert_is_send() {} + assert_is_send::(); + } }