Commit Graph

2062 Commits

Author SHA1 Message Date
Argyrios Kyrtzidis
eeb9589d2c [AST] Introduce "hasName()" convenience methods and replace "getName().empty()" callers.
Swift SVN r14206
2014-02-21 15:00:38 +00:00
Dmitri Hrybenko
0fe2b682bd Fix spaces in AST printer results for { get set }
Swift SVN r14143
2014-02-20 11:50:32 +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
Chris Lattner
ecbbb4a42c rework our representations of subscripts to not curry the indexes
separately from the get/set value.  There is no exposed way in the
source language to use this, and this causes shorter term annoyance.

I chose to flatten the value and indices so the value comes first.
In principle, this allows us to completely eliminate our ObjC importer
thunks.  I haven't removed them though, because they might be useful
for something else.


Swift SVN r14049
2014-02-18 21:34:33 +00:00
Doug Gregor
9d41af15b6 Make SIL output for open_existential actually parseable.
Swift SVN r13939
2014-02-15 05:52:19 +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
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
Dmitri Hrybenko
5fa3e49b91 AST printer: don't print module qualification on declarations from 'ObjectiveC'
module

rdar://16015774


Swift SVN r13838
2014-02-12 20:53:36 +00:00
Joe Groff
fb2ebf59f7 SIL: Parse and print SILFunction's context generic params.
- Alter parseSILType to take an optional GenericParamList out param to take the parsed GenericParamList, and use this to set the GenericParamList of parsed SILFunctions independent of their lowered type.
- Add a ContextGenericParams field to PrintOptions which, when set, provides a set of archetypes to print in place of the dependent types in an interface type.
- Use this to print the type of SILFunctions using their context generic params.

Swift SVN r13774
2014-02-11 04:03:59 +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
Chris Lattner
827acad533 Various inout improvements:
- purge @inout from comments in the compiler except for places talking about
   the SIL argument convention.
 - change diagnostics to not refer to @inout
 - Change the astprinter to print InoutType without the @, so it doesn't show
   up in diagnostics or in closure argument types in code completion.
 - Implement type parsing support for the new inout syntax (before we just 
   handled patterns).
 - Switch the last couple of uses in the stdlib (in types) to inout.
 - Various testcase updates (more to come).



Swift SVN r13564
2014-02-06 06:22:27 +00:00
Chris Lattner
79cbda7f88 convert a heck of a lot of tests to use the new inout syntax (yay for regex's),
and implement code completion and ast-printer support for the new syntax.



Swift SVN r13562
2014-02-06 05:35:36 +00:00
Chris Lattner
63dc900f91 Pattern processing cleanups, NFC:
Introduce a new Pattern::forEachVariable that takes a lambda and iterates
over all the variables encompassed by the pattern (the ones found by
collectVariables) and runs the lambda on it.

Use this to implement collectVariables, so we only have one copy of the code.

Convert several places to use this, removing a bunch of duplicated code for
walking the pattern structure and extracting decls.

Convert a few uses of collectVariables to forEachVariable, leading to more
clear code without a temporary smallvector.

Remove simplifyPatternTypes in CSApply.cpp, which is dead.



Swift SVN r13545
2014-02-06 01:52:35 +00:00
Argyrios Kyrtzidis
48023490de [AST] Move AccessorKind enum to top-level so it can be forward declared.
No functionality change.

Swift SVN r13299
2014-02-01 08:50:15 +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
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
Chris Lattner
e668e86cc3 With many prerequisites out of the way, lets start actually working on didset/willset
properties.  This step provides AST support to model them.


Swift SVN r13011
2014-01-27 22:11:16 +00:00
Chris Lattner
929ad99f08 Clean up and generalize the code pertaining to how a FuncDecl accessor
knows about the AbstractStorageDecl it works on.  NFC.



Swift SVN r12994
2014-01-27 17:57:38 +00:00
Chris Lattner
f5b85341a1 Expand out the "isComputed" property in AbstractStorageDecl to be an enum
with two kinds, and some more specific predicates that clients can use.

The notion of 'computed or not' isn't specific enough for how properties
are accessed.  We already have problems with ObjC properties that are 
stored but usually accessed through getters and setters, and a bool here
isn't helping matters.

NFC.



Swift SVN r12593
2014-01-20 18:16:30 +00:00
Joe Groff
0776c4b6b8 SIL: Reorient function type lowering toward interface types.
Lower types for SILDeclRefs from the interface types of their referents, dragging the old type along for the ride so we can still offer the context to clients that haven't been weaned off of it. Make SILFunctionType's interface types and generic signature independent arguments of its  Derive the context types of SILFunctionType from the interface types, instead of the other way around. Do a bunch of annoying inseparable work in the AST and IRGen to accommodate the switchover.

Swift SVN r12536
2014-01-18 19:42:02 +00:00
John McCall
1bc1c669a2 Add the '@unchecked T?' syntactic sugar for UncheckedOptional<T>.
Swift SVN r12128
2014-01-10 19:13:51 +00:00
Manman Ren
ce642b89f7 Move printing of DeclAttributes from PrintAST::printAttributes to
DeclAttributes::print.

Also add printing of mutating to the print functions.
In serializer, print out the unhandled attributes.


Swift SVN r12073
2014-01-08 23:44:05 +00:00
Doug Gregor
9412c07dea Switch 'static' to 'type' in tests.
Switch some diagnostic text from 'static' over to 'type' to make
things easier, and fix up some parsing issues with selector-style
declarations found by doing this. NFC


Swift SVN r12030
2014-01-08 01:37:32 +00:00
Joe Groff
25ef450017 SIL: Print SILFunctionTypes using their interface types.
Swift SVN r11852
2014-01-03 06:09:44 +00:00
Joe Groff
8bebb084e6 Rename 'RequirementKind::ValueWitnessMarker' to 'WitnessMarker'.
It's witnessing protocol requirements, not values, and "value witness" has a particular meaning in IRGen.

Swift SVN r11814
2014-01-02 17:47:40 +00:00
Chris Lattner
9ae289de46 Drive the semantic wedge harder into lvalues. Now, instead of having one LValueType
with qualifiers on it, we have two distinct types:
 - LValueType(T) aka @lvalue T, which is used for mutable values on the LHS of an
   assignment in the typechecker.
 - InOutType(T) aka @inout T, which is used for @inout arguments, and the implicit
   @inout self argument of mutable methods on value types.  This type is also used
   at the SIL level for address types.

While I detangled a number of cases that were checking for LValueType (without checking
qualifiers) and only meant @inout or @lvalue, there is more to be done here.  Notably,
getRValueType() still strips @inout, which is totally and unbearably wrong.



Swift SVN r11727
2013-12-29 22:23:11 +00:00
Chris Lattner
60cfcf74e9 - delete a dead function from the AST verifier,
- fix some logic in the type checker that only works on
  implicit lvalues to be explicit about that.
- update some comments



Swift SVN r11707
2013-12-28 23:55:33 +00:00
Chris Lattner
d3c91387e9 Substantially simplify the API to LValueType now that nonsettable is gone.
Swift SVN r11703
2013-12-28 22:48:44 +00:00
Chris Lattner
d7621b5a7b Remove the concept of a "nonsettable lvalue": Now everything that is
nonsettable is represented as an rvalue.  Yay for one less concept in
the AST.


Swift SVN r11640
2013-12-25 22:20:01 +00:00
Joe Groff
63d08c786d SIL: Handle metatype abstraction differences.
Lower metatype types as @thin or @thick based on whether the type is static and whether the abstraction pattern allows for a thin metatype. Add a '@thick' attribute and require SIL metatypes to always be annotated with either '@thin' or '@thick' to distinguish them from unlowered metatypes.

Swift SVN r11525
2013-12-20 23:06:16 +00:00
Jordan Rose
7a30de2efe Disallow inheritance clauses for concrete typealiases.
typealias MyInt: ForwardIndex = Int

There is no real reason to allow this; it's just a static_assert that Int
conforms to ForwardIndex, which would be better spelled some other way.

This only applies to concrete typealiases, i.e. those that simply alias an
underlying type. Associated types can still have both inheritance clauses
and a (default) underlying type.

Swift SVN r11481
2013-12-19 21:13:54 +00:00
Joe Groff
017440165e Fix the weird capitalization of MetaTypeType.
Swift SVN r11475
2013-12-19 18:43:08 +00:00
Joe Groff
2af06d7a14 Allow a '@thin' modifier on metatypes in SIL mode.
Because of abstraction difference, unitary metatype types may still need a non-empty representation in positions where they substitute an archetype metatype. Borrow the '@thin' attribute to make empty metatype types explicit, so that we will be able to handle them correctly with respect to abstraction changes.

Swift SVN r11473
2013-12-19 18:26:10 +00:00
Doug Gregor
ec4913b0ea Implement default definitions for associated types.
Addresses <rdar://problem/14292873>.


Swift SVN r11422
2013-12-18 06:24:53 +00:00
Argyrios Kyrtzidis
ece603b1ed [ASTPrinter] Add an option in swift-ide-test to print a module interface with annotations and test it.
Swift SVN r11368
2013-12-17 02:19:54 +00:00
Dmitri Hrybenko
2c4c7ffcfa AST printer: ensure a stable printing order for ImportDecls
Swift SVN r11366
2013-12-17 01:34:07 +00:00
Dmitri Hrybenko
c54c979f95 Clang importer: don't add @objc *attribute* to imported decls, just set the objc bit
AST printer: print @objc attribute only on top-level imported decls to reduce
the amount of noise.


Swift SVN r11365
2013-12-17 00:50:12 +00:00
Argyrios Kyrtzidis
93c15bed50 [AST] Introduce the ASTPrinter class, and have its callbacks invoked during AST printing.
This provides useful extension points during AST printing.

Swift SVN r11338
2013-12-16 01:26:36 +00:00
Dmitri Hrybenko
bd314574bc Set options for module interface printing in printModuleInterface(),
rather than in swift-ide-test


Swift SVN r11232
2013-12-13 02:25:49 +00:00
Dmitri Hrybenko
374aa1d57c AST printing: when printing module interface, explode PatternBindingDecls
The exact pattern that was used to declare a variable is not important from the
module interface point of view.


Swift SVN r11231
2013-12-13 02:19:04 +00:00
Dmitri Hrybenko
b5b46ca022 Remove stale fixme: Decl::shouldPrintInContext() should not be responsible for
skipping implicit decls, there is an AST priting option for that.


Swift SVN r11228
2013-12-13 01:42:42 +00:00
Dmitri Hrybenko
ee8a9af14d AST printer: add an option to print types qualified if they are possibly ambiguous
Swift SVN r11210
2013-12-12 21:25:05 +00:00
John McCall
0bfa86673f Introduce (but don't yet create) a new kind of DeclContext for
various kinds of expressions that appear outside of local
evaluation contexts.

Swift SVN r11176
2013-12-12 03:36:17 +00:00
Joe Groff
5a08bfae70 Extend SubstitutableType::getName() to handle dependent substitutable types.
And factor the code that produces the canonical '$T_n_n' names into it.

Swift SVN r10986
2013-12-07 23:56:28 +00:00
Dmitri Hrybenko
11ccb38e06 AST printer: use getDisplayDecls() to find a list of decls to print.
We are still not completely correct in determining which extensions to print,
will fix in future patches.


Swift SVN r10960
2013-12-07 00:54:05 +00:00
Argyrios Kyrtzidis
345564380c Rename 'ibaction/iboutlet' attributes to 'IBAction/IBOutlet'.
Swift SVN r10953
2013-12-07 00:14:51 +00:00
Dmitri Hrybenko
8fcb7c428c AST printer: print declarations from a module in alphabetical order
Also, move module interface printing to libAST to make it reuseable.


Swift SVN r10932
2013-12-06 20:23:54 +00:00
Joe Groff
0ff977d407 Add a 'WitnessMethod' enumerator to AbstractCC.
We'll use this to represent the slightly-different polymorphic calling convention used for passing Self into protocol witnesses.

Swift SVN r10898
2013-12-06 01:32:35 +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