Commit Graph

812 Commits

Author SHA1 Message Date
John McCall
512e55683e Make it easy to create a SILBasicBlock immediately before a target block.
Also, make "after" requests explicit in the API.
2018-08-18 12:36:36 -04:00
Michael Gottesman
9b036b2316 Merge pull request #18724 from gottesmm/pr-e32bbcf553e857952e63a87d9b9f24d9d991da98
[sil-optimizer] Centralize how we send out serialization notifications.
2018-08-16 10:48:09 -07:00
Michael Gottesman
872bf40e17 [sil-optimizer] Centralize how we send out serialization notifications.
Previously SILModule contained two different pathways for the deserializer to
send notifications that it had created functions:

1. A list of function pointers that were called when a function's body was
deserialized. This was added recently so that access enforcement elimination is
run on newly deserialized SIL code if we have already eliminated access
enforcement from the module.

2. SILModule::SerializationCallback. This is an implementation of the full
callback interface and is used by the SILModule to update linkage and other
sorts of book keeping.

To fix the pass manager notification infrastructure, I need to be able to send
notifications to a SILPassManager when deserializing. I also need to be able to
eliminate these callbacks when a SILPassManager is destroyed. These requirements
are incompatible with the current two implementations since: (2) is an
implementation detail of SILModule and (1) only notifies on function bodies
being deserialized instead of the creation of new declarations (what the caller
analysis wants).

Rather than adding a third group of callbacks, this commit refactors the
infrastructure in such a way that all of these use cases can use one
implementation. This is done by:

1. Lifting the interface of SerializedSILLoader::Callback into a base
notification protocol for deserialization called
DeserializationNotificationHandlerBase and its base no-op implementation into an
implementation of the aforementioned protocol:
DeserializationNotificationHandler.

2. Changing SILModule::SerializationCallback to implement
DeserializationNotificationHandler.

3. Creating a class called FunctionBodyDeserializationNotificationHandler that
takes in a function pointer and uses that to just override the
didDeserializeFunctionBody. This eliminates the need for the specific function
body deserialization list.

4. Replacing the state associated with the two other pathways with a single
DeserializationNotificationHandlerSet class that contains a set of
DeserializationNotificationHandler and chains notifications to them. This set
implements DeserializationNotificationHandlerBase so we know that its
implementation will always be in sync with DeserializationNotificationHandler.

rdar://42301529
2018-08-15 15:49:15 -07:00
Andrew Trick
c9033ed938 Add a SIL attribute [without_actually_escaping].
ConvertFunction and reabstraction thunks need this attribute. Otherwise,
there is no way to identify that withoutActuallyEscaping was used
to explicitly perform a conversion.

The destination of a [without_actually_escaping] conversion always has
an escaping function type. The source may have either an escaping or
@noescape function type. The conversion itself may be a nop, and there
is nothing distinctive about it. The thing that is special about these
conversions is that the source function type may have unboxed
captures. i.e. they have @inout_aliasable parameters. Exclusivity
requires that the compiler enforce a SIL data flow invariant that
nonescaping closures with unboxed captures can never be stored or
passed as an @escaping function argument. Adding this attribute allows
the compiler to enforce the invariant in general with an escape hatch
for withoutActuallyEscaping.
2018-08-14 17:14:25 -07:00
swift-ci
71f0248b0a Merge remote-tracking branch 'origin/master' into master-next 2018-08-06 11:07:55 -07:00
swift-ci
1623f42447 Merge pull request #18292 from mhong/master_bytes_string 2018-08-06 09:05:58 -07:00
swift-ci
ba1b68af78 Merge remote-tracking branch 'origin/master' into master-next 2018-08-01 14:09:45 -07:00
Michael Gottesman
72d3323465 [sil-serialization] Create SILSerializationFunctionBuilder and use it when deserializing.
This allowed me to fold all of the weird direct calls to createFunction into a
singular SILSerializationFunctionBuilder::createDeclaration. This is the only
API that is needed by the SILParser so only providing that gives us a
significantly cleaner API.

