Commit Graph

2441 Commits

Author SHA1 Message Date
Hamish Knight
5aab237468 [Profiler] Emit skipped regions for inactive #if branches
For any `#if` blocks in the function we're emitting,
emit skipped ranges for the inactive clauses, including
the syntax for the `#if` itself, since that should
not be considered executable code.

rdar://116860865
2023-11-14 20:41:35 +00:00
Hamish Knight
d31f76853a [SIL] Introduce skipped coverage ranges
Introduce a skipped region kind, printed using
a `skipped` keyword.
2023-11-14 20:41:35 +00:00
nate-chandler
88b3c57929 Merge pull request #69769 from nate-chandler/rdar116877403
[Diagnostics] Allow multiple non-custom _effects.
2023-11-13 07:03:33 -08:00
Allan Shortlidge
da3af768e6 SIL: Fix a crash during access path verification.
The access path verification optimizer pass calls
`getStaticallyInitializedVariable()`, which was written assuming that the given
`SILFunction` would always have a valid return basic block. When the
`-unavailable-decl-optimization=stub` option is passed to the frontend, though,
any function generated for a declaration marked `@available(*, unavailable)` is
rewritten to trap by calling a function that returns `Never`. Therefore the
rewritten functions do not have return blocks and passing these functions to
`getStaticallyInitializedVariable()` would result in the compiler invoking
undefined behavior.

Resolves rdar://118281508
2023-11-12 09:47:49 -08:00
Doug Gregor
f9a576451a Merge pull request #69767 from DougGregor/typed-throws-closure-reabstract-fix
[Typed throws] Properly reabstract closure types with originally-indirect errors
2023-11-09 22:34:31 -08:00
Nate Chandler
648cede13b [Diagnostics] Allow multiple non-custom _effects.
Adjust `SILFunctionBuilder` to allow distinct non-custom effects and to
interpret such "conflicting" guarantees to provide the strongest
guarantee. For example, annotating a function both `@_effects(readnone)`
and `@_effects(releasenone)` is equivalent to only annotating it
`@_effects(readnone)`.

First step to reapplying https://github.com/apple/swift/pull/68285 .

rdar://118216287
2023-11-09 21:39:43 -08:00
Doug Gregor
bcbc1da00a [Typed throws] Properly reabstract closure types with originally-indirect errors
Thank you, John McCall for debugging this with me!
2023-11-09 18:25:37 -08:00
Doug Gregor
0042201f1f Merge pull request #69700 from DougGregor/typed-throws-reabstraction-thunks
[Typed throws] Implement reabstraction thunks that change the error
2023-11-08 21:01:49 -08:00
Doug Gregor
927e2420a0 [Typed throws] Handle closure reabstraction
This peephole optimization in SILGen requires us to use the thrown
error for the context of a closure type rather than the thrown error
for the closure AST node itself.
2023-11-08 12:08:01 -08:00
Michael Gottesman
48b4ca0b24 Merge pull request #69686 from gottesmm/rdar117880194
[region-isolation] When assigning RValues into memory, use tuple_addr_constructor instead of doing it in pieces.
2023-11-07 20:15:58 -08:00
Kavon Farvardin
ab6734aa04 Merge pull request #69590 from kavon/check-if-copyable-inferred
[NoncopyableGenerics] Synthesize conditional conformances
2023-11-07 18:19:23 -08:00
Michael Gottesman
b1f69030fc [region-isolation] When assigning RValues into memory, use tuple_addr_constructor instead of doing it in pieces.
I also included changes to the rest of the SIL optimizer pipeline to ensure that
the part of the optimizer pipeline before we lower tuple_addr_constructor (which
is right after we run TransferNonSendable) work as before.

The reason why I am doing this is that this ensures that diagnostic passes can
tell the difference in between:

```
x = (a, b, c)
```

and

```
x.0 = a
x.1 = b
x.2 = c
```

This is important for things like TransferNonSendable where assigning over the
entire tuple element is treated differently from if one were to initialize it in
pieces using projections.

