Commit Graph

812 Commits

Author SHA1 Message Date
Michael Gottesman
436e560e5b Remove redundent assertion. We check the same assertion in SILValue::replaceAllUsesWith.
Swift SVN r14748
2014-03-06 20:15:47 +00:00
Michael Gottesman
6015c5ad9c [deserialization] It looks like readSILInstruction uses its return value to signal I have a declaration and I have an error. Disambiguate the cases by checking before calling it if we have no BB and returning the assumed function declaration.
Swift SVN r14719
2014-03-06 04:20:26 +00:00
Michael Gottesman
2aa197f636 [deserialization] Expose ModuleFile::error and use the method in SILDeserializer to mark a module as being malformed when invalid SIL is encountered.
Swift SVN r14703
2014-03-06 00:08:35 +00:00
John McCall
84c9eb0d2f Use getEnumElementType instead of getTypeOfMember directly.
This is nicer, and it also does type-lowering and
abstraction difference for us automatically.

Swift SVN r14696
2014-03-05 22:49:02 +00:00
Doug Gregor
82c1ba2e29 Remove peer_method instruction; we're no longer using it.
Swift SVN r14599
2014-03-03 17:13:06 +00:00
Michael Gottesman
b90979be67 [deserialization] Only deserialize witness table functions as declarations.
This is analogous to the issue in r14581.

Swift SVN r14584
2014-03-03 06:46:27 +00:00
Michael Gottesman
044b85be7b [deserialization] When deserializing vtables, do not deserialize the functions they reference.
This fixes a bug where we were deserializing a function with a call to a shared
linkage function. The shared linkage function was never deserialized causing an
assertion to fire due to shared linkage functions always needing a definition.

I am planning on implementing lazy deserialization of vtable functions.

Swift SVN r14581
2014-03-03 05:05:20 +00:00
Doug Gregor
5d8bd84dfa Introduce the SIL instruction alloc_ref_dynamic.
alloc_ref_dynamic allocates an instance of a class type based on the
value in its metatype operand. Start emitting these instructions for
the allocating constructor of a complete object initializer (not yet
tested) and for the allocating constructor synthesized for an imported
Objective-C init method.

Still missing:
  - IRGen still does the same thing as alloc_ref right now. That
  change will follow.
  - There are devirtualization opportunities when we know the value of
  the metatype that would turn an alloc_ref_dynamic into an alloc_ref;
  I'm not planning to do this optimization.



Swift SVN r14560
2014-03-01 21:55:50 +00:00
Joe Groff
67ca7ce1e9 SIL: Rename 'protocol_metatype' to 'existential_metatype'.
It's not forming the metatype for the protocol type (exists t: P. t).metatype, it's forming the existential of a metatype of a conforming type, exists t: P. (t.metatype).

Swift SVN r14520
2014-02-28 16:14:00 +00:00
Joe Groff
88b6efcc43 Rename ArchetypeMethodInst -> WitnessMethodInst more thoroughly.
Swift SVN r14501
2014-02-28 06:41:18 +00:00
Joe Groff
9424de6787 SIL: Rename 'archetype_metatype' to 'value_metatype'.
Since it can grab a metatype from any value now.

Swift SVN r14500
2014-02-28 06:33:05 +00:00
Joe Groff
545f173507 SIL: Fold 'archetype_metatype' and 'class_metatype'.
Having one instruction to get the dynamic metatype of a (non-existential) value makes more sense from a generic specialization standpoint and should stave off inevitable crashers when archetype_metatypes get specialized. protocol_metatype remains separate because metatype existentials are more interesting.

Swift SVN r14499
2014-02-28 06:32:58 +00:00
Joe Groff
855ea99063 SIL: Combine 'archetype_ref_to_super' and 'upcast'.
We were wantonly applying 'upcast' to archetypes in some cases, and really, that's OK, since these instructions do the same thing (and generic specialization could turn archetype_ref_to_super into upcast). Make everyone's life easier by folding archetype_to_super into upcast. Fixes <rdar://problem/16192324>.

Swift SVN r14496
2014-02-28 04:33:18 +00:00
Jordan Rose
b6fa8a00bd [serialization] Rename SILGenericOuterParamDeclID to SILGenericOuterParams.
Also, add the record to the block info for the SIL block, so that it can be
inspected by llvm-bcanalyzer.

