This is an archive of the discontinued LLVM Phabricator instance.

Add a static assertions for custom Op<> to not defined data members (NFC)
ClosedPublic

Authored by mehdi_amini on Jun 7 2021, 10:32 PM.

Details

Summary

A common mistake for newcomers to MLIR is to try to store extra member
on the Op class. However these are intended to be thing wrapper around
an Operation*, all the storage is meant to be encoded in attribute on
the underlying Operation. This can be confusing to debug, so better
catch it at build time.

Diff Detail

Event Timeline

mehdi_amini created this revision.Jun 7 2021, 10:32 PM
mehdi_amini requested review of this revision.Jun 7 2021, 10:32 PM
ftynse accepted this revision.Jun 8 2021, 12:27 AM
This revision is now accepted and ready to land.Jun 8 2021, 12:27 AM
ftynse added inline comments.Jun 8 2021, 12:27 AM
mlir/include/mlir/IR/OpDefinition.h
1792
This revision was landed with ongoing or failed builds.Jun 8 2021, 11:38 AM
This revision was automatically updated to reflect the committed changes.
mehdi_amini reopened this revision.Jun 8 2021, 5:46 PM
This revision is now accepted and ready to land.Jun 8 2021, 5:46 PM
mehdi_amini updated this revision to Diff 350751.EditedJun 8 2021, 5:46 PM

Reopen, after revert because windows build was broken

It looks like this is causing a build failure on the windows mlir buildbot which may be the goal since the assert is firing, but it would be nice to keep the buildbot green.

https://lab.llvm.org/buildbot/#/builders/13/builds/8726

FAILED: tools/mlir/lib/IR/CMakeFiles/obj.MLIRIR.dir/BuiltinDialect.cpp.obj 
C:\PROGRA~2\MICROS~3\2017\COMMUN~1\VC\Tools\MSVC\1416~1.270\bin\Hostx64\x64\cl.exe  /nologo /TP -DBUILD_EXAMPLES -DGTEST_HAS_RTTI=0 -DMLIR_CUDA_CONVERSIONS_ENABLED=1 -DMLIR_ROCM_CONVERSIONS_ENABLED=1 -DUNICODE -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_HAS_EXCEPTIONS=0 -D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS -D_UNICODE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Itools\mlir\lib\IR -IC:\buildbot\mlir-x64-windows-ninja\llvm-project\mlir\lib\IR -Iinclude -IC:\buildbot\mlir-x64-windows-ninja\llvm-project\llvm\include -IC:\buildbot\mlir-x64-windows-ninja\llvm-project\mlir\include -Itools\mlir\include /DWIN32 /D_WINDOWS   /Zc:inline /Zc:__cplusplus /Zc:strictStrings /Oi /Zc:rvalueCast /bigobj /W4 -wd4141 -wd4146 -wd4244 -wd4267 -wd4291 -wd4351 -wd4456 -wd4457 -wd4458 -wd4459 -wd4503 -wd4624 -wd4722 -wd4100 -wd4127 -wd4512 -wd4505 -wd4610 -wd4510 -wd4702 -wd4245 -wd4706 -wd4310 -wd4701 -wd4703 -wd4389 -wd4611 -wd4805 -wd4204 -wd4577 -wd4091 -wd4592 -wd4319 -wd4709 -wd4324 -w14062 -we4238 /Gw /MD /O2 /Ob2  /EHs-c- /GR- -UNDEBUG -std:c++14 /showIncludes /Fotools\mlir\lib\IR\CMakeFiles\obj.MLIRIR.dir\BuiltinDialect.cpp.obj /Fdtools\mlir\lib\IR\CMakeFiles\obj.MLIRIR.dir\ /FS -c C:\buildbot\mlir-x64-windows-ninja\llvm-project\mlir\lib\IR\BuiltinDialect.cpp
C:\buildbot\mlir-x64-windows-ninja\llvm-project\mlir\include\mlir/IR/OpDefinition.h(1783): error C2338: Op class aren't allowed to have data members
C:\buildbot\mlir-x64-windows-ninja\llvm-project\mlir\include\mlir/IR/OpDefinition.h(1782): note: while compiling class template member function 'mlir::LogicalResult mlir::Op<mlir::UnrealizedConversionCastOp,mlir::OpTrait::ZeroRegion,mlir::OpTrait::VariadicResults,mlir::OpTrait::ZeroSuccessor,mlir::OpTrait::VariadicOperands,mlir::CastOpInterface::Trait,mlir::MemoryEffectOpInterface::Trait>::verifyInvariants(mlir::Operation *)'

