Commit Graph

232 Commits

Author SHA1 Message Date
Erik Eckstein
74d44b74e7 SIL: remove SILValue::getDef and add a cast operator to ValueBase * as a repelacement. NFC. 2016-01-25 15:00:49 -08:00
Erik Eckstein
506ab9809f SIL: remove getTyp() from SILValue 2016-01-25 15:00:49 -08:00
Erik Eckstein
2db6f3d213 SIL: remove multiple result values from SILValue
As there are no instructions left which produce multiple result values, this is a NFC regarding the generated SIL and generated code.
Although this commit is large, most changes are straightforward adoptions to the changes in the ValueBase and SILValue classes.
2016-01-21 10:30:31 -08:00
Erik Eckstein
4dab67c582 SIL: add a new project_existential_box instruction.
It will be used as a replacement for the second return value of alloc_existential_box.
2016-01-20 11:27:06 -08:00
Michael Gottesman
6099702789 Fixes requested by Jordan when reviewing 389238e801.
These were all small fixes suggested by Jordan. All of the changes are cosmetic
except for 1 removal of a sort that was not needed.
2016-01-15 22:58:10 -08:00
John McCall
2df6880617 Introduce ProtocolConformanceRef. NFC.
The main idea here is that we really, really want to be
able to recover the protocol requirement of a conformance
reference even if it's abstract due to the conforming type
being abstract (e.g. an archetype).  I've made the conversion
from ProtocolConformance* explicit to discourage casual
contamination of the Ref with a null value.

As part of this change, always make conformance arrays in
Substitutions fully parallel to the requirements, as opposed
to occasionally being empty when the conformances are abstract.

As another part of this, I've tried to proactively fix
prospective bugs with partially-concrete conformances, which I
believe can happen with concretely-bound archetypes.

In addition to just giving us stronger invariants, this is
progress towards the removal of the archetype from Substitution.
2016-01-08 00:19:59 -08:00
Slava Pestov
046606a8f4 SIL: Add a new alloc_global instruction
If a global variable in a module we are compiling has a type containing
a resilient value type from a different module, we don't know the size
at compile time, so we cannot allocate storage for the global statically.

Instead, we will use a buffer, just like alloc_stack does for archetypes
and resilient value types.

This adds a new SIL instruction but does not yet make use of it.
2016-01-07 13:40:48 -08:00
Michael Gottesman
389238e801 Add support for multiple @_semantics attributes at the SIL level.
This is something that we have wanted for a long time and will enable us to
remove some hacks from the compiler (i.e. how we determine in the ARC optimizer
that we have "fatalError" like function) and also express new things like
"noarc".
2016-01-02 04:17:07 -06:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
practicalswift
22e10737e2 Fix typos 2015-12-26 01:19:40 +01:00
ken0nek
fcd8fcee91 Convert [Cc]an not -> [Cc]annot 2015-12-23 00:55:48 +09:00
Erik Eckstein
94d2c2fcd0 Remove a wrong TODO comment. 2015-12-11 10:00:49 -08:00
swiftix
54dcae48fc Revert "Fix TODO by removing unneeded ShouldSerializeAll parameters." 2015-12-11 08:29:31 -08:00
Gabriel Peart
971f399374 Fix TODO by removing unneeded ShouldSerializeAll parameters. 2015-12-11 09:07:16 +01:00
John McCall
5fddd4a704 Remove the autorelease_return and strong_retain_autoreleased instructions.
There's a buggy SIL verifier check that was previously tautological,
and it turns out that it's violated, apparently harmlessly.  Since it
was already doing nothing, I've commented it out temporarily while
I figure out the right way to fix SILGen to get the invariant right.
2015-12-09 14:50:20 -08:00
John McCall
bdb4b896a2 Move ObjC-compatible unowned references to the new runtime
functions.

Take the code for the old, broken reference-counting
implementation and delete it with prejudice.
2015-12-08 16:20:32 -08:00
Nadav Rotem
5f3f1a31c7 Revert "[Serialization] Fix a bug in the serialization of shared functions."
This reverts commit 422d46638e.

Jordan said that this change is incorrect. I am reverting the patch and plan to
investigate why we are deserializing shared_external functions with no body.
2015-11-29 08:25:44 -08:00
Nadav Rotem
422d46638e [Serialization] Fix a bug in the serialization of shared functions.
We do not allow external declarations with shared visibility. This commit makes
the serializer translate shared_external linkage to public_external because the
serialized functions will be available at runtime.

