Commit Graph

166 Commits

Author SHA1 Message Date
Argyrios Kyrtzidis
7476762dae Remove IdentifierType from the type system.
Swift SVN r6327
2013-07-17 14:57:38 +00:00
Jordan Rose
87689d1c84 [serialization] Handle references to generic parameters.
Generic parameters are implemented using specially-tagged TypeAliasDecls.
Unlike normal ValueDecls, their names are not resilient, and so cross-
module references shouldn't refer to them by name. Instead, use an index
into the generic parameter list of their context.

Since generic parameters can appear within extensions, this new kind isn't
mutually exclusive with the just-introduced ExtensionValue. Change that to
be a separate flag that applies to both Values and GenericParameters.

Swift SVN r6304
2013-07-16 23:10:56 +00:00
Jordan Rose
c15653f645 [serialization] Add support for asmname.
We were actually ignoring this completely because DeclAttributes::isEmpty
wasn't taking them into account.

Swift SVN r6302
2013-07-16 23:10:43 +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
Doug Gregor
423abc5038 Codify the default argument hack for __FILE__/__LINE__/__COLUMN__.
Teach TuplePatternElt to keep track of the kind of the default
argument: none, normal (provided by calling into the appropriate
callee generator), __FILE__, __LINE__, or __COLUMN__. For the latter
three cases, the type checker forms the appropriate argument as part
of the call. 

The actual default argument expression will only be held in the tuple
pattern element when we've parsed it; it won't be serialized or
deserialized, because only the defining module cares. This is a step
toward eliminate the initialization expression from tuple types.

The extension to TupleShuffleExpr is a hack, which will also be
replicated in ScalarToTupleExpr, until we finally rework the
representation of TupleShuffleExpr (<rdar://problem/12340004>).


Swift SVN r6299
2013-07-16 22:52:38 +00:00
Argyrios Kyrtzidis
37dc84e13c Remove VarargBaseType from TuplePatternElt and introduce a bit in TuplePattern to indicate if there is a vararg.
The semantics of varargs (only for the last element) make it more appropriate as a property of the TuplePattern.
Also free the Parser from needing to construct synthetic types (ArraySlice for type of vararg element) to
accommodate the TypeChecker and move the logic to the TypeChecker. This will be more beneficial when the parser stops
creating types in general.

Swift SVN r6271
2013-07-15 20:21:30 +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
Argyrios Kyrtzidis
fee0e6635e [serialization] Update the field of TupleTypeEltLayout.
Swift SVN r6234
2013-07-13 00:31:37 +00:00
Joe Groff
d956fdbd9e Update 'oneof' syntax.
Give oneof bodies syntax consistent with other NominalTypes. Give oneof elements first-class declaration syntax using the 'case' introducer, as suggested by Jordan. Oneofs can contain 'case' decls, functions, properties, and constructors, but not physical ivars. Non-oneof scopes cannot contain 'case' decls. Add some QoI to the oneof 'case' parser to also parse and complain about things that resemble switch 'case' labels inside decl contexts.

Swift SVN r6211
2013-07-12 20:42:19 +00:00
Jordan Rose
c699b84cfa [serialization] Add support for destructors.
With this commit, we can now serialize all of stdlib_core!
(Deserializing still has a few issues.)

Swift SVN r6188
2013-07-11 23:35:34 +00:00
Jordan Rose
e0301b6037 [serialization] Add support for UnboundGenericTypes.
I had previously thought these didn't appear in public decls, but they're
used when you extend a generic class without generic arguments.

Swift SVN r6187
2013-07-11 23:35:25 +00:00
Jordan Rose
37d9ae4e09 [serialization] Add support for extensions.
Currently, we are eagerly deserializing extensions. This probably isn't
what we want to do in the long run, but until lookup settles down a bit
it's not worth optimizing.

Swift SVN r6186
2013-07-11 23:35:19 +00:00
Jordan Rose
d1163afb4b [serialization] Add support for [conversion] methods.
Take advantage of the fact that a function can never be both a conversion
method and an assignment operator to pack both flags into the same bit in
the serialized record.

Swift SVN r6185
2013-07-11 23:35:12 +00:00
Jordan Rose
0afaa86bcc [serialization] Add support for subscript decls.
For consistency purposes, VarDecls in the subscript pattern now have the
enclosing nominal as their decl context, rather than no decl context at all.

Swift SVN r6177
2013-07-11 21:22:08 +00:00
Jordan Rose
9b7ae1aa50 [serialization] Handle archetypes unified by a constraint.
Turns out we actually have to serialize the name of an archetype, because
it may be different from the declaration in a context where it has been
unified with another archetype. Found on attempting to emit a module for
the standard library.

(This is actually the commit that uses the two-container for_each
introduced in the last commit.)

Swift SVN r6172
2013-07-11 21:12:46 +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
Doug Gregor
bb2046c37b (De-)serialized ProtocolConformance::DefaultedDefinitions.
Swift SVN r6166
2013-07-11 18:34:03 +00:00
Jordan Rose
ca6f08164f [serialization] Add support for oneofs.
Since SILGen support is so poor, the test just uses -parse.

Swift SVN r6136
2013-07-10 23:26:00 +00:00
Jordan Rose
b4fe4f098c [serialization] Handle computed properties with a getter /and/ setter.
Since accessor FuncDecl have a backreference to the VarDecl they are
attached to, we were getting re-entrant deserialization issues. Fix
this by just not serializing the backreference and relying on the
property being deserialized first.

Swift SVN r6134
2013-07-10 23:25:39 +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
John McCall
6e79ed41f9 Per review, there's currently no need to reserve space
for future expansion in this.

Swift SVN r6122
2013-07-10 18:35:47 +00:00
John McCall
f4f164cb9e Add deserialization and stable encodings for ReferenceStorageType.
Jordan, please review.

Swift SVN r6111
2013-07-10 09:00:36 +00:00
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
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
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
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
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