Commit Graph

28619 Commits

Author SHA1 Message Date
Slava Pestov
c598ec3f5c Sema: Add LLVM_DEBUG to WitnessChecker::findBestWitness() 2025-03-19 09:30:46 -04:00
Gábor Horváth
e5c5ec57d2 Update lib/Sema/TypeCheckType.cpp
Co-authored-by: Anthony Latsis <alatsis@apple.com>
2025-03-19 12:56:56 +00:00
Gabor Horvath
b632534528 [cxx-interop] Interpret Self as a static shorthand for FRTs
We do not have dynamic self metadata for foreign reference types.

rdar://145066864
2025-03-19 12:56:56 +00:00
Slava Pestov
6a3ead3a44 Merge pull request #80107 from slavapestov/for-abstract-conformance
Fix a few more callers of ProtocolConformanceRef::forAbstract() to pass in a subject type
2025-03-19 07:15:27 -04:00
Holly Borla
8ec70e2559 [Macros] Gate closure body macros behind an experimental feature flag. 2025-03-18 20:50:47 -07:00
Pavel Yaskevich
9cd3c8de86 [TypeCheckMacros] Never associate MacroExpansionExpr with a closure
The closures are type-checked after macros are expanded
which means that macro cannot reference any declarations
from inner or outer closures as its arguments.

For example:

`_: (Int) -> Void = { x in { @Macro(x) in ... }() }`

`x` is not going to be type-checked at macro expansion
time and cannot be referenced by `@Macro`.

Let's walk up declaration contexts until we find first
non-closure one. This means that we can support a local
declaration that is defined inside of a closure because
they are separately checked after outer ones are already
processed.
2025-03-18 20:50:47 -07:00
Pavel Yaskevich
42ccd182f6 [PreCheckTarget] Move closure body expansion into PreCheckTarget::walkToClosureExprPre
If closure body is expanded in expression context we need to do
some special handling to make sure that source ranges are not
completely broken.
2025-03-18 20:50:47 -07:00
Pavel Yaskevich
b7e4b4370e [Macros] A macro attached to a closure body covers a range after in and up to }
The macro is not allowed to write explicit type or `in` keyword.
2025-03-18 20:50:47 -07:00
Holly Borla
31d4f661fc [Macros] Support function body macros on closures. 2025-03-18 20:50:47 -07:00
Doug Gregor
a02633ad47 Merge pull request #80103 from DougGregor/strict-safety-more-minor-cleanups 2025-03-18 20:29:25 -07:00
Slava Pestov
f7b0b72766 Sema: Refactor TypeChecker::containsProtocol() a bit 2025-03-18 19:38:21 -04:00
Pavel Yaskevich
cfad698202 [CSDiagnostics] Tailor diagnostic for Escapable conformance mismatch in key path context 2025-03-18 14:38:40 -07:00
Doug Gregor
9570e1e3a7 [SE-0458] Add fix-it for removing unnecessary "unsafe" keywords 2025-03-18 13:57:16 -07:00
Pavel Yaskevich
6c2b12547b [CSDiagnostics] Tailor diagnostic for Copyable conformance mismatch in key path context 2025-03-18 13:46:56 -07:00
Doug Gregor
4742d2c5db [SE-0458] withoutActuallyEscaping is unsafe for @convention(block)
The implementation of `withoutActuallyEscaping` for `@convention(block)`
functions cannot verify at runtime that the function did not actually
escape. Diagnose this as unsafe code under strict memory safety checking.

