Commit Graph

23169 Commits

Author SHA1 Message Date
swift-ci
2deb2f9a87 Merge remote-tracking branch 'origin/main' into rebranch 2025-09-19 22:17:53 -07:00
Kavon Farvardin
889baf7f2c Merge pull request #84411 from kavon/copyprop-onone
sil: provide ability to run CopyPropagation in -Onone
2025-09-19 22:09:59 -07:00
swift-ci
ce0f17aeac Merge remote-tracking branch 'origin/main' into rebranch 2025-09-19 21:35:40 -07:00
Henrik G. Olsson
7fcc72f108 Merge pull request #81859 from swiftlang/swiftify-inherit-imports
[MacrosOnImports][Swiftify] Copy module imports from clang node's module to its Swift macro SourceFile
2025-09-19 21:21:09 -07:00
Kavon Farvardin
4a943d464d sil: provide ability to run CopyPropagation in -Onone
This does not enable it by default. Use either of the flags:

```
-enable-copy-propagation
-enable-copy-propagation=always
```

to enable it in -Onone. The previous frontend flag
`-enable-copy-propagation=true` has been renamed to
`-enable-copy-propagation=optimizing`, which is currently default.

rdar://107610971
2025-09-19 16:23:19 -07:00
swift-ci
9be21897d9 Merge remote-tracking branch 'origin/main' into rebranch 2025-09-19 15:20:12 -07:00
Hamish Knight
801cd646ad Merge pull request #84390 from hamishknight/out-of-place
[Sema] Reject placeholders in type resolution for param and result types
2025-09-19 23:19:48 +01:00
swift-ci
80f659cce2 Merge remote-tracking branch 'origin/main' into rebranch 2025-09-19 12:18:05 -07:00
fahadnayyar
7b8b33eda0 [cxx-interop] Allow SWIFT_RETURNS_(UN)RETAINED on template class member functions returning T* (#84375)
When importing C++ template classes like`Ref<T>` that have methods
returning `T*`, we face the following situation when `T` is a
`SWIFT_SHARED_REFERENCE` type:

1. Without `SWIFT_RETURNS_(UN)RETAINED` annotation: Swift compiler would
emit a warning (currently under experimental-feature flag
`WarnUnannotatedReturnOfCxxFrt`) _"cannot infer the ownership of the
returned value" when T is a SWIFT_SHARED_REFERENCE type_
2. With annotation: Compiler rejects it with this error: _"cannot be
annotated... not returning a SWIFT_SHARED_REFERENCE type"_

This affects WebGPU's smart pointer types (`WTF::Ref<T>,
WTF::RefPtr<T>`) and similar patterns in other C++ codebases.

In this patch I am fixing the logic for diagnostic
`returns_retained_or_returns_unretained_for_non_cxx_frt_values`. I'm
also making it a warning instead of an error to minimize the risk, as
this diagnostic has been a hindrance to the adoption of these
annotations in real codebases when templated functions and types are
involved. (Refer to
[PR-78968](https://github.com/swiftlang/swift/pull/78968))

rdar://160862498
2025-09-19 12:09:05 -07:00
Hamish Knight
62798494ff Revert "[Sema] Handle PlaceholderTypes in associated type inference"
This reverts commit aa9aa58cea.
2025-09-19 14:22:39 +01: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
swift-ci
e7eb500826 Merge remote-tracking branch 'origin/main' into rebranch 2025-09-19 01:14:59 -07:00
Doug Gregor
3e981b7d8f Merge pull request #84374 from DougGregor/embedded-swift-restrictions
Embedded swift restrictions
2025-09-19 01:09:19 -07:00
swift-ci
ca93b4b068 Merge remote-tracking branch 'origin/main' into rebranch 2025-09-18 16:17:26 -07:00
Kavon Farvardin
84cf0a3551 Merge pull request #81858 from kavon/kavon/manual-ownership
introduce @_manualOwnership performance attribute
2025-09-18 16:15:20 -07: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
Doug Gregor
74d5ee26f0 [Embedded] Downgrade type-checker error about non-final generic class methods to a warning
The existing SIL-level diagnostic for this check only triggers when
the type is actually used, while the type-checker version is more
eager. Stage in the stricter check as a warning and we'll clamp down
on things later.
2025-09-18 10:05:35 -07:00
Doug Gregor
ade6e55b0c [Embedded] Diagnose uses of generic methods on existential values
Generic methods declared in protocols (and extensions thereof) cannot
be used on existential values, because there is no way to specialize
them for all potential types. Diagnose such cases in Embedded Swift
mode and via `-Wwarning EmbeddedRestrictions`.

This adds a bunch more warnings to the standard library that we'll
need to clean up, probably by `#if`'ing more code out.

Part of rdar://119383905.
2025-09-18 10:05:35 -07:00
Doug Gregor
844ba5f4f8 [Embedded] Diagnose non-final generic methods in class in the type checker
Move the diagnostic about non-final generic methods in classes up to
the type checker, so that it is available to `-Wwarning
EmbeddedRestrictions` and earlier in the pipeline. The SIL version of
this is still available as a backstop.

Yet another part of rdar://133874555.
2025-09-18 10:05:33 -07:00
Doug Gregor
c8e6bfd814 Put SIL diagnostics involving Embedded Swift restrictions into the appropriate group
Embedded Swift must defer some of the diagnostics about its
restrictions to late in the optimization pipeline, because some
source-level constructs (such as metatypes) are allowed in specific
cases that cannot be diagnosed in the type checker.

Put these diagnostics into the same EmbeddedRestrictions diagnostic
group as the type checker diagnostics, because that's the central
point at which we can direct folks to more information about the
restrictions in Embedded Swift.

Addresses rdar://119383905.
2025-09-18 10:05:20 -07:00
swift-ci
7b8b46694b Merge remote-tracking branch 'origin/main' into rebranch 2025-09-18 06:36:53 -07:00
Hamish Knight
deab5f7970 Merge pull request #84280 from hamishknight/csapply-cleanup
Reapply: [Sema] Remove some unreachable code from CSApply
2025-09-18 14:25:51 +01:00
swift-ci
9e3d4161b5 Merge remote-tracking branch 'origin/main' into rebranch 2025-09-18 05:03:55 -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
Hamish Knight
aa9aa58cea [Sema] Handle PlaceholderTypes in associated type inference
Avoid attempting to infer an associatedtype as a type that contains
placeholders.
2025-09-17 20:51:06 +01:00
Hamish Knight
78ea361257 [AST] Override getLocFromSource for ParamDecl
Ensure we can still produce a source location even if there's no name
loc, which is the case for e.g enum associated types.
2025-09-17 20:41:20 +01:00
Slava Pestov
90bfc1676d Sema: Remove some unreachable code from CSApply
I believe these code paths could only be reached by re-typechecking
invalid code in the old CSDiag implementation.
2025-09-17 16:11:53 +01:00
Henrik G. Olsson
928cc6c83e [ClangImporter] Deduplicate imports copied from submodule to TLM
The imported top-level module inherits the imports of all its
(transitive) submodules. Since multiple submodules can import the same
modules these need to be deduplicated to avoid redundant work.
2025-09-16 21:10:03 -07:00
swift-ci
df8f7818a0 Merge remote-tracking branch 'origin/main' into rebranch 2025-09-16 20:26:17 -07:00
Doug Gregor
56f60635b1 Merge pull request #84328 from DougGregor/coroframealloc-backdeploy 2025-09-16 20:15:50 -07:00
swift-ci
efdca7809a Merge remote-tracking branch 'origin/main' into rebranch 2025-09-16 15:42:34 -07:00
Doug Gregor
f7264e327f [IRGen] Only use a stub for swift_coroFrameAlloc when we need it
swift_coroFrameAlloc was introduced in the Swift 6.2 runtime. Give it
the appropriate availability in IRGen, so that it gets weak
availability when needed (per the deployment target). Then, only
create the stub function for calling into swift_coroFrameAlloc or
malloc (when the former isn't available) when we're back-deploying to
a runtime prior to Swift 6.2. This is a small code size/performance
win when allocating coroutine frames on Swift 6.2-or-newer platforms.

This has a side effect of fixing a bug in Embedded Swift, where the
swift_coroFrameAlloc was getting unconditionally set to have weak
external linkage despite behind defined in the same LLVM module
(because it comes from the standard library).

Fixes rdar://149695139 / issue #80947.
2025-09-16 10:51:12 -07:00
Allan Shortlidge
4841bcffa1 ModuleInterface: Print imports with @preconcurrency in swiftinterface files.
When a module has been imported `@preconcurrency` in source, when it is printed
in a `swiftinterface` file it should be printed along with the attribute to
ensure that type checking of the module's public declarations behaves
consistently.

This fix is a little unsatisfying because it adds another a linear scan over
all imports in the source for each printed import. This should be improved, but
it can be done later.

Resolves rdar://136857313.
2025-09-15 17:33:13 -07:00
swift-ci
374c577cc3 Merge remote-tracking branch 'origin/main' into rebranch 2025-09-15 12:56:24 -07:00
Doug Gregor
01873c996f Merge pull request #84283 from DougGregor/embedded-swift-untyped-throws-restriction
[Embedded] Diagnose untyped throws as an Embedded Swift restriction
2025-09-15 12:55:16 -07:00
swift-ci
0d2c4ca9be Merge remote-tracking branch 'origin/main' into rebranch 2025-09-15 10:29:21 -07:00
Allan Shortlidge
cfe9f90347 Merge pull request #84244 from tshortli/require-swift-version-in-module-interfaces
Frontend: Require `-language-mode` option when emitting swiftinterfaces
2025-09-15 10:08:23 -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
swift-ci
09d0324a71 Merge remote-tracking branch 'origin/main' into rebranch 2025-09-15 01:41:51 -07:00
Hamish Knight
411e14d00b Merge pull request #84275 from hamishknight/skippy
[CS] Avoid skipping SingleValueStmtExpr branch with ReturnStmt for completion
2025-09-15 09:33:17 +01:00
Meghana Gupta
995d6a77d9 Update hasGuaranteedResult and hasGuaranteedAddressResult 2025-09-14 23:38:06 -07:00
Meghana Gupta
6665cd5d46 [NFC] hasGuaranteedAddressResults -> hasGuaranteedAddressResult and hasGuaranteedResults -> hasGuaranteedResult 2025-09-14 23:38:06 -07:00
Doug Gregor
7d21bc332a [Embedded] Diagnose untyped throws as an Embedded Swift restriction
Untyped throws depends on existentials (`any Error`), and is therefore
not available in Embedded Swift. Introduce a diagnostic that diagnoses
any use of untyped throws, suggesting that one use typed throws
instead.

Make this an opt-in diagnostic enabled with `-Wwarning
EmbeddedRestrictions`, whether in Embedded Swift or not, using the
"default ignore" flag on these new warnings. Document this new
diagnostic group, and put the existing Embedded Swift error about
weak/unowned references in it as well.

Part of the general push to have the type checker identify code that
will not compile as Embedded Swift earlier, rdar://133874555.
2025-09-14 21:48:50 -07:00
Hamish Knight
f1ad703430 [CS] Avoid skipping SingleValueStmtExpr branch with ReturnStmt for completion
We still need to solve a branch with a ReturnStmt to avoid leaving
the contextual result type unbound. This isn't currently legal anyway,
so isn't likely to come up often in practice, but make sure we can
still solve.
2025-09-13 19:15:34 +01:00
swift-ci
bf9d79f5c1 Merge remote-tracking branch 'origin/main' into rebranch 2025-09-13 06:17:00 -07:00
Slava Pestov
6bf5213d41 Merge pull request #84251 from slavapestov/fix-rdar151171381
Fix @_opaqueReturnTypeOf module interface syntax for parameter packs
2025-09-13 08:44:44 -04:00
Hamish Knight
8e460d1e6c Merge pull request #84225 from hamishknight/access-noted
Requestify the loading of access notes
2025-09-13 12:06:43 +01:00
Hamish Knight
73255ab7a0 Merge pull request #84265 from hamishknight/tracksuit
[Frontend] Only enable request reference tracking when needed
2025-09-13 10:34:43 +01:00
swift-ci
edf0c5fffd Merge remote-tracking branch 'origin/main' into rebranch 2025-09-12 21:14:20 -07:00
Henrik G. Olsson
8e802be2b8 Merge pull request #81663 from hnrklssn/swiftify-debug-logging
[Swiftify] add debug logs for safe interop
2025-09-12 18:40:55 -07:00