Commit Graph

2516 Commits

Author SHA1 Message Date
Doug Gregor
c1c51b4e8b Move checking of non-failable-to-failable initializer calls into constraint application.
This makes sure we get the same checking for initializer delegation in
structs/enums as we do for classes, fixing rdar://problem/18458622.

Swift SVN r23128
2014-11-06 06:29:35 +00:00
Joe Groff
5e682924f6 AST: Drop insignificant CheckedCastKinds.
We'd like to kill this enum off eventually, since the runtime inevitably needs to be able to handle arbitrary checked casts in opaque contexts, and SILGen and IRGen can deal with picking more optimal runtime entry points for specific casts. Only the container bridging kinds are still depended on anymore, and even those ought to eventually be handlable by the runtime in 'x as T' situations. NFC yet.

Swift SVN r23127
2014-11-06 04:05:05 +00:00
Chris Willmore
22f2452909 Only allow labeled parameters with function type to claim trailing closures, as opposed to any unlabeled argument.
For real this time. Added some additional tests.

rdar://problem/18778670

Swift SVN r23094
2014-11-04 03:40:08 +00:00
Chris Willmore
da2e3c4c73 Revert "Only allow labeled parameters with function type to claim trailing closures, as opposed to any unlabeled argument."
The commit broke the PerfTestSuite build:

/Users/buildslave/jenkins/sharedspace/swift-release-asserts/swift/src/tools/swift/benchmark/PerfTestSuite/SingleSource/DollarChain.swift:30:14:
error: missing argument label 'function:' in call
       $.tap(beatle, {$0.name = "Beatle"}).color = "Blue"

This reverts commit r23090.

Swift SVN r23093
2014-11-04 02:19:10 +00:00
Chris Willmore
f64bdb3021 Only allow labeled parameters with function type to claim trailing closures, as opposed to any unlabeled argument.
rdar://problem/18778670

Swift SVN r23090
2014-11-03 22:22:48 +00:00
Jordan Rose
cc23b8a936 Replace some unqualified lookups with direct lookups.
These are very-slightly-but-not-significantly faster; there's no need to
go through the intermediate layer of unqualified lookup.

No functionality change.

Swift SVN r22872
2014-10-22 01:00:22 +00:00
Devin Coughlin
4fcbf5a8bb [Sema] Add checking for declarations with potentially unavailable types.
This commit adds checking of declarations with potentially unavailable types to
the existing checking for explicitly unavailable types. At the moment, these
two checking mechanisms are separate -- I will unify them in a future commit.

This commit removes the TypeExpr-based checking added in r22651; such checks
are now superfluous.


Swift SVN r22679
2014-10-10 22:40:27 +00:00
Devin Coughlin
f8fe884e98 Add availability checking for references to classes to Sema.
This commit adds availability checking for references to classes in Sema. We
now emit a diagnostic when a potentially unavailable class is referenced
in an expression, either directly (via a TypeExpr) or as the result of being
substituted as a replacement type in a call to a generic function. This
latter check is needed at the callsite because the callee may use its
formal type parameter to get at the metadata for the type.

This commit does not check declarations of variables, etc., with unavailable
types -- this will come in a later patch.


Swift SVN r22651
2014-10-10 01:11:40 +00:00
Devin Coughlin
2e3acba163 Add availability checking for properties to Sema
This commit adds availability checking for properties to Sema. When
EnableExperimentalAvailabilityChecking is enabled, we now emit a diagnostic
when a potentially unavailable property is accessed. To support this, we
now build type refinement contexts for most ValueDecls.


Swift SVN r22622
2014-10-09 17:21:52 +00:00
Devin Coughlin
0aa115c09b Add diagnostics for potentially unavailable initializers.
This patch adds diagnostics for initializers that are potentially unavailable.
It does not treat such initializers as optionals, even when
EnableExperimentalUnavailableAsOptional is true -- there is some tricky
interaction with failable initializers that still needs to be worked out.



Swift SVN r22548
2014-10-06 19:50:08 +00:00
Devin Coughlin
59814bd140 Add type checking for potentially unavailable method references.
This commit modifies Sema to add type checking for potentially unavailable
method references. We now record the reason for method unavailability when
recording a potential overload choice during member constraint simplification
and either diagnose or lift to an optional type during CSApply. This commit also
generalizes UnavailableToOptionalExpr to take an arbitrary subexpression.

This commit does not address potentially unavailable properties, initializers,
or dynamic member references.


