Commit Graph

7976 Commits

Author SHA1 Message Date
Slava Pestov
5cbaa9d7a6 Sema: When simplifying types, build ErrorTypes for failed conformance lookups 2017-01-28 18:35:23 -08:00
swift-ci
503baaf285 Merge pull request #7084 from DougGregor/shrink-less-aggressively 2017-01-27 15:37:17 -08:00
Doug Gregor
545c43f500 [Type checker] Don't shrink() arithmetic expressions of literals.
Shrinking such expressions will immediately restrict the solution set
to the default literal types (Int or Double), causing later solutions
to fail. Fixes rdar://problem/30220565.
2017-01-27 14:48:12 -08:00
Brian King
e9e237871c Fix a crash with a nil pattern returned from StmtConditionElement 2017-01-27 15:37:19 -05:00
Jordan Rose
7c8117301a In Swift 3 mode, allow "tuple unsplatting" in certain cases. (#7077)
Swift 3.0 allowed constructing an enum or calling a function-typed
property with multiple arguments even when a single argument of tuple
type was expected. Emulate that in Swift 3 mode by wrapping in an
extra level of parentheses when the situation comes up.

Last vestiges of fallout from SE-0110. Hopefully last, anyway. A nice
follow-up to this commit might be to /warn/ in Swift 3 mode when this
happens.

rdar://problem/30171399
2017-01-27 11:19:07 -08:00
Jordan Rose
1cf1961fc7 Merge pull request #7007 from jrose-apple/accessor-argument-labels
[Importer] Preserve argument labels even for accessors.
2017-01-27 11:18:44 -08:00
Brian King
3c4fec8d87 Make sure braces are consistently cuddled 2017-01-26 21:52:19 -05:00
swift-ci
48029307ee Merge pull request #7065 from DougGregor/bridge-then-convert 2017-01-26 15:08:56 -08:00
Brian King
b389fc3ef5 Code review feedback 2017-01-26 18:00:00 -05:00
Doug Gregor
fab0371eba [Type checker] Allow bridging followed by a conversion to existential.
When I refactored the handling of bridging conversions (e.g.,
valueType as? NSClassType), I broke the path that performed a bridging
conversion followed by a conversion to an existential, e.g.,
"some-bridged-value-type as CVarArg". Reinstate such use cases.

Fixes rdar://problem/30195862.
2017-01-26 14:26:11 -08:00
Jordan Rose
6fed3d1edf Merge pull request #6990 from jrose-apple/available-is-better-than-unavailable
[ClangImporter] Prefer available enum elements over unavailable ones.
2017-01-26 11:52:36 -08:00
John McCall
98aa9f3b04 Merge pull request #7047 from rjmccall/track-access-dc-in-constraints
Track the actual DC of a member access in the constraint system.
2017-01-26 14:09:32 -05:00
Joe Groff
b03dfab3b4 Merge pull request #7017 from jckarter/discard-tautological-type-witness-candidates
Sema: Discard associated type inference candidates that are obviously tautological or divergent.
2017-01-26 08:37:49 -08:00
Brian King
d835167485 Flag global variables declared in guard constructs 2017-01-26 09:59:51 -05:00
Brian King
36e36a1551 Align TLCD checking better with existing approach 2017-01-26 09:59:27 -05:00
John McCall
39b65f49a0 Track the actual DC of a member access in the constraint system.
Without this, CSGen/CSSimplify and CSApply may have differing
opinions about whether e.g. a let property is settable, which
can lead to invalid ASTs.

Arguably, a better fix would be to remove the dependency on the
exact nested DC.  For example, we could treat lets as settable
in all contexts and then just complain later about invalid
attempts to set them.  Or we could change CSApply to directly
use the information it already has about how an l-value is used,
rather than trying to figure out whether it *might* be getting set.
But somehow, tracking a new piece of information through the
entire constraint system seems to be the more minimal change.

Fixes rdar://29810997.
2017-01-26 00:14:21 -05:00
Doug Gregor
9b99d26d0e Merge pull request #7029 from huonw/protocol-self-signature
[AST] Introduce the notion of a protocol requirement signature.
2017-01-25 20:55:52 -08:00
Jordan Rose
25e40d0a57 Use interface types when checking #keyPath. (#7028)
This avoids a crash when the path refers to a property in another
Swift module.

https://bugs.swift.org/browse/SR-3714
2017-01-25 19:29:42 -08:00
Mark Lacey
c57dc58dab Revert "Disallow conversions from IUOs to extistentials."
Revert 7c665c105b because it results in a
much worse source compatibility regression than the one it was intended
to fix.

The problem is that it results in force-unwrapping IUOs, which can lead
to cases where we prefer type-checking solutions that choose methods
over properties where we used to choose properties. So for example a
collection literal like [x] will result in a collection with a method
named 'x' in it rather than a property named 'x'.

I'll be looking at other solutions which fix both the original
compatibility regression as well as retain the behavior in the new test
added here.

Fixes SR-3715 and rdar://problem/30176166.
2017-01-25 17:04:18 -08:00
Huon Wilson
a964b6ad78 [AST] Introduce the notion of a protocol requirement signature.
This is a generic signature that stores exactly the requirements that a
protocol decl introduces, not letting them be implied by the Self :
Protocol requirement, nor storing any requirements introduced by the
protocols requirements.

Specifically, suppose we have

    protocol Foo {}
    protocol Bar {}

    protocol Baz {
        associatedtype X : Foo
    }
    protocol Qux: Baz {
        associatedtype X : Bar
    }

The normal generic signature and (canonical) protocol requirement
signature of `Baz` will be, respectively

    <Self where Self : Baz>
    <Self where Self : Baz, Self.X : Foo>

And for `Qux`, they will be:

    <Self where Self : Qux>
    <Self where Self : Qux, Self : Baz, Self.X : Bar>

Note that the `Self.X : Foo` requirement is not listed.

For the moment, this is unused except for `-debug-generic-signatures`.
2017-01-25 16:06:50 -08:00
Jordan Rose
abb88f9492 [Verifier] Hack: Don't verify loaded modules in SIL mode.
It turns out we've been loading decls from the ClangImporter when
parsing SIL forever; when we do that without a TypeChecker around, the
imported decls aren't always set up correctly (because the TypeChecker
is supposed to do part of that work). For now, just don't verify
imported declarations in loaded modules when parsing SIL.
2017-01-25 13:44:25 -08:00
Brian King
5d6bd40b46 Move invocation of the top level diagnostics 2017-01-25 16:03:42 -05:00
Joe Groff
bbaa7f7163 Sema: Discard associated type inference candidates that are obviously tautological or divergent.
When considering an implementation from a protocol extension as a possible witness to a protocol requirement, and using that witness to try to infer the protocol's associated types, we would sometimes consider `AssocType == ConformingType.AssocType` as a potential solution, even though this is a tautology; we would subsequently mark the potential solution as failed (because ConformingType.AssocType doesn't exist yet; it doesn't conform to any protocols) even when the witness is necessary to infer other associated types. Worse, this would introduce an order dependency when certain potential witnesses were visited before the right associated types were inferred. Fix this by filtering out useless tautological inferred witnesses before trying to validate them for conforming to the necessary requirements. Fixes rdar://problem/29954938.
2017-01-25 11:23:03 -08:00
Brian King
6091cda408 Run the VarDeclUsageChecker on top level declarations 2017-01-24 22:50:28 -05:00
Doug Gregor
200d7d77f1 [Archetype builder] Infer same-type constraints for same-named associated types.
When two associated types with the same name are on the same dependent
type T, introduce a same-type constraint between the the corresponding
potential archetypes. This eliminates ordering dependencies in the
archetype builder.

