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.
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.
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> {
^
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.
UnresolvedConstructorExpr is not providing any value here; it's
essentially just UnresolvedDotExpr where the name refers to an
initializer, so use that instead. NFC
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.
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
This reverts commit 5ce503c886 because it
breaks the stdlib build with:
Assertion failed: (!isPolymorphic() && "no args for polymorphic substitution"), function substGenericArgs
tested in the testsuite because they are generally already handled
by the CSDiags infrastructure. Remove them in prep for dismantling
the Failure infrastructure. NFC.
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
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.
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.
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.
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>.
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.
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.
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.
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.
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()
^~~ ~~~
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.
closures which have already been transformed into void conversion closures.
This fixes 28213-swift-expr-walk.swift/28187-llvm-foldingset-swift-constraints-constraintlocator.swift
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.