This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Fix infinite recursion in alias initializer
ClosedPublic

Authored by zero9178 on Aug 26 2023, 7:13 AM.

Details

Summary

The alias initializer keeps a list of child indices around. When an alias is then marked as non-deferrable, all children are also marked non-deferrable.

This is currently done naively which leads to an infinite recursion if using mutable types or attributes containing a cycle.

This patch fixes this by adding an early return if the alias is already marked non-deferrable. Since this function is the only way to mark an alias as non-deferrable, it is guaranteed that if it is marked non-deferrable, all its children are as well, and it is not required to walk all the children.
This incidentally makes the non-deferrable marking also O(n) instead of O(n^2) (although not performance sensitive obviously).

Diff Detail

Event Timeline

zero9178 created this revision.Aug 26 2023, 7:13 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 26 2023, 7:13 AM
zero9178 requested review of this revision.Aug 26 2023, 7:13 AM
mehdi_amini added inline comments.Aug 26 2023, 3:04 PM
mlir/test/lib/Dialect/Test/TestTypes.cpp
493

I really don't like using global state: do we have an alternative?

zero9178 added inline comments.Aug 26 2023, 3:19 PM
mlir/test/lib/Dialect/Test/TestTypes.cpp
493

There currently is not and all upstream mutable attributes and types that may create cycles suffer from this problem.
I am actually currently working on patches that should fix this.
For the time being, this is the best we got.

mehdi_amini accepted this revision.Aug 26 2023, 4:32 PM
mehdi_amini added inline comments.
mlir/test/lib/Dialect/Test/TestTypes.cpp
493

Adding some tracking to the parser itself instead?

Looking forward to your patch!

This revision is now accepted and ready to land.Aug 26 2023, 4:32 PM
This revision was automatically updated to reflect the committed changes.