Commit Graph

1869 Commits

Author SHA1 Message Date
Egor Zhdan
65f319a242 [cxx-interop] Do not crash while generating a diagnostic for un-instantiatable template
Swift was previously crashing while emitting an error ("could not generate C++ types from the generic Swift types provided") for C++ decls that do not have a name, such as constructors: `func->getName()` triggered an assertion.
2023-01-17 17:19:20 +00:00
Erik Eckstein
712fd7922b Merge remote-tracking branch 'origin/main' into rebranch 2023-01-09 08:48:47 +01:00
Egor Zhdan
9e35a175e9 [cxx-interop] Members of private base classes should not be exposed
Trying to use members of C++ private base classes from Swift causes an assertion failure in ClangImporter:

```
<build dir>/swift/lib/swift/macosx/arm64/libcxxshim.h:2:66: error: cannot cast 'A' to its private base class 'B'
To __swift_interopStaticCast(From from) { return static_cast<To>(from); }
                                                                 ^
```

Such members should not be exposed.

rdar://103871000
2023-01-04 13:41:50 +00:00
Egor Zhdan
1f920d5e96 [cxx-interop] Instantiate templated operator== for iterator types
C++ iterator types are often templated, and sometimes declare `operator==` as a non-member templated function. In libc++, an example of this is `__wrap_iter` which is used as an iterator type for `std::vector` and `std::string`.

We don't currently import templated non-member operators into Swift, however, we still want to support common C++ iterator patterns.

This change adds logic to instantiate templated non-member `operator==` for types that define `iterator_category` and are therefore likely to be valid iterator types.

rdar://97915515
2023-01-04 11:56:36 +00:00
swift-ci
bfe12a8ca9 Merge remote-tracking branch 'origin/main' into rebranch 2023-01-03 09:13:55 -08:00
swift-ci
5a7d5d877b Merge remote-tracking branch 'origin/main' into rebranch 2023-01-03 06:04:03 -08:00
Egor Zhdan
745d92d9cb [cxx-interop] Allow instantiated operator methods to serve as protocol conformance witnesses
If a templated C++ class declares an operator as a member function, and is instantiated using a typedef or a using-decl on the C++ side, it previously could not be conformed to a Swift protocol that requires the operator function despite matching signatures.

This was due to a Swift name lookup issue: operators, unlike regular member functions, are found by doing an unqualified lookup. Since C++ class template specializations and their members are not added to `SwiftLookupTable`, when doing qualified lookup members are searched by looking at all of the members of the specialization and choosing the ones with matching names. With unqualified lookup, we cannot rely on knowing the right specialization and need to search for all the operators in a given module.

This change adds synthesized operator thunks to `SwiftLookupTable` to make them discoverable by unqualified lookup.
2023-01-03 13:57:08 +00:00
Egor Zhdan
d663bb4568 [cxx-interop] Treat name lookup as successful if we found a C++ member operator
`ClangImporter::Implementation::lookupValue` used to return `false` if it found an overloaded C++ operator that is declared as a member function of a C++ type.

This doesn't have any effect now since the return value isn't used under normal conditions, but it might bite us later.
2022-12-22 19:48:18 +00:00
swift-ci
1d3d68d0e7 Merge remote-tracking branch 'origin/main' into rebranch 2022-12-13 13:35:20 -08:00
Egor Zhdan
bbf8f0d5bc [cxx-interop] Fix lookup failure for operators in templated classes
If an operator is declared as a method of a templated class, we were failing to look it up during auto-conformance to `UnsafeCxxInputIterator`.

This fixes `Interop/Cxx/stdlib/use-std-map.swift` on Ubuntu.

rdar://102420290
2022-12-13 17:05:38 +00:00
swift-ci
fa97319512 Merge remote-tracking branch 'origin/main' into rebranch 2022-11-28 14:33:53 -08:00
Alexis Laferrière
c266e9dce5 Merge pull request #62185 from xymus/improve-rmodule-loading
Improve `-Rmodule-loading` to show both the path to the source and to the cached file actually loaded
2022-11-28 14:25:15 -08:00
swift-ci
efef52a86e Merge remote-tracking branch 'origin/main' into rebranch 2022-11-28 09:33:40 -08:00
Erik Eckstein
ab1b343dad use new llvm::Optional API
`getValue` -> `value`
`getValueOr` -> `value_or`
`hasValue` -> `has_value`
`map` -> `transform`

The old API will be deprecated in the rebranch.
To avoid merge conflicts, use the new API already in the main branch.