Swift SVN r14417
2014-02-26 22:15:56 +00:00
Michael Gottesman
7091395c4b [sil-deserialization] Increment format minor version and move sil record info to SILFormat.h from ModuleFormat.h/DeclTypeRecordNodes.def.
Swift SVN r14367
2014-02-26 01:42:59 +00:00
Michael Gottesman
0aebf1f4a5 [sil-deserialization] Teach SIL how to deserialize generic outer parameters.
With this commit, we can deserialize the stdlib. Still running into
issues related to linking that requires a consultation with John. That
will come in a later commit.

Swift SVN r14365
2014-02-26 01:14:08 +00:00
Michael Gottesman
b2abd4047b [sil-parse][sil-deserialize] Teach the SIL Parser/Deserializer to use the
lowered field type of a ref_element_addr's parent projection, rather than using
the unlowered siltype generated via creating a SILType from the field's
vardecl.

Swift SVN r14294
2014-02-24 04:01:45 +00:00
Michael Gottesman
3d7f5f86e9 [sil-deserialization] Deserialization counterpart to r14257.
Swift SVN r14293
2014-02-24 03:46:38 +00:00
John McCall
3d5d8fdc03 Resilience expansion is really an aspect of a SILDeclRef.
We should also remove it from IRGen's Explosion API; IRGen
should always use maximal explosion, and SILGen will tell us
whether or not we need to put that in memory somewhere.
But that can be a later commit.

Swift SVN r14242
2014-02-21 23:28:43 +00:00
Dmitri Hrybenko
30ab76d3c3 Remove unused private member
Swift SVN r14207
2014-02-21 15:22:15 +00:00
Michael Gottesman
fa69cb6f54 Identifier's are only needed for AST types not for SIL Types. Simplify DeserializeSIL.cpp to use StringRefs instead of Identifiers whenever possible.
Swift SVN r14188
2014-02-21 00:32:00 +00:00
Michael Gottesman
ec52d16f57 Teach SerializedSILLoader how to load all SILFunctions. Also add SerializedSILLoader::getAll().
getAll deserializes all SIL (except for globals). This enables us to iterate
over the SILModules once instead of once for first SILFunctions, then VTables,
then WitnessTables which is just inefficient.

Swift SVN r14176
2014-02-20 22:22:20 +00:00
Michael Gottesman
9311672c33 Move ModuleFile.h, ModuleFormat.h, and DeclTypeRecordNodes.def to include/swift/Serialization.
This allows for a secondary tool to access the deserialized Module inside the SerializedASTFile's ModuleFile.

Swift SVN r14173
2014-02-20 22:03:55 +00:00
Michael Gottesman
20349edbad Change SILDeserializer to use StringRef instead of Identifier as its internal key.
This enables us to lookup a function from a key by avoiding the need to create
an identifier inside the OnDiskHashTable structure. Doing so would require an
ASTContext, something that is not available therein.

As a side effect this also makes OnDiskHashTable more efficient by just using a
StringRef reference instead of creating a uniqued identifier in the AST for
every deserialized node in the table.

Swift SVN r14169
2014-02-20 21:19:53 +00:00
Joe Groff
7fd26d22d5 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.

In this version of the patch, we adjust the deserialization point for the
generic param list to correctly come before we check if the SILFunction block
is empty, and we add a kludge to keep the JIT from crapping itself when it sees
the same transparent definition in multiple REPL lines' modules
<rdar://problem/16094902>.

The previous commit solves a problem this exposed at r14050 in inout deshadowing
that caused memory corruption when transparent functions were imported. This
should now be safe to commit.

Swift SVN r14109
2014-02-19 22:47:25 +00:00
Doug Gregor
3182cd3910 Introduce thick/Objective-C metatype conversion instructions.
Introduce the SIL instructions thick_to_objc_metatype and
objc_to_thick_metatype to convert between the 'thick' and
'Objective-C' representations of a metatype. Most of this code is
trivial support code for these conversions: printing, parsing,
(de-)serialization, etc., for which testing will come online in
subsequent patches or is incidental in other tests.

Lower Objective-C metatype values down to objc_class* at the IR level
and implement IRGen support for these SIL instructions. SIL-only test
case at the moment because SILGen never creates these instructions.



Swift SVN r14087
2014-02-19 18:20:21 +00:00
Greg Parker
675952c719 Revert r14030 which appears to segfault performance test hash2.swift.
Swift SVN r14038
2014-02-18 13:18:17 +00:00
Joe Groff
61f7a7c482 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.

In this version of the patch, we adjust the deserialization point for the generic param list to correctly come before we check if the SILFunction block is empty, and we add a kludge to keep the JIT from crapping itself when it sees the same transparent definition in multiple REPL lines' modules <rdar://problem/16094902>.

Swift SVN r14030
2014-02-18 07:30:11 +00:00
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