Commit Graph

1030 Commits

Author SHA1 Message Date
Kuba (Brecka) Mracek
eb23d3bc0a Merge pull request #85074 from kubamracek/section
SE-0492: Stabilize @_section/@_used into @section/@used
2025-10-24 12:29:48 -07: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
John Hui
e5c863c7ff [NFC] Capitalize FIXME comment to make it more discoverable 2025-10-22 14:53:11 -07:00
Fahad Nayyar
facef0e034 [cxx-interop] Enabling WarnUnannotatedReturnOfCxxFrt on by default and add it to a diagnostic group
This change makes the warning for unannotated C++ functions returning foreign
reference types (FRT) enabled by default, improving memory safety for Swift/C++
interop users. Also added CxxForeignReferenceType diagnostic group for better control
2025-10-17 17:06:44 -07:00
Alexis Laferrière
0136e19dae Sema: Allow availability macros in embedded code
Availability macros are rejected from library-evolution inlinable code
as the compiler didn't know how to print them in the swiftinterface.
This isn't a concern with the embedded style of fragile functions, we
can allow availability macros there.
2025-10-14 14:14:55 -07:00
Allan Shortlidge
1a86cd9c26 AST: Introduce a Swift runtime availability domain.
Add support for the `Swift` availability domain, which represents availability
with respect to the Swift runtime. Use of this domain is restricted by the
experimental feature `SwiftRuntimeAvailability`.
2025-10-08 17:31:57 -07:00
Artem Chikin
7c74890bd8 [Performance Hints] Add simple check for returning of values of array and dictionary type
This check will run on each type-checked primary input of the current compilation and emit a warning diagnostic for all discovered occurences of this code pattern when the performance hint diagnostic is enabled
2025-10-02 10:31:13 -07:00
Hamish Knight
46df852610 [Sema] Reject placeholders in type resolution for param and result types
Not all clients can properly handle the presence of placeholders in
interface types and it doesn't seem worth the complexity for the 
type replacement diagnostic.
2025-09-19 14:22:39 +01:00
Doug Gregor
3e981b7d8f Merge pull request #84374 from DougGregor/embedded-swift-restrictions
Embedded swift restrictions
2025-09-19 01:09:19 -07:00
Slava Pestov
cf3dab10bb Merge pull request #84339 from slavapestov/better-prepared-overloads
Sema: Better prepared overloads
2025-09-18 21:47:06 -04:00
Slava Pestov
e9070cf229 Sema: Remove unused variable 2025-09-18 14:54:16 -04:00
Doug Gregor
a16c9f7ab4 [Embedded] Diagnose dynamic casts to existentials
Embedded Swift doesn't have protocol conformance metadata, so it cannot
handle dynamic casts to existentials (nor should it).

Another part of rdar://119383905.
2025-09-18 10:05:35 -07:00
Kavon Farvardin
61fe8a9b8e introduce @_manualOwnership performance attribute
This attribute forces programmers to acknowledge every
copy that is required to happen in the body of the
function. Only those copies that make sense according
to Swift's ownership rules should be "required".

The way this is implemented as of now is to flag each
non-explicit copy in a function, coming from SILGen, as
an error through PerformanceDiagnostics.
2025-09-17 13:51:57 -07:00
Meghana Gupta
c764244df0 Merge pull request #84180 from meg-gupta/borrowandmutatepr
Add preliminary support for borrow accessors
2025-09-15 10:01:15 -07:00
Meghana Gupta
9fe489ce22 Introduce borrow and mutate as new accessor kinds
And handle them in various covered switches
2025-09-09 14:30:26 -07:00
Hamish Knight
84847bcd06 [Sema] Relax a check in VarDeclUsageChecker
We don't want to just check the first pattern, we're interested in
the first pattern that binds the given variable. That can be determined
by checking if it's canonical or not.
2025-09-09 13:48:40 +01:00
Hamish Knight
84befd43ab [AST] Make case body variables for CaseStmt non-optional
We don't really care about the distinction between empty and nil here.
2025-09-09 13:48:40 +01:00
Allan Shortlidge
0c5eac5c3e Sema: Downgrade missing import diagnostics for key paths.
For now, downgrade the `MemberImportVisibility` diagnostics introduced in
https://github.com/swiftlang/swift/pull/83934 to warnings.

