Commit Graph

826 Commits

Author SHA1 Message Date
swift-ci
604f5930fe Merge remote-tracking branch 'origin/master' into master-next 2018-05-03 19:29:42 -07:00
swift-ci
5f22c9ceec Merge remote-tracking branch 'origin/master' into master-next 2018-05-03 13:49:29 -07:00
Doug Gregor
caad325a54 [Serialization] Serialize SIL *apply instructions using SubstitutionMaps. 2018-05-03 13:24:30 -07:00
swift-ci
5ce78da1d3 Merge remote-tracking branch 'origin/master' into master-next 2018-05-03 08:49:46 -07:00
Doug Gregor
408aaa5332 [SIL] Use SubstitutionMap in BuiltinInst. 2018-05-03 08:48:55 -07:00
Doug Gregor
d5c9f71a6d [SIL] Switch InitBlockStorageHeaderInst over to SubstitutionMap. 2018-05-03 08:48:54 -07:00
Doug Gregor
7e08b66499 [SIL] Use SubstitutionMap in KeyPathInst rather than SubstitutionList. 2018-05-03 08:48:54 -07:00
Doug Gregor
5724338abe [SIL] Switch "external" key path pattern components to SubstitutionMap.
Eliminates another source of SubstitutionList.
2018-05-03 08:48:54 -07:00
Doug Gregor
d2cf60c465 Revert "[SIL] Replace more SubstitutionLists with SubstitutionMap" 2018-05-03 08:35:20 -07:00
swift-ci
32853a9ed1 Merge remote-tracking branch 'origin/master' into master-next 2018-05-03 01:29:45 -07:00
Doug Gregor
ed1983d9d0 [SIL] Use SubstitutionMap in BuiltinInst. 2018-05-03 00:05:21 -07:00
Doug Gregor
216906cf59 [SIL] Switch InitBlockStorageHeaderInst over to SubstitutionMap. 2018-05-03 00:05:21 -07:00
Doug Gregor
a6dfe0ff88 [SIL] Use SubstitutionMap in KeyPathInst rather than SubstitutionList. 2018-05-03 00:05:21 -07:00
Doug Gregor
25b9afe20f [SIL] Switch "external" key path pattern components to SubstitutionMap.
Eliminates another source of SubstitutionList.
2018-05-03 00:05:21 -07:00
swift-ci
49b2c7fe2a Merge remote-tracking branch 'origin/master' into master-next 2018-05-01 12:08:52 -07:00
Arnold Schwaighofer
1f65ee25f6 Distinguish between withoutActuallyEscaping and passing @noescape
Objective C closures when reporting that a closure has escaped

rdar://39682865
2018-05-01 07:24:19 -07:00
Arnold Schwaighofer
678a99e76a Add a copy_block_without_escaping %block withoutEscaping %closure instruction
Mandatory pass will clean it up and replace it by a copy_block and
is_escaping/cond_fail/release combination on the %closure in follow-up
patches.

The instruction marks the dependence of a block on a closure that is
used as an 'withoutActuallyEscaping' sentinel.

rdar://39682865
2018-05-01 07:24:19 -07:00
swift-ci
b95dd21966 Merge remote-tracking branch 'origin/master' into master-next 2018-04-17 06:29:07 -07:00
Arnold Schwaighofer
36d5408125 SIL: Add an [escaped] attribute to convert_escape_to_noescape instruction
To mark when a user of it is known to escape the value. This happens
with materializeForSet arguments which are captured and used in the
write-back. This means we need to keep the context alive until after
the write-back.

Follow-up patches to fully replace the PostponedCleanup hack in SILGen
by a mandatory SIL transformation pass to guarantee the proper lifetime
will use this flag to be more conservative when extending the lifetime.

The problem:

%pa = partial_apply %f(%some_context)
%cvt = convert_escape_to_noescape [not_guaranteed] [escaped] %pa
%ptr = %materialize_for_set(..., %cvt)
...  write_back
... // <-- %pa needs to be alive until after write_back
2018-04-13 12:40:10 -07:00
swift-ci
58b2cad4ee Merge remote-tracking branch 'origin/master' into master-next 2018-04-05 19:11:48 -07:00
Joe Groff
8cf2d90738 SIL Deserializer: Assert that we don't deserialize during "lowered" stage.
Pre-IRGen lowering passes take SIL out of canonical form, making it potentially incompatible with the serialized canonical SIL.
2018-04-05 09:54:56 -07:00
swift-ci
8f0f89053a Merge remote-tracking branch 'origin/master' into master-next 2018-04-05 09:29:49 -07:00
Joe Groff
ed39787877 SIL deserializer: Allow multiple shared definitions of a witness table.
By design, things with shared linkage are allowed to have definitions in different TUs, and we're supposed to pick one when linking or merging modules.
2018-04-04 14:41:18 -07:00
swift-ci
1a436bcb75 Merge remote-tracking branch 'origin/master' into master-next 2018-03-31 10:08:58 -07:00
Andrew Trick
4ed120e46c Merge branch 'master' into add-access-tracking-flag 2018-03-30 19:25:46 -07:00
swift-ci
e99fdb8f07 Merge remote-tracking branch 'origin/master' into master-next 2018-03-30 13:48:46 -07:00
Arnold Schwaighofer
80e7a1914d Add a convert_escape_to_noescape [not_guaranteed] variant 2018-03-30 08:53:40 -07:00
Andrew Trick
70ee3df099 Serialization support for begin_access [no_nested_conflict].
Add serialization layouts for rare instructions that take extra attributes. We
can continue adding bits to these layout without affecting the layout of the
vast majority of instructions.
2018-03-27 12:04:20 -07:00
swift-ci
860b409021 Merge remote-tracking branch 'origin/master' into master-next 2018-03-14 14:53:53 -07:00
Joe Groff
a795b4fc0c SIL: Move responsibility for external keypath equals/hash to the caller.
A public subscript might have generic indexes that aren't unconditionally Hashable, or might use indexes that are retroactively made Hashable, so the property descriptor on the implementer's side can't always resiliently provide this information to the final instantiated KeyPath.
2018-03-14 14:05:49 -07:00
swift-ci
ecd7a48bb2 Merge remote-tracking branch 'origin/master' into master-next 2018-03-09 09:49:07 -08:00
Arnold Schwaighofer
1e4f55de8d Merge pull request #15046 from aschwaighofer/without_actually_escaping_verification
Implement withoutActuallyEscaping verification
2018-03-09 09:34:06 -08:00
Bob Wilson
1dce60b2a6 Merge remote-tracking branch 'origin/master' into master-next 2018-03-07 17:02:53 -08:00
Joe Groff
a8e3c4fc8b SILGen: Emit property descriptors for (some) decls that need them.
If a property or subscript is referenceable from other modules, we need to give it a descriptor so that we can reliably build an equivalent key path in or out of that module.

There are some cases that we should handle but don't yet:

- Global and static properties ought to be key-path-able someday, so we should make descriptors for them, but this might need a new key path component kind.
- Subscripts with indexes that aren't Hashable in the current module ought to get descriptors too, in case we ever support non-hashable key path components, and also because a generic subscript might be substituted with Hashable types by an external user, or an external module might post-hoc extend a type to be Hashable, so we really need to change things so that the client supplies the hashing and equality implementations for the indexes instead of the descriptor.
2018-03-07 15:32:12 -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
Adrian Prantl
0747d9a339 Force the DJB hash seed to 0 for compatibility with HashString.
The obsolete llvm::HashString() was equivalent to
llvm::djbHash(seed=0) and was removed from llvm. This patch replaces
all occurences of llvm::HashString() with llvm::djbHash(seed=0), no
functional change.

The default seed of llvm::djbHash() is supposed to yield a higher
quality result that using seed=0, but changing it looks like it
affects the ordering of SIL serialization.
2018-02-28 14:10:25 -08:00
Saleem Abdulrasool
a0c6a70c31 upstream-update: adjust for SVN r326091 2018-02-27 12:36:15 -08:00
Joe Groff
d365c153d4 SIL: Introduce sil_property declarations for property descriptors.
This provides SILGen a place to generate the key path component information for an exported property so that it can be linked to from other modules.
2018-02-23 14:57:45 -08:00
Joe Groff
2d377a4636 SIL: Serialization for external key path components 2018-02-23 12:58:19 -08:00
Jordan Rose
bb339778b4 Add @_weakLinked and a corresponding SIL attribute
This is mostly intended to be used for testing at this point; in the
long run, we want to be using availability information to decide
whether to weak-link something or not. You'll notice a bunch of FIXMEs
in the test case that we may not need now, but will probably need to
handle in the future.

