Commit Graph

834 Commits

Author SHA1 Message Date
Bob Wilson
deddf19aae Merge remote-tracking branch 'origin/master' into master-next 2016-12-13 10:23:03 -08:00
Michael Gottesman
66cff7e37e [semantic-arc] Add StoreBorrowInst and BeginBorrowInst. 2016-12-12 13:06:18 -08:00
Michael Gottesman
9792bda1ce [deserialization] When deserializing sil, deserialize all globals even if they are not referenced by anything else that would cause them to be deserialized.
I noticed this when trying to figure out why sil-nm was not dumping certain
globals.

This will be tested by the addition of sil-nm in the next commit.
2016-12-08 17:43:31 -08:00
Bob Wilson
13da3fa8b1 Merge remote-tracking branch 'origin/master' into master-next 2016-12-04 18:16:09 -08:00
Joe Groff
9b858a7431 SIL: Remove the ElementType from DeallocBoxInst's representation.
This was made redundant by typed boxes, and the type operand was already removed from textual SIL, but the field was never removed from the instruction's in memory representation. It becomes wrong in the face of compound boxes with layout.
2016-12-02 15:19:43 -08:00
Michael Gottesman
96837babda Merge pull request #5920 from gottesmm/vacation_gardening
Vacation gardening
2016-11-25 09:17:21 -06:00
Michael Gottesman
0a8c54d04f [gardening] Always create new SILArguments using SILBasicBlock::createArgument instead of inline placement new.
The reasoning here is the same as in e42bf07.
2016-11-25 01:14:45 -06:00
Michael Gottesman
e42bf07af4 [gardening] Always create SILBasicBlocks via SILFunction::createBasicBlock.
This eliminates all inline creation of SILBasicBlock via placement new.

There are a few reasons to do this:

1. A SILBasicBlock is always created with a parent function. This commit
formalizes this into the SILBasicBlock API by only allowing for SILFunctions to
create SILBasicBlocks. This is implemented via the type system by making all
SILBasicBlock constructors private. Since SILFunction is a friend of
SILBasicBlock, SILFunction can still create a SILBasicBlock without issue.

2. Since all SILBasicBlocks will be created in only a few functions, it becomes
very easy to determine using instruments the amount of memory being allocated
for SILBasicBlocks by simply inverting the call tree in Allocations.

With LTO+PGO, normal inlining can occur if profitable so there shouldn't be
overhead that we care about in shipping compilers.
2016-11-25 01:12:49 -06:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
Saleem Abdulrasool
46d684f35f remove usage of BitstreamReader
LLVM SVN r286207 removed the BitstreamReader interface.  Remove the usage of the
type, updating the cursor constructor accordingly.
2016-11-15 17:39:37 -08:00
Huon Wilson
e92b9c2fc1 [Serialization] Remove extraneous argument from ModuleFile::readGenericEnvironment. 2016-11-11 15:02:28 -08:00
Huon Wilson
1102cf6643 [AST] Store a GenericSignature in GenericEnvironment.
An environment is always associated with a location with a signature, so
having them separate is pointless duplication. This patch also updates
the serialization to round-trip the signature data.
2016-11-11 14:57:03 -08:00
Joe Groff
e1e7e19248 SIL: Construct alloc_box insns with the type of the box.
This becomes necessary with generalized boxes, since the box type isn't derivable from a single field type.
2016-11-03 19:26:42 -07:00
Michael Gottesman
e077502285 [semantic-arc] When deserializing functions, only set the unqualified bit when we deserialize the body.
There is no reason to make a declaration have qualified or unqualified
ownership. Incidently, this also fixes a bug where we were only setting the
unqualified bit for functions created in the deserializer. If we created a
declaration and linked it in later, we would not get the proper setting for
ownership qualification.

