Skip to content

Commit 006e78e

Browse files
authored
Merge pull request #37320 from fwcd/sourcekit-diagnostic-ids
[SourceKit] Add id and category to diagnostics
2 parents c8169c3 + da77e61 commit 006e78e

31 files changed

+228
-65
lines changed

include/swift/AST/DiagnosticEngine.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -999,6 +999,12 @@ namespace swift {
999999
/// diagnostic.
10001000
bool isAPIDigesterBreakageDiagnostic(DiagID id) const;
10011001

1002+
/// \returns true if the diagnostic is marking a deprecation.
1003+
bool isDeprecationDiagnostic(DiagID id) const;
1004+
1005+
/// \returns true if the diagnostic is marking an unused element.
1006+
bool isNoUsageDiagnostic(DiagID id) const;
1007+
10021008
/// \returns true if any diagnostic consumer gave an error while invoking
10031009
//// \c finishProcessing.
10041010
bool finishProcessing();
@@ -1037,6 +1043,8 @@ namespace swift {
10371043
llvm::StringRef diagnosticStringFor(const DiagID id,
10381044
bool printDiagnosticNames);
10391045

1046+
static llvm::StringRef diagnosticIDStringFor(const DiagID id);
1047+
10401048
/// If there is no clear .dia file for a diagnostic, put it in the one
10411049
/// corresponding to the SourceLoc given here.
10421050
/// In particular, in batch mode when a diagnostic is located in

include/swift/AST/DiagnosticsParse.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1753,7 +1753,7 @@ ERROR(version_component_not_number,none,
17531753
"version component contains non-numeric characters", ())
17541754
ERROR(compiler_version_too_many_components,none,
17551755
"compiler version must not have more than five components", ())
1756-
WARNING(unused_compiler_version_component,none,
1756+
WARNING(unused_compiler_version_component,NoUsage,
17571757
"the second version component is not used for comparison", ())
17581758
ERROR(empty_version_component,none,
17591759
"found empty version component", ())

include/swift/AST/DiagnosticsSema.def

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -575,12 +575,12 @@ NOTE(async_inferred_from_operation,none,
575575
// Key-path expressions.
576576
ERROR(expr_keypath_no_objc_runtime,none,
577577
"'#keyPath' can only be used with the Objective-C runtime", ())
578-
ERROR(expression_unused_keypath_result,none,
578+
ERROR(expression_unused_keypath_result,NoUsage,
579579
"result of key path is unused", ())
580580
ERROR(expr_keypath_non_objc_property,none,
581581
"argument of '#keyPath' refers to non-'@objc' property %0",
582582
(Identifier))
583-
WARNING(expr_keypath_swift3_objc_inference,none,
583+
WARNING(expr_keypath_swift3_objc_inference,Deprecation,
584584
"argument of '#keyPath' refers to property %0 in %1 that depends on "
585585
"'@objc' inference deprecated in Swift 4",
586586
(Identifier, Identifier))
@@ -640,7 +640,7 @@ ERROR(expr_swift_keypath_anyobject_root,none,
640640
"the root type of a Swift key path cannot be 'AnyObject'", ())
641641
ERROR(expr_keypath_multiparam_func_conversion, none,
642642
"cannot convert key path into a multi-argument function type %0", (Type))
643-
WARNING(expr_deprecated_writable_keypath,none,
643+
WARNING(expr_deprecated_writable_keypath,Deprecation,
644644
"forming a writable keypath to property %0 that is read-only in this context "
645645
"is deprecated and will be removed in a future release",(DeclName))
646646

@@ -683,7 +683,7 @@ ERROR(expr_selector_not_objc,none,
683683
NOTE(make_decl_objc,none,
684684
"add '@objc' to expose this %0 to Objective-C",
685685
(DescriptiveDeclKind))
686-
WARNING(expr_selector_swift3_objc_inference,none,
686+
WARNING(expr_selector_swift3_objc_inference,Deprecation,
687687
"argument of '#selector' refers to %0 %1 in %2 that depends on "
688688
"'@objc' inference deprecated in Swift 4",
689689
(DescriptiveDeclKind, DeclName, Identifier))
@@ -693,10 +693,10 @@ WARNING(selector_literal_invalid,none,
693693
"string literal is not a valid Objective-C selector", ())
694694
WARNING(selector_literal_undeclared,none,
695695
"no method declared with Objective-C selector %0", (ObjCSelector))
696-
WARNING(selector_literal_deprecated,none,
696+
WARNING(selector_literal_deprecated,Deprecation,
697697
"use of string literal for Objective-C selectors is deprecated; "
698698
"use '#selector' or explicitly construct a 'Selector'", ())
699-
WARNING(selector_literal_deprecated_suggest,none,
699+
WARNING(selector_literal_deprecated_suggest,Deprecation,
700700
"use of string literal for Objective-C selectors is deprecated; "
701701
"use '#selector' instead", ())
702702
WARNING(selector_construction_suggest,none,
@@ -831,7 +831,7 @@ ERROR(invalid_redecl_implicit,none,
831831
"invalid redeclaration of synthesized "
832832
"%select{%0|implementation for protocol requirement}1 %2",
833833
(DescriptiveDeclKind, bool, DeclName))
834-
WARNING(invalid_redecl_swift5_warning,none,
834+
WARNING(invalid_redecl_swift5_warning,Deprecation,
835835
"redeclaration of %0 is deprecated and will be an error in Swift 5",
836836
(DeclName))
837837

@@ -1274,7 +1274,7 @@ ERROR(extra_trailing_closure_in_call,none,
12741274
ERROR(trailing_closure_bad_param,none,
12751275
"trailing closure passed to parameter of type %0 that does not "
12761276
"accept a closure", (Type))
1277-
WARNING(unlabeled_trailing_closure_deprecated,none,
1277+
WARNING(unlabeled_trailing_closure_deprecated,Deprecation,
12781278
"backward matching of the unlabeled trailing closure is deprecated; label the argument with %0 to suppress this warning",
12791279
(Identifier))
12801280
NOTE(decl_multiple_defaulted_closure_parameters,none,
@@ -1554,7 +1554,7 @@ ERROR(missing_unimplemented_init_runtime,none,
15541554
ERROR(missing_undefined_runtime,none,
15551555
"standard library error: missing _undefined", ())
15561556

1557-
WARNING(expr_dynamic_lookup_swift3_objc_inference,none,
1557+
WARNING(expr_dynamic_lookup_swift3_objc_inference,Deprecation,
15581558
"reference to %0 %1 of %2 depends on '@objc' inference "
15591559
"deprecated in Swift 4",
15601560
(DescriptiveDeclKind, DeclName, Identifier))
@@ -2679,7 +2679,7 @@ WARNING(implicitly_final_cannot_be_open_swift4,none,
26792679
"static declarations}0 are implicitly 'final'; use 'public' instead of "
26802680
"'open'", (unsigned))
26812681

2682-
WARNING(override_swift3_objc_inference,none,
2682+
WARNING(override_swift3_objc_inference,Deprecation,
26832683
"override of %0 %1 from extension of %2 depends on deprecated "
26842684
"inference of '@objc'",
26852685
(DescriptiveDeclKind, DeclName, Identifier))
@@ -2695,7 +2695,7 @@ WARNING(duplicate_anyobject_class_inheritance,none,
26952695
"redundant inheritance from 'AnyObject' and Swift 3 'class' keyword", ())
26962696
ERROR(inheritance_from_protocol_with_superclass,none,
26972697
"inheritance from class-constrained protocol composition type %0", (Type))
2698-
WARNING(anyobject_class_inheritance_deprecated,none,
2698+
WARNING(anyobject_class_inheritance_deprecated,Deprecation,
26992699
"using 'class' keyword to define a class-constrained protocol is deprecated; "
27002700
"use 'AnyObject' instead", ())
27012701
ERROR(multiple_inheritance,none,
@@ -3760,7 +3760,7 @@ NOTE(fix_unqualified_access_top_level_multi,none,
37603760
"use '%0' to reference the %1 in module %2",
37613761
(StringRef, DescriptiveDeclKind, Identifier))
37623762

3763-
WARNING(warn_deprecated_conditional_conformance_outer_access,none,
3763+
WARNING(warn_deprecated_conditional_conformance_outer_access,Deprecation,
37643764
"use of %0 as reference to %1 in %2 %3 will change in future versions of Swift to reference %4 in %5 %6 "
37653765
"which comes via a conditional conformance",
37663766
(DeclNameRef, DescriptiveDeclKind, DescriptiveDeclKind, DeclName,
@@ -3936,32 +3936,32 @@ WARNING(guard_always_succeeds,none,
39363936
"'guard' condition is always true, body is unreachable", ())
39373937

39383938

3939-
ERROR(expression_unused_closure,none,
3939+
ERROR(expression_unused_closure,NoUsage,
39403940
"closure expression is unused", ())
3941-
ERROR(expression_unused_function,none,
3941+
ERROR(expression_unused_function,NoUsage,
39423942
"function is unused", ())
3943-
WARNING(expression_unused_lvalue,none,
3943+
WARNING(expression_unused_lvalue,NoUsage,
39443944
"%select{"
39453945
"variable|"
39463946
"property is accessed but result|"
39473947
"subscript is accessed but result"
39483948
"}0 is unused",
39493949
(unsigned))
3950-
WARNING(expression_unused_result_call,none,
3950+
WARNING(expression_unused_result_call,NoUsage,
39513951
"result of call to %0 is unused", (DeclName))
3952-
WARNING(expression_unused_result_operator,none,
3952+
WARNING(expression_unused_result_operator,NoUsage,
39533953
"result of operator %0 is unused", (DeclName))
3954-
WARNING(expression_unused_result_unknown, none,
3954+
WARNING(expression_unused_result_unknown, NoUsage,
39553955
"result of call to %select{function|closure}0 returning %1 is unused", (bool, Type))
3956-
WARNING(expression_unused_result, none,
3956+
WARNING(expression_unused_result, NoUsage,
39573957
"expression of type %0 is unused", (Type))
3958-
WARNING(expression_unused_init_result,none,
3958+
WARNING(expression_unused_init_result,NoUsage,
39593959
"result of %0 initializer is unused", (Type))
3960-
WARNING(expression_unused_optional_try,none,
3960+
WARNING(expression_unused_optional_try,NoUsage,
39613961
"result of 'try?' is unused", ())
3962-
WARNING(expression_unused_selector_result, none,
3962+
WARNING(expression_unused_selector_result, NoUsage,
39633963
"result of '#selector' is unused", ())
3964-
WARNING(expression_unused_literal,none,
3964+
WARNING(expression_unused_literal,NoUsage,
39653965
"%0 literal is unused", (StringRef))
39663966

39673967
ERROR(assignment_lhs_not_lvalue,none,
@@ -4105,7 +4105,7 @@ ERROR(pattern_type_mismatch_context,none,
41054105

41064106
ERROR(tuple_pattern_in_non_tuple_context,none,
41074107
"tuple pattern cannot match values of the non-tuple type %0", (Type))
4108-
WARNING(found_one_pattern_for_several_associated_values,none,
4108+
WARNING(found_one_pattern_for_several_associated_values,Deprecation,
41094109
"enum case '%0' has %1 associated values; matching them as a tuple "
41104110
"is deprecated", (StringRef, unsigned))
41114111
WARNING(converting_tuple_into_several_associated_values,none,
@@ -4629,7 +4629,7 @@ ERROR(enum_element_ellipsis,none,
46294629
WARNING(implicitly_unwrapped_optional_in_illegal_position_interpreted_as_optional,none,
46304630
"using '!' is not allowed here; treating this as '?' instead", ())
46314631

4632-
WARNING(implicitly_unwrapped_optional_deprecated_in_this_position,none,
4632+
WARNING(implicitly_unwrapped_optional_deprecated_in_this_position,Deprecation,
46334633
"using '!' here is deprecated and will be removed in a future release", ())
46344634

46354635
ERROR(implicitly_unwrapped_optional_in_illegal_position,none,
@@ -4693,7 +4693,7 @@ ERROR(attribute_requires_function_type,none,
46934693
"@%0 attribute only applies to function types", (StringRef))
46944694
ERROR(unsupported_convention,none,
46954695
"convention '%0' not supported", (StringRef))
4696-
ERROR(unreferenced_generic_parameter,none,
4696+
ERROR(unreferenced_generic_parameter,NoUsage,
46974697
"generic parameter '%0' is not used in function signature", (StringRef))
46984698
ERROR(unexpected_ctype_for_non_c_convention,none,
46994699
"convention '%0' does not support the 'cType' argument label, did you "
@@ -4808,9 +4808,9 @@ ERROR(objc_operator, none,
48084808
"operator methods cannot be declared @objc", ())
48094809
ERROR(objc_operator_proto, none,
48104810
"@objc protocols must not have operator requirements", ())
4811-
WARNING(objc_inference_swift3_dynamic,none,
4811+
WARNING(objc_inference_swift3_dynamic,Deprecation,
48124812
"inference of '@objc' for 'dynamic' members is deprecated", ())
4813-
WARNING(objc_inference_swift3_objc_derived,none,
4813+
WARNING(objc_inference_swift3_objc_derived,Deprecation,
48144814
"inference of '@objc' for members of Objective-C-derived classes is "
48154815
"deprecated", ())
48164816

@@ -4835,7 +4835,7 @@ ERROR(objc_setter_for_nonobjc_property,none,
48354835
"'@objc' setter for non-'@objc' property", ())
48364836
ERROR(objc_setter_for_nonobjc_subscript,none,
48374837
"'@objc' setter for non-'@objc' subscript", ())
4838-
WARNING(accessor_swift3_objc_inference,none,
4838+
WARNING(accessor_swift3_objc_inference,Deprecation,
48394839
"%select{%0 %1|%1}2 with '@objc' %select{getter|setter}3 depends on "
48404840
"deprecated inference of '@objc'",
48414841
(DescriptiveDeclKind, DeclName, bool, bool))
@@ -4930,7 +4930,7 @@ NOTE(objc_overriding_objc_decl,none,
49304930
NOTE(objc_witness_objc_requirement,none,
49314931
"satisfying requirement for %0 %1 in protocol %2",
49324932
(DescriptiveDeclKind, DeclName, Identifier))
4933-
WARNING(witness_swift3_objc_inference,none,
4933+
WARNING(witness_swift3_objc_inference,Deprecation,
49344934
"use of %0 %1 to satisfy a requirement of protocol %2 depends on "
49354935
"'@objc' inference deprecated in Swift 4",
49364936
(DescriptiveDeclKind, DeclName, Type))
@@ -5212,13 +5212,13 @@ NOTE(availability_obsoleted, none,
52125212
"%select{getter for |setter for |}0%1 was obsoleted in %2 %3",
52135213
(unsigned, DeclName, StringRef, llvm::VersionTuple))
52145214

5215-
WARNING(availability_deprecated, none,
5215+
WARNING(availability_deprecated, Deprecation,
52165216
"%select{getter for |setter for |}0%1 %select{is|%select{is|was}4}2 "
52175217
"deprecated%select{| in %3%select{| %5}4}2%select{|: %6}6",
52185218
(unsigned, DeclName, bool, StringRef, bool, llvm::VersionTuple,
52195219
StringRef))
52205220

5221-
WARNING(availability_deprecated_rename, none,
5221+
WARNING(availability_deprecated_rename, Deprecation,
52225222
"%select{getter for |setter for |}0%1 %select{is|%select{is|was}4}2 "
52235223
"deprecated%select{| in %3%select{| %5}4}2: "
52245224
"%select{renamed to|replaced by}6%" REPLACEMENT_DECL_KIND_SELECT "7 "
@@ -5330,7 +5330,7 @@ NOTE(conformance_availability_obsoleted, none,
53305330
"conformance of %0 to %1 was obsoleted in %2 %3",
53315331
(Type, Type, StringRef, llvm::VersionTuple))
53325332

5333-
WARNING(conformance_availability_deprecated, none,
5333+
WARNING(conformance_availability_deprecated, Deprecation,
53345334
"conformance of %0 to %1 %select{is|%select{is|was}4}2 "
53355335
"deprecated%select{| in %3%select{| %5}4}2%select{|: %6}6",
53365336
(Type, Type, bool, StringRef, bool, llvm::VersionTuple,
@@ -5476,31 +5476,31 @@ NOTE(specialize_found_function_of_type, none,
54765476
// MARK: Variable usage diagnostics
54775477
//------------------------------------------------------------------------------
54785478

5479-
WARNING(pbd_never_used_stmtcond, none,
5479+
WARNING(pbd_never_used_stmtcond, NoUsage,
54805480
"value %0 was defined but never used; consider replacing "
54815481
"with boolean test",
54825482
(Identifier))
5483-
WARNING(unused_setter_parameter, none,
5483+
WARNING(unused_setter_parameter, NoUsage,
54845484
"setter argument %0 was never used, but the property was accessed",
54855485
(Identifier))
54865486
NOTE(fixit_for_unused_setter_parameter, none,
54875487
"did you mean to use %0 instead of accessing the property's current value?", (Identifier))
54885488

5489-
WARNING(pbd_never_used, none,
5489+
WARNING(pbd_never_used, NoUsage,
54905490
"initialization of %select{variable|immutable value}1 %0 was never used"
54915491
"; consider replacing with assignment to '_' or removing it",
54925492
(Identifier, unsigned))
54935493

54945494

5495-
WARNING(capture_never_used, none,
5495+
WARNING(capture_never_used, NoUsage,
54965496
"capture %0 was never used",
54975497
(Identifier))
54985498

5499-
WARNING(variable_never_used, none,
5499+
WARNING(variable_never_used, NoUsage,
55005500
"%select{variable|immutable value}1 %0 was never used; "
55015501
"consider replacing with '_' or removing it",
55025502
(Identifier, unsigned))
5503-
WARNING(immutable_value_never_used_but_assigned, none,
5503+
WARNING(immutable_value_never_used_but_assigned, NoUsage,
55045504
"immutable value %0 was never used; consider removing it",
55055505
(Identifier))
55065506
WARNING(variable_never_mutated, none,
@@ -5585,7 +5585,7 @@ ERROR(override_nsobject_hash_error,none,
55855585
"'NSObject.hash(into:)' is not overridable; "
55865586
"did you mean to override 'NSObject.hash'?", ())
55875587

5588-
WARNING(hashvalue_implementation,none,
5588+
WARNING(hashvalue_implementation,Deprecation,
55895589
"'Hashable.hashValue' is deprecated as a protocol requirement; "
55905590
"conform type %0 to 'Hashable' by implementing 'hash(into:)' instead",
55915591
(Type))
@@ -5705,10 +5705,10 @@ ERROR(property_wrapper_type_not_usable_from_inline,none,
57055705
"%select{%select{variable|constant}0|property}1 "
57065706
"must be '@usableFromInline' or public",
57075707
(bool, bool))
5708-
WARNING(property_wrapper_wrapperValue,none,
5708+
WARNING(property_wrapper_wrapperValue,Deprecation,
57095709
"property wrapper's 'wrapperValue' property should be renamed to "
57105710
"'projectedValue'; use of 'wrapperValue' is deprecated", ())
5711-
WARNING(property_wrapper_init_initialValue,none,
5711+
WARNING(property_wrapper_init_initialValue,Deprecation,
57125712
"property wrapper's 'init(initialValue:)' should be renamed "
57135713
"to 'init(wrappedValue:)'; use of 'init(initialValue:)' is deprecated",
57145714
())
@@ -5805,7 +5805,7 @@ NOTE(result_builder_missing_build_limited_availability, none,
58055805
// MARK: Tuple Shuffle Diagnostics
58065806
//------------------------------------------------------------------------------
58075807

5808-
WARNING(warn_reordering_tuple_shuffle_deprecated,none,
5808+
WARNING(warn_reordering_tuple_shuffle_deprecated,Deprecation,
58095809
"expression shuffles the elements of this tuple; "
58105810
"this behavior is deprecated", ())
58115811

0 commit comments

Comments
 (0)