Commit Graph

4518 Commits

Author SHA1 Message Date
Doug Gregor
c45c5d4bd1 Stop performing silly, ridiculous hasTypeWitness checks.
Swift SVN r27638
2015-04-23 18:20:56 +00:00
Doug Gregor
b32a62585b Make TypeChecker::resolveTypeWitness() slightly more lazy.
If we can resolve just this type witness via name lookup, do so. NFC

Swift SVN r27637
2015-04-23 18:20:54 +00:00
Dmitri Hrybenko
c11cf9cbc0 Use std::make_tuple instead of the libc++ extension
Swift SVN r27629
2015-04-23 06:37:06 +00:00
Joe Groff
b1098da61f Sema: Relax this assertion.
It causes a crash in test/attr/attr_objc.swift when CFunctionPointer is deprecated.

Swift SVN r27627
2015-04-23 04:24:48 +00:00
Doug Gregor
126e404fe5 Reimplement inference of type witnesses with a separate non-recursive pass.
Inference of type witnesses for associated types was previously
implemented as part of value witness matching in the constraint
solver. This led to a number of serious problems, including:
  - Recursion problems with the solver hunting for a type witness,
  which triggers more attemts to match value witnesses...
  - Arbitrarily crummy attempts to break the recursion causing
  type-check failures in fun places.
  - Ordering dependencies abound: different results depending on which
  value witnesses were satisfied first, failures because of the order
  in which we attempted to infer type witnesses, etc.

This new implementation of type witness inference uses a separate pass
that occurs whenever we're looking for any type witness, and solves
all of the type witnesses within a given conformance
simultaneously. We still look at potential value witnesses to infer
type witnesses, but we match them structurally, without invoking the
constraint solver.

There are a few caveats to this implementation:
  * We're not currently able to infer type witnesses from value
  witnesses that are global operators, so some tricks involving global
  operators (*cough* ~> *cough*) might require some manually-specified
  type witnesses. Note that the standard library doesn't include any
  such cases.

  * Yes, it's another kind of solver. At simple one, fortunately.

On the other hand, this implementation should be a big step forward:
  * It's far more predictable, order-invariant, and non-recursive.
  * The diagnostics for failures to infer type witnesses have
  improved.

Fixes rdar://problem/20598513.

Swift SVN r27616
2015-04-23 00:20:05 +00:00
Joe Groff
676073ac1d Provide @convention migration fixits.
Warn and fix '@thin' -> '@convention(thin)' and '@objc_block' -> '@convention(block)'.

Swift SVN r27614
2015-04-22 23:50:30 +00:00
Joe Groff
40b0fcfe72 Remove the @cc attribute.
We never exposed this to Swift users, and it's now unused by SIL, so we can remove it.

Swift SVN r27613
2015-04-22 23:16:26 +00:00
Luqman Aden
ce4bff5645 Frontend: Allow passing .sil as -primary-file along with other .sib as input.
Swift SVN r27612
2015-04-22 22:53:18 +00:00
Joe Groff
fd138326ba SIL: Reject '@cc', '@thin', and '@objc_block' in SIL.
Since it's an internal interface, there's no need for migration in SIL.

Swift SVN r27610
2015-04-22 22:40:08 +00:00
Joe Pamer
d4e744b2ed Use "isa" instead of "dyn_cast".
Swift SVN r27606
2015-04-22 21:35:57 +00:00
Joe Pamer
220c92a09b Revert "Revert "A couple of 'throws' inference fix-ups:""
This reverts commit r27576.

(In some cases of catastrophic error recovery, ctor types may still be null during constraint solving, so it was wrong of me to assume otherwise.)

Swift SVN r27599
2015-04-22 20:34:05 +00:00
Slava Pestov
af5fb8a7b0 Fix conformances when calling protocol extension method with constraints
We need to use the constrants from the extension, otherwise we might
pass in the wrong witness method table at the call site, among other
problems.

Fixes rdar://problem/20532214.

