Skip to content

Commit 001534c

Browse files
committed
SIL: Serialize default arguments of inlinable local functions
Fixes <https://bugs.swift.org/browse/SR-12404>.
1 parent edb71db commit 001534c

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

lib/SIL/IR/SILDeclRef.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -442,12 +442,9 @@ bool SILDeclRef::isTransparent() const {
442442

443443
/// True if the function should have its body serialized.
444444
IsSerialized_t SILDeclRef::isSerialized() const {
445-
DeclContext *dc;
446445
if (auto closure = getAbstractClosureExpr()) {
447-
dc = closure->getLocalContext();
448-
449-
// Otherwise, ask the AST if we're inside an @inlinable context.
450-
if (dc->getResilienceExpansion() == ResilienceExpansion::Minimal) {
446+
// Ask the AST if we're inside an @inlinable context.
447+
if (closure->getResilienceExpansion() == ResilienceExpansion::Minimal) {
451448
if (isForeign)
452449
return IsSerializable;
453450

@@ -465,6 +462,13 @@ IsSerialized_t SILDeclRef::isSerialized() const {
465462
// Default argument generators are serialized if the containing
466463
// declaration is public.
467464
if (isDefaultArgGenerator()) {
465+
// Ask the AST if we're inside an @inlinable context.
466+
if (d->getDeclContext()->getResilienceExpansion()
467+
== ResilienceExpansion::Minimal) {
468+
return IsSerialized;
469+
}
470+
471+
// Otherwise, check if the owning declaration is public.
468472
auto scope =
469473
d->getFormalAccessScope(/*useDC=*/nullptr,
470474
/*treatUsableFromInlineAsPublic=*/true);
@@ -490,7 +494,7 @@ IsSerialized_t SILDeclRef::isSerialized() const {
490494

491495
// Note: if 'd' is a function, then 'dc' is the function itself, not
492496
// its parent context.
493-
dc = d->getInnermostDeclContext();
497+
auto *dc = d->getInnermostDeclContext();
494498

495499
// Local functions are serializable if their parent function is
496500
// serializable.

test/SILGen/default_arguments_local.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,16 @@ class ArtClass<T> {
5757
return 0
5858
}
5959
}
60+
61+
// Default arguments of local functions inside @inlinable contexts should be serialized.
62+
// https://bugs.swift.org/browse/SR-12404
63+
64+
// CHECK-LABEL: sil [serialized] [ossa] @$s23default_arguments_local5outeryyF : $@convention(thin) () -> () {
65+
@inlinable public func outer() {
66+
// CHECK-LABEL: sil shared [serialized] [ossa] @$s23default_arguments_local5outeryyF5innerL_1xySi_tFfA_ : $@convention(thin) () -> Int {
67+
68+
// CHECK-LABEL: sil shared [serializable] [ossa] @$s23default_arguments_local5outeryyF5innerL_1xySi_tF : $@convention(thin) (Int) -> () {
69+
func inner(x: Int = 0) {}
70+
71+
inner()
72+
}

0 commit comments

Comments
 (0)