rdar://21989088
2015-11-28 03:04:56 -08:00
Nadav Rotem
5542bc3792 [Serialization] Fix a bug in the serialization of resilient functions
The SIL serializer can decide not to serialize the body of functions in the SIL
module, and only emit a declaration.  If we keep the original linkage kind
(public, private, etc) then the deserialized module won't pass verification
because we do not allow internal functions to have external declarations. This
commit changes the linkage kind for the functions that the serializer decides to
emit as a declaration (without a body).

rdar://21989088
2015-11-28 03:04:56 -08:00
Erik Eckstein
ee988e21cb SIL: Add stack attributes to alloc_ref and dealloc_ref.
For details see docs/SIL.rst.
This is needed for the stack promotion optimization.



Swift SVN r32908
2015-10-27 15:29:20 +00:00
Slava Pestov
76f1168adf Remove dealloc_ref's [constructor] form since its no longer needed
Swift SVN r32688
2015-10-14 22:50:09 +00:00
Slava Pestov
7cc59e01d7 SIL: Add DeallocPartialRefInst
This instruction destroys instance variables in a partially-initialized
object, then frees it.

Swift SVN r32661
2015-10-13 19:56:20 +00:00
Slava Pestov
090d723763 SIL: Remove null_class instruction
Swift SVN r32605
2015-10-11 02:11:22 +00:00
Andrew Trick
c20370a664 Remove the last remnants of unchecked_ref_bit_cast
Swift SVN r32598
2015-10-10 05:42:57 +00:00
Andrew Trick
665e5169d5 Add unchecked_ref_cast_addr SIL instruction.
Swift SVN r32587
2015-10-10 03:39:32 +00:00
Erik Eckstein
388bc31ba7 Add a nothrow flag to the SIL apply_inst.
If the compiler can prove that a throwing function actually does not throw it can
replace a try_apply with an "apply [nothrow]". Such an apply_inst calls a function
with an error result but does not have the overhead of checking for the error case.

Currently this flag is not set, yet.



Swift SVN r31151
2015-08-12 00:18:36 +00:00
Slava Pestov
1628bfc3e2 SIL: Split dealloc_ref into [constructor] and [destructor] kinds
dealloc_ref [destructor] is the existing behavior. It expects the
reference count to have reached zero and the isDeallocating bit to
be set.

The new [constructor] variant first drops the initial strong
reference.

This allows DI to properly free uninitialized instances in
constructors. Previously this would fail with an assertion if the
runtime was built with debugging enabled.

Progress on <rdar://problem/21991742>.

Swift SVN r31142
2015-08-11 18:38:00 +00:00
Roman Levenstein
d5650ae210 Propagate a "let" flag from VarDecl into resulting SILGlobalVariables.
This flag is required for performing the propagation of global and static "let" values into their uses.
Let variables have now a [let] attribute in the SIL textual form.

Swift SVN r30153
2015-07-13 19:03:23 +00:00
Andrew Trick
7565a65235 Introduce unchecked_bitwise_cast SIL instruction.
We need a SIL level unsafe cast that supports arbitrary usage of
UnsafePointer, generalizes Builtin.reinterpretCast, and has the same
semantics on generic vs. nongeneric code. In other words, we need to
be able to promote the cast of an address type to the cast of an
object type without changing semantics, and that cast needs to support
types that are not layout identical.

This patch introduces an unchecked_bitwise_cast instruction for that
purpose. It is different from unsafe_addr_cast, which has been our
fall-back "unknown" cast in the past. With unchecked_bitwise_cast we
cannot assume layout or RC identity. The cast implies a store and
reload of the value to obtain the low order bytes. I know that
bit_cast is just an abbreviation for bitwise_cast, but we use
"bitcast" throught to imply copying a same sized value. No one could
come up with a better name for copying an objects low bytes via:

  @addr = alloca $wideTy
    store @addr, $wideTy
      load  @addr, $narrowTy

Followup patches will optimize unchecked_bitwise_cast into more
semantically useful unchecked casts when enough type information is
present. This way, the optimizer will rarely need to be taught about
the bitwise case.

Swift SVN r29510
2015-06-19 16:29:35 +00:00
Joe Groff
821b0f488e SIL: Add a project_box insn to project the address of the value from a box.
Still no implementation yet; we'll need to renovate how boxes work a bit to make them projectable (and renovate SILGen to generate typed boxes for the insn to be useful).

Swift SVN r29490
2015-06-18 15:47:22 +00:00
Mark Lacey
f56ca1ed68 Revert "SIL: Add a project_box insn to project the address of the value from a box."
This reverts commit r29475 because it conflicts with reverting r29474,
and it looks like that commit is breaking the build of the SpriteKit
overlay.

Swift SVN r29481
2015-06-18 06:27:52 +00:00
Joe Groff
15c29e5d1f SIL: Add a project_box insn to project the address of the value from a box.
Still no implementation yet; we'll need to renovate how boxes work a bit to make them projectable (and renovate SILGen to generate typed boxes for the insn to be useful).

