Commit Graph

1889 Commits

Author SHA1 Message Date
Egor Zhdan
638abd991f [cxx-interop] Refactor: move synthesis logic elsewhere 2024-03-01 15:57:33 +00:00
Becca Royal-Gordon
1a97803c8c Add flag for dumping ClangImporter lookup tables
ClangImporter’s SwiftLookupTables map Swift names to their corresponding Clang declarations. These tables are built into a module’s clang .pcm file and missing or inaccurate entries can cause name lookup to fail to find an imported declaration.

Swift has always included a helper function that would dump these tables, and swift-ide-test has a command-line switch that would invoke it, but these tools are clumsy to use in many debugging scenarios. Add a frontend flag that dumps the tables at the end of the frontend job, making it a lot easier to get at this information in the context of a specific compilation.
2024-02-29 17:51:00 -08:00
Egor Zhdan
3e75fd207d Revert "[cxx-interop] Enable virtual function calling from Swift to C++"
This partially reverts commit 128064f3
2024-02-29 22:33:27 +00:00
Egor Zhdan
98fc9fd9c5 Merge pull request #71813 from apple/egorzhdan/std-not-found
[cxx-interop] Correctly generate the list of transitive dependencies for CxxStdlib overlay
2024-02-26 12:35:25 +00:00
Ben Barham
f292ec9784 Use the new template deduction guides rather than makeArrayRef
LLVM has removed `make*ArrayRef`, migrate all references to their
constructor equivalent.
2024-02-23 20:04:51 -08:00
Egor Zhdan
9147522506 [cxx-interop] Correctly generate the list of transitive dependencies for CxxStdlib overlay
This fixes a compiler error that occurred while building `CxxStdlib.swiftmodule` and other projects that use C++ interop: `error: cannot find type 'std' in scope`.

The compiler was creating two distinct `swift::ModuleDecl` instances for the CxxStdlib module while building the CxxStdlib overlay: one as a main module (the module that is currently being compiled), one as a dependency of the main module. This confused the Swift name lookup logic down the road.

This only happened with recent libc++.

See the inline comment for more details.

rdar://122815523
2024-02-22 16:43:51 +00:00
Ben Barham
5637284e48 Merge pull request #71368 from bnbarham/std-optional-all-the-things
Migrate llvm::Optional to std::optional
2024-02-21 16:54:00 -08:00
Ben Barham
ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -08:00
Pavel Yaskevich
c533d4298e [ClangImporter] Produce ErrorType for invalid variables
If type couldn't be imported, produce error type instead
of `Type()` to align with other checks.

Resolves: rdar://123244479
2024-02-21 09:32:25 -08:00
Becca Royal-Gordon
7aa5b7fd88 Merge pull request #71445 from beccadax/category-error 2024-02-13 11:13:48 -08:00
Steven Wu
9607e9dec1 Merge pull request #71497 from cachemeifyoucan/eng/PR-122423965
[Caching] Use subInvocation to verify interface
2024-02-13 09:18:40 -08:00
Steven Wu
3986937e03 [Caching][NFC] Restructure CASOption in swift. NFC
Clean up how CASOptions are kept and passed inside swift to make the
code more readable. Also avoid a copy of CAS configuration in
ClangImporter.
2024-02-11 14:08:09 -08:00
Becca Royal-Gordon
9bcd818fb1 [NFC] Make objcImpl request one-to-many
An @_objcImpl extension with no category name *should* implement not only the class’s main @interface, but also any class extension @interfaces. Start making this true by making ObjCInterfaceAndImplementationRequest return all of these decls as the interfaces for such an implementation.

This commit doesn’t actually change Sema or IRGen to process the extra interfaces, so it’s NFC.
2024-02-09 21:32:06 -08:00
Jan Svoboda
757c50cd4b [ClangImporter] Align callback with Clang change (#71475) 2024-02-08 20:17:14 -08:00
Becca Royal-Gordon
8621508098 Merge pull request #71320 from beccadax/globally-lazy-maximum
[ClangImporter] Support lazy member loading for import-as-member globals in extensions
2024-02-08 12:13:32 -08:00
Kuba Mracek
dba8d5d3a0 Revert "Merge pull request #71278 from kubamracek/embedded-no-mach-defines"
This reverts commit 21eddf0b1a, reversing
changes made to e2d516f3c9.
2024-02-05 09:05:22 -08:00
Kuba (Brecka) Mracek
21eddf0b1a Merge pull request #71278 from kubamracek/embedded-no-mach-defines
[embedded] Implicitly define __APPLE__ and __MACH__ when on -apple-none triples
2024-02-02 19:30:56 -08:00
Kuba Mracek
4776e993ad [embedded] Use defined(__wasm__) instead of defined(__wasi__) in Visibility.h 2024-02-02 12:41:54 -08:00
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