Commit Graph

2092 Commits

Author SHA1 Message Date
Doug Gregor
0652bb7abe Always infer AsyncSequence.Failure from AsyncIteratorProtocol.Failure
The newly-introduced associated type `AsyncSequence.Failure` must
always be equivalent to the `Failure` type of the
`AsyncIteratorProtocol`. If the `AsyncSequence` type itself defines a
nested `Failure` type (say, for another purpose), associated type inference
would pick it and reject the `AsyncSequence`, causing a source compatibility
problem.

Work around the issue in two ways. First, always infer the type
witness for `AsyncSequence.Failure` from the type witness for
`AsyncIteratorProtocol.Failure`, so they can't be out of sync. This
means that we'll never even consider a nested `Failure` type in the
`AsyncSequence`-conforming type. This hack only applies prior to Swift 6.

Second, when we have inferred a `Failure` type and there is already
something else called `Failure` within that same nominal type, don't
print the inferred typelias into a module interface because it will
cause a conflict.

Fixes rdar://123543633.
2024-02-28 13:49:50 -08:00
Michael Gottesman
c65e10e36f [transferring] Improve how the AST dumps/prints transferring.
Specifically:

1. Previously when printing we would not put a space after transferring.
2. When a function type has a transferring result, we wouldn't print it when dumping.
2024-02-27 17:55:45 -08:00
Meghana Gupta
a79facf02b Fix ASTPrinting of lifetime dependence
This fixes the errors while compiling functions with lifetime dependence
in the textual interface files.

Also fixes rdar://122573346
2024-02-23 15:35:37 -08:00
Allan Shortlidge
766e6231d3 Merge pull request #71800 from tshortli/module-interface-typed-throws-closure
ModuleInterface: Improve TypedThrows feature guards
2024-02-21 21:46:05 -08:00
Allan Shortlidge
1b7d8b6eda ModuleInterface: Improve TypedThrows feature guards.
Functions that use typed throws _anywhere_ in their signature (including in
closure types) need to be surrounded with `if $TypedThrows` guards in
swiftinterfaces.
2024-02-21 17:59:49 -08:00
Ben Barham
ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -08:00
Pavel Yaskevich
11ef6e58d8 Merge pull request #71659 from xedin/noncopyable-circularity-fixes
[AST/Sema] NonCopyableGenerics: Address some of the request circularity issues
2024-02-20 12:38:16 -08:00
Kavon Farvardin
5d599850de Merge pull request #71748 from kavon/ncgenerics-test-fixes-kavon-v18
ASTPrinter: fix nested inverse printing (v18)
2024-02-20 03:21:38 -08:00
Kavon Farvardin
722282ee4f ASTPrinter: fix nested inverse printing
Nested types with inverse requirements on generic parameters would
sometimes print incorrectly. We only print the inverses on outer generic
parameters for extensions.

fixes rdar://123281976
2024-02-19 23:50:15 -08:00
Kavon Farvardin
d6e038f760 ASTPrinter: include a synth. extension's inverses
We're requesting to print inverses, but haven't included any of those
inverses!
2024-02-19 17:01:51 -08:00
Nate Chandler
1906b28f2b Add missing guard around new builtin.
Avoid a condfail.
2024-02-19 16:04:29 -08:00
Pavel Yaskevich
c81db8e149 [AST] NonCopyableGenerics: Expand hasInverseMarking to support associated type declarations
This is required for `ASTPrinter` to wrap the protocol that has
associated type with inverses in a feature block.
2024-02-19 10:37:16 -08:00
Pavel Yaskevich
937d9d08d5 [AST] Route hasInverse through hasInverseMarking and simplify it 2024-02-16 17:55:52 -08:00
John McCall
668297e977 Don't print conformance attributes redundantly in -preserve-types-as-written.
Since we no longer remove these attributes from the AttributedTypeRepr,
if we print based on the TypeRepr, we'll print them twice.  The best
solution is to only print the attributes based on the inheritance clause
if we're not printing the type based on the TypeRepr.

