Commit Graph

1056 Commits

Author SHA1 Message Date
John Hui 91f3dde9dd [cxx-interop] [NFC] Move Clang call diagnostics to ClangImporter
Moving this here gives us access to ClangImporter's internal APIs for
future improvements. It also keeps changes to interop-specific
diagnostics localized to the interop-specific part of the compiler.
2026-03-19 23:07:46 -07:00
John Hui 9fe81ed792 Merge pull request #87643 from j-hui/frt-rq 2026-03-06 16:11:10 -08:00
John Hui e178af568c [cxx-interop] [NFC] Replace some uses of CxxRecordSemantics
... with ForeignReferenceTypeInfoRequest (which CxxRecordSemantics now
uses under the hood anyway).

rdar://170858418
2026-03-05 14:22:57 -08:00
Allan Shortlidge 272eec14a2 Sema: Upgrade missing import diagnostics for key paths.
Diagnose missing imports for members referenced by key paths as errors, rather
than warnings. This reverts the downgrade that was originally implemented in
https://github.com/swiftlang/swift/pull/84160.

Resolves rdar://160154529.
2026-03-02 13:36:04 -08:00
Pavel Yaskevich fab592539e [MiscDiagnostics] MemberImportVisibility: Downgrade errors about make{Async}Iterator and next
The compiler synthesized references to these members previously weren't
diagnosed at all in closure contexts. With changes to how `for-in` loops
are type-checked, they are now picked up by `MemberImportVisibility` checking,
but errors about them have to be downgraded to warnings to maintain source
compatibility for the existing code.

Resolves: rdar://169565467
2026-02-10 19:31:21 -08:00
Anthony Latsis 85db41932d Switch ASTContext::isLanguageModeAtLeast to LanguageMode 2026-02-10 16:06:58 +00:00
Anthony Latsis 31cafb0a27 Switch DiagnosticEngine::warnUntilLanguageMode and co. to LanguageMode 2026-02-10 16:06:56 +00:00
Gábor Horváth 18961b169f Merge pull request #87002 from Xazax-hun/objc-method-locs-imported
[cxx-interop] Import the locations of ObjC methods
2026-02-07 00:36:10 +00:00
Gabor Horvath 2c03085d2e [cxx-interop] Import the locations of ObjC methods
We did not import the source locations for ObjC methods properly but had
some workarounds in place for diagnostics.

rdar://158977633
2026-02-06 11:29:48 +00:00
Kavon Farvardin ae77ba81e3 Merge pull request #87013 from kavon/revert-84789
Back out #84789 after additional testing
2026-02-06 02:58:00 -08:00
Kavon Farvardin d5f9a1eeeb Revert "Merge pull request #84789 from nickolas-pohilets/mpokhylets/fix-82618"
This reverts commit b633bd37ac, reversing
changes made to b27bb64b03.
2026-02-05 11:34:59 -08:00
Hamish Knight 746f011cd0 Merge pull request #77063 from jamieQ/jquadri/warn-weak-to-strong-capture
[Sema]: diagnose implicit strong captures of weak capture list entries
2026-02-04 14:55:58 +00:00
Jamie f9e41569f1 [Sema]: diagnose implicit strong captures of weak capture list items
Add a diagnostic for when a weak or unowned capture list item binds a
referent that is implicitly strongly captured in an outer escaping
closure.
2026-02-03 16:21:20 -06:00
Elsa Keirouz f7c21941b8 [AST] ForEachStmt: rename sequence getter/setter 2026-01-23 15:17:29 +00:00
Elsa Keirouz d54a572f7f [Sema] desugar ForEachStmt at AST level 2026-01-23 15:17:29 +00:00
John Hui e6669db10a Merge pull request #86685 from j-hui/annotate-frt-ctors
[cxx-interop] Support ownership annotations on FRT constructors
2026-01-22 03:20:02 -08:00
John Hui f3a8d1134c [cxx-interop] [NFC] Treat return type of ctor as parent type
In 53ca5c57309a45700978e4d92c7f5a215fa33547, we started treating the
return type of a constructor as the type that it is constructing
(rather than void, which is the return type stored in the AST) in
some places. This was necessary to suppress warnings that constructors
were annotated with RETURNS_{,UN}RETAINED despite them not technically
returning a FRT.

This patch adjusts some other places to be consistent about this.
However, this patch should be an NFC because constructors shouldn't
end up along these code paths, because by the time we're here we
should already have wrapped those constructors with synthesized shim
factory functions.
2026-01-21 16:23:53 -08:00
Mykola Pokhylets 170004b5c0 Applied review comments 2026-01-20 14:49:56 +01:00
Mykola Pokhylets 551a2cec6c Using ClosureExpr instead of ConversionPair in CollectionUpcastConversionExpr 2026-01-20 14:49:56 +01:00
Pavel Yaskevich 516faf505b Merge pull request #86536 from xedin/modernize-checkUseOfMetaTypeName
[MiscDiagnostics] Modernize `checkUseOfMetaTypeName`
2026-01-15 09:05:58 -08:00
Pavel Yaskevich 5d74bcd57c [MiscDiagnostics] Modernize checkUseOfMetaTypeName
This is a follow-up to https://github.com/swiftlang/swift/pull/86499.

Make sure that the error is downgraded even when there is no parent
expression, this covers pattern binding initializer expressions which
started to error after `DynamicSelf` change.

Replace a custom "will be an error in Swift 6" with a modern
downgrade API.
2026-01-13 10:09:37 -08:00
Tim Kientzle 8eabeeb8ca [SE-0474] Read2/Modify2 => YieldingBorrow/YieldingMutate
This updates a large number of internal symbols, function names,
and types to match the final approved terminology.  Matching the
surface language terminology and the compiler internals should
make the code easier for people to understand into the future.
2026-01-03 16:05:12 -08:00
Rintaro Ishizaki dffd88ee51 [Parser] Eliminate 'CommentRetentionMode::None' in Lexer
Lexer should always set `Token.CommentLength` correctly because it
necessary for restoring to the token position with comments.
Otherwise, 'Token::isAtStartOfLine()' might not correctly set.
2025-12-10 10:10:51 -08:00
Anthony Latsis 88220a33c3 [NFC] "SwiftVersion" → "LanguageMode" in DiagnosticEngine::warnUntilSwiftVersion, etc. 2025-12-04 15:11:07 +00:00
Slava Pestov 64f2d1acce AST: Rename mapConformanceOutOfContext() => mapConformanceOutOfEnvironment(), mapReplacementTypesOutOfContext() => subs.mapReplacementTypesOutOfEnvironment() 2025-11-12 14:48:19 -05:00
Slava Pestov 819738c83e AST: Rename mapTypeIntoContext() => mapTypeIntoEnvironment(), mapTypeOutOfContext() => mapTypeOutOfEnvironment() 2025-11-12 14:48:19 -05:00
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