Commit Graph

622 Commits

Author SHA1 Message Date
Jordan Rose
8b8cc8ee62 Turn SerializedModule into SerializedASTFile.
Part of the FileUnit restructuring. A serialized module is now represented as
a TranslationUnit containing a single SerializedASTFile.

As part of this change, the FileUnit interface has been made virtual, rather
than switching on the Kind in every accessor. We think the operations
performed on files are sufficiently high-level that this shouldn't affect us.

A nice side effect of all this is that we now properly model the visibility
of modules imported into source files. Previously, we would always consider
the top-level imports of all files within a target, whether re-exported or
not.

We may still end up wanting to distinguish properties of a complete Swift
module file from a partial AST file, but we can do that within
SerializedModuleLoader.

Swift SVN r10832
2013-12-05 01:51:09 +00:00
John McCall
4bba9b38f8 Make several new interfaces traffic in AbstractionPatterns.
Swift SVN r10621
2013-11-21 02:19:46 +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
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
554abf2d7a IRGen/Runtime: Expose extra inhabitants of class types.
Start using null-page values as extra inhabitants when laying out single-payload enums that contain class pointers as their payload type. Don't use inhabitants that set the lowest bit, to avoid trampling potential ObjC tagged pointer representations. This means that 'T?' for class type T now has a null pointer representation. Enums with multiple empty cases, as well as nested enums like 'T??', should now have optimal representations for class type T as well.

Note that we don't yet expose extra inhabitants for aggregates that contain heap object references, such as structs with class fields, Swift function types, or class-bounded existentials (even when the existential has no witness tables).

Swift SVN r10061
2013-11-09 00:43:40 +00:00
Doug Gregor
beac4e65cd Generate Objective-C protocol metadata for optional requirements.
This should finish off the implementation of optional requirements in
protocols <rdar://problem/14357101>.


Swift SVN r9997
2013-11-06 19:26:21 +00:00
Doug Gregor
0107e36e8b Allow models to omit witnesses for optional protocol requirements.
Swift SVN r9962
2013-11-05 16:28:34 +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
d2de66b18b IRGen: Include formal protocol conformances in ObjC class and protocol data.
So that Swift-defined classes actually do the right thing when -conformsToProtocol:-ed by dynamic protocol casts. Partially addresses <rdar://problem/15247517>, but we still need to dynamically emit runtime calls to register the conformance when compiling extensions in the JIT.

Swift SVN r9471
2013-10-17 22:51:04 +00:00
Joe Groff
f164a88615 IRGen: Emit ObjC protocol records for protocols used in casts.
Greg indicated that objc_getProtocol only works if somebody actually reifies a protocol_t record for the protocol with the runtime, so we need to emit our own protocol_t for every Protocol* value we do a checked cast with. Hijack the ClassDataBuilder to also build protocol_t records.

Swift SVN r9420
2013-10-16 21:50:56 +00:00
Chris Lattner
09705dc7cd 1) Redesign DeclAttributes to be based around an array indexed by attribute, instead
of having a ton of ad-hoc bools in it.  This allows us to consolidate a ton of 
   boilerplate, eliminating 250 lines of code:

 17 files changed, 435 insertions(+), 662 deletions(-)

2) This eliminates the special case for weak and unowned attributes, which previously
   didn't show up in Attr.def.

3) While we're at it, keep track of proper source locations for each attribute, and
   use these to emit diagnostics pointing at the attribute in question instead of at
   a funcdecl or the @ sign.

4) Fix axle attributes, which had vertex and fragment swapped.



Swift SVN r9263
2013-10-13 01:25:50 +00:00
Joe Groff
ab04ce9f34 IRGen: Populate fixed offsets in class metadata when we have them.
In particular, when a nongeneric class inherits a fragile generic class, we need to populate the field offsets for the instantiated base class because we can't rely on the runtime to populate it for us.

