Skip to content

Commit a822d80

Browse files
committed
[Sema] Add miscellaneous sema diagnostics to check that the new os log
APIs and atomic operations are passed compile-time constants for certain arguments.
1 parent 95f0651 commit a822d80

16 files changed

+832
-50
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5023,6 +5023,29 @@ ERROR(experimental_differentiable_programming_disabled, none,
50235023
"differentiable programming is an experimental feature that is "
50245024
"currently disabled", ())
50255025

5026+
ERROR(oslog_arg_must_be_bool_literal, none,
5027+
"argument must be a bool literal", ())
5028+
ERROR(oslog_arg_must_be_integer_literal, none,
5029+
"argument must be an integer literal", ())
5030+
ERROR(oslog_arg_must_be_string_literal, none,
5031+
"argument must be a string literal", ())
5032+
ERROR(oslog_arg_must_be_float_literal, none,
5033+
"argument must be a floating-point literal", ())
5034+
ERROR(oslog_arg_must_be_metatype_literal, none,
5035+
"argument must be a <Type>.self", ())
5036+
ERROR(oslog_arg_must_be_closure, none, "argument must be a closure", ())
5037+
ERROR(argument_must_be_constant, none,
5038+
"argument must be an expression with only literals", ())
5039+
ERROR(oslog_message_must_be_string_interpolation, none,
5040+
"argument must be a string interpolation", ())
5041+
ERROR(oslog_arg_must_be_enum_case, none,
5042+
"argument must be a case of enum %0", (Identifier))
5043+
ERROR(oslog_arg_must_be_type_member_access, none,
5044+
"argument must be a static method or property of %0", (Identifier))
5045+
ERROR(atomics_ordering_must_be_constant, none,
5046+
"ordering argument must be a static method or property of %0",
5047+
(Identifier))
5048+
50265049
#ifndef DIAG_NO_UNDEF
50275050
# if defined(DIAG)
50285051
# undef DIAG

include/swift/AST/KnownIdentifiers.def

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,11 @@ IDENTIFIER_(nsError)
203203
// Custom string interpolation type used by os log APIs.
204204
IDENTIFIER(OSLogMessage)
205205

206+
// Atomics ordering type identifiers.
207+
IDENTIFIER(AtomicLoadOrdering)
208+
IDENTIFIER(AtomicStoreOrdering)
209+
IDENTIFIER(AtomicUpdateOrdering)
210+
206211
// Differentiable programming
207212
IDENTIFIER(along)
208213
IDENTIFIER(differential)

include/swift/AST/SemanticAttrs.def

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,10 @@ SEMANTICS_ATTR(OPTIMIZE_SIL_SPECIALIZE_GENERIC_PARTIAL_NEVER,
6868
SEMANTICS_ATTR(OPTIMIZE_SIL_SPECIALIZE_GENERIC_SIZE_NEVER,
6969
"optimize.sil.specialize.generic.size.never")
7070

71-
SEMANTICS_ATTR(OSLOG_INTERPOLATION_INIT, "oslog.interpolation.init")
7271
SEMANTICS_ATTR(OSLOG_MESSAGE_INIT_INTERPOLATION, "oslog.message.init_interpolation")
7372
SEMANTICS_ATTR(OSLOG_MESSAGE_INIT_STRING_LITERAL, "oslog.message.init_stringliteral")
73+
SEMANTICS_ATTR(OSLOG_REQUIRES_CONSTANT_ARGUMENTS, "oslog.requires_constant_arguments")
74+
SEMANTICS_ATTR(ATOMICS_REQUIRES_CONSTANT_ORDERINGS, "atomics.requires_constant_orderings")
7475

7576
SEMANTICS_ATTR(TYPE_CHECKER_OPEN_EXISTENTIAL, "typechecker._openExistential(_:do:)")
7677
SEMANTICS_ATTR(TYPE_CHECKER_TYPE, "typechecker.type(of:)")

lib/Sema/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ add_swift_host_library(swiftSema STATIC
1010
CSFix.cpp
1111
CSDiagnostics.cpp
1212
CodeSynthesis.cpp
13+
ConstantnessSemaDiagnostics.cpp
1314
Constraint.cpp
1415
ConstraintGraph.cpp
1516
ConstraintLocator.cpp

0 commit comments

Comments
 (0)