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

    <tr>
        <th>Summary</th>
        <td>
            [mlir] `mlir::DialectRegistry` can't be copied
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

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

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

<pre>
    Recall

```c++
class DialectRegistry {
  ...
private:
  llvm::MapVector<TypeID, std::unique_ptr<DialectExtensionBase>> extensions;
```

then

```c++
template <typename T> void wrap_copy(void *dst, const void *src) {
  new ((T *) dst) T(*(const T *) src);
}

foo() {
  (void)wrap_copy<mlir::DialectRegistry>;
}
```

will produce 

```
/usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_algobase.h:385:18: error: object of type 'std::pair<mlir::TypeID, std::unique_ptr<mlir::DialectExtensionBase>>' cannot be assigned because its copy assignment operator is implicitly deleted
  385 | *__result = *__first;
      |                         ^
```

on 

```
(eudsl) mlevental@Shark17:~/dev_projects/eudsl/projects/eudsl-py/src$ clang-20 --version
Ubuntu clang version 20.0.0 (++20241108053735+b613a54075c6-1~exp1~20241108053914.2037)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm-20/bin
```

The copy offending copy comes from `SmallVectorImpl::operator=(const SmallVectorImpl<T> &RHS)`:
https://github.com/llvm/llvm-project/blob/9d85ba5724f22d73c95858246691e0b389bdb28d/llvm/include/llvm/ADT/SmallVector.h#L1017

I don't know what the correct solution is (should `SmallVector` be smarter?) but doing

```c++
DialectRegistry(const DialectRegistry&) = delete;
```

fixes (in the sense that `wrap_copy` reports a call to a deleted ctor, and/or `std::is_copy_constructible<mlir::DialectRegistry>::value == false`). 

Full compile error stack follows.

---