rdar://117880194
2023-11-07 15:38:33 -08:00
Doug Gregor
251bbbbda0 Fix the definition of SILFunctionConventions::isTypedError()
This needs to identify typed errors that aren't passed indirectly at
the SIL level.
2023-11-07 13:42:30 -08:00
Doug Gregor
0ba605a4b9 [Typed throws] Implement reabstraction thunks that change the error
Introduce SILGen support for reabstractions thunks that change the
error, between indirect and direct errors as well as conversions
amongst error types (e.g., from concrete to `any Error`).
2023-11-07 11:39:56 -08:00
Yuta Saito
79b3d2d626 Add underscore prefix to extern attribute
It's already guarded by a feature flag, but it would be nice to signal
users that it's not stable yet by adding an underscore prefix.
2023-11-07 02:01:02 +00:00
Kavon Farvardin
a9c64baaa3 [Sema] refactor TypeDecl::isNoncopyable
In preparation for reporting whether the inverse marking on a TypeDecl
was inferred instead of explicit.
2023-11-06 15:40:12 -08:00
Michael Gottesman
6a65c7829e [sil] Add tuple_addr_constructor an instruction that can be used to initial a tuple in memory from individual address and object components.
This commit just introduces the instruction. In a subsequent commit, I am going
to add support to SILGen to emit this. This ensures that when we assign into a
tuple var we initialize it with one instruction instead of doing it in pieces.
The problem with doing it in pieces is that when one is emitting diagnostics it
looks semantically like SILGen actually is emitting code for initializing in
pieces which could be an error.
2023-11-06 15:32:05 -08:00
Doug Gregor
53c8e84a1f [Typed throws] Handle throw_addr in the same places as throw. 2023-11-03 19:02:58 -07:00
swift-ci
6532b23b3e Merge pull request #69591 from kavon/noncopyable-generics-pt3
[NoncopyableGenerics] Basic end-to-end testing (without stdlib).
2023-11-03 13:06:43 -07:00
Kavon Farvardin
3f93370daf [SIL] improve SILType::isMoveOnly
We were missing some of the "artificial" types in the
TypeBase::isNoncopyable implementation. Rather than add them to the
frontend, I just check for those special SIL-only types in
SILType::isMoveOnly.

resolves rdar://117282929
2023-11-01 16:49:35 -07:00
Kavon Farvardin
d75d6539b8 [SIL] fix AllocBoxInst's isMoveOnly check 2023-11-01 16:49:35 -07:00
Slava Pestov
05ccd9734c SIL: Introduce ThrowAddrInst 2023-10-31 16:58:54 -04:00
Hamish Knight
5853304da1 Remove BridgingUtils.h headers
These are now empty, and it seems like generally
we ought to prefer putting the bridging logic on
the BridgedXXX wrappers.
2023-10-30 23:50:00 +00:00
Varun Dhand
528894e8ca fix: typo in SILDeclRef.cpp from intializers to initializers 2023-10-30 23:12:01 +05:30
Slava Pestov
d430d12b2c SIL: Don't destructure tuples in AbstractionPattern::getErrorConvention()
Tuples don't conform to Error anyway so it's moot, but if they ever do
we won't be destructuring them into multiple indirect error results.
2023-10-27 21:15:06 -04:00
Slava Pestov
ad5697778e Merge pull request #69430 from slavapestov/silgen-typed-throws-wip
Preliminary SILGen support for address-only typed throws
2023-10-27 21:00:51 -04:00
Slava Pestov
eac491ccd2 SIL: Fix memory lifetime verifier check for the thrown error result 2023-10-27 17:37:43 -04:00
Slava Pestov
b84df92b70 SIL: Type lowering support for indirect error results 2023-10-27 17:37:43 -04:00
Slava Pestov
1d05c356c4 SIL: AbstractionPattern support for typed throws 2023-10-27 17:37:43 -04:00
Michael Gottesman
b99a4f89d9 Merge pull request #69453 from gottesmm/pr-2fef04440592fb93039bb726507eb8897c2b8e47
[region-isolation] Make sure that we treat Sendable functions as Sendable
2023-10-27 14:37:06 -07:00
Ellie Shin
cbc050a9d8 Merge pull request #69414 from apple/es-tbd
Emit default arg for a package func during silgen
2023-10-27 12:14:24 -07:00
Michael Gottesman
dc8e4794a8 [region-isolation] Make sure that we treat Sendable functions as Sendable.
The reason for this issue is that we were originally checking in our NonSendable
type oracle just if a type conformed to Sendable. But function types do not
conform to protocols, so this would fail for protocols. To fix this, I added
some helper methods to call swift::isSendableType on SILType, called that in our
oracle, and then I added support in swift::isSendableType for both
SILFunctionType and AnyFunctionType so that we correctly handle them depending
on their sendability.

There was also a question if we also handled function conversions correctly. I
added a test case that shows that we do not error in either of the cases.

Another nice aspect of this change is that we no longer need to stash a pointer
to a looked up Sendable protocol to perform the check since that just happens
naturally inside SILType::isSendable() when it calls isSendableType. This is a
better separation of concerns.

