Commit Graph

53 Commits

Author SHA1 Message Date
Doug Gregor
36df570c15 Record the generic type of a generic function as its "interface" type.
We're still not using the interface type for anything, but record it
and serialize/deserialize it.


Swift SVN r8897
2013-10-04 00:14:04 +00:00
Manman Ren
be3a4101ed SIL Serialization: perform SIL linking right after SILGen.
Add a SILLinkage mode "Deserialized" to make sure IRGen will emit
hidden symbols for deserialized SILFunction.

Inside SIL linker, set Linkage to external if we only have a declaration for
a callee function.

Both sil block and decl block in a module can emit an array of substitutions.
To share the serialization between SILSerializer and Serializer, we modify
the interface to pass in the abbreviation codes to write functions and to
pass in a cursor to read functions.

We now correctly handle the serialization of Substitutions in SpecializeInst.

For a deserialized SILFunction, we now temporarily set its SILLocation and 
DebugScope to an empty FileLocation. Once mandatory inliner sets the SILLocation
to the location of ApplyInst, a null SILLocation and a null DebugScope
may work for a deserialized SILFunction.

Update testing cases to reflect that we are now inlining transparent functions
from modules, or to disable SILDeserializer for now (I am not sure how to update
those testing cases).


Swift SVN r8582
2013-09-24 00:44:54 +00:00
Manman Ren
8cd676143a SIL Serialization: handle more SILInstructions
Add serialization/deserialization of the following SILInstructions:
BuiltinFunctionRefInst, IndexRawPointerInst, ModuleInst,
Conversion instructions:
  RefToObjectPointerInst, UpcastInst, CoerceInst, AddressToPointerInst,
  PointerToAddressInst, ObjectPointerToRefInst, RefToRawPointerInst,
  RawPointerToRefInst, RefToUnownedInst, UnownedToRefInst
DestroyAddrInst, LoadInst, StrongReleaseInst, StrongRetainInst,
TupleElementAddrInst, TupleExtractInst

Make getModule in ModuleFile public to be used by SILDeserializer, also
make addModuleRef in Serializer public to be used by SILSerializer.

Update testing case to cover the above SILInstructions.


Swift SVN r8372
2013-09-18 00:25:23 +00:00
Manman Ren
e3f542cf73 SIL Serialization: handle more SILInstructions
Use a worklist in SIL linking to traverse the newly serialized SILFunction.
Add serialization/deserialization of the following SILInstructions:
AllocArray, Apply, FunctionRef, IntegerLiteral, Metatype, StructExtract,
Struct and Tuple.

Make getDecl and getIdentifier in ModuleFile public to be used by
SILDeserializer, also make addDeclRef and addIdentifierRef in Serializer
public to be used by SILSerializer.

Update testing case to cover the above SILInstructions.

TODO: lookupSILFunction should replace the existing empty SILFunction instead
of creating a new SILFunction.


Swift SVN r8339
2013-09-17 18:39:20 +00:00
Manman Ren
fa0acc9328 SIL Serialiation: add implementation to deserialize SIL and a wrapper class
SerializedSILLoader to hold a list of SIL deserializers.

Also add an intial implementation of a linking pass that is run right after
SILGen to link the declaration of SILFunction to the actual definition in
the serialized module.

We add two blocks to the serialized module: a sil index block that
maps identifier to a function ID and also holds a list of function offsets,
and a sil block for the actual SILFunctions. We can probably use subblock
instead of two top-level blocks.

The serialization/de-serialization of the function hash table and the function
offsets are implemented. But we are missing handling of types (see FIXME in
the code).

ModuleFile::Serialized is made public to be used by SIL deserializer, as well
as ModuleFile::getType.

The SIL deserializer holds a pointer to the ModuleFile, it gets the sil cursor
and the sil index cursor from the ModuleFile. The other option is for SIL
deserializer to find the start of the two sil blocks within itself, thus having
less coupling with ModuleFile.

No testing case yet because we are missing handling of types.


Swift SVN r8206
2013-09-13 17:44:41 +00:00
Jordan Rose
12f6e68385 [serialization] std::function is already nullable; no need for Optional.
Thanks, Dmitri.

Swift SVN r8096
2013-09-11 18:26:25 +00:00
Chris Lattner
55200e5274 Now that Module has its own kind field, drop the various module
discriminators from DeclContext.  This is cleaner and should
enable us to drop the alignment of DeclContext (coming next Jordan!)



