NFC: Fix duplicate definition of macro warnings.

Centralize the `SWIFT_{BEGIN/END}_NULLABILITY_ANNOTATIONS` definitions in a new
Nullability.h header to share.
This commit is contained in:
Allan Shortlidge
2023-07-27 11:40:25 -07:00
parent 874b318e3f
commit f9a93a55d7
11 changed files with 75 additions and 74 deletions

View File

@@ -13,9 +13,10 @@
#ifndef SWIFT_AST_ASTBRIDGING_H
#define SWIFT_AST_ASTBRIDGING_H
#include "swift/AST/DiagnosticEngine.h"
#include "swift/Basic/BasicBridging.h"
#include "swift/Basic/Compiler.h"
#include "swift/AST/DiagnosticEngine.h"
#include "swift/Basic/Nullability.h"
#include <stdbool.h>
#include <stddef.h>

View File

@@ -1,4 +1,4 @@
//===--- ASTBridging.h - header for the swift SILBridging module ----------===//
//===--- CASTBridging.h - header for the swift SILBridging module ---------===//
//
// This source file is part of the Swift.org open source project
//
@@ -15,29 +15,15 @@
#include "swift/Basic/CBasicBridging.h"
#include "swift/Basic/Compiler.h"
#include "swift/Basic/Nullability.h"
// NOTE: DO NOT #include any stdlib headers here. e.g. <stdint.h>. Those are
// part of "Darwin"/"Glibc" module, so when a Swift file imports this header,
// it causes importing the "Darwin"/"Glibc" overlay module. That violates
// layering. i.e. Darwin overlay is created by Swift compiler.
#if __clang__
// Provide macros to temporarily suppress warning about the use of
// _Nullable and _Nonnull.
#define SWIFT_BEGIN_NULLABILITY_ANNOTATIONS \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wnullability-extension\"") \
_Pragma("clang assume_nonnull begin")
#define SWIFT_END_NULLABILITY_ANNOTATIONS \
_Pragma("clang diagnostic pop") _Pragma("clang assume_nonnull end")
#else
#define SWIFT_BEGIN_NULLABILITY_ANNOTATIONS
#define SWIFT_END_NULLABILITY_ANNOTATIONS
#define _Nullable
#endif
SWIFT_BEGIN_NULLABILITY_ANNOTATIONS
SWIFT_BEGIN_ASSUME_NONNULL
typedef long SwiftInt;
typedef unsigned long SwiftUInt;
@@ -486,9 +472,7 @@ _Bool Plugin_waitForNextMessage(PluginHandle handle, BridgedData *data);
}
#endif
SWIFT_END_ASSUME_NONNULL
SWIFT_END_NULLABILITY_ANNOTATIONS
#undef SWIFT_BEGIN_NULLABILITY_ANNOTATIONS
#undef SWIFT_END_NULLABILITY_ANNOTATIONS
#endif // SWIFT_C_AST_ASTBRIDGING_H

View File

@@ -19,6 +19,7 @@
#include "llvm/CAS/CASReference.h"
#include "swift/Basic/BridgedSwiftObject.h"
#include "swift/Basic/Nullability.h"
#include "swift/Basic/SourceLoc.h"
#include <stddef.h>

View File

