mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
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:
@@ -1465,6 +1465,8 @@ public:
|
||||
void completeAssignmentRHS(AssignExpr *E) override;
|
||||
void completeCallArg(CallExpr *E) override;
|
||||
void completeReturnStmt(CodeCompletionExpr *E) override;
|
||||
void completeYieldStmt(CodeCompletionExpr *E,
|
||||
Optional<unsigned> yieldIndex) override;
|
||||
void completeAfterPound(CodeCompletionExpr *E, StmtKind ParentKind) override;
|
||||
void completeGenericParams(TypeLoc TL) override;
|
||||
void completeAfterIfStmt(bool hasElse) override;
|
||||
@@ -4746,6 +4748,15 @@ void CodeCompletionCallbacksImpl::completeReturnStmt(CodeCompletionExpr *E) {
|
||||
Kind = CompletionKind::ReturnStmtExpr;
|
||||
}
|
||||
|
||||
void CodeCompletionCallbacksImpl::completeYieldStmt(CodeCompletionExpr *E,
|
||||
Optional<unsigned> index) {
|
||||
CurDeclContext = P.CurDeclContext;
|
||||
CodeCompleteTokenExpr = E;
|
||||
// TODO: use a different completion kind when completing without an index
|
||||
// in a multiple-value context.
|
||||
Kind = CompletionKind::YieldStmtExpr;
|
||||
}
|
||||
|
||||
void CodeCompletionCallbacksImpl::completeAfterPound(CodeCompletionExpr *E,
|
||||
StmtKind ParentKind) {
|
||||
CurDeclContext = P.CurDeclContext;
|
||||
@@ -4890,6 +4901,7 @@ void CodeCompletionCallbacksImpl::addKeywords(CodeCompletionResultSink &Sink,
|
||||
LLVM_FALLTHROUGH;
|
||||
case CompletionKind::AssignmentRHS:
|
||||
case CompletionKind::ReturnStmtExpr:
|
||||
case CompletionKind::YieldStmtExpr:
|
||||
case CompletionKind::PostfixExprBeginning:
|
||||
case CompletionKind::ForEachSequence:
|
||||
addSuperKeyword(Sink);
|
||||
@@ -5479,6 +5491,18 @@ void CodeCompletionCallbacksImpl::doneParsing() {
|
||||
break;
|
||||
}
|
||||
|
||||
case CompletionKind::YieldStmtExpr: {
|
||||
SourceLoc Loc = P.Context.SourceMgr.getCodeCompletionLoc();
|
||||
if (auto FD = dyn_cast<AccessorDecl>(CurDeclContext)) {
|
||||
if (FD->isCoroutine()) {
|
||||
// TODO: handle multi-value yields.
|
||||
Lookup.setExpectedTypes(FD->getStorage()->getValueInterfaceType());
|
||||
}
|
||||
}
|
||||
Lookup.getValueCompletionsInDeclContext(Loc);
|
||||
break;
|
||||
}
|
||||
|
||||
case CompletionKind::AfterPound: {
|
||||
Lookup.addPoundAvailable(ParentStmtKind);
|
||||
Lookup.addPoundSelector(/*needPound=*/false);
|
||||
|
||||
Reference in New Issue
Block a user