Commit Graph

594 Commits

Author SHA1 Message Date
Doug Gregor
55ca3b01f3 Parse dictionary type sugar [K : V].
Handle parsing of dictionary type sugar into its own type
representation, including both type and expression contexts.

This is the first part of <rdar://problem/17460972>; we still need a
sugared Type node.


Swift SVN r19239
2014-06-26 16:57:42 +00:00
Doug Gregor
5783d0b313 Revert r19185: Add T* syntactic sugar type for UnsafePointer<T>.
Swift SVN r18255
2014-05-17 16:43:46 +00:00
Doug Gregor
806daf3a87 Add T* syntactic sugar type for UnsafePointer<T>.
This is the basic plumbing for <rdar://problem/16912508>.


Swift SVN r18195
2014-05-16 15:30:26 +00:00
Chris Lattner
a698fda0b3 teach the AST walker to walk into the capture list of closure exprs, teach the
type checker to type check them, tweak the ast dumper to dump out something nicer.



Swift SVN r17790
2014-05-09 18:36:35 +00:00
Joe Pamer
d22ffa8cb8 Re-lazify the addition of equatable conformances to imported enum types. (rdar://problem/16808612)
Rather than force conformances to Equatable to be added to all imported enumeration types outright, change them back to being lazily added. We can then handle situations where new overloads of '==' are introduced during constraint generation by re-writing the relevant overload disjunction constraint to include the newly forced declarations as bind options.

Swift SVN r17557
2014-05-06 19:56:29 +00:00
Ted Kremenek
050fd53af7 Rename UncheckedOptional to ImplicitlyUnwrappedOptional.
Swift SVN r17232
2014-05-02 06:13:57 +00:00
Ted Kremenek
6caf910d32 Implement new syntactic sugar for UncheckedOptional<T>.
This leaves in the existing syntax for @unchecked T?.  That will
be addressed in later patches.

There's still a mysterious case where some of the SIL output
includes UncheckedOptional<T> and some places T!.

Moreover, this doesn't handle SourceKit's behavior for printing
for overrides.  This just handles parsing the 'T!' syntax.

Swift SVN r16945
2014-04-27 21:59:29 +00:00
Chris Lattner
78e8d3f0a9 rename the MetatypeExpr AST node to DynamicTypeExpr now that it is only
used by the "foo.dynamicType" syntax.


Swift SVN r16658
2014-04-22 20:10:11 +00:00
Chris Lattner
7de9c0802a Peel off almost all of the uses of MetaTypeExpr, replacing
them with uses of TypeExpr instead.  The remaining uses of 
MetaTypeExpr (which will be renamed soon) are places where we
are applying the ".dynamicType" virtual property to an expression.

Unadorned uses of types in code, e.g. the Int in "Int.self" are
now represented with TypeExpr.

One unfortunate travesty that doing this work revealed is that we
are extremely sloppy and terrible about maintaining location information
in implicitly generated decls, and our invariants vary quite a bit.  This
is really horrible, but I'm not sure whether I'll go fix the hacks or not.

This patch perpetuates the existing crimes, but makes them more visible.

NFC!




Swift SVN r16646
2014-04-22 05:15:44 +00:00
Chris Lattner
7f3d88632d Introduce a new AST node, named TypeExpr, which will be formed by sema
when resolving identifiers into types.  This will eventually allow us to
solve annoying issues like rdar://15295763&15588967 by better modeling
what we already have.


Swift SVN r16620
2014-04-21 16:10:11 +00:00
Doug Gregor
8e597cc695 Eliminate argument parameter patterns.
Swift SVN r16444
2014-04-17 05:20:14 +00:00
Jordan Rose
0324b9e027 Don't walk into an as-of-yet-unsynthesized function body.
...and don't dump it, and don't force it just to see if an accessor is present.

Swift SVN r15830
2014-04-02 21:00:48 +00:00
Joe Groff
8f1c2d1e79 Sema: Implement type-checking for inout writeback conversion.
Add a third branch to the constraint system for '&x' expressions that allows conversion from an lvalue to a type via an additional writeback step:

- Add an LValueConversionExpr node that converts from @lvalue T to @lvalue U, given a pair of functions that convert T -> U and U -> T, to represent the writeback temporary.
- Allow conversion in an inout expression from @lvalue T to a type U that has the following members:

  static func __writeback_conversion(Builtin.RawPointer, T.Type) -> U
  static func __writeback_conversion_get(T) -> V
  static func __writeback_conversion_set(V) -> T

which builds a solution that produces an LValueConversion from the get/set pair before passing the pointer to the writeback temporary off to the conversion function.

Swift SVN r15764
2014-04-02 00:17:51 +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
46f77c6181 Sema: Build the AST for inout address conversions.
Add two new AST node types:

- InOutConversionExpr, which represents an '&x' expression that involves inout conversion. This will be a signal to SILGen not to introduce a writeback scope for the nested conversion call.

- LValueToPointerExpr, which represents the primitive '@lvalue T' to 'RawPointer' conversion that produces the argument to the inout conversion.

Build an InOutConversionExpr AST when an inout expression is resolved by a conversion to an BuiltinInOutAddressConvertible type.

Swift SVN r15594
2014-03-29 02:50:25 +00:00
Joe Groff
45eadd1d9b Rename AddressOfExpr to InOutExpr.
The "address" is an implementation detail; formally, it turns an lvalue into an inout parameter.

Swift SVN r15458
2014-03-25 16:28:28 +00:00
Dmitri Hrybenko
11fea869c1 Change 'switch' not to fall through between empty cases and always require at
least one statement per case

rdar://16301313


Swift SVN r15266
2014-03-20 11:44:59 +00:00
Joe Groff
363a324984 Parse: Start parsing selector member references.
Parse 'x.y:z:' for at least two selector pieces as an UnresolvedSelectorExpr, and declare it unimplemented in Sema.

Swift SVN r14492
2014-02-28 01:47:32 +00:00
Joe Groff
c0d8ae7c13 Parse 'x.self' as an identity expression.
Factor an IdentityExpr base class out of ParenExpr, and migrate most of the logic to see through ParenExprs to see through IdentityExprs instead. Add DotSelfExpr as a new subclass of IdentityExpr, produced by parsing 'x.self'.

Swift SVN r14381
2014-02-26 06:23:55 +00:00
Joe Pamer
988a5877f2 Some updates:
- Respond to Doug's code review feedback
   - Stop hacking around with scopes and use "emplace" to work around RAII in the inactive config case
   - Limit use of StringRef on the front-end, in favor of std::string
   - Use ArrayRef rather than SmallVector within IfConfigDecl
   - Reorder new property declarations on BraceStmt to prevent unnecessary alignment issues
- Update ParseBraceItems to better capture top-level declarations, rather than using token lookahead

Swift SVN r14306
2014-02-24 18:16:49 +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
Chris Lattner
3392c4e8ab remove ArchetypeSubscriptExpr, since it is dead now.
Swift SVN r14284
2014-02-23 08:04:51 +00:00
Chris Lattner
30f4b1ba4a remove the unused ArchetypeMemberRefExpr and ExistentialMemberRefExpr nodes.
Swift SVN r14274
2014-02-22 22:09:38 +00:00
Chris Lattner
380e44c615 remove ExistentialSubscriptExpr. We don't need specialized forms of
subscriptexpr for various base types, for the same reason we don't need
multiple different kinds of MemberRefExpr.


Swift SVN r14268
2014-02-22 20:18:02 +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
Argyrios Kyrtzidis
b3e874f845 [ASTWalker] Walk the TypeRepr of an ExplicitCastExpr.
Swift SVN r13570
2014-02-06 07:17:08 +00:00
Chris Lattner
ee0986fa9e introduce a new TypeRepr to represent "inout" in the argument list to a
function.  Parse inout as a contextual keyword there, shoving it into the
TypedPattern (instead of introducing a new kind of Pattern).  This enables
us to parse, sema, and irgen the new '@-less' syntax for inout.


Swift SVN r13559
2014-02-06 04:31:13 +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
Joe Groff
9fe1ab427a Implement 'if let' and 'while let' statements.
Allow IfStmts and WhileStmts to have as their condition either an expression, as usual, or a pattern binding introduced by 'var' or 'let', which will conditionally bind to the value inside an optional. Unlike normal pattern bindings, these bindings require an in-line initializer, which will be required to be Optional type. Parse variable bindings in this position, and type-check them by requiring an Optional on the right-hand side and unwrapping it to form the pattern type. Extend SILGen's lowering of if and while statements to handle conditionally binding variables.

Swift SVN r13146
2014-01-30 10:37:39 +00:00
Doug Gregor
2cc183472b Teach the AST walker to walk the caller-side default arguments of TupleShuffleExpr.
Fixes the rest of <rdar://problem/15730944>.


Swift SVN r12821
2014-01-23 00:12:48 +00:00
Argyrios Kyrtzidis
639086266e [AST] Have the ASTWalker visiting the members of NominalTypeDecls and ExtensionDecls even when
they haven't been deserialized yet.

If a specific ASTWalker subclass doesn't care about the members then it should just skip walking them.

Swift SVN r12722
2014-01-22 07:10:37 +00:00
Jordan Rose
5299a502d0 [ClangImporter] Import class, protocol, and category members lazily.
This still isn't /that/ lazy because a lot of things can force member
deserialization (such as the type-checker generating a DestructorDecl for
every imported class), and we don't do this in a member-granular way just
yet. I don't see any change in testing time, for example.

But besides just being a good thing in general, this perturbs the order
of imported decls enough to fix <rdar://problem/15799697>: we can now
reliably see that there is a -URL:something: function on NSObject that
blocks any properties named 'URL' from being imported as properties.

(Which we don't actually want; see <rdar://problem/15456130>.)

Swift SVN r12685
2014-01-22 00:54:47 +00:00
Argyrios Kyrtzidis
84e20a0620 [AST] Break down IdentTypeRepr to different subtypes.
This makes memory allocation for it more efficient and it's more convenient to handle.

Swift SVN r12541
2014-01-18 20:19:09 +00:00
Dave Abrahams
0f994b6ba0 Rename "Container" => "Sequence" in core compiler
A few places in the core compiler were referring to instances of the
Sequence protocol as "Containers".  The "Indexable" protocol will soon
be renamed "Container," so eliminate this potential confusion

Swift SVN r11944
2014-01-06 20:07:01 +00:00
Chris Lattner
b35858f131 Simplify more cases to use getSemanticsProvidingPattern.
Change Pattern::getBoundName to look through VarPatterns,
which means that the presence of var/let in an argument list no longer 
change the mangling of the function.



Swift SVN r11780
2013-12-31 22:25:43 +00:00
Joe Groff
017440165e Fix the weird capitalization of MetaTypeType.
Swift SVN r11475
2013-12-19 18:43:08 +00:00
Chris Lattner
39224db6a9 remove the ZeroValueExpr AST node.
Swift SVN r11048
2013-12-09 23:16:14 +00:00
Doug Gregor
19759529db Allow delayed identifier expressions (.foo) with static variables and methods.
This allows expressions such as ".foo" and ".foo(1)" to refer to
static variables and static methods, respectively, as well as enum
cases. 

To get here, rework the parsing of delayed identifier expressions a
bit, so that the argument itself is part of the delayed argument
expression rather than a separate call expression. This simplifies
both the handling of patterns of this form and the type checker, which
can now user simpler constraints.

If we really want to support (.foo)(1), we can make that work, but it
seems unnecessary and perhaps confusing.


Swift SVN r10626
2013-11-21 06:24:06 +00:00
Chris Lattner
68af974227 Remove 'axle' related code and build machinery. It turns out that we
will not be pursuing this project in the immediate future.



Swift SVN r9901
2013-11-03 16:04:27 +00:00
Doug Gregor
a7664fda78 Clean up the checking of pattern binding declarations.
Eliminate the annoying, rarely-firing "while converting 'var' initial
value to declared type" note. We'll eventually have better ways to
deal with this. Otherwise, no functionality change.


Swift SVN r9677
2013-10-25 21:14:03 +00:00
Argyrios Kyrtzidis
d9e0921a76 [ASTWalker] Walk the pattern of a ForEachStmt.
Swift SVN r9291
2013-10-13 18:50:50 +00:00
Argyrios Kyrtzidis
f995d2ac28 [ASTWalker] Walk the TypeRepr of a typealias.
Swift SVN r9290
2013-10-13 18:50:49 +00:00
Doug Gregor
7fee09b41e Axle: Implement Matrix<T, N> and Matrix<T, N, M> syntactic sugar.
This completes the majority of <rdar://problem/15100137>.


Swift SVN r9098
2013-10-09 22:24:21 +00:00
Doug Gregor
fba128e191 Axle: Implement Vec<T, N> syntactic sugar for the VecTxN structs.
Implements the first part of <rdar://problem/15100137>.


Swift SVN r9092
2013-10-09 21:12:19 +00:00
Argyrios Kyrtzidis
275ce0970e [ASTWalker] Walk the TypeReprs of an extension decl.
Swift SVN r9032
2013-10-08 21:53:56 +00:00
Doug Gregor
611a5cce4b Replace the library-defined postfix '!' with an expr-postfix production.
As with the monadic '?', we treat any left-bound '!' as a postfix
operator. Currently, it extracts the value of its optional
subexpression, failing at run-time if the optional is empty.


Swift SVN r8948
2013-10-06 23:09:58 +00:00
Argyrios Kyrtzidis
781dcf7b11 [AST] Store the TypeReprs of generic arguments used to specialize a decl reference in DeclRefExpr, to impove source fidelity.
Fixes rdar://15034958

Swift SVN r8880
2013-10-03 17:55:55 +00:00
Argyrios Kyrtzidis
883a9eec61 [ASTWalker] Walk the TypeReprs of UnresolvedSpecializeExprs so we can syntax-annotate them.
Swift SVN r8879
2013-10-03 17:55:54 +00:00
Joe Groff
3b0180b1b0 Allow '_' in assignments again.
Parse '_' as a DiscardAssignmentExpr. Type-check it as an lvalue, and check that it only appears in the LHS of AssignExprs. During matching pattern resolution, convert it into an AnyPattern. In SILGen, when we see '_' in the LHS of an assignment, ignore the corresponding RHS rvalue.

Swift SVN r8848
2013-10-02 18:43:20 +00:00
John McCall
298577676e Introduce the monadic ? operator.
A ? operator is interpreted as this if it's left-bound,
so ternary operators now have to be spaced on the left.

Swift SVN r8832
2013-10-02 01:27:45 +00:00