Commit Graph

5910 Commits

Author SHA1 Message Date
gregomni
b697a208fc Check for nearness to bound type when generic arg doesn't match
Also made evaluateCloseness into a member.
2016-01-22 08:04:16 -08:00
practicalswift
33312eac6b [gardening] Remove unreachable/unused/redundant code
* Make parameter naming in forward declaration match definition
* Remove unused argument to function persistAsync(…)
* Remove unused enum ShouldHalt
* Remove unused enum class IsProtocol
* Remove unused function dumpTypeSubstitutionMap()
* Remove unused function template getFirstPairElt(…)
* Remove unused method addConstantWordInWords(…)
* Remove unused method asExistentialTI()
* Remove unused method currentTrackedState()
* Remove unused method getNumBodyParameters()
* Remove unused method getSuccIndex()
* Remove unused method getTypeOfDeclReference(…)
* Remove unused method hasStructWithAtMostOneNonTrivialField(…)
* Remove unused method initForDirectValues()
* Remove unused method nextIfNot(…)
* Remove unused method overwriteLoweredValue(…)
* Remove unused method removeColumn(…)
* Remove unused methods HasSingleDecl() and GetFirstDecl()
* Remove unused methods overwriteLoweredExplosion(…) and setLoweredSingleValue(…)
* Remove unused methods requireRetainablePointerValue(…), getMethodSelfInstanceType(…) and isSelfArchetype(…)
* Remove unused methods setAsEmptyDirect(), setAsSingleDirectUnmanagedFragileValue(…), setAsIndirectAddress(…) and getDirectValues()
* Remove unused struct CachedMemberInfo
* Remove unused struct CallEdit
* Remove unused struct ErrorImportInfo
* Remove unused synonym ConformancePair
* Remove unused variable SemaInfo
* Remove unused variable localDeclNameNode
* Remove unused variables kindToken and kindLoc
2016-01-22 09:43:24 +01:00
gregomni
2b301938e0 [SR-69][Sema] Improved quality of diagnoses messages
In the specific case of sr-69, and in a bunch of other code where
errors arise involving generic function application, better type
constraint failure diagnoses are being masked by the overly
conservative implementation in evaluateCloseness(). If the actual arg
types didn’t exactly match the parameter types, we’d always diagnose a
non-specific arguments-don’t-match error instead of allowing discovery
of better errors from the constraint system.

This commit adds more cases where evaluateCloseness will return
CC_ExactMatch, specifically in application of functions with one or
more arguments of a single archetype, like `func min<T: Comparable>(T,
T) -> T`. It verifies that the actual argument type
isSubstitutableFor() the archetype, and that all such arguments are of
the same type. Anything more complicated than that still has the
previous behavior of not matching at all.

I think the final answer here ought to be to make a constraint system
with type variables for any archetypes, add appropriate constraints to
the actual args and then see if the system can solve all the argument
constraints at once. That’s because the next most complicated set of
things to handle in the stdlib are things like `func -<T:
Strideable>(lhs: T, rhs: T.Stride)` where generic argument types depend
on each other. I tried attacking that, but it was too big of a bite for
me to manage all at once. But there are FIXME’s here to try that again
at some point.

New tests for SR-69 are at the end of deduction.swift, and the rest of
the test changes are generally improved deduced diagnoses. I think the
changed diagnoses in materializable_restrictions.swift is the only one
which is worse instead of better, and that’s just because the previous
general message mentioned `inout` basically accidentally. Opportunity
for further improvement (a new diagnosis maybe) there.

Validation tests run and passed.
2016-01-21 23:48:54 -08:00
Slava Pestov
c75f443c83 Sema: Better fix for duplicate emission of accessors
When compiling a module with multiple FileUnits (eg, while running
swiftc without -whole-module-optimization), we emit all decls
in the ExternalDeclarations list for every FileUnit, leading to
duplicate symbols if any of those decls were public.

