Commit Graph

18474 Commits

Author SHA1 Message Date
Kuba (Brecka) Mracek
d427696bf9 Allow @_silgen_name to be used on globals and add a @_silgen_name(raw: ...) version that skips mangling (#66540)
Attribute @_silgen_name is today only allowed to be used on functions, this change allows usage on globals as well. The motivation for that is to be able to "forward declare" globals just like it's today possible to do with functions (for the cases where it's not practical or convenient to use a bridging header).

Separately, this change also adds a @_silgen_name(raw: ...) syntax, which simply avoids mangling the name (by using the \01 name prefix that LLVM uses). The motivation for that is to be able to reference the "magic Darwin linker symbols" that can be used to look up section bounds (in the current dylib/module) -- those symbols don't use the underscore prefix in their mangled names.
2023-06-29 08:37:51 -07:00
Rintaro Ishizaki
21d1e2e1dc [Macros] Fix memory leak in PluginSearchOption
Destructor of PluginSearchOption wasn't properly implemented.
Implement special member functions.

rdar://111064325
2023-06-28 20:17:36 -07:00
Doug Gregor
74e5da226d Merge pull request #66997 from DougGregor/observation-shadowing 2023-06-28 17:43:14 -07:00
Becca Royal-Gordon
4331d2ff5d Merge pull request #66966 from beccadax/unconventional-implementation
Match @objcImpl members’ foreign error conventions
2023-06-28 16:04:51 -07:00
Holly Borla
81a1f64811 [Macros] Allow @attached(extension) attributes to be suppressed in
module interfaces.
2023-06-28 14:53:16 -07:00
Doug Gregor
81acd82cf7 [Name lookup] Shadow the _Observation model as we do with other stdlib modules
Fixes rdar://111464071.
2023-06-28 14:30:03 -07:00
Michael Gottesman
bd90e310e1 Merge pull request #66952 from gottesmm/pr-87fcc78991b465d8a15454dc76b66d6f347ddff0
[move-only] Emit an error if we /ever/ partially consume a noncopyable type.
2023-06-28 01:00:40 -07:00
Holly Borla
c867c7c917 [Macros] Allow extension macros to specify conformances in the attached
attribute.
2023-06-28 00:42:23 -07:00
Holly Borla
095542ae96 [Macros] Ban extension macros attached to local types. 2023-06-27 21:42:43 -07:00
Holly Borla
725374e0d8 [Macros] Implement attached extension macros. 2023-06-27 21:22:12 -07:00
Becca Royal-Gordon
a8fbad3551 Match @objcImpl members’ foreign error conventions
ClangImporter can import some methods as throwing that `@objc` cannot generate. For instance, an imported Objective-C method with an error out parameter in an unconventional position can still be imported as throwing no matter its selector, but `@objc` can only generate an error out parameter in an unconventional position if the matching selector part consists of the word `error` or (for the first part) ends with `Error`. Detect and diagnose these situations.

Note that the tests do not cover all of the new diagnostics because some of these conditions (like the `Void` parameter) cause selector mismatches and others (like the owned error parameter) are representable in the compiler but cannot currently be imported. I have chosen to add these diagnostics anyway in case there is a corner case that I haven’t discovered.

Fixes rdar://110100071.
2023-06-27 16:08:49 -07:00
Michael Gottesman
3dde9df468 [move-only] Emit an error if we /ever/ partially consume a noncopyable type.
The reason why I am doing this is that this was not part of the original
evolution proposal (it was called an extension) and after some discussion it was
realized that partial consumption would benefit from discussion on the forums.

rdar://111353459
2023-06-27 13:52:49 -07:00
Steven Wu
bed01ade89 [CAS][DependencyScanning] Don't keep a shared state of common file deps
Unlike `swift-frontend -scan-dependencies` option, when dependency
scanner is used as a library by swift driver, the SwiftScanningService
is shared for multiple driver invocations. It can't keep states (like
common file dependencies) that can change from one invocation to
another.

Instead, the clang/SDK file dependencies are computed from each driver
invocations to avoid out-of-date information when scanning service is
reused.

The test case for a shared Service will be added to swift-driver repo
since there is no tool to test it within swift compiler.
2023-06-27 09:50:26 -07:00
Evan Wilde
250082df25 [NFC] Reformat all the LLVMs
Reformatting everything now that we have `llvm` namespaces. I've
separated this from the main commit to help manage merge-conflicts and
for making it a bit easier to read the mega-patch.
2023-06-27 09:03:52 -07:00
Evan Wilde
f3ff561c6f [NFC] add llvm namespace to Optional and None
This is phase-1 of switching from llvm::Optional to std::optional in the
next rebranch. llvm::Optional was removed from upstream LLVM, so we need
to migrate off rather soon. On Darwin, std::optional, and llvm::Optional
have the same layout, so we don't need to be as concerned about ABI
beyond the name mangling. `llvm::Optional` is only returned from one
function in
```
getStandardTypeSubst(StringRef TypeName,
                     bool allowConcurrencyManglings);
```
It's the return value, so it should not impact the mangling of the
function, and the layout is the same as `std::optional`, so it should be
mostly okay. This function doesn't appear to have users, and the ABI was
already broken 2 years ago for concurrency and no one seemed to notice
so this should be "okay".

