Commit Graph

805 Commits

Author SHA1 Message Date
Nate Chandler
4a8a647e4c [Test] Used test header rather than SDK.
Stopped validation-test/compiler_crashers_2_fixed/rdar79383990.swift
from trying to call -[NSBackgroundActivityScheduler scheduleWithBlock:]
async--that method is now annotated NS_SWIFT_DISABLE_ASYNC.
2021-07-28 20:37:46 -07:00
nate-chandler
8345174bae Merge pull request #38370 from nate-chandler/rdar79383990
[SILGen] Used formal type when bridging completion handler arguments.
2021-07-26 10:57:49 -07:00
Nate Chandler
c493632b68 [SILGen] Used type AbstractionPattern.
Previously, AbstractionPattern::getOpaque() was used for async
continuations.  That was problematic for functions like

```objc
- (void)performVoid2VoidWithCompletion:(void (^ _Nonnull)(void (^ _Nonnull)(void)))completion;
```

whose completion takes a closure.  Doing so resulted in attempting to
build a block to func thunk where one of the functions had an out
parameter.

Instead, use the AbstractionPattern(ty).

rdar://79383990
2021-07-24 14:25:27 -07:00
Slava Pestov
8d65042d22 SIL: Fix verifier failure when witness_method's lookup type involves dynamic Self
Fixes rdar://problem/80296242.
2021-07-19 21:25:05 -04:00
jiaren wang
c5de1f0800 [SR-14824] Improve diagnostic for multi-statement closures instead of saying "too complex closure return type" 2021-06-30 14:36:38 +08:00
Slava Pestov
70f038a18b Sema: Avoid an assertion when diagnosing failures in some cases with invalid associated types
The solver's simplifyType() can produce a DependentMemberType with a
concrete or archetype base, if that associated type could not be
resolved during associated type inference.

mapTypeOutOfContext() could assert when given a type that violates
invariants in this manner. Instead, let's directly call subst() here,
providing a conformance lookup function (which will probably end up
returning ErrorTypes).

Fixes https://bugs.swift.org/browse/SR-14672 / rdar://problem/78626943.
2021-06-15 16:17:20 -04:00
Slava Pestov
3e1e9fae1e Add regression test for fixed crasher 2021-05-17 21:57:23 -04:00
Slava Pestov
d2ada0de4e Add regression test for fixed crasher 2021-05-17 21:57:23 -04:00
Pavel Yaskevich
2898b50b7f Revert "Revert "[TypeChecker] PreCheck: Don't strip away tuple/paren from subscripts …"" 2021-05-04 11:19:33 -07:00
Pavel Yaskevich
b12d57afac Revert "[TypeChecker] PreCheck: Don't strip away tuple/paren from subscripts …" 2021-05-03 11:55:25 -07:00
Pavel Yaskevich
f36ecf2fa1 [CSSimplify] Allow overload choices with missing labels to be considered for diagnostics
Let's make use of a newly added "disable for performance" flag to
allow solver to consider overload choices where the only issue is
missing one or more labels - this makes it for a much better
diagnostic experience without any performance impact for valid code.
2021-04-28 12:04:57 -07:00
Pavel Yaskevich
a21f323c16 Merge pull request #36946 from xedin/rdar-61749633
[TypeChecker] PreCheck: Don't strip away tuple/paren from subscripts …
2021-04-26 12:19:55 -07:00
Strieker
72fc506612 "modified existing validation test after improving error handling for composed property werapper mismatches" 2021-04-22 22:08:03 -07:00
Alex Hoppen
b68443156a Merge pull request #36818 from ahoppen/pr/rdar76329083
[TypeChecker] Fix assertion failure when using Self in extension that’s not on top-level
2021-04-21 10:20:57 +02:00
Pavel Yaskevich
593bbab880 [TypeChecker] PreCheck: Don't strip away tuple/paren from subscripts and ObjC literals
`PreCheckExpression` already skips calls, make sure that invalid subscripts,
dynamic subscript, ObjC literals preserve paren/tuple for an index/argument.

Resolves: rdar://61749633
2021-04-16 11:40:19 -07:00
Slava Pestov
508dc8c0d9 Sema: Handle Error self-conformance in TypeChecker::containsProtocol()
While ModuleDecl::lookupConformance() did the right thing here, we have
another entry point, TypeChecker::containsProtocol(), that also needs
to special-case Error.

