Commit Graph

45942 Commits

Author SHA1 Message Date
Alexis Laferrière
3b33531ff7 ASTGen: Accept @cdecl 2025-07-03 14:11:27 -07:00
Alexis Laferrière
22521548a7 Parser: Accept @cdecl with an indentifier for the C name
Begin accepting the attribute in the form of `@cdecl(cName)`, using an
identifier instead of a string.

For ease of landing this change we still accept the string form. We
should stop accepting it before making this feature available in
production.
2025-07-03 14:11:27 -07:00
Alexis Laferrière
eedc7c2857 Sema: Update more diagnostics for @cdecl vs @objc 2025-07-03 14:11:27 -07:00
Alexis Laferrière
0600ddd2e9 Sema: Use ForeignLanguage directly in diagnostic definitions 2025-07-03 14:11:27 -07:00
Alexis Laferrière
41f126fde6 Sema: Basic type-checking of @cdecl on global functions
This implements basic checks on the validity of the @cdecl attribute and
ensures the parameters and result types are representable in C. Many
more diagnostics will need to be updated to verify full representability
in C.
2025-07-03 14:11:26 -07:00
Alexis Laferrière
732918d5a5 Sema: Abstracted service for @cdecl style attributes 2025-07-03 13:45:33 -07:00
Alexis Laferrière
3209730bac Parser: Intro @cdecl attribute and gate it behind feature flag CDecl 2025-07-03 13:45:33 -07:00
Alexis Laferrière
221a6f09f1 Sema: Requestify most checks on @_cdecl 2025-07-03 13:45:33 -07:00
Artem Chikin
716331e77a [Dependency Scanning] Add libSwiftScan API and JSON output for source import information 2025-07-03 11:12:55 -07:00
Artem Chikin
1c9b864738 [Dependency Scanning] Keep track of each imported module's access control
Adds an access control field for each imported module identified. When multiple imports of the same module are found, this keeps track of the most "open" access specifier.
2025-07-03 11:12:46 -07:00
Pavel Yaskevich
01404bf1ae Merge pull request #82735 from xedin/rdar-154754939-6.2
[6.2][Concurency] Allow declarations with `@isolated(any)` parameters be m…
2025-07-03 09:17:34 -07:00
Allan Shortlidge
1a7e16ac97 Merge pull request #82759 from tshortli/async-priority-tests-6.2
[6.2] SILGen: Fix mis-compile of `#if available` with `-disable-availability-checking`
2025-07-03 06:39:11 -07:00
Hamish Knight
ef8e576d23 Merge pull request #82741 from hamishknight/err-val-6.2
[6.2] [AST] Use ErrorType for invalid value generic parameter
2025-07-03 14:32:44 +01:00
Erik Eckstein
849a5e9082 MandatoryPerformanceOptimizations: don't de-virtualize a generic class method call to specialized method
This results in wrong argument/return calling conventions.
First, the method call must be specialized. Only then the call can be de-virtualized.
Usually, it's done in this order anyway, because the `class_method` instruction is located before the `apply`.
But when inlining functions, the order (in the worklist) can be the other way round.

Fixes a compiler crash.
rdar://154631438
2025-07-03 13:21:27 +02:00
Hamish Knight
2e0b9d7f8a Merge pull request #82743 from hamishknight/diag-it-6.2 2025-07-03 09:24:25 +01:00
Allan Shortlidge
6e264d98e3 SILGen: Fix if #available miscompile with -disable-availabilty-checking. 2025-07-02 22:19:34 -07:00
Hamish Knight
e0ed130019 Constify DiagnosticState::determineBehavior
Split out the state mutation into a new `updateFor`
function that we call for diagnostic emission, allowing
`DiagnosticTransaction::hasErrors` to query the behavior without
mutating any state.
2025-07-02 21:29:32 +01:00
Hamish Knight
13118899cd NFC: Constify GenericTypeParamDeclGetValueTypeRequest's parameter 2025-07-02 21:19:45 +01:00
Pavel Yaskevich
b353f717f5 [Concurency] Allow declarations with @isolated(any) parameters be marked as @concurrent/nonisolated(nonsending)
It's shouldn't be possible to use these attributes directly on
the function type that is `@isolated(any)` as per SE-0461 proposal
but it shouldn't preclude declarations that have parameters with
`@isolated(any)` from using them.

