Commit Graph

1871 Commits

Author SHA1 Message Date
zoecarver
2e0398f867 [cxx-interop] Add support for subscripts in base classes. 2022-03-01 15:13:10 -08:00
YOCKOW
e4834d8ac4 [NFC|ClangImporter] DRY to determine whether or not ext is PCH. 2022-02-27 15:03:13 +09:00
Ben Barham
bbc98aae16 [Importer] Wrap the VFS passed to Clang with an overlay FS instead
`OverlayFileSystem` is very simple - it just passes along each request
to each VFS it contains until one is successful (or none are). Use it
when wrapping the VFS to pass down into the Clang invocation creation,
instead of the much more complicated `RedirectingFileSystem`.

This has the side effect of also fixing a case where due to a bug in
`RedirectingFileSystem`, the originally passed in path will be returned
regardless of `use-external-name`. While that should also be fixed,
there is no reason to use this VFS here anyway.

Added a small cursor info test case that should catch issues like this
in the future.
2022-02-25 10:06:04 -08:00
Zoe Carver
e30ba5fc47 Merge pull request #39349 from zoecarver/import-base-class-members 2022-02-20 03:12:13 -08:00
Victoria Mitchell
cab1669e09 only recurse getDisplayDecls in SymbolGraphGen 2022-02-19 10:32:29 -07:00
zoecarver
bb00e8dcfe [cxx-interop] Rudimentary support for importing base classes.
This commit adds very basic support for importing and calling base class methods, getting and setting base class fields, and using types inside of base classes.
2022-02-18 15:59:52 -08:00
Becca Royal-Gordon
f440c2dcc9 [NFC] 32-bit-safe ImportDiagnosticTarget
Previously, ImportDiagnosticTarget was a PointerUnion of five types. This required more spare bits than were available on 32-bit platforms, so the compiler (and more importantly, lldb) could not be built for those.

Fortunately, it turns out that there’s no good reason for `clang::ModuleMacro` to be part of the pointer union—we always convert it to `clang::MacroInfo` before looking up diagnostics anyway. Removing it gets us back into territory which ought to be 32-bit-safe.

Fixes rdar://88922618.
2022-02-17 17:23:59 -08:00
Volodymyr Sapsai
6f9bebe10c Merge pull request #41144 from vsapsai/accept-demoted-tagdecl
Make isVisibleFromModule accept TagDecl definitions that were demoted to declarations.
2022-02-16 14:02:13 -08:00
zoecarver
283fc782ec Revert "Revert "[cxx-interop] A few cleanups and fixes for function templates.""
This reverts commit 5de09631ff.
2022-02-15 13:30:10 -08:00
Zoe Carver
5de09631ff Revert "[cxx-interop] A few cleanups and fixes for function templates." 2022-02-13 09:54:39 -08:00
zoecarver
daceecfc75 [cxx-interop] Remove generateSpecializedCXXFunctionTemplate and just import the decl directly.
1) This unifies two code paths that do essentially the same thing.
2) This fixes how we import certain types (such as return types).
2022-02-04 16:18:02 -08:00
Volodymyr Sapsai
91a48693a3 Make isVisibleFromModule accept TagDecl definitions that were demoted to declarations.
Clang AST requires to have only a single definition in a redeclaration
chain, that's why it demotes duplicate definitions from other modules to
declarations. But on the Swift side it is important to know a module
contains a full definition and not just a forward declaration, even if
it was demoted to a declaration.
2022-02-01 16:42:23 -08:00
Nuri Amari
7ec861fbd9 Enable lazy ClangImporter diagnostics by default
Replace the existing `-enable-experimental-clang-importer-diagnostics`
flag with an opt-out version entitled `-disable-experimentalc-clang-importer-diagnostics`.
Enable the beviour previously hidden behind the old flag by default.
2022-02-01 18:43:49 -05:00
Nuri Amari
3762ca1fa7 Attach Lazy ClangImporter Diagnostics as Notes
Clang importer diagnostics that are produced as a result of a reference
in Swift code are attached to as notes to the Sema produced diagnostic
that indicates the declaration is unavailable.

Ex: Notes about why a C function import failed are attached to
the error explaining that the symbol could not be found in scope.
2022-01-29 14:32:42 -05:00
QuietMisdreavus
c99089cfe8 Merge pull request #40860 from apple/QuietMisdreavus/display-decl-recur
[AST] check modules before recursing for display decls

