Commit Graph

266 Commits

Author SHA1 Message Date
Slava Pestov f7dd583ca3 SIL: Remove workaround for rdar://problem/36799163 2018-03-10 03:39:09 -08:00
Joe Groff ad79b5c752 SILGen: Fix up ownership of key path entry points for +0. 2018-03-09 11:52:39 -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
Sho Ikeda 26d650292f [gardening] Use empty() over size() == 0 2018-03-05 14:43:13 +09:00
Andrew Trick 33b89122bc Allow address-phis with -enforce-exclusivity.
As long as begin/end access scopes are respected, enforce-exclusivity does not
actually care about address phis.

Eventually, we will disable address phis completely, but that requires adding a
"address legalization" transform to various CFG passes, such as jump threading
and loop rotate.

Meanwhile, we will continue to suppress these CFG transformations when access
markers are involved. This means that optimizations will work differently, and
some will be suppressed in the presence of access markers. That means that
optimizing the access markers themselves will be a prerequisite to enabling them
by default, even if the overhead of the checks is tolerable.
2018-03-01 00:05:34 -08:00
Andrew Trick cf962e0148 [SILVerifier] Disallow address-type block arguments in raw SIL.
As a structural SIL property, we disallow address-type block
arguments. Supporting them would prevent reliably reasoning about the
underlying storage of memory access. This reasoning is important for
diagnosing violations of memory access rules and supporting future
optimizations such as bitfield packing. Address-type block arguments
also create unnecessary complexity for SIL optimization passes that
need to reason about memory aliasing.

This must be enforced in RAW SIL for diagnosing exclusive memory
access. The optimizer currently breaks the invariant in three places:
1. Normal Simplify CFG during conditional branch simplification
   (sneaky jump threading).
2. Simplify CFG via Jump Threading.
3. Loop Rotation.
2018-02-27 09:53:13 -08:00
John McCall a3d401439d Remove check that's been #if 0'd for years; if this is valuable,
it's for reasons that escape me.
2018-02-26 15:20:06 -05:00
Joe Groff b00ea61945 SILGen: Lower keypath references to other modules' properties and subscripts as external keypath components.
This way we'll link against the key path component the other module provides instead of making fragile assumptions about its current implementation. Since external keypath lowering isn't fully implemented elsewhere in the compiler, this is enabled behind a staging flag.

external keypath staging
2018-02-23 12:58:19 -08:00
Adrian Prantl 9b6a9946ec Be explicit about whether a DebugInfo-carying SILInstruction has debug info.
This patch both makes debug variable information it optional on
alloc_stack and alloc_box instructions, and forced variable
information on debug_value and debug_value_addr instructions. The
change of the interface uncovered a plethora of bugs in SILGen,
SILTransform, and IRGen's LoadableByAddress pass.

Most importantly this fixes the previously commented part of the
DebugInfo/local-vars.swift.gyb testcase.

rdar://problem/37720555
2018-02-21 10:50:19 -08:00
swift-ci 0ca90b8eeb Merge pull request #14637 from shajrawi/tuples 2018-02-19 06:26:25 -08:00
Joe Shajrawi e28fc903c4 LoadableByAddress: Add better tuples support
When working with tuples, if the tuple does not contain a large loadable type but does contain a function signature, we currently do nothing.

We should convert the function signature inside the tuple type instead.
2018-02-19 13:41:51 +02:00
Joe Groff d4e03f2ba3 SIL: Add an 'external' KeyPathPatternComponent kind.
This will allow key paths to resiliently reference public properties from other binaries by referencing a descriptor vended by the originating binary. NFC yet, this just provides printing/parsing/verification of the new component.
2018-02-14 10:48:24 -08:00
Arnold Schwaighofer 48b3737404 SIL: Add support for trivial @noescape function types
- @noescape functions are trivial types
That makes @noescape functions incompatible with escaping functions.
- Forward ownership of mark_dependence %3 : callee_guaranteed () -> () on %0 : noescape @callee_guaranteed () -> ()
- SIL: Add ABIEscapeToNoEscapeConversion to SILFunctionType::ABICompatibilityCheckResult
- SIL: A thin_to_thick_function with a @noescape result type has trivial ownership
- SIL: thin_to_thick_function can create noescape function types

Part of:
SR-5441
rdar://36116691
2018-02-13 04:19:58 -08:00
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
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
Mark Lacey b4b66bc8e8 Replace getAnyOptionalObjectType with getOptionalObjectType. 2018-02-05 23:59:00 -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