Commit Graph

1871 Commits

Author SHA1 Message Date
Alex Lorenz
029644806d [cxx-interop] fix the use of '.pointee' with getter accessor for derived-to-base synthesized accessor 2023-11-29 15:42:11 -08:00
Alex Lorenz
16a8ae42ef [cxx-interop] fix the use of '.pointee' with address accessors for derived-to-base synthesized accessors 2023-11-29 15:10:27 -08:00
Egor Zhdan
d3460cb2cd [cxx-interop] Do not crash when synthesizing a base method call
rdar://114823867
2023-11-29 19:24:58 +00:00
Alex Lorenz
bacc58e0f7 [cxx-interop] provide correct referential access to non-copyable base fields from a derived value type 2023-11-28 20:10:07 -08: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
Ben Langmuir
383d52fdfc Update for clang maybeAddDependency API change 2023-11-09 09:16:09 -08:00
Egor Zhdan
f9bf957594 [cxx-interop] Do not import inherited methods with rvalue this
We do not synthesize the inheritance thunks correctly for such methods. Do not try to synthesize them, as that causes issues when there are two overloads of the same method, one with rvalue this and one without.

The proper solution is tracked as https://github.com/apple/swift/issues/69745

Unblocks rdar://114282353
2023-11-09 13:42:59 +00:00
Ben Barham
322b03d0f9 [ClangImporter] Always rebuild any bridging PCH that has errors
If a PCH was output with errors, it may not have serialized all its
inputs. If there was a change to the search path or a headermap now
exists where it didn't previously, it's possible those inputs will now
be found. Ideally we would only rebuild in this particular case rather
than any error in general, but explicit module builds are the real
solution there. For now, just treat PCH with errors as out of date.

Resolves rdar://117037471.
2023-11-06 11:28:50 -08:00
Nuri Amari
103f71630c Merge pull request #69357 from apple/fwd-declarations-fix 2023-10-31 07:43:15 -07:00
Allan Shortlidge
d0a4f2633c NFC: Fix unused variable warnings. 2023-10-25 09:42:21 -07:00
Doug Gregor
5ad39c84e0 [Typed throws] Record thrown error types and conversions in the AST
For any operation that can throw an error, such as calls, property
accesses, and non-exhaustive do..catch statements, record the thrown
error type along with the conversion from that thrown error to the
error type expected in context, as appropriate. This will prevent
later stages from having to re-compute the conversion sequences.
2023-10-24 12:40:22 -07:00
Nuri Amari
5494136a29 Fix infinite lookup importing forward declarations from bridging header 2023-10-23 22:01:20 -07:00
Ben Barham
360c5d8465 Merge remote-tracking branch 'origin/main' into 20231019-merge-main
Conflicts:
  - `lib/AST/TypeCheckRequests.cpp` renamed `isMoveOnly` which requires
    a static_cast on rebranch because `Optional` is now a `std::optional`.
2023-10-19 16:16:23 -07:00
Alex Lorenz
41dc466108 Merge pull request #68846 from hyp/eng/base-member-cxx-synthesized-accessor
[cxx-interop] Use a synthesized C++ method when invoking a base metho…
2023-10-17 07:07:59 -07:00
Alex Lorenz
f7ce9aa37f [cxx-interop] Synthesized derived-to-base field getter should copy out a retainable FRT value
This matches the semantics of accessing the same field from the base class
2023-10-16 14:41:44 -07:00
Alex Lorenz
415045024c [cxx-interop] Use a synthesized C++ method when accessing a base field or subscript from a derived class synthesized method
The use of a synthesized C++ method allows us to avoid making a copy of self when accessing the base field or subscript from Swift
2023-10-16 14:34:37 -07:00
Jan Svoboda
8b6e58ac15 [scanner] Adopt new Clang API for build arguments (#68503) 2023-10-06 11:31:05 -07:00
swift-ci
06f9a8a703 Merge remote-tracking branch 'origin/main' into rebranch 2023-09-30 11:33:40 -07:00
Doug Gregor
581b9d8a95 Merge pull request #68629 from DougGregor/typed-throws
Typed throws
2023-09-30 11:18:41 -07:00
Alex Lorenz
ba5b1bab89 [cxx-interop] Use a synthesized C++ method when invoking a base method from a derived class synthesized method
The use of a synthesized C++ method allows us to avoid making a copy of self when invoking the base method from Swift
2023-09-29 13:52:10 -07:00
Doug Gregor
ef642098f2 [Typed throws] Parsing and AST representation for typed errors
Parse typed throw specifiers as `throws(X)` in every place where there
are effects specified, and record the resulting thrown error type in
the AST except the type system. This includes:
* `FunctionTypeRepr`, for the parsed representation of types
* `AbstractFunctionDecl`, for various function-like declarations
* `ClosureExpr`, for closures
* `ArrowExpr`, for parsing of types within expression context

This also introduces some serialization logic for the thrown error
type of function-like declarations, along with an API to extract the
thrown interface type from one of those declarations, although right
now it will either be `Error` or empty.
2023-09-29 10:51:51 -07:00
swift-ci
c6b4638c38 Merge remote-tracking branch 'origin/main' into rebranch 2023-09-29 10:36:19 -07:00
Alex Lorenz
59f86d71f2 Revert "[cxx-interop] Refactor: do not rely on Clang module importer being available"
This reverts commit 6a2f10a388.
2023-09-28 18:47:12 -07:00
swift-ci
b8367f9d78 Merge remote-tracking branch 'origin/main' into rebranch 2023-09-21 15:41:14 -07:00
swift-ci
255d7372cb Merge pull request #68549 from artemcm/NoErrorOnMissingOptionalTranstiveDep
[ClangImporter] On failing a module lookup, reset Clang's DiagnosticEngine, in addition to filtering out the "module not found" diagnostic
2023-09-21 15:21:02 -07:00
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