tvm_tirx.script.parser.from_source

Contents

tvm_tirx.script.parser.from_source#

tvm_tirx.script.parser.from_source(source, extra_vars=None, *, filename=None, track_loc=True, definition_scope=None, root_function_kwargs=None, **options)#

Transpile and execute a source string, Python function, or Python class.

Parameters:
  • source (str or function or type) – Original source text or inspectable Python object.

  • extra_vars (mapping of str to object, optional) – Lexical bindings overriding captured values. Default is None, interpreted as an empty mapping.

  • filename (str, optional) – Source filename override. Default is None, which uses the inspected filename for objects and "<str>" for text.

  • track_loc (bool, optional) – Enable shared source metadata and IR location instrumentation. Default is True. False retains Python source locations only.

  • definition_scope (mapping of str to object, optional) – Temporary definition-site bindings for annotation reconstruction. None and an empty mapping both add no external scope; parse never inspects its caller for bindings. These values do not replace body globals or closures.

  • root_function_kwargs (mapping of str to object, optional) – Already-evaluated kwargs forwarded to function_ for a standalone root function. None reads options from its source decorator; an empty mapping supplies no kwargs and does not re-evaluate source arguments. Nested functions and module members use their own source decorators. Defaults are owned by the builder hook; check_well_formed is separate.

  • **options – _const_args maps parameter names to fixed constexpr values and explicit optional-parameter absence. None selects ordinary parsing; an empty mapping still selects root JIT construction. check_well_formed controls completed-result validation; construction policy otherwise comes from qualified source decorators.

Returns:

object – Opaque result of the generated builder program.

Raises:
  • OSError – If source inspection cannot recover the supplied object’s text.

  • TypeError – If the source object cannot be inspected.

  • SyntaxError – If source parsing fails or transpilation detects a syntax restriction. Parser restrictions retain their source filename and range.

Return type:

Any

Notes

Source text supplies namespace aliases through imports or extra_vars; conventional names such as T, R and I are not implicitly available. Printed scripts display suggested imports as comments; execute those imports in the source text or supply equivalent extra_vars for a round trip. Each call owns its freshly acquired AST and a fresh lexical environment. Declaration and definition frames are entered only during generated execution. Source acquisition, host and builder errors propagate with their original type, identity and traceback. Temporary captures are released even when execution fails.