Commit Graph

1896 Commits

Author SHA1 Message Date
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
Egor Zhdan
51a1176d90 [cxx-interop] Clang member lookup should not look into Swift extensions
Calling `NominalTypeDecl::lookupDirect` triggers deserialization of Swift extensions for the type. `ClangRecordMemberLookup` shouldn't assume it is allowed to deserialize Swift extensions for the given C++ type: there might be extensions which reference the module that is currently being imported, which causes circular request dependency errors.
2022-08-08 17:05:25 +01:00
Hamish Knight
6b9bcf3935 [AST] Change DotSyntaxCallExpr to take an Argument base
This allows us to more easily propagate inout
information to it, which will become a necessity
once InOutExpr is removed.
2022-08-08 15:11:00 +01:00
Hamish Knight
ee49794d0f [AST] Introduce Argument::implicitInOut
This will allow us to abstract away the creation
of InOutExpr for bits of code synthesis.
2022-08-08 15:10:51 +01:00
swift-ci
4e2838d9f1 Merge remote-tracking branch 'origin/main' into rebranch 2022-07-23 20:53:19 -07:00
Zoe Carver
bd003bcd7f Merge pull request #59509 from zoecarver/frt-with-ref-counting
[cxx-interop] Add support for reference counting operations on foreign reference types.
2022-07-23 20:51:39 -07:00
zoecarver
a18abb7a49 [cxx-interop] Move definition of debug functions to be accessable in AST. 2022-07-22 10:24:12 -04:00
Arnold Schwaighofer
2c682ae698 Merge remote-tracking branch 'origin/main' into rebranch 2022-07-21 15:15:40 -07:00
zoecarver
13b0a5bc37 [nfc] Clang format changes. 2022-07-21 17:34:36 -04:00
zoecarver
446b2c38ab [cxx-interop] Add source locations to diagnostics for un-importable APIs. 2022-07-21 14:59:27 -04:00
zoecarver
74d76e2888 [cxx-interop] Add diagnostics and validation for retain/release function; require all foreign reference types to provide retain release functions or be immortal. 2022-07-21 12:25:21 -04:00
swift-ci
81f8371ef5 Merge remote-tracking branch 'origin/main' into rebranch 2022-07-21 07:13:25 -07:00
Zoe Carver
0654bca2e7 Merge pull request #60149 from zoecarver/disable-eager-import
[cxx-interop] Add back 'import_as_ref' attr for libswift hosttools.
2022-07-21 10:06:16 -04:00
swift-ci
a5e7bd7dd3 Merge remote-tracking branch 'origin/main' into rebranch 2022-07-20 07:53:55 -07:00
zoecarver
721fc6945d [cxx-interop] Add back 'import_as_ref' attr for libswift hosttools. 2022-07-20 10:12:32 -04:00
Egor Zhdan
d85d2e9e75 [cxx-interop] Synthesize conformances to UnsafeCxxInputIterator
This teaches ClangImporter to synthesize conformances of C++ iterator types to `UnsafeCxxInputIterator` protocol from the `Cxx` module.

We consider a C++ type to be an iterator if it defines a subtype (usually a typedef or a using decl) called `iterator_category` that inherits from `std::input_iterator_tag`.

rdar://96235368
2022-07-20 11:44:25 +01:00
swift-ci
9de631f94f Merge remote-tracking branch 'origin/main' into rebranch 2022-07-19 17:35:57 -07:00
zoecarver
ba7e6e44aa [cxx-interop] Fix predicate to find copy assignment operators. 2022-07-19 16:38:57 -04:00
zoecarver
09384be097 [cxx-interop] Simplify logic in IsSafeUseOfCxxDecl; fix bug for pointer types.
Previously types containing pointers would mark all C++ methods as unsafe.
2022-07-18 17:15:16 -04:00
zoecarver
3498ff9765 [cxx-interop] Remove UnsafeLifetimeOperation record semantic kind.
This makes "owned" the default kind for records that have custom copy constructors and no pointer-members.
2022-07-18 17:15:15 -04:00
zoecarver
ca5fa9aa9b [nfc] Clang format changes. 2022-07-18 17:15:15 -04:00
zoecarver
9d1d03124b [nfc][cxx-interop] Add diagnostics when something cannot be imported. 2022-07-18 17:15:15 -04:00
zoecarver
6acffbbee6 [cxx-interop] Flip the switch: only import safe APIs. 2022-07-18 17:15:15 -04:00
swift-ci
968e43db49 Merge remote-tracking branch 'origin/main' into rebranch 2022-07-08 07:34:44 -07:00