rdar://28851920
2016-10-29 20:11:07 -07:00
Michael Gottesman
68e1940083 [semantic-arc] Instead of using the parsing heuristic for determining ownership when serializing, just serialize a bit.
The reason we are using the parsing heuristic is to ensure that we do
not need to update a ton of test cases. This makes sense since in
general, when parsing we are creating new code that is running for the
first time through the compiler. On the other hand, in
serialization/deserialization we expect to get back exactly the
SILFunction that we serialized. So it makes sense to explicitly
preserve whether we have ownership qualification or not.

rdar://28851920
2016-10-25 00:01:48 -07:00
Joe Groff
e4c67e2d5a SIL: Give project_box a field index operand.
Allow project_box to get the address of any field in a multi-field box.
2016-10-24 13:10:41 -07:00
Michael Gottesman
1b1d90fff0 [semantic-arc] Implement simple verification of the ownership qualification of copy_value, destroy_value.
rdar://28851920
2016-10-23 00:34:26 -07:00
Michael Gottesman
ab0ffa2c39 [semantic-arc] Wire up Parsing/Printing/IRGen/Serialization/Deserialization for copy_value, destroy_value.
rdar://28851920
2016-10-22 22:10:57 -07:00
Michael Gottesman
a3e7bd6cad [semantic-arc] As staging detail, add a HasQualifiedOwnership flag on all SILFunctions.
Over the past day or so I have been thinking about how we are going to need to
manage verification of semantic ARC semantics in the pass pipeline. Specifically
the Eliminator pass really needs to be a function pass to ensure that we can
transparently put it at any stage of the optimization pipeline. This means that
just having a flag on the SILVerifier that states whether or not ownership is
enabled is not sufficient for our purposes. Instead, while staging in the SIL
ownership model, we need a bit on all SILFunctions to state whether the function
has been run through the ownership model eliminator so that the verifier can
ensure that we are in a world with "SIL ownership" or in a world without "SIL
ownership", never in a world with only some "SIL ownership" instructions. We
embed this distinction in SIL by creating the concept of a function with
"qualified ownership" and a function with "unqualified ownership".

Define a function with "qualified ownership" as a function that contains no
instructions with "unqualified ownership" (i.e. unqualified load) and a function
with "unqualified ownership" as a function containing such no "ownership
qualified" instructions (i.e. load [copy]) and at least 1 unqualified ownership
instruction.

This commit embeds this distinction into SILFunction in a manner that is
transparently ignored when compiling with SIL ownership disabled. This is done
by representing qualified or unqualified ownership via an optional Boolean on
SILFunction. If the Boolean is None, then SILOwnership is not enabled and the
verifier/passes can work as appropriate. If the Boolean is not None, then it
states whether or not the function has been run through the Ownership Model
Eliminator and thus what invariants the verifier should enforce.

How does this concept flow through the compilation pipeline for functions in a
given module? When SIL Ownership is enabled, all SILFunctions that are produced
in a given module start with "qualified ownership" allowing them to contain SIL
ownership instructions. After the Ownership Model eliminator has run, the
Ownership Model sets the "unqualified" ownership flag on the SILFunction stating
that no more ownership qualified instructions are allowed to be seen in the
given function.

But what about functions that are parsed or are deserialized from another
module? Luckily, given the manner in which we have categories our functions, we
can categorize functions directly without needing to add anything to the parser
or to the deserializer. This is done by enforcing that it is illegal to have a
function with qualified ownership and unqualified ownership instructions and
asserting that functions without either are considered qualified.

rdar://28685236
2016-10-21 17:37:02 -07:00
Michael Gottesman
d7951f8bdc [semantic-arc] When parsing/deserializing SILInstructions, we know that ResultVal is always a SILInstruction, so just make it a SILInstruction instead of a ValueBase.
As I was preparing a semantic arc commit that worked in this area, I realized I
needed ResultVal to be a SILInstruction, not a ValueBase. As I prepared to
perform a dyn_cast, I realized that ResulVal is always a SILInstruction
anyways... so why not just use the right type in the first place... Thus this
commit.

*sigh*

