Skip to content

Commit 44eec49

Browse files
committed
Change the signature of materializeForSet to return an
optional callback; retrofit existing implementations. There's a lot of unpleasant traffic in raw pointers here which I'm going to try to clean up. Swift SVN r24123
1 parent 09cf7b8 commit 44eec49

17 files changed

+647
-211
lines changed

lib/AST/Decl.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2821,7 +2821,7 @@ DeclName AbstractFunctionDecl::getEffectiveFullName() const {
28212821
if (auto afd = func->getAccessorStorageDecl()) {
28222822
auto &ctx = getASTContext();
28232823
auto subscript = dyn_cast<SubscriptDecl>(afd);
2824-
switch (func->getAccessorKind()) {
2824+
switch (auto accessorKind = func->getAccessorKind()) {
28252825
case AccessorKind::NotAccessor:
28262826
break;
28272827

@@ -2839,6 +2839,10 @@ DeclName AbstractFunctionDecl::getEffectiveFullName() const {
28392839
SmallVector<Identifier, 4> argNames;
28402840
// The implicit value/buffer parameter.
28412841
argNames.push_back(Identifier());
2842+
// The callback storage parameter on materializeForSet.
2843+
if (accessorKind == AccessorKind::IsMaterializeForSet)
2844+
argNames.push_back(Identifier());
2845+
// The subscript index parameters.
28422846
if (subscript) {
28432847
argNames.append(subscript->getFullName().getArgumentNames().begin(),
28442848
subscript->getFullName().getArgumentNames().end());

lib/AST/Verifier.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2371,12 +2371,12 @@ struct ASTNodeBase {};
23712371
void checkSourceRanges(Pattern *P) {
23722372
PrettyStackTracePattern debugStack(Ctx, "verifying ranges", P);
23732373

2374-
if (!P->getSourceRange().isValid()) {
2375-
// We don't care about source ranges on implicitly-generated
2376-
// patterns.
2377-
if (P->isImplicit())
2378-
return;
2374+
// We don't care about source ranges on implicitly-generated
2375+
// patterns.
2376+
if (P->isImplicit())
2377+
return;
23792378

2379+
if (!P->getSourceRange().isValid()) {
23802380
Out << "invalid source range for pattern: ";
23812381
P->print(Out);
23822382
Out << "\n";

lib/SILGen/LValue.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ class LogicalPathComponent : public PathComponent {
228228
/// \param base - always an address, but possibly an r-value
229229
virtual void writeback(SILGenFunction &gen, SILLocation loc,
230230
ManagedValue base, Materialize temporary,
231-
SILValue otherInfo) &&;
231+
ArrayRef<SILValue> otherInfo) &&;
232232
};
233233

234234
inline LogicalPathComponent &PathComponent::asLogical() {

lib/SILGen/SILGenApply.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2715,7 +2715,8 @@ emitMaterializeForSetAccessor(SILLocation loc, SILDeclRef materializeForSet,
27152715
ArrayRef<Substitution> substitutions,
27162716
RValueSource &&selfValue,
27172717
bool isSuper, bool isDirectUse,
2718-
RValue &&subscripts, SILValue buffer) {
2718+
RValue &&subscripts, SILValue buffer,
2719+
SILValue callbackStorage) {
27192720

27202721
Callee callee = emitSpecializedAccessorFunctionRef(*this, loc,
27212722
materializeForSet,
@@ -2730,37 +2731,36 @@ emitMaterializeForSetAccessor(SILLocation loc, SILDeclRef materializeForSet,
27302731
accessType = cast<AnyFunctionType>(accessType.getResult());
27312732
}
27322733

2733-
ManagedValue mbuffer = {
2734-
B.createAddressToPointer(loc, buffer,
2735-
SILType::getRawPointerType(getASTContext())),
2736-
CleanupHandle::invalid()
2737-
};
2738-
2739-
// (buffer) or (buffer, indices) ->
2734+
// (buffer, callbackStorage) or (buffer, callbackStorage, indices) ->
27402735
RValue args = [&] {
2736+
SmallVector<ManagedValue, 4> elts;
2737+
2738+
auto bufferPtr =
2739+
B.createAddressToPointer(loc, buffer,
2740+
SILType::getRawPointerType(getASTContext()));
2741+
elts.push_back(ManagedValue::forUnmanaged(bufferPtr));
2742+
2743+
elts.push_back(ManagedValue::forLValue(callbackStorage));
2744+
27412745
if (subscripts) {
2742-
SmallVector<ManagedValue, 4> elts;
2743-
elts.push_back(mbuffer);
27442746
std::move(subscripts).getAll(elts);
2745-
return RValue(elts, accessType.getInput());
2746-
} else {
2747-
return RValue(mbuffer, accessType.getInput());
27482747
}
2748+
return RValue(elts, accessType.getInput());
27492749
}();
27502750
emission.addCallSite(loc, RValueSource(loc, std::move(args)),
27512751
accessType.getResult());
2752-
// (buffer, i1)
2753-
SILValue pointerAndNeedsWriteback = emission.apply().getUnmanagedValue();
2752+
// (buffer, optionalCallback)
2753+
SILValue pointerAndOptionalCallback = emission.apply().getUnmanagedValue();
27542754

27552755
// Project out the materialized address.
2756-
SILValue address = B.createTupleExtract(loc, pointerAndNeedsWriteback, 0);
2756+
SILValue address = B.createTupleExtract(loc, pointerAndOptionalCallback, 0);
27572757
address = B.createPointerToAddress(loc, address, buffer.getType());
27582758

2759-
// Project out the needsWriteback flag.
2760-
SILValue needsWriteback =
2761-
B.createTupleExtract(loc, pointerAndNeedsWriteback, 1);
2759+
// Project out the optional callback.
2760+
SILValue optionalCallback =
2761+
B.createTupleExtract(loc, pointerAndOptionalCallback, 1);
27622762

2763-
return { address, needsWriteback };
2763+
return { address, optionalCallback };
27642764
}
27652765

27662766
SILDeclRef SILGenFunction::getAddressorDeclRef(AbstractStorageDecl *storage,

lib/SILGen/SILGenFunction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ class LLVM_LIBRARY_VISIBILITY SILGenFunction
722722
RValueSource &&optionalSelfValue,
723723
bool isSuper, bool isDirectAccessorUse,
724724
RValue &&optionalSubscripts,
725-
SILValue buffer);
725+
SILValue buffer, SILValue callbackStorage);
726726

727727
SILDeclRef getAddressorDeclRef(AbstractStorageDecl *decl,
728728
AccessKind accessKind,

0 commit comments

Comments
 (0)