rdar://42301529
2018-08-01 13:03:06 -07:00
swift-ci
100bec92a7 Merge remote-tracking branch 'origin/master' into master-next 2018-07-31 11:09:58 -07:00
Michael Gottesman
11b24415c1 [sil-module] Create SILFunctionBuilder and hide creation/erasing functions on SILModule.
This commit does not modify those APIs or their usage. It just:

1. Moves the APIs onto SILFunctionBuilder and makes SILFunctionBuilder a friend
   of SILModule.
2. Hides the APIs on SILModule so all users need to use SILFunctionBuilder to
   create/destroy functions.

I am doing this in order to allow for adding/removing function notifications to
be enforced via the type system in the SILOptimizer. In the process of finishing
off CallerAnalysis for FSO, I discovered that we were not doing this everywhere
we need to. After considering various other options such as:

1. Verifying after all passes that the notifications were sent correctly and
   asserting. Turned out to be expensive.
2. Putting a callback in SILModule. This would add an unnecessary virtual call.

I realized that by using a builder we can:

1. Enforce that users of SILFunctionBuilder can only construct composed function
   builders by making the composed function builder's friends of
   SILFunctionBuilder (notice I did not use the word subclass, I am talking
   about a pure composition).
2. Refactor a huge amount of code in SILOpt/SILGen that involve function
   creation onto a SILGenFunctionBuilder/SILOptFunctionBuilder struct. Many of
   the SILFunction creation code in question are straight up copies of each
   other with small variations. A builder would be a great way to simplify that
   code.
3. Reduce the size of SILModule.cpp by 25% from ~30k -> ~23k making the whole
   file easier to read.

NOTE: In this commit, I do not hide the constructor of SILFunctionBuilder since
I have not created the derived builder structs yet. Once I have created those in
a subsequent commit, I will hide that constructor.

rdar://42301529
2018-07-31 10:04:03 -07:00
Mingsheng Hong
ba38bcb279 Introduce a new 'bytes' form of the string_literal SIL instruction. Have it
print and parse as a stable hexadecimal form that isn't interpreted as UTF8.

One use case is in representing serialized protobuf strings (as in the
tensorflow branch: f7ed452eba/lib/SILOptimizer/Mandatory/TFPartition.cpp (L3875)).

The original work was done by @lattner and merged into the tensorflow
branch. This PR is to upstream those changes.
2018-07-27 11:58:00 -07:00
Bob Wilson
ffa88c3d28 Merge remote-tracking branch 'origin/master' into master-next 2018-07-23 14:38:55 -07:00
Bob Wilson
ad8cd14233 Merge pull request #18127 from bob-wilson/fix-indentation
NFC: Fix indentation around the newly renamed LLVM_DEBUG macro.
2018-07-23 14:23:19 -07:00
swift-ci
b4bae42909 Merge remote-tracking branch 'origin/master' into master-next 2018-07-21 13:49:33 -07:00
Slava Pestov
1cd22b6ebc Serialization: Serialize SILDeclRef.isCurried in a more direct way 2018-07-21 01:25:06 -07:00
Bob Wilson
8e330ee344 NFC: Fix indentation around the newly renamed LLVM_DEBUG macro.
Jordan used a sed command to rename DEBUG to LLVM_DEBUG. That caused some
lines to wrap and messed up indentiation for multi-line arguments.
2018-07-21 00:56:18 -07:00
Jordan Rose
cefb0b62ba Replace old DEBUG macro with new LLVM_DEBUG
...using a sed command provided by Vedant:

$ find . -name \*.cpp -print -exec sed -i "" -E "s/ DEBUG\(/ LLVM_DEBUG(/g" {} \;
2018-07-20 14:37:26 -07:00
swift-ci
2507876125 Merge remote-tracking branch 'origin/master' into master-next 2018-07-06 17:08:57 -07:00
Joe Groff
849d9397d6 SIL: Generate external key path references with local candidate components.
The other side of #17404. Since we don't want to generate up front key path metadata for properties/subscripts with no withheld implementation details, the client should generate a key path component that can be used to represent a key path component based on its public interface.
2018-07-06 14:24:07 -07:00
swift-ci
decf2b1130 Merge remote-tracking branch 'origin/master' into master-next 2018-07-05 11:49:26 -07:00
John McCall
34b0cbc11d Merge pull request #16237 from davezarzycki/metaprogram_ref_storage_types
[AST] NFC: Enable reference storage type meta-programming
2018-07-05 14:45:38 -04:00
Bob Wilson
e468fae196 Merge remote-tracking branch 'origin/master' into master-next 2018-07-04 11:13:51 -07:00
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
David Zarzycki
b61c111f12 [Serialization] NFC: Adopt reference storage type meta-programming macros 2018-06-30 06:44:34 -04:00
Bob Wilson
b254041121 Merge remote-tracking branch 'origin/master' into master-next 2018-06-28 23:23:29 -07:00
Jordan Rose
f1b347c0cc Handle non-deserializable SIL functions referenced in witness tables
This is enough to let the test case in rdar://problem/40899824 pass,
and any callers of this function already need to be able to handle a
nullptr result. There's a lot more work to do in this area, but it's
nice to get the simple things working again.
2018-06-27 17:24:22 -07:00
Jordan Rose
2a89d5cd51 Start recovering from missing types in SIL deserialization
Now that @inlinable is a supported feature, we need to handle cases
where a function is inlinable but it references some type that imports
differently in different Swift versions. To start, handle the case
where a SIL function's type is now invalid and therefore the entire
function can't be imported. This doesn't open up anything interesting
yet, but it's a start.

Part of rdar://problem/40899824
2018-06-27 11:38:27 -07:00
Bob Wilson
44712233c3 Merge remote-tracking branch 'origin/master' into master-next 2018-06-21 23:36:03 -07:00
Joe Groff
3e4e00c163 SILGen: Emit "trivial" property descriptors for properties that withhold no information about their implementation.
Client code can make a best effort at emitting a key path referencing a property with its publicly exposed API, which in the common case will match what the defining module would produce as the canonical key path component representation of the declaration. We can reduce the code size impact of these descriptors by not emitting them when there's no hidden or possibly-resiliently-changed-in-the-past information about a storage declaration, having the property descriptor symbol reference a sentinel value telling client key paths to use their definition of the key path component.
2018-06-21 15:18:24 -07:00
Bob Wilson
d933b5d60c Merge remote-tracking branch 'origin/master' into master-next 2018-06-15 20:20:25 -07:00
Jordan Rose
570ed72ea5 Add assertions to prevent truncation when using llvm::endian::Writer (#17266)
Also, stop serializing a few constant values, saving a tiny bit of
space in swiftmodule files.
2018-06-15 19:26:35 -07:00
Vedant Kumar
105a61e50d Use LLVM_DEBUG() instead of DEBUG()
Upstream has renamed the DEBUG() macro to LLVM_DEBUG. This updates swift
accordingly:

$ find . -name \*.cpp -print -exec sed -i "" -E "s/ DEBUG\(/ LLVM_DEBUG(/g" {} \;
2018-05-24 13:10:45 -07:00
swift-ci
fe33d12ead Merge remote-tracking branch 'origin/master' into master-next 2018-05-11 16:29:53 -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
swift-ci
bed7dc124d Merge remote-tracking branch 'origin/master' into master-next 2018-05-10 16:09:03 -07:00
Andrew Trick
fe326266cc [exclusivity] Add a [builtin] flag to begin_[unpaired_]access.
This flag supports promoting KeyPath access violations to an error in
Swift 4+, while building the standard library in Swift 3 mode. This is
only necessary as long as the standard library continues to build in
Swift 3 mode. Once the standard library build migrates, it can all be
ripped out.

<rdar://problem/40115738> [Exclusivity] Enforce Keypath access as an error, not a warning in 4.2.
2018-05-09 21:42:37 -07:00
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