Skip to content

Commit

Permalink
[Sema] Add miscellaneous sema diagnostics to check that the new os log
Browse files Browse the repository at this point in the history
APIs and atomic operations are passed compile-time constants for
certain arguments.
  • Loading branch information
ravikandhadai committed Mar 31, 2020
1 parent 95f0651 commit a822d80
Show file tree
Hide file tree
Showing 16 changed files with 832 additions and 50 deletions.
23 changes: 23 additions & 0 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -5023,6 +5023,29 @@ ERROR(experimental_differentiable_programming_disabled, none,
"differentiable programming is an experimental feature that is "
"currently disabled", ())

ERROR(oslog_arg_must_be_bool_literal, none,
"argument must be a bool literal", ())
ERROR(oslog_arg_must_be_integer_literal, none,
"argument must be an integer literal", ())
ERROR(oslog_arg_must_be_string_literal, none,
"argument must be a string literal", ())
ERROR(oslog_arg_must_be_float_literal, none,
"argument must be a floating-point literal", ())
ERROR(oslog_arg_must_be_metatype_literal, none,
"argument must be a <Type>.self", ())
ERROR(oslog_arg_must_be_closure, none, "argument must be a closure", ())
ERROR(argument_must_be_constant, none,
"argument must be an expression with only literals", ())
ERROR(oslog_message_must_be_string_interpolation, none,
"argument must be a string interpolation", ())
ERROR(oslog_arg_must_be_enum_case, none,
"argument must be a case of enum %0", (Identifier))
ERROR(oslog_arg_must_be_type_member_access, none,
"argument must be a static method or property of %0", (Identifier))
ERROR(atomics_ordering_must_be_constant, none,
"ordering argument must be a static method or property of %0",
(Identifier))

#ifndef DIAG_NO_UNDEF
# if defined(DIAG)
# undef DIAG
Expand Down
5 changes: 5 additions & 0 deletions include/swift/AST/KnownIdentifiers.def
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ IDENTIFIER_(nsError)
// Custom string interpolation type used by os log APIs.
IDENTIFIER(OSLogMessage)

// Atomics ordering type identifiers.
IDENTIFIER(AtomicLoadOrdering)
IDENTIFIER(AtomicStoreOrdering)
IDENTIFIER(AtomicUpdateOrdering)

// Differentiable programming
IDENTIFIER(along)
IDENTIFIER(differential)
Expand Down
3 changes: 2 additions & 1 deletion include/swift/AST/SemanticAttrs.def
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ SEMANTICS_ATTR(OPTIMIZE_SIL_SPECIALIZE_GENERIC_PARTIAL_NEVER,
SEMANTICS_ATTR(OPTIMIZE_SIL_SPECIALIZE_GENERIC_SIZE_NEVER,
"optimize.sil.specialize.generic.size.never")

SEMANTICS_ATTR(OSLOG_INTERPOLATION_INIT, "oslog.interpolation.init")
SEMANTICS_ATTR(OSLOG_MESSAGE_INIT_INTERPOLATION, "oslog.message.init_interpolation")
SEMANTICS_ATTR(OSLOG_MESSAGE_INIT_STRING_LITERAL, "oslog.message.init_stringliteral")
SEMANTICS_ATTR(OSLOG_REQUIRES_CONSTANT_ARGUMENTS, "oslog.requires_constant_arguments")
SEMANTICS_ATTR(ATOMICS_REQUIRES_CONSTANT_ORDERINGS, "atomics.requires_constant_orderings")

SEMANTICS_ATTR(TYPE_CHECKER_OPEN_EXISTENTIAL, "typechecker._openExistential(_:do:)")
SEMANTICS_ATTR(TYPE_CHECKER_TYPE, "typechecker.type(of:)")
Expand Down
1 change: 1 addition & 0 deletions lib/Sema/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ add_swift_host_library(swiftSema STATIC
CSFix.cpp
CSDiagnostics.cpp
CodeSynthesis.cpp
ConstantnessSemaDiagnostics.cpp
Constraint.cpp
ConstraintGraph.cpp
ConstraintLocator.cpp
Expand Down
Loading

0 comments on commit a822d80

Please sign in to comment.