Commit Graph

6754 Commits

Author SHA1 Message Date
Michael Gottesman
4fcc60e794 [move-only] When emitting a module, do not emit the body of the deinit of a move only type.
rdar://102173152
2022-11-09 19:40:04 -08:00
Josh Soref
9a6bf46c0f Spelling silgen
* actually
* arbitrary
* cargo-culted
* clazz
* constrained
* continuation
* coordinator
* coroutine
* derivative
* destroyer
* given
* have
* imported
* initialization
* items
* necessarily
* occurring
* omitting
* overridden
* parameter
* possible
* predecessor
* preparation
* resilience
* should
* struct
* that
* the
* throwing
* unexpectedly
* uniqueness
* using
* value
* villain

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2022-11-09 21:44:17 -05:00
Slava Pestov
85419cfa66 Merge pull request #61942 from slavapestov/archetype-existential-type-fixes
More accurate ArchetypeType::getExistentialType()
2022-11-08 07:35:15 -05:00
Slava Pestov
16a84fc382 AST: Rename ProtocolDecl::getExistentialType() to getDeclaredExistentialType() 2022-11-07 18:38:06 -05:00
Michael Gottesman
26db1f20a3 [move-only] Emit a copy_addr instead of a mark_unresolved_move_addr when applying the move operator to move only vars.
The reason why we are doing this is that we want move only addresses to be
checked by the move only address checker and not the move operator address
checker.

rdar://102056097
2022-11-07 14:29:03 -08:00
Robert Widmann
d6143a5ef3 Merge pull request #61937 from CodaFi/mcmainerberry
[SILGen] Look for the C-Language Copy of UIApplicationMain
2022-11-04 17:11:28 -07:00
nate-chandler
02ee6b6915 Merge pull request #61924 from nate-chandler/opaque-values/2/20221103
[OpaqueValues] Handled more instructions.
2022-11-04 16:15:03 -07:00
Nate Chandler
c3183d3c90 [Gardening] Fixed comment. 2022-11-04 10:47:09 -07:00
Robert Widmann
fc52e7adc6 Look for the C-Language Copy of UIApplicationMain
A long while back we added a copy of UIApplicaitonMain to the UIKit
overlay. This was intended to fix the signature of UIApplicationMain by
forcing clients to choose a non-deprecated copy with revised nullability
annotations that were compatible with the (then) interface of the (then)
CommandLine stdlib type. Since then, we've gone in a completely different
direction with type-based entrypoints and @main, but the compatibility
shims remain. This code was assuming that it would always find one
declaration of UIApplicationMain in the clang module, but that's not
a sound assumption to make. In certain scenarios, we can wind up finding
the overlay's copy of UIApplicationMain too. When that's the Swift
function, we reference a native-to-foreign thunk that we don't actually
wind up generating in the open-coding and this results in a nasty linker
error. Filter the available candidates here looking for the C copy of
UIApplicationMain.

rdar://101932338
2022-11-04 10:22:41 -07:00
nate-chandler
94717da036 Merge pull request #61893 from nate-chandler/opaque-values/2/20221102
[OpaqueValues] Return generic tuples directly.
2022-11-03 14:46:43 -07:00
nate-chandler
db9a140c44 Merge pull request #61887 from nate-chandler/opaque-values/1/20221102
[OpaqueValues] Handle Builtin.addressOfBorrow.
2022-11-03 14:46:02 -07:00
Allan Shortlidge
23fe16875c Merge pull request #61886 from tshortli/silgen-has-symbol-forward-decls
SILGen: Forward declare SIL functions referenced by `#_hasSymbol` query helpers
2022-11-03 13:06:51 -07:00
Pavel Yaskevich
5014d7f59b Merge pull request #61875 from amritpan/physical-path-component-set
[SILGen] Move PhysicalPathComponent tail assign into set method
2022-11-03 11:46:42 -07:00
Michael Gottesman
94b17595ee Merge pull request #61848 from gottesmm/pr-1ce4557b1e09a2f5a8afd251c388492597ea3d9f
[silgen] Verify protocol witnesses's SIL right after emitting them.
2022-11-03 10:20:06 -07:00
nate-chandler
f931727f76 Merge pull request #61846 from nate-chandler/opaque-values/1/20221027
[OpaqueValues] Handle PartialApplyInsts and @out tuples.
2022-11-03 08:05:05 -07:00
Allan Shortlidge
2847ee9759 SILGen: Generate valid SIL for no-op #_hasSymbol conditions. 2022-11-02 21:38:33 -07:00
Allan Shortlidge
4da1ed6f73 SILGen: Forward declare SILFunctions that will be referenced by #_hasSymbol query functions. 2022-11-02 21:38:33 -07:00
Allan Shortlidge
54e5fa0fbb SILGen: Record the declarations that need a #_hasSymbol query function generated.
The query functions will be fully defined by IRGen.
2022-11-02 21:38:33 -07:00
Nate Chandler
424174cd24 [OpaqueValues] Return generic tuples directly.
Only create alloc_stacks for address-only tuple returns when using
lowered addresses.
2022-11-02 16:01:58 -07:00
Nate Chandler
520dfc26cd [OpaqueValues] Added variants of addressOfBorrow.
The variants are produced by SILGen when opaque values are enabled.
They are necessary because otherwise SILGen would produce
address_to_pointer of values.

They will be lowered by AddressLowering.
2022-11-02 14:41:35 -07:00
Egor Zhdan
145bf5ff30 Merge pull request #61847 from apple/egorzhdan/cxx-dependency-on-sema
[cxx-interop] Avoid a ClangImporter dependency on Sema
2022-11-02 09:14:57 -07:00
Amritpan Kaur
fd31b663dd [LValue] Move PhysicalPathComponent tail assign into set method. 2022-11-02 08:53:28 -07:00
Slava Pestov
36b3f0ee12 AST: Remove AbstractTypeParamDecl 2022-11-01 19:13:46 -04:00
Egor Zhdan
a7f00d6096 [build] Fix undefined reference linker errors on Linux 2022-11-01 14:45:18 -07:00
Nate Chandler
332750d1fd [SILGen] Handle @out tuple expansion.
When branching to the exit block, flatten an @out tuple return value
into its components, as is done for all other return values.

In the exit block, when constructing the @out tuple to return, visit the
tuple-type-tree of the return value to reconstruct the nested tuple
structure: @out tuple returns are not flattened, unlike regular tuple
returns.
2022-11-01 13:02:32 -07:00
Michael Gottesman
873922bf4f [silgen] Verify protocol witnesses's SIL right after emitting them.
These still get verified as part of SILGenModule's verification during
SILGenModule's destructor. But moving this earlier catches the error earlier and
makes it easier to debug any SIL issues immediately in the debugger rather than
having to backtrack from the SILGenModule's destructor.
2022-11-01 12:00:55 -07:00
Nate Chandler
b0bcc75051 [SILGen] Handle @out tuple expansion.
When branching to the exit block, flatten an @out tuple return value
into its components, as is done for all other return values.

In the exit block, when constructing the @out tuple to return, visit the
tuple-type-tree of the return value to reconstruct the nested tuple
structure: @out tuple returns are not flattened, unlike regular tuple
returns.
2022-11-01 10:37:25 -07:00
nate-chandler
b7793511a1 Merge pull request #61747 from nate-chandler/opaque-values/1/20221014
[AddressLowering] Storage root inherits lexical.
2022-10-27 16:35:15 -07:00
Allan Shortlidge
0d37f52fe0 APIDigester: Break cycle between Frontend and APIDigester targets.
Also push a utility that was previously on `SILDeclRef` down to AST so that the SIL dependency can be removed entirely from APIDigester.
2022-10-26 20:30:36 -07:00
Nate Chandler
24883bf630 [SILGen] Copied opaque tuple fields before switch.
The switch_enum_addr consumes its operand so a copy is needed.
2022-10-26 11:01:28 -07:00
Michael Gottesman
14c687a577 [move-only] Emit the move only marker for move only trivial enums.
Just an oversight I discovered when writing the enum deinit tests.
2022-10-24 20:05:04 -07:00
Michael Gottesman
6cfa72d7aa Merge pull request #61651 from gottesmm/pr-727f8b30b3e32b1eb29003ac26642f5cf54b78e6
[silgen] Eliminate lifetime gap caused by AutoreleasingUnsafeMutablePointer's LValue component set.
2022-10-21 10:17:03 -07:00
swift-ci
1ebcd13975 Merge pull request #61662 from rxwei/macro-expansion-expr
[Macros] Parse MacroExpansionExpr and MacroExpansionDecl
2022-10-21 06:13:41 -07:00
Richard Wei
56e7cce809 [Macros] Parse MacroExpansionExpr and MacroExpansionDecl
Introduce `MacroExpansionExpr` and `MacroExpansionDecl` and plumb it through. Parse them in roughly the same way we parse `ObjectLiteralExpr`.

The syntax is gated under `-enable-experimental-feature Macros`.
2022-10-21 01:50:35 -07:00
Pavel Yaskevich
5c8c008c8e Merge pull request #61479 from xedin/type-wrappers-init-values-in-user-defined-inits
[SILGen] TypeWrappers:  Support default values in user-defined initializers
2022-10-21 08:48:35 +01:00
Michael Gottesman
444c3ee5e0 [silgen] Eliminate lifetime gap caused by AutoreleasingUnsafeMutablePointer's LValue component set.
The problem here is that the AutoreleasingUnsafeMutablePointer's LValue
component would given the following Swift:

```
public class C {}

@inline(never)
func updateC(_ p: AutoreleasingUnsafeMutablePointer<C>) -> () {
  p.pointee = C()
}

public func test() -> C {
  var cVar = C()
  updateC(&cVar)
  return cVar
}
```

generate the following SIL as part of setting cVar after returning from updateC.

```
  %18 = function_ref @$s11autorelease7updateCyySAyAA1CCGF : $@convention(thin) (AutoreleasingUnsafeMutablePointer<C>) -> () // user: %19
  %19 = apply %18(%17) : $@convention(thin) (AutoreleasingUnsafeMutablePointer<C>) -> ()
  %20 = load [trivial] %8 : $*@sil_unmanaged C    // user: %21
  %21 = unmanaged_to_ref %20 : $@sil_unmanaged C to $C // user: %22
  %22 = copy_value %21 : $C                       // user: %23
  assign %22 to %7 : $*C                          // id: %23
  end_access %7 : $*C                             // id: %24
```

Once we are in Canonical SIL, we get the following SIL:

```
  %18 = function_ref @$s11autorelease7updateCyySAyAA1CCGF : $@convention(thin) (AutoreleasingUnsafeMutablePointer<C>) -> () // user: %19
  %19 = apply %18(%17) : $@convention(thin) (AutoreleasingUnsafeMutablePointer<C>) -> ()
  %20 = load [trivial] %8 : $*@sil_unmanaged C    // user: %21
  %21 = unmanaged_to_ref %20 : $@sil_unmanaged C to $C // user: %22
  %22 = copy_value %21 : $C                       // user: %23
  store %22 to [assign] %7 : $*C                          // id: %23
  end_access %7 : $*C                             // id: %24
```

which destroy hoisting then modifies by hoisting the destroy by the store assign
before the copy_value:

```
  %18 = function_ref @$s11autorelease7updateCyySAyAA1CCGF : $@convention(thin) (AutoreleasingUnsafeMutablePointer<C>) -> () // user: %19
  %19 = apply %18(%17) : $@convention(thin) (AutoreleasingUnsafeMutablePointer<C>) -> ()
  destroy_addr %7 : $*C
  %20 = load [trivial] %8 : $*@sil_unmanaged C    // user: %21
  %21 = unmanaged_to_ref %20 : $@sil_unmanaged C to $C // user: %22
  %22 = copy_value %21 : $C                       // user: %23
  store %22 to [init] %7 : $*C                          // id: %23
  end_access %7 : $*C                             // id: %24
```

Given the appropriate Swift code, one could have that %21 is actually already
stored in %7 and has a ref count of 1. In such a case, the destroy_addr would
cause %21 to be deallocated before we can retain the value.

In order to fix this edge case as a bug fix, in the setter for
AutoreleasingUnsafeMutablePointer, we introduce a mark_dependence from the
copied value onto the memory. This ensures that destroy hoisting does not hoist
the destroy_addr past the mark_dependence, yielding correctness. That is we
generate the following SIL:

```
  %18 = function_ref @$s11autorelease7updateCyySAyAA1CCGF : $@convention(thin) (AutoreleasingUnsafeMutablePointer<C>) -> () // user: %19
  %19 = apply %18(%17) : $@convention(thin) (AutoreleasingUnsafeMutablePointer<C>) -> ()
  %20 = load [trivial] %8 : $*@sil_unmanaged C    // user: %21
  %21 = unmanaged_to_ref %20 : $@sil_unmanaged C to $C // user: %22
  %22 = copy_value %21 : $C                       // user: %23
  %23 = mark_dependence %22 : $C on %7 : $*C
  assign %23 to %7 : $*C                          // id: %23
  end_access %7 : $*C                             // id: %24
```

For those unfamiliar, mark_dependence specifies that any destroy of the memory
in %7 can not move before any use of %23.

rdar://99402398
2022-10-20 16:55:17 -07:00
Becca Royal-Gordon
ad359fa753 Give @_objcImpl classes implicit deinits 2022-10-18 17:21:56 -07:00
Becca Royal-Gordon
6143b8379f Generate IR for @_objcImpl stored properties
Only works for trivial types right now because features related to initialization and deinitialization are seriously busted.
2022-10-18 17:21:56 -07:00
Slava Pestov
da8ae1d36d Sema: Remove PackExpr 2022-10-16 21:37:25 -04:00
Hamish Knight
350e28b4b7 [Profiler] Rework profiling of top-level code
Instead of creating and destroying a SILProfiler
per TopLevelCodeDecl, setup a single profiler
for the top-level entry point function, and visit
all the TopLevelCodeDecls when mapping regions.
2022-10-14 17:45:14 +01:00
Hamish Knight
7529346a0f [Profiler] Remove unnecessary createProfiler call
We never end up creating the profiler for a
backing initializer from projected value, as it
has no user-written code.
2022-10-14 17:45:13 +01:00
Hamish Knight
d1e2ac15d4 Factor out SILDeclRef::getInitializationExpr 2022-10-14 17:45:12 +01:00
Hamish Knight
1c9b77ef54 Merge pull request #61566 from hamishknight/countdown 2022-10-14 13:57:48 +01:00
Allan Shortlidge
182cc8de37 SILGen: Implement if #_hasSymbol() conditions.
Emit a call to a helper function that determines whether the symbols associated with the declaration referenced in the `#_hasSymbol(...)` condition are non-null at runtime. An upcoming change will emit a definition for this function during IRGen.

Resolves rdar://100130015
2022-10-13 21:00:24 -07:00
Hamish Knight
809cfb7bf2 [Profiler] Introduce ProfileCounterRef
For now this just wraps an ASTNode, but in the
future it will allow us to model counters
that cannot simply hang off ASTNodes, e.g
error branch counters.
2022-10-13 19:42:37 +01:00
Hamish Knight
bfa3a3f4f3 [Profiler] Avoid passing null node to loadProfilerCount
This will become an assertion failure in a future
commit.
2022-10-13 19:42:37 +01:00
Hamish Knight
5a8c14d583 [Profiler] Fix up a couple uses of emitProfilerIncrement
Remove a case where we know we don't have a
profiler, and avoid incrementing for a distributed
factory method. Otherwise such cases could pass
a null ASTNode, which will become an assertion
failure in a future commit.

While we're here, let's standardize on emitting
the profiler increment for function entry after
the prolog, as if there's e.g an unreachable
parameter, the increment can be safely elided
anyway.
2022-10-13 19:42:36 +01:00
Holly Borla
c4b946195e [AST] Replace the "type sequence" terminology with "parameter pack". 2022-10-10 16:28:13 -07:00
Holly Borla
67fb143f0e [AST] Remove ReifyPackExpr. 2022-10-10 16:25:26 -07:00
Holly Borla
464e54aa02 Merge pull request #61523 from hborla/pack-expansion-expr
[AST] Add the skeleton for `PackExpansionExpr`.
2022-10-10 11:22:05 -07:00