Commit Graph

792 Commits

Author SHA1 Message Date
swift-ci
2fc0e354e7 Merge pull request #40596 from CodaFi/label-and-slander 2021-12-16 16:40:34 -08:00
Robert Widmann
6f68210fb2 Use the API Name of Enum Parameters to Determine Coding Keys
Covers a missing case in codable synthesis for enums with argument
payloads that have internal and external labels. When the name of the
var decl is used, the internal name of the parameter becomes the key
instead of the API name. In this case, this causes an invalid reference
to an enum case with the internal name as an argument to be synthesized
in the derived Decodable conformance which (hopefully) crashes
downstream.

rdar://86339848
2021-12-16 13:02:35 -08:00
swift-ci
ad7abdcbc7 Merge pull request #40278 from atrick/fix-debuginfo 2021-12-15 16:14:50 -08:00
Andrew Trick
7fec04c8fb Fix a test case with copy-pasted SIL IDs. 2021-12-15 13:57:05 -08:00
Slava Pestov
b32694e736 GSB: Try to avoid calling Type::subst() from expandConformanceRequirement() 2021-12-14 19:44:21 -05:00
Slava Pestov
2441e688e4 Pass -requirement-machine-protocol-signatures=on in a few tests where the GSB got it wrong
These fail with -requirement-machine-protocol-signatures=verify because
the GSB produces incorrect output. Enable the requirement machine
unconditionally for these tests, bypassing verification.

A new file test/Generics/same_type_requirements_in_protocol.swift
contains reduced versions of all of the failures, with FileCheck
used to confirm the exact requirement signature output.
2021-12-14 02:17:51 -05:00
Nate Chandler
06971042e5 [Test] Disabled a couple tests on arm64e.
rdar://85526879
rdar://85526916
2021-12-03 08:32:40 -08:00
Doug Gregor
4fccfccadf [Clang importer] Don't insert members found via lookup into the wrong context.
Discovered while investigating rdar://85840928.
2021-12-01 09:57:32 -08:00
Pavel Yaskevich
bc54bc6bb7 Revert "[TypeChecker] SE-0326: Enable multi-statement closure inference by default" 2021-11-29 17:26:08 -08:00
Anthony Latsis
588603f795 Sema: Pass the correct substitutions to 'checkGenericArguments' instead of mapping into context in place 2021-11-19 16:39:37 +03:00
Pavel Yaskevich
67d87e104f [Tests] NFC: Adjust all the test-cases improved by multi-statement inference 2021-11-15 16:42:06 -08:00
Alex Hoppen
b888dc0e40 [Parser] Don't modify the current token kind when cutting off parsing
Previously, when we reached the maximum nesting level, we changed the current token’s kind to an EOF token. A lot of places in the parser are not set up to expect this token change. The intended workaround was to check whether pushing a structure marker failed (which would change the token kind) and bail out parsing if this happened. This was fragile and caused assertion failures in assert builds.

Instead of changing the current token’s kind, and failing to push the structure marker, let the lexer know that it should cut off lexing, essentially making the input buffer stop at the current position. The parser will continue to consume its current token (`Parser.Tok`) and the next token that’s already lexed in the lexer (`Lexer.NextToken`) before reaching the emulated EOF token. Thus two more tokens are parsed than before, but that shouldn’t make much of a difference.
2021-11-09 12:28:10 +01:00
Anthony Latsis
a987ad619b Merge pull request #40082 from AnthonyLatsis/invalid-ext-bind
AST: Make sure malscoped extensions get their extended nominal computed
2021-11-08 20:52:20 +03:00
Anthony Latsis
5215fe5d95 AST: Make sure malscoped extensions get their extended nominal computed 2021-11-08 17:29:38 +03:00
Doug Gregor
d3a370914b Make sure we propagate 'async' down to inherited designed initializes.
Fixes a crash reported via rdar://80353441.
2021-11-04 21:21:37 -07:00
Karoy Lorentey
8e154a415a Merge pull request #39962 from lorentey/concurrency-availability
[stdlib] Introduce availability macros
2021-10-31 14:23:57 -07:00
nate-chandler
22609acef5 Merge pull request #39957 from nate-chandler/rdar80704984_2
[SILGen] Handled foreign funcs with async, error, and more args.
2021-10-29 13:49:18 -07:00
Karoy Lorentey
47956908b7 [Concurrency] SwiftStdlib 5.5 ⟹ SwiftStdlib 5.1 (usages)
The concurrency runtime now deploys back to macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, which corresponds to the 5.1 release of the stdlib.

