Skip to content

Commit fd423ff

Browse files
Upgrade rust dependencies
1 parent 18f4a14 commit fd423ff

File tree

6 files changed

+92
-75
lines changed

6 files changed

+92
-75
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ name = "egglog"
1010
crate-type = ["cdylib"]
1111

1212
[dependencies]
13-
pyo3 = { version = "0.22.6", features = ["extension-module"] }
13+
pyo3 = { version = "0.23.0", features = ["extension-module"] }
1414

1515
egglog = { git = "https://github.com/saulshanabrook/egg-smol", rev = "889ca7635368d7e382e16a93b2883aba82f1078f" }
1616
egglog-experimental = { git = "https://github.com/egraphs-good/egglog-experimental", rev = "8a1b3d6ad2723a8438f51f05027161e51f37917c" }
1717
egraph-serialize = { version = "0.2.0", features = ["serde", "graphviz"] }
18-
serde_json = "1.0.139"
19-
pyo3-log = "0.11.0"
20-
log = "0.4.25"
18+
serde_json = "1.0.140"
19+
pyo3-log = "0.12.1"
20+
log = "0.4.26"
2121
lalrpop-util = { version = "0.22", features = ["lexer"] }
2222
ordered-float = "3.7.0"
23-
uuid = { version = "1.13.2", features = ["v4"] }
23+
uuid = { version = "1.16.0", features = ["v4"] }
2424

2525
# Use unreleased version of egglog in experimental
2626
[patch.'https://github.com/egraphs-good/egglog']

rust-toolchain.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[toolchain]
2-
channel = "1.79.0"
2+
channel = "1.85.0"

src/conversions.rs

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::utils::*;
44
use egglog::ast::Symbol;
55
use ordered_float::OrderedFloat;
66
use pyo3::prelude::*;
7-
use pyo3::types::PyDeltaAccess;
7+
use pyo3::types::{PyDelta, PyDeltaAccess};
88
use std::collections::HashMap;
99
use std::sync::Arc;
1010

@@ -460,9 +460,13 @@ impl FromPyObject<'_> for Box<Schedule> {
460460
}
461461
}
462462

463-
impl IntoPy<PyObject> for Box<Schedule> {
464-
fn into_py(self, py: Python<'_>) -> PyObject {
465-
(*self).into_py(py)
463+
impl<'py> IntoPyObject<'py> for Box<Schedule> {
464+
type Target = PyAny; // the Python type
465+
type Output = Bound<'py, Self::Target>; // in most cases this will be `Bound`
466+
type Error = pyo3::PyErr;
467+
468+
fn into_pyobject(self, py: Python<'py>) -> Result<Self::Output, Self::Error> {
469+
Ok((*self).into_pyobject(py)?.as_any().clone())
466470
}
467471
}
468472

@@ -472,9 +476,13 @@ impl FromPyObject<'_> for Box<Command> {
472476
}
473477
}
474478

475-
impl IntoPy<PyObject> for Box<Command> {
476-
fn into_py(self, py: Python<'_>) -> PyObject {
477-
(*self).into_py(py)
479+
impl<'py> IntoPyObject<'py> for Box<Command> {
480+
type Target = PyAny; // the Python type
481+
type Output = Bound<'py, Self::Target>; // in most cases this will be `Bound`
482+
type Error = pyo3::PyErr;
483+
484+
fn into_pyobject(self, py: Python<'py>) -> Result<Self::Output, Self::Error> {
485+
Ok((*self).into_pyobject(py)?.as_any().clone())
478486
}
479487
}
480488

@@ -495,9 +503,13 @@ impl FromPyObject<'_> for WrappedOrderedF64 {
495503
}
496504
}
497505

