Skip to content

Commit

Permalink
test: discard unused parameters but not void expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
JohelEGP committed Dec 12, 2023
1 parent e3ad1b5 commit d0986ee
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 40 deletions.
17 changes: 8 additions & 9 deletions regression-tests/pure2-bugfix-for-deducible-parameters.cpp2
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Dependent, non-deducible parameters
// are wrapped like non-dependent parameters.
// Dependent, non-deducible parameters are wrapped like non-dependent parameters.
init: <T> (out x: std::integral_constant<i32, T::value>) = { x = (); }
init: <T> (out x: std::integral_constant<i32, T::value>, _: T) = { x = (); }
id: <T> (x: std::integral_constant<i32, T::value>) -> forward _ = x;
Expand All @@ -13,21 +12,21 @@ main: () = {
assert(id<zero>(z)& == z&);

// Deducible parameters.
_ = :v = 0;
_ = :<T> (x: std::vector<T>) = {}(:std::vector<i32> = ());
_ = :<T> (x: std::vector<std::vector<T>>) = {}(:std::vector<std::vector<i32>> = ());
_ = :v = 0;
:<T> (_: std::vector<T>) = {}(:std::vector<i32> = ());
:<T> (_: std::vector<std::vector<T>>) = {}(:std::vector<std::vector<i32>> = ());
// _ = :<T, U> (x: std::pair<T, typename U::value_type>, y: U) = {}(:std::pair = (0, 0), z); // Blocked on #727.
_ = :<T, U> (x: std::array<T, U::value>, y: U) = {}(:std::array<i32, 0> = (), z);
:<T, U> (_: std::array<T, U::value>, _: U) = {}(:std::array<i32, 0> = (), z);
init(out z, z);
id(z, z);

// Test that these are emitted unwrapped in case they are deducible.
(copy f := :<T> (x: std::vector<std::type_identity_t<T>>) = {})
(copy f := :<T> (_: std::vector<std::type_identity_t<T>>) = {})
static_assert(!std::is_invocable_v<decltype(f), std::vector<i32>>, "`T` is non-deducible.");
(copy f := :<T> (x: std::vector<std::vector<T>>) = {})
(copy f := :<T> (_: std::vector<std::vector<T>>) = {})
static_assert(std::is_invocable_v<decltype(f), std::vector<std::vector<i32>>>, "`T` is deducible.");
}