Fixes the reduced test case from rdar://problem/23149063, but doesn't
fully address the idea that we should be tracking associated type
redeclarations in a meaningful way.
2017-01-24 19:36:44 -08:00
Slava Pestov
4148079a9e Sema: Change diagnostics to not talk about 'materializable' types
This is not a term we want users to have to care about.
2017-01-23 23:54:50 -08:00
Slava Pestov
55c0e7401c Sema: Fix crash when @noescape or @autoclosure is applied to parameter
In Swift 3, these attributes were changed to apply to the type,
and not the parameter. If they appear on the parameter, we would
go down a diagnostic code path.

When checking a generic function signature, we might not have a
contextual type for the parameter yet, so bail out instead of
crashing.
2017-01-23 23:54:50 -08:00
Slava Pestov
1d1517ff06 Sema: Narrow-ish fix for issue with varargs and anonymous closure arguments
This still doesn't work in a number of cases, but fixes a case
that used to work in Swift 3.0 which was affecting the Dollar.swift
library.

Fixes <rdar://problem/29007725>.
2017-01-23 22:46:54 -08:00
Jordan Rose
c054713f69 Adopt llvm::function_ref in availability checking.
The function is a callback parameter that does not escape, therefore
function_ref is the right choice.

No functionality change.
2017-01-23 15:34:08 -08:00
Doug Gregor
cc28774a40 Merge pull request #6973 from colinhowell/SR-3668
[CSGen] Fix for exponential dictionary literal behavior in SR-3668
2017-01-23 14:50:16 -08:00
practicalswift
a9d6d8938c [gardening] Fix recently introduced typos 2017-01-22 20:40:45 +01:00
Colin Douglas Howell
fb235125fb [CSGen] Fix for exponential dictionary literal behavior in SR-3668
In ConstraintGenerator::visitDictionaryExpr(), if the dictionary_expr has a
contextual type which is also a dictionary type, use it to add a new type
constraint for each of the dictionary_expr's elements. This has a huge effect
on solver performance for dictionary literals with elements that have
overloading. The approach closely follows that used in
ConstraintGenerator::visitArrayExpr(), which has included a similar
optimization (from git commit a22b391) for over two and a half years.

