Commit Graph

699 Commits

Author SHA1 Message Date
Nate Chandler
9b8828848d [SIL] Add SILFunctionType flag for async. 2020-08-19 11:29:58 -07:00
Dan Zheng
bf2ef3934d [AutoDiff] NFC: make LinearFunctionExtractInst inherit UnaryInstructionBase. (#33418)
Remove ad-hoc operand list and operand getters.
2020-08-11 22:20:58 -07:00
Varun Gandhi
29188e3fe7 [AST] Update equality for ExtInfo to take Clang types into account.
In the future, we will remove the UseClangFunctionTypes language option, but we
temporarily need the scaffolding for equality checks to be consistent in all
places.
2020-07-31 13:55:55 -07:00
Varun Gandhi
f219e58ada [NFC] Refactor ExtInfo to use a builder-pattern based API.
Since the two ExtInfos share a common ClangTypeInfo, and C++ doesn't let us
forward declare nested classes, we need to hoist out AnyFunctionType::ExtInfo
and SILFunctionType::ExtInfo to the top-level.

We also add some convenience APIs on (AST|SIL)ExtInfo for frequently used
withXYZ methods. Note that all non-default construction still goes through the
builder's build() method.

We do not add any checks for invariants here; those will be added later.
2020-07-31 13:55:55 -07:00
Joe Groff
90f0f7c627 Merge pull request #32359 from jckarter/enable-prune-vtables
Add PruneVTables to the performance optimizer passes.
2020-07-27 11:10:53 -07:00
Meghana Gupta
b34791a0a0 Update code as per Apple Style Guide
whitelist -> allowlist
blacklist -> denylist
2020-07-24 11:37:15 -07:00
Joe Groff
cc358ba8fb PruneVTables: Keep SILModule's vtable lookup table in sync with updates.
And add a verifier check to ensure the cache remains synced.
2020-07-23 20:40:49 -07:00
Andrew Trick
6ecbeefd50 Add AccessedStorage::Tail access kind and remove more checks.
Distinguish ref_tail_addr storage from the other storage classes.

We didn't have this originally because be don't expect a begin_access
to directly operate on tail storage. It could occur after inlining, at
least with static access markers. More importantly it helps ditinguish
regular formal accesses from other unidentified access, so we probably
should have always had this.

At any rate, it's particularly important when AccessedStorage is
generalized to arbitrary memory access.

The immediate motivation is to add an AccessPath utility, which will
need to distinguish tail storage.

In the process, rewrite AccessedStorage::isDistinct. This could have a
large positive impact on exclusivity performance.
2020-07-20 16:42:53 -07:00
Andrew Trick
9fda3f565c Verify OSSA address phis.
Verify that address phis are prohibited in all OSSA passes.

Eventually they should be prohibited in all passes. This at least
allows preserving access markers in OSSA passes.
2020-07-19 17:47:04 -07:00
Andrew Trick
5826e75b00 Generalize the MemAccessUtils API.
For use outside access enforcement passes.

Add isUniquelyIdentifiedAfterEnforcement.

Rename functions for clarity and generality.

Rename isUniquelyIdentifiedOrClass to isFormalAccessBase.

Rename findAccessedStorage to identifyFormalAccess.

Rename findAccessedStorageNonNested to findAccessedStorage.

Part of generalizing the utility for use outside the access
enforcement passes.
2020-07-17 10:13:20 -07:00
Michael Gottesman
5e36ae1c7c [sil] Add a forwarding cast called unchecked_value_cast.
Today unchecked_bitwise_cast returns a value with ObjCUnowned ownership. This is
important to do since the instruction can truncate memory meaning we want to
treat it as a new object that must be copied before use.

This means that in OSSA we do not have a purely ossa forwarding unchecked
layout-compatible assuming cast. This role is filled by unchecked_value_cast.
2020-07-09 21:14:32 -07:00
Hamish Knight
241c5d95e3 Merge pull request #32461 from hamishknight/its-all-linked 2020-07-08 11:07:17 -07:00
Michelle Casbon
c556b00d66 Replace assert() with llvm_unreachable() 2020-07-06 19:54:02 +00:00
Michelle Casbon
150f252514 Add explicit return true 2020-07-03 23:26:31 +00:00
Hamish Knight
0c9c606d28 Remove MergePartialModules from SILOptions
Its use in deserialization can be replaced with a
more general check for whether we're deserializing
into the same module. Its use in the SILVerifier
is subsumed by the check for whether the SILModule
is canonical, which it isn't during merge-modules.
2020-07-01 23:14:50 -07:00
Michael Gottesman
3d3a3c2eb2 [verifier] Do not use llvm::report_fatal_error since it swallows PrettyStackTrace.
I thought this was me being more standard but I keep on hitting this so I am
returning back to an assert(0) version of this. This is only enabled if NDEBUG
is set, so this is ok.
2020-06-22 12:30:06 -07:00
Joe Groff
04c8f0df42 IRGen: Don't reify internal vtable entries that are marked overridden.
Private and internal classes shouldn't have ABI constraints on their concrete vtable layout, so if methods
don't have overrides in practice, we can elide their vtable entries.
2020-06-12 11:59:24 -07:00
David Zarzycki
e077b6ffd9 [SIL] NFC: Make SILVTable follow C++ and LLVM best practices
1) Convert the `Entry` type to a class with getters/setters
2) Use llvm::TrailingObjects
3) Use llvm::PointerIntPair
2020-06-11 07:51:42 -04:00
David Zarzycki
017ee7bf04 [SIL] NFC: Simplify SILVTable and save 8 bytes per SILVTable
We were not using the primary benefits of an intrusive list, namely the
ability to insert or remove from the middle of the list, so let's switch
to a plain vector. This also avoids linked-list pointer chasing.
2020-06-10 07:54:23 -04:00
Dan Zheng
d3b6b89de6 [AutoDiff] Support multiple differentiability result indices in SIL. (#32206)
`DifferentiableFunctionInst` now stores result indices.
`SILAutoDiffIndices` now stores result indices instead of a source index.

`@differentiable` SIL function types may now have multiple differentiability
result indices and `@noDerivative` resutls.

`@differentiable` AST function types do not have `@noDerivative` results (yet),
so this functionality is not exposed to users.

Resolves TF-689 and TF-1256.

Infrastructural support for TF-983: supporting differentiation of `apply`
instructions with multiple active semantic results.
2020-06-05 16:25:17 -07:00
Michael Gottesman
8ea7009437 Merge pull request #32177 from gottesmm/pr-f5820e0408ca527e9c54f4b3c46468e4706e7c80
[memory-lifetime] Teach the verifier that select_enum_addr doesn't write to memory.
2020-06-04 12:34:50 -07:00
Michael Gottesman
ebf291c484 [memory-lifetime] Teach the verifier that select_enum_addr doesn't write to memory.
This is an older verifier that checks that uses of addresses from things like
in_guaranteed parameters are never written to. We just never hit this before.

<rdar://problem/63188699>
2020-06-03 19:33:55 -07:00
Joe Groff
8538a2afcc SIL: Verify kinds of vtable entries.
Validate that inherited entries are not left at "normal" state, and that non-overridden entries do not in fact have
overrides.
2020-06-03 16:29:44 -07:00
Michael Gottesman
736a848714 Merge pull request #32143 from gottesmm/pr-18735e23f15ef6aaa8992016e9c6ac89c2102eb4
[ownership] Add support for handling address_to_pointer to LoadBorrowInvalidationChecker.
2020-06-02 16:04:35 -07:00
Michael Gottesman
58e49dbd45 [ownership] Add support for handling address_to_pointer to LoadBorrowInvalidationChecker.
We treat address_to_pointer as an explicit opt in escape from the protection we
provide. The code emitter must instead provide other manners of guaranteeing
safety such as using mark_dependence. So we just treat the instruction as a
non-write instruction.

This verifier is not enabled in 5.3, so this does not need to be cherry-picked
to there.

<rdar://problem/63387309>
2020-06-02 11:39:45 -07:00
Anthony Latsis
267e32dcd8 Merge pull request #32118 from AnthonyLatsis/post-increment-cleanup
[NFC] Pre- increment and decrement where possible
2020-06-02 20:10:29 +03:00
Anthony Latsis
9fd1aa5d59 [NFC] Pre- increment and decrement where possible 2020-06-01 15:39:29 +03:00
Varun Gandhi
c14e934563 [NFC] Remove redundant includes for llvm/ADT/SmallSet.h. 2020-05-31 13:07:45 -07:00
Saleem Abdulrasool
cebe79d482 SIL: use object libraries instead of globbing
This simplifies the handling of the subdirectories in the SIL and
SILOptimizer paths.  Create individual libraries as object libraries
which allows the analysis of the source changes to be limited in scope.
Because these are object libraries, this has 0 overhead compared to the
previous implementation.  However, string operations over the filenames
are avoided.  The cost for this is that any new sub-library needs to be
added into the list rather than added with the special local function.
2020-05-18 18:56:34 +00:00
Anthony Latsis
44a92a926c [NFC] GenericSignatureImpl: Spell conformsToProtocol & getConformsTo in terms of requirements 2020-05-14 22:51:44 +03:00
Michael Gottesman
2599421c3b [semantic-arcopts] Teach optimizer how to convert load [copy] -> load_borrow from inout parameters that only have writes that do not overlap with the lifetime region of the load [copy]'s result.
rdar://58667192
2020-05-10 23:49:00 -07:00
Michael Gottesman
849180f083 Merge pull request #31611 from gottesmm/pr-444346873e7671db9a13c2b22f77cc5ec4eac841
[ownership] Track /all/ non consuming uses and emit errors for all of them instead of relying on just the last one in a block.
2020-05-07 14:49:20 -07:00
Erik Eckstein
3c3425d098 SILOwnershipVerifier: fix a compiler error in the no-assert build. 2020-05-07 09:25:09 +02:00
Michael Gottesman
b619d30908 [ownership] Track /all/ non consuming uses and emit errors for all of them instead of relying on jsut the last one in a block.
Beyond allowing us to emit better errors, this will allow me to (in a subsequent
commit) count the amount of uses that are "outside" of the linear lifetime. I
can then compare that against a passed in set of "non consuming uses". If the
count of the number of uses "outside" of the linear lifetime equals the count of
the passed in set of "non consuming uses", then I know that /all/ non consuming
uses that I am testing against are not co-incident with the linear lifetime,
meaning that they can not effect (in a local, direct sense) the linear lifetime.

I am going to use that information to determine when it is safe to convert an
inout form a load [copy] to a load_borrow in the face of local mutations. I can
pass the set of local mutations as non-consuming uses to a linear lifetime
consisting of the load [copy]/destroy_values and thus prove that no writes occur
in between the load [copy]/destroy_value meaning it is safe to conver them to
borrow form.

NOTE: The aforementioned optimization is an extension of an optimization already
in tree that just bails if we have any writes to an inout locally, which is so
unfortunate.
2020-05-06 22:36:53 -07:00
Michael Gottesman
7ffccfeffa Merge pull request #31588 from gottesmm/pr-2186749b7a14ac85f1db79d840c880aa440bf6fe
[ownership] Change the ownership verifier textual error dumper to emit error counts on a per function instead of global basis.
2020-05-06 12:58:33 -07:00
Arnold Schwaighofer
970c27248f Merge pull request #31470 from aschwaighofer/fix_rdar62560867
SIL: Thread type expansion context through to function convention apis
2020-05-06 11:52:19 -07:00
Michael Gottesman
820d204285 [ownership] Change the ownership verifier textual error dumper to emit error counts on a per function instead of global basis.
This will just make them easier to update over time since adding a new function
doesn't require one to renumber the /entire/ file... *face-palm*.

Originally the reason why I added this is b/c I need to ensure that we handle
all errors exactly once so making sure we control the exact amount of emitted
errors is important. I can still do this with the new approach by just doing
per-function max error counts. Thus I also in this commit added FileCheck
patterns that implemented this scheme so now we have everything.
2020-05-06 09:39:19 -07:00
Michael Gottesman
82b08c5722 [ownership] Add new pass OwnershipVerifierTextualErrorDumper and use it in ownership verifier FileCheck tests instead of SILVerifier.
This will make it easier for me with a few further refactors to make the
ownership verifier testing mode emit per function error numbers instead of the
global error number that it is emitting now.

The reason why this is necessary is that today, the verification by
-sil-verify-all causes the errors to be emitted. That verification is done on a
per value level, rather than a per function level, so it is hard to get per
function error numbers without doing unprincipled things like propagating around
state saying what the current function being verified is.

This pass instead will let me make the error counter be per ErrorBuilder which
are created per function.

One thing to be aware of is that this /will/ cause SILValue::verifyOwnership to
not emit any output when the testing flag is enabled. This is to ensure I only
do not get duplicate textual error messages from the SILVerifier.
2020-05-04 13:58:56 -07:00
Arnold Schwaighofer
147144baa6 SIL: Thread type expansion context through to function convention apis
This became necessary after recent function type changes that keep
substituted generic function types abstract even after substitution to
correctly handle automatic opaque result type substitution.

Instead of performing the opaque result type substitution as part of
substituting the generic args the underlying type will now be reified as
part of looking at the parameter/return types which happens as part of
the function convention apis.

rdar://62560867
2020-05-04 13:53:30 -07:00
Michael Gottesman
a70eb28f43 [ownership] Accept unconditional_checked_cast_addr, treating it like a write.
Just missed this on my first pass through.

rdar://62609950
2020-04-29 15:18:38 -07:00
Andrew Trick
0c13ed1803 Merge pull request #28022 from atrick/fix-exclusivity-coroutine
Fix four problems with static exclusivity diagnostics:
2020-04-29 08:59:28 -07:00
Joe Groff
cf92823f1c Merge pull request #31383 from jckarter/internal_protocol_refines_public_protocol_with_public_default_implementation.swift
SIL: Fix witness visibility hack to handle non-serialized declarations.
2020-04-29 08:16:51 -07:00
Joe Groff
bba87cdc10 SIL: Fix witness visibility hack to handle non-serialized declarations.
We have a hack to handle "public" declarations in extensions to internal protcols that are
intended as default implementations for a public protocol that the internal protocol refines.
This hack failed to trigger for synthesized declarations with shared linkage, such as
automatically generated `read` coroutines, causing a visibility assertion failure where we would
try to refer to the non-serializable synthesized declaration from the witness thunk we would
normally consider serialized. Fixes rdar://problem/55846638.
2020-04-28 15:53:08 -07:00
Michael Gottesman
973a82e85d [ownership] Cleanup how we emit filecheck-compatible verification errors for the ownership verifier.
This is doing a few things with a simple change to use a builder:

1. It cleans up how we emit errors so we have a builder object that constructs
errors. The errors then just become dumb POD data that the builder vends to
callers that via the boolean values describe what errors were found.

2. Now that we have one place where we are actually emitting these errors, I
cleaned up how we emit the errors by normalizing the output so function names
are quoted the same.

3. I changed our error emission so that we emit a unique count of the errors as
we emit them. This makes it so that our pattern matching is much more robust
against weird pattern match errors that can be difficult to debug due to the
errors having unrelated test cases/file check patterns bleed
together. Before/end checks eliminate this problem. I updated all of the
relevant test cases.

The reason /why/ I am doing this though is that I am going to be adding support
to the LinearLifetimeChecker for flagging objects that are outside of the
lifetime that we are verifying (meaning either before or after). This is going
to cause me to need to track /all/ non consuming uses when performing linear
lifetime checks and thus most likely emit more errors. I was finding it to be
difficult to update the current tests given the state of the world before this
patch, so I was inspired to clean this up to satisfy practical as well as debt
concerns.
2020-04-28 12:35:02 -07:00
Andrew Trick
6823b100a7 Diagnose exclusivity in the presence of coroutines.
Potentially source breaking: SR-11700 Diagnose exclusivity violations
with Dictionary.subscript._modify:

  Exclusivity violations within code that computes the `default`
  argument during Dictionary access are now diagnosed.

  ```swift
  struct Container {
     static let defaultKey = 0

     var dictionary = [defaultKey:0]

     mutating func incrementValue(at key: Int) {
       dictionary[key, default: dictionary[Container.defaultKey]!] += 1
     }
  }
  error: overlapping accesses to 'self.dictionary', but modification requires exclusive access; consider copying to a local variable
       dictionary[key, default: dictionary[Container.defaultKey]!] += 1
       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  note: conflicting access is here
       dictionary[key, default: dictionary[Container.defaultKey]!] += 1
                                ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
  ```

This reworks the logic so that four problems end up being fixed:

Fixes three problems related to coroutines:

(1) DiagnoseStaticExclusivity must consider begin_apply as a user of accessed variables. This was an undefined behavior hole in the diagnostics.

(2) AccessedSummaryAnalysis should consider begin_apply as a user of accessed arguments. This does not show up in practice because coroutines don't capture things.

(3) AccessedSummaryAnalysis must consider begin_apply a valid user of
    noescape closures.

And fixes one problem related to resilience:

(4) AccessedSummaryAnalysis must conservatively consider arguments to external functions.

Fixes <rdar://problem/56378713> Investigate why AccessSummaryAnalysis is crashing
2020-04-28 10:57:40 -07:00
Michael Gottesman
f373f6ef12 [ownership] Add an exhaustive load borrow invalidation checker.
This verifier validates that while a load_borrow's value is live (that is until
it is invalidated by its end_borrow), the load_borrow's address source is never
written to.

