Commit Graph

2062 Commits

Author SHA1 Message Date
Doug Gregor
00162dc243 Start emitting stubs for unimplemented designated initializers of the superclass.
When a subclass does not implement a designated initializer of its
superclass, introduce a stub initializer that simply traps. Such stubs
cannot be invoked directly using Swift syntax, but can be invoked
through the Objective-C runtime and from Objective-C code. Catch such
errors rather than allowing them to violate the memory safety of the
language.

Note that we're currently using cond_fail to trap; this will be
improved in the future,


Swift SVN r14839
2014-03-09 07:16: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
15d2b9402f [serialization] Force derived top-level decls to be serialized.
Previously, serialization of a single source file only includes decls that
are within the SourceFile context. However, new top-level decls can be
added in order to derive protocol conformances; these decls need to be
serialized /somewhere/. Add the concept of decls "forced" to be serialized
along with the decls within the primary SourceFile context, and then mark
all derived top-level decls as "forced" if they come from a decl in the
primary source file.

Possibly a fix for <rdar://problem/16254101>, which crashes nearby.

Swift SVN r14817
2014-03-08 01:54:50 +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
Dmitri Hrybenko
5a2d367fe2 Correct an assertion: sizeof() is in bytes
Swift SVN r14644
2014-03-04 15:12:02 +00:00
Dmitri Hrybenko
8038a03e68 Remove unused code
Swift SVN r14643
2014-03-04 13:11:28 +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
Jordan Rose
b6fa8a00bd [serialization] Rename SILGenericOuterParamDeclID to SILGenericOuterParams.
Also, add the record to the block info for the SIL block, so that it can be
inspected by llvm-bcanalyzer.

Swift SVN r14417
2014-02-26 22:15:56 +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
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
Dmitri Hrybenko
73aa816935 Track upstream change in raw_fd_ostream API
The default (F_None) used to mean F_Text, now it is F_Binary, which is arguably
a better default.  It only matters on Windows anyway, so just use F_None (to
mean binary mode) everywhere to allow Swift to be compled with older LLVM as
well as current ToT.


Swift SVN r14312
2014-02-24 21:00:00 +00:00
Joe Pamer
f83f94d9d8 Support build and target configurations
These changes add support for build and target configurations in the compiler.
Build and target configurations, combined with the use of #if/#else/#endif allow
for conditional compilation within declaration and statement contexts.

Build configurations can be passed into the compiler via the new '-D' flag, or
set within the LangOptions class. Target configurations are implicit, and
currently only "os" and "arch" are supported.

Swift SVN r14305
2014-02-24 18:16:48 +00:00
Doug Gregor
0da11a8b0b Implement semantic analysis for abstract initializers.
Swift SVN r14221
2014-02-21 19:41:14 +00:00
Argyrios Kyrtzidis
eeb9589d2c [AST] Introduce "hasName()" convenience methods and replace "getName().empty()" callers.
Swift SVN r14206
2014-02-21 15:00:38 +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
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
Dmitri Hrybenko
ecd798b9fd Comment parsing: attaching comments to declarations
We can attach comments to declarations.  Right now we only support comments
that precede the declarations (trailing comments will be supported later).

The implementation approach is different from one we have in Clang.  In Swift
the Lexer attaches the comments to the next token, and parser checks if
comments are present on the first token of the declaration.  This is much
cleaner, and faster than Clang's approach (where we perform a binary search on
source locations and do ad-hoc fixups afterwards).

The comment <-> decl correspondence is modeled as "virtual" attributes that can
not be spelled in the source.  These attributes are not serialized at the
moment -- this will be implemented later.


Swift SVN r14031
2014-02-18 09:04:37 +00:00
Chris Lattner
28903887e7 Rename the internal compiler lexicon from let -> val.
Swift SVN r13992
2014-02-17 16:48:21 +00:00
Dmitri Hrybenko
571c9b3c5e Split 'type' keyword into 'static' and 'class'
rdar://15911697


Swift SVN r13908
2014-02-14 14:50:32 +00:00
Doug Gregor
1fa4612eb8 Implement (de-)serialization for open_existential[_ref].
Swift SVN r13898
2014-02-14 05:01:18 +00:00
Chris Lattner
a6640a1b12 Rework has .sil files handle computed vardecls and subscripts.
Previously, we would just parse vars and subscripts with no definitions,
then let getters and setters be referenced arbitrarily later.  This was
problematic for a number of reasons, not least of which, the .sil file
might be invalid.

Instead, change sil to require that a protocol style definition indicate
whether a vardecl/subscript is computed or not, and whether it is both 
get-able and set-able, e.g. like "var x : Int { get }".  Change the 
sil printer to print decls in this form, and change the SILParser to 
make SILDeclRef::Func values instead of ::Getter/Setter values.

One thing that this exposed is that we weren't correctly serializing the
accessor state in modules, so accessors would get detatched from their
AbstractStorageDecls when deserialized (and in fact, their ASD never got
deserialized at all in some cases).  Fix this in the serialization of
the accessors.

NFC, other than the SIL printer and parser.



Swift SVN r13884
2014-02-14 00:57:04 +00:00
Jordan Rose
7995dde448 Module::getImportedModules can now get public, private, or all imports.
...whereas before the only options were "public" and "all".

No functionality change.

Swift SVN r13849
2014-02-12 23:57:43 +00:00
Joe Groff
dd4db41048 Serialization: Don't throw away the conformances of ApplyInst substitutions.
We kinda need those. Limit the hack to pad it out with nulls to only apply in the case when the conformance list is empty but the original archetype requires conformances, which only occurs for archetypes or existentials.

At long last, we can build at -O0 again, again! Reapplying now that Jordan fixed some fallout this had on his objc printer tests. Thanks Jordan!

Swift SVN r13840
2014-02-12 21:10:54 +00:00
Dmitri Hrybenko
05aa4403a0 Revert r13815, it breaks tests
Swift SVN r13827
2014-02-12 15:04:50 +00:00
Joe Groff
c0b39cb57a Serialization: Don't throw away the conformances of ApplyInst substitutions.
We kinda need those. Limit the hack to pad it out with nulls to only apply in the case when the conformance list is empty but the original archetype requires conformances, which only occurs for archetypes or existentials.

At long last, we can build at -O0 again!

Swift SVN r13815
2014-02-12 05:59:26 +00:00
Joe Groff
b19cfb27ea Drop the context generic params from SILFunctionType.
SILFunctionType is now 100% context free!

Swift SVN r13775
2014-02-11 04:21:20 +00:00
Jordan Rose
0de8d19514 Define globals for the names of the stdlib, ObjectiveC, and Foundation modules.
This is mostly useful for the standard library, whose name is going to
change to "Swift" soon. (See <rdar://problem/15972383>.) But it's good DRY.

Swift SVN r13758
2014-02-10 22:40:42 +00:00
Doug Gregor
474016398f Model references to DynamicSelf methods on existentials by opening the existential.
Introduce a new expression kind, OpenExistentialExpr, that "opens" up
an existential value into a value of a fresh archetype type that
represents the dynamic type of the existential. That value can be
referenced (via an OpaqueValueExpr) within the within the
subexpression of OpenExistentialExpr. For example, a call to a
DynamicSelf method on an existential looks something like this:

        (open_existential_expr implicit type='P'
          (opaque_value_expr implicit type='opened P' @ 0x7fd95207c290
          unique)
          (load_expr implicit type='P'
            (declref_expr type='@lvalue P' decl=t.(file).func
          decl.p@t.swift:5:37 specialized=no))
          (erasure_expr implicit type='P'
            (call_expr type='opened P'
              (archetype_member_ref_expr type='() -> opened P'
          decl=t.(file).P.f@t.swift:2:8 [with Self=opened P]
                (opaque_value_expr implicit type='opened P' @
          0x7fd95207c290 unique))
              (tuple_expr type='()')))))

Note that we're using archetype_member_ref_expr rather than
existential_member_ref_expr, because the call is operating on the
opaque_value_expr of archetype type. The outer erasure turns the
archetype value back into an existential value.

The SILGen side of this is somewhat incomplete; we're using
project_existential[_ref] to open the existential, which is almost
correct: it gives us access to the value as an archetype, but IRGen
doesn't know to treat the archetype type as a fresh archetype whose
conformances come from the existential. Additionally, the output of
the opened type is not properly parsable. I'll fix this in follow-on
commits.

Finally, the type checker very narrowly introduces support for
OpenExistentialExpr as it pertains to DynamicSelf. However, this can
generalize to support all accesses into existentials, eliminating the
need for ExistentialMemberRef and ExistentialSubscript in the AST and
protocol_method in SIL, as well as enabling more advanced existential
features should we want them later.



Swift SVN r13740
2014-02-10 06:44:44 +00:00
Joe Groff
481fbb7b91 Drop the non-interface types from SILFunctionType.
There are some straggling references to the context generic param list, but nothing uses the non-interface param or result types anymore!