Fixes rdar://122965951.
2024-02-16 15:12:24 -05:00
Slava Pestov
1c24b880ec Merge pull request #70467 from AnthonyLatsis/recursive-member-typerepr
AST: Remodel `MemberTypeRepr` to be recursive
2024-02-16 11:36:31 -05:00
Kavon Farvardin
4fb90d3e2c Merge pull request #71654 from kavon/ncgenerics-test-fixes-kavon-v14
Ncgenerics test fixes kavon v14
2024-02-15 14:04:50 -08:00
Kavon Farvardin
63ed8ec4a6 NCGenerics: handle legacy definition of Sendable
This should be a temporary measure while bootstrapping the feature.
2024-02-15 11:07:49 -08:00
Doug Gregor
dba0a4087f Macro-metaprogram "baseline" features that all Swift compilers handle
This is better than a pile of usesXXXFeature() functions that return
`false` with no explanation.
2024-02-14 21:53:53 -08:00
Doug Gregor
bae1026b77 Stop emitting conditions for Swift 5.5-era features into textual interfaces
The "#if compiler(>=5.3) && $AsyncAwait" checks were necessary for
staging in concurrency in Swift 5.5. At this point, it's safe to assume
that any compiler that tries to read a generated Swift interface file will
support concurrency, so we can stop emitting these guards.
2024-02-14 21:51:55 -08:00
Michael Gottesman
23ab974574 Merge pull request #71567 from gottesmm/transferring-param
[transferring] Implement transferring result and clean up transferring param support by making transferring a bit on param instead of a ParamSpecifier.
2024-02-14 17:54:48 -08:00
Doug Gregor
81ffafdc6a Merge pull request #70602 from ApolloZhu/macro/expression-as-default-argument
[Macros] Expression macro as caller-side default argument
2024-02-14 16:10:11 -08:00
Michael Gottesman
f3edb5730a [transferring] Add support for transferring results.
rdar://121324697
2024-02-14 14:39:02 -08:00
Michael Gottesman
bf2ec7eb85 [transferring] Change transferring to no longer be a ParamSpecifier.
Instead it is a bit on ParamDecl and SILParameterInfo. I preserve the consuming
behavior by making it so that the type checker changes the ParamSpecifier to
ImplicitlyCopyableConsuming if we have a default param specifier and
transferring is set. NOTE: The user can never write ImplicitlyCopyableConsuming.

NOTE: I had to expand the amount of flags that can be stored in ParamDecl so I
stole bits from TypeRepr and added some logic for packing option bits into
TyRepr and DefaultValue.

rdar://121324715
2024-02-14 13:04:46 -08:00
Michael Gottesman
1f0527d47f [ast] Rename ParamSpecifier::{Transferring,ImplicitlyCopyableConsuming}.
The reason why I am doing this is that I am going to be changing transferring to
not be a true ParamSpecifier. Instead, it is going to be a bit on Param that
changes the default ParamSpecifier used. That being said, I cannot use consuming
for this purpose since consuming today implies no implicit copy semantics, which
we do not want unless the user specifically asks for it by writing consuming.
2024-02-14 13:04:21 -08:00
Mishal Shah
61ed95a32f Merge pull request #71599 from hborla/update-build-task-executor-feature-guard
[Features] Rename the `BuiltinBuildTaskExecutor` feature guard.
2024-02-14 00:09:54 -08:00
Holly Borla
56c2b34071 [Features] Rename the BuiltinBuildTaskExecutor feature guard.
The name of the `TaskExecutor` protocol was recently changed to remove
underscores after the feature was accepted in Swift Evolution. An implication
of that rename is that the `buildOrdinaryTaskExecutorRef` builtin changed
the type that it expected as the argument. However, the original change
landed in the standard library which as since produced swiftinterfaces
that contain the following inlinable code:

```
@inlinable public init<E>(ordinary executor: __shared E) where E : _Concurrency._TaskExecutor {
  #if $BuiltinBuildTaskExecutor
  self.executor = Builtin.buildOrdinaryTaskExecutorRef(executor)
  #else
  fatalError("Swift compiler is incompatible with this SDK version")
  #endif
}
```

When a compiler containing the protocol rename attempts to type check the
above inlinable code, it crashes because the builtin is expecting an argument
conforming to `TaskExecutor`, which doesn't exist in this version of the
standard library. The issue is that the current compiler still supports
the `$BuiltinBuildTaskExecutor` feature guard, but the builtin supported
has since changed.

To resolve this issue, we need to stop supporting the `$BuiltinBuildTaskExecutor`
feature guard and introduce a new one that is only supported by compiler versions
that contain the rename. This approach relies on nothing having adopted the
API, otherwise we would need to stage in the rename as a parallel set of APIs,
and only remove the old APIs once nothing is relying on the old _Concurrency
swiftinterfaces.
2024-02-13 20:16:42 -08:00
John McCall
d5142668f4 SIL and IRGen support for @isolated(any). SILGen to come. 2024-02-13 03:04:13 -05:00
Kavon Farvardin
8125e609e1 NFC: add a few module asserts 2024-02-11 12:54:35 -08:00
Anthony Latsis
fd4094cf09 [NFC] Introduce TypeRepr::isSimpleUnqualifiedIdentifier to simplify some code 2024-02-09 17:22:56 +03:00
Hamish Knight
2c77947000 Merge pull request #71006 from hamishknight/implicit-last-expression
Introduce implicit last expression results
2024-02-08 10:15:01 +00:00
Hamish Knight
d73e394ea7 Allow implicit last expression results for if/switch expressions
Allow implicitly treating the last expression of
the branch as the result, behind the experimental
feature `ImplicitLastExprResults`.
2024-02-07 18:14:22 +00:00
John McCall
2f8a33cf0a Experimental type-checking support for @isolated(any) function types. 2024-02-06 22:54:27 -05:00
Apollo Zhu
b09a22a9a0 Somewhat working
Test shadowed variable of same type

