Skip to content

Commit 489028e

Browse files
snarkmastermeta-codesync[bot]
authored andcommitted
rename "non-value" to "error-or-stopped"
Summary: See predecessor D91389724. Reviewed By: ispeters Differential Revision: D91389725 fbshipit-source-id: 02c5116c735273a7ac091250efc7b66c2d43dd22
1 parent 62fade0 commit 489028e

7 files changed

Lines changed: 143 additions & 137 deletions

File tree

folly/result/test/enrich_non_value_bench.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ FOLLY_ALWAYS_INLINE void bench_enrich_non_value(size_t iters, EnrichFn&& fn) {
3939
for (size_t i = 0; i < iters; ++i) {
4040
// An immortal avoids measuring the cost of dynamic `std::exception_ptr`
4141
// for the base error -- otherwise, the baseline would be closer to 50ns.
42-
auto enriched = fn(non_value_result{immortal_rich_error<BenchErr>});
42+
auto enriched = fn(error_or_stopped{immortal_rich_error<BenchErr>});
4343
folly::compiler_must_not_predict(enriched);
4444
numOkay += nullptr !=
4545
std::move(enriched)
@@ -51,29 +51,29 @@ FOLLY_ALWAYS_INLINE void bench_enrich_non_value(size_t iters, EnrichFn&& fn) {
5151
}
5252

5353
BENCHMARK(non_enriched_baseline, n) {
54-
bench_enrich_non_value<BenchErr>(n, [](non_value_result&& nvr) {
55-
return std::move(nvr);
54+
bench_enrich_non_value<BenchErr>(n, [](error_or_stopped&& eos) {
55+
return std::move(eos);
5656
});
5757
}
5858

5959
BENCHMARK(enrich_non_value_location_only, n) {
6060
bench_enrich_non_value<detail::enriched_non_value>(
6161
n,
62-
[](non_value_result&& nvr) { return enrich_non_value(std::move(nvr)); });
62+
[](error_or_stopped&& eos) { return enrich_non_value(std::move(eos)); });
6363
}
6464

6565
BENCHMARK(enrich_non_value_location_plus_static_message, n) {
6666
bench_enrich_non_value<detail::enriched_non_value>(
67-
n, [](non_value_result&& nvr) {
68-
return enrich_non_value(std::move(nvr), "context");
67+
n, [](error_or_stopped&& eos) {
68+
return enrich_non_value(std::move(eos), "context");
6969
});
7070
}
7171

7272
BENCHMARK(enrich_non_value_location_plus_formatted_message, n) {
7373
int value = 42;
7474
bench_enrich_non_value<detail::enriched_non_value>(
75-
n, [&](non_value_result&& nvr) {
76-
return enrich_non_value(std::move(nvr), "value={}", value);
75+
n, [&](error_or_stopped&& eos) {
76+
return enrich_non_value(std::move(eos), "value={}", value);
7777
});
7878
}
7979

folly/result/test/enrich_non_value_test.cpp

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -59,23 +59,23 @@ TEST(RichErrorBaseFormatTest, SameErrorDirectThenUnderlying2) {
5959
TEST(EnrichNonValueTest, accessEnrichedAndUnderlyingException) {
6060
std::string bare_msg = "folly::TinyErr";
6161

62-
auto assertUnderlying = [&](auto& nvr, const std::string& re) {
62+
auto assertUnderlying = [&](auto& eos, const std::string& re) {
6363
{
6464
// Only `rich_exception_ptr` can show the enrichment info AND expose the
6565
// underlying exception. By converting to a bare `exception_ptr`, we
6666
// discard the enrichment chain.
67-
auto eptr = copy(nvr).to_exception_ptr_slow();
67+
auto eptr = copy(eos).to_exception_ptr_slow();
6868
EXPECT_EQ(bare_msg, fmt::format("{}", *get_rich_error(eptr)));
6969
EXPECT_FALSE(get_exception<detail::enriched_non_value>(eptr));
7070
EXPECT_TRUE(get_exception<TinyErr>(eptr));
7171
EXPECT_TRUE(get_exception<rich_error<TinyErr>>(eptr));
7272
}
73-
checkFormatViaGet<TinyErr, rich_error_base, std::exception>(nvr, re);
73+
checkFormatViaGet<TinyErr, rich_error_base, std::exception>(eos, re);
7474

7575
// Enrichment is transparent: although `enriched_non_value` is itself a
7676
// `rich_error_base`, all public APIs (except `get_outer_exception()` go to
7777
// the underlying error.
78-
auto rex = get_rich_error(nvr);
78+
auto rex = get_rich_error(eos);
7979
EXPECT_FALSE(dynamic_cast<const detail::enriched_non_value*>(rex.get()));
8080
EXPECT_TRUE(dynamic_cast<const TinyErr*>(rex.get()));
8181
EXPECT_TRUE(dynamic_cast<const rich_error<TinyErr>*>(rex.get()));
@@ -92,13 +92,13 @@ TEST(EnrichNonValueTest, accessEnrichedAndUnderlyingException) {
9292
EXPECT_TRUE(std::nullopt == get_rich_error_code<A1>(*rex));
9393
};
9494

95-
non_value_result nvr0{rich_error<TinyErr>{}};
96-
const auto* innerErr = get_exception<TinyErr>(nvr0).get();
95+
error_or_stopped eos0{rich_error<TinyErr>{}};
96+
const auto* innerErr = get_exception<TinyErr>(eos0).get();
9797

9898
// Cover the "outer" `rich_error_base` interface (except codes)
99-
auto assertOuter = [&](auto& nvr, int err_line, const char* msg = "") {
99+
auto assertOuter = [&](auto& eos, int err_line, const char* msg = "") {
100100
auto& outer =
101-
*std::move(nvr)
101+
*std::move(eos)
102102
.release_rich_exception_ptr()
103103
.template get_outer_exception<detail::enriched_non_value>();
104104
EXPECT_EQ(err_line, outer.source_location().line());
@@ -112,19 +112,19 @@ TEST(EnrichNonValueTest, accessEnrichedAndUnderlyingException) {
112112

113113
// Add and test 1 enrichment
114114
auto err_line1 = source_location::current().line() + 1;
115-
auto nvr1 = enrich_non_value(std::move(nvr0));
115+
auto eos1 = enrich_non_value(std::move(eos0));
116116

117-
assertOuter(nvr1, err_line1);
117+
assertOuter(eos1, err_line1);
118118
assertUnderlying(
119-
nvr1,
119+
eos1,
120120
fmt::format("{} \\[via\\] {}:{}", bare_msg, test_file_name, err_line1));
121121

122122
// Wrap a second enrichment to ensure skip-to-underlying, not skip-to-next
123123
auto err_line2 = source_location::current().line() + 1;
124-
auto nvr2 = enrich_non_value(std::move(nvr1), "literal");
125-
assertOuter(nvr2, err_line2, "literal");
124+
auto eos2 = enrich_non_value(std::move(eos1), "literal");
125+
assertOuter(eos2, err_line2, "literal");
126126
assertUnderlying(
127-
nvr2,
127+
eos2,
128128
fmt::format(
129129
"{} \\[via\\] literal @ {}:{} \\[after\\] {}:{}",
130130
bare_msg,
@@ -136,17 +136,17 @@ TEST(EnrichNonValueTest, accessEnrichedAndUnderlyingException) {
136136

137137
// The underlying error doesn't have to be a `rich_error_base`.
138138
TEST(EnrichNonValueTest, enrichPlainError) {
139-
auto nvr = enrich_non_value(
139+
auto eos = enrich_non_value(
140140
enrich_non_value(
141-
enrich_non_value(non_value_result{std::logic_error{"inner"}}), "msg"),
141+
enrich_non_value(error_or_stopped{std::logic_error{"inner"}}), "msg"),
142142
"format{}",
143143
std::string{"ted"});
144144

145145
// `get_exception` makes a `logic_error*` quack-alike with rich formatting
146-
const std::logic_error* ex{get_exception<std::logic_error>(nvr)};
146+
const std::logic_error* ex{get_exception<std::logic_error>(eos)};
147147
EXPECT_STREQ("inner", ex->what());
148148
checkFormatViaGet<std::logic_error, std::exception>(
149-
nvr,
149+
eos,
150150
fmt::format(
151151
"std::logic_error: inner \\[via\\] formatted @ {}:[0-9]+ \\[after\\] "
152152
"msg @ {}:[0-9]+ \\[after\\] {}:[0-9]+",
@@ -180,7 +180,7 @@ TEST(EnrichNonValueTest, enrichResultWithValue) {
180180
// Add enrichment to a non-value `result`
181181
TEST(EnrichNonValueTest, enrichResultWithNonValue) {
182182
auto r = enrich_non_value(
183-
result<int>{non_value_result{std::logic_error{"inner"}}}, "msg");
183+
result<int>{error_or_stopped{std::logic_error{"inner"}}}, "msg");
184184
static_assert(std::same_as<result<int>, decltype(r)>);
185185
EXPECT_FALSE(r.has_value());
186186

@@ -195,8 +195,8 @@ TEST(EnrichNonValueTest, enrichResultWithNonValue) {
195195

196196
// Codes are forwarded to the underlying error, and formatted.
197197
TEST(EnrichNonValueTest, retrieveCodeDelegatesToUnderlying) {
198-
auto nvr = enrich_non_value(
199-
enrich_non_value(non_value_result{make_coded_rich_error(A1::ONE_A1)}));
198+
auto eos = enrich_non_value(
199+
enrich_non_value(error_or_stopped{make_coded_rich_error(A1::ONE_A1)}));
200200

201201
// If we insist on inspecting the outer error (I'm not seeing how this would
202202
// happen in normal usage), it has no code. Yes, we could easily forward the
@@ -205,16 +205,16 @@ TEST(EnrichNonValueTest, retrieveCodeDelegatesToUnderlying) {
205205
EXPECT_EQ(
206206
std::nullopt,
207207
get_rich_error_code<A1>(
208-
*copy(nvr)
208+
*copy(eos)
209209
.release_rich_exception_ptr()
210210
.get_outer_exception<detail::enriched_non_value>()));
211211

212212
// Normal access first resolves the underlying error, so code access works.
213-
EXPECT_EQ(A1::ONE_A1, get_rich_error_code<A1>(nvr));
213+
EXPECT_EQ(A1::ONE_A1, get_rich_error_code<A1>(eos));
214214

215215
// The `get_exception` pointer has enriched formatting, including the code.
216216
checkFormatViaGet<coded_rich_error<A1>, rich_error_base, std::exception>(
217-
nvr,
217+
eos,
218218
fmt::format(
219219
"A1=1 @ {}:[0-9]+ \\[via\\] {}:[0-9]+ \\[after\\] {}:[0-9]+",
220220
test_file_name,

folly/result/test/or_unwind_rich_test.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,25 +50,25 @@ TEST(OrUnwindRich, error) {
5050
"std::logic_error: {} @ {}:{}", msgViaCtx, test_file_name, err_line);
5151
};
5252

53-
checkEnrichedError( // `result` in non-value state
53+
checkEnrichedError( // `result` in error-or-stopped state
5454
[&]() -> result<> {
55-
result<int> r{non_value_result{std::logic_error{"err1"}}};
55+
result<int> r{error_or_stopped{std::logic_error{"err1"}}};
5656
err_line = std::source_location::current().line() + 1;
5757
(void)co_await or_unwind_rich(std::move(r), "ctx1");
5858
}(),
5959
expectedMsg("err1 [via] ctx1"));
6060

61-
checkEnrichedError( // `non_value_result`
61+
checkEnrichedError( // `error_or_stopped`
6262
[&]() -> result<> {
63-
non_value_result nvr{std::logic_error{"err2"}};
63+
error_or_stopped eos{std::logic_error{"err2"}};
6464
err_line = std::source_location::current().line() + 1;
65-
co_await or_unwind_rich(std::move(nvr), "ctx2");
65+
co_await or_unwind_rich(std::move(eos), "ctx2");
6666
}(),
6767
expectedMsg("err2 [via] ctx2"));
6868

6969
checkEnrichedError( // `result` with format args
7070
[&]() -> result<> {
71-
result<int> r{non_value_result{std::logic_error{"err3"}}};
71+
result<int> r{error_or_stopped{std::logic_error{"err3"}}};
7272
err_line = std::source_location::current().line() + 1;
7373
(void)co_await or_unwind_rich(std::move(r), "x={} y={}", 10, 20);
7474
}(),
@@ -85,9 +85,9 @@ TEST(OrUnwindRich, stopped) {
8585
EXPECT_TRUE(res.has_stopped());
8686
auto msg = "folly::OperationCancelled: coroutine operation cancelled";
8787
// Temporary workaround for `static_assert` against testing for OC in
88-
// `result.h`. Future: Once `result` or `non_value_result` is formattable,
88+
// `result.h`. Future: Once `result` or `error_or_stopped` is formattable,
8989
// we can avoid this hackery.
90-
auto rep = std::move(res).non_value().release_rich_exception_ptr();
90+
auto rep = std::move(res).error_or_stopped().release_rich_exception_ptr();
9191
EXPECT_EQ(
9292
fmt::format("{} [via] ctx @ {}:{}", msg, test_file_name, err_line),
9393
fmt::format("{}", get_exception<OperationCancelled>(rep)));

folly/result/test/or_unwind_test.cpp

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
// - Awaiter: `or_unwind` (&, const&, &&), `or_unwind_owning`
3030
// - Context: `result` coroutine, `now_task` coroutine
3131
// - Inner type: `void`, `int` and refs, `string`, `unique_ptr` and refs
32-
// - Result-like container: `result`, `value_only_result`, `non_value_result`
32+
// - Result-like container: `result`, `value_only_result`, `error_or_stopped`
3333
// - States: value, error, stopped
3434

3535
#if FOLLY_HAS_RESULT
@@ -90,7 +90,8 @@ consteval void checkAwaitResumeType() {
9090
decltype(std::declval<Awaitable>().await_resume())>);
9191
}
9292

93-
// Check `await_resume()` types for rvalue-only types (e.g. `non_value_result`).
93+
// Check `await_resume()` types for rvalue-only types (e.g.
94+
// `error_or_stopped`).
9495
template <typename ResultT, typename RvalueT, typename OwningT>
9596
consteval void checkRvalueAwaitResumeTypes() {
9697
checkAwaitResumeType<RvalueT, decltype(or_unwind(FOLLY_DECLVAL(ResultT)))>();
@@ -150,9 +151,9 @@ ResultT makeResultWithValue(MakeInner&& makeInner) {
150151
}
151152
}
152153

153-
// An empty `non_value_result` made from an empty `exception_wrapper`.
154-
inline non_value_result emptyNonValue() {
155-
return non_value_result::make_legacy_error_or_cancellation_slow(
154+
// An empty `error_or_stopped` made from an empty `exception_wrapper`.
155+
inline error_or_stopped emptyErrorOrStopped() {
156+
return error_or_stopped::make_legacy_error_or_cancellation_slow(
156157
detail::result_private_t{}, exception_wrapper{});
157158
}
158159

@@ -170,16 +171,17 @@ void forEachOrUnwindVariant(MakeResult makeResult, Check&& check) {
170171
check(tag_t<Context>{}, or_unwind(std::as_const(val)));
171172
// Lvalue refs must NOT mutate the original (error is copied, not moved).
172173
// Users don't expect `co_await or_unwind(r)` to mutate `r`.
173-
if constexpr (requires { val.non_value(); }) {
174-
EXPECT_TRUE(hasValue || (emptyNonValue() != val.non_value()));
174+
if constexpr (requires { val.error_or_stopped(); }) {
175+
EXPECT_TRUE(
176+
hasValue || (emptyErrorOrStopped() != val.error_or_stopped()));
175177
}
176178
}
177179
check(tag_t<Context>{}, or_unwind_owning(makeResult()));
178180
// By rvalue ref -- error SHOULD be moved out.
179181
check(tag_t<Context>{}, or_unwind(std::move(val)));
180-
if constexpr (requires { val.non_value(); }) {
182+
if constexpr (requires { val.error_or_stopped(); }) {
181183
// NOLINTNEXTLINE(bugprone-use-after-move)
182-
EXPECT_TRUE(hasValue || (emptyNonValue() == val.non_value()));
184+
EXPECT_TRUE(hasValue || (emptyErrorOrStopped() == val.error_or_stopped()));
183185
}
184186
}
185187

@@ -220,19 +222,19 @@ struct CheckExtractRef {
220222
}
221223
};
222224

223-
// Test non-value propagation across all applicable variants.
224-
template <typename MakeNonValue, typename Verify>
225-
void testNonValue(MakeNonValue makeNonValue, Verify verify) {
225+
// Test error-or-stopped propagation across all applicable variants.
226+
template <typename MakeErrorOrStopped, typename Verify>
227+
void testErrorOrStopped(MakeErrorOrStopped makeErrorOrStopped, Verify verify) {
226228
forEachOrUnwindVariant<InResult>(
227-
makeNonValue, [&](tag_t<InResult>, auto&& awaitable) {
229+
makeErrorOrStopped, [&](tag_t<InResult>, auto&& awaitable) {
228230
auto out = InResult::run([&]() -> InResult::Coro<void> {
229231
(void)co_await must_use_immediately_unsafe_mover(
230232
static_cast<decltype(awaitable)>(awaitable))();
231233
});
232234
verify(out);
233235
});
234236
forEachOrUnwindVariant<InTask>(
235-
makeNonValue, [&](tag_t<InTask>, auto&& awaitable) {
237+
makeErrorOrStopped, [&](tag_t<InTask>, auto&& awaitable) {
236238
auto out = InTask::run([&]() -> InTask::Coro<void> {
237239
(void)co_await must_use_immediately_unsafe_mover(
238240
static_cast<decltype(awaitable)>(awaitable))();
@@ -242,18 +244,18 @@ void testNonValue(MakeNonValue makeNonValue, Verify verify) {
242244
}
243245

244246
template <typename... Makes>
245-
void testNonValueErrors(Makes... makes) {
247+
void testErrorOrStoppedErrors(Makes... makes) {
246248
auto verify = [](auto& out) {
247249
EXPECT_TRUE(!out.has_value() && !out.has_stopped());
248250
EXPECT_NE(nullptr, get_exception<std::runtime_error>(out));
249251
};
250-
(testNonValue(makes, verify), ...);
252+
(testErrorOrStopped(makes, verify), ...);
251253
}
252254

253255
template <typename... Makes>
254-
void testNonValueStopped(Makes... makes) {
256+
void testErrorOrStoppedStopped(Makes... makes) {
255257
auto verify = [](auto& out) { EXPECT_TRUE(out.has_stopped()); };
256-
(testNonValue(makes, verify), ...);
258+
(testErrorOrStopped(makes, verify), ...);
257259
}
258260

259261
// Test all `or_unwind...` flavors in both `result` and `now_task` coros.
@@ -278,12 +280,12 @@ void testOrUnwind(MakeInner makeInner, const CheckValue& checkValue) {
278280
forEachOrUnwindVariant<InTask>(makeRes, checkValue);
279281
}
280282

281-
// Propagate error/stopped, for result types with `.non_value()`
282-
if constexpr (requires { FOLLY_DECLVAL(ResultT).non_value(); }) {
283-
testNonValueErrors([&] {
284-
return ResultT{non_value_result{std::runtime_error{"err"}}};
283+
// Propagate error/stopped, for result types with `.error_or_stopped()`
284+
if constexpr (requires { FOLLY_DECLVAL(ResultT).error_or_stopped(); }) {
285+
testErrorOrStoppedErrors([&] {
286+
return ResultT{error_or_stopped{std::runtime_error{"err"}}};
285287
});
286-
testNonValueStopped([&] { return ResultT{stopped_result}; });
288+
testErrorOrStoppedStopped([&] { return ResultT{stopped_result}; });
287289
}
288290
}
289291

@@ -339,16 +341,16 @@ TEST(OrUnwind, valueOnlyResult) {
339341
testOrUnwindVaryingInnerType<value_only_result>();
340342
}
341343

342-
// Test `or_unwind...` overloads for `non_value_result` & `stopped_result_t`
343-
TEST(OrUnwind, nonValueResult) {
344-
checkRvalueAwaitResumeTypes<non_value_result, void, void>();
344+
// Test `or_unwind...` overloads for `error_or_stopped` & `stopped_result_t`
345+
TEST(OrUnwind, errorOrStoppedResult) {
346+
checkRvalueAwaitResumeTypes<error_or_stopped, void, void>();
345347
checkRvalueAwaitResumeTypes<stopped_result_t, void, void>();
346348

347-
testNonValueErrors([] {
348-
return non_value_result{std::runtime_error{"err"}};
349+
testErrorOrStoppedErrors([] {
350+
return error_or_stopped{std::runtime_error{"err"}};
349351
});
350-
testNonValueStopped(
351-
[] { return non_value_result{stopped_result}; },
352+
testErrorOrStoppedStopped(
353+
[] { return error_or_stopped{stopped_result}; },
352354
[] { return stopped_result; });
353355
}
354356

0 commit comments

Comments
 (0)