Skip to content

Commit b57a1d7

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 fccfa29 commit b57a1d7

16 files changed

+872
-50
lines changed

include/swift/AST/DiagnosticsSema.def

+23
Original file line numberDiff line numberDiff line change
@@ -5031,6 +5031,29 @@ ERROR(differentiable_programming_attr_used_without_required_module, none,
50315031
"'@%0' attribute used without importing module %1",
50325032
(StringRef, Identifier))
50335033

5034+
ERROR(oslog_arg_must_be_bool_literal, none,
5035+
"argument must be a bool literal", ())
5036+
ERROR(oslog_arg_must_be_integer_literal, none,
5037+
"argument must be an integer literal", ())
5038+
ERROR(oslog_arg_must_be_string_literal, none,
5039+
"argument must be a string literal", ())
5040+
ERROR(oslog_arg_must_be_float_literal, none,
5041+
"argument must be a floating-point literal", ())
5042+
ERROR(oslog_arg_must_be_metatype_literal, none,
5043+
"argument must be a <Type>.self", ())
5044+
ERROR(oslog_arg_must_be_closure, none, "argument must be a closure", ())
5045+
ERROR(argument_must_be_constant, none,
5046+
"argument must be an expression with only literals", ())
5047+
ERROR(oslog_message_must_be_string_interpolation, none,
5048+
"argument must be a string interpolation", ())
5049+
ERROR(oslog_arg_must_be_enum_case, none,
5050+
"argument must be a case of enum %0", (Identifier))
5051+
ERROR(oslog_arg_must_be_type_member_access, none,
5052+
"argument must be a static method or property of %0", (Identifier))
5053+
ERROR(atomics_ordering_must_be_constant, none,
5054+
"ordering argument must be a static method or property of %0",
5055+
(Identifier))
5056+
50345057
#ifndef DIAG_NO_UNDEF
50355058
# if defined(DIAG)
50365059
# undef DIAG

include/swift/AST/KnownIdentifiers.def

+5
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

+2-1
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

+1
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)