Commit Graph

46165 Commits

Author SHA1 Message Date
Andrew Trick
5a866009f9 Merge pull request #82472 from atrick/explicit-init
Disable surprising lifetime inference of implicit initializers
2025-06-27 04:19:05 -07:00
Slava Pestov
34253a8606 Merge pull request #82506 from slavapestov/warn-long-expression-type-checking
Sema: Fix the -warn-long-expression-type-checking flag
2025-06-27 01:10:25 -04:00
Anthony Latsis
1f89bb6a94 Merge pull request #82452 from swiftlang/jepa2
Sema: Fix the insertion location for conformances attributes
2025-06-26 21:38:41 +01:00
Andrew Trick
7abe2222f9 Disable surprising lifetime inference of implicit initializers
Non-escapable struct definitions often have inicidental integer fields that are
unrelated to lifetime. Without an explicit initializer, the compiler would infer
these fields to be borrowed by the implicit intializer.

    struct CountedSpan: ~Escapable {
      let span: Span<Int>
      let i: Int

      /* infer: @lifetime(copy span, borrow i) init(...) */
    }

This was done because
- we always want to infer lifetimes of synthesized code if possible
- inferring a borrow dependence is always conservative

But this was the wrong decision because it inevitabely results in lifetime
diagnostic errors elsewhere in the code that can't be tracked down at the use
site:

    let span = CountedSpan(span: span, i: 3) // ERROR: span depends on the lifetime of this value

Instead, force the author of the data type to specify whether the type actually
depends on trivial fields or not. Such as:

    struct CountedSpan: ~Escapable {
      let span: Span<Int>
      let i: Int

      @lifetime(copy span) init(...) { ... }
    }

This fix enables stricter diagnostics, so we need it in 6.2.

Fixes rdar://152130977 ([nonescapable] confusing diagnostic message when a
synthesized initializer generates dependence on an Int parameter)
2025-06-26 12:47:01 -07:00
Anthony Latsis
de6870ed35 Merge pull request #82478 from swiftlang/jepa3
AST: Fix out of sync diagnostic
2025-06-26 18:33:22 +01:00
Pavel Yaskevich
32a0d80b60 Merge pull request #82085 from xedin/rdar-149811049
[ClangImporter] SE-0463: Implement `@Sendable` inference exception for global actor isolated functions
2025-06-26 09:26:28 -07:00
Hamish Knight
46f5e417fd Merge pull request #82481 from hamishknight/tic-tac-toe
[SourceKit] Print backticks if needed in `printDisplayName`
2025-06-26 12:29:27 +01:00
Andrew Trick
e25dcfa0a7 Merge pull request #82505 from atrick/inout-syntax
Fix diagnostics for missing or invalid @_lifetime annotations on inout params
2025-06-26 01:14:49 -07:00
Andrew Trick
3309f75f82 Merge pull request #82474 from atrick/feature-flag
Promote feature NonescapableAccessorOnTrivial to be non-experimental
2025-06-25 19:28:47 -07:00
Slava Pestov
487918f07b Sema: Fix -warn-long-expression-type-checking when expression timer is turned off
My change 983b75e1cf broke
-warn-long-expression-type-checking because now the
ExpressionTimer is not instantiated by default and that
entire code path is skipped.

Change it so that if -warn-long-expression-type-checking
is passed in, we still start the timer, we just don't
ever consider it to have 'expired'.

Fixes rdar://problem/152998878.
2025-06-25 22:07:23 -04:00
Slava Pestov
84d1d115e1 Sema: Change -solver-memory-threshold into a frontend flag for consistency with the others 2025-06-25 22:07:23 -04:00
Andrew Trick
080b68292d Fix a compiler crash with '@'_lifetime(inout x), add diagnostic
This is a common mistake made more common be suggestions of existing diagnostic
that tell users not to use a 'copy' dependency.

Report a diagnostic error rather than crashing the compiler. Fix the diagnostic
output to make sense relative to the source location.

Fixes rdar://154136015 ([nonescapable] compiler assertion with @_lifetime(x: inout x))
2025-06-25 16:34:43 -07:00
Andrew Trick
05fa82b7a7 Fix misleading Lifetime diagnostics for inout parameters
Correctly diagnose this as:
"invalid use of inout dependence on the same inout parameter

    @_lifetime(a: &a)
    func f_inout_useless(a: inout MutableRawSpan) {}

Correctly diagnose this as:
"lifetime-dependent parameter must be 'inout'":

    @_lifetime(a: borrow a)
    func f_inout_useless(a: borrowing MutableRawSpan) {}
2025-06-25 16:34:43 -07:00
Andrew Trick
df0b81c88d Lifetime diagnostics: clarify @_lifetime usage for inout parameters
This comes up often when passing a MutableSpan as an 'inout' argument.  The
vague diagnostic was causing developers to attempt incorrect @_lifetime
annotations. Be clear about why the annotation is needed and which annotation
should be used.
2025-06-25 16:34:42 -07:00
Andrew Trick
465d6a82e7 Fix LifetimeDependence diagnostic formatting
Remove incorrectly nested single quotes from the suggested fix.
2025-06-25 15:24:12 -07:00
Argyrios Kyrtzidis
d385e8c87a Merge pull request #81792 from sina-mahdavi/sina-mahdavi/fix-llvm-prefix-mapping-calls
fix calls to llvm prefix mapping functions to use space-separated opt…
2025-06-25 13:19:21 -07:00
Artem Chikin
705b1a667f Merge pull request #82429 from artemcm/ScannerInvalidBinaryModuleRefactor
[Dependency Scanning] Refactor the scanner to simplify layering
2025-06-25 09:03:18 -07:00
Tony Allevato
180693b6ea Merge pull request #82453 from azarovalex/fix-overridden-typo
[Diagnostics] Fix typo in 'overridden' warning message and identifier
2025-06-25 11:01:41 -04:00
Hamish Knight
55ef1bcaf0 [SourceKit] Print backticks if needed in printDisplayName
Ensure we print raw identifier names with backticks for e.g the
document structure request.

rdar://152524780
2025-06-25 15:15:17 +01:00
Anthony Latsis
797548a085 AST: Fix out of sync diagnostic
`declared_protocol_conformance_here` depends on the raw values of
`ConformanceEntryKind`
2025-06-25 09:46:07 +01:00
Andrew Trick
1a2d8e48fe Promote feature NonescapableAccessorOnTrivial to be non-experimental
This flag was not experimental for any good reason; it should always be
enabled. The flag only exists so we can introduce a new API:
UnsafeMutablePointer.mutableSpan. Supported compilers cannot handle the new API.

rdar://154247502 (Promote feature NonescapableAccessorOnTrivial to be
non-experimental)
2025-06-24 18:51:18 -07:00
Adrian Prantl
e24e676520 Merge pull request #82336 from charles-zablit/charles-zablit/add-new-demangling-methods
add new methods to the NodePrinter to enable range tracking possibilities when demangling a name
2025-06-24 16:11:06 -07:00
Doug Gregor
ab4e87fe5a Merge pull request #82443 from DougGregor/preconcurrency-unsafe-silence
Allow '@unsafe' on import declarations to silence '@preconcurrency' warning
2025-06-24 13:49:55 -07:00
Sina Mahdavi
7090b7e145 fix calls to llvm prefix mapping functions to use space-separated option format 2025-06-24 13:32:55 -07:00
Erik Eckstein
0dbc63a00b Guard InlineArray addressors with feature flag
To be able to parse a recent Swift.swiftinterface file with a 6.2 compiler.
This is a follow-up fix for https://github.com/swiftlang/swift/pull/81441

rdar://154118968
2025-06-24 16:02:54 +02:00
Anthony Latsis
ad8c52237c Sema: Fix the insertion location for conformances attributes 2025-06-24 14:49:03 +01:00
Charles Zablit
e8ea37b681 remove unused API 2025-06-24 13:03:32 +01:00
Alex Azarov
b72cda2cfb [Diagnostics] Fix typo in 'overridden' warning message and identifier 2025-06-24 13:41:36 +02:00
Meghana Gupta
86bdca5bf4 Merge pull request #82354 from meg-gupta/lifetimeenum
Add lifetime dependencies on function types representing ~Escapable enum elements with ~Escapable payloads
2025-06-23 22:07:38 -07:00
Doug Gregor
0e3da0e499 Allow '@unsafe' on import declarations to silence '@preconcurrency' warning
'@preconcurrency' imports open up memory safety holes with respect to
Sendable, which are diagnosed under strict memory safety + strict
concurrency checking. Allow one to write '@unsafe' on those imports to
silence the diagnostic about it.
2025-06-23 19:06:14 -07:00
Daniil Kovalev
644f364d3d [AutoDiff] Use LinkEntity::SecondaryPointer for diff witness (#82412)
If `LinkEntity::isTypeKind()` is true, `IRGenModule::getAddrOfLLVMVariable` assumes that we can safely call
`LinkEntity::getType()`, which does `reinterpret_cast` of `LinkEntity::Pointer` to `TypeBase *`. However, for SIL
differentiability witness, the pointer has `SILDifferentiabilityWitness *` type, which is not derived from `TypeBase`. So, such a cast is not allowed.

Just as with `ProtocolWitnessTableLazyAccessFunction` and `ProtocolWitnessTableLazyCacheVariable` link entity kinds (which are also type kinds), we should use `SecondaryPointer` instead of `Pointer` for storing payload here, while setting `Pointer` to `nullptr`.
2025-06-23 16:18:07 -07:00
Meghana Gupta
db24b6f758 Support lifetime dependence inference on enum elements 2025-06-23 13:42:53 -07:00
Artem Chikin
39c096c388 [Dependency Scanning] Refactor 'ModuleDependenciesCache' to not hold a reference to the global 'SwiftDependencyScanningService'
While this made sense in the distant past where the scanning service provided backing storage for the dependency cache, it no longer does so and now makes for awkard layering where clients get at the service via the cache. Now the cache is a simple data structure while all the clients that need access to the scanning service will get it explicitly.
2025-06-23 13:39:43 -07:00
Artem Chikin
68883a1014 [Dependency Scanning] Refactor Swift Scanner loader to be standalone
- 'SwiftModuleScanner' will now be owned directly by the 'ModuleDependencyScanningWorker' and will contain all the necessary custom logic, instead of being instantiated by the module interface loader for each query
- Moves ownership over module output path and sdk module output path directly into the scanning worker, instead of the cache
2025-06-23 13:39:36 -07:00
Egor Zhdan
4911078437 [cxx-interop] NFC: Remove unused function 2025-06-23 15:25:00 +01:00
Andrew Trick
374026f344 Merge pull request #82380 from atrick/nonescapable-accessor-on-trivial
Add Feature: NonescapableAccessorOnTrivial
2025-06-21 09:24:12 -07:00
nate-chandler
17c1fbd5f4 Merge pull request #82313 from jamieQ/copy-prop-ossa-dead-ends-build-time-fix
[SILOptimizer]: slow OSSA lifetime canonicalization mitigation
2025-06-21 08:50:58 -07:00
eeckstein
1d3895610e Merge pull request #82349 from eeckstein/alloc-box-to-stack
Optimizer: re-implement and improve the AllocBoxToStack pass
2025-06-21 07:28:18 +02:00
Andrew Trick
cc357f4f32 Add Feature: NonescapableAccessorOnTrivial
To guard the new UnsafeMutablePointer.mutableSpan APIs.

This allows older compilers to ignore the new APIs. Otherwise, the type checker
will crash on the synthesized _read accessor for a non-Escapable type:

    error: cannot infer lifetime dependence on the '_read' accessor because 'self'
    is BitwiseCopyable, specify '@lifetime(borrow self)'

I don't know why the _read is synthesized in these cases, but apparently it's
always been that way.

Fixes: rdar://153773093 ([nonescapable] add a compiler feature to guard
~Escapable accessors when self is trivial)
2025-06-20 15:59:13 -07:00
Anthony Latsis
1ceeb7089b Merge pull request #82338 from AnthonyLatsis/jepa
ASTBridging: Bridge more enums directly
2025-06-20 23:13:50 +01:00
Ian Anderson
58cd10c045 Merge pull request #82283 from ian-twilightcoder/swift-api-digester-args
[ABIChecker] Use -Isystem and -Fsystem for swift-api-digester
2025-06-20 14:17:21 -07:00
Anthony Latsis
dd78cd6dbe ASTBridging: Bridge swift::PlatformKind directly 2025-06-20 16:46:03 +01:00
Anthony Latsis
de46b95e7e ASTBridging: Bridge swift::GenericTypeParamKind directly 2025-06-20 16:46:03 +01:00
Anthony Latsis
dcbf2781c5 ASTBridging: Bridge swift::RequirementReprKind directly 2025-06-20 16:46:03 +01:00
Anthony Latsis
69a27e1735 ASTBridging: Bridge swift::LayoutConstraintKind directly 2025-06-20 16:46:03 +01:00
Anthony Latsis
b347aedeb0 ASTBridging: Encapsulate some operations on BridgedLayoutConstraint
NB: Switching from factory methods to initializers as well crashes on
Windows.
2025-06-20 16:44:49 +01:00
Adrian Prantl
267d063599 Merge pull request #82325 from adrian-prantl/153687085
[RemoteInspection] Change RemoteAbsolutePointer (NFC)
2025-06-20 08:18:47 -07:00
Charles Zablit
479e664a04 add new methods to the NodePrinter to enable range tracking possibilities when demangling a name 2025-06-20 15:30:19 +02:00
Pavel Yaskevich
286f975c29 Merge pull request #82320 from xedin/hide-solver-hacks-behind-a-flag
[ConstraintSystem] Guard all the performance hacks with a flag
2025-06-20 00:12:16 -07:00
Erik Eckstein
6714a72256 Optimizer: re-implement and improve the AllocBoxToStack pass
This pass replaces `alloc_box` with `alloc_stack` if the box is not escaping.
The original implementation had some limitations. It could not handle cases of local functions which are called multiple times or even recursively, e.g.

```
public func foo() -> Int {
  var i = 1

  func localFunction() { i += 1 }

  localFunction()
  localFunction()
  return i
}

```

The new implementation (done in Swift) fixes this problem with a new algorithm.
It's not only more powerful, but also simpler: the new pass has less than half lines of code than the old pass.

The pass is invoked in the mandatory pipeline and later in the optimizer pipeline.
The new implementation provides a module-pass for the mandatory pipeline (whereas the "regular" pass is a function pass).
This is required because the mandatory pass needs to remove originals of specialized closures, which cannot be done from a function-pass.
In the old implementation this was done with a hack by adding a semantic attribute and deleting the function later in the pipeline.

I still kept the sources of the old pass for being able to bootstrap the compiler without a host compiler.

rdar://142756547
2025-06-20 08:15:04 +02:00