Commit Graph

254 Commits

Author SHA1 Message Date
Doug Gregor
1bd583cdf8 [Module file] (De-)serialize inherited protocol conformances.
Swift SVN r6886
2013-08-05 14:29:16 +00:00
Doug Gregor
666213348d [Protocol conformance] Refactor protocol conformance representation.
Factor the ProtocolConformance class into a small hierarchy of
protocol conformances: 
  - "normal" conformance, which provides a complete mapping for the
  explicit conformance of a nominal type (which may be generic) to a
  protocol;
  -  "specialized" conformance, which specializes a generic
  conformance by applying a set of substitutions; and
  - "inherited" conformance, which projects the conformance from a
  superclass to a conformance for a subclass.

In this scheme "normal" conformances are fairly heavyweight, because
they provide a complete mapping. Normal conformances are unique,
because they're associated with explicit conformance declarations
(which cannot be repeated within a module; checking is TBD). Thus, IR
generation will eventually emit them as strong symbols.

"Specialized" and "inherited" conformances occur when we're dealing
with generic specializations or subclasses. They project most of their
members through to some underlying conformance, eventually landing at
a "normal" conformance. ASTContext is responsible for uniquing these
conformances when it sees them. The IR generation model for
specialized conformances will involve runtime specialization of the
underlying witness table; inherited conformances are probably no-ops
from the IR generation perspective.

Aside from being the right thing to do, having small, uniqued
conformances for the specialization and inheritance cases is good for
compile-time performance and memory usage. We're not really taking
advantage of this everywhere we could, yet.

This change uncovered a few existing issues (one known, one not
known), particularly because we're projecting inherited conformances
rather than building new conformances:
  - <rdar://problem/14620454>: protocol witnesses to methods of
  classes need to perform dynamic dispatch. See the
  test/Interpreter/typeof.swift test for an example.
  - <rdar://problem/14637688>: comparing NSString and String with ==
  fails, because they are inter-convertible. I suspect we were missing
  some protocol conformances previously, and therefore accepting this
  obviously-invalid code.



Swift SVN r6865
2013-08-02 22:59:54 +00:00
Jordan Rose
9d5c803aff Enable specific-decl imports.
Note that the import kind is not checked yet; this is effectively our old
behavior for "import swift.print".

Infrastructure: move Module::forAllVisibleModules out-of-line, and add
makeStackLambda to STLExtras for using a non-escaping lambda with
std::function.

Swift SVN r6852
2013-08-02 21:00:41 +00:00
Jordan Rose
f03245a206 Fix up a bunch of filtering-by-decl-access-path.
Mostly cleanup, a few filled-in FIXMEs to filter out decls that don't match
the access path name.

Swift SVN r6850
2013-08-02 21:00:28 +00:00
Joe Groff
f4eed420b3 Store the Module of a ProtocolConformance rather than the decl.
This is all we need for linkage and is easier to reliably recover during deserialization.

Swift SVN r6803
2013-08-01 04:10:52 +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
Jordan Rose
62535fb95c [serialization] Serialize ObjC bit, [iboutlet], [ibaction], [class_protocol].
This should include all of the attributes we care about for the time being.
Only the resilience attributes (not designed) and [force_inline] are left
unaccounted for.

Swift SVN r6767
2013-07-30 23:17:12 +00:00
Doug Gregor
ceaa5e00bf Suggest explicit protocol conformance via Fix-Its.
When we notice that a type implicitly conforms to a protocol but is
not explicitly stated to do so, note this and provide a Fix-It
attaching the conformance to a declaration within the translation
unit, e.g.,

t.swift:28:16: error: type 'S1' does not explicitly conform to protocol 'P'
var p1 : P = S1()
               ^