I've also added a couple of new test cases which would trigger the bug without
this fix.
2017-01-21 23:47:01 -08:00
practicalswift
f74763facb [gardening] Use consistent argument naming 2017-01-21 11:08:27 +01:00
Slava Pestov
f154b6a314 Merge pull request #6944 from JaSpa/dont-remove-too-much
Fix the fixit for specialized non-generic types
2017-01-20 14:10:54 -08:00
Janek Spaderna
5b35f451da Fix the fixit for specialized non-generic types
If a non-generic type is specialized a fixit is provided to remove the
generic arguments. The DiagnosticEngine turns a SourceRange into a
CharSourceRange by re-lexing the token at `SourceRange::End`.

The problem solved by this change occurs, if the non-generic type is
nested in an other generic type like this:

let a: GenericType<NongenericType<NongenericType>>

The lexer doesn't know that the closing angle brackets are individual
tokens leading to the removal of both of them. We can work around this
by directly specifying the start and end locations.
2017-01-20 16:49:45 +01:00
Slava Pestov
0c294314d0 Sema: Diagnose invalid initializers on resilient types
Value type initializers must initialize stored properties directly
if they do not delegate to another initializer via self.init().

Since direct stored property access is not permitted for resilient
value types from outside their resilience domain, this means that
such initializers are prohibited in two cases:

- If the initializer is defined in an extension from outside the
  value type's resilience domain

- If the initializer is public and @_inlineable, since it might get
  inlined outside the value type's resilience domain

Right now, such initializers cannot *assign* to self either;
I filed <https://bugs.swift.org/browse/SR-3686> to track the issue.
2017-01-20 01:22:51 -08:00
Slava Pestov
ec028235be Sema: Fix incorrect diagnostic when referencing members of a @_versioned protocol
Protocol members can be directly referenced from protocol extensions
and generic functions. Since protocol members do not have accessibility
distinct from the protocol itself, ignore them, since they won't carry
the @_versioned attribute.

While workign on this I uncovered an interesting bug where we allow
members of protocol extensions to be more accessible than the protocol
itself, but then we give the symbols hidden visibility at the SIL level
anyway.

I filed <https://bugs.swift.org/browse/SR-3684> to track this issue.
2017-01-20 01:22:50 -08:00
Slava Pestov
ae35e4e069 Sema: Diagnose @_versioned on protocol requirements
Protocol requirements do not have accessibility distinct from that
of the protocol itself, and this also applies to @_versioned.
2017-01-20 01:22:50 -08:00
Slava Pestov
d6c857259d Sema: Diagnose @_fixed_layout when applied to internal types
This attribute is only meaningful for versioned and public types;
private and internal types are always fixed-layout.
2017-01-20 01:22:50 -08:00
swift-ci
41539284eb Merge pull request #6924 from graydon/rdar-28815071-fixit-to-narrow-availability-check 2017-01-20 01:22:28 -08:00
Slava Pestov
c86b5ae427 AST: Header file gardening - include what you use 2017-01-19 20:07:06 -08:00
Slava Pestov
8de0ca54e5 Sema: Merge the two implementations of simplifyType()
ConstraintSystem::simplifyType() replaced types with their fixed types
from the global map.

Solution::simplifyType() replaced types with their fixed types from the
current bindings.

There were some minor differences between the two, and some dead code.
2017-01-19 20:07:06 -08:00
Slava Pestov
10e292bfdf Sema: Make it explicit that the 'tuple splat' diagnostic is only for Swift 3 compatibility mode 2017-01-19 20:07:06 -08:00
Slava Pestov
599021bf7b Sema: Simplify interface of Solution::computeSubstitutions()
Instead of passing the original type and DeclContext, we just
need a GenericSignature.
2017-01-19 20:07:05 -08:00
Slava Pestov
a22b46244c Sema: Don't canonicalize base type in member lookup
We would lose ParenType sugar in function types as a result.

Fixes part of <rdar://problem/29739905>.
2017-01-19 20:07:05 -08:00
Jordan Rose
d79fc62394 Don't try to infer @objc for non-getter/setter accessors (#6926)
These are never part of an @objc protocol, so we shouldn't bother
looking for them and certainly shouldn't expect them to be there.
Fixes a crash introduced in 1f2121377.

rdar://problem/30101703
2017-01-19 19:28:04 -08:00
Slava Pestov
cf5a88aa49 Merge pull request #6923 from slavapestov/fix-assoc-type-inference-regression
Sema: Teach getReferencedAssociatedTypes() to look through typealiases
2017-01-19 17:21:53 -08:00
Graydon Hoare
d94b76f396 Suggest narrowing an exising availability context, when feasible. 2017-01-19 16:29:16 -08:00
Slava Pestov
7370523386 Merge pull request #6910 from xedin/crasher-28636
[Diagnostics] Don't attempt member lookup if base type has unresolved type parameters
2017-01-19 15:55:09 -08:00
Slava Pestov
0926773c69 Sema: Teach getReferencedAssociatedTypes() to look through typealiases
Now that NameAliasTypes desugar to interface types, it is possible
to have a protocol requirement type contain a NameAliasType which
contains an associated type:

protocol P {
  associatedtype Element
  typealias Elements = [Element]

  func process(elements: Elements)
}

In Swift 3, the typealias would be desugared at name lookup time
in this case, but this is no longer the case, as a result associated
type inference stopped working in this example.

Fixes <https://bugs.swift.org/browse/SR-3641>.
2017-01-19 14:39:03 -08:00