Swift SVN r8059
2013-09-09 22:43:11 +00:00
Chris Lattner
53e0f11141 Introduce a new ModuleKind enum to implement RTTI for module downcasting.
No functionality change.



Swift SVN r8053
2013-09-09 21:53:21 +00:00
Argyrios Kyrtzidis
36a469df0b [modules] Introduce Module::getTopLevelDecls() to get the local-in-module top-level decls.
getDisplayDecls() was introduced for ":print_module" and works slightly differently, e.g.
it will return the decls from a shadowed clang module, since we want to display them.

Swift SVN r7909
2013-09-04 20:55:27 +00:00
Argyrios Kyrtzidis
2a6dc12607 [modules] Introduce APIs to get the path for the file that a module came from.
Swift SVN r7890
2013-09-04 01:57:53 +00:00
Jordan Rose
cad735b896 [serialization] Remove FALL_BACK_TO_TRANSLATION_UNIT hack.
As a bring-up hack, the module serializer would write a special record,
FALL_BACK_TO_TRANSLATION_UNIT, if it encountered something it didn't know
how to serialize. This then directed the deserializer to ignore the
contents of the module file and instead reload the original source file.
Now that we can serialize pretty much everything*, though, we don't need
this, and instead we'd rather know where the serialization coverage has
gaps (by asserting).

Swift SVN r7752
2013-08-29 22:05:43 +00:00
Jordan Rose
eef39ff914 Add a :print_module directive to the REPL.
This is basically the same as doing a :print_decl on every decl in the module,
except that it does not print extensions that come from other modules, and
/does/ print extensions and operators that come from this module.

Does not yet work for Clang modules or the Builtin module.

Swift SVN r7601
2013-08-26 23:07:51 +00:00
Jordan Rose
ee2ed392c7 Hack in a -module-link-name option for autolinking.
In Swift, a module is expected to know which libraries it needs, rather than
having this specified by an external module map. While we haven't quite
designed this yet (frameworks get this for free in Clang, for example),
we can at least provide a simple option for the common case of a module
associated with a single library.

This will probably change in the future, so I left in the more general
deserialization code I was working on before simplifying the use case.
A loaded module can in theory specify any arbitrary frameworks or libraries
as dependencies, not just a single dylib.

Swift SVN r7583
2013-08-26 18:57:48 +00:00
Jordan Rose
f1bc7801f4 Rework getReexportedModules to optionally find all imported modules.
...instead of just those that are re-exported. This will be used for
autolinking (and probably few other places).

As part of this, we get two name changes:
  (1) Module::getReexportedModules -> getImportedModules
  (2) TranslationUnit::getImportedModules -> getImports

The latter doesn't just get modules-plus-access-paths; it also includes
whether or not the import is re-exported. Mainly, though, it just didn't
seem like a good idea to overload this name when the two functions aren't
really related.

No tests yet, will come with autolinking.

Swift SVN r7487
2013-08-22 23:20:18 +00:00
Jordan Rose
2c7858bfb2 Add an entry point for id-style lookup of a known name.
This will be used to resolve properties and method calls on objects with
dynamic-lookup ("id") type. For now, this is tested in swift-ide-test
by using the -dynamic-lookup-completion option and providing a
-code-completion-token value.

Caveats/TODOs:
- As before, since we're using the global method pool, this isn't scoped by
  module. We could do a per-module filter, but I don't know if that will
  actually buy us much.
- Again, Clang's method pool does not include methods from protocols.
- Lookup by selector name cannot find properties with a customized getter
  name. <rdar://problem/14776565>
- The Clang-side method pool is keyed by selector, but Swift wants to look
  things up by method name, which maps to the first selector piece, so we
  end up having to do a scan of all the selectors in the pool.

Swift SVN r7330
2013-08-19 21:33:33 +00:00
Jordan Rose
2241086363 Add lookupClassMembers for use in id-style dynamic lookup.
With this, we can now get a list of all class members* available in the
current translation unit, which will be necessary for doing id-style
dynamic lookup (inferring which method you're referring to when the base
type is some magic "dynamic lookup" type).

* Including members of protocols, since a class we don't know about could
have implemented the protocol.

Since there is no code currently using this, I've added a new mode to
swift-ide-test to just dump all class members -- what will eventually
happen when you code complete on a dynamic lookup type. This mode will
go away once the other pieces of id-style lookup are in place.

Swift SVN r7287
2013-08-16 20:22:14 +00:00
Jordan Rose
cf6bb91b20 [serialization] Serialize a table of all class members, by name.
This will be used for id-style lookup.

