Skip to content

Commit 735e35d

Browse files
committed
Address more of Jordan's (offline) comments.
1 parent a3ede2b commit 735e35d

File tree

2 files changed

+21
-163
lines changed

2 files changed

+21
-163
lines changed

lib/Serialization/Deserialization.cpp

Lines changed: 16 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -723,14 +723,7 @@ void ModuleFile::readGenericRequirements(
723723
break;
724724

725725
scratch.clear();
726-
Expected<unsigned> maybeRecordID =
727-
DeclTypeCursor.readRecord(entry.ID, scratch, &blobData);
728-
if (!maybeRecordID) {
729-
// FIXME this drops the error on the floor.
730-
consumeError(maybeRecordID.takeError());
731-
return;
732-
}
733-
unsigned recordID = maybeRecordID.get();
726+
unsigned recordID = fatalIfUnexpected(DeclTypeCursor.readRecord(entry.ID, scratch, &blobData));
734727
switch (recordID) {
735728
case GENERIC_REQUIREMENT: {
736729
uint8_t rawKind;
@@ -916,15 +909,7 @@ GenericSignature *ModuleFile::getGenericSignature(
916909
return nullptr;
917910
}
918911

919-
Expected<unsigned> maybeRecordID =
920-
DeclTypeCursor.readRecord(entry.ID, scratch, &blobData);
921-
if (!maybeRecordID) {
922-
// FIXME this drops the error on the floor.
923-
consumeError(maybeRecordID.takeError());
924-
error();
925-
return nullptr;
926-
}
927-
unsigned recordID = maybeRecordID.get();
912+
unsigned recordID = fatalIfUnexpected(DeclTypeCursor.readRecord(entry.ID, scratch, &blobData));
928913
if (recordID != GENERIC_SIGNATURE) {
929914
error();
930915
return nullptr;
@@ -1006,15 +991,7 @@ ModuleFile::getGenericSignatureOrEnvironment(
1006991
if (entry.Kind != llvm::BitstreamEntry::Record)
1007992
return result;
1008993

1009-
Expected<unsigned> maybeRecordID =
1010-
DeclTypeCursor.readRecord(entry.ID, scratch, &blobData);
1011-
if (!maybeRecordID) {
1012-
// FIXME this drops the error on the floor.
1013-
consumeError(maybeRecordID.takeError());
1014-
error();
1015-
return nullptr;
1016-
}
1017-
unsigned recordID = maybeRecordID.get();
994+
unsigned recordID = fatalIfUnexpected(DeclTypeCursor.readRecord(entry.ID, scratch, &blobData));
1018995
if (recordID != SIL_GENERIC_ENVIRONMENT) {
1019996
error();
1020997
return result;
@@ -1116,15 +1093,7 @@ SubstitutionMap ModuleFile::getSubstitutionMap(
11161093

11171094
StringRef blobData;
11181095
SmallVector<uint64_t, 8> scratch;
1119-
Expected<unsigned> maybeRecordID =
1120-
DeclTypeCursor.readRecord(entry.ID, scratch, &blobData);
1121-
if (!maybeRecordID) {
1122-
// FIXME this drops the error on the floor.
1123-
consumeError(maybeRecordID.takeError());
1124-
error();
1125-
return SubstitutionMap();
1126-
}
1127-
unsigned recordID = maybeRecordID.get();
1096+
unsigned recordID = fatalIfUnexpected(DeclTypeCursor.readRecord(entry.ID, scratch, &blobData));
11281097
if (recordID != SUBSTITUTION_MAP) {
11291098
error();
11301099
return SubstitutionMap();
@@ -1342,15 +1311,7 @@ ModuleFile::resolveCrossReference(ModuleID MID, uint32_t pathLen) {
13421311
// In particular, operator path pieces represent actual operators here, but
13431312
// filters on operator functions when they appear later on.
13441313
scratch.clear();
1345-
Expected<unsigned> maybeRecordID =
1346-
DeclTypeCursor.readRecord(entry.ID, scratch, &blobData);
1347-
if (!maybeRecordID) {
1348-
// FIXME this drops the error on the floor.
1349-
consumeError(maybeRecordID.takeError());
1350-
error();
1351-
return nullptr;
1352-
}
1353-
unsigned recordID = maybeRecordID.get();
1314+
unsigned recordID = fatalIfUnexpected(DeclTypeCursor.readRecord(entry.ID, scratch, &blobData));
13541315
switch (recordID) {
13551316
case XREF_TYPE_PATH_PIECE:
13561317
case XREF_VALUE_PATH_PIECE: {
@@ -1460,14 +1421,7 @@ ModuleFile::resolveCrossReference(ModuleID MID, uint32_t pathLen) {
14601421
return Identifier();
14611422

14621423
scratch.clear();
1463-
Expected<unsigned> maybeRecordID =
1464-
DeclTypeCursor.readRecord(entry.ID, scratch, &blobData);
1465-
if (!maybeRecordID) {
1466-
// FIXME this drops the error on the floor.
1467-
consumeError(maybeRecordID.takeError());
1468-
return Identifier();
1469-
}
1470-
unsigned recordID = maybeRecordID.get();
1424+
unsigned recordID = fatalIfUnexpected(DeclTypeCursor.readRecord(entry.ID, scratch, &blobData));
14711425
switch (recordID) {
14721426
case XREF_TYPE_PATH_PIECE: {
14731427
IdentifierID IID;
@@ -1538,15 +1492,7 @@ ModuleFile::resolveCrossReference(ModuleID MID, uint32_t pathLen) {
15381492
}
15391493

15401494
scratch.clear();
1541-
Expected<unsigned> maybeRecordID =
1542-
DeclTypeCursor.readRecord(entry.ID, scratch, &blobData);
1543-
if (!maybeRecordID) {
1544-
// FIXME this drops the error on the floor.
1545-
consumeError(maybeRecordID.takeError());
1546-
error();
1547-
return nullptr;
1548-
}
1549-
unsigned recordID = maybeRecordID.get();
1495+
unsigned recordID = fatalIfUnexpected(DeclTypeCursor.readRecord(entry.ID, scratch, &blobData));
15501496
switch (recordID) {
15511497
case XREF_TYPE_PATH_PIECE: {
15521498
if (values.size() == 1 && isa<NominalTypeDecl>(values.front())) {
@@ -1958,15 +1904,7 @@ DeclContext *ModuleFile::getLocalDeclContext(DeclContextID DCID) {
19581904
SmallVector<uint64_t, 64> scratch;
19591905
StringRef blobData;
19601906

1961-
Expected<unsigned> maybeRecordID =
1962-
DeclTypeCursor.readRecord(entry.ID, scratch, &blobData);
1963-
if (!maybeRecordID) {
1964-
// FIXME this drops the error on the floor.
1965-
consumeError(maybeRecordID.takeError());
1966-
error();
1967-
return nullptr;
1968-
}
1969-
unsigned recordID = maybeRecordID.get();
1907+
unsigned recordID = fatalIfUnexpected(DeclTypeCursor.readRecord(entry.ID, scratch, &blobData));
19701908
switch(recordID) {
19711909
case decls_block::ABSTRACT_CLOSURE_EXPR_CONTEXT: {
19721910
TypeID closureTypeID;
@@ -2056,15 +1994,7 @@ DeclContext *ModuleFile::getDeclContext(DeclContextID DCID) {
20561994
SmallVector<uint64_t, 64> scratch;
20571995
StringRef blobData;
20581996

2059-
Expected<unsigned> maybeRecordID =
2060-
DeclTypeCursor.readRecord(entry.ID, scratch, &blobData);
2061-
if (!maybeRecordID) {
2062-
// FIXME this drops the error on the floor.
2063-
consumeError(maybeRecordID.takeError());
2064-
error();
2065-
return nullptr;
2066-
}
2067-
unsigned recordID = maybeRecordID.get();
1997+
unsigned recordID = fatalIfUnexpected(DeclTypeCursor.readRecord(entry.ID, scratch, &blobData));
20681998

20691999
if (recordID != decls_block::DECL_CONTEXT)
20702000
llvm_unreachable("Expected a DECL_CONTEXT record");
@@ -4087,13 +4017,7 @@ llvm::Error DeclDeserializer::deserializeDeclAttributes() {
40874017
return llvm::Error::success();
40884018
}
40894019

4090-
Expected<unsigned> maybeRecordID =
4091-
MF.DeclTypeCursor.readRecord(entry.ID, scratch, &blobData);
4092-
if (!maybeRecordID) {
4093-
MF.error();
4094-
return maybeRecordID.takeError();
4095-
}
4096-
unsigned recordID = maybeRecordID.get();
4020+
unsigned recordID = MF.fatalIfUnexpected(MF.DeclTypeCursor.readRecord(entry.ID, scratch, &blobData));
40974021

40984022
if (isDeclAttrRecord(recordID)) {
40994023
DeclAttribute *Attr = nullptr;
@@ -4405,13 +4329,7 @@ DeclDeserializer::getDeclCheckedImpl() {
44054329

44064330
SmallVector<uint64_t, 64> scratch;
44074331
StringRef blobData;
4408-
Expected<unsigned> maybeRecordID =
4409-
MF.DeclTypeCursor.readRecord(entry.ID, scratch, &blobData);
4410-
if (!maybeRecordID) {
4411-
MF.error();
4412-
return maybeRecordID.takeError();
4413-
}
4414-
unsigned recordID = maybeRecordID.get();
4332+
unsigned recordID = MF.fatalIfUnexpected(MF.DeclTypeCursor.readRecord(entry.ID, scratch, &blobData));
44154333

44164334
PrettyDeclDeserialization stackTraceEntry(
44174335
&MF, declOrOffset, static_cast<decls_block::RecordKind>(recordID));
@@ -4794,13 +4712,7 @@ class swift::TypeDeserializer {
47944712
break;
47954713

47964714
scratch.clear();
4797-
Expected<unsigned> maybeRecordID =
4798-
MF.DeclTypeCursor.readRecord(entry.ID, scratch, &blobData);
4799-
if (!maybeRecordID) {
4800-
MF.error();
4801-
return maybeRecordID.takeError();
4802-
}
4803-
unsigned recordID = maybeRecordID.get();
4715+
unsigned recordID = MF.fatalIfUnexpected(MF.DeclTypeCursor.readRecord(entry.ID, scratch, &blobData));
48044716
if (recordID != decls_block::TUPLE_TYPE_ELT)
48054717
break;
48064718

@@ -4861,13 +4773,7 @@ class swift::TypeDeserializer {
48614773
break;
48624774

48634775
scratch.clear();
4864-
Expected<unsigned> maybeRecordID =
4865-
MF.DeclTypeCursor.readRecord(entry.ID, scratch, &blobData);
4866-
if (!maybeRecordID) {
4867-
MF.error();
4868-
return maybeRecordID.takeError();
4869-
}
4870-
unsigned recordID = maybeRecordID.get();
4776+
unsigned recordID = MF.fatalIfUnexpected(MF.DeclTypeCursor.readRecord(entry.ID, scratch, &blobData));
48714777
if (recordID != decls_block::FUNCTION_PARAM)
48724778
break;
48734779

@@ -5456,13 +5362,7 @@ Expected<Type> TypeDeserializer::getTypeCheckedImpl() {
54565362

54575363
SmallVector<uint64_t, 64> scratch;
54585364
StringRef blobData;
5459-
Expected<unsigned> maybeRecordID =
5460-
MF.DeclTypeCursor.readRecord(entry.ID, scratch, &blobData);
5461-
if (!maybeRecordID) {
5462-
MF.error();
5463-
return maybeRecordID.takeError();
5464-
}
5465-
unsigned recordID = maybeRecordID.get();
5365+
unsigned recordID = MF.fatalIfUnexpected(MF.DeclTypeCursor.readRecord(entry.ID, scratch, &blobData));
54665366

54675367
switch (recordID) {
54685368
#define CASE(RECORD_NAME) \
@@ -5923,14 +5823,7 @@ Optional<StringRef> ModuleFile::maybeReadInlinableBodyText() {
59235823
if (next.Kind != llvm::BitstreamEntry::Record)
59245824
return None;
59255825

5926-
Expected<unsigned> maybeRecKind =
5927-
DeclTypeCursor.readRecord(next.ID, scratch, &blobData);
5928-
if (!maybeRecKind) {
5929-
// FIXME this drops the error diagnostic on the floor.
5930-
consumeError(maybeRecKind.takeError());
5931-
return None;
5932-
}
5933-
unsigned recKind = maybeRecKind.get();
5826+
unsigned recKind = fatalIfUnexpected(DeclTypeCursor.readRecord(next.ID, scratch, &blobData));
59345827
if (recKind != INLINABLE_BODY_TEXT)
59355828
return None;
59365829

@@ -5950,13 +5843,7 @@ Optional<ForeignErrorConvention> ModuleFile::maybeReadForeignErrorConvention() {
59505843
if (next.Kind != llvm::BitstreamEntry::Record)
59515844
return None;
59525845

5953-
Expected<unsigned> maybeRecKind = DeclTypeCursor.readRecord(next.ID, scratch);
5954-
if (!maybeRecKind) {
5955-
// FIXME this drops the error diagnostic on the floor.
5956-
consumeError(maybeRecKind.takeError());
5957-
return None;
5958-
}
5959-
unsigned recKind = maybeRecKind.get();
5846+
unsigned recKind = fatalIfUnexpected(DeclTypeCursor.readRecord(next.ID, scratch));
59605847
switch (recKind) {
59615848
case FOREIGN_ERROR_CONVENTION:
59625849
restoreOffset.reset();

lib/Serialization/DeserializeSIL.cpp

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,7 @@ SILDeserializer::SILDeserializer(
141141
return;
142142

143143
// Load any abbrev records at the start of the block.
144-
if (llvm::Expected<llvm::BitstreamEntry> Advanced = SILCursor.advance()) {
145-
// FIXME this drops the error on the floor.
146-
consumeError(Advanced.takeError());
147-
return;
148-
}
144+
MF->fatalIfUnexpected(SILCursor.advance());
149145

150146
llvm::BitstreamCursor cursor = SILIndexCursor;
151147
// We expect SIL_FUNC_NAMES first, then SIL_VTABLE_NAMES, then
@@ -154,27 +150,14 @@ SILDeserializer::SILDeserializer(
154150
// omitted if no entries exist in the module file.
155151
unsigned kind = 0;
156152
while (kind != sil_index_block::SIL_PROPERTY_OFFSETS) {
157-
llvm::Expected<llvm::BitstreamEntry> maybeNext = cursor.advance();
158-
if (!maybeNext) {
159-
// FIXME this drops the error on the floor.
160-
consumeError(maybeNext.takeError());
161-
return;
162-
}
163-
llvm::BitstreamEntry next = maybeNext.get();
153+
llvm::BitstreamEntry next = MF->fatalIfUnexpected(cursor.advance());
164154
if (next.Kind == llvm::BitstreamEntry::EndBlock)
165155
return;
166156

167157
SmallVector<uint64_t, 4> scratch;
168158
StringRef blobData;
169159
unsigned prevKind = kind;
170-
llvm::Expected<unsigned> maybeKind =
171-
cursor.readRecord(next.ID, scratch, &blobData);
172-
if (!maybeKind) {
173-
// FIXME this drops the error on the floor.
174-
consumeError(maybeKind.takeError());
175-
return;
176-
}
177-
kind = maybeKind.get();
160+
kind = MF->fatalIfUnexpected(cursor.readRecord(next.ID, scratch, &blobData));
178161
assert((next.Kind == llvm::BitstreamEntry::Record &&
179162
kind > prevKind &&
180163
(kind == sil_index_block::SIL_FUNC_NAMES ||
@@ -204,21 +187,9 @@ SILDeserializer::SILDeserializer(
204187
}
205188

206189
// Read SIL_FUNC|VTABLE|GLOBALVAR_OFFSETS record.
207-
maybeNext = cursor.advance();
208-
if (!maybeNext) {
209-
// FIXME this drops the error on the floor.
210-
consumeError(maybeNext.takeError());
211-
return;
212-
}
213-
next = maybeNext.get();
190+
next = MF->fatalIfUnexpected(cursor.advance());
214191
scratch.clear();
215-
maybeKind = cursor.readRecord(next.ID, scratch, &blobData);
216-
if (!maybeKind) {
217-
// FIXME this drops the error on the floor.
218-
consumeError(maybeKind.takeError());
219-
return;
220-
}
221-
unsigned offKind = maybeKind.get();
192+
unsigned offKind = MF->fatalIfUnexpected(cursor.readRecord(next.ID, scratch, &blobData));
222193
(void)offKind;
223194
if (kind == sil_index_block::SIL_FUNC_NAMES) {
224195
assert((next.Kind == llvm::BitstreamEntry::Record &&

0 commit comments

Comments
 (0)