Commit Graph

163 Commits

Author SHA1 Message Date
Michael Gottesman
5dbfb3ab7f [devirtualization] Return the witness table when looking up SILFunctions from a witness table.
This is important since it enables one to analyze the type of the
conformance that the witness table implements which may be different
than the original type. This follows the precedent where we return the
Substitutions from the protocol conformance tree traversal.

Swift SVN r17220
2014-05-02 01:43:31 +00:00
Michael Gottesman
c9baa6d739 [devirtualization] Extract the method SILModule::lookUpSILFunctionFromVTable from optimizeClassMethodInst. NFC.
Swift SVN r17133
2014-05-01 02:08:57 +00:00
Michael Gottesman
5449d6f673 [devirtualizer] Refactor findFuncInWitnessTable -> SILModule::findFuncInWitnessTable.
Swift SVN r17130
2014-05-01 01:06:06 +00:00
Michael Gottesman
14e0f3fef2 [deserialization] When deserializing init_existential_inst pull in all the relevant witness tables.
<rdar://problem/16646818>

Swift SVN r16742
2014-04-24 03:37:34 +00:00
Michael Gottesman
afa464f980 [deserialization] Do not allow SILModule to attempt to deserialize a witness table lazily while we are already deserializing.
When deserializing, the serialized sil loader attempts to first lookup
from its SILModule the witness table to attempt to grab a witness table
declaration. Before this patch if the SILModule could not find it, it
would attempt to deserialize it. In certain edge cases this would cause
us to attempt to deserialize a function definition which violates the
invariant that that should never happen.

This patch adds an argument to SILModule::lookUpWitnessTable that
enables you to turn off the lazy deserialization behavior. The default
argument gives the current behavior which should be used everywhere
except for the deserializer.

Swift SVN r16740
2014-04-24 03:37:33 +00:00
Chris Lattner
a3916614ef respond to mainline API changes in the Debug.h header, by defining the
DEBUG_TYPE macro in all .cpp files that use the DEBUG macro.  Hopefully
this will unbreak the build.


Swift SVN r16638
2014-04-22 02:54:55 +00:00
Mark Lacey
1452d24671 Small cleanup: Remove unnecessary calls to getDef(), mostly in dyn_cast<>(...).
Swift SVN r16235
2014-04-11 23:05:16 +00:00
Michael Gottesman
0bc4f9c936 Call SILFunction destructor when we cleanup functions so that if the function contains a function_ref, the function referenced by the function_ref has its refcount properly decrement.
Otherwise a function_ref which was supposed to be deallocated would keep
functions alive.

rdar://16287331

Swift SVN r16192
2014-04-11 01:44:38 +00:00
John McCall
f1180f5e6d in order to work correctly for non-@objc protocols.
Language features like erasing concrete metatype
values are also left for the future.  Still, baby steps.

The singleton ordinary metatype for existential types
is still potentially useful; we allow it to be written
as P.Protocol.

I've been somewhat cavalier in making code accept
AnyMetatypeType instead of a more specific type, and
it's likely that a number of these places can and
should be more restrictive.
When T is an existential type, parse T.Type as an
ExistentialMetatypeType instead of a MetatypeType.

An existential metatype is the formal type
 \exists t:P . (t.Type)
whereas the ordinary metatype is the formal type
 (\exists t:P . t).Type
which is singleton.  Our inability to express that
difference was leading to an ever-increasing cascade
of hacks where information is shadily passed behind
the scenes in order to make various operations with
static members of protocols work correctly.

This patch takes the first step towards fixing that
by splitting out existential metatypes and giving
them a pointer representation.  Eventually, we will
need them to be able to carry protocol witness tables

Swift SVN r15716
2014-04-01 00:38:28 +00:00
Michael Gottesman
4e73547a3e Change SerializedSILLoader::create to return a unique_ptr and use that everywhere so we don't leak SILLoaders.
Swift SVN r15700
2014-03-31 22:57:03 +00:00
Michael Gottesman
0d0c00ce15 [deserialization] Create the SILLoader for a SILModule lazily the first time deserialization occurs instead of when the SILModule is created.
This enables us to get around timing issues when we create a SILModule before we
have finished loading all Swift Modules.

This manifested itself in sil-opt where we were unable to deserialize from the
standard library when optimizing a separate *.sil file.

