Skip to content

Commit 68e1940

Browse files
committed
[semantic-arc] Instead of using the parsing heuristic for determining ownership when serializing, just serialize a bit.
The reason we are using the parsing heuristic is to ensure that we do not need to update a ton of test cases. This makes sense since in general, when parsing we are creating new code that is running for the first time through the compiler. On the other hand, in serialization/deserialization we expect to get back exactly the SILFunction that we serialized. So it makes sense to explicitly preserve whether we have ownership qualification or not. rdar://28851920
1 parent 186c6db commit 68e1940

File tree

5 files changed

+26
-31
lines changed

5 files changed

+26
-31
lines changed

include/swift/Serialization/ModuleFormat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const uint16_t VERSION_MAJOR = 0;
5454
/// in source control, you should also update the comment to briefly
5555
/// describe what change you made. The content of this comment isn't important;
5656
/// it just ensures a conflict if two people change the module format.
57-
const uint16_t VERSION_MINOR = 279; // Last change: copy_value, destroy_value
57+
const uint16_t VERSION_MINOR = 280; // Last change: function qualified ownership
5858

5959
using DeclID = PointerEmbeddedInt<unsigned, 31>;
6060
using DeclIDField = BCFixed<31>;

lib/Serialization/DeserializeSIL.cpp

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -380,13 +380,13 @@ SILFunction *SILDeserializer::readSILFunction(DeclID FID,
380380
DeclID clangNodeOwnerID;
381381
TypeID funcTyID;
382382
unsigned rawLinkage, isTransparent, isFragile, isThunk, isGlobal,
383-
inlineStrategy, effect, numSpecAttrs;
383+
inlineStrategy, effect, numSpecAttrs, hasQualifiedOwnership;
384384
ArrayRef<uint64_t> SemanticsIDs;
385385
// TODO: read fragile
386386
SILFunctionLayout::readRecord(scratch, rawLinkage, isTransparent, isFragile,
387387
isThunk, isGlobal, inlineStrategy, effect,
388-
numSpecAttrs, funcTyID, clangNodeOwnerID,
389-
SemanticsIDs);
388+
numSpecAttrs, hasQualifiedOwnership, funcTyID,
389+
clangNodeOwnerID, SemanticsIDs);
390390

