Skip to content

Commit 6638ea2

Browse files
committed
Make the check and panic functions into macros
This allows message construction to be entirely elided in release builds if desired.
1 parent 7eb7cbe commit 6638ea2

File tree

106 files changed

+740
-783
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+740
-783
lines changed

.clang-format

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ AllowShortCaseLabelsOnASingleLine: true
44
DerivePointerAlignment: false
55
PointerAlignment: Left
66
ReflowComments: false
7+
IndentPPDirectives: AfterHash
78

89
# This would be nice but it also changes requires() and not wrapping requires clauses with () introduces clang-tidy bugs like:
910
#```
1011
# template <size_t I>
1112
# requires I <= sizeof
1213
# ...(Ts) constexpr inline const auto& at() const& noexcept {
13-
# ::sus::check(!moved_from(I));
14+
# sus_check(!moved_from(I));
1415
# return __private::find_storage<I>(storage_).value;
1516
# }
1617
#```

STYLE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ footguns, crashes, bugs, and UB.
77
1. All methods are `constexpr` unless they must call a non-`constexpr` function,
88
or they expose floating point NaNs (since constexpr NaNs change their bit
99
values).
10-
* Consider `panic()`/`check()` as constexpr for these purposes, they will
10+
* Consider `sus_panic()`/`sus_check()` as constexpr for these purposes, they will
1111
correctly prevent compiling if the condition fails.
1212
1. If you override on `const&`, then explicitly provide or delete the `&&`
1313
override.

