Commit Graph

147 Commits

Author SHA1 Message Date
Erik Eckstein
3ec5d7de24 SIL: replace the is_escaping_closure instruction with destroy_not_escaped_closure
The problem with `is_escaping_closure` was that it didn't consume its operand and therefore reference count checks were unreliable.
For example, copy-propagation could break it.
As this instruction was always used together with an immediately following `destroy_value` of the closure, it makes sense to combine both into a `destroy_not_escaped_closure`.
It
1. checks the reference count and returns true if it is 1
2. consumes and destroys the operand
2025-01-24 19:23:27 +01:00
Michael Gottesman
6058b1d9bd [silgen] Change SILGen to emit ignored_user for emitIgnoredExpr and black hole initialization. 2025-01-22 21:12:36 -08:00
Michael Gottesman
c28ad4eaec [sil-mode.el] Add syntax highlighting for pack instructions. 2024-01-29 21:34:41 -08:00
Meghana Gupta
5d401fb70a Remove select_value SIL instruction 2023-06-13 14:13:43 -07:00
Michael Gottesman
65a9ba457c [sil-mode.el] Add syntax highlighting for noimplicit copy instructions. 2023-06-06 13:50:04 -04:00
Erik Eckstein
6b7ae416e6 SIL: remove unused instructions thin_function_to_pointer and pointer_to_thin_function 2022-03-25 15:44:59 +01:00
Michael Gottesman
f9122a79b7 [moveOnly] Implement a new _copy function that performs an explicit copy value.
The key thing is that the move checker will not consider the explicit copy value
to be a copy_value that can be rewritten, ensuring that any uses of the result
of the explicit copy_value (consuming or other wise) are not checked.

Similar to the _move operator I recently introduced, this is a transparent
function so we can perform one level of specialization and thus at least be
generic over all concrete types.
2021-10-29 15:37:46 -07:00
Erik Eckstein
7849f09e52 SIL: remove the unused alloc_value_buffer, project_value_buffer and dealloc_value_buffer instructions.
Those instructions were use for the materializeForSet implementation, which was replaced by modify-coroutines.
2021-10-07 07:41:54 +02:00
Michael Gottesman
5590c7b526 [sil] Add a move_value instruction.
This is a new instruction that can be used by SILGen to perform a semantic move
in between two entities that are considered separate variables at the AST
level. I am going to use it to implement an experimental borrow checker.

This PR contains the following:

1. I define move_value, setup parsing, printing, serializing, deserializing,
   cloning, and filled in all of the visitors as appropriate.
2. I added createMoveValue and emitMoveValueOperation SILBuilder
   APIs. createMoveValue always creates a move and asserts is passed a trivial
   type. emitMoveValueOperation in contrast, will short circuit if passed a
   trivial value and just return the trivial value.
3. I added IRGen tests to show that we can push this through the entire system.

This is all just scaffolding for the instruction to live in SIL land and as of
this PR doesn't actually do anything.
2021-09-12 11:07:42 -07:00
Michael Gottesman
694c1982bd [sil-mode.el] Improve handling of box types by sil-mode-display-function-cfg
Specifically, I changed how sil-mode-display-function-cfg searches for the
start/end of the SIL function body where the current point is. Previously, we
just searched for the exact strings "{" and "}" backwards and forwards
respectively. That was insufficient in the context of box types that use those
characters.

Instead with this change, we convert the aforementioned static search to a regex
search. Our regex match "{$" for the beginning of the SIL function and "^} //
end sil function '" or "^}" which I think will generally work to get the correct
body. NOTE: We first check for the end sil function variant.
2020-12-20 16:13:33 -08:00
Michael Gottesman
d287963c4d [sil-mode] Change viewcfg integration to specify dot as a renderer. 2020-08-26 19:27:42 -07:00
Michael Gottesman
5e36ae1c7c [sil] Add a forwarding cast called unchecked_value_cast.
Today unchecked_bitwise_cast returns a value with ObjCUnowned ownership. This is
important to do since the instruction can truncate memory meaning we want to
treat it as a new object that must be copied before use.

This means that in OSSA we do not have a purely ossa forwarding unchecked
layout-compatible assuming cast. This role is filled by unchecked_value_cast.
2020-07-09 21:14:32 -07:00
Michael Gottesman
7ee5ad7318 [sil] Rename {,Strong}Copy{Unowned,Unmanaged}. 2019-10-26 17:03:47 -07:00
Michael Gottesman
5fc1d1d349 [ownership] Define a new instruction copy_unmanaged_value.
This provides a singular instruction for convert an unmanaged value to a ref,
then strong_retain it. I expanded the definition of UNCHECKED_REF_STORAGE to
include these copy like instructions. This instruction is valid in all SIL.