rdar://116525224
2023-10-27 11:13:35 -07:00
Saleem Abdulrasool
1cb0099901 IRGen,Serialization: account for transitive dynamic linkage
When building complex projects, there may cases of static libraries
which expose `@inlinable` functions which reference functions from
dynamically linked dependencies. In such a case, we need to consider the
provenance of the `function_ref` when determining the DLL storage for
linkage. We would previously use the deserialised metadata on the
`SILFunction` as there are entities where the `DeclContext` may not be
deserialised. However, this leaves us in a state where we are unable to
determine the actual provenance correctly in some cases. By simply
accessing the parent module directly from the `SILFunction` we ensure
that we properly identify the origin of the function allowing us to
query the DLL storage property. This further allows us to remove the
extra storage required for whether the `SILFunction` is statically
linked.
2023-10-26 18:03:45 -07:00
Ellie Shin
9311783616 If a package func has a default arg, its symbol is not generated
in TBD, causing a linker error. This is because the default arg
is not generated during silgen. This PR adds a check to make sure
it's represented by SILDeclRef and its linkage emitted.

Resolves rdar://116184295
2023-10-26 11:50:06 -07:00
Arnold Schwaighofer
235c27b749 Don't keep generic versions of PtrAuth functions alive
We don't support generating code for ptrauth builtins with generic
inputs (or non-constant inputs). We rely on specialization/inlining for
such code to work.

After a recent commit (#68843 ) code in IRGen keeps internal unreferenced
functions alive for debugging purposes.

This is a problem for the generic functions in PtrAuth.swift using
ptrauth builtins.

Opt out of this new behavior by sprinkling some pixie dust.

Fixes debug swift standard library builds targeting arm64e.

rdar://117411740
2023-10-24 11:52:47 -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
Mishal Shah
aa6a588f45 Merge pull request #69163 from apple/rebranch
Merge `rebranch` into `main` to support `stable/20230725` llvm-project branch
2023-10-23 09:26:37 -07:00
Ben Barham
83620827fb [rebranch] Move SILBuilder::substituteAnonymousArgs out of the header
An attempt to fix an undefined reference to `std::_Construct` that we're
hitting on Ubuntu 22.04 and UBI 9.
2023-10-20 11:15:21 -07:00
Andrew Trick
f1bec99705 Merge pull request #69250 from atrick/fix-deserialize-access
Fix deserialization to avoid invoking a pass N times per function
2023-10-20 11:02:25 -07:00
Yuta Saito
69479933df [c-interop] Rename @_extern to @extern
Now the feature is gated by experimental feature flag.
It's not shipped in any language release, so this rename should be fine.
2023-10-20 17:37:43 +00:00
Yuta Saito
7767f6d272 [c-interop] Ban non-ASCII identifiers in @_extern(c) conservatively 2023-10-20 15:34:09 +00:00
Yuta Saito
7a75f5d2e2 [c-interop] Use Swift base name for @_extern(c) without explicit name 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
Ben Barham
360c5d8465 Merge remote-tracking branch 'origin/main' into 20231019-merge-main
Conflicts:
  - `lib/AST/TypeCheckRequests.cpp` renamed `isMoveOnly` which requires
    a static_cast on rebranch because `Optional` is now a `std::optional`.
2023-10-19 16:16:23 -07:00
Kavon Farvardin
148897ac1a [nfc] refactor ValueDecl::isMoveOnly
I've renamed the method to `TypeDecl::isNoncopyable`, because the query
doesn't make sense for many other kinds of `ValueDecl`'s beyond the
`TypeDecl`'s. In fact, it looks like no one was relying on that anyway.

Thus, we now have a distinction where in Sema, you ask whether
a `Type` or `TypeDecl` is "Noncopyable". But within SIL, we still
preserve the notion of "move-only" since there is additionally the
move-only type wrapper for types that otherwise support copying.
2023-10-18 13:45:50 -07:00
Andrew Trick
ef29250dcb Fix deserialization to avoid invoking a pass N times per function
Deserialization is calling AccessMarkerElimination repeatedly on the
same function.

The bug was introduced here:

commit 872bf40e17
Date:   Mon Aug 13 10:24:20 2018

    [sil-optimizer] Centralize how we send out serialization notifications.

Where the code that uniques the deserialization callbacks was simply
removed!

As a result, this pass was being invoked a number of times equal to
the number of functions in the module *multiplied* by the number of
functions being deserialized.

Fixes rdar://117141871 (Building spends most of its time in
AccessMarkerElimination)
2023-10-18 10:32:04 -07:00
Andrew Trick
681a2b72e0 Merge pull request #69164 from atrick/nonescapable_attr
Add a temporary @_nonEscapable and @_hasUnsafeNonEscapableResult attribute
2023-10-17 21:39:10 -07:00
Andrew Trick
ca7253a25c Add the @_unsafeNonEscapableResult function
This will allow NonEscapable types to be returned from a function.
2023-10-17 12:44:31 -07:00
Andrew Trick
045253e614 Add SILType::isEscapable 2023-10-17 12:44:31 -07:00
Andrew Trick
fca92e4ec6 Add a temporary @_nonEscapable attribute
For testing compiler support until we have the ~Escapable syntax.
2023-10-17 12:44:24 -07:00