Swift SVN r7286
2013-08-16 20:22:07 +00:00
Jordan Rose
95ff29b6e2 Make deserialization of known protocol adopters lazy.
...by adding a new callback to ModuleLoader: loadDeclsConformingTo.
This is used only when the type checker doesn't have enough contextual
information to resolve an expression involving a literal, so it's
possible many *LiteralConvertible types will never be loaded.

Deserialization of types with conversion methods is still eager, since
there's no easy hook to tell when they're needed, but the list has been
renamed to refer to any decls that need to be eagerly deserialized, in
case we need it for other purposes in the future.

This probably won't help much in a real program, but it cuts the test
run time by about 5-10% in my build.

Swift SVN r7268
2013-08-15 18:43:40 +00:00
Jordan Rose
5ce857c45c Only record conformances to known protocols, and include them in modules.
This is really two commits in one: first, change the AST and TypeChecker
to only track conformances to known protocols, and second, make sure we
can deserialize decls that conform to known protocols on demand. The
latter is necessary for the type checker to solve constraint systems that
are not fully constrained, and also requires tracking decls with conversion
methods.

Currently decls conforming to known protocols are eagerly deserialized;
that will change soon to be a new ModuleLoader callback. Decls with
conversion functions will continue to be eagerly deserialized for the near
future.

This fixes the initial regressions in making decl deserialization lazy.

Swift SVN r7264
2013-08-15 17:32:20 +00:00
Jordan Rose
45f37732ba [serialization] Separate extensions out into their own table.
This also makes extension-loading slightly more precise; if asked to
load extensions for some struct Foo, we will load extensions for /every/
struct Foo...but now we won't /also/ load extensions for every /class/ Foo.

Swift SVN r7260
2013-08-15 17:31:51 +00:00
Jordan Rose
bca05dab59 [serialization] Lazily load top-level decls, extensions, and operators.
This switches from simple lists of decls to name-based on-disk hash tables,
which allows decls to be loaded lazily when doing simple lookup (but not
code completion, at least not yet).

The on-disk hash table implementation is borrowed from Clang; eventually
it will be pushed down to LLVM's Support library. (Fortunately the
implementation is header-only.)

This breaks a few tests that rely on magic protocols like
IntegerLiteralConvertible, because the type checker won't have seen the
types that conform to those protocols yet. This will be fixed by doing
an additional "hey, modules, got any of these?" lookup.

Swift SVN r7259
2013-08-15 17:31:44 +00:00
Jordan Rose
a35f7cbd4b Thread [exported] through TranslationUnit and the Serialization library.
This still doesn't do anything yet.

Swift SVN r7051
2013-08-08 19:09:21 +00:00
Jordan Rose
42a109674d [serialization] Serialize import access paths, and only the TU's own imports.
Previously, a module contained references to every module listed in the
ASTContext. Now, we actually only encode the imports from the TU itself,
which allows us to include access paths for scoped imports.
This is necessary to implement proper name lookup shadowing rules.

Swift SVN r7013
2013-08-07 22:56:41 +00:00
Doug Gregor
6fbe6de81a Rework (de-)serialization of generic and inherited conformances.
IdentifierIDs and TypeIDs should be kept distinct. Instead, conflict
DeclID and TypeID, which is acceptable.


Swift SVN r6906
2013-08-05 17:12:39 +00:00
Doug Gregor
1bd583cdf8 [Module file] (De-)serialize inherited protocol conformances.
Swift SVN r6886
2013-08-05 14:29:16 +00:00
Joe Groff
70dbbc806b Store type, protocol, and conforming decl in ProtocolConformances.
This makes ProtocolConformances fully self-identifying so that a ProtocolConformance* pointer alone is enough to identify a conformance as a link entity.

We currently lose the conforming decl during deserialization because trying to deserialize a reference to an ExtensionDecl asserts out. I'll bug Jordan about that.

Swift SVN r6735
2013-07-30 01:26:26 +00:00
Adrian Prantl
2306563aa2 Debug info: emit the module name for types declare in a swiftmodule.
Swift SVN r6734
2013-07-30 01:17:02 +00:00
Doug Gregor
cfe9e0ad37 [Module format] Don't serialize 'inherited' types of any declaration.
The 'inherited' type list of a declaration represents the parsed for
of the inheritance clause, which is now not serialized. The semantic
informance exists in the superclass (when present) and list of
protocols. Future refactoring of the 'inherited' list will make this
more clear.


