Commit Graph

1316 Commits

Author SHA1 Message Date
Manman Ren
c4233e98ff [Printer] use SIL print options when printing SILWitnessTable.
Add PrintOptions to Substitution::print and ProtocolConformance::printName.
rdar://18021102


Swift SVN r22366
2014-09-29 21:59:03 +00:00
John McCall
6923101341 Rename "AccessKind" to "AccessSemantics". NFC.
There are a lot of different ways to interpret the
"kind" of an access.  This enum specifically dictates
the semantic rules for an access:  direct-to-storage
and direct-to-accessor accesses may be semantically
different from ordinary accesses, e.g. if there are
observers or overrides.

Swift SVN r22290
2014-09-25 23:12:39 +00:00
Devin Coughlin
b727b6d932 Treat potentially unavailable global variable references as optional.
This patch adds the ability (-enable-experimental-unavailable-as-optional) to
treat potentially unavailable declarations as if they had optional types. For
the moment, this is only implemented for global variables.

The high-level approach is to (1) record the potential unavailability of a
declaration reference in the overload choice during constraint generation; (2)
treat the declaration as if it had an optional type during overload resolution
(this is similar to how optional protocol members are treated); and (3) add an
implicit conversion (UnavailableToOptionalExpr) during constraint application
to represent the run-time availability check and optional injection.

This patch does not implement SILGen for UnavailableToOptionalExpr.


Swift SVN r22245
2014-09-24 00:07:46 +00:00
John McCall
16cb523c3a AST support for accessors.
Swift SVN r22228
2014-09-23 20:34:19 +00:00
Devin Coughlin
d9c10b1915 Extend parsing of #os(...) to allow queries for multiple platforms.
This patch extends the AST and parsing of #os(...) queries to permit queries for
multiple platforms, e.g., #os(OSX >= 10.10, iOS >= 8.0). It also improves
parsing error recovery.


Swift SVN r22154
2014-09-21 01:27:53 +00:00
Doug Gregor
042a71055b Dump full name with references.
This is just a little debugging aid.


Swift SVN r22096
2014-09-18 20:34:59 +00:00
John McCall
8cae5ba1d0 Generalize 'isDirectPropertyAccess' to allow for
direct (i.e. non-polymorphic) access to accessor
functions, and use this in materializeForSet for
computed properties.

Swift SVN r22059
2014-09-18 05:51:32 +00:00
John McCall
5b82dc5f5b Minor improvements to declaration dumping.
Swift SVN r22015
2014-09-17 08:08:09 +00:00
John McCall
75050f8166 Generate an implicit 'materializeForSet' accessor
along with getters and setters.

Just generate it for now.

Swift SVN r22011
2014-09-17 08:08:03 +00:00
Devin Coughlin
5a9ccc5ab2 Add ASTDumper support for AvailabilityQueryExpr
This patch also moves some static utility methods involving PlatformKind out of Attr.h and into PlatformKind.h.


