Commit Graph

834 Commits

Author SHA1 Message Date
Joe Groff
21429cbfae Revert "Serialization: Fix a couple of issues with serializing context params of generic SILFunctions."
This reverts commit 57ec1ee1e888b7ed61b731237218cd9529143d2d. It fixes r13984
but breaks ToT.

Swift SVN r14006
2014-02-17 20:32:04 +00:00
Joe Groff
67fd13ed66 Serialization: Fix a couple of issues with serializing context params of generic SILFunctions.
- Parameterize maybeReadGenericParams' BitstreamCursor so that we can read from the correct cursor when trying to read the generic params of a SILFunction.
- Only serialize the context generic params for SILFunctions for which we're serializing a complete definition. This fixes issues with us getting the wrong archetypes forward-declared from references in other modules.

This gets me a clean build when applied against r13984.

Swift SVN r14005
2014-02-17 20:05:46 +00:00
Chris Lattner
a6640a1b12 Rework has .sil files handle computed vardecls and subscripts.
Previously, we would just parse vars and subscripts with no definitions,
then let getters and setters be referenced arbitrarily later.  This was
problematic for a number of reasons, not least of which, the .sil file
might be invalid.

Instead, change sil to require that a protocol style definition indicate
whether a vardecl/subscript is computed or not, and whether it is both 
get-able and set-able, e.g. like "var x : Int { get }".  Change the 
sil printer to print decls in this form, and change the SILParser to 
make SILDeclRef::Func values instead of ::Getter/Setter values.

One thing that this exposed is that we weren't correctly serializing the
accessor state in modules, so accessors would get detatched from their
AbstractStorageDecls when deserialized (and in fact, their ASD never got
deserialized at all in some cases).  Fix this in the serialization of
the accessors.

NFC, other than the SIL printer and parser.



Swift SVN r13884
2014-02-14 00:57:04 +00:00
Doug Gregor
2134072285 Split open_existential[_ref] out as their own instructions.
Riding off of project_existential[_ref] was convenient, but the
resuls are used quite differently. Note that open_existential[_ref]
still don't print/parse reasonably yet.



Swift SVN r13878
2014-02-13 23:42:23 +00:00
Joe Groff
6fbb356cc7 Serialization: Deserialize apply and partial_apply using substFnType's interface type.
NFC, since the substFnType is never generic.

Swift SVN r13698
2014-02-09 06:50:23 +00:00
Manman Ren
b6217c2242 SILSerializer: preserve correct type of generic StructExtract/StructElementAddrInsts.
rdar://15893086


Swift SVN r13657
2014-02-07 22:36:35 +00:00
Manman Ren
f455e6db7f SILSerializer: serialize 3 more witness entry types.
method type was handled earlier. This commit handles associated_type,
associated_type_protocol and base_protocol.

rdar://15722175


Swift SVN r13538
2014-02-06 01:43:46 +00:00
Joe Groff
0c0d30d5eb SIL: Make ContextGenericParams a constructor parameter of SILFunction.
Edge SILFunction one step closer to independence from SILFunctionType context by taking the generic param list as a separate constructor parameter, and serializing those params alongside the function record. For now we still pass in the context params from the SILFunctionType in most cases, because the logic for finding the generic params tends to be entangled in type lowering, but this pushes the problem up a step.

Thanks Jordan for helping work out the serialization changes needed.

Compared to r13036, this version of the patch includes the decls_block RecordKind enumerators for the GENERIC_PARAM_LIST layouts in the sil_block RecordKind enumerator, as Jordan had suggested before. r13036 caused buildbot failures when building for iOS, but I am unable to reproduce those failures locally now.

Swift SVN r13485
2014-02-05 16:52:02 +00:00
Michael Gottesman
800ea37c34 Revert r13036 as per Joe's request.
Swift SVN r13063
2014-01-28 21:36:06 +00:00
Joe Groff
5d58f10e48 SIL: Make ContextGenericParams a constructor parameter of SILFunction.
Edge SILFunction one step closer to independence from SILFunctionType context by taking the generic param list as a separate constructor parameter, and serializing those params alongside the function record. For now we still pass in the context params from the SILFunctionType in most cases, because the logic for finding the generic params tends to be entangled in type lowering, but this pushes the problem up a step.

Thanks Jordan for helping work out the serialization changes needed.

Swift SVN r13036
2014-01-28 02:17:46 +00:00
Manman Ren
eaad8df51a SILSerializer: handle SILWitnessTable.
We add two records in sil_block to specify a witness table record and a method
entry record. Out of the four entry types, only "Method" is handled in this
commit.

Two records are also added to sil_index_block to search for a specific witness
table given a unique identifier. The interface lookupWitnessTable is not
implemented yet.