Fixes https://bugs.swift.org/browse/SR-13734 / rdar://problem/70338670.
2021-04-14 17:55:43 -04:00
Slava Pestov
cf646da193 Merge pull request #36888 from slavapestov/opaque-result-type-with-tuple
SIL: A tuple type can be lowered with an opaque result type as the original type
2021-04-13 17:27:56 -04:00
Slava Pestov
a0c215b7d2 SIL: A tuple type can be lowered with an opaque result type as the original type
AbstractionPattern::matchesTuple() is used by various assertions, and
the condition was too strict. Relax the condition to fix an assertion
failure in the case where an opaque result type has a tuple as its
underlying type.

Fixes https://bugs.swift.org/browse/SR-14426 / rdar://problem/76057095.
2021-04-13 14:46:58 -04:00
Alex Hoppen
78d6fb2e26 [TypeChecker] Fix assertion failure when using Self in extension that’s not on top-level
We fail to resolve the extended type if an extension is not declared at the top level. This causes us to diagnose a lookup failure on `Self`. If the extended type is a protocol, we thus end up with a nominal Self type that’s not a class, violating the assertion that’s currently in place. To fix the crasher, convert the assertion to an `if` condition and issue a generic "cannot find type 'Self' in scope" in the else case.

Fixes rdar://76329083
2021-04-08 18:50:14 +02:00
Slava Pestov
7bd05080e0 GSB: Add regression test for already-fixed crasher 2021-04-08 01:57:29 -04:00
Robert Widmann
2e9fb5a057 Merge pull request #36723 from CodaFi/extension-cord
Add a Null Check for Missing Generic Signatures
2021-04-04 23:14:38 -07:00
Slava Pestov
bcee54b936 GSB: The combination of a superclass and conformance requirement might force a type to be concrete
A protocol can constrain an associated type to Self:

    protocol P {
      associatedtype A : Q where A.B == Self
    }

    protocol Q {
      associatedtype B
    }

And a class might conform to this protocol:

    class C : P {
      typealias A = D
    }

    class D : Q {
      typealias B = C
    }

The generic signature <Self where Self : P, Self : C> is built during
conformance checking. Since Self : C, we must have that Self.A == D;
since D.B == C, the requierement 'A.B == Self' in protocol P implies
that 'Self == C'. So the correct minimized signature here is
<Self where Self == C>.

This wasn't handled properly before, because of assumptions in
removeSelfDerived() and a couple of other places.

Fixes rdar://71677712, rdar://76155506, https://bugs.swift.org/browse/SR-10033,
https://bugs.swift.org/browse/SR-13884.
2021-04-03 23:04:39 -04:00
Robert Widmann
9e496d38f9 Add a Null Check for Missing Generic Signatures
When an extension is nested inside of an invalid decl context, it is
going to pull the signature of its nearest enclosing context instead of
its extended type. This leads to a null signature since the nearest
enclosing context for an extension should always be its parent source
file.

rdar://76049852
2021-04-02 09:43:35 -07:00
Slava Pestov
f3f2ea6f62 AST: Skip requirement checks in IsBindableVisitor::visitBoundGenericType() if substituted type is an interface type
IsBindableVisitor is part of TypeBase::substituteBindingsTo(), which
is used for two things:

- Checking if one contextual type is a proper substitution of another
  contextual type, used in the solver

- To compute the substituted generic signature when lowering a SIL
  function type

In the first case, we're interested in knowing if the substitution
succeeds or fails. In the second case, we know the substitution is
correct by construction, and we're trying to recover the generic
requirements.

In the second case though, the substituted type might be an
interface type, and if the interface type is constrained to a
concrete type in the original type's generic signature, we would
conclude that the substitution should fail.

This is incorrect, and we should just skip the check if the
substituted type is an interface type -- we do not have enough
information to know if it succeeds, and instead we must assume it
does because otherwise the substituted type passed in to type
lowering must be incorrect.

Fixes https://bugs.swift.org/browse/SR-13849.
2021-04-01 01:02:38 -04:00
Slava Pestov
1d9b202719 GSB: Fix inconsistent 'redundant conformance' diagnostic 2021-03-27 00:35:19 -04:00
Slava Pestov
99d49f0ccb GSB: When rebuilding a signature, use the as-written requirements instead of the minimized ones
We rebuild a signature after dropping redundant conformance requirements,
since conformance requirements change the canonical type and conformance
access path computation.