rdar://102362022
2022-11-21 19:44:24 +01:00
Alexis Laferrière
319d49816d [Frontend] -Rmodule-loading shows both source path and cached path 2022-11-18 15:28:16 -08:00
swift-ci
b3d9c1efd3 Merge remote-tracking branch 'origin/main' into rebranch 2022-11-07 09:35:16 -08:00
Erik Eckstein
b2439b70f8 ClangImporter: check if a decl's destructor is null
For some reason even if `decl->hasUserDeclaredDestructor()` is true, `decl->getDestructor()` still can be null.
2022-11-04 20:44:19 +01:00
Erik Eckstein
9ddd4cd98d adapt changed API for clang::createInvocation 2022-11-04 20:44:19 +01:00
Alexis Laferrière
ea2f222f83 [ClangImporter] Support loading clang modules that are aliased 2022-11-04 11:10:26 -07:00
Alexis Laferrière
47b29b68db Merge pull request #61649 from xymus/index-swiftinterfaces
[Index] Force indexing of system modules to read only from swiftinterfaces
2022-10-31 14:18:45 -07:00
Alexis Laferrière
730497e9a3 [Serialization] Add control over adding a loaded module to the in-memory cache 2022-10-31 10:58:57 -07:00
Zoe Carver
777eafc0da Merge pull request #61752 from zoecarver/enable-frt-no-cxx-interop
Support foreign reference types when C++ interop is disabled.
2022-10-26 20:51:30 -07:00
zoecarver
dc581b9d58 Support foreign reference types when C++ interop is disabled. 2022-10-26 14:50:09 -07:00
Augusto Noronha
26a3c454af Merge pull request #61729 from augusto2112/expose-isKnownCFTypeName
Expose "isKnownCFTypeName" through ClangImporter
2022-10-26 09:47:51 -07:00
Augusto Noronha
7a7663eec7 Expose "isKnownCFTypeName" through ClangImporter
LLDB needs to know if a type was specially handled by the compiler, so
expose "isKnownCFTypeName" so LLDB can call it.
2022-10-25 16:23:14 -07:00
Becca Royal-Gordon
82d78a384f Merge pull request #60630 from beccadax/at-implementation
Add @_objcImplementation
2022-10-20 17:14:21 -07:00
Egor Zhdan
6a88f75072 [cxx-interop] Implicitly import Cxx module
This lifts the requirement for the user to explicitly add `import Cxx` in Swift code that relies on protocols from the `Cxx` module, such as `CxxSequence`.
2022-10-19 15:00:50 +01:00
Becca Royal-Gordon
6143b8379f Generate IR for @_objcImpl stored properties
Only works for trivial types right now because features related to initialization and deinitialization are seriously busted.
2022-10-18 17:21:56 -07:00
Becca Royal-Gordon
ecf0ee65b8 Cache @_objcImpl pointers and diagnose dupes 2022-10-18 17:21:56 -07:00
Becca Royal-Gordon
3a2f12a099 Allow stored properties in @_objcImpls
Stored properties are only allowed in the extension implementing the class's main interface, not its categories. This also means banning `@objc final`, which is unenforceable anyway when ObjC subclasses are allowed, and therefore allowing `@objc let` and `@objc static` properties to be overridden if they're declared in objcImplementations.
2022-10-18 17:21:56 -07:00
Becca Royal-Gordon
f2a0ab79c7 Add basic Sema support for @_objcImplementation
Does not validate members yet; nor does it emit different metadata.
2022-10-18 17:21:56 -07:00
zoecarver
492f2aaff2 [cxx-interop] Fix friend operators that come from class template specializations. 2022-10-14 13:33:06 -07:00
Luciano Almeida
a95f60e387 [AST] Refactor generic parameter list parse logic for AccessorDecl 2022-10-07 09:43:08 -03:00
Anthony Latsis
18156d1177 Merge pull request #61347 from AnthonyLatsis/migrate-compiler-to-gh-issues
Gardening: Migrate compiler sources to GitHub issues
2022-09-30 10:48:52 +03:00
Anthony Latsis
2843e0c871 Gardening: Migrate compiler sources to GitHub issues 2022-09-29 23:58:55 +03:00
Artem Chikin
bfa63750ce [ClangImporter] Add a mode to create the underlying Clang 'CompilerInvocation' directly from 'cc1' arguments, bypassing the Clang driver, only in the 'emit-pcm' compilation flow.
Controlled with a new flag '-direct-clang-cc1-module-build'

This will allow clients to formulate 'swift-frontend' invocations with fully-specified set of cc1 arguments (using '-Xcc -Xclang -Xcc <FLAG>') required for the PCM build, without having to go through the driver.
2022-09-27 09:59:06 -07:00
Egor Zhdan
61d3bde796 [cxx-interop] Fix ASAN error
`e3c58386` introduced an ASAN error:
```
ERROR: AddressSanitizer: stack-use-after-scope on address ...
in swift::ClangImporter::Implementation::loadModuleClang ...
SUMMARY: AddressSanitizer: stack-use-after-scope ClangImporter.cpp:1903 in swift::ClangImporter::Implementation::loadModuleClang
```

