Commit Graph

29258 Commits

Author SHA1 Message Date
Anton Korobeynikov
4eb5d62df6 Unbreak tests after read / modify accessors added 2025-11-13 12:34:16 -08:00
Anton Korobeynikov
263f6e3dd6 Few fixes related to coroutine function types. 2025-11-12 21:02:55 -08:00
Anton Korobeynikov
6c504bb9fa Add parsing of @yield_once and @yields attributes and corresponding type checks 2025-11-12 21:02:55 -08:00
Anton Korobeynikov
76c9a23f27 First cut of making coroutine AST type 2025-11-12 21:02:53 -08:00
Anton Korobeynikov
797f500286 Add basic boilerplate for AST coroutines and yields 2025-11-12 21:02:25 -08:00
Pavel Yaskevich
4bd370fe46 Merge pull request #85451 from xedin/rdar-164201746
[CSOptimizer] Skip `??` if it's involved in optional chain with unres…
2025-11-12 17:30:51 -08:00
Hamish Knight
e2287b6312 Merge pull request #85449 from hamishknight/whats-the-catch
[Sema] Skip type-checking catch bodies when computing the bound error type
2025-11-12 19:34:45 +00:00
Kavon Farvardin
47a6f2acfd Merge pull request #85392 from kavon/borrow-expr-implicit-infra
SILGen: add RValue emission for BorrowExpr
2025-11-12 11:23:52 -08:00
Alexis Laferrière
937e6c5241 Merge pull request #85446 from xymus/serial-xref-check
Serialization: Error on leaked cross-references to `@_implementationOnly` dependencies
2025-11-12 10:42:58 -08:00
Alexis Laferrière
dc7f30fac9 Merge pull request #85387 from xymus/exportability-nle-proto
Sema: Exportability check protocols in non-library-evolution mode
2025-11-12 10:04:04 -08:00
Pavel Yaskevich
4d8d719b92 Merge pull request #85406 from naveen-seth/fix-ambiguous-trailing-closure-init
[Sema] Fix crash when diagnosing ambiguous trailing closure inits
2025-11-12 10:03:46 -08:00
Pavel Yaskevich
a01692ace1 [CSOptimizer] Skip ?? if it's involved in optional chain with unresolved result type
`??` operator is overloaded on optionality of its result. When the
first argument matches exactly, the ranking is going to be skewed
towards selecting an overload choice that returns a non-optional type.
This is not always correct i.e. when operator is involved in optional
chaining. To avoid producing an incorrect favoring, let's skip the this
disjunction when constraints associated with result type indicate
that it should be optional.

Simply adding it as a binding won't work because if the second argument
is non-optional the overload that returns `T?` would still have a lower
score.

Resolves: rdar://164201746
2025-11-11 15:21:33 -08:00
Hamish Knight
14608cb059 [Sema] Skip type-checking catch bodies when computing the bound error type
Make sure we only ever type-check the `do` body of a `do-catch`
statement when lazily type-checking the bound error type, which we can
do for completion.

