Commit Graph

174 Commits

Author SHA1 Message Date
Hiroshi Yamauchi
be641d73ef Fix the GUID type not found error on Windows
Predefined declarations (like _GUID) are special forward declarations
inserted by Clang and aren't serialized into the pcm and their
definition pointers aren't retained across serialization and
deserialization, which causes this type not found error. Avoid putting
non-defining predefined declarations into the swift lookup table when
their definitions exist in the same module so that the definitions
will be associated with the base name and avoid this error.
2025-11-19 17:27:50 -08:00
swift-ci
65bba7d138 Merge remote-tracking branch 'origin/main' into rebranch 2025-09-23 11:57:20 -07:00
Egor Zhdan
c3a56fdc91 Revert "[cxx-interop] Import decls in extern blocks within namespaces"
This reverts commit 844787fd

Reverting because of a modularization issue in host libc++.

rdar://160536819
rdar://160536878
2025-09-17 19:17:14 +01:00
Egor Zhdan
d15e139014 Revert "[cxx-interop] Do not look into extern blocks in libc++'s std_private_random_binomial_distribution"
This reverts commit 8e71509108.
2025-09-17 19:15:57 +01:00
swift-ci
c0223fb423 Merge remote-tracking branch 'origin/main' into rebranch 2025-08-15 12:15:24 -07:00
Egor Zhdan
8e71509108 [cxx-interop] Do not look into extern blocks in libc++'s std_private_random_binomial_distribution
rdar://139067788
2025-08-08 18:47:28 +01:00
Egor Zhdan
a5b4975204 Revert "Revert "[cxx-interop] Import decls in extern blocks within namespaces""
This reverts commit 8f60840551.
2025-08-07 15:03:08 +01:00
swift-ci
e50230f935 Merge remote-tracking branch 'origin/main' into rebranch 2025-08-06 22:35:25 -07:00
Allan Shortlidge
8f60840551 Revert "[cxx-interop] Import decls in extern blocks within namespaces"
This reverts commit 844787fddb.
2025-08-06 21:50:55 -07:00
swift-ci
43b83de02e Merge remote-tracking branch 'origin/main' into rebranch 2025-08-06 04:34:26 -07:00
Egor Zhdan
844787fddb [cxx-interop] Import decls in extern blocks within namespaces
This teaches ClangImporter to import C++ decls that are declared within `extern "C" { ... }`/`extern "C++" { ... }` blocks which are nested in namespaces.

rdar://139067788
2025-08-04 19:42:43 +01:00
swift-ci
3998a187f9 Merge remote-tracking branch 'origin/main' into rebranch 2025-07-30 09:36:41 -07:00
Anthony Latsis
3f841b515c Merge remote-tracking branch 'origin/main' into jepa-rebranch 2025-07-30 14:31:33 +01:00
Anthony Latsis
fec049e5e4 Address llvm::PointerUnion::{is,get} deprecations
These were deprecated in
https://github.com/llvm/llvm-project/pull/122623.
2025-07-29 18:37:48 +01:00
Egor Zhdan
ba8807802f Merge pull request #83261 from egorzhdan/egorzhdan/allow-qual-swift-name-reland
Reland "[cxx-interop] Allow import-as-member for types in namespaces"
2025-07-25 12:35:59 +01:00
Egor Zhdan
e4af21f4c2 [cxx-interop] Fix source compatibility for NSEvent.SpecialKey.upArrow.rawValue
AppKit renames some of its C constants via API Notes, e.g. `NSUpArrowFunctionKey` is renamed into `NSEvent.SpecialKey.upArrow.rawValue`.

In this example, `NSEvent` is an existing type, but `SpecialKey` is not, so the Swift compiler synthesizes an empty type named `SpecialKey`.

The logic that was added to support import-as-member for namespaces did not account for this: it assumed that if a nested type wasn't found, then the name must be invalid.

