Commit Graph

6196 Commits

Author SHA1 Message Date
Kavon Farvardin
b8cd7effeb Merge pull request #70866 from kavon/ncgenerics-stdlib-building-v4
Build Stdlib with Noncopyable Generics (Part 4)
2024-01-25 07:09:38 -08:00
Kavon Farvardin
3e03c674c7 [NCGenerics] remove arg from isNoncopyable(DC)
It should be the responsibility of callers to map the type to a
contextual type, as needed. When it's not possible or repetitive to do
so, there is a special-purpose function `isInterfaceTypeNoncopyable` for
 Sema.
2024-01-23 22:42:38 -08:00
Hamish Knight
c97d80b1c3 [AST] NFC: Add convenience constructors for ReturnStmt
Add `ReturnStmt::createParsed` and `createImplict`.
2024-01-23 19:30:18 +00:00
Becca Royal-Gordon
e63a887dde Merge pull request #71027 from beccadax/globally-lazy-minimum
[ClangImporter] Break cycle in IAM extensions
2024-01-22 14:35:00 -08:00
Steven Wu
af4e5357fa [ClangImporter] Remove out-of-date clang argument
"-opaque-pointers" has not been a valid clang cc1 argument for a long time
since it is the default. What is even worst is that clang is treating
that out of date option as "-o paque-pointers" and return no error.
Fortunately, ClangImport doesn't write anything to output file,
otherwise it is going directly to this "paque-pointers" file.
2024-01-19 15:44:44 -08:00
Egor Zhdan
74c444d688 [cxx-interop] Emit function types as Swift closures in templated params
This is required to make the compiler distinguish between instantiations of `std::function`.

Previously, when generating a Swift type name for a `std::function` instantiation, we would always emit `_` as the template parameter. If someone referenced two different instantiations of `std::function` in a Swift module, they would get mangled with the same name, triggering linker errors later.

rdar://103979602
2024-01-19 21:02:03 +00:00
Egor Zhdan
7c63cd4ad2 [cxx-interop] Emit _ as a fallback type name in template params
Emit an underscore instead of an empty type name when we weren't able to emit a more meaningful representation of a C++ template parameter in Swift.
2024-01-19 19:31:59 +00:00
Becca Royal-Gordon
0683f3985a [ClangImporter] Break cycle in IAM extensions
Under a set of circumstances that I cannot fully characterize, it was possible for `ClangImporter::Implementation::importDeclContextOf()` to end up recursing until stack overflow while trying to import a global as a member.

The cycle was caused by `addExtension()` using a newly-created extension’s lazy member loader to load its members before the extension had been added to ClangImporter’s `extensionPoints` table. Loading the members would try to import the IAM members again, which would cause `importDeclContextOf()` to try to create another extension to contain them, which `addExtension()` would force to load those members. Repeat until stack overflow.

I have fixed this bug by registering the extension in the `extensionPoints` map before its member loader is set. This ensures that if `importDeclContextOf()` gets called for any reason after that point, it will return the existing extension instead of creating a new one, avoiding the cycle.

Unfortunately, I was not able to figure out the exact conditions that were necessary to reproduce this bug, so I have not included a test. However, I have tested with the affected project locally and confirmed that this change lets it build. All existing tests pass.

Fixes rdar://120854030.
2024-01-18 19:26:17 -08:00
Steven Wu
746de8b5cd Merge pull request #70974 from cachemeifyoucan/eng/PR-121082031
[ExplicitModule] Fix `canImport` lookup for swift explicit module build
2024-01-18 15:39:29 -08:00
Steven Wu
4fb7abc9f9 [ExplicitModule] Fix canImport lookup for swift explicit module build
Previously, canImport lookup is not completely working with explicit
module due to two issues:
* For clang modules, canImport check still do a full modulemap lookup
  which is repeated work from scanner. For caching builds, this lookup
  cannot be performed because all modulemap and search path are dropped
  after scanning.
* For swift module, if the canImport module was never actually imported
  later, this canImport check will fail during the actual compilation,
  causing different dependencies in the actual compilation.

