Commit Graph

59 Commits

Author SHA1 Message Date
Jordan Rose
ad9875c19e [serialization] Add support for ArrayTypes.
...in a quest for completeness. ArrayTypes don't actually work yet
(single-dimensional arrays are typed as slices), but when they do the test
that is currently XFAIL'd should start passing.

With this, all non-transient types can now be serialized and deserialized.

Swift SVN r6101
2013-07-09 23:45:46 +00:00
Jordan Rose
e7aad15272 [serialization] Add block info for REFERENCE_STORAGE_TYPE.
This type may not stick around, but while it is around we should record
its name for llvm-bcanalyzer.

Swift SVN r6100
2013-07-09 23:45:39 +00:00
Jordan Rose
9443394fad [serialization] Mark some transient types as llvm_unreachable.
Also, remove a defensive check for a case there is now support for.

Swift SVN r6099
2013-07-09 23:45:28 +00:00
John McCall
18a9290cbe Add ReferenceStorageType.
The idea for now is that this is a SIL-only type used for
representing the storage of a weak or unowned reference.
Having it be its own type is pretty vital for reasonable
behavior in SIL and IR-generation, and it's likely that
this will surface into runtime metadata as well (hence
the mangling).

I've implemented a bunch of things that technically I don't
think are necessary if this stays out of the typechecker,
but it's easier to implement half-a-dozen "recurse into
the child type" methods now that it would be to find them
all later if we change our minds.

Swift SVN r6091
2013-07-09 08:37:40 +00:00
Jordan Rose
fdd5b36dfc [serialization] Handle fixity and assignment function attributes.
With this change we should be able to round-trip all of Policy.swift.

Swift SVN r6085
2013-07-09 00:45:05 +00:00
Jordan Rose
aa230234eb [serialization] Remove "isNeverLValue" flag.
This isn't worth serializing; any public decl can't meaningfully use this flag.

Swift SVN r6084
2013-07-09 00:44:56 +00:00
Jordan Rose
bec3b0a216 [serialization] Add support for infix operators.
Swift SVN r6081
2013-07-09 00:02:15 +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
03f7c3ef2c [serialization] Add support for slice types and variadic functions.
This is the first time reaching the case where the module refers to a type
that also appears in the TU and tries to modify it. This shouldn't be a
problem for any of the other types we currently serialize besides
BoundGenericType and ArraySliceType because we either don't try to modify
them after creation or are guaranteed a new type object.

Swift SVN r6060
2013-07-08 19:57:04 +00:00
Jordan Rose
aa2d1b2a64 [serialization] Handle PolymorphicFunctionTypes more carefully.
PolymorphicFunctionTypes are built on GenericParamLists, which are
owned by decls that introduce generic parameters. This made deserializing
them a pain, because they /cannot/ be recreated in isolation -- the decl
provides some context. Rather than try to come up with a very generic way
to serialize these, this patch just records the GenericParamList of every
decl, allowing the type to be serialized with a reference to the decl
instead of to the param list. Deserialization can then just pluck the list
back out of the decl.

According to Doug and Joe, PolymorphicFunctionType's due for a refresh
anyway, so this kind of hackery / kludgery is acceptable.

With this change, we can now handle generic structs and generic functions
inside generic structs.

Swift SVN r6032
2013-07-06 00:20:04 +00:00
Jordan Rose
eb9a1feaf3 [serialization] Handle oneof and class types (but not decls).
This allows us to reference Bool.

Swift SVN r6030
2013-07-06 00:19:40 +00:00
Jordan Rose
ce9c5c1d13 [serialization] Add support for generic structs (and constructors).
Swift SVN r5989
2013-07-04 00:20:38 +00:00
Jordan Rose
820c5a1404 [serialization] Serialize conformances for typealiases and protocols too.
Swift SVN r5988
2013-07-04 00:20:34 +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
bcab0b4fbe [serialization] Add support for substituted types and nested archetypes.
This also allows us to check same-type requirements.

Swift SVN r5986
2013-07-04 00:20:26 +00:00
Jordan Rose
197b696ce6 [serialization] Add support for generic requirements.
Same-type requirements aren't tested yet because there's currently no
support for associated types.

This includes an improvement to BCRecordLayout: array elements can be
passed inline, and the static checks that the data count matches the
field count will take this into account.

Swift SVN r5984
2013-07-04 00:15:06 +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
45fc3672f4 [serialization] Add support for protocol compositions.
Swift SVN r5964
2013-07-02 21:56:43 +00:00
Jordan Rose
cc92da302d [serialization] Add support for protocols.
Swift SVN r5962
2013-07-02 21:56:28 +00:00
Dave Abrahams
096ffc6eaf Silence warnings in the release build
Swift SVN r5950
2013-07-01 21:42:16 +00:00
Jordan Rose
1441258e17 [serialization] Use member initializers for Serializer.
No functionality change.

