Commit Graph

9116 Commits

Author SHA1 Message Date
David Zarzycki
dbb421ba95 [AST] NFC: Tail allocate ErasureExpr conformances 2017-12-20 09:35:15 -05:00
swift-ci
ed1db5f73f Merge pull request #13540 from DougGregor/infer-from-concrete-sr-6640 2017-12-19 15:36:42 -08:00
Doug Gregor
f26d794495 [Conformance checking] Allow same-type constraints to infer associated types.
When a protocol closes off an associated type by tying it to a concrete
type (e.g., via a same-type constraint), allow associated type inference
to use that information to infer the associated type rather than
requiring the user to restate the obvious.

Fixes SR-6640.
2017-12-19 14:28:20 -08:00
David Zarzycki
af0ed2339b Merge pull request #13533 from davezarzycki/nfc_repack_expr_nodes
NFC: More Expr node layout optimization
2017-12-19 16:16:30 -05:00
Doug Gregor
82a8833ab0 [Associated type inference] Use defaults from overridden associated types.
During associated type inference, also look for default associated type
witnesses from overridden associated types, so that one need not
redeclare default associated types at every level in a protocol hierarchy.
2017-12-19 13:03:29 -08:00
David Zarzycki
60d2f5586e [AST] QoI: Track DictionaryExpr commas and tail allocate CollectionExpr comma locs 2017-12-19 13:33:09 -05:00
Doug Gregor
5c831a71ee Revert "[SE-0143] Put conditional conformances behind an "experimental" flag."
This reverts commit b59c30c1af.
2017-12-18 22:54:31 -08:00
Doug Gregor
d9095b1079 [Conformance checking] Don't suppress substitution failures during checking.
When checking whether a particular protocol conformance satisfies all of
the protocol's requirements, we were suppressing substitution failures.
In some cases, this would mean that we marked a conformance "invalid"
without ever emitting a diagnostic, which would lead to downstream crashes.

Instead, treat substitution failures somewhat more lazily. If we encounter
one while performing the checking, put the conformance into a "delayed" list
rather than failing immediately. Teach the top-level type checking
loop to re-check these conformances, emitting a diagnostic if they
fail the second time around.

Fixes rdar://problem/35082483 and likely other issues that slipped
through the type checker or blew up in unpredictable ways.
2017-12-18 16:43:59 -08:00
Doug Gregor
607a0ddffb [Conformance checking] Record type witnesses for overridden associated types.
When we determine a type witness for an associated type, record that
same type witness for all of the associated types it overrides.
2017-12-18 16:43:55 -08:00
Slava Pestov
bc990d38a8 Sema: Fix keypaths vs. lazy member validation
Constructing a keypath expression that references a class member
needs to validate all other members of the class (or a protocol,
but I couldn't reproduce a crash with that case -- added a test
anyway).

Fixes <rdar://problem/36083061>.
2017-12-17 19:10:18 -08:00
David Zarzycki
af361c041e Merge pull request #13494 from davezarzycki/nfc_sil_repack_part1
NFC: SIL repack of misc node bits (part 1)
2017-12-16 23:10:23 -05:00
David Zarzycki
54ea315586 [Basic] NFC: Stop using transparent unions 2017-12-16 10:43:49 -05:00
Jeffrey MACKO
716457c135 Fix SR-5615 2017-12-16 01:23:36 -05:00
Pavel Yaskevich
b6dbafba29 Merge pull request #13471 from CodaFi/array-of-sunshine
[DiagnosticsQoI] Refactor ArrayExpr visitor for better QoI
2017-12-15 16:19:40 -08:00
Robert Widmann
1d6f11ab54 Refactor ArrayExpr visitor for better QoI
Also remove mention of the word “contextual” type from the diagnostic
that rewrites array literals into dictionary literals and scale back
the scope of the diagnostic.  This method was catching and
mis-diagnosing too many errors that could better be handled by invalid
conversion diagnostics.
2017-12-15 18:20:36 -05:00
Doug Gregor
43fce99d43 [Type checker] Use the declared interface type of a type declaration.
Fix a silly error where we were returning the interface type of a type
declaration rather than the *declared* interface type, which meant we were
getting a metatype where we shouldn't.