rdar://164481242
2025-11-11 23:04:30 +00:00
Hamish Knight
8b0853d92c [Sema] Assert that we don't re-type-check conditions
Sink the assertion down into `TypeChecker::typeCheckCondition` and
remove the old logic.
2025-11-11 23:04:30 +00:00
Alexis Laferrière
06db612d79 Sema: Intro the CheckImplementationOnlyStrict feature 2025-11-11 10:26:00 -08:00
Alexis Laferrière
8eb530cc71 Sema: Accept @_implementationOnly protocols 2025-11-11 09:54:37 -08:00
Anthony Latsis
bda6edb85c AST: Rename GenericContext::isGeneric to hasGenericParamList
`isGeneric` is a misleading name because this method checks for the
existence of a `GenericParamList`, which is not implied by genericity.
2025-11-11 15:55:16 +00:00
Kuba (Brecka) Mracek
75506a17ce Merge pull request #85413 from kubamracek/section-convention-c
Allow function conversions to `@convention(c)` in `@section` expressions
2025-11-11 04:18:30 -08:00
Hamish Knight
de51fed13d Merge pull request #85410 from hamishknight/pack-fix
[CS] Handle packs in `increaseScoreForGenericParamPointerConversion`
2025-11-11 09:07:55 +00:00
Kuba (Brecka) Mracek
6e68130897 Merge pull request #85412 from kubamracek/section-uint8
Support 'as UInt8' in @section expressions
2025-11-10 21:32:17 -08:00
naveen-seth
9a88d61462 Address xedin's review feedback 2025-11-10 23:04:50 +01:00
Pavel Yaskevich
c7b3b73708 Merge pull request #85391 from xedin/rdar-164247524
[CSOptimizer] Avoid favoring overloads that mismatch context on async
2025-11-10 09:52:17 -08:00
Kuba Mracek
4e919fb235 Allow function conversions to @convention(c) in @section expressions 2025-11-10 09:34:38 -08:00
Kuba Mracek
ac49d93e3f Support 'as UInt8' in @section expressions 2025-11-10 09:02:40 -08:00
Hamish Knight
ded97baea1 [CS] Handle packs in increaseScoreForGenericParamPointerConversion
Missed this in my original patch, handle pack parameters the same as
regular generic parameters, ensuring we don't prefer a pack overload
over a generic overload just because there are pointer conversions
involved. Note this doesn't fix the wider issue of rdar://122011759,
I'm planning on looking into that in a follow-up.
2025-11-10 14:26:25 +00:00
naveen-seth
8b7b0e944b [Sema] Fix crash when diagnosing ambiguous trailing closure inits
Fixes #85376.

This fixes a compiler crash that occurred when diagnosing an ambiguous call
using trailing closure syntax, where one of the candidates was a function or
initializer with no parameters.
2025-11-10 03:12:18 +01:00
Doug Gregor
087aee833f Merge pull request #85396 from DougGregor/se-0497-export
[SE-0497] Implement @export attribute syntax
2025-11-08 23:46:06 -08:00
Doug Gregor
020b69d4b6 [SE-0497] Implement @export attribute syntax
Implement the @export(implementation) and @export(interface) attributes
to replace @_alwaysEmitIntoClient and @_neverEmitIntoClient. Provide a
warning + Fix-It to start staging out the very-new
@_neverEmitIntoClient. We'll hold off on pushing folks toward
@_alwaysEmitIntoClient for a little longer.
2025-11-07 22:00:40 -08:00
Hamish Knight
fe54011bcb Merge pull request #85393 from hamishknight/add-null-check
[CS] Add null check for ParameterList in `findFavoredChoicesBasedOnArity`
2025-11-08 03:44:10 +00:00
Alexis Laferrière
ed85a12b59 Merge pull request #85317 from xymus/non-neic-funcs-and-typealiases
Sema: Allow more embedded code to reference non-public imports
2025-11-07 15:19:52 -08:00
Pavel Yaskevich
5f91e49c9c Merge pull request #85105 from xedin/rdar-140928937
[AST/Sema] Allow `Sendable` suppression on Objective-C class declarations
2025-11-07 15:09:35 -08:00
Hamish Knight
b26b0b783e [CS] Add null check for ParameterList in findFavoredChoicesBasedOnArity
rdar://164116965
2025-11-07 22:17:33 +00:00
Pavel Yaskevich
513caf2c9b [CSOptimizer] Avoid favoring overloads that mismatch context on async
This is a fix for the ported "calls with a single unlabeled argument"
hack. If overload doesn't match context on async effect, let's not favor
it because that is more important than defaulted parameters.

