-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Serialization] Fast lookup of nested types in modules with overlays #20024
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
13 changes: 13 additions & 0 deletions
13
test/Serialization/Inputs/nested-type-with-overlay/HasOverlay.h
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,13 @@ | ||
struct Base { | ||
int dummy; | ||
}; | ||
|
||
struct Nested { | ||
int dummy; | ||
} __attribute((swift_name("Base.NestedFromClang"))); | ||
|
||
struct NestedAndShadowed { | ||
int dummy; | ||
} __attribute((swift_name("Base.NestedAndShadowed"))); | ||
|
||
struct NestedAndShadowed getShadowedFromClang(); |
3 changes: 3 additions & 0 deletions
3
test/Serialization/Inputs/nested-type-with-overlay/module.modulemap
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,3 @@ | ||
module HasOverlay { | ||
header "HasOverlay.h" | ||
} |
10 changes: 10 additions & 0 deletions
10
test/Serialization/Inputs/nested-type-with-overlay/overlay.swift
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,10 @@ | ||
@_exported import HasOverlay | ||
|
||
extension Base { | ||
public struct NestedFromSwift {} | ||
public struct NestedAndShadowed { | ||
init(dummy: ()) {} | ||
} | ||
} | ||
|
||
public var shadowedFromSwift = Base.NestedAndShadowed(dummy: ()) |
12 changes: 12 additions & 0 deletions
12
test/Serialization/Inputs/nested-type-with-overlay/verify.swift
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,12 @@ | ||
import main | ||
import HasOverlay | ||
|
||
func test() { | ||
var a = getShadowedFromClang() | ||
a = main.shadowedFromClang // okay | ||
a = HasOverlay.shadowedFromSwift // expected-error {{cannot assign}} | ||
|
||
var b = HasOverlay.shadowedFromSwift | ||
b = main.shadowedFromSwift // okay | ||
b = getShadowedFromClang() // expected-error {{cannot assign}} | ||
} |
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,22 @@ | ||
// RUN: %empty-directory(%t) | ||
// RUN: %target-swift-frontend -emit-module -o %t/HasOverlay.swiftmodule %S/Inputs/nested-type-with-overlay/overlay.swift -I %S/Inputs/nested-type-with-overlay -module-name HasOverlay | ||
|
||
// RUN: %target-swift-frontend -emit-module -o %t/main~partial.swiftmodule -primary-file %s -module-name main -I %t -I %S/Inputs/nested-type-helper | ||
// RUN: %target-swift-frontend -merge-modules -emit-module -o %t/main.swiftmodule %t/main~partial.swiftmodule -print-stats -module-name main -I %t -I %S/Inputs/nested-type-with-overlay 2>&1 | %FileCheck %s | ||
|
||
// RUN: %target-swift-frontend -emit-silgen %S/Inputs/nested-type-with-overlay/verify.swift -I %t -I %S/Inputs/nested-type-with-overlay -verify | ||
|
||
// REQUIRES: asserts | ||
|
||
// CHECK: 3 Serialization - # of nested types resolved without full lookup | ||
// Unfortunately this isn't 4 because of the shadowed nested type from Clang. | ||
|
||
import HasOverlay | ||
|
||
public func resolveNestedTypes( | ||
_: Base.NestedFromClang, | ||
_: Base.NestedFromSwift | ||
) {} | ||
|
||
public var shadowedFromClang = getShadowedFromClang() | ||
public var shadowedFromSwift = HasOverlay.shadowedFromSwift |
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.
Just curious, why assign a 1-element initializer list vs. calling
push_back
?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.
A serialization cross-reference is a chain of nested names; when resolving component N,
values
contains the results from resolving component N-1.* So here we're saying we've resolved component N to a single result, and are replacing the results from component N-1.* It's not always actually the immediately previous component; it's the previous component that represents a type. But, close enough.