Skip to content

Commit

Permalink
Revert "[flang] Add & use a better visit()"
Browse files Browse the repository at this point in the history
This reverts commit 2ab9990. It has
caused multiple build failures:
*  https://lab.llvm.org/buildbot/#/builders/177/builds/4346
*  https://lab.llvm.org/buildbot/#/builders/180/builds/3803
*  https://lab.llvm.org/buildbot/#/builders/175/builds/10419
*  https://lab.llvm.org/buildbot/#/builders/191/builds/4318
*  https://lab.llvm.org/buildbot/#/builders/173/builds/4274
*  https://lab.llvm.org/buildbot/#/builders/181/builds/4297

All these bots failed with a time-out:
```
command timed out: 1200 seconds without output running [b'ninja', b'-j', b'32'], attempting to kill
```
I'm guessing that that's due to template instantiations failing at some
point (https://reviews.llvm.org/D122441 introduced a custom
implementation of std::visit). Everything seems fine when either:
* building on X86 with GCC or Clang (tested with GCC 9.3 and Clang 12)
* building on AArch64 with GCC (tested with GCC 11)
  • Loading branch information
banach-space committed Mar 28, 2022
1 parent 8a2a966 commit 4ca111d
Show file tree
Hide file tree
Showing 62 changed files with 1,297 additions and 1,427 deletions.
5 changes: 2 additions & 3 deletions flang/include/flang/Common/idioms.h
Expand Up @@ -23,7 +23,6 @@
#error g++ >= 7.2 is required
#endif