Adjust macro usages accordingly.
2021-10-28 14:36:36 -07:00
Nate Chandler
bc09cc9cf8 [SILGen] Handled foreign funcs with async, error, and more.
In 1ae317dd88, all the machinery was added
to enable calling ObjC functions that have both async and error
conventions.  The handling that was added for matching up arguments and
parameters, however, failed to handle functions that had both foreign
async and foreign error and other arguments.  Here, that handling is
fixed.

The fix is in four parts:
- Reverting to a single call to CallSite::emit to emit the formal
  params.  At this point, the foreign async and/or error params will be
  claimed as well.
- Separately counting the async and error parameters in
  ParamLowering::claimParams to ensure we get the right parameter
  slices.
- Letting ArgEmitter::maybeEmitForeignArgument look for an error
  parameter even if it already found an async parameter.
- Letting ArgEmitter::maybeEmitForeignArgument keep looking for foreign
  arguments after it finds one.

rdar://80704984
2021-10-28 13:42:08 -07:00
Cassie Jones
d1fe263e48 [test] Mark availability on failing validation-tests
The validation-test suite was incorrectly being run without the
concurrency feature enabled, so the tests were disabled. Now that
they're running, they need fixed availability annotations.
2021-10-24 14:03:00 -04:00
Slava Pestov
8ab330a32d RequirementMachine: Add some testcases 2021-10-09 19:11:15 -04:00
Doug Gregor
293e47a351 Handle missing Sendable conformances in SILFunctionType substitutions.
Fixes SR-15248 / rdar://83556240.
2021-09-27 13:35:46 -07:00
Slava Pestov
4c8e7429f3 Disable requirement machine with compiler_crashers_2_fixed/0022-rdar21625478.swift for now 2021-09-23 14:44:31 -04:00
Robert Widmann
6ffd6f5f8f [NFC] Strip Unnecessary %s's out of Tests
%target-typecheck-verify-swift already implies the current file being passed to the frontend - these just lead to duplicate input file errors.
2021-09-20 11:50:37 -07:00
Slava Pestov
8b59660143 GSB: Don't infer requirements from type constructors in a protocol inheritance clause
This enabled a gross idiom that should not have been allowed in the first place:

    typealias G<T> = Any where T : P

    protocol P {}
    protocol Q : G<Self> {} // Q inherits from P now!

I'd like to ban this, assuming nothing is actually relying on this behavior.
2021-09-06 23:35:19 -04:00
Slava Pestov
4a019f0662 Sema: Improved recovery from circular generic signature construction
Returning a null GenericSignature is not the right way to break a cycle,
because then callers have to be careful to handle the case of a null
GenericSignature together with a non-null GenericParamList, for example
in applyGenericArguments().

An even worse problem can occur when a GenericSignatureRequest for a
nested generic declaration requests the signature of the parent context,
which hits a cycle. In this case, we would build a signature where
the first generic parameter did not have depth 0.

This makes the requirement machine upset, so this patch implements a new
strategy to break such cycles. Instead of returning a null
GenericSignature, we build a signature with the correct generic
parameters, but no requirements. The generic parameters can be computed
just by traversing GenericParamLists, which does not trigger more
GenericSignatureRequests, so this should be safe.
2021-09-04 00:13:03 -04:00
Holly Borla
d2bdbd6208 [ConstraintSystem] Fix a silly crash in repairFailures.
The code checked if the last element of locator path vector
is a certain kind of element without first ensuring that the
vector isn't empty.
2021-09-01 13:48:29 -07:00
Hamish Knight
4c66ff01a1 [test] Skip some Concurrency tests during back deployment testing
rdar://82123254
2021-08-20 11:11:34 +01:00
Nate Chandler
a4992cff64 [Test] Reenabled compiler_crashers_2_fixed/rdar81590807.swift.
The test isn't supported on optimized builds because of the different
crash behavior there.

