Commit Graph

178 Commits

Author SHA1 Message Date
Dmitri Hrybenko
4315fdbbf8 @availability: implement serialization and AST printing
Swift SVN r16010
2014-04-07 14:07:28 +00:00
Dmitri Hrybenko
fb2a6499cd Move @class_protocol to use the new attribute infrastructure
... and fix a few other bugs:

* always set the inherited protocols on the ProtocolDecl in the type checker,
  so that we can remove a hack in ProtocolDecl::requiresClassSlow();

* diagnose DeclAttributes that are inverted when this is not allowed.


Swift SVN r15992
2014-04-06 01:24:08 +00:00
Dmitri Hrybenko
f661691962 Don't serialize @final twice and add tests for printing @final
Swift SVN r15962
2014-04-04 23:20:55 +00:00
Dmitri Hrybenko
f198c28d75 Serialize @required as a DeclAttribute
Also introduce an invalid bit on a DeclAttribute for use by semantic analysis.

This fixes AST printing for @required.


Swift SVN r15938
2014-04-04 15:24:47 +00:00
Dmitri Hrybenko
7a63906b15 Serialize @objc as a DeclAttribute
This allows us to consistently print the AST, no matter if it was just parsed
or deserialized.

Note that we still serialize the isObjC bit from Decl, because it can be set or
cleared by the typechecker.  It is possible to have isObjC=true when there is
not attribute (the ObjC'ness was inferred), and it is possible that
isObjC=false while there is an attribute (when the attribute does not pass the
semantic check).  While we can represent the former with an implicit attribute,
the latter is harder to represent (maybe with an invalid bit on the attribute?)


Swift SVN r15935
2014-04-04 12:42:52 +00:00
Ted Kremenek
ad2afaeb34 Start serializing out DeclAttribute objects using generalized serialization logic.
To generalize our serialization logic for more attributes, serialize
each DeclAttribute object in a separate bitcode record.

For simple declaration attributes (no arguments), all of this
serialization logic can be fully automatically generated, and is
done so in this patch.  This currently includes @final, but will
expand over time.

To illustrate the plumbing end-to-end, move the serialization logic
for asmnmame over to the new mechanism.

Swift SVN r15933
2014-04-04 08:52:32 +00:00
Jordan Rose
646952defd [serialization] Write substitution conformances as references when possible.
More importantly, when writing substitution conformances /within the same
module/, use an "incomplete" form of the NormalProtocolConformance layout
that doesn't include any of the substitutions or defaulted definitions.
This avoids a serialization cycle when the witness for a protocol itself
ends up conforming to the protocol.

I couldn't come up with a reduced test cases, but both cases filed by Dave
now work.

<rdar://problem/16468715>

Swift SVN r15912
2014-04-04 01:17:55 +00:00
Jordan Rose
aa6aa72ba1 Add lazy conformances to nominals and extensions.
...and deserialize conformances lazily.

No intended user-visible change.

Swift SVN r15911
2014-04-04 01:17:54 +00:00
Doug Gregor
d07d0b8366 More fixes for FinalAttr.
Swift SVN r15902
2014-04-03 22:57:16 +00:00
Chris Lattner
3528e70aa9 change -ast-dump to print the final attribute, change the serialization
support to serialize and deserialize it (also bump the version #),
@final is still a WIP.



Swift SVN r15898
2014-04-03 22:45:36 +00:00
Doug Gregor
527b147ba7 Revert "Allow the first name of a selector-style function declaration to be separated."
This reverts r15140.

Conflicts:
	include/swift/Serialization/ModuleFormat.h
	lib/Parse/ParsePattern.cpp

Swift SVN r15846
2014-04-02 23:27:52 +00:00
Doug Gregor
9189145cc5 Change DeclName over to basename(arg1:arg2:...argN:).
Swift will use the basename + argument names formulation for
names. Update the DeclName interfaces, printing, and __FUNCTION__ to
use the method syntax.

We'll still need to rework the "x.foo:bar:wibble:" syntax; that will
come (significantly) later.

Swift SVN r15763
2014-04-02 00:00:03 +00:00
John McCall
f1180f5e6d in order to work correctly for non-@objc protocols.
Language features like erasing concrete metatype
values are also left for the future.  Still, baby steps.

The singleton ordinary metatype for existential types
is still potentially useful; we allow it to be written
as P.Protocol.

I've been somewhat cavalier in making code accept
AnyMetatypeType instead of a more specific type, and
it's likely that a number of these places can and
should be more restrictive.
When T is an existential type, parse T.Type as an
ExistentialMetatypeType instead of a MetatypeType.

An existential metatype is the formal type
 \exists t:P . (t.Type)
whereas the ordinary metatype is the formal type
 (\exists t:P . t).Type
which is singleton.  Our inability to express that
difference was leading to an ever-increasing cascade
of hacks where information is shadily passed behind
the scenes in order to make various operations with
static members of protocols work correctly.

This patch takes the first step towards fixing that
by splitting out existential metatypes and giving
them a pointer representation.  Eventually, we will
need them to be able to carry protocol witness tables

Swift SVN r15716
2014-04-01 00:38:28 +00:00
Joe Groff
9f7dab725c Make the ASTContext parameter to MetatypeType::get optional for type-checked types.
We can just get it from the instance type, if the instance type has been fully initialized, which is the case except during parsing of type decls when the decls' own types are being formed.

Swift SVN r15598
2014-03-29 02:50:30 +00:00
Ted Kremenek
07a4449621 Remove vestigial comma-separated attribute list for declarations.
For example:

  @class_protocol, @objc

is now just:

  @class_protocol @objc

Once we removed attribute grouping in brackets this comma separation
became vestigial.  Doug and I discussed this and thought this
was a good simplification in the grammar.

This change still remains to be done for type attributes.

Swift SVN r15540
2014-03-27 00:11:40 +00:00
Doug Gregor
51672965f4 Remove the unused @fragile, @resilient, and @born_fragile attributes.
Swift SVN r15518
2014-03-26 19:47:08 +00:00
Ted Kremenek
f43842e160 Change processing of @asmname to use a new internal representation.
This representation is inspired by Clang's internal representation.
The current attribute representation, which is basically a union
of "stuff" in DeclAttributes, is not amendable to richer
attributes, such as @availability, that need to be implemented.
In Clang, attributes are modeled with actual objects that
encode both semantic and syntactic information (e.g., source ranges)
that facilitate richer checking, better diagnostics, and better tools.

This change is foundational for implementing @availability, but
also is a better long-term representation.  As a migratory path,
it creates some duplications, with AttrKind and DeclAttrKind, the
two which should eventually become the same thing.

As part of this patch, there is some additional parser recovery
(for the new attribute representation) for duplicate attributes.
The parser now parses the entire duplicate attribute, which could
be quite complex, and then issues a diagnostic that the attribute
is a duplicate (and discarding it).  This delayed diagnostic
also allows us to present ranges for the duplicate attribute, which
provides a better user experience.

Swift SVN r15365
2014-03-22 14:58:30 +00:00
Michael Gottesman
2235221854 [deserialization] Unique normal protocol conformances in ASTContext like we do for specialized/inherited protocol conformances.
This fixes the following two bugs:

1. We sometimes would create new conformances when deserializing a
witness method which would not be mapped in the SILModule to the
appropriate witness table. This would cause us to be unable to perform
devirtualization of this witness method. This is tested via a new
verifier check.

2. Different conformances would be created for an instance of a base
protocol and the original protocol. This would cause IRGen to try to
emit witness table global variables with differing types, hitting an
assertion. This is tested via a traditional test.

Swift SVN r15362
2014-03-22 05:05:48 +00:00
Chris Lattner
1f275532a6 now that nothing uses the PatternBindingDecl::HasStorage bit, there is no
reason to compute it, store it, serialize it, etc.  Remove the associated
logic.



Swift SVN r15302
2014-03-20 22:49:43 +00:00
Doug Gregor
5e8e7279f8 Allow the first name of a selector-style function declaration to be separated.
Parse function declarations with the form

  func murder inRoom(room: Int) weapon(Int) {}

where the function name ("murder") is separated from the parameter
names. This is the same style used in initializers, i.e.,

  init withCString(cstr: CString) encoding(Encoding)



Swift SVN r15140
2014-03-17 16:04:21 +00:00
Jordan Rose
6522228a7c [serialization] Properly cross-reference accessors, which don't have names.
Instead of referencing them by name, serialize a reference to their
storage decl instead, then note which accessor to retrieve.

Uncovered by Chris's override work in r15051...thanks, Chris!

Swift SVN r15063
2014-03-14 18:58:50 +00:00
Doug Gregor
d32f668fb2 Introduce "inherited" default arguments and use them for inherited initializers.
Previously, we were cloning the default arguments completely, which
meant code duplication (when inheriting within a module) or simply a
failure (when inheriting across modules). Now, we reference the
default arguments where we inherited them, eliminating the
duplication. Part of <rdar://problem/16318855>.

Swift SVN r15062
2014-03-14 18:31:22 +00:00
Doug Gregor
ea7e70bbf7 Automatically inherit subobject initializers when none are explicitly defined.
If a subclass defines no subobject initializers and all of its stored
properties have initial values, "inherit" all of the subobject
initializers of its superclass by creating a new initializer with the
same signature that overrides (and chains to) the corresponding
subobject initializer of its parent. Do this instead of blindly
creating a default initializer.

Note that we aren't yet doing this for generic initializers. That will
be a separate step.

Swift SVN r14995
2014-03-13 18:43:30 +00:00
Joe Groff
9f12e2e4a4 Enable same-type concrete constraints, e.g. <T: P where T.Assoc == Int>
Let ArchetypeType nested types and PotentialArchetypes be bound to concrete types in addition to archetypes. Constraints to outer context archetypes still suffer type-checker issues, but constraints to true concrete types should work now.

Swift SVN r14832
2014-03-08 17:18:17 +00:00
Jordan Rose
9c8637622b [serialization] Set a FuncDecl's associated operator a little more eagerly.
This is used when deciding if the FuncDecl is a valid target for an XREF,
so we want to do this as soon as possible.

Swift SVN r14816
2014-03-08 01:54:49 +00:00
Jordan Rose
44134c4295 [serialization] Provide an XREF member path trace sooner.
Before, we would hit one of the error conditions before updating the path
trace, which was misleading at best.

No functionality change.

Swift SVN r14815
2014-03-08 01:54:44 +00:00
Jordan Rose
b9d1e14dd6 [serialization] Break a cyclic dependency involving associated types.
The standard library likes to have default definitions for associated types,
which is good. Often the /choice/ of default type, however, is a type that
(indirectly) conforms to the very protocol containing the associated type.
Rather than try to make sure everything is present all at once, just delay
the deserialization of the default definition until it's actually requested.

This does swell the size of AssociatedTypeDecl by two words. I've filed
<rdar://problem/16266669> to remind myself to try to reduce this.

Part of <rdar://problem/16257259>

Swift SVN r14809
2014-03-08 00:07:29 +00:00
Jordan Rose
dece63903f [serialization] Beef up PrettyStackTraces with more info.
No functionality change.

Swift SVN r14808
2014-03-08 00:07:27 +00:00
Joe Groff
9e5bc637ae Add __FUNCTION__ as a magic literal identifier.
Add __FUNCTION__ to the repertoire of magic source-location-identifying tokens. Inside a function, it gives the function name; inside a property accessor, it gives the property name; inside special members like 'init', 'subscript', and 'deinit', it gives the keyword name, and at top level, it gives the module name. As a bit of future-proofing, stringify the full DeclName, even though we only ever give declarations simple names currently.

Swift SVN r14710
2014-03-06 01:06:06 +00:00
John McCall
a8ed3dae12 Deserialize generic contexts by mapping their archetypes
to the archetypes of their generic parameter declarations.

This was a major inconsistency that was causing a lot of
problems with deserialized generic functions in the presence
of chained module files.  In particular, what would happen is
that all the deserialized uses of the archetype would be
mapped to a freshly-created archetype, but the GenericParamList
would refer to GenericTypeParamDecls deserialized from
(potentially) a different ModuleFile and therefore using a
different archetype (since the deserializer assumes that
different modules never share archetypes).

The fix relies on processing a generic parameter list before
any references to the archetypes.  Unfortunately, we have
bogus references to archetypes in substitution lists scattered
everywhere in SIL and the AST.  I've introduced a really
gross hack where we allow archetypes to be created in that
way but just drop them (in favor of the parameter's archetype)
after processing the generic parameter list; this should
work as long as all the decontextualized references are
basically pointless, but like I said, it's gross, and I've
filed rdar://16240384 to clean it up.

Swift SVN r14694
2014-03-05 22:41:28 +00:00
Jordan Rose
34cfaddedd [serialization] Be more careful about deserializing the same Decl twice.
If we got just the wrong chain of dependencies, we'd create two VarDecls
for the same variable. I'm not sure if any of the other decls have the
same problem, but better safe than sorry.

I couldn't think of a small test case for this, but it does fix the one
in the Radar.

<rdar://problem/16205936>

Swift SVN r14625
2014-03-04 01:09:12 +00:00
Doug Gregor
15be2159a2 Rename "abstract initializers" to "required initializers".
It's better than what we have.

Swift SVN r14620
2014-03-03 23:12:40 +00:00
Joe Groff
179b101e6f Serialization: Serialize compound names of FuncDecls.
Store the name components as a BCArray, and push the asmname BCBlob into an optional trailing record layout.

Swift SVN r14556
2014-03-01 04:10:33 +00:00
Doug Gregor
571ae697d5 Parsing and AST support for complete object initializers.
Enforce that complete object initializers always be delegating.

Swift SVN r14549
2014-03-01 00:51:18 +00:00
Dmitri Hrybenko
cf82449090 Rename @IBLiveView to IBDesignable per request in rdar://16135911
Swift SVN r14462
2014-02-27 15:26:54 +00:00
Chris Lattner
1344319677 Rename the internal compiler lexicon from val -> let.
Swift SVN r14408
2014-02-26 21:21:18 +00:00
Doug Gregor
230c8a4982 Introduce the 'override' attribute and start requiring it on all overrides.
The 'override' attribute indicates that the given declaration, which
may be a method, property, or subscript, overrides a declaration in
its superclass. Per today's discussion, the 'override' attribute must
be present if and only if the corresponding declaration overrides a
declaration in its superclass. 

This implements most of <rdar://problem/14798539>. There's still more
work to do to on property and subscript overrides.



Swift SVN r14388
2014-02-26 08:53:06 +00:00
Doug Gregor
981f8f6509 Rename "destructor" -> "deinit" (as a keyword) and -> "deinitializer" (in diagnostics).
Swift SVN r14380
2014-02-26 05:51:45 +00:00
Michael Gottesman
79df4dd8b4 Remove trailing whitespace and unneeded -*- c++ -*- from .cpp files.
Swift SVN r14350
2014-02-25 19:17:05 +00:00
Chris Lattner
7f4c0b981c rename the StoredObjC storage class to StoredWithTrivialAccessors since
we'll be using it for more general things soon.  NFC.


Swift SVN r14329
2014-02-25 01:08:27 +00:00
Doug Gregor
0da11a8b0b Implement semantic analysis for abstract initializers.
Swift SVN r14221
2014-02-21 19:41:14 +00:00
Michael Gottesman
9311672c33 Move ModuleFile.h, ModuleFormat.h, and DeclTypeRecordNodes.def to include/swift/Serialization.
This allows for a secondary tool to access the deserialized Module inside the SerializedASTFile's ModuleFile.

Swift SVN r14173
2014-02-20 22:03:55 +00:00
Joe Groff
7fd26d22d5 Serialization: Fix a couple of issues with serializing context params of generic SILFunctions.
- Parameterize maybeReadGenericParams' BitstreamCursor so that we can read from
  the correct cursor when trying to read the generic params of a SILFunction.
- Only serialize the context generic params for SILFunctions for which we're
  serializing a complete definition. This fixes issues with us getting the
  wrong archetypes forward-declared from references in other modules.

In this version of the patch, we adjust the deserialization point for the
generic param list to correctly come before we check if the SILFunction block
is empty, and we add a kludge to keep the JIT from crapping itself when it sees
the same transparent definition in multiple REPL lines' modules
<rdar://problem/16094902>.

The previous commit solves a problem this exposed at r14050 in inout deshadowing
that caused memory corruption when transparent functions were imported. This
should now be safe to commit.

Swift SVN r14109
2014-02-19 22:47:25 +00:00
Doug Gregor
a1673d7c8f Add an Objective-C metatype representation spelled with @objc_metatype.
This representation is just a placeholder at the moment.


Swift SVN r14076
2014-02-19 07:21:38 +00:00
Doug Gregor
c54f98fbc9 Convert thick/thin metatype bool to an enumeration. NFC
Swift SVN r14075
2014-02-19 06:05:48 +00:00
Greg Parker
675952c719 Revert r14030 which appears to segfault performance test hash2.swift.
Swift SVN r14038
2014-02-18 13:18:17 +00:00
Joe Groff
61f7a7c482 Serialization: Fix a couple of issues with serializing context params of generic SILFunctions.
- Parameterize maybeReadGenericParams' BitstreamCursor so that we can read from the correct cursor when trying to read the generic params of a SILFunction.
- Only serialize the context generic params for SILFunctions for which we're serializing a complete definition. This fixes issues with us getting the wrong archetypes forward-declared from references in other modules.

In this version of the patch, we adjust the deserialization point for the generic param list to correctly come before we check if the SILFunction block is empty, and we add a kludge to keep the JIT from crapping itself when it sees the same transparent definition in multiple REPL lines' modules <rdar://problem/16094902>.

Swift SVN r14030
2014-02-18 07:30:11 +00:00
Joe Groff
21429cbfae Revert "Serialization: Fix a couple of issues with serializing context params of generic SILFunctions."
This reverts commit 57ec1ee1e888b7ed61b731237218cd9529143d2d. It fixes r13984
but breaks ToT.

Swift SVN r14006
2014-02-17 20:32:04 +00:00
Joe Groff
67fd13ed66 Serialization: Fix a couple of issues with serializing context params of generic SILFunctions.
- Parameterize maybeReadGenericParams' BitstreamCursor so that we can read from the correct cursor when trying to read the generic params of a SILFunction.
- Only serialize the context generic params for SILFunctions for which we're serializing a complete definition. This fixes issues with us getting the wrong archetypes forward-declared from references in other modules.

This gets me a clean build when applied against r13984.

Swift SVN r14005
2014-02-17 20:05:46 +00:00
Chris Lattner
28903887e7 Rename the internal compiler lexicon from let -> val.
Swift SVN r13992
2014-02-17 16:48:21 +00:00