MCPcopy Index your code
hub / github.com/apache/tvm / _duplicate_lhs_check

Method _duplicate_lhs_check

python/tvm/script/parser/core/parser.py:528–562  ·  view source on GitHub ↗

Check whether duplicate lhs exists in assignment. Parameters ---------- target : doc.expr The doc AST expr node for lhs. Returns ------- res : Union[bool, Set[str]] The result of true if duplicate lhs exists, or th

(self, target: doc.expr)

Source from the content-addressed store, hash-verified

526 return eval_expr(self, node, var_values)
527
528 def _duplicate_lhs_check(self, target: doc.expr) -> bool | set[str]:
529 """Check whether duplicate lhs exists in assignment.
530
531 Parameters
532 ----------
533 target : doc.expr
534 The doc AST expr node for lhs.
535
536 Returns
537 -------
538 res : Union[bool, Set[str]]
539 The result of true if duplicate lhs exists,
540 or the set of lhs names if no duplicate lhs exists.
541 """
542 if isinstance(target, doc.Tuple | doc.List):
543 vars: set[str] = set() # pylint: disable=redefined-builtin
544 for i in target.elts:
545 res = self._duplicate_lhs_check(i)
546 if isinstance(res, bool) and res:
547 return True
548 assert isinstance(res, set)
549 if vars & res:
550 return True
551 vars = vars.union(res)
552 return vars
553 elif isinstance(target, doc.Name):
554 return {target.id}
555 elif isinstance(target, doc.Starred):
556 return self._duplicate_lhs_check(target.value)
557 elif isinstance(target, doc.Attribute):
558 # Attribute assignment like packedB.data = ..., treated as rebinding.
559 return {target.attr}
560 else:
561 self.report_error(target, "Invalid type in assign statement")
562 raise NotImplementedError
563
564 def eval_assign(
565 self,

Callers 1

eval_assignMethod · 0.95

Calls 2

report_errorMethod · 0.95
unionMethod · 0.80

Tested by

no test coverage detected