Skip to content

Commit 9220dff

Browse files
committed
SILGen: On-demand accessors in the primary file should still be emitted lazily
Otherwise we won't emit them if we synthesize them after visiting their storage declaration.
1 parent 9c5bd44 commit 9220dff

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

lib/SILGen/SILGen.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -613,14 +613,14 @@ static bool isEmittedOnDemand(SILModule &M, SILDeclRef constant) {
613613
if (isa<ClangModuleUnit>(dc))
614614
return true;
615615

616-
if (auto *sf = dyn_cast<SourceFile>(dc))
617-
if (M.isWholeModule() || M.getAssociatedContext() == dc)
618-
return false;
619-
620616
if (auto *func = dyn_cast<FuncDecl>(d))
621617
if (func->hasForcedStaticDispatch())
622618
return true;
623619

620+
if (auto *sf = dyn_cast<SourceFile>(dc))
621+
if (M.isWholeModule() || M.getAssociatedContext() == dc)
622+
return false;
623+
624624
return false;
625625
}
626626

lib/SILGen/SILGenType.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,7 +1050,8 @@ class SILGenType : public TypeMemberVisitor<SILGenType> {
10501050

10511051
void visitAccessors(AbstractStorageDecl *asd) {
10521052
for (auto *accessor : asd->getAllAccessors())
1053-
visitFuncDecl(accessor);
1053+
if (!accessor->hasForcedStaticDispatch())
1054+
visitFuncDecl(accessor);
10541055
}
10551056
};
10561057

@@ -1180,7 +1181,8 @@ class SILGenExtension : public TypeMemberVisitor<SILGenExtension> {
11801181

11811182
void visitAccessors(AbstractStorageDecl *asd) {
11821183
for (auto *accessor : asd->getAllAccessors())
1183-
visitFuncDecl(accessor);
1184+
if (!accessor->hasForcedStaticDispatch())
1185+
visitFuncDecl(accessor);
11841186
}
11851187
};
11861188

test/SILGen/read_accessor.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -181,14 +181,14 @@ protocol ReadableTitle {
181181
class OverridableGetter : ReadableTitle {
182182
var title: String = ""
183183
}
184-
// The concrete read accessor is generated on-demand and does a class dispatch to the getter.
185-
// CHECK-LABEL: sil shared [ossa] @$s13read_accessor17OverridableGetterC5titleSSvr
186-
// CHECK: class_method %0 : $OverridableGetter, #OverridableGetter.title!getter.1
187-
// CHECK-LABEL: // end sil function '$s13read_accessor17OverridableGetterC5titleSSvr'
188184
// The read witness thunk does a direct call to the concrete read accessor.
189185
// CHECK-LABEL: sil private [transparent] [thunk] [ossa] @$s13read_accessor17OverridableGetterCAA13ReadableTitleA2aDP5titleSSvrTW
190186
// CHECK: function_ref @$s13read_accessor17OverridableGetterC5titleSSvr
191187
// CHECK-LABEL: // end sil function '$s13read_accessor17OverridableGetterCAA13ReadableTitleA2aDP5titleSSvrTW'
188+
// The concrete read accessor is generated on-demand and does a class dispatch to the getter.
189+
// CHECK-LABEL: sil shared [ossa] @$s13read_accessor17OverridableGetterC5titleSSvr
190+
// CHECK: class_method %0 : $OverridableGetter, #OverridableGetter.title!getter.1
191+
// CHECK-LABEL: // end sil function '$s13read_accessor17OverridableGetterC5titleSSvr'
192192

193193
protocol GettableTitle {
194194
var title: String { get }
@@ -197,11 +197,11 @@ class OverridableReader : GettableTitle {
197197
@_borrowed
198198
var title: String = ""
199199
}
200-
// The concrete getter is generated on-demand and does a class dispatch to the read accessor.
201-
// CHECK-LABEL: sil shared [ossa] @$s13read_accessor17OverridableReaderC5titleSSvg
202-
// CHECK: class_method %0 : $OverridableReader, #OverridableReader.title!read.1
203-
// CHECK-LABEL: // end sil function '$s13read_accessor17OverridableReaderC5titleSSvg'
204200
// The getter witness thunk does a direct call to the concrete getter.
205201
// CHECK-LABEL: sil private [transparent] [thunk] [ossa] @$s13read_accessor17OverridableReaderCAA13GettableTitleA2aDP5titleSSvgTW
206202
// CHECK: function_ref @$s13read_accessor17OverridableReaderC5titleSSvg
207203
// CHECK-LABEL: // end sil function '$s13read_accessor17OverridableReaderCAA13GettableTitleA2aDP5titleSSvgTW'
204+
// The concrete getter is generated on-demand and does a class dispatch to the read accessor.
205+
// CHECK-LABEL: sil shared [ossa] @$s13read_accessor17OverridableReaderC5titleSSvg
206+
// CHECK: class_method %0 : $OverridableReader, #OverridableReader.title!read.1
207+
// CHECK-LABEL: // end sil function '$s13read_accessor17OverridableReaderC5titleSSvg'

0 commit comments

Comments
 (0)