Commit Graph

1537 Commits

Author SHA1 Message Date
Dmitri Hrybenko
a01809e171 Use SmallVector instead of std::vector
Swift SVN r11114
2013-12-11 02:23:34 +00:00
Dmitri Hrybenko
49e739e2ca Replace a nonsense DeclContext with the correct one
Swift SVN r11113
2013-12-11 02:17:52 +00:00
Jordan Rose
417b5d3982 Merge TranslationUnit into Module, and eliminate the term "translation unit".
This completes the FileUnit refactoring. A module consists of multiple
FileUnits, which provide decls from various file-like sources. I say
"file-like" because the Builtin module is implemented with a single
BuiltinUnit, and imported Clang modules are just a single FileUnit source
within a module.

Most modules, therefore, contain a single file unit; only the main module
will contain multiple source files (and eventually partial AST files).

The term "translation unit" has been scrubbed from the project. To refer
to the context of declarations outside of any other declarations, use
"top-level" or "module scope". To refer to a .swift file or its DeclContext,
use "source file". To refer to a single unit of compilation, use "module",
since the model is that an entire module will be compiled with a single
driver call. (It will still be possible to compile a single source file
through the direct-to-frontend interface, but only in the context of the
whole module.)

Swift SVN r10837
2013-12-05 01:51:15 +00:00
Jordan Rose
be12d86ddd Turn ClangModule into ClangModuleUnit.
Part of the FileUnit restructuring. A Clang module (whether from a framework
or a simple collection of headers) is now imported as a TranslationUnit
containing a single ClangModuleUnit.

One wrinkle in all this is that Swift very much wants to do searches on a
per-module basis, but Clang can only do lookups across the entire
TranslationUnit. Unless and until we get a better way to deal with this,
we're stuck with an inefficiency here. Previously, we used to hack around
this by ignoring the "per-module" bit and only performing one lookup into
all Clang modules, but that's not actually correct with respect to visibility.

Now, we're just taking the filtering hit for looking up a particular name,
and caching the results when we look up everything (for code completion).
This isn't ideal, but it doesn't seem to be costing too much in performance,
at least not right now, and it means we can get visibility correct.

In the future, it might make sense to include a ClangModuleUnit alongside a
SerializedASTFile for adapter modules, rather than having two separate
modules with the same name. I haven't really thought through this yet, though.

Swift SVN r10834
2013-12-05 01:51:11 +00:00
Jordan Rose
eede5ec4f9 Begin refactoring for mixed file kinds within a single module.
The goal of this series of commits is to allow the main module to consist
of both source files and AST files, where the AST files represent files
that were already built and don't need to be rebuilt, or of Swift source
files and imported Clang headers that share a module (because they are in
the same target).

Currently modules are divided into different kinds, and that defines how
decls are looked up, how imports are managed, etc. In order to achieve the
goal above, that polymorphism should be pushed down to the individual units
within a module, so that instead of TranslationUnit, BuiltinModule,
SerializedModule, and ClangModule, we have SourceFile, BuiltinUnit,
SerializedFile, and ClangUnit. (Better names welcome.) At that point we can
hopefully collapse TranslationUnit into Module and make Module non-polymorphic.

This commit makes SourceFile the subclass of an abstract FileUnit, and
makes TranslationUnit hold an array of FileUnits instead of SourceFiles.
To demonstrate that this is actually working, the Builtin module has also
been converted to FileUnit: it is now a TranslationUnit containing a single
BuiltinUnit.

Swift SVN r10830
2013-12-05 01:51:03 +00:00
John McCall
20e58dcf93 Change the type of function values in SIL to SILFunctionType.
Perform major abstraction remappings in SILGen.  Introduce
thunking functions as necessary to map between abstraction
patterns.

Swift SVN r10562
2013-11-19 22:55:09 +00:00
Joe Groff
15dc4967aa IRGen: Lower SILGlobalVariables.
Add support for emitting IR for SILGlobalVariables and SILGlobalAddrInst.

