Commit Graph

7976 Commits

Author SHA1 Message Date
Doug Gregor
447dce6c1f Merge pull request #9004 from itaiferber/swift-archival-serialization
Swift Archival & Serialization API
2017-04-28 20:02:33 -07:00
Robert Widmann
2a7eee86fc Merge pull request #8908 from CodaFi/space-engine
Redo Exhaustiveness Analysis
2017-04-28 21:28:31 -04:00
Graydon Hoare
cd48479d14 Merge pull request #9110 from graydon/grab-bag-of-metrics
Add an assortment of new "always-on" metrics.
2017-04-28 16:59:09 -07:00
Graydon Hoare
b5292f04f8 Add an assortment of new "always-on" metrics. 2017-04-28 13:56:13 -07:00
Slava Pestov
3130c3cbd7 AST: Remove an overload of GenericSignature::getSubstitutions() 2017-04-28 13:26:02 -07:00
Doug Gregor
7be3a142f9 Merge pull request #9093 from DougGregor/warn-unavailable-witnesses
[Type checker] Warn about unavailable witnesses used to satisfy a requirement
2017-04-28 10:20:59 -07:00
Robert Widmann
1dfab98931 Look through parens to the semantic pattern below 2017-04-28 02:33:09 -04:00
Robert Widmann
39494b2ba2 Rearrange test code for exhaustiveness 2017-04-28 02:06:39 -04:00
Robert Widmann
42c59554a0 Introduce the Space Engine
Implement exhaustiveness checking in Sema with rich error messages.  The
algorithm used is a variant of the one described in Fengyun Liu's paper
"A Generic Algorithm for Checking Exhaustivity of Pattern Matching"
published in the EPFL conference, and Luc Maranget's seminal paper
"Warnings for Pattern Matching"

The Space Engine views pattern matching as a problem of projecting the
scrutinee of a pattern-match into a "Space", then iteratively
constructing a Space from the cases.  Taking the difference of this
master space and the covered spaces yields the "holes" left over or
reveals a completely covered space.

The algorithm also extends trivially to redundancy checks in patterns,
but that check is already implemented in SILGen and this algorithm does
not improve upon it.
2017-04-28 02:06:39 -04:00
Doug Gregor
9ebc4caa41 [Type checker] Warn about unavailable witnesses used to satisfy a requirement. 2017-04-27 22:40:21 -07:00
Slava Pestov
e3b68e7bdd Remove -enable-experimental-subclass-existentials staging flag 2017-04-27 20:46:37 -07:00
Slava Pestov
7a3f12f327 Sema: Small fix to get class property access working on subclass existentials
This is tested in the next commit. This code path is about to
get more cleanup shortly to fix a miscompile with class
existentials (not just subclass existentials; an old problem),
so I'm not too concerned with adding the new conditinals here.
2017-04-27 16:08:32 -07:00
Slava Pestov
e7d9d00119 Sema: Remove a bit of dead code from CSApply 2017-04-27 16:06:54 -07:00
Itai Ferber
4c2320724e Fix init(from:) required condition 2017-04-27 12:44:41 -07:00
Itai Ferber
3e6eb8f20a Derive encoding an empty container by default
struct X : Codable {} should generate an encode(to:) which encodes an
empty keyed container, not an encode(to:) which does nothing
2017-04-27 10:56:19 -07:00
swift-ci
b2d71ecc14 Merge pull request #9064 from DougGregor/typealias-infer-same-type-requirements 2017-04-26 22:44:29 -07:00
Mark Lacey
55f5afd039 Merge pull request #9043 from rudkx/remove-unused-argument
[Constraint solver] Remove unused function argument.
2017-04-26 15:57:13 -07:00
John McCall
7bb263161a Fix a semantic bug in CSApply's optional-to-optional application.
Implicit conversions from T?? to U?? would map nil to some(nil) instead of nil.
2017-04-26 17:24:17 -04:00
John McCall
338825e73d Fix the emission of r-value pointer conversions to delay the
conversions and extend lifetimes over the call.

Apply this logic to string-to-pointer conversions as well as
array-to-pointer conversions.

Fix the AST verifier to not blow up on optional pointer conversions,
and make sure we SILGen them correctly.  There's still an AST bug
here, but I'll fix that in a follow-up patch.
2017-04-26 14:15:44 -04:00
practicalswift
ab5aaeb359 Merge pull request #9001 from practicalswift/gardening-20170425
[gardening] Unused variables. Unused diagnostics. Namespace comments. Typos.
2017-04-26 09:28:24 +02:00
Mark Lacey
39deefaa02 [Constraint solver] Remove unused function argument. 2017-04-25 18:24:06 -07:00
swift-ci
a321dcc679 Merge pull request #9022 from DougGregor/solver-lvalue-optional 2017-04-25 17:52:38 -07:00
Doug Gregor
a5868a6148 [Constraint solver] Look through lvalue types when establish nil-convertibility.
When determining whether our inference of an optional type should add
a layer of optionality, look through lvalue types.
Fixes rdar://problem/31779785.
2017-04-25 17:04:22 -07:00
Doug Gregor
e858c553cb [GSB] Start inferring same-type requirements from inherited type declarations.
Infer same-type requirements among same-named associated
types/typealiases within inherited protocols. This is more staging; it
doesn't really have teeth until we stop wiring together these types as
part of lookup.
2017-04-25 16:13:48 -07:00
swift-ci
83ba94ba60 Merge pull request #9003 from DougGregor/rdar-31794932-part-deux 2017-04-25 13:27:01 -07:00
Itai Ferber
e2318392be Add CodingKey and *codable derived conformance
* Allow CodingKey conformance to be automatically derived for enums
  which have no raw type (with no associated values) and which have
  a raw type of String or Int.
* Allow Encodable and Decodable conformance to be automatically derived
  for classes and structs with Encodable/Decodable properties
* Add initial unit tests for verifying derived conformance
2017-04-25 13:13:35 -07:00
Doug Gregor
dd96aee1b1 [Type checker] Fix rethrow checking with a single argument label harder.
My original fix for rdar://problem/31794932 didn't work for generic
functions because it was checking in the unsubstituted interface
type. Check structurally instead. Fixes rdar://problem/31794932.
2017-04-25 12:37:32 -07:00
practicalswift
4ef5c6d840 [gardening] Remove unused variables 2017-04-25 21:03:41 +02:00
Slava Pestov
c3391afbea Sema: A composition consisting of a single class type is equivalent to the class itself
Otherwise, you can run into confusing behavior.
2017-04-25 01:32:44 -07:00
swift-ci
2f11ae3b37 Merge pull request #8977 from DougGregor/rethrow-single-arg-func 2017-04-24 15:44:25 -07:00
Doug Gregor
b07d9951e4 [Type checker] Handle 'rethrows' checks for single-parameter functions.
The throw-checking code wasn't properly coping with functions that
take a single, labeled argument, due to the longstanding lie that
pretends that functions take a tuple argument vs. zero or more
separate arguments. Here, the lie manifests as spurious "call can
throw, but is not marked as such" errors.

Fixes rdar://problem/31794932.
2017-04-24 14:48:54 -07:00
Jordan Rose
e575d2d5ba [ClangImporter] Error structs from enums are not imported decls.
Enums with the ns_error_domain attribute represent codes for NSError,
which means Swift developers will expect to interact with them in
terms of Error. SE-0112 improved bridging for these enums to generate
a struct with the following form:

    struct MyError: Error {
      @objc enum Code: RawRepresentable {
        case outOfMemory
        case fileNotFound
      }
      var userInfo: [NSObject: AnyObject] { get }
      static var outOfMemory: Code { get }
      static var fileNotFound: Code { get }
    }

where MyError.Code corresponds to the original MyError enum defined in
Objective-C. Until recently, both the enum and the synthesized struct
were marked as having the original enum as their "Clang node", but
that leads to problems: the struct isn't really ObjC-compatible, and
the two decls have the same USR. (The latter had already been worked
around.)

This commit changes the struct to be merely considered a synthesized
"external definition", with no associated Clang node. This meant
auditing everywhere that's looking for a Clang node and seeing which
ones applied to external definitions in general.

There is one regression in quality here: the generated struct is no
longer printed as part of the Swift interface for a header file, since
it's not actually a decl with a corresponding Clang node. The previous
change to AST printing mitigates this a little by at least indicating
that the enum has become a nested "Code" type.
2017-04-24 09:57:41 -07:00
Slava Pestov
07c189558c Sema: Improve the fixit for 'Self' in invalid places
In an extension of a nested type, the extended type must be
fully qualified.

Also clean up the diagnostic logic a little bit and centralize
it in diagnoseUnknownType().

Fixes <https://bugs.swift.org/browse/SR-4379>.
2017-04-23 01:10:40 -07:00
Slava Pestov
aaca0badf9 Sema: Diagnose invalid references to type alias members of unbound generic types
Consider the following setup:

struct GenericStruct<T> {
  typealias Dependent = T
  typealias Concrete = Int
}

We have no way to model 'GenericStruct.Dependent' in the AST, so the
reference would crash. Instead, produce a diagnostic suggesting to
insert generic parameters, like 'GenericStruct<Int>.Dependent'.

The reference 'GenericStruct.Concrete' is fine though, and should
not crash; add a test that it works.

Fixes <https://bugs.swift.org/browse/SR-4390>, <rdar://problem/31480755>.
2017-04-23 00:02:30 -07:00
Slava Pestov
39b697898a Sema: Fix for unbound generic type handling
Previously we prohibited unbound generics in the underlying
type of a typealias, but due to an oversight the check was
not performed when resolving a nested type.

So this worked:

struct Outer { struct Inner<T> {} }
typealias OuterInner = Outer.Inner
let _: OuterInner<Int> = Outer.Inner<Int>()

However it was easy to cause a crash this way by stating an
unbound generic type where one was not expected. Also,
unqualified types in a typealias did not get this treatment,
so the following did not work:

typealias MyOptional = Optional

Formalize the old behavior by allowing unbound generic types
in the underlying type of a typealias, while otherwise
prohibiting unbound references to nested types.
2017-04-23 00:02:29 -07:00
swift-ci
b95de36096 Merge pull request #8950 from DougGregor/ibaction-31776315 2017-04-22 22:40:34 -07:00
Doug Gregor
25ce6fa28c [Type checker] Fail more usefully if something synthesizes a bogus attribute.
No part of the compiler, including the Clang importer, should
synthesize an attribute that would fail early attribute
validation. When it happens, it would emit diagnostics with no
location information, which is really annoyingly hard to debug.

Instead, assert that this doesn't happen, i.e., both that the Clang
importer doesn't synthesize bogus attributes (as in the previous
commit) and that nothing synthesizes such attributes with empty source
location informations.

In non-asserting builds, just suppress the diagnostic.
2017-04-22 21:44:51 -07:00
Doug Gregor
facf1996b1 [Clang importer] Don't transfer IBAction attributes that don't make sense.
Fixes an error emitted on declarations imported from Objective-C,
rdar://problem/31776315.
2017-04-22 21:38:23 -07:00
Slava Pestov
9984194e3d Sema: Fix for name lookup from the where clause of a nested type extension
Normally name lookup from a where clause walks up to the parent
DeclContext, so it does not need to handle outer generic parameters
specially. But with an extension of a nested type, the outer
DeclContext is the source file, and the extension itself has a
chain of GenericParamLists linked by the OuterParameters field.
2017-04-22 20:30:36 -07:00
swift-ci
83908723d5 Merge pull request #8936 from DougGregor/multi-file-conformance 2017-04-21 23:12:46 -07:00
Doug Gregor
75e0bf7438 Mark conformances as "used" when the GenericSignatureBuilder needs them.
When the type checker forms a GenericSignatureBuilder to process
requirements, the GSB may look up concrete conformances. Route such
requests through TypeChecker::conformsToProtocol() so they can be
marked as used. This fixes multi-file scenarios where conformances
from another file might be used only in a generic signature in the
primary file, e.g., rdar://problem/31759258.
2017-04-21 22:55:06 -07:00
Doug Gregor
449aa2f6b4 Mark conformances as "used" when the GenericSignatureBuilder needs them.
When the type checker forms a GenericSignatureBuilder to process
requirements, the GSB may look up concrete conformances. Route such
requests through TypeChecker::conformsToProtocol() so they can be
marked as used. This fixes multi-file scenarios where conformances
from another file might be used only in a generic signature in the
primary file, e.g., rdar://problem/31759258.
2017-04-21 22:36:28 -07:00
Joe Groff
3d178be169 Merge pull request #8875 from jckarter/keypaths
Keypaths
2017-04-21 17:51:17 -07:00
Joe Groff
d5cdf658da KeyPaths: Generate _kvcKeyPathString for ObjC-compatible keypaths. 2017-04-21 16:56:17 -07:00
Slava Pestov
f3236ed019 Merge pull request #8890 from KingOfBrian/bugfix/SR-1762-error-in-swift-4
Emit error in Swift 4 mode for final protocol extensions
2017-04-21 02:19:55 -07:00
Brian King
ca6637909d Only emit compatibility warning in Swift 3 mode 2017-04-20 16:05:20 -04:00
practicalswift
a596961187 [gardening] Make parameter name comments match actual parameter names 2017-04-20 13:47:10 +02:00
Slava Pestov
eb8b1ab3e1 Sema: Casts between unrelated optional types may succeed
... if the value is 'nil'!

Fixes <https://bugs.swift.org/browse/SR-3505>.
2017-04-20 00:37:39 -07:00
Slava Pestov
b1177f0413 Sema: Fix bogus "always fails" warnings with casts between generic classes
We would misreport a cast from G<T> to G<Int> or vice versa
as always failing, because we were checking for an exact
subtype relationship instead of archetype binding.

Fixes <https://bugs.swift.org/browse/SR-3609>.
2017-04-20 00:37:39 -07:00
Slava Pestov
3146823441 Sema: Simplify TypeChecker::isSubstitutableFor() 2017-04-20 00:37:39 -07:00