391391
if (funcTyID == 0) {
392392
DEBUG(llvm::dbgs() << "SILFunction typeID is 0.\n");
@@ -454,6 +454,8 @@ SILFunction *SILDeserializer::readSILFunction(DeclID FID,
454454
for (auto ID : SemanticsIDs) {
455455
fn->addSemanticsAttr(MF->getIdentifier(ID).str());
456456
}
457+
if (!hasQualifiedOwnership)
458+
fn->setUnqualifiedOwnership();
457459

458460
if (Callback) Callback->didDeserialize(MF->getAssociatedModule(), fn);
459461
}
@@ -538,7 +540,6 @@ SILFunction *SILDeserializer::readSILFunction(DeclID FID,
538540
LocalValues.clear();
539541
ForwardLocalValues.clear();
540542

541-
FunctionOwnershipEvaluator OwnershipEvaluator(fn);
542543
SILOpenedArchetypesTracker OpenedArchetypesTracker(*fn);
543544
SILBuilder Builder(*fn);
544545
// Track the archetypes just like SILGen. This
@@ -572,8 +573,7 @@ SILFunction *SILDeserializer::readSILFunction(DeclID FID,
572573
return fn;
573574

574575
// Handle a SILInstruction record.
575-
if (readSILInstruction(fn, CurrentBB, Builder, OwnershipEvaluator, kind,
576-
scratch)) {
576+
if (readSILInstruction(fn, CurrentBB, Builder, kind, scratch)) {
577577
DEBUG(llvm::dbgs() << "readSILInstruction returns error.\n");
578578
MF->error();
579579
return fn;
@@ -659,10 +659,10 @@ static SILDeclRef getSILDeclRef(ModuleFile *MF,
659659
return DRef;
660660
}
661661

662-
bool SILDeserializer::readSILInstruction(
663-
SILFunction *Fn, SILBasicBlock *BB, SILBuilder &Builder,
664-
FunctionOwnershipEvaluator &OwnershipEvaluator, unsigned RecordKind,
665-
SmallVectorImpl<uint64_t> &scratch) {
662+
bool SILDeserializer::readSILInstruction(SILFunction *Fn, SILBasicBlock *BB,
663+
SILBuilder &Builder,
664+
unsigned RecordKind,
665+
SmallVectorImpl<uint64_t> &scratch) {
666666
// Return error if Basic Block is null.
667667
if (!BB)
668668
return true;
@@ -1900,11 +1900,6 @@ bool SILDeserializer::readSILInstruction(
19001900
llvm_unreachable("todo");
19011901
}
19021902

1903-
// Evaluate ResultVal's ownership. If we find that as a result of ResultVal,
1904-
// we are mixing qualified and unqualified ownership instructions, bail.
1905-
if (!OwnershipEvaluator.evaluate(ResultVal))
1906-
return true;
1907-
19081903
if (ResultVal->hasValue()) {
19091904
LastValueID = LastValueID + 1;
19101905
setLocalValue(ResultVal, LastValueID);
@@ -1973,12 +1968,12 @@ bool SILDeserializer::hasSILFunction(StringRef Name,
19731968
DeclID clangOwnerID;
19741969
TypeID funcTyID;
19751970
unsigned rawLinkage, isTransparent, isFragile, isThunk, isGlobal,
1976-
inlineStrategy, effect, numSpecAttrs;
1971+
inlineStrategy, effect, numSpecAttrs, hasQualifiedOwnership;
19771972
ArrayRef<uint64_t> SemanticsIDs;
19781973
SILFunctionLayout::readRecord(scratch, rawLinkage, isTransparent, isFragile,
19791974
isThunk, isGlobal, inlineStrategy, effect,
1980-
numSpecAttrs, funcTyID, clangOwnerID,
1981-
SemanticsIDs);
1975+
numSpecAttrs, hasQualifiedOwnership, funcTyID,
1976+
clangOwnerID, SemanticsIDs);
19821977
auto linkage = fromStableSILLinkage(rawLinkage);
19831978
if (!linkage) {
19841979
DEBUG(llvm::dbgs() << "invalid linkage code " << rawLinkage

lib/Serialization/DeserializeSIL.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "SILFormat.h"
14-
#include "swift/SIL/InstructionUtils.h"
1514
#include "swift/SIL/SILModule.h"
1615
#include "swift/Serialization/ModuleFile.h"
1716
#include "swift/Serialization/SerializedSILLoader.h"
@@ -84,7 +83,6 @@ namespace swift {
8483
/// Read a SIL instruction within a given SIL basic block.
8584
bool readSILInstruction(SILFunction *Fn, SILBasicBlock *BB,
8685
SILBuilder &Builder,
87-
FunctionOwnershipEvaluator &OwnershipEvaluator,
8886
unsigned RecordKind,
8987
SmallVectorImpl<uint64_t> &scratch);
9088

lib/Serialization/SILFormat.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -238,15 +238,16 @@ namespace sil_block {
238238

239239
using SILFunctionLayout =
240240
BCRecordLayout<SIL_FUNCTION, SILLinkageField,
241-
BCFixed<1>, // transparent
242-
BCFixed<1>, // fragile
243-
BCFixed<2>, // thunk/reabstraction_thunk
244-
BCFixed<1>, // global_init
245-
BCFixed<2>, // inlineStrategy
246-
BCFixed<2>, // side effect info.
247-
BCFixed<2>, // number of specialize attributes
248-
TypeIDField,// SILFunctionType
249-
DeclIDField,// ClangNode owner
241+
BCFixed<1>, // transparent
242+
BCFixed<1>, // fragile
243+
BCFixed<2>, // thunk/reabstraction_thunk
244+
BCFixed<1>, // global_init
245+
BCFixed<2>, // inlineStrategy
246+
BCFixed<2>, // side effect info.
247+
BCFixed<2>, // number of specialize attributes
248+
BCFixed<1>, // has qualified ownership
249+
TypeIDField, // SILFunctionType
250+
DeclIDField, // ClangNode owner
250251
BCArray<IdentifierIDField> // Semantics Attribute
251252
// followed by specialize attributes
252253
// followed by generic param list, if any

lib/Serialization/SerializeSIL.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,8 @@ void SILSerializer::writeSILFunction(const SILFunction &F, bool DeclOnly) {
358358
(unsigned)F.isTransparent(), (unsigned)F.isFragile(),
359359
(unsigned)F.isThunk(), (unsigned)F.isGlobalInit(),
360360
(unsigned)F.getInlineStrategy(), (unsigned)F.getEffectsKind(),
361-
(unsigned)numSpecAttrs, FnID, clangNodeOwnerID, SemanticsIDs);
361+
(unsigned)numSpecAttrs, (unsigned)F.hasQualifiedOwnership(), FnID,
362+
clangNodeOwnerID, SemanticsIDs);
362363

363364
if (NoBody)
364365
return;

0 commit comments

Comments
 (0)