kparzysz-quic commented on PR #15260:
URL: https://github.com/apache/tvm/pull/15260#issuecomment-1636879942

   For the purposes of the rest of the comment, I renamed `TIRMacro` to 
`ScriptMacro`, and created a subclass `RelaxMacro`.
   
   There are some complications with macros returning values, specifically when 
the call to the macro is a part of a larger expression.  The problem is that 
there are no specific parser visitors for subexpressions---the whole expression 
is evaluated by the evaluator all at once, so I can't do the same "AST 
injection" as I did for TIR (at least not without adding detailed visitors and 
capturing AST.Call nodes).
   
   For example,
   ```
   @R.macro
   def m():
       return 1
   
   @R.function
   def foo():
       x = m() + 1
   ```
   The entire `m() + 1` will be evaluated, causing Python to actually call the 
`RelaxMacro` object.  I went down that route a bit, added `__call__` operator 
to `RelaxMacro`, parsed it as if it was `R.function`, and returned the body.  
This works, but has severe limitations: the macro's parameters need to be 
annotated and can only be objects that a `R.function` can take, so no `str` for 
example.
   
   I'm inclined to follow the TIR route instead, but I wanted to consult with 
you in case this is a bad idea.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to