diff --git a/nac3artiq/src/lib.rs b/nac3artiq/src/lib.rs index f9cf7aa93..a9d8fa1d3 100644 --- a/nac3artiq/src/lib.rs +++ b/nac3artiq/src/lib.rs @@ -577,7 +577,7 @@ impl Nac3 { field_to_val: RwLock::default(), name_to_pyid, module: module.to_object(py), - helper, + helper: helper.clone(), string_store: self.string_store.clone(), exception_ids: self.exception_ids.clone(), deferred_eval_store: self.deferred_eval_store.clone(), @@ -822,6 +822,20 @@ impl Nac3 { panic!("Failed to run optimization for module `main`: {}", err.to_string()); } + Python::with_gil(|py| { + let string_store = self.string_store.read(); + let mut string_store_vec = string_store.iter().collect::>(); + string_store_vec.sort_by(|(_s1, key1), (_s2, key2)| key1.cmp(key2)); + for (s, key) in string_store_vec { + let embed_key: i32 = helper.store_str.call1(py, (s,)).unwrap().extract(py).unwrap(); + assert_eq!( + embed_key, *key, + "string {s} is out of sync between embedding map (key={embed_key}) and \ + the internal string store (key={key})" + ); + } + }); + link_fn(&main) } diff --git a/nac3artiq/src/symbol_resolver.rs b/nac3artiq/src/symbol_resolver.rs index 9e29acf83..fa57755dc 100644 --- a/nac3artiq/src/symbol_resolver.rs +++ b/nac3artiq/src/symbol_resolver.rs @@ -1536,10 +1536,7 @@ impl SymbolResolver for Resolver { if let Some(id) = string_store.get(s) { *id } else { - let id = Python::with_gil(|py| -> PyResult { - self.0.helper.store_str.call1(py, (s,))?.extract(py) - }) - .unwrap(); + let id = string_store.len() as i32; string_store.insert(s.into(), id); id }