-
Notifications
You must be signed in to change notification settings - Fork 52
Description
Tile Language, or TensorIR Script, uses Python as its interface and automatically translates Python AST into TIR AST. However, this automatic translation can sometimes lead to inconvenient behavior.
For instance, consider the following example:
sub_func = get_function(condition)
# Depending on the condition, sub_func requires a different number of arguments
if condition:
sub_func requires three arguments
else:
sub_func requires two arguments.
@T.prim_func
def function(
A, B, C
):
if condition is True:
sub_func(A, B, C)
else:
sub_func(A, C)The parser will transform this code into T.if_then_else(cond, sub_func(A, B, C), sub_func(A, C)). However, the parser must evaluate both branches of the if-then-else expression. This can cause issues when sub_func has a different number of required arguments based on the condition.
For example, if condition is True, sub_func expects three arguments (i.e., sub_func(A, B, C)). But because the parser also tries to evaluate the else branch (sub_func(A, C)), it throws an error like unexpected keyword argument, as sub_func is defined to take three arguments, not two. This leads to crashes since the parser is unable to reconcile the differing argument counts in both branches of the expression.