-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Revert "Revert "[cxx-interop] Import decls in extern blocks within namespaces"" #83589
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
egorzhdan
merged 2 commits into
swiftlang:main
from
egorzhdan:egorzhdan/reland-extern-namespace
Aug 15, 2025
+186
−63
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
28 changes: 28 additions & 0 deletions
28
test/Interop/Cxx/namespace/Inputs/extern-within-namespace.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,28 @@ | ||
namespace Outer { | ||
namespace Inner { | ||
extern "C" { | ||
int foobar() { return 123; } | ||
struct NestedType { | ||
char c; | ||
}; | ||
} | ||
} // namespace Inner | ||
|
||
inline namespace InnerInline { | ||
extern "C" { | ||
int baz() { return 321; } | ||
} | ||
} // namespace InnerInline | ||
} // namespace Outer | ||
|
||
namespace ExternWithinExtern { | ||
extern "C" { | ||
extern "C++" { | ||
namespace Inner { | ||
extern "C" { | ||
int deep() { return 42; } | ||
} | ||
} // namespace Inner | ||
} | ||
} | ||
} // namespace ExternWithinExtern |
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
17 changes: 17 additions & 0 deletions
17
test/Interop/Cxx/namespace/extern-within-namespace-module-interface.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,17 @@ | ||
// RUN: %target-swift-ide-test -print-module -module-to-print=ExternWithinNamespace -I %S/Inputs -source-filename=x -cxx-interoperability-mode=upcoming-swift | %FileCheck %s | ||
|
||
// CHECK: enum Outer { | ||
// CHECK-NEXT: enum Inner { | ||
// CHECK-NEXT: static func foobar() | ||
// CHECK-NEXT: struct NestedType { | ||
// CHECK: } | ||
// CHECK-NEXT: } | ||
// CHECK-NEXT: enum InnerInline { | ||
// CHECK-NEXT: static func baz() -> Int32 | ||
// CHECK-NEXT: } | ||
// CHECK-NEXT: } | ||
// CHECK-NEXT: enum ExternWithinExtern { | ||
// CHECK-NEXT: enum Inner { | ||
// CHECK-NEXT: static func deep() -> Int32 | ||
// CHECK-NEXT: } | ||
// CHECK-NEXT: } |
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,25 @@ | ||
// RUN: %target-run-simple-swift(-I %S/Inputs -Xfrontend -cxx-interoperability-mode=upcoming-swift) | ||
|
||
// REQUIRES: executable_test | ||
|
||
import StdlibUnittest | ||
import ExternWithinNamespace | ||
|
||
var ExternTestSuite = TestSuite("Extern block within namespaces") | ||
|
||
ExternTestSuite.test("Function within extern block within namespace") { | ||
let r = Outer.Inner.foobar() | ||
expectEqual(r, 123) | ||
} | ||
|
||
ExternTestSuite.test("Function within extern block within inline namespace") { | ||
let r = Outer.InnerInline.baz() | ||
expectEqual(r, 321) | ||
} | ||
|
||
ExternTestSuite.test("Function within extern block within extern block") { | ||
let r = ExternWithinExtern.Inner.deep() | ||
expectEqual(r, 42) | ||
} | ||
|
||
runAllTests() |
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.
Is the root issue in the module/header construction in libc++, or in the (de)serialization implementation? Do we have a ticket tracking the root cause, so that we can eventually remove this hack?
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.
The problem here seems to be on the intersection of Swift modules and Clang modules – in Clang AST, this function is represented as a definition in
_math
and a declaration instd_private_random_binomial_distribution
, but in Swift we're getting a function declaration instd_private_random_binomial_distribution
and nothing in_math
.So serialization and deserialization work as expected here.
I'm not sure if there is a good reason to redeclare
lgamma_r
in libc++, I'll check with libc++ folks on this.