Skip to content

Commit 102abd9

Browse files
committed
[MLIR][ODS] Re-enable direct implementation of type interfaces with method bodies
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 93e860e commit 102abd9

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
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: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -637,12 +637,15 @@ 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+
} else if (method.getDefaultImplementation() &&
643+
!alwaysDeclared.count(method.getName())) {
642644
genTraitMethodUsingDecl(trait, method);
643645
continue;
646+
} else {
647+
emitTraitMethod(method);
644648
}
645-
emitTraitMethod(method);
646649
}
647650
}
648651

0 commit comments

Comments
 (0)