rdar://154783494
2025-07-24 12:47:17 +01:00
swift-ci
c8477b5f42 Merge remote-tracking branch 'origin/main' into rebranch 2025-07-23 13:17:41 -07:00
Doug Gregor
72be0e0851 [Clang importer] Import incomplete SWIFT_SHARED_REFERENCE types
Normally, Swift cannot import an incomplete type. However, when we are
importing a SWIFT_SHARED_REFERENCE type, we're always dealing with
pointers to the type, and there is no need for the underlying type to
be complete. This permits a common pattern in C libraries where the
actual underlying storage is opaque and all APIs traffic in the
pointer, e.g.,

    typedef struct MyTypeImpl *MyType;
    void MyTypeRetain(MyType ptr);
    void MyTypeRelease(MyType ptr);

to use SWIFT_SHARED_REFERENCE to import such types as foreign
references, rather than as OpaquePointer.

Fixes rdar://155970441.
2025-07-22 20:20:23 -07:00
Egor Zhdan
ab54e00097 Revert "Revert "[cxx-interop] Allow import-as-member for types in namespaces""
This reverts commit dd809c6452.
2025-07-22 18:36:27 +01:00
swift-ci
b02a3ab4c2 Merge remote-tracking branch 'origin/main' into rebranch 2025-07-18 04:17:04 -07:00
Susana Monteiro
0337f7e64a Merge pull request #83067 from susmonteiro/rename-virtual-methods
[cxx-interop] Adding swift_name attributes to virtual methods overrides
2025-07-18 11:57:46 +01:00
susmonteiro
585ca5e2da [cxx-interop] Adding swift_name attributes to virtual methods overrides 2025-07-17 16:23:32 +01:00
swift-ci
1330e7a74c Merge remote-tracking branch 'origin/main' into rebranch 2025-07-10 08:55:10 -07:00
Ben Barham
dd809c6452 Revert "[cxx-interop] Allow import-as-member for types in namespaces"
This reverts commit e95f6a3ce9.
2025-07-09 12:50:34 -07:00
swift-ci
4129e2fc45 Merge remote-tracking branch 'origin/main' into rebranch 2025-06-27 05:38:12 -07:00
Egor Zhdan
e95f6a3ce9 [cxx-interop] Allow import-as-member for types in namespaces
This adds support for `swift_name` attribute being used with C++ types that are declared within namespaces, e.g.
```
__attribute__((swift_name("MyNamespace.MyType.my_method()")))
```

Previously import-as-member would only accept a top-level unqualified type name.

rdar://138934888
2025-06-26 12:39:50 +01:00
Anthony Latsis
a090bfed1b ClangImporter: Refactor call to obsoleted clang::ASTWriter::getMacroID
Per 5d62a79bb79fee20f92f26dc55fd78440b9945ca (llvm-project).
2025-04-24 01:52:47 +01:00
Allan Shortlidge
6527a068eb ClangImporter: Remove custom AvailabilityDomain serialization.
Partially revert https://github.com/swiftlang/swift/pull/80035 now that Clang
has its own APIs for querying serialized modules for the decl representing the
availability domain with a given name.
2025-04-08 08:53:06 -07:00
Allan Shortlidge
72c821e2a7 ClangImporter: Look up availability domains in Clang modules.
In addition to tracking availability domains in SwiftLookupTable, also
serialize and deserialize the mapping from domain name to `clang::VarDecl`.
Ideally this serialization and lookup infrastructure would be entirely handled
by Clang, since it also needs to look up availability domains in serialized
modules, but the implementation for that is not ready yet.

Part of rdar://138441266.
2025-03-15 07:44:37 -07:00
Allan Shortlidge
017dae382e ClangImporter: Look up availability domains defined in bridging headers.
This is very brittle in this first iteration. For now we require the
declaration representing the availability domain be deserialized before it can
be looked up by name since Clang does not have a lookup table for availabilty
domains in its module representation. As a result, it only works for bridging
headers that are not precompiled.