Swift SVN r5948
2013-07-01 21:05:48 +00:00
Jordan Rose
cb45063516 [serialization] Don't special-case builtin types.
Instead, special-case cross-references to use the empty identifier as the
name of the Builtin module. This way imported modules will be able to use
builtin types and functions without the main TU having access.

Swift SVN r5947
2013-07-01 21:05:39 +00:00
Joe Groff
53221db84c AST: Add 'VarPattern' node.
We decided to go with 'var' as a distributive pattern introducer which applies to bare identifiers within the subpattern. For example, 'var (a, b)' and '(var a, var b)' would be equivalent patterns. To model this, give 'var' its own AST node with a subpattern and remove the introducer loc from NamedPattern.

Swift SVN r5824
2013-06-26 23:01:47 +00:00
Doug Gregor
9a5c96a8c1 Introduce basic support for LLVM vectors as builtins.
This adds builtin types Builtin.VecNxT, where N is a natural number
and T is a builtin type, which map down to the LLVM type <N x T>. 

Update varous builtins to support vector arguments, e.g., binary
operations, comparisons, negation. Add InsertElement and
ExtractElement builtins for vectors.

On top of these builtins, add Vec4f and Vec4b structs to the standard
library, which provide 4xFloat and 4xBool vectors, respectively, with
basic support for arithmetic. These are mostly straw men, to be burned
down at our leisure.

Some issues as yet unresolved:
  - Comparisons of Vec4f'ss are producing bogus Vec4b's, which I
  haven't tracked down yet.
  - We still don't support the shuffle builtin, although it should be
  easy
  - More testing!



Swift SVN r5820
2013-06-26 21:16:36 +00:00
Joe Groff
e460a01af6 Remove the 'UnresolvedCallPattern' I stubbed out.
I talked to John about parsing patterns today, and because of the magnitude of name-lookup-dependent ambiguities between patterns and expressions, we agreed that at least for a first-pass implementation it makes sense to parse patterns as extensions of the expr grammar and charge name binding with distinguishing patterns from expressions. This gets us out of needing the concept of an "unresolved pattern", at least in the short term.

Swift SVN r5808
2013-06-26 04:23:47 +00:00
Doug Gregor
cace751e86 Eliminate DeducibleGenericParamType.
The type was used by the old type coercion code; it is no longer relevant.


Swift SVN r5799
2013-06-25 16:32:44 +00:00
Jordan Rose
d6780dfd02 [serialization] Add cross-module decl references.
This is currently implemented in terms of an access path of identifiers,
with a type check at the very end to pick the correct overload for a
function. Of course there are plenty of things missing here:
- function overloading on parameter names (selector pieces)
- access to values inside extensions
- generics (as everywhere)

This allows the serialization tests to be built against the standard
library instead of requiring -parse-stdlib.

Swift SVN r5797
2013-06-25 00:48:01 +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
Joe Groff
7ba95cfd26 Add AST nodes for refutable patterns.
Introduce Pattern subclasses for the 'is T', 'T(<pattern>)', and '<expr>' pattern syntaxes we'll be introducing for pattern-matching "switch" statements. Also add an 'UnresolvedCalLPattern' to act as an intermediate for name lookup to resolve to a nominal type, oneof element, or function call expression pattern. Since we'll need to be able to rewrite patterns like we do expressions, add setters to AST nodes that contain references to subpatterns. Implement some basic walking logic in places we search patterns for var decls, but punt on any more complex type-checking or SILGen derived from these nodes until we actually use them.

Swift SVN r5780
2013-06-24 17:17:34 +00:00
Jordan Rose
a63dddfba6 [serialization] Include BLOCKINFO block even in Release builds.
Though it adds a small bit of bloat to the serialized modules, it's
necessary for llvm-bcanalyzer-based tests, and it's really not something
to worry about anyway.

Swift SVN r5750
2013-06-21 18:23:49 +00:00
Jordan Rose
c957a28f99 [serialization] Add support for lvalue types and pattern binding decls.
This revealed an issue where a function's pattern may have variables that
depend on the function itself; it's therefore important that the function
decl is recorded in the decl map before its argument patterns are loaded.

We should now support structs, concrete properties, and computed properties.

Swift SVN r5745
2013-06-21 17:51:53 +00:00
Jordan Rose
b57c8c4f62 [serialization] Add support for metatype types and constructor arguments.
Swift SVN r5744
2013-06-21 17:51:47 +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
93be189ca4 [serialization] Add support for niladic function decls.
Like everything else, there are several caveats: no generic params, no
attributes, and (for now) no arguments. Pattern support is coming next.

