Skip to content

Commit 3da1241

Browse files
committed
Replace asserts with valueErrors
1 parent 90e5424 commit 3da1241

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

xdsl_smt/utils/transfer_function_util.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@ def call_function(func: DefineFunOp, args: list[SSAValue]) -> CallOp:
2929
Given a function in smt dialect and its args, return CallOp(func, args) with type checking
3030
"""
3131
func_args = func.body.block.args
32-
assert len(func_args) == len(args)
32+
if len(func_args) != len(args):
33+
raise ValueError(f"Arguments of the call to function {func.fun_name} mismatch")
3334
for f_arg, arg in zip(func_args, args):
3435
if f_arg.type != arg.type:
35-
print(func.fun_name)
3636
print(func_args)
3737
print(args)
38-
assert f_arg.type == arg.type
38+
raise ValueError(
39+
f"Argument of the call to function {func.fun_name} has different type"
40+
)
3941
callOp = CallOp.get(func.results[0], args)
4042
return callOp
4143

@@ -74,7 +76,8 @@ def call_function_and_assert_result(
7476
equals to the bv
7577
"""
7678
callOp = call_function(func, args)
77-
assert len(callOp.results) == 1
79+
if len(callOp.results) != 1:
80+
raise ValueError(f"Incorrect returned value {func.fun_name}")
7881
firstOp = FirstOp(callOp.results[0])
7982
assertOps = assert_result(firstOp.res, bv)
8083
return [callOp, firstOp] + assertOps
@@ -104,7 +107,8 @@ def get_argument_instances_with_effect(
104107
"""
105108
result: list[DeclareConstOp | ConstantOp] = []
106109
# ignore last effect arg
107-
assert isinstance(func.body.block.args[-1].type, BoolType)
110+
if not isinstance(func.body.block.args[-1].type, BoolType):
111+
raise ValueError(f"Function {func.fun_name} is not ended with effect")
108112
for i, arg in enumerate(func.body.block.args[:-1]):
109113
argType = arg.type
110114
if i in int_attr:
@@ -207,7 +211,7 @@ def compress_and_op(lst: list[Operation]) -> tuple[SSAValue, list[Operation]]:
207211
result and a list of constructed and operations
208212
"""
209213
if len(lst) == 0:
210-
assert False and "cannot compress lst with size 0 to an AndOp"
214+
raise ValueError("cannot compress lst with size 0 to an AndOp")
211215
elif len(lst) == 1:
212216
empty_result: list[Operation] = []
213217
return (lst[0].results[0], empty_result)

0 commit comments

Comments
 (0)