Commit Graph

1566 Commits

Author SHA1 Message Date
Pavel Yaskevich
0286f4ab82 [AST/Sema] SE-0487: Expand @nonexhaustive attribute to support warn argument
The spelling `@nonexhaustive(warn)` replaces `@preEnumExtensibility`
attriubte.

(cherry picked from commit 43eec8fede)
2025-08-18 23:58:29 -07:00
Doug Gregor
6e419b6345 Revert "[6.2] Accept @cdecl global functions and enums, behind experimental feature flags" 2025-07-16 10:05:35 -07:00
Alexis Laferrière
2647a8e150 Serialization: Read and write the underscored bit for @cdecl 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
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
Anthony Latsis
1f28a04d29 Sema: Fix the insertion location for conformances attributes 2025-07-01 02:58:48 +01:00
Meghana Gupta
9604081c46 Serialize/deserialize lifetime dependencies on enum elements 2025-06-23 13:50:13 -07:00
Slava Pestov
15f968f269 AST: Call setExtendedNominal() instead of cacheOutput(ExtendedNominalRequest...) 2025-06-13 16:00:16 -04:00
Meghana Gupta
637f8ef03e [6.2] Fix deserialization of lifetime dependencies on ast function types 2025-06-02 17:36:22 -07:00
Pavel Yaskevich
e12201769d [AST/Sema/SIL] Implement @_inheritActorContext(always)
- Extend `@_inheritActorContext` attribute to support optional `always` modifier.
  The new modifier will make closure context isolated even if the parameter is not
  captured by the closure.
- Implementation `@_inheritActorContext` attribute validation - it could only be
  used on parameter that have `@Sendable` or `sending` and `@isolated(any)` or
  `async` function type (downgraded to a warning until future major Swift mode
  to avoid source compatibility issues).
- Add a new language feature that guards use of `@_inheritActorContext(always)` in swift interface files
- Update `getLoweredLocalCaptures` to add an entry for isolation parameter implicitly captured by `@_inheritActorContext(always)`
- Update serialization code to store `always` modifier

(cherry picked from commit 04d46760bb)
(cherry picked from commit c050e8f75a)
(cherry picked from commit c0aca5384b)
(cherry picked from commit a4f6d710cf)
(cherry picked from commit 6c911f5d42)
(cherry picked from commit 17b8f7ef12)
2025-05-22 11:32:35 -07:00
Michael Gottesman
e04e15f125 [swift-settings] Now that we aren't using it immediately, remove it from tree.
We can always get it back from the git history.

rdar://150695113
(cherry picked from commit 9d59dbed17)

Conflicts:
	include/swift/AST/DiagnosticsSema.def
	include/swift/Basic/Features.def
	test/abi/macOS/arm64/concurrency.swift
	test/abi/macOS/x86_64/concurrency.swift
2025-05-06 14:12:23 -07:00
Pavel Yaskevich
0af7032d91 [AST] Mark parameter declarations as caller isolated
When `nonisolated(nonsending)` parameter specifier is present
mark the declaration as caller isolated.

(cherry picked from commit 9bc96d4669)
2025-04-17 11:44:11 -07:00
Pavel Yaskevich
06f880e65c [AST/ASTGen/Sema/Serialization] Remove @execution attribute
Complete the transition from `@execution` to `@concurrent` and `nonisolated(nonsending)`
2025-04-16 13:18:52 -07:00
Pavel Yaskevich
d8c64c1ff0 [AST/Sema] Intoduce nonisolated(nonsending) as a replacement for @execution(caller) 2025-04-16 10:06:08 -07:00
Doug Gregor
678ea3df35 Fix deserialization assertion involving isolated conformances
(cherry picked from commit f09cdc2893)
2025-04-14 16:38:31 -07:00
Alexis Laferrière
59adcae6c3 Merge pull request #80656 from xymus/deser-late-shadowing-6.2
[6.2] Serialization: Apply type-checking shadowing after deserialization filtering
2025-04-09 09:43:38 -07:00
Alexis Laferrière
764cd1fa32 Serialization: Bring back shadowing but only after the filtering
Followup fix to #80009. We can still get ambiguities from colliding
decls across modules with the deserialization filtering. Bring back
calling the general lookup shadowing after the filtering. This way it
won't use filtered out decls to hide potential candidates.

rdar://148286345
2025-04-08 15:01:31 -07:00
Allan Shortlidge
1cd636d9b3 Serialization: Encode custom availability domains.
When serializing `@available` attributes, if the attribute applies to a custom
domain include enough information to deserialize the reference to that domain.

