Commit Graph

458 Commits

Author SHA1 Message Date
Arnold Schwaighofer
4873f6c431 Fix assert 2019-05-22 10:16:05 -07:00
Andrew Trick
c1bda8f090 Replace AccessedStorage projection with an index.
Further simplify AccessedStorage. Shrink it to two words. Remove the
Projection abstraction and streamline the projection logic.
2019-05-14 12:44:46 -07:00
swift-ci
f243484180 Merge pull request #24716 from gottesmm/pr-ada147d650664b6f8f9c93845c53a9fab1380abf 2019-05-11 15:54:13 -07:00
Michael Gottesman
f385834823 [sil] When the immutable address use verifier errors due to an unknown instruction, print the instruction to improve debuggability. 2019-05-11 14:38:06 -07:00
Michael Gottesman
da37a56896 [sil] Change the immutable address use verifier to ignore br/cond_br uses that introduce address phis and re-enable the test that shows this behavior.
We want to eventually remove address phi arguments from SIL. This will enable
all sorts of nice IRGen optimizations and in general make life better. We are
not there yet, but given that is the direction we are going in, I don't think
there is much use in having to implement this sort of checking for SIL phi
arguments.

rdar://50676315
2019-05-11 14:37:11 -07:00
Michael Gottesman
afe3114d3d [sil] Expand immutable address verification to in_guaranteed parameters.
rdar://50212579
2019-05-09 23:01:43 -07:00
Michael Gottesman
293f49ed47 Merge pull request #24414 from gottesmm/pr-9e785198e1505f9322f31451df995019d47bb5d2
[sil] Refactor the open_existential_addr immutable use checking into …
2019-05-02 10:39:07 -07:00
Arnold Schwaighofer
aa376a4e66 Merge pull request #24224 from aschwaighofer/specialize_opaque_result_types
Add a pass to specialize opaque type archetypes.
2019-05-02 04:40:54 -07:00
Michael Gottesman
8925b5b510 [sil] Refactor the open_existential_addr immutable use checking into its own verifier utility.
My intention is to use this checker to also verify that in_guaranteed arguments
are used in the same manner immutably. Beyond improving that in_guaranteed
parameters are properly used immutably (which is just goodness), by using the
same check it ensures that we can always inline a callee into a caller with an
open_existential_addr without violating any check on the oea instruction.

I am doing this separately from adding more checks/applying it to
in_guaranteed/fixing some exposed bugs for ease of review. This change is
completely mechanical.

rdar://50212579
2019-05-01 13:57:25 -07:00
Michael Gottesman
4374754217 [sil] Teach the verifier that open_existential_addr immutable is safe to pass as Indirect_InoutAliasable.
We do not consider inout_aliasable to be "truly mutating" since today it is just
used as a way to mark a captured argument and not that something truly has
mutating semantics. The reason why this is safe is that the typechecker
guarantees that if our value was immutable, then the use in the closure must be
immutable as well.

In a future SIL, we want to remove Inout_Aliasable in favor of just using
inout/in_guaranteed using the capture info from the type checker.

rdar://50212579
2019-05-01 10:36:24 -07:00
Arnold Schwaighofer
cec1a5268e More fixes for opaque types specializer
* Opaque types are abi compatible with their substituted types
* Insert casts in more places
* Respect no optimization attribute
2019-05-01 09:31:07 -07:00
Erik Eckstein
2e01b0edeb SIL: add assign_by_delegate instruction
Used for property delegates.
2019-04-23 11:32:28 -07:00
Joe Groff
c771a7e71b SILGen: Substitute away opaque types. 2019-04-17 14:43:32 -07:00
Slava Pestov
1864f6f679 AST: Introduce ClassDecl::isSuperclassOf() 2019-03-26 18:42:59 -04:00
Michael Gottesman
0dfaa19f9f [ownership] Rename enable-sil-ownership => verify-sil-ownership.
I have been meaning to do this change for a minute, but kept on putting it off.
This describes what is actually happening and is a better name for the option.
2019-03-18 01:31:44 -07:00
Slava Pestov
8915f96e3e SIL: Replace SILType::isTrivial(SILModule) with isTrivial(SILFunction) 2019-03-12 01:16:04 -04:00
Slava Pestov
a3d8d9c9c8 SIL: Add a new overload of SILType::isTrivial() taking a SILFunction 2019-03-06 02:26:26 -05:00
Slava Pestov
980fb7c437 SIL: Remove default resilience expansion from isTypeABIAccessible() 2019-03-06 02:26:26 -05:00
Slava Pestov
5847e163c1 SIL: Use better type lowering APIs in a couple of spots 2019-03-05 20:59:58 -05:00
Slava Pestov
7b0d10e2c7 Merge pull request #23004 from slavapestov/sil-resilience-expansion-plumbing
Continue plumbing resilience expansion through SIL type lowering
2019-03-01 07:32:01 -05:00
Slava Pestov
903721cdc5 SIL: Remove SILType::getMetatypeInstanceType() 2019-03-01 02:07:16 -05:00
Slava Pestov
1944254253 SIL: Use SILFunction type lowering APIs in various places 2019-03-01 02:07:16 -05:00
David Zarzycki
b6b5ea5faa [AST] Reference ownership macro fixes and cleanup
This simplifies some boilerplate, and in particular, some SIL verifier
logic; and fixes a couple bugs related to always loadable reference
storage types.
2019-02-28 20:52:19 -05:00
Joe Groff
bb67cf815c Merge pull request #21355 from technicated/tuple-keypaths-2
Tuple KeyPaths
2019-02-25 12:56:05 -08:00
swift-ci
1a66c77110 Merge pull request #21067 from ravikandhadai/yieldcheck 2019-02-20 17:27:08 -08:00
Joe Groff
0cfca9496a Give opened archetypes a generic environment.
And maybe allow nested types to live on them.
2019-02-20 12:52:48 -08:00
Ravi Kandhadai
a9b0ebe542 [SIL Diagnostics] Create a mandatory pass to check correct usage of
yields in generalized accessors: _read and _modify, which are
yield-once corountines. This pass is based on the existing SIL verifier
checks but diagnoses only those errors that can be introduced by programmers
when using yields.

<rdar://43578476>
2019-02-19 18:25:47 -08:00
technicated
d7324b977e Added more tests
Testing SILGen & IRGen tuple keypath generation
Added tuple element type check in SILVerifier
2019-02-18 10:19:42 +01:00
Andrea Tomarelli
bf5943f9c2 Added some checks for KeyPathPatternComponent::Kind::TupleElement in SILVerifier::verifyKeyPathComponent 2019-02-18 09:04:43 +01:00
Andrea Tomarelli
17cf1360c4 Very minimal POC of tuple KP feature 2019-02-18 09:04:43 +01:00
Andrea Tomarelli
aab138dcea Barebone implementation of TupleElement in SIL 2019-02-18 09:04:42 +01:00
Michael Gottesman
391762f690 [sil] Tighten up SIL verification around when checked_cast_br should/shouldn't have failure arguments.
checked_cast_br in ownership SIL funnels through the original value to the
failure block as a SILArgument for cleanup purposes. In contrast, when SIL is
not in ossa, we do not want the failure bb case to have any arguments since that
is the pattern that SILOptimizer passes expect.

This commit just formalizes these constraints into the SILVerifier to catch
mistakes.
2019-02-10 21:59:09 -08:00
Doug Gregor
2d1fc680ed [SIL] Eliminate SILFunctionType::getDefaultWitnessMethodProtocol().
This method wasn’t returning the protocol on which the that the witness
method would satisfy, as documented. Rather, it was returning the protocol
to which the `Self` type conforms, which could be completely unrelated. For
example, in IndexingIterator’s conformance to IteratorProtocol, this method
would produce the protocol “Collection”, because that’s where the witness
itself was implemented. However, there isn’t necessarily a single such
protocol, so checking for/returning a single protocol was incorrect.

It turns out that there were only a few SIL verifier assertions of it
(that are trivially true) and two actual uses in code:
(1) The devirtualizer was using this computation to decide when it didn’t
need to perform any additional substitutions, but it’s predicate for doing
so was essentially incorrect. Instead, it really wanted to check whether
the Self type is still a type parameter. 
(2) Our polymorphic convention was using it to essentially check whether 
the ’Self’ instance type of a witness_method was a GenericTypeParamType,
which we can check directly.


Fixes rdar://problem/47767506 and possibly the hard-to-reproduce
rdar://problem/47772899.
2019-02-04 16:18:00 -08:00
Doug Gregor
0d36a1f6dc [SIL] The Self type of a protocol can conform to multiple protocols.
Through a same-type constraint on an associated type, the Self type of
a protocol can conform to multiple protocols that are not related by
direct inheritance. There were two places that incorrectly assumed
that this didn't happen:

1) The SIL verifier checked that the archetype for Self conformed to
only a single protocol. This only tripped up +Asserts builds, and had
no effect on code generation. Change it to ensure that the archetype
for Self conforms to the expected protocol.
2) SILFunctionType's getDefaultWitnessMethodProtocol() asserted that
the Self type of a protocol only conformed to a single protocol, and
then returned the first protocol in the list. This could end up
returning the wrong protocol, in turn producing an incorrect
substitution list in IRGen. Change it to return the protocol from the
constraint in the generic signature.

Fixes SR-9848 / rdar://problem/47767506.
2019-02-04 10:46:12 -08:00
Michael Gottesman
d012762d26 [sil] Ban passing non-trivial values to copy_value, destroy_value.
I also fixed a small violation in SILGenProlog/added a test for it.
2019-01-29 16:54:37 -08: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
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
eeckstein
3275f5618f Merge pull request #21614 from eeckstein/resilient-globalopt
GlobalOpt: optimize static properties with resilient types.
2019-01-04 13:21:41 -08:00
Erik Eckstein
5a91d13d78 SIL: make verification for loadable types more accurate regarding resilience.
Allow creating instructions with types which are only loadable in resilient functions (but not in all functions).
2019-01-04 11:21:25 -08:00
Arnold Schwaighofer
cb0c53abee SIL: Remove isEscapedByUser flag on convert_escape_to_noescape instruction
It was only used for materializeForSet and is now dead code.
2019-01-04 09:21:38 -08:00
Slava Pestov
d8cf20e3bc SIL: Fix oversight in switch_enum vs switch_enum_addr verification
Just like a switch_enum, switch_enum_addr must have a default case if
the enum is resilient from the current function.
2018-12-21 17:55:09 -05:00
Slava Pestov
d0e92f833d SIL: Verifier checks resilience invariants for class instructions 2018-12-21 17:54:51 -05:00
Slava Pestov
3f7eb019e0 SIL: Verifier checks resilience invariants for struct instructions 2018-12-21 17:54:39 -05:00
Slava Pestov
9c9ad09f15 SIL: Verifier checks resilience invariants for global variable instructions 2018-12-21 17:54:19 -05:00
Slava Pestov
5e617b5cb9 SIL: Verifier checks resilience invariants for keypath instruction 2018-12-21 17:53:28 -05:00
Slava Pestov
a3b266e2d5 SIL: Don't create witness table declarations when creating new SIL instructions
Another simplification made possible by the change to
SILModule::lookUpWitnessTable().
2018-12-20 17:36:38 -05:00
Michael Gottesman
23378cc16f [sil] Rename QualifiedOwnership => Ownership.
Done using Xcode's refactoring engine.
2018-12-16 15:21:52 -08:00
Joe Groff
89979137fc Push ArchetypeType's API down to subclasses.
And clean up code that conditionally works only with certain kinds of archetype along the way.
2018-12-12 19:45:40 -08:00
Arnold Schwaighofer
41e14ed38b We can't pass Objective-C methods as branch arguments 2018-12-11 10:26:44 -08:00
Slava Pestov
aa747dcd81 Remove property behaviors 2018-12-07 20:38:33 -05:00