Commit Graph

370 Commits

Author SHA1 Message Date
Michael Gottesman
3641050675 [region-isolation] Wordsmith some diagnostics.
I tried to make them shorter and standardized on "; later accesses could race"
as the mark on a diagnostic that the problem was that a race was occuring
(before we had several small different variations).
2024-01-19 15:38:41 -08:00
Michael Gottesman
eb573092d1 [region-isolation] Teach the checker that a use of a local value after being strongly transferred is an error.
Before the previous patch, we were just getting lucky on macOS due to UB. Now
that the UB is fixed, we correctly crash without this commit since we were not
pattern matching the simple case of a local value that was transferred and used
later.
2024-01-18 13:20:28 -08:00
Michael Gottesman
9303c40162 [region-isolation] Teach region isolation that assigning into a transferring parameter is a transfer of the value.
The specific semantics is if we assign into a transferring parameter's field,
then we "merge" src's value into the transferring parameter, so we
conservatively leave the region of the transferring parameter alone. If we
assign over the entire transferring parameter, we perform an assign fresh since
any value that used to be in the transferring parameter cannot reference
anything in its new value since they are all gone.
2024-01-18 13:20:28 -08:00
Kuba Mracek
97e454d577 Diagnose a conflicting silgen_name/extern(c) name instead of asserting/crashing 2024-01-05 14:11:19 +01:00
Kuba Mracek
31057e4910 [embedded] Add -no-allocations test for UnsafeMutablePointer.allocate(), improve diag messsage 2024-01-04 08:36:08 +01:00
Kuba Mracek
2739aeb239 [embedded] Fix typo 'alllocation' in diagnostic message 2023-12-11 09:00:51 -08:00
Kuba Mracek
ff1f8adac8 [embedded] Implement non-allocating embedded Swift mode, under -no-allocations flag 2023-12-11 09:00:50 -08:00
Erik Eckstein
ae278058e6 Add an experimental pass to lower allocateVector builtins
By default it lowers the builtin to an `alloc_vector` with a paired `dealloc_stack`.
If the builtin appears in the initializer of a global variable and the vector elements are initialized,
a statically initialized global is created where the initializer is a `vector` instruction.
2023-12-09 18:49:58 +01:00
zoecarver
69498e2f2e [opt] Add three new perf annotations: @_noRuntime, @_noExistential, and @_noObjCBridging. 2023-12-01 09:13:24 -07:00
Michael Gottesman
ccefdebb26 Merge pull request #70031 from gottesmm/region-isolation-async-let
[region-isolation] Add support for async let
2023-11-28 20:30:47 -08:00
Michael Gottesman
18f91c0acd [region-isolation] Add support for async let.
Specifically:

1. If the value is transferred such that it becomes part of an actor region, the
value is permanently part of the actor region as one would normally have.

2. If the value is just used in an async let or is used by a nonisolated async
function within the async let then while the async let is alive it cannot be
used. But once the async let has been awaited upon, we allow for it to be used
again.

rdar://117506395
2023-11-28 09:39:04 -08:00
Erik Eckstein
96e57d62f6 Optimizer: de-virtualize deinits of non-copyable types
In regular swift this is a nice optimization. In embedded swift it's a requirement, because the compiler needs to be able to specialize generic deinits of non-copyable types.
The new de-virtualization utilities are called from two places:

* from the new DeinitDevirtualizer pass. It replaces the old MoveOnlyDeinitDevirtualization, which is very basic and does not fulfill the needs for embedded swift.

