Skip to content

Commit cea750d

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 7ce4055 commit cea750d

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
@@ -52,6 +52,16 @@
5252

5353
#define DEBUG_TYPE "Serialization"
5454

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

0 commit comments

Comments
 (0)