Joe's workaround skipped decls on ExternalDefinitions that were
already emitted in the current FileUnit, but that was not sufficient;
the right fix is to not put stuff on ExternalDeclarations at all,
if we're going to emit it as part of a decl inside our file.

In this case, the synthesized _code accessors for an ErrorType
conformance do not belong in ExternalDefinitions, because they're
part of an ExtensionDecl that is in the current FileUnit.

Finally add some tests for this stuff, because it appears our
existing coverage was insufficient.
2016-01-21 22:30:56 -08:00
Chris Lattner
f102876943 Improve diagnostics for unbound archetypes coming from a type, to indicate
information about where the archetype was defined.  Before:

t.swift:6:17: error: generic parameter 'T' could not be inferred
var a : Int = A.foo()
                ^

After:

t.swift:6:17: error: generic parameter 'T' could not be inferred
var a : Int = A.foo()
                ^
t.swift:2:8: note: 'T' declared as parameter to type 'A'
struct A<T> {
       ^
2016-01-21 17:37:39 -08:00
Chris Lattner
2910d54cf6 Fix <rdar://problem/24267414> QoI: error: cannot convert value of type 'Int' to specified type 'Int'
When a contextual conversion has a matching type, don't diagnose it as a
conversion error, the problem is due to something else (in this case, an
unresolved archetype somewhere else in the expression).

Before:
t.swift:6:17: error: cannot convert value of type 'Int' to specified type 'Int'
After:
t.swift:6:17: error: generic parameter 'T' could not be inferred

This should still be a bit better to provide information about where the T
archetype came from, but at least now it isn't completely wrong diagnostic.
2016-01-21 17:37:39 -08:00
Dmitri Gribenko
f5153572d7 stdlib: rename count labels in underscored protocols
lengthInBytes => utf8CodeUnitCount

numberOfCodeUnits => utf16CodeUnitCount
2016-01-21 17:18:15 -08:00
Doug Gregor
3520f7af04 [Sema] Get rid of "allZeros" string literal. NFC 2016-01-21 15:06:09 -08:00
David Farler
e03a064586 Revert "REVERTME: Disallow partial application of super methods except for implicit self"
This reverts commit 7796d78008.

Now that multiple parameter list declarations are an error in Swift 3,
this diagnostic isn't necessary anymore.
2016-01-21 14:48:38 -08:00
John McCall
130d31c346 Don't ignore tuple labels in same-type *or stronger* constraints.
Thanks to Doug Gregor for finding the bug here.

Fixes rdar://24210190 (by making it ill-formed).
2016-01-21 11:27:33 -08:00
Chris Lattner
2dcad44ff1 Fix <rdar://problem/23904262> QoI: ivar default initializer cannot reference other default initialized ivars?
This was previously fixed for method calls, but this part handles property accesses.
2016-01-20 22:50:54 -08:00
Chris Lattner
2ae2e5ffa4 Fix <rdar://problem/22326930> QoI: "argument for generic parameter 'Element' could not be inferred" lacks context
Now that diagnostic emission is detangled from default argument handling.
2016-01-20 22:30:14 -08:00
Chris Lattner
638816e621 Now that resolveLocatorToDecl has a single caller, move it to CSApply.cpp
and make it a static function.  NFC.
2016-01-20 21:56:04 -08:00
Chris Lattner
005809d8a9 Significantly simplify noteTargetOfDiagnostic by cutting it off of
resolveLocatorToDecl entirely.  Rename it to noteTargetOfMissingArchetype.
NFC.
2016-01-20 21:52:28 -08:00
Chris Lattner
e901bd03dc Continue whittling away at complexity in resolveLocatorToDecl.
This time remove the hacky/fixme code to drill into parameter lists
which is dead.
2016-01-20 20:53:52 -08:00
Chris Lattner
a230d402d2 simplify some code to eliminate unnecessary tests, NFC. 2016-01-20 18:08:29 -08:00
Chris Lattner
5957a9274e Reapply Simplify resolveLocatorToDecl to return a ConcreteDeclRef instead of
having it return a ResolvedLocator, allowing us to remove ResolvedLocator

The previous commit accidentally dropped the hunk in CSApply.cpp.  NFC.
2016-01-20 18:08:29 -08:00
Doug Gregor
fd3f03f3be Remove UnresolvedConstructorExpr.
UnresolvedConstructorExpr is not providing any value here; it's
essentially just UnresolvedDotExpr where the name refers to an
initializer, so use that instead. NFC
2016-01-20 17:09:02 -08:00
Doug Gregor
c9c1d1390c [SE-0021] Allow naming of specific initializers via "self.init(foo:bar:)". 2016-01-20 17:09:02 -08:00
Doug Gregor
5f07f6b12f Remove all vestiges of UnresolvedSelectorExpr. NFC 2016-01-20 17:09:01 -08:00
Doug Gregor
ecfde0e71c Start parsing names with argument labels.
Basic implementatation of SE-0021, naming functions with argument
labels. Handle parsing of compound function names in various
unqualified-identifier productions, updating the AST representation of
various expressions from Identifiers to DeclNames. The result doesn't
capture all of the source locations we want; more on that later.

As part of this, remove the parsing code for the "selector-style"
method names, since we now have a replacement. The feature was never
publicized and doesn't make sense in Swift, so zap it outright.
2016-01-20 17:09:01 -08:00
Devin Coughlin
523296161d [Sema] Fix assertion building refinement context for synthesized accessors.
For VarDecls with synthesized trivial accessors, we may have not a valid
location for the end of the braces, which causes an assertion failure when
constructing the type refinement context range for underlying storage.

This is a quick fix to fall back to using the range of the storage in this case.
The right fix here is to update AbstractStorageDecl::addTrivialAccessors() to
take brace locations and have callers of that method provide appropriate source
locations.

rdar://problem/24258839
2016-01-20 16:00:15 -08:00
Slava Pestov
1d77d810fd Re-apply "Sema: Always synthesize accessors for structs, unless they were imported from Clang"
This reverts commit 24a70e17ea.
2016-01-20 15:04:10 -08:00
Max Moiseev
9a018bd77d Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-01-20 14:38:22 -08:00
Mark Lacey
061c7776d8 Revert "Simplify resolveLocatorToDecl to return a ConcreteDeclRef instead of"
This reverts commit 5ce503c886 because it
breaks the stdlib build with:
  Assertion failed: (!isPolymorphic() && "no args for polymorphic substitution"), function substGenericArgs
2016-01-20 13:23:04 -08:00
Chris Lattner
5ce503c886 Simplify resolveLocatorToDecl to return a ConcreteDeclRef instead of
having it return a ResolvedLocator, allowing us to remove ResolvedLocator.
2016-01-20 10:57:33 -08:00
Chris Lattner
69ba5bc876 Remove shouldDiscardFailures() from ConstraintLocator,
remove shouldRecordFailures() from ConstraintSystem.  NFC.
2016-01-20 10:38:37 -08:00
Chris Lattner
a1112b3c7d Remove Failure and some of the supporting infrastructure. NFC. 2016-01-20 10:28:21 -08:00
Chris Lattner
f0ff88379f The last few Failure's generated by the constraint solver are not
tested in the testsuite because they are generally already handled
by the CSDiags infrastructure.  Remove them in prep for dismantling
the Failure infrastructure.  NFC.
2016-01-20 10:17:10 -08:00
Mark Lacey
24a70e17ea Revert "Sema: Always synthesize accessors for structs, unless they were imported from Clang"
This reverts commit 2b6ab633fc because it
at least breaks:
    Swift :: stdlib/SequenceType.swift.gyb
and possibly also results in some or all of these failures:
    Swift :: compiler_crashers/27944-swift-astvisitor.swift
    Swift :: compiler_crashers/28200-swift-typebase-getdesugaredtype.swift
    Swift :: stdlib/CollectionType.swift.gyb
    Swift :: stdlib/MicroStdlib.swift
2016-01-20 08:32:39 -08:00
Slava Pestov
2b6ab633fc Sema: Always synthesize accessors for structs, unless they were imported from Clang
This fixes the issue that "SILGen: Correctly emit accessors synthesized to
witness protocol requirements" was meant to solve, but in a simpler way.

A better fix would be to first address the issue where @_transparent
function bodies are not serialized in some cases, and then only emit
synthesized accessors as needed, in the original version of this patch.
To fix the duplicate symbol issues, we would emit the synthesized
accessors with shared linkage, which would always work once serialized
bodies were available.

For resilient structs of course, we'll always need to emit accessors
anyway.
2016-01-20 02:11:53 -08:00
Slava Pestov
5273249838 Sema: Fix for setter->isMutating() check before setter was type checked
With an upcoming patch we would call setMutating() on materializeForSet
before computing the setter's isMutating() in the case where a setter
was explicitly declared 'nonmutating'.

Fix that by replacing the setter->isMutating() call with a direct
computation of the expected result.

It seems that the materializeForSet of protocol protocol requirements
has to be mutating, even if the protocol is a class protocol or the
property is nonmutating -- I need to investigate why and fix SILGen
to not make this assumption, but in the meantime, opt-out of the
new logic with protocol requirements to avoid more breakage.
2016-01-20 01:50:17 -08:00
Slava Pestov
31718e7914 Sema: Fix checkMutating() for stored properties that had accessors synthesized for them already
Otherwise, a struct's static property cannot witness two different
protocol requirements, because the second one thinks it is mutating.

Probably we should push the isInstanceMember() check up into the
code that computes isMutating(). A more principled cleanup for this
code is coming soon.
2016-01-20 01:50:17 -08:00
Doug Gregor
7d70b704e4 Merge commit '5e11e3f7287427d386636a169c4065c0373931a8' into swift-3-api-guidelines 2016-01-19 23:18:20 -08:00
Chris Lattner
b3ac017277 Fix <rdar://23248290> Name lookup: "Cannot convert type 'Int' to expected argument type 'Int'" while trying to initialize ivar of generic type in class scope
Type resolution wasn't looking through property initializer decl contexts
to find out whether an unbound generic type reference was referring to the
enclosing type.  Previously we'd reject this with:

error: cannot convert value of type 'Int' to specified type 'Int'
  private var data: Int = Matrix4.size()
                          ~~~~~~~~^~~~~~

which was super confusing.  The problem was that we weren't resolving
Matrix4 to Matrix4<T>.
2016-01-19 23:12:30 -08:00
Chris Lattner
4341ef35cd Move CalleeCandidateInfo to using NameLookupFlags::IgnoreAccessibility
for initializer lookup, allowing it to produce more specific diagnostics
when referring to a private initializer that the compiler can see.

In addition to improving diagnostics, this allows us to eliminate the
NoPublicInitializers failure kind.
2016-01-19 22:52:26 -08:00
Chris Lattner
e4d54392dd Merge pull request #1020 from gregomni/misc-cleanup
[Sema] Misc code cleanup (removed unnecessary switch)
2016-01-19 22:51:43 -08:00
gregomni
46bd289493 [Sema] Misc code cleanup (removed unnecessary switch)
Was just reading through the code here and noticed that the result of
matchTypes() here is always the returned result from this function, so
might as well save code and confusion and return it directly.
2016-01-19 22:24:49 -08:00
Xi Ge
0f4e7a5ea5 [CodeCompletion] Add code completion for where clauses. rdar://24245022
When completing at "extension A where #^HERE^#", we suggest the generic params of A to users.
2016-01-19 14:17:15 -08:00
Chris Lattner
2f5af054bf Don't complain about unreachable catch blocks that are due to platform
specific #if code.  This has no known ticket filed for them, Dmitri
mentioned this on swift-dev.
2016-01-18 23:05:06 -08:00
Chris Lattner
5a4464fbca Fix <rdar://19935319> QoI: poor diagnostic initializing a variable with a non-class func
It is a common point of confusion that property initializers cannot access self, so
produce a tailored diagnostic for it.

Also, when building implicit TypeExprs for the self type, properly mark them implicit.
2016-01-18 22:37:22 -08:00
gregomni
4b07e1b0fb [SR-547] Invalidate more parts of protocols involved in recursive definitions
The idea here is to do more marking of the generic parts of the
protocol as being invalid as soon as the recursiveness is diagnosed in
order to simplify checking (and avoid infinite loops) down the line.
2016-01-18 14:17:07 -08:00
Doug Gregor
c4a6902589 Abstract the set of known Foundation entities into a .def-driven enum. NFC
Specifically, we don't want to hard-code the Swift names of these
Objective-C entities, because the importer renaming will affect them.
2016-01-17 23:40:14 -08:00
Slava Pestov
7e002fe4f3 Sema: Clean up circularity check in resolveTypeInContext() 2016-01-17 19:39:21 -08:00
Chris Lattner
8a41d14b2d Fix <rdar://problem/21429694> QoI: diagnostic for accessing private methods could be improved
When member lookup completely fails and when CSDiags is the one performing
the lookup, reissue another lookup that ignores access control.  This allows
it to find inaccessible members and diagnose them as such, instead of pretending
we have no idea what the user wants.  We now produce an error message like this:

main.swift:1:6: error: 'foo' is inaccessible due to 'private' protection level
 C().foo()
     ^
test.swift:1:35: note: 'foo' declared here
  internal class C { private func foo() {} }
                                  ^

instead of:

main.swift:1:2: error: value of type 'C' has no member 'foo'
 C().foo()
 ^~~ ~~~
2016-01-17 17:13:07 -08:00
Chris Lattner
849ec50a12 Fix <rdar://problem/21269142> Diagnostic should say why enum has no .rawValue member
If someone is trying to refer to the rawValue of an enum that has no
raw type, give them a hint that they need to go do that.
2016-01-17 15:35:22 -08:00
Chris Lattner
728659d02b My fix for 28203-swift-typebase-getdesugaredtype.swift broke a few other
validation tests that we actually benefiting from the computeType() in
this code producing a dangling pointer to an archetype that hasn't been
created.  Preserve that behavior but still nuke out the assoc type decl's
type when the protocol is invalid, fixing the failures.
2016-01-17 12:22:08 -08:00
Chris Lattner
5ba57cb498 Fix ExprRewriter::coerceClosureExprToVoid to be resilient to type checking
closures which have already been transformed into void conversion closures.

This fixes 28213-swift-expr-walk.swift/28187-llvm-foldingset-swift-constraints-constraintlocator.swift
2016-01-17 12:07:13 -08:00
Chris Lattner
6ea637f698 Fix 28203-swift-typebase-getdesugaredtype.swift by being more careful about setting an errortype on an AssociatedTypeDecl when type checking of the containing protocoltype has failed. 2016-01-17 11:37:35 -08:00
Chris Lattner
20263bf466 fix <rdar://problem/24221830> Bogus "no calls to throwing functions" warning in derived throwing init
This is a case where we used to produce:

<unknown>:0: warning: no calls to throwing functions occur within 'try' expression

Which is bogus, due to the try expr implicitly generated as part of the
implicit super.init call for an init that doesn't otherwise contain a super.init.
Silence this warning by ignoring implicitly generated trys, since this try gets
produced before name binding has resolved exactly which try is being invoked.
2016-01-16 23:15:47 -08:00