Files
swift-mirror/include/swift/SIL/BridgedSwiftObject.h
3405691582 5147706037 Work around a possible platform/modules bug.
On OpenBSD, `stdint.h` is a symlink to `sys/stdint.h`, and the platform
modulemap (basically identical to `libcxx/include/module.modulemap`) has
a defined submodule `std.depr.stdint_h`. When compiling happens with
`-fmodules`, which is what happens in bootstrap builds, this seems to
confuse clang royally and demands that `stdint.h` be included when it
already is.

I don't actually understand what the problem is here. The problem isn't
the symlink, but something... else. I think the problem is the fact that
`std.depr.stdint_h` exists which causes the problem somehow. Removing
the module fixes the problem, as does using a different include (like
`inttypes.h` which does not have a corresponding module) which includes
`stdint.h` transitively.

The other alternative is to counsel users trying to build for the
platform to disable libswift, which means that modules aren't used. This
would be OK, but given that eeckstein says that "*Currently* libswift
does not contain any "mandatory" code yet" (emphasis mine) suggests that
such counsel wouldn't be very durable.

Therefore, to make sure the build is unbroken, make this terrible little
hack for now.
2022-01-24 16:36:50 -05:00

72 lines
2.3 KiB
C

//===--- BridgedSwiftObject.h - C header which defines SwiftObject --------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2021 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
//
//===----------------------------------------------------------------------===//
//
// This is a C header, which defines the SwiftObject header. For the C++ version
// see SwiftObjectHeader.h.
//
//===----------------------------------------------------------------------===//
#ifndef SWIFT_SIL_BRIDGEDSWIFTOBJECT_H
#define SWIFT_SIL_BRIDGEDSWIFTOBJECT_H
#if defined(__OpenBSD__)
#include <sys/stdint.h>
#else
#include <stdint.h>
#endif
#if !defined(__has_feature)
#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;
/// The header of a Swift object.
///
/// This must be in sync with HeapObject, which is defined in the runtime lib.
/// It must be layout compatible with the Swift object header.
struct BridgedSwiftObject {
SwiftMetatype metatype;
int64_t refCounts;
};
typedef struct BridgedSwiftObject * _Nonnull SwiftObject;
typedef struct BridgedSwiftObject * _Nullable OptionalSwiftObject;
SWIFT_END_NULLABILITY_ANNOTATIONS
#endif