@@ -18,6 +18,8 @@
#ifndef SWIFT_BASIC_BRIDGEDSWIFTOBJECT_H
#define SWIFT_BASIC_BRIDGEDSWIFTOBJECT_H
#include "swift/Basic/Nullability.h"
#if defined(__OpenBSD__)
#include <sys/stdint.h>
#else
@@ -28,28 +30,6 @@
#define __has_feature(feature) 0
#endif
// TODO: These macro definitions are duplicated in Visibility.h. Move
// them to a single file if we find a location that both Visibility.h and
// BridgedSwiftObject.h can import.
#if __has_feature(nullability)
// Provide macros to temporarily suppress warning about the use of
// _Nullable and _Nonnull.
#define SWIFT_BEGIN_NULLABILITY_ANNOTATIONS \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wnullability-extension\"")
#define SWIFT_END_NULLABILITY_ANNOTATIONS \
_Pragma("clang diagnostic pop")
#else
// #define _Nullable and _Nonnull to nothing if we're not being built
// with a compiler that supports them.
#define _Nullable
#define _Nonnull
#define _Null_unspecified
#define SWIFT_BEGIN_NULLABILITY_ANNOTATIONS
#define SWIFT_END_NULLABILITY_ANNOTATIONS
#endif
SWIFT_BEGIN_NULLABILITY_ANNOTATIONS
typedef const void * _Nonnull SwiftMetatype;

View File

@@ -14,30 +14,15 @@
#define SWIFT_C_BASIC_BASICBRIDGING_H
#include "swift/Basic/Compiler.h"
#include "swift/Basic/Nullability.h"
// NOTE: DO NOT #include any stdlib headers here. e.g. <stdint.h>. Those are
// part of "Darwin"/"Glibc" module, so when a Swift file imports this header,
// it causes importing the "Darwin"/"Glibc" overlay module. That violates
// layering. i.e. Darwin overlay is created by Swift compiler.
#if __clang__
// Provide macros to temporarily suppress warning about the use of
// _Nullable and _Nonnull.
#define SWIFT_BEGIN_NULLABILITY_ANNOTATIONS \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wnullability-extension\"") \
_Pragma("clang assume_nonnull begin")
#define SWIFT_END_NULLABILITY_ANNOTATIONS \
_Pragma("clang diagnostic pop") _Pragma("clang assume_nonnull end")
#else
#define SWIFT_BEGIN_NULLABILITY_ANNOTATIONS
#define SWIFT_END_NULLABILITY_ANNOTATIONS
#define _Nullable
#define _Nonnull
#endif
SWIFT_BEGIN_NULLABILITY_ANNOTATIONS
SWIFT_BEGIN_ASSUME_NONNULL
#ifdef __cplusplus
extern "C" {
@@ -119,9 +104,7 @@ void *JSON_array_pushNewValue(void *arrayPtr);
}
#endif
SWIFT_END_ASSUME_NONNULL
SWIFT_END_NULLABILITY_ANNOTATIONS
#undef SWIFT_BEGIN_NULLABILITY_ANNOTATIONS
#undef SWIFT_END_NULLABILITY_ANNOTATIONS
#endif // SWIFT_C_BASIC_BASICBRIDGING_H

View File

@@ -0,0 +1,41 @@
//===--- Nullability.h ----------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2023 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
#ifndef SWIFT_BASIC_NULLABILITY_H
#define SWIFT_BASIC_NULLABILITY_H
// TODO: These macro definitions are duplicated in Visibility.h. Move
// them to a single file if we find a location that both Visibility.h and
// BridgedSwiftObject.h can import.
#if __has_feature(nullability)
// Provide macros to temporarily suppress warning about the use of
// _Nullable and _Nonnull.
#define SWIFT_BEGIN_NULLABILITY_ANNOTATIONS \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wnullability-extension\"")
#define SWIFT_END_NULLABILITY_ANNOTATIONS _Pragma("clang diagnostic pop")
#define SWIFT_BEGIN_ASSUME_NONNULL _Pragma("clang assume_nonnull begin")
#define SWIFT_END_ASSUME_NONNULL _Pragma("clang assume_nonnull end")
#else
// #define _Nullable and _Nonnull to nothing if we're not being built
// with a compiler that supports them.
#define _Nullable
#define _Nonnull
#define _Null_unspecified
#define SWIFT_BEGIN_NULLABILITY_ANNOTATIONS
#define SWIFT_END_NULLABILITY_ANNOTATIONS
#define SWIFT_BEGIN_ASSUME_NONNULL
#define SWIFT_END_ASSUME_NONNULL
#endif
#endif