* from MandatoryPerformanceOptimizations for embedded swift
2023-11-27 09:21:34 +01:00
Michael Gottesman
389078d4fa [region-isolation] Remove count of emitted diagnostics from main diagnostic.
These are not actionable to the user.
2023-11-10 12:48:45 -08:00
Michael Gottesman
2c0efe6b8b [region-isolation] Go through the implementation again changing Consume -> Transfer.
I just missed these.
2023-10-23 13:52:14 -07:00
Kuba Mracek
a026b38411 [embedded] Tweak diagnostic message about metatypes in embedded Swift 2023-10-18 17:04:30 -07:00
Kuba Mracek
db10e78eb2 [embedded] Start diagnosing metatype/value_metatype instructions in embedded Swift 2023-10-18 16:51:10 -07:00
Kuba Mracek
30046b1f8d [embedded] Update wording on existential diagnostics, take 2 2023-10-14 14:03:59 -07:00
Kuba Mracek
bbe111cca6 [embedded] Update wording on 'no existentials' diagnostic 2023-10-13 10:31:14 -07:00
Kuba Mracek
d5b1abb726 [embedded] Improve the diagnostic message when using an existential 2023-10-09 16:20:08 -07:00
nate-chandler
a9e03df58c Revert "[Diagnostics] Require explicit releasenone." 2023-10-04 14:19:15 -07:00
Kuba Mracek
e2de477609 [embedded] avoid metadata accessors, fix vtable map, add a diagnostic on non-final generic functions 2023-09-12 16:57:09 -07:00
Nate Chandler
2ca262c03a [SIL] Require explicit releasenone.
Functions which which consume their arguments will release them on any
branches where the arguments are unused.  Users of `@_effects(readnone)`
and `@_effects(readonly)` may not consider this when annotating their
functions.  Require that functions annotated thus are also annotated
@_effects(releasenone).