Swift SVN r9258
2013-10-12 14:56:47 +00:00
Joe Groff
9ab5414609 IRGen: Load dependent class instance size and alignment from metadata.
When allocating and deallocating dependent generic class instances, load the instance size and alignment from the metadata instead of trying to use a static size from the compile-time class layout.

Swift SVN r9250
2013-10-12 02:57:41 +00:00
Joe Groff
4ff3c62ef6 IRGen: Include instance size and alignment mask in class metadata.
We need these for dependent-layout generic classes so we know the allocation/deallocation size and alignment. When I figure out ObjC interop with generic subclasses these should move to the rodata so they get handled resiliently by the ObjC runtime, but for generic class bringup this is convenient.

Swift SVN r9249
2013-10-12 01:51:18 +00:00
Joe Groff
b724a6ea92 IRGen: Fix an off-by-one in class field access calculation.
The field's layout kind affects its own field access in addition to that of its following fields. This puts dependent fragile field accesses down the right code path. The NonFixedOffsets were inside us all along.

Swift SVN r9221
2013-10-11 21:38:35 +00:00
Joe Groff
b898d1daaa Don't pass a null pointer as the NonFixedOffsets for classes.
So we at least get a better crash when trying to reach generic fields.

Swift SVN r9203
2013-10-11 17:20:17 +00:00
Joe Groff
7c1bc944a1 IRGen: Substitute superclass generic parameters.
If a class inherits a generic class instance, apply substitutions from the superclass to expose better fixed layout opportunities in the derived class's own metadata when the base class instance is fragile and has fixed layout with the added constraints.

Swift SVN r9198
2013-10-11 16:15:29 +00:00
Joe Groff
c2d3da32a5 IRGen: Stub out some dependencies on fixed layout in class metadata codegen.
Some things we'll need to arrange to instantiate at runtime:

- The deallocation size in the deallocating destructor,
- The ivar offset pointers for dependent-layout fields,
- The ivar start offset in the rodata.

For now, just fill in zero as a placeholder until the runtime pieces are in place so the compiler doesn't assert out when emitting generic classes.

Swift SVN r9195
2013-10-11 05:09:56 +00:00
Joe Groff
b6c5da2a9e Conditionalize dynamic class layout on -enable-dynamic-value-type-layout.
The flag name isn't totally accurate, but it's just a developer aid, so who cares

Swift SVN r9194
2013-10-11 05:09:49 +00:00
John McCall
affefbe1e0 Remove the AllocSelfExpr from constructors and teach
alloc_ref how to call +allocWithZone: for classes that might
(i.e. probably do) use ObjC allocation.

Swift SVN r8874
2013-10-03 06:36:34 +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
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
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
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
Dmitri Hrybenko
69cfa73640 More 'this' -> 'self' replacements
Swift SVN r7657
2013-08-28 02:57:21 +00:00
John McCall
38baa056f8 Add a _Tt prefix to mangled class names in class metadata.
rdar://14812566

Swift SVN r7496
2013-08-23 00:31:04 +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
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
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
John McCall
eaa6228124 getFragileTypeInfo -> getTypeInfo
I didn't end up going the same way with fragility that I
thought I would at start, and this method name has become a
legacy.

Swift SVN r7340
2013-08-19 23:01:44 +00:00
Dmitri Hrybenko
de59d8dcd4 Remove unneeded llvm:: qualifier for llvm::StringRef and llvm::SmallVector
Swift SVN r7089
2013-08-09 18:41:46 +00:00
Adrian Prantl
5e98accde4 Debug info: Rename createFunction -> emitFunction for consistency.
Swift SVN r7054
2013-08-08 21:20:07 +00:00
Jordan Rose
674a03b085 Replace "oneof" with "union"...everywhere.
We haven't fully updated references to union cases, and enums still are not
their own thing yet, but "oneof" is gone. Long live "union"!