t.swift:8:8: note: introduce explicit conformance to protocol 'P'
struct S1 : Q {
       ^
             , P



Swift SVN r6760
2013-07-30 22:45:10 +00:00
Jordan Rose
3e7eef56e7 Kill [stdlib] attribute.
Now that we have true serialized modules, the standard library can import
the Builtin module without any special direction (beyond -parse-stdlib),
and anyone can include those modules without special direction.

Swift SVN r6752
2013-07-30 21:27:42 +00:00
Jordan Rose
d6c135291e [serialization] Be defensive in preserving the deserialization cursor's offset.
Add BCOffsetRAII to getDecl() and getType() so that these functions
preserve the current cursor position. This spends an extra save and
restore to avoid accidentally shooting ourselves in the foot by losing
our position (see r6516).

No functionality change.

Swift SVN r6750
2013-07-30 21:10:05 +00:00
Joe Groff
70dbbc806b Store type, protocol, and conforming decl in ProtocolConformances.
This makes ProtocolConformances fully self-identifying so that a ProtocolConformance* pointer alone is enough to identify a conformance as a link entity.

We currently lose the conforming decl during deserialization because trying to deserialize a reference to an ExtensionDecl asserts out. I'll bug Jordan about that.

Swift SVN r6735
2013-07-30 01:26:26 +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
cfe9e0ad37 [Module format] Don't serialize 'inherited' types of any declaration.
The 'inherited' type list of a declaration represents the parsed for
of the inheritance clause, which is now not serialized. The semantic
informance exists in the superclass (when present) and list of
protocols. Future refactoring of the 'inherited' list will make this
more clear.


Swift SVN r6686
2013-07-29 15:23:44 +00:00
Doug Gregor
3d0c2e2612 Record the protocols and superclass for generic parameters.
This allows us to use getProtocols() rather than getInherited()
wherever we're dealing with generic parameters and associated types.


Swift SVN r6683
2013-07-29 14:27:25 +00:00
Doug Gregor
1759210067 (De-)Serialize the protocols from which a protocol inherits.
Switch a few more clients from ::getInherited() to
::getProtocols(). The trajectory here is that ::getInherited() will
turn into something only populated when we've parsed the inheritance
clause, and that "the truth" will be getProtocols(). The former will
cease being serialized once this is the case.


Swift SVN r6661
2013-07-26 23:57:52 +00:00
Doug Gregor
709882c2b8 Capture complete associated type substitution information in the AST.
Previously, we only tracked the mapping from associated types to their
type witnesses. Now, also track the protocol conformances for each of
the requirements placed on the associated types.


Swift SVN r6655
2013-07-26 22:04:53 +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
Jordan Rose
d11585f810 [serialization] Include generic protocol witness substitutions.
This finishes up Joe's changes in r6397.

Swift SVN r6558
2013-07-24 21:15:42 +00:00
Jordan Rose
cf2f43b710 [serialization] Use canonical conformance records for substitutions...
...instead of keeping around extra deserialized copies.

Also, fix memory management for inherited conformances already in the
ASTContext, instead of just leaking them.

In the long run, conformances under substitutions should be encoded with
some kind of CONFORMANCE_REF, because it is known that these conformances
will already exist.

Swift SVN r6557
2013-07-24 21:15:33 +00:00
Jordan Rose
8e081367ca Basic implementation of lookupVisibleDecls() for serialized modules.
This involved threading it through ModuleLoader, as with all the other
module-generic callbacks. I plan to collapse a bit of the chaining, but
unfortunately not that much.

This brings back the CodeCompletion tests.

Swift SVN r6527
2013-07-23 23:10:28 +00:00
Jordan Rose
0d3e410fc4 [serialization] Look past one typealias when looking for a nominal decl.
This is a hack to handle "typedef struct CGRect CGRect", but obviously
it isn’t going to work in the general case. Filed <rdar://problem/14526923>
to undo this later.

Swift SVN r6526
2013-07-23 23:10:26 +00:00
Jordan Rose
837a845087 [serialization] Properly record protocol conformances in the ASTContext.
This involves correctly uniquing them, using existing archetypes
(rather than deserializing new ones), and recording them in the
ASTContext's conformance maps, which are used by the type-checker.

Swift SVN r6525
2013-07-23 23:10:23 +00:00
Jordan Rose
3087e8d5ea Add the notion of "re-exported" modules, and use that where it makes sense.
Rather than automatically re-exporting or not re-exporting every import in
a TranslationUnit, we'll eventually want to control which imports are local
(most of them) and which imports are shared with eventual module loaders.
It's probably not worth implementing this for TranslationUnit, but
LoadedModule can certainly do something here.

Currently, a LoadedModule is even more permissive than a TranslationUnit:
all imports are re-exported. We can lock down on this once we have a
re-export syntax.

Swift SVN r6523
2013-07-23 23:10:17 +00:00
Jordan Rose
110d644297 Provide a skeleton for re-exports from serialized modules...
...and use it for shadowed modules (e.g. the Clang module "Foundation"
referenced by the Swift module "Foundation"), so that we can actually
find "NSString" when building AppKit.

Additionally, record shadowed modules as dependencies, so that they can
be loaded when the adapter module is loaded.

Swift SVN r6522
2013-07-23 23:10:13 +00:00
Jordan Rose
3e606010ee [serialization] Silence an unused variable warning in Release builds.
Swift SVN r6520
2013-07-23 23:10:08 +00:00
Jordan Rose
6547b9790a [serialization] Allow references to Clang-imported values.
This unfortunately duplicates the hack of directly referencing the Clang
module loader if a cross-reference points to the current module; ideally
we'd have some kind of module chain, but I'd settle for a refactoring of
the code to share with NameBinding.

Additionally, Clang nodes are not actually validated to be from the right
module, which could be problematic for extensions or any case of actual
name collision.

Swift SVN r6519
2013-07-23 23:10:05 +00:00
Jordan Rose
36138474d1 [serialization] Fix another cursor-clobbering mistake.
When reading trailing records, make sure we don't go off and read something
else in the mean time...

Swift SVN r6518
2013-07-23 23:10:02 +00:00
Jordan Rose
b619a125a1 [serialization] Make sure accessors are correctly associated with a subscript.
Trivial fix. Undetected for a long time because most accesses go from
subscript to accessors, rather than the other way around.

Swift SVN r6517
2013-07-23 23:10:00 +00:00
Jordan Rose
be6c5b3707 [serialization] Preserve the implicit bit for patterns.
This is used by code completion to determine if curried
arguments are implicit, e.g. for method calls.

Swift SVN r6516
2013-07-23 23:09:56 +00:00
Jordan Rose
5689d1a4a4 [serialization] Set the type of the FuncExpr in a FuncDecl.
Swift SVN r6515
2013-07-23 23:09:53 +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
Anna Zaks
74bc6f05b2 Add "noreturn" attribute : stage 1
- Add the attribute to AnyFunctionType::ExtInfo.
- Propagate the attributes from DeclAttributes to AnyFunctionType for
  FuncDecls in TypeCheckDecl.cpp.
- Make sure the new attribute is serialized.

The main missing pieces are checking the applicability of the type attributes
on the FuncDecl and teaching typechecker about conversions on types with
noreturn.

Swift SVN r6359
2013-07-18 22:57:22 +00:00
Anna Zaks
92e07c6a54 Use ExtInfo struct to pass around call related info in FunctionType and PolymorphicFunctionType getters.
Swift SVN r6358
2013-07-18 22:57:21 +00:00
Doug Gregor
ad1a9ac2c3 Eliminate default argument expressions from the type system.
Elements of a tuple type now know if there is a default argument, and
what kind of default argument it is (callee side, __FILE__, __LINE__,
__COLUMN__), but they don't have an actual expression. There are a
number of cleanups this enables that will follow. 

Note that the serialization support is as-yet-untested.


Swift SVN r6351
2013-07-18 18:49:32 +00:00
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
Jordan Rose
c01b7fb2fd [serialization] Fix another scary use of stack memory.
...instead of ASTContext-allocated memory.

Swift SVN r6243
2013-07-13 19:37:05 +00:00
Jordan Rose
1712ee6661 [serialization] Handle overloaded decls.
Swift SVN r6230
2013-07-13 00:03:14 +00:00
Jordan Rose
9a180ea9c6 [serialization] Relax assertions to allow reentrant deserialization.
As long as we don't create an entity twice, it's actually okay to be
re-entrant. This makes it simpler to deserialize members -- trying to
do so will deserialize the parent instead, which will then initialize
each of the members including the one that was asked for.

Swift SVN r6228
2013-07-12 23:29:57 +00:00
Jordan Rose
4db68ed617 [serialization] Record nominal types in the module table ASAP.
Deserializing a nominal decl often ends up referring to the nominal's type,
so if we're /already/ serializing the type, we should finish that as soon
as we have a decl. Accomplish this by adding a callback that is called
right after a nominal decl is recorded in the module's decl table, so that
the type can be immediately recorded as well.

Swift SVN r6227
2013-07-12 23:29:45 +00:00
Argyrios Kyrtzidis
b7817e4879 Remove VarargBaseTy field from TupleTypeElt.
Use a bit to indicate whether the element is a vararg one and infer the
VarargBase type via the element type.

Swift SVN r6220
2013-07-12 22:24:31 +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