Skip to content

Commit 8eacea9

Browse files
authored
[MLIR][ODS] Re-enable direct implementation of type interfaces with method bodies (#166335)
Since commit 842622b adding support for overloading interface methods, a `using` directive is emitted for any interface method that does not require emission of a trait method, including for methods that define a method body. However, methods directly specifying a body (e.g., via the `methodBody` parameter of `InterfaceMethod`) are implemented directly in the interface class and are therefore not present in the associated trait. The generated `using` directive then referes to a non-existent method of the trait, resulting in an error upon compilation of the generated code. This patch changes `DefGen::emitTraitMethods()`, such that `genTraitMethodUsingDecl()` is not invoked for interface methods with a body anymore.
1 parent 628d53a commit 8eacea9

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

mlir/test/lib/Dialect/Test/TestTypeDefs.td

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,4 +470,11 @@ def TestMemrefType : Test_Type<"TestMemref",
470470
}];
471471
}
472472

473+
// Test implementation of an interface with methods specifying a
474+
// method body
475+
def TestBaseBody : Test_Type<"TestBaseBody",
476+
[DeclareTypeInterfaceMethods<TestBaseTypeInterfacePrintTypeA>]> {
477+
let mnemonic = "test_base_body";
478+
}
479+
473480
#endif // TEST_TYPEDEFS

mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -637,8 +637,10 @@ void DefGen::emitTraitMethods(const InterfaceTrait &trait) {
637637
for (auto &method : iface.getMethods()) {
638638
// Don't declare if the method has a body. Or if the method has a default
639639
// implementation and the def didn't request that it always be declared.
640-
if (method.getBody() || (method.getDefaultImplementation() &&
641-
!alwaysDeclared.count(method.getName()))) {
640+
if (method.getBody())
641+
continue;
642+
if (method.getDefaultImplementation() &&
643+
!alwaysDeclared.count(method.getName())) {
642644
genTraitMethodUsingDecl(trait, method);
643645
continue;
644646
}

0 commit comments

Comments
 (0)