Swift SVN r27585
2015-04-22 17:18:45 +00:00
Slava Pestov
2e083fd8ed ConstraintSystem.h: Fix grammar in doc comment
Swift SVN r27583
2015-04-22 17:18:43 +00:00
Dmitri Hrybenko
4229e8a14f Revert "A couple of 'throws' inference fix-ups:"
This reverts commit r27568 to unblock the buildbot.  It regressed three
compiler crashers:

    Swift :: compiler_crashers_fixed/0367-llvm-errs.swift
    Swift :: compiler_crashers_fixed/1769-getselftypeforcontainer.swift
    Swift :: compiler_crashers_fixed/1916-swift-nominaltypedecl-getdeclaredtypeincontext.swift

Swift SVN r27576
2015-04-22 08:42:21 +00:00
Joe Pamer
70fd1d6360 A couple of 'throws' inference fix-ups:
- When inferring 'throws' for a closure function type, look inside of catchless do blocks for 'try' expressions.
- When simplifying overload constriants for applications of throwing initializers, the bound member type of the initializer should also be marked as throwing.
  (Not doing so would cause us to incorrectly reject the overload.)

Swift SVN r27568
2015-04-22 06:39:39 +00:00
Joe Groff
3f241bb80a Sema: Handle NSError not being found during type checking better.
Fix crashes when type-checking ErrorType dynamic casts when NSError isn't available. Split the ErrorType execution tests into separate units for bridging and non-bridging, so that we get better coverage of this situation in both ObjC and non-ObjC builds. Fixes rdar://problem/20585210.

Swift SVN r27556
2015-04-22 03:49:01 +00:00
Devin Coughlin
721d1870aa [Sema] Change Fix-It for availability version check to include '*'
Update the Fix-It thats suggests adding a #available() check to include the
wildcard query '*', which is now required. We were omitting it before, which
meant that after applying this Fix-It the developer would get a second Fix-It
to add the '*'.

rdar://problem/20601569

Swift SVN r27514
2015-04-21 01:13:30 +00:00
Doug Gregor
750566b249 Implicitly create type declarations for inferred associated type witnesses.
The type checker (and various other parts of the front end) jump
through many hoops to try to cope with the lack of a proper
declaration for an inferred type witness, causing various annoying
bugs. Additionally, we were creating implicit declarations for
derived/synthesized witnesses, leading to inconsistent AST
representations. This ch

Note that we'll now end up printing the inferred type aliases for type
witnesses, which represents a reversal of the decision that closed
rdar://problem/15168378. This result is more consistent.

Now with a simpler accessibility computation.

Swift SVN r27512
2015-04-21 00:21:55 +00:00
John McCall
3d3f1a7d7e Parsing/AST/Sema support for rethrows, and fix bugs with
throws/rethrows override and conformance checking.

Swift SVN r27508
2015-04-20 23:39:12 +00:00
Doug Gregor
9e68a5761a Revert "Implicitly create type declarations for inferred associated type witnesses."
This reverts r27487; it's breaking one of the bots.

Swift SVN r27505
2015-04-20 22:56:50 +00:00
Doug Gregor
78cc7b75f8 Basic support for typealiases in protocol extensions.
Handle substitutions properly when a typealias declared in a protocol
extension is used to satisfy an associated type requirement. Fixes
rdar://problem/20564605.

Swift SVN r27490
2015-04-20 20:19:03 +00:00
Chris Willmore
4330f2a8a9 Instead of replacing ObjectLiteralExpr in CSApply, set its semantic expression (a la InterpolatedStringLiteralExpr).
Swift SVN r27488
2015-04-20 19:41:10 +00:00
Doug Gregor
e907845d3e Implicitly create type declarations for inferred associated type witnesses.
The type checker (and various other parts of the front end) jump
through many hoops to try to cope with the lack of a proper
declaration for an inferred type witness, causing various annoying
bugs. Additionally, we were creating implicit declarations for
derived/synthesized witnesses, leading to inconsistent AST
representations. This ch

Note that we'll now end up printing the inferred type aliases for type
witnesses, which represents a reversal of the decision that closed
rdar://problem/15168378. This result is more consistent.

Swift SVN r27487
2015-04-20 18:10:57 +00:00
Chris Willmore
d4db635e3d Add object literal syntax and _{Color,Image}LiteralConvertible protocols
Add syntax "[#Color(...)#]" for object literals, to be used by
Playgrounds for inline color wells etc. The arguments are forwarded to
the relevant constructor (although we will probably change this soon,
since (colorLiteralRed:... blue:... green:... alpha) is kind of
verbose). Add _ColorLiteralConvertible and _ImageLiteralConvertible
protocols, and link them to the new expressions in the type checker.
CSApply replaces the object literal expressions with a call to the
appropriate protocol witness.

