Skip to content

Commit b257a02

Browse files
authored
Merge pull request #69081 from kubamracek/embedded-existential-diag
[embedded] Improve the diagnostic message when using an existential
2 parents ff13b77 + 30046b1 commit b257a02

File tree

5 files changed

+12
-4
lines changed

5 files changed

+12
-4
lines changed

include/swift/AST/DiagnosticsSIL.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,10 @@ ERROR(global_must_be_compile_time_const,none,
352352
"global variable must be a compile-time constant", ())
353353
ERROR(non_final_generic_class_function,none,
354354
"classes cannot have non-final generic fuctions in embedded Swift", ())
355+
ERROR(embedded_swift_existential_type,none,
356+
"cannot use a value of protocol type %0 in embedded Swift", (Type))
357+
ERROR(embedded_swift_existential,none,
358+
"cannot use a value of protocol type in embedded Swift", ())
355359
NOTE(performance_called_from,none,
356360
"called from here", ())
357361

lib/SILOptimizer/Mandatory/PerformanceDiagnostics.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,11 @@ bool PerformanceDiagnostics::visitInst(SILInstruction *inst,
356356
if (module.getOptions().EmbeddedSwift &&
357357
impact & RuntimeEffect::Existential) {
358358
PrettyStackTracePerformanceDiagnostics stackTrace("existential", inst);
359-
diagnose(loc, diag::performance_metadata, "existential");
359+
if (impactType) {
360+
diagnose(loc, diag::embedded_swift_existential_type, impactType.getASTType());
361+
} else {
362+
diagnose(loc, diag::embedded_swift_existential);
363+
}
360364
return true;
361365
}
362366

test/embedded/anyobject-error-no-stdlib.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ public typealias AnyObject = Builtin.AnyObject
1313
precedencegroup AssignmentPrecedence { assignment: true }
1414

1515
public func foo(_ x: AnyObject) {
16-
_ = type(of: x) // expected-error {{existential can cause metadata allocation or locks}}
16+
_ = type(of: x) // expected-error {{cannot use a value of protocol type 'AnyObject' in embedded Swift}}
1717
// expected-note@-1 {{called from here}}
1818
}

test/embedded/basic-errors-no-stdlib.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ public protocol Player {}
44
struct Concrete: Player {}
55

66
public func test() -> any Player {
7-
Concrete() // expected-error {{existential can cause metadata allocation or locks}}
7+
Concrete() // expected-error {{cannot use a value of protocol type 'any Player' in embedded Swift}}
88
// expected-note@-1 {{called from here}}
99
}

test/embedded/throw-trap.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public func catching1() {
2323
}
2424
}
2525

26-
// CHECK-EXISTENTIALS: error: existential can cause metadata allocation or locks
26+
// CHECK-EXISTENTIALS: error: cannot use a value of protocol type 'any Error' in embedded Swift
2727

2828
// CHECK-TRAPS-SIL: sil @$s4main9throwing1SiyKF : $@convention(thin) () -> (Int, @error any Error) {
2929
// CHECK-TRAPS-SIL-NEXT: bb0:

0 commit comments

Comments
 (0)