Swift SVN r6783
2013-07-31 21:33:33 +00:00
Doug Gregor
0842fb5cf8 Rename "base class" to "superclass" and "derived class" to "subclass".
Standardize on the more-common "superclass" and "subclass" terminology
throughout the compiler, rather than the odd mix of base/derived and
super/sub. 

Also, have ClassDecl only store the Type of the superclass. Location
information will be part of the inheritance clause for parsed classes.




Swift SVN r6687
2013-07-29 15:48:34 +00:00
Doug Gregor
532dd646dc Use "witness" rather than "value witness" to mean a non-type witness in the AST/type checker.
The term "value witness" has a very specific meaning in IR generation,
causing unnecessary confusion.


Swift SVN r6650
2013-07-26 18:34:06 +00:00
Doug Gregor
d0f60ab755 Introduce some encapsulation into ProtocolConformance.
Swift SVN r6648
2013-07-26 18:12:17 +00:00
Joe Groff
10f290a01d AST: Add slot for substitutions for generic witnesses.
If a protocol requirement is satisfied by a generic method, we'll need to save the substitutions necessary to call that method from the witness thunk. This patch adds the spot in the ProtocolConformance::Mapping to save the substitutions; for now, always leave it empty and update the code for the type change.

Swift SVN r6399
2013-07-20 00:08:43 +00:00
Joe Groff
e78c0255a6 IRGen: Raise "not implemented" errors for non-fixed-layout ivars.
instead of marching forward off a cliff.

Swift SVN r6356
2013-07-18 22:32:27 +00:00
Adrian Prantl
149ebb0ef3 Debug Info: Associate the remaining artificial functions with their debug scopes.
Swift SVN r5885
2013-06-28 22:27:25 +00:00
Joe Groff
e129ad26d0 Recursively consider ObjC protocol conformances.
Propagate ObjC-ness and emit ObjC thunks and metadata for ObjC protocols indirectly conformed to through protocol refinement.

Swift SVN r5680
2013-06-19 05:35:27 +00:00
Joe Groff
f5101ddb97 Stop trusting the inliner to handle trivial 'size()' method calls.
Swift SVN r5671
2013-06-19 01:14:27 +00:00
Joe Groff
dffab88d47 IRGen: Put other contexts' objc conformances in extension categories.
Include methods from other contexts used to conform to an extension's declared objc protocol conformances in the category generated for that extension.

Swift SVN r5669
2013-06-19 00:56:18 +00:00
Joe Groff
514d659ead IRGen: Emit categories for extensions that conform to ObjC protocols.
Swift SVN r5659
2013-06-18 22:37:55 +00:00
Joe Groff
56a4220eeb IRGen: Use superclass repr and refcount for superclass archetypes.
If an archetype has a superclass bound, we can assume the superclass's
retain semantics for the type. We can also use the superclass's storage pointer type to cut down on some bitcast IR noise when calling superclass methods on the archetype value.

Swift SVN r5642
2013-06-18 03:42:27 +00:00
Joe Groff
4ff8cd27dd IRGen: Abstract out an "unknown refcounted" concept.
In the implementation of class-bounded archetypes and existentials, instead of referring to ObjC pointer types and retain/release operations directly, use an 'UnknownRefCountedPtrTy' and 'emitUnknownRetain/Release' functions.

Swift SVN r5619
2013-06-17 18:31:49 +00:00
Joe Groff
72e53052dc IRGen: Build method/property encodings based on bridged type.
This gives [objc] properties or property-ish methods of String type encodings as their NSString counterparts in the ObjC world.

Swift SVN r5365
2013-05-28 21:05:14 +00:00
Joe Groff
3d2cd72330 IRGen: Push SILTypes into emitClassAllocation.
Swift SVN r5188
2013-05-16 21:52:28 +00:00
Joe Groff
193e7c3b13 IRGen: Kill CanType version of projectPhysicalClassMemberAddress.
ObjC thunking was the last use of it.

Swift SVN r5181
2013-05-16 19:06:52 +00:00