Swift SVN r21896
2014-09-12 00:13:48 +00:00
Devin Coughlin
ab563d6ef1 Add availability query expression (#os(...))to the AST
This commit adds a new expression (AvailabilityQueryExpr) and a single kind of
specification for when a block of code or function is available
(VersionConstraintAvailabilitySpec). We may add more kinds of specifications
in the future. At the moment, the AvailabilityQueryExpr allows only a
single platform to be queried; I will add support for multiple platforms
in a later commit.

This commit contains just the added AST nodes; no parsing, type checking, etc.
I’ve added assert(false && “Unimplemented”) for places where support for
AvailabilityQueryExpr will need to be added later.



Swift SVN r21760
2014-09-06 02:11:02 +00:00
Doug Gregor
51c1433ddd Add magic "literal" __DSO_HANDLE__ to refer to the DSO handle.
__DSO_HANDLE__ can be used as a callee-side default
argument. Addresses rdar://problem/17878114.


Swift SVN r21440
2014-08-25 16:33:54 +00:00
Doug Gregor
17716524c5 Handle CF <-> Objective-C toll-free-bridged conversions in the type checker.
Introduce an attribute that describes when a given CF type is
toll-free-bridged to an Objective-C class, and which class that
is. Use that information in the type checker to provide the CF <->
Objective-C toll-free-bridged conversions directly, rather than using
the user-defined conversion machinery.

Swift SVN r21376
2014-08-21 21:36:05 +00:00
Doug Gregor
344ecfd3f9 Add a new 'fail' statement to the AST for failing from an initializer.
The spelling of the 'fail' statement is simply 'return nil', but
distinguishing it in the AST clarifies intent for SILGen.

Swift SVN r21310
2014-08-20 17:22:36 +00:00
Doug Gregor
42dc448e7e Reflect failability of an initializer in the optionality of its result type.
Don't verify this for the Optional and ImplicitlyUnwrappedOptional types.


Swift SVN r21293
2014-08-19 20:42:06 +00:00
Doug Gregor
c06e22d406 Revert r21291; it's breaking the standard library build.
Swift SVN r21292
2014-08-19 20:37:05 +00:00
Doug Gregor
e6f051fcd2 Reflect failability of an initializer in the optionality of its result type.
Swift SVN r21291
2014-08-19 20:22:25 +00:00
Doug Gregor
64bd844e0e Parse failable initializers.
Parsing, representation, (de-)serialization, printing, and dumping for
failable initializers.


Swift SVN r21290
2014-08-19 18:41:30 +00:00
Dmitri Hrybenko
938e7c2676 stdlib: introduce UnicodeScalarLiteralConvertible protocol
This allows UnicodeScalars to be constructed from an integer, rather
then from a string.  Not only this avoids an unnecessary memory
allocation (!) when creating a UnicodeScalar, this also allows the
compiler to statically check that the string contains a single scalar
value (in the same way the compiler checks that Character contains only
a single extended grapheme cluster).

rdar://17966622

Swift SVN r21198
2014-08-14 16:04:39 +00:00
Doug Gregor
5670ecacc0 Dump 'where' clause as part of GenericParamList dump. NFC
Swift SVN r20826
2014-07-31 15:15:54 +00:00
Doug Gregor
ec6016040e Clang importer: try harder to mark initializers from protocols as required.
There is an egregious hack here that special-cases -initWithCoder:. We
need to completely revisit how we handle 'required' checking.

Swift SVN r20516
2014-07-24 21:29:05 +00:00
Chris Lattner
bc481f0fe1 implement <rdar://problem/16859927> remove the underscore in "auto_closure"
autoclosure is one work, not two.



Swift SVN r20253
2014-07-21 15:23:50 +00:00
Chris Lattner
72e97f6023 fix printing of accessors to be more properly parentheses nested.
Swift SVN r20217
2014-07-20 04:39:42 +00:00
Chris Lattner
5b49d59c57 Remove the @ from @final and @lazy, the last major piece of
rdar://17168115.

Also, reinstate the ARM driver change and testcase that I removed
in my last patch.


Swift SVN r19790
2014-07-10 06:23:27 +00:00
Doug Gregor
2f3f6acf21 Make "true" and "false" Boolean literal constants for the BooleanLiteralConvertible protocol.
Introduce the new BooleanLiteralConvertible protocol for Boolean
literals. Take "true" and "false" as real keywords (which is most of the
reason for the testsuite churn). Make Bool BooleanLiteralConvertible
and the default Boolean literal type, and ObjCBool
BooleanLiteralConvertible. Fixes <rdar://problem/17405310> and the
recent regression that made ObjCBool not work with true/false.


Swift SVN r19728
2014-07-09 16:57:35 +00:00
Jordan Rose
132a29eb67 Remove unnecessary wrapper type GenericParam.
This always wrapped a single GenericTypeParamDecl *, and provided no benefit
over just using the decl directly.

No (intended) functionality change.

Swift SVN r19628
2014-07-07 20:51:50 +00:00
Joe Groff
151ed6143d Add a StringToPointerExpr node.
To represent string-to-pointer argument conversions.

Swift SVN r19314
2014-06-28 00:36:43 +00:00
Doug Gregor
5a08a69ebc Remove NewArrayExpr entirely; reject "new" expressions in the parser.
Swift SVN r19293
2014-06-27 15:57:48 +00:00
Joe Groff
9a190ea59e AST: Remove unneeded expression nodes for __inout_conversion and __writeback_conversion.
We no longer need this language feature. The Sema support is still skeletally kept in place because removing it seems to totally break pointer conversions; I need to work with Joe and Doug to figure out why that's the case.

Swift SVN r19289
2014-06-27 04:23:35 +00:00
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
Jordan Rose
20bc9ec2b9 Add accessibility printing, and test the accessibility inference so far.
Swift SVN r19144
2014-06-24 21:32:15 +00:00
Doug Gregor
2b8923e3ef Allow "isa" patterns to downcast collections and bridge through Objective-C classes.
When checking an isa pattern that requires either collection
downcasting or bridging through an Objective-C class (e.g., 
"is String" or "is Dictionary<String, Int>"), form a conditional
downcast and place it in an expression pattern.

With this change, we can test for these cases (with "is") but we can't
capture the value produced on success (e.g., for "let str as
String"). This is a first small step toward <rdar://problem/17408934>.


Swift SVN r19070
2014-06-21 22:46:15 +00:00
Joe Groff
08a48565fb Sema: Introduce intrinsic pointer argument conversions.
Add primitive type-checker rules for pointer arguments. An UnsafePointer argument accepts:

- an UnsafePointer value of matching element type, or of any type if the argument is UnsafePointer<Void>,
- an inout parameter of matching element type, or of any type if the argument is UnsafePointer<Void>, or
- an inout Array parameter of matching element type, or of any type if the argument is UnsafePointer<Void>.

A ConstUnsafePointer argument accepts:

- an UnsafePointer, ConstUnsafePointer, or AutoreleasingUnsafePointer value of matching element type, or of any type if the argument is ConstUnsafePointer<Void>,
- an inout parameter of matching element type, or of any type if the argument is ConstUnsafePointer<Void>, or
- an inout or non-inout Array parameter of matching element type, or of any type if the argument is ConstUnsafePointer<Void>.

An AutoreleasingUnsafePointer argument accepts:

- an AutoreleasingUnsafePointer value of matching element type, or
- an inout parameter of matching element type.

This disrupts some error messages in unrelated tests, which is tracked by <rdar://problem/17380520>.

Swift SVN r19008
2014-06-19 18:03:10 +00:00
Doug Gregor
4eeee3580f Remove *CollectionDowncastExpr; wen're not using them any more.
This simplifies constraint application quite a bit, and eliminates
some code duplication.


Swift SVN r18980
2014-06-18 13:10:22 +00:00
Doug Gregor
4019d28ba8 Start using the forced collection downcast entry points.
This means that we'll get deferred checking of array and dictionary
downcasts when writing "arr as Derived[]", 
"(dict as? Dictionary<DerivedKey, DerivedValue>)!", etc, when the
collection can do so.

This is both a general optimization and also staging for
<rdar://problem/17319154>.


Swift SVN r18975
2014-06-18 05:22:41 +00:00
Doug Gregor
f0186ea490 Rename CollectionDowncastExpr to ConditionalCollectionDowncastExpr.
Swift SVN r18974
2014-06-18 04:25:07 +00:00
Chris Lattner
60fc0e6cd2 Implement <rdar://problem/16951729> nil should be a literal type
This is all goodness, and eliminates a major source of implicit conversions.
One thing this regresses on though, is that we now reject "x == nil" where
x is an option type and the element of the optional is not Equtatable.  If
this is important, there are ways to enable this, but directly testing it as
a logic value is more straight-forward.

This does not include support for pattern matching against nil, that will be
a follow on patch.



Swift SVN r18918
2014-06-15 22:59:03 +00:00
Doug Gregor
c5e3dc4e20 Rename ArrayDowncastExpr to CollectionDowncastExpr. NFC
Swift SVN r18898
2014-06-14 17:08:33 +00:00
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