Swift SVN r13725
2014-02-09 22:39:01 +00:00
Chris Lattner
b581fc916d stop serializing the self decl for ctors and dtors, it is redundant with the
argument pattern that already includes it.


Swift SVN r13707
2014-02-09 17:37:06 +00:00
Chris Lattner
595817bd89 Rename data structures relating to WillSetDidSet properties to call them "Observing"
properties internally to the compiler.  NFC.


Swift SVN r13587
2014-02-06 17:51:45 +00:00
Manman Ren
f455e6db7f SILSerializer: serialize 3 more witness entry types.
method type was handled earlier. This commit handles associated_type,
associated_type_protocol and base_protocol.

rdar://15722175


Swift SVN r13538
2014-02-06 01:43:46 +00:00
Joe Groff
0c0d30d5eb SIL: Make ContextGenericParams a constructor parameter of SILFunction.
Edge SILFunction one step closer to independence from SILFunctionType context by taking the generic param list as a separate constructor parameter, and serializing those params alongside the function record. For now we still pass in the context params from the SILFunctionType in most cases, because the logic for finding the generic params tends to be entangled in type lowering, but this pushes the problem up a step.

Thanks Jordan for helping work out the serialization changes needed.

Compared to r13036, this version of the patch includes the decls_block RecordKind enumerators for the GENERIC_PARAM_LIST layouts in the sil_block RecordKind enumerator, as Jordan had suggested before. r13036 caused buildbot failures when building for iOS, but I am unable to reproduce those failures locally now.

Swift SVN r13485
2014-02-05 16:52:02 +00:00
Jordan Rose
07db002927 [serialization] Force a stable order for dependencies.
Makes things easier to test, even though the order is not significant.

Swift SVN r13453
2014-02-04 23:41:37 +00:00
Jordan Rose
0f7a1e2cc6 Re-apply "[serialization] Preserve dependencies when merging modules."
This re-applies r13401, reverted in r13404. This wasn't actually causing
problems, but got pulled along with r13400 (reverted in r13405).

Swift SVN r13452
2014-02-04 22:46:50 +00:00
Michael Gottesman
a602f130e7 Revert "[serialization] Preserve dependencies when merging modules."
This reverts commit r13401. This broke the build.

Swift SVN r13404
2014-02-04 05:48:50 +00:00
Jordan Rose
fcdf8a4542 [serialization] Preserve dependencies when merging modules.
Swift SVN r13401
2014-02-04 01:32:47 +00:00
Chris Lattner
91e29d16cf use an enum to make serialized modules more stable against changes to the AST.
This isn't really how we'd like to serialize vardecls in the 2.0 timeframe anyway,
but it helps maintain the existing pattern.


Swift SVN r13373
2014-02-03 21:48:09 +00:00
Chris Lattner
74833d0679 properly serialize stored_objc and willset/didset properties in module files.
Swift SVN r13367
2014-02-03 19:55:07 +00:00
Doug Gregor
15c9359f05 Swift2ObjC: Print DynamicSelf as "instancetype".
... and properly register DynamicSelfType for serialization.


Swift SVN r13298
2014-02-01 07:11:28 +00:00
Chris Lattner
3e08673772 Introduce patterns for self arguments to ctors and dtors, making them uniform
with FuncDecls.  This allows us to eliminate special case code for handling
self in various parts of the compiler.

This also improves loc info (debug info and AST info) because 'self' now
has a location instead of being invalid.

I also took the opportunity to factor a bunch of places creating self decls
to use similar patterns and less copy and paste code.



Swift SVN r13196
2014-01-31 02:17:22 +00:00
Jordan Rose
bac31d985a Add '-sil-serialize-all' testing option to the new frontend.
Swift SVN r13190
2014-01-31 01:02:06 +00:00
Jordan Rose
101fd40076 Rip out -emit-module-for-lldb option.
We ended up not using the wrapper around the module data in the Mach-O.

Swift SVN r13185
2014-01-31 00:02:47 +00:00
Doug Gregor
030770a8c2 Make DynamicSelf into its own special type node.
Making DynamicSelf its own special type node makes it easier to opt-in
to the behavior we want rather than opting out of the behavior we
don't want. Some things already work better with this representation,
such as mangling and overriding; others are more broken, such as the
handling of DynamicSelf within generic classes and the lookup of the
DynamicSelf type.


Swift SVN r13141
2014-01-30 05:36:20 +00:00