SILGen: Manage retain/release properly for dynamic member lookups.

Introduce a proper cleanup for the Optional<T> value created by
non-forced dynamic member lookups.

Additionally, properly manage each reference to an OpaqueValue within
an expression, and release the value when the RAII object goes out of
scope. This is the conservative approach to be optimized soon.


Swift SVN r8071
This commit is contained in:
Doug Gregor
2013-09-10 17:40:51 +00:00
parent af562d1696
commit d04e9b7659
3 changed files with 28 additions and 11 deletions

View File

@@ -1679,13 +1679,17 @@ RValue SILGenFunction::emitDynamicMemberRefExpr(DynamicMemberRefExpr *e,
SILValue appliedMethod = B.createPartialApply(e, memberArg, operand,
getLoweredType(methodTy));
// Package up the applied method in .Some().
OpaqueValueRAII opaqueValue(*this, e->getOpaqueFn(), appliedMethod);
SILValue optResult;
{
// Package up the applied method in .Some().
OpaqueValueRAII opaqueValue(*this, e->getOpaqueFn(), appliedMethod);
optResult = emitRValue(e->getCreateSome()).forwardAsSingleValue(*this, e);
}
// Branch to the continuation block.
B.createBranch(e, contBB,
emitRValue(e->getCreateSome()).forwardAsSingleValue(*this,
e));
B.createBranch(e, contBB, optResult);
}
// Create the no-member branch.
@@ -1704,7 +1708,6 @@ RValue SILGenFunction::emitDynamicMemberRefExpr(DynamicMemberRefExpr *e,
B.emitBlock(contBB);
// Package up the result.
ManagedValue result(optMethodArg, existential.getCleanup());
return RValue(*this, result, e);
return RValue(*this, emitManagedRValueWithCleanup(optMethodArg), e);
}