The reason why I am adding this instruction is that currently when we emit an
access to an unowned (unsafe) ivar, we use an unmanaged_to_ref and a strong
retain. This can look to the optimizer like a strong retain that can potentially
be optimized. By combining the two together into a new instruction, we can avoid
this potential problem since the pattern matching will break.
2019-08-25 21:26:40 -07:00
Michael Gottesman
cc279da904 [sil-mode] Add highlighting for copy_block_without_escaping. 2019-02-25 11:51:44 -08:00
Michael Gottesman
0290cd4323 [sil] Eliminate end_borrow_argument now that end_borrow has a single operand.
I changed all of the places that used end_borrow_argument to use end_borrow.

NOTE: I discovered in the process of this patch that we are not verifying
guaranteed block arguments completely. I disabled the tests here that show this
bad behavior and am going to re-enable them with more tests in a separate PR.
This has not been a problem since SILGen does not emit any such arguments as
guaranteed today. But once I do the SILGenPattern work this will change.

rdar://33440767
2018-09-06 14:04:57 -07:00
Michael Gottesman
c599539044 [sil] Eliminate the src parameter from end_borrow.
This does not eliminate the entrypoints on SILBuilder yet. I want to do this in
two parts so that it is functionally easier to disentangle changing the APIs
above SILBuilder and changing the underlying instruction itself.

rdar://33440767
2018-09-04 16:38:24 -07:00
Erik Eckstein
c6eb5fe82a minor follow-ups for remove pinning in utilities and docs 2018-08-25 11:14:18 -07:00
Arnold Schwaighofer
5940796cc1 SIL: Add an is_escaping_closure instruction
Will be used to verify that withoutActuallyEscaping's block does not
escape the closure.

``%escaping = is_escaping_closure %closure`` tests the reference count. If the
closure is not uniquely referenced it prints out and error message and
returns true. Otherwise, it returns false. The returned result can be
used with a ``cond_fail %escaping`` instruction to abort the program.

rdar://35525730
2018-03-07 08:56:00 -08:00
Michael Gottesman
f8d90ec7c8 [sil-mode] Add syntax highlighting for convert_escape_to_noescape 2018-02-22 21:02:22 -08:00
Michael Gottesman
bd44cc85be [sil-mode] Add highlighting for ref_tail_addr instruction. 2018-01-02 13:35:00 -05:00
Michael Gottesman
696cd13cdb [sil-mode] Add highlighting for objc_protocol. 2017-10-25 14:25:47 -07:00
Michael Gottesman
36a8d0d5c0 [sil] Add support for the destructure_{struct,tuple} instructions.
rdar://31521023
2017-10-24 18:36:37 -07:00
Slava Pestov
0acf3ac8d9 SIL: Remove is_nonnull instruction 2017-10-13 17:38:32 -07:00
Andrew Trick
4db2a46cff Add SIL instruction: open_existential_box_value.
This has the same semantics as open_existential_box, but returns an object value
instead of an address.

This is used in SIL opaque values mode. Attempting to reuse open_existential_box
in this mode causes SIL type inconsistencies that are too difficult to work
around. Adding this instruction allows for consistent handling of opaque values.

The original versions of several of these currently redundant instructions will
be removed once the SIL representation stabilizes.
2017-07-17 23:46:41 -07:00
Andrew Trick
f657ad2d3a Rename *ExistentialOpaque instructions to *ExistentialValue.
These instructions have the same semantics as the *ExistentialAddr instructions
but operate directly on the existential value, not its address.

This is in preparation for adding ExistentialBoxValue instructions.
The previous name would cause impossible confusion with "opaque existentials"
and "opaque existential boxes".
2017-07-17 23:46:41 -07:00
Michael Gottesman
f81d714d45 [sil-mode] Add viewcfg support.
This adds a new function called sil-mode-display-function-cfg. This simply
function grabs the current function body by searching forward/backward for '{'
and '}' and sends the region to viewcfg.

*NOTE* This currently like the vim version requires viewcfg to be in your path.
It is possible that we could add support for swift-project-settings and just
infer this value directly.
2017-07-03 10:27:28 -07:00
Michael Gottesman
fd8030cc52 [sil-mode] Some small comment fixes. 2017-07-03 10:27:27 -07:00
Michael Gottesman
c3086ff747 [sil-mode] Somehow release_value got replaced with retain_value.
Previously somehow we had two instances of retain_value in this list...
2017-07-03 10:27:27 -07:00
Michael Gottesman
0df0e586f6 [sil-mode] Add a syntax highlighting for begin_access, end_access. 2017-05-09 11:56:02 -07:00
Joe Shajrawi
0d0cac357a retain_value_addr and release_value_addr SIL instructions: take as an input an address, load the value inside it and call retain_value and release_value respectively 2017-04-30 10:23:55 -07:00
Joe Shajrawi
33b0cf653f Rename unconditional_checked_cast_opaque to unconditional_checked_cast_value 2017-03-07 18:53:52 -08:00
Michael Gottesman
141817c513 [sil-mode] Fix highlighting of end_borrow so that it supports highlighting when a borrowed register has more than 1 alphanum in its register id. 2017-03-06 20:39:31 -08:00
Joe Shajrawi
ca77872ba8 Merge CheckedCastValueBranch with new master 2017-03-06 17:32:09 -08:00
Joe Shajrawi
1f626304f1 Add support for conditional checked cast instruction for opaque value types + SILGen support for it 2017-03-06 16:35:27 -08:00
Michael Gottesman
cfb5893663 [silgen] Fix destroying destructor to use proper ownership with its @owned return value.
rdar://29791263
2017-03-02 17:17:17 -08:00
Michael Gottesman
4bc12aedbd [sil] Add end_lifetime.
This is the lifetime ending variant of fix_lifetime. It is a lie to the
ownership verifier that a value is being consumed along a path. Its intention is
to be used to allow for the static verification of ownership in deallocating
deinits which for compatibility with objective-c have weird ownership behavior.
See the commit merged with this commit for more information.
2017-03-01 18:30:23 -08:00
Michael Gottesman
dc21218a89 [sil-mode] Change [attribute] highlighting to use a non-greedy + so that [take] [initialization] does not hightlight the ][ in between the two. 2017-02-27 21:26:22 -05:00
Joe Shajrawi
16b6cb5e1d Support for deinit of opaque existentials: deinit_existential_opaque instruction + SILGen support 2017-02-27 14:46:43 -08:00
Joe Shajrawi
ec1e3ee20e Add support for unconditional checked cast instruction for opaque value types + SILGen support for it 2017-02-22 16:35:46 -08:00
Joe Shajrawi
1e521c453b Add support for Init Existentials for opaque value types 2017-02-20 16:40:02 -08:00
Joe Shajrawi
c478828de7 Support for Open Existentials that do no take an address 2017-02-09 11:25:34 -08:00
Michael Gottesman
554feff463 [semantic-sil] Create unmanaged_autorelease_value.
This is an autorelease for use with Builtin.autorelease that does not need to be
balanced as part of the ownership model.

rdar://29791263
2017-02-06 12:11:46 -08:00
Michael Gottesman
9202a80442 [sil-mode] Add highlighting for dealloc_existential_box. 2017-01-25 18:03:05 -08:00
Michael Gottesman
d045f20867 [semantic-sil] Add a new instruction end_borrow_argument.
I need this instruction in order to model the end of life of a guaranteed phi
arguments.

rdar://29791263
2017-01-22 20:46:25 -08:00
Michael Gottesman
2da18c7b47 [semantic-sil] Add special unmanaged_{retain,release}_value instructions for unpaired retain/release operations in semantic sil.
The reason why I am introducing special instructions is so I can maintain the
qualified ownership API wedge in between qualified SIL and the rest of the ARC
instructions that are pervasively used in the compiler.

These instructions in the future /could/ be extended to just take @sil_unmanaged
operands directly, but I want to maintain flexibility to take regular
non-trivial operands in the short term.

rdar://29791263
2017-01-19 13:23:08 -08:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Michael Gottesman
6213550239 [semantic-sil] Create copy_unowned_value.
This was in the first high level ARC instruction proposal, but I have not needed
it until now. The use case for this is to ahandle strong_retain_unowned (which
takes in an unowned value, asserts it is still alive, performs a strong_retain,
and returns the @owned value). This @owned value needs a destroy_value.

rdar://29671437
2016-12-14 19:22:24 -08:00
Michael Gottesman
66cff7e37e [semantic-arc] Add StoreBorrowInst and BeginBorrowInst. 2016-12-12 13:06:18 -08:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00