Print diagnostic group names by default

Print diagnostic groups as part of the LLVM printer in the same manner as the
Swift one does, always. Make `-print-diagnostic-groups` an inert option, since we
always print diagnostic group names with the `[#GroupName]` syntax.

As part of this, we no longer render the diagnostic group name as part
of the diagnostic *text*, instead leaving it up to the diagnostic
renderer to handle the category appropriately. Update all of the tests
that were depending on `-print-diagnostic-groups` putting it into the
text to instead use the `{{documentation-file=<file name>}}`
diagnostic verification syntax.
This commit is contained in:
Doug Gregor
2025-03-29 15:37:10 -07:00
parent e88f8995e1
commit b182c96bd7
34 changed files with 320 additions and 325 deletions

View File

@@ -1,4 +1,4 @@
// RUN: %target-typecheck-verify-swift -strict-memory-safety -print-diagnostic-groups
// RUN: %target-typecheck-verify-swift -strict-memory-safety
// The feature flag should be enabled.
#if !hasFeature(StrictMemorySafety)
@@ -91,9 +91,9 @@ func testUnsafeAsSequenceForEach() {
// expected-warning@+1{{expression uses unsafe constructs but is not marked with 'unsafe'}}{{12-12=unsafe }}
for _ in uas { } // expected-note{{conformance}}
// expected-warning@-1{{for-in loop uses unsafe constructs but is not marked with 'unsafe' [StrictMemorySafety]}}{{7-7=unsafe }}
// expected-warning@-1{{for-in loop uses unsafe constructs but is not marked with 'unsafe'}}{{documentation-file=strict-memory-safety}}{{7-7=unsafe }}
for _ in unsafe uas { } // expected-warning{{for-in loop uses unsafe constructs but is not marked with 'unsafe' [StrictMemorySafety]}}{{7-7=unsafe }}
for _ in unsafe uas { } // expected-warning{{for-in loop uses unsafe constructs but is not marked with 'unsafe'}}{{documentation-file=strict-memory-safety}}{{7-7=unsafe }}
for unsafe _ in unsafe uas { } // okay
}

View File

