mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
rearrange the order in which we set up initializations, so that
'unowned let' initializations don't drop their ReferenceStorageInitialization transformation. This defines away another class of problems related to weak and unowned pointers, and allows us to remove a hack added to paper over rdar://16681656. Swift SVN r17846
This commit is contained in:
@@ -623,23 +623,21 @@ SILGenFunction::emitInitializationForVarDecl(VarDecl *vd, bool isArgument,
|
||||
if (isa<InOutType>(varType))
|
||||
return InitializationPtr(new InOutInitialization(vd));
|
||||
|
||||
// Initializing a weak or unowned variable requires a change in type.
|
||||
if (isa<ReferenceStorageType>(varType))
|
||||
return InitializationPtr(new ReferenceStorageInitialization(
|
||||
emitLocalVariableWithCleanup(vd)));
|
||||
|
||||
// If this is a 'let' initialization for a non-address-only type, set up a
|
||||
// let binding, which stores the initialization value into VarLocs directly.
|
||||
if (vd->isLet())
|
||||
return InitializationPtr(new LetValueInitialization(vd, isArgument, *this));
|
||||
|
||||
// Otherwise, we have a normal local-variable initialization.
|
||||
auto varInit = emitLocalVariableWithCleanup(vd);
|
||||
|
||||
// Initializing a @weak or @unowned variable requires a change in type.
|
||||
if (isa<ReferenceStorageType>(varType))
|
||||
return InitializationPtr(new ReferenceStorageInitialization(
|
||||
std::move(varInit)));
|
||||
|
||||
// Otherwise, the pattern type should match the type of the variable.
|
||||
// Otherwise, we have a normal local-variable initialization and the pattern
|
||||
// type should match the type of the variable.
|
||||
// FIXME: why do we ever get patterns without types here?
|
||||
assert(!patternType || varType == patternType->getCanonicalType());
|
||||
return varInit;
|
||||
return emitLocalVariableWithCleanup(vd);
|
||||
}
|
||||
|
||||
void SILGenFunction::visitPatternBindingDecl(PatternBindingDecl *D) {
|
||||
|
||||
Reference in New Issue
Block a user