Commit Graph

1871 Commits

Author SHA1 Message Date
Egor Zhdan
c81325461a [cxx-interop] Treat un-instantiated templated types as unsafe
When determining whether a C++ method is safe to be imported, we look at its return type to see if it stores any pointers in its fields.

If the type is templated, we might not have its definition available yet. Unfortunately we cannot instantiate it on the spot, since the Clang AST would be read and written at the same time.

Let's stay on the safe side and treat such methods as unsafe.

rdar://107609381
2023-04-04 15:33:09 +01:00
Doug Gregor
828de17b00 [Macros] Resolve macro names using unqualified lookup that ignores expansions
The macro name resolution in the source lookup cache was only looking at
macros in the current module, meaning that any names introduced by peer
or declaration macros declared in one module but used in another would
not be found by name lookup.

Switch the source lookup cache over to using the same
`forEachPotentialResolvedMacro` API that is used by lookup within
types, so we have consistent name-lookup-level macro resolution in both
places.

... except that would be horribly cyclic, of course, so introduce name
lookup flags to ignore top-level declarations introduced by macro
expansions. This is semantically correct because macro expansions are
not allowed to introduce new macros anyway, because that would have
been a terrible idea.

Fixes rdar://107321469. Peer and declaration macros at module scope
should work a whole lot better now.
2023-04-02 23:15:38 -07:00
Becca Royal-Gordon
e09d02e12f [NFC] Expose extension category name accessor 2023-03-25 14:52:40 -07:00
Zoe Carver
e93e7d1b7a Merge pull request #64513 from zoecarver/revert-75dc69a81da07647bda2d1ccc3b82ce6e68b44a7
Revert 75dc69a81d
2023-03-23 09:58:10 -07:00
zoecarver
00dc5406fb Revert "[nfc] Fix a few warnings I introduced."
This reverts commit 077d3cb8b3.
2023-03-21 13:27:11 -07:00
Ben Barham
8090366ff6 Merge pull request #64491 from bnbarham/probe-precompiled
[ClangImporter] Probe for a PCH when the header is missing
2023-03-21 11:01:46 -07:00
Zoe Carver
b90f789df3 Merge pull request #64438 from zoecarver/fixits-for-clang-types-swiftpm-2 2023-03-21 08:28:34 -07:00
zoecarver
ba8e00d7f2 [cxx-interop] Add fix-it for foreign reference types. 2023-03-20 16:14:42 -07:00
zoecarver
ebc492a368 [cxx-interop] Add fix-its to apply 'safe_to_import' and 'self_contained'. 2023-03-20 16:14:42 -07:00
Ben Barham
9b8f7c30d1 [ClangImporter] Probe for a PCH when the header is missing
The default for `ProbePrecompiled` was changed in rebranch. Set it back
to `true` to avoid breaking existing clients.

Resolves rdar://106966024.
2023-03-20 15:49:13 -07:00
zoecarver
9d5e06cad7 [cxx-interop] Revert hasCopyTypeOperations to the old behavior to get Swift Compiler Sources building. 2023-03-20 15:47:23 -07:00
zoecarver
9ee2667699 stash 2023-03-20 15:47:22 -07:00
zoecarver
a10bf21fcd [cxx-interop] 'Support' C++ move only types; fix a few bugs in the object model.
The implemented object model should now match the object model outlined in the Forward Vision document.
2023-03-20 15:47:22 -07:00
Alex Lorenz
cf0763dc87 [interop] Swift -> C++ -> Swift class type bridging 2023-03-18 19:29:55 -07:00
Zoe Carver
e3b3e82dca Merge pull request #64460 from zoecarver/factor-owned-attr-into-is-safe-req
[cxx-interop] Object model: fix crash when importing explicitly owned…
2023-03-17 20:32:23 -07:00
Zoe Carver
81637d9ba5 Merge pull request #64458 from zoecarver/fix-my-warnings
[nfc] Fix a few warnings I introduced.
2023-03-17 20:32:14 -07:00
Egor Zhdan
55a08bb2e5 Merge pull request #64453 from apple/egorzhdan/cxx-completion-unsafe
[cxx-interop] Do not auto-complete unsafe underscored methods, part 2
2023-03-17 22:05:39 +00:00
zoecarver
0795083237 [cxx-interop] Object model: fix crash when importing explicitly owned type. 2023-03-17 13:57:24 -07:00
zoecarver
077d3cb8b3 [nfc] Fix a few warnings I introduced. 2023-03-17 13:49:47 -07:00
Egor Zhdan
9247d53082 [cxx-interop] Do not auto-complete unsafe underscored methods, part 2
Previous patch removed unsafe C++ methods from the module interface, but not from auto-completion results.