rdar://81804817
2021-08-11 13:47:36 -07:00
Holly Borla
f6a6a34b08 [Test] Disable compiler_crashers_2_fixed/rdar81590807.swift 2021-08-11 11:39:56 -07:00
nate-chandler
931a5dfc3e Merge pull request #38825 from nate-chandler/rdar81625544
[SIL] Fixed return index for call-as-async (BOOL, Error, Value) case.
2021-08-10 16:56:34 -07:00
nate-chandler
9bb056b0d5 Merge pull request #38785 from nate-chandler/rdar81617749
[SILGen] Fixed handler formal arg type indexing.
2021-08-10 15:21:48 -07:00
Nate Chandler
e349fd0cae [SIL] Fixed return index for call-as-async (BOOL, Error, Value) case.
When converting an ObjC method type which is being called as async to a
Swift function type, some of the values passed to the ObjC method's
completion handler are converted to return values of the Swift function.
The flag and error parameters, however, if present, are ignored.

When abstracting the result type for the Swift method, the formal type
of the corresponding parameter in the ObjC method's completion handler
is used.  Digging out that parameter entails indexing into the
parameters of the completion handler.  Previously, the indexing logic
relied on the error appearing before the flag if both appeared before
the value of interest.  Here, the indexing is tweaked to check both
special indices for each possible index until the first that matches
neither is found.

rdar://81625544
2021-08-10 12:50:22 -07:00
Nate Chandler
cef64c9c44 [SILGen] Fixed handler formal arg type indexing.
In the synthesized completion handler that is passed to ObjC methods
that are called as async, the formal type of each argument is the
corresponding parameter of the formal type of the block.  The non-error,
non-index arguments need to be prepared so that they can be used to
fulfill the continuation; the lambda which does that preparation for
each such argument takes the formal type of that argument.  As such, the
call to that lambda needs to pass the type of the corresponding
parameter of the formal type of the block to that lambda.  Doing so
entails skipping over the error and flag parameters if they appear
before some of the non-error, non-index arguments.

Previously, no parameters were skipped over.  Consequently, when an
error or flag argument preceded one of the non-error, non-index
arguments, the wrong formal type was passed to the preparation lambda.

Here, that is fixed by passing the correct index.  The to-be-used
indices for the formal block parameters are the same as the to-be-used
indices for the lowered block parameters minus one reflecting the fact
that the lowered block always has an initial block_storage parameter as
the first argument which the formal type never has.

rdar://81617749
2021-08-09 19:07:10 -07:00
Nate Chandler
03e175a13e [Test] Added for call-as-async Optional<NS_EXTENSIBLE_STRING_ENUM>.
The underlying problem was fixed by the change for rdar://81590807 .
Add tests for the specific case that was originally reported.

rdar://80704382
2021-08-09 19:06:21 -07:00
Nate Chandler
6eb4f2ca8a [SILGen] Handled transforming Bridged? -> Swift.
Previously, the function emitCBridgedToNativeValue handled three
situations around optionals:
- Bridged?, Native?
- Bridged, Native?
- Bridged, Native

Here, handling for the fourth case
- Bridged?, Native
is added.

To enable this, the number of Optional wrappings that the bridged type
has that the native type does not is passed in to the function.  Then,
in the portions of the function where actual transformations are done,
the values are unwrapped an appropriate number of times.  Mostly that
means force unwrapping N times before doing the transformation.  In the
case of types that conform to _ObjectiveCBridgeable, however, it means
force unwrapping the value N-1 times after doing the transformation
because _ObjectiveCBridgeable._unconditionallyBridgeFromObjectiveC
performs one layer of unwrapping itself.

rdar://81590807
2021-08-09 19:02:27 -07:00
Nate Chandler
1ae317dd88 [SILGen] Handle foreign funcs with error and async conventions.
Previously, SILGen assumed that a foreign function could either have a
foreign async convention or a foreign error convention, but if it had
both, the error would be subsumed into the completion.  That resulted in
failures to emit code for async calls of functions like

```
- (BOOL)minimalWithError:(NSError* _Nullable*)error
         completionHandler:(void (^ _Nonnull)(void))completionHandler;
```

Here, SILGen gains the ability to emit such functions.  To enable that,
a few changes were required when both conventions are present:
- a separate argument for each convention is used
- the ResultPlan is a ForeignErrorResultPlan nesting a
  ForeignAsyncResultPlan
- the continuation is always of the form UnsafeContinuation<_, Error>
  regardless of whether the completion handler takes an error
- the foreign error block fills the continuation with the error that was
  passed by reference out of the ObjC method call
- the foreign error block branches to the block containing the await
  instruction

rdar://80704984
2021-08-03 18:36:15 -07:00
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