Skip to content

Commit aa6a0cc

Browse files
committed
Serialization: Intro the UNWRAP macro to simplify bubbling up errors
Non-error resilient call sites like this: DeclContext *DC = MF.getDeclContext(contextID); Can be replaced with this error tolerant alternative: DeclContext *DC; UNWRAP(MF.getDeclContextChecked(contextID), DC);
1 parent f4d7327 commit aa6a0cc

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

lib/Serialization/Deserialization.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@
5353

5454
#define DEBUG_TYPE "Serialization"
5555

56+
// Unwrap an Expected<> variable following the typical deserialization pattern:
57+
// - On a value, assign it to Output.
58+
// - On an error, return it to bubble it up to the caller.
59+
#define UNWRAP(Input, Output) { \
60+
auto ValueOrError = Input; \
61+
if (!ValueOrError) \
62+
return ValueOrError.takeError(); \
63+
Output = ValueOrError.get(); \
64+
}
65+
5666
STATISTIC(NumDeclsLoaded, "# of decls deserialized");
5767
STATISTIC(NumMemberListsLoaded,
5868
"# of nominals/extensions whose members were loaded");

0 commit comments

Comments
 (0)