- 
                Notifications
    
You must be signed in to change notification settings  - Fork 3.7k
 
Closed
Labels
tir:printerTIR printer:python/tvm/script, src/printer/tir_text_printer.cc, src/printer/tvmscript_printer.ccTIR printer:python/tvm/script, src/printer/tir_text_printer.cc, src/printer/tvmscript_printer.cctype: language
Description
In TVMScript, there are places where literal string is used in type annotation as type parameter. For instance,
@T.prim_func
def main(A: T.Buffer[(8,), "float32"], B: T.Buffer[(8,), "float32"]):
    ...This will result in lint error undefined name 'float32' since linter (or type checker) treats literal string in type annotation as forward references. While there will not be any runtime errors, this makes editing TVMScript in modern editor less pleasant. This issue is opened to discuss the potential workaround for this problem.
One possible approach is to have a magic object to turn symbol into string, like
class TypeString:
    def __getattribute__(self, name):
        return name
T.type = TypeString()
@T.prim_func
def main(A: T.Buffer[(8,), T.type.float32], B: T.Buffer[(8,), T.type.float32]):
    ...Metadata
Metadata
Assignees
Labels
tir:printerTIR printer:python/tvm/script, src/printer/tir_text_printer.cc, src/printer/tvmscript_printer.ccTIR printer:python/tvm/script, src/printer/tir_text_printer.cc, src/printer/tvmscript_printer.cctype: language