498-
impl IntoPy<PyObject> for WrappedOrderedF64 {
499-
fn into_py(self, py: Python<'_>) -> PyObject {
500-
self.0.into_inner().into_py(py)
506+
impl<'py> IntoPyObject<'py> for WrappedOrderedF64 {
507+
type Target = PyAny; // the Python type
508+
type Output = Bound<'py, Self::Target>; // in most cases this will be `Bound`
509+
type Error = pyo3::PyErr;
510+
511+
fn into_pyobject(self, py: Python<'py>) -> Result<Self::Output, Self::Error> {
512+
Ok((self.0.into_inner()).into_pyobject(py)?.as_any().clone())
501513
}
502514
}
503515

@@ -522,20 +534,22 @@ impl FromPyObject<'_> for WrappedDuration {
522534
)))
523535
}
524536
}
537+
impl<'py> IntoPyObject<'py> for WrappedDuration {
538+
type Target = PyDelta; // the Python type
539+
type Output = Bound<'py, Self::Target>; // in most cases this will be `Bound`
540+
type Error = pyo3::PyErr;
525541

526-
impl IntoPy<PyObject> for WrappedDuration {
527-
fn into_py(self, py: Python<'_>) -> PyObject {
542+
fn into_pyobject(self, py: Python<'py>) -> Result<Self::Output, Self::Error> {
528543
let d = self.0;
529-
pyo3::types::PyDelta::new_bound(
544+
Ok(pyo3::types::PyDelta::new(
530545
py,
531546
0,
532547
0,
533548
d.as_millis()
534549
.try_into()
535550
.expect("Failed to convert miliseconds to int32 when converting duration"),
536551
true,
537-
)
538-
.expect("Failed to contruct timedelta")
539-
.into()
552+
)?
553+
.clone())
540554
}
541555
}

src/py_object_sort.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use egglog::{
1010
ArcSort, EGraph, PrimitiveLike, Term, TermDag, TypeInfo, Value,
1111
};
1212
use pyo3::{
13-
ffi, intern, prelude::*, types::PyDict, AsPyPointer, IntoPy, PyAny, PyErr, PyObject, PyResult,
13+
ffi, intern, prelude::*, types::PyDict, AsPyPointer, PyAny, PyErr, PyObject, PyResult,
1414
PyTraverseError, PyVisit, Python,
1515
};
1616

@@ -137,6 +137,7 @@ impl PyObjectSort {
137137
}
138138

139139
/// Implement wrapper struct so can implement foreign sort on it
140+
#[derive(IntoPyObject, IntoPyObjectRef)]
140141
pub struct MyPyObject(pub PyObject);
141142

142143
impl FromSort for MyPyObject {
@@ -147,12 +148,6 @@ impl FromSort for MyPyObject {
147148
}
148149
}
149150

150-
impl IntoPy<PyObject> for MyPyObject {
151-
fn into_py(self, _py: Python<'_>) -> PyObject {
152-
self.0
153-
}
154-
}
155-
156151
#[pyclass(name = "PyObjectSort")]
157152
#[derive(Debug, Clone)]
158153
pub struct ArcPyObjectSort(
@@ -355,9 +350,13 @@ impl PrimitiveLike for Eval {
355350
let globals = globals.downcast_bound::<PyDict>(py).unwrap();
356351
let locals = self.py_object.load(py, values[2]);
357352
let locals = locals.downcast_bound::<PyDict>(py).unwrap();
358-
py.eval_bound(code.into(), Some(globals), Some(locals))
359-
.unwrap()
360-
.into()
353+
py.eval(
354+
CString::new(code.to_string()).unwrap().as_c_str(),
355+
Some(globals),
356+
Some(locals),
357+
)
358+
.unwrap()
359+
.into()
361360
});
362361
Some(self.py_object.store(res_obj))
363362
}
@@ -444,7 +443,7 @@ impl PrimitiveLike for Dict {
444443
_egraph: Option<&mut EGraph>,
445444
) -> Option<Value> {
446445
let dict: PyObject = Python::with_gil(|py| {
447-
let dict = PyDict::new_bound(py);
446+
let dict = PyDict::new(py);
448447
// Update the dict with the key-value pairs
449448
for i in values.chunks_exact(2) {
450449
let key = self.py_object.load(py, i[0]);
@@ -591,7 +590,8 @@ impl PrimitiveLike for FromString {
591590
_egraph: Option<&mut EGraph>,
592591
) -> Option<Value> {
593592
let str = Symbol::load(self.string.as_ref(), &values[0]).to_string();
594-
let obj: PyObject = Python::with_gil(|py| str.into_py(py));
593+
let obj: PyObject =
594+
Python::with_gil(|py| str.into_pyobject(py).unwrap().as_any().clone().unbind());
595595
Some(self.py_object.store(obj))
596596
}
597597
}
@@ -624,7 +624,8 @@ impl PrimitiveLike for FromInt {
624624
_egraph: Option<&mut EGraph>,
625625
) -> Option<Value> {
626626
let int = i64::load(self.int.as_ref(), &values[0]);
627-
let obj: PyObject = Python::with_gil(|py| int.into_py(py));
627+
let obj: PyObject =
628+
Python::with_gil(|py| int.into_pyobject(py).unwrap().as_any().clone().unbind());
628629
Some(self.py_object.store(obj))
629630
}
630631
}

src/utils.rs

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,14 @@ pub fn data_repr<T: pyo3::PyClass>(
77
slf: PyRef<T>,
88
field_names: Vec<&str>,
99
) -> PyResult<String> {
10-
let obj = slf.into_py(py);
11-
let class_name: String = obj
12-
.getattr(py, "__class__")?
13-
.getattr(py, "__name__")?
14-
.extract(py)?;
10+
let binding = slf.into_pyobject(py)?;
11+
let obj = binding.as_any();
12+
let class_name: String = obj.getattr("__class__")?.getattr("__name__")?.extract()?;
1513
let field_strings: PyResult<Vec<String>> = field_names
1614
.iter()
1715
.map(|name| {
18-
obj.getattr(py, *name)
19-
.and_then(|x| x.call_method_bound(py, "__repr__", (), None)?.extract(py))
16+
obj.getattr(*name)
17+
.and_then(|x| x.call_method("__repr__", (), None)?.extract())
2018
})
2119
.collect();
2220
Ok(format!("{}({})", class_name, field_strings?.join(", ")))
@@ -64,11 +62,11 @@ macro_rules! convert_enums {
6462
fn __str__(&self) -> String {
6563
format!($str, <$from_type>::from(self.clone()))
6664
}
67-
fn __richcmp__(&self, other: &Self, op: pyo3::basic::CompareOp, py: Python<'_>) -> PyObject {
65+
fn __richcmp__(&self, other: &Self, op: pyo3::basic::CompareOp, py: Python<'_>) -> PyResult<PyObject> {
6866
match op {
69-
pyo3::basic::CompareOp::Eq => (self == other).into_py(py),
70-
pyo3::basic::CompareOp::Ne => (self != other).into_py(py),
71-
_ => py.NotImplemented(),
67+
pyo3::basic::CompareOp::Eq => Ok((self == other).into_pyobject(py)?.as_any().clone().unbind()),
68+
pyo3::basic::CompareOp::Ne => Ok((self != other).into_pyobject(py)?.as_any().clone().unbind()),
69+
_ => Ok(py.NotImplemented()),
7270
}
7371
}
7472
}
@@ -91,13 +89,17 @@ macro_rules! convert_enums {
9189
$variant($variant),
9290
)*
9391
}
94-
impl IntoPy<PyObject> for $to_type {
95-
fn into_py(self, py: Python<'_>) -> PyObject {
96-
match self {
92+
impl<'py> IntoPyObject<'py> for $to_type {
93+
type Target = PyAny; // the Python type
94+
type Output = Bound<'py, Self::Target>; // in most cases this will be `Bound`
95+
type Error = pyo3::PyErr;
96+
97+
fn into_pyobject(self, py: Python<'py>) -> Result<Bound<'py, Self::Target>, Self::Error> {
98+
Ok(match self {
9799
$(
98-
$to_type::$variant(v) => v.into_py(py),
100+
$to_type::$variant(v) => v.into_pyobject(py)?.as_any().clone(),
99101
)*
100-
}
102+
})
101103
}
102104
}
103105
impl From<$to_type> for $from_type {
@@ -203,12 +205,12 @@ macro_rules! convert_struct {
203205
fn __str__(&self) -> String {
204206
format!($str, <$from_type>::from(self.clone()))
205207
}
206-
fn __richcmp__(&self, other: &Self, op: pyo3::basic::CompareOp, py: Python<'_>) -> PyObject {
207-
match op {
208-
pyo3::basic::CompareOp::Eq => (self == other).into_py(py),
209-
pyo3::basic::CompareOp::Ne => (self != other).into_py(py),
208+
fn __richcmp__(&self, other: &Self, op: pyo3::basic::CompareOp, py: Python<'_>) -> PyResult<PyObject> {
209+
Ok(match op {
210+
pyo3::basic::CompareOp::Eq => (self == other).into_pyobject(py)?.as_any().clone().unbind(),
211+
pyo3::basic::CompareOp::Ne => (self != other).into_pyobject(py)?.as_any().clone().unbind(),
210212
_ => py.NotImplemented(),
211-
}
213+
})
212214
}
213215
}
214216

0 commit comments

Comments
 (0)