It looks like this is causing a build failure on the windows mlir buildbot which may be the goal since the assert is firing, but it would be nice to keep the buildbot green.

https://lab.llvm.org/buildbot/#/builders/13/builds/8726

FAILED: tools/mlir/lib/IR/CMakeFiles/obj.MLIRIR.dir/BuiltinDialect.cpp.obj 
C:\PROGRA~2\MICROS~3\2017\COMMUN~1\VC\Tools\MSVC\1416~1.270\bin\Hostx64\x64\cl.exe  /nologo /TP -DBUILD_EXAMPLES -DGTEST_HAS_RTTI=0 -DMLIR_CUDA_CONVERSIONS_ENABLED=1 -DMLIR_ROCM_CONVERSIONS_ENABLED=1 -DUNICODE -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_HAS_EXCEPTIONS=0 -D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS -D_UNICODE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Itools\mlir\lib\IR -IC:\buildbot\mlir-x64-windows-ninja\llvm-project\mlir\lib\IR -Iinclude -IC:\buildbot\mlir-x64-windows-ninja\llvm-project\llvm\include -IC:\buildbot\mlir-x64-windows-ninja\llvm-project\mlir\include -Itools\mlir\include /DWIN32 /D_WINDOWS   /Zc:inline /Zc:__cplusplus /Zc:strictStrings /Oi /Zc:rvalueCast /bigobj /W4 -wd4141 -wd4146 -wd4244 -wd4267 -wd4291 -wd4351 -wd4456 -wd4457 -wd4458 -wd4459 -wd4503 -wd4624 -wd4722 -wd4100 -wd4127 -wd4512 -wd4505 -wd4610 -wd4510 -wd4702 -wd4245 -wd4706 -wd4310 -wd4701 -wd4703 -wd4389 -wd4611 -wd4805 -wd4204 -wd4577 -wd4091 -wd4592 -wd4319 -wd4709 -wd4324 -w14062 -we4238 /Gw /MD /O2 /Ob2  /EHs-c- /GR- -UNDEBUG -std:c++14 /showIncludes /Fotools\mlir\lib\IR\CMakeFiles\obj.MLIRIR.dir\BuiltinDialect.cpp.obj /Fdtools\mlir\lib\IR\CMakeFiles\obj.MLIRIR.dir\ /FS -c C:\buildbot\mlir-x64-windows-ninja\llvm-project\mlir\lib\IR\BuiltinDialect.cpp
C:\buildbot\mlir-x64-windows-ninja\llvm-project\mlir\include\mlir/IR/OpDefinition.h(1783): error C2338: Op class aren't allowed to have data members
C:\buildbot\mlir-x64-windows-ninja\llvm-project\mlir\include\mlir/IR/OpDefinition.h(1782): note: while compiling class template member function 'mlir::LogicalResult mlir::Op<mlir::UnrealizedConversionCastOp,mlir::OpTrait::ZeroRegion,mlir::OpTrait::VariadicResults,mlir::OpTrait::ZeroSuccessor,mlir::OpTrait::VariadicOperands,mlir::CastOpInterface::Trait,mlir::MemoryEffectOpInterface::Trait>::verifyInvariants(mlir::Operation *)'

Looks like you already caught it. Thanks!

@stella.stamenova relanded in 1b21e9c1fa99, the premerge passed on Windows here, but feel free to revert if you see any failure!