Commit Graph

2062 Commits

Author SHA1 Message Date
Joe Groff
5d8a7ff9e7 Allow multiple comma-separated enum elements in a 'case' decl.
Introduce an EnumCaseDecl for source fidelity to track the 'case' location and ordering of EnumElementDecls. Parse a comma-separated list of EnumElementDecls after a 'case' token.

Swift SVN r8509
2013-09-20 19:51:13 +00:00
Joe Groff
e109124186 Replace 'union' keyword with 'enum'.
This only touches the compiler and tests. Doc updates to follow.

Swift SVN r8478
2013-09-20 01:33:14 +00:00
Anna Zaks
ecff37478c Sprinkle transparent on methods involved in computation of true/false
This allows us to inline all methods involved in computation of true and false.
Now it's up to CCP to simplify it all to 1 and 0.

Swift SVN r8435
2013-09-19 00:53:14 +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
Doug Gregor
90b8b3e499 Constructor selectors always start with 'init'.
Implement the new rules for mapping between selector names and
constructors. The selector for a given constructor is formed by
looking at the names of the constructor parameters:
  * For the first parameter, prepend "init" to the parameter name and
  uppercase the first letter of the parameter name. Append ':' if
  there are > 1 parameters or the parameter has non-empty-tuple type.
  * For the remaining parameters, the name of each parameter followed
  by ':'.

When a parameter doesn't exist, assume that the parameter name is the
empty string.

And, because I failed to commit it separately, support selector-style
declarations of constructor parameters so that we can actually write
constructors nicely, e.g.:

  // selector is initWithFoo:bar:
  constructor withFoo(foo : Foo) bar(bar : Bar) { ... }



Swift SVN r8361
2013-09-17 22:49:05 +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
Dmitri Hrybenko
10291e0334 Make AbstractClosureExpr a DeclContext
(remove DeclContext base class from PipeClosureExpr and ImplicitClosureExpr)


Swift SVN r8303
2013-09-16 22:39:12 +00:00
Manman Ren
e797f23df0 SIL Serialization: add handling of types.
For PolymorphicFunctionType used in a SILFunction, we don't have a
corresponding Decl to share the parameter list with. In that case,
we set the owning Decl ID to 0 and add a trailing param lists.

We add a helper function to find the TypeAliasDecl for a Builtin type.
If the lookup is expensive, we can cache the lookup.

Deserializing SILBasicBlock and SILInstruction is not implemented yet.

SIL serializer and deserializer are implicitly tested when a module
contains transparant SILFunctions.


Swift SVN r8230
2013-09-13 23:54:33 +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
Doug Gregor
e5c39d3e16 Always compute the substitutions of a BoundGenericType on-the-fly.
We often won't need the complete substitutions, so only compute them
when needed. This also means that we don't need to serialize them into
module files.


Swift SVN r8194
2013-09-13 14:38:23 +00:00
Doug Gregor
978eaab5c6 Introduce lazy computation of a BoundGenericType's substitutions.
Teach a BoundGenericType to compute its own substitutions, which
allows AST clients to create new bound generic types without the aid
of the type checker. 

This eliminates the TypeChecker::validateTypeSimple() abomination as
well as the need for the BoundGenericType AST validation step. There
is still more cleanup to do in this area.

Note that BoundGenericType::getSubstitutions() now accepts a module
parameter, which is the place from which we will look for
conformances. This is a baby step toward properly modeling the
conformances as part of the bound generic type, and is nowhere near
complete.


Swift SVN r8193
2013-09-13 14:25:36 +00:00
Dmitri Hrybenko
45e654fbaa Make AbstractFunctionDecl a DeclContext
and remove DeclContext base class from FuncDecl, ConstructorDecl and
DestructorDecl

This decreases the number of DeclContexts to 7 and allows us to apply
alignas(8) to DeclContext.


Swift SVN r8186
2013-09-13 03:38:33 +00:00
Dmitri Hrybenko
0d6d9a0ffb Move the DeclContext base class from FuncExpr to FuncDecl
FuncDecl still has a FuncExpr because capture list is stored in FuncExpr
(which is a CapturingExpr).


Swift SVN r8179
2013-09-13 01:40:41 +00:00
Dmitri Hrybenko
7da84fd13d Make FuncExpr, PipeClosureExpr and ClosureExpr DeclContexts on their own.
This is a first step to detach them from CapturingExpr and eventually move them
in the AST class hierarchy.


