|
1 | | -use std::{cmp::Ordering, sync::Arc}; |
| 1 | +use std::cmp::Ordering; |
2 | 2 |
|
3 | 3 | use pyo3::{exceptions::PyValueError, prelude::*}; |
4 | 4 |
|
5 | 5 | use crate::{conversions::Term, egraph::EGraph, egraph::Value, termdag::TermDag}; |
6 | 6 |
|
7 | 7 | #[derive(Debug)] |
8 | | -// Wrap in Arc so we can clone efficiently |
9 | | -// https://pyo3.rs/main/migration.html#pyclone-is-now-gated-behind-the-py-clone-feature |
10 | | -// We also have to store the result, since the cost model does not return errors |
| 8 | +// We have to store the result, since the cost model does not return errors |
11 | 9 | struct Cost(PyResult<Py<PyAny>>); |
12 | 10 |
|
13 | | -impl Clone for Cost { |
14 | | - fn clone(&self) -> Self { |
15 | | - Python::attach(|py| { |
16 | | - Cost(match &self.0 { |
17 | | - Ok(v) => Ok(v.clone_ref(py)), |
18 | | - Err(e) => Err(e.clone_ref(py)), |
19 | | - }) |
20 | | - }) |
21 | | - } |
22 | | -} |
23 | | - |
24 | 11 | impl Ord for Cost { |
25 | 12 | fn cmp(&self, other: &Self) -> Ordering { |
26 | 13 | // Always order errors as smallest cost so they are prefered |
@@ -53,6 +40,17 @@ impl PartialEq for Cost { |
53 | 40 |
|
54 | 41 | impl Eq for Cost {} |
55 | 42 |
|
| 43 | +impl Clone for Cost { |
| 44 | + fn clone(&self) -> Self { |
| 45 | + Python::attach(|py| { |
| 46 | + Cost(match &self.0 { |
| 47 | + Ok(v) => Ok(v.clone_ref(py)), |
| 48 | + Err(e) => Err(e.clone_ref(py)), |
| 49 | + }) |
| 50 | + }) |
| 51 | + } |
| 52 | +} |
| 53 | + |
56 | 54 | impl egglog::extract::Cost for Cost { |
57 | 55 | fn identity() -> Self { |
58 | 56 | panic!("Should never be called from Rust directly"); |
@@ -175,6 +173,7 @@ impl egglog::extract::CostModel<Cost> for CostModel { |
175 | 173 | } |
176 | 174 | } |
177 | 175 |
|
| 176 | +// TODO: Don't progress just return an error if there was an exception? |
178 | 177 |
|
179 | 178 | #[pyclass(unsendable)] |
180 | 179 | pub struct Extractor(egglog::extract::Extractor<Cost>); |
|
0 commit comments