#include "visit.h"
#include "llvm/Support/Compiler.h"
#include <functional>
#include <list>
Expand All @@ -50,8 +49,8 @@ using namespace std::literals::string_literals;
namespace Fortran::common {

// Helper templates for combining a list of lambdas into an anonymous
// struct for use with common::visit() on a std::variant<> sum type.
// E.g.: common::visit(visitors{
// struct for use with std::visit() on a std::variant<> sum type.
// E.g.: std::visit(visitors{
// [&](const firstType &x) { ... },
// [&](const secondType &x) { ... },
// ...
Expand Down
4 changes: 2 additions & 2 deletions flang/include/flang/Common/template.h
Expand Up @@ -118,14 +118,14 @@ template <typename A> const A *GetPtrFromOptional(const std::optional<A> &x) {
// Copy a value from one variant type to another. The types allowed in the
// source variant must all be allowed in the destination variant type.
template <typename TOV, typename FROMV> TOV CopyVariant(const FROMV &u) {
return common::visit([](const auto &x) -> TOV { return {x}; }, u);
return std::visit([](const auto &x) -> TOV { return {x}; }, u);
}

// Move a value from one variant type to another. The types allowed in the
// source variant must all be allowed in the destination variant type.
template <typename TOV, typename FROMV>
common::IfNoLvalue<TOV, FROMV> MoveVariant(FROMV &&u) {
return common::visit(
return std::visit(
[](auto &&x) -> TOV { return {std::move(x)}; }, std::move(u));
}

Expand Down
5 changes: 2 additions & 3 deletions flang/include/flang/Common/unwrap.h
Expand Up @@ -12,7 +12,6 @@
#include "indirection.h"
#include "reference-counted.h"
#include "reference.h"
#include "visit.h"
#include <memory>
#include <optional>
#include <type_traits>
Expand Down Expand Up @@ -104,7 +103,7 @@ struct UnwrapperHelper {

template <typename A, typename... Bs>
static A *Unwrap(std::variant<Bs...> &u) {
return common::visit(
return std::visit(
[](auto &x) -> A * {
using Ty = std::decay_t<decltype(Unwrap<A>(x))>;
if constexpr (!std::is_const_v<std::remove_pointer_t<Ty>> ||
Expand All @@ -118,7 +117,7 @@ struct UnwrapperHelper {

template <typename A, typename... Bs>
static auto Unwrap(const std::variant<Bs...> &u) -> std::add_const_t<A> * {
return common::visit(
return std::visit(
[](const auto &x) -> std::add_const_t<A> * { return Unwrap<A>(x); }, u);
}

Expand Down
94 changes: 0 additions & 94 deletions flang/include/flang/Common/visit.h

This file was deleted.

2 changes: 1 addition & 1 deletion flang/include/flang/Evaluate/expression.h
Expand Up @@ -646,7 +646,7 @@ template <> class Relational<SomeType> {
EVALUATE_UNION_CLASS_BOILERPLATE(Relational)
static constexpr DynamicType GetType() { return Result::GetType(); }
int Rank() const {
return common::visit([](const auto &x) { return x.Rank(); }, u);
return std::visit([](const auto &x) { return x.Rank(); }, u);
}
llvm::raw_ostream &AsFortran(llvm::raw_ostream &o) const;
common::MapTemplate<Relational, DirectlyComparableTypes> u;
Expand Down
8 changes: 4 additions & 4 deletions flang/include/flang/Evaluate/fold-designator.h
Expand Up @@ -67,7 +67,7 @@ class DesignatorFolder {

template <typename T>
std::optional<OffsetSymbol> FoldDesignator(const Expr<T> &expr) {
return common::visit(
return std::visit(
[&](const auto &x) { return FoldDesignator(x, elementNumber_++); },
expr.u);
}
Expand Down Expand Up @@ -98,7 +98,7 @@ class DesignatorFolder {
template <typename T>
std::optional<OffsetSymbol> FoldDesignator(
const Expr<T> &expr, ConstantSubscript which) {
return common::visit(
return std::visit(
[&](const auto &x) { return FoldDesignator(x, which); }, expr.u);
}

Expand All @@ -110,14 +110,14 @@ class DesignatorFolder {
template <typename T>
std::optional<OffsetSymbol> FoldDesignator(
const Designator<T> &designator, ConstantSubscript which) {
return common::visit(
return std::visit(
[&](const auto &x) { return FoldDesignator(x, which); }, designator.u);
}
template <int KIND>
std::optional<OffsetSymbol> FoldDesignator(
const Designator<Type<TypeCategory::Character, KIND>> &designator,
ConstantSubscript which) {
return common::visit(
return std::visit(
common::visitors{
[&](const Substring &ss) {
if (const auto *dataRef{ss.GetParentIf<DataRef>()}) {
Expand Down
2 changes: 1 addition & 1 deletion flang/include/flang/Evaluate/initial-image.h
Expand Up @@ -88,7 +88,7 @@ class InitialImage {
template <typename T>
Result Add(ConstantSubscript offset, std::size_t bytes, const Expr<T> &x,
FoldingContext &c) {
return common::visit(
return std::visit(
[&](const auto &y) { return Add(offset, bytes, y, c); }, x.u);
}

Expand Down
2 changes: 1 addition & 1 deletion flang/include/flang/Evaluate/shape.h
Expand Up @@ -167,7 +167,7 @@ class GetShapeHelper
template <typename T>
MaybeExtentExpr GetArrayConstructorValueExtent(
const ArrayConstructorValue<T> &value) const {
return common::visit(
return std::visit(
common::visitors{
[&](const Expr<T> &x) -> MaybeExtentExpr {
if (auto xShape{
Expand Down
43 changes: 20 additions & 23 deletions flang/include/flang/Evaluate/tools.h
Expand Up @@ -83,7 +83,7 @@ template <typename A> bool IsAssumedRank(const Designator<A> &designator) {
}
}
template <typename T> bool IsAssumedRank(const Expr<T> &expr) {
return common::visit([](const auto &x) { return IsAssumedRank(x); }, expr.u);
return std::visit([](const auto &x) { return IsAssumedRank(x); }, expr.u);
}
template <typename A> bool IsAssumedRank(const std::optional<A> &x) {
return x && IsAssumedRank(*x);
Expand All @@ -100,7 +100,7 @@ template <typename A> bool IsCoarray(const Designator<A> &designator) {
return false;
}
template <typename T> bool IsCoarray(const Expr<T> &expr) {
return common::visit([](const auto &x) { return IsCoarray(x); }, expr.u);
return std::visit([](const auto &x) { return IsCoarray(x); }, expr.u);
}
template <typename A> bool IsCoarray(const std::optional<A> &x) {
return x && IsCoarray(*x);
Expand Down Expand Up @@ -177,11 +177,11 @@ auto UnwrapExpr(B &x) -> common::Constify<A, B> * {
return UnwrapExpr<A>(*expr);
}
} else if constexpr (std::is_same_v<Ty, Expr<SomeType>>) {
return common::visit([](auto &x) { return UnwrapExpr<A>(x); }, x.u);
return std::visit([](auto &x) { return UnwrapExpr<A>(x); }, x.u);
} else if constexpr (!common::HasMember<A, TypelessExpression>) {
if constexpr (std::is_same_v<Ty, Expr<ResultType<A>>> ||
std::is_same_v<Ty, Expr<SomeKind<ResultType<A>::category>>>) {
return common::visit([](auto &x) { return UnwrapExpr<A>(x); }, x.u);
return std::visit([](auto &x) { return UnwrapExpr<A>(x); }, x.u);
}
}
return nullptr;
Expand Down Expand Up @@ -217,17 +217,15 @@ auto UnwrapConvertedExpr(B &x) -> common::Constify<A, B> * {
return UnwrapConvertedExpr<A>(*expr);
}
} else if constexpr (std::is_same_v<Ty, Expr<SomeType>>) {
return common::visit(
[](auto &x) { return UnwrapConvertedExpr<A>(x); }, x.u);
return std::visit([](auto &x) { return UnwrapConvertedExpr<A>(x); }, x.u);
} else if constexpr (!common::HasMember<A, TypelessExpression>) {
using Result = ResultType<A>;
if constexpr (std::is_same_v<Ty, Expr<Result>> ||
std::is_same_v<Ty, Expr<SomeKind<Result::category>>>) {
return common::visit(
[](auto &x) { return UnwrapConvertedExpr<A>(x); }, x.u);
return std::visit([](auto &x) { return UnwrapConvertedExpr<A>(x); }, x.u);
} else if constexpr (std::is_same_v<Ty, Parentheses<Result>> ||
std::is_same_v<Ty, Convert<Result, Result::category>>) {
return common::visit(
return std::visit(
[](auto &x) { return UnwrapConvertedExpr<A>(x); }, x.left().u);
}
}
Expand Down Expand Up @@ -264,7 +262,7 @@ common::IfNoLvalue<std::optional<DataRef>, A> ExtractDataRef(
template <typename T>
std::optional<DataRef> ExtractDataRef(
const Designator<T> &d, bool intoSubstring = false) {
return common::visit(
return std::visit(
[=](const auto &x) -> std::optional<DataRef> {
if constexpr (common::HasMember<decltype(x), decltype(DataRef::u)>) {
return DataRef{x};
Expand All @@ -281,7 +279,7 @@ std::optional<DataRef> ExtractDataRef(
template <typename T>
std::optional<DataRef> ExtractDataRef(
const Expr<T> &expr, bool intoSubstring = false) {
return common::visit(
return std::visit(
[=](const auto &x) { return ExtractDataRef(x, intoSubstring); }, expr.u);
}
template <typename A>
Expand Down Expand Up @@ -330,7 +328,7 @@ bool IsArrayElement(const Expr<T> &expr, bool intoSubstring = true,
template <typename A>
std::optional<NamedEntity> ExtractNamedEntity(const A &x) {
if (auto dataRef{ExtractDataRef(x, true)}) {
return common::visit(
return std::visit(
common::visitors{
[](SymbolRef &&symbol) -> std::optional<NamedEntity> {
return NamedEntity{symbol};
Expand All @@ -356,10 +354,10 @@ struct ExtractCoindexedObjectHelper {
std::optional<CoarrayRef> operator()(const CoarrayRef &x) const { return x; }
template <typename A>
std::optional<CoarrayRef> operator()(const Expr<A> &expr) const {
return common::visit(*this, expr.u);
return std::visit(*this, expr.u);
}
std::optional<CoarrayRef> operator()(const DataRef &dataRef) const {
return common::visit(*this, dataRef.u);
return std::visit(*this, dataRef.u);
}
std::optional<CoarrayRef> operator()(const NamedEntity &named) const {
if (const Component * component{named.UnwrapComponent()}) {
Expand Down Expand Up @@ -451,7 +449,7 @@ Expr<TO> ConvertToType(Expr<SomeKind<FROMCAT>> &&x) {
ConvertToType<Part>(std::move(x)), Expr<Part>{Constant<Part>{zero}}}};
} else if constexpr (FROMCAT == TypeCategory::Complex) {
// Extract and convert the real component of a complex value
return common::visit(
return std::visit(
[&](auto &&z) {
using ZType = ResultType<decltype(z)>;
using Part = typename ZType::Part;
Expand Down Expand Up @@ -505,7 +503,7 @@ common::IfNoLvalue<Expr<Type<TC, TK>>, FROM> ConvertTo(
template <TypeCategory TC, typename FROM>
common::IfNoLvalue<Expr<SomeKind<TC>>, FROM> ConvertTo(
const Expr<SomeKind<TC>> &to, FROM &&from) {
return common::visit(
return std::visit(
[&](const auto &toKindExpr) {
using KindExpr = std::decay_t<decltype(toKindExpr)>;
return AsCategoryExpr(
Expand All @@ -517,7 +515,7 @@ common::IfNoLvalue<Expr<SomeKind<TC>>, FROM> ConvertTo(
template <typename FROM>
common::IfNoLvalue<Expr<SomeType>, FROM> ConvertTo(
const Expr<SomeType> &to, FROM &&from) {
return common::visit(
return std::visit(
[&](const auto &toCatExpr) {
return AsGenericExpr(ConvertTo(toCatExpr, std::move(from)));
},
Expand Down Expand Up @@ -567,7 +565,7 @@ using SameKindExprs =
template <TypeCategory CAT>
SameKindExprs<CAT, 2> AsSameKindExprs(
Expr<SomeKind<CAT>> &&x, Expr<SomeKind<CAT>> &&y) {
return common::visit(
return std::visit(
[&](auto &&kx, auto &&ky) -> SameKindExprs<CAT, 2> {
using XTy = ResultType<decltype(kx)>;
using YTy = ResultType<decltype(ky)>;
Expand Down Expand Up @@ -628,7 +626,7 @@ Expr<SPECIFIC> Combine(Expr<SPECIFIC> &&x, Expr<SPECIFIC> &&y) {
template <template <typename> class OPR, TypeCategory CAT>
Expr<SomeKind<CAT>> PromoteAndCombine(
Expr<SomeKind<CAT>> &&x, Expr<SomeKind<CAT>> &&y) {
return common::visit(
return std::visit(
[](auto &&xy) {
using Ty = ResultType<decltype(xy[0])>;
return AsCategoryExpr(
Expand Down Expand Up @@ -729,7 +727,7 @@ Expr<Type<C, K>> operator/(Expr<Type<C, K>> &&x, Expr<Type<C, K>> &&y) {
}

template <TypeCategory C> Expr<SomeKind<C>> operator-(Expr<SomeKind<C>> &&x) {
return common::visit(
return std::visit(
[](auto &xk) { return Expr<SomeKind<C>>{-std::move(xk)}; }, x.u);
}

Expand Down Expand Up @@ -874,7 +872,7 @@ std::optional<BaseObject> GetBaseObject(const Designator<T> &x) {
}
template <typename T>
std::optional<BaseObject> GetBaseObject(const Expr<T> &x) {
return common::visit([](const auto &y) { return GetBaseObject(y); }, x.u);
return std::visit([](const auto &y) { return GetBaseObject(y); }, x.u);
}
template <typename A>
std::optional<BaseObject> GetBaseObject(const std::optional<A> &x) {
Expand Down Expand Up @@ -1014,8 +1012,7 @@ class ScalarConstantExpander {
return Expand(std::move(x.left())); // Constant<> can be parenthesized
}
template <typename T> Expr<T> Expand(Expr<T> &&x) {
return common::visit(
[&](auto &&x) { return Expr<T>{Expand(std::move(x))}; },
return std::visit([&](auto &&x) { return Expr<T>{Expand(std::move(x))}; },
std::move(x.u));
}

Expand Down
2 changes: 1 addition & 1 deletion flang/include/flang/Evaluate/traverse.h
Expand Up @@ -78,7 +78,7 @@ template <typename Visitor, typename Result> class Traverse {
}
template <typename... A>
Result operator()(const std::variant<A...> &u) const {
return common::visit(visitor_, u);
return std::visit(visitor_, u);
}
template <typename A> Result operator()(const std::vector<A> &x) const {
return CombineContents(x);
Expand Down

0 comments on commit 4ca111d

Please sign in to comment.