Commit Graph

473 Commits

Author SHA1 Message Date
Erik Eckstein
a80d0cb8a7 remove now unused utilities
* StaticInitCloner
* some APIs in SILGlobalVariable
2023-05-22 15:34:26 +02:00
Erik Eckstein
54aacf64e1 SIL: don't allow upcast to be done on address types
It's not needed and just complicates the SIL
2023-05-22 15:34:26 +02:00
Meghana Gupta
1dc713e2f7 Add new flags "reborrow" and "escaping" to SILArgument.
"reborrow" flag on the SILArgument avoids transitive walk over the phi operandsi
to determine if it is a reborrow in multiple utilities.
SIL transforms must keep the flag up-to-date by calling SILArgument::setReborrow.
SILVerifier checks to ensure the flag is not invalidated.

Currently "escaping" is not used anywhere.
2023-05-11 12:31:37 -07:00
Slava Pestov
64569a274c SIL: Teach about SILVerifier about TuplePackElementAddrInst and PackElementSetInst 2023-05-05 22:45:03 -04:00
Erik Eckstein
4b33b99ee2 MemoryLifetimeVerifier: be more precise with indirect function arguments.
Optimizations can rely on alias analysis to know that an in-argument (or parts of it) is not actually read.
We have to do the same in the verifier: if alias analysis says that an in-argument is not read, there is no need that the memory location is initialized.

Fixes a false verifier error.
rdar://106806899
2023-05-03 14:33:45 +02:00
Adrian Prantl
686023861e Merge pull request #65552 from adrian-prantl/108736443
Remove a stateful workaround for Property Wrappers.
2023-05-02 13:43:51 -07:00
Adrian Prantl
dcd881e105 SILDebugScopes: Remove a stateful workaround for Property Wrappers.
In an earlier version of the ASTScope -> SILdebugScope translation a workaround
was put into place that would select the current debug scope if an ASTScope was
marked as ignoreInDebugInfo. Removing this workaround makes the translation more
predictable as it eliminated the dependency on the current SILBuilder state. The
property wrapper tests still pass without this.

This uncovers a situations with let bindings where the SIL instructions are
emitted RHS before LHS, which does violate the di-hole verifier. This is
addressed by relaxing the verifier for now.

rdar://108736443
2023-05-01 17:52:44 -07:00
Michael Gottesman
c577055100 [move-only] Instead of using AccessUseVisitor to visit addresses use TransitiveAddressVisitor.
This makes it so that the move address checker is not dependent on starting the
traversal at a base object. I also included verifier checks that the API can
visit all address uses for:

1. project_box.
2. alloc_stack.
3. ref_element_addr.
4. ref_tail_addr.
5. global_addr_inst.

this is because this visitor is now apart of the SIL API definition as being
able to enumerate /all/ addresses derived from a specific chosen address value.

This is a refactoring NFCI change.

rdar://108510644
2023-04-25 10:51:03 -07:00
Adrian Prantl
b6be6ad809 Disable dihole verifier in a non-asserts build 2023-04-14 15:22:23 -07:00
swift-ci
703222583c Merge pull request #65047 from adrian-prantl/107764966
Ignore profile counter instructions in the dihole verifier.
2023-04-12 21:36:02 -07:00
Adrian Prantl
8d6c55e673 Skip instructions without source location in dihole verfication 2023-04-12 17:06:08 -07:00
Erik Eckstein
c4ae7fe9e6 move-only: support deinits which get the self argument as indirect argument
This happens for address-only move-only types.
2023-04-11 10:25:49 +02:00
Erik Eckstein
7d70a70acf SIL: add the drop_deinit instruction
his instruction is a marker for a following destroy instruction to suppress the call of the move-only type's deinitializer.
2023-04-11 10:25:48 +02:00
Adrian Prantl
c877a4a802 Ignore profile counter instructions in the dihole verifier.
rdar://107764966
2023-04-10 14:23:43 -07:00
Slava Pestov
db058a4f9c Merge pull request #64753 from slavapestov/variadic-conformances
Fixes for conformances of variadic generic types
2023-04-06 08:18:22 -04:00
Slava Pestov
86f37e2acf SIL: Fill in unimplemented logic in verifyDynamicPackIndexStructuralEquality()
However, it should probably do something more elaborate where
it recovers the conformance from the pack conformance instead.
2023-04-05 23:42:17 -04:00
Adrian Prantl
158772c2ab Rebase SILScope generation on top of ASTScope.
This patch replaces the stateful generation of SILScope information in
SILGenFunction with data derived from the ASTScope hierarchy, which should be
100% in sync with the scopes needed for local variables. The goal is to
eliminate the surprising effects that the stack of cleanup operations can have
on the current state of SILBuilder leading to a fully deterministic (in the
sense of: predictible by a human) association of SILDebugScopes with
SILInstructions. The patch also eliminates the need to many workarounds. There
are still some accomodations for several Sema transformation passes such as
ResultBuilders, which don't correctly update the source locations when moving
around nodes. If these were implemented as macros, this problem would disappear.

This necessary rewrite of the macro scope handling included in this patch also
adds proper support nested macro expansions.

This fixes

rdar://88274783

and either fixes or at least partially addresses the following:

rdar://89252827
rdar://105186946
rdar://105757810
rdar://105997826
rdar://105102288
2023-04-04 15:20:11 -07:00
Konrad `ktoso` Malawski
0586c14b60 [Concurrency] SerialExecutor.isSameExclusiveExecutionContext (#64604) 2023-03-28 15:56:28 +09:00
nate-chandler
4ea51cfe33 Revert "Add a verify-di-hole assertion to SILBuilder." 2023-03-23 13:27:06 -07:00
Andrew Trick
119e712c32 Merge pull request #64534 from atrick/liveblocks-bitfield
Cleanup PrunedLiveBlocks
2023-03-22 16:33:08 -07:00
Andrew Trick
15796e3ff9 PrunedLiveness: add a SILFunction argument
So that liveness can migrate to using a SILBitfield.
2023-03-22 01:36:48 -07:00
Adrian Prantl
5129aea296 Add a verify-di-hole assertion to SILBuilder.
The verify-di-hole SILVerifier pass is very useful in catching incorrectly set
SILDebugScopes, but it can be very tedious to track down the root cause of a
verification failure. This patch replicates much of its functionality inside an
assertion in SILBuilder, which will result in a backtrace pointing directly to
where the offending scope is being set.
2023-03-21 09:40:11 -07:00
John McCall
32fa74d374 Merge pull request #64374 from rjmccall/verify-multiple-opening
Verify instructions depending on multiple archetypes from the same open_pack_element
2023-03-15 15:07:54 -04:00
John McCall
22c05ba5a6 Fix the SIL verifier to handle openings of multiple element archetypes 2023-03-14 22:31:38 -04:00
Kavon Farvardin
49c8b5861b basic verifier coverage for explicit_copy_* instructions
These are just basic restrictions for now to help avoid
mistakes. The restrictions are inferred based on how the
move checker uses these instructions.
2023-03-13 22:39:32 -07:00
John McCall
b0dd825f53 Prevent the normal tuple instructions from being used with pack expansions 2023-03-09 02:17:35 -05:00
Erik Eckstein
cc104173c0 SILVerifier: fix quadratic complexity in verifying the predecessor-successor structure of basic blocks
Use sets instead of nested iterating over the predecessor/successor lists.
2023-03-08 12:20:45 +01:00
Erik Eckstein
b21802c7e2 SILVerifier: turn on the ownership verifier again
It was turned off by mistake
2023-03-07 15:38:09 +01:00
Michael Gottesman
00d54ebaa8 [reference-binding] Add mark_unresolved_reference_binding to signal from SILGen to the pass to check.
Just the SIL part of this.
2023-03-03 17:14:41 -08:00
Andrew Trick
c588c657f5 SILVerifier - option to verify with or without linear lifetime check
Add a separate 'verifyOwnership()' entry point so it's possible
to check OSSA lifetimes at various points.

Move SILGenCleanup into a SILGen pass pipeline.

After SILGen, verify incomplete OSSA.

After SILGenCleanup, verify ownership.
2023-03-01 21:41:46 -08:00
Andrew Trick
103a6fefb8 LinearLifetimeChecker - make DeadEndBlocks optional 2023-03-01 21:41:46 -08:00
Michael Gottesman
ecb864c159 Merge pull request #63755 from gottesmm/pr-dac78af5673ab6d4a9bebea882b8440c37c9457c
[move-only] A few small changes in preparation for a larger patch
2023-02-18 17:03:50 -08:00
Michael Gottesman
a24d46097f [sil] Teach the various address verifiers about ExplicitCopyAddrInst.
Just treating it the same as copy_addr as expected.
2023-02-17 16:04:47 -08:00
Erik Eckstein
2c1d48b69c SIL: add type-dependent operands to the keypath instruction
It's need to correctly maintain dependencies from an open-existential instruction to a `keypath` instruction which uses the opened type.
Fixes a SILVerifier crash.

rdar://105517521
2023-02-17 17:48:55 +01:00
Michael Gottesman
5acb6c939a [move-only] Perform an exclusive borrow when passing a var to a consuming var.
Consider the following example:

```
class Klass {}

@_moveOnly struct Butt {
  var k = Klass()
}

func mixedUse(_: inout Butt, _: __owned Butt) {}

func foo() {
    var y = Butt()
    mixedUse(&y, y)
}
```

In this case, we want to have an exclusivity violation. Before this patch, we
did a by-value load [copy] of y and then performed the inout access. Since the
access scopes did not overlap, we would not get an exclusivity violation.
Additionally, since the checker assumes that exclusivity violations will be
caught in such a situation, we convert the load [copy] to a load [take] causing
a later memory lifetime violation as seen in the following SIL:

```
sil hidden [ossa] @$s4test3fooyyF : $@convention(thin) () -> () {
bb0:
  %0 = alloc_stack [lexical] $Butt, var, name "y" // users: %4, %5, %8, %12, %13
  %1 = metatype $@thin Butt.Type                  // user: %3
  // function_ref Butt.init()
  %2 = function_ref @$s4test4ButtVACycfC : $@convention(method) (@thin Butt.Type) -> @owned Butt // user: %3
  %3 = apply %2(%1) : $@convention(method) (@thin Butt.Type) -> @owned Butt // user: %4
  store %3 to [init] %0 : $*Butt                  // id: %4
  %5 = begin_access [modify] [static] %0 : $*Butt // users: %7, %6
  %6 = load [take] %5 : $*Butt                    // user: %10                // <————————— This was a load [copy].
  end_access %5 : $*Butt                          // id: %7
  %8 = begin_access [modify] [static] %0 : $*Butt // users: %11, %10
  // function_ref mixedUse2(_:_:)
  %9 = function_ref @$s4test9mixedUse2yyAA4ButtVz_ADntF : $@convention(thin) (@inout Butt, @owned Butt) -> () // user: %10
  %10 = apply %9(%8, %6) : $@convention(thin) (@inout Butt, @owned Butt) -> ()
  end_access %8 : $*Butt                          // id: %11
  destroy_addr %0 : $*Butt                        // id: %12
  dealloc_stack %0 : $*Butt                       // id: %13
  %14 = tuple ()                                  // user: %15
  return %14 : $()                                // id: %15
} // end sil function '$s4test3fooyyF'
```

Now, instead we create a [consume] access and get the nice exclusivity error we
are looking for.

NOTE: As part of this I needed to tweak the verifier so that [deinit] accesses
are now allowed to have any form of access enforcement before we are in
LoweredSIL. I left in the original verifier error in LoweredSIL and additionally
left in the original error in IRGen. The reason why I am doing this is that I
need the deinit access to represent semantically what consuming from a
ref_element_addr, global, or escaping mutable var look like at the SIL level so
that the move checker can error upon it. Since we will error upon such
consumptions in Canonical SIL, such code patterns will never actually hit
Lowered/IRGen SIL, so it is safe to do so (and the verifier/errors will help us
if we make any mistakes). In the case of a non-escaping var though, we will be
able to use deinit statically and the move checker will make sure that it is not
reused before it is reinitialized.

rdar://101767439
2023-02-10 19:43:58 -08:00
Pavel Yaskevich
8eebb5bec1 Merge pull request #63522 from xedin/revert-type-wrappers
[AST/Sema/SIL] Revert TypeWrappers feature functionality
2023-02-09 09:27:18 -08:00
Pavel Yaskevich
e0bf2ff854 [SIL/DI] NFC: Remove TypeWrappers feature functionality 2023-02-08 10:14:29 -08:00
John McCall
dcf90ba3f3 Merge pull request #63512 from rjmccall/tuple_pack_element_addr
Add the tuple_pack_element_addr SIL instruction
2023-02-08 11:48:23 -05:00
Meghana Gupta
5d17c846fa Merge pull request #63475 from meg-gupta/ptrauthaddchanges
Misc changes to support import of structs with ptrauth qualified field function ptrs
2023-02-07 21:37:49 -08:00
John McCall
159c653780 Add the tuple_pack_element_addr SIL instruction.
This allows dynamically indexing into tuples.  IRGen not yet
implemented.

I think I'm going to need a type_refine_addr instruction in
order to handle substitutions into the operand type that
eliminate the outer layer of tuple-ness.  Gonna handle that
in a follow-up commit.
2023-02-07 23:22:35 -05:00
Meghana Gupta
a9ac6792a1 Additional sil verifier changes for importing structs with ptrauth qualified fields
Make sure we don't generate struct_extract for ptrauth qualified field
2023-02-07 00:17:48 -08:00
John McCall
27142e42f6 Add SIL instructions to get and set pack elements 2023-02-07 01:10:15 -05:00
Meghana Gupta
cbdf6e51ec Merge pull request #63323 from meg-gupta/ptrauthaddrdiversified4
Changes to support imported structs with ptruath qualified field function pointers
2023-02-02 09:19:29 -08:00
John McCall
6bf9ac858b Add instructions to allocate and deallocate packs.
Having added these, I'm not entirely sure we couldn't just use
alloc_stack and dealloc_stack.  Well, if we find ourselves adding
a lot of redundancy with those instructions (e.g. around DI), we
can always go back and rip these out.
2023-01-31 22:39:34 -05:00
Meghana Gupta
3a987cac67 Add verification for projections from structs with ptrauth qualified fields 2023-01-31 00:47:26 -08:00
John McCall
d25a8aec8b Add explicit lowering for value packs and pack expansions.
- SILPackType carries whether the elements are stored directly
  in the pack, which we're not currently using in the lowering,
  but it's probably something we'll want in the final ABI.
  Having this also makes it clear that we're doing the right
  thing with substitution and element lowering.  I also toyed
  with making this a scalar type, which made it necessary in
  various places, although eventually I pulled back to the
  design where we always use packs as addresses.

- Pack boundaries are a core ABI concept, so the lowering has
  to wrap parameter pack expansions up as packs.  There are huge
  unimplemented holes here where the abstraction pattern will
  need to tell us how many elements to gather into the pack,
  but a naive approach is good enough to get things off the
  ground.

- Pack conventions are related to the existing parameter and
  result conventions, but they're different on enough grounds
  that they deserve to be separated.
2023-01-29 03:29:06 -05:00
Doug Gregor
d192bfc7e5 Merge pull request #63125 from DougGregor/debug-info-dump-macro-expansion-buffers 2023-01-21 07:43:45 -08:00
Adrian Prantl
6335f1dee5 Debug Info: Represent macro expansions as inlined functions.
This allows the debugger to choose whether to display the expanded macro
(inlined) or the original source code (parent frame).

rdar://102916513
2023-01-20 21:43:20 -08:00
John McCall
374c202b99 Add SIL instructions to generate pack indices 2023-01-19 23:57:22 -05:00
John McCall
37baf9b2dc Add a SIL instruction to open a pack as an element archetype
IRGen not yet done.
2023-01-11 03:11:30 -05:00