Part of rdar://138441266.
2025-03-15 07:44:37 -07:00
fahadnayyar
d8f919778d [cxx-interop] [cxx-interop] Infer SWIFT_SHARED_REFERENCE for types inheriting from a C++ foreign reference type
rdar://97914474
2025-02-20 08:46:57 -08:00
Ben Barham
05d62155f8 Merge remote-tracking branch 'origin/main' into manual-main-20240814
Conflicts:
  - `include/swift/Localization/LocalizationFormat.h`
  - `lib/ClangImporter/SwiftLookupTable.cpp`
  - `lib/ClangImporter/SwiftLookupTable.h`
  - `lib/Serialization/ModuleFormat.h`
  - `lib/Serialization/Serialization.cpp`

All from the hash changes being added to main. Took main except for the
lookup table minor version, which needs to be bumped still because of
other changes.
2024-08-14 19:21:52 -07:00
Ben Barham
273d7ee79d [Serialization] Do not serialize unstable hashes
https://github.com/llvm/llvm-project/pull/96282 changed
`get_execution_seed` to be non-deterministic. Use stable hashes instead.
2024-08-13 19:51:35 -07:00
Ben Barham
cfbc007535 [rebranch] Do not serialize unstable hashes
https://github.com/llvm/llvm-project/pull/96282 changed
`get_execution_seed` to be non-deterministic. Use stable hashes instead.
2024-08-01 14:33:44 -07:00
Becca Royal-Gordon
0a6e5874e2 Accommodate 64-bit clang serialization IDs
Several serialization IDs that used to be 32 bits are being widened to 64. Modify SwiftLookupTable and its supporting types to accommodate this.

The new design uses a 64-bit integer for the pointer, decl, macro, or identifier ID, plus a 32-bit integer for the submodule ID (this field is set to all ones to indicate a decl vs. a macro). An additional in-memory bool distinguishes pointer nodes from ID nodes. Advantages:

• The main ID is now 64 bits wide, accommodating recent changes in clang.
• We’re no longer stealing bits from clang (we *do* steal the max value of the submodule ID, though).
• There’s no on-disk bit that, when set, will cause an ID to be interpreted as a pointer.
• Design is robust against `clang::serialization::SubmoduleID` also becoming 64-bit (although this will waste space).

Fixes rdar://131134424.
2024-07-31 08:57:31 -07:00
Ben Barham
70c348129f [ClangImporter] Use new LocalDeclID
There were a number of upstream LLVM changes to `DeclID` in order to
separate "local" and "global" IDs:
07b1177eed
b8e3b2ad66
b467c6b536
https://github.com/llvm/llvm-project/pull/89873
d86cc73bbf
8af86025af
... and probably more.

This likely needs further cleaning up to not use `DeclID` at all.
2024-07-02 16:13:49 -07:00
Ben Barham
b7954411ec Merge remote-tracking branch 'origin/main' into manually-merge-main-to-rebranch
Conflicts:
  - `include/swift/AST/PluginRegistry.h`
2024-06-27 14:56:11 -07:00
Hamish Knight
bb4d0126f4 [ClangImporter] Switch lookupGlobalsAsMembers to take a non-optional EffectiveClangContext
The only caller is `loadNamedMembers`, and that
passes in a non-optional EffectiveClangContext,
meaning that we'd miss the case when
`getEffectiveClangContext` returns `nullptr`, crashing
in `translateContext`. No test case unfortunately
as I haven't been able to come up with a reproducer.

rdar://129619711
2024-06-25 12:27:48 +01:00
Xi Ge
736ccef626 Merge remote-tracking branch 'apple/main' into rebranch 2024-06-20 15:16:55 -07:00
Tim Kientzle
1d961ba22d Add #include "swift/Basic/Assertions.h" to a lot of source files
Although I don't plan to bring over new assertions wholesale
into the current qualification branch, it's entirely possible
that various minor changes in main will use the new assertions;
having this basic support in the release branch will simplify that.
(This is why I'm adding the includes as a separate pass from
rewriting the individual assertions)
2024-06-05 19:37:30 -07:00
Ben Barham
cacfd3e3ae Rename llvm::support::endianness to llvm::endianness
LLVM is gearing up to move to `std::endianness` and as part of that has
moved `llvm::support::endianness` to `llvm::endianness`
(bbdbcd83e6702f314d147a680247058a899ba261). Rename our uses.
2024-04-08 08:58:58 -07:00
Ben Barham
f292ec9784 Use the new template deduction guides rather than makeArrayRef
LLVM has removed `make*ArrayRef`, migrate all references to their
constructor equivalent.
2024-02-23 20:04:51 -08:00
Ben Barham
ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -08:00
Egor Zhdan
c8017e7d9f [cxx-interop] Add friend operators to the lookup table properly
Previously, `friend` operators declared in C++ classes were added to the lookup table when the class is being imported.