Fixes rdar://139994149.
2025-03-18 13:26:47 -07:00
Pavel Yaskevich
9a8f8277f9 Merge pull request #80085 from xedin/fix-assignFixedType-use
[CSSimplify] NFC: `assignFixedType` no longer accepts a locator
2025-03-18 08:49:30 -07:00
Anthony Latsis
ad3a5adc6d Merge pull request #80008 from AnthonyLatsis/danaus-plexippus-4 2025-03-18 13:24:17 +00:00
Pavel Yaskevich
e0f9e65976 [CSSimplify] NFC: assignFixedType no longer accepts a locator
`assignFixedType` now accepts `bool` as a third parameter but
not all call sites were updated to reflect that, some of them
are still passing `ConstraintLocator *` which implicitly gets
converted to a `bool`.
2025-03-18 00:16:22 -07:00
Anthony Latsis
c49947579a Sema: Implement adoption mode for AsyncCallerExecution 2025-03-18 01:58:31 +00:00
Slava Pestov
145a7c5fe2 Merge pull request #80057 from slavapestov/fix-rdar146780049
Sema: Fix non-determinism with ConstraintSystem::ConstraintRestrictions
2025-03-17 21:28:01 -04:00
Pavel Yaskevich
a8baec6c41 [CSSimplify] Open key path type before assignment to its record requirements
`Root` and `Value` generic parameters now have conformance requirements
which we need to account for post-binding inference.
2025-03-17 17:03:09 -07:00
Allan Shortlidge
dd68e98002 Merge pull request #80051 from tshortli/refactor-semantic-decl-availability-request
AST: Introduce `DeclRuntimeAvailability`
2025-03-17 14:35:48 -07:00
Pavel Yaskevich
6c22036931 [CSSimplify] NFC: Perform assignments to a key path in a separate method
Previously key path type didn't have any requirements on their
root and value types but now that they do, we need a dedicated
place to perform an assignment and open/record all of the requirements.
2025-03-17 14:06:45 -07:00
Anthony Latsis
2c7fb6a463 [NFC] Sema: Move determineClosureIsolation definition to the top level
Also combine the computed isolation and preconcurrency once at the end
rather than at every return.
2025-03-17 19:46:25 +00:00
Anthony Latsis
de36c3ff2c [NFC] Sema: Remove some redundant getASTContext calls in the isolation checker 2025-03-17 19:46:25 +00:00
Slava Pestov
34e7e824e9 Sema: Fix non-determinism with ConstraintSystem::ConstraintRestrictions
We iterate over the DenseMap and simplify both types appearing
in the key. If multiple keys simplify to the same type, later
keys overwrite earlier keys, so the outcome depends on hash
table order.

Fix this by introducing an arbitrary tie break: we prefer the
highest-numbered restriction.

Fixes rdar://146780049.
2025-03-17 14:35:10 -04:00
Pavel Yaskevich
b32a1caf53 Merge pull request #80032 from xedin/expand-scope-of-execution-attr
[AST/Sema] Allow `@execution(...)` attribute to be used on initializers and accessors
2025-03-17 09:01:41 -07:00
Allan Shortlidge
fc2b5bebdc AST: Remove Decl::isSemanticallyUnavailable().
It can be replaced by querying the `AvailabilityContext` for a declaration
directly.
2025-03-16 23:33:56 -07:00
Allan Shortlidge
1945c37af5 Sema: Retire some ExportContext availability conveniences.
Just use the `AvailabilityContext` directly.
2025-03-16 09:38:54 -07:00
Allan Shortlidge
44ab0074ad Sema: Retire TypeChecker::overApproximateAvailabilityAtLocation().
It has been superseded by `AvailabilityContext::forLocation()`.
2025-03-16 09:38:54 -07:00
Allan Shortlidge
2dd544a73c AST/Sema: Sink AvailabilityContext for location queries from Sema to AST. 2025-03-15 23:47:29 -07:00
Allan Shortlidge
151c9dee39 AST: Consolidate abstract/contrete syntax decl lookup functions. 2025-03-15 23:47:29 -07:00
Allan Shortlidge
02dcd5d8cf AST/Sema: Sink AvailabilityScopeBuilder from Sema to AST. 2025-03-15 23:47:29 -07:00
Allan Shortlidge
ff9b541c57 AST/Sema: Sink isExported() queries from Sema to AST. 2025-03-15 23:47:29 -07:00
Doug Gregor
bf387c56e2 Merge pull request #80030 from DougGregor/import-macro-in-cpp-class-and-namespace
[Clang importer] Report auxiliary decls from C++ class and namespace lookup
2025-03-14 19:23:00 -07:00
Pavel Yaskevich
eeabaaee6c [AST/Sema] Allow @execution(...) attribute to be used on initializers and accessors 2025-03-14 17:28:53 -07:00
Doug Gregor
84a4a8bedb [Importer] Ensure that we can see macro-expanded declarations in C++ namespaces
Lookup into C++ namespaces uses a different path from C++ record declarations.
Augment the C++ namespace lookup path to also account for the auxiliary
declarations introduced by peer macro expansions.
2025-03-14 14:10:44 -07:00
Pavel Yaskevich
26eaf7566d Merge pull request #80004 from xedin/se-0463-enablement
[Frontend] SE-0463: Enable `SendableCompletionHandlers` feature by default
2025-03-14 11:24:44 -07:00
Doug Gregor
4cc6411d05 Merge pull request #79983 from DougGregor/isolated-conformances-alignment
Align isolated conformances with the current proposal
2025-03-13 22:40:36 -07:00
Doug Gregor
01b2789dc8 Do not infer conformance isolation to an isolated protocol 2025-03-13 17:47:26 -07:00
Doug Gregor
c7fd48aa67 Rework storage for conformance isolation
Switch over to split caching for the conformance isolation request,
which optimizes for the common case where the conformance is
nonisolated. Also put the explicit global actor TypeExpr* in an
ASTContext side table, so we don't take a pointer's worth of storage
in every conformance.

