[all-commits] [llvm/llvm-project] de3f7e: [mlir] Fix infinite recursion in alias initializer

Markus Böck via All-commits all-commits at lists.llvm.org
Sun Aug 27 08:32:34 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: de3f7e2f0fb4363c17eec73ce79ca30e221ea844
      https://github.com/llvm/llvm-project/commit/de3f7e2f0fb4363c17eec73ce79ca30e221ea844
  Author: Markus Böck <markus.boeck02 at gmail.com>
  Date:   2023-08-27 (Sun, 27 Aug 2023)

  Changed paths:
    M mlir/lib/IR/AsmPrinter.cpp
    M mlir/test/IR/recursive-type.mlir
    M mlir/test/lib/Dialect/Test/TestDialectInterfaces.cpp
    M mlir/test/lib/Dialect/Test/TestTypeDefs.td
    M mlir/test/lib/Dialect/Test/TestTypes.cpp
    M mlir/test/lib/Dialect/Test/TestTypes.h

  Log Message:
  -----------
  [mlir] Fix infinite recursion in alias initializer

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).

Differential Revision: https://reviews.llvm.org/D158932




More information about the All-commits mailing list