To fix the problem, first unified the lookup method for clang and swift
module, which will only lookup the module dependencies reported by
scanner to determine if `canImport` succeed or not. Secondly, add all
the successful `canImport` check modules into the dependency of the
current module so this information can be used during actual
compilation.

Note the behavior change here is that if a module is only checked in
`canImport` but never imported still needs to be built. Comparing to
implicit module build, this can bring in additional clang modules if
they are only check inside `canImport` but should not increase work for
swift modules (where binary module needs to be on disk anyway) or the
most common usecase for `canImport` which is to check the same module
before importing.

rdar://121082031
2024-01-18 10:31:33 -08:00
Anthony Latsis
96ee57b00b Merge pull request #70623 from AnthonyLatsis/init-sema
Move unqualified `init` diagnosis from Parse to Sema
2024-01-18 03:53:33 +03:00
Pavel Yaskevich
6cdab78028 Merge pull request #70867 from xedin/dynamic-enforcement-of-witness-isolation-with-preconcurrency
[TypeChecker/SILGen] Dynamic enforcement of witness/objc isolation with @preconcurrency attribute
2024-01-17 10:01:37 -08:00
Egor Zhdan
206164013b Merge pull request #70772 from apple/egorzhdan/std-function-initial-tests
[cxx-interop] Initial tests for `std::function` usage
2024-01-17 13:25:02 +00:00
Pavel Yaskevich
e8b7a26eac [AST] Add a flag to indicate that the conformance is @preconcurrency 2024-01-16 11:51:42 -08:00
Pavel Yaskevich
233d279a5c [AST] Support @preconcurrency attribute on test/extension inheritance entries 2024-01-16 10:30:58 -08:00
Pavel Yaskevich
6a3ef05109 [ClangImporter] Augment has*Attr methods to find attributes in type positions
`SwiftAttr` can now appear in type positions and `has*Attr` methods
have to account for that when the given declaration is `ParmVarDecl`.
2024-01-15 12:20:46 -08:00
Egor Zhdan
ad7ff59ce4 [cxx-interop] Do not treat std::pair as an owned type on Linux
In libstdc++ 11, `std::pair` has a base class `std::__pair_base`, which defines a copy constructor.

We still continue not treating `std::pair` as an owned type, just like on other platforms.
2024-01-15 16:14:54 +00:00
Pavel Yaskevich
8f8e856ea6 [ClangImporter] Account for Sendable attributes on generic parameter requirements 2024-01-12 11:32:06 -08:00
Pavel Yaskevich
a168a94f1f [ClangImporter] NFC: Transform applyTypeAttributes into getConcurrencyAttrs
It has to be reachable to declaration converter to handle attributes
associated with generic parameters.
2024-01-12 11:32:06 -08:00
Pavel Yaskevich
2e36b2cca1 [ClangImporter] Move SendableCompletionHandlers feature handling into type importer
Parameters no longer expose their attributes at their declaration,
all of the attributes are handled uniformly as type attributes.
2024-01-12 11:32:06 -08:00
Pavel Yaskevich
1c813c61da [ClangImporter] Augment importType to infer concurrency attributes from types
Support for `swift_attr` has been extended to type contexts.
Such attributes form `clang::AtributedType` that carries an
optional `clang::Attr *`. Teach `importType` has to examine
immediate sugar to determine whether it carries any concurrency
information and, if so, add it to `ImportTypeAttrs` to be
applied after import.
2024-01-12 11:32:06 -08:00
Pavel Yaskevich
578f82f466 [ClangImporter] Introduce a new kind of parameter - completion handler 2024-01-12 11:32:06 -08:00
Pavel Yaskevich
41ef9b6f38 [ClangImporter] NFC: Convert CF{Un}retainedOutParaeter into ImportTypeAttr 2024-01-12 11:32:06 -08:00
Pavel Yaskevich
1e1f0a54ae [Serialization] Implementation serialization of clang::SwiftAttrAttr
This is an attribute that is attached to `AttributedType` to support
concurrency annotations in type context.
2024-01-12 11:32:06 -08:00
Egor Zhdan
4ca4b9a290 [cxx-interop] Check for type completeness consistently
`clangSema.isCompleteType` checks for decl visibility according to the module visibility rules, which we don't actually need. What we need to check is whether the record has a definition – this is the check we already use elsewhere in ClangImporter.

This makes sure that we can import `std::function` on Windows.

rdar://103979602
2024-01-11 20:53:45 +00:00
Artem Chikin
aa05a5c0bd Revert "[Dependency Scanning] Use VFS-remapped paths for Clang Module Dependencies' .modulemap files" 2024-01-11 09:43:18 -08:00
Egor Zhdan
b138f223c2 Merge pull request #70044 from apple/egorzhdan/default-arguments
[cxx-interop] Support C++ default arguments
2024-01-11 00:57:35 +00:00
Egor Zhdan
494474b021 [cxx-interop] Support C++ default arguments
This allows calling a C++ function with default arguments from Swift without having to explicitly specify the values of all arguments.

rdar://103975014
2024-01-10 16:37:42 +00:00
Artem Chikin
6c5e884297 [Dependency Scanning] Use VFS-remapped paths for Clang Module Dependencies' .modulemap files
These files are used as an explicit input for the resulting compilation task

Resolves rdar://120554985
2024-01-09 12:46:38 -08:00
Akira Hatanaka
3692f75ebe Merge pull request #70549 from apple/diagnostic-walker-crash
Fix a crash in ClangImporter::Implementation::DiagnosticWalker::TraverseDecl
2024-01-02 10:13:50 -08:00
Anthony Latsis
bd2f48d9d2 [NFC] AST: Introduce and use Identifier::isConstructor 2023-12-25 21:09:17 +03:00
Steven Wu
ead742b8f1 [CAS] Do not create redirect file system when using clang-include-tree
Redirecting file system can canonicalize the file path before forwarding
the path to IncludeTreeFileSystem, which is a simplied FS that can only
intepret the paths that has been seen by dep-scanner. Since all files
that need redirecting already added to underlying FS via DepScan, there
is no need for such layer when compiling using clang-include-tree.

rdar://119727344
2023-12-20 12:30:14 -08:00
Akira Hatanaka
14cfebc640 Fix a crash in ClangImporter::Implementation::DiagnosticWalker::TraverseDecl
The call to `D->getBeginLoc` crashes when `D` is null.

rdar://118899818
2023-12-19 15:58:42 -08:00
Steven Wu
9be16a1410 [Caching] Workaround not needed modulemap not found
When caching + clang include tree is enabled, don't take module map file
from command-line in clang importer. Those are resulted from `-Xcc`
arguments and do not needed in compilation since module maps are
included in include-tree.

rdar://119577349
2023-12-19 12:16:20 -08:00
Steven Wu
ea58ef8fa5 [ClangImporter] Simply clang-importer creation flags
Currently,  `-direct-clang-cc1-module-build` and `-only-use-extra-clang-opts`
have to be passed together for clang importer creation to succeed.
Missing either will result in error. Simplified the swift-frontend flags
by removing `-only-use-extra-clang-opts` and let
`-direct-clang-cc1-module-build` to do both.
2023-12-19 12:16:20 -08:00
Steven Wu
7698d36dfb [ClangImporter] Re-write how clang-importer is created via args
Re-write and clean up how clang-importer is created from clang
arguments. Previously, it is unclear if `getClangArguments` will return
CC1 args or driver args and the logic is unnecessarily compilicated when
creating clang invocation. Now clang invocation is always created from
cc1 arguments, which can be directly provided via direct-cc1-mode or
converted from driver args.

There is no functional changes in this patch, other than
`-dump-clang-diagnostics` now will always print cc1 args, and also
driver args if that is applicable.
2023-12-19 12:16:18 -08:00
Egor Zhdan
233b80e431 Merge pull request #70503 from apple/egorzhdan/no-abstract-ctors
[cxx-interop] Do not import constructors of abstract C++ classes
2023-12-18 17:24:00 +00:00
Egor Zhdan
325868808b [cxx-interop] Do not import constructors of abstract C++ classes
Clang rejects code that tries to call a constructor of an abstract C++ class with an error: "Variable type 'Base' is an abstract class". Swift should reject this as well.

rdar://119689243
2023-12-18 14:52:32 +00:00
Alex Lorenz
9261fa765d Merge pull request #70420 from hyp/eng/virtual-methods++
[cxx-interop] virtual method fixes
2023-12-16 06:37:44 -08:00
Artem Chikin
33e09f9e87 Merge pull request #70211 from artemcm/ParallelScanFixes
[Dependency Scanning] Remove/move mutable state from parallel scanner workers
2023-12-15 11:14:16 -08:00
Egor Zhdan
ac13ef50be Merge pull request #70445 from apple/egorzhdan/split-libcxx-lookup
[cxx-interop] Keep pulling in the entire libc++
2023-12-15 01:29:11 +01:00
Egor Zhdan
3ca0d56675 [cxx-interop] Discard duplicating IteratorTy::iterator_category decls
libc++ recently split the `std` module into many top-level modules: 571178a21a

This broke the logic that conforms C++ iterator types to `UnsafeCxxInputIterator`/`UnsafeCxxRandomAccessIterator`. To determine if a C++ type is an iterator type, we look for its inner type called `iterator_category`. After module std was split, Clang instantiates `std::string::const_iterator::iterator_category` twice and doing a Clang lookup within the `const_iterator` type returns two identical `TypedefDecl`s. Clang itself has logic to merge them, but Swift doesn't.

rdar://119270491
2023-12-14 17:37:01 +00:00
Egor Zhdan
65eaafe7da [cxx-interop] Keep pulling in the entire libc++
libc++ recently split the `std` module into many top-level modules: 571178a21a

Previously if a C++ module had `#include <iosfwd>`, importing that module in Swift would make the entire C++ stdlib visible from Swift, since it was a single top-level Clang module. After libc++ got split it doesn't automatically do so, but we need to preserve the current behavior for Swift users.

rdar://119270491
2023-12-14 15:58:15 +00:00
Becca Royal-Gordon
e9672194b4 Merge pull request #69468 from beccadax/c-implementation
Make @objcImpl work with @_cdecl
2023-12-14 00:36:12 -08:00
Artem Chikin
674dfb3bd4 [Dependency Scanning] Move generation of a named import path 'Identifier' out of the individual scanning workers up into the parent scanner. This operation mutates the scanner ASTContext by potentially adding new identifiers to it and is therefore not thread-safe. 2023-12-13 13:17:05 -08:00
Becca Royal-Gordon
426e5beb8d Begin checking cdecl implementations
This commit diagnoses cdecl implementations with no matching imported declaration, and also runs them through the ObjCImplementationChecker. Actually testing that the ObjCImplementationChecker diagnoses various failure conditions correctly will be added in a subsequent commit.
2023-12-13 11:09:50 -08:00
Becca Royal-Gordon
8b22b85e0b [NFC] Move duplicate ObjCImpl diagnosis 2023-12-13 11:09:50 -08:00
Egor Zhdan
06f9c012c0 Merge pull request #70411 from apple/egorzhdan/libcxx-requires-cplusplus
[cxx-interop] Adjust detection of C++ modules after changes in libc++
2023-12-13 17:02:21 +01:00
Egor Zhdan
01670cdb62 Merge pull request #70325 from apple/egorzhdan/friend-operator-lookup
[cxx-interop] Add friend operators to the lookup table properly
2023-12-13 14:24:58 +01:00
Egor Zhdan
24b0d6e91e [cxx-interop] Adjust detection of C++ modules after changes in libc++
libc++ recently split the `std` module into many top-level modules: 571178a21a

This prevented the conformances to `CxxSet`, `CxxVector`, etc. from being synthesized with a fresh libc++ version.

rdar://119270491
2023-12-13 13:15:31 +00:00