[mlir] ODS: emit interface traits outside of the interface class
authorAlex Zinenko <zinenko@google.com>
Wed, 16 Jun 2021 14:31:17 +0000 (16:31 +0200)
committerAlex Zinenko <zinenko@google.com>
Thu, 17 Jun 2021 08:25:35 +0000 (10:25 +0200)
commita4f81b2054c30954c6739532b923f2b223bc7d77
treeba0a63a74df49969b989eee68c944fd38fee5ea7
parent25fa67868b36c99d2704bd291b3b495737f16f0e
[mlir] ODS: emit interface traits outside of the interface class

ODS currently emits the interface trait class as a nested class inside the
interface class. As an unintended consequence, the default implementations of
interface methods have implicit access to static fields of the interface class,
e.g. those declared in `extraClassDeclaration`, including private methods (!),
or in the parent class. This may break the use of default implementations for
external models, which are not defined in the interface class, and generally
complexifies the abstraction.

Emit intraface traits outside of the interface class itself to avoid accidental
implicit visibility. Public static fields can still be accessed via explicit
qualification with a class name, e.g., `MyOpInterface::staticMethod()` instead
of `staticMethod`.

Update the documentation to clarify the role of `extraClassDeclaration` in
interfaces.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D104384
mlir/docs/Interfaces.md
mlir/include/mlir/Interfaces/ControlFlowInterfaces.td
mlir/tools/mlir-tblgen/OpInterfacesGen.cpp