rdar://87601741
2022-01-20 10:50:48 -07:00
Victoria Mitchell
7338eb02b7 add test for top-level decls of Clang submodules 2022-01-19 16:07:31 -07:00
Victoria Mitchell
aeaf6b22db [AST] check modules before recursing for display decls 2022-01-18 08:51:29 -07:00
swift-ci
95586e858c Merge remote-tracking branch 'origin/main' into rebranch 2022-01-04 16:00:29 -08:00
Robert Widmann
e5118fcf79 Merge pull request #34094 from ApolloZhu/fix-canImport-submodule
Implement canImport test for submodule
2022-01-04 15:22:19 -08:00
Nuri Amari
130f2de7fd Improve ClangImporter failure diagnostics
This patch introduces new diagnostics to the ClangImporter to help
explain why certain C, Objective-C or C++ declarations fail to import
into Swift. This patch includes new diagnostics for the following entities:

- C functions
- C struct fields
- Macros
- Objective-C properties
- Objective-C methods

In particular, notes are attached to indicate when any of the above
entities fail to import as a result of refering an incomplete (only
forward declared) type.

The new diangostics are hidden behind two new flags, -enable-experimental-clang-importer-diagnostics
and -enable-experimental-eager-clang-module-diagnostics. The first flag emits diagnostics lazily,
while the second eagerly imports all declarations visible from loaded Clang modules. The first
flag is intended for day to day swiftc use, the second for module linting or debugging the importer.
2022-01-02 12:43:59 -05:00
ApolloZhu
683d469fcd Extends canImport to check for submodule availability 2021-12-28 22:54:47 -08:00
Adrian Prantl
c30f256bbe Initialize clang::CodeGenOptions.DebugExtRefs in ClangImporter.
This fixes a race condition in parallel builds. DebugExtRefs is part of the
Clang module hash. ObjectFilePCHContainerOperations has its own CodenOpts object
which always sets DebugExtRefs=true, so the module has could differ depending on
whether a module was built as a top-level module or as a dependency of another
module.

This fixes the SwiftREPL tests.

rdar://86279876
2021-12-20 16:48:11 -08:00
Alex Hoppen
669e3f34a6 Merge pull request #40155 from ahoppen/pr/improve-module-search-path-lookup
[Serialization] Improve module loading performance
2021-12-20 18:09:17 +01:00
Alex Hoppen
fe7878ecce [Serialization] Improve module loading performance
When looking for a Swift module on disk, we were scanning all module search paths if they contain the module we are searching for. In a setup where each module is contained in its own framework search path, this scaled quadratically with the number of modules being imported. E.g. a setup with 100 modules being imported form 100 module search paths could cause on the order of 10,000 checks of `FileSystem::exists`. While these checks are fairly fast (~10µs), they add up to ~100ms.

To improve this, perform a first scan of all module search paths and list the files they contain. From this, create a lookup map that maps filenames to the search paths they can be found in. E.g. for
```
searchPath1/
  Module1.framework

searchPath2/
  Module1.framework
  Module2.swiftmodule
```
we create the following lookup table
```
Module1.framework -> [searchPath1, searchPath2]
Module2.swiftmodule -> [searchPath2]
```
2021-12-14 12:44:13 +01:00
Robert Widmann
ea8a4e15a2 Fix Up Initialization Ordering In ClangImporter::Implementation 2021-12-13 12:25:45 -08:00
Xi Ge
c5a715d4ed Revert "[cxx-interop] Fix two issues with extending nested types across modules."
This reverts commit 6ba7a1ec1e.
2021-12-08 20:00:41 -08:00
zoecarver
fc3b3a1d71 [cxx-interop] Implement foreign reference types.
This is an expiremental feature to allow an attribute, `import_as_ref`, to import a C++ record as a non-reference-counted reference type in Swift.
2021-12-08 15:35:18 +00:00
Argyrios Kyrtzidis
7ad553f981 Merge pull request #40273 from bnbarham/pch-allow-errors
[ClangImporter] Handle allowing PCM/PCH errors
2021-12-03 18:13:46 -08:00
Egor Zhdan
9010d89c5e Merge pull request #39999 from egorzhdan/cxx-mutating-attr
C++ Interop: support mutating attribute for C++ methods
2021-11-30 10:58:16 +03:00
Ben Barham
594fabafd9 [ClangImporter] Handle allowing PCM/PCH errors
Ignore errors when emitting/reading a PCM/PCH and Clang has
`-fallow-(pcm|pch)-with-compiler-errors` set.

Resolves rdar://85576570.
2021-11-30 15:46:51 +10:00
Egor Zhdan
06612934e8 C++ Interop: support mutating attribute for C++ methods
This change teaches ClangImporter to import C++ methods marked with `__attribute__((__swift_attr__("mutating")))` as mutating in Swift. This is useful, for example, when a method mutates `this` despite being `const` in C++ (e.g. via `const_cast`).
2021-11-29 21:13:16 +03:00
Becca Royal-Gordon
b9480f12d0 Allow imported types to add a Sendable conformance
...by using `__attribute__((swift_attr("@Sendable")))`. `@_nonSendable` will "beat" `@Sendable`, while `@_nonSendable(_assumed)` will not.