View File

@@ -20,7 +20,6 @@
#define SWIFT_DEMANGLING_ERRORS_H
#include "swift/Demangling/NamespaceMacros.h"
#include "swift/shims/Visibility.h"
#include <inttypes.h>
#include <stdarg.h>
@@ -44,6 +43,14 @@
#endif
#endif
#ifndef SWIFT_NORETURN
#if __has_attribute(noreturn)
#define SWIFT_NORETURN __attribute__((__noreturn__))
#else
#define SWIFT_NORETURN
#endif
#endif
namespace swift {
namespace Demangle {
SWIFT_BEGIN_INLINE_NAMESPACE

View File

@@ -15,6 +15,7 @@
#define REGEX_PARSER_BRIDGING
#include "swift/AST/ASTBridging.h"
#include "swift/Basic/Nullability.h"
#include <stdbool.h>
/// Attempt to lex a regex literal string. Takes the following arguments:

View File

@@ -13,20 +13,21 @@
#ifndef SWIFT_SIL_SILBRIDGING_H
#define SWIFT_SIL_SILBRIDGING_H
#include "swift/Basic/BasicBridging.h"
#include "swift/Basic/BridgedSwiftObject.h"
#include "swift/AST/Builtins.h"
#include "swift/AST/Decl.h"
#include "swift/AST/SubstitutionMap.h"
#include "swift/SIL/SILInstruction.h"
#include "swift/Basic/BasicBridging.h"
#include "swift/Basic/BridgedSwiftObject.h"
#include "swift/Basic/Nullability.h"
#include "swift/SIL/ApplySite.h"
#include "swift/SIL/SILBuilder.h"
#include "swift/SIL/SILLocation.h"
#include "swift/SIL/SILFunctionConventions.h"
#include "swift/SIL/SILModule.h"
#include "swift/SIL/SILWitnessTable.h"
#include "swift/SIL/SILDefaultWitnessTable.h"
#include "swift/SIL/SILFunctionConventions.h"
#include "swift/SIL/SILInstruction.h"
#include "swift/SIL/SILLocation.h"
#include "swift/SIL/SILModule.h"
#include "swift/SIL/SILVTable.h"
#include "swift/SIL/SILWitnessTable.h"
#include <stdbool.h>
#include <stddef.h>
#include <string>

View File

@@ -13,12 +13,13 @@
#ifndef SWIFT_SILOPTIMIZER_OPTIMIZERBRIDGING_H
#define SWIFT_SILOPTIMIZER_OPTIMIZERBRIDGING_H
#include "swift/Basic/Nullability.h"
#include "swift/SIL/SILBridging.h"
#include "swift/SILOptimizer/PassManager/PassManager.h"
#include "swift/SILOptimizer/Analysis/AliasAnalysis.h"
#include "swift/SILOptimizer/Analysis/BasicCalleeAnalysis.h"
#include "swift/SILOptimizer/Analysis/DeadEndBlocksAnalysis.h"
#include "swift/SILOptimizer/Analysis/DominanceAnalysis.h"
#include "swift/SILOptimizer/PassManager/PassManager.h"
#include "swift/SILOptimizer/Utils/InstOptUtils.h"
SWIFT_BEGIN_NULLABILITY_ANNOTATIONS

View File

@@ -14,14 +14,15 @@
//
//===----------------------------------------------------------------------===//
#include "swift/Parse/Parser.h"
#include "swift/AST/ASTWalker.h"
#include "swift/AST/Attr.h"
#include "swift/AST/GenericParamList.h"
#include "swift/AST/SourceFile.h" // only for isMacroSignatureFile
#include "swift/AST/TypeRepr.h"
#include "swift/Parse/Lexer.h"
#include "swift/Basic/Nullability.h"
#include "swift/Parse/IDEInspectionCallbacks.h"
#include "swift/Parse/Lexer.h"
#include "swift/Parse/Parser.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/Twine.h"