Commit Graph

6754 Commits

Author SHA1 Message Date
Andrew Trick
86365cdbd1 Merge pull request #69476 from atrick/fix-conversion-lifetime
Fix SILGen to emit fix_lifetime for inout-to-pointer conversion.
2023-11-01 17:36:27 -07:00
Andrew Trick
966df3585c Fix SILGen to emit fix_lifetime for inout-to-pointer conversion.
This fixes use-after-free miscompilation bugs that can occur when a
lifetime-optimized standard library type, like Dictionary or String is
converted to an UnsafePointer using implicit inout-to-pointer
conversion:

func ptrToDictionary(_: UnsafePointer<Dictionary<K, V>>) {}

func testDictionary() {
  var d: Dictionary = ...
  ptrToDictionary(&d)
}

func ptrToString(_: UnsafePointer<String>) {}

func testString() {
  var s: String = ...
  ptrToString(&s)
}

Address to pointer conversion must always be guarded by either a
mark_dependence or a fix_lifetime. Use fix_lifetime for call emission
in SILGen to limit the optimization impact to the narrow scope of the
pointer conversion.

This could negatively impact performance simply because SIL does not
provide a way to scope pointer conversion. fix_lifetime is
unnecessarilly conservative and prevents the elimination of dead
allocations.

rdar://117807309 (Fix SILGen to emit fix_lifetime for
inout-to-pointer conversion)
2023-11-01 11:34:25 -07:00
Meghana Gupta
192bb2eed2 Merge pull request #69450 from meg-gupta/uninarrayfix
Add a mark_dependence while emitting SIL for uninitialized array allocation
2023-10-31 22:07:14 -07:00
Slava Pestov
204bb0c2f2 SILGen: Lowering 'try?' and 'try!' with typed throws 2023-10-31 22:55:48 -04:00
Slava Pestov
079c5c4a1c SILGen: Support for 'throw' and 'try_apply' with indirect error result 2023-10-31 16:58:54 -04:00
Slava Pestov
2f2ee61da3 SILGen: Fix crash when emitting throwing closure as opaque 2023-10-30 17:11:28 -04:00
Kavon Farvardin
29acda5136 Merge pull request #69406 from kavon/noncopyable-generics-pt2
[NoncopyableGenerics] handle `~Copyable` in `where`, `some`, and compositions.
2023-10-28 22:36:22 -07: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
Kavon Farvardin
a92181827a [Sema] handle inverses everywhere
Previously, inverses were only accounted-for in inheritance clauses.

This batch of changes handles inverses appearing in other places, like:

- Protocol compositions
- `some ~Copyable`
- where clauses

with proper attribution of default requirements in their absence.
2023-10-27 15:01:10 -07:00
Slava Pestov
581776b997 SILGen: Emit indirect error result argument 2023-10-27 17:37:43 -04:00
Slava Pestov
4ed2dc4428 SILGen: Don't use CanType() on a type that might be a sugared type 2023-10-27 17:37:43 -04:00
Meghana Gupta
08cd370117 Add mark_dependence to represent lifetime dependence in array allocation 2023-10-27 14:19:21 -07:00
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
Allan Shortlidge
d0e2ca4e0c SILGen: Skip emitting distributed thunks for skipped accessors.
Generalizes https://github.com/apple/swift/pull/68917 to cover accessors in
addition to methods.

Resolves rdar://117226130
2023-10-26 16:32:51 -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
Holly Borla
cbdb892fe5 Merge pull request #69391 from hborla/isolated-default-value-revision
[Concurrency] Allow isolated default arguments to be used from across isolation boundaries.
2023-10-26 09:33:25 -07:00
Allan Shortlidge
1be7745699 SILGen: Remove unnecessary assertion when emitting conformances.
Asserting that a conformance is "complete" before emitting its witness table
during SILGen is unnecessary since the typechecking request architecture
already handles checking a conformance lazily as needed.

Resolves rdar://117439077
2023-10-25 11:17:22 -07:00
Allan Shortlidge
114a46aa88 SILGen: Handle nested functions in shouldSkipDecl().
Functions that are nested within other functions are not exportable to clients
since they cannot be called directly by clients. However, they need still to be
emitted during SILGen when -experimental-skip-non-exportable-decls is specified
so walk the decl context hierarchy when determining whether to skip emitting a
function.

Resolves rdar://117440503
2023-10-24 22:58:51 -07:00
Holly Borla
49d6399a88 [Concurrency] Allow isolated default arguments to be used from across isolation
boundaries.
2023-10-24 22:54:22 -07: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
Joe Groff
251becbbdd Merge pull request #69263 from jckarter/move-only-loadable-to-address-reabstraction
Move only loadable to address reabstraction
2023-10-19 09:33:36 -07:00
Joe Groff
f3ef4322f5 SILGen: Avoid redundant materialization when reabstracting a property base from loadable to in-memory.
The code here was materializing the value in this case, but then re-loading it, which is unnecessary
since call emission will materialize the value to match the callee's calling convention already.
It does look like a copy into formal evaluation scope is necessary to get the correct lifetimes
in some circumstances. The move-only checker doesn't like any additional copies at all because
it thinks they're consumes, so only borrow in the case where the value is move-only.
2023-10-18 18:03:25 -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
Joe Groff
1b5796ce90 SILGen: Treat projections from non-implicitly-copyable parameters as borrow bases. 2023-10-17 13:42:55 -07:00
swift-ci
d432ad3f51 Merge remote-tracking branch 'origin/main' into rebranch 2023-10-12 10:54:41 -07:00
Allan Shortlidge
b8bddb58fe SILGen: Honor -experimental-skip-non-exportable-decls.
When the flag is specified, only emit SIL for declarations that are exposed to
clients.

