Skip to content

Conversation

slavapestov
Copy link
Contributor

No description provided.

This also adds some tests for the existing generic parameter
capture logic, which was only tested as part of SILGen tests
until now.

Also, move capture analysis into a new TypeCheckCaptures.cpp file.
To support closures that capture the dynamic Self type, we need to add
a new hidden parameter which does not have a VarDecl.
…type of $Self

Formerly SILGen would never emit this sequence. In fact in most places
we lower away dynamic Self, replacing it with the concrete Self type
instead.

However, with an upcoming change, I'm using 'metatype $Self' as a handy
way to grab IRGenSILFunction::LocalSelfMetadata, since that's what it
already does.

Note that the tests for this are in the next patch.
If a closure captures the dynamic 'Self' type, but no value of type 'Self'
(for example, it is possible to have a weak capture of 'self'; if the weak
reference becomes nil, there's no way for the closure to get the dynamic
'Self' type from the value).

In this case, add a hidden argument of type $Self.Type, and pass in the
Self metatype.

Fixes <https://bugs.swift.org/browse/SR-1558> / <rdar://problem/22299905>.
@@ -26,12 +26,6 @@ using namespace swift;
SILArgument::SILArgument(SILBasicBlock *ParentBB, SILType Ty,
const ValueDecl *D)
: ValueBase(ValueKind::SILArgument, Ty), ParentBB(ParentBB), Decl(D) {
// Function arguments need to have a decl.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @jckarter, if you have a better idea here, let me know. I'm not a fan of removing assertions for all the usual reasons.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of this particular assertion, but you might want to check with @adrian-prantl to make sure the debugger's able to do something reasonable with the self metadata.

@slavapestov
Copy link
Contributor Author

@swift-ci Please test

@slavapestov slavapestov merged commit e920ddc into swiftlang:master Jun 28, 2016
@slavapestov slavapestov deleted the fix-capturing-dynamic-self branch June 28, 2016 04:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants