Commit Graph

1896 Commits

Author SHA1 Message Date
swift-ci
094988051f Merge remote-tracking branch 'origin/main' into rebranch 2023-09-19 08:55:18 -07:00
Egor Zhdan
6a2f10a388 [cxx-interop] Refactor: do not rely on Clang module importer being available
This makes sure that we can emit a pch from a C++ header that uses `CF_OPTIONS`.

rdar://112225263
2023-09-18 21:54:11 +01:00
Artem Chikin
d840b88e14 [ClangImporter] On failing a module lookup, reset Clang's DiagnosticEngine, in addition to filtering out the "module not found" diagnostic
Even though 'ClangDiagnosticConsumer' filters out 'clang::diag::err_module_not_found' from being emitted by the Swift compiler, delegating to Swift's module-loading logic for error-handling, we must also ensure that we reset Clang's 'DiagnosticEngine''s error count. Otherwise, if we do not, final stages of IRGen will query Clang's code-gen to finalize its 'Module', which Clang will not do if its internal DiagnosticEngine contains errors. This will cause Swift's IRGen to fail, even though the only error emitted was one Swift intended to suppress.
2023-09-14 15:33:05 -07:00
Ben Barham
9bbae2b63c Merge pull request #68077 from bnbarham/add-separate-incremental-option
[rebranch] Use enableIncrementalProcessing again
2023-09-07 17:55:09 -07:00
Sophia Poirier
86d368f364 Merge remote-tracking branch 'upstream/main' into fix-rebranch-automerger 2023-08-31 14:10:52 -07:00
Doug Gregor
8b0b1bfb72 [Clang importer] Fix lookup of custom ref-counting ops in bridging headers
Lookup for custom reference counting operators into a precompiled bridging
header was causing a crash because there is no "underlying module" in which
to perform the lookup. Handle the lookup at the level of the main Swift
module for such cases, filtering out declarations not coming from Clang.

Fixes rdar://114495840.
2023-08-30 09:53:46 -07:00
Ben Barham
cea351352e [rebranch] Use enableIncrementalProcessing again
The `incremental-extensions` is used for incremental parsing in the REPL
(which also changes how parsing runs). We only want "incremental
processing" in so far as it doesn't teardown the lexer or run the end of
translation unit action. This was joined into `incremental-extensions`,
but is now split apart again.

Resolves rdar://113406310.
2023-08-28 09:20:32 -07:00
swift-ci
525350af1b Merge remote-tracking branch 'origin/main' into rebranch 2023-08-10 22:14:25 -07:00
Artem Chikin
8501f99cb2 [Dependency Scanning] Add option to specify a separate Clang Dependency scanner module cache.
Clang dependency scanning produces scanner PCMs which we may want to live in a
different filesystem location than the main build module cache.

Resolves rdar://113222853
2023-08-10 11:10:18 -07:00
swift-ci
ae4b70bf28 Merge remote-tracking branch 'origin/main' into rebranch 2023-08-04 18:59:37 -07:00
Slava Pestov
9ebb5f2e03 AST: Rename VarDecl::getType() to VarDecl::getTypeInContext()
This is a futile attempt to discourage future use of getType() by
giving it a "scary" name.

We want people to use getInterfaceType() like with the other decl kinds.
2023-08-04 14:19:25 -04:00
swift-ci
6c12f59576 Merge remote-tracking branch 'origin/main' into rebranch 2023-08-01 11:34:57 -07:00
Alex Lorenz
0eed1a944c [cxx-interop] correctly add and lookup enumerators added to enums that correspond to namespaces
Fixes https://github.com/apple/swift/issues/67604
2023-07-31 18:57:50 -07:00
Ben Barham
f7d10b87b5 [ClangImporter] Move incremental processing to the new language option
`IncrementalProcessing` is now a language option
`IncrementalExtensions`, which also means it is now part of the module
hash.

When compiling a clang module, the output file path would be generated
in the `BeginSourceFile` prior to `enableIncrementalProcessing` being
called on the preprocessor. The hash would then be generated again when
compiling the module (after the `enableIncrementalProcessing` call) and
included in the PCM, leading to a mismatch between the path and the hash
in the module.

This could be fixed by moving `enableIncrementalProcessing` above
`BeginSourceFile`, but now that it's an option we can instead just add
it to the invocation arguments.

Resolves rdar://112993659.
2023-07-28 22:59:53 -07:00
swift_jenkins
a31c7211e6 Merge remote-tracking branch 'origin/main' into next 2023-07-24 09:43:25 -07:00
Egor Zhdan
43e6e97c1a Merge pull request #67482 from apple/egorzhdan/vector-of-string
[cxx-interop] Import iterator types that are not typedef-ed
2023-07-24 17:29:26 +01:00
Egor Zhdan
af014c02b3 [cxx-interop] Import iterator types that are not typedef-ed
This prevented `std::vector<std::string>` from being auto-conformed to `CxxRandomAccessCollection`.

If an iterator type is templated, and does not have an explicit instantiation via a typedef or a using-decl, its specialization will not have an owning Clang module. Make sure we treat it as a part of the Clang module that owns the template decl.

rdar://112762768 / resolves https://github.com/apple/swift/issues/67410
2023-07-24 11:25:15 +01:00
swift_jenkins
24e6d24580 Merge remote-tracking branch 'origin/main' into next 2023-07-19 14:30:40 -07:00
zoecarver
806956d80f [cxx-interop] always mark begin and end methods as unsafe (to help automatic rac conformance); update tests accordingly. 2023-07-18 17:42:56 -07:00
zoecarver
fd7b39e736 [cxx-interop] Mark *all* iterators as unsafe; update tests accordingly; fix a few remaining tests that use raw pointers. 2023-07-18 17:42:56 -07:00
zoecarver
782641af68 [cxx-interop] ExpirementalFeature -> LanguageFeature. 2023-07-18 17:42:35 -07:00
zoecarver
8677fab6a8 [cxx-interop] Add legacy implementation of is-safe-use-of-cxx-method. 2023-07-18 17:42:35 -07:00
zoecarver
7db669ce5b [cxx-interop] Fix a bug with explicit, nested, self-contained types (and add a test). 2023-07-18 17:42:05 -07:00
zoecarver
474a7cd834 [cxx-interop] Only mark projections of self-contained types as unsafe.
Projections of trivial types and view types aren't unsafe. This matches what was described in the vision document.
2023-07-18 17:42:05 -07:00
swift_jenkins
311947e23f Merge remote-tracking branch 'origin/main' into next 2023-07-18 11:26:34 -07:00
Egor Zhdan
bc56ddc2bb [cxx-interop] Handle inherited templated operators during auto-conformance
This fixes the automatic `std::unordered_map` conformance to CxxDictionary on Linux. Previously `std::unordered_map::const_iterator` was not auto-conformed to UnsafeCxxInputIterator because its `operator==` is defined on a templated base class of `const_iterator`.

rdar://105220600
2023-07-17 21:10:32 +01:00
Evan Wilde
26a974e772 [NFC] Headers headers headers!
Including headers that were being transitively included from LLVM
before. Also pointing them at the new locations for some of them.
2023-07-17 10:55:55 -07:00
Evan Wilde
8ce6ee8dd1 Updating API usages
LLVM deprecated, renamed, and removed a bunch of APIs. This patch
contains a lot of the changes needed to deal with that.

The SetVector type changed the template parameters.

APInt updated multiple names, countPopulation became popcount,
getAllOnesValue became getAllOnes, getNullValue became getZero, etc...

Clang type nullability check stopped taking a clang AST context.

The LLVM IRGen Function type stopped exposing basic block list directly,
but gained enough API surface that the translation isn't too bad.
(GenControl.cpp, LLVMMergeFunctions.cpp)

llvm::Optional had a transform function. That was being used in a couple
of places, so I've added a new implementation under STLExtras that
transforms valid optionals, otherwise it returns nullopt.
2023-07-17 10:53:42 -07:00
Alex Lorenz
4d084100ce [cxx-interop] Mark C++ functions with unavailable return type as unavailable
This prevents users from calling functions with unsupported or unavailable return types. This ensures that users don't for example call a function that returns a non-copyable and non-movable type

Fixes https://github.com/apple/swift/issues/64401
2023-07-11 16:40:57 -07:00
Cyndy Ishida
65d819e615 [ClangImporter] Use TextAPI apis for capturing current-version (#67204)
Use LLVM apis for understanding TBD files instead of parsing the yaml
directly. This prevents breaking the compiler when TBD-v5 exists which
is in json.
2023-07-11 07:47:58 -07:00
Alex Lorenz
a10332548c [cxx-interop] Do not add base class members that cause lookup ambiguities with a derived class member of the same name
Fixes https://github.com/apple/swift/issues/66323
2023-07-07 10:38:48 -07:00
Egor Zhdan
39a837c1b5 Merge pull request #67115 from apple/egorzhdan/cxx-semantics-kind
[cxx-interop] Tweak C++ type semantics detection
2023-07-05 19:09:00 +01:00
Egor Zhdan
6e7fb3263b [cxx-interop] Tweak C++ type semantics detection
`CxxRecordSemanticsKind::ExplicitlyUnsafe` and `CxxRecordSemanticsKind::UnsafePointerMember` were never directly used, and those do not indicate semantics: they indicate safety of the type when used from Swift, which should be handled by another request `IsSafeUseOfCxxDecl` instead of `CxxRecordSemantics`.

Having `ExplicitlyUnsafe` and `UnsafePointerMember` as semantics indicators was problematic, for instance, for types that are move-only and store a pointer at the same time. Swift allowed the usage of these types (under the rules for `UnsafePointerMember` types) when move-only types are disabled, and did not apply the move-only attribute on such types when move-only types are enabled.

rdar://110644300
2023-07-04 20:12:06 +01:00
Alex Lorenz
6c6092ebee [interop] ensure C++ stdlib set's insert methods are unsafe 2023-07-03 13:44:17 -07:00
Alex Lorenz
14020201f5 Revert "[interop] do not import functions whose return type is not imported"
This reverts commit 8e0c17b274.
2023-07-03 10:06:54 -07: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
Steven Wu
2b7d38dc16 [CAS] Improve swift cas options
Using the same CASOption from clang to communicate CAS configurations so
it is easier to exchange CAS configuration between them.
2023-06-26 10:34:26 -07:00
zoecarver
7d47cb9fec [cxx-interop] fix how we import CF types. 2023-06-22 12:21:10 -07:00
Steven Wu
f509a29bd9 Merge pull request #66575 from cachemeifyoucan/eng/PR-caching-tune-up
Various cleanups to allow better swift caching.
2023-06-21 10:23:01 -07:00
Steven Wu
07a35e9bd3 [CAS] Workaround the missing file system dependency from clang importer 2023-06-20 14:04:01 -07:00
Egor Zhdan
4a1afa9bd3 [cxx-interop] Avoid crashing when template substitution fails
This code used to crash the compiler:

    var s = std.string("hi")
    s.append("foo")

`append` in this case resolves to a templated C++ method that accepts `std::string_view`, while we tried passing a Swift String to it as a parameter.

rdar://107018724
2023-06-19 15:58:41 +01:00
Puyan Lotfi
b140bc32c3 Merge pull request #66619 from plotfi/plotfi-cxx-interop-uicontrolstate-mangling
[cxx-interop] Add fix for corner case where NS_OPTIONS typedef has to be desugared
2023-06-15 16:47:41 -07:00
Puyan Lotfi
fe6ccd7a29 [cxx-interop] Add fix for corner case where NS_OPTIONS typedef has to be desugared
This patch is an add-on to https://github.com/apple/swift/pull/64043.
Essentially when encountering NS_OPTIONS enums, in C++-Interop mode
if they are not specially handled then they can mangle differently than
they do without C++-Interop. This patch adds logic to handle when a
typedef and enum have additional clang::ElaboratedType sugar, but
otherwise it does the same as the existing 64043 patch.

The test case provided was encountered in a real app build. The problem
came from when two modules are each compiled one with and one without
C++-Interop. For the test case code provided the mangling of the
protocol conformance is not consistent and the code in
SILGenLazyConformance.cpp crashes on an invalid conformance with reason
"Invalid conformance in type-checked AST".
2023-06-15 11:17:25 -07:00
Arnold Schwaighofer
654f21f1d1 Enable opaque pointers 2023-06-14 10:48:13 -07:00
Steven Wu
b1f99b8e93 [CAS] swift dependency scanning using CAS for compiler caching (#66366)
Teach swift dependency scanner to use CAS to capture the full dependencies for a build and construct build commands with immutable inputs from CAS.

This allows swift compilation caching using CAS.
2023-06-12 10:55:53 -07:00
Doug Gregor
a72fb83034 Requestify AbstractStorageDecl::hasStorage().
The `hasStorage()` computation is used in many places to determine the
signatures of other declarations. It currently needs to expand accessor
macros, which causes a number of cyclic references. Provide a
simplified request to determine `hasStorage` without expanding or
resolving macros, breaking a common pattern of cycles when using
macros.

Fixes rdar://109668383.
2023-06-10 08:28:06 -07:00
Doug Gregor
b374c099ac [Clang importer] Eliminate redundant imports of C++ fields as properties
A recent refactoring uncovered two places where we could end up
importing a C++ field declaration as a property more than once:

1. Importing the declaration context of a field in C++ mode can then
  go import all of the fields. In such a case, check that the field
  we're importing didn't happen already, and bail out early if it did.
  This is common practice in the Clang importer but wasn't happening here.
2. One caller to the function that imported a field from a C++ base
  class into its inheriting class (as a computed property) wasn't
  checking the cache, and therefore created a redundant version.

Fix both issues.
2023-06-03 10:03:10 -07:00
Egor Zhdan
f2771584df [cxx-interop] Do not treat std::pair<UnsafeType, T> as safe
rdar://109529750
2023-06-01 14:00:03 +01:00
Steven Wu
c2c24145bf Merge pull request #65925 from cachemeifyoucan/eng/PR-swift-frontend-tweaks-for-caching
Cleanup some redundant dependencies and unnecessary works that prevent compiler caching.
2023-05-23 15:32:05 -07:00