Resolves rdar://116774565
2023-10-11 22:41:31 -07:00
Allan Shortlidge
17f6f4e7a4 SILGen: Introduce and adopt SILGenModule::shouldSkipDecl().
This method centralizes the logic for determining whether to skip emission of
SIL associated with a Decl.
2023-10-11 22:41:30 -07:00
swift-ci
049f39ca15 Merge remote-tracking branch 'origin/main' into rebranch 2023-10-10 21:30:38 -07:00
Doug Gregor
a14f280104 Merge pull request #69087 from DougGregor/typed-throws-conformances 2023-10-10 21:16:44 -07:00
swift-ci
46c67c20cf Merge remote-tracking branch 'origin/main' into rebranch 2023-10-10 02:35:18 -07:00
Doug Gregor
7d7c726efe [Typed throws] Teach associated type inference to infer from thrown errors
When comparing a requirement that uses typed throws and uses an
associated type for the thrown error type against a potential witness,
infer the associated type from the thrown error of the
witness---whether explicitly specified, untyped throws (`any Error`),
or non-throwing (`Never`).
2023-10-09 21:21:21 -07:00
Hamish Knight
ccd32eb452 NFC: Remove ClangModuleLoader.h include from ExtInfo.h
This was unnecessarily pulling in a whole bunch
of Clang headers when all was needed was a
forward declaration.
2023-10-09 20:29:03 +01:00
swift-ci
ae3c263d08 Merge remote-tracking branch 'origin/main' into rebranch 2023-10-05 05:15:28 -07:00
Doug Gregor
698cfb9559 Merge pull request #68976 from DougGregor/typed-do-catch
[Typed throws] Compute and use the caught error type of a do..catch block
2023-10-05 05:06:27 -07:00
swift-ci
1ba3021ab0 Merge remote-tracking branch 'origin/main' into rebranch 2023-10-04 20:25:08 -07:00
Holly Borla
f7a8bc2e04 Merge pull request #68794 from hborla/isolated-initializer-expressions
[Concurrency] Allow default arguments to require actor isolation.
2023-10-04 20:10:43 -07:00
swift-ci
042e9df19d Merge remote-tracking branch 'origin/main' into rebranch 2023-10-04 18:22:41 -07:00
Doug Gregor
2d4e8fda3e [Typed throws] Compute and use the caught error type of a do..catch block.
The type that is caught by the `catch` clauses in a `do..catch` block is
determined by the union of the thrown error types in the `do`
statement. Compute this type and use it for the catch clauses. This
does several things at once:

* Makes the type of the implicit `error` be a more-specific concrete
type when all throwing sites throw that same type
* When there's a concrete type for the error, one can use patterns
like `.cancelled`
* Check that this error type can be rethrown in the current context
* Verify that SIL generation involving do..catch with typed errors
doesn't require any existentials.
2023-10-04 17:20:36 -07:00
nate-chandler
a9e03df58c Revert "[Diagnostics] Require explicit releasenone." 2023-10-04 14:19:15 -07:00
Holly Borla
3cb9bb89bc [Concurrency] Serialize default argument isolation. 2023-10-04 13:12:11 -07:00
Holly Borla
7f119474ac [Concurrency] Allow default initializer expressions for stored instance
properties to require actor isolation.

Member initializer expressions are only used in a constructor with
matching actor isolation. If the isolation prohibits the member
initializer from being evaluated synchronously (or propagating required
isolation through closure bodies), then the default value cannot be used
and the member must be explicitly initialized in the constructor.

Member initializer expressions are also used as default arguments for the
memberwise initializer, and the same rules for default argument isolation
apply.
2023-10-04 13:12:11 -07:00
swift-ci
799c35664c Merge remote-tracking branch 'origin/main' into rebranch 2023-10-04 07:36:02 -07:00
Joe Groff
b4f536927a Disable destructuring initializations in struct let stored properties.
This looks like it was never properly implemented, since when we generate the
memberwise initializer for the struct in SILGen, it incorrectly tries to apply
the entire initializer expression to each variable binding in the pattern,
rather than destructuring the result and pattern-matching it to the variables.
Since it never worked it doesn't look like anyone is using this, so let's
put up an error saying it's unsupported until we can implement it properly.
Add `StructLetDestructuring` as an experimental feature flag so that tests around
the feature for things like module interface printing can still work.
2023-10-03 13:24:39 -07:00
swift-ci
9b7014c86c Merge remote-tracking branch 'origin/main' into rebranch 2023-10-02 15:53:26 -07:00
Allan Shortlidge
fa4a0ab4d1 Merge pull request #68917 from tshortli/skipped-distributed-actor-thunk
SILGen: Skip emitting distributed thunks for skipped functions
2023-10-02 15:44:06 -07:00
Allan Shortlidge
a200333a2d SILGen: Skip emitting distributed thunks for skipped functions. 2023-10-02 11:04:07 -07:00
swift-ci
f0bd604d71 Merge remote-tracking branch 'origin/main' into rebranch 2023-10-02 09:33:57 -07:00
Pavel Yaskevich
829694fec1 Merge pull request #68875 from xedin/issue-67827-with-multiple-stored
[SILGen/DI] InitAccessors: Fix handling of `nonmutating set` when type has other stored properties
2023-10-02 09:23:25 -07:00
swift-ci
06f9a8a703 Merge remote-tracking branch 'origin/main' into rebranch 2023-09-30 11:33:40 -07:00
Doug Gregor
581b9d8a95 Merge pull request #68629 from DougGregor/typed-throws
Typed throws
2023-09-30 11:18:41 -07:00