Commit Graph

75 Commits

Author SHA1 Message Date
Aidan Hall d779a13f2d LifetimeDependence: Closure capture dependencies 2026-04-24 16:14:21 +01:00
Aidan Hall c62d981ea5 LifetimeDependence: Document subtyping rules
These rules are implemented in #87281.
2026-02-27 14:07:20 +00:00
Andrew Trick e2288798dd Lifetime documentation: update the inout parameter default rule. 2026-02-24 13:56:37 -08:00
Andrew Trick 033108ad2c Document new @_lifetime restrictions and defaults 2026-02-14 17:29:44 -08:00
Aidan Hall 87ad8207e5 [docs] Update func type lifetimes section with closures 2026-02-10 11:24:51 +00:00
Aidan Hall 0c1c892514 [docs] + section for function type lifetimes 2026-02-06 17:29:35 +00:00
Kavon Farvardin 458b62c9ed introduce UnderscoreOwned feature
This experimental feature allows you to override the default behavior
of a 'get' returning a noncopyable type, so that it returns an owned
value rather than a borrow, when that getter is exposed in opaque
interfaces like protocol requirements or resilient types.

resolves rdar://157318147
2026-01-06 16:39:54 -08:00
Doug Gregor 09a12946a4 Merge pull request #86100 from DougGregor/aeic-now-export-docs
Note that @_alwaysEmitIntoClient was formalized as `@export(implementation)`
2025-12-17 02:28:39 -08:00
Doug Gregor 6a600de97e Note that @_alwaysEmitIntoClient was formalized as @export(implementation) 2025-12-16 15:20:43 -08:00
Andrew Trick c490a9f731 [docs] update lifetime defaults to prioritize the same-type rule 2025-12-12 20:58:55 -08:00
Kuba Mracek adeb40f261 SE-0492: Stabilize @_section/@_used into @section/@used
Removes the underscored prefixes from the @_section and @_used attributes, making them public as @section and @used respectively. The SymbolLinkageMarkers experimental feature has been removed as these attributes are now part of the standard language. Implemented expression syntactic checking rules per SE-0492.

Major parts:
- Renamed @_section to @section and @_used to @used
- Removed the SymbolLinkageMarkers experimental feature
- Added parsing support for the old underscored names with deprecation warnings
- Updated all tests and examples to use the new attribute names
- Added syntactic validation for @section to align with SE-0492 (reusing the legality checker by @artemcm)
- Changed @DebugDescription macro to explicitly use a tuple type instead of type inferring it, to comply with the expression syntax rules
- Added a testcase for the various allowed and disallowed syntactic forms, `test/ConstValues/SectionSyntactic.swift`.
2025-10-22 16:05:39 -07:00
Andrew Trick 84a4b328ec Lifetime inference test case improvements.
Cleanup the tests so we can cross reference them with the documentation.

Update the tests to allow multiple annotations and defaults.
2025-09-03 22:42:13 -07:00
Andrew Trick bbdadac8fe Document @_lifetime annotation 2025-09-03 22:42:13 -07:00
Pavel Yaskevich 04d46760bb [AST] Extend @_inheritActorContext attribute to support optional always modifier
By default (currently) the closure passed to a parameter with `@_inheritActorContext`
would only inherit isolation from `nonisolated`, global actor isolated or actor
context when "self" is captured by the closure. `always` changes this behavior to
always inherit actor isolation from context regardless of whether it's captured
or not.
2025-05-14 20:07:57 -07:00
Doug Gregor e88f8995e1 [Diagnostics] Eliminate educational notes in favor of diagnostic groups
We've been converging the implementations of educational notes and
diagnostic groups, where both provide category information in
diagnostics (e.g., `[#StrictMemorySafety]`) and corresponding
short-form documentation files. The diagnostic group model is more
useful in a few ways:

* It provides warnings-as-errors control for warnings in the group
* It is easier to associate a diagnostic with a group with
GROUPED_ERROR/GROUPED_WARNING than it is to have a separate diagnostic
ID -> mapping.
* It is easier to see our progress on diagnostic-group coverage
* It provides an easy name to use for diagnostic purposes.