USAGE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ target_link_libraries(subspace-example PRIVATE subspace::lib)
3939
int main() {
4040
i32 a = 6;
4141
i32 b = 9;
42-
sus::check(a < b);
42+
sus_check(a < b);
4343
return 0;
4444
}
4545
```

subdoc/lib/database.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ struct CommentElement {
8383
name(sus::move(name)),
8484
sort_key(sort_key) {
8585
// All elements have the Global namespace in their path.
86-
sus::check(this->namespace_path.len() > 0u);
86+
sus_check(this->namespace_path.len() > 0u);
8787
}
8888

8989
sus::Vec<Namespace> namespace_path;

subdoc/lib/friendly_names.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ inline std::string friendly_record_type_name(RecordType t,
6767
case RecordType::Struct: return capitalize ? "Struct" : "struct";
6868
case RecordType::Union: return capitalize ? "Union" : "union";
6969
}
70-
sus::unreachable_unchecked(unsafe_fn);
70+
sus_unreachable_unchecked(unsafe_fn);
7171
}
7272

7373
} // namespace subdoc

subdoc/lib/gen/files.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ inline std::filesystem::path construct_html_namespace_file_path(
9999
return fmt::format("namespace.{}",
100100
namespace_path[0u].as<Namespace::Tag::Named>());
101101
}
102-
sus::unreachable();
102+
sus_unreachable();
103103
}();
104104

105105
fname << name;
@@ -231,7 +231,7 @@ inline std::filesystem::path construct_html_file_path_for_function(
231231

232232
inline std::string construct_html_url_anchor_for_method(
233233
const FunctionElement& element) noexcept {
234-
sus::check(!element.record_path.is_empty());
234+
sus_check(!element.record_path.is_empty());
235235
// There's no escaping that happens for anchors on the record page, unlike
236236
// for file paths. So we don't use construct_html_file_path_for_function()
237237
// here which escapes.
@@ -286,7 +286,7 @@ inline sus::Option<std::string> construct_html_url_for_alias(
286286
switch (ref) {
287287
case TypeRef::Tag::Record: {
288288
const RecordElement& e = ref.as<TypeRef::Tag::Record>();
289-
sus::check_with_message(
289+
sus_check_with_message(
290290
!e.hidden(),
291291
fmt::format("reference to hidden Record {}", e.name));
292292
return construct_html_url_for_type(e);
@@ -297,7 +297,7 @@ inline sus::Option<std::string> construct_html_url_for_alias(
297297
// aliases.
298298
break;
299299
}
300-
sus::unreachable();
300+
sus_unreachable();
301301
});
302302
}
303303
case AliasTarget::Tag::AliasOfConcept: {
@@ -311,11 +311,11 @@ inline sus::Option<std::string> construct_html_url_for_alias(
311311
}
312312
case ConceptRefOrName::Tag::Name: return sus::none();
313313
}
314-
sus::unreachable();
314+
sus_unreachable();
315315
}
316316
case AliasTarget::Tag::AliasOfMethod: {
317317
// TODO: Link to method.
318-
sus::unreachable();
318+
sus_unreachable();
319319
}
320320
case AliasTarget::Tag::AliasOfFunction: {
321321
const LinkedFunction& fun =
@@ -328,11 +328,11 @@ inline sus::Option<std::string> construct_html_url_for_alias(
328328
}
329329
case FunctionRefOrName::Tag::Name: return sus::none();
330330
}
331-
sus::unreachable();
331+
sus_unreachable();
332332
}
333333
case AliasTarget::Tag::AliasOfEnumConstant: {
334334
// TODO: Link to constant.
335-
sus::unreachable();
335+
sus_unreachable();
336336
}
337337
case AliasTarget::Tag::AliasOfVariable: {
338338
const LinkedVariable& var =
@@ -345,10 +345,10 @@ inline sus::Option<std::string> construct_html_url_for_alias(
345345
}
346346
case VariableRefOrName::Tag::Name: return sus::none();
347347
}
348-
sus::unreachable();
348+
sus_unreachable();
349349
}
350350
}
351-
sus::unreachable();
351+
sus_unreachable();
352352
} else {
353353
// TODO: Link to the alias' page.
354354
return sus::some("TODO");

subdoc/lib/gen/generate.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ struct sus::error::ErrorImpl<subdoc::gen::GenerateError> {
7070
return fmt::format("parsing doc comment markdown");
7171
}
7272
}
73-
sus::unreachable();
73+
sus_unreachable();
7474
}
7575
static sus::Option<const sus::error::DynError&> source(
7676
const GenerateError& e) noexcept {
@@ -88,6 +88,6 @@ struct sus::error::ErrorImpl<subdoc::gen::GenerateError> {
8888
return sus::some(*p);
8989
}
9090
}
91-
sus::unreachable();
91+
sus_unreachable();
9292
}
9393
};

subdoc/lib/gen/generate_alias.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ sus::Result<void, MarkdownToHtmlError> generate_alias_reference(
116116
}
117117
case AliasTarget::Tag::AliasOfMethod: {
118118
// TODO: Link to method.
119-
sus::unreachable();
119+
sus_unreachable();
120120
}
121121
case AliasTarget::Tag::AliasOfFunction: {
122122
const LinkedFunction& fun =
@@ -132,7 +132,7 @@ sus::Result<void, MarkdownToHtmlError> generate_alias_reference(
132132
}
133133
case AliasTarget::Tag::AliasOfEnumConstant: {
134134
// TODO: Link to constant.
135-
sus::unreachable();
135+
sus_unreachable();
136136
}
137137
case AliasTarget::Tag::AliasOfVariable: {
138138
const LinkedVariable& var =

subdoc/lib/gen/generate_concept.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ void generate_concept_overview(HtmlWriter::OpenDiv& record_div,
7373
break; // Function can't be an ancesor of a concept.
7474
case CppPathConcept: return "concept-name";
7575
}
76-
sus::unreachable();
76+
sus_unreachable();
7777
}());
7878
ancestor_anchor.add_href(e.link_href);
7979
ancestor_anchor.write_text(e.name);

subdoc/lib/gen/generate_cpp_path.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ sus::Vec<CppPathElement> generate_with_ancestors(
4141
return std::string("(anonymous)");
4242
case Namespace::Tag::Named: return sus::clone(ancestor.name);
4343
}
44-
sus::unreachable();
44+
sus_unreachable();
4545
}(),
4646
.link_href = construct_html_url_for_namespace(ancestor),
4747
.type =
@@ -51,7 +51,7 @@ sus::Vec<CppPathElement> generate_with_ancestors(
5151
case Namespace::Tag::Anonymous: return CppPathNamespace;
5252
case Namespace::Tag::Named: return CppPathNamespace;
5353
}
54-
sus::unreachable();
54+
sus_unreachable();
5555
}(),
5656
});
5757
}

0 commit comments

Comments
 (0)