Storage uniquer isn't initialized: the dialect was likely not loaded, or the type wasn't added with addTypes<...>() in the Dialect::initialize() method

Hello there,

I am new to MLIR. I created my own dialect with some types. When I try to use my new type, I get the following runtime error:

LLVM ERROR: can't create type 'mlir::standalone::CustomType' because storage uniquer isn't initialized: the dialect was likely not loaded, or the type wasn't added with addTypes<...>() in the Dialect::initialize() method.

I saw two other posts with a similar issue, but it seemed their issue was because addTypes<…> was not added in the dialect initialize() method.

When I list the loaded dialects in the context, my dialect is not there. However, when my input MLIR contains an operation of my dialect, the dialect is loaded, and I don’t get this error.

I tried to do something similar with the MLIR example dialect standalone (mlir/examples/standalone/lib/Standalone/StandalonePasses.cpp):

  void runOnOperation() final {
    RewritePatternSet patterns(&getContext());
    //====================Testing the new type====================
    CustomType customType = CustomType::get(&getContext(), "test");
    //============================================================
    patterns.add<StandaloneSwitchBarFooRewriter>(&getContext());
    FrozenRewritePatternSet patternSet(std::move(patterns));
    if (failed(applyPatternsAndFoldGreedily(getOperation(), patternSet)))
      signalPassFailure();
  }

Am I missing something? Do we need to load the new dialects explicitly? If yes, how and where this should be done?

Thanks in advance for your help!

Maybe you can check the “dependentDialect” filed in your pass.td.
I think StandaloneDialect may be missing.