Swift SVN r22508
2014-10-03 23:23:13 +00:00
Jordan Rose
042569a3be Optional: Replace uses of Nothing with None.
llvm::Optional (like Swift.Optional!) uses None as its placeholder value,
not Nothing.

Swift SVN r22476
2014-10-02 18:51:42 +00:00
Devin Coughlin
2e8d4bc718 Add handling of potentially unavailable overloaded global functions to Sema.
This commit also factors out some common checking and diagnostic code; it
additionally moves diagnostic emission for unavailable references from CSGen to
CSApply.


Swift SVN r22447
2014-10-01 23:52:08 +00:00
Devin Coughlin
3749a98763 Record the reason a declaration is potentially unavailable.
This commit adds tracking of the reason a declaration reference is potentially
unavailable to the UnavailableToOptionalExpr AST node and to OverloadChoice. We
will use this reason during SILGen to emit the appropriate run-time check and
during typechecking to provide more helpful diagnostics.

To keep OverloadChoice as small as possible, we encode the reason as an index
into a vector of reasons stored in a given instance of ConstraintSystem (this is
the same approach that Fix takes).

This commit adds Sema/OverloadChoice.cpp (for the parts of OverloadChoice that
now rely on ConstraintSystem) and AST/Availability.h (to bring in
availability-related structures without TypeRefinementContext).


Swift SVN r22377
2014-09-30 01:53:59 +00:00
Joe Groff
8faf876eb0 AST: Drop array injection functions from vararg representations.
We only need the array type (and a known intrinsic stdlib function) now in order to produce a literal array.

Swift SVN r22295
2014-09-26 04:22:00 +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
Doug Gregor
df33350219 Switch string interpolation protocol over to initializer requirements.
With this, we're now using initializer requirements rather than
"convertFromXXX" requirements everywhere, addressing the rest of
rdar://problem/18154091. r22176 eliminated the performance penalty
that prevented this change from sticking earlier.



Swift SVN r22177
2014-09-22 20:17:55 +00:00
Doug Gregor
5c5cc998a1 Provide Fix-Its for the RawRepresentable interface change.
Calls to fromRaw are replaced with uses of the new failable
initializer init(rawValue:). Similarly, calls to toRaw are replaced
with uses of the rawValue property. Fixes rdar://problem/18357647.


Swift SVN r22164
2014-09-21 23:10:07 +00:00
Doug Gregor
82d7daf5fc Revert StringInterpolationConvertible back to class method requirements.
The initializer requirement is causing too much exponential behavior
in the constraint solver. We'll have to address that
first. Re-instating this change is tracked by rdar://problem/18381811.


Swift SVN r22080
2014-09-18 17:10:53 +00:00
Doug Gregor
f1e47a7b18 Switch string interpolation protocol over to initializer requirements.
With this, we're now using initializer requirements rather than
"convertFromXXX" requirements everywhere, addressing the rest of
rdar://problem/18154091.


Swift SVN r22078
2014-09-18 16:13:18 +00:00
Doug Gregor
3ebf5cb3da Switch the string literal protocols over to initializer requirements.
Swift SVN r22076
2014-09-18 15:48:42 +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
Doug Gregor
d42563291e Switch DictionaryLiteralConvertible over to an initializer requirement.
Swift SVN r22033
2014-09-17 19:42:31 +00:00
Doug Gregor
3972316d25 Switch ArrayLiteralConvertible over to an initializer requirement.
Swift SVN r22024
2014-09-17 17:46:26 +00:00
John McCall
b89f493378 Preserve implicitness when applying constraints to
subscript expressions.

Swift SVN r22018
2014-09-17 08:08:13 +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
Doug Gregor
6a19c1235e Convert FloatLiteralConvertible to initializers
Swift SVN r21992
2014-09-16 22:45:09 +00:00
Dmitri Hrybenko
fad578b304 stdlib: remove ArrayBonudType
Swift SVN r21991
2014-09-16 22:42:33 +00:00
Doug Gregor
4dca192b18 Switch IntegerLiteralConvertible over to initializers.
Swift SVN r21986
2014-09-16 21:59:15 +00:00
Doug Gregor
e23aa008e6 Switch CharacterLiteralConvertible over to an initializer requirement.
Swift SVN r21985
2014-09-16 21:59:11 +00:00
Doug Gregor
7f80e00d37 Swift NilLiteralConvertible to an initializer requirement
Swift SVN r21980
2014-09-16 20:43:35 +00:00
Doug Gregor
d93eaed9f7 Switch BooleanLiteralConvertible over to an initializer requirement.
Conforming to BooleanLiteralConvertible now requires

  init(booleanLiteral: Bool)