Swift SVN r15670
2014-03-31 08:40:35 +00:00
Michael Gottesman
6946e86d0e [deserialization] Enable deserialization of VTables by default.
Swift SVN r15635
2014-03-29 21:58:55 +00:00
Michael Gottesman
08cd417faf [deserialization] Rename addCalleeFunction() -> addFunctionToWorklist(). CalleeFunction is an inappropriate name since we are using this also for deserializing functions referenced by vtables and witness tables.
Swift SVN r15634
2014-03-29 21:58:52 +00:00
Michael Gottesman
a571cd83f9 [deserialization] Add ClassDecl -> VTable map to SILModule.
Swift SVN r15545
2014-03-27 03:52:00 +00:00
Michael Gottesman
fdaa10b94f [deserialization] Teach WitnessMethodInst how to deserialize SILFunctions referenced by a witness table.
I need to add in the non-lazy linking pass before I can properly test
this. But I did not want to leave this bug in the wild. Expect the test
in the next bit.

Swift SVN r15544
2014-03-27 01:51:07 +00:00
Michael Gottesman
406bc0c19a [deserialization] Change SILLinking to use SILModule for linking instead of performing the linking itself.
This approach will allow us to go back to doing lazy linking if we want
to in the future.

Swift SVN r15498
2014-03-26 08:47:01 +00:00
Michael Gottesman
f4bb049bfc [deserialization] Enable lazy deserialization of witness tables.
This patch adds in the necessary infrastructure for lazily deserializing
witness tables. This is done by following the same approach as the
deserialization/serialization of SILFunction.

Now if one calls SILModule::lookUpWitnessTable and the given witness table is a
definition, the SILModule will attempt to deserialize it from one of the other
modules.

Swift SVN r15403
2014-03-24 09:16:09 +00:00
Michael Gottesman
5b1e2d4025 This caching statement should not be necessary due to r15399.
Swift SVN r15401
2014-03-24 05:07:20 +00:00
Michael Gottesman
69af5467ce Add a witness table to the witness table lookup cache when we create it, not lazily as we perform a search.
This means that every witness table in a SILModule must be in the
protocol conformance -> witness table map. We still return nullptr if
there is no such witness table.

Swift SVN r15399
2014-03-24 04:38:49 +00:00
Michael Gottesman
3ad6f33202 Teach the generic specializer how to create SILWitnessTable declarations if a specialized conformance does not have a witness table.
This also teaches IRGen not to emit WitnessTable declarations. This
causes them to be left as unknown symbols in the resulting executable.

Swift SVN r15361
2014-03-22 05:05:47 +00:00
Michael Gottesman
084d468236 [deserialization] Refactor SILModule::linkFunction into a SILVisitor pattern.
The if statement therein was just going to keep getting bigger and
bigger especially since I am going to add support for witness_method
among other things.

Swift SVN r15360
2014-03-22 02:06:38 +00:00
Michael Gottesman
11c03b0482 [deserialization] When linking functions, return failure if we get back a declaration.
We consider linking to only succeed if we actually convert a declaration
into a definition.

Swift SVN r15070
2014-03-14 20:36:17 +00:00
Chris Lattner
bca9000809 silence some fallthrough warnings.
Swift SVN r15033
2014-03-14 05:50:38 +00:00
Michael Gottesman
ea1d62e23a [deserialization] Verify functions when we deserialize them. This should help to catch deserialization issues.
Swift SVN r14876
2014-03-10 21:16:04 +00:00
Michael Gottesman
c52da10ee6 Fix typo where nullptr should be false.
Swift SVN r14835
2014-03-09 05:05:40 +00:00
Michael Gottesman
ba6ac196f6 Revert "[deserialization] Deserialize WitnessTables/VTables in SILModule, not in SILLinking."
This reverts commit r14623. I will recommit this when I reenable deserialization
of witness tables/vtables. This will enable the deserialization of SILFunctions
by default from the stdlib by avoiding the lack of external witness
tables/vtables.

Swift SVN r14786
2014-03-07 19:27:01 +00:00
Michael Gottesman
a50e4d54b8 Revert "[deserialization] Disable deserialization of vtables/witness tables for now."
This reverts commit r14750. I need to disable some tests.

Swift SVN r14751
2014-03-06 20:52:01 +00:00
Michael Gottesman
0b142c1f04 [deserialization] Disable deserialization of vtables/witness tables for now.
Some recent work done by John have unblocked deserialization of SILFunctions. We
still can not properly deserialize witness tables/vtables but enabling by
default deserialization of SILFunctions from the stdlib is a good first step
toward reaching our performance goals.

There will be forthcoming commits which removes Benchmarks.swift and all of the
infrastructure we have in place for compiling benchmarks in the standard
library.