Swift SVN r5701
2013-06-19 23:34:33 +00:00
Jordan Rose
a3cd729262 [serialization] Add support for FunctionType.
The only tricky thing here is that the calling convention enum needs to be
stable in the module format, so it's marshalled in and out by helper
functions when crossing serialization boundaries.

Swift SVN r5699
2013-06-19 23:34:27 +00:00
Jordan Rose
dbf41543f5 [serialization] Add support for TupleTypes.
These are implementing using trailing TUPLE_TYPE_ELT records after the
initial TUPLE_TYPE record. This is the next step towards function decls.

Element initializers are silently ignored for now.

Also, do serialize a record for IdentifierTypes, even though we're not
including the components yet, so that we don't serialize the underlying
type more than once.

Swift SVN r5683
2013-06-19 18:19:41 +00:00
Jordan Rose
ce84b185ea [serialization] Add support for ParenType.
This is a simple wrapper type. It was trivial to implement.

Swift SVN r5682
2013-06-19 18:19:35 +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
8bd38abdff [serialization] Blaze a straight-line path for no-arg constructors.
Ignore everything else. Unfortunately, even this requires VarDecls...

Swift SVN r5531
2013-06-08 00:18:22 +00:00
Jordan Rose
413b2ae485 [serialization] Sketch out struct serialization.
This serializes structs, but not any of their members. Unfortunately, all
structs have members (the implicit constructor at the very least), so this
doesn't actually do anything at all and is completely untested.

Immediate goal: round-tripping an empty struct.

Swift SVN r5530
2013-06-08 00:18:21 +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
Jordan Rose
76b19d53c4 [serialization] Deserialize typealiases and builtin types.
This includes the reading half of BCRecordLayout metaprogramming, and
then a fairly straightforward deserialize-and-cache implementation in
ModuleFile. Once again, this is based on Clang's module implementation:
decls and types are referred to by an ID, which is used as an index into
an array, which contains offsets to the definitions of the decl/type in
the "decls-and-types" block in the serialized module.

In order to test the feature, the code is currently eagerly deserializing
all declarations. This will be partially fixed in the next commit.

Swift SVN r5324
2013-05-25 01:34:56 +00:00
Jordan Rose
9b712a2fe9 [serialization] Remove skeleton for sharing module decl/type IDs.
Clang modules have a clever way to share decl and type IDs, by saying
"this range of IDs comes from this other module". Swift modules have to
be resilient, however, and so this is not a viable solution.

We still use 0 as a special ID for null decls and types, when applicable.

Swift SVN r5323
2013-05-25 01:34:55 +00:00
Jordan Rose
4f2b0bb917 [serialization] Replace hand-rolled PointerUnion with simple wrapper.
I avoided this the first time around because I wasn't sure if Type really had
low bits free, but it looks like we're relying on that elsewhere. If we ever
use up all the bits in Type we'll have to rip all these up, but for now it's
better to stick with what's in LLVM.

Swift SVN r5322
2013-05-25 01:34:54 +00:00
Jordan Rose
fc1cbf0aaf [serialization] Serialize builtin types and typealiases.
Just a starting point -- builtin types are serialized by name, and the
IdentifierType necessary to /refer/ to a typealias is completely skipped.
This should be enough to start working on deserialization, however.

Swift SVN r5320
2013-05-25 01:34:51 +00:00
Daniel Dunbar
61300747cc Fix capitalization of llvm/Config/config.h.
Swift SVN r5254
2013-05-21 19:31:00 +00:00
Jordan Rose
8707fa7000 [serialization] Add BCGenericRecordLayout, for shared layouts.
Micro-optimization in module file size and loading complexity.
No functionality change.

Swift SVN r5240
2013-05-20 22:50:42 +00:00
Jordan Rose
ea0d5031ab [serialization] Codify the bringup hack with a special note in the module file.
The bringup hack, again, is to just process the module source files as a
TranslationUnit if the module doesn't accurately represent the original
source. Currently this happens if the module is not empty, or if it imports
/anything/, since we don't actually serialize anything yet.

This also cleans up the decl/type serialization skeleton a bit.

Swift SVN r5238
2013-05-20 22:50:39 +00:00
Jordan Rose
b9b0789908 [serialization] Sketch out high-level decl/type serialization.
This is basically modeled off of Clang's ASTWriter: write out all decls
and types en masse, then write out a list of offsets for quick access later,
and use the indexes into the offset lists as module-unique IDs for the decls
and types.

No decls or types are actually being serialized yet, and I haven't done
any of the work necessary for multi-module support (which would assume
offsets don't start at 0). There's also no reader support yet.

Swift SVN r5237
2013-05-20 22:50:35 +00:00