Resolves: rdar://154754939
(cherry picked from commit a522448e90)
2025-07-02 11:50:22 -07:00
Zachary 'Clack' Cole
305125d8a0 Merge pull request #82694 from clackary/cherrypick/autodiff-fix-link-entity-diff-witness
[6.2 🍒][AutoDiff] Use `LinkEntity::SecondaryPointer` for diff witness
2025-07-02 11:30:48 -06:00
Anthony Latsis
6ddd1c95f3 Merge pull request #82664 from swiftlang/jepa2-6.2
[6.2] Sema: Fix the insertion location for conformances attributes
2025-07-02 16:51:55 +01:00
Doug Gregor
7d10f95f6a Merge pull request #82662 from DougGregor/back-deploy-main-actor-isolated-deinit-6.2
[6.2] [SE-0371] Back-deploy support for main-actor-isolated deinit
2025-07-02 00:13:47 -07:00
John McCall
eff0845360 Merge pull request #82613 from rjmccall/local-function-isolation-fixes-6.2
[6.2] Local function isolation fixes
2025-07-01 13:34:16 -04:00
QuietMisdreavus
a75f94eef4 [6.2] use RespectOriginallyDefinedIn when mangling extension contexts (#82657)
- **Explanation**: USR mangling can include an extension context infix
(`AAE`) when an extended type uses `@_originallyDefinedIn` on platforms
other than the active one. This adds a check for the
`RespectOriginallyDefinedIn` flag when checking extension decls against
their extended type.
- **Scope**: Changes USR mangling in these situations so that USRs are
the same for the same code regardless of platform.
- **Issues**: rdar://152598492
- **Original PRs**: https://github.com/swiftlang/swift/pull/82348
- **Risk**: Low. The change is limited to situations where the name
mangler is already disrespecting the alternate module name, and only
additionally turns on that flag for any USR mangling.
- **Testing**: Automated tests
- **Reviewers**: @edymtt @augusto2112
2025-07-01 00:30:15 -07:00
Anthony Latsis
1f28a04d29 Sema: Fix the insertion location for conformances attributes 2025-07-01 02:58:48 +01:00
Doug Gregor
dc27da053c [SE-0371] Back-deploy support for main-actor-isolated deinit
When targeting a platform that predates the introduction of isolated
deinit, make a narrow exception that allows main-actor-isolated deinit
to work through a special, inlineable entrypoint that is
back-deployed. This implementation

  1. Calls into the real implementation when available, otherwise
  2. Checks if we're on the main thread, destroying immediately when
we are, otherwise
  3. Creates a new task on the main actor to handle destruction.

This implementation is less efficient than the implementation in the
runtime, but allows us to back-deploy this functionality as far back
as concurrency goes.

Fixes rdar://151029118.
2025-06-30 17:40:00 -07:00
Daniil Kovalev
a86e717991 [AutoDiff] Use LinkEntity::SecondaryPointer for diff witness
If `LinkEntity::isTypeKind()` is true, `IRGenModule::getAddrOfLLVMVariable`
assumes that we can safely call `LinkEntity::getType()`, which does
`reinterpret_cast` of `LinkEntity::Pointer` to `TypeBase *`. However, for SIL
differentiability witness, the pointer has `SILDifferentiabilityWitness *`
type, which is not derived from `TypeBase`. So, such a cast is not allowed.

Just as with `ProtocolWitnessTableLazyAccessFunction` and
`ProtocolWitnessTableLazyCacheVariable` link entity kinds (which are
also type kinds), we should use `SecondaryPointer` instead of `Pointer` for
storing payload here, while setting `Pointer` to `nullptr`.

(cherry picked from commit 77a3873448)
2025-06-30 15:18:55 -06:00
Joe Groff
f299c6a856 Merge pull request #82344 from jckarter/addressable-for-dependencies-vw-flag-6.2
[6.2] Add an "addressable for dependencies" flag to value witness flags.
2025-06-30 12:54:25 -07:00
Adrian Prantl
637a043453 Merge pull request #82345 from adrian-prantl/expected-lowering-6.2
[Reflection] Add lightweight error handling to ReflectionContext
2025-06-30 09:23:13 -07:00
John McCall
06dec05473 Fix a bunch of bugs with the isolation of local funcs. Since we
use local funcs to implement `defer`, this also fixes several
bugs with that feature, such as it breaking in nonisolated
functions when a default isolation is in effect in the source file.

Change how we compute isolation of local funcs. The rule here is
supposed to be that non-`@Sendable` local funcs are isolated the
same as their enclosing context. Unlike closure expressions, this
is unconditional: in instance-isolated functions, the isolation
does not depend on whether `self` is captured. But the computation
was wrong: it didn't translate global actor isolation between
contexts, it didn't turn parameter isolation into capture isolation,
and it fell through for several other kinds of parent isolation,
causing the compiler to try to apply default isolation instead.
I've extracted the logic from the closure expression path into a
common function and used it for both paths.

The capture computation logic was forcing a capture of the
enclosing isolation in local funcs, but only for async functions.
Presumably this was conditional because async functions need the
isolation for actor hops, but sync functions don't really need it.
However, this was causing crashes with `-enable-actor-data-race-checks`.
(I didn't investigate whether it also failed with the similar
assertion we do with preconcurrency.) For now, I've switched this
to capture the isolated instance unconditionally. If we need to
be more conservative by either only capturing when data-race checks
are enabled or disabling the checks when the isolation isn't captured,
we can look into that.

Fix a bug in capture isolation checking. We were ignoring captures
of nonisolated declarations in order to implement the rule that
permits `nonisolated(unsafe)` variables to be captured in
non-sendable closures. This check needs to only apply to variables!
The isolation of a local func has nothing to do with its sendability
as a capture.

That fix exposed a problem where we were being unnecessarily
restrictive with generic local func declarations because we didn't
consider them to have sendable type. This was true even if the
genericity was purely from being declared in a generic context,
but it doesn't matter, they ought to be sendable regardless.

Finally, fix a handful of bugs where global actor types were not
remapped properly in SILGen.
2025-06-30 01:48:48 -04:00
John McCall
00463df058 [NFC] Encapsulate the parameter index of an ActorIsolation 2025-06-30 01:48:37 -04:00
Doug Gregor
2f838823ee Merge pull request #82590 from DougGregor/no-main-actor-when-conforming-to-sendable-6.2
[6.2] [SE-0466 experimental amendment] Don't infer @mainactor on types conforming to Sendable
2025-06-28 05:57:50 -07:00
Slava Pestov
68b9a52fc6 Merge pull request #82508 from slavapestov/warn-long-expression-type-checking-6.2
[6.2] Sema: Fix -warn-long-expression-type-checking when expression timer is disabled
2025-06-28 01:31:02 -04:00
Doug Gregor
b5cce1f694 [SE-0466] Don't infer @MainActor on types conforming to Sendable
When the default isolation is main-actor, don't infer @MainActor
for a type that conforms to a protocol P in its primary definition when
P inherits from Sendable. Such types should remain non-isolated
because they're highly unlikely to be able to implement the P
conformance (which cannot be isolated).

Put this feature behind a new experimental flag,
SendableProhibitsMainActorInference.

Implements rdar://151029300
2025-06-27 15:14:26 -07:00
Argyrios Kyrtzidis
0127926255 Merge pull request #82513 from sina-mahdavi/sina-mahdavi/cherry-pick-fix-llvm-prefix-mapping-calls
[6.2🍒] fix calls to llvm prefix mapping functions to use space-separated option format
2025-06-27 15:08:32 -07:00
Andrew Trick
92fd571d07 Merge pull request #82511 from atrick/62-inout-syntax
[6.2] Fix diagnostics for missing or invalid @_lifetime annotations on inout params
2025-06-26 23:33:16 -07:00
Slava Pestov
892e555310 Merge pull request #82543 from slavapestov/fix-rdar153730847-6.2
[6.2] ASTDemangler: Round-trip @isolated @sil_implicit_leading_param parameter attributes
2025-06-27 01:08:48 -04:00
Andrew Trick
102e5ecee1 Fix a compiler crash with '@'_lifetime(inout x), add diagnostic
This is a common mistake made more common be suggestions of existing diagnostic
that tell users not to use a 'copy' dependency.

Report a diagnostic error rather than crashing the compiler. Fix the diagnostic
output to make sense relative to the source location.

Fixes rdar://154136015 ([nonescapable] compiler assertion with @_lifetime(x: inout x))

(cherry picked from commit 080b68292d)
2025-06-26 12:58:40 -07:00
Andrew Trick
fcbcc8c1e4 Fix misleading Lifetime diagnostics for inout parameters
Correctly diagnose this as:
"invalid use of inout dependence on the same inout parameter

    @_lifetime(a: &a)
    func f_inout_useless(a: inout MutableRawSpan) {}

Correctly diagnose this as:
"lifetime-dependent parameter must be 'inout'":

    @_lifetime(a: borrow a)
    func f_inout_useless(a: borrowing MutableRawSpan) {}

(cherry picked from commit 05fa82b7a7)
2025-06-26 12:58:40 -07:00
Andrew Trick
e409752e00 Lifetime diagnostics: clarify @_lifetime usage for inout parameters
This comes up often when passing a MutableSpan as an 'inout' argument.  The
vague diagnostic was causing developers to attempt incorrect @_lifetime
annotations. Be clear about why the annotation is needed and which annotation
should be used.

(cherry picked from commit df0b81c88d)
2025-06-26 12:58:39 -07:00
Andrew Trick
52654095c1 Fix LifetimeDependence diagnostic formatting
Remove incorrectly nested single quotes from the suggested fix.

(cherry picked from commit 465d6a82e7)
2025-06-26 12:58:39 -07:00
Slava Pestov
7ed5d2bfc2 ASTDemangler: Round-trip @isolated @sil_implicit_leading_param parameter attributes
We sometimes mangle SILFunctionTypes when generating debug info
for reabstraction thunks, and these can have various exotic
parameter and result attributes. Two recent additions were
never plumbed through the mangler, causing assertion failures
when emitting debug info.

Fixes rdar://153730847.
2025-06-26 15:00:44 -04:00
Pavel Yaskevich
b2bcd21b10 [ClangImporter] Use DefaultsToSendable with completion handler parameter
This lifts the check for the feature flag up into the `importParameterType`
from `importType` and means that completion handler type for `async` variant
is no longer gains `@Sendable` attribute.

(cherry picked from commit 74471e858b)
2025-06-26 09:32:52 -07:00
Charles Zablit
e180d8bb38 Merge pull request #82479 from charles-zablit/charles-zablit/add-new-demangling-methods-to-6.2
🍒 [demangling] add new methods to the NodePrinter to enable range tracking possibilities when demangling a name
2025-06-26 11:07:26 +01:00
Hamish Knight
8e0749eea2 Merge pull request #82498 from hamishknight/tic-tac-toe-6.2 2025-06-26 09:07:26 +01:00
Slava Pestov
017be57e9b Sema: Fix -warn-long-expression-type-checking when expression timer is turned off
My change 983b75e1cf broke
-warn-long-expression-type-checking because now the
ExpressionTimer is not instantiated by default and that
entire code path is skipped.

Change it so that if -warn-long-expression-type-checking
is passed in, we still start the timer, we just don't
ever consider it to have 'expired'.

Fixes rdar://problem/152998878.
2025-06-25 22:07:56 -04:00
Sina Mahdavi
fabbbc87c8 [6.2🍒] fix calls to llvm prefix mapping functions to use space-separated option format 2025-06-25 16:48:50 -07:00
Hamish Knight
0c8468e0ee [SourceKit] Print backticks if needed in printDisplayName
Ensure we print raw identifier names with backticks for e.g the
document structure request.

rdar://152524780
2025-06-25 19:52:09 +01:00
Andrew Trick
54651d1b16 Merge pull request #82473 from atrick/62-explicit-init
[6.2] Disable surprising lifetime inference of implicit initializers
2025-06-25 11:32:40 -07:00
Charles Zablit
e1a1609045 remove unused API 2025-06-25 13:13:36 +01:00