-
Notifications
You must be signed in to change notification settings - Fork 15.9k
[mlir][Python] fix namespace shadowing on MSVC #175077
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: Abhishek Varma <abhvarma@amd.com>
3a1a1b8 to
3938502
Compare
|
@llvm/pr-subscribers-mlir Author: Maksim Levental (makslevental) ChangesIf you set Full diff: https://github.com/llvm/llvm-project/pull/175077.diff 1 Files Affected:
diff --git a/mlir/include/mlir/Bindings/Python/IRCore.h b/mlir/include/mlir/Bindings/Python/IRCore.h
index 59dc496c9e206..330318683c15e 100644
--- a/mlir/include/mlir/Bindings/Python/IRCore.h
+++ b/mlir/include/mlir/Bindings/Python/IRCore.h
@@ -947,7 +947,7 @@ class MLIR_PYTHON_API_EXPORTED PyConcreteType : public BaseTy {
if (!DerivedTy::isaFunction(orig)) {
auto origRepr =
nanobind::cast<std::string>(nanobind::repr(nanobind::cast(orig)));
- throw nanobind::value_error((llvm::Twine("Cannot cast type to ") +
+ throw nanobind::value_error((::llvm::Twine("Cannot cast type to ") +
DerivedTy::pyClassName + " (from " +
origRepr + ")")
.str()
@@ -966,7 +966,7 @@ class MLIR_PYTHON_API_EXPORTED PyConcreteType : public BaseTy {
if (DerivedTy::getTypeIdFunction)
return PyTypeID(DerivedTy::getTypeIdFunction());
throw nanobind::attribute_error(
- (DerivedTy::pyClassName + llvm::Twine(" has no typeid."))
+ (DerivedTy::pyClassName + ::llvm::Twine(" has no typeid."))
.str()
.c_str());
},
@@ -1080,7 +1080,7 @@ class MLIR_PYTHON_API_EXPORTED PyConcreteAttribute : public BaseTy {
if (!DerivedTy::isaFunction(orig)) {
auto origRepr =
nanobind::cast<std::string>(nanobind::repr(nanobind::cast(orig)));
- throw nanobind::value_error((llvm::Twine("Cannot cast attribute to ") +
+ throw nanobind::value_error((::llvm::Twine("Cannot cast attribute to ") +
DerivedTy::pyClassName + " (from " +
origRepr + ")")
.str()
@@ -1110,7 +1110,7 @@ class MLIR_PYTHON_API_EXPORTED PyConcreteAttribute : public BaseTy {
if (DerivedTy::getTypeIdFunction)
return PyTypeID(DerivedTy::getTypeIdFunction());
throw nanobind::attribute_error(
- (DerivedTy::pyClassName + llvm::Twine(" has no typeid."))
+ (DerivedTy::pyClassName + ::llvm::Twine(" has no typeid."))
.str()
.c_str());
},
@@ -1324,7 +1324,7 @@ class MLIR_PYTHON_API_EXPORTED PySymbolTable {
/// Custom exception that allows access to error diagnostic information. This is
/// converted to the `ir.MLIRError` python exception when thrown.
struct MLIR_PYTHON_API_EXPORTED MLIRError {
- MLIRError(llvm::Twine message,
+ MLIRError(::llvm::Twine message,
std::vector<PyDiagnostic::DiagnosticInfo> &&errorDiagnostics = {})
: message(message.str()), errorDiagnostics(std::move(errorDiagnostics)) {}
std::string message;
@@ -1544,7 +1544,7 @@ class MLIR_PYTHON_API_EXPORTED PyConcreteValue : public PyValue {
if (!DerivedTy::isaFunction(orig.get())) {
auto origRepr =
nanobind::cast<std::string>(nanobind::repr(nanobind::cast(orig)));
- throw nanobind::value_error((Twine("Cannot cast value to ") +
+ throw nanobind::value_error((::llvm::Twine("Cannot cast value to ") +
DerivedTy::pyClassName + " (from " +
origRepr + ")")
.str()
@@ -1555,11 +1555,11 @@ class MLIR_PYTHON_API_EXPORTED PyConcreteValue : public PyValue {
/// Binds the Python module objects to functions of this class.
static void bind(nanobind::module_ &m) {
- auto cls = ClassTy(
- m, DerivedTy::pyClassName, nanobind::is_generic(),
- nanobind::sig((Twine("class ") + DerivedTy::pyClassName + "(Value[_T])")
- .str()
- .c_str()));
+ auto cls = ClassTy(m, DerivedTy::pyClassName, nanobind::is_generic(),
+ nanobind::sig((::llvm::Twine("class ") +
+ DerivedTy::pyClassName + "(Value[_T])")
+ .str()
+ .c_str()));
cls.def(nanobind::init<PyValue &>(), nanobind::keep_alive<0, 1>(),
nanobind::arg("value"));
cls.def(
|
kuhar
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks
|
We saw this in a downstream too. It doesn’t seem like we have upstream CI to cover this configuration? For what it’s worth, we saw this with clang-cl too. |
TBH I don't really understand which configuration this fails on - both IREE and substrate (@ingomueller-net) reported Windows issues but we do have Windows pre-commit right and I have basically "exhaustive" Windows (among others) tests in eudsl (where I do use |
I was somewhat hoping you would have the answer there despite me having no idea. 😅 I also don't have a good idea. I tried to reproduce this issue (which manifest in Jax/XLA for us) locally and could not. I sent a patch to patch in this change and someone else tested it on the CI and that worked. It was an old clang-cl version (v18), but I tried locally with that too and also could not reproduce. So not really sure what's happening. |
If you set `MLIR_PYTHON_BINDINGS_DOMAIN=mlir`, you get namespace nesting like `mlir::python::mlir` and then `mlir::Twine` shadows `llvm::Twine` (but only on MSVC). So prefix with `::llvm` to have the correct root namespace. Co-authored-by: Abhishek Varma <abhvarma@amd.com>
Existing local reverts carried forward: * Local revert of llvm/llvm-project#169614 due to llvm/llvm-project#172932. * llvm/llvm-project#174084 -- causes linker errors related to rtti in stablehlo code * llvm/llvm-project@2b903df -- follow up fix to the above (doesn't fix it for us) -- Along with the above, IREE header fixes were done to accomodate changes introduced via llvm/llvm-project#82190 for `Affine/Transforms/Passes.h`. NOTE: [Twine fix commit](iree-org/llvm-project@2eaa29c) was dropped from our fork since llvm/llvm-project#175077 got merged upstream. Signed-off-by: Abhishek Varma <abhvarma@amd.com>
Existing local reverts carried forward: * Local revert of llvm/llvm-project#169614 due to llvm/llvm-project#172932. * llvm/llvm-project#174084 -- causes linker errors related to rtti in stablehlo code * llvm/llvm-project@2b903df -- follow up fix to the above (doesn't fix it for us) -- Along with the above, IREE header fixes were done to accomodate changes introduced via llvm/llvm-project#82190 for `Affine/Transforms/Passes.h`. NOTE: [Twine fix commit](iree-org/llvm-project@2eaa29c) was dropped from our fork since llvm/llvm-project#175077 got merged upstream. Signed-off-by: Abhishek Varma <abhvarma@amd.com> Signed-off-by: Abhishek Varma <abhvarma@amd.com>
If you set `MLIR_PYTHON_BINDINGS_DOMAIN=mlir`, you get namespace nesting like `mlir::python::mlir` and then `mlir::Twine` shadows `llvm::Twine` (but only on MSVC). So prefix with `::llvm` to have the correct root namespace. Co-authored-by: Abhishek Varma <abhvarma@amd.com>
Existing local reverts carried forward: * Local revert of llvm/llvm-project#169614 due to llvm/llvm-project#172932. * llvm/llvm-project#174084 -- causes linker errors related to rtti in stablehlo code * llvm/llvm-project@2b903df -- follow up fix to the above (doesn't fix it for us) -- Along with the above, IREE header fixes were done to accomodate changes introduced via llvm/llvm-project#82190 for `Affine/Transforms/Passes.h`. NOTE: [Twine fix commit](iree-org/llvm-project@2eaa29c) was dropped from our fork since llvm/llvm-project#175077 got merged upstream. Signed-off-by: Abhishek Varma <abhvarma@amd.com> Signed-off-by: Abhishek Varma <abhvarma@amd.com> Signed-off-by: Keshav Vinayak Jha <keshavvinayakjha@gmail.com>
If you set
MLIR_PYTHON_BINDINGS_DOMAIN=mlir, you get namespace nesting likemlir::python::mlirand thenmlir::Twineshadowsllvm::Twine(but only on MSVC). So prefix with::llvmto have the correct root namespace.