rdar://28685236
2016-10-21 11:55:48 -07:00
Michael Gottesman
c41ead0b72 [semantic-arc] Add support for the load_borrow and end_borrow instructions to SIL, Serialization, Printing/Parsing.
I did not add it to the ownership verifier or to IRGen yet.

rdar://28685236
2016-10-20 10:53:44 -07:00
Michael Gottesman
e0bea5f9bb [semantic-arc] Implement SIL serialization support for ownership qualified store and load.
rdar://28685236
2016-10-15 18:10:52 -07:00
Joe Groff
664390ace3 SIL: Add the ability for partial_apply instructions to control the ownership of the produced closure.
This lets us get to the goal of +0 guaranteed closure contexts. NFC yet, just add the under-the-hood ability for partial_apply instructions producing callee-guaranteed closures to be parsed, printed, and serialized.
2016-10-06 15:38:04 -07:00
Erik Eckstein
db00c5e924 SIL: allow alloc_ref_dynamic to allocate tail elements.
It's the same thing as for alloc_ref: the optional [tail_elems ...] attribute specify the tail elements to allocate.
For details see docs/SIL.rst

This feature is needed so that we can allocate a MangedBuffer with alloc_ref_dynamic.
The ManagedBuffer.create() function uses the dynamic self type to create the buffer instance.
2016-10-06 08:46:23 -07:00
practicalswift
3a4ee89034 [gardening] Use consistent formatting. 2016-09-17 12:12:49 +02:00
Erik Eckstein
34a4e6df0a SIL: add new instructions to support tail-allocated arrays in SIL.
The new instructions are: ref_tail_addr, tail_addr and a new attribute [ tail_elems ] for alloc_ref.
For details see docs/SIL.rst

As these new instructions are not generated so far, this is a NFC.
2016-09-16 11:02:19 -07:00
Erik Eckstein
84a949c751 Fix a compiler warning 2016-09-16 09:20:19 -07:00
Erik Eckstein
670ba8a3fc Don't serialize debug_value/debug_value_addr instructions.
We didn't serialize the their var-info so after de-serializing they were useless anyway.
By not serializing them we get rid of useless debug_value instructions coming from the stdlib.
In future we might change this and fully serialize them.
2016-09-15 17:15:19 -07:00
Dmitri Gribenko
fbb3cf35a5 Revert "New SIL instructions to support tail-allocated arrays in SIL." 2016-09-15 00:25:25 -07:00
Erik Eckstein
b11b60e658 SIL: add new instructions to support tail-allocated arrays in SIL.
The new instructions are: ref_tail_addr, tail_addr and a new attribute [ tail_elems ] for alloc_ref.
For details see docs/SIL.rst

As these new instructions are not generated so far, this is a NFC.
2016-09-14 14:54:18 -07:00
Slava Pestov
ca0b548584 SIL: Replace SILFunction::ContextGenericParams with a GenericEnvironment
This patch is rather large, since it was hard to make this change
incrementally, but most of the changes are mechanical.

Now that we have a lighter-weight data structure in the AST for mapping
interface types to archetypes and vice versa, use that in SIL instead of
a GenericParamList.

This means that when serializing a SILFunction body, we no longer need to
serialize references to archetypes from other modules.

Several methods used for forming substitutions can now be moved from
GenericParamList to GenericEnvironment.

Also, GenericParamList::cloneWithOuterParameters() and
GenericParamList::getEmpty() can now go away, since they were only used
when SILGen-ing witness thunks.

Finally, when printing generic parameters with identical names, the
SIL printer used to number them from highest depth to lowest, by
walking generic parameter lists starting with the innermost one.
Now, ambiguous generic parameters are numbered from lowest depth
to highest, by walking the generic signature, which means test
output in one of the SILGen tests has changed.
2016-08-28 13:51:37 -07:00
Roman Levenstein
89c41ca2d4 [sil-serializer] Do not use RPOT order for serializing SIL basic blocks
My earlier patch started serializing SIL basic blocks using the RPOT order. While it works, changing the existing order of BBs during the serialization may be very surprising for users. After all, serialization is not supposed to transform the code.

