-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Serialization] Handle XREFs to private types #14352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import LibCore | ||
|
||
public let lazyFoo = Foo() | ||
public func testFoo(_: Foo = lazyFoo) {} | ||
public let lazyBar = Bar() | ||
public func testBar(_: Bar = lazyBar) {} | ||
public let lazyBaz = Baz() | ||
public func testBaz(_: Baz = lazyBaz) {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
private class TopLevelInternalClass {} | ||
public struct Foo { | ||
private var ref: TopLevelInternalClass | ||
|
||
public init() { self.ref = .init() } | ||
} | ||
|
||
public struct Bar { | ||
private class NestedInternalClass {} | ||
|
||
private var ref: NestedInternalClass | ||
|
||
public init() { self.ref = .init() } | ||
} | ||
|
||
public struct Baz { | ||
fileprivate class NestedInternalClass { | ||
fileprivate class DoublyNestedInternalClass {} | ||
} | ||
|
||
private var ref: NestedInternalClass.DoublyNestedInternalClass | ||
|
||
public init() { self.ref = .init() } | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// RUN: %empty-directory(%t) | ||
// RUN: %target-build-swift -swift-version 4 -O -force-single-frontend-invocation -emit-module-path %t/LibCore.swiftmodule %S/Inputs/xref-private-type/LibCore.swift | ||
// RUN: %target-build-swift -swift-version 4 -O -I %t -force-single-frontend-invocation -emit-module-path %t/Lib.swiftmodule %S/Inputs/xref-private-type/Lib.swift | ||
// RUN: %target-build-swift -swift-version 4 -O -I %t -emit-sil %s | %FileCheck %s | ||
|
||
import Lib | ||
|
||
// CHECK: sil{{.*}} @[[TESTSR6874:[^ ]+10testSR6874[^ ]+]] : | ||
func testSR6874() { | ||
// The important lines in this test are the strong_retains, which refer to | ||
// private types defined in LibCore. Normally we shouldn't have references to | ||
// non-public declarations in inlinable code, but because SIL passes can break | ||
// apart non-resilient structs and enums we can end up in that situation. | ||
// Worse, this can happen *across module boundaries.* | ||
// | ||
// In this test, the addressor for each global defined in Lib ends up | ||
// referencing private types defined in LibCore. Using those globals in | ||
// default argument position leads to the addressor getting inlined into | ||
// calling code in Swift 4 and later. This results in an attempt to not just | ||
// reference a private type, but to *resolve a cross-reference to a private | ||
// type.* | ||
// | ||
// This is the situation in SR-6874 (simplified). I'm not sure of a simpler | ||
// way to reliably trigger the issue. But if this test breaks, please try to | ||
// find one. | ||
// | ||
// (We may want to revisit this whole thing later, as it violates the model. | ||
// But it's also useful for performance in non-resilient code.) | ||
|
||
// CHECK: [[ADDR:%.+]] = global_addr @{{[^ ]+}}3Lib7lazyFoo | ||
// CHECK: [[LOADED:%.+]] = load [[ADDR]] : $*Foo | ||
// CHECK: [[REF:%.+]] = struct_extract [[LOADED]] : $Foo, #Foo.ref | ||
// CHECK: strong_retain [[REF]] : $TopLevelInternalClass | ||
// CHECK: apply {{%.+}}([[LOADED]]) | ||
testFoo() | ||
|
||
// CHECK: [[ADDR:%.+]] = global_addr @{{[^ ]+}}3Lib7lazyBar | ||
// CHECK: [[LOADED:%.+]] = load [[ADDR]] : $*Bar | ||
// CHECK: [[REF:%.+]] = struct_extract [[LOADED]] : $Bar, #Bar.ref | ||
// CHECK: strong_retain [[REF]] : $Bar.NestedInternalClass | ||
// CHECK: apply {{%.+}}([[LOADED]]) | ||
testBar() | ||
|
||
// CHECK: [[ADDR:%.+]] = global_addr @{{[^ ]+}}3Lib7lazyBaz | ||
// CHECK: [[LOADED:%.+]] = load [[ADDR]] : $*Baz | ||
// CHECK: [[REF:%.+]] = struct_extract [[LOADED]] : $Baz, #Baz.ref | ||
// CHECK: strong_retain [[REF]] : $Baz.NestedInternalClass.DoublyNestedInternalClass | ||
// CHECK: apply {{%.+}}([[LOADED]]) | ||
testBaz() | ||
} // CHECK: end sil function '[[TESTSR6874]]' | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Boo :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess I could have written a do-while-false loop, but I think that would have been less self-documenting.