Skip to content

Commit f40c724

Browse files
committed
Remove the run* helpers, they're noisy.
We can use a tidy to check how Fn/FnMut/FnOnce concept types are called
1 parent 3260381 commit f40c724

File tree

9 files changed

+38
-120
lines changed

9 files changed

+38
-120
lines changed

subspace/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ target_sources(subspace PUBLIC
5555
"fn/fn_box_defn.h"
5656
"fn/fn_box_impl.h"
5757
"fn/fn_ref.h"
58-
"fn/run_fn.h"
5958
"iter/__private/into_iterator_archetype.h"
6059
"iter/__private/iterator_end.h"
6160
"iter/__private/iterator_loop.h"

subspace/containers/array.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include "subspace/containers/__private/slice_iter.h"
2828
#include "subspace/containers/slice.h"
2929
#include "subspace/fn/fn_concepts.h"
30-
#include "subspace/fn/run_fn.h"
3130
#include "subspace/macros/lifetimebound.h"
3231
#include "subspace/marker/unsafe.h"
3332
#include "subspace/mem/clone.h"
@@ -85,8 +84,7 @@ class Array final {
8584
constexpr static Array with_initializer(::sus::fn::FnMut<T()> auto f) noexcept
8685
requires(::sus::mem::Move<T>)
8786
{
88-
return Array(kWithInitializer, ::sus::move(f),
89-
std::make_index_sequence<N>());
87+
return Array(kWithInitializer, f, std::make_index_sequence<N>());
9088
}
9189

9290
// Uses convertible_to<T> to accept `sus::into()` values. But doesn't use
@@ -289,7 +287,7 @@ class Array final {
289287
requires(N > 0)
290288
Array<R, N> map(MapFn f) && noexcept {
291289
return Array<R, N>::with_initializer([this, &f, i = size_t{0}]() mutable {
292-
return ::sus::run_mut(f, move(storage_.data_[i++]));
290+
return f(::sus::move(storage_.data_[i++]));
293291
});
294292
}
295293

@@ -305,9 +303,9 @@ class Array final {
305303
private:
306304
enum WithInitializer { kWithInitializer };
307305
template <size_t... Is>
308-
constexpr Array(WithInitializer, ::sus::fn::FnMut<T()> auto&& f,
306+
constexpr Array(WithInitializer, ::sus::fn::FnMut<T()> auto& f,
309307
std::index_sequence<Is...>) noexcept
310-
: storage_{((void)Is, ::sus::run_mut(f))...} {}
308+
: storage_{((void)Is, f())...} {}
311309

312310
enum WithValue { kWithValue };
313311
template <size_t... Is>

subspace/containers/slice.h

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include "subspace/construct/into.h"
2525
#include "subspace/containers/__private/slice_iter.h"
2626
#include "subspace/fn/fn_concepts.h"
27-
#include "subspace/fn/run_fn.h"
2827
#include "subspace/iter/iterator_defn.h"
2928
#include "subspace/macros/lifetimebound.h"
3029
#include "subspace/marker/unsafe.h"
@@ -239,10 +238,9 @@ class [[sus_trivial_abi]] Slice {
239238
requires(!std::is_const_v<T>)
240239
{
241240
if (len_ > 0_usize) {
242-
std::stable_sort(data_, data_ + size_t{len_},
243-
[&compare](const T& l, const T& r) {
244-
return ::sus::run_mut(compare, l, r) < 0;
245-
});
241+
std::stable_sort(
242+
data_, data_ + size_t{len_},
243+
[&compare](const T& l, const T& r) { return compare(l, r) < 0; });
246244
}
247245
}
248246

@@ -274,10 +272,9 @@ class [[sus_trivial_abi]] Slice {
274272
requires(!std::is_const_v<T>)
275273
{
276274
if (len_ > 0_usize) {
277-
std::sort(data_, data_ + size_t{len_},
278-
[&compare](const T& l, const T& r) {
279-
return ::sus::run_mut(compare, l, r) < 0;
280-
});
275+
std::sort(
276+
data_, data_ + size_t{len_},
277+
[&compare](const T& l, const T& r) { return compare(l, r) < 0; });
281278
}
282279
}
283280

subspace/containers/vec.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include "subspace/containers/__private/vec_marker.h"
2525
#include "subspace/containers/slice.h"
2626
#include "subspace/fn/fn_concepts.h"
27-
#include "subspace/fn/run_fn.h"
2827
#include "subspace/iter/from_iterator.h"
2928
#include "subspace/iter/into_iterator.h"
3029
#include "subspace/macros/lifetimebound.h"

subspace/fn/fn.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,3 @@
1919
#include "subspace/fn/fn_box_impl.h"
2020
#include "subspace/fn/fn_concepts.h"
2121
#include "subspace/fn/fn_ref.h"
22-
#include "subspace/fn/run_fn.h"

subspace/fn/fn_concepts.h

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ struct Anything {
5656
/// ```
5757
///
5858
/// # Use of `FnOnce`
59-
/// The `sus::run_once()` helper ensures that FnOnce is called correctly.
59+
/// `FnOnce` should be received as an rvalue reference typically, to avoid an
60+
/// unnecessary copy or move operation, but may also be received by value.
6061
///
6162
/// A `FnOnce` should only be called once, and should be moved with
62-
/// `sus::move()` when calling it. It is typically received as an rvalue
63-
/// reference to avoid an unnecessary copy or move operation.
63+
/// `sus::move()` when calling it.
6464
///
6565
/// Calling it multiple times may panic or cause Undefined Behaviour. Not moving
6666
/// the `FnOnce` when calling it may fail to compile, panic, or cause Undefined
@@ -130,11 +130,13 @@ concept FnOnce = requires(F&& f) {
130130
/// ```
131131
///
132132
/// # Use of `FnMut`
133-
/// The `sus::run_mut()` helper ensures that `FnMut` is called correctly.
133+
/// `FnMut` should be received by value reference typically, which isolates any
134+
/// internal mutation to the current function. It may also be received as an
135+
/// lvalue reference if it's desired to have its internal mutations visible to
136+
/// the caller.
134137
///
135-
/// A `FnMut` may be called any number of times, unlike `FnOnce`, and need not
136-
/// be moved when called. It is typically received as a function parameter by
137-
/// value, which isolates any internal mutation to the current function.
138+
/// A `FnMut` may be called any number of times, unlike `FnOnce`, and should not
139+
/// be moved when called.
138140
///
139141
/// # Compatibility
140142
/// Any callable type that satisfies `Fn` or `FnMut` will also satisfy `FnOnce`.
@@ -203,11 +205,12 @@ concept FnMut = requires(F& f) {
203205
/// ```
204206
///
205207
/// # Use of `Fn`
206-
/// The `sus::run()` helper ensures that `Fn` is called correctly.
208+
/// `Fn` should be received by const reference, so that calls to it can be sure
209+
/// to reach the intended const overload of operator() if there is more than
210+
/// one.
207211
///
208-
/// A `Fn` may be called any number of times, unlike `FnOnce`, and need not
209-
/// be moved when called. It is typically received as a function parameter as a
210-
/// const reference, which ensures a non-mutating call operator will be used.
212+
/// A `Fn` may be called any number of times, unlike `FnOnce`, and should not
213+
/// be moved when called.
211214
///
212215
/// # Compatibility
213216
/// Any callable type that satisfies `Fn` will also satisfy `FnMut` and

subspace/fn/run_fn.h

Lines changed: 0 additions & 71 deletions
This file was deleted.

subspace/ops/ord.h

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include "subspace/assertions/check.h"
2121
#include "subspace/fn/fn_concepts.h"
2222
#include "subspace/fn/fn_ref.h"
23-
#include "subspace/fn/run_fn.h"
2423
#include "subspace/macros/lifetimebound.h"
2524
#include "subspace/mem/forward.h"
2625

@@ -111,8 +110,7 @@ constexpr T min_by(
111110
T a sus_lifetimebound, T b sus_lifetimebound,
112111
::sus::fn::FnOnce<std::strong_ordering(const T&, const T&)> auto&&
113112
compare) noexcept {
114-
return ::sus::run_once(::sus::move(compare), a, b) ==
115-
std::strong_ordering::greater
113+
return ::sus::move(compare)(a, b) == std::strong_ordering::greater
116114
? ::sus::forward<T>(b)
117115
: ::sus::forward<T>(a);
118116
}
@@ -133,8 +131,7 @@ template <class T, ::sus::fn::FnMut<::sus::fn::NonVoid(const T&)> KeyFn,
133131
requires(Ord<Key>)
134132
constexpr T min_by_key(T a sus_lifetimebound, T b sus_lifetimebound,
135133
KeyFn f) noexcept {
136-
return ::sus::run_mut(f, a) > ::sus::run_mut(f, b) ? ::sus::forward<T>(b)
137-
: ::sus::forward<T>(a);
134+
return f(a) > f(b) ? ::sus::forward<T>(b) : ::sus::forward<T>(a);
138135
}
139136

140137
/// Compares and returns the maximum of two values.
@@ -169,8 +166,7 @@ constexpr T max_by(
169166
T a sus_lifetimebound, T b sus_lifetimebound,
170167
::sus::fn::FnOnce<std::strong_ordering(const T&, const T&)> auto&&
171168
compare) noexcept {
172-
return ::sus::run_once(::sus::move(compare), a, b) ==
173-
std::strong_ordering::greater
169+
return ::sus::move(compare)(a, b) == std::strong_ordering::greater
174170
? ::sus::forward<T>(a)
175171
: ::sus::forward<T>(b);
176172
}
@@ -191,8 +187,7 @@ template <class T, ::sus::fn::FnMut<::sus::fn::NonVoid(const T&)> KeyFn,
191187
requires(Ord<Key>)
192188
constexpr T max_by_key(T a sus_lifetimebound, T b sus_lifetimebound,
193189
KeyFn f) noexcept {
194-
return ::sus::run_mut(f, a) > ::sus::run_mut(f, b) ? ::sus::forward<T>(a)
195-
: ::sus::forward<T>(b);
190+
return f(a) > f(b) ? ::sus::forward<T>(a) : ::sus::forward<T>(b);
196191
}
197192

198193
/// Restrict a value to a certain interval.

subspace/option/option.h

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include "subspace/assertions/unreachable.h"
2828
#include "subspace/construct/default.h"
2929
#include "subspace/fn/fn_concepts.h"
30-
#include "subspace/fn/run_fn.h"
3130
#include "subspace/iter/from_iterator.h"
3231
#include "subspace/iter/into_iterator.h"
3332
#include "subspace/macros/always_inline.h"
@@ -452,7 +451,7 @@ class Option final {
452451
if (t_.state() == Some) {
453452
return t_.take_and_set_none();
454453
} else {
455-
return ::sus::run_once(::sus::move(f));
454+
return ::sus::move(f)();
456455
}
457456
}
458457

@@ -522,7 +521,7 @@ class Option final {
522521
/// the Option, and instead it can not be called on rvalues.
523522
T& get_or_insert_with(::sus::fn::FnOnce<T()> auto&& f) & noexcept {
524523
if (t_.state() == None) {
525-
t_.construct_from_none(move_to_storage(::sus::run_once(::sus::move(f))));
524+
t_.construct_from_none(move_to_storage(::sus::move(f)()));
526525
}
527526
return t_.val_mut();
528527
}
@@ -551,7 +550,7 @@ class Option final {
551550
class R = std::invoke_result_t<MapFn&&, T&&>>
552551
constexpr auto map(MapFn&& m) && noexcept {
553552
if (t_.state() == Some) {
554-
return Option<R>(::sus::run_once(::sus::move(m), t_.take_and_set_none()));
553+
return Option<R>(::sus::move(m)(t_.take_and_set_none()));
555554
} else {
556555
return Option<R>::none();
557556
}
@@ -567,7 +566,7 @@ class Option final {
567566
class R = std::invoke_result_t<MapFn&&, T&&>>
568567
constexpr R map_or(R default_result, MapFn&& m) && noexcept {
569568
if (t_.state() == Some) {
570-
return ::sus::run_once(::sus::move(m), t_.take_and_set_none());
569+
return ::sus::move(m)(t_.take_and_set_none());
571570
} else {
572571
return default_result;
573572
}
@@ -582,9 +581,9 @@ class Option final {
582581
requires(std::is_same_v<D, R>)
583582
constexpr R map_or_else(DefaultFn&& default_fn, MapFn&& m) && noexcept {
584583
if (t_.state() == Some) {
585-
return ::sus::run_once(::sus::move(m), t_.take_and_set_none());
584+
return ::sus::move(m)(t_.take_and_set_none());
586585
} else {
587-
return ::sus::run_once(::sus::move(default_fn));
586+
return ::sus::move(default_fn)();
588587
}
589588
}
590589

@@ -597,7 +596,7 @@ class Option final {
597596
constexpr Option<T> filter(
598597
::sus::fn::FnOnce<bool(const T&)> auto&& p) && noexcept {
599598
if (t_.state() == Some) {
600-
if (::sus::run_once(::sus::move(p), t_.val())) {
599+
if (::sus::move(p)(t_.val())) {
601600
return Option(t_.take_and_set_none());
602601
} else {
603602
// The state has to become None, and we must destroy the inner T.
@@ -635,7 +634,7 @@ class Option final {
635634
requires(::sus::option::__private::IsOptionType<R>::value)
636635
constexpr Option<U> and_then(AndFn&& f) && noexcept {
637636
if (t_.state() == Some)
638-
return ::sus::run_once(::sus::move(f), t_.take_and_set_none());
637+
return ::sus::move(f)(t_.take_and_set_none());
639638
else
640639
return Option<U>::none();
641640
}
@@ -656,7 +655,7 @@ class Option final {
656655
if (t_.state() == Some)
657656
return Option(t_.take_and_set_none());
658657
else
659-
return ::sus::run_once(::sus::move(f));
658+
return ::sus::move(f)();
660659
}
661660

662661
/// Consumes this Option and returns an Option, holding the value from either
@@ -710,7 +709,7 @@ class Option final {
710709
if (t_.state() == Some)
711710
return Result::with(t_.take_and_set_none());
712711
else
713-
return Result::with_err(::sus::run_once(::sus::move(f)));
712+
return Result::with_err(::sus::move(f)());
714713
}
715714

716715
/// Transposes an #Option of a #Result into a #Result of an #Option.

0 commit comments

Comments
 (0)