Swift SVN r6686
2013-07-29 15:23:44 +00:00
Jordan Rose
d11585f810 [serialization] Include generic protocol witness substitutions.
This finishes up Joe's changes in r6397.

Swift SVN r6558
2013-07-24 21:15:42 +00:00
Jordan Rose
8e081367ca Basic implementation of lookupVisibleDecls() for serialized modules.
This involved threading it through ModuleLoader, as with all the other
module-generic callbacks. I plan to collapse a bit of the chaining, but
unfortunately not that much.

This brings back the CodeCompletion tests.

Swift SVN r6527
2013-07-23 23:10:28 +00:00
Jordan Rose
3087e8d5ea Add the notion of "re-exported" modules, and use that where it makes sense.
Rather than automatically re-exporting or not re-exporting every import in
a TranslationUnit, we'll eventually want to control which imports are local
(most of them) and which imports are shared with eventual module loaders.
It's probably not worth implementing this for TranslationUnit, but
LoadedModule can certainly do something here.

Currently, a LoadedModule is even more permissive than a TranslationUnit:
all imports are re-exported. We can lock down on this once we have a
re-export syntax.

Swift SVN r6523
2013-07-23 23:10:17 +00:00
Jordan Rose
110d644297 Provide a skeleton for re-exports from serialized modules...
...and use it for shadowed modules (e.g. the Clang module "Foundation"
referenced by the Swift module "Foundation"), so that we can actually
find "NSString" when building AppKit.

Additionally, record shadowed modules as dependencies, so that they can
be loaded when the adapter module is loaded.

Swift SVN r6522
2013-07-23 23:10:13 +00:00
Jordan Rose
6e4f36cab2 [serialization] Handle cross-module references to values in extensions.
Previously, cross-references used a simple access path to refer to values
in other modules, but extensions have no name. They also accidentally
picked up values in extensions anyway, because lookupDirect includes
members in extensions. Now, we filter out values that don't come from
the referenced module, which may not be the same module the base type
comes from.

Swift SVN r6301
2013-07-16 23:10:33 +00:00
Jordan Rose
4376b1aa93 [serialization] Serialize protocols alongside conformances.
Turns out the typechecker uses these for resolving literals and such.

Swift SVN r6244
2013-07-13 19:37:14 +00:00
Jordan Rose
1712ee6661 [serialization] Handle overloaded decls.
Swift SVN r6230
2013-07-13 00:03:14 +00:00
Jordan Rose
9a180ea9c6 [serialization] Relax assertions to allow reentrant deserialization.
As long as we don't create an entity twice, it's actually okay to be
re-entrant. This makes it simpler to deserialize members -- trying to
do so will deserialize the parent instead, which will then initialize
each of the members including the one that was asked for.

Swift SVN r6228
2013-07-12 23:29:57 +00:00
Jordan Rose
4db68ed617 [serialization] Record nominal types in the module table ASAP.
Deserializing a nominal decl often ends up referring to the nominal's type,
so if we're /already/ serializing the type, we should finish that as soon
as we have a decl. Accomplish this by adding a callback that is called
right after a nominal decl is recorded in the module's decl table, so that
the type can be immediately recorded as well.

Swift SVN r6227
2013-07-12 23:29:45 +00:00
Jordan Rose
e3999dde36 [serialization] Handle absent protocol conformances.
These still need to be serialized, because they are one-to-one with the
type's protocol list, but don't actually require any data. Found on
attempting to emit a module for the standard library.

Most of the churn here is moving Interleave.h to a more general STLExtras.h.

Swift SVN r6167
2013-07-11 18:38:50 +00:00
Jordan Rose
9a67bc597e [serialization] Add support for classes.
Classes are exactly like structs except that they may have a base class.
However, this type will show up in the inheritance list. That means we
don't actually need to serialize it twice; we can just grab the base class
from the inheritance list.

Swift SVN r6133
2013-07-10 23:25:34 +00:00
Jordan Rose
929d86bb16 [serialization] Add support for prefix and postfix operators.
This includes adding an operator lookup table to ModuleFile. Operators are
keyed by a (name, fixity) pair.

Swift SVN r6078
2013-07-08 23:41:06 +00:00
Jordan Rose
0054e58935 [serialization] Serialize protocol conformances instead of ignoring them.
For some reason this didn't actually affect any testing, but it's going to
be necessary very soon.