The operators were added to the wrong lookup table if the class is declared in a C++ namespace. Since a namespace can span across multiple Clang modules, its contents should be added to a translation unit level lookup table, not to a module level lookup table.

This change makes sure we add `friend` operators to the lookup table earlier, when we are actually building the lookup table. Note that this is not possible for class template instantiations, because those are instantiated later, so for templates we still handle `friend` operators when importing the instantiation.

rdar://116349899
2023-12-08 18:48:58 +00:00
Egor Zhdan
efc008a2ca [cxx-interop] Import using decls that expose methods from private base classes
If a C++ type `Derived` inherits from `Base` privately, the public methods from `Base` should not be callable on an instance of `Derived`. However, C++ supports exposing such methods via a using declaration: `using MyPrivateBase::myPublicMethod;`.

MSVC started using this feature for `std::optional` which means Swift doesn't correctly import `var pointee: Pointee` for instantiations of `std::optional` on Windows. This prevents the automatic conformance to `CxxOptional` from being synthesized.

 rdar://114282353 / resolves https://github.com/apple/swift/issues/68068
2023-11-14 00:30:54 +00:00
Egor Zhdan
64401aeeea [ClangImporter] NFC: Remove unused definitions 2023-07-20 19:37:58 +01:00
Evan Wilde
250082df25 [NFC] Reformat all the LLVMs
Reformatting everything now that we have `llvm` namespaces. I've
separated this from the main commit to help manage merge-conflicts and
for making it a bit easier to read the mega-patch.
2023-06-27 09:03:52 -07:00
Evan Wilde
f3ff561c6f [NFC] add llvm namespace to Optional and None
This is phase-1 of switching from llvm::Optional to std::optional in the
next rebranch. llvm::Optional was removed from upstream LLVM, so we need
to migrate off rather soon. On Darwin, std::optional, and llvm::Optional
have the same layout, so we don't need to be as concerned about ABI
beyond the name mangling. `llvm::Optional` is only returned from one
function in
```
getStandardTypeSubst(StringRef TypeName,
                     bool allowConcurrencyManglings);
```
It's the return value, so it should not impact the mangling of the
function, and the layout is the same as `std::optional`, so it should be
mostly okay. This function doesn't appear to have users, and the ABI was
already broken 2 years ago for concurrency and no one seemed to notice
so this should be "okay".

I'm doing the migration incrementally so that folks working on main can
cherry-pick back to the release/5.9 branch. Once 5.9 is done and locked
away, then we can go through and finish the replacement. Since `None`
and `Optional` show up in contexts where they are not `llvm::None` and
`llvm::Optional`, I'm preparing the work now by going through and
removing the namespace unwrapping and making the `llvm` namespace
explicit. This should make it fairly mechanical to go through and
replace llvm::Optional with std::optional, and llvm::None with
std::nullopt. It's also a change that can be brought onto the
release/5.9 with minimal impact. This should be an NFC change.
2023-06-27 09:03:52 -07:00
zoecarver
4c73369366 Revert "[cxx-interop] Add debug dump when we hit The Flakey Issue™."
This reverts commit 75dc69a81d.
2023-03-21 13:27:17 -07:00
zoecarver
00dc5406fb Revert "[nfc] Fix a few warnings I introduced."
This reverts commit 077d3cb8b3.
2023-03-21 13:27:11 -07:00