Commit Graph

7976 Commits

Author SHA1 Message Date
Doug Gregor
331937a129 [Type checker] Track defaulted constraints based on their locator. NFC
While, tracking defaulted constraints based on their type variable
usually works in practice, it can break if the type variable ends up
being equivalent to some other type variable that. Instead, record the
locators associated with Defaultable constraints where we used the
default, which are easier to work with during constraint application.
2016-10-11 17:09:13 -07:00
Doug Gregor
a36993add0 [Constraint graph] Make dumping print type variables. NFC 2016-10-11 17:09:13 -07:00
Doug Gregor
c2b9759cd3 Simplify ConstraintSystem::getFixedTypeRecursive and use it consistently.
We had a few places that were performing ad hoc variants of
ConstraintSystem::getFixedTypeRecursive(); simplify it's interface so
we can use it everywhere consistently. Fixes rdar://problem/27261929.
2016-10-11 17:08:52 -07:00
Robert Widmann
6a48934ba5 Merge pull request #5195 from CodaFi/prescriptivist-descriptivism
Improve diagnostics for optionals in string interpolation segments
2016-10-11 18:30:13 -04:00
Pavel Yaskevich
f526a251c6 [Diagnostics] SR-1255: Improve diagnostic when one of the parameters marked as autoclosure 2016-10-11 14:43:37 -07:00
Doug Gregor
ab959c9f21 Introduce TypeBase::isTypeVariableOrMember(). NFC
Similar to “isTypeParameter,” this new entry point determines whether the type is a type variable or a nested type of a type thereof. The latter case isn’t actually formed yet, so this is NFC staging the trivial bits of this change.
2016-10-11 11:38:52 -07:00
Doug Gregor
f38029bae5 [Constraint application] Replace a transform with a ‘simplifyType()’. NFC 2016-10-11 11:38:51 -07:00
Doug Gregor
32ebd54677 Remove unused TypeVariableType::getBaseBeingSubstituted(). NFC 2016-10-11 11:38:51 -07:00
Jordan Rose
e5f7ef9aaf Merge pull request #5200 from benasher44/basher_granular_debug_time
Log debug elapsed time using 2 decimal places
2016-10-11 10:31:43 -07:00
Robert Widmann
f7984f86a6 Improve diagnostics for optionals in string interpolation segments 2016-10-11 12:27:09 -04:00
Ben Asher
d14a49b44a Add period. Use ceil instead of round 2016-10-10 16:27:17 -07:00
Michael Ilseman
54f4103b5b [3.0 compat] Don't diagnose @escaping var-arg closures.
Var-arg closures are already escaping, so we typically want to issue
an error if @escaping is specified. To not do sure will confuse and
give a false impression on the un-annotated semantics and whether it
is needed. But, 3.0 shipped with a bug where we didn't consistently
apply the no-escape-by-default rule here, and thus it was semantically
meaningful (and needed).

In order to preserve source compatibility, albeit at the expense of
developers on versions 3.0.1 and later in the Swift 3 family, we
suppress the error if we see @escaping. Either way, this is a
relatively uncommon usage, so the confusion won't be too wide spread.
2016-10-10 16:16:41 -07:00
Ben Asher
56629383ae Round to nearest 100th of a millisecond 2016-10-10 15:08:52 -07:00
Rintaro Ishizaki
430a0d8459 [AST] Remove @escaping from decl attributes.
@escaping is not really a decl attribute, ever since it was introduced.
2016-10-11 02:26:13 +09:00
Ben Asher
6e49cf06e2 Log debug elapsed time using 3 decimal places
For flags like -debug-time-function-bodies, this
makes it easier to measure the impact of parsing
functions that take a short amount of time to parse
(less than 0.1ms) but are parsed many times and
therefore add up over the course of the full build.
2016-10-09 11:28:02 -07:00
swift-ci
d38198bd68 Merge pull request #5063 from graydon/rdar-27982012-poor-diagnostic 2016-10-07 17:56:00 -07:00
Mark Lacey
5356cc37bd Fix a couple cases of ArrayRef capturing compiler temps.
Use a SmallVector for scratch space to use to build the ArrayRefs
instead.
2016-10-07 16:06:23 -07:00
swift-ci
edd2ecdf0c Merge pull request #5177 from DougGregor/error-type-with-original 2016-10-07 12:14:38 -07:00
Doug Gregor
50341da32b Use "TypeBase::hasError()" rather than "is<ErrorType>()" where needed.
In most places where we were checking "is<ErrorType>()", we now mean
"any error occurred". The few exceptions are in associated type
inference, code completion, and expression diagnostics, where we might
still work with partial errors.
2016-10-07 10:58:23 -07:00
Graydon Hoare
0d5420b7dd In CSDiag, diagnose callee inaccessibility before digging into args.
Fixes QoI rdar://problem/27982012
2016-10-07 09:35:03 -07:00
Doug Gregor
66e20116f2 Extend ErrorType with an "original type" and use it to clean up substitution.
Type::subst()'s "IgnoreMissing" option was fairly unprincipled, dropping
unsubstituted types into the resulting AST without any indication
whatsoever that anything went wrong. Replace this notion with a new
form of ErrorType that explicitly tracks which substituted type caused
the problem. It's still an ErrorType, but it prints like the
substituted type (which is important for code completion) and allows
us to step back to the substituted type if needed (which is used by
associated type inference). Then, allow Type::subst(), when the new
UseErrorTypes flag is passed, to form partially-substituted types that
contain errors, which both code completion and associated type
inference relied on.