Swift SVN r5987
2013-07-04 00:20:31 +00:00
Jordan Rose
61efdb5ff7 [serialization] Add support for generic functions.
This currently does a little dance to handle PolymorphicFunctionTypes.
These are currently implemented by referencing the GenericParamList of
an actual polymorphic function, so they can't be deserialized without
knowing which function they are attached to. To solve this,
PolymorphicFunctionTypes are serialized as regular FunctionTypes. Then,
when a generic function decl is being deserialized, it will rebuild
a PolymorphicFunctionType from the serialized type and its own generic
parameter list.

Requirements on the generic types are coming next.

Swift SVN r5983
2013-07-04 00:14:23 +00:00
Jordan Rose
cc92da302d [serialization] Add support for protocols.
Swift SVN r5962
2013-07-02 21:56:28 +00:00
Jordan Rose
0e4f6c6a12 [serialization] Record dependencies on other modules.
When loading a module, we now try to load its dependencies as well.
If one of those dependencies can't be loaded, we emit an error message.

Swift SVN r5796
2013-06-25 00:47:48 +00:00
Jordan Rose
d6801fe0fd [serialization] Fix a recursive-dependency bug caught by previous commit.
Constructors have their "implicit this" VarDecl specified at creation, but
the context for said VarDecl is the constructor itself. Add a new flag to
allow the deserialization of a VarDecl without setting a DeclContext.

Swift SVN r5747
2013-06-21 17:52:08 +00:00
Jordan Rose
2300d7a1ce [serialization] Add support for function arguments.
The main work here is serializing patterns, which are recursive. Unlike
Types, Patterns are not uniqued (in the original AST they contain location
info). Therefore, rather than using cross-referencing IDs, patterns are
serialized as trailing records with an implied hierarchy. Each pattern
record tells you what trailing records to expect. So, for example, the
pattern ((x : Int, y : Int), _ : Int) will give you this serialization:

 1. TuplePattern - 2 elements
 2.   TuplePatternElt
 3.     TuplePattern - 2 elements
 4.       TuplePatternElt
 5.         TypedPattern - Int
 6.           NamedPattern - x
 7.       TuplePatternElt
 8.         TypedPattern - Int
 9.           NamedPattern - y
10.   TuplePatternElt
11.     TypedPattern - Int
12.       AnyPattern

Functions contain two sets of patterns: "argument" patterns and "body"
patterns, which are different in selector-style declarations. Currently
we always serialize both of these, but it would be easy enough to add a
flag in the FUNC_DECL record to skip one of them if they are the same.

If the function is curried, each set will contain multiple patterns.
These are simply read eagerly as trailing records from the function;
as soon as a non-pattern record is encountered, we know all of the patterns
have been read in.

Swift SVN r5742
2013-06-21 17:51:20 +00:00
Jordan Rose
eb8657f2ac [serialization] Unique identifiers and serialize them into a blob table.
This removes the egregious NAME_HACK records that trailed various named
decls, and replaces them with proper identifier IDs. The identifiers
themselves are serialized into a blob as null-terminated strings, with no
particular optimization (i.e. no substring matching or anything). We can
revisit this format later, but this at least allows identifiers to be
referenced inline within a record, which will be much more convenient for
function parameter patterns (upcoming).

Swift SVN r5638
2013-06-18 00:32:56 +00:00
Jordan Rose
44cde3ae0a [serialization] Serialize DeclContexts, VarDecls, and StructTypes.
Unlike Clang, Swift's DeclContexts are not all Decls. However, I believe
each DeclContext that is /serialized/ will be either a decl, a
TranslationUnit, or a FuncExpr for a function with an actual declaration.
This might turn out to be wrong if (a) SIL needs proper DeclContexts for
variables in function bodies, or (b) we need to serialize anonymous
closure default arguments.

Along with an extension of the ConstructorDecl placeholder code, this allows
us to round-trip empty structs.

Swift SVN r5532
2013-06-08 00:18:24 +00:00
Jordan Rose
c8958a232e Replace PointerIntUnion with a PointerUnion-compatible Fixnum type.
Per discussion on swift-dev, we'd prefer to have a "pointer-like" integer
with limited bit width, to reuse all the existing infrastructure for
pointer-like types, rather than invent another new data structure.

Swift SVN r5529
2013-06-08 00:18:19 +00:00
Jordan Rose
7a13e58b38 [serialization] Hook up basic name lookup for imported modules.
Also, explicitly list the top-level decls in a module. Eventually this
will be a proper lazily-loaded identifier-DeclID map, but for now it's
just a flat list of IDs to deserialize as soon as a lookup is
requested.

We can now parse and typecheck a file that imports typealiases of builtin
types.

Swift SVN r5325
2013-05-25 01:34:57 +00:00