Commit Graph

789 Commits

Author SHA1 Message Date
Robert Widmann
2aac6d2af4 Merge pull request #34679 from CodaFi/quality-of-type
Fix Crashes When Resolving Clang Types For Unrepresentable UnsafePointers
2020-11-10 18:53:33 -08:00
Robert Widmann
591c70e364 Fix Crashes When Resolving Clang Types For Unrepresentable UnsafePointers
If the underlying pointer type was not representable in C, we would
attempt to form a pointer type with a null underlying type and crash.
2020-11-10 16:04:05 -08:00
Robert Widmann
363b66a7ad Fully Qualify the Parent Type When Diagnosing Missing Member Types
Use the FullyQualified<Type> abstraction from the prior commit plus DescriptiveDeclKind to give a bit more information when issuing a missing member type diagnostic during type resolution.
2020-11-09 17:10:18 -08:00
Ben Barham
ea365d5d18 [TypeChecker] Do not attempt to skip typechecking for didSet
15f8eb45ea (see PR#26632) introduced
refined didSet semantics where the `oldValue` parameter is skipped if it
isn't used. This would perform typechecking, but later try to set the
body to skipped and thus fire an assert.

For now, do not attempt to skip typechecking of didSet accessors. Still
skip outputting their SIL though.
2020-11-05 11:27:38 +10:00
Pavel Yaskevich
f24e5dbd26 [Diangostics] NFC: Adjust test-cases to expect that "type cannot conform" diagnostic has a note 2020-10-27 14:54:07 -07:00
Slava Pestov
acef0261fc Add regression test for https://bugs.swift.org/browse/SR-13727 / rdar://problem/70298061 2020-10-23 17:07:30 -04:00
Slava Pestov
b3578abe69 Add regression test for https://bugs.swift.org/browse/SR-12473 / rdar://problem/61111969 2020-10-23 17:06:20 -04:00
John McCall
a8464dcaf1 Implicitly import _Concurrency under -enable-experimental-concurrency 2020-10-22 00:53:15 -04:00
Doug Gregor
6a40a3a8aa [SE-0289] Add support for @resultBuilder.
"Function builders" are being renamed to "result builders". Add the
corresponding `@resultBuilder` attribute, with `@_functionBuilder` as
an alias for it, Update test cases to use @resultBuilder.
2020-10-20 13:24:51 -07:00
Slava Pestov
c39bb8970a Add regression test for https://bugs.swift.org/browse/SR-8456 2020-10-19 16:03:06 -04:00
nate-chandler
c9115dc7c5 Merge pull request #34277 from nate-chandler/concurrency/irgen/thread-emission-through-emit-polymorphic
[Async CC] Pull polymorphic parameters from entry point emission.
2020-10-12 14:13:03 -07:00
Nate Chandler
6fce6d9363 [Async CC] Pull poly params from entry point emission.
Previously, EmitPolymorphicParameters dealt directly with an Explosion
from which it pulled values.  In one place, there was a conditional
check for async which handled some cases.  There was however another
place where the polymorphic parameter was pulled directly from the
explosion.  That missed case resulted in attempting to pull a
polymorphic parameter directly from an Explosion which contains only a
%swift.context* per the async calling convention.

Here, those parameters are now pulled from an EntryPointArgumentEmission
subclasses of which are able to provide the relevant definition of what
pulling a parameter means.

rdar://problem/70144083
2020-10-12 10:52:23 -07:00
Slava Pestov
e59069f60f Add a couple of crashers that are now fixed 2020-10-07 12:33:58 -04:00
Slava Pestov
bd36100cb3 Update tests in preparation for disabling parser lookup
I created a second copy of each test where the output changes
after disabling parser lookup. The primary copy now explicitly
calls the frontend with -disable-parser-lookup and expects the
new diagnostics; the *_parser_lookup.swift version calls the
frontend with -enable-parser-lookup and has the old expectations.

This allows us to turn parser lookup on and off by default
without disturbing tests. Once parser lookup is completely
removed we can remove the *_parser_lookup.swift variants.
2020-10-03 09:37:55 -04:00
Robert Widmann
84c5065547 [SR-13461] Relax An Assert
This assert doesn't consider reference storage types in its predicate.
Look through them since they're not relevant to the type consistency
check it's trying to pick out.
2020-08-27 12:51:04 -07:00
Slava Pestov
5e3ef645e6 AST: Fix ASTScopeLookup crash if a PatternBindingEntry's context is not a PatternBindingInitializer
The function builder transform creates pattern bindings parented
in other DeclContexts. If those pattern binding initializer
expressions in turn contain multi-statement closures, we will
try to perform unqualified lookups from those contexts when we
get around to type checking the closure body.

Change some unconditional casts to conditional casts in ASTScope
lookup, to handle this case. The casts are only performed while
checking if the initializer context is part of a 'lazy'
property, which doesn't apply here.

Fixes <rdar://problem/67265731>.
2020-08-24 22:55:23 -04:00
Slava Pestov
21c9c39fa5 Merge pull request #33548 from slavapestov/redecl-check-set-invalid
Sema: Redeclaration checking should not mark implicit decls as invalid
2020-08-19 09:38:02 -04:00
Slava Pestov
a1255a81aa Merge pull request #33549 from slavapestov/regression-test-sr13141
Add regression test for https://bugs.swift.org/browse/SR-13141
2020-08-19 09:37:52 -04:00
Slava Pestov
487f6d9c47 Add regression test for https://bugs.swift.org/browse/SR-12691 2020-08-18 23:56:57 -04:00
Slava Pestov
b183c69d4d Add regression test for https://bugs.swift.org/browse/SR-13141 2020-08-18 23:53:55 -04:00
Slava Pestov
876fe2f639 Sema: Redeclaration checking should not mark implicit decls as invalid
If both the 'other' and 'current' declarations are implicit, we don't
emit a diagnostic unless they are both derived from property wrappers
or lazy property storage.

However, we would still call setInvalid() unconditionally, which splats
an ErrorType into the interface type, which would crash in the AST
verifier if no other diagnostic was emitted.

Fixes <rdar://problem/67259506>.
2020-08-18 23:45:52 -04:00
Slava Pestov
d50e3b00bf Add regression test for rdar://problem/62268062 2020-08-18 18:13:31 -04:00
Slava Pestov
6d84c18ba4 Sema: Check 'where' clause requirements on type witnesses
In the included test case, conformance checking of Wrapper : B would
pick up typealias Foo as a witness for the associated type B.Foo.

However, this typealias Foo is defined in a constrained extension where
T : A, and the underlying type references the associated type A.Foo
on T.

The resulting substitution is invalid when the conformance Wrapper : B
is used in a context where T does not conform to A.

Instead, we should ignore this typealias entirely, since it appears
in an unusable constrained extension.

Fixes <rdar://problem/60219705>, <https://bugs.swift.org/browse/SR-12327>,
<https://bugs.swift.org/browse/SR-12663>.
2020-08-15 01:43:13 -04:00
Slava Pestov
5ad4fa8b07 SIL: Don't canonicalize struct field and enum element types against the wrong signature
The replacement types of the substitution map are either going
to be contextual types, or interface types using some generic
signature. There is no requirement that this generic signature
is the generic signature of the type declaration itself.

By using the generic signature of the type declaration, we
could incorrectly canonicalize generic parameters to concrete
types if the type itself was defined in a constrained extension,
as in the test case here.

Fixes <rdar://problem/65272763>.
2020-08-11 22:54:19 -04:00
Robert Widmann
aada983ceb Replace supersuperclassConformsTo
This more powerful primitive is capable of
1) Detecting invalid classes
2) Detecting invalid superclasses
3) Detecting circularity in inheritance hierarchies