Resolves: rdar://164269641
2025-11-07 14:15:45 -08:00
Kavon Farvardin
314093f426 SILGen: add RValue emission for BorrowExpr 2025-11-07 14:01:35 -08:00
Hamish Knight
4be003b057 Merge pull request #85383 from hamishknight/third-times-a-charm
[CS] Fix an over-eager assert
2025-11-07 21:49:49 +00:00
Alexis Laferrière
1e1361f4ee Merge pull request #85369 from xymus/exportability-nle-classes-and-structs
Sema: Exportability check enums and classes in non-library-evolution mode
2025-11-07 09:19:25 -08:00
Hamish Knight
0feacec63b [CS] Fix an over-eager assert
We can in fact have placeholders here if the type is bound to a hole.
2025-11-07 16:23:30 +00:00
Doug Gregor
66e7a783a6 Merge pull request #85370 from DougGregor/extern-global-variables 2025-11-06 21:40:24 -08:00
Hamish Knight
8b73c9c717 Merge pull request #85363 from hamishknight/hattrick
[Sema] Avoid member attribute cycle in ResolveMacroRequest
2025-11-07 04:02:44 +00:00
Anton Korobeynikov
89a7663f1d [AutoDiff] Initial support for differentiation of throwing functions (#82653)
This adds initial support for differentiation of functions that may produce `Error` result. 

Essentially we wrap the pullback into `Optional` and emit a diamond-shape control flow pattern depending on whether the pullback value is available or not. VJP emission was modified to accommodate for this. In addition to this, some additional tricks are required as `try_apply` result is not available in the instruction parent block, it is available in normal successor basic block.

As a result we can now:
- differentiate an active `try_apply` result (that would be produced from `do ... try .. catch` constructions)
- `try_apply` when error result is unreachable (usually `try!` and similar source code constructs)
- Support (some) throwing functions with builtin differentiation operators. stdlib change will follow. Though we cannot support typed throws here (yet)
- Correctly propagate error types during currying around differentiable functions as well as type-checking for `@derivative(of:)` attribute, so we can register custom derivatives for functions producing error result
- Added custom derivative for `Optional.??` operator (note that support here is not yet complete as we cannot differentiate through autoclosures, so `x ?? y` works only if `y` is not active, e.g. a constant value).

Some fixes here and there
2025-11-06 13:12:43 -08:00
Doug Gregor
c8a60c8524 Patterns with multiple variables can support initialization 2025-11-06 13:05:38 -08:00
Hamish Knight
f2b0b92dc1 [Sema] Avoid member attribute cycle in ResolveMacroRequest
If we have a custom attribute on a type that does a qualified lookup
into the same type, we need to be able to expand member attribute
macros for that type. As such, the check to see if we already have
a nominal for the attribute would hit a cycle. Limit this check such
that it only applies to local vars, which is the only case where it
actually matters.

rdar://163961797
2025-11-06 19:33:09 +00:00
Alexis Laferrière
5bffd70452 Sema: Accept @_implementationOnly on enums and classes 2025-11-06 11:30:43 -08:00
Doug Gregor
a10194c0e3 Ensure that we don't diagnose the lack of initializer for @_extern variables 2025-11-06 11:20:57 -08:00
Doug Gregor
5b642f548f Extend @_extern to global and static variables
Allow external declaration of global variables via `@_extern(c)`. Such
variables need to have types represented in C (of course), have only
storage (no accessors), and cannot have initializers. At the SIL
level, we use the SIL asmname attribute to get the appropriate C name.

While here, slightly shore up the `@_extern(c)` checking, which should
fix issue #70776 / rdar://153515764.
2025-11-06 11:09:31 -08:00
Pavel Yaskevich
e39a31a05f Merge pull request #85319 from xedin/rdar-162394810
[AST/Sema] Add a diagnostic group `ExplicitSendable` to replace `-require-explicit-sendable`
2025-11-06 06:48:50 -08:00
Hamish Knight
3e0ea3ac68 Merge pull request #85342 from hamishknight/absolute-cinema 2025-11-06 08:25:05 +00:00
Alexis Laferrière
579a228d3f Merge pull request #85179 from xymus/exportability-nle-structs
Sema: Opt-in check for structs references to hidden dependencies in non-library-evolution mode
2025-11-05 15:32:05 -08:00
Hamish Knight
f205f469a9 [CS] Replace error type with hole for projected value
Missed this in my previous patch, make sure we replace an error with
a hole if necessary.
2025-11-05 20:29:15 +00:00
Hamish Knight
dad263728f Merge pull request #85193 from hamishknight/wrapping-paper
[CS] A couple of property wrapper fixes
2025-11-05 19:51:51 +00:00