Commit Graph

1278 Commits

Author SHA1 Message Date
Doug Gregor
1789c4ccbc Collapse CollectionBridgedConversionExpr into CollectionUpcastConversionExpr.
Semantically, these expressions handle the same thing: an upcast of a
collection when the underlying element types of the source are
subtypes of or can be bridged to subtypes of the destination. This
reduces some branching in the type checker and eliminates duplication
in SILGen.

Swift SVN r18865
2014-06-13 16:32:47 +00:00
Doug Gregor
5ca3882b06 Rename array upcast/bridge expressions to "collection".
This is staging for dictionary bridging upcasts.


Swift SVN r18840
2014-06-12 21:41:55 +00:00
Joe Groff
cf9e0d2624 Sema: Introduce metatype-to-object conversions.
Allow class metatypes (including class-constrained existential metatypes) to be treated as subtypes of AnyObject, and single-@objc protocol metatypes to be treated as subtypes of the Protocol class from objc. No codegen support yet, so this is hidden behind a frontend flag for now.

Swift SVN r18810
2014-06-11 23:06:23 +00:00
Doug Gregor
f8409eb025 Print location in expression AST dumps as well
Swift SVN r18559
2014-05-22 07:41:31 +00:00
Doug Gregor
049cd39322 Add source ranges to expression dumps.
Swift SVN r18558
2014-05-22 07:26:43 +00:00
Doug Gregor
67ca1c9ea1 Implement the new casting syntaxes "as" and "as?".
There's a bit of a reshuffle of the ExplicitCastExpr subclasses:
  - The existing ConditionalCheckedCastExpr expression node now represents
"as?". 
  - A new ForcedCheckedCastExpr node represents "as" when it is a
  downcast.
  - CoerceExpr represents "as" when it is a coercion.
  - A new UnresolvedCheckedCastExpr node describes "as" before it has
  been type-checked down to ForcedCheckedCastExpr or CoerceExpr. This
  wasn't a strictly necessary change, but it helps us detangle what's
  going on.

There are a few new diagnostics to help users avoid getting bitten by
as/as? mistakes:
  - Custom errors when a forced downcast (as) is used as the operand
  of postfix '!' or '?', with Fix-Its to remove the '!' or make the
  downcast conditional (with as?), respectively.
  - A warning when a forced downcast is injected into an optional,
  with a suggestion to use a conditional downcast.
  - A new error when the postfix '!' is used for a contextual
  downcast, with a Fix-It to replace it with "as T" with the
  contextual type T.

Lots of test updates, none of which felt like regressions. The new
tests are in test/expr/cast/optionals.swift. 

Addresses <rdar://problem/17000058>


Swift SVN r18556
2014-05-22 06:15:29 +00:00
Doug Gregor
f477f061fe Replace ArrayDowncastConversionExpr with ArrayDowncastExpr.
Array downcast is an explicit cast written "x as U[]", not an implicit
conversion, so make it a subclass of ExplicitCastExpr. The only
effective change here is that we retain the location of the "as" and
the type as written in the AST. No semantic change.



Swift SVN r18391
2014-05-19 04:41:42 +00:00
Doug Gregor
2da304d05e Start using the _arrayBridgeFromObjectiveC entry point for checked downcasts.
This allows us to perform a checked downcast from an Object[] to a String[].

Swift SVN r18371
2014-05-19 00:04:41 +00:00
John McCall
b8c2967567 Create a dedicated implementation file for Substitution. NFC.
Swift SVN r18295
2014-05-18 02:16:21 +00:00
John McCall
a617cfbabb We can compare archetypes directly with pointer equality;
this is both faster and correctly handles the possibility
of a null archetype.

Swift SVN r18294
2014-05-18 02:16:19 +00:00
Chris Lattner
2c15f7f0e9 improve AST dumper of TupleExpr to print the label names.
Swift SVN r18129
2014-05-15 21:48:27 +00:00
Sean Callanan
da5112e7b8 Fixed a crash when dumping an anonymous NamedPattern.
<rdar://problem/16908334>