Swift SVN r14750
2014-03-06 20:15:49 +00:00
Michael Gottesman
7f628360d9 [deserialization] Deserialize WitnessTables/VTables in SILModule, not in SILLinking.
Now we deserialize WitnessTables, VTables, and SILFunctions without
-sil-link-all passed in.

Swift SVN r14623
2014-03-03 23:49:42 +00:00
Michael Gottesman
29e1a53bbb [deserialization] Deserialize transparent functions lazily iff they will be used in mandatory inlining.
Swift SVN r14490
2014-02-28 01:05:01 +00:00
Michael Gottesman
a073096093 [deserialization] Begin move to lazy linking by putting a SerializedModuleLoader on SILModule.
Right now it is not wired up. That is coming in forthcoming commits. I am trying
to be very incremental about this.

This series of patches will fix an assertion triggered by us not deserializing
functions from vtables appropriately. Doing linking lazily fixes that issue and
does the "right thing".

The work is being done in consultation with John, Joe, and Jordan.

Swift SVN r14479
2014-02-27 21:30:54 +00:00
Michael Gottesman
ffa9b06042 Remove trailing whitespace. NFC.
Swift SVN r14478
2014-02-27 21:30:53 +00:00
Joe Groff
df356b475b SIL: Set the context generic params of reabstraction thunks less greedily.
Don't try to set the generic params of a reabstraction thunk until we've established it hasn't already been defined, fixing an issue where the same generic reabstraction pattern occurred in different contexts and we ended up clobbering the archetypes of a thunk that was already defined in terms of other archetypes.

Swift SVN r13964
2014-02-16 16:56:43 +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
Joe Groff
3b132bdcc7 SIL: SILModule::lookUpWitnessTable should always return a substitution list for generic conformances.
Even if the type is the DeclaredTypeInContext of the nominal, we still want the substitution list for generic specialization. Ideally the AST would always have a SpecializedProtocolConformance when we refer to a generic type instance, but our representation makes that difficult.

Swift SVN r12887
2014-01-23 23:45:32 +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
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
Joe Groff
8f47dc7383 SIL: Add a SILModule::lookUpWitnessTable method.
Looks up the SILWitnessTable for a ProtocolConformance.

Swift SVN r11576
2013-12-22 22:37:56 +00:00
Joe Groff
fd7b61ac71 SIL: Add a lookup cache StringMap to SILModule.
Because doing linear lookup all the time is dumb. NFC.

Swift SVN r11575
2013-12-22 22:37:55 +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
John McCall
007d3974d6 Use a proper mangling to try to share reabstraction thunks.
Swift SVN r10764
2013-12-03 23:23:52 +00:00
Chris Lattner
ecfba9fb53 Rename getBuiltinValue -> getBuiltinValueDecl since it doesn't
produce a value, it produces a decl.



Swift SVN r10697
2013-12-01 02:13:45 +00:00
Chris Lattner
3b954ed44d strength reduce SILGenModule::getBuiltinInfo/getIntrinsicInfo to
take an identifier instead of a FuncDecl.


Swift SVN r10692
2013-11-30 00:57:46 +00:00
Joe Groff
003709d51f SIL: Add a backreference from SILModule to its originating Swift Module.
Ideally this wouldn't be necessary, but the type substitution APIs required by generic specialization and SIL verification currently require a Module* pointer, and it's obnoxious to have to pass it down separately everywhere it's needed. Longer-term the reliance on Modules for type substitution might be able to go away.

Swift SVN r9866
2013-11-01 00:46:21 +00:00
Sean Callanan
ac43e98dd2 Added SILExternalSource, a class that can be used
to interpose on the SIL linking process.  Under the
following conditions:

- a function is called by the current SILModule;
- that function is transparent and empty in the
  generated SIL;
- the SIL linker doesn't find a serialized
  version of it; and
- the external client (right now, LLDB) has a
  SILExternalSource installed in the SILModule;

the SIL linker will query the SILExternalSource
via lookupSILFunction.

This interface will be used by LLDB to provide
SIL accessors for a program's variables when they
are referred to by Swift expressions.


Swift SVN r9452
2013-10-17 18:04:24 +00:00
Anna Zaks
59175bdc08 [SIL] Remove TranslationUnit pointer from SILModule.
This reverts r8624 and compensates by passing the TU to the SILModule printer when needed.

This addresses concerns that Jordan and Sean had raised.

Swift SVN r8678
2013-09-25 23:52:04 +00:00
Anna Zaks
4c61550b20 [SIL] Use TranslationUnit instead of ASTContext when creating a SILModule.
TU contains Decls that will need to be serialized when we print the SILModule.

Swift SVN r8626
2013-09-25 17:08:40 +00:00