Resolves rdar://138441265.
2025-04-08 10:35:32 -07:00
Artem Chikin
281f84da0f [Compile Time Values] Rewrite the 'Diagnose Unknown Compile Time Values' diagnostic pass in Swift 2025-03-28 10:30:07 -07:00
Michael Gottesman
de7a62e13e Merge pull request #80312 from gottesmm/pr-126bc735b2d01c0f2f35f27268ff26d404b2fb16
[sil] Make SILFunctionTypeInfo a struct enum.
2025-03-26 18:05:57 -07:00
Becca Royal-Gordon
123447d160 Don’t add HasStorageAttr to ABI-only decls
It’s unnecessary, shouldn’t be serialized into module interfaces, and Swift doesn’t know how to compute it for an ABI-only decl since it doesn’t have accessors or an initial value.

No tests because enforcement isn’t in yet.
2025-03-26 10:47:14 -07:00
Michael Gottesman
8cfb029b5c [sil] Make SILFunctionTypeInfo a struct enum.
I am doing this in preparation for adding the ability to represent in the SIL
type system that a function is global actor isolated. Since we have isolated
parameters in SIL, we do not need to represent parameter, nonisolated, or
nonisolated caller in the type system. So this should be sufficient for our
purposes.

I am adding this since I need to ensure that we mangle into thunks that convert
execution(caller) functions to `global actor` functions what the global actor
is. Otherwise, we cannot tell the difference in between such a thunk and a thunk
that converts execution(caller) to execution(concurrent).
2025-03-26 10:23:44 -07:00
Slava Pestov
0155b41b50 AST: Extend @_originallyDefinedIn to allow specifying module name for linker directive purposes
The module name changes the symbol mangling, and also causes
TBDGen to emit linker directives. To separate out these two
behaviors, introduce a terrible hack. If the module name
contains a semicolon (`;`), the part before the semicolon
is the module name for mangling, and the part after the
semicolon is the module name for linker directives.

If there is no semicolon, both module names are identical,
and the behavior is the same as before.
2025-03-24 17:56:45 -04:00
Doug Gregor
731f58443c Address review feedback on AbstractConformance in ProtocolConformanceRef 2025-03-23 20:54:39 -07:00
Doug Gregor
2a7de1b559 Store the conforming type within an abstract ProtocolConformanceRef
An "abstract" ProtocolConformanceRef is a conformance of a type
parameter or archetype to a given protocol. Previously, we would only
store the protocol requirement itself---but not track the actual
conforming type, requiring clients of ProtocolConformanceRef to keep
track of this information separately.

Record the conforming type as part of an abstract ProtocolConformanceRef,
so that clients will be able to recover it later. This is handled by a uniqued
AbstractConformance structure, so that ProtocolConformanceRef itself stays one
pointer.

