Skip to content

[Feature Request][TL] Maybe need an annotation to disable part of the ast be translated into TL #221

@LeiWang1999

Description

@LeiWang1999

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions