Commit Graph

458 Commits

Author SHA1 Message Date
Mark Lacey
d63bb3fc53 Remove most uses of OptionalTypeKind.
What remains are places where we are conflating optionality with
either nullability or failability.
2018-02-10 16:24:09 -08:00
swift-ci
f31db98c4f Merge remote-tracking branch 'origin/master' into master-next 2018-02-07 05:29:51 -08: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
swift-ci
67e4edf809 Merge remote-tracking branch 'origin/master' into master-next 2018-02-06 06:09:32 -08:00
Mark Lacey
b4b66bc8e8 Replace getAnyOptionalObjectType with getOptionalObjectType. 2018-02-05 23:59:00 -08:00
swift-ci
54c9ce7d76 Merge remote-tracking branch 'origin/master' into master-next 2018-01-25 08:49:40 -08:00
Davide Italiano
59aea90ef3 Merge pull request #14138 from dcci/hotfixes
[Master-next] Update after recent breaking changes
2018-01-24 15:21:04 -08:00
Davide Italiano
5d9d8c4257 [Verifier] Update a check now that memcpy takes 3 arguments. 2018-01-24 15:13:56 -08:00
Arnold Schwaighofer
f8d7b9c743 Update comment per review 2018-01-24 14:51:02 -08:00
Arnold Schwaighofer
737d568a72 SIL: Fix zealous assert in verifier
A materialize for set / write-back sequence is not really mutating the opened existential

rdar://36799163
2018-01-24 13:43:57 -08:00
Davide Italiano
4cc84f5da3 [Verifier] Check that AST type matches the SIL type before lowered stage.
Just like we do for other instructions (checkTupleExtractInst for example).
This fixes a verifier with -sil-verify-all.

<rdar://problem/36559617>
2018-01-18 13:53:26 -08:00
Davide Italiano
a4dba76467 [DebugInfo] Add a verifier pass to find holes in lexical scopes.
This found a bunch of issues where we didn't properly preserve
debug infos which have been fixed over the course of the past
two weeks.

The basic idea is we want to make sure that within a BB we never
have `holes` in debug scopes, i.e. if we enter a scope, one of
the two holds

1) We never visited that scope before
2) We're re-entering a scope that is an ancestor of the scope
   currently leaving. This is needed to correctly model nested
   scopes, e.g.
    {
      let i = 0; // scope 0
      if (cond) {
        let j = i // scope 1
      }
      let k = i + 1 // scope 0 and okay.
    }

I also checked in a `cl::opt`, so that if this breaks something,
it can be conveniently disabled. This is currently not enabled
as we flesh out the last violations.

<rdar://problem/35816212>
2018-01-17 15:25:44 -08:00
Michael Gottesman
adf63e0ac4 Improve a FIXME.
We want this once mark_uninitialized is on the allocation instead of on the
project_box. We aren't there yet though.
2018-01-15 13:46:51 -08:00
Slava Pestov
f8ceae8aef SIL: Remove isLessVisibleThan()
Another cleanup before I add a new SILLinkage kind.

This operation is difficult to reason about and was only used by
the SIL verifier. Replace the SIL verifier checks with simpler
operations.

I still need to revisit and uncomment the default witness table
visibility check. Right now we serialize default witness tables,
but default witness thunks have private linkage, which is
clearly wrong.
2018-01-13 01:03:48 -08:00
Slava Pestov
48d0407f43 SIL: Remove SILFunction::{is,set}KeepAsPublic() 2018-01-12 22:08:00 -08:00
John McCall
7f0f8830cd Split AccessorDecl out from FuncDecl. NFC.
This has three principal advantages:

- It gives some additional type-safety when working
  with known accessors.

- It makes it significantly easier to test whether a declaration
  is an accessor and encourages the use of a common idiom.

- It saves a small amount of memory in both FuncDecl and its
  serialized form.
2018-01-12 14:20:27 -05:00
Devin Coughlin
d5e6e3239c [Exclusivity] Extend SILVerifier for init_block_storage_header for exclusivity
Extend the SIL verifier to check for the assumptions that the static exclusivity
diagnostics make about conversions from noescape closures to noescape blocks.
Soundness of the static diagnostics requires that the analysis can locally
determine when a noescape closure is converted to a noescape and then
passed to a function.
2018-01-07 20:01:04 -08:00
Michael Gottesman
5263e9e74e [sil] Eliminate redundant method SILFunction::hasUnqualifiedOwnership().
We can just !SILFunction::hasQualifiedOwnership(). Plus as Andy pointed out,
even ignoring the functional aspects, having APIs with names this close can
create confusion.
2017-12-02 17:42:34 -08:00
Slava Pestov
1f79af7504 SIL: Use objc_method instruction for Objective-C protocol method calls
Fixes <rdar://problem/15933365>.
2017-11-29 16:26:43 -08:00
Arnold Schwaighofer
ea9907ae15 Revert "SIL: Use objc_method instruction for Objective-C protocol method calls" 2017-11-29 11:19:46 -08:00
Slava Pestov
a3b1308c76 Merge pull request #13139 from slavapestov/no-more-volatile-witness-method
SIL: Use objc_method instruction for Objective-C protocol method calls
2017-11-29 02:12:46 -08:00
Slava Pestov
1ee0970934 SIL: Use objc_method instruction for Objective-C protocol method calls
Fixes <rdar://problem/15933365>.
2017-11-29 01:22:05 -08:00
Michael Gottesman
566f3d1cae [sil] Move determining if two SILFunctionTypes are ABI compatible from the verifier onto SILFunctionType itself.
Right now if convert_function is used incorrectly by SILGen, we get an error via
the SILVerifier after we have finished building the entire function. This is a
pain in the butt to track down. Using this refactor, I am able to just assert in
the SILBuilder itself.

On another note, down the line we should just separate the dataflow checker part
of the verifier from specific SILInstruction verification. This would allow for
SILBuilder to perform the SILInstruction verification upon creation giving the
same effect. Such a change is a much larger change though and this is just a
commit chopped off a larger commit.

rdar://34222540
2017-11-28 20:10:37 -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
John McCall
aff457381c Change ApplyInstBase to not try to handle trailing objects itself. NFC.
The goal is to make it more composable to add trailing-objects fields in
a subclass.

While I was doing this, I noticed that the apply instructions provided
redundant getNumArguments() and getNumCallArguments() accessors, so I
went ahead and unified them.
2017-11-13 04:03:21 -05:00
John McCall
7743be30f6 Add a "token" type to SIL to allow dependencies to be expressed without
allowing abstraction.
2017-11-13 04:03:21 -05:00
John McCall
14d6390352 Add "yield" and "unwind" instructions to SIL. 2017-11-07 03:51:54 -05:00
John McCall
5c33d2106a Add simple accessor/generator coroutine support to SILFunctionType. 2017-11-07 01:50:12 -05:00
Davide Italiano
1ebaee199f Merge pull request #12519 from dcci/noabort
[SILVerifier] Add a flag to not abort upon verification failure.
2017-10-23 20:11:43 -07:00
swift-ci
44e3e17627 Merge pull request #12583 from gottesmm/pr-e194681a009c5227d83b0062a44d05474bdc1801 2017-10-23 10:26:35 -07:00
Michael Gottesman
c3182d17ef [gardening] Replace else-if with early returns and sink computation of ownership in the SILVerifier.
Noticed this while doing other work. Just chopping it off to ease review on the
larger patch.
2017-10-23 10:00:56 -07:00
Roman Levenstein
d86ef3b7e3 Add [serialized] flag to sil_vtables 2017-10-21 19:18:15 -07:00
Davide Italiano
98992dfc60 [SILVerifier] Add a flag to exit instead of aborting on failure.
This matches what LLVM does, and makes testing/fuzzing easier.
It's also slightly more friendly in case the user violates an
assumption. It can't be turned on by default (yet) because it's
important to crash on verification failures, when running swiftc
in a debugger.
2017-10-21 18:13:21 -07:00
Davide Italiano
ff402cf47c [SIL] Enforce dominance property of the entry block.
An entry block can't have predecessors. I'll commit a
test as a follow-up to make sure this doesn't regress.
2017-10-19 09:12:38 -07:00
Joe Shajrawi
b9c93bde47 Relax the open_existential_addr immutable_access verifier further after sil-combine bail-out 2017-10-17 00:26:06 -07:00
Slava Pestov
0acf3ac8d9 SIL: Remove is_nonnull instruction 2017-10-13 17:38:32 -07:00
Joe Shajrawi
89cb274717 Merge pull request #12356 from shajrawi/sil_combine_bugfix_v2
Fixes a bug in SILCombiner that caused a use-after-free
2017-10-10 16:29:39 -07:00
Joe Shajrawi
ac8a48b2c2 Fixes a bug in SILCombiner that caused a use-after-free 2017-10-10 13:40:14 -07:00
Doug Gregor
1f1b75a56d [AST] Eliminate ModuleDecl parameters from GenericSignature. 2017-10-10 10:01:39 -07:00
Slava Pestov
6def545696 AST: Remove GenericEnvironment::containsPrimaryArchetype()
This is no longer necessary now that archetypes refer back to a
GenericEnvironment.
2017-10-07 04:46:37 -07:00
Slava Pestov
e806b6248d SIL: Remove dynamic_method instruction 2017-10-04 03:53:16 -07:00
Slava Pestov
aceb620595 SIL: Relax invariants on objc_method, allowing it to be used for dynamic method calls 2017-10-04 03:53:16 -07:00
Slava Pestov
7bf3b90b62 SIL: Split off objc_method / objc_super_method from class_method / super_method
This replaces the '[volatile]' flag. Now, class_method and
super_method are only used for vtable dispatch.

The witness_method instruction is still overloaded for use
with both ObjC protocol requirements and Swift protocol
requirements; the next step is to make it only mean the
latter, also using objc_method for ObjC protocol calls.
2017-10-03 22:13:31 -07:00
Jordan Rose
b6c28b02d0 [SIL] Remove the builtins related to UnknownObject.
No functionality change; nothing is using them.
2017-10-02 09:05:31 -07:00
Roman Levenstein
c15ffa0571 Some fixes for the Serialized attribute of pre-specializations
Pre-specializations need some special handling when it comes to the Serialized attribute. Their bodies should not be SIL serialized. Instead, only their declarations should be serialized.

And since their bodies are not serialized and cannot be imported by the client code, it is OK if pre-specializations reference non-fragile functions inside their bodies. Due to the same reason, it is fine if pre-specializations are referenced from fragile functions, even though these pre-specializations are not fragile in a usual sense.
2017-09-29 12:45:31 -07:00
John McCall
ab3f77baf2 Make SILInstruction no longer a subclass of ValueBase and
introduce a common superclass, SILNode.

This is in preparation for allowing instructions to have multiple
results.  It is also a somewhat more elegant representation for
instructions that have zero results.  Instructions that are known
to have exactly one result inherit from a class, SingleValueInstruction,
that subclasses both ValueBase and SILInstruction.  Some care must be
taken when working with SILNode pointers and testing for equality;
please see the comment on SILNode for more information.

A number of SIL passes needed to be updated in order to handle this
new distinction between SIL values and SIL instructions.

Note that the SIL parser is now stricter about not trying to assign
a result value from an instruction (like 'return' or 'strong_retain')
that does not produce any.
2017-09-25 02:06:26 -04:00
Slava Pestov
6478256b20 SIL: Relax some verifier checks when merging partial modules
When merging partial SIL modules we only link in function bodies defined
in the current module, so we might encounter functions with shared
linkage and no body.

Since pulling in these functions from other modules is a waste of time,
run the verifier in "single function" mode in this case.

Note that when the module is ultimately used and one of these functions
is deserialized, we should link in all downstream functions with shared
linkage, and failure to do so will be caught by the SIL verifier then.

Fixes <rdar://problem/34469704>.
2017-09-18 23:59:23 -07:00
Erik Eckstein
fb935a3d49 SIL: support statically initialized StaticString globals
The main part of the change is to support the ptr_to_int builtin in statically initialized globals. This builtin is used to build a StaticString from a string_literal.
On the other hand I removed the support of the FPTrunc builtin, which is not needed anyway (because it can be constant propagated).
2017-09-18 17:50:24 -07:00
Joe Groff
78d75428d6 SILGen: Lower key path subscript indexes.
And fill out SIL support for parsing, printing, and serializing key path
patterns with captured indexes.
2017-09-15 10:00:32 -07:00
Andrew Trick
15df313481 [sil-opaque-values] Allow open_existential_addr to be loaded (post-ownership). 2017-09-11 14:37:39 -07:00