cozodb / cozo

A transactional, relational-graph-vector database that uses Datalog for query. The hippocampus for AI!
https://cozodb.org
Mozilla Public License 2.0
3.37k stars 102 forks source link

Unconditional use of optional `rayon` dependency #272

Open NinoScript opened 3 months ago

NinoScript commented 3 months ago

There's code that unconditionally uses rayon even though it is an optional dependency. This makes me unable to build cozo-lib-python, as it fails with this error message:

error[E0599]: no method named `par_iter` found for reference `&BTreeMap<MagicSymbol, CompiledRuleSet>` in the current scope
   --> cozo-core/src/query/eval.rs:200:26
    |
199 |                       let execs = prog
    |  _________________________________-
200 | |                         .par_iter()
    | |_________________________-^^^^^^^^
    |
NinoScript commented 3 months ago

One possible solution would be to use the rayon feature of cozo-core in the cozo-lib-python crate:

[dependencies]
- cozo = { version = "0.7.6", path = "../cozo-core", default-features = false }
+ cozo = { version = "0.7.6", path = "../cozo-core", features = ["rayon"] }

(maybe it affects other crates too, I haven't checked)


The code that uses rayon is already conditional, but it is testing for not(wasm32) instead of rayon itself. So, another possible solution would be to change these to check for rayon directly:

- #[cfg(not(target_arch = "wasm32"))]
+ #[cfg(rayon)]
use rayon::prelude::*;
-               #[cfg(not(target_arch = "wasm32"))]
+               #[cfg(rayon)]
                { /* ... */
                    let execs = prog
                        .par_iter()

(assuming there's no other reason for those target_arch checks)


Let me know you're ok with any of these solutions and I'll contribute with a PR