When doing this, instead of using the canonical requirements from the
signature, use the original as-written requirements.

This fixes some weirdness around concrete same-type requirements.

There's a philosophical benefit here too -- since we rebuild the
signature without ever having built the old signature, we never create
an invalid GenericSignature in the ASTContext.

Fixes rdar://problem/75690903.
2021-03-25 17:35:52 -04:00
nate-chandler
64c75828f7 Merge pull request #36529 from nate-chandler/rdar75547146
Sema: Stop checking @main if no decl synthesized.
2021-03-23 08:04:40 -07:00
Nate Chandler
6c5d62c011 Sema: Stop checking @main if no decl synthesized.
When requestifying the synthesis of the main function for the type
annotated @main via SynthesizeMainFunctionRequest, what were previously
were bailouts from AttributeChecker::visitMainTypeAttr had to become
returns of nullptr from SynthesizeMainFunctionRequest::evaluate.
Consequently, AttributeChecker::visitMainTypeAttr must check whether
synthesis actually succeeded before proceeding to to register the main
decl for a file.

In simple cases, this happened to work because
SourceFile::registerMainDecl would return early if the decl being
registered was the same as the already registered main decl and in
particular if the decl being registered was nullptr and the previously
registered one was nullptr as well.  When, however, there are multiple
types annotated @main, if a function is successfully synthesized for one
type but synthesis fails for the second, an attempt will be made to
register nullptr as the main decl and will move past the check at the
beginning of SourceFile::registerMainDecl, resulting in a crash.

Here, we bail from AttributeChecker::visitMainTypeAttr if function
synthesis fails and add an assert to SourceFile::registerMainDecl that
the provided decl is non-null.

rdar://75547146
2021-03-19 16:54:16 -07:00
Robert Widmann
ee5f2c3131 Redo getConditionalRequirements as a Request 2021-03-18 23:28:52 -07:00
Slava Pestov
504d4f526a Add two passing regression tests and a failing one 2021-03-17 17:25:41 -04:00
Slava Pestov
6f4f9f8c0f Merge pull request #36411 from slavapestov/fix-gsb-verification
GSB: Move signature verification from CanGenericSignature::getCanonical() to computeGenericSignature()
2021-03-12 09:36:35 -05:00
Slava Pestov
f240b95fa7 Merge pull request #36407 from slavapestov/tjw-regression-from-sr11153
Add regression tests for fixed crashers
2021-03-11 23:42:43 -05:00
Slava Pestov
91ebe4485c GSB: Move signature verification from CanGenericSignature::getCanonical() to computeGenericSignature()
Doing this when computing a canonical signature didn't really
make sense because canonical signatures are not canonicalized
any more strongly _with respect to the builder_; they just
canonicalize their requirement types.

Instead, let's do these checks after creating the signature in
computeGenericSignature().

The old behavior had another undesirable property; since the
canonicalization was done by registerGenericSignatureBuilder(),
we would always build a new GSB from scratch for every
signature we compute.

The new location also means we do these checks for protocol
requirement signatures as well. This flags an existing fixed
crasher where we still emit bogus same-type requirements in
the requirement signature, so I moved this test back into
an unfixed state.
2021-03-11 21:07:33 -05:00
Slava Pestov
29307345ad Add regression test for a fixed crasher 2021-03-11 17:06:12 -05:00
Slava Pestov
3644a5ec81 Add regression test for a fixed crasher
This test case was also posted by a developer in
https://bugs.swift.org/browse/SR-11153, but it appears to
be a different problem that was fixed in Swift 5.2.
2021-03-11 17:04:30 -05:00
Robert Widmann
779276a0c6 Bail On Checking Invalid Precedence Group
When the user spells an invalid precedence group, the Relation for that
group will fail to resolve the decl. We need to handle this in
checkPrecedenceGroup. Also add some asserts while I'm here.

rdar://75248642
2021-03-11 12:40:23 -08:00
Slava Pestov
60ae2262b0 Merge pull request #36101 from slavapestov/conformance-access-path-cleanup
Re-implement GenericSignature::getConformanceAccessPath()
2021-02-24 12:40:43 -05:00
Robert Widmann
326fc09576 Remove a Bogus Assertion
The self type in this routine is absolutely allowed to resolve to an
Optional.

rdar://74557857
2021-02-23 14:24:54 -08:00
Slava Pestov
f3f9555c55 GSB: New implementation of getConformanceAccessPath()
A new implementation from "first principles". The idea is that
for a given conformance, we either have an explicit source
which forms the root of the requirement path, or a derived
source, which we 'factor' into a parent type/parent protocol
pair, and a requirement signature requirement.

We recursively compute the conformance access path of the
parent type and parent protocol, and append the path element
for the requirement.

This fixes a long-standing crasher, and eliminates two hacks,
the 'usesRequirementSource' flag in RequirementSource, and
the 'HadAnyRedundantConstraints' flag in GenericSignatureBuilder.

Fixes https://bugs.swift.org/browse/SR-7371 / rdar://problem/39239511
2021-02-23 16:26:04 -05:00
Slava Pestov
034c2be004 GSB: An unresolved DependentMemberType might resolve to a concrete TypeAliasDecl with a dependent underlying type
Fixes https://bugs.swift.org/browse/SR-11639 / rdar://problem/56466696
2021-02-12 17:47:31 -05:00
Slava Pestov
5acd795178 Add regression test for recently-fixed crasher 2021-02-11 16:33:35 -05:00
Slava Pestov
8edf4264ae GSB: Better handling of unresolved DependentMemberTypes in maybeResolveEquivalenceClass()
A DependentMemberType can either have a bound AssociatedTypeDecl,
or it might be 'unresolved' and only store an identifier.

In maybeResolveEquivalenceClass(), we did not handle the unresolved
case when the base type of the DependentMemberType had itself been
resolved to a concrete type.

Fixes <rdar://problem/71162777>.
2021-02-11 16:33:35 -05:00
Robert Widmann
013127a947 Fix a Simple Crash-On-Invalid For @_spi
The parser attempts to recover here by producing a broken VarDecl with
no parent pattern. The DeclChecker sees this when trying to install
a default initializer in the linked regression test and crashes because
it tries to look into a null parent pattern.

rdar://74154023
2021-02-09 12:36:50 -08:00
Slava Pestov
65620d75f3 GSB: FloatingRequirementSource::getSource() now takes a ResolvedType 2021-02-07 01:14:52 -05:00
Daniel Rodríguez Troitiño
748339a83a [test] Mark concurrency tests with appropiate REQUIRES. (#35624)
The Python build system always enables concurrency, but CMake has it
disable by default. Collaborators that do not use the Python build
system and use directly CMake will have it disable, unless they
explicitely enable it. If the tests are not marked as requiring the
concurrency features, the tests will fail to execute when concurrency is
disabled.

The changes add the `REQUIRES: concurrency` line to many tests that deal
with concurrency, but wasn't marked as such.
2021-02-01 11:45:15 -08:00
Robert Widmann
0943351fe7 Use the Correct DeclContext When Simplifying Member Constraints
Looking for the parent source file is going to fail when the paramter
we're interested in comes from a module context. Request the correct
top-level context in those situations.

rdar://73379770
2021-01-20 15:42:35 -08:00
Luciano Almeida
1d7d282065 Merge pull request #35255 from LucianoPAlmeida/SR-12383
[SR-12383][Diagnostics] Do not use canonical type for aka diagnostics instead walk the type recursivelly desugaring
2021-01-19 08:19:00 -03:00
Slava Pestov
c8aee4180e Sema: Fix a couple of crash-on-invalid problems with class inheritance
It is possible for ClassDecl::getSuperclassDecl() to succeed but for
ClassDecl::getSuperclass() to fail. This happens if the superclass is
a generic type and one of the generic arguments could not be resolved,
or does not satisfy the generic requirements, for example; in that
case, a BoundGenericType cannot be formed.

In a couple of places we were not prepared for this possibility.
Let's recover by making judicious use of ErrorType.

Fixes <rdar://problem/73169149>.
2021-01-17 18:06:13 -05:00
Varun Gandhi
b263e99d71 Merge pull request #35367 from mininny/simplify-unused-lvalue-wording
[Diagnostics] Simplify unused lvalue warning wording
2021-01-16 14:29:43 -08:00
Minhyuk Kim
7eaabe1996 Simplify unused lvalue warning wording 2021-01-15 22:14:56 +09:00