Commit Graph

6754 Commits

Author SHA1 Message Date
Hamish Knight
b12015c343 [SIL] Introduce the increment_profiler_counter instruction
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
2022-09-07 17:55:13 +01:00
nate-chandler
2efc0f6857 Merge pull request #60940 from nate-chandler/eager_move_self
Self parameters can be @_noImplicitCopy or @_eagerMove.
2022-09-07 06:12:53 -07:00
Alex Hoppen
442cf9bd4e [Sema] Add custom functions to ActorIsolationChecker to determine expr type and closure actor isolation
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.
2022-09-07 11:12:23 +02:00
Nate Chandler
cacac0bd83 [SILGen] Allow annotating self @_noImplicitCopy.
Allow @_noImplicitCopy to be applied to methods.  Applying it there
means that the self argument will have the attribute.
2022-09-02 17:32:48 -07:00
Nate Chandler
9dbdfa8e3f [SILGen] Allow annotating self @_eagerMove.
Allow @_eagerMove (and @_lexical) to be applied to methods.  Applying
it there means that the self argument will have the attribute.
2022-09-02 16:13:08 -07:00
Nate Chandler
158c782960 [AST] Promote isNoImplicitCopy to Decl.
Move the predicate up from ParamDecl to Decl and use it everywhere in
place of hasAttribute<NoImplicitCopyAttr>.
2022-09-02 16:12:17 -07:00
Hamish Knight
1e2af9b037 Merge pull request #60911 from hamishknight/dist-deinit 2022-09-02 14:38:25 +01:00
Hamish Knight
ab7b691cca [Profiler] Fix distributed deinit crash when emitting coverage
We need to emit the profiler increment in the
`deinitBodyBB` if we're within a distributed
actor.
2022-09-01 20:29:50 +01:00
Hamish Knight
27b27a400e [Profiler] Fix autoclosure property wrapper crash
We need to query the top-level expression, not
the sub-expression of a potential function
conversion.

rdar://99449154
2022-09-01 19:29:19 +01:00
Kavon Farvardin
850797d588 [SILGen] correct missing canonicalization of global actor
resolves rdar://96309577 / https://github.com/apple/swift/issues/59705
2022-08-30 16:15:09 -07:00
swift-ci
a66951aa3d Merge pull request #60521 from kavon/preconcurrency-var-access
Add missing function conversion for member access to preconcurrency vardecl.
2022-08-30 00:58:49 -07:00
Kavon Farvardin
6c24bc57cb [AST][SILGen] model ABI-safe casts of LValues
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.
2022-08-29 20:58:26 -07:00
Doug Gregor
fde58da5c2 Merge pull request #60809 from DougGregor/distributed-thunk-default-impls 2022-08-26 21:22:00 -07:00
Doug Gregor
641d896a26 [Distributed] Use distributed thunk witnesses for DA protocol extensions.
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.
2022-08-26 16:56:03 -07:00
Doug Gregor
0db7246c59 Merge pull request #60799 from DougGregor/generalize-actor-isolation 2022-08-26 13:03:00 -07:00
Hamish Knight
05e2309788 [Profiler] Fix coverage mapping for switches
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
2022-08-25 17:30:34 +01:00
Doug Gregor
5191c315e1 Eliminate ImplicitActorHopTarget in favor of ActorIsolation.
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.
2022-08-23 23:19:46 -07:00
Doug Gregor
141ffc2b8d Model isolated parameters in ActorIsolation.
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.
2022-08-23 23:19:46 -07:00
Slava Pestov
7a16b0275b AST: Allow one-element tuple types to be constructed
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.
2022-08-23 11:12:00 -04:00
Nate Chandler
3c78a0bb90 [SILGen] Only lexical types get lexical lifetimes.
Only emit `begin_borrow [lexical]` and only mark `alloc_stack`s
`[lexical]` when the variable in question's lifetime is lexical, not
eager move.
2022-08-22 15:28:00 -07:00
Nate Chandler
31b2d8166e [SILGen] Added TODO. 2022-08-21 21:44:31 -07:00
Nate Chandler
7ea2d5c54d [Gardening] Tweaked argument label. 2022-08-21 21:44:31 -07:00
Nate Chandler
0659e16846 [SILGen] Use decl for noImplicitCopy attr.
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.
2022-08-21 21:44:30 -07:00
Doug Gregor
20be955eed Open existential actors when retrieving their executors.
Fixes rdar://91448324.
2022-08-19 15:08:51 -07:00
Hamish Knight
6a6ba8300c [Profiler] Re-enable an assertion
This was disabled as it was hit when attempting to
profile lazy variables. Now that we handle them
correctly, re-enable it.
2022-08-19 14:03:41 +01:00
Hamish Knight
64fcbd9412 [Profiler] Support lazy variable initializers
Start visiting LazyInitializerExpr for profiling,
such that we emit a profile counter when
initializing the initial value for the first time.

