Skip to content

Commit 3d19f16

Browse files
committed
Type check @abi decls (sans attrs)
This commit compares the decl inside the `@abi` attribute to the decl it’s attached to, diagnosing ABI-incompatible differences. It does not yet cover attributes, which are a large undertaking.
1 parent e6af80c commit 3d19f16

File tree

5 files changed

+1669
-110
lines changed

5 files changed

+1669
-110
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8291,16 +8291,16 @@ ERROR(attr_abi_mismatched_kind,none,
82918291

82928292
ERROR(attr_abi_mismatched_arity,none,
82938293
"cannot give %kind0 the ABI of a %kindonly0 with a different number of "
8294-
"low-level parameters",
8295-
(ValueDecl *))
8294+
"%select{|generic }1parameters",
8295+
(Decl *, /*genericParams=*/bool))
82968296

82978297
ERROR(attr_abi_mismatched_throws,none,
82988298
"cannot give %0 the ABI of a %kindonly0 which %select{cannot|can}1 throw",
8299-
(ValueDecl *, /*abiCanThrow=*/bool))
8299+
(Decl *, /*abiCanThrow=*/bool))
83008300

83018301
ERROR(attr_abi_mismatched_async,none,
83028302
"cannot give %0 the ABI of %select{a non-async|an async}1 %kindonly0",
8303-
(ValueDecl *, /*abiIsAsync=*/bool))
8303+
(Decl *, /*abiIsAsync=*/bool))
83048304

83058305
ERROR(attr_abi_mismatched_pbd_size,none,
83068306
"cannot give pattern binding the ABI of a binding with "
@@ -8309,13 +8309,65 @@ ERROR(attr_abi_mismatched_pbd_size,none,
83098309

83108310
ERROR(attr_abi_mismatched_var,none,
83118311
"no match for %select{%kind0 in the ABI|ABI %kind0}1",
8312-
(ValueDecl *, /*isABI=*/bool))
8312+
(Decl *, /*isABI=*/bool))
83138313

83148314
ERROR(attr_abi_incompatible_with_silgen_name,none,
83158315
"cannot use '@_silgen_name' and '@abi' on the same %0 because they serve "
83168316
"the same purpose",
83178317
(DescriptiveDeclKind))
83188318

8319+
ERROR(attr_abi_mismatched_type,none,
8320+
"type %0 in '@abi' should match %1",
8321+
(Type, Type))
8322+
NOTE(attr_abi_should_match_type_here,none,
8323+
"should match type here", ())
8324+
8325+
ERROR(attr_abi_mismatched_generic_signature,none,
8326+
"generic signature '%0' in '@abi' is not compatible with '%1'",
8327+
(StringRef, StringRef))
8328+
ERROR(attr_abi_missing_generic_signature,none,
8329+
"declaration in '@abi' should have generic signature compatible with "
8330+
"'%0'",
8331+
(StringRef))
8332+
ERROR(attr_abi_extra_generic_signature,none,
8333+
"declaration in '@abi' should not have generic signature because %0 "
8334+
"is not generic",
8335+
(Decl *))
8336+
8337+
ERROR(attr_abi_mismatched_param_modifier,none,
8338+
"%select{default |}0%3 %select{attribute|modifier}2 "
8339+
"%select{|'%0' }0in '@abi' is not compatible with %select{default|'%1'}1",
8340+
(StringRef, StringRef, /*isModifier=*/bool, DescriptiveDeclKind))
8341+
ERROR(attr_abi_no_default_arguments,none,
8342+
"%kind0 in '@abi' should not have a default argument; it does not "
8343+
"affect the parameter's ABI",
8344+
(Decl *))
8345+
8346+
// These macros insert 'final', 'non-final', or nothing depending on both the
8347+
// current decl and its counterpart, such that 'non-final' is used if the
8348+
// counterpart would be described as 'final' or 'static'. They must be kept in
8349+
// sync with `StaticnessAndFinality`.
8350+
#define NONFINAL_OR_NOTHING(COUNTERPART) \
8351+
"%select{||non-final |non-final |non-final |%error}" #COUNTERPART
8352+
#define FINAL_OR_NONFINAL_OR_NOTHING(CURRENT, COUNTERPART, FINAL_OK) \
8353+
"%select{|%select{" NONFINAL_OR_NOTHING(COUNTERPART) \
8354+
"|" NONFINAL_OR_NOTHING(COUNTERPART) \
8355+
"|final |final ||%error}" #CURRENT "}" #FINAL_OK
8356+
8357+
ERROR(attr_abi_static_final_mismatch,none,
8358+
FINAL_OR_NONFINAL_OR_NOTHING(0, 2, 4) "%kind1 in '@abi' should be "
8359+
FINAL_OR_NONFINAL_OR_NOTHING(2, 0, 4) "%kindonly3 to ensure ABI "
8360+
"compatibility",
8361+
(uint8_t, Decl *, uint8_t, Decl *, /*isClass=*/bool))
8362+
8363+
#undef NONFINAL_OR_NOTHING
8364+
#undef FINAL_OR_NONFINAL_OR_NOTHING
8365+
8366+
ERROR(attr_abi_failable_mismatch,none,
8367+
"cannot give %select{non-failable|failable}1 %kind0 the ABI of a "
8368+
"%select{non-failable|failable}2 %kindonly0",
8369+
(Decl *, bool, bool))
8370+
83198371
//===----------------------------------------------------------------------===//
83208372
// MARK: Isolated conformances
83218373
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)