Groundwork for doing backward-deployment execution tests.
2018-02-20 17:55:31 -08:00
Joe Shajrawi
102b6f0b61 Merge pull request #14587 from shajrawi/newinstr
Optimizer peephole for tagged BridgeObjects
2018-02-13 07:38:53 -08:00
Joe Shajrawi
f732ea66ef Builtins: add ValueToBridgeObject instruction 2018-02-12 13:27:59 +02:00
Andrew Trick
66a579cc77 Add ModuleFile::isSIB
We can't make the same assumptions about .sib files.

Ideally, we should serialize the module's stage and set WasDeserializedCanonical
based on that state. However, we probably still want the IsSIB flag for
assertions.
2018-02-09 09:55:47 -08:00
Andrew Trick
287ccece75 Add SILFunction::WasDeserializedCanonical flag.
We need to be able to detect function definitions that have been
deserialized. There's no need to rerun diagnostics on those functions,
and in some cases it's actually incorrect to do so. With exclusivity,
we could even miscompile in theory (debug assert) because the fully
optimized SIL does adhere to rules requires by the
diagnostic. Hopefully that specific issue can be fixed soon, but the
point is that we need control over the order that passes are run
because we play these games all the time. Not to mention the wasted
compilation time.

It would probably be sufficient to check isAvailableExternally. However, using
an explicit flag is, well, more explicit. It also generalizes to serializing IR
at any stage.

Note: I would strongly prefer not to rely on this flag for correctness. In
principle, serialized SIL should be compatible with all SIL stages prior to the
serialization point. However, it is necessary to fix bugs in the short term, and
useful for bootstrapping SIL changes in general. Also, it formalizes some
assumptions about the way the pass pipeline is expected to work making it easier
to reason about and avoid pass ordering bugs. In particular, we should not be
relying on a second round of the mandatory pass pipeline to catch important
performance opportunities.
2018-02-09 09:55:47 -08:00
Jordan Rose
0c92fdda33 [SIL] Remove unused ResilienceExpansion from SILDeclRef (#14451)
We ended up not using this, so let's not leave it in as cruft.
No functionality change.
2018-02-07 09:41:25 -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
Slava Pestov
1831b5471e SIL: Clean up 'early serialization' a bit
- Clear the 'serialized' flag on witness tables and vtables
  after serialization, not just functions. This fixes SIL
  verifier failures if post-serialization SIL is printed
  out and parsed back in.

- Clear the 'serialized' flag when deserializing functions,
  witness tables and vtables in a module that has already
  been serialized. This fixes SIL verifier failures if
  we deserialize more declarations after serializing SIL.

We were seeing SIL verifier failures on bots that run the
tests with the stdlib built with non-standard flags.

Unfortunately I don't have a reduced test case that would
fail in PR testing without these fixes.

Fixes <rdar://problem/36682929>.
2018-01-21 01:35:13 -08:00
Slava Pestov
7dc7a1fc4c Serialization: When deserializing a SIL function in the merge-modules step, update linkage
Consider a module with two files, one of which references a
function in the other file. If the function had PublicNonABI
linkage, the forward reference has HiddenExternal linkage.

If we saw the forward reference first in the merge modules
process, we would not update the linkage of the function
when we later deserialized its body.

This would result in it being dropped from the final merged
SIL module. Previously this did not cause any problems
because all inlineable functions had public linkage, but now
that default argument generators no longer have public entry
points, this could cause linker errors.
2018-01-21 01:31:44 -08:00
Adrian Prantl
b4781f63ef Debug Info: Create artificial functions in a virtual file <compiler-generated>.
For the majority of artificial helper functions the filename is
actively misleading since it usually represents the file of the caller
that triggered the helper to be generated. Instead, this patch creates
a virtual filname `<compiler-generated>` to make it very obvious that
the function has not correspondence to any source code.

<rdar://problem/33809560>
2018-01-17 11:09:35 -08:00
Slava Pestov
c857a480e1 SIL: Introduce SILLinkage::PublicNonABI
This is going to be used for "always emit into client" functions,
such as default argument generators and stored property
initializers.

- In dead function elimination, these functions behave identically to
  public functions, serving as "anchors" for the mark-and-sweep
  analysis.

- There is no external variant of this linkage, because external
  declarations can use HiddenExternal linkage -- the definition should
  always be emitted by another translation unit in the same Swift
  module.

- When deserialized, they receive shared linkage, because we want the
  linker to coalesce multiple copies of the same deserialized
  definition if it was deserialized from multiple translation units
  in the same Swift module.

- When IRGen emits a definition with this linkage, it receives the
  same LLVM-level linkage as a hidden definition, ensuring it does not
  have a public entry point.
2018-01-14 22:59:40 -08:00