@@ -321,55 +321,78 @@ TEST(InterfaceAttachment, Operation) {
321321 ASSERT_FALSE (isa<TestExternalOpInterface>(otherModuleOp.getOperation ()));
322322}
323323
324+ template <class ConcreteOp >
324325struct TestExternalTestOpModel
325- : public TestExternalOpInterface::ExternalModel<TestExternalTestOpModel,
326- test::OpJ > {
326+ : public TestExternalOpInterface::ExternalModel<
327+ TestExternalTestOpModel<ConcreteOp>, ConcreteOp > {
327328 unsigned getNameLengthPlusArg (Operation *op, unsigned arg) const {
328329 return op->getName ().getStringRef ().size () + arg;
329330 }
330331
331332 static unsigned getNameLengthPlusArgTwice (unsigned arg) {
332- return test::OpJ ::getOperationName ().size () + 2 * arg;
333+ return ConcreteOp ::getOperationName ().size () + 2 * arg;
333334 }
334335};
335336
336337TEST (InterfaceAttachment, OperationDelayedContextConstruct) {
337338 DialectRegistry registry;
338339 registry.insert <test::TestDialect>();
339340 registry.addOpInterface <ModuleOp, TestExternalOpModel>();
340- registry.addOpInterface <test::OpJ, TestExternalTestOpModel>();
341+ registry.addOpInterface <test::OpJ, TestExternalTestOpModel<test::OpJ>>();
342+ registry.addOpInterface <test::OpH, TestExternalTestOpModel<test::OpH>>();
341343
342344 // Construct the context directly from a registry. The interfaces are expected
343345 // to be readily available on operations.
344346 MLIRContext context (registry);
345347 context.loadDialect <test::TestDialect>();
348+
346349 ModuleOp module = ModuleOp::create (UnknownLoc::get (&context));
347350 OpBuilder builder (module );
348- auto op =
351+ auto opJ =
349352 builder.create <test::OpJ>(builder.getUnknownLoc (), builder.getI32Type ());
353+ auto opH =
354+ builder.create <test::OpH>(builder.getUnknownLoc (), opJ.getResult ());
355+ auto opI =
356+ builder.create <test::OpI>(builder.getUnknownLoc (), opJ.getResult ());
357+
350358 EXPECT_TRUE (isa<TestExternalOpInterface>(module .getOperation ()));
351- EXPECT_TRUE (isa<TestExternalOpInterface>(op.getOperation ()));
359+ EXPECT_TRUE (isa<TestExternalOpInterface>(opJ.getOperation ()));
360+ EXPECT_TRUE (isa<TestExternalOpInterface>(opH.getOperation ()));
361+ EXPECT_FALSE (isa<TestExternalOpInterface>(opI.getOperation ()));
352362}
353363
354364TEST (InterfaceAttachment, OperationDelayedContextAppend) {
355365 DialectRegistry registry;
356366 registry.insert <test::TestDialect>();
357367 registry.addOpInterface <ModuleOp, TestExternalOpModel>();
358- registry.addOpInterface <test::OpJ, TestExternalTestOpModel>();
368+ registry.addOpInterface <test::OpJ, TestExternalTestOpModel<test::OpJ>>();
369+ registry.addOpInterface <test::OpH, TestExternalTestOpModel<test::OpH>>();
359370
360371 // Construct the context, create ops, and only then append the registry. The
361372 // interfaces are expected to be available after appending the registry.
362373 MLIRContext context;
363374 context.loadDialect <test::TestDialect>();
375+
364376 ModuleOp module = ModuleOp::create (UnknownLoc::get (&context));
365377 OpBuilder builder (module );
366- auto op =
378+ auto opJ =
367379 builder.create <test::OpJ>(builder.getUnknownLoc (), builder.getI32Type ());
380+ auto opH =
381+ builder.create <test::OpH>(builder.getUnknownLoc (), opJ.getResult ());
382+ auto opI =
383+ builder.create <test::OpI>(builder.getUnknownLoc (), opJ.getResult ());
384+
368385 EXPECT_FALSE (isa<TestExternalOpInterface>(module .getOperation ()));
369- EXPECT_FALSE (isa<TestExternalOpInterface>(op.getOperation ()));
386+ EXPECT_FALSE (isa<TestExternalOpInterface>(opJ.getOperation ()));
387+ EXPECT_FALSE (isa<TestExternalOpInterface>(opH.getOperation ()));
388+ EXPECT_FALSE (isa<TestExternalOpInterface>(opI.getOperation ()));
389+
370390 context.appendDialectRegistry (registry);
391+
371392 EXPECT_TRUE (isa<TestExternalOpInterface>(module .getOperation ()));
372- EXPECT_TRUE (isa<TestExternalOpInterface>(op.getOperation ()));
393+ EXPECT_TRUE (isa<TestExternalOpInterface>(opJ.getOperation ()));
394+ EXPECT_TRUE (isa<TestExternalOpInterface>(opH.getOperation ()));
395+ EXPECT_FALSE (isa<TestExternalOpInterface>(opI.getOperation ()));
373396}
374397
375398} // end namespace
0 commit comments