Swift SVN r27479
2015-04-20 12:55:56 +00:00
Chris Lattner
25cb47879b Have Sema create an implicit "return" at the end of constructors if there isn't one
already. NFC right now, but this allows us to simplify SILGen.

It would also be reasonable to do this in the parser instead of sema, and would also
be reasonable to do for deinit and normal void-returning functions as well, thoughts
welcome.


Swift SVN r27468
2015-04-19 21:16:35 +00:00
Doug Gregor
2fdd8ed6e1 Delay protocol-conformance diagnostics until the conformance is fully checked.
When we're checking for a particular witness in a protocol conformance
because the result is needed elsewhere, capture the diagnostic we
would emit and then store it in the ASTContext. We will emit these
diagnostics when doing the full check of the conformance. Addresses
the rest of rdar://problem/20564378.

Swift SVN r27449
2015-04-18 05:03:31 +00:00
Ben Langmuir
48cce21bdc Filter out completions from unusable protocol extensions
... and add a bunch more tests. Thanks to Doug for help with the
typechecker bits!

rdar://problem/20305938

Swift SVN r27444
2015-04-17 22:41:56 +00:00
Devin Coughlin
31413bb01c [Sema] Honor -disable-availability-checking flag for protocol conformances
Suppress API availability diagnostics about protocol conformances when the
-disable-availability-checking frontend flag is passed. We weren't
checking the flag before, so there was no way to disable this diagnostic.

I've added a test to make sure this flag is honored. We can remove the test when
we remove the flag, which is temporary.