Resolves rdar://160146503.
2025-09-08 16:15:49 -07:00
Anthony Latsis
380736292e Sema: Fix -Wsometimes-uninitialized warning 2025-08-31 11:18:27 +01:00
Slava Pestov
a5a8cf4a36 Merge pull request #83858 from slavapestov/covariant-result-type-part-2
AST: Continue process of removing replaceCovariantResultType()
2025-08-28 10:07:13 -04:00
Slava Pestov
1716832a7a AST: Remove most usages of AbstractFunctionDecl::hasDynamicSelfResult() 2025-08-27 15:34:26 -04:00
Allan Shortlidge
ea714d246f Sema: Diagnose key paths when MemberImportVisibility is enabled.
The diagnostic pass that checks whether expressions reference member
declarations that have not been imported failed to handle key path expressions.

Resolves rdar://159093481.
2025-08-27 09:44:38 -07:00
Allan Shortlidge
9de88624b2 Sema: Diagnose availability of availability domains in if #available queries.
When emitting statement diagnostics for `if #available` queries, diagnose the
availability of the decls representing the referenced availability domains.
Among other things, this checks that the domains are sufficiently visible to be
used in the containing function body context.
2025-08-26 08:20:12 -07:00
fahadnayyar
720406fdd6 Diagnose unannotated C++ APIs returning SWIFT_SHARED_REFERENCE at Swift call sites (#83025)
This patch improves the warning for C++ APIs returning
`SWIFT_SHARED_REFERENCE` types but not annotated with either
`SWIFT_RETURNS_RETAINED` or `SWIFT_RETURNS_UNRETAINED` in the following
ways:

1. The warning for missing `SWIFT_RETURNS_(UN)RETAINED` annotations is
now emitted on Swift use sites, rather than while importing the API
(func/method decls).
- This logic is now implemented as a Misl Diagnostic in function
`diagnoseCxxFunctionCalls` in file lib/Sema/MiscDiagnostics.cpp.
- The warning is now triggered only when the API is actually used, which
reduces noise in large C++ headers.
- These warnings are still gated behind experimental-feature-flag `WarnUnannotatedReturnOfCxxFrt`

rdar://150800115
2025-08-25 14:44:25 -07:00
Slava Pestov
4146a7f935 Merge pull request #83736 from slavapestov/fix-rdar157329046
Sema: New opaque return type circularity check that doesn't trigger lazy type checking of bodies
2025-08-14 23:46:01 -04:00
Mykola (Nickolas) Pokhylets
31470bbd1e Merge pull request #82732 from nickolas-pohilets/mpokhylets/weak-let-feature
Wrap SE-0481 into an upcoming feature until source incompatibilities are resolved
2025-08-14 23:59:28 +02:00
Slava Pestov
e26034b7ac Sema: New opaque return type circularity check that doesn't trigger lazy type checking of bodies
Commit b70f8a82b1 introduced a usage of
ReplaceOpaqueTypesWithUnderlyingTypes in Sema. Previously this was only
called from SILGen.

The problem was that ReplaceOpaqueTypesWithUnderlyingTypes would call
getUniqueUnderlyingTypeSubstitutions(), which triggers a request to
type check the body of the referenced function.

While this didn't result in unnecessary type checking work, because
UniqueUnderlyingTypeSubstitutionsRequest::evaluate() would skip bodies
in secondary files, it did change declaration checking order.

The specific issue we saw was a bad interaction with associated type
inference and unqualified lookup in a WMO build, and a complete test
case is hard to reduce here.

However, no behavior change is intended with this change, modulo bugs
elsewhere related to declaration checking order, so I feel OK not adding
a test case.

I'll hopefully address the unqualified lookup issue exposed in the
radar soon; it has a reproducer independent of opaque return types.

Fixes rdar://157329046.
2025-08-14 17:01:47 -04:00
Allan Shortlidge
db117bfefe Sema: Don't apply access level fix-it to @dynamicMemberLookup subscript.
The adjusted access level for the subscript shouldn't be fixed automatically
since sometimes the diagnostic is a warning and other times automatically
applying the fix-it immediately causes other errors, which can be confusing.

Resolves rdar://158261884.
2025-08-13 23:13:07 -07:00
Allan Shortlidge
b4fb7c81c0 AST: Refactor AvailabilityQuery constructors.
Get rid of the boolean arguments for unavailability in AvailabilityQuery's
constructors and introduce a `asUnavailable()` modifier that can be used
instead in the contexts where unavailability is relevant.
2025-08-06 18:01:44 -07:00
Allan Shortlidge
78f50ba741 AST: Refactor ConditionallyAvailableSubstitutions to use AvailabilityQuery.
Conditionally available opaque return types should support availability
conditions that are evaluated in any availability domain. Update
`ConditionallyAvailableSubstitutions` to model its conditions with
`AvailabilityQuery` instead of assuming that conditions are always a single
version query for the current platform.
2025-08-06 18:01:10 -07:00
Mykola Pokhylets
4e233706b9 Updated code comment to avoid giving false promises about adoption strategy of the feature 2025-08-02 20:24:46 +02:00
Mykola Pokhylets
86100fe685 Created separated warning group for warnings about unnecessary mutable weak variables 2025-08-02 20:24:46 +02:00
Mykola Pokhylets
89f8f8b9bf Wrap only changes related to the closure frontend logic 2025-08-02 20:24:46 +02:00
Mykola Pokhylets
ae48446716 Wrap SE-0481 into an upcoming feature until source incompatibilities are resolved 2025-08-02 20:24:21 +02:00
Anthony Latsis
fec049e5e4 Address llvm::PointerUnion::{is,get} deprecations
These were deprecated in
https://github.com/llvm/llvm-project/pull/122623.
2025-07-29 18:37:48 +01:00
Slava Pestov
b70f8a82b1 Sema: Improve the infinite opaque return type check
Now look through other opaque return types that appear in the
underlying type. This catches various forms of recursion that
otherwise would cause a SILGen or SILOptimizer crash.

- Fixes rdar://82992151.
2025-07-18 20:03:03 -04:00
Anthony Latsis
d7ec3a34bb Merge pull request #83094 from swiftlang/jepa-main
Sema: Make `@concurrent` not imply `async` on closures
2025-07-17 01:54:04 +01:00
Anthony Latsis
58d5059617 Sema: Make @concurrent not imply async on closures
The present approach is not prudent because `@concurrent` synchronous
functions, a natural extension, are a likely-to-happen future direction,
whereas the current inference rule is entirely grounded on `@concurrent`
being exclusive to async functions.

If we were to ship this rule, we would have to keep the promise for
backwards compatibility when implementing the aforementioned future
direction, replacing one inconsistency with another, and possibly
introducing new bug-prone expression checking code.

```swift
func foo(_: () -> Void) {}
func foo(_: () async -> Void) {}

// In a future without this change and  `@concurrent` synchronous
// functions accepted, the first call resolves to the first overload,
// and the second call resolves to the second, despite `@concurrent` no
// longer implying `async`.
foo { }
foo { @concurrent in }
```

This change also drops the fix-it for removing `@concurrent` when used
on a synchronous closure. With the inference rule gone, and the
diagnosis delayed until after solution application, this error raises a
fairly balanced choice between removing the attribute and being
explicit about the effect, where a unilateral suggestion is quite
possibly more harmful than useful.
2025-07-16 20:46:29 +01:00
Allan Shortlidge
e03cf967c3 Sema: Diagnose invalid OS versions in if #available queries.
Part of rdar://155558161.
2025-07-14 16:03:52 -07:00
Allan Shortlidge
59d74fa1c7 Sema: Diagnose opaque types that depend on availability of a custom domain.
Serialization and IRGen don't yet support opaque return types that would depend
on querying availability of a custom domain so we need to reject this code to
avoid mis-compiling it.
2025-07-02 11:23:42 -07:00
Allan Shortlidge
4a76c04cf5 SILGen: Fix if #unavailable mis-compile for zippered libraries.
Inverted availability queries were mis-compiled for zippered libraries because
the code that emits calls to `isOSVersionAtLeastOrVariantVersionAtLeast()` was
not updated when the `if #unavailable` syntax was introduced (at that time
support for zippered libraries had not yet been upstreamed). The result of
these calls is now inverted when appropriate.

To make it easier to manage the growing complexity of supporting availability
queries, Sema now models the relevant information about an availability query
with the new `AvailabilityQuery` type. It encapsulates the domain for the
query, the result if it is known at compile time, and the version tuple
arguments to pass to a runtime invocation if applicable.

Resolves rdar://147929876.
2025-07-02 11:23:42 -07:00
Allan Shortlidge
b493b56e7e Sema: Remove OpaqueUnderlyingTypeChecker::AvailabilityContext.
`AvailabilityContext` is now a fundamental type used throughout the compiler,
so it's confusing for `OpaqueUnderlyingTypeChecker` to repurpose this name to
represent an `IfStmt`.

NFC.
2025-07-02 11:23:42 -07:00
Slava Pestov
ef5e2861a2 Sema: Fix crash on invalid code in diagnoseDictionaryLiteralDuplicateKeyEntries() 2025-06-17 09:52:03 -04:00
Anthony Latsis
f2e1420a90 Sema: Never record argument label mismatches for unlabeled trailing closures
Fixes a crash on invalid. The previous logic was causing a label
mismatch constraint fix to be recorded for an unlabeled trailing closure
argument matching a variadic paramater after a late recovery argument
claim in `matchCallArgumentsImpl`, because the recovery claiming skips
arguments matching defaulted parameters, but not variadic ones. We may
want to reconsider that last part, but currently it regresses the
quality of some diagnostics, and this is a targeted fix.

The previous behavior is fine because the diagnosis routine associate
with the constraint fix (`diagnoseArgumentLabelError`) skips unlabeled
trailing closures when tallying labeling issues — *unless* there are no
other issues and the tally is zero, which we assert it is not.

Fixes rdar://152313388.
2025-06-05 18:01:20 +01:00
Mykola (Nickolas) Pokhylets
87e536ebec Merge pull request #80440 from nickolas-pohilets/mpokhylets/weak-let 2025-06-05 09:59:33 +02:00
Allan Shortlidge
aca604660f AST/Sema: Make MemberImportVisibility a migratable feature.
The migration to `MemberImportVisibility` can be performed mechanically by
adding missing import declarations, so offer automatic migration for the
feature.

Resolves rdar://151931597.
2025-05-30 15:34:08 -07:00
Mykola Pokhylets
847a7d247b Update comments 2025-05-28 21:25:37 +02:00
Mykola Pokhylets
de3a87c0ab Merge branch 'main' into mpokhylets/weak-let 2025-05-23 17:26:49 +02:00
Artem Chikin
d8176a7e89 [Compile Time Values] Add syntactic verification of valid expressions in '@const' contexts
Syntactically verify that initializer expressions of '@const' variables and argument expressions to '@const' parameters consist strictly of syntactically-verifiable set of basic values and operations
2025-05-20 09:38:36 -07:00
Mykola Pokhylets
b138c2cc35 Updated logic for diagnosting implicit self capture to handle immutable weak capture (minor source-breaking change) 2025-05-19 16:31:01 +02:00