v: <T> type = {
operator=: (out this, x: T) = { }
operator=: (out this, _: T) = { }
}
8 changes: 4 additions & 4 deletions regression-tests/pure2-bugfix-for-dependent-types.cpp2
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ main: () = {
_ = :() = { _ = :() = { _ = :<T> () = { _ = :() = { _ = :T::value_type = (); }; }; }; };
_ = :() = { _ = :<T> () = { _ = :() = { _ = :() = { _ = :T::value_type = (); }; }; }; };
_ = :<T> () = { _ = :() = { _ = :() = { _ = :() = { _ = :T::value_type = (); }; }; }; };
_ = :<T> () = { _ = :() = { _ = :() = { _ = :(x: T::value_type) = {}; }; }; };
_ = :<T> () = { _ = :() = { _ = :(x: T::value_type) = { _ = :() = {}; }; }; };
_ = :<T> () = { _ = :(x: T::value_type) = { _ = :() = { _ = :() = {}; }; }; };
_ = :<T> (x: T::value_type) = { _ = :() = { _ = :() = { _ = :() = {}; }; }; };
_ = :<T> () = { _ = :() = { _ = :() = { _ = :(_: T::value_type) = {}; }; }; };
_ = :<T> () = { _ = :() = { _ = :(_: T::value_type) = { _ = :() = {}; }; }; };
_ = :<T> () = { _ = :(_: T::value_type) = { _ = :() = { _ = :() = {}; }; }; };
_ = :<T> (_: T::value_type) = { _ = :() = { _ = :() = { _ = :() = {}; }; }; };

// Lookup.
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,39 @@

#line 1 "pure2-bugfix-for-deducible-parameters.cpp2"

#line 31 "pure2-bugfix-for-deducible-parameters.cpp2"
#line 30 "pure2-bugfix-for-deducible-parameters.cpp2"
template<typename T> class v;


//=== Cpp2 type definitions and function declarations ===========================

#line 1 "pure2-bugfix-for-deducible-parameters.cpp2"
// Dependent, non-deducible parameters
// are wrapped like non-dependent parameters.
#line 3 "pure2-bugfix-for-deducible-parameters.cpp2"
// Dependent, non-deducible parameters are wrapped like non-dependent parameters.
#line 2 "pure2-bugfix-for-deducible-parameters.cpp2"
template<typename T> auto init(cpp2::out<std::integral_constant<cpp2::i32,T::value>> x) -> void;
template<typename T> auto init(cpp2::out<std::integral_constant<cpp2::i32,T::value>> x, [[maybe_unused]] T const& unnamed_param_2) -> void;
template<typename T> [[nodiscard]] auto id(cpp2::in<std::integral_constant<cpp2::i32,T::value>> x) -> auto&&;
template<typename T> auto id(cpp2::in<std::integral_constant<cpp2::i32,T::value>> x, T const& y) -> void;

auto main() -> int;

#line 31 "pure2-bugfix-for-deducible-parameters.cpp2"
#line 30 "pure2-bugfix-for-deducible-parameters.cpp2"
template<typename T> class v {
public: explicit v(T const& x);
#line 32 "pure2-bugfix-for-deducible-parameters.cpp2"
public: auto operator=(T const& x) -> v& ;
public: explicit v([[maybe_unused]] T const& unnamed_param_2);
#line 31 "pure2-bugfix-for-deducible-parameters.cpp2"
public: auto operator=([[maybe_unused]] T const& unnamed_param_2) -> v& ;
public: v(v const&) = delete; /* No 'that' constructor, suppress copy */
public: auto operator=(v const&) -> void = delete;

#line 33 "pure2-bugfix-for-deducible-parameters.cpp2"
#line 32 "pure2-bugfix-for-deducible-parameters.cpp2"
};


//=== Cpp2 function definitions =================================================

#line 1 "pure2-bugfix-for-deducible-parameters.cpp2"

#line 3 "pure2-bugfix-for-deducible-parameters.cpp2"
#line 2 "pure2-bugfix-for-deducible-parameters.cpp2"
template<typename T> auto init(cpp2::out<std::integral_constant<cpp2::i32,T::value>> x) -> void{x.construct(); }
template<typename T> auto init(cpp2::out<std::integral_constant<cpp2::i32,T::value>> x, [[maybe_unused]] T const& unnamed_param_2) -> void{x.construct(); }
template<typename T> [[nodiscard]] auto id(cpp2::in<std::integral_constant<cpp2::i32,T::value>> x) -> auto&& { return x; }
Expand All @@ -55,33 +54,33 @@ auto main() -> int{
cpp2::Default.expects(&id<zero>(z.value()) == &z.value(), "");

// Deducible parameters.
static_cast<void>(v{0});
static_cast<void>([]<typename T>(std::vector<T> const& x) mutable -> void{}(std::vector<cpp2::i32>{}));
static_cast<void>([]<typename T>(std::vector<std::vector<T>> const& x) mutable -> void{}(std::vector<std::vector<cpp2::i32>>{}));
static_cast<void>(v{ 0});
[]<typename T>([[maybe_unused]] std::vector<T> const& unnamed_param_1) mutable -> void{}(std::vector<cpp2::i32>{});
[]<typename T>([[maybe_unused]] std::vector<std::vector<T>> const& unnamed_param_1) mutable -> void{}(std::vector<std::vector<cpp2::i32>>{});
// _ = :<T, U> (x: std::pair<T, typename U::value_type>, y: U) = {}(:std::pair = (0, 0), z); // Blocked on #727.
static_cast<void>([]<typename T, typename U>(std::array<T,U::value> const& x, U const& y) mutable -> void{}(std::array<cpp2::i32,0>{}, z.value()));
[]<typename T, typename U>([[maybe_unused]] std::array<T,U::value> const& unnamed_param_1, [[maybe_unused]] U const& unnamed_param_2) mutable -> void{}(std::array<cpp2::i32,0>{}, z.value());
init(cpp2::out(&z.value()), z.value());
id(z.value(), std::move(z.value()));
{
auto f = []<typename T>(std::vector<std::type_identity_t<T>> const& x) mutable -> void{};
auto f = []<typename T>([[maybe_unused]] std::vector<std::type_identity_t<T>> const& unnamed_param_1) mutable -> void{};

// Test that these are emitted unwrapped in case they are deducible.

#line 26 "pure2-bugfix-for-deducible-parameters.cpp2"
#line 25 "pure2-bugfix-for-deducible-parameters.cpp2"
static_assert(!(std::is_invocable_v<decltype(f),std::vector<cpp2::i32>>), "`T` is non-deducible.");
}
{
auto f = []<typename T>(std::vector<std::vector<T>> const& x) mutable -> void{};
auto f = []<typename T>([[maybe_unused]] std::vector<std::vector<T>> const& unnamed_param_1) mutable -> void{};

#line 28 "pure2-bugfix-for-deducible-parameters.cpp2"
#line 27 "pure2-bugfix-for-deducible-parameters.cpp2"
static_assert(std::is_invocable_v<decltype(std::move(f)),std::vector<std::vector<cpp2::i32>>>, "`T` is deducible.");
}
#line 29 "pure2-bugfix-for-deducible-parameters.cpp2"
#line 28 "pure2-bugfix-for-deducible-parameters.cpp2"
}

#line 32 "pure2-bugfix-for-deducible-parameters.cpp2"
template <typename T> v<T>::v(T const& x){}
#line 32 "pure2-bugfix-for-deducible-parameters.cpp2"
template <typename T> auto v<T>::operator=(T const& x) -> v& {
#line 31 "pure2-bugfix-for-deducible-parameters.cpp2"
template <typename T> v<T>::v([[maybe_unused]] T const& unnamed_param_2){}
#line 31 "pure2-bugfix-for-deducible-parameters.cpp2"
template <typename T> auto v<T>::operator=([[maybe_unused]] T const& unnamed_param_2) -> v& {
return *this; }

Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ auto main() -> int{
static_cast<void>([]() mutable -> void{static_cast<void>([]() mutable -> void{static_cast<void>([]<typename T>() mutable -> void{static_cast<void>([]() mutable -> void{static_cast<void>(typename T::value_type{}); }); }); }); });
static_cast<void>([]() mutable -> void{static_cast<void>([]<typename T>() mutable -> void{static_cast<void>([]() mutable -> void{static_cast<void>([]() mutable -> void{static_cast<void>(typename T::value_type{}); }); }); }); });
static_cast<void>([]<typename T>() mutable -> void{static_cast<void>([]() mutable -> void{static_cast<void>([]() mutable -> void{static_cast<void>([]() mutable -> void{static_cast<void>(typename T::value_type{}); }); }); }); });
static_cast<void>([]<typename T>() mutable -> void{static_cast<void>([]() mutable -> void{static_cast<void>([]() mutable -> void{static_cast<void>([](cpp2::in<typename T::value_type> x) mutable -> void{}); }); }); });
static_cast<void>([]<typename T>() mutable -> void{static_cast<void>([]() mutable -> void{static_cast<void>([](cpp2::in<typename T::value_type> x) mutable -> void{static_cast<void>([]() mutable -> void{}); }); }); });
static_cast<void>([]<typename T>() mutable -> void{static_cast<void>([](cpp2::in<typename T::value_type> x) mutable -> void{static_cast<void>([]() mutable -> void{static_cast<void>([]() mutable -> void{}); }); }); });
static_cast<void>([]<typename T>(cpp2::in<typename T::value_type> x) mutable -> void{static_cast<void>([]() mutable -> void{static_cast<void>([]() mutable -> void{static_cast<void>([]() mutable -> void{}); }); }); });
static_cast<void>([]<typename T>() mutable -> void{static_cast<void>([]() mutable -> void{static_cast<void>([]() mutable -> void{static_cast<void>([]([[maybe_unused]] cpp2::in<typename T::value_type> unnamed_param_1) mutable -> void{}); }); }); });
static_cast<void>([]<typename T>() mutable -> void{static_cast<void>([]() mutable -> void{static_cast<void>([]([[maybe_unused]] cpp2::in<typename T::value_type> unnamed_param_1) mutable -> void{static_cast<void>([]() mutable -> void{}); }); }); });
static_cast<void>([]<typename T>() mutable -> void{static_cast<void>([]([[maybe_unused]] cpp2::in<typename T::value_type> unnamed_param_1) mutable -> void{static_cast<void>([]() mutable -> void{static_cast<void>([]() mutable -> void{}); }); }); });
static_cast<void>([]<typename T>([[maybe_unused]] cpp2::in<typename T::value_type> unnamed_param_1) mutable -> void{static_cast<void>([]() mutable -> void{static_cast<void>([]() mutable -> void{static_cast<void>([]() mutable -> void{}); }); }); });

// Lookup.
{
Expand Down

0 comments on commit d0986ee

Please sign in to comment.