rather than

  static func convertFromBooleanLiteral(value: Bool) -> Self

This posed a problem for NSNumber's conformance to
BooleanLiteralConvertible. A class needs a required initializer to
satisfy an initializer requirement, but one cannot add a required
initializer via an extension. To that end, we hack the Clang importer
to import NSNumber's initWithBool with the name

  init(booleanLiteral:)

and add back the expected init(bool:) initializer in the
overlay. These tricks make NSNumber even harder to subclass, but we
don't really care: it's nearly impossible to do well anyway, and is
generally a Bad Idea.

Part of rdar://problem/18154091.

Swift SVN r21961
2014-09-15 23:59:30 +00:00
Doug Gregor
dd6c32cf3e Use ConstraintLocator::Member for members rather than ConstraintLocator::MemberRefBase.
Swift SVN r21920
2014-09-12 20:27:20 +00:00
Doug Gregor
43b6ed364a Thread constraint locators through opening of generic types.
Locators that refer to opened type parameters now carry information
about the source location where we needed to open the type, so that
(for example) we can trace an opened type parameter back to the
location it was opened. As part of this, eliminate the "rootExpr"
fallback, because we're threading constraint locators everywhere.

This is infrastructural, and should be NFC.

Swift SVN r21919
2014-09-12 20:27:19 +00:00
Devin Coughlin
0d7996f4ee Add parsing of availability query expressions (#os(...))
This patch adds a new 'pound_os' token, a new case for it in parseExprPostfix, and parsing of platform version constraints, e.g., OSX >= 10.10. 

It also adds enough type checking and SILGen to get the parsing tests to run without triggering "Unimplemented" assertions.


Swift SVN r21865
2014-09-11 02:59:05 +00:00
Joe Pamer
ede74dd90e When solving for call witness argument conversions, post diagnostics in the case of failures rather than raise an assertion. This addresses crash suite issue 040. (rdar://problem/18233081)
Swift SVN r21852
2014-09-10 22:28:03 +00:00
Joe Pamer
9bbf4ac5fe Improve diagnostic so as not to mystify users.
Swift SVN r21824
2014-09-10 01:52:07 +00:00
Joe Pamer
acce45bdc8 Lock down existential metatype to metatype coercions. Since they're currently unsupported, we'll display a semantic error rather than crash.
This addresses crash suite scenarios 011 and 013. (rdar://problem/17777218, rdar://problem/18232728)

Swift SVN r21822
2014-09-10 00:54:34 +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
eea25df96e Allow construction of a final class via a metatype using a non-required initializer rdar://problem/18154062.
Swift SVN r21737
2014-09-05 04:07:02 +00:00
Chris Lattner
5a8345905b Generalize some overly conservative type checker and verifier code:
when type checking a reference to an optional requirement (producing 
a dynamic_member_ref), downcast the receiver to the protocol in question
instead of to AnyObject.  At SILGen time, we do an unchecked_ref_cast anyway,
and this is a more general solution to the problem it is trying to solve.



Swift SVN r21515
2014-08-28 05:25:55 +00:00
Chris Lattner
525531bf5b silgen doesn't support partial method application of protocol methods, but
sema let them slip through if classbound.  Reject them until silgen handles
them, fixing <rdar://problem/18158354> partial application of protocol method crashes the compiler in silgen


Swift SVN r21514
2014-08-28 05:01: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
Dave Abrahams
f3ac09497d Store ASCII string literals as UTF8
Fixes <rdar://problem/16740011> ASCII string literals produce UTF16
Strings

Swift SVN r21419
2014-08-22 19:05:15 +00:00
Doug Gregor
7f9e49be37 Diagnose conditional downcasts to CoreFoundation metatypes.
The last part of <rdar://problem/18088474>.


Swift SVN r21403
2014-08-22 04:52:30 +00:00
Doug Gregor
efb9a39d78 Diagnose conditional casts to CF types; they'll always succeed.
Part of <rdar://problem/18088474>.

Swift SVN r21388
2014-08-21 23:13:02 +00:00
Doug Gregor
397f4a9888 Remove user-defined conversions from the type checker.
Nobody is using this crufty old feature now, so remove it and the
complexity that goes along with it.

Swift SVN r21379
2014-08-21 21:59:49 +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
1a8f5e1eec Remove -enable-optional-lvalues and its language option; they're always on anyway.
Swift SVN r21356
2014-08-21 15:53:31 +00:00