The reason why this verifier is especially important now is that I am adding
many optimizations that convert `load [copy]` -> `load_borrow`. If that
optimization messes up, we break this invariant [in fact, an optimization I am
working on right now violated the invariant =--(]. So by adding this verifier I
am checking that semantic arc opts doesn't break it as well as eliminating any
other such bugs from the compiler (in the future).
2020-04-27 16:07:27 -07:00
Erik Eckstein
6da902ef8b Add an option to completely disable SIL verification.
This is useful to disable SIL verification in an assert build of the compiler.
2020-04-10 20:10:24 +02:00
Michael Gottesman
96410196ac [gardening] Move maybeScopeLess from SIL/Verifier/SILVerifier.cpp -> SIL/IR/SILDebugScope.cpp.
This is defined in SILDebugScope.h, so I don't know why it was put into
SILVerifier.cpp.
2020-03-30 16:16:58 -07:00
Michael Gottesman
e1a19e4173 [sil] Split library into subfolders, while still building as a single library still.
Specifically, I split it into 3 initial categories: IR, Utils, Verifier. I just
did this quickly, we can always split it more later if we want.

I followed the model that we use in SILOptimizer: ./lib/SIL/CMakeLists.txt vends
 a macro (sil_register_sources) to the sub-folders that register the sources of
 the subdirectory with a global state variable that ./lib/SIL/CMakeLists.txt
 defines. Then after including those subdirs, the parent cmake declares the SIL
 library. So the output is the same, but we have the flexibility of having
 subdirectories to categorize source files.
2020-03-30 11:01:00 -07:00