Swift SVN r27439
2015-04-17 20:04:10 +00:00
Joe Pamer
006c182c13 Begin inferring throwing function types for closures. (There's more work to do here - hence the thin tests - but I need to investigate a couple of sema bugs before moving forward.)
Swift SVN r27438
2015-04-17 19:06:52 +00:00
Doug Gregor
69718f77fa When failing to find a suitable type witness, always record ErrorType.
Fixes the crash in rdar://problem/20564378. In these cases, we end up
swallowing some diagnostics. That will be addressed in a subsequent
commit.

Swift SVN r27436
2015-04-17 18:11:35 +00:00
Joe Groff
be7c339af8 Type checker: Increase the score of metatype-to-object conversions.
Metatype-to-metatype conversions should be favored.

Swift SVN r27415
2015-04-17 05:30:38 +00:00
Joe Groff
d46afe513e AnyObject is a BridgeableObjectType even if it's not @objc.
Swift SVN r27412
2015-04-17 05:30:29 +00:00
Joe Groff
852a701051 Type checker: Allow implicit conversions from existential metatypes to more general ones.
An existential composition protocol<P,Q>.Type is convertible to P.Type is convertible to Any.Type.

Swift SVN r27410
2015-04-17 05:30:24 +00:00
Joe Groff
92636a4a64 Type checker: Allow 'AnyObject: AnyObject' self-conformance even when AnyObject isn't @objc.
It can still trivially witness itself, since being a class is evidence enough.

Swift SVN r27408
2015-04-17 05:30:18 +00:00
Joe Groff
dfc57e6f01 Type checker: Don't attempt metatype-to-object conversions if ObjC interop is disabled.
The post-type-checking error that was here is arguably better QoI, but it is causing ambiguities that break the non-ObjC-compatible build in the stdlib. We shouldn't even attempt these conversions if there's no runtime support to back them up.

Swift SVN r27407
2015-04-17 05:30:16 +00:00
Joe Groff
58660ec6ba PrintAsObjC: Support for SIMD types.
Splat out a bunch of typedefs for the small vector types we want to support, and map the SIMD.* types to them.

Swift SVN r27385
2015-04-16 22:07:09 +00:00
Joe Groff
47eedc3c08 Sema: Consider SIMD types as representable in ObjC.
Corresponding PrintAsObjC and GenClangType parts to follow.

Swift SVN r27384
2015-04-16 22:07:03 +00:00
Doug Gregor
7687be3a9a Fix another bogus use of ProtocolConformance::isComplete().
Swift SVN r27382
2015-04-16 21:22:11 +00:00
Doug Gregor
f554fb9680 Member type lookup: when we have a type witness, use it.
This doesn't actually break the circular type-checking issues with
have with associated type inference, but it makes them less
painful. Fixes rdar://problem/20549165.

While here, and as a test, remove the _prext_underestimateCount
workound from the library. _CollectionDefaultsType now refines
_SequenceDefaultsType.

Swift SVN r27368
2015-04-16 19:55:53 +00:00
Doug Gregor
4e0e32197f Extend 'availability' attribute with an unconditional 'deprecated' option.
Allow an unversioned 'deprecated' attribute to specify unconditional
deprecation of an API, e.g.,

  @availability(*, deprecated, message="sorry")
  func foo() { }

Also support platform-specific deprecation, e.g.,

  @availability(iOS, deprecated, message="don't use this on iOS")
  func bar() { }

Addresses rdar://problem/20562871.

Swift SVN r27355
2015-04-16 06:36:45 +00:00
Argyrios Kyrtzidis
707394aea8 [AST] Refactor implementation for ValueDecl::getSatisfiedProtocolRequirements().
Move the map that keeps track of conforming decl -> requirement from ASTContext
to a nominal type's ConformanceLookupTable, and populate it lazily.

This allows getSatisfiedProtocolRequirements() to work with declarations from module files.
Test on the SourceKit side.

Part of rdar://20526240.

Swift SVN r27353
2015-04-16 06:23:56 +00:00
Argyrios Kyrtzidis
5f6d091efc [AST] Keep track of the type decl that the type witness came from, for protocol conformances.
Swift SVN r27352
2015-04-16 06:23:54 +00:00
Doug Gregor
921855ee0d Revert "Extend 'availability' attribute with an unconditional 'deprecated' option."
This reverts r27339; it broke an iOS test.

Swift SVN r27343
2015-04-16 03:36:40 +00:00
Doug Gregor
b4b5dbb5d8 Extend 'availability' attribute with an unconditional 'deprecated' option.
Allow an unversioned 'deprecated' attribute to specify unconditional
deprecation of an API, e.g.,

  @availability(*, deprecated, message="sorry")
  func foo() { }

Also support platform-specific deprecation, e.g.,

  @availability(iOS, deprecated, message="don't use this on iOS")
  func bar() { }

Addresses rdar://problem/20562871.

Swift SVN r27339
2015-04-15 23:59:20 +00:00
Nadav Rotem
f2169f8103 Silence a few more warnings in Release builds.
Swift SVN r27334
2015-04-15 21:38:23 +00:00
Joe Groff
e4e0f35aed IRGen: Implement an @_alignment attribute.
This is an internal-only affordance for the numerics team to be able to work on SIMD-compatible types. For now, it can only increase alignment of fixed-layout structs and enums; dynamic layout, classes, and other obvious extensions are left to another day when we can design a proper layout control design.

Swift SVN r27323
2015-04-15 17:23:30 +00:00
Argyrios Kyrtzidis
3eceeba976 [Sema] Associate typealias decls in concrete types with the associated type decls they are conforming to.
Test case on the SourceKit side.
Part of rdar://20526240.

Swift SVN r27316
2015-04-15 14:47:02 +00:00
John McCall
6d2326f08a Test (and fix) some simple calls to foreign-error methods.
Swift SVN r27296
2015-04-14 23:52:53 +00:00
Doug Gregor
41ae48b22e Start parsing 'throws' on initializers.
Introduce basic validation for throwing @objc initializers, e.g., a
failable @objc initializer cannot also be throwing. However,
Objective-C selector computation is broken.

Swift SVN r27292
2015-04-14 22:52:29 +00:00
Doug Gregor
27f108522d Allow an explicit @objc(selector) to indicate where the error parameter goes.
For a throwing @objc method, we place the error parameter just before
the last parameter of (possibly-optional) function type. Allow this
default to be overridden with an explicit @objc(selector) attribute,
which can contain an "error" selector piece to indicate where the
error parameter goes (or an "Error" word suffix on the first selector
piece to put the error argument at the beginning).

Swift SVN r27278
2015-04-14 16:24:26 +00:00