Collapse the educational-notes infrastructure into diagnostic groups,
migrating all of the existing educational notes into new groups.
Simplify the code paths that dealt with multiple educational notes to
have a single, possibly-missing "category documentation URL", which is
how we're treating this.
2025-03-29 15:40:35 -07:00
강수진 56144a0eb0 [docs] Fix markdown link text for SE-0302 (#79681)
Added missing link text for marker protocol reference.
2025-02-28 11:47:27 -08:00
Alejandro Alonso ca8c90ecc0 Support movesAsLike for the array variant of @_rawLayout 2024-07-28 10:29:57 -07:00
Joe Groff 044d8c9f56 Merge pull request #75378 from jckarter/warn-on-runtime-function-symbol-references
Stage in a warning when trying to access symbols used by the compiler.
2024-07-24 08:18:57 -07:00
LamTrinh.Dev b6239b8cee [docs] Update links to repositories moved to https://github.com/swiftlang/ 2024-07-22 12:22:43 -07:00
Joe Groff 8bc5a1f1fc Stage in a warning when trying to access symbols used by the compiler.
Attempting to bypass the compiler and access runtime functions directly has
a long history of breaking in hard-to-predict ways, and there's usually a better
way. Put up a warning to try to flush out misuses of runtime functions to see
if we can turn this into an error.
2024-07-19 16:55:11 -07:00
Kavon Farvardin bcedccac9c Docs: discuss @_preInverseGenerics 2024-06-25 12:06:23 -07:00
Michael Gottesman 3f39bdc1ed [sending] closure literals that are passed as sending parameters are now inferred to be nonisolated.
Consider the following piece of code and what the isolation is of the closure
literal passed to doSomething():

```swift
func doSomething(_ f: sending () -> ()) { ... }

@MyCustomActor
func foo() async {
  doSomething {
    // What is the isolation here?
  }
}
```

In this case, the isolation of the closure is @MyCustomActor. This is because
non-Sendable closures are by default isolated to their current context (in this
case @MyCustomActor since foo is @MyCustomActor isolated). This is a problem
since

1. Our closure is a synchronous function that does not have the ability to hop
to MyCustomActor to run said code. This could result in a concurrency hole
caused by running the closure in doSomething() without hopping to
MyCustomActor's executor.

2. In Region Based Isolation, a closure that is actor isolated cannot be sent,
so we would immediately hit a region isolation error.

To fix this issue, by default, if a closure literal is passed as a sending
parameter, we make its isolation nonisolated. This ensures that it is
disconnected and can be transferred safely.

In the case of an async closure literal, we follow the same semantics, but we
add an additional wrinkle: we keep support of inheritActorIsolation. If one
marks an async closure literal with inheritActorIsolation, we allow for it to be
passed as a sendable parameter since it is actually Sendable under the hood.
2024-06-21 02:24:03 -07:00
Alejandro Alonso 1d941cddb4 Note that rawLayout movesAsLike should be initialized 2024-05-29 09:37:08 -07:00
Alejandro Alonso a9da08ccb6 Add option for raw layout to move as its like type 2024-05-28 14:34:22 -07:00
Becca Royal-Gordon 2a53433ad7 Soften @impl warnings only for early adopters
Adopting @implementation turns all of the warnings into errors.
2024-03-27 14:29:57 -07:00
cui fliter 127077b3aa chore: fix some comments
Signed-off-by: cui fliter <imcusg@gmail.com>
2024-03-05 17:23:22 +08:00
Yuta Saito 79b3d2d626 Add underscore prefix to extern attribute
It's already guarded by a feature flag, but it would be nice to signal
users that it's not stable yet by adding an underscore prefix.
2023-11-07 02:01:02 +00:00
Yuta Saito 69479933df [c-interop] Rename @_extern to @extern
Now the feature is gated by experimental feature flag.
It's not shipped in any language release, so this rename should be fine.
2023-10-20 17:37:43 +00:00
Yuta Saito 7a75f5d2e2 [c-interop] Use Swift base name for @_extern(c) without explicit name 2023-10-20 15:34:09 +00:00
Yuta Saito 8f6491e6b6 [c-interop][docs] Add @_extern(c) attribute explanation 2023-10-20 15:34:09 +00:00
Andrew Trick fca92e4ec6 Add a temporary @_nonEscapable attribute
For testing compiler support until we have the ~Escapable syntax.
2023-10-17 12:44:24 -07:00
Yuta Saito bd898b0e7e [wasm] add @_extern(wasm) attribute support
This attribute instructs the compiler that this function declaration
should be "import"ed from host environment. It's equivalent of Clang's
`__attribute__((import_module("module"), import_name("field")))`
2023-10-10 22:42:08 +00:00
Yuta Saito 6d378a3ec3 [wasm] add @_expose(wasm) attribute support
This attribute instructs the compiler that this function declaration
should be "export"ed from this .wasm module. It's equivalent of Clang's
`__attribute__((export_name("name")))`
2023-09-26 14:13:33 +00:00
Andrew Trick e14bda90cf Merge pull request #68287 from atrick/document-readonly
Document _effects(readonly) pitfalls
2023-09-08 10:50:19 -07:00
Andrew Trick e76c534461 Document _effects(readonly) pitfalls
And the new _effects(releasenone) requirement.
2023-09-01 17:22:12 -07:00
K 4ffc9c4fe9 Fix syntax highlighting in UnderscoredAttributes.md 2023-08-29 14:24:50 +02:00
Joe Groff 523d7aa165 Clarify a statement in the @_rawLayout docs
Make it clearer the statement about borrowed `self` and other parameters having
stable addresses for the duration of a method only holds for `@_rawLayout` types.
2023-07-27 10:40:23 -07:00
Joe Groff aee071bf4e Introduce an experimental @_rawLayout attribute.
This attribute can be attached to a noncopyable struct to specify that its
storage is raw, meaning the type definition is (with some limitations)
able to do as it pleases with the storage. This provides a basis for
implementing types for things like atomics, locks, and data structures
that use inline storage to store conditionally-initialized values.
The example in `test/Prototypes/UnfairLock.swift` demonstrates the use
of a raw layout type to wrap Darwin's `os_unfair_lock` APIs, allowing
a lock value to be stored inside of classes or other types without
needing a separate allocation, and using the borrow model to enforce
safe access to lock-guarded storage.
2023-07-24 14:28:19 -07:00
Kuba (Brecka) Mracek d427696bf9 Allow @_silgen_name to be used on globals and add a @_silgen_name(raw: ...) version that skips mangling (#66540)
Attribute @_silgen_name is today only allowed to be used on functions, this change allows usage on globals as well. The motivation for that is to be able to "forward declare" globals just like it's today possible to do with functions (for the cases where it's not practical or convenient to use a bridging header).

Separately, this change also adds a @_silgen_name(raw: ...) syntax, which simply avoids mangling the name (by using the \01 name prefix that LLVM uses). The motivation for that is to be able to reference the "magic Darwin linker symbols" that can be used to look up section bounds (in the current dylib/module) -- those symbols don't use the underscore prefix in their mangled names.
2023-06-29 08:37:51 -07:00
Kuba (Brecka) Mracek 2d5f33e2e3 Add @_used and @_section attributes for global variables and top-level functions (#65901)
* Add @_used and @_section attributes for global variables and top-level functions

This adds:
- @_used attribute that flags as a global variable or a top-level function as
  "do not dead-strip" via llvm.used, roughly the equivalent of
  __attribute__((used)) in C/C++.
- @_section("...") attribute that places a global variable or a top-level
  function into a section with that name, roughly the equivalent of
  __attribute__((section("..."))) in C/C++.
2023-05-26 14:02:32 -07:00
Nate Chandler ec1a5e0911 Add attr to enable lexical lifetime per function.
Enables modules to migrate to the new lifetime rules incrementally.
2023-02-18 11:59:54 -08:00
Allan Shortlidge d44c9f2ccc NFC: Add a changelog entry for SE-0376. 2023-02-01 22:04:33 -08:00
AgranatMarkit f3a461b42a move Generics.rst to archive folder 2022-11-30 23:18:45 +02:00
Erik Eckstein e1d59b6817 docs: fix documentation for the @inline attribute 2022-11-21 10:03:51 +01:00
Becca Royal-Gordon e544c21f99 Make all internal-or-more @_objcImpl members impls 2022-10-18 17:21:56 -07:00
Becca Royal-Gordon f2a0ab79c7 Add basic Sema support for @_objcImplementation
Does not validate members yet; nor does it emit different metadata.
2022-10-18 17:21:56 -07:00
Marco Eidinger 9c23df238c [Docs] improve @_spiOnly attribute info
Related to https://github.com/apple/swift/commit/b6800847481d29309fe86dd35c66aacc40bc9398
2022-09-30 18:09:33 -07:00
Nate Chandler 5642a46378 Renamed _noEagerMove attribute.
Avoid introducing extra terminology via an underscored attribute.

rdar://99723104
2022-09-12 08:21:18 -07:00
QuietMisdreavus f674b473ec introduce a @_documentation(...) attribute to influence SymbolGraphGen (#60242)
* add @_documentation(...) attribute to influence SymbolGraphGen

rdar://79049241
2022-09-06 14:12:42 -06:00
Alexis Laferrière 7ed3ed8167 [Docs] Document the @_spiOnly attribute 2022-09-01 15:18:40 -07:00