Swift SVN r8171
2013-09-12 23:58:06 +00:00
Manman Ren
ddd7fb4d46 SIL Serialiation: add implementation to serialize SIL basic block and a
few SIL instructions types.

This will be tested when we have a SIL deserializer. Testing cases covering
each implemented SIL instruction will be added.


Swift SVN r8094
2013-09-11 17:52:05 +00:00
Dmitri Hrybenko
3cc01cf7d6 Introduce AbstractFunctionDecl -- a base class for ConstructorDecl,
DestructorDecl, FuncDecl -- and move some of the common concepts and logic
into it

No functionality change.


Swift SVN r8090
2013-09-11 04:04:01 +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
Dmitri Hrybenko
1e23c936e0 Rename FuncDecl::getBody() to FuncDecl::getFuncExpr()
ConstructorDecl::getBody() and DestructorDecl::getBody() return 'BraceStmt *'.
After changing the AST representation for functions, FuncDecl::getBody() will
return 'BraceStmt *' and FuncDecl::getFuncExpr() will be gone.


Swift SVN r8050
2013-09-09 19:57:27 +00:00
Jordan Rose
d112448c93 [serialization] Remove dead code found by the static analyzer.
<rdar://problem/14911430>

Swift SVN r7920
2013-09-04 22:18:46 +00:00
Manman Ren
64ccd88c8c SIL Serialiation: pass in a SILModule to serialize and a few other functions.
Add SerializeSIL.cpp for basic implementation of a SIL serializer.

serialize, serializeToStream, Serializer::writeToStream, and
Serializer::writeTranslationUnit all take an additional SILModule to pass it
to Serializer::writeSILFunctions.

Serializer::writeSILFunctions goes through all SILFunctions in a SILModule, and
serializes all SILFunctions that are transparent.


Swift SVN r7875
2013-09-03 22:57:37 +00:00
Manman Ren
70c9ab5658 Move class definition of Serializer to header file to help SIL serialization.
No functionality change.


Swift SVN r7873
2013-09-03 22:42:25 +00:00
Doug Gregor
7a0ce11980 Replace ProtocolConformanceWitness with ConcreteDeclRef.
The latter is more efficient and should eventually be more common.


Swift SVN r7840
2013-09-03 15:15:13 +00:00
Manman Ren
3b4a90e8c3 Serialization: handle transparent attribute.
Swift SVN r7797
2013-08-30 20:29:05 +00:00
Dave Zarzycki
2da92327c4 Adopt [transparent] in a bunch of places
Swift SVN r7779
2013-08-30 16:28:13 +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
Dmitri Hrybenko
69cfa73640 More 'this' -> 'self' replacements
Swift SVN r7657
2013-08-28 02:57:21 +00:00
Doug Gregor
330f5fe1e7 For nested archetypes, track the corresponding associated type.
Each nested archetype X.Y corresponds to an associated type named 'Y'
within one of the protocols to which X conforms. Record the associated
type within the archetype itself. When performing type substitutions,
use that associated type to extract the corresponding type witness
rather than looking for the type itself. This is technically more
correct (since we used the type witness for type checking), and a step
toward pulling type substitutions into the AST.



Swift SVN r7624
2013-08-27 17:05:11 +00:00
Doug Gregor
2852e461e8 Teach AST to lazily fill in the T[] and T? implementation types.
We previously relied on the type checker to fill in the implementation
types (swift.Slice<T> and swift.Optional<T>, respectively), which
limited our ability to perform type transformations in the AST. Now,
the AST knows how to form these implementation types on demand.



Swift SVN r7587
2013-08-26 19:08:39 +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
John McCall
1ea82afa8e Split ReferenceStorageType into {Weak,Unowned}StorageType.
Swift SVN r7478
2013-08-22 21:36:36 +00:00
Doug Gregor
7c84fd5926 Start detangling archetypes from the interface of generic functions.
This breaks the type-canonicalization link between a generic parameter
type and the archetype to which it maps. Generic type parameter types
are now separate entities (that can eventually be canonicalized) from
archetypes (rather than just being sugar).

Most of the front end still traffics in archetypes. As a step away
from this, allow us to type-check the generic parameter list's types
prior to wiring the generic type parameter declarations to archetypes,
using the new "dependent" member type to describe assocaited
types. The archetype builder understands dependent member types and
uses them to map down to associated types when building archetypes.

Once we have assigned archetypes, we revert the dependent identifier
types within the generic parameter list to an un-type-checked state
and do the type checking again in the presence of archetypes, so that
nothing beyond the generic-parameter-list checking code has to deal
with dependent types. We'll creep support out to other dependent types
elsewhere over time.