Swift SVN r29475
2015-06-18 04:07:23 +00:00
Jordan Rose
ac5fa6740c [Serialization] Only serialize witness tables for the current file or module.
Otherwise, we end up with duplicates.

rdar://problem/21145040

Swift SVN r29121
2015-05-28 23:33:08 +00:00
Slava Pestov
76490922c7 Fix serialization of TryApplyInst
Fixes <rdar://problem/20925014>

Swift SVN r28688
2015-05-18 00:21:42 +00:00
Jordan Rose
9ef66a35e1 [Serialization] Avoid some non-determinism in the serializer.
Unfortunately, we still have non-determinism coming from elsewhere, so we
can't start trying to test this yet.

Motivated by rdar://problem/20539158

Swift SVN r28576
2015-05-14 20:10:53 +00:00
Doug Gregor
b8995b0aa3 Transform the Module class into ModuleDecl.
Modules occupy a weird space in the AST now: they can be treated like
types (Swift.Int), which is captured by ModuleType. They can be
treated like values for disambiguation (Swift.print), which is
captured by ModuleExpr. And we jump through hoops in various places to
store "either a module or a decl".

Start cleaning this up by transforming Module into ModuleDecl, a
TypeDecl that's implicitly created to describe a module. Subsequent
changes will start folding away the special cases (ModuleExpr ->
DeclRefExpr, name lookup results stop having a separate Module case,
etc.).

Note that the Module -> ModuleDecl typedef is there to limit the
changes needed. Much of this patch is actually dealing with the fact
that Module used to have Ctx and Name public members that now need to
be accessed via getASTContext() and getName(), respectively.

Swift SVN r28284
2015-05-07 21:10:50 +00:00
Andrew Trick
a174aa4dfe Add AST and SILGen support for Builtin.isUnique.
Preparation to fix <rdar://problem/18151694> Add Builtin.checkUnique
to avoid lost Array copies.

This adds the following new builtins:

    isUnique : <T> (inout T[?]) -> Int1
    isUniqueOrPinned : <T> (inout T[?]) -> Int1

These builtins take an inout object reference and return a
boolean. Passing the reference inout forces the optimizer to preserve
a retain distinct from what’s required to maintain lifetime for any of
the reference's source-level copies, because the called function is
allowed to replace the reference, thereby releasing the referent.

Before this change, the API entry points for uniqueness checking
already took an inout reference. However, after full inlining, it was
possible for two source-level variables that reference the same object
to appear to be the same variable from the optimizer's perspective
because an address to the variable was longer taken at the point of
checking uniqueness. Consequently the optimizer could remove
"redundant" copies which were actually needed to implement
copy-on-write semantics. With a builtin, the variable whose reference
is being checked for uniqueness appears mutable at the level of an
individual SIL instruction.

The kind of reference count checking that Builtin.isUnique performs
depends on the argument type:

    - Native object types are directly checked by reading the
      strong reference count:
      (Builtin.NativeObject, known native class reference)

    - Objective-C object types require an additional check that the
      dynamic object type uses native swift reference counting:
      (Builtin.UnknownObject, unknown class reference, class existential)

    - Bridged object types allow the dymanic object type check to be
      bypassed based on the pointer encoding:
      (Builtin.BridgeObject)

Any of the above types may also be wrapped in an optional.  If the
static argument type is optional, then a null check is also performed.

Thus, isUnique only returns true for non-null, native swift object
references with a strong reference count of one.

isUniqueOrPinned has the same semantics as isUnique except that it
also returns true if the object is marked pinned regardless of the
reference count. This allows for simultaneous non-structural
modification of multiple subobjects.

In some cases, the standard library can dynamically determine that it
has a native reference even though the static type is a bridge or
unknown object. Unsafe variants of the builtin are available to allow
the additional pointer bit mask and dynamic class lookup to be
bypassed in these cases:

    isUnique_native : <T> (inout T[?]) -> Int1
    isUniqueOrPinned_native : <T> (inout T[?]) -> Int1

These builtins perform an implicit cast to NativeObject before
checking uniqueness. There’s no way at SIL level to cast the address
of a reference, so we need to encapsulate this operation as part of
the builtin.

Swift SVN r27887
2015-04-28 22:54:24 +00:00
Chris Lattner
42b4a966b0 Introduce a new null_class SIL instruction for forming a null pointer
reference to something of class type.  This is required to model
RebindSelfInConstructorExpr correctly to DI, since in the class case, 
self.init and super.init *take* a value out of class box so that it 
can pass the +1 value without performing an extra retain.  Nothing
else in the compiler uninitializes a DI-controlled memory object
like this, so nothing else needs this.  DI really doesn't like something
going from initialized to uninitialized.