Right now, we serialize a witness table only when sil-serialize-all is on and
deserialize all witness tables in the module when sil-link-all is on.

rdar://15722175


Swift SVN r13000
2014-01-27 19:30:43 +00:00
Joe Groff
63ede14d40 Fix deserialization of partial_apply insns with out parameters.
Instead of taking the scenic route of building a Swift function type from the parameter types and re-lowering it to a SIL type, which loses the parameter convention information, derive the type of the partial_apply directly from the type of its callee. Addresses part of the problem with <rdar://problem/15884245>, but does not fix it, because it looks like we still don't serialize closures referenced inside transparent functions.

Swift SVN r12970
2014-01-26 22:32:46 +00:00
Joe Groff
a17654a7dd Serialization: Serialize the conformances of InitExistential*Inst.
Swift SVN r12847
2014-01-23 03:58:43 +00:00
Doug Gregor
3a6db8292e Revert "Introduce the self_downcast SIL instruction to downcast the result of super.init."
We need to model the difference between Objective-C- and Swift-rooted
class hierarchies in SIL. IRGen is too late to handle nil returns.

This reverts commit 549db981ea0136a67aee3029aefe18a05d3c8833.

Swift SVN r12400
2014-01-16 06:01:21 +00:00
Doug Gregor
d19065048b Introduce the self_downcast SIL instruction to downcast the result of super.init.
No functional difference from the unconditional checked downcast we
had before, but this gives IRGen the chance to specialize the
implementation.

Swift SVN r12382
2014-01-16 04:24:56 +00:00
Doug Gregor
68e416bb21 SIL: Zap the unused "coerce" instruction.
The coercion doesn't represent anything interesting for SIL.


Swift SVN r12261
2014-01-13 23:50:12 +00:00
Chris Lattner
1c7803a1f9 Introduce new debug_value and debug_value_addr instructions to
give 'let' declarations debug info.  This is part of rdar://15785053.

IRGen is just stubbed out and nothing generates these yet (other than
the sil parser).


Swift SVN r12179
2014-01-11 01:07:36 +00:00
Doug Gregor
3f09a9891d Add an [objc] bit to the alloc_ref instruction to indicate when to use Objective-C's +allocWithZone:.
Swift SVN r12099
2014-01-09 21:35:55 +00:00
John McCall
5da6defa1f Clean up the linkage model and the computation of linkage.
In general, this forces SILGen and IRGen code that's grabbing
a declaration to state whether it's doing so to define it.

Change SIL serialization to serialize the linkage of functions
and global variables, which means also serializing declarations.

Change the deserializer to use this stored linkage, even when
only deserializing a declaration, and to call a callback to
inform the client that it has deserialized a new entity.

Take advantage of that callback in the linking pass to alter
the deserialized linkage as appropriate for the fact that we
imported the declaration.  This computation should really take
advantage of the relationship between modules, but currently
it does not.

Swift SVN r12090
2014-01-09 08:58:07 +00:00
Joe Groff
8f6a58b998 SIL: Split address-only enum dispatch from destructive projection.
Split 'destructive_switch_enum_addr' into separate 'switch_enum_addr' and 'take_enum_data_addr' instructions. This should unblock some optimization work we would like to do with enums.

Swift SVN r12015
2014-01-07 22:58:21 +00:00
Joe Groff
530e948cb2 SIL: Rename 'enum_data_addr' to 'init_enum_data_addr'.
Emphasize the fact that this address is only intended for initialization. When we split destructive_switch_enum_addr, there will be another similar instruction for destructively taking the payload out of an already-initialized enum.

Swift SVN r12000
2014-01-07 18:40:00 +00:00
Doug Gregor
1cf3bdbe8c Use objc_msgSendSuper[Stret] for foreign initializer delegation.
Introduce the SIL instruction peer_method, which references a method
in the given class or one of its superclasses (but not a subclass). It
IRGen's to objc_msgSendSuper[Stret] (vs. super_method IRGen'ing to
objc_msgSendSuper[Stret]2 for superclass lookup).

Use peer_method for initializer delegation to a foreign initializer
(i.e., an init-family method written in Objective-C) to close the
safety loophole introduced by initializer delegation in r11965. The
loophole still exists, but can only be triggered from Objective-C.

Teach definite initialization that peer_method really isn't a use of
self.



Swift SVN r11992
2014-01-07 17:33:41 +00:00
John McCall
e507341c1b SILModule lookup: now with that magic O(1) flavor.
Swift SVN r11978
2014-01-07 01:21:10 +00:00
John McCall
bb63d2312b Hide the constructors of SILFunction/SILGlobalVariable
behind factory methods.