rdar://43393937
2022-08-19 14:03:40 +01:00
Hamish Knight
df66f2777e Merge pull request #60509 from hamishknight/insurance-claim 2022-08-19 13:46:33 +01:00
Meghana Gupta
196994fc11 Fix store_borrow generation in SILGen
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
2022-08-16 15:08:22 -07:00
Hamish Knight
19e1e2f7a2 [SILGen] Fix deinit coverage mapping
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
2022-08-11 15:09:53 +01:00
swift-ci
d0700b3f2a Merge remote-tracking branch 'origin/main' into rebranch 2022-08-10 16:34:37 -07:00
Kavon Farvardin
b0fb7c54b2 Merge pull request #60399 from kavon/fix-97646309
Fix crash when emitting force-unwrap-and-call expression for optional ObjC methods
2022-08-10 16:27:56 -07:00
swift-ci
71c6bd422e Merge remote-tracking branch 'origin/main' into rebranch 2022-08-09 13:14:18 -07:00
Slava Pestov
03f2225d96 Merge pull request #60463 from slavapestov/reduced-types
AST: Rename 'canonical wrt. generic signature' to 'reduced'
2022-08-09 16:12:58 -04:00
Slava Pestov
9d96ed940f AST: Rename 'canonical wrt. generic signature' to 'reduced'
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'.
2022-08-09 12:46:31 -04:00
swift-ci
0409774802 Merge remote-tracking branch 'origin/main' into rebranch 2022-08-08 16:56:17 -07:00
Michael Gottesman
6493886e1d [move-keyword] Wire up support for the move keyword in lvalue/rvalue emission.
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.
2022-08-08 12:50:42 -07:00
swift-ci
a37a9a3385 Merge remote-tracking branch 'origin/main' into rebranch 2022-08-05 04:37:32 -07:00
Slava Pestov
182946e6be Merge pull request #60370 from slavapestov/cleaner-conformance-collapse
Cleaner conformance collapsing
2022-08-05 07:20:32 -04:00
swift-ci
3d1db6bf31 Merge remote-tracking branch 'origin/main' into rebranch 2022-08-04 13:54:34 -07:00
Suyash Srijan
b2593ee5e3 [CSDiagnostics] Optional closure diagnostic improvement (#60321)
* [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
2022-08-04 21:40:17 +01:00
Kavon Farvardin
d3f644a154 [SILGen] fix crash invoking global-actor qualified optional ObjC async method
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
2022-08-03 14:20:47 -07:00
Slava Pestov
1d8b0f25ac SILGen: Simplify SILGenModule::useConformance() 2022-08-03 00:28:43 -04:00
swift-ci
73280e6ed5 Merge remote-tracking branch 'origin/main' into rebranch 2022-08-02 12:13:17 -07:00
Hamish Knight
9da53193da [AST] Remove ParameterTypeFlags from ParenType and TupleType
The last clients that relied on stashing parameter
type flags on these types are now gone.
2022-08-02 13:56:32 +01:00
Hamish Knight
6e51841d14 [AST] Enforce that composeTuple drops parameter flags
Callers may either assert that the parameter flags
are empty, or ask for them to be dropped.
2022-08-02 13:56:31 +01:00
Ikko Ashimine
d82d26b03f [SILGen] Fix typo in SILGenStmt.cpp
refering -> referring
2022-08-01 11:40:03 +09:00
swift-ci
4b73728c9f Merge remote-tracking branch 'origin/main' into rebranch 2022-07-30 17:13:56 -07:00
Slava Pestov
ce93261a86 Merge pull request #60310 from slavapestov/clean-up-override-substitutions
Clean up calculation of override substitutions
2022-07-30 20:05:00 -04:00
swift-ci
8bafc37be1 Merge remote-tracking branch 'origin/main' into rebranch 2022-07-29 09:35:02 -07:00
Joe Groff
0c48517a65 Merge pull request #60167 from maxovtsin/fix-crash-uninhabited-param-closure-executor
[SILGen] Emit unreachable in emitProlog() for uninhabited arguments after other codegen
2022-07-29 09:25:42 -07:00