I'm doing the migration incrementally so that folks working on main can
cherry-pick back to the release/5.9 branch. Once 5.9 is done and locked
away, then we can go through and finish the replacement. Since `None`
and `Optional` show up in contexts where they are not `llvm::None` and
`llvm::Optional`, I'm preparing the work now by going through and
removing the namespace unwrapping and making the `llvm` namespace
explicit. This should make it fairly mechanical to go through and
replace llvm::Optional with std::optional, and llvm::None with
std::nullopt. It's also a change that can be brought onto the
release/5.9 with minimal impact. This should be an NFC change.
2023-06-27 09:03:52 -07:00
swift-ci
44ab03a90b Merge pull request #66871 from kavon/generics-error-noncopyable
Be more specific than "noncopyable type T can't be used with generics yet"
2023-06-26 18:32:26 -07:00
Doug Gregor
6d58bce230 Merge pull request #66928 from DougGregor/unify-call-isolation-checking 2023-06-26 18:21:47 -07:00
Kavon Farvardin
8072eef926 describe noncopyables in parameter packs 2023-06-26 16:55:06 -07:00
Kavon Farvardin
485bdc7918 describe more cases of noncopyable in a tuple; also improve existing message a bit. 2023-06-26 16:55:06 -07:00
Kavon Farvardin
c40985dfb3 describe how generic parameters implicitly require Copyable 2023-06-26 16:55:06 -07:00
Rintaro Ishizaki
d230a1a49e Merge pull request #66918 from rintaro/macros-plugins-collappsed-attached-result
[Macros] Attached macro expansions return single string
2023-06-26 16:04:45 -07:00
Steven Wu
a6714bcb55 Merge pull request #66887 from cachemeifyoucan/eng/PR-cas-option-updates
Update CAS/Caching options as final candidate.
2023-06-26 15:47:29 -07:00
Doug Gregor
d78a5edb99 Handle all isolation checking for function calls in one place
Isolation checking for calls had two separate implementation places:
one that looked at the declaration being called (for member
declarations) and one that worked on the actual call expression. Unify
on the latter implementation, which is more general and has access to
the specific call arguments. Improve diagnostics here somewher so we
don't regress in that area.

This refactoring shouldn't change the actual semantics, but it makes
upcoming semantic changes easier.
2023-06-26 13:39:56 -07:00
Rintaro Ishizaki
eefe9dc7ef [Macros] Attached macro expansions return single string
* Move collapse(expansions:for:attachedTo:) to SwiftSyntaxMacroExpansion
* SwiftSyntaxMacroExpansion.expandAttachedMacro() now perform collapsing
* SwiftSyntaxMacroExpansion.expandAttachedMacroWithoutCollapsing()
  to keep old behavior
* IPC request 'getCapability' now sends the host protocol version
* Unified IPC response 'macroExpansionResult' that returns single string
  for both 'expandFreestandingMacro' and 'expandAttachedMacro'
* Compiler accepts old 'expandFreestandingMacroResult' and
  'expandAttachedMacroResult' to keep compatibility
* Plugins check the compiler's protcol version to see if it suppports
  'macroExpansionResult', and fall back to old behavior if necessary