Swift SVN r11967
2014-01-07 00:22:15 +00:00
Manman Ren
93243ca683 SIL serialization: do not use attribute field for cast kind.
Attribute field is a fixed 2-bit field, but cast kind exceeds 4,
so using 2-bit attribute field for cast kind will cause overflow.
The fix is to add a record for the cast instruction with a 4-bit
kind field instead of a 2-bit attribute field.


Swift SVN r11938
2014-01-06 19:35:29 +00:00
Doug Gregor
c76017754f Return an error if we couldn't handle the deserialized literal encoding in SIL.
Swift SVN r11923
2014-01-06 16:36:24 +00:00
John McCall
12b1c9daf7 Add support for multiple encodings to the string_literal
SIL instruction.  Implement IR-gen support for same.  Fix
the parsing of SIL string literals to properly unescape them.

SIL-gen still emits UTF8 literals unconditionally.

Swift SVN r11904
2014-01-04 11:42:57 +00:00
Chris Lattner
b29748a6be remove the ASTContext argument from Type::transform,
(various) FunctionType::get's, ArrayType::get,
ArraySliceType::get, OptionalType::get, and a few
other places.

There is more to be done here, but this is all I plan to do
for now.


Swift SVN r11497
2013-12-20 02:23:21 +00:00
Adrian Prantl
d405aa3ccc Hush!
Swift SVN r11257
2013-12-13 17:35:19 +00:00
Adrian Prantl
c610ac94ef Add an IsBare attribute to SILFunction for functions that do not have an
AST.

Swift SVN r11236
2013-12-13 04:48:37 +00:00
Manman Ren
44a714a45a SILDeserializer: We expect SIL_FUNC_NAMES first, then SIL_VTABLE_NAMES, then
SIL_GLOBALVAR_NAMES. But each one can be omitted if no entries exist in the
module file.

rdar://15626995


Swift SVN r11088
2013-12-10 19:30:55 +00:00
Adrian Prantl
42fd177c01 silence warning
Swift SVN r11087
2013-12-10 19:23:35 +00:00
Joe Groff
02a0e996c4 SIL: Kill initialize_var instruction.
Remove the initialize_var instruction now that DI fully diagnoses initialization problems. Change String-to-NSString bridging to explicitly invoke String's default constructor; it was the last remaining user of initialize_var. Remove dead code to emit an implicit default constructor without a body.

Swift SVN r11066
2013-12-10 03:36:59 +00:00
Chris Lattner
a0499d90d5 remove the SIL builtin_zero instruction.
Swift SVN r11052
2013-12-09 23:41:35 +00:00
Joe Groff
27d96bbdc9 SIL: Generalize archetype_method to accept concrete types.
Allow archetype_method to look up a witness from a concrete ProtocolConformance record. This will allow generic specialization to apply to constrained generic functions independent of archetype_method devirtualization. <rdar://problem/14748543>

Swift SVN r10950
2013-12-07 00:00:51 +00:00
Manman Ren
395b8f4eda SILSerializer: handle sil_global and sil_global_addr.
Always serialize global variables and deserialize a global variable lazily
when deserializing SILGlobalAddr.

rdar://15493552


Swift SVN r10884
2013-12-05 21:56:02 +00:00
Chris Lattner
567a3175dc extend the mark_initialized SIL instruction to have a "kind" enum field.
Existing uses use a "globalvar" kind.  Add a new "rootinit" kind which
will be used for root initializers (i.e. init methods of structs, enums, 
and root classes).



Swift SVN r10772
2013-12-04 02:02:15 +00:00
Chris Lattner
ad05efc481 Redesign the BuiltinFunctionRefInst to contain an Identifier instead of
a FuncDecl.  This makes it much more straight-forward for SIL passes to
introduce a new one - without doing name lookup in the builtin module!



Swift SVN r10694
2013-11-30 01:49:36 +00:00
John McCall
20e58dcf93 Change the type of function values in SIL to SILFunctionType.
Perform major abstraction remappings in SILGen.  Introduce
thunking functions as necessary to map between abstraction
patterns.

Swift SVN r10562
2013-11-19 22:55:09 +00:00
Joe Groff
f6b1745650 SIL: Remove 'ModuleInst'.
Module values could never be used for anything, and we have SILUndef now, so when SILGen sees a ModuleExpr, we can just emit 'undef'.

Swift SVN r10548
2013-11-18 21:36:08 +00:00
Joe Groff
4c0ebedc6a SIL: Add SILGlobalAddrInst.
Like GlobalAddrInst, but for SILGlobalVariables. These would become the same instruction when SILGlobalVariable can replace AST-level global references.

