Commit Graph

3561 Commits

Author SHA1 Message Date
Michael Gottesman
0cb64638d0 [concurrency] Add Concurrent/ConcurrentUnsafe and use it instead of ActorIsolation::Nonisolated.
This is just the first part of a larger transition.
2025-02-03 10:56:06 -08:00
stzn
65ac75fae5 [Sema]Set IsSending flag to subscript.getter if needed 2025-02-01 06:43:15 +09:00
Anthony Latsis
34f9b80cbc Merge pull request #78750 from AnthonyLatsis/oryza-sativa
[Gardening] Fix some set but not used variables
2025-01-31 04:29:05 +00:00
Anthony Latsis
a84dfc8387 [Gardening] Fix some set but not used variables 2025-01-30 21:34:38 +00:00
QuietMisdreavus
ab26b8b9d7 add support to getTopLevelDecls for clang submodules (#76401)
rdar://126031510
2025-01-30 09:39:58 -07:00
Ellie Shin
997eab4410 Merge pull request #79019 from swiftlang/elsh/downgrade-to-warning
Package CMO: downgrade error to warning when checking for deserialization errors.
2025-01-29 23:30:17 -08:00
Michael Gottesman
37720323d2 Merge pull request #78997 from gottesmm/wire-up-execution
[concurrency] Wire up execution(concurrent)/execution(caller)
2025-01-29 16:53:11 -08:00
elsh
4b6e0bf8d9 Package CMO: downgrade error to warning when checking for deserialization errors.
Binary module built with Package CMO can be loaded for package-external client
modules which do not have direct access to decls that are serialized_for_package.
Downgrade build-time error to warning when a deserialization error is found for
a decl that should be allowed to access by package-external clients resiliently.

rdar://143800032
2025-01-29 10:46:02 -08:00
Michael Gottesman
d79fcb6d84 [caller-isolation] Teach Sema how to handle isolation of explicit @execution({concurrent,caller}). 2025-01-28 13:48:44 -08:00
Allan Shortlidge
e019a32122 AST: Introduce and adopt DeclContext::isInSwiftinterface().
Checking whether a declaration is in a `.swiftinterface` is a very common query
that is made somewhat awkward because declarations are not always in source
files. To make these checks more ergonomic, expose a convenience on
DeclContext.
2025-01-27 19:25:41 -08:00
Doug Gregor
9af4d6eb65 Merge pull request #78730 from DougGregor/safe-attr
Introduce the @safe attribute as described in the opt-in safety checking proposal
2025-01-24 19:42:52 -08:00
Doug Gregor
4395537fa0 Introduce the @safe attribute as described in the opt-in safety checking proposal 2025-01-23 07:47:17 -08:00
Tony Allevato
f249db3f85 Use cached evaluator results when looking up function types.
Also improve the output for thrown error destinations in
parsable modes.
2025-01-22 14:26:14 -05:00
Joe Groff
5d0fe0a156 Merge pull request #78705 from jckarter/explicit-conditional-invertible-extension-requirements
Require explicit statement of all `Copyable`/`Escapable` requirements for conditional `Copyable`/`Escapable` conformances.
2025-01-22 09:52:26 -08:00
Alexis Laferrière
7a49b63a97 Merge pull request #78703 from xymus/fix-importing-non-visible-decls
Sema: Ensure access-level on imports only applies to visible imported decls
2025-01-22 09:32:12 -08:00
Joe Groff
a0a26b8330 Require explicit statement of all Copyable/Escapable requirements for conditional Copyable/Escapable conformances.
As specified by the SE-0446 acceptance, extensions that declare a type's
conditional `Copyable` or `Escapable` ability must reiterate explicitly all
of the `Copyable` and/or `Escapable` requirements, whether required or not
required (by e.g. `~Copyable`) that were suppressed in the original
type declaration.
2025-01-21 09:36:39 -08:00
Alexis Laferrière
880af32110 Sema: Ensure access-level on imports don't make non-visible decls visible
Access-level on imports is designed to downgrade the visibility of
imported decls. Add a check to apply this logic only to decls that were
originally visible: public and same-package.

rdar://143008763
2025-01-16 16:58:57 -08:00
Ellie Shin
727fb8c32d Merge pull request #78258 from swiftlang/elsh/disallow-bypass-deser-check
Package CMO: add deserialization checks to ensure correct memory layout
2025-01-11 05:40:49 -08:00
Doug Gregor
1b7707d2cc Remove the now-unused @safe(unchecked) 2025-01-10 10:39:16 -08:00
Doug Gregor
c043f1138b Drop the "allows unsafe" modeling as availability
With the move to unsafe effects, we no longer model `unsafe` as an
availability problem. Remove all of that supporting code.
2025-01-10 10:39:16 -08:00
Allan Shortlidge
7ed123a126 AST: Adopt SemanticAvailableAttr in Decl::getIntroducedOSVersion(). 2025-01-08 08:17:27 -08:00
elsh
c03abed00d Package optimization allows bypassing resilience, but that assumes the memory layout of the
decl being accessed is correct. When this assumption fails due to a deserialization error
of its members, the use site accesses the layout with a wrong field offset, resulting in
UB or a crash. The deserialization error is currently not caught at compile time due to
LangOpts.EnableDeserializationRecovery being enabled by default to allow for recovery of some
of the deserialization errors at a later time. In case of member deserialization, however,
it's not necessarily recovered later on.

This PR tracks whether member deserialization had an error by recursively loading members and
checking for deserialization error, and fails and emits a diagnostic. It provides a way to
prevent resilience bypassing when the deserialized decl's layout is incorrect.

Resolves rdar://132411524
2025-01-07 21:51:49 -08:00
Hamish Knight
33bff48e92 Merge pull request #78367 from hamishknight/in-context
[Sema] Remove RecontextualizeClosures
2025-01-07 09:43:27 +00:00
Allan Shortlidge
d0f63a0753 AST: Split Availability.h into multiple headers.
Put AvailabilityRange into its own header with very few dependencies so that it
can be included freely in other headers that need to use it as a complete type.

NFC.
2025-01-03 18:36:04 -08:00
Michael Gottesman
5d4239af57 [concurrency] Add new isolation kind CallerIsolationInheriting.
Right now it is basically a version of nonisolated beyond a few simple cases
like constructors/destructors where we are pretty sure we want to not support
this.

This is part of my bringup strategy for changing nonisolated/unspecified to be
caller isolation inheriting.
2025-01-02 13:18:30 -08:00
Doug Gregor
7d6e3776ba Merge pull request #78332 from DougGregor/strict-safety-improvements
Strict safety improvements
2025-01-02 08:25:02 -08:00
Anthony Latsis
9dad512515 Merge pull request #78356 from AnthonyLatsis/tuber-melanosporum
Sema: Minor QoI improvements for existential `any` diagnosis
2025-01-02 11:58:34 +00:00
Hamish Knight
af9e0c1698 [AST] Update DeclContext parent in Decl::setDeclContext
If the decl itself is a DeclContext, make sure to
update its parent too.
2024-12-27 14:44:56 +00:00
Anthony Latsis
56e2e19707 AST: Make HasSelfOrAssociatedTypeRequirementsRequest evaluate to false on cycle
Because we will have considered all the protocols in a cyclic hierarchy
by the time the cycle is hit.
2024-12-23 21:56:22 +00:00
Doug Gregor
5b90b8851a Generalize protocol conformance options spelled via attribute and incorporate @unsafe
Protocol conformances have a handful attributes that can apply to them
directly, including @unchecked (for Sendable), @preconcurrency, and
@retroactive. Generalize this into an option set that we carry around,
so it's a bit easier to add them, as well as reworking the
serialization logic to deal with an arbitrary number of such options.

Use this generality to add support for @unsafe conformances, which are
needed when unsafe witnesses are used to conform to safe requirements.
Implement general support for @unsafe conformances, including
producing a single diagnostic per missing @unsafe that provides a
Fix-It and collects together all of the unsafe witnesses as notes.
2024-12-20 23:16:23 -08:00
Becca Royal-Gordon
a6df4ef85c Merge pull request #76878 from beccadax/abi-changed-your-name 2024-12-20 10:30:48 -08:00
Allan Shortlidge
57cce71fc2 Merge pull request #78308 from tshortli/adopt-semantic-available-attr 2024-12-20 00:51:40 -08:00
Anthony Latsis
cd1ef24c49 Merge pull request #78309 from AnthonyLatsis/nymphaea
Assortment of small fixes and cleanups
2024-12-20 06:51:19 +00:00
Becca Royal-Gordon
413c673da4 [NFC] Requestify ABI role computation 2024-12-19 21:22:08 -08:00
Anthony Latsis
97a59c1dc8 TypeCheckType: Do not form protocol type with generic parent in resolveTypeInContext 2024-12-20 02:57:29 +00:00
Allan Shortlidge
0de339db1c AST: Introduce a SemanticAvailableAttr::isNoAsync() convenience. 2024-12-19 17:22:04 -08:00
Becca Royal-Gordon
08e2a4ddae Type check ABI decls
Sema now type-checks the alternate ABI-providing decls inside of @abi attributes.

Making this work—particularly, making redeclaration checking work—required making name lookup aware of ABI decls. Name lookup now evaluates both API-providing and ABI-providing declarations. In most cases, it will filter ABI-only decls out unless a specific flag is passed, in which case it will filter API-only decls out instead. Calls that simply retrieve a list of declarations, like `IterableDeclContext::getMembers()` and friends, typically only return API-providing decls; you have to access the ABI-providing ones through those.

As part of that work, I have also added some basic compiler interfaces for working with the API-providing and ABI-providing variants. `ABIRole` encodes whether a declaration provides only API, only ABI, or both, and `ABIRoleInfo` combines that with a pointer to the counterpart providing the other role (for a declaration that provides both, that’ll just be a pointer to `this`).

Decl checking of behavior specific to @abi will come in a future commit.

Note that this probably doesn’t properly exercise some of the new code (ASTScope::lookupEnclosingABIAttributeScope(), for instance); I expect that to happen only once we can rename types using an @abi attribute, since that will create distinguishable behavior differences when resolving TypeReprs in other @abi attributes.
2024-12-19 15:49:34 -08:00
Becca Royal-Gordon
94ff062edd Parse and serialize @abi attribute
This attribute will allow you to specify an alternate version of the declaration used for mangling. It will allow minor adjustments to be made to declarations so long as they’re still compatible at the calling convention level, such as refining isolation or sendability, renaming without breaking ABI, etc.

The attribute is behind the experimental feature flag `ABIAttribute`.
2024-12-19 15:48:54 -08:00
Becca Royal-Gordon
c9f539e146 [NFC] Extract autodiff parsing code to Decl.cpp
The `@differentiable` and `@derivative` attributes need a parent pointer. Move the code to populate it from Parser to AST so it can be more easily shared between the parsers.

Done in preparation for similar code to be added for `@abi`.
2024-12-19 15:47:07 -08:00
Allan Shortlidge
0288eaa3b7 AST: Introduce Decl::getSemanticAvailableAttrs().
This new attribute iterator returned from the query makes it simpler to
implement algorithms that need access to both the `AvailableAttr *` and its
corresponding `AvailabilityDomain`. This is also work towards making it
possible to return an optional `AvailabilityDomain` from
`Decl::getDomainForAvailableAttr()`.
2024-12-19 08:40:00 -08:00
Augusto Noronha
dccc52d07e Merge pull request #78104 from augusto2112/orig-defined-in
[DebugInfo] Fix handling of @_originallyDefinedIn types
2024-12-18 13:38:55 -08:00
Augusto Noronha
72b0120b43 [DebugInfo] Fix handling of @_originallyDefinedIn types
Emit an imported declaration for @_originallyDefinedIn under the
real module that these types live in.

This patch also changes the mangling for the debugger to respect
@_originallyDefinedIn, and fixes a bug where @_originallyDefinedIn
that should be ignored was still being used when mangling.

rdar://137146961
2024-12-16 10:28:18 -08:00
Doug Gregor
f49c594f7a Fix attribute insertion location in the presence of "static" and a modifier
We were incorrectly ignoring the "static" because it's not in the
DeclAttributes list.
2024-12-14 21:47:43 -08:00
Doug Gregor
268d5ccbde Suppress strict safety diagnostics in @unsafe declarations
When a declaration is `@unsafe`, don't emit strict safety diagnostics
for uses of unsafe entities, constructs, or types within it. This
allows one to account for all unsafe behavior in a module using strict
memory safety by marking the appropriate declarations `@unsafe`.

Enhance the strict-safety diagnostics to suggest the addition of
`@unsafe` where it is needed to suppress them, with a Fix-It. Ensure
that all such diagnostics can be suppressed via `@unsafe` so it's
possible to get to the above state.

Also includes a drive-by bug fix where we weren't diagnosing unsafe
methods overriding safe ones in some cases.

Fixes rdar://139467327.
2024-12-12 21:22:41 -08:00
Joe Groff
8436db3b9d Merge pull request #78021 from jckarter/addressable-params-2
Add an `@_addressableSelf` attribute to mark the self param of methods as addressable.
2024-12-09 08:42:49 -08:00
Doug Gregor
d004d24560 Ensure that we wire up *all* custom attribute initializer contexts
Thank you again, Rintaro
2024-12-06 23:02:25 -08:00
Doug Gregor
ee9c066050 Introduce a new Initializer subclass for the arguments of custom attributes
Since the introduction of custom attributes (as part of property
wrappers), we've modeled the context of expressions within these
attributes as PatternBindingInitializers. These
PatternBindingInitializers would get wired in to the variable
declarations they apply to, establishing the appropriate declaration
context hierarchy. This worked because property wrappers only every
applied to---you guessed it!---properties, so the
PatternBindingInitializer would always get filled in.

When custom attributes were extended to apply to anything for the
purposes of macros, the use of PatternBindingInitializer became less
appropriate. Specifically, the binding declaration would never get
filled in (it's always NULL), so any place in the compiler that
accesses the binding might have to deal with it being NULL, which is a
new requirement. Few did, crashes ensued.

Rather than continue to play whack-a-mole with the abused
PatternBindingInitializer, introduce a new CustomAttributeInitializer
to model the context of custom attribute arguments. When the
attributes are assigned to a declaration that has a
PatternBindingInitializer, we reparent this new initializer to the
PatternBindingInitializer. This helps separate out the logic for
custom attributes vs. actual initializers.

Fixes https://github.com/swiftlang/swift/issues/76409 / rdar://136997841
2024-12-06 17:40:32 -08:00
Joe Groff
ac7a61679d Add an @_addressableSelf attribute to mark the self param of methods as addressable. 2024-12-06 16:54:01 -08:00
Slava Pestov
351c36f327 Merge pull request #77959 from slavapestov/fix-issue-73245
Sema: Fix soundness hole with variable initializers and opaque return types
2024-12-05 15:36:55 -05:00
Slava Pestov
c0787f337f Sema: Fix soundness hole with variable initializers and opaque return types
Just because the type of the initializer expression is an opaque return type,
does not mean it is the opaque return type *for the variable being initialized*.

It looks like there is a bit of duplicated logic and layering violations going
on so I only fixed one caller of openOpaqueType(). This addresses the test case
in the issue. For the remaining calls I added FIXMEs to investigate what is
going on.

Fixes https://github.com/swiftlang/swift/issues/73245.
Fixes rdar://127180656.
2024-12-04 15:13:22 -05:00