When performance diagnostics were introduced, typed throws didn't exist
so it was not generally possible to have throws anywhere without
triggering performance diagnostics. As a short term hack, we disabled
checking of `throw` instructions and the basic blocks that terminate
in a `throw`.
Now that typed throws is available and can be used to eliminate
allocations with error handling, remove all of the hacks. We'll now
diagnose attempts to throw or catch existential values (e.g., the `any
Error` used for untyped throws), but typed throws are fine.
Prior to throwing, Swift emits a call to `swift_willThrow(Typed)`,
which allows various diagnostic tools (such as debuggers and testing
libraries) to intercept errors at the point where they are initially
thrown.
Since `swift_willThrow(Typed)` can be hooked by arbitrary code at
runtime, there is no way for it to meet performance constraints like
@_noLocks or @_noAllocation. Therefore, in a function that has those
performance constraints specified, disable emission of the call to
`swift_willThrow(Typed)`.
Fixes rdar://140230684.
Find all the usages of `--enable-experimental-feature` or
`--enable-upcoming-feature` in the tests and replace some of the
`REQUIRES: asserts` to use `REQUIRES: swift-feature-Foo` instead, which
should correctly apply to depending on the asserts/noasserts mode of the
toolchain for each feature.
Remove some comments that talked about enabling asserts since they don't
apply anymore (but I might had miss some).
All this was done with an automated script, so some formatting weirdness
might happen, but I hope I fixed most of those.
There might be some tests that were `REQUIRES: asserts` that might run
in `noasserts` toolchains now. This will normally be because their
feature went from experimental to upcoming/base and the tests were not
updated.
An initializing store is not a copy and therefore doesn't perform ref counting operations
Fixes a false performance error when using non-copyable types.
https://github.com/apple/swift/issues/73582
Even if the destroyed value doesn't have a deinit.
This fixes a false alarm when a non-copyable value ends its lifetime in a function with performance annotations.
rdar://117002721
* Don't exclude code which end up in an infinite loop. rdar://116705459
* Don't exclude error handling code (throw, catch). Errors are existentials and will always allocate. Once we have typed throws it will be possible to do error handling without allocations.
For example:
```
var p = Point(x: 10, y: 20)
let o = UnsafePointer(&p)
```
Also support outlined arrays with pointers to other globals. For example:
```
var g1 = 1
var g2 = 2
func f() -> [UnsafePointer<Int>] {
return [UnsafePointer(&g1), UnsafePointer(&g2)]
}
```
We inline a function (e.g. a struct initializer) into a global init function if the result is part of the initialized global.
Now, also handle functions with indirect return values. Such function can result from not-reabstracted generic specializations.
Handle cases where the result is stored into a temporary alloc_stack or directly stored to (a part) of the global variable.
* Look through `begin_borrow` when analyzing closure values
* Treat non-escaping closures as trivial values when passed to a `partial_apply`
rdar://111046264
And replace them with explicit `metatype` instruction in the entry block.
This allows such metatype instructions to be deleted if they are dead.
This was already done for performance-annotated functions. But now do this for all functions.
It is essential that performance-annotated functions are specialized in the same way as other functions.
Because otherwise it can happen that the same specialization has different performance characteristics in different modules.
And it's up to the linker to select one of those ODR functions when linking.
Also, dropping metatype arguments is good for performance and code size in general.
This change also contains a few bug fixes for dropping metatype arguments.
rdar://110509780
Run DestroyAddrHoisting in the pipeline where DestroyHoisting was
previously running. Avoid extra ARC traffic that having no form of
destroy hoisting in the mandatory pipeline results in.
rdar://90495704
Remove dead `metatype` instructions which only have `debug_value` uses.
We lose debug info for such type variables, but this is a compromise we need to accept to get allocation/lock free code.
rdar://103270882
In performance-annotated functions optimize the pattern where a partial_apply is immediately applied.
This remove the partial apply and thus avoids an allocation.
Fixes an unnecessary performance violation error.
rdar://95155145
This is important for performance diagnostics: it’s assumed that (non-generic) MemoryLayout constants do not need to create metadata at runtime. At Onone this is only guaranteed if the TargetConstantFolding pass runs.
rdar://94836837
And replace them with explicit `metatype` instruction in the entry block.
This allows such metatype instructions to be deleted if they are dead.
rdar://94388453
Replace the dynamic initialization of trivial globals with statically initialized globals, even in -Onone.
This is required to be able to use global variables in performance-annotated functions.
Also, it's a small performance improvement for -Onone.
The PerformanceDiagnostics pass issues performance diagnostics for functions which are annotated with performance annotations, like @_noLocks, @_noAllocation.
This is done recursively for all functions which are called from performance-annotated functions.
rdar://83882635