The attached crasher demonstrates the reason we need to validate all of these predicates. Simply put, a circular class hierarchy is always going to report the superclass conforms to any protocol with a declaration in the source. Leveraging this, one could construct any circular class hierarchy, and a conformance to Codable would immediately crash because we got as far as trying to build a CodingKeys enum with an absolutely nonsensical structure.

This also has the added benefit of de-complecting an enormous amount of codable conformance code.

rdar://66588925
2020-08-10 14:38:29 -07:00
Suyash Srijan
3502e07bf0 [Mangling] Add a new mangling for opaque return type to use when mangling an ObjC runtime name (#33035)
* [Mangling] Add a new mangling to represent opaque return type for ObjC runtime name

* [Docs] Add the new 'Qu' mangling to 'Mangling.rst' document

* [Test] Update test invocation arguments
2020-08-05 05:03:45 +01:00
Slava Pestov
769c4c1911 Sema: Fix some crashes with invalid nesting of extensions and protocols
Make sure we consistently use getParentForLookup() and not getParent()
when looking at generic DeclContexts. This is because an extension or
protocol that is nested inside of another generic context must never
inherit generic parameters from the parent context.

We already had this invariant enforced in some places, but now that we
do it more consistently we can fix more crashes of this kind.

Fixes <rdar://problem/58813746>, <https://bugs.swift.org/browse/SR-13004>.
2020-07-28 02:07:16 -04:00
Slava Pestov
2a0c8d1090 GSB: Fix use-after-free error when vending ResolvedType
The maybeResolveEquivalenceClass() method can deallocate equivalence
classes, because it calls updateNestedTypeForConformance(), which
calls addSameTypeRequirement().

Therefore, the EquivalenceClass stored inside a ResolvedType could
become invalid across calls to maybeResolveEquivalenceClass().

This was a problem in one place in particular, when adding a new
same-type constraint between two type parameters.

Fix this by not caching the equivalence class of a PotentialArchetype
in the ResolvedType implementation. The only time an equivalence class
is now stored is when returning an unresolved type, which is acted
upon immediately.

Fixes <https://bugs.swift.org/browse/SR-12812>, <rdar://problem/63422600>.
2020-07-16 23:31:33 -04:00
Robert Widmann
50c4b3fbf1 Merge pull request #32822 from CodaFi/totally-spaced-out
Handle Boolean Patterns Matching Against Invalid Constructor Forms
2020-07-10 23:20:25 -07:00
Robert Widmann
4369a71a03 Handle Boolean Patterns Matching Against Invalid Constructor Forms
The Space Engine maintains as one of its invariants that the AST it is
handed must at least typecheck. When swift typechecks patterns, the only
case one is allowed to form a Boolean pattern is when a literal is
expected, and the corresponding type of the pattern clause is exactly
Bool. This precludes the use of other types, including
ExpressibleByBooleanLiteral types, from matching. Thus, this code path
was never hit. That is, until we accidentally lifted the restriction on
enum case base name overloading too early. Now, it is possible for the
space engine to see the same constructor head that has subspaces with
different argument types. The space engine is relatively tolerant of
this bizarre situation, but in this one narrow case it was not.

This patch has a narrow fix to add the missing case to the
space engine. In the long term, we need to actually finish SE-0155 which
will make this crash structurally impossible once again.

Resolves rdar://65229620
2020-07-10 14:23:12 -07:00
Slava Pestov
1f5433fe51 Add regression test for rdar://64759168 2020-07-08 23:08:40 -04:00
Slava Pestov
94e9263699 Sema: Fix crash on circular reference in checkContextualRequirements()
The call to getGenericSignature() might return nullptr if we encounter
a circular reference.

Fixes <rdar://problem/64992293>.
2020-07-08 23:08:39 -04:00
Holly Borla
063d420e50 Merge pull request #32672 from hborla/property-wrapper-diagnostics
[Property Wrappers] Improve diagnostics for property wrappers initialized out-of-line
2020-07-07 19:07:55 -07:00
Holly Borla
9b4f1f0935 [NFC] Update validation tests with new property wrapper diagnostics 2020-07-02 14:47:45 -07:00
Holly Borla
b871528179 Merge pull request #32524 from OnyekachiSamuel/fix-confusing-protocol-diagnostic
[Diagnostics] Fix Confusing Protocol Diagnostic
2020-07-02 13:01:19 -07:00
Onyekachi Ezeoke
a08f421c1a fix failing tests 2020-07-02 12:09:07 +01:00
Slava Pestov
ffb59e78bb Merge pull request #32610 from slavapestov/regression-test-sr11030
Add regression test for https://bugs.swift.org/browse/SR-11030 / rdar://problem/52266834
2020-06-30 00:50:51 -04:00
Slava Pestov
422fd41396 Sema: Fix assertion when synthesizing Codable with an IUO stored property
Fixes <https://bugs.swift.org/browse/SR-13118>.
2020-06-29 22:27:38 -04:00
Slava Pestov
63bf06d959 Add regression test for https://bugs.swift.org/browse/SR-11030 / rdar://problem/52266834 2020-06-29 22:26:16 -04:00
Slava Pestov
71e267d5b1 GSB: Teach 'derived via concrete' computation about superclass constraints
Under certain circumstances, introducing a concrete same-type or
superclass constraint can re-introduce conformance constraints
which were previously redundant.

For example, consider this code, which we correctly support today:

protocol P {
  associatedtype T : Q
}

protocol Q {}

class SomeClass<U : Q> {}

struct Outer<T> where T : P {
  func inner<U>(_: U) where T == SomeClass<U>, U : Q {}
}

The constraint 'T == SomeClass<U>' makes the outer constraint
`T : P' redundant, because SomeClass already conforms to P.
It also introduces an implied same-type constraint 'U == T.T'.

However, whereas 'T : P' together with 'U == T.T' make 'U : Q'
redundant, the introduction of the constraint 'T == SomeClass<U>'
removes 'T : P', so we re-introduce an explicit constraint 'U : Q'
in order to get a valid generic signature.

This code path did the right thing for constraints derived via
concrete same-type constraints, but it did not handle superclass
constraints.

As a result, this case was broken:

struct Outer<T> where T : P {
  func inner<U>(_: U) where T : SomeClass<U>, U : Q {}
}

This is the same example as above, except T is related via a
superclass constraint to SomeClass<U>, instead of via a concrete
same-type constraint.

The subtlety here is that we must check if the superclass type
actually conforms to the requirement source's protocol, because it
is possible to have a superclass-constrained generic parameter
where some conformances are abstract. Eg, if SomeClass did not
conform to another protocol P2, we could write

func foo<T, U>(_: T, _: U) where T : SomeClass<U>, T : P2 {}

In this case, 'T : P2' is an abstract conformance on the type 'T'.

The common case where this would come up in real code is when you
have a class that conforms to a protocol with an associated type,
and one of the protocol requirements was fulfilled by a default in
a protocol extension, eg:

protocol P {
  associatedtype T : Q

  func foo()
}

extension P {
  func foo() {}
}

class ConformsWithDefault<T : Q> : P {}

The above used to crash; now it will type-check correctly.

Fixes <rdar://problem/44736411>, <https://bugs.swift.org/browse/SR-8814>..
2020-06-21 23:42:10 -04:00
Slava Pestov
989f4e119f Add regression test for https://bugs.swift.org/browse/SR-1329 2020-06-19 16:32:05 -04:00
Suyash Srijan
b61b68d387 [AST] Look through try expressions inside open existential expression's sub expression in 'getUnwrappedCurryThunkExpr()' (#32458) 2020-06-19 03:29:25 +01:00
Luciano Almeida
59add19684 Merge pull request #32056 from LucianoPAlmeida/minor-typos
[NFC][test] Minor typo corrections on test messages
2020-06-17 07:14:27 -03:00
Luciano Almeida
d22821e18b Merge pull request #31814 from LucianoPAlmeida/SR-12723-conventions
[SR-12723][Sema] Validate function type param representations thick-to-thin conversions
2020-06-15 21:31:04 -03:00
Suyash Srijan
8573d70e47 [Typechecker] Diagnose use of magic literals as raw value for enum case (#32364) 2020-06-16 00:47:58 +01:00
Suyash Srijan
15643777df [CS] Update splice logic in simplifyLocator to handle situations where the index expression isn't a tuple or paren expression (#32356) 2020-06-13 03:28:57 +01:00
Robert Widmann
6ab29cbe4e Introduce NeverNullType to Assert resolveType Never Returns the null Type 2020-06-11 13:00:21 -07:00
Luciano Almeida
d6bf34e65c [CSSimplify] Thin to thin is also allowed 2020-06-08 20:36:09 -03:00
Luciano Almeida
bacbc574a7 [tests] Adding silgen validation tests for SR-12723 to ensure that certain representation convertions do not crash 2020-06-08 20:36:09 -03:00
Luciano Almeida
6d3f53a417 [NFC][test] Minor corrections on test messages 2020-06-05 06:36:09 -03:00