Commit Graph

9116 Commits

Author SHA1 Message Date
Jordan Rose
970073ad77 Promote a bunch of Swift 3 compatibility access warnings to errors. (#10086)
This was done back in Swift 3.0.1 or 3.0.2. Let's finally make them
errors in Swift 4!

I also fixed up a number of '%error' entries in diagnostics that can
actually happen in invalid code. These are the ones that were already
present in the warnings.
2017-06-16 11:47:10 -07:00
Itai Ferber
238a7a281e Allow synthesis of Codable for weak/unowned vars
The type of non-strong properties is wrapped in a ReferenceStorageType,
which does not conform to Codable. This needs to be unwrapped so the
inner reference type can be considered for Codable conformance.
2017-06-16 10:42:27 -07:00
Slava Pestov
319a7b4cdd Merge pull request #10277 from slavapestov/unqualified-lookup-cleanup
Unqualified lookup cleanup
2017-06-16 01:45:25 -07:00
Doug Gregor
6a2b6c271f [AST] Add TypeBase::findUnresolvedDependentMemberType() and use it 3x.
NFC: Eliminate some duplicated "search for an unresolved dependent
member type" code scattered around.
2017-06-15 23:23:07 -07:00
Slava Pestov
aa84dc604f Sema: Use protocol generic signature instead of requirement signature to check type witnesses
Regression was introduced by
ec60c88412.

I don't have a reduced test case, but this solves
<rdar://problem/32668454>.
2017-06-15 22:57:40 -07:00
Doug Gregor
b44f24dc2d [Type checker] Re-validate typealiases in protocols after protocol validation.
Validation for typealiases in protocols is... odd. It needs to avoid
depending on the whole protocol being validated, so it does an initial
validation that can leave nested types of Self (and other associated
types) somewhat unresolved. In these cases, do something icky but
partially effective: when we resolve the protocol, go back and clean
up the types of these typealiases.

A better solution would allow us to use the types of these typealiases
within the Generic Signature Builder without recording them in the AST
as "the interface type", so there's no way unresolved nested types
could be found (and, therefore, nothing to "fix up" later). Howwever,
that's a more significant undertaking.

Fixes rdar://problem/32287795.
2017-06-15 22:51:30 -07:00
Slava Pestov
61b7effbb2 Sema: Always model nested types as member accesses
When an unqualified reference is overloaded, we would walk
the list of overload candidates and check if they are all
member accesses. If they are, we would form an
UnresolvedMemberRefExpr with the right base. Otherwise,
we would form an UnresolvedDeclRefExpr.

Now, consider forming an UnresolvedMemberRefExpr even if
some of the members are types. This forces all nested
type lookups to go through getTypeOfMemberReference(),
not getTypeOfReference().

As a result, we no longer pass nested types to the
resolveTypeInContext() function from expression checking.

This will allow resolveTypeInContext() to take the base
declaration on which the nested type was found as a
parameter, instead of walking parent DeclContexts to
try to guess what the right base was.
2017-06-15 21:31:52 -07:00
Slava Pestov
773d7b3225 Sema: Remove more methods from GenericTypeResolver
resolveGenericTypeParamType(), resolveTypeOfDecl() and
resolveTypeOfContext() would all take the type of a
declaration, and optionally map it into context.

Replace them with a mapTypeIntoContext() that takes a
type and either returns it verbatim or maps it into
context.
2017-06-15 21:31:35 -07:00
Slava Pestov
d1610a5536 Sema: Kill GenericTypeResolver::resolveSelfAssociatedType() 2017-06-15 18:37:16 -07:00
Slava Pestov
746a66f600 Sema: Simplify TypeChecker::lookupUnqualified() a bit
There's no need to walk up the parent contexts here.
2017-06-15 15:39:08 -07:00
Doug Gregor
7b56977eff [Type checker] Consistently mark used protocol conformances as "used".
Keep track of the protocol conformances required to form a particular
solution. At the point where we apply a solution, mark each of those
conformances as "used" so we're sure they are complete for later
phases (SILGen, SIL optimizer, IRGen). This general mechanism makes
sure we don't miss any cases in CSApply, such as the multi-case
illustrated in the new test where CSApply doesn't form any AST notes
describing the type erasure in a function conversion, so it otherwise
wouldn't see the conformance to mark it "used".

Pavel went most of the way down this path to track conformances last
month for unrelated reasons (that didn't really pan out). Resurrect
his work to track conformances, but only use them to mark as "used".

Fixes rdar://problem/32111710.
2017-06-15 14:40:04 -07:00
Pavel Yaskevich
3781877b93 [ConstraintSystem] Track conformance checking done while solving to validate solution
Track outcomes of `conformsToProtocol` calls in `simplifyConformanceConstraints`
to be able to validate conformances when solution is formed to avoid returning
solutions with nominal types with invalid conformances to protocols.
2017-06-15 14:18:36 -07:00
Alex Hoppen
2078ec6f0a Remove getName from ValueDecl
Push the getName method from ValueDecl down to only those types that are
guaranteed to have a name that is backed by an identifier and that will
not be special.
2017-06-15 21:49:34 +02:00
Doug Gregor
511c24586f [Type checker] Eliminate a dynamically-dead diagnostic.
Between syntactic restrictions and later checks for spurious '&'
expressions, we don't need to check for '&' expressions when coercing
to an rvalue. Plus, 'inout' doesn't imply 'not lvalue', so we'd never
get here.
2017-06-14 22:44:48 -07:00
Doug Gregor
01b45a245c Fold ConstraintSolver::coerceToRValue() into TypeChecker::coerceToRValue()
ConstraintSolver::coerceToRValue() missed a bunch of cases where we
should be dealing with lvalues, e.g., tuples, "try" expressions, and
so on. Extend TypeChecker::coerceToRValue() to deal with the
expression type side-tables and ConstraintSolver::coerceToRValue() to
it.

Fixes rdar://problem/32700180, a crash-on-valid.
2017-06-14 22:44:32 -07:00
Xi Ge
a2e5910efa FixCode: when inserting protocol stubs, avoid inserting @available. rdar://32645956 (#10272) 2017-06-14 20:49:42 -07:00
Itai Ferber
5d663e7cf3 Indentation + style fixes 2017-06-14 13:34:21 -07:00
Itai Ferber
ea5f4e03ce Collate Codable diagnostics for correct ordering
Codable failures produced diagnostics and notes explaining what failed
during decode. These diagnostics were being output as they were
generated, which was suboptimal because it meant that NOTEs could be
produced before the error they were related to.

This was bad for consumers like Xcode, which associate NOTEs with the
last error or warning diagnostic.

This collates these notes using a diagnostic transaction and only
outputs the errors if something goes wrong.
2017-06-14 13:34:21 -07:00
Robert Widmann
abd5aa8e6d Rename some X-Value-related entities
* Rename coerceToMaterializableValue to coerceToRValue

* Rename isLValueType to hasLValueType to better match the
intended semantics of the member.
2017-06-14 13:18:45 -07:00
Robert Widmann
3af359cb44 Merge pull request #10242 from CodaFi/in-through-the-out-door
[NFC] Move HasInOut bit out of recursive type properties
2017-06-14 13:11:19 -07:00
Robert Widmann
a4bf57f9d1 Move HasInOut bit out of recursive type properties
In anticipation of removing this bit, move it from the
recursive type property into TupleType - its only real
user.  This necessitates uglifying a bit of logic in the
short term that used to speak broadly of materializability
to instead speak about LValues and Tuples of InOut values
independently.
2017-06-14 09:54:19 -07:00
Slava Pestov
28c35ff325 SILGen: Fix problems with local generic functions
When evaluating if a call of a local function requires substitutions,
we checked if the immediate function being referenced captured
generic parameters, without checking if it transitively captured
generic parameters via other local functions it references.

Also, when calling accessors, we did not perform this check at all.

Fix both ordinary function calls and accessor calls to drop the
substitutions only if the *lowered* local captures say it is safe.

Finally, fix Sema to not consider substitutions in local function
references as generic parameter captures, since we now correctly
calculate the transitive closure of all captures.

Fixes <rdar://problem/32761305> and related issues.
2017-06-14 01:42:13 -07:00
Slava Pestov
65c3565c2d Sema: Fix failure to produce diagnostics when 'is' casts are involved
When re-typechecking an expression during diagnostics, we begin by
erasing all the types in the expression. However, any expressions
created as part of applying the solution will remain.

CSGen was doing the wrong thing when it encountered EnumIsCaseExpr,
which can only appear in already-type checked ASTs.

Returning expr->getType() is not correct, because the type is not
yet set; returning a null type is intended to signal that a
diagnostic was already emitted, which causes Sema to stop
type checking.

The end result is that certain combinations of invalid code with
an 'is' cast nested inside would crash either the AST verifier
(with asserts on) or in SILGen (with asserts off), because we
would stop trying to diagnose the issue prematurely, and possibly
not emit a diagnostic at all.

Fixes <https://bugs.swift.org/browse/SR-5050> and
<rdar://problem/32487948>.
2017-06-13 20:19:43 -07:00
Alex Hoppen
d922944af0 Merge pull request #9976 from ahoppen/pdm-diagnostics2
Migration to DeclBaseName in diagnostic definitions
2017-06-13 12:55:16 +02:00
Mark Lacey
301067b5ce Merge pull request #10214 from rudkx/warn-long-compile
Add -warn-long-expression-type-checking=<limit> frontend option.
2017-06-12 19:50:56 -07:00
Mark Lacey
d26c859222 Add -warn-long-expression-type-checking=<limit> frontend option.
Generates a warning for any expression that takes longer than <limit>
milliseconds to type check. This compliments the existing
-warn-long-function-body=<limit> option.
2017-06-12 17:27:29 -07:00
Huon Wilson
ffeb291397 [Sema] NFC: (void) a variable used only in assert. 2017-06-12 12:35:51 -07:00
John McCall
b542c75cb1 Use abstract implicit-conversion expressions for bridging cases instead of
expanding the conversion calls in Sema.
2017-06-11 01:39:51 -04:00
Slava Pestov
03f9c3e0a2 Sema: Fix bugs when applying solutions containg type(of:)
When applying a solution to an ApplyExpr, we have to coerce the
argument to the input type of the function. This is because the
solution succeeds if the argument is convertible to the
function's input, not just if they are equal.

We were forgetting to do that for the special case of a type(of:),
which has its own semantics.

Fixes <rdar://problem/32435723> and
<https://bugs.swift.org/browse/SR-5168>.
2017-06-10 21:13:19 -07:00
Robert Widmann
51623f7cbb Merge pull request #10184 from CodaFi/pat-a-pan
Diagnose misplaced associated values in simple enum patterns
2017-06-09 23:01:06 -07:00
Robert Widmann
e50713d94e Diagnose misplaced associated values in simple enum patterns 2017-06-09 21:24:28 -07:00
Pavel Yaskevich
04fc022609 Merge pull request #10183 from xedin/rdar-32390726
[QoI] Don't suggest `var` to `let` when binding inside for-statement
2017-06-09 01:40:12 -07:00
Pavel Yaskevich
6180ecef73 [QoI] Don't suggest var to let when binding inside for-statement
Instead of doing that, suggest removing 'var' altogether because
'let' cannot be used directly in an implicitly immutable context.

Resolves: rdar://problem/32390726
2017-06-09 01:10:40 -07:00
Robert Widmann
4504d76c2d Merge pull request #10174 from CodaFi/a-pattern-of-incidents
Expand implicit tuple patterns in the AST
2017-06-08 19:33:39 -07:00
swift-ci
bbe1ca3b40 Merge pull request #10175 from CodaFi/that-one-broom-scene-in-fantasia 2017-06-08 17:23:39 -07:00
Robert Widmann
3b26466cef Clean up some UB
* The SILBuilder could potentially reference itself during its own
initialization if a valid insertion point was left around and a
new basic block was created.  Move basic block creation after the
initializer instead.

* CSDiag was comparing canonical types for equality directly, which
leads to mixed-type comparisons if one side of the comparison is nullptr.
Use isEqual instead.
2017-06-08 16:47:48 -07:00
Beta
924ddd2678 Expand implicit tuple patterns in the AST 2017-06-08 16:15:30 -07:00
Slava Pestov
28beb03cd2 Merge pull request #10168 from slavapestov/default-arguments-versus-effective-access-v2
Sema: Targeted fix for bad interaction between resilience checks and -enable-testing [v2]
2017-06-08 10:15:50 -07:00
Slava Pestov
89dc5afa57 Sema: Targeted fix for bad interaction between resilience checks and -enable-testing
The -enable-testing flag makes ValueDecl::getEffectiveAccess()
say that internal declarations are public.

This would lead us to emit spurious diagnostics if a default
argument of an internal function referenced a private symbol,
for example, which is something we actually want to allow.

This is a second revision of the patch -- instead of changing
getEffectiveAccess() to take an extra parameter, this changes
getFormalAccessScope() instead.

Fixes <rdar://problem/32592973>.
2017-06-08 01:35:44 -07:00
Robert Widmann
0008354238 Merge pull request #10169 from CodaFi/sweeps
[NFC] Run clang format on the space engine
2017-06-08 01:32:29 -07:00
Beta
acd95d1c03 clang format the space engine 2017-06-07 23:45:54 -07:00
Slava Pestov
7cfa34952a Revert "Sema: Targeted fix for bad interaction between resilience checks and -enable-testing"
This reverts commit 66173a9b97.
2017-06-07 22:06:54 -07:00
Slava Pestov
66173a9b97 Sema: Targeted fix for bad interaction between resilience checks and -enable-testing
The -enable-testing flag makes ValueDecl::getEffectiveAccess()
say that internal declarations are public.

This would lead us to emit spurious diagnostics if a default
argument of an internal function referenced a private symbol,
for example, which is something we actually want to allow.

Hack around this by adding a new 'forLinkage' parameter to
getEffectiveAccess(). When this is false, we ignore the
-enable-testing flag, and only look for the @_versioned
attribute.

I'm not very happy with the fix, because it only compliates
the subtle behaviors of getFormalAccess(), getEffectiveAccess()
and getFormalAccessScope() further. But refactoring this is
a bigger change than I'm willing to put into swift-4.0-branch.

Fixes <rdar://problem/32592973>.
2017-06-07 21:43:37 -07:00
Slava Pestov
443ba236fc Sema: Fix a few problems with generic typealiases in protocols
- Unqualified lookup was incorrectly checking generic arguments even
  when resolving interface types, resulting in a bogus 'Self does
  not conform to P' error when referencing a generic typealias from
  inside a protocol.

- The generic argument check was also done incorrectly if the
  underlying type did not contain any type parameters, resulting
  in bogus ErrorTypes. Just remove the no-type-parameter
  "optimization" instead, since it was working around another
  crash.

- When opening up a generic typealias in the constraint solver, we
  did the wrong thing if the generic typealias was defined in a
  protocol, producing concrete substitutions for the parent type
  instead of a 'Self := ParentType' substitution.

Fixes <rdar://problem/32633645>.
2017-06-07 18:33:46 -07:00
Slava Pestov
c4df92aef3 Sema: Clean up 'dynamic' inference a bit 2017-06-07 17:55:42 -07:00
Slava Pestov
c152fee9f8 Sema: A couple of recursion-breaking hacks 2017-06-07 17:19:09 -07:00
Alex Hoppen
e7da52776c Merge pull request #10152 from ahoppen/fixit-optional-switch
[Diag] Correct fixit location of "?" when pattern matching optional with non-optional
2017-06-07 10:59:54 -07:00
Alex Hoppen
99acf816f4 [Diag] Correct fixit location of "?" when pattern matching optional with non-optional
Trying to pattern match an optional with a non-optional should provide
a fixit inserting a "?" after the last token and not before it.
2017-06-07 07:25:46 -07:00
Slava Pestov
00997138b5 Sema: Fix crash with associated type <=> typealias circularity 2017-06-06 23:56:34 -07:00
Slava Pestov
ec60c88412 Sema: Use requirement signature to check type witnesses 2017-06-06 23:56:33 -07:00