Swift SVN r18085
2014-05-14 23:26:36 +00:00
Joe Pamer
1e5b9116d4 More array casting work:
- Continue adding support for checked downcasts of array types (rdar://problem/16535104)
- Fix non-bridged array conversions post-r17868
- Fix rdar://problem/16773693
- Add tests for NSArray coercions to and from Array<T>

Swift SVN r17957
2014-05-12 20:49:42 +00:00
Chris Lattner
24f06eb0e4 Rework my handling of @lazy in struct init() synthesization: the underlying
storage can be explicitly specified with a memberwise constructor (this already
worked) and the presence of the property shouldn't block synth of the default
ctor since it is default initialized to nil.

Unrelatedly, print the lazy attribute in the AST dumper.



Swift SVN r17925
2014-05-12 03:54:46 +00:00
Chris Lattner
24aa50069d Adjust diagnostics now that weak/unowned aren't attributes
Swift SVN r17800
2014-05-09 21:11:28 +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
Chris Lattner
2426134853 improve hte AST representation of capture lists to build VarDecls and
PatternBindingDecls, and inject the vardecls into the name resolution
scope while parsing the body of the closure.  This allows references
from the body of the closure to be resolved to the capture list,
e.g. in cases like the testcase.


Swift SVN r17760
2014-05-09 05:39:28 +00:00
Joe Pamer
2eedc06d66 Begin adding plumbing for the type checker to accept "forward" bridged array conversions. (rdar://problem/16540403)
Swift SVN r17640
2014-05-07 19:45:37 +00:00
Joe Pamer
edb4946f66 Begin updating type checking of array upcasts to conform with the new spec.
Also, call through DaveA's new entry point for upcasts on Array<T>.

Swift SVN r17564
2014-05-06 21:32:22 +00:00
Chris Lattner
d230228cdd store the capture list of a ClosureExpr in the AST and print it out
in the AST dumper.


Swift SVN r17451
2014-05-05 16:25:33 +00:00
Chris Lattner
29aca1c851 Various minor TypeExpr improvements:
- Change astdumper to print the typerepr in the more canonical syntax.
 - Remove bogus logic from CSApply that was preventing us from rewriting
   TypeExprs properly
 - Teach CSGen to handle unbound generics correctly (thanks to Doug for the help on this)



Swift SVN r17007
2014-04-29 02:58:43 +00:00
Chris Lattner
eeaf7a657d have the ast dumper print TypeExprs a bit nicer.
Swift SVN r16953
2014-04-27 23:38:36 +00:00
Chris Lattner
0c390777ba Implement <rdar://problem/16204675> Need #elseif
This restructures IfConfigDecl/Stmt to be a list of clauses controlled
by a condition.  This makes it straight-forward to drop in #elseif support.

While I'm in here, this patch moves checking for extraneous stuff at the
end of the #if line from the lexer to the parser.  This means that you can
now put a comment on the same line as a #if/#else/#elseif/#endif.



Swift SVN r16912
2014-04-27 04:51:36 +00:00
Joe Pamer
86b79d6bd3 Some code cleanup for array upcast conversions. (Part 2 of the fix for rdar://problem/16540403)
Swift SVN r16837
2014-04-25 19:52:06 +00:00
Joe Pamer
066f5e6da5 Allow for simple upcast conversions between array types. (Part 1 of the fix for rdar://problem/16540403)
Swift SVN r16836
2014-04-25 19:52:05 +00:00
Joe Groff
8f51b0e738 Revert "wip"
This reverts commit r16662. Fat fingers.

Swift SVN r16663
2014-04-22 21:50:52 +00:00
Joe Groff
4a81e48ef8 wip
Swift SVN r16662
2014-04-22 21:46:36 +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
09797f7f99 Introduce a new declaration node, ParamDecl, for function parameters.
Use this node to capture the argument name and its source location in
the AST. We're only building these in one place at the moment; the
rest will be updated soon.


Swift SVN r16581
2014-04-20 05:23:35 +00:00
Nadav Rotem
001533d1eb Fix the build by adding the '==' operator to Substitution.
Swift SVN r16565
2014-04-19 05:47:00 +00:00
Doug Gregor
812dc091eb Introduce the notion of factory initializers.
Factory initializers express an initializer that produces an object of
the given type, but is not inherited and not designated. Although they
have a syntactic form for presentation purposes (-> ClassName), there
is no way to specify or implement them within Swift. Rather, factory
initializers are created when importing an Objective-C factory method
that returns the class type rather than instancetype.

Swift SVN r16528
2014-04-18 16:04:48 +00:00
Doug Gregor
d80b689c51 Introduce "convenience factory" initializers.
Convenience factory initializers are convenience initializers produced
by importing an Objective-C factory method as a convenience
initializer. The distinction is currently only used to eliminate the
awful layering violation I recently introduced in name lookup, which
was consulting Clang AST nodes directly. It will also be useful in
SILGen.

Swift SVN r16527
2014-04-18 15:34:26 +00:00
Doug Gregor
8bc2ea4ea1 Use designated/convenience initializer terminology throughout. NFC
Introduce CtorInitializerKind to describe the kind of an enum, rather
than a bool, to make way for more initializer kinds in the future.

Swift SVN r16525
2014-04-18 15:10:13 +00:00
John McCall
9000278dcd Introduce MetatypeErasureExpr for erasing metatype
values into existential metatypes.  Erase thin metatypes
correctly in SILGen.

rdar://16610078

Swift SVN r16477
2014-04-17 22:31:47 +00:00
Doug Gregor
129aa191a6 Remove the use of ArgParamPatterns in the AST printer and dumper.
Swift SVN r16436
2014-04-17 03:33:46 +00:00
Doug Gregor
86ecc725c9 Start building compound names for functions parsed with the new signature style.
Swift SVN r16394
2014-04-16 03:55:05 +00:00
Joe Groff
3bad92b342 AST: Remove the stopgap BridgeToBlockExpr and handle block <-> non-block conversions freely as function conversions.
Teach SILGen to handle function representation changes as part of function conversion instead of needing to be spoonfed a special expr for the purpose. Handle representation changes in both directions to and from blocks using the same logic as the bridging conversions.

Swift SVN r16318
2014-04-14 15:00:34 +00:00
Doug Gregor
d023035103 Allow associated types to have superclasses.
Fixes <rdar://problem/16413389>.


Swift SVN r16219
2014-04-11 17:07:56 +00:00
Doug Gregor
5b8dab7c19 AST dumper: dump the full name of a function.
Swift SVN r15980
2014-04-05 05:45:51 +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
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
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
Argyrios Kyrtzidis
4f1bdd42a6 [ASTDumper] Dump an IfConfigDecl.
Swift SVN r15442
2014-03-25 03:55:27 +00:00
Joe Groff
4fdc20f739 Allow '<pattern> as T' checked patterns with subpattern bindings.
Allow a form of 'case is T' that matches the cast result to a subpattern, 'case <pattern> as T'. This exposes an issue in switch destructuring with casting into complex class hierarchies <rdar://problem/16401831> but works for common cases.

Swift SVN r15396
2014-03-24 00:02:44 +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
John McCall
c40a2e54b2 Extract a method to print a CheckedCastKind and dump
it on CheckedCastExprs.

Swift SVN r15245
2014-03-19 20:25:09 +00:00