rdar://103252957
2023-03-17 18:04:22 +00:00
Nuri Amari
fe2f85765e Merge pull request #64043 from apple/ns-option-linkage-conflict
Fix ASTMangler mangling NS_OPTION differently in C++ mode
2023-03-17 09:33:47 -07:00
Doug Gregor
ce6dec5d70 Merge pull request #64288 from apple/revert-63668-checkmate 2023-03-11 10:47:50 -08:00
Zoe Carver
78dbbbab26 Merge pull request #64300 from zoecarver/user/zoecarver/97361196
[cxx-interop] Separate `CxxRecordSemantics` and `IsSafeUseOfCxxDecl` requests.
2023-03-10 20:53:59 -08:00
zoecarver
bcf4977a64 [cxx-interop] Separate CxxRecordSemantics and IsSafeUseOfCxxDecl requests. 2023-03-10 17:39:12 -08:00
Doug Gregor
ef7f707fcc Revert "Improve @objcImplementation member checking" 2023-03-10 12:00:33 -08:00
Nuri Amari
709321b69f Fix ASTMangler mangling NS_OPTION differently in C++ mode
CF_OPTIONS is defined differently in the SDK based on
a __cplusplus preprocessor branch. As a result, declarations
referencing CF_OPTIONS are mangled differently depending
on if C++ interop is enabled.

This meant a module compiled with cxx interop on could
not be linked with a module compiled without and vice versa.
This patch modifies the mangler such that the mangled names
are consistent. This is achieved by feeding the mangler a modified
AST node that looks like the Objective-C definition of CF_OPTIONS,
even when we have cxx interop enabled.
2023-03-09 09:30:05 -08:00
Puyan Lotfi
d55cfd26da Merge pull request #61606 from NuriAmari/fwd-declarations
Import Forward Declared Objective-C Interfaces and Protocols
2023-03-08 21:44:47 -08:00
Alex Lorenz
11e5fc80b8 Merge pull request #64177 from hyp/eng/libstdcxx-dynamic
[interop] Configure libstdc++ module map at runtime
2023-03-08 15:34:51 -08:00
Alex Lorenz
eba8a00673 [interop] Inject header files into libstdcxx.modulemap dynamically
This allows the module map we use for libstdc++ to correctly include optional headers like "any" and other C++17/20 files.
2023-03-08 07:59:52 -08:00
Nuri Amari
86c5698780 Implement importing of forward declared objc protocols and interfaces
This modifies the ClangImporter to introduce an opaque placeholder
representation for forward declared Objective-C interfaces and
protocols when imported into Swift.

In the compiler, the new functionality is hidden behind a frontend
flag -enable-import-objc-forward-declarations, and is on by default
for language mode >6.

The feature is disabled entirely in LLDB expression evaluation / Swift
REPL, regardless of language version.
2023-03-07 16:00:16 -08:00
Saleem Abdulrasool
73cafebaf5 Driver: introduce additional Windows controls
This adds the following four new options:
  - `-windows-sdk-root`
  - `-windows-sdk-version`
  - `-visualc-tools-root`
  - `-visualc-tools-version`

