[Unity] Require TupleStructInfo when iterating over relax.Expr#15975
Closed
Lunderberg wants to merge 1 commit intoapache:unityfrom
Closed
[Unity] Require TupleStructInfo when iterating over relax.Expr#15975Lunderberg wants to merge 1 commit intoapache:unityfrom
Lunderberg wants to merge 1 commit intoapache:unityfrom
Conversation
Contributor
Author
This was referenced Oct 24, 2023
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.
c193b20 to
b34a120
Compare
c95d45f to
45eeb8c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Prior to this commit, iteration over a
relax.Exprrelied on an exception being thrown fromTupleGetItem, which was then re-raised as anIndexError. 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 haveTupleStructInfo, it would result in an infinite loop.This commit adds an explicit implementation of
__iter__, which checks whether the expression being iterated over to haveTupleStructInfo. This retains backwards compatibility for cases that were previously valid, but provides an explicit error in cases that would previously cause an infinite loop.