Swift SVN r7462
2013-08-22 18:07:40 +00:00
Doug Gregor
2e91172d4f Don't record the declared type of nominal type decls within the module file.
Instead, compute the type just after we load the nominal type
declaration. This centralizes the type-computation code better as
well.


Swift SVN r7454
2013-08-22 17:33:24 +00:00
Doug Gregor
5034803021 Lazily compute the type of protocol declarations.
Swift SVN r7453
2013-08-22 17:09:16 +00:00
Doug Gregor
e7f5f3da01 Set the type of class/struct/union declarations during type checking.
Previously, we were creating the type corresponding to
class/struct/union declarations as part of creating the declaration
node, which happens at parse time. The main problem with this (at the
moment) occurs with nested nominal types, where we'd end up with the
wrong "parent" type when the type was nested inside an extension
(because the extension hadn't been resolved at the time we accessed
the parent's type). Amusingly, only code completion observed this,
because the canonical type system hid the problem. The churn in the
code-completion tests come from the fact that we now have the proper
declared type for class/struct/union declarations within extensions.

Take a step toward order-independent type checking by setting the type
of a class/struct/union declaration in type checking when we either
find the declaration (e.g., due to name lookup) or walk to the
declaration (in our walk of the whole translation unit to type-check
it), extending the existing TypeChecker::validateTypeDecl() entry
point and adding a few more callers.

The removeShadowedDecls() hack is awful; this needs to move out to the
callers, which should be abstracted better in the type checker anyway.

Incremental, non-obvious step toward fixing the representation of
polymorphic function types. This yak has a *lot* of hair.



Swift SVN r7444
2013-08-22 00:57:38 +00:00
Jordan Rose
148ccdbd82 [serialization] Have swift::serialize forward to swift::serializeToStream.
The latter is simple, but there's still no reason to duplicate this code.

Swift SVN r7422
2013-08-21 20:20:51 +00:00
Adrian Prantl
661315763a Debug Info: This patch implements the "emit modules when compiling -g"
proposal.
When compiling with debug info, build a swiftmodule that contains all the
type decls referenced by DWARF and emit it into a special __apple_swiftast
section in the .o file.

Swift SVN r7398
2013-08-21 01:07:30 +00:00
Anna Zaks
2f05d5c4df [SIL] Move GenFunc to use getBuiltinInfo and getIntrinsicInfo.
Make the functions support a wider range of builtins and store types to make
it possible.

This is an optimization - the cached ID will be used for builtin identification,
instead of retrieval of the string name and using it as the key.

Swift SVN r7390
2013-08-21 00:02:22 +00:00
Jordan Rose
f18556f49b [serialization] Don't bother serializing empty conformance lists.
If nothing in the module conforms to IntegerLiteralConvertible, we don't
need a record for it.

Swift SVN r7384
2013-08-20 23:17:48 +00:00
Doug Gregor
e4eaf3fb56 Record depth/index of generic parameters.
Another baby step toward a proper canonical form for polymorphic
function types: generic parameters will eventually be uniquable by
their depth and index.


Swift SVN r7380
2013-08-20 22:44:00 +00:00
Doug Gregor
6c6f70d3bd Remove debugging code
Swift SVN r7361
2013-08-20 16:44:14 +00:00
Doug Gregor
1ddb34fb71 Factor generic parameters and associated types into their own decl nodes.
Previously, TypeAliasDecl was used for typealiases, generic
parameters, and assocaited types, which is hideous and the source of
much confusion. Factor the latter two out into their own decl nodes,
with a common abstract base for "type parameters", and push these
nodes throughout the frontend.

No real functionality change, but this is a step toward uniquing
polymorphic types, among other things.


Swift SVN r7345
2013-08-19 23:36:58 +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
88cad52d72 Implement type sugar "T?" for Optional<T>.
- New type representation OptionalTypeRepr.
- New sugared type OptionalType.
- New base type SyntaxSugarType, parent of ArraySliceType and OptionalType.
  These two are the same in a lot of ways.
- The form "T[]?" is forbidden, because it makes "Int[4][2]" oddly
  different from "Int[4]?[2]". The type can be spelled "(T[])?" or
  Optional<T[]>.
- Like Slice, "Optional" is just looked up in the current module. This may
  or may not be the desired behavior in the long run.

<rdar://problem/14666783>

Swift SVN r7100
2013-08-09 21:33:36 +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