Commit Graph

805 Commits

Author SHA1 Message Date
Luciano Almeida
b9dec7da4c [test] Adjusting tests for generic parameters that are now being aka on diagnostics 2021-01-14 17:44:52 -03:00
Anthony Latsis
afcb1665f8 GSB: Handle concrete ResolvedTypes in ArchetypeType::resolveNestedType()
A nested type of an archetype type might be concrete, for example, via a
same-type constraint:

extension SomeProtocol where SomeAssoc == Int {
  ... Self.SomeAssoc ...
}

This can happen in one of two ways; either the EquivalenceClass of the
nested type has a concrete type, or it is "fully concrete" because
there is no equivalence class and maybeResolveEquivalenceClass() returns
a ResolvedType storing the concrete type.

For some reason we didn't handle the second case here.

Fixes https://bugs.swift.org/browse/SR-13519 / rdar://problem/68531679
2021-01-12 23:52:44 -05:00
David Zarzycki
238413d349 [testing] add missing REQUIRES: concurrency 2020-12-17 09:03:04 -05:00
Nate Chandler
d2726c31bb [Async CC] Don't lookup known archetype conformance.
Previously, when saving NecessaryBindings for an async function, if a
type that was passed-in happened to be an archetype, a lookup for that
type's conformance would always be done.  However, that lookup was not
always necessary or possible such as in the case where both the metadata
and the witness table were provided to the function in an async context.
Here, that is fixed by using the conformance that was seen when
constructing the NecessaryBindings if one is available.

rdar://problem/72397303
2020-12-16 17:20:31 -08:00
David Zarzycki
0e650c1c89 [Testing] Add missing REQUIRES 2020-12-01 06:39:13 -05:00
Nate Chandler
f33f1d3646 [Async CC] Always add full type metadata to bindings.
NecessaryBindings are used by both async functions and partial apply
forwarders.  The latter are able to avoid bindings in some cases because
a new function is generated where the information that would otherwise
be available in the bindings can be made available.  That is not the
case for async functions.  A generic async function requires all of the
metadata and witness tables be passed along to it: unlike a partial
apply forwarder it isn't in any way specialized so this information
can't be recovered.

Previously, metadata bindings were always passed along to async
functions.  However, destructuring that can be done for partial apply
forwarders was still being applied.  This resulted in an inappropriate
and unexpected number of bindings in NecessaryBindings.

Here, that destructuring is avoided for metadata passed to async
functions.

Now, the full metadata required by async functions are passed along to
them as necessary.

rdar://problem/71816041
2020-11-30 14:02:56 -08:00
nate-chandler
84f92a3f00 Merge pull request #34784 from nate-chandler/concurrency/irgen/rdar71491604
[Async CC] Find wtable in async context in thunk.
2020-11-17 14:56:49 -08:00
Slava Pestov
fe5be6368e Merge pull request #34772 from slavapestov/fix-lazy-getter-source-range
Sema: Fix source range of 'lazy' property getter
2020-11-17 17:23:22 -05:00
Slava Pestov
9a510b8ffa Merge pull request #34773 from slavapestov/fix-objc-attr-diagnostic
Sema: Still diagnose '@objc' even if Foundation was imported
2020-11-17 17:22:48 -05:00
Slava Pestov
96c9456ee8 Sema: Still diagnose '@objc' even if Foundation was imported
We checked for an import of a module named 'Foundation' before
checking if Objective-C interoperability was enabled, which
would lead to hilarious results.

Fixes <https://bugs.swift.org/browse/SR-13713> / <rdar://problem/70140319>.
2020-11-17 14:54:34 -05:00
Nate Chandler
e06d316fe7 [Async CC] Find wtable in async context in thunk.
Previously, when looking up a protocol method, the witness table was
always exepcted to be the final argument passed to the function.

That is true for sync protocol witnesses but not for async witnesses.
In the async case, the witness table is embedded in the async context.

Here, the witness table is dug out of the async context.

rdar://problem/71491604
2020-11-17 11:23:37 -08:00
Slava Pestov
756357b8a2 Sema: Fix source range of 'lazy' property getter
The source range of the getter's body was set incorrectly;
both the start and the end were the property's location.

Instead, let's use the source range of the initializer
expression, which fixes an assertion in name lookup.

Fixes <rdar://problem/70732736>.
2020-11-16 23:46:11 -05:00
Slava Pestov
5808d9beb9 Parse: Remove parse-time name lookup 2020-11-16 22:39:44 -05:00
David Zarzycki
b1448edfba [Testing] Add missing REQUIRES: concurrency 2020-11-16 05:54:44 -05:00
Nate Chandler
e27647244d [AsyncCC] Resolve metadata from class instances.
Metadata for an instance of a type is resolved by extracting it from an
instance of the class.  When doing method lookup for an instance method
of a resilient class, the lowered self value was being obtained from the
list of arguments directly by indexing.  That does not apply to async
functions where self is embedded within the async context.  Here, the
self parameter is extracted from the async context so that the metadata
can in turn be extracted from it.

rdar://problem/71260862
2020-11-14 15:15:12 -08:00
Nate Chandler
11723ccc55 [Async CC] Never map to native explosions.
Previously, when lowering the entry point of an async function, the
parameters were lowered to explosions that matched those of sync
functions, namely native explosions.  That is incorrect for async
functions where the structured values are within the async context.
Here, that error is fixed, by adding a new customization point to
NativeCCEntryPointArgumentEmission which behaves as before for sync
functions but which simply extracts an argument from the async context
for async functions.

rdar://problem/71260972
2020-11-13 19:45:03 -08:00
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