Implement generalized accessors using yield-once coroutines.

For now, the accessors have been underscored as `_read` and `_modify`.
I'll prepare an evolution proposal for this feature which should allow
us to remove the underscores or, y'know, rename them to `purple` and
`lettuce`.

`_read` accessors do not make any effort yet to avoid copying the
value being yielded.  I'll work on it in follow-up patches.

Opaque accesses to properties and subscripts defined with `_modify`
accessors will use an inefficient `materializeForSet` pattern that
materializes the value to a temporary instead of accessing it in-place.
That will be fixed by migrating to `modify` over `materializeForSet`,
which is next up after the `read` optimizations.

SIL ownership verification doesn't pass yet for the test cases here
because of a general fault in SILGen where borrows can outlive their
borrowed value due to being cleaned up on the general cleanup stack
when the borrowed value is cleaned up on the formal-access stack.
Michael, Andy, and I discussed various ways to fix this, but it seems
clear to me that it's not in any way specific to coroutine accesses.

rdar://35399664
This commit is contained in:
John McCall
2018-07-22 02:28:59 -04:00
parent 46a83909c6
commit 7a4aeed570
91 changed files with 1935 additions and 136 deletions

View File

@@ -228,6 +228,10 @@ UIdent SwiftLangSupport::getUIDForAccessor(const ValueDecl *D,
case AccessorKind::MutableAddress:
return IsRef ? KindRefAccessorMutableAddress
: KindDeclAccessorMutableAddress;
case AccessorKind::Read:
return IsRef ? KindRefAccessorRead : KindDeclAccessorRead;
case AccessorKind::Modify:
return IsRef ? KindRefAccessorModify : KindDeclAccessorModify;
}
llvm_unreachable("Unhandled AccessorKind in switch.");