Commit Graph

9116 Commits

Author SHA1 Message Date
Doug Gregor
a6913bb2ef [Constraint solver] Check conditional requirements for type erasure.
Rather than wantonly dropping the conditional requirements when checking
for type erasure, add them in the same way we do for (e.g.) conformance
checking for generics. Fixes rdar://problem/35480860.
2017-11-19 22:22:32 -08:00
Doug Gregor
d58a596be1 [Constraint solver] Remove a now-unnecessary hack for conditional conformances.
We added this hack to work around the use of context types within normal
protocol conformances, which created tautological constraint systems.
With the switch to interface types in normal protocol conformances, this
hack is no longer necessary.
2017-11-19 22:07:18 -08:00
Mark Lacey
8b55a0f61b SE-0054: Rework diagnostics for IUOs and revise Swift 3 /4 semantics.
For Swift 3 / 4:

Deprecate the spelling "ImplicitlyUnwrappedOptional", emitting a warning
and suggesting "!" in places where they are allowed according to
SE-0054.

In places where SE-0054 disallowed IUOs but we continued to accept them
in previous compilers, emit a warning suggesting "Optional" or "?"  as
an alternative depending on context and treat the IUO as an Optional,
noting this in the diagnostic.

For Swift 5:

Treat "ImplicitlyUnwrappedOptional" as an error, suggesting
"!" in places where they are allowed by SE-0054.

In places where SE-0054 disallowed IUOs, emit an error suggestion
"Optional" or "?" as an alternative depending on context.
2017-11-18 11:41:53 +09:00
swift-ci
c9e9c90e3e Merge pull request #12993 from DougGregor/interface-types-conformances-vapor 2017-11-17 13:24:49 -08:00
Pavel Yaskevich
b56786fc03 Merge pull request #12986 from xedin/rdar-35540159
[CSSolver] Prune disjunction choices based on their equivalence class
2017-11-17 13:05:04 -08:00
Doug Gregor
a322628620 [Interface types in normal conformances] Cope with inherited conformances.
When mapping from context types to interface types to record the
conformances within a NormalProtocolConformance, take care to deal
with inherited conformances based on superclass constraints.

Fixes a crasher uncovered by Vapor. This fix is unprincipled but expedient;
a better fix will come shortly.
2017-11-17 12:28:59 -08:00
Doug Gregor
1ee30a3132 [Type checker diags] Check generic arguments for any generic function.
This includes functions without type parameters that are generic
because they are members of a generic context. This addresses a
diagnostics regression because the '==' operators for Optional, Array,
and Dictionary were made into members.

The resulting error message is a little ugly, but is more informative
(and much shorter) than what we had before.
2017-11-17 11:01:39 -08:00
Doug Gregor
3882c2922c [Type checker] Teach optional-promotion warning to understand member operators.
Fixes a diagnostics regression for expressions such as "x != nil"
(where x is non-optional), due to moving Optional's == into Optional
itself.
2017-11-17 10:52:05 -08:00
Doug Gregor
0b4b05a67b [Constraint application] Remove a bogus assertion.
THe constraint solver validates that any conditional requirements have
been satisfied; we don't need to fail here.
2017-11-17 10:52:04 -08:00
Doug Gregor
7ec8512b11 Merge pull request #12970 from DougGregor/conformance-interface-type
[AST] Store only interface types in NormalProtocolConformances.
2017-11-17 07:52:59 -08:00
Pavel Yaskevich
92e2a25991 Merge pull request #12934 from xedin/rdar-35198459
[CSApply] Fix source breakage related to deep-equality types and SE-0110
2017-11-17 00:15:11 -08:00
Doug Gregor
9ff4d7b936 Cleanups for interface types in normal conformances.
Fix some line breaks, remove some unnecessary code, and fix a
crash in printing synthesized extensions.
2017-11-16 22:42:44 -08:00
Pavel Yaskevich
05d524d6e0 [CSApply] Fix source breakage related to deep-equality types and SE-0110
Fix problem related to Swift 3 mode (with assertions),
since Swift 3 mode allows passing arguments with extra parens
to parameters which don't expect them, it should be supported
by "deep equality" types e.g. Optional<T>:

```swift
func foo(_: (() -> Void)?) {}
func bar() -> ((()) -> Void)? { return nil }
foo(bar) // This expression should compile in Swift 3 mode
```

Resolves: rdar://problem/35198459
2017-11-16 21:56:24 -08:00
Pavel Yaskevich
b16add7685 [CSSolver] Prune disjunction choices based on their equivalence class
There are situations where we know equivalence relationship between
multiple disjunctions, let's prune dependent choice space based on
choice picked for the parent disjunction.

Resolves: rdar://problem/35540159
2017-11-16 19:35:14 -08:00
Pavel Yaskevich
57ccdf7423 Merge pull request #12520 from xedin/remove-strideable
[stdlib] changes to remove `_Strideable` protocol.
2017-11-16 19:06:40 -08:00
Brian Gesiak
f068506b49 Merge pull request #12939 from modocache/sr-2910
[Sema] Descriptive -debug-time-function-bodies
2017-11-16 16:54:54 -05:00
Pavel Yaskevich
7b121de1a0 [CSRanking] Change ranking to weight overload choices in evaluation order
Consider different overload choices for the same location in evaluation
order, this makes overload resolution more predictable because it's going
to follow expression bottom-up, that prevents situations when some
expressions are considered ambigious because choices taken further up
equate the score, instead each level is given distinct weight
based on evaluation order.

Resolves: rdar://problem/31888810
2017-11-16 13:38:24 -08:00
Jordan Rose
99cfcf13f3 Transforms: re-check error handling for nested functions as well (#12950)
Since both in-tree AST transforms (playground and program counter) add
new ApplyExprs (and literals that turn into ApplyExprs), we need to
recheck nested function bodies as well as top-level ones.

rdar://problem/28784059
2017-11-16 13:12:34 -08:00
Huon Wilson
5f70f68c0d [AST] Store only interface types in NormalProtocolConformances.
Rather than storing contextual types in the type witnesses and associated
conformances of NormalProtocolConformance, store only interface types.

@huonw did most of the work here, and @DougGregor patched things up to
complete the change.
2017-11-16 11:45:18 -08:00
Slava Pestov
2920b4fd1c AST: Remove DeclContext::mapTypeOutOfContext() 2017-11-15 22:52:28 -08:00
Slava Pestov
f07cde75e7 AST: Move mapTypeOutOfContext() from GenericEnvironment to TypeBase
It doesn't actually *use* the generic environment.
2017-11-15 22:52:13 -08:00
Slava Pestov
3f51dbc3b1 Sema: Don't validate types when binding extensions 2017-11-15 21:55:55 -08:00
Slava Pestov
ada481f03f Sema: Make sure the protocol is validated before conformance checking 2017-11-15 21:55:55 -08:00
Slava Pestov
4096000530 Merge pull request #12942 from slavapestov/lazy-protocol-member-validation
Lazy protocol member validation
2017-11-15 18:03:40 -08:00
Greg Parker
3f7d7c2589 Merge pull request #12949 from apple/revert-12910-conditional-conformance-equatable
Revert "Use conditional conformances to implement Equatable for Optional, Array and Dictionary"
2017-11-15 16:52:02 -08:00
Slava Pestov
772bd7634c Sema: Lazily validate protocol members 2017-11-15 16:26:27 -08:00
Slava Pestov
9b7f3f73d2 Sema: Don't validate class layout when validating an extension
We only need to validate all the members of a class when
we type check an extension, which means we will generate
code for it.

Merely validating an extension, as happens during name
lookup, does not need to validate all members of a class.
2017-11-15 16:26:20 -08:00
Slava Pestov
29279afd9b Merge pull request #12940 from slavapestov/clang-importer-type-checked-ast
ClangImporter: Synthesize fully-type checked AST for common functions
2017-11-15 16:23:20 -08:00
Greg Parker
e8475cc130 Revert "Use conditional conformances to implement Equatable for Optional, Array and Dictionary" 2017-11-15 14:17:22 -08:00
Slava Pestov
3c07c27f84 Revert "[CSRanking] Delete a pointless old ranking hack. NFC"
This reverts commit 199273bcf7.
2017-11-15 13:41:07 -08:00
Graydon Hoare
97ac580384 Merge pull request #12782 from graydon/fix-35198678-a-little-better
Fix 35198678 a little better
2017-11-15 00:21:47 -08:00
Slava Pestov
1b8a7d6c93 Sema: Don't try to synthesize implicit initializers for imported structs
The ClangImporter already does everything here.
2017-11-14 21:52:28 -08:00
Brian Gesiak
a83f75f704 [Sema] Descriptive -debug-time-function-bodies
Generated getters and setters don't have their names printed alongside them in
the log output for `-debug-time-function-bodies`. Here are some examples:

```
get {}
set {}
final get {}
final set {}
@objc get {}
@objc set {}
@objc final get {}
@objc final set {}
(closure)
```

Re-use the logic from the diagnostics for `-warn-long-function-bodies=`
in order to print getter and setter names (but not attributes such as
`final` or `@objc`), for example:

```
geter bar
setter bar
global function foo()
global function baz(one:two:three:)
deinitializer deinit
initializer init()
```

Addresses https://bugs.swift.org/browse/SR-2910.
2017-11-14 23:25:18 -05:00
Doug Gregor
199273bcf7 [CSRanking] Delete a pointless old ranking hack. NFC 2017-11-14 17:04:48 -08:00
Doug Gregor
1f9b28a117 [Type checker diags] Check generic arguments for any generic function.
This includes functions without type parameters that are generic
because they are members of a generic context. This addresses a
diagnostics regression because the '==' operators for Optional, Array,
and Dictionary were made into members.

The resulting error message is a little ugly, but is more informative
(and much shorter) than what we had before.
2017-11-14 16:23:20 -08:00
Doug Gregor
c8e21e7b57 [Type checker] Teach optional-promotion warning to understand member operators.
Fixes a diagnostics regression for expressions such as "x != nil"
(where x is non-optional), due to moving Optional's == into Optional
itself.
2017-11-14 16:23:20 -08:00
Doug Gregor
600c967563 [Constraint application] Remove a bogus assertion.
THe constraint solver validates that any conditional requirements have
been satisfied; we don't need to fail here.
2017-11-14 16:23:20 -08:00
Joe Groff
4b401e257a Merge pull request #12835 from jckarter/key-path-type-checking
Sema: Fixes for KeyPath type checking.
2017-11-14 13:10:44 -08:00
Erik Eckstein
8033476b64 Function-level optimization attributes.
For now these are underscored attributes, i.e. compiler internal attributes:
@_optimize(speed)
@_optimize(size)
@_optimize(none)

Those attributes override the command-line specified optimization mode for a specific function.
The @_optimize(none) attribute is equivalent to the already existing @_semantics("optimize.sil.never") attribute
2017-11-14 11:25:02 -08:00
Slava Pestov
b6200728a6 Sema: Fix crash on invalid openUnboundGenericType()
We can't construct a nominal type with an ErrorType as a
parent, so in the bad circular case, return a Type() instead
to bail out of transform() altogether.
2017-11-14 00:07:56 -08:00
Slava Pestov
0715eaeaed AST: Move SourceEntityWalker to IDE 2017-11-13 22:10:41 -08:00
Doug Gregor
91fa3aab44 [CSRanking] Remove dead code.
As noted in the comment, we expected this code to be unnecessary,
which it is. Remove it.
2017-11-13 15:14:58 -08:00
Huon Wilson
1339685c5f [CS] Fix conditional conformances in overload ranking.
Resolves rdar://problem/35480952.
2017-11-13 13:14:39 -08:00
Slava Pestov
66211a8781 Sema: Remove unused LocalFunctionCapture type 2017-11-12 19:47:40 -08:00
Slava Pestov
ed0ef94d91 Sema: Use a flag to short-circuit the requestClassLayout() check 2017-11-12 19:47:33 -08:00
Slava Pestov
0b666b4b13 Sema: Remove more extension binding dead code 2017-11-12 19:47:28 -08:00
Slava Pestov
35c4b755cf Sema: Merge bound generic and protocol extension paths in validateExtension() 2017-11-12 16:39:43 -08:00
Slava Pestov
ca6763a103 Sema: We never see bound generic types in formExtensionInterfaceType() 2017-11-12 16:39:43 -08:00
Jordan Rose
ec5ba41108 Simplify diagnoseResilientConstructor all the way away.
Now that struct initializers "just" fall into the delegating case when
they're made inlinable, the only interesting case is class
initializers, which can be checked in a more direct way than what we
were doing before.
2017-11-10 16:09:06 -08:00
Jordan Rose
14198a360c Treat cross-module struct initializers as delegating in Swift 5
(and when the struct in question is non-fixed-layout, which was
already implemented)

This ensures that these initializers are never fieldwise in Swift 5
mode, which makes it safe for library authors to add new fields.
2017-11-10 10:59:24 -08:00