Skip to content

Commit 4c6e29b

Browse files
committed
Address feedback
1 parent f25f024 commit 4c6e29b

File tree

3 files changed

+19
-22
lines changed

3 files changed

+19
-22
lines changed

include/swift/SIL/SILLocation.h

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,9 @@ class SILLocation {
5252
/// Describes a position in a source file by explicitly storing the file name,
5353
/// line and column.
5454
///
55-
/// This is used for parsed locations from a SIL file, for
55+
/// This is used for parsed locations from SIL and swiftmodule files, for
5656
/// "-sil-based-debuginfo" (see SILDebugInfoGenerator) and for the
5757
/// "compiler-generated" singleton location.
58-
/// In future we might also use it for de-serialized locations from a
59-
/// swiftmodule file.
6058
struct FilenameAndLocation : public SILAllocated<FilenameAndLocation> {
6159
unsigned line;
6260
uint16_t column;
@@ -556,9 +554,7 @@ class RegularLocation : public SILLocation {
556554
bool isForDebugOnly = true);
557555
RegularLocation(SourceLoc L, bool Implicit = true)
558556
: SILLocation(L, RegularKind, Implicit) {}
559-
RegularLocation(FilenameAndLocation *filePos)
560-
: SILLocation(filePos, RegularKind) {}
561-
RegularLocation(FilenameAndLocation *filePos, bool Implicit)
557+
RegularLocation(FilenameAndLocation *filePos, bool Implicit = false)
562558
: SILLocation(filePos, RegularKind, Implicit) {}
563559

564560
/// Convert \p loc to a RegularLocation.
@@ -627,10 +623,7 @@ class ReturnLocation : public SILLocation {
627623
/// Construct the return location for a constructor or a destructor.
628624
ReturnLocation(BraceStmt *BS);
629625

630-
ReturnLocation(FilenameAndLocation *filePos)
631-
: SILLocation(filePos, ReturnKind) {}
632-
633-
ReturnLocation(FilenameAndLocation *filePos, bool Implicit)
626+
ReturnLocation(FilenameAndLocation *filePos, bool Implicit = false)
634627
: SILLocation(filePos, ReturnKind, Implicit) {}
635628

636629
static bool isKind(const SILLocation& L) {
@@ -651,10 +644,7 @@ class ImplicitReturnLocation : public SILLocation {
651644

652645
ImplicitReturnLocation(AbstractFunctionDecl *AFD);
653646

654-
ImplicitReturnLocation(FilenameAndLocation *filePos)
655-
: SILLocation(filePos, ImplicitReturnKind) {}
656-
657-
ImplicitReturnLocation(FilenameAndLocation *filePos, bool Implicit)
647+
ImplicitReturnLocation(FilenameAndLocation *filePos, bool Implicit = false)
658648
: SILLocation(filePos, ImplicitReturnKind, Implicit) {}
659649

660650
/// Convert \p loc to an ImplicitReturnLocation.

lib/Serialization/DeserializeSIL.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,11 @@ SILDeserializer::readNextRecord(SmallVectorImpl<uint64_t> &scratch) {
396396

397397
std::optional<SILLocation> SILDeserializer::readLoc(unsigned kind,
398398
SmallVectorImpl<uint64_t> &scratch) {
399-
unsigned LocationKind = 0, Implicit;
399+
unsigned LocationKind, Implicit = 0;
400400
SILLocation::FilenameAndLocation *FNameLoc = nullptr;
401+
// Each SourceLoc opaque pointer is serialized once. Successive appearences
402+
// are serialized as references to earlier serializations, with LocID as the
403+
// indexing key
401404
if (kind == SIL_SOURCE_LOC_REF) {
402405
ValueID LocID;
403406
SourceLocRefLayout::readRecord(scratch, LocID, LocationKind, Implicit);
@@ -415,16 +418,16 @@ std::optional<SILLocation> SILDeserializer::readLoc(unsigned kind,
415418
ParsedLocs.push_back(FNameLoc);
416419
}
417420

418-
// FIXME: Instructions are being deserialized as implicit as existing code in
419-
// readSILInstruction also deserializes instructions as implicit by default.
420-
// This suppresses some diagnostics which otherwise break tests. This should
421-
// be fixed in both places
422421
switch(LocationKind) {
423422
case SILLocation::ReturnKind:
424423
return ReturnLocation(FNameLoc, Implicit);
425424
case SILLocation::ImplicitReturnKind:
426425
return ImplicitReturnLocation(FNameLoc, Implicit);
427-
default:
426+
case SILLocation::InlinedKind:
427+
case SILLocation::MandatoryInlinedKind:
428+
case SILLocation::CleanupKind:
429+
case SILLocation::ArtificialUnreachableKind:
430+
case SILLocation::RegularKind:
428431
return RegularLocation(FNameLoc, Implicit);
429432
}
430433
}

lib/Serialization/SerializeSIL.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3094,9 +3094,13 @@ void SILSerializer::writeSourceLoc(SILLocation Loc, const SourceManager &SM) {
30943094
case SILLocation::ImplicitReturnKind:
30953095
LocationKind = SILLocation::ImplicitReturnKind;
30963096
break;
3097-
//TODO: handle other cases correctly
3098-
default:
3097+
case SILLocation::InlinedKind:
3098+
case SILLocation::MandatoryInlinedKind:
3099+
case SILLocation::CleanupKind:
3100+
case SILLocation::ArtificialUnreachableKind:
3101+
case SILLocation::RegularKind:
30993102
LocationKind = SILLocation::RegularKind;
3103+
break;
31003104
}
31013105

31023106
if (SourceLocMap.find(OpaquePtr) != SourceLocMap.end()) {

0 commit comments

Comments
 (0)