There remain a small number of places where we create an abstract
ProtocolConformanceRef with a null type. We'll want to chip away at
those and establish some stronger invariants on the abstract conformance
in the future.
2025-03-23 20:53:48 -07:00
Hamish Knight
f8ab391737 Introduce type sugar for InlineArray (#80087)
* [CS] Decline to handle InlineArray in shrink

Previously we would try the contextual type `(<int>, <element>)`,
which is wrong. Given we want to eliminate shrink, let's just bail.

* [Sema] Sink `ValueMatchVisitor` into `applyUnboundGenericArguments`

Make sure it's called for sugar code paths too. Also let's just always
run it since it should be a pretty cheap check.

* [Sema] Diagnose passing integer to non-integer type parameter

This was previously missed, though would have been diagnosed later
as a requirement failure.

* [Parse] Split up `canParseType` 

While here, address the FIXME in `canParseTypeSimpleOrComposition`
and only check to see if we can parse a type-simple, including
`each`, `some`, and `any` for better recovery.

* Introduce type sugar for InlineArray

Parse e.g `[3 x Int]` as type sugar for InlineArray. Gated behind
an experimental feature flag for now.
2025-03-23 15:31:37 -07:00
Alexis Laferrière
c9b586207d Serialization: Update recent uses of SET_OR_RETURN_ERROR 2025-03-19 16:25:48 -07:00
Alexis Laferrière
fe9c48cc8c Serialization: Protect getType for params and classes 2025-03-19 16:25:48 -07:00
Alexis Laferrière
06d2d4cb50 Serialization: Recover from missing raw types on an enum
Recover from a raw type hidden behind an internal or implementation-only
import by dropping the whole enum when the raw type is unavailable. This
scenario should happen only when looking at non-public decl for indexing or
debugging, or if dependencies somehow changed and left behind a stale
swiftmodule file.

rdar://147091863
2025-03-19 14:10:57 -07:00
Alexis Laferrière
10f95098ad Serialization: Rename macro to SET_OR_RETURN_ERROR and invert params
Rename the macro UNWRAP to SET_OR_RETURN_ERROR for clarity and invert its
parameters to have a more intuitive order of assignment target and then
expression.
2025-03-19 14:10:33 -07:00
Slava Pestov
9c657e440c Serialization: Fix a call to ProtocolConformanceRef::forAbstract() 2025-03-18 19:38:43 -04:00
Alexis Laferrière
7ae7371b62 Merge pull request #80009 from xymus/deser-internal-shadow
Serialization: Ignore lookup shadowing when resolving cross-references
2025-03-18 10:42:38 -07:00
Alexis Laferrière
18eb4e43e4 Serialization: Skip lookup shadowing when resolving cross-references
When a Swift function shadows a clang function of the same name, the
assumption was that Swift code would refer only to the Swift one.
However, if the Swift function is `@usableFromInline internal` it can be
called only from the local module and inlined automatically in other
clients. Outside of that module, sources see only the clang function, so
their inlinable code calls only the clang function and ignores the Swift
one. This configuration passed type checking but it could crash the
compiler at inlining the call as the compiler couldn't see the clang
function.

Let's update the deserialization logic to support inlined calls to the
shadowed or the shadower. Typical shadowing is already handled by the
custom deserialization cross-reference filtering logic which looks for
the defining module, scope and whether it's a Swift or clang decl. We
can disable the lookup shadowing logic and rely only on the
deserialization filtering.

rdar://146320871
https://github.com/swiftlang/swift/issues/79801
2025-03-14 12:35:18 -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
Alexis Laferrière
1392926139 Merge pull request #79927 from xymus/deser-protect-loadAllConformances
Serialization: Don't crash in loadAllConformances in extended recovery
2025-03-13 09:39:42 -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
eeckstein
47b449372e Merge pull request #79917 from eeckstein/rename-opened-archetype-type
AST: rename OpenArchetypeType -> ExistentialArchetypeType
2025-03-12 06:01:10 +01:00
Alexis Laferrière
e4ad174a1d Serialization: Don't crash in loadAllConformances in extended recovery
In extended recovery mode we should recover from all errors without
crashing. Protect loadAllConformances and drop all conformance errors in
this mode.

rdar://81811394
2025-03-11 15:12:15 -07:00
Alexis Laferrière
c0a4056768 Merge pull request #79851 from xymus/deser-recover-conformance-xref
Serialization: Diagnose broken conformances from stale swiftmodule files
2025-03-11 15:07:38 -07:00
Erik Eckstein
d225c47d25 AST: rename OpenArchetypeType -> ExistentialArchetypeType
NFC
2025-03-11 20:21:46 +01:00
Doug Gregor
1132934a4b Merge pull request #79887 from DougGregor/remove-serialization-assertion
[Serialization] Remove spurious assertion
2025-03-11 01:21:35 -07:00
Michael Gottesman
f64dd5a8d5 [concurrency] Add initial support for SwiftSettings to control defaultIsolation at the file level.
We introduce a new macro called #SwiftSettings that can be used in conjunction
with a new stdlib type called SwiftSetting to control the default isolation at
the file level. It overrides the current default isolation whether it is the
current nonisolated state or main actor (when -enable-experimental-feature
UnspecifiedMeansMainActorIsolated is set).
2025-03-10 17:33:45 -07:00
Doug Gregor
f4d10600f0 [Serialization] Remove spurious assertion 2025-03-10 11:32:01 -07:00
Alexis Laferrière
fb3944f1b1 Serialization: Error on mismatch between requirements and confirmances
When deserialization a protocol conformance from a binary swiftmodule
file the compiler can encounter inconsistencies caused by stale module
files. Replace the hard crash with a proper error and print the list of
requirements and conformances being compared to stderr for manual
inspection. Recover silently when we can afford to, during indexing or
in LLDB.
2025-03-07 14:05:57 -08:00
Alexis Laferrière
ea5658eece Serialization: Protect readNormalProtocolConformanceXRef
Failures in `readNormalProtocolConformanceXRef` are usually caused by a
dependency change without the required rebuild of its dependents.
Display a proper error instead of crashing when encountering such an
issue during normal compilation. Recover silently when we can afford to,
during indexing or in LLDB.
2025-03-07 14:05:57 -08:00
Artem Chikin
de26e960e2 Rename '_const' attribute to 'CompileTimeLiteral'
To pave the way for the new experimental feature which will operate on '@const' attribute and expand the scope of what's currently handled by '_const' without breaking compatibility, for now.
2025-03-04 07:30:02 -08:00
Alexis Laferrière
ecaa041344 Merge pull request #79165 from xymus/deser-protect-generic-params
Serialization: Protect `maybeReadGenericParams` against errors
2025-02-21 17:24:55 -08:00
Rintaro Ishizaki
6980509f8c [ASTGen] Generate DefaultArgumentInitializer
Rework ParamDecl contextualization.
2025-02-18 11:13:39 -08:00
Joe Groff
f778170cfb Merge pull request #79351 from jckarter/lifetime-dependence-lowering
SIL: Lower lifetime dependencies when lowering function types.
2025-02-17 07:51:20 -08:00
Hamish Knight
1e8dc55b7f [AST] NFC: Remove InitRetType
This is no longer used.
2025-02-16 18:52:23 +00:00