Therefore, this patch follows a different approach. It uses the existing order of BBs during the serialization. When it deserializes/parses SIL and detects a use of an opened archetype before its definition, it basically introduced a forward definition of this opened archetype. Later on, when the actual definition of the opened archetype is found, it replaces the forward definition. There is a correctness check at the end of a SIL function deserialization, which verifies that there are no forward definitions of opened archetypes left unresolved.
2016-07-19 13:04:40 -07:00
Andrew Trick
2b732d0af5 Introduce Builtin.bindMemory and SIL bind_memory. (#3573)
Required for SE-0107: UnsafeRawPointer.
2016-07-18 13:18:03 -07:00
Roman Levenstein
c8284b0109 Revert "[sil-serializer] Do not use RPOT order for serializing SIL basic blocks"
This reverts commit 2f9ee20df2.
It broke some of the stdlib serialization tests.

rdar://problem/27404044
2016-07-18 10:37:08 -07:00
Roman Levenstein
2f9ee20df2 [sil-serializer] Do not use RPOT order for serializing SIL basic blocks
My earlier patch started serializing SIL basic blocks using the RPOT order. While it works, changing the existing order of BBs during the serialization may be very surprising for users. After all, serialization is not supposed to transform the code.

Therefore, this patch follows a different approach. It uses the existing order of BBs during the serialization. When it deserializes SIL and detects a use of an opened archetype before its definition, it basically introduced a forward definition of this opened archetype. Later on, when the actual definition of the opened archetype is found, it replaces the forward definition. There is a correctness check at the end of a SIL function deserialization, which verifies that there are no forward definitions of opened archetypes left unresoved.
2016-07-16 21:53:17 -07:00
Andrew Trick
c47687da2c Add an isStrict flag to SIL pointer_to_address. (#3529)
Strict aliasing only applies to memory operations that use strict
addresses. The optimizer needs to be aware of this flag. Uses of raw
addresses should not have their address substituted with a strict
address.

Also add Builtin.LoadRaw which will be used by raw pointer loads.
2016-07-15 15:04:02 -05:00
adrian-prantl
64d998d4d8 Merge pull request #3213 from adrian-prantl/24102282
Merge SILFunction::Location into SILFunction::DebugScope::Loc.
2016-07-06 12:05:48 -07:00
practicalswift
dd93d551df [gardening] Fix recently introduced typos 2016-07-01 19:28:34 +02:00
Roman Levenstein
794d72e923 Track dependencies of SIL instructions on opened archetypes which they use
Till now there was no way in SIL to explicitly express a dependency of an instruction on any opened archetypes used by it. This was a cause of many errors and correctness issues. In many cases the code was moved around without taking into account these dependencies, which resulted in breaking the invariant that any uses of an opened archetype should be dominated by the definition of this archetype.

This patch does the following:
- Map opened archetypes to the instructions defining them, i.e. to open_existential instructions.
- Introduce a helper class SILOpenedArchetypesTracker for creating and maintaining such mappings.
- Introduce a helper class SILOpenedArchetypesState for providing a read-only API for looking up available opened archetypes.
- Each SIL instruction which uses an opened archetype as a type gets an additional opened archetype operand representing a dependency of the instruction on this archetype. These opened archetypes operands are an in-memory representation. They are not serialized. Instead, they are re-constructed when reading binary or textual SIL files.
- SILVerifier was extended to conduct more thorough checks related to the usage of opened archetypes.
2016-06-28 08:43:01 -07:00
Adrian Prantl
a23c990111 Merge SILFunction::Location into SILFunction::DebugScope::Loc.
NFC intended.
2016-06-25 15:16:17 -07:00
swiftix
be27850aa2 Revert "Track dependencies of SIL instructions on opened archetypes which they use" 2016-06-24 21:25:08 -07:00
Roman Levenstein
9d4fc913d9 Track dependencies of SIL instructions on opened archetypes which they use
Till now there was no way in SIL to explicitly express a dependency of an instruction on any opened archetypes used by it. This was a cause of many errors and correctness issues. In many cases the code was moved around without taking into account these dependencies, which resulted in breaking the invariant that any uses of an opened archetype should be dominated by the definition of this archetype.

This patch does the following:
- Map opened archetypes to the instructions defining them, i.e. to open_existential instructions.
- Introduce a helper class SILOpenedArchetypesTracker for creating and maintaining such mappings.
- Introduce a helper class SILOpenedArchetypesState for providing a read-only API for looking up available opened archetypes.
- Each SIL instruction which uses an opened archetype as a type gets an additional opened archetype operand representing a dependency of the instruction on this archetype. These opened archetypes operands are an in-memory representation. They are not serialized. Instead, they are re-constructed when reading binary or textual SIL files.
- SILVerifier was extended to conduct more thorough checks related to the usage of opened archetypes.
2016-06-24 10:36:52 -07:00
Xin Tong
4526e88bef Revert "Track dependencies of SIL instructions on opened archetypes which they use"
This reverts commit 8ef8bb4eb1.

Broke swift_tools-RA_stdlib-RD_test-no_device and soem others
2016-06-22 18:17:25 -07:00
Roman Levenstein
8ef8bb4eb1 Track dependencies of SIL instructions on opened archetypes which they use
Till now there was no way in SIL to explicitly express a dependency of an instruction on any opened archetypes used by it. This was a cause of many errors and correctness issues. In many cases the code was moved around without taking into account these dependencies, which resulted in breaking the invariant that any uses of an opened archetype should be dominated by the definition of this archetype.

This patch does the following:
- Map opened archetypes to the instructions defining them, i.e. to open_existential instructions.
- Introduce a helper class SILOpenedArchetypesTracker for creating and maintaining such mappings.
- Introduce a helper class SILOpenedArchetypesState for providing a read-only API for looking up available opened archetypes.
- Each SIL instruction which uses an opened archetype as a type gets an additional opened archetype operand representing a dependency of the instruction on this archetype. These opened archetypes operands are an in-memory representation. They are not serialized. Instead, they are re-constructed when reading binary or textual SIL files.
- SILVerifier was extended to conduct more thorough checks related to the usage of opened archetypes.
2016-06-22 14:28:39 -07:00
Joe Groff
9398ce9413 SILGen: Propagate generic types through func-to-block invoke functions.
Now that ObjC types can be generic, we need to satisfy the type system by plumbing pseudogeneric parameters through func-to-block invocation thunks. Fixes rdar://problem/26524763.
2016-06-01 19:37:43 -07:00
John McCall
c2b8bb22ba Provide ways to get back to the original Clang declaration from
a SILFunction or SILGLobalVariable.

This will be used as one step towards moving IRGen off of the
global external-definitions list.
2016-05-18 11:40:58 -07:00
Slava Pestov
2e52338d7c SIL: Rename long form of getOrCreateFunction() to createFunction(), NFC
This made call sites confusing to read because it doesn't actually
check if the function already exists.

Also fix some minor formatting issues. This came up while I was working
on a fix for a bug that turned out to not be a bug.
2016-04-21 17:58:10 -07:00
practicalswift
9cbfddbb12 [gardening] Fix recently introduced typo: "modelled" → "modeled" 2016-04-14 22:26:44 +02:00
practicalswift
c36c517e34 [gardening] Fix recently introduced typo: "noticable" → "noticeable" 2016-04-14 09:51:28 +02:00
Roman Levenstein
9234eb3ca7 [sil-linker] Improve the implementation of the hasSILFunction API
It it now possible to check if a function with a given name and a given linkage exists in one of the modules,
even if the current module contains a function with this name but a difference linkage.
This is useful e.g. for performing a lookup of pre-specializations.
2016-04-13 15:46:57 -07:00