@@ -1,4 +1,4 @@
// RUN: %target-typecheck-verify-swift -strict-memory-safety -print-diagnostic-groups
// RUN: %target-typecheck-verify-swift -strict-memory-safety
@unsafe
class NotSafe {
@@ -36,7 +36,7 @@ class NotSafeSubclass: NotSafe {
_ = NotSafe[ns]
NotSafe.doStatically(NotSafe.self)
ns.stillUnsafe() // expected-warning{{expression uses unsafe constructs but is not marked with 'unsafe' [StrictMemorySafety]}}
ns.stillUnsafe() // expected-warning{{expression uses unsafe constructs but is not marked with 'unsafe'}}{{documentation-file=strict-memory-safety}}
// expected-note@-1{{reference to parameter 'ns' involves unsafe type 'NotSafe'}}
// expected-note@-2{{reference to instance method 'stillUnsafe()' involves unsafe type 'NotSafe'}}
}

View File

@@ -1,4 +1,4 @@
// RUN: %target-typecheck-verify-swift -strict-memory-safety -print-diagnostic-groups
// RUN: %target-typecheck-verify-swift -strict-memory-safety
@unsafe
func iAmUnsafe() { }
@@ -21,7 +21,7 @@ class C {
class D1: C { // expected-note{{make class 'D1' @unsafe to allow unsafe overrides of safe superclass methods}}{{1-1=@unsafe }}
@unsafe
override func method() { } // expected-warning{{override of safe instance method with unsafe instance method [StrictMemorySafety]}}
override func method() { } // expected-warning{{override of safe instance method with unsafe instance method}}{{documentation-file=strict-memory-safety}}
}
@unsafe class D2: C {
@@ -34,7 +34,7 @@ protocol P {
}
struct S1: P {
// expected-warning@-1{{conformance of 'S1' to protocol 'P' involves unsafe code; use '@unsafe' to indicate that the conformance is not memory-safe [StrictMemorySafety]}}{{12-12=@unsafe }}
// expected-warning@-1{{conformance of 'S1' to protocol 'P' involves unsafe code; use '@unsafe' to indicate that the conformance is not memory-safe}}{{documentation-file=strict-memory-safety}}{{12-12=@unsafe }}
@unsafe
func protoMethod() { } // expected-note{{unsafe instance method 'protoMethod()' cannot satisfy safe requirement}}
}
@@ -48,7 +48,7 @@ struct S2: P {
struct S3 { }
extension S3: P {
// expected-warning@-1{{conformance of 'S3' to protocol 'P' involves unsafe code; use '@unsafe' to indicate that the conformance is not memory-safe [StrictMemorySafety]}}{{15-15=@unsafe }}
// expected-warning@-1{{conformance of 'S3' to protocol 'P' involves unsafe code; use '@unsafe' to indicate that the conformance is not memory-safe}}{{documentation-file=strict-memory-safety}}{{15-15=@unsafe }}
@unsafe
func protoMethod() { } // expected-note{{unsafe instance method 'protoMethod()' cannot satisfy safe requirement}}
}
@@ -116,12 +116,12 @@ extension UnsafeOuter {
var yieldUnsafe: Int {
_read {
@unsafe let x = 5
yield x // expected-warning{{expression uses unsafe constructs but is not marked with 'unsafe' [StrictMemorySafety]}}
yield x // expected-warning{{expression uses unsafe constructs but is not marked with 'unsafe'}}{{documentation-file=strict-memory-safety}}
// expected-note@-1{{reference to unsafe let 'x'}}
}
_modify {
@unsafe var x = 5
yield &x // expected-warning{{expression uses unsafe constructs but is not marked with 'unsafe' [StrictMemorySafety]}}
yield &x // expected-warning{{expression uses unsafe constructs but is not marked with 'unsafe'}}{{documentation-file=strict-memory-safety}}
// expected-note@-1{{reference to unsafe var 'x'}}
}
}
@@ -142,9 +142,9 @@ struct UnsafeSequence: @unsafe IteratorProtocol, @unsafe Sequence {
}
func forEachLoop(us: UnsafeSequence) {
for _ in us { } // expected-warning{{expression uses unsafe constructs but is not marked with 'unsafe' [StrictMemorySafety]}}{{12-12=unsafe }}
for _ in us { } // expected-warning{{expression uses unsafe constructs but is not marked with 'unsafe'}}{{documentation-file=strict-memory-safety}}{{12-12=unsafe }}
// expected-note@-1{{@unsafe conformance of 'UnsafeSequence' to protocol 'Sequence' involves unsafe code}}
// expected-warning@-2{{for-in loop uses unsafe constructs but is not marked with 'unsafe' [StrictMemorySafety]}}
// expected-warning@-2{{for-in loop uses unsafe constructs but is not marked with 'unsafe'}}{{documentation-file=strict-memory-safety}}
for _ in unsafe us { }
// expected-warning@-1{{for-in loop uses unsafe constructs but is not marked with 'unsafe' [StrictMemorySafety]}}
// expected-warning@-1{{for-in loop uses unsafe constructs but is not marked with 'unsafe'}}{{documentation-file=strict-memory-safety}}
}

View File

@@ -1,7 +1,7 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -emit-module-path %t/unsafe_swift_decls.swiftmodule %S/Inputs/unsafe_swift_decls.swift
// RUN: %target-typecheck-verify-swift -strict-memory-safety -I %t -print-diagnostic-groups
// RUN: %target-typecheck-verify-swift -strict-memory-safety -I %t
// Make sure everything compiles without error when unsafe code is allowed.
// RUN: %target-swift-frontend -typecheck %s -I %t
@@ -16,7 +16,7 @@ protocol P {
@unsafe func g()
}
struct XP: P { // expected-warning{{conformance of 'XP' to protocol 'P' involves unsafe code; use '@unsafe' to indicate that the conformance is not memory-safe [StrictMemorySafety]}}{{12-12=@unsafe }}
struct XP: P { // expected-warning{{conformance of 'XP' to protocol 'P' involves unsafe code; use '@unsafe' to indicate that the conformance is not memory-safe}}{{documentation-file=strict-memory-safety}}{{12-12=@unsafe }}
@unsafe func f() { } // expected-note{{unsafe instance method 'f()' cannot satisfy safe requirement}}
@unsafe func g() { }
}
@@ -30,7 +30,7 @@ protocol Ptrable2 {
}
extension HasAPointerType: Ptrable2 { } // expected-note{{unsafe type 'HasAPointerType.Ptr' (aka 'PointerType') cannot satisfy safe associated type 'Ptr'}}
// expected-warning@-1{{conformance of 'HasAPointerType' to protocol 'Ptrable2' involves unsafe code; use '@unsafe' to indicate that the conformance is not memory-safe [StrictMemorySafety]}}{{28-28=@unsafe }}
// expected-warning@-1{{conformance of 'HasAPointerType' to protocol 'Ptrable2' involves unsafe code; use '@unsafe' to indicate that the conformance is not memory-safe}}{{documentation-file=strict-memory-safety}}{{28-28=@unsafe }}
struct UnsafeXP: @unsafe P {
@unsafe func f() { }
@@ -44,7 +44,7 @@ protocol MultiP {
struct ConformsToMultiP { }
// expected-warning@+1{{conformance of 'ConformsToMultiP' to protocol 'MultiP' involves unsafe code; use '@unsafe' to indicate that the conformance is not memory-safe [StrictMemorySafety]}}{{29-29=@unsafe }}
// expected-warning@+1{{conformance of 'ConformsToMultiP' to protocol 'MultiP' involves unsafe code; use '@unsafe' to indicate that the conformance is not memory-safe}}{{documentation-file=strict-memory-safety}}{{29-29=@unsafe }}
extension ConformsToMultiP: MultiP {
// expected-note@-1{{unsafe type 'UnsafeSuper' cannot satisfy safe associated type 'Ptr'}}
@unsafe func f() -> UnsafeSuper {
@@ -74,7 +74,7 @@ class Super {
}
class Sub: Super { // expected-note{{make class 'Sub' @unsafe to allow unsafe overrides of safe superclass methods}}{{1-1=@unsafe }}
@unsafe override func f() { } // expected-warning{{override of safe instance method with unsafe instance method [StrictMemorySafety]}}
@unsafe override func f() { } // expected-warning{{override of safe instance method with unsafe instance method}}{{documentation-file=strict-memory-safety}}
@unsafe override func g() { }
}
@@ -117,7 +117,7 @@ class ExclusivityChecking {
func f() { }
};
// expected-warning@+1{{class 'UnsafeSub' has superclass involving unsafe type 'UnsafeSuper' [StrictMemorySafety]}}{{1-1=@unsafe }}
// expected-warning@+1{{class 'UnsafeSub' has superclass involving unsafe type 'UnsafeSuper'}}{{documentation-file=strict-memory-safety}}{{1-1=@unsafe }}
class UnsafeSub: UnsafeSuper { }
// -----------------------------------------------------------------------
@@ -129,13 +129,13 @@ struct BufferThingy<T> {
}
func testConstruction() {
let _ = BufferThingy<Int>(count: 17) // expected-warning{{expression uses unsafe constructs but is not marked with 'unsafe' [StrictMemorySafety]}}{{11-11=unsafe }}
let _ = BufferThingy<Int>(count: 17) // expected-warning{{expression uses unsafe constructs but is not marked with 'unsafe'}}{{documentation-file=strict-memory-safety}}{{11-11=unsafe }}
// expected-note@-1{{reference to unsafe initializer 'init(count:)'}}
}
func testRHS(b: Bool, x: Int) {
@unsafe let limit = 17
if b && x > limit { // expected-warning{{expression uses unsafe constructs but is not marked with 'unsafe' [StrictMemorySafety]}}{{6-6=unsafe }}
if b && x > limit { // expected-warning{{expression uses unsafe constructs but is not marked with 'unsafe'}}{{documentation-file=strict-memory-safety}}{{6-6=unsafe }}
// expected-note@-1{{reference to unsafe let 'limit'}}
}
}
@@ -171,7 +171,7 @@ typealias SuperUnsafe = UnsafeSuper
@unsafe typealias SuperUnsafe2 = UnsafeSuper
// expected-warning@+3{{enum 'HasUnsafeThings' has storage involving unsafe types [StrictMemorySafety]}}
// expected-warning@+3{{enum 'HasUnsafeThings' has storage involving unsafe types}}{{documentation-file=strict-memory-safety}}
// expected-note@+2{{add '@unsafe' if this type is also unsafe to use}}{{1-1=@unsafe }}
// expected-note@+1{{add '@safe' if this type encapsulates the unsafe storage in a safe interface}}{{1-1=@safe }}
enum HasUnsafeThings {
@@ -181,7 +181,7 @@ case one(UnsafeSuper) // expected-note{{enum case 'one' involves unsafe type 'Un
case two(UnsafeSuper) // expected-note{{enum case 'two' involves unsafe type 'UnsafeSuper'}}
}
// expected-warning@+3{{class 'ClassWithUnsafeStorage' has storage involving unsafe types [StrictMemorySafety]}}
// expected-warning@+3{{class 'ClassWithUnsafeStorage' has storage involving unsafe types}}{{documentation-file=strict-memory-safety}}
// expected-note@+2{{add '@unsafe' if this type is also unsafe to use}}{{1-1=@unsafe }}
// expected-note@+1{{add '@safe' if this type encapsulates the unsafe storage in a safe interface}}{{1-1=@safe }}
class ClassWithUnsafeStorage {

View File

@@ -1,4 +1,4 @@
// RUN: %target-typecheck-verify-swift -print-diagnostic-groups
// RUN: %target-typecheck-verify-swift
protocol P { }

View File

@@ -1,4 +1,4 @@
// RUN: %target-typecheck-verify-swift -print-diagnostic-groups
// RUN: %target-typecheck-verify-swift
@unsafe func unsafeFunc() { }