Fully type check caller side macro expansion

Skip macro default arg caller side expr at decl primary

Test macro expand more complex expressions

Set synthesized expression as implicit

Add test case for with argument, not compiling currently

Test with swiftinterface

Always use the string representation of the default argument

Now works across module boundary

Check works for multiple files

Make default argument expression work in single file

Use expected-error

Disallow expression macro as default argument

Using as a sub expression in default argument still allowed as expression macros behave the same as built-in magic literals
2024-02-06 15:02:11 -08:00
Kavon Farvardin
f0b4f4a865 NCGenerics: omit inverses on invertible protocols
The interface files were still printing inverses on the invertible
protocols, when that's not required. Doing so yielded warnings during
the build because `~Escapable` isn't yet ready for appearing in the
stdlib.
2024-02-06 08:15:26 -08:00
Slava Pestov
366f741438 AST: Print substitution signature without applying inverse transform 2024-02-05 18:43:06 -05:00
Hamish Knight
658be5b40f Merge pull request #64667 from Rajveer100/branch-for-issue-61601
Added unimplemented expression cases in the ASTPrinter
2024-02-05 11:42:09 +00:00
John McCall
dd90ae7416 Rename SIL's @isolated attribute to @sil_isolated.
We want to use @isolated in ordinary Swift, and while we could probably
make it coexist with this SIL use, doing so would be really inconvenient.
2024-02-03 01:51:36 -05:00
Pavel Yaskevich
a77d119c99 Merge pull request #71261 from xedin/introduce-thunks-for-runtime-check-func-refs
[Sema/SILGen] DynamicActorIsolation: Implement dynamic actor isolation checks for unsafe APIs
2024-02-02 13:32:00 -08:00
Rintaro Ishizaki
8fdc4cc225 [AST] Split Attr.def to DeclAttr.def and TypeAttr.def 2024-02-02 09:36:49 -08:00
Rintaro Ishizaki
b839718351 [AST] Use scoped enum for attribute kinds
Align with other kind enum e.g. DeclKind.
2024-02-02 09:36:48 -08:00
Rintaro Ishizaki
07bb0380a1 [AST] Use class names for type attribute kind enum
Align with DeclAttrKind.
2024-02-02 09:36:47 -08:00
Rajveer
48847da5e6 Added the expression cases of the form 'visit...Expr()'
Part of Issue #61601
2024-02-02 13:51:37 +05:30
Pavel Yaskevich
db7959668e [Frontend] NFC: Rename PreconcurrencyConformances to DynamicActorIsolation 2024-02-01 13:28:25 -08:00
Pavel Yaskevich
4debaf2c5d [AST] Introduce a new conversion expression - ActorIsolationErasure
To be used in situations when a global actor isolation is stripped
from a function type in argument positions and could be extended in
the future to cover more if needed.
2024-02-01 13:28:25 -08:00
Slava Pestov
80205ecf9c Merge pull request #71241 from slavapestov/ncgenerics-fixes
Non-copyable generics fixes
2024-02-01 07:18:29 -05:00
Slava Pestov
23b1690f6b ASTPrinter: Refactor printing of RequirementSignatures 2024-01-31 21:55:52 -05:00
Slava Pestov
2355cb4090 Sema: Move -debug-generic-signatures behavior to TypeCheckDeclPrimary.cpp 2024-01-31 18:41:43 -05:00
Slava Pestov
45f31b4516 AST: Refactor ASTPrinter to use getRequirementsWithInverses() 2024-01-31 18:40:35 -05:00
Joe Groff
a52e96e358 Merge pull request #71263 from jckarter/borrowing-switch-3
Parse `_borrowing x` in patterns as a borrow binding.
2024-01-31 07:08:32 -08:00
Hamish Knight
27c08b130a Merge pull request #71123 from hamishknight/sema-expr-return
Move the single-expr return transform from Parse to Sema
2024-01-31 10:13:24 +00:00