Commit Graph

490 Commits

Author SHA1 Message Date
Jonas Devlieghere
5fbab9ddaa [Docs] Fix headings in SIL.rst
Fixes "Title underline too short." warning which is treated as an error.
2019-05-22 17:04:18 -07:00
Arnold Schwaighofer
56924d4962 Document dynamic_function_ref and prev_dynamic_function_ref 2019-05-22 09:13:11 -07:00
Erik Eckstein
2e01b0edeb SIL: add assign_by_delegate instruction
Used for property delegates.
2019-04-23 11:32:28 -07:00
Slava Pestov
1159af50d9 Rename -enable-resilience to -enable-library-evolution and make it a driver flag
Fixes <rdar://problem/47679085>.
2019-03-14 22:24:26 -04:00
Manu Sridharan
244a1f2fd7 Fix types in open_existential_addr / value
Result type for `open_existential_addr` should be `$*@opened P`.  Similar change for `open_existential_value`
2019-03-05 16:51:25 -08:00
Richard Wei
976a9c7fe2 [SIL.rst] Fix is_escaping_closure code block. 2019-02-17 02:47:17 -08:00
Robert Widmann
441c85fe98 Merge pull request #22499 from rex4539/fix-typos
Fix typos
2019-02-14 14:11:27 -05:00
Andrew Trick
cd78226f84 Merge pull request #21867 from LucianoPAlmeida/gardening-link-sil-docs
[gardening] Adding some links to SIL files
2019-02-13 16:28:32 -08:00
Dimitris Apostolou
d84048e555 Fix typos 2019-02-11 08:33:47 +02:00
Richard Wei
dcbb26cc6d Fix typo in SIL.rst: [stack] -> [on_stack]. 2019-01-28 05:09:55 -05:00
swift-ci
10f84f0f9b Merge pull request #21985 from gottesmm/pr-44903c025f4dedd6fcf95759f6512365cd8eb662 2019-01-18 15:30:04 -08:00
Michael Gottesman
3585d7d36d Make text clearer. 2019-01-18 13:49:45 -08:00
Michael Gottesman
5701eb33bb Update given John's feedback. 2019-01-18 13:43:47 -08:00
Michael Gottesman
cbb3f11909 [sil] Add clarity to how load_weak [take] and store_weak effect an objects weak ref count. 2019-01-18 13:18:59 -08:00
Arnold Schwaighofer
ccbf25b0a2 Merge pull request #21933 from aschwaighofer/partial_apply_stack
Use stack allocation for Swift closures
2019-01-18 10:35:46 -08:00
Gwynne Raskind
664e5659c5 Merge pull request #21910 from gwynne/drop-litre-references
Remove all references to unused LitRe tool
2019-01-16 18:49:55 -06:00
Arnold Schwaighofer
f664b16010 SIL: Add an on stack version of partial_apply
It does not take ownership of its non-trivial arguments, is a trivial
function type and therefore must not be destroyed. The compiler must
make sure to extend the lifetime of non-trivial arguments beyond the
last use of the closure.

  %objc = copy_value %0 : $AnObject
  %closure = partial_apply [stack] [callee_guaranteed] %16(%obj) : $@convention(thin) (@guaranteed AnObject) -> ()
  %closure2 = mark_dependence %closure : $@noescape @callee_guaranteed () -> () on %obj : $AnObject
  %user = function_ref @useClosure : $@convention(thin) (@noescape @callee_guaranteed () -> ()) -> ()
  apply %user(%closure2) : $@convention(thin) (@noescape @callee_guaranteed () -> ()) -> ()
  dealloc_stack %closure : $() ->()
  destroy_value %obj : $AnObject // noescape closure does not take ownership

SR-904
rdar://35590578
2019-01-15 11:20:33 -08:00
Luciano Almeida
ff51f4d307 Fix broken ref of HighLevelSILOptimizations.rst on SIL.rst 2019-01-15 01:35:59 -02:00
Luciano Almeida
50d0118463 Adding some links on SIL docs. 2019-01-15 01:29:54 -02:00
Jordan Rose
425c190086 Restore initializing entry points for @objc convenience initializers (#21815)
This undoes some of Joe's work in 8665342 to add a guarantee: if an
@objc convenience initializer only calls other @objc initializers that
eventually call a designated initializer, it won't result in an extra
allocation. While Objective-C /allows/ returning a different object
from an initializer than the allocation you were given, doing so
doesn't play well with some very hairy implementation details of
compiled nib files (or NSCoding archives with cyclic references in
general).

This guarantee only applies to
(1) calling `self.init`
(2) where the delegated-to initializer is @objc
because convenience initializers must do dynamic dispatch when they
delegate, and Swift only stores allocating entry points for
initializers in a class's vtable. To dynamically find an initializing
entry point, ObjC dispatch must be used instead.

(It's worth noting that this patch does NOT check that the calling
initializer is a convenience initializer when deciding whether to use
ObjC dispatch for `self.init`. If we ever add peer delegation to
designated initializers, which is totally a valid feature, that should
use static dispatch and therefore should not go through objc_msgSend.)

This change doesn't /always/ result in fewer allocations; if the
delegated-to initializer ends up returning a different object after
all, the original allocation was wasted. Objective-C has the same
problem (one of the reasons why factory methods exist for things like
NSNumber and NSArray).

We do still get most of the benefits of Joe's original change. In
particular, vtables only ever contain allocating initializer entry
points, never the initializing ones, and never /both/ (which was a
thing that could happen with 'required' before).

rdar://problem/46823518
2019-01-14 13:06:50 -08:00
Gwynne Raskind
687585eafa Docs: Remove all references to long-unused LitRe tool. Also incidentally removes redundant/duplicate check for sphinx-build binary. 2019-01-13 21:15:56 -06:00
Slava Pestov
6a507b460e Document non_abi linkage in SIL.rst 2019-01-02 18:00:05 -05:00
Brett Koonce
79fec2d230 minor spelling tweaks 2018-12-30 07:45:38 -08:00
Mike Ash
798edb9d0e [Runtime][Stdlib][Overlays] Rename various Objective-C classes and methods that would conflict when loading old Swift libraries into a process alongside ABI-stable libraries.
rdar://problem/35768222
2018-09-13 16:55:10 -04:00
Erik Eckstein
99a9ed5535 SIL: remove the pinning instructions: strong_pin, strong_unpin, is_unique_or_pinned
They are not used anymore after removing the pinning addressors.
2018-08-23 12:47:56 -07:00
Andrew Trick
c9033ed938 Add a SIL attribute [without_actually_escaping].
ConvertFunction and reabstraction thunks need this attribute. Otherwise,
there is no way to identify that withoutActuallyEscaping was used
to explicitly perform a conversion.

The destination of a [without_actually_escaping] conversion always has
an escaping function type. The source may have either an escaping or
@noescape function type. The conversion itself may be a nop, and there
is nothing distinctive about it. The thing that is special about these
conversions is that the source function type may have unboxed
captures. i.e. they have @inout_aliasable parameters. Exclusivity
requires that the compiler enforce a SIL data flow invariant that
nonescaping closures with unboxed captures can never be stored or
passed as an @escaping function argument. Adding this attribute allows
the compiler to enforce the invariant in general with an escape hatch
for withoutActuallyEscaping.
2018-08-14 17:14:25 -07:00
Jordan Rose
7d8acefd3d [docs] Update SIL.rst for the new verifier checks on enum instructions (#18450) 2018-08-01 13:12:18 -07:00
Andrew Trick
f6ba49e292 Add docs/SILDevelopment.rst.
Document SILFunction and `apply` arguments.

Create TBD headers to give the document some form.
2018-07-27 11:02:01 -07:00
kitasuke
8e591b0820 Fix wrong blockquote 2018-07-01 17:35:04 +09:00
Joe Shajrawi
93c036a77d Documentation: add entry for value_to_bridge_object 2018-05-22 17:15:43 -07:00
Andrew Trick
24c94f78fc Document begin/end access marker flags in SIL.rst. 2018-05-14 10:51:18 -07:00
Slava Pestov
e24fbbbc17 Fix formatting in SIL.rst 2018-05-01 17:40:53 -06:00
Arnold Schwaighofer
1f65ee25f6 Distinguish between withoutActuallyEscaping and passing @noescape
Objective C closures when reporting that a closure has escaped

rdar://39682865
2018-05-01 07:24:19 -07:00
Arnold Schwaighofer
678a99e76a Add a copy_block_without_escaping %block withoutEscaping %closure instruction
Mandatory pass will clean it up and replace it by a copy_block and
is_escaping/cond_fail/release combination on the %closure in follow-up
patches.

The instruction marks the dependence of a block on a closure that is
used as an 'withoutActuallyEscaping' sentinel.

rdar://39682865
2018-05-01 07:24:19 -07:00
Arnold Schwaighofer
28a869a916 Fix typo 2018-04-16 08:59:47 -07:00
Arnold Schwaighofer
b5308a6287 Add doc for convert_escape_to_noescape attributes 2018-04-13 14:26:33 -07:00
Arnold Schwaighofer
1e4f55de8d Merge pull request #15046 from aschwaighofer/without_actually_escaping_verification
Implement withoutActuallyEscaping verification
2018-03-09 09:34:06 -08:00
swift-ci
0b9c973017 Merge pull request #15077 from atrick/noescape-doc 2018-03-08 16:00:16 -08:00
Andrew Trick
2aebd75786 Document the @noescape SIL function type attribute. 2018-03-08 13:41:24 -08:00
Arnold Schwaighofer
e616f0a6a8 Add documentation to SIL.rst for convert_function to clarify escaping and not escaping types 2018-03-08 07:44:00 -08: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
John Eismeier
09452396cc Propose fixing some typos 2018-02-15 14:37:51 -05:00
Arnold Schwaighofer
d51053b003 Add convert_escape_to_noescape instruction for converting escaping to noescape functions
@noescape function types will eventually be trivial. A
convert_escape_to_noescape instruction does not take ownership of its
operand. It is a projection to the trivial value carried by the closure
-- both context and implementation function viewed as a trivial value.

A safe SIL program must ensure that the object that the project value is based
on is live beyond the last use of the trivial value. This will be
achieve by means of making the lifetimes dependent.

For example:

  %e = partial_apply [callee_guaranteed] %f(%z) : $@convention(thin) (Builtin.Int64) -> ()
  %n = convert_escape_to_noescape %e : $@callee_guaranteed () -> () to $@noescape @callee_guaranteed () -> ()
  %n2 = mark_dependence %n : $@noescape @callee_guaranteed () -> () on %e : $@callee_guaranteed () -> ()
  %f2 = function_ref @use : $@convention(thin) (@noescape @callee_guaranteed () -> ()) -> ()
  apply %f2(%n2) : $@convention(thin) (@noescape @callee_guaranteed () -> ()) -> ()
  release_value %e : $@callee_guaranteed () -> ()

Note: This is not yet actually used.

Part of:
SR-5441
rdar://36116691
2018-02-06 18:01:23 -08:00
Erik Eckstein
cd3d50a5d9 ABI: Change the mangling prefix from _T0 to $S 2018-01-06 13:55:59 -08:00
Chris Lattner
415cd50ba2 Reduce array abstraction on apple platforms dealing with literals (#13665)
* Reduce array abstraction on apple platforms dealing with literals

Part of the ongoing quest to reduce swift array literal abstraction
penalties: make the SIL optimizer able to eliminate bridging overhead
 when dealing with array literals.

Introduce a new classify_bridge_object SIL instruction to handle the
logic of extracting platform specific bits from a Builtin.BridgeObject
value that indicate whether it contains a ObjC tagged pointer object,
or a normal ObjC object. This allows the SIL optimizer to eliminate
these, which allows constant folding a ton of code. On the example
added to test/SILOptimizer/static_arrays.swift, this results in 4x
less SIL code, and also leads to a lot more commonality between linux
and apple platform codegen when passing an array literal.

This also introduces a couple of SIL combines for patterns that occur
in the array literal passing case.
2018-01-02 15:23:48 -08:00
Jordan Rose
8f8f00012a Merge pull request #12834 from jrose-apple/restrict-cross-module-struct-initializers-2
Implementation of SE-0189 "Restrict cross-module struct initializers to be delegating"

rdar://problem/34777878
2017-11-30 13:32:45 -08:00
Arnold Schwaighofer
e18bb9fad7 Fix SIL.rst 2017-11-13 07:38:46 -08:00
John McCall
045998544f Add begin_apply, abort_apply, and end_apply instructions to allow
yield_once coroutines to be executed.
2017-11-13 04:03:54 -05:00
Jordan Rose
1598a21e43 DI: Warn on non-delegating cross-module struct initializers
...as detected by initializing an individual field without having
initialized the whole object (via `self = value`).

This only applies in pre-Swift-5 mode because the next commit will
treat all cross-module struct initializers as delegating in Swift 5.
2017-11-09 11:24:28 -08:00
Erik Eckstein
934e0ea563 docs: fix title underlines 2017-11-07 13:49:36 -08:00