Skip to content

Commit 4009375

Browse files
committed
Haplotype should be thread-safe again
1 parent eac51e2 commit 4009375

File tree

6 files changed

+190
-28
lines changed

6 files changed

+190
-28
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
- Added epistatic interactions
99
- Added preliminary cached fitness evaluation for recombinants
1010
- Huge performance improvements when collecting all mutations
11+
- Tree will now merge internal nodes when possible
12+
- Methods that access data have to be annotated with `#[require_deferred_drop]`
1113

1214
## 0.3.0 --- Mixed Performance (May 06, 2024)
1315

Cargo.lock

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ opt-level = 3
2121
codegen-units = 1
2222

2323
[workspace]
24+
members = ["macros"]
2425

2526
[dependencies]
2627
block-id = "0.1.2"
@@ -44,6 +45,7 @@ seq_io = "0.3.1"
4445
simple-logging = "2.0.2"
4546
anyhow = "1.0"
4647
rayon = { version = "1.7.0", optional = true }
48+
macros = { path = "macros" }
4749

4850
[build-dependencies]
4951
clap = { version = "4.3.11", features = ["derive"] }

macros/Cargo.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[package]
2+
name = "macros"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[lib]
7+
proc-macro = true
8+
9+
[dependencies]
10+
proc-macro2 = "1.0"
11+
quote = "1.0"
12+
syn = { version = "1.0", features = ["full"] }

macros/src/lib.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//! # require_deferred_drop
2+
//!
3+
//! This crate provides a procedural macro to require deferred drop for a type that implements
4+
//! `DeferredDrop`.
5+
6+
extern crate proc_macro;
7+
8+
use proc_macro::TokenStream;
9+
use quote::quote;
10+
use syn::{parse_macro_input, ItemFn};
11+
12+
#[proc_macro_attribute]
13+
pub fn require_deferred_drop(_attr: TokenStream, item: TokenStream) -> TokenStream {
14+
// Parse the input tokens into a syntax tree
15+
let input_fn = parse_macro_input!(item as ItemFn);
16+
17+
// Extract parts of the function
18+
let attrs = input_fn.attrs;
19+
let vis = input_fn.vis;
20+
let sig = input_fn.sig;
21+
let block = input_fn.block;
22+
23+
// Generate the new function body
24+
let expanded = quote! {
25+
#(#attrs)*
26+
#vis #sig {
27+
self.require_deferred_drop();
28+
29+
let __require_deferred_drop_result = (|| #block )();
30+
31+
match self.inquire_deferred_drop() {
32+
Ok(Some(haplotype_ref)) => {
33+
drop(haplotype_ref);
34+
},
35+
Ok(None) => {},
36+
Err(e) => {
37+
// Handle or propagate the error as needed
38+
// For example, you can return Err(e);
39+
},
40+
}
41+
42+
__require_deferred_drop_result
43+
}
44+
};
45+
46+
// Return the generated code as a TokenStream
47+
TokenStream::from(expanded)
48+
}

0 commit comments

Comments
 (0)