2023-06-26 11:04:59 -07:00
Steven Wu
744e01ea47 [CAS] Allow SwiftDependencyScanningService be shared
When the CASOptions are the same, SwiftDependencyScanningService can be
shared with multiple swift driver invocation for scanning.
2023-06-26 10:34:26 -07:00
Steven Wu
2b7d38dc16 [CAS] Improve swift cas options
Using the same CASOption from clang to communicate CAS configurations so
it is easier to exchange CAS configuration between them.
2023-06-26 10:34:26 -07:00
Xi Ge
0a3dadff90 Sema: temporarily downgrade backdeployed_opaque_result_not_supported to a warning
rdar://111334653
2023-06-26 10:05:33 -07:00
Kabir Oberai
c499dd22ee [Sema] Improve SerialExecutor diagnostics 2023-06-26 06:36:07 -04:00
Kavon Farvardin
66bf3c03fc describe illegal casts to existentials 2023-06-23 20:15:01 -07:00
Doug Gregor
a44c77d098 Merge pull request #66867 from DougGregor/requestify-member-init-properties 2023-06-23 17:37:38 -07:00
Doug Gregor
e89fdd3084 Requestify the computation of the list of memberwise initialized properties.
Fixes rdar://110776763, a case where initialized stored properties
introduced by peer macros weren't working alongside declared stored
properties.
2023-06-23 11:34:52 -07:00
Keith Smiley
e9ff334778 Fix missing indexing data with overloaded type (#65729)
When you have a type that's ambiguous because it's defined in 2 imported
modules, but you don't have to disambiguate by using the module name,
previously no index references were produced. Now most are for the
common case, but notably nested type constructors and generics still
aren't emitted, partially because of https://github.com/apple/swift/issues/65726

Fixes: https://github.com/apple/swift/issues/64598
2023-06-23 09:58:17 -07:00
Kavon Farvardin
e6312058ec add more specific versions of the noncopyable generics error diagnostic 2023-06-22 15:12:20 -07:00
Egor Zhdan
e064d23d74 Merge pull request #66764 from apple/egorzhdan/cxx-set-insert
[cxx-interop] Allow inserting elements into `std::set` from Swift
2023-06-22 15:26:57 +01:00
Michael Gottesman
80bb497275 Merge pull request #66833 from gottesmm/pr-e19b18739384c4a73467c39d7034ec6efcb6f466
[move-only] Ban resilient noncopyable types.
2023-06-21 22:31:19 -07:00
Michael Gottesman
d0938a906f [move-only] Ban resilient noncopyable types.
One can still in resilient frameworks have noncopyable frozen types.

This means that one cannot make a noncopyable:

1. Full resilient public type.
2. @usableFromInline type.

NOTE: One can still use a frozen noncopyable type as a usableFromInline class
field. I validated in the attached tests that we get the correct code
generation.

I also eliminated a small bug in TypeCheckDeclPrimary where we weren't using a
requestified attr check and instead were checking directly.

rdar://111125845
2023-06-21 16:57:44 -07:00
swift-ci
7c3917c0d3 Merge pull request #66818 from kavon/noncopyable-and-raw-error
emit error when a noncopyable enum has a raw type
2023-06-21 13:56:05 -07:00
Kavon Farvardin
79332c19b0 emit error when a noncopyable enum has a raw type
previously I was allowing these because I thought there was
some representational difference if the enum is raw. it
turns out that a raw enum is only useful if you synthesize
conformance to RawRepresentable. since I disabled that
synthesis it's kind of silly to still allow the raw type
to be written at all.

rdar://110539937
2023-06-21 11:21:49 -07:00
Egor Zhdan
84a2f33424 Merge pull request #66749 from apple/egorzhdan/cxx-template-subst-crash
[cxx-interop] Avoid crashing when template substitution fails
2023-06-21 13:51:22 +01:00
Rintaro Ishizaki
a22b71fb75 Merge pull request #66722 from rintaro/macros-pluginloader-table
[Macros] Create plugin search lookup table.
2023-06-20 16:43:10 -07:00
Joshua Turcotti
b63a10698d Merge pull request #66640 from JTurcotti/protocol-variance
Super-level sendable checking for function parameters in overrides and conformances
2023-06-20 10:43:46 -07:00
Joe Groff
c7d6821f4f Merge pull request #66726 from jckarter/disallow-dynamic-move-only-definite-init
DefiniteInitialization: Error when noncopyable types are conditionally initialized.
2023-06-20 09:57:52 -07:00
Egor Zhdan
b79b65c056 [cxx-interop] Allow inserting elements into std::set from Swift
`std::set::insert` isn't exposed into Swift, because it returns an instance of an unsafe type.

This change adds a Swift overload of `insert` for `std::set` and `std::unordered_set` that has the return type identical to `Swift.Set.insert`: a tuple of `(inserted: Bool, memberAfterInsert: Element)`.

rdar://111036912
2023-06-20 16:56:54 +01:00
Egor Zhdan
4a1afa9bd3 [cxx-interop] Avoid crashing when template substitution fails
This code used to crash the compiler:

    var s = std.string("hi")
    s.append("foo")

`append` in this case resolves to a templated C++ method that accepts `std::string_view`, while we tried passing a Swift String to it as a parameter.

rdar://107018724
2023-06-19 15:58:41 +01:00
Rauhul Varma
2a7895757c Merge pull request #66072 from apple/platform-ccc
Add frontend flag for explicitly setting ccc
2023-06-18 18:32:34 -07:00
Adrian Prantl
c2f164d7ac Merge pull request #66692 from adrian-prantl/110841130
SILDebugScopes: Don't ignore ConditionalClauseInitializerScope.
2023-06-17 10:31:56 -07:00
swift-ci
670964870e Merge pull request #66713 from kavon/require-switch-consume
require `consume x` for noncopyable pattern bindings since they're consuming
2023-06-16 21:07:38 -07:00
Rintaro Ishizaki
b8a073cb9f [Macros] Create plugin search lookup table.
Iterating all options and potential file system access is not great for
every plugin lookup request. Instead, lazily create a single lookup table
keyed by module name.
2023-06-16 18:17:07 -07:00
Kavon Farvardin
36451efb55 require consume x for noncopyable pattern bindings since they're consuming
this was staged in as a warning initially but it was intended to be
an error if it is not written so that we can move to a world where
these pattern matches are done as a borrowing operation instead.

rdar://110908714
2023-06-16 17:18:44 -07:00
Joe Groff
40ad5aaffc DefiniteInitialization: Error when noncopyable types are conditionally initialized.
This leads to unhandled complications in the move-only checker that were causing miscompiles.
We can disallow this for now. rdar://109695770
2023-06-16 17:13:38 -07:00