Skip to content

[Unity] Require TupleStructInfo when iterating over relax.Expr#15975

Closed
Lunderberg wants to merge 1 commit intoapache:unityfrom
Lunderberg:unity_expr_iteration_requires_tuplestructinfo
Closed

[Unity] Require TupleStructInfo when iterating over relax.Expr#15975
Lunderberg wants to merge 1 commit intoapache:unityfrom
Lunderberg:unity_expr_iteration_requires_tuplestructinfo

Conversation

@Lunderberg
Copy link
Contributor

Prior to this commit, iteration over a relax.Expr relied on an exception being thrown from TupleGetItem, which was then re-raised as an IndexError. This allowed Python's default implementation of iteration over an object that defines __getitem__, but doesn't define __iter__ or __len__ to terminate. However, if the object being iterated over did not have TupleStructInfo, it would result in an infinite loop.

This commit adds an explicit implementation of __iter__, which checks whether the expression being iterated over to have TupleStructInfo. This retains backwards compatibility for cases that were previously valid, but provides an explicit error in cases that would previously cause an infinite loop.

@Lunderberg
Copy link
Contributor Author

#15975 and #15976 are two possible implementations to resolve issues with iteration over relax objects. Both are currently in draft form, to allow discussion and to check what issues arise from each implementation.

Prior to this commit, iteration over a `relax.Expr` relied on an
exception being thrown from `TupleGetItem`, which was then re-raised
as an `IndexError`.  This allowed Python's default implementation of
iteration over an object that defines `__getitem__`, but doesn't
define `__iter__` or `__len__` to terminate.  However, if the object
being iterated over did not have `TupleStructInfo`, it would result in
an infinite loop.

This commit adds an explicit implementation of `__iter__`, which
checks whether the expression being iterated over to have
`TupleStructInfo`.  This retains backwards compatibility for cases
that were previously valid, but provides an explicit error in cases
that would previously cause an infinite loop.
@Lunderberg Lunderberg force-pushed the unity_expr_iteration_requires_tuplestructinfo branch from c193b20 to b34a120 Compare October 25, 2023 14:19
@junrushao junrushao force-pushed the unity branch 2 times, most recently from c95d45f to 45eeb8c Compare December 18, 2023 21:00
@tqchen tqchen deleted the branch apache:unity March 29, 2024 12:18
@tqchen tqchen closed this Mar 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants