Commit Graph

19 Commits

Author SHA1 Message Date
Meghana Gupta
2e7556c144 Fix a lifetime dependence diagnostic
`LifetimeDescriptor::getName()` can crash if the descriptor had a `self`.
Replace with `LifetimeDescriptor::getString()`

(cherry picked from commit 6d0a6d2760)
2025-07-04 11:44:35 -07:00
Andrew Trick
78e8b5af50 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)

(cherry picked from commit 8789a686fed869e3cd7bc4e748a443e71df464e1)
2025-06-24 18:09:09 -07:00
Andrew Trick
efa276a62c Disallow @_lifetime(borrow) for trivial 'inout' arguments
@_lifetime(borrow holder) // ERROR
    func test(holder: inout Holder) -> NE

Fixes rdar://153040843 ([nonescapable] disallow @_lifetime(borrow)
for trivial 'inout' arguments)

(cherry picked from commit a38925493b)
2025-06-12 16:03:55 -07:00
Meghana Gupta
8d3f38623d [NFC] Update tests and diagnostics 2025-06-11 13:15:22 -07:00
Meghana Gupta
ea35d41f2a [6.2] Fix diagnostic messages for some cases of invalid lifetime dependencies
The diagnostic messages were misleading and suggested an invalid alternative.

rdar://151810577
2025-06-02 16:04:13 -07:00
Meghana Gupta
c73187aa64 [NFC] Update tests 2025-04-09 10:19:04 -07:00
Andrew Trick
64a48d08e1 Update tests for strict @lifetime type checking 2025-03-19 11:59:04 -07:00
Andrew Trick
90021dd27b Add a test for unsupported lifetime dependencies on params. 2025-03-19 11:59:01 -07:00
Pavel Yaskevich
cfad698202 [CSDiagnostics] Tailor diagnostic for Escapable conformance mismatch in key path context 2025-03-18 14:38:40 -07:00
Meghana Gupta
e8abd59da5 Update tests 2024-11-18 18:09:19 -08:00
Meghana Gupta
84a0d9c0b2 Remove -disable-experimental-parser-round-trip from @lifetime tests 2024-11-07 14:38:01 -08:00
Alex Hoppen
9bbdeaa8c0 Enable experimental parser round-trip in test cases that no longer need it
Also, track all remaining uses of `-disable-experimental-parser-round-trip` by issues.
2024-11-04 15:49:47 -08:00
Daniel Rodríguez Troitiño
ba68faaed5 [test] Mark tests that use experimental/upcoming features as such
Find all the usages of `--enable-experimental-feature` or
`--enable-upcoming-feature` in the tests and replace some of the
`REQUIRES: asserts` to use `REQUIRES: swift-feature-Foo` instead, which
should correctly apply to depending on the asserts/noasserts mode of the
toolchain for each feature.

Remove some comments that talked about enabling asserts since they don't
apply anymore (but I might had miss some).

All this was done with an automated script, so some formatting weirdness
might happen, but I hope I fixed most of those.

There might be some tests that were `REQUIRES: asserts` that might run
in `noasserts` toolchains now. This will normally be because their
feature went from experimental to upcoming/base and the tests were not
updated.
2024-11-02 11:46:46 -07:00
Meghana Gupta
008431c3b4 Update some dependsOn tests to @lifetime 2024-10-08 15:12:13 -07:00
Meghana Gupta
ea420e0780 Add a test for @lifetime(immortal) 2024-10-08 15:10:59 -07:00
Meghana Gupta
4ac90a3e11 Diagnose multiple @lifetime attributes with same target 2024-10-08 15:10:59 -07:00
Rintaro Ishizaki
761d013224 [Test] Disable new parser validation in 3 tests
These tests have syntax SwiftParser currently doesn't parse correctly.

* test/SILGen/keypaths.swift
```
\Foo.Type[0]
```
* test/SIL/lifetime_dependence_span_lifetime_attr.swift and
  test/Sema/lifetime_attr.swift
```
@lifetime(borrow x)
```
2024-10-03 11:26:52 -07:00
Meghana Gupta
f8f043f585 Change @lifetime to always mean inherit lifetime dependence 2024-09-20 22:05:23 -07:00
Meghana Gupta
7af6c11e7e Store parsed @lifetime attribute on the function type 2024-09-09 22:02:44 -07:00