1627 Commits

Author SHA1 Message Date
Sophia Poirier
77e7dc2c19 Merge pull request #69280 from sophiapoirier/globals_strict_concurrency_opt_out_nonisolated_unsafe
nonisolated(unsafe) to opt out of strict concurrency static checking for global variables
2023-10-26 22:34:22 -07:00
Sophia Poirier
4c9a726183 nonisolated(unsafe) to opt out of strict concurrency static checking for global variables 2023-10-26 16:22:28 -07:00
Hiroshi Yamauchi
89db645aad Merge pull request #69375 from hjyamauchi/debugger2
Add a few deserialization recovery paths.
2023-10-26 15:46:54 -07:00
Hiroshi Yamauchi
c4864d2395 Add a few deserialization recovery paths.
This avoids cross-reference modularization error crashes in
lldb/lldb-dap on Windows, seen with our internal app, reported at
https://github.com/apple/swift/issues/69374.
2023-10-24 12:13:26 -07:00
Yuta Saito
4f0e3bf3ea Merge pull request #69207 from kateinoigakukun/yt/cdecl-without-body
Introduce `@extern(c)` to declare C function without Clang module
2023-10-23 12:48:12 -07:00
Harlan Haskins
4ac34a40ea @retroactive conformance syntax and checking (#36068) 2023-10-20 14:27:03 -07:00
Yuta Saito
1008ecc293 [c-interop] Use llvm::Optional instead of std::optional for now
The Attr.h is shared with SwiftCompilerSources through C++ interop and
C++ interop somehow crashes with libc++'s std::optional. So use legacy
llvm::Optional for now.
2023-10-20 15:34:09 +00:00
Yuta Saito
b27fd9a616 [c-interop] Add @_extern(c) attribute to declare C function in Swift 2023-10-20 15:34:08 +00:00
Becca Royal-Gordon
5c8bcfdf52 [NFC] Correct AFD::needsNewVTableEntry()
Serialization depended on a longstanding bug in NeedsNewVTableEntryRequest: For a member of a non-class, it always returned `true`, not `false`. It turns out this was because serialization was conflating the concepts of vtable entries and witness table entries, so it needed NeedsNewVTableEntryRequest to return true for members of protocols. Untangle this logic so that NeedsNewVTableEntryRequest can be given the logical behavior.
2023-10-13 14:33:44 -07:00
Yuta Saito
051bf4dd43 Merge pull request #69107 from kateinoigakukun/yt/extern-wasm-sym
[wasm] Add @_extern(wasm) attribute support
2023-10-12 09:29:13 -07:00
Slava Pestov
28d1455373 AST: Re-implement associated conformance storage in preparation for AssociatedConformanceRequest 2023-10-11 15:04:09 -04:00
Slava Pestov
61730af232 Serialization: Call setAssociatedConformance() from deserialization 2023-10-11 15:04:09 -04:00
Yuta Saito
bd898b0e7e [wasm] add @_extern(wasm) attribute support
This attribute instructs the compiler that this function declaration
should be "import"ed from host environment. It's equivalent of Clang's
`__attribute__((import_module("module"), import_name("field")))`
2023-10-10 22:42:08 +00:00
Holly Borla
3cb9bb89bc [Concurrency] Serialize default argument isolation. 2023-10-04 13:12:11 -07:00
Doug Gregor
51eed19d4b [Typed throws] Type system support for typed throws.
Add the thrown type into the AST representation of function types,
mapping from function type representations and declarations into the
appropriate thrown type. Add tests for serialization, printing, and
basic equivalence of function types that have thrown errors.
2023-09-29 10:51:53 -07:00
Doug Gregor
ef642098f2 [Typed throws] Parsing and AST representation for typed errors
Parse typed throw specifiers as `throws(X)` in every place where there
are effects specified, and record the resulting thrown error type in
the AST except the type system. This includes:
* `FunctionTypeRepr`, for the parsed representation of types
* `AbstractFunctionDecl`, for various function-like declarations
* `ClosureExpr`, for closures
* `ArrowExpr`, for parsing of types within expression context

This also introduces some serialization logic for the thrown error
type of function-like declarations, along with an API to extract the
thrown interface type from one of those declarations, although right
now it will either be `Error` or empty.
2023-09-29 10:51:51 -07:00
Yuta Saito
6d378a3ec3 [wasm] add @_expose(wasm) attribute support
This attribute instructs the compiler that this function declaration
should be "export"ed from this .wasm module. It's equivalent of Clang's
`__attribute__((export_name("name")))`
2023-09-26 14:13:33 +00:00
Saleem Abdulrasool
e1fcb90331 Merge pull request #68525 from hjyamauchi/wrapped-modularization-error-remarks
Emit diagnostics/remarks out of wrapped ModularizationError
2023-09-21 09:43:43 -07:00
Yuta Saito
c5314bd3af Centralize KeyPath accessor calling convention logic to IRGen
KeyPath's getter/setter/hash/equals functions have their own calling
convention, which receives generic arguments and embedded indices from a
given KeyPath argument buffer.
The convention was previously implemented by:
1. Accepting an argument buffer as an UnsafeRawPointer and casting it to
   indices tuple pointer in SIL.
2. Bind generic arguments info from the given argument buffer while emitting
   prologue in IRGen by creating a new forwarding thunk.

This 2-phase lowering approach was not ideal, as it blocked KeyPath
projection optimization [^1], and also required having a target arch
specific signature lowering logic in SIL-level [^2].

This patch centralizes the KeyPath accessor calling convention logic to
IRGen, by introducing `@convention(keypath_accessor_XXX)` convention in
SIL and lowering it in IRGen. This change unblocks the KeyPath projection
optimization while capturing subscript indices, and also makes it easier
to support WebAssembly target.

[^1]: https://github.com/apple/swift/pull/28799
[^2]: https://forums.swift.org/t/wasm-support/16087/21
2023-09-20 11:25:39 -07:00
Hiroshi Yamauchi
c5dc68a348 Emit diagnostics/remarks out of wrapped ModularizationError
The diagnostics/remarks out of the ModularizationError wrapped in a
TypeError (eg. coming from resolveCrossReference) is otherwise just
dropped but could help better understand C/C++ interop issues.
2023-09-18 08:17:58 -07:00
Anthony Latsis
b6be6da277 ASTGen: Translate associated type declarations
Plus tweak `DefaultDefinitionTypeRequest` caching to support querying the
cached type when dumping. This fixes a crash where type computation is
triggered in the dumper before import resolution in `-dump-parse` mode.
2023-09-12 20:37:50 +03:00
Luciano Almeida
499547a3b8 [Serialization] Remove serialization code for initializes() and accesses() attributes 2023-08-22 20:57:30 -03:00
Slava Pestov
f219274e9b AST: Remove generic signature and conditional requirements from BuiltinProtocolConformance 2023-08-09 17:42:57 -04:00
Slava Pestov
7f9a71cd15 AST: Rename ASTContext::getConformance() to getNormalConformance() 2023-08-09 17:42:25 -04:00
Joe Groff
aee071bf4e Introduce an experimental @_rawLayout attribute.
This attribute can be attached to a noncopyable struct to specify that its
storage is raw, meaning the type definition is (with some limitations)
able to do as it pleases with the storage. This provides a basis for
implementing types for things like atomics, locks, and data structures
that use inline storage to store conditionally-initialized values.
The example in `test/Prototypes/UnfairLock.swift` demonstrates the use
of a raw layout type to wrap Darwin's `os_unfair_lock` APIs, allowing
a lock value to be stored inside of classes or other types without
needing a separate allocation, and using the borrow model to enforce
safe access to lock-guarded storage.
2023-07-24 14:28:19 -07:00
John McCall
1a7d44a11d Diagnose attempts to reabstract variadic function types in unimplementable ways. 2023-07-18 13:22:35 -04:00
Pavel Yaskevich
387bcf3187 [Serialization] InitAccessors: Serialization for @storageRestrictions attribute 2023-07-07 10:00:36 -07:00
Holly Borla
7a46466b65 Merge pull request #66967 from hborla/extension-macro
[Macros] Generalize `conformance` macros as `extension` macros
2023-06-29 08:57:04 -07:00
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
Holly Borla
c867c7c917 [Macros] Allow extension macros to specify conformances in the attached
attribute.
2023-06-28 00:42:23 -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
Holly Borla
fc24471ff7 Merge pull request #66532 from hborla/suppress-expansion-in-macro-argument
[Macros] Use source locations to determine whether to suppress macro expansions.
2023-06-12 11:18:25 -07:00
QuietMisdreavus
e45c9df2a3 always use the argNames constructor for macro DeclNames (#66497)
rdar://110179186
2023-06-12 09:10:02 -06:00
Holly Borla
cd752cca22 [NameLookup] Plumb source location arguments through all name lookup APIs.
This source location will be used to determine whether to add a name lookup
option to exclude macro expansions when the name lookup request is constructed.
Currently, the source location argument is unused.
2023-06-11 23:09:47 -07:00
Doug Gregor
a72fb83034 Requestify AbstractStorageDecl::hasStorage().
The `hasStorage()` computation is used in many places to determine the
signatures of other declarations. It currently needs to expand accessor
macros, which causes a number of cyclic references. Provide a
simplified request to determine `hasStorage` without expanding or
resolving macros, breaking a common pattern of cycles when using
macros.

Fixes rdar://109668383.
2023-06-10 08:28:06 -07:00
Alexis Laferrière
b18e7f14a8 Merge pull request #66227 from xymus/recovery-notes
[Serialization] Display contextual notes on deserialization errors and misconfigurations
2023-06-09 12:09:06 -07:00
Alexis Laferrière
9804075549 [Serialization] Show contextual notes on deserialization errors
This PR makes diagnostics on deserialization errors caused by project
configuration more helpful by providing contextual information on the
issue:

- Path to the modules involved (up to 4 modules): the loaded swiftmodule
with the broken outgoing reference, the path to the module where the
decl was expected, the path to the underlying clang module, and the path
to the module where the decl was found. This information should prevent
us from having to ask for a different log with `-Rmodule-loading`.
- Hint to delete the swiftmodule files when the module is
library-evolution enabled.
- Hint that clang settings affect clang modules involved in this
scenario.
- Pointing out when a decl moved between two modules with a similar name
(where one name is a prefix of the other). This is a common issue when
headers are shared between a clang framework's public and private
modules.
- Pointing out layering issues when an SDK module imports a local
module.
- Pointing out Swift language version mismatch which may lead to the
compiler viewing the same clang decls differently when they are modified
by APINotes files.
2023-06-08 09:24:11 -07:00
Alexis Laferrière
b1e0b89cf7 [Serialization] Invert order of diagnostics in forced recovery mode 2023-06-07 16:03:08 -07:00
Alexis Laferrière
1cd4f4ac67 [Serialization] Intro ModularizationError::getSourceLoc
This service provides a path to the loaded swiftmodule file and
synthesizes pseudo-Swift code representing the reference.
2023-06-07 15:34:23 -07:00
Alexis Laferrière
2f03c952c3 [Serialization] ModularizationError keeps full objects
Preserve more information about the context of modularization errors by
replacing the module names with pointers to ModuleDecl and ModuleFile
objects.
2023-06-07 13:01:37 -07:00
Holly Borla
e5f75029de [AST] Add 'initializes' and 'accesses' attributes for init accessor
definite initialization dependencies.
2023-06-06 18:59:13 -07:00
Alexis Laferrière
814ca434f0 Merge pull request #66186 from xymus/force-workaround
[Serialization] Add flag to force unsafe recovery from some xref failures
2023-05-30 08:55:17 -07:00
Alexis Laferrière
261f32cb84 Merge pull request #66139 from xymus/r-module-recovery 2023-05-26 16:00:43 -07:00
Alexis Laferrière
d50f20e4a8 [Serialization] Make a warning the diagnostic about attempting recovery
Use the `attempting forced recovery` diagnostic as main warning to which
we attach other messages as notes. Also mention the flag in the
diagnostic to reinforce that the flag is active.
2023-05-26 15:28:01 -07:00
Alexis Laferrière
642980cbb1 [Serialization] Add flag to force unsafe recovery from some xref failures
Intro a deserialization mode controlled by the flag
`-experimental-force-workaround-broken-modules` to attempt unsafe
recovery from deserialization failures caused by project issues.

The one issue handled at this time is when a type moves from one module
to another. With this new mode the compiler may be able to pick a
matching type in a different module. This is risky to use, but may help
in a pinch for a client to fix and issue in a library over which they
have no control.
2023-05-26 14:36:28 -07:00
Alexis Laferrière
4f66fcfadb [Serialization] Intro -Rmodule-recovery to remark about silent errors
Deserialization recovery silently drops errors and the affected decls.
This can lead to surprises when a function from an imported module
simply disappears without an explanation.

This commit introduces the flag -Rmodule-recovery to report as remarks
some of these previously silently dropped issues. It can be used to
debug project configuration issues.
2023-05-25 10:44:08 -07:00
Alexis Laferrière
65b5f82b52 [Serialization|NFC] Extract some diagnostic logic into diagnoseModularizationError 2023-05-25 10:33:03 -07:00
Slava Pestov
b2bc2c72ec AST: Introduce PackElementType 2023-05-25 11:17:30 -04:00
Alexis Laferrière
a475f4c132 [Serialization|NFC] Intro diagnoseAndConsumeError
Intro the service `diagnoseAndConsumeError` as the ultimate site to drop
deserialization issues we can recover from. It will be used to raise
diagnostics on the issues before dropping them silently.
2023-05-18 14:25:26 -07:00