Over time, I hope we can use error-types-with-original-types more
often to eliminate "<<error type>>" from diagnostics and teach
Type::subst() never to return a "null" type. Clients can check
"hasError()" to deal with failure cases rather than checking null.
2016-10-06 16:40:28 -07:00
Doug Gregor
262fe95344 Drastically scale back usage of SubstFlags::IgnoreMissing.
This particular flag should only be used in rare cases where we don't
want to know about failures, but instead want to get some
partially-formed type. Only very specific parts of the type checker
need this (associated type inference), and code completion relies on
it for slightly-better results.
2016-10-06 14:44:11 -07:00
Doug Gregor
8fab641da0 [AST] Simplify DependentMemberType creation and use isTypeParameter() more. NFC 2016-10-06 14:24:55 -07:00
Robert Widmann
97a99ae315 Merge pull request #5110 from CodaFi/failure-is-not-an-optional
Extend Optional-As-Any Warning to String Interpolation Segments
2016-10-06 15:27:09 -04:00
Jordan Rose
764bf83145 SR-2673: @NSManaged property can't satisfy protocol requirement (#5141)
Targeted fix for SR-2673: if a potential protocol witness is
@NSManaged, add accessors the NSManaged way, not the stored property
way.

There's probably more weirdness around here, so I'll clone the bug to
go through maybeAddAccessorsToVariable a lot more often. (Lazy
properties could easily be broken in the same way.)
2016-10-06 09:44:12 -07:00
Slava Pestov
cbf76fd79d Sema: More cleanup from removal of markInvalidGenericSignature() 2016-10-04 23:39:10 -04:00
Slava Pestov
199a909857 Merge pull request #5127 from slavapestov/remove-unnecessary-error-path
Remove unnecessary error path
2016-10-04 23:10:08 -04:00
Mark Lacey
139b3c7a89 Merge pull request #5105 from xedin/r25601651
[Diagnostics] Fix bad diagnostic for failed assignment from Any to a more specific type
2016-10-04 19:51:15 -07:00
Slava Pestov
7069fbc9be Sema: Remove unnecessary error path in generic signature validation
The idea here is that if a generic signature has invalid requirements,
we would drop all the requirements and build a new set of archetypes
without requirements.

When this logic was added, it fixed 700 compiler_crashers:

<c258f991f6>

Nowadays it appears that all the underlying issues were solved, so
removing this error path actually fixed two crashers and improved
a couple of diagnostics.
2016-10-04 21:47:53 -04:00
Slava Pestov
8f88d19518 Sema: Allow extensions to make generic parameters concrete via same-type constraints
Fixes <https://bugs.swift.org/browse/SR-1009>.
2016-10-04 20:36:56 -04:00
Slava Pestov
8bf32c5280 AST: Better checks for same-type constraints making generic parameters concrete
The old logic missed some cases where this could come up.
2016-10-04 20:01:39 -04:00
swift-ci
c563019ec9 Merge pull request #5124 from rudkx/fix-stray-line 2016-10-04 16:33:35 -07:00
Pavel Yaskevich
4a60a53b19 [Diagnostics] Fix bad diagnostic for failed assignment from Any to a more specific type
When generating constraints for subscript convert InOutType into LValueType,
because base of the subscript should never be marked as inout, but rather as
@lvalue to denote mutability.

Resolves <rdar://problem/25601561>.
2016-10-04 16:23:05 -07:00
Mark Lacey
7269a69197 Fix stray line was intended to be part of the previous line.
This line was added in 769ed07a6d and was
clearly meant to replace the last argument of the previous function call.
2016-10-04 13:11:17 -07:00
Robert Widmann
024349788e General bike shedding 2016-10-04 10:09:56 -04:00
Slava Pestov
3b2bef56a4 AST: Remove some usages of ArchetypeType::getSelfProtocol()
There's no fundamental reason to special-case the Self archetype of
a protocol or protocol extension to refer back to the protocol itself.
2016-10-04 01:16:00 -04:00
Robert Widmann
43a582ef0f Initial implementation of optionals-in-string-interpolation warnings
Basic extension of the optional-to-any AST walker to incorporate
warnings for the as-of-now up and coming Swift evolution proposal.
2016-10-03 17:08:11 -04:00
Slava Pestov
354416f912 AST: Kill Type::getAllGenericArgs()
This was almost identical to getMemberSubstitutions(), except
protocol and protocol extension members are not properly
supported.