In order to support this, 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)`.
2023-09-05 08:18:06 -07:00
Michael Gottesman
361562aef5 [consume-operator] Emit a better error message when failing to consume globals or escaping captures.
Specifically, we previously emitted a "compiler doesn't understand error", so we
were always emitting an error appropriately. This just gives a better error
message saying instead that the compiler did understand what happened and that
one cannot apply consume to globals or escaping captures.

https://github.com/apple/swift/issues/67755
rdar://112561671
2023-08-20 18:59:37 -07:00
jturcotti
853ef7cf3c fix bugs that present themselves when handling multiarg and varargs functions, including adding better debug dump methods 2023-07-20 14:01:08 -07:00
jturcotti
a83d7aa39c improve diagnostics about data races; highlight the individual expressions being sent and accessed as precisely as possible, and include information about specific non-sendable types and isolation crossings 2023-07-19 17:27:16 -07:00
Joshua Turcotti
992fc6c987 Merge pull request #67318 from JTurcotti/better-diags
[SendNonSendable] Diagnose consumption sites not requirement sites for flow-sensitive region-based Sendable Analysis
2023-07-19 09:38:40 -07:00
John McCall
1a7d44a11d Diagnose attempts to reabstract variadic function types in unimplementable ways. 2023-07-18 13:22:35 -04:00
jturcotti
34113c4c0f implement searching for a ConsumeReason instead of just diagnosing accesses to consumed values 2023-07-14 16:12:52 -07:00
jturcotti
e7a1747af2 Tweak, improve, and debug the PartitionAnalysis engine until a fairly comprehensive suite of simple tests passes (region_based_sendability.swift) 2023-07-11 11:12:38 -07:00
jturcotti
29bd728f4c Begin to fill in the SendNonSendable SIL pass using a PartitionAnalysis engine, works for some simple examples but needs to address address values in SIL. 2023-07-10 15:20:14 -07:00
Kuba (Brecka) Mracek
2961cafb05 Merge pull request #66844 from kubamracek/static-init-structs
Allow using structs with trivial initializers in globals that require static initialization (e.g. @_section attribute)
2023-07-10 15:11:55 -07:00
Kuba Mracek
145f12f6a3 Allow using structs with trivial initializers in globals that require static initialization (e.g. @_section attribute)
Before this change, if a global variable is required to be statically initialized (e.g. due to @_section attribute), we don't allow its type to be a struct, only a scalar type works. This change improves on that by teaching MandatoryPerformanceOptimizations pass to inline struct initializer calls into initializer of globals, as long as they are simple enough so that we can be sure that we don't trigger recursive/infinite inlining.
2023-07-08 19:26:59 -07:00
Michael Gottesman
69a03c93f9 [move-only] Ban partial reinitialization after consuming a value.
This is similar to our ban on partial consuming a value for this release. The
reason for this is that, one can achieve a similar affect as partial consumption
via a consumption of the entire value and then a partial reinitialization. Example:

```swift
struct X : ~Copyable { var i = 5, var i2 = Klass() }
var x = X()
_ = consume x
x.i = 5
```

in the case above, we now have a value that is in a partially initialized state.

We still allow for move only types to have their fields initialized as long as
there is an intervening init.

rdar://111498740
2023-07-05 20:26:26 -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
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
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
Kavon Farvardin
219f94fd1a tailor reinit-after-consume message for closure captures
rdar://109908383
2023-06-12 21:04:25 -07:00
Kavon Farvardin
e71594725a be specific that only escaping closures prevent consumption
rdar://109908383
2023-06-12 17:15:46 -07:00
Pavel Yaskevich
112d0d4f2d [DI] InitAccessors: Start marking initializes(...) properties as "out"
Adjust DI to recognize that "out" location without uses is uninitialized.
2023-06-06 18:59:45 -07:00
Kavon Farvardin
bd253c602f prevent reinitialization of self after discard
The value `self` is mutable (i.e., var-bound) in
a `consuming` method. Since you're allowed to
reinitialize a var after consuming, that means
you were also naturally allowed to reinitialize
self after `discard self`. But that capability was
not intended; after you discard self you shouldn't
be reinitializing it, as that's probably a mistake.

This change makes reinitialization of `self`
reachable from a `discard self` statement an error.

rdar://106098163
2023-06-05 19:25:50 -07:00
Kavon Farvardin
88d35a00b3 emit error on implicit destruction of self in discard context
As part of SE-390, you're required to write either:

  - `consume self`
  - pass self as a `consuming` parameter to a function
  - `discard self`

before the function ends in a context that contains a
`discard self` somewhere. This prevents people from accidentally
invoking the deinit due to implicit destruction of `self` before
exiting the function.

rdar://106099027
2023-06-04 18:45:22 -07:00
Michael Gottesman
577e76b0f6 [move-only] Change closure capture diagnostic for let patterns to say that it cannot be captured by an escaping closure.
rdar://109742587
2023-05-28 13:58:59 -07:00
Kuba (Brecka) Mracek
2d5f33e2e3 Add @_used and @_section attributes for global variables and top-level functions (#65901)
* Add @_used and @_section attributes for global variables and top-level functions

This adds:
- @_used attribute that flags as a global variable or a top-level function as
  "do not dead-strip" via llvm.used, roughly the equivalent of
  __attribute__((used)) in C/C++.
- @_section("...") attribute that places a global variable or a top-level
  function into a section with that name, roughly the equivalent of
  __attribute__((section("..."))) in C/C++.
2023-05-26 14:02:32 -07:00
Kavon Farvardin
03d2017a84 reword 'other consume here' to 'consumed again here'
this also fixes a bug where sometimes we simply emit
'consumed here' twice and other times we'd said 'other
consume here' for the same "consumed more than once"
message. so I went through and changed all of the 2nd
consumes into "consumed again".

rdar://109281444
2023-05-24 20:56:39 -07:00
Kavon Farvardin
71763a124e merge similar diagnostics together under a unified naming scheme for more consistent word tense
sil_movekillscopyablevalue_* and sil_moveonlychecker_* can share diagnostics.

rdar://109281444
2023-05-24 20:56:38 -07:00
Kavon Farvardin
667459ee75 tighten up consistency in terminology
- refer to a "consuming use" as simply a "consume", to reserve "use" for non-consuming uses.
- refer to "non-consuming uses" as just a "use".
- don't call it a "user defined deinit" and instead a "deinitializer" to match Sema
- be specific about what binding a closure is capturing that is preventing consumption.

rdar://109281444
2023-05-24 20:56:38 -07:00
Kavon Farvardin
e9e6cdaf2e remove "within a closure" since you can't consume any captured noncopyable binding
rdar://109281444
2023-05-24 20:56:38 -07:00
Kavon Farvardin
616395c6ed specify "inout" for missing reinit error
rdar://109281444
2023-05-24 20:56:37 -07:00
Kavon Farvardin
3149102fea reword "boundary use" to just "non-consuming"
rdar://109281444
2023-05-24 20:56:37 -07:00
Kavon Farvardin
d3730d896d reword diagnostics for partial consume of fields
also moves the error to the invalid partial consume.

rdar://109281444
2023-05-24 20:56:37 -07:00