This commit also checks if `SwiftAttr` supports `#pragma clang attribute` and, if it does, defines `__SWIFT_ATTR_SUPPORTS_SENDABLE_DECLS` in imported headers so they know they can apply these attributes in an auditing style.
2021-11-19 11:34:01 -08:00
Saleem Abdulrasool
4d44953691 Revert "Support __available__((swift_attr("@Sendable")))" 2021-11-19 07:40:24 -08:00
Becca Royal-Gordon
3d2d4e1721 Merge pull request #40170 from beccadax/send-me-an-object
Support __available__((swift_attr("@Sendable")))
2021-11-19 01:26:10 -08:00
Robert Widmann
f97d0cc4c0 [NFC] Initialize Members in Order 2021-11-17 13:17:00 -08:00
Zoe Carver
8980b8b6ec Merge pull request #40165 from zoecarver/fix-extensions-across-modules
[cxx-interop] Fix two issues with extending nested types across modules.
2021-11-16 09:08:06 -08:00
zoecarver
6ba7a1ec1e [cxx-interop] Fix two issues with extending nested types across modules.
One fix allows extending nested records in other modules, the other fixes the same issue for namespaces.
2021-11-15 16:20:15 -08:00
Zoe Carver
fb88ace28b Merge pull request #40143 from apple/revert-40010-importSourceLoc
Revert "Implement ClangImporter importSourceLoc and importSourceRange"
2021-11-13 16:58:11 -08:00
Becca Royal-Gordon
7549278314 Allow imported types to add a Sendable conformance
...by using `__attribute__((swift_attr("@Sendable")))`. `@_nonSendable` will "beat" `@Sendable`, while `@_nonSendable(_assumed)` will not.

This commit also checks if `SwiftAttr` supports `#pragma clang attribute` and, if it does, defines `__SWIFT_ATTR_SUPPORTS_SENDABLE_DECLS` in imported headers so they know they can apply these attributes in an auditing style.
2021-11-12 23:13:29 -08:00
Alex Lorenz
1089959b0f [interop] clang name lookup should find declarations in inline namespaces 2021-11-12 17:40:38 -08:00
Zoe Carver
c6474b970d Revert "Implement ClangImporter importSourceLoc and importSourceRange (#40010)"
This reverts commit 8eb8263f81.
2021-11-11 12:09:55 -08:00
Nuri Amari
8eb8263f81 Implement ClangImporter importSourceLoc and importSourceRange (#40010)
Co-authored-by: Nuri Amari <nuriamari@fb.com>
2021-11-09 16:31:03 -08:00
Jan Svoboda
8979602fef Merge pull request #39810 from apple/jan_svoboda/search_path_remark_sloc
[ClangImporter] Pass `SourceLocation` to `lookupModule`
2021-10-22 14:54:17 +02:00
Zoe Carver
401f334b90 Merge pull request #38675 from zoecarver/lazy-importer-namespaces
[cxx-interop] Lazily import members of clang namespaces and records via requests.
2021-10-21 09:04:52 -07:00
Jan Svoboda
7f344cbf25 [ClangImporter] Pass SourceLocation to lookupModule 2021-10-21 14:24:11 +02:00
zoecarver
b8e52a7ad2 [cxx-interop] Lazily import members of Clang namespaces and records via requests.
Also adds a ClangImporter request zone and move some requests into it.
2021-10-20 14:52:43 -07:00
Ellie Shin
6f34844b49 Merge pull request #39705 from apple/es-module-alias-serialize
[Module aliasing] Serialize SIL and binaries with module real names for referenced or imported modules. Resolves rdar://83632529
2021-10-18 21:55:45 -07:00
zoecarver
0ca8dd364f [nfc][cxx-interop] Add three requests ClangDirectLookupRequest, CXXNamespaceMemberLookup, and ClangRecordMemberLookup.
None of these requests are used, so this is a non-functional change.
2021-10-13 16:31:09 -07:00
Zoe Carver
40422f021b Merge pull request #39664 from zoecarver/lazy-pt9-use-lookup-table
[cxx-interop] Add members to the LookupTable where possible.
2021-10-13 15:29:31 -07:00
zoecarver
eeeb27d66e [cxx-interop] Add members to the LookupTable where possible.
If possible, add imported members to the StructDecl's LookupTable rather than adding them directly as members. This will fix the issues with ordering that #39436 poorly attempted to solve during IRGen.

This also allows us to break out most of the test changes from #39436.
2021-10-13 11:53:58 -07:00