This is a dedicated instruction for incrementing a
profiler counter, which lowers to the
`llvm.instrprof.increment` intrinsic. This
replaces the builtin instruction that was
previously used, and ensures that its arguments
are statically known. This ensures that SIL
optimization passes do not invalidate the
instruction, fixing some code coverage cases in
`-O`.
rdar://39146527
When we get rid of `LeaveClosureBodiesUnchecked` we no longer save closure types to the AST and thus also don’t save their actor isolation to the AST. Hence, we need to extract types and actor isolations of parent closures from the constraint system solution instead of the AST. This prepares `ActorIsolationChecker` to take custom functions to determine the type of an expression or the actor isolation of a closure.
We needed a way to describe an ABI-safe cast of an address
representing an LValue to implement `@preconcurrency` and
its injection of casts during accesses of members.
This new AST node, `ABISafeConversionExpr` models what is
essentially an `unchecked_addr_cast` in SIL when accessing
the LVAlue.
As of now I simply implemented it and the verification of
the node for the concurrency needs to ensure that it's not
misused by accident. If it finds use outside of that,
feel free to update the verifier.
When a distributed member of an extension of a DistributedActor
protocol is used to satisfy a distributed requirement for the same
protocol, make sure we still use the distributed thunk.
Noticed by inspection.
Previously we assumed the exit counter was the
same as the entry counter. Update the logic such
that we track break statements (including
implicitly at the end of a case), as well as
early returns and jumps to parent statements. This
follows a similar logic to what we do for if
statements.
rdar://99141044
The generalized ActorIsolation is enough to represent everything that
ImplicitActorHopTarget can do, and we were mapping between the two way
too often, so collapse them.
A function can be actor instance-isolated to one of its parameters.
Make sure that this is reflected in ActorIsolation, so such a function
doesn't get a different actor isolation.
These will never appear in the source language, but can arise
after substitution when the original type is a tuple type with
a pack expansion type.
Two examples:
- original type: (Int, T...), substitution T := {}
- original type: (T...), substitution T := {Int}
We need to model these correctly to maintain invariants.
Callers that previously used to rely on TupleType::get()
returning a ParenType now explicitly check for the one-element
case instead.
Rather than using the SILValue of the ManagedValue generated for that
argument, which is not always a SILFunctionArgument, just look directly
at the ParmDecl for the attribute.
Start visiting LazyInitializerExpr for profiling,
such that we emit a profile counter when
initializing the initial value for the first time.
rdar://43393937
This change ensures all store_borrows are ended with an end_borrow, and uses of the store_borrow
destination are all in the enclosing store_borrow scope and via the store_borrow return address.
Fix tests to reflect new store_borrow pattern
Stop profiling the deallocating deinitializer
function for non-ObjC classes, and instead profile
the destructor, which is where we emit the user's
code written in a `deinit`.
rdar://54443107
We had two notions of canonical types, one is the structural property
where it doesn't contain sugared types, the other one where it does
not contain reducible type parameters with respect to a generic
signature.
Rename the second one to a 'reduced type'.
I also updated the move function tests to show that this is working. As a nice
bonus, I was able to enable all of the tests also in a non-optimized stdlib.
* [NFC] Add a getOptionalityDepth method to return the number of optionals a type has
* [NFC] Use getOptionalityDepth to remove existing code
* [AST] Add a new diagnostic note for suggesting optional chaining
* [CSDiagnostics] Tweak MissingOptionalUnwrapFailure to suggest using optional chaining on closure
* [Test] Add a couple of test cases for perform_optional_chain_on_closure
* [CSDiagnostics] Change DeclRefExpr casts to isa checks
* [AST] Update diagnostic phrasing
* [Sema] Use new diagnostic identifier and update comment
* [Test] Add a new test case for function type
* [Test] Update cfuncs_parse.swift tests to check for new diagnostic note
Due to some changes in how the AST is constructed by CSApply to handle
global actors from @preconcurrency declarations, the AST for a force-call to
an optional ObjC method that is part of a global-actor qualified protocol, such as:
```
import Foundation
@MainActor
@objc protocol P {
@objc optional func generateMaybe() async
}
extension P {
func test() async -> Void {
await self.generateMaybe!()
}
}
```
now contains a function conversion in between the forced-value operation and the dynamic-ref:
```
(force_value_expr type='@MainActor () async -> ()'
(optional_evaluation_expr implicit type='(@MainActor () async -> ())?'
(inject_into_optional implicit type='(@MainActor () async -> ())?'
(function_conversion_expr implicit type='@MainActor () async -> ()' <<<<< new!
(bind_optional_expr implicit type='() async -> ()'
(dynamic_member_ref_expr type='(() async -> ())?' ... )))))
```
For compatibility with how ObjC does message sends to these optional methods, in Swift there
is a difference between how something like `a.method!()` and the following are compiled:
```
let meth = a.method!
meth()
```
The former will directly call the optional method and let the "unknown selector" error be emitted
if it's not implemented. But the latter will query the dynamic method and inject that result into an
`Optional<...>` to then be forced, yielding a "force-unwrap nil" error. It's a subtle difference but
those two scenarios lead to different code paths in SILGen.
Now, this patch fixes the issue by enhancing the recognition of these direct call scenarios so that it
can look past these function conversions. Because that recognition already tries to ignore implicit
conversions, this is not something new. The problem was that we weren't considering implicit conversions
between the optional-evaluation and bind-optional expressions.
This patch is intentionally precise about what kind of function conversions can be skipped, because I
do not know if all of them are OK to blindly skip or not. We might need to expand that in the future.
Resolves rdar://97646309