<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/55044>55044</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [ODS] Dialect ctor should be emitted to .cpp file, not .h file
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            mlir:core
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          lattner
      </td>
    </tr>
</table>

<pre>
    ODS is generating dialect ctors inline in header files like this:

```
class MyDialect : public ::mlir::Dialect {
  explicit MyDialect(::mlir::MLIRContext *context)
    : ::mlir::Dialect(getDialectNamespace(), context,
      ::mlir::TypeID::get<MyDialect>()) {

    initialize();
  }
```

This is annoying because it forces types to be complete and prevents use of unique pointer.  One example of this is when [implementing fallback interfaces](https://github.com/tensorflow/tensorflow/blob/494c7507982e935d2c68a6ced08d6dc11fc8634c/tensorflow/core/ir/dialect.td#L121) where you want to keep the class in the .cpp file, and not put it into the header.  This example should use a unique pointer, but you can't do that because the header-exposed ctor requires the T type to be complete.

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx9VNtu3CAQ_Rr7BcWysb22H_yQZLtSpKSV2vwAhvGahgUHcJLt13dgb-32IiEMYubMzDkzHozY91_W34h0ZAsaLPNSb4mQTAH3hHtjHZFaSQ34IRMwAZaMUoEjSr4A8ZN0SXmb5OskP-2r_LjilSvmHHnar4-YaE3mZVCShyOunZL2cDqbNHcHX0LgY0ZL6S8ACW2v_Z4eH77eG-3hA33pLT8cE9qdUEiM-o9wCLgFf7x8ZjtwM-MQwiAAvSdnuPsLHPkD7Hk_w8P6cEa4pLy_ZFx-OqF1l9ouYFJLj5byxyloeS4_adZ_JfWwPyP5QTmmtdkH3QbgbHEolSejsRxF8pgW7gafsJDdrMAD2gsyW3gD7R0J9mYki5avC5DZSKzWZoR8QcnhgwWX8O6Psd4n0CSp72R42CFCiDsypQbGX0h0HpE-l9RrrGbyfo79QTe4ttJPy5BhHnjxoJ2xozLv15dBmQE_VVfxps6brqXQlbWgfNWyFQeRt2IleFGMvF2VFb9258YikRsUhm6OjZx5kdDysaBFkABLsED2ZiHvTPtAzgvAjBUiRbFZsdPDJePzHHs9dEHgTBuPresDvVioiUaHkUC-ohgnwtxkFiUit-yK2gA2IEiIz5lOaOOJCFjMn_W7AN_gABgHIo4isfC6SBsERYPnKO6VttmhM1LRl6IrO5Z66RX0KBhOOWpC1r-M9ilN9Ied9B7DINpvZYeSsyle08Wq_j-CKvV2-tzM1nyPo7WRzi3YDXRT13lVpVPf0WIQA6WsbGnBxrZmzdgWVcFXKDXULFVsAOVCygmlxwE7aEqxgFT2NKc0rygtmqqqVxkTTdlWY16MOXQ1HZMqhx2TKguZZMZuU9vHpIZl6_BRSefd5REFl1sNkaOAzxY_GfRg3uP_MI359zH5n_bQpfI">