Yes, I feel super-gross about this and am really unhappy about it.  I
may end up reverting this if I can find an alternate solution to this
problem.



Swift SVN r27525
2015-04-21 05:56:55 +00:00
John McCall
6d8fff9c06 Parsing and basic structure of try_apply. Not yet properly
threaded into IRGen; tests to follow when that's done.

I made a preliminary effort to make the inliner do the
right thing with try_apply, but otherwise tried to avoid
touching the optimizer any more than was required by the
removal of ApplyInstBase.

Swift SVN r26747
2015-03-31 02:41:03 +00:00
John McCall
1ffb87bb1f Implement a 'throw' instruction in SIL.
Swift SVN r26668
2015-03-28 02:00:20 +00:00
Luqman Aden
35c56fb0bd [Serialization] Only serialize vtables for classes from the current
module.

rdar://problem/20295441

Swift SVN r26569
2015-03-26 00:45:18 +00:00
Mark Lacey
1f23ff27bb Remove the transparent bit from apply instructions.
We no longer need or use it since we can always refer to the same bit on
the applied function when deciding whether to inline during mandatory
inlining.

Resolves rdar://problem/19478366.

Swift SVN r26534
2015-03-25 08:36:34 +00:00
Doug Gregor
8b97f911c6 Reimplement (de-)serialization of protocol conformances.
Primarily, unique normal protocol conformances and reference them via
a conformance ID. This eliminates the use of trailing records for
normal protocol conformances and (more importantly) the cases were we
would write incomplete conformances. The latter could cause problems
if we ever ended up deserializing an incomplete conformance without
also deserializing a complete record for that same conformance.

Secondarily, simplify the way we write conformances. They are now
always trailing records, and we separate out the derived conformance
kinds (specialized/inherited) from either a reference to a normal
conformance in the current module file (via a normal conformance ID)
or via a cross-reference to a conformance in another module file
(currently always a normal conformance, but this need not always be
the case). As part of this, make each conformance record
self-sustaining, so we don't have to push information down to the
reading routines (e.g., the conforming type) to actually produce a
proper conformance. This simplifies deserialization logic further.

Swift SVN r26482
2015-03-24 06:48:23 +00:00
Joe Groff
fdde2a8e99 SIL: Add instructions for boxed existential operations.
Parsing and serialization for {Alloc,Open,Dealloc}ExistentialBox instructions to represent operations on ErrorType boxes.

Swift SVN r26145
2015-03-15 03:32:37 +00:00
Joe Groff
962a87f444 SIL: Rename address-only existential instructions to '{init,deinit,open}_existential_addr'.
For better consistency with other address-only instruction variants, and to open the door to new exciting existential representations (such as a refcounted boxed representation for ErrorType).

Swift SVN r25902
2015-03-09 23:55:31 +00:00
Luqman Aden
34b74cfa1c [driver] Add -emit-sib primary action.
Swift SVN r25783
2015-03-05 19:15:07 +00:00
Erik Eckstein
9dfd349faf Add a new Thunk-flag in SILFunction which specifies that a function is a thunk.
This will have an effect on inlining into thunks.
Currently this flag is set for witness thunks and thunks from function signature optimization.
No change in code generation, yet.



Swift SVN r24998
2015-02-05 16:45:05 +00:00
Michael Gottesman
897325b096 Codebase Gardening. NFC.
1. Eliminate unused variable warnings.
2. Change field names to match capitalization of the rest of the field names in the file.
3. Change method names to match rest of the file.
4. Change get,set method for a field to match the field type.

Swift SVN r24501
2015-01-19 00:34:07 +00:00
John McCall
5c8fbc704c Add SIL instructions to convert between thin functions
and raw pointers.

Swift SVN r23992
2014-12-17 22:23:15 +00:00
John McCall
169e4fe319 Add Builtin.UnsafeValueBuffer, which provides opaque
storage for arbitrary values.

A buffer doesn't provide any way to identify the type of
value it stores, and so it cannot be copied, moved, or
destroyed independently; thus it's not available as a
first-class type in Swift, which is why I've labelled
it Unsafe.  But it does allow an efficient means of
opaquely preserving information between two cooperating
functions.  This will be useful for the adjustments I
need to make to materializeForSet to support safe
addressors.

I considered making this a SIL type category instead,
like $@value_buffer T.  This is an attractive idea because
it's generally better-typed.  The disadvantages are that:
- it would need its own address_to_pointer equivalents and
- alloc_stack doesn't know what type will be stored in
  any particular buffer, so there still needs to be
  something opaque.

This representation is a bit gross, but it'll do.

Swift SVN r23903
2014-12-13 01:27:12 +00:00