Now that this method is no longer used by the ASTPrinter, there
are only two remaining usages, both trivially refactorable to
use better APIs.
2016-10-03 00:39:49 -04:00
Slava Pestov
cfe9e6a3de IDE: Use GenericSignatures and interface types (mostly)
There was a ton of complicated logic here to work around
two problems:

- Same-type constraints were not represented properly in
  RequirementReprs, requiring us to store them in strong form
  and parse them out when printing type interfaces.

- The TypeBase::getAllGenericArgs() method did not do the
  right thing for members of protocols and protocol extensions,
  and so instead of simple calls to Type::subst(), we had
  an elaborate 'ArchetypeTransformer' abstraction repeated
  in two places.

Rewrite this code to use GenericSignatures and
GenericFunctionType instead of old-school GenericParamLists
and PolymorphicFunctionType.

This changes the code completion and AST printer output
slightly. A few of the changes are actually fixes for cases
where the old code didn't handle substitutions properly.
A few others are subjective, for example a generic parameter
list of the form <T : Proto> now prints as <T where T : Proto>.

We can add heuristics to make the output whatever we want
here; the important thing is that now we're using modern
abstractions.
2016-10-02 23:49:15 -04:00
Slava Pestov
7af52384e0 AST: Add SubstFlags::DesugarMemberTypes
For code completion to use Type::subst() without undoing
previously-added heuristics, we need a form of member lookup
that strips the outermost typealias type. For example, if we
have

protocol P {
  associatedtype Fruit
}

struct Apple {}
typealias Pear = Apple

class Bowl : P {
  typealias Fruit = Pear
}

With DesugarMemberTypes OFF, the substitution 'T := Bowl'
applied to 'T.Fruit' yields 'Bowl.Fruit'.

With DesugarMemberTypes ON, the same substitution instead
produces 'Pear' (note: not 'Apple'; we only desugar one
level here, to match the current code completion behavior).

Also, add another tweak that will become important shortly;
if a type witness cannot be derived, set the type witness
to an alias type pointing to an error type, instead of
directly storing an error type in there.
2016-10-02 23:49:14 -04:00
Michael Ilseman
e1b2a27bac Merge pull request #5060 from milseman/import_name
Import name
2016-09-29 11:10:00 -07:00
Michael Ilseman
fe4b66f875 [TypeCheckType] Setters are escaping by default only at top level.
We have a special case check for the no-escape-by-default rules for a
computed property setter's newValue argument, which if a closure,
obviously has to be escaping. But, we checked this by checking the
type's overall DeclContext, which unfortunately meant we also made
nested closures escaping implicitly. This fixes that to only tack on
the implicit escaping at the top level for the setter's type.
2016-09-28 09:58:22 -07:00
Michael Ilseman
2c5065d236 [TypeCheckType] Move Setter newValue logic into Options
By moving the is-setter-newValue logic into a TypeCheckOption, we
allow more local reasoning inside of resolve type and can plumb the
special knowledge directly into applyNonEscapingFromContext. This is a
little cleaner, but mainly has the advantage that it will keep future
refactorings of the AST and escapability more localized.

Added test cases for SILGen as well, to make sure we don't crash
(enforces getter/setter escapability parity).
2016-09-27 17:56:37 -07:00
Michael Ilseman
19fc5f9409 [TypeCheckType] Setters are escaping by default only at top level.
We have a special case check for the no-escape-by-default rules for a
computed property setter's newValue argument, which if a closure,
obviously has to be escaping. But, we checked this by checking the
type's overall DeclContext, which unfortunately meant we also made
nested closures escaping implicitly. This fixes that to only tack on
the implicit escaping at the top level for the setter's type.
2016-09-27 09:31:45 -07:00
practicalswift
02d3fcb6ae [gardening] Fix accidental \t 2016-09-25 21:47:34 +02:00
Rintaro Ishizaki
65f3ba5dbb [Sema] Unify fix-it logic for enclosing trailing closure in argument parens (#4961)
`tryDiagnoseTrailingClosureAmbiguity` and `checkStmtConditionTrailingClosure`
had similar logic.
Added swift::fixItEncloseTrailingClosure function.
2016-09-24 18:33:40 +09:00
Pavel Yaskevich
054e3e4eb4 [Diagnostics] SR-2242: Fix diagnostic when argument label is omitted 2016-09-23 17:17:59 -07:00
Pavel Yaskevich
2dfc8b60ad [Diagnostics] Refactor argument source range retrieval 2016-09-23 15:14:21 -07:00
Pavel Yaskevich
f0078d6bc3 [Diagnostics] Refactor argument matching when dealing with a single candidate 2016-09-23 15:14:21 -07:00
Jordan Rose
d89c232f59 Add empty parens to var-to-function renames, take two. (#4938)
This time, propagate the decl marked deprecated or unavailable through
to the fix-it, so we can be sure it's a var.

https://bugs.swift.org/browse/SR-1649
2016-09-23 14:56:08 -07:00