Swift SVN r10510
2013-11-16 00:50:18 +00:00
Joe Groff
19457c12ea Give Builtin.Word an abstract size.
Instead of hardcoding Builtin.Word to be an alias for Builtin.Int64, make it its own type of abstract pointer width.

- Change BuiltinIntegerType's width representation to accommodate abstract widths.

- In the AST and in SIL, store values of the types as the greatest supported size for the abstract width (64 bits for a pointer).

- Add some type safety to the ([sz]ext|trunc)(OrBitCast)? builtins that they're used appropriately given the upper and lower bounds of the abstract sizes they're working with.

- Now that Builtin.Word is a distinct type, give it its own mangling.

- In IRGen, lower pointer-sized BuiltinIntegerType appropriately for the target, and truncate lowered SIL values if necessary.

Fixes <rdar://problem/15367913>.

Swift SVN r10467
2013-11-14 19:56:26 +00:00
Chris Lattner
4968cc208b A couple of related changes:
- Enhance SILBuilder::emitStrongRelease to be smarter.
- Start using emitStrongRelease in type lowering, SILGen,
  CapturePromotion (replacing its implementation of the
  same logic), and MandatoryInlining (one more place)
- Rename the primitive createStrongRetain/ReleaseInst
  instructions to lose their suffix.
- Now that createStrongRetain/ReleaseInst are not special
  cases from the naming perspective, remove some special cases
  from DeserializeSIL and ParseSIL.
  


Swift SVN r10449
2013-11-14 02:21:27 +00:00
Chris Lattner
425819ac07 Change the SIL string_literal instruction to produce three results
(the same way alloc_box returns two) instead of returning a tuple.

This eliminates a ton of tuple_extract instructions, which just
bloat the generated SIL.  This resolves rdar://15378135.



Swift SVN r10416
2013-11-13 06:43:09 +00:00
Manman Ren
c2188c8328 SIL Serializer: vtable can trigger serialiation of a SILFunction declaration.
Also add serialization of resilience attributes: Fragile, InherentlyFragile
and Resilient. Serialize VTables before SILFunctions because it may trigger
serializations of non-transparent SILFunctions.

Update funcOrOffset and vTableOrOffset when a SILFunction or a VTable is
de-serialized.

rdar://15165644


Swift SVN r9926
2013-11-04 18:17:34 +00:00
Chris Lattner
a2a1b2af55 Clean up tuple and extract SILBuilder stuff:
- Introduce emitTupleExtract / emitStructExtract, which fold when their operand is a tuple/struct.
- Rename SILBuilder::createTupleExtractInst -> createTupleExtract, "Inst" isn't used as a suffix.
- Switch capture promotion and DI to use the new functions.

This trims 300 lines out of the stdlib.


Swift SVN r9897
2013-11-03 04:47:40 +00:00
Manman Ren
313bd88d88 SIL Serializer: fix a bug in handling of forward-referenced values.
In serializer, we pre-assign a value ID in order, to each basic block
argument and each SILInstruction that has a value.
In deserializer, we use LocalValues to store the definitions and
ForwardMRVLocalValues for forward-referenced values (values that are
used but not yet defined). LocalValues are updated in setLocalValue where
the ID passed in assumes the same ordering as in serializer: in-order
for each basic block argument and each SILInstruction that has a value.
We update ForwardMRVLocalValues in getLocalValue and when a value is defined
in setLocalValue, the corresponding entry in ForwardMRVLocalValues will be
erased.

rdar://15351123


Swift SVN r9884
2013-11-01 22:37:05 +00:00
Chris Lattner
ef93c81ffb Introduce a new SIL-level "undef" value, useful for SIL transformations.
IRGen support is missing, Joe volenteers to implement it.


Swift SVN r9776
2013-10-30 00:58:09 +00:00
Manman Ren
b2bd2e9f8d SIL Serialization: handle SILVTable.
We add two records in sil_block to specify a Vtable and its entry list. Two
records are also added in sil_index_block for mapping from name to ID and
from ID to bit offset.

Two functions are added to SerializedSILLoader: to look up a specific VTable
given the class name or to deserialize all VTables in all SILModules. The latter
is mostly used for testing.

We serialize a VTable if the class is fragile and deserialize it via
SerializedSILLoader::lookupVTable.


Swift SVN r9746
2013-10-28 23:38:48 +00:00
Manman Ren
00ca99b2ed SIL Deserialization: readSILFunction handles the case where the input
SILFunction is null.

When the input SILFunction is null, we create a SILFunction. A null input
SILFunction can happen when deserializing SILVTable.


Swift SVN r9736
2013-10-28 22:44:56 +00:00