Skip to content

Commit d5b1abb

Browse files
committed
[embedded] Improve the diagnostic message when using an existential
1 parent 4430799 commit d5b1abb

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+
"Existential type %0 is unavailable in embedded Swift", (Type))
357+
ERROR(embedded_swift_existential,none,
358+
"Existentials are unavailable 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
@@ -357,7 +357,11 @@ bool PerformanceDiagnostics::visitInst(SILInstruction *inst,
357357
if (module.getOptions().EmbeddedSwift &&
358358
impact & RuntimeEffect::Existential) {
359359
PrettyStackTracePerformanceDiagnostics stackTrace("existential", inst);
360-
diagnose(loc, diag::performance_metadata, "existential");
360+
if (impactType) {
361+
diagnose(loc, diag::embedded_swift_existential_type, impactType.getASTType());
362+
} else {
363+
diagnose(loc, diag::embedded_swift_existential);
364+
}
361365
return true;
362366
}
363367

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 {{Existential type 'AnyObject' is unavailable 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 {{Existential type 'any Player' is unavailable 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: Existential type 'any Error' is unavailable 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)