```
In file included from /home/mlevental/dev_projects/eudsl/projects/eudsl-py/src/eudsl_ext.cpp:1:
In file included from /home/mlevental/miniconda3/envs/eudsl/lib/python3.11/site-packages/nanobind/include/nanobind/nanobind.h:32:
In file included from /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/stdexcept:39:
In file included from /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/string:53:
In file included from /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/basic_string.h:39:
In file included from /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/ext/alloc_traits.h:34:
In file included from /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/alloc_traits.h:33:
/usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_construct.h:119:25: error: call to implicitly-deleted copy constructor of 'std::pair<mlir::TypeID, std::unique_ptr<mlir::DialectExtensionBase>>'
  119 |       ::new((void*)__p) _Tp(std::forward<_Args>(__args)...);
      | ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_uninitialized.h:120:11: note: in instantiation of function template specialization 'std::_Construct<std::pair<mlir::TypeID, std::unique_ptr<mlir::DialectExtensionBase>>, const std::pair<mlir::TypeID, std::unique_ptr<mlir::DialectExtensionBase>> &>' requested here
  120 | std::_Construct(std::__addressof(*__cur), *__first);
      | ^
/usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_uninitialized.h:137:16: note: in instantiation of function template specialization 'std::__do_uninit_copy<const std::pair<mlir::TypeID, std::unique_ptr<mlir::DialectExtensionBase>> *, std::pair<mlir::TypeID, std::unique_ptr<mlir::DialectExtensionBase>> *>' requested here
  137 | { return std::__do_uninit_copy(__first, __last, __result); }
      | ^
/usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_uninitialized.h:185:2: note: in instantiation of function template specialization 'std::__uninitialized_copy<false>::__uninit_copy<const std::pair<mlir::TypeID, std::unique_ptr<mlir::DialectExtensionBase>> *, std::pair<mlir::TypeID, std::unique_ptr<mlir::DialectExtensionBase>> *>' requested here
  185 |         __uninit_copy(__first, __last, __result);
 | ^
/home/mlevental/dev_projects/eudsl/llvm-install/include/llvm/ADT/SmallVector.h:356:10: note: in instantiation of function template specialization 'std::uninitialized_copy<const std::pair<mlir::TypeID, std::unique_ptr<mlir::DialectExtensionBase>> *, std::pair<mlir::TypeID, std::unique_ptr<mlir::DialectExtensionBase>> *>' requested here
  356 | std::uninitialized_copy(I, E, Dest);
      | ^
/home/mlevental/dev_projects/eudsl/llvm-install/include/llvm/ADT/SmallVector.h:1043:9: note: in instantiation of function template specialization 'llvm::SmallVectorTemplateBase<std::pair<mlir::TypeID, std::unique_ptr<mlir::DialectExtensionBase>>>::uninitialized_copy<const std::pair<mlir::TypeID, std::unique_ptr<mlir::DialectExtensionBase>> *, std::pair<mlir::TypeID, std::unique_ptr<mlir::DialectExtensionBase>> *>' requested here
 1043 |   this->uninitialized_copy(RHS.begin()+CurSize, RHS.end(),
      | ^
/home/mlevental/dev_projects/eudsl/llvm-install/include/llvm/ADT/SmallVector.h:1238:27: note: in instantiation of member function 'llvm::SmallVectorImpl<std::pair<mlir::TypeID, std::unique_ptr<mlir::DialectExtensionBase>>>::operator=' requested here
 1238 |       SmallVectorImpl<T>::operator=(RHS);
      | ^
/home/mlevental/dev_projects/eudsl/llvm-install/include/llvm/ADT/MapVector.h:36:7: note: in instantiation of member function 'llvm::SmallVector<std::pair<mlir::TypeID, std::unique_ptr<mlir::DialectExtensionBase>>, 0>::SmallVector' requested here
   36 | class MapVector {
      | ^
/home/mlevental/dev_projects/eudsl/projects/eudsl-py/src/eudsl_ext.cpp:282:9: note: in instantiation of function template specialization 'wrap_copy<mlir::DialectRegistry>' requested here
  282 | (void)wrap_copy<mlir::DialectRegistry>;
      | ^
/usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_pair.h:195:17: note: explicitly defaulted function was implicitly deleted here
  195 | constexpr pair(const pair&) = default;    ///< Copy constructor
      | ^
/usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_pair.h:192:11: note: copy constructor of 'pair<mlir::TypeID, std::unique_ptr<mlir::DialectExtensionBase>>' is implicitly deleted because field 'second' has a deleted copy constructor
  192 |       _T2 second; ///< The second member
      | ^
/usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/unique_ptr.h:514:7: note: 'unique_ptr' has been explicitly marked deleted here
  514 | unique_ptr(const unique_ptr&) = delete;
```

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkWl9v6yoS_zT0BSWyIf73kIc0aXQr7b6ck91XC9uThC0BX8Bteh_OZ18BduK26faeu_1zpRNFlQMYhpkfv5lhyozhOwkwR8k1SlZXrLN7pecHdmcE3IO0TFxVqnmcf4OaCYGihfumUfjWiFy7b7SoBTMGrzgTUNtvsOPG6keMMteH8XQ6RdGi1fyeWUB04RuFuD-4Z7r4J2v_DbVVGtHl5rGF2xUiS2xsE7o7yX_voGyt6--XuDlakIYrec0MIHqD6A2Goc0gej0WM0ht9yBfld_CoRXMAkZ0aR9bkOwAeONmvVe8wQ-atWWt2kdEct-AyKIx1olZK2ksHhqNrhEpThuX8IARyRHJN67XdfnXCrzxzQtE8jDBqT_M0O8gWwWJt0r58eeZe0EQKc6y0eVBcB2U9swUXkWjKZ-q5oELgVutmq4G_ExH7pmsO6MRWQteIbLe1TUi62OelulsIrjsjpOd7BBZxwSR9XT68g-XtegaQGQ9aLwfXHFrEFkbK0omdqpiBqZ7RBc0TxBdxDmiCwxaO2QssKr-A7XFaoudhTAi2QkiLXP7Hm3_LRi9UNQFQCGS4ZpJqSyuAPcnpcEV1KwzgLk12Km97zmAtFi1oJlVGnOD-aEVvOZWPOIGBFhovOFonmCULZ25y1KD6YTFiK7C7y3XxgZDYf9xI1_7oOTmpSmVvGjAHLrGCAegw3Cu0Sz6vmf6Ls4QXfxAZN3Afdlq5ZTsjNK_sX7eNH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