[mlir] Prevent SubElementInterface from going into infinite recursion
authorMin-Yih Hsu <minyihh@uci.edu>
Sat, 21 May 2022 04:52:49 +0000 (21:52 -0700)
committerMin-Yih Hsu <minyihh@uci.edu>
Wed, 29 Jun 2022 20:58:02 +0000 (13:58 -0700)
commitd41028610b5372669adcb9b7091fae5250f0a4a8
treeba676aa8d5741c4c0fe792574941304a015584d2
parentbc5e7ced1c7e6155e9d527f88a657793ffad4761
[mlir] Prevent SubElementInterface from going into infinite recursion

Since only mutable types and attributes can go into infinite recursion
inside SubElementInterface::walkSubElement, and there are only a few of
them (mutable types and attributes), we introduce new traits for Type
and Attribute: TypeTrait::IsMutable and AttributeTrait::IsMutable,
respectively. They indicate whether a type or attribute is mutable.
Such traits are required if the ImplType defines a `mutate` function.

Then, inside SubElementInterface, we use a set to record visited mutable
types and attributes that have been visited before.

Differential Revision: https://reviews.llvm.org/D127537
13 files changed:
mlir/include/mlir/Dialect/LLVMIR/LLVMTypes.h
mlir/include/mlir/Dialect/SPIRV/IR/SPIRVTypes.h
mlir/include/mlir/IR/Attributes.h
mlir/include/mlir/IR/StorageUniquerSupport.h
mlir/include/mlir/IR/Types.h
mlir/lib/IR/SubElementInterfaces.cpp
mlir/test/IR/recursive-type.mlir
mlir/test/lib/Dialect/Test/TestDialect.cpp
mlir/test/lib/Dialect/Test/TestTypes.h
mlir/unittests/Dialect/CMakeLists.txt
mlir/unittests/Dialect/LLVMIR/CMakeLists.txt [new file with mode: 0644]
mlir/unittests/Dialect/LLVMIR/LLVMTestBase.h [new file with mode: 0644]
mlir/unittests/Dialect/LLVMIR/LLVMTypeTest.cpp [new file with mode: 0644]