Commit Graph

2864 Commits

Author SHA1 Message Date
Ben Cohen
2b04e9f105 Suppress a number of warnings in no-assert builds (#17721)
* Supress a number of warnings about things used only in asserts

* Re-use a couple of variables instead of supressing the warning
2018-07-04 07:15:14 -07:00
Ravi Kandhadai
e35da021d8 [DefiniteInitialization] Detect overwriting of immutable optionals
through optional chaining.

<rdar://38624845>
SR-7226
2018-07-03 09:22:10 -07:00
Ravi Kandhadai
895c1f0355 [DefiniteInitialization] Check whether globals captured by top-level
defer statements are initialized.

<rdar://30720636>
2018-07-02 11:40:21 -07:00
David Zarzycki
03b7eae9ed [SILOptimizer] NFC: Adopt reference storage type meta-programming macros 2018-06-30 06:44:33 -04:00
Andrew Trick
6ed43afcf8 Fix checks and assertions in -enable-verify-exclusivity mode.
Now that access marker verification is strict and exhaustive, adjust some code
to handle the extra markers and extra checks produced by -enable-verify-exclusivity.
2018-06-29 15:56:02 -07:00
Andrew Trick
d0a867ad53 Preserve all access markers with -verify-exclusivity. 2018-06-28 23:25:07 -07:00
Andrew Trick
4353e27db2 Exclusivity access marker verification. Handle Unsafe access.
Now that SILGen change adds Unsafe access markers to addressors and
materializeForSet, we can use that as a sentinel to enable strict
verification everywhere.
2018-06-28 23:25:07 -07:00
Andrew Trick
8d41d6ef5f Enable strict verification of begin_access patterns in all SIL passes. (#17534)
* Teach findAccessedStorage about global addressors.

AccessedStorage now properly represents access to global variables, even if they
haven't been fully optimized down to global_addr instructions.

This is essential for optimizing dynamic exclusivity checks. As a
verified SIL property, all access to globals and class properties
needs to be identifiable.

* Add stronger SILVerifier support for formal access.

Ensure that all formal access follows recognizable patterns
at all points in the SIL pipeline.

This is important to run acccess enforcement optimization late in the pipeline.
2018-06-27 23:40:52 -07:00
Michael Gottesman
9e70b855e4 [cmake] Use a helper macro to simplify adding sources to the SILOptimizer library.
All this does is automate the creation of the ${DIRNAME}_SOURCES variables that we already create and allows for the author to avoid having to prefix with the directory name, i.e.:

set(FOOBAR_SOURCES
  FooBar/Source.cpp
  PARENT_SCOPE)

=>

silopt_register_sources(
  Source.cpp)

Much easier and cleaner to read. I put the code that implements this in the
CMakeLists.txt file just for the SILOptimizer.
2018-06-27 17:48:59 -07:00
ravikandhadai
083707294b Merge pull request #17563 from ravikandhadai/DIOptWritePR
Revert "[DefiniteInitialization] Fix the bug that allows overwriting immutable optionals" due to internal build failure <rdar://41501480>
2018-06-27 16:02:45 -07:00
Michael Gottesman
97367d3dd4 [ownership] Do not lower copy_unowned_value to strong_retain_unowned.
The major important thing here is that by using copy_unowned_value we can
guarantee that the non-ownership SIL ARC optimizer will treat the release
associated with the strong_retain_unowned as on a distinc rc-identity from its
argument. As an example of this problem consider the following SILGen like
output:

----
%1 = copy_value %0 : $Builtin.NativeObject
%2 = ref_to_unowned %1
%3 = copy_unowned_value %2
destroy_value %1
...
destroy_value %3
----

In this case, we are converting a strong reference to an unowned value and then
lifetime extending the value past the original value. After eliminating
ownership this lowers to:

----
strong_retain %0 : $Builtin.NativeObject
%1 = ref_to_unowned %0
strong_retain_unowned %1
strong_release %0
...
strong_release %0
----

From an RC identity perspective, we have now blurred the lines in between %3 and
%1 in the previous example. This can then result in the following miscompile:

----
%1 = ref_to_unowned %0
strong_retain_unowned %1
...
strong_release %0
----

In this case, it is possible that we created a lifetime gap that will then cause
strong_retain_unowned to assert. By not lowering copy_unowned_value throughout
the SIL pipeline, we instead get this after lowering:

----
strong_retain %0 : $Builtin.NativeObject
%1 = ref_to_unowned %0
%2 = copy_unowned_value %1
strong_release %0
...
strong_release %2
----

And we do not miscompile since we preserved the high level rc identity
pairing.

There shouldn't be any performance impact since we do not really optimize
strong_retain_unowned at the SIL level. I went through all of the places that
strong_retain_unowned was referenced and added appropriate handling for
copy_unowned_value.

rdar://41328987

**NOTE** I am going to remove strong_retain_unowned in a forthcoming commit. I
just want something more minimal for cherry-picking purposes.
2018-06-27 13:02:58 -07:00
Ravi Kandhadai
964397c9a8 Revert "[DefiniteInitialization] Fix the bug that allows overwriting immutable"
This reverts commit 82abf974f2 as it breaks
compatability of some existing benchmarks.

<rdar://41501480>
2018-06-27 11:45:58 -07:00
swift-ci
70e757a7dd Merge pull request #17543 from gottesmm/pr-81a6b3cbe30cc676e69e9b5a9f2095fbeaaf8826 2018-06-26 19:54:46 -07:00
Michael Gottesman
b9f69cb0ea [pmo] Eliminate incomplete support for promoting enums.
This was never implemented correctly way back in 2013-2014. It was originally
added I believe so we could DI checks, but the promotion part was never added.

Given that DI is now completely split from PMO, we can just turn this off and if
necessary add it back on master "properly".

rdar://41161408
2018-06-26 18:49:08 -07:00
Andrew Trick
5308a2ae3b Remove stale references to '@_semantics(optimize.sil.preserve_exclusivity)'. (#17501) 2018-06-26 13:24:32 -07:00
swift-ci
bc67ab4c08 Merge pull request #17271 from ravikandhadai/DIOptWritePR 2018-06-25 17:38:07 -07:00
Michael Gottesman
0716dfaa36 [pmo][gardening] loop-if-else => loop-if-continue. 2018-06-25 08:32:31 -07:00
Ravi Kandhadai
82abf974f2 [DefiniteInitialization] Fix the bug that allows overwriting immutable
variables of optional type (SR-7226, rdar://38624845)
2018-06-22 14:55:21 -07:00
swift-ci
13dfae7be5 Merge pull request #17258 from aschwaighofer/cleanup_cfg_after_noreturn_folding 2018-06-15 16:55:33 -07:00
Arnold Schwaighofer
f7a4ed8e86 Cleanup dead blocks after noreturn folding
Follow-up passes might not handle blocks with undef instruction operands
well.

rdar://41139395
2018-06-15 14:32:42 -07:00
Slava Pestov
296ce3f312 AST: Remove hack-around for getInterfaceType() on ParamDecl returning InOutType
Most callers did not want the InOutType here, and checked
the ParamDecl's flags instead.
2018-06-13 15:38:52 -07:00
Joe Groff
3b227e9928 Merge pull request #17066 from jckarter/defer-let-inout-bug-2
DI: Consider capture of `let`s to be a read-only use.
2018-06-11 14:24:26 -07:00
swift-ci
9ffda06141 Merge pull request #17110 from aschwaighofer/closurelifetimefixup_delete_dead_store 2018-06-11 11:45:40 -07:00
Arnold Schwaighofer
d735c1ef95 ClosureLifetimeFixup: Delete a dead store 2018-06-11 10:55:44 -07:00
Joe Groff
10e038528a DI: Consider captures of let properties to be read-only uses.
Sema enforces that closures can't modify the let properties of their captured contexts, but we consider the capture argument to be @inout_aliasable at the SIL level. Add an exception to our normal handling so that this use is considered read-only. Fixes rdar://problem/40828667.

A more principled solution would be to treat let captures as @in_guaranteed (see #17047), but that unfortunately leads to breakage elsewhere in the optimizer.
2018-06-11 10:53:26 -07:00
Devin Coughlin
c50ca98ac6 [SIL] Factor out logic for detecting sanitizer instrumentation. NFC.
Factor out common logic for detecting sanitizer instrumentation and put it in
SIL/InstructionUtils.
2018-06-10 16:44:19 -07:00
Slava Pestov
2c65f5d3b3 SILGen: Don't emit unreachable code warnings for explicit return statement 2018-06-04 23:06:03 -07:00
Slava Pestov
003ef6cef9 DI: Remove unnecessary assertion
It's totally fine to have a conditional destroy of 'self' because
we now uniformly treat assignment to self and self.init delegation,
both of which can appear multiple times in a value type
initializer.

This change removes the assertion and adds some tFileCheck tests to
ensure that DI was already capable of inserting the correct memory
management operations in this scenario.

Fixes <rdar://problem/40417944>, <https://bugs.swift.org/browse/SR-7727>.
2018-06-03 23:57:38 -07:00
Arnold Schwaighofer
968d2279a9 ClosureLifetimeFixup: Fix closure insertion point in deallocating deinits
We must not capture self beyond the call to super.deinit

rdar://40660799
2018-06-01 09:12:00 -07:00
Michael Gottesman
8886368854 [definite-init] Treat destroys of mark_uninitialized [var] container to be a load + destroy.
This ensures that DI creates dealloc_box in cases where the box is uninitialized
conditionally.

In the process, I also discovered that we were missing a test case for DI being
used by LLDB. Long term we shouldn't support that code pattern in the general
case, but for now we at least need a test case for it.

rdar://40332620
2018-05-30 14:25:50 -07:00
Michael Gottesman
e0aaa5f073 [pred-memopts] Add a large file comment to PMOMemoryUtils.h explaining the history of the utilities and that the code in DIMemoryUtils is similar due to this historical relationship. 2018-05-28 17:15:31 -07:00
Michael Gottesman
ed6bcdee2a Merge pull request #16774 from gottesmm/pr-e9a2e719f8fe7c5d31d0258bc42e15ae56d59fb0
[pred-memopt] Replace remaining occurances of prefix DI with PMO prefix.
2018-05-28 17:06:31 -07:00
Michael Gottesman
b35da17775 [definite-init] DI only analyzes mark_uninitialized... so eliminate more dead code and conditional checks.
rdar://40332620
2018-05-25 13:17:51 -07:00
Michael Gottesman
46c025a219 [definite-init] Remove dead code.
collectRetainCountInfo bails early if our memory instruction is a
mark_uninitialized... but our instruction is always a mark_uninitialized... so
this code is dead.

The origin of this code is from the flattening of the control flow in DI that
was necessary to be done to "extract" predictable mem opts from it.

rdar://40332620
2018-05-25 13:17:50 -07:00
Andrew Trick
e29c2089a4 Rework AccessStorageAnalysis design. 2018-05-23 09:23:39 -07:00
Michael Gottesman
160742ae16 Merge pull request #16782 from gottesmm/pr-8cb08737bbc02f7bd7b79cd80cd7d3ccde893680
Two small cleanups for DI since I am in the area.
2018-05-22 20:23:37 -07:00
Michael Gottesman
2872389826 [definite-init] Split raw SIL instruction lowering out of DI into its own pass run after DI.
I am doing this so I can start writing DI tests without this lowering occuring.
There never was a real reason for this code to be in DI beyond convenience. Now
it just makes writing tests more difficult. To prevent any test delta, I changed
all current DI tests to run this pass after DI.
2018-05-22 18:18:22 -07:00
Michael Gottesman
1bc3190def [definite-init] Reorganize the top level entry point so that all analysis of classes occurs via the same UseCollector. 2018-05-22 17:57:55 -07:00
Michael Gottesman
2a85c68daa [definite-init] Split DelegatingInitElementUseCollector into value type and class type parts.
The value type part is now implemented in a simple function. The class type part
is still in DelegatingInitElementUseCollector, but since that struct only
handles class initialization now, I renamed it to
DelegatingClassInitElementUseCollector.

Should be NFC.
2018-05-22 17:57:54 -07:00
Michael Gottesman
db30959a9d [pred-memopt] Replace remaining occurances of prefix DI with PMO prefix.
I am going to DI and predictable mem opts have been split for a long time and
their subroutines aren't going to be joined in the future... so replace the DI
prefixes in pred-mem-opts impl with PMO and rename DIMemoryUseCollector =>
PMOUseCollector.

Been sitting on this for a long time... just happy to get it in.
2018-05-22 12:52:43 -07:00
Arnold Schwaighofer
261639d18d ClosureLifetimeFixup: We need to insert a None on the backedge of a loop after we destroyed the value
rdar://40221767
2018-05-15 08:02:39 -07:00
Doug Gregor
09446defef Eliminate yet more SubstitutionLists from SIL in search of a steady-state 2018-05-11 13:18:06 -07:00
Doug Gregor
4b5abbddbc [SIL] Teach *ApplyInst to traffic in SubstitutionMap.
Push SubstitutionMaps through most of SILGen and the SIL optimizers
that involve the various *ApplyInsts.
2018-05-11 13:18:06 -07:00
Michael Gottesman
04e6e5d7a6 Merge pull request #16543 from gottesmm/pr-d6ed522f8c3454952c992ba022867e44fcbd97f2
[pred-memopts] Rather than asserting on recursive initialization, jus…
2018-05-11 12:47:56 -07:00
Michael Gottesman
269f8e8d56 [pred-memopts] Rather than asserting on recursive initialization, just return false and bail.
Until the beginning of the ownership transition, DI and predictable mem opts
used the same memory use collector. I split them partially since I need to turn
on ownership for predictable mem opts at one time, but also b/c there was a huge
amount of special code that would only trigger if it was used by DI or used by
predictable mem opts. After I did the copy some of the asserts that were needed
for DI remained in the predictable mem opts code. When pred-memopts was only run
in the mandatory pipeline keeping these assertions were ok, but pred-memopts was
recently added to the perf pipeline meaning that it may see code that breaks
these DI invariants (and thus hit this assertion).

We should remove this limitation on predictable-memopts but that would require
some scheduled time to read the code (more than I have to fix this bug = p). So
instead I changed the code to just bail in these cases.

rdar://40032102
2018-05-11 09:50:32 -07:00
Andrew Trick
e8c65b37ef Remove the optimize.sil.preserve_exclusivity attribute. 2018-05-09 23:10:35 -07:00
Andrew Trick
dda3d7be36 [exclusivity] Make KeyPath enforcement an error in Swift 3 mode.
Modify IRGen to emit builtin access markers with an error flag in
Swift 3 mode.

KeyPath enforcement is required by user code in Swift 4+ mode, but is
implemented within the standard library. A [builtin] flag marks the
special case for access generated by Builtins so that they are
always enforced as an error regardless of the language mode.

This is necessary for Swift 4.2 because the standard library continues
to build in Swift 3 mode. Once the standard library build migrates,
this is all irrelevant.

This does not actually affect existing Swift 3 code, since the KeyPath
feature wasn't introduced until Swift 4.

<rdar://problem/40115738> [Exclusivity] Enforce Keypath access as an error, not a warning in 4.2.
2018-05-09 22:52:42 -07:00
Andrew Trick
fb3ae2549c Merge pull request #16296 from atrick/exclusivity-fix
Shoring up the exclusivity diagnostics.
2018-05-08 15:56:57 -07:00
Andrew Trick
5e1829ce65 Remove the unused ConflictingAccess::AlwaysDiagnoseAsWarning. 2018-05-08 12:47:31 -07:00
Andrew Trick
22677470e8 Reorganize code in DiagnoseStaticExclusivity for readability.
The file is more approachable now. The data flow algorithm is self-contained in
about 250 lines, split into manageable routines, with separate data flow state.
2018-05-08 12:44:41 -07:00