rdar://99986478
2022-09-16 13:48:22 +01:00
Egor Zhdan
e3c58386b7 [cxx-interop] Recognize CxxStdlib as an alias for std
C++ standard library module is called `std`. To make it more clear to a Swift developer that this module is a C++ stdlib, and not a Swift stdlib, let's rename it to `CxxStdlib`.

This is the first step in the module rename. We don't ban `std` in this patch to be able to build SwiftCompilerSources with hosttools until a new Swift compiler is shipped.
2022-09-15 14:37:38 +01:00
Zoe Carver
c47a55dec5 Merge pull request #61026 from zoecarver/fix-invalid-vars
[cxx-interop] Lazily instanciate var types and compute their type.
2022-09-10 16:08:22 -07:00
zoecarver
f0d5cb9a84 [cxx-interop] Lazily instanciate var types and compute their type. 2022-09-09 17:26:22 -07:00
Robert Widmann
18b79ffcfd Resolve a Layering Violation in libBasic
Basic should not be allowed to link Parse, yet it was doing so
to allow Version to provide a constructor that would conveniently
parse a StringRef. This entrypoint also emitted diagnostics, so it
pulled in libAST.

Sink the version parser entrypoint down into Parse where it belongs
and point all the clients to the right place.
2022-09-09 00:21:30 -07:00
Allan Shortlidge
bbf189c8ab AST: Make the versioned variants of #if canImport() more reliable and consistent.
Previously, when evaluating a `#if canImport(Module, _version: 42)` directive the compiler could diagnose and ignore the directive under the following conditions:

- The associated binary module is corrupt/bogus.
- The .tbd for an underlying Clang module is missing a current-version field.

This behavior is surprising when there is a valid `.swiftinterface` available and it only becomes apparent when building against an SDK with an old enough version of the module that the version in the `.swiftinterface` is too low, making this failure easy to miss. Some modules have different versioning systems for their Swift and Clang modules and it can also be intentional for a distributed binary `.swiftmodule` to contain bogus data (to force the compiler to recompile the `.swiftinterface`) so we need to handle both of these cases gracefully and predictably.

Now the compiler will enumerate all module loaders, ask each of them to attempt to parse the module version and then consistently use the parsed version from a single source. The `.swiftinterface` is preferred if present, then the binary module if present, and then finally the `.tbd`. The `.tbd` is still always used exclusively for the `_underlyingVersion` variant of `canImport()`.

Resolves rdar://88723492
2022-09-07 14:18:05 -07:00
Zoe Carver
73ace80a5e Merge pull request #60907 from zoecarver/reference-types-in-namespace
[cxx-interop] Fix foreign reference types with reference counting that live in a namespace.
2022-09-01 15:01:09 -07:00
zoecarver
625760a3a8 [cxx-interop] Fix foreign reference types with reference counting that live in a namespace.
Before this patch we tried to do lookup in the _ObjC module for the retain/release functions. Now we use the clang module that the reference type lives in.
2022-09-01 10:48:36 -07:00
Zoe Carver
445cbd7aaf Merge pull request #60778 from zoecarver/dont-import-reference-type-ctors
[cxx-interop] Don't import constructors of foreign reference types.
2022-08-25 14:56:36 -07:00
zoecarver
8df9fca041 [cxx-interop] Don't import constructors of foreign reference types.
The logic is here for this in the importer, which means the module interface tests make it appear that the behavior is correct, but lazy member lookup still finds the constructors, so this patch fixes that part.
2022-08-25 10:45:12 -07:00
Mishal Shah
91b2abe996 Merge pull request #60531 from apple/pull-request-rebranch
Merge `rebranch` into  `main` to support llvm-project `stable/20220421`
2022-08-15 17:10:56 -07:00
Hamish Knight
76931677a8 Merge pull request #60438 from hamishknight/factor-in-factor-out 2022-08-13 17:21:37 +01:00
Egor Zhdan
109d44c541 [cxx-interop] Emit LValue type in a base subscript assignment expression
This fixes an assertion that tripped when running `member-inline.swift` test with an unrelated patch:
```
type is not an l-value in LHS of assignment: Int32
...
3.	While walking into body of setter for subscript(_:) (in module 'MemberInline')
```
2022-08-12 16:22:48 +01:00
swift-ci
41366ebccd Merge remote-tracking branch 'origin/main' into rebranch 2022-08-12 03:54:16 -07:00