Together these options make one the master of Windows SDK selection for
the Swift compilation.  This is important as now that the injection is
no longer done by the user, we need to ensure that we have enough
control over the paths so that the synthesized overlay is going to map
the files to the proper location.
2023-03-06 13:29:31 -08:00
Xi Ge
ffc998a0e7 Merge pull request #63668 from beccadax/checkmate
Improve @objcImplementation member checking
2023-03-06 08:21:59 -08:00
Ben Barham
59afba5bf9 Manually merge branch 'main' into rebranch 2023-03-01 14:13:50 -08:00
Becca Royal-Gordon
a169f371a1 [NFC] Expose extension category name accessor 2023-03-01 09:00:43 -08:00
Artem Chikin
3ea5087e2f Add Swift compilation flags to enable Clang's validate-per-build-session module behavior
Add '-validate-clang-modules-once' and '-clang-build-session-file' corresponding to Clang's '-fmodules-validate-once-per-build-session' and '-fbuild-session-file='. Ensure they are propagated to module interface build sub-invocations.

We require these to be first-class Swift options in order to ensure they are propagated to both: ClangImporter and implicit interface build compiler sub-invocations.

Compiler portion of rdar://105982120
2023-02-28 13:19:05 -08:00
Arnold Schwaighofer
1dfc30eb1f Merge remote-tracking branch 'origin/main' into rebranch 2023-02-27 09:18:56 -08:00
Rintaro Ishizaki
1f3d6718c0 [ClangImporter] Fix stack-use-after-scope in createClangInvocation
ClangDiagnosticConsumer was initialized on the stack in a scope of 'if'
branch, and was passed to the DiagnosticEngine as a pointer. Then the
diagnostic engine was used outside the scope.

Instead, allocate the consumer in the heap, and pass to the engine with
`ShouldOwnClient` true. So the engine takes the ownership.

Speculative fix for rdar://105801504
2023-02-23 21:38:31 -08:00
swift-ci
0a5137f6eb Merge remote-tracking branch 'origin/main' into rebranch 2023-02-21 06:13:28 -08:00
Egor Zhdan
fc5215f0f8 [cxx-interop] Treat C++ structs that store iterators as unsafe
C++ types that store pointers as fields are treated as unsafe in Swift. Types that store other types that in turn store pointers are also treated as unsafe.

Types that store raw C++ iterators are also treated as unsafe in Swift. However, a type that stores another type that stores a raw iterator was previously imported as safe. This change fixes that.

rdar://105493479
2023-02-15 13:50:35 +00:00
swift-ci
68e72ce6c1 Merge remote-tracking branch 'origin/main' into rebranch 2023-02-07 20:33:37 -08:00
Alex Lorenz
1a763c0cbc Merge pull request #63336 from hyp/eng/emit-symbolic-interfaces
[interop] Emit symbolic interfaces while indexing
2023-02-07 20:24:36 -08:00
swift-ci
9fd0ce37f4 Merge remote-tracking branch 'origin/main' into rebranch 2023-02-01 18:53:37 -08:00
Doug Gregor
cd0a3dcb4e [Clang importer] Remove addition of -Werror=non-modular-include-in-framework-module
We shouldn't be stricter than Clang. Fixes rdar://104064443.
2023-02-01 09:57:53 -08:00
Alex Lorenz
a44a98bf64 [interop] clear importer decl when emitting symbolic interface
This ensures that our interface do not reference already instantiated and imported specializations.
2023-01-31 14:58:31 -08:00
Alex Lorenz
0e60775e9a NFC, refactor importer::requiresCPlusPlus into reusable function 2023-01-31 14:58:25 -08:00
Alex Lorenz
d4aa18ab9f [cxx-interop][index] emit symbolic interface files for C++ modules 2023-01-31 14:58:19 -08:00
Alex Lorenz
f36e5cf641 [interop] add 'ImportSymbolicCXXDecls' experimental import mode for importing class templates syntactically but not semantically 2023-01-31 14:58:13 -08:00
swift-ci
668dde7e39 Merge remote-tracking branch 'origin/main' into rebranch 2023-01-26 08:53:43 -08:00
Egor Zhdan
ee6b9b2a67 [cxx-interop] Disallow import std, require import CxxStdlib
`CxxStdlib` will now be the only accepted module name for the C++ standard library module in Swift.
2023-01-26 14:15:56 +00:00
swift-ci
bcc3282c7b Merge remote-tracking branch 'origin/main' into rebranch 2023-01-18 10:41:34 -08:00