For that side table, introduce a new "ASTContext::GlobalCache" that's
there only for side tables, so we don't have to go add get/set
operations to ASTContext and recompile the world every time we want to
add a side table like this.

Thanks, Slava!
2025-03-13 17:38:54 -07:00
Pavel Yaskevich
6966b7f8d7 [TypeChecker] Ignore mismatches on sendability in @objc @implementation witnesses unless in strict concurrency mode
The requirement is `@preconcurrency` in this case and the checking
should abide by the rules.
2025-03-13 15:34:17 -07:00
Pavel Yaskevich
00af0eeb0f Merge pull request #79975 from xedin/execution-attr-on-closures
[Concurrency] Extend `@execution(...)` attribute support to closures
2025-03-13 09:25:19 -07:00
Doug Gregor
836fcbe900 Don't infer isolated conformances when the feature isn't enabled 2025-03-13 08:16:36 -07:00
Doug Gregor
6eb79052f6 [Isolated conformances] Infer main actor isolation under UnspecifiedMeansMainActorIsolated
When code in the current module defaults to main actor (under SE-0466),
also infer main-actor isolation for protocol conformances of main-actor
isolated types.
2025-03-12 23:18:34 -07:00
Doug Gregor
c58e22fccc Simplify APIs for accessing conformance isolation
The NormalProtocolConformance APIs for checking for an explicitly-written
isolation on a conformance were easy to get to, and the real semantic
API was buried in the type checker, leading to some unprincipled
checking. Instead, create a central ProtocolConformance::getIsolation()
to get the (semantic) actor isolation, and let that be the only place
that will access the explicitly-written global actor isolation for a
conformance. Update all call sites appropriately.
2025-03-12 23:18:32 -07:00
Doug Gregor
0cfa048c0a [Isolated conformances] Start parsing 'nonisolated' on conformances
It doesn't mean anything yet, but parse it and make sure it reproduces
in the module interface.
2025-03-12 23:18:31 -07:00
Doug Gregor
3837661b84 [Isolated conformances] Allow conformance isolation to differ from the type's
With the move to explicitly specifying the global actor for an isolated
conformance, we can now have conformances whose isolation differs from
that of the type, including having actors with global-actor-isolated
conformances. Introduce this generalization to match the proposal, and
update/add tests accordingly.
2025-03-12 23:18:28 -07:00
Doug Gregor
4f2476116d Suggest global actor isolation rather than 'isolated' for conformances
Update diagnostic and Fix-It to suggest global actor isolation on a
conformance (e.g, `@MainActor P`) rather than `isolated`.
2025-03-12 23:18:23 -07:00
Doug Gregor
0e873e723c [Isolated conformances] Change syntax to @<global actor type> P
Instead of using the `isolated P` syntax, switch to specifying the
global actor type directly, e.g.,

   class MyClass: @MainActor MyProto { ... }

No functionality change at this point
2025-03-12 23:18:10 -07:00