Commit Graph

531 Commits

Author SHA1 Message Date
Omar Habra
4167e2f80d [cxx-interop] Computed properties from getters and setters (#40842)
* fixing setters

* adding tests

* Removing extras

* fixing tests

* Better naming for properties

* Cleanup

* Add tests

* Clang format it

* more refactoring and some more tests

* More tests and more fixes

* Updating tests:

fixing other tests to work with new property importing

* Fix the two asserts. Move things around. Remove createImported. Move CXXMethodBridging to it's own header.

* General updates:

Fixing tests, adding radars to follow issues that cna be a started issues on the project.
Also Factoring out MethodBridging.

* Fixing Comments left on the PR:

General formatting.

* Fixing tests, and general updates for formatting

* removing extras and passing this on swift.

Co-authored-by: Omar Habra <ohabra@apple.com>
2022-02-28 23:13:17 -08:00
Victoria Mitchell
cab1669e09 only recurse getDisplayDecls in SymbolGraphGen 2022-02-19 10:32:29 -07: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
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
Victoria Mitchell
aeaf6b22db [AST] check modules before recursing for display decls 2022-01-18 08:51:29 -07: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
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
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
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
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
elsh
adf33e0bb9 Add doc comments
Rename test
2021-10-12 15:03:30 -07:00
zoecarver
d706863a52 [cxx-interop][nfc] Add a ClangImporter request zone.
This is just the boilerplate for adding a request zone. I haven't actually added any requrests in this commit.
2021-09-28 17:08:48 -07:00
zoecarver
d13f43c31b [cxx-interop] Add three utilities to the ClangModuleLoader.
This adds `importDeclDirectly`, `findLookupTable`, `importName`, and `getEffectiveClangContext`. These are all needed for #38675.
2021-09-23 16:51:03 -07:00
Artem Chikin
e64a40451b [Dependency Scanning] Model main module as separate dependency kind: SwiftSource
These kinds of modules differ from `SwiftTextual` modules in that they do not have an interface and have source-files.
It is cleaner to enforce this distinction with types, instead of checking for interface optionality everywhere.
2021-09-15 09:31:20 -07:00
zoecarver
6e9bf50996 [cxx-interop] Lazily load the result of imported functions.
Note: we only lazily load the result if it's a record, because otherwise it's trivial to load when importing the function. Also, we still eagerly import operator's results types.
2021-09-08 17:48:39 -07:00
Egor Zhdan
a8f126f7cd C++ Interop: import const methods as non-mutating
This change makes ClangImporter import some C++ member functions as non-mutating, given that they satisfy two requirements:
* the function itself is marked as `const`
* the parent struct doesn't contain any `mutable` members

`get` accessors of subscript operators are now also imported as non-mutating if the C++ `operator[]` satisfies the requirements above.

Fixes SR-12795.
2021-07-25 15:18:33 +03:00
Ben Barham
28bb2505b0 [ClangImporter] Respect -working-directory in the created VFS
Pass a wrapped VFS down into `clang::createInvocationFromCommandLine` so
that the working directory is set and then used in the underlying Clang
`CompilerInstance`.

Fixes the possibility of differing modules hashes when the same
arguments are used in Clang directly vs from the importer.

Resolves rdar://79376364
2021-06-24 11:07:40 +10:00
Xi Ge
bbe5b83de9 Parser: teach canImport to take an additional parameter indicating the minimum module version
canImport should be able to take an additional parameter labeled by either version or
underlyingVersion. We need underlyingVersion for clang modules with Swift overlays because they
have separate version numbers. The library users are usually interested in checking the importability
of the underlying clang module instead of its Swift overlay.

Part of rdar://73992299
2021-05-02 17:47:44 -07:00
Ben Barham
384b309f89 [Refactoring] Only convert calls with handlers that have completion-like names
Still convert the call if it was requested directly - only check the name
when converting a whole function. Once we have an attribute, we should
use that instead.
2021-02-12 07:43:57 +10:00
swift-ci
e349794517 Merge remote-tracking branch 'origin/main' into rebranch 2021-01-27 04:12:41 -08:00
Marcel Hlopko
4f5c75a236 [cxx-interop] Instantiate C++ class templates from Swift (#33284)
This PR makes it possible to instantiate C++ class templates from Swift. Given a C++ header:

```c++
// C++ module `ClassTemplates`
template<class T>
struct MagicWrapper {
  T t;
};

struct MagicNumber {};
```

it is now possible to write in Swift:

```swift
import ClassTemplates

func x() -> MagicWrapper<MagicNumber> {
  return MagicWrapper<MagicNumber>()
}
```

This is achieved by importing C++ class templates as generic structs, and then when Swift type checker calls `applyGenericArguments` we detect when the generic struct is backed by the C++ class template and call Clang to instantiate the template. In order to make it possible to put class instantiations such as `MagicWrapper<MagicNumber>` into Swift signatures, we have created a new field in `StructDecl` named `TemplateInstantiationType` where the typechecker stores the `BoundGenericType` which we serialize. Deserializer then notices that the `BoundGenericType` is actually a C++ class template and performs the instantiation logic.

Depends on https://github.com/apple/swift/pull/33420.
Progress towards https://bugs.swift.org/browse/SR-13261.
Fixes https://bugs.swift.org/browse/SR-13775.

Co-authored-by: Dmitri Gribenko <gribozavr@gmail.com>
Co-authored-by: Rosica Dejanovska <rosica@google.com>
2021-01-27 13:01:20 +01:00
Varun Gandhi
ad89b31e2b [Serialization] Update Clang type serialization for LLVM-side change.
Corresponding LLVM change in https://reviews.llvm.org/D94196.
2021-01-07 12:52:12 -08:00
Jonas Devlieghere
d01474cc72 Change interfaces to accept a FileCollectorBase
The FileCollectorBase is the common interface shared by different
implementations. In lldb, we implement our own lazy variant that allows
us to do the heavy lifting out-of-process instead of inside the signal
handler.
2020-10-28 20:14:46 -07:00
Zoe Carver
f0f2246793 [cxx-interop] Support C++ function templates in Swift. (#33053)
This patch adds rudimentary support for C++ template functions in swift.
2020-10-21 20:42:25 -07:00
Brent Royal-Gordon
b440ab7331 [NFC] Move several types/functions to Import.h
To help consolidate our various types describing imports, this commit moves the following types and methods to Import.h:

* ImplicitImports
* ImplicitStdlibKind
* ImplicitImportInfo
* ModuleDecl::ImportedModule
* ModuleDecl::OrderImportedModules (as ImportedModule::Order)
* ModuleDecl::removeDuplicateImports() (as ImportedModule::removeDuplicates())
* SourceFile::ImportFlags
* SourceFile::ImportOptions
* SourceFile::ImportedModuleDesc

This commit is large and intentionally kept mechanical—nothing interesting to see here.
2020-10-09 18:57:07 -07:00
Brent Royal-Gordon
cff4ddf13a [NFC] Adopt new ImportPath types and terminology
# Conflicts:
#	lib/IDE/CodeCompletion.cpp
2020-09-10 19:07:49 -07:00
Xi Ge
e107182f1a Merge remote-tracking branch 'apple/master' into master-rebranch 2020-09-02 18:36:37 -07:00
Xi Ge
a4d731ed9f ModuleLoader: remove several walk-arounds for not having a persistent ClangImporterOptions available. NFC 2020-09-02 15:10:50 -07:00
Xi Ge
c403b140e1 ClangImporter: refactor ClangImporterOptions to be ASTContext-owned. NFC
We need ClangImporterOptions to be persistent for several scenarios: (1)
when creating a sub-ASTContext to build Swift modules from interfaces; and
(2) when creating a new Clang instance to invoke Clang dependencies scanner.

This change is NFC.
2020-09-01 14:04:22 -07:00
swift_jenkins
4eaa071e8b Merge remote-tracking branch 'origin/master' into master-rebranch 2020-08-31 18:46:27 -07:00
Xi Ge
55e77785df ABI checker: add a mechansim for specifying allowd ABI breakages
When the checker found a breakage listed in the user-specified list,
the breage should be consumed internally without failing the check.

rdar://68086477
2020-08-31 10:57:15 -07:00
Nathan Hawes
9d4ed5f39c Manually merge remote-tracking branch 'upstream/master' into manually-merge-master-to-master-rebranch 2020-07-20 16:09:55 -07:00
Daniel Duan
942893d7a6 ClangImporter: Preserve CChar type (#32692)
Addresses SR-466.
2020-07-08 10:18:58 -07:00
swift_jenkins
465eae8559 Merge remote-tracking branch 'origin/master' into master-next 2020-06-30 08:58:09 -07:00
Hamish Knight
7bc5440d17 [Frontend] Internalize createDependencyTracker
Expand the FrontendOptions to allow the enabling
of the dependency tracker for non-system
dependencies, and switch the previous clients of
`createDependencyTracker` over to using this
option. This ensures that the dependency tracker
is now set only during `CompilerInstance::setup`.
2020-06-29 15:26:26 -07:00
Karoy Lorentey
57ea964f2c Merge commit '3eb82c183662945687f48e11c09828f551b34858' into master-next
# Conflicts:
#	include/swift/Frontend/FrontendInputsAndOutputs.h
2020-06-08 16:58:37 -07:00
Karoy Lorentey
68351d2110 Revert "Merge remote-tracking branch 'origin/master-next'"
This reverts commit 1c9b0908e6, reversing
changes made to 3eb82c1836.
2020-06-08 16:48:38 -07:00
Karoy Lorentey
1c9b0908e6 Merge remote-tracking branch 'origin/master-next'
# Conflicts:
#	include/swift/Frontend/FrontendInputsAndOutputs.h
2020-06-08 16:43:40 -07:00
Xi Ge
9e88549199 ModuleInterface: teach module interface building to use explicitly built PCMs 2020-06-02 16:51:45 -07:00
Xi Ge
3a214d99f6 Frontend: add an argument to disable implicitly built Swift modules 2020-06-02 16:51:45 -07:00
swift_jenkins
68af9d595b Merge remote-tracking branch 'origin/master' into master-next 2020-05-22 20:18:30 -07:00
Xi Ge
38c0452d65 DependenciesScanner: report command-line arguments for building pcm explicitly 2020-05-22 07:50:08 -07:00
swift_jenkins
4f45260171 Merge remote-tracking branch 'origin/master' into master-next 2020-05-12 21:38:40 -07:00
Xi Ge
3952fd5bf7 ModuleInterface: refactor compiler instance configuration to a standalone delegate class. NFC
Module interface builder used to maintain a separate compiler instance for
building Swift modules. The configuration of this compiler instance is also
useful for dependencies scanner because it needs to emit front-end compiler invocation
for building Swift modules explicitly.

This patch refactor the configuration out to a delegate class, and the
delegate class is also used by the dependency scanner.
2020-05-12 16:19:27 -07:00
swift_jenkins
4f38d3e06a Merge remote-tracking branch 'origin/master' into master-next 2020-05-05 13:57:12 -07:00
Xi Ge
9bc036c050 DependencyScanner: honor additional compiler flags in interfaces files when collecting imports
Additional flags in interface files may change parsing behavior like #if
statements. We should use a fresh ASTContext with these additional
flags when parsing interface files to collect imports.

rdar://62612027
2020-05-04 22:18:11 -07:00
swift_jenkins
ed20b9c058 Merge remote-tracking branch 'origin/master' into master-next 2020-04-24 23:58:13 -07:00
Doug Gregor
d6484c8280 [Dependency scanning] Scan and record bridging header dependencies.
When there is a bridging header associated with the module, scan and record
its dependencies. Note them in a separate structure to capture the specific
dependencies of the bridging header.
2020-04-24 12:58:45 -07:00