|
| 1 | +#include "pybind11_tests.h" |
| 2 | + |
| 3 | +#include <memory> |
| 4 | +#include <string> |
| 5 | + |
| 6 | +#if defined(__clang__) |
| 7 | +# if __has_warning("-Wdeprecated-copy-with-user-provided-dtor") |
| 8 | +# pragma clang diagnostic error "-Wdeprecated-copy-with-user-provided-dtor" |
| 9 | +# endif |
| 10 | +# if __has_warning("-Wdeprecated-copy-with-dtor") |
| 11 | +# pragma clang diagnostic error "-Wdeprecated-copy-with-dtor" |
| 12 | +# endif |
| 13 | +#endif |
| 14 | + |
| 15 | +namespace test_pytorch_regressions { |
| 16 | + |
| 17 | +// Directly extracted from PyTorch patterns that regressed in CI. |
| 18 | +struct TracingState : std::enable_shared_from_this<TracingState> { |
| 19 | + TracingState() = default; |
| 20 | + ~TracingState() = default; |
| 21 | + int value = 0; |
| 22 | +}; |
| 23 | + |
| 24 | +const std::shared_ptr<TracingState> &get_tracing_state() { |
| 25 | + static std::shared_ptr<TracingState> state = std::make_shared<TracingState>(); |
| 26 | + return state; |
| 27 | +} |
| 28 | + |
| 29 | +struct InterfaceType { |
| 30 | + ~InterfaceType() = default; |
| 31 | + int value = 0; |
| 32 | +}; |
| 33 | +using InterfaceTypePtr = std::shared_ptr<InterfaceType>; |
| 34 | + |
| 35 | +struct CompilationUnit { |
| 36 | + InterfaceTypePtr iface = std::make_shared<InterfaceType>(); |
| 37 | + |
| 38 | + InterfaceTypePtr get_interface(const std::string &) const { return iface; } |
| 39 | +}; |
| 40 | + |
| 41 | +} // namespace test_pytorch_regressions |
| 42 | + |
| 43 | +TEST_SUBMODULE(pybind11_pytorch_regressions, m) { |
| 44 | + using namespace test_pytorch_regressions; |
| 45 | + |
| 46 | + py::class_<TracingState, std::shared_ptr<TracingState>>(m, "TracingState") |
| 47 | + .def(py::init<>()) |
| 48 | + .def_readwrite("value", &TracingState::value); |
| 49 | + |
| 50 | + m.def("_get_tracing_state", []() { return get_tracing_state(); }); |
| 51 | + |
| 52 | + py::class_<InterfaceType, InterfaceTypePtr>(m, "InterfaceType") |
| 53 | + .def(py::init<>()) |
| 54 | + .def_readwrite("value", &InterfaceType::value); |
| 55 | + |
| 56 | + py::class_<CompilationUnit, std::shared_ptr<CompilationUnit>>(m, "CompilationUnit") |
| 57 | + .def(py::init<>()) |
| 58 | + .def("get_interface", |
| 59 | + [](const std::shared_ptr<CompilationUnit> &self, const std::string &name) { |
| 60 | + return self->get_interface(name); |
| 61 | + }); |
| 62 | +} |
0 commit comments