Skip to content

Commit 6b43670

Browse files
Merge pull request swiftlang#77603 from nate-chandler/general-coro/20241113/1
[CoroutineAccessors] Several small fixes.
2 parents f2e48bd + 430307a commit 6b43670

File tree

8 files changed

+98
-0
lines changed

8 files changed

+98
-0
lines changed

lib/SIL/IR/SILSymbolVisitor.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,11 @@ class SILSymbolVisitorImpl : public ASTVisitor<SILSymbolVisitorImpl> {
823823
Visitor.addDispatchThunk(declRef);
824824
Visitor.addMethodDescriptor(declRef);
825825
}
826+
auto *decl =
827+
llvm::dyn_cast_or_null<AbstractFunctionDecl>(declRef.getDecl());
828+
if (decl && decl->hasBody()) {
829+
Visitor.addFunction(declRef);
830+
}
826831
}
827832

828833
void addAssociatedType(AssociatedType associatedType) {

lib/SIL/Parser/ParseSIL.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,7 +1291,9 @@ static std::optional<AccessorKind> getAccessorKind(StringRef ident) {
12911291
.Case("addressor", AccessorKind::Address)
12921292
.Case("mutableAddressor", AccessorKind::MutableAddress)
12931293
.Case("read", AccessorKind::Read)
1294+
.Case("read2", AccessorKind::Read2)
12941295
.Case("modify", AccessorKind::Modify)
1296+
.Case("modify2", AccessorKind::Modify2)
12951297
.Default(std::nullopt);
12961298
}
12971299

lib/SILOptimizer/Utils/Devirtualize.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,10 @@ replaceBeginApplyInst(SILBuilder &builder, SILPassManager *pm, SILLocation loc,
619619
// Forward the token.
620620
oldBAI->getTokenResult()->replaceAllUsesWith(newBAI->getTokenResult());
621621

622+
if (auto *allocation = oldBAI->getCalleeAllocationResult()) {
623+
allocation->replaceAllUsesWith(newBAI->getCalleeAllocationResult());
624+
}
625+
622626
auto oldYields = oldBAI->getYieldedValues();
623627
auto newYields = newBAI->getYieldedValues();
624628
assert(oldYields.size() == newYields.size());

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6850,6 +6850,7 @@ void TypeChecker::inferDefaultWitnesses(ProtocolDecl *proto) {
68506850
RequirementEnvironment reqEnv(proto, reqSig, proto, nullptr, nullptr);
68516851
auto match =
68526852
RequirementMatch(asd, MatchKind::ExactMatch, asdTy, reqEnv);
6853+
match.WitnessSubstitutions = reqEnv.getRequirementToWitnessThunkSubs();
68536854
checker.recordWitness(asd, match);
68546855
}
68556856
}

lib/Sema/TypeCheckStorage.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -950,6 +950,9 @@ bool AccessorDecl::doesAccessorHaveBody() const {
950950
if (!requiresFeatureCoroutineAccessors(accessor->getAccessorKind())) {
951951
return false;
952952
}
953+
if (storage->getOverrideLoc()) {
954+
return false;
955+
}
953956
return accessor->getStorage()
954957
->requiresCorrespondingUnderscoredCoroutineAccessor(
955958
accessor->getAccessorKind(), accessor);

test/SILGen/coroutine_accessors.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,3 +235,13 @@ class OverridableReader : GettableTitle {
235235
}
236236
}
237237
}
238+
239+
// CHECK-LABEL: sil_default_witness_table ReadableField {
240+
// CHECK-NEXT: no_default
241+
// CHECK-NEXT: method #ReadableField.field!read2
242+
// CHECK-SAME: : @$s19coroutine_accessors13ReadableFieldP5fieldSivy
243+
// CHECK-NEXT: }
244+
public protocol ReadableField {
245+
@_borrowed
246+
var field: Int { get }
247+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// RUN: %target-sil-opt \
2+
// RUN: -devirtualizer \
3+
// RUN: %s \
4+
// RUN: -enable-sil-verify-all \
5+
// RUN: -enable-experimental-feature CoroutineAccessors \
6+
// RUN: | %FileCheck %s
7+
8+
// REQUIRES: swift_feature_CoroutineAccessors
9+
10+
import Builtin
11+
12+
struct Int {
13+
var _value: Builtin.Word
14+
}
15+
16+
class Base {
17+
var x : Int { read }
18+
}
19+
20+
class Derived : Base {
21+
override var x : Int { read }
22+
}
23+
24+
// CHECK-LABEL: sil [ossa] @utilize_begin_apply : {{.*}} {
25+
// CHECK-NOT: class_method
26+
// CHECK-LABEL: } // end sil function 'utilize_begin_apply'
27+
sil [ossa] @utilize_begin_apply : $@convention(thin) () -> () {
28+
bb0:
29+
%derived = alloc_ref $Derived
30+
%base = upcast %derived : $Derived to $Base
31+
%reader = class_method %base : $Base, #Base.x!read2 : (Base) -> () -> (), $@yield_once_2 @convention(method) (@guaranteed Base) -> @yields Int
32+
(%value, %token, %allocation) = begin_apply %reader(%base) : $@yield_once_2 @convention(method) (@guaranteed Base) -> @yields Int
33+
end_apply %token as $()
34+
dealloc_stack %allocation : $*Builtin.SILToken
35+
destroy_value %base : $Base
36+
%retval = tuple ()
37+
return %retval : $()
38+
}
39+
40+
sil [ossa] @Base_x_read2 : $@yield_once_2 @convention(method) (@guaranteed Base) -> @yields Int
41+
42+
sil [ossa] @Derived_x_read2 : $@yield_once_2 @convention(method) (@guaranteed Base) -> @yields Int
43+
44+
sil_vtable Base {
45+
#Base.x!read2: @Base_x_read2
46+
}
47+
48+
sil_vtable Derived {
49+
#Base.x!read2: @Derived_x_read2 [override]
50+
}

test/TBD/coroutine_accessors.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: %target-build-swift-dylib(%t/%target-library-name(thing)) \
2+
// RUN: %s \
3+
// RUN: -emit-tbd \
4+
// RUN: -Xfrontend -validate-tbd-against-ir=all \
5+
// RUN: -enable-library-evolution \
6+
// RUN: -Xfrontend -tbd-install_name -Xfrontend thing \
7+
// RUN: -emit-module \
8+
// RUN: -module-name thing \
9+
// RUN: -enable-experimental-feature CoroutineAccessors
10+
11+
// REQUIRES: swift_feature_CoroutineAccessors
12+
13+
public struct S {}
14+
15+
public protocol P {
16+
associatedtype A
17+
18+
var s: S { read set }
19+
}
20+
21+
public protocol Q : P {
22+
override var s: S { read set }
23+
}

0 commit comments

Comments
 (0)