1
0
forked from M-Labs/nac3

string_store: update embedding map after compilation

This commit is contained in:
occheung 2024-12-03 16:45:46 +08:00
parent ae09a0d444
commit 964945d244
2 changed files with 16 additions and 5 deletions

View File

@ -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::<Vec<_>>();
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)
}

View File

@ -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<i32> {
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
}