@@ -81,7 +81,7 @@ def __str__(self) -> str:
8181
8282class Unit (BuiltinExpr , egg_sort = "Unit" ):
8383 """
84- The unit type. This is used to reprsent if a value exists in the e-graph or not.
84+ The unit type. This is used to represent if a value exists in the e-graph or not.
8585 """
8686
8787 def __init__ (self ) -> None : ...
@@ -288,6 +288,9 @@ def bool_ge(self, other: i64Like) -> Bool: ...
288288 @method (egg_fn = "abs" )
289289 def __abs__ (self ) -> i64 : ...
290290
291+ @method (egg_fn = "vec-range" )
292+ def range (self ) -> Vec [i64 ]: ...
293+
291294
292295# The types which can be converted into an i64
293296i64Like : TypeAlias = i64 | int # noqa: N816, PYI042
@@ -1024,6 +1027,9 @@ def set(self, index: i64Like, value: T) -> Vec[T]: ...
10241027 @method (egg_fn = "vec-union" )
10251028 def __or__ (self , other : Vec [T ]) -> Vec [T ]: ...
10261029
1030+ @method (egg_fn = "unstable-vec-map" , reverse_args = True )
1031+ def map (self , fn : Callable [[T ], V ]) -> Vec [V ]: ...
1032+
10271033
10281034for sequence_type in (list , tuple ):
10291035 converter (
@@ -1036,87 +1042,6 @@ def __or__(self, other: Vec[T]) -> Vec[T]: ...
10361042
10371043VecLike : TypeAlias = Vec [T ] | tuple [TO , ...] | list [TO ]
10381044
1039- v = Vec (i64 (10 ))
1040- v .append ([i64 (10 )])
1041-
1042-
1043- class PyObject (BuiltinExpr , egg_sort = "PyObject" ):
1044- @method (preserve = True )
1045- @deprecated ("use .value" )
1046- def eval (self ) -> object :
1047- return self .value
1048-
1049- @method (preserve = True ) # type: ignore[prop-decorator]
1050- @property
1051- def value (self ) -> object :
1052- expr = cast ("RuntimeExpr" , self ).__egg_typed_expr__ .expr
1053- if not isinstance (expr , PyObjectDecl ):
1054- raise ExprValueError (self , "PyObject(x)" )
1055- return cloudpickle .loads (expr .pickled )
1056-
1057- __match_args__ = ("value" ,)
1058-
1059- def __init__ (self , value : object ) -> None : ...
1060-
1061- @method (egg_fn = "py-call" )
1062- def __call__ (self , * args : object ) -> PyObject : ...
1063-
1064- @method (egg_fn = "py-call-extended" )
1065- def call_extended (self , args : PyObject , kwargs : PyObject ) -> PyObject :
1066- """
1067- Call the PyObject with the given args and kwargs PyObjects.
1068- """
1069-
1070- @method (egg_fn = "py-from-string" )
1071- @classmethod
1072- def from_string (cls , s : StringLike ) -> PyObject : ...
1073-
1074- @method (egg_fn = "py-to-string" )
1075- def to_string (self ) -> String : ...
1076-
1077- @method (egg_fn = "py-to-bool" )
1078- def to_bool (self ) -> Bool : ...
1079-
1080- @method (egg_fn = "py-dict-update" )
1081- def dict_update (self , * keys_and_values : object ) -> PyObject : ...
1082-
1083- @method (egg_fn = "py-from-int" )
1084- @classmethod
1085- def from_int (cls , i : i64Like ) -> PyObject : ...
1086-
1087- @method (egg_fn = "py-dict" )
1088- @classmethod
1089- def dict (cls , * keys_and_values : object ) -> PyObject : ...
1090-
1091-
1092- converter (object , PyObject , PyObject )
1093-
1094-
1095- @function (builtin = True , egg_fn = "py-eval" )
1096- def py_eval (code : StringLike , globals : object = PyObject .dict (), locals : object = PyObject .dict ()) -> PyObject : ...
1097-
1098-
1099- class PyObjectFunction (Protocol ):
1100- def __call__ (self , * __args : PyObject ) -> PyObject : ...
1101-
1102-
1103- @deprecated ("use PyObject(fn) directly" )
1104- def py_eval_fn (fn : Callable ) -> PyObjectFunction :
1105- """
1106- Takes a python callable and maps it to a callable which takes and returns PyObjects.
1107-
1108- It translates it to a call which uses `py_eval` to call the function, passing in the
1109- args as locals, and using the globals from function.
1110- """
1111- return PyObject (fn )
1112-
1113-
1114- @function (builtin = True , egg_fn = "py-exec" )
1115- def py_exec (code : StringLike , globals : object = PyObject .dict (), locals : object = PyObject .dict ()) -> PyObject :
1116- """
1117- Copies the locals, execs the Python code, and returns the locals with any updates.
1118- """
1119-
11201045
11211046TS = TypeVarTuple ("TS" )
11221047
@@ -1167,9 +1092,9 @@ def __call__(self, *args: *TS) -> T: ...
11671092
11681093
11691094# Method Type is for builtins like __getitem__
1170- converter (MethodType , UnstableFn , lambda m : UnstableFn [* get_type_args ()](m .__func__ , m .__self__ ))
1171- converter (RuntimeFunction , UnstableFn , lambda rf : UnstableFn [* get_type_args ()](rf ))
1172- converter (partial , UnstableFn , lambda p : UnstableFn [* get_type_args ()](p .func , * p .args ))
1095+ converter (MethodType , UnstableFn , lambda m : UnstableFn [* get_type_args ()](m .__func__ , m .__self__ )) # type: ignore[operator, misc]
1096+ converter (RuntimeFunction , UnstableFn , lambda rf : UnstableFn [* get_type_args ()](rf )) # type: ignore[operator, misc]
1097+ converter (partial , UnstableFn , lambda p : UnstableFn [* get_type_args ()](p .func , * p .args )) # type: ignore[operator, misc]
11731098
11741099
11751100def _convert_function (fn : FunctionType ) -> UnstableFn :
@@ -1207,5 +1132,83 @@ def _convert_function(fn: FunctionType) -> UnstableFn:
12071132converter (FunctionType , UnstableFn , _convert_function )
12081133
12091134
1135+ class PyObject (BuiltinExpr , egg_sort = "PyObject" ):
1136+ @method (preserve = True )
1137+ @deprecated ("use .value" )
1138+ def eval (self ) -> object :
1139+ return self .value
1140+
1141+ @method (preserve = True ) # type: ignore[prop-decorator]
1142+ @property
1143+ def value (self ) -> object :
1144+ expr = cast ("RuntimeExpr" , self ).__egg_typed_expr__ .expr
1145+ if not isinstance (expr , PyObjectDecl ):
1146+ raise ExprValueError (self , "PyObject(x)" )
1147+ return cloudpickle .loads (expr .pickled )
1148+
1149+ __match_args__ = ("value" ,)
1150+
1151+ def __init__ (self , value : object ) -> None : ...
1152+
1153+ @method (egg_fn = "py-call" )
1154+ def __call__ (self , * args : object ) -> PyObject : ...
1155+
1156+ @method (egg_fn = "py-call-extended" )
1157+ def call_extended (self , args : PyObject , kwargs : PyObject ) -> PyObject :
1158+ """
1159+ Call the PyObject with the given args and kwargs PyObjects.
1160+ """
1161+
1162+ @method (egg_fn = "py-from-string" )
1163+ @classmethod
1164+ def from_string (cls , s : StringLike ) -> PyObject : ...
1165+
1166+ @method (egg_fn = "py-to-string" )
1167+ def to_string (self ) -> String : ...
1168+
1169+ @method (egg_fn = "py-to-bool" )
1170+ def to_bool (self ) -> Bool : ...
1171+
1172+ @method (egg_fn = "py-dict-update" )
1173+ def dict_update (self , * keys_and_values : object ) -> PyObject : ...
1174+
1175+ @method (egg_fn = "py-from-int" )
1176+ @classmethod
1177+ def from_int (cls , i : i64Like ) -> PyObject : ...
1178+
1179+ @method (egg_fn = "py-dict" )
1180+ @classmethod
1181+ def dict (cls , * keys_and_values : object ) -> PyObject : ...
1182+
1183+
1184+ converter (object , PyObject , PyObject )
1185+
1186+
1187+ @function (builtin = True , egg_fn = "py-eval" )
1188+ def py_eval (code : StringLike , globals : object = PyObject .dict (), locals : object = PyObject .dict ()) -> PyObject : ...
1189+
1190+
1191+ class PyObjectFunction (Protocol ):
1192+ def __call__ (self , * __args : PyObject ) -> PyObject : ...
1193+
1194+
1195+ @deprecated ("use PyObject(fn) directly" )
1196+ def py_eval_fn (fn : Callable ) -> PyObjectFunction :
1197+ """
1198+ Takes a python callable and maps it to a callable which takes and returns PyObjects.
1199+
1200+ It translates it to a call which uses `py_eval` to call the function, passing in the
1201+ args as locals, and using the globals from function.
1202+ """
1203+ return PyObject (fn )
1204+
1205+
1206+ @function (builtin = True , egg_fn = "py-exec" )
1207+ def py_exec (code : StringLike , globals : object = PyObject .dict (), locals : object = PyObject .dict ()) -> PyObject :
1208+ """
1209+ Copies the locals, execs the Python code, and returns the locals with any updates.
1210+ """
1211+
1212+
12101213Container : TypeAlias = Map | Set | MultiSet | Vec | UnstableFn
12111214Primitive : TypeAlias = String | Bool | i64 | f64 | Rational | BigInt | BigRat | PyObject | Unit
0 commit comments