Swift SVN r10543
2013-11-18 17:40:45 +00:00
John McCall
93dfaa6bf4 Make everything getting a TypeInfo declare whether it's
working with a SIL-lowered or SIL-unlowered type.

Swift SVN r10067
2013-11-09 01:41:16 +00:00
Joe Groff
aee4eefe81 IRGen: Emit metadata for imported NS_ENUMs.
Also, the extra inhabitant lookup for native Swift no-payload enums is inappropriate for C enums. For now, expose no extra inhabitants from C enums.

Swift SVN r10006
2013-11-06 21:45:53 +00:00
Jordan Rose
98717a2296 Add -multi-file-output mode, which generates one object file per input file.
SILGen, SIL passes, and IRGen have been factored out of main() into a
helper function "performCompile", which is called separately for each
input file. This will eventually be used to avoid rebuilding an entire
target when a single file changes.

Known issues:
- @transparent functions are not inlined across file boundaries.
  <rdar://problem/15366167>
- Some work and caches could definitely be shared between "compilations".
- Unless all files use the same LLVMContext, we get crashes.
  <rdar://problem/15283227>
- This mode is not compatible with -emit-module, so building a library still
  requires using single-file mode, or performing two invocations of swift.
  Eventually we'll have an AST-merging tool to combine the ASTs serialized
  into object files. <rdar://problem/15246467>

But the long-term design is to have these separate compilations happen in
separate cc1-like processes, so we shouldn't spend too much time optimizing
this.

Swift SVN r9889
2013-11-02 01:08:36 +00:00
Joe Groff
a0c4486808 IRGen: Emit protocol descriptors.
Produce protocol descriptors when we see a protocol definition in the current module. If the protocol is @objc, go through the existing path for generating full Protocol* metadata for objc objects; otherwise, emit our layout-compatible but strong-external-linkage Swift protocol descriptor record.

Swift SVN r9867
2013-11-01 04:28:43 +00:00
Joe Groff
5ec3cad5f6 ClangImporter: Emit metadata for imported enums.
Whatever kind of Swift decl we cons up for a Clang enum, add it to the externals list so we can pick it up and emit Swift metadata for it in IRGen. Fixes <rdar://problem/15242452>.

Swift SVN r9801
2013-10-30 18:15:09 +00:00
Jordan Rose
4a90ab0a4f [IRGen] Separate out SourceFile-specific processing from whole-module stuff.
We're going to want to emit multiple SourceFiles and one SILModule in one
IRGenModule.

Swift SVN r9670
2013-10-25 17:30:39 +00:00
Jordan Rose
0702acab3d Make SourceFile a DeclContext, but don't actually do anything with it yet.
Swift SVN r9646
2013-10-24 18:59:21 +00:00
Joe Groff
c757ebf049 IRGen: Give nominal type descriptors for Clang-imported types thunk linkage.
Make them hidden linkonce_odr like other Clang-bridging symbols.

Swift SVN r9639
2013-10-24 15:35:43 +00:00
Joe Groff
b8c75769b3 IRGen: Emit nominal type descriptors in struct and enum metadata.
Build a nominal type descriptor when we emit the metadata or generic metadata pattern for a nominal type, and put a reference into the formerly null slot in the struct or enum metadata. We need to make a place for them in class metadata; that'll come next.

Swift SVN r9492
2013-10-18 21:04:58 +00:00
Joe Groff
0974d7d373 IRGen: Register ObjC protocol conformances at runtime when JIT-ing extensions.
Swift SVN r9474
2013-10-18 01:20:49 +00:00
Jordan Rose
09787207fc Push TUKind into SourceFile (as InputKind).
Different SourceFiles in the same module will eventually have different
input kinds (at the very least Main vs. Library).

Swift SVN r9076
2013-10-09 18:38:25 +00:00
Jordan Rose
49cd5b1680 Use SourceFile in IRGen.
The only real change here is that module-wide IR (autolinking and ObjC
runtime flags) have been pushed up from emitTranslationUnit (now
emitSourceFile) to its only caller, performIRGeneration.

Swift SVN r9075
2013-10-09 18:38:24 +00:00
Jordan Rose
597640a5d2 Introduce "SourceFile" within a TranslationUnit.
Right now this is just an extra layer of indirection for the decls,
operators, and imports in a TU, but it's the first step towards compiling
multiple source files at once without pretending they're all in a single
file. This is important for the "implicit visibility" feature, where
declarations from other source files in the same module are accessible
from the file currently being compiled.

Swift SVN r9072
2013-10-09 18:38:15 +00:00
Dmitri Hrybenko
4a0c050d81 Store the standard library module name as ASTContext::StdlibModuleName
... instead of repeating it everywhere


Swift SVN r8792
2013-09-30 21:07:35 +00:00
Jordan Rose
e05c03d5bc Standardize terminology for "computed", "stored", "variable", and "property".
These are the terms sent out in the proposal last week and described in
StoredAndComputedVariables.rst.

variable
  anything declared with 'var'
member variable
  a variable inside a nominal type (may be an instance variable or not)
property
  another term for "member variable"
computed variable
  a variable with a custom getter or setter
stored variable
  a variable with backing storage; any non-computed variable

These terms pre-exist in SIL and IRGen, so I only attempted to solidify
their definitions. Other than the use of "field" for "tuple element",
none of these should be exposed to users.

field
  a tuple element, or
  the underlying storage for a stored variable in a struct or class
physical
  describes an entity whose value can be accessed directly
logical
  describes an entity whose value must be accessed through some accessor

Swift SVN r8698
2013-09-26 18:50:44 +00:00
Doug Gregor
56edc42dc8 IRGen for Objective-C subscript thunks.
Swift SVN r8617
2013-09-25 01:14:54 +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
Adrian Prantl
29ca4e26d9 comments.
Swift SVN r8537
2013-09-21 00:19:32 +00:00
Adrian Prantl
31dfc7be93 Debug info: Emit the implicit import of swift.swift in DWARF.
rdar://problem/14821063

Swift SVN r8536
2013-09-21 00:14:21 +00:00
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
Dmitri Hrybenko
429633b18a Let the type checker create implicit DestructorDecls
Improve the type checker to create implicit DestructorDecls, tighten the
assertion in ImplicitReturnLocation::getImplicitReturnLoc(), and add a verifier
check that a class in a type checked AST always has exactly one destructor.

SILGen used to generate a destructor if the class does not have a
DestructorDecl.  SILGen used to put the ClassDecl inside the SILLocation for
the destructor SIL code.  This is not a very clean solution: in this case
ImplicitReturnLocation SILLocations contain ClassDecl, which is surprising.

rdar://14970972 Implicit destructors should have AST nodes


Swift SVN r8498
2013-09-20 17:34:22 +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
Adrian Prantl
021bdd70d0 Debug info: emit the return type for main().
Lldb gets really confused otherwise.

Swift SVN r8430
2013-09-18 23:49:09 +00:00
Doug Gregor
f7a2d5eed0 Emit Objective-C thunks for [objc] initializing constructors.
Now that all [objc] constructors have a suitable "init" selector, emit
an Objective-C thunk for the initializing constructor (not the
allocating constructor!) with that selector, and make sure it shows up
in the Objective-C metadata. 

With this, we can write a Swift constructor "constructor()" to
override "-init"; see the change to ListMaker that exercises this.

Joe or John: I'd love a review of these.



Swift SVN r8373
2013-09-18 00:30:54 +00:00
Doug Gregor
daded7abb3 Always Objective-C categories for extensions with [objc] entry points.
Previously, we predicated this on the original class itself being
[objc] or the extension having adopted any [objc] protocols. Extend
that definition to consider one-off, explicitly-marked [objc] methods
or properties.

Since we're here, and make sure we can reference the Objective-C
metaclass in the interpreter even when the original class wasn't
marked [objc].



Swift SVN r8310
2013-09-16 23:55: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
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
Daniel Dunbar
7a00197905 [IRGen] llvm.global_ctor should not be emitted as a constant.
- Appending globals need to have the same type as Clang emits for them in order
   for LTO to be able to merge them.

Swift SVN r8141
2013-09-12 02:25:11 +00:00
Joe Groff
705102b544 SIL: Rename 'ClangThunk' specifier to 'Thunk'.
Lazily-generated currying thunks will require the same IR-level linkonce_odr linkage as clang thunks currently do, so generalize the name of the existing SIL-level linkage specifier 'clang_thunk'.

Swift SVN r8122
2013-09-11 23:47:15 +00:00
Adrian Prantl
46caf67a2d More cleanups: Someone implemented Size and Alignment while I wasn't looking :-)
Swift SVN r8121
2013-09-11 23:47:04 +00:00
Doug Gregor
0e3aa19313 Factor the selector-loading logic into its own routine.
When loading a selector in the JIT, we need to call
sel_registerName(). This was manually coded in two places and missed
in a third, so factor it appropriately.


Swift SVN r8082
2013-09-10 22:42:45 +00:00
Adrian Prantl
af562d1696 Debug info: name mangling for composite types containing Archetypes.
Among other things this enables mangled names for tuples.
This adds a pointer to the DeclContext to SILFunction and which is used
to provide the necessary context to the Mangler.
Fixes rdar://problem/14808764 and rdar://problem/14813658.

Swift SVN r8070
2013-09-10 17:04:33 +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
Anna Zaks
e36839ca8a [IRGen] Eliminate calls to SILLocation() from IRGen.
Here, the location information does not have to always be available. Use Optional instead of creating an empty location.

Swift SVN r8055
2013-09-09 22:34:01 +00:00
Anna Zaks
369a948248 [SIL] Minor auto-generated SILLocation API rename/refactor.
Swift SVN r8018
2013-09-06 23:57:27 +00:00
Joe Groff
e6309152e5 IRGen: Kill the 'buildFakeType' abomination in GenericMetadataBuilder.
To instantiate the value witness table for generic types, we were instantiating the generic type at () for all of its parameters and hoping for the best. That's insane. Instead, let's use the DeclaredTypeInContext for the generic type so the archetypes actually get usefully bound inside the witnesses. This way, the witness implementations should be independent of generic parameters, so we can also mangle the unbound type into the witness symbols.

Swift SVN r7901
2013-09-04 17:50:12 +00:00
Anna Zaks
440631f86a [SIL] Add the SILLocation hierarchy.
Now we should be ready to start using these.

Swift SVN r7632
2013-08-27 22:16:18 +00:00
Adrian Prantl
cf4e28a70a Debug Info: Change the type caching to be based on the Type instead of
DebugTypeInfo. This is based off the observation that no two types that
share the same canonical type can have different storage and alignment
and has the benefit of being able to locate the debug info for a type
described by a meta type.

Swift SVN r7578
2013-08-26 17:55:14 +00:00
Doug Gregor
484ab259de Switch a few more clients over to Type::findIf().
Swift SVN r7536
2013-08-23 22:28:02 +00:00
Jordan Rose
1b687f3855 Add autolinking metadata output to IRGen.
This currently only works with Clang modules, since there's no way to specify
requirements for a Swift module.

Also, update some tests with a fake Foundation module to make sure they pick
up the fake Foundation adapter instead of the real one.

Swift SVN r7490
2013-08-22 23:20:28 +00:00
John McCall
1ea82afa8e Split ReferenceStorageType into {Weak,Unowned}StorageType.
Swift SVN r7478
2013-08-22 21:36:36 +00:00