Fixes rdar://problem/36003312.
2017-12-14 16:25:03 -08:00
Robert Widmann
d2aa82de1f Merge pull request #12818 from CodaFi/cover-model
Stricter enforcement of the "large space" heuristic
2017-12-14 02:01:17 -05:00
swift-ci
a24121af65 Merge pull request #13417 from DougGregor/override-objc-diag 2017-12-13 16:06:23 -08:00
Ben Langmuir
68a454556f Merge pull request #13348 from benlangmuir/cc-generic-subscript
[parse] Recover better from malformed subscript decls for code-completion
2017-12-13 15:45:03 -08:00
Doug Gregor
cabdf84179 Suggest @objc for overrides of declarations from/in extensions.
The Swift class model does not support overriding declarations where either
the overridden declaration or the overriding declaration are in an extension.
However, the Objective-C class model does, so marking the declaration as
@objc (when possible) will work around the limitation.

Customize the "cannot override declaration in extension" diagnostic to
suggest adding @objc to the overridden declaration in cases where
@objc is permitted. Fixes SR-6512 / rdar://problem/35787914.
2017-12-13 14:54:32 -08:00
Ben Langmuir
dc5888d887 [parse] Recover better from malformed subscript decls for code-completion
Code-completion of generic types expects to get a DeclContext for the
subscript, so make sure we recover well enough to produce a
SubscriptDecl.

rdar://35619175
2017-12-13 13:37:41 -08:00
Robert Widmann
43f06afef2 Defer analysis of large switch bodies
This presents a regression in diagnostic quality that is definitely
worth it not to lie to SILGen about whether a switch is covered or not.

At the same time, disable SIL’s unreachable diagnostic for ‘default’
clauses which would previously cause a warning to be emitted if the
default was proven to be unreachable.  This analysis is incomplete
anyways and can be done by Sema in the future if we desire.
2017-12-13 16:22:48 -05:00
Robert Widmann
8990bd00b6 Stricter enforcement of the "large space" heuristic
The Space Engine includes a heuristic that attempted a combinatorics-
based check to see if a pattern covered an insufficient amount of cases.
In straight-line switches this avoided computing a subspace match that
would have been quite expensive computationally.  However, when
expressive patterns (like tuple patterns) are used, it can fool the
check because the covered space is much larger than the actual size of
the space due to pattern overlap that counting like this simply can't detect.

Instead, just do the right thing and perform a space subtraction after
the existing preconditions for the heuristic are satisfied.

Resolves SR-6316
2017-12-13 14:35:53 -05:00
Slava Pestov
422000a2f2 Sema: Remove isProtocolExtensionUsable()
It doesn't do anything that isExtensionApplied() doesn't do.
2017-12-12 21:12:46 -08:00
Slava Pestov
042d9e9a10 Sema: Nuke resolveExternalDeclImplicitMembers() 2017-12-12 14:01:55 -08:00
Slava Pestov
10ca955806 Sema: Remove TypeChecker::forceExternalDeclMembers()
It doesn't appear to do anything, or at least it was being
called in places that make no sense.
2017-12-12 14:01:54 -08:00
Slava Pestov
21168dabad Sema: Simplify a bit in performMemberLookup() 2017-12-12 14:01:54 -08:00
Doug Gregor
82dde17ef4 [Conformance checking] More refactoring of associated type inference.
Move the rest of associated type inference into the new source file,
and split RequirementEnvironment into its own AST-level header, because it
can be re-used and has no ties to the type checker.
2017-12-11 16:34:49 -08:00
Jordan Rose
ca9d5a9df9 In Swift 3/4 mode, continue treating 'lazy override' as an override (#13335)
Follow-up for 7c707ce97c. Without this, the declaration would be
accepted, but any uses of the overridden property would be treated as
ambiguous because the property wouldn't really be marked as an
override.

rdar://problem/35900345
2017-12-11 15:13:55 -08:00
swift-ci
b77b541d3f Merge pull request #13366 from davezarzycki/nfc_repack_misc_typebase_bits 2017-12-10 22:34:13 -08:00
David Zarzycki
780f41b402 [AST] NFC: Repack misc TypeVariableType bits
1) This saves 16 bytes per type variable.
2) Please note that the 'ID' was "32 - NumTypeBaseBits" just a few weeks
   ago, so this isn't a real change.
2017-12-11 00:01:57 -05:00
Slava Pestov
fc3cf2863a Sema: Infer default witnesses before finishing conformance checking
Otherwise, we'll never get a chance to drain the TypeChecker's
UsedConformances list.

Fixes <https://bugs.swift.org/browse/SR-6565>, <rdar://problem/35949729>.
2017-12-10 20:30:48 -08:00
Slava Pestov
da90feca41 Sema: Keep all instance variables together in RequirementMatch 2017-12-10 20:30:47 -08:00
Slava Pestov
ea7251bbae SILGen: Don't emit default witness tables unless protocol is resilient 2017-12-10 20:30:47 -08:00
Mark Lacey
eebde102f5 Merge pull request #13186 from rudkx/fix-warnings
Squelch some dead code warnings.
2017-12-10 18:12:30 -08:00
Mark Lacey
d8f492e5d7 Squelch some warnings.
Fix up some dead code warnings as well as a warning for testing
whether an unsigned number is non-negative (which it always is).
2017-12-10 15:21:19 -08:00
Mark Lacey
116b6649eb [ConstraintSystem] Use locator from result of cast rather than source.
Be consistent with CoerceExpr and for the constraint we create use the
locator from the result of the expression rather than the locator from
the source of the expression.
2017-12-10 14:20:06 -08:00
Mark Lacey
12e7caf5d7 Merge pull request #13357 from rudkx/remove-param-from-coerce-iuo-to-value
NFC: Remove unused locator param from coerceImpicitlyUnwrappedOptiona…
2017-12-10 13:50:50 -08:00
Mark Lacey
7eafe07f59 NFC: Remove unused locator param from coerceImpicitlyUnwrappedOptionalToValue. 2017-12-10 12:32:51 -08:00
Doug Gregor
4ae4ab70fa [Conformance checking] Put associated type inference into its own file.
Factor associated type inference out into its own separate source file, so
it's easier to maintain on its own.
2017-12-09 23:06:51 -08:00
Doug Gregor
9b2c462709 [Conformance checking] Factor out associated type inference.
Move associated type inference into its own class, to make this
code easier to understand/maintain/improve. Minor diagnostics changes
because we're properly passing uninference associated type declarations
to the "group" checker.
2017-12-09 23:05:24 -08:00
Slava Pestov
336a97bc1a Sema: Diagnose invalid 'self.init' delegation where 'self' is an archetype
This is a corner case but would previously lead to a compiler crash
or miscompile.

Fixes <rdar://problem/21991470>, <https://bugs.swift.org/browse/SR-5022>.
2017-12-08 17:46:16 -08:00
Slava Pestov
71afed85d4 Sema: Clean up 'polymorphic use of non-required initializer' diagnostic 2017-12-08 17:46:16 -08:00
swift-ci
2514f7061f Merge pull request #13330 from DougGregor/where-clause-ref-typealias-in-protocol 2017-12-07 15:38:53 -08:00
Doug Gregor
5431400367 [Name lookup] Allow where clauses to find typealiases declared in a protocol.
Within the where clause of (e.g.) an extension, unqualified name lookup is
permitted to find associated types. Extend this to also include finding
typealiases declared within the protocol itself.

This is service of the IndexDistance change (SE-0191), and
fixes rdar://problem/35490504.
2017-12-07 13:46:33 -08:00
Mark Lacey
7ffb1a4691 Merge pull request #13302 from rudkx/iuo-attr-on-param-decl
IUO: Add the IUO attr to function parameters declared with '!'
2017-12-06 19:58:19 -08:00
Mark Lacey
c23dd4435e IUO: Add the IUO attr to function parameters declared with '!' 2017-12-06 16:55:09 -08:00
swift-ci
7409b716ee Merge pull request #13306 from DougGregor/rdar-35832679 2017-12-06 15:06:55 -08:00
Doug Gregor
6eec137374 [Type checker] Don't check near-miss candidates of the wrong kind.
Fixes rdar://problem/35832679.
2017-12-06 14:01:47 -08:00
Jordan Rose
7c707ce97c For 'lazy', make "cannot override with a stored property" a warning (#13304)
Previous versions of Swift accidentally treated lazy properties as
computed properties because of how they were implemented. Now that we
check this correctly, we've broken source compatibility. Downgrade the
error to a warning in this case.

(Arguably we could /allow/ overriding with a stored property. The
original concerns were that you could accidentally end up with extra
storage you didn't need, and that observing accessors would behave
differently based on whether or not the property was overriding. But
there's at least no ambiguity for 'lazy', which can't have observing
accessors today.)

rdar://problem/35870371
2017-12-06 13:41:07 -08:00