Skip to content

Commit 638117e

Browse files
committed
Move hashcons to native base
1 parent 6d7e60f commit 638117e

File tree

2 files changed

+64
-18
lines changed

2 files changed

+64
-18
lines changed

claripy/ast/base.py

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -101,22 +101,22 @@ class Base(clarirs.Base, metaclass=type):
101101
"""
102102

103103
__slots__ = [
104-
"op",
105-
"args",
106-
"variables",
107-
"symbolic",
104+
# "op",
105+
# "args",
106+
# "variables",
107+
# "symbolic",
108108
"_hash",
109109
"_simplified",
110110
"_cached_encoded_name",
111111
"_cache_key",
112112
"_errored",
113113
"_eager_backends",
114-
"length",
114+
# "length",
115115
"_excavated",
116116
"_burrowed",
117117
"_uninitialized",
118118
"_uc_alloc_depth",
119-
"annotations",
119+
# "annotations",
120120
"simplifiable",
121121
"_uneliminatable_annotations",
122122
"_relocatable_annotations",
@@ -286,7 +286,15 @@ def __new__(cls, op, args, add_variables=None, hash=None, **kwargs): # pylint:d
286286
h = Base._calc_hash(op, a_args, kwargs) if hash is None else hash
287287
self = cache.get(h, None)
288288
if self is None:
289-
self = super().__new__(cls)
289+
self = super().__new__(
290+
cls,
291+
op,
292+
tuple(args),
293+
kwargs.get("length", None),
294+
frozenset(kwargs["variables"]),
295+
kwargs["symbolic"],
296+
annotations,
297+
)
290298
depth = arg_max_depth + 1
291299
self.__a_init__(
292300
op,
@@ -314,7 +322,15 @@ def __init_with_annotations__(
314322
if self is not None:
315323
return self
316324

317-
self = super().__new__(cls)
325+
self = super().__new__(
326+
cls,
327+
op,
328+
tuple(a_args),
329+
kwargs.get("length", None),
330+
frozenset(kwargs["variables"]),
331+
kwargs["symbolic"],
332+
tuple(kwargs.get("annotations", ())),
333+
)
318334
self.__a_init__(
319335
op,
320336
a_args,
@@ -476,12 +492,13 @@ def __a_init__(
476492

477493
# HASHCONS: these attributes key the cache
478494
# BEFORE CHANGING THIS, SEE ALL OTHER INSTANCES OF "HASHCONS" IN THIS FILE
479-
self.op = op
480-
self.args = args if type(args) is tuple else tuple(args)
481-
self.length = length
482-
self.variables = frozenset(variables) if type(variables) is not frozenset else variables
483-
self.symbolic = symbolic
484-
self.annotations: tuple[Annotation] = annotations
495+
# super().__new__(op, args, length, frozenset(variables), symbolic, annotations)
496+
# self.op = op
497+
# self.args = args if type(args) is tuple else tuple(args)
498+
# self.length = length
499+
# self.variables = frozenset(variables) if type(variables) is not frozenset else variables
500+
# self.symbolic = symbolic
501+
# self.annotations: tuple[Annotation] = annotations
485502
self._uneliminatable_annotations = uneliminatable_annotations
486503
self._relocatable_annotations = relocatable_annotations
487504

src/lib.rs

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,43 @@
1-
use pyo3::prelude::*;
1+
use std::collections::HashSet;
22

3+
use pyo3::{prelude::*, types::PyTuple};
34

45
#[pyclass(subclass)]
5-
struct Base {}
6+
struct Base {
7+
#[pyo3(get, set)]
8+
op: String,
9+
#[pyo3(get, set)]
10+
args: Py<PyTuple>,
11+
#[pyo3(get, set)]
12+
length: PyObject,
13+
#[pyo3(get, set)]
14+
variables: PyObject, // TODO: This should be a HashSet, leave opaque for now
15+
#[pyo3(get, set)]
16+
symbolic: bool,
17+
#[pyo3(get, set)]
18+
annotations: Py<PyTuple>,
19+
}
620

721
#[pymethods]
822
impl Base {
923
#[new]
10-
fn new() -> Self {
11-
Base {}
24+
#[pyo3(signature = (op, args, length, variables, symbolic, annotations))]
25+
fn new(
26+
op: String,
27+
args: Py<PyTuple>,
28+
length: PyObject,
29+
variables: PyObject,
30+
symbolic: bool,
31+
annotations: Py<PyTuple>,
32+
) -> PyResult<Self> {
33+
Ok(Base {
34+
op,
35+
args,
36+
length,
37+
variables,
38+
symbolic,
39+
annotations,
40+
})
1241
}
1342
}
1443

0 commit comments

Comments
 (0)