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

[flang][Evaluate] Add AsGenericExpr that takes std::optional #81264

Closed
wants to merge 1 commit into from

Conversation

kparzysz
Copy link
Contributor

@kparzysz kparzysz commented Feb 9, 2024

AsGenericExpr already returns optional Expr. Making it accept an optional Expr as input would reduce the number of necessary checks when handling frequent optional values in evaluator.

@kparzysz kparzysz marked this pull request as ready for review February 9, 2024 16:19
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Feb 9, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Feb 9, 2024

@llvm/pr-subscribers-flang-semantics

Author: Krzysztof Parzyszek (kparzysz)

Changes

AsGenericExpr already returns optional Expr. Making it accept an optional Expr as input would reduce the number of necessary checks when handling frequent optional values in evaluator.


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

1 Files Affected:

  • (modified) flang/include/flang/Evaluate/tools.h (+8)
diff --git a/flang/include/flang/Evaluate/tools.h b/flang/include/flang/Evaluate/tools.h
index d257da1a709642..f7f155a5da9e13 100644
--- a/flang/include/flang/Evaluate/tools.h
+++ b/flang/include/flang/Evaluate/tools.h
@@ -148,6 +148,14 @@ inline Expr<SomeType> AsGenericExpr(Expr<SomeType> &&x) { return std::move(x); }
 std::optional<Expr<SomeType>> AsGenericExpr(DataRef &&);
 std::optional<Expr<SomeType>> AsGenericExpr(const Symbol &);
 
+// Propagate std::optional from input to output.
+template <typename A>
+std::optional<Expr<SomeType>> AsGenericExpr(std::optional<A> &&x) {
+  if (!x)
+    return std::nullopt;
+  return AsGenericExpr(std::move(*x));
+}
+
 template <typename A>
 common::IfNoLvalue<Expr<SomeKind<ResultType<A>::category>>, A> AsCategoryExpr(
     A &&x) {

`AsGenericExpr` already returns optional Expr. Making it accept an
optional Expr as input would reduce the number of necessary checks
when handling frequent optional values in evaluator.
@clementval
Copy link
Contributor

Where is it used?

@kparzysz
Copy link
Contributor Author

Included in another PR: #81626

@kparzysz kparzysz closed this Feb 13, 2024
@kparzysz kparzysz deleted the users/kparzysz/a03b-tools branch February 13, 2024 16:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:semantics flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants