Commit Graph

1871 Commits

Author SHA1 Message Date
Rintaro Ishizaki
b839718351 [AST] Use scoped enum for attribute kinds
Align with other kind enum e.g. DeclKind.
2024-02-02 09:36:48 -08:00
Adrian Prantl
23519bef9b Merge pull request #71318 from adrian-prantl/bridging-header-progress
Extend PreModuleImportCallback to support bridging header compilation
2024-02-01 19:56:44 -08:00
Adrian Prantl
c6c688c648 Extend PreModuleImportCallback to support bridging header compilation 2024-02-01 15:11:11 -08:00
Becca Royal-Gordon
3835a4b323 [NFC] [ClangImporter] Fully support lazy loading
Previously, the lazily-created extensions used for globals imported as members of a type used the lazy module loader, but `ClangImporter::Implementation::loadNamedMembers()` didn’t actually work for them. Other parts of the compiler instead contrived to avoid loading these members by name by forcing all members to load before any selective loading might occur.

This commit modifies that code path to accommodate extensions with no matching clang node, which is how these are represented. With this change, other parts of the compiler can unconditionally use the `LazyMemberLoader` whenever it is present.

There may be performance improvements from this change, but I don’t expect any functional changes.
2024-02-01 13:25:33 -08:00
Becca Royal-Gordon
6e44517af0 [NFC] Make insertMembersAndAlternates more specific
This will help when ClangImporter::Impl::loadNamedMembers() starts having to handle a lot more import-as-members names, but it’s NFC in this commit.
2024-02-01 12:41:42 -08:00
Egor Zhdan
b98d7a5679 Merge pull request #71310 from apple/egorzhdan/nfc-cxxshim-name
[cxx-interop] NFC: use a CxxShim name constant
2024-02-01 20:19:39 +00:00
Egor Zhdan
2ac4aa64f8 [cxx-interop] NFC: use a CxxShim name constant 2024-02-01 14:08:57 +00:00
Slava Pestov
bbbfc62e6d ClangImporter: Fixes for non-copyable generics 2024-01-31 21:56:45 -05:00
Slava Pestov
af3ab14986 SILGen: Clean up substitution map construction to deal with Copyable 2024-01-31 21:55:52 -05:00
Kuba Mracek
e84c2a81e8 [embedded] Conditionalize passing -D__MACH__ on isOSBinFormatMachO() 2024-01-31 11:39:05 -08:00
Kuba Mracek
e22aedbcc3 [embedded] Implicitly define __APPLE__ and __MACH__ when on -apple-none triples 2024-01-31 09:22:31 -08:00
Artem Chikin
e04512f55c Merge pull request #71161 from artemcm/IncrementalExplicitHeaderFixes
[Explicit Module Builds] Register Clang module dependencies' input `.h` files with the dependency tracker
2024-01-26 13:24:37 -08:00
Artem Chikin
5fdb695d6d [Explicit Module Builds] Register Clang module dependencies' input .h files with the dependency tracker
Prior to emission of `.d` and `.swiftdeps` outputs. In implicit builds such dependencies are registered during the construction of the corresponding Clang module by the ClangImporter's built-in Compiler Instance. In explicit builds, since we load pre-built PCMs directly, we do not get to do so. So instead, manually register all `.h` inputs of Clang module dependnecies.

Resolves rdar://121354886
2024-01-25 15:41:19 -08:00
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
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
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
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
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
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
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
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
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
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
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
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
Doug Gregor
2ca67e0e0a Merge pull request #70414 from DougGregor/clang-importer-special-names
[Clang importer] Map imported names via the user-facing name
2023-12-13 00:31:06 -08:00
Doug Gregor
25faa002a4 Merge pull request #70397 from DougGregor/cleanup-caught-error-type
[Typed throws] Cleanups for the caught error type computation
2023-12-12 23:13:00 -08:00
Doug Gregor
7e30d54deb [Clang importer] Map imported names via the user-facing name
Swift names provided via C attributes or API notes can be parsed as
special names, such as `init` or `subscript`. However, doing so would
cause the Clang importer to crash, because it assumes that these names
are always identifiers. In these places, we actually want to treat
them as identifiers, where special names are mapped back to their
keywords. Introduce a function to do that, and use it consistently.
2023-12-12 14:22:02 -08:00
Doug Gregor
91df336a4d [Typed throws] Unify ThrownTypeRequest and DoCatchExplicitThrownTypeRequest
These two requests are effectively doing the same thing to two
different cases within CatchNode. Unify the requests into a single
request, ExplicitCaughtTypeRequest, which operates on a CatchNode.

This also moves the logic for closures with explicitly-specified throws
clauses into the same request, taking it out of the constraint system.
2023-12-12 00:06:17 -08:00
Ian Anderson
94e860e795 [ClangImporter] Swift needs to pass -Xclang -fbuiltin-headers-in-system-modules for its module maps that group cstd headers
Swift has some module maps it overlays on Linux and Windows that groups all of the C standard library headers into a single module. This doesn’t allow clang and C++ headers to layer properly with the OS/SDK modules. clang will set -fbuiltin-headers-in-system-modules as necessary for Apple SDKs, but Swift will need to pass that flag itself when required by its module maps.
2023-12-08 22:33:12 -08:00
Hamish Knight
5e7854f46b [AST] Remove static loc and spelling kind from AccessorDecl
The spelling kind was only ever set to
`StaticSpellingKind::None`, and the static location
was never used for anything (and should be queried
on the storage anyway). This doesn't affect the
computation of `isStatic` since `IsStaticRequest`
already takes the static-ness from the storage for
accessors.
2023-12-08 17:59:44 +00:00
Alex Lorenz
c7345d08cf Merge pull request #69790 from hyp/eng/move-only-is-back
[cxx-interop] enable support for move-only types
2023-12-06 09:43:43 -08:00
Alex Lorenz
623d3d2032 [cxx-interop] review fixes for non-copyable patch, ensure we only enable this in upcoming Swift 2023-12-05 14:16:30 -08:00
Egor Zhdan
c39c8da4db [cxx-interop] Use APINotes to apply import_owned attr to std::string and std::vector
This removes a special case in the compiler for these types, and applies the `import_owned` attribute to all instantiations of `vector` and `basic_string` via API Notes.
2023-12-04 19:54:17 +00:00
Puyan Lotfi
84e1007304 Merge pull request #69954 from plotfi/plotfi-swift-virtual-functions
[cxx-interop] Enable virtual function calling from Swift to C++
2023-12-04 10:37:20 -05:00
Puyan Lotfi
ebe83a4ac2 [cxx-interop] WA: skip virtual function import when symbolic import enabled
This is a simple work around to avoid importing virtual functions when symbolic
imports are turned on. Test cases that were failing before this WA are in
test/Interop/Cxx/symbolic-imports.

Thanks to Alex Lorenz for providing this WA to me (@hyp).
2023-12-04 01:57:13 -05:00
Puyan Lotfi
128064f31d [cxx-interop] Enable virtual function calling from Swift to C++
This is a forward-interop feature that wires up existing functionality for
synthesizing base class function calling to enable virtual function calling.
The general idea is to sythesize the pattern:

```
// C++ class:
struct S { virtual auto f() -> int { return 42; } };

// Swift User:
var s = S()
print("42: \(s.f())")

// Synthetized Swift Code:
extension S { func f() -> CInt { __synthesizedVirtualCall_f() } }

// Synthetized C/C++ Code:
auto __cxxVirtualCall_f(S *s) -> int { return s->f(); }
```

The idea here is to allow for the synthetized C++ bits from the Clang side to
handle the complexity of virtual function calling.
2023-12-04 01:55:30 -05:00
Alex Lorenz
b7158ea486 [cxx-interop] add SWIFT_NONCOPYABLE annotation 2023-11-29 18:13:31 -08:00