Commit Graph

694 Commits

Author SHA1 Message Date
Nate Chandler
570a58385d [NFC] Tweaked memory verifier require messages.
Grammar.
2022-12-09 11:16:30 -08:00
Nate Chandler
7430c6142f [SIL] Verified yielded addresses.
For yielded, nontrivial addresses, verify based on convention:
- guaranteed -> must be initialized at end_apply/abort_apply
- owned -> must be deinitialized at end_apply/abort_apply
- inout -> must be initialized at end_apply/abort_apply
2022-12-07 18:51:50 -08:00
nate-chandler
d069fff105 [SILDebugInfo] Only print under !NDEBUG. (#62325) 2022-11-30 13:11:50 -08:00
swift-ci
fbb1c0f011 Merge pull request #62181 from nate-chandler/nfc/20221118/1
[SILDebugInfo] Small tweaks.
2022-11-29 22:48:53 -08:00
Erik Eckstein
ab1b343dad use new llvm::Optional API
`getValue` -> `value`
`getValueOr` -> `value_or`
`hasValue` -> `has_value`
`map` -> `transform`

The old API will be deprecated in the rebranch.
To avoid merge conflicts, use the new API already in the main branch.

rdar://102362022
2022-11-21 19:44:24 +01:00
Nate Chandler
a191795c2b [NFC] Simplified isAncestorScope.
Clarified preconditions, removed spurious explicit typing, and suprious
control flow.
2022-11-18 08:38:46 -08:00
Nate Chandler
0120f13bd4 [SILVerifier] Log on bad debug-info.
Previously, logging of the actually problematic instruction was guarded
by LLVM_DEBUG.  Meanwhile the verifier's require method prints an
instruction (usually one different from that at which the non-contiguous
scope was encountered).

Here, instead, the problematic instruction and the instruction which
defined the previous scope are printed to llvm::errs always (i.e.
whenever verification is actually run).

Additionally, debug-info logging is forcibly set on upon failure so that
the logs clearly show both what the previous scope was, what the current
scope is, and what instructions defined them.
2022-11-18 08:38:46 -08:00
Meghana Gupta
6471188d46 Merge pull request #61883 from meg-gupta/lbisuniq
LoadBorrowImmutabilityVerifier: Mark is_unique as a write
2022-11-02 16:06:45 -07:00
Meghana Gupta
ce332b9578 LoadBorrowImmutabilityVerifier: Mark is_unique as a write 2022-11-02 12:45:10 -07:00
Allan Shortlidge
5053055362 CMake: Break dependency cycles involving Sema. 2022-10-29 15:10:39 -07:00
Meghana Gupta
b26225c4d0 Merge pull request #61724 from meg-gupta/revertaddrphi
Revert changes to ArrayPropertyOpt to avoid address phis
2022-10-26 10:14:29 -07:00
Meghana Gupta
c9c9036c4e Revert "Ban address phis in non-OSSA SIL"
This reverts commit 035f062e69.
2022-10-25 11:10:52 -07:00
Meghana Gupta
3616fc6b53 Revert "Add verification to ensure we don't have redundant borrow scopes for @guaranteed forwarding phis"
This reverts commit dfbb2bd62a.
2022-10-21 22:31:04 -07:00
Becca Royal-Gordon
82d78a384f Merge pull request #60630 from beccadax/at-implementation
Add @_objcImplementation
2022-10-20 17:14:21 -07:00
Meghana Gupta
283f15e418 Remove dead code in LoadBorrowImmutabilityChecker 2022-10-19 19:55:17 -07:00
Meghana Gupta
ebd7a90587 NFC: Remove unused code + reorg 2022-10-19 19:54:28 -07:00
Meghana Gupta
786eb94853 Support @guaranteed forwarding phis 2022-10-19 19:54:27 -07:00
Meghana Gupta
dfbb2bd62a Add verification to ensure we don't have redundant borrow scopes for @guaranteed forwarding phis 2022-10-19 19:54:27 -07:00
Meghana Gupta
b1f719709b Rename ForwardingBorrow -> GuaranteedForwarding 2022-10-19 19:54:27 -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
36c01e80cc Merge pull request #61537 from hborla/variadic-generics-terminology
[AST] Use consistent variadic generics terminology.
2022-10-13 16:20:43 -04:00
Meghana Gupta
f7e7fed2df Use AccessPath exact use visitor in LoadBorrowImmutabilityChecker 2022-10-11 15:53:43 -07:00
Holly Borla
9bb837a241 [AST] Rename SequenceArchetype to PackArchetype. 2022-10-10 16:25:26 -07:00
Andrew Trick
eee184ae4e Delete isValueAddressOrTrivial
If we want a short-circuit test for address types, that should be done
within getOwnershipKind() itself.
2022-10-05 06:30:02 -07:00
Andrew Trick
52b87c25cf Temporarily disable a SILVerifier unit test.
We can't verify that store borrows aren't nested until we can reliably
compute liveness.

This can be fixed in two ways, both of which we plan to do ASAP:

 (1) With complete lifetimes, this no longer needs to perform transitive
 liveness at all.

 (2) findInnerTransitiveGuaranteedUses, which ends up being called on the
 load_borrow to compute liveness, can be taught to transitively process
 InteriorPointer uses instead of returning PointerEscape. We need to make
 sure all uses of the utility need to handle this first.
2022-10-04 13:27:47 -07:00
Andrew Trick
619a638e34 ScopedAddressUtils - clarify the API used for transitive liveness.
Begin to distnguish logic that relies on complete OSSA lifetimes from
the logic that computes transitive uses.
2022-10-04 13:27:47 -07:00
Andrew Trick
464e353028 Fix ScopedAddressValue::computeLiveness.
Return the AddressUseKind.

Fixes a bug in extendStoreBorrow where it was looking at an
uninitialized liveness result whenever a pointer escape was present.
2022-10-04 13:27:47 -07:00
Andrew Trick
40e03ef782 Update passes to use SSAPrunedLiveness or MultiDefPrunedLiveness 2022-10-04 13:27:47 -07:00
Andrew Trick
ca503b54b7 Redesign PrunedLiveness APIs, introducing live ranges
First restore the basic PrunedLiveness abstraction to its original
intention. Move code outside of the basic abstraction that polutes the
abstraction and is fundamentally wrong from the perspective of the
liveness abstraction.

Most clients need to reason about live ranges, including the def
points, not just liveness based on use points. Add a PrunedLiveRange
layer of types that understand where the live range is
defined. Knowing where the live range is defined (the kill set) helps
reliably check that arbitrary points are within the boundary. This
way, the client doesn't need to be manage this on its own. We can also
support holes in the live range for non-SSA liveness. This makes it
safe and correct for the way liveness is now being used. This layer
safety handles:

- multiple defs
- instructions that are both uses and defs
- dead values
- unreachable code
- self-loops

So it's no longer the client's responsibility to check these things!

Add SSAPrunedLiveness and MultiDefPrunedLiveness to safely handle each
situation.

Split code that I can't figure out into
DiagnosticPrunedLiveness. Hopefully it will be deleted soon.
2022-10-04 13:27:44 -07:00
Pavel Yaskevich
df87a494c2 [SIL] Add originator to assign_by_wrapper instruction
Originator of this temporary instruction could be either
type or property wrapper.
2022-09-29 20:50:36 -07:00
Meghana Gupta
035f062e69 Ban address phis in non-OSSA SIL 2022-09-12 11:26:01 -07:00
Michael Gottesman
467b742a5c [move-only] Update the non-address move checker part of the optimizer to handle mark_must_check on addresses. 2022-09-09 13:38:18 -07:00
Meghana Gupta
3bcf41e141 Revert "Ban address phis in non-OSSA as well"
This reverts commit 923c62c932.
2022-09-09 09:31:34 -07:00
Meghana Gupta
24dfb18666 Merge pull request #60763 from meg-gupta/looprotateaddressphi
Ban address phis in non-OSSA SIL
2022-09-07 15:13:35 -07:00
Meghana Gupta
923c62c932 Ban address phis in non-OSSA as well 2022-09-05 23:42:28 -07:00
Michael Gottesman
9d92d40060 [move-only] Move most move only passes earlier in the pass pipeline before Mandatory Inlining, right after DI. 2022-09-05 20:41:44 -07:00
Michael Gottesman
4dc6e6ecc4 [move-keyword] Remove old implementation.
By using the keyword instead of the function, we actually get a much simpler
implementation since we avoid all of the machinery of SILGenApply. Given that we
are going down that path, I am removing the old builtin implementation since it
is dead code.

The reason why I am removing this now is that in a subsequent commit, I want to
move all of the ownership checking passes to run /before/ mandatory inlining. I
originally placed the passes after mandatory inlining since the function version
of the move keyword was transparent and needing to be inlined before we could
process it. Since we use the keyword now, that is no longer an issue.
2022-09-04 01:19:01 -07:00
Alejandro Alonso
315ee2a167 Fix tuple keypath verifier (#60737) 2022-08-26 15:28:59 -07:00
Meghana Gupta
f2d9bc7bf6 Add dealloc_stack_ref as a non-write in LoadBorrowImmutabilityAnalysis 2022-08-19 09:46:53 -07:00
Meghana Gupta
1761fc2406 Consider store_borrow as a write in LoadBorrowImmutabilityChecker 2022-08-17 16:26:17 -07:00
Meghana Gupta
5244e6f3d5 Improve verification for store_borrow
Add ScopedAddressOperand and ScopedAddressValue abstraction utilities
Introduce verification for store_borrow to validate its uses are correctly enclosed in their scope.

Include end_borrow/end_access as implicit uses while validating a borrow introducer

Add flow sensitive verifier rule for store_borrow/end_borrow pair

Make sure store_borrow is always to an alloc_stack

Make sure uses to store borrow location are via its return address only
2022-08-16 15:08:22 -07:00
nate-chandler
feecc515d2 Merge pull request #60478 from nate-chandler/lexical_lifetimes/optimize_more_alloc_stack_destroys
[SILOpt] Hoist destroys for non-lexical alloc_stacks more aggressively.
2022-08-15 10:36:24 -07:00
Nate Chandler
3df609f756 [SILVerifier] Check lex borrows of box instances.
Require that lexical borrows of values which are instances of some
SILBoxType guard the lifetime of vars or closure captures; that's to
say, of AllocBoxInsts and SILFunctionArguments.

Look through a few instructions types to find those:
- copy_value - inserted by SILGen
- begin_borrow - inserted during inlining
- mark_uninitialized - inserted by SILGen
2022-08-12 11:37:19 -07:00
Michael Gottesman
64a984bca9 [move-only] Validate in the SILVerifier that we only have copy_addr [init]/load [copy] on move only values in Raw SIL.
This is already an invariant for copy_value and now that I am implementing move
semantics for addresses, it makes sense to ban those in a similar
way. Specifically, we are enforcing the invariant that move only types are
allowed to be copied in Raw SIL, but not in later parts of SIL. For those who
are unaware, we then run checkers later to validate that we preserve ownership
semantics.
2022-08-11 10:15:47 -07: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
Michael Gottesman
1e6187c4f4 [sil] Update all usages of old API SILValue::getOwnershipKind() in favor of new ValueBase::getOwnershipKind().
Andy some time ago already created the new API but didn't go through and update
the old occurences. I did that in this PR and then deprecated the old API. The
tree is clean, so I could just remove it, but I decided to be nicer to
downstream people by deprecating it first.
2022-07-26 11:46:23 -07:00
Michael Gottesman
afd8accb75 [move-only] Add a move only request to lookup if a ValueDecl is a "move only type".
I also created a SILType::isMoveOnly() helper that returns true if a type is
a move only wrapped type or a first class move only type. The verifier check
that move only types aren't copied in canonical SIL was rewired to use that as well.
2022-07-21 15:33:17 -07:00
Michael Gottesman
f1182a73da [no-implicit-copy] Remove auto +1 param signature change called by noimplicit copy in favor of following normal convention.
I also added a bunch of tests for both the trivial/non-trivial case as well as
some docs to SIL.rst.
2022-07-19 16:39:03 -07:00
Michael Gottesman
9b625588f0 [sil] Make copyable_to_moveonlywrapper forwarding like moveonlywrapper_to_copyable.
Specifically this means that rather than always being owned, we now have owned
and guaranteed versions of copyable_to_moveonlywrapper. Similar to
moveonlywrapper_to_copyable, one chooses which variant one gets by using
specific SILBuilder APIs:
create{Owned,Guaranteed}CopyableToMoveOnlyWrapperValueInst. It is still
forwarding and the rest of the forwarding APIs work as expected except that the
forwarding ownership is fixed (and an assertion will result if one attempts to
do so).

NOTE: It is assumed that trivial operands are always passed to the owned
variant.
2022-07-19 14:39:59 -07:00
Doug Gregor
43399bad78 Make sure we propagate @preconcurrency to closures consistently.
The type checker is now permitting `@Sendable` closures whose captures
can be by-reference, because we do not error. Remove an aspirational
SIL verifier check that banned this.
2022-07-01 15:29:49 -07:00