Skip to content
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

[mlir] Mark isa/dyn_cast/cast/... member functions deprecated. #90413

Merged
merged 2 commits into from
Apr 30, 2024

Conversation

chsigg
Copy link
Contributor

@chsigg chsigg commented Apr 28, 2024

This also removes the member overload in TypeSwitch.

All other users have been removed in fac349a and bd9fdce.

@llvmbot llvmbot added mlir:core MLIR Core Infrastructure mlir llvm:adt labels Apr 28, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Apr 28, 2024

@llvm/pr-subscribers-flang-codegen
@llvm/pr-subscribers-flang-fir-hlfir
@llvm/pr-subscribers-mlir-core

@llvm/pr-subscribers-mlir

Author: Christian Sigg (chsigg)

Changes

All users have been removed in fac349a.

Except for TypeSwitch, where the deprecation warning needs to be disabled until the functions are removed.


Full diff: https://github.com/llvm/llvm-project/pull/90413.diff

4 Files Affected:

  • (modified) llvm/include/llvm/ADT/TypeSwitch.h (+3)
  • (modified) mlir/include/mlir/IR/Attributes.h (+5)
  • (modified) mlir/include/mlir/IR/Location.h (+3)
  • (modified) mlir/include/mlir/IR/Types.h (+5)
diff --git a/llvm/include/llvm/ADT/TypeSwitch.h b/llvm/include/llvm/ADT/TypeSwitch.h
index 10a2d48e918db9..14ad56ad575ffc 100644
--- a/llvm/include/llvm/ADT/TypeSwitch.h
+++ b/llvm/include/llvm/ADT/TypeSwitch.h
@@ -74,7 +74,10 @@ template <typename DerivedT, typename T> class TypeSwitchBase {
       ValueT &&value,
       std::enable_if_t<is_detected<has_dyn_cast_t, ValueT, CastT>::value> * =
           nullptr) {
+    // Silence warnings about MLIR's deprecated dyn_cast member functions.
+    LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_PUSH
     return value.template dyn_cast<CastT>();
+    LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_POP
   }
 
   /// Attempt to dyn_cast the given `value` to `CastT`. This overload is
diff --git a/mlir/include/mlir/IR/Attributes.h b/mlir/include/mlir/IR/Attributes.h
index cc0cee6a31183c..8a077865b51b5f 100644
--- a/mlir/include/mlir/IR/Attributes.h
+++ b/mlir/include/mlir/IR/Attributes.h
@@ -50,14 +50,19 @@ class Attribute {
   /// Casting utility functions. These are deprecated and will be removed,
   /// please prefer using the `llvm` namespace variants instead.
   template <typename... Tys>
+  [[deprecated("Use mlir::isa<U>() instead")]]
   bool isa() const;
   template <typename... Tys>
+  [[deprecated("Use mlir::isa_and_nonnull<U>() instead")]]
   bool isa_and_nonnull() const;
   template <typename U>
+  [[deprecated("Use mlir::dyn_cast<U>() instead")]]
   U dyn_cast() const;
   template <typename U>
+  [[deprecated("Use mlir::dyn_cast_or_null<U>() instead")]]
   U dyn_cast_or_null() const;
   template <typename U>
+  [[deprecated("Use mlir::cast<U>() instead")]]
   U cast() const;
 
   /// Return a unique identifier for the concrete attribute type. This is used
diff --git a/mlir/include/mlir/IR/Location.h b/mlir/include/mlir/IR/Location.h
index aa8314f38cdfac..423b4d19b5b944 100644
--- a/mlir/include/mlir/IR/Location.h
+++ b/mlir/include/mlir/IR/Location.h
@@ -78,14 +78,17 @@ class Location {
 
   /// Type casting utilities on the underlying location.
   template <typename U>
+  [[deprecated("Use mlir::isa<U>() instead")]]
   bool isa() const {
     return llvm::isa<U>(*this);
   }
   template <typename U>
+  [[deprecated("Use mlir::dyn_cast<U>() instead")]]
   U dyn_cast() const {
     return llvm::dyn_cast<U>(*this);
   }
   template <typename U>
+  [[deprecated("Use mlir::cast<U>() instead")]]
   U cast() const {
     return llvm::cast<U>(*this);
   }
diff --git a/mlir/include/mlir/IR/Types.h b/mlir/include/mlir/IR/Types.h
index a89e13b625bf40..65824531fdc908 100644
--- a/mlir/include/mlir/IR/Types.h
+++ b/mlir/include/mlir/IR/Types.h
@@ -97,14 +97,19 @@ class Type {
   bool operator!() const { return impl == nullptr; }
 
   template <typename... Tys>
+  [[deprecated("Use mlir::isa<U>() instead")]]
   bool isa() const;
   template <typename... Tys>
+  [[deprecated("Use mlir::isa_and_nonnull<U>() instead")]]
   bool isa_and_nonnull() const;
   template <typename U>
+  [[deprecated("Use mlir::dyn_cast<U>() instead")]]
   U dyn_cast() const;
   template <typename U>
+  [[deprecated("Use mlir::dyn_cast_or_null<U>() instead")]]
   U dyn_cast_or_null() const;
   template <typename U>
+  [[deprecated("Use mlir::cast<U>() instead")]]
   U cast() const;
 
   /// Return a unique identifier for the concrete type. This is used to support

@llvmbot
Copy link
Collaborator

llvmbot commented Apr 28, 2024

@llvm/pr-subscribers-llvm-adt

Author: Christian Sigg (chsigg)

Changes

All users have been removed in fac349a.

Except for TypeSwitch, where the deprecation warning needs to be disabled until the functions are removed.


Full diff: https://github.com/llvm/llvm-project/pull/90413.diff

4 Files Affected:

  • (modified) llvm/include/llvm/ADT/TypeSwitch.h (+3)
  • (modified) mlir/include/mlir/IR/Attributes.h (+5)
  • (modified) mlir/include/mlir/IR/Location.h (+3)
  • (modified) mlir/include/mlir/IR/Types.h (+5)
diff --git a/llvm/include/llvm/ADT/TypeSwitch.h b/llvm/include/llvm/ADT/TypeSwitch.h
index 10a2d48e918db9..14ad56ad575ffc 100644
--- a/llvm/include/llvm/ADT/TypeSwitch.h
+++ b/llvm/include/llvm/ADT/TypeSwitch.h
@@ -74,7 +74,10 @@ template <typename DerivedT, typename T> class TypeSwitchBase {
       ValueT &&value,
       std::enable_if_t<is_detected<has_dyn_cast_t, ValueT, CastT>::value> * =
           nullptr) {
+    // Silence warnings about MLIR's deprecated dyn_cast member functions.
+    LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_PUSH
     return value.template dyn_cast<CastT>();
+    LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_POP
   }
 
   /// Attempt to dyn_cast the given `value` to `CastT`. This overload is
diff --git a/mlir/include/mlir/IR/Attributes.h b/mlir/include/mlir/IR/Attributes.h
index cc0cee6a31183c..8a077865b51b5f 100644
--- a/mlir/include/mlir/IR/Attributes.h
+++ b/mlir/include/mlir/IR/Attributes.h
@@ -50,14 +50,19 @@ class Attribute {
   /// Casting utility functions. These are deprecated and will be removed,
   /// please prefer using the `llvm` namespace variants instead.
   template <typename... Tys>
+  [[deprecated("Use mlir::isa<U>() instead")]]
   bool isa() const;
   template <typename... Tys>
+  [[deprecated("Use mlir::isa_and_nonnull<U>() instead")]]
   bool isa_and_nonnull() const;
   template <typename U>
+  [[deprecated("Use mlir::dyn_cast<U>() instead")]]
   U dyn_cast() const;
   template <typename U>
+  [[deprecated("Use mlir::dyn_cast_or_null<U>() instead")]]
   U dyn_cast_or_null() const;
   template <typename U>
+  [[deprecated("Use mlir::cast<U>() instead")]]
   U cast() const;
 
   /// Return a unique identifier for the concrete attribute type. This is used
diff --git a/mlir/include/mlir/IR/Location.h b/mlir/include/mlir/IR/Location.h
index aa8314f38cdfac..423b4d19b5b944 100644
--- a/mlir/include/mlir/IR/Location.h
+++ b/mlir/include/mlir/IR/Location.h
@@ -78,14 +78,17 @@ class Location {
 
   /// Type casting utilities on the underlying location.
   template <typename U>
+  [[deprecated("Use mlir::isa<U>() instead")]]
   bool isa() const {
     return llvm::isa<U>(*this);
   }
   template <typename U>
+  [[deprecated("Use mlir::dyn_cast<U>() instead")]]
   U dyn_cast() const {
     return llvm::dyn_cast<U>(*this);
   }
   template <typename U>
+  [[deprecated("Use mlir::cast<U>() instead")]]
   U cast() const {
     return llvm::cast<U>(*this);
   }
diff --git a/mlir/include/mlir/IR/Types.h b/mlir/include/mlir/IR/Types.h
index a89e13b625bf40..65824531fdc908 100644
--- a/mlir/include/mlir/IR/Types.h
+++ b/mlir/include/mlir/IR/Types.h
@@ -97,14 +97,19 @@ class Type {
   bool operator!() const { return impl == nullptr; }
 
   template <typename... Tys>
+  [[deprecated("Use mlir::isa<U>() instead")]]
   bool isa() const;
   template <typename... Tys>
+  [[deprecated("Use mlir::isa_and_nonnull<U>() instead")]]
   bool isa_and_nonnull() const;
   template <typename U>
+  [[deprecated("Use mlir::dyn_cast<U>() instead")]]
   U dyn_cast() const;
   template <typename U>
+  [[deprecated("Use mlir::dyn_cast_or_null<U>() instead")]]
   U dyn_cast_or_null() const;
   template <typename U>
+  [[deprecated("Use mlir::cast<U>() instead")]]
   U cast() const;
 
   /// Return a unique identifier for the concrete type. This is used to support

@chsigg
Copy link
Contributor Author

chsigg commented Apr 28, 2024

Note that this change previously broke a Windows build.

@dyung, could you please advise how to test this change so I don't break it again?

@dyung
Copy link
Collaborator

dyung commented Apr 29, 2024

Note that this change previously broke a Windows build.

@dyung, could you please advise how to test this change so I don't break it again?

I don't know if this change is any different from what you submitted, but when I applied the patches locally, our Windows build failed the same way as before.

All users have been removed in fac349a and bd9fdce.

Except for TypeSwitch, where the deprecation warning needs to be disabled until the functions are removed.
Remove member cast overload in TypeSwitch so we don't have to disable the warning.
@chsigg
Copy link
Contributor Author

chsigg commented Apr 30, 2024

This passes the Windows CI now which uses the same Visual Studio 2019 version as the CI build that previously broke. This is expected because it no longer uses the LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_PUSH macro. I did see cl.exe running out of heap space on previous revisions building flang, but that is likely an unrelated transient failure.

@chsigg chsigg merged commit 7ac1fb0 into llvm:main Apr 30, 2024
4 checks passed
@chsigg chsigg deleted the deprecate_cast branch April 30, 2024 08:34
@chsigg
Copy link
Contributor Author

chsigg commented Apr 30, 2024

The Windows build that caused problems previously is still passing after this change.

@DanielCChen
Copy link
Contributor

DanielCChen commented Apr 30, 2024

It seems this PR causes build failure on LoP (Linux On Power) as

llvm-project/flang/lib/Optimizer/Transforms/AddDebugInfo.cpp:148:26: error: 'dyn_cast' is deprecated: Use mlir::dyn_cast<U>() instead [-Werror,-Wdeprecated-declarations]
    if (auto funcLoc = l.dyn_cast<mlir::FileLineColLoc>())
                         ^

There are also quite a lot warning on top of the failures. @chsigg

@chsigg
Copy link
Contributor Author

chsigg commented May 2, 2024

It seems this PR causes build failure on LoP (Linux On Power) as

llvm-project/flang/lib/Optimizer/Transforms/AddDebugInfo.cpp:148:26: error: 'dyn_cast' is deprecated: Use mlir::dyn_cast<U>() instead [-Werror,-Wdeprecated-declarations]
    if (auto funcLoc = l.dyn_cast<mlir::FileLineColLoc>())
                         ^

There are also quite a lot warning on top of the failures. @chsigg

Sorry about that, not sure how I missed these. Hopefully they are now fixed with 52cb953?

Thank you very much kazutakahirata and PeimingLiu for jumping in!

@DanielCChen
Copy link
Contributor

It seems this PR causes build failure on LoP (Linux On Power) as

llvm-project/flang/lib/Optimizer/Transforms/AddDebugInfo.cpp:148:26: error: 'dyn_cast' is deprecated: Use mlir::dyn_cast<U>() instead [-Werror,-Wdeprecated-declarations]
    if (auto funcLoc = l.dyn_cast<mlir::FileLineColLoc>())
                         ^

There are also quite a lot warning on top of the failures. @chsigg

Sorry about that, not sure how I missed these. Hopefully they are now fixed with 52cb953?

Thank you very much kazutakahirata and PeimingLiu for jumping in!

Yes. All the errors and warnings are fixed. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:codegen flang:fir-hlfir flang Flang issues not falling into any other category llvm:adt mlir:core MLIR Core Infrastructure mlir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants