Skip to content

[Tools] Add a library to build specialized generic metadata out of process. #70900

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -215,18 +215,22 @@ option(SWIFT_BUILD_REMOTE_MIRROR
"Build the Swift Remote Mirror Library"
TRUE)

option(SWIFT_BUILD_EXTERNAL_GENERIC_METADATA_BUILDER
"Build the Swift External Generic Metadata Builder Library"
TRUE)

option(SWIFT_BUILD_DYNAMIC_STDLIB
"Build dynamic variants of the Swift standard library"
TRUE)

option(SWIFT_BUILD_STATIC_STDLIB
"Build static variants of the Swift standard library"
FALSE)

option(SWIFT_STDLIB_STATIC_PRINT
"Build compile-time evaluated vprintf()"
FALSE)

option(SWIFT_STDLIB_ENABLE_UNICODE_DATA
"Include Unicode data files in the standard library.
NOTE: Disabling this will cause many String methods to crash."
Expand Down Expand Up @@ -1245,6 +1249,11 @@ if(SWIFT_BUILD_REMOTE_MIRROR)
message(STATUS "")
endif()

if(SWIFT_BUILD_EXTERNAL_GENERIC_METADATA_BUILDER)
message(STATUS "Building Swift External Generic Metadata Builder for SDKs: ${SWIFT_SDKS}")
message(STATUS "")
endif()

#
# Find required dependencies.
#
Expand Down
2 changes: 1 addition & 1 deletion cmake/modules/SwiftComponents.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
# * llvm-toolchain-dev-tools -- install LLVM development tools useful in a shared toolchain
# * dev -- headers and libraries required to use Swift compiler as a library.
set(_SWIFT_DEFINED_COMPONENTS
"autolink-driver;back-deployment;compiler;clang-builtin-headers;clang-resource-dir-symlink;clang-builtin-headers-in-clang-resource-dir;libexec;stdlib;stdlib-experimental;sdk-overlay;static-mirror-lib;swift-syntax-lib;editor-integration;tools;testsuite-tools;toolchain-tools;toolchain-dev-tools;llvm-toolchain-dev-tools;dev;license;sourcekit-xpc-service;sourcekit-inproc;swift-remote-mirror;swift-remote-mirror-headers")
"autolink-driver;back-deployment;compiler;clang-builtin-headers;clang-resource-dir-symlink;clang-builtin-headers-in-clang-resource-dir;libexec;stdlib;stdlib-experimental;sdk-overlay;static-mirror-lib;swift-syntax-lib;editor-integration;tools;testsuite-tools;toolchain-tools;toolchain-dev-tools;llvm-toolchain-dev-tools;dev;license;sourcekit-xpc-service;sourcekit-inproc;swift-remote-mirror;swift-remote-mirror-headers;swift-external-generic-metadata-builder;swift-external-generic-metadata-builder-headers")

# The default install components include all of the defined components, except
# for the following exceptions.
Expand Down
20 changes: 11 additions & 9 deletions include/swift/ABI/Metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ template <typename Runtime>
struct TargetTypeMetadataHeaderBase {
/// A pointer to the value-witnesses for this type. This is only
/// present for type metadata.
TargetPointer<Runtime, const ValueWitnessTable> ValueWitnesses;
TargetPointer<Runtime, const TargetValueWitnessTable<Runtime>> ValueWitnesses;
};

template <typename Runtime>
Expand Down Expand Up @@ -329,7 +329,7 @@ struct TargetMetadata {
return asFullMetadata(this)->layoutString;
}

const ValueWitnessTable *getValueWitnesses() const {
const TargetValueWitnessTable<Runtime> *getValueWitnesses() const {
return asFullMetadata(this)->ValueWitnesses;
}

Expand Down Expand Up @@ -2979,7 +2979,7 @@ template <typename Runtime>
struct swift_ptrauth_struct_context_descriptor(ModuleContextDescriptor)
TargetModuleContextDescriptor final : TargetContextDescriptor<Runtime> {
/// The module name.
RelativeDirectPointer<const char, /*nullable*/ false> Name;
TargetRelativeDirectPointer<Runtime, const char, /*nullable*/ false> Name;

/// Is this module a special C-imported module?
bool isCImportedContext() const {
Expand Down Expand Up @@ -3036,7 +3036,7 @@ struct swift_ptrauth_struct_context_descriptor(ExtensionContextDescriptor)
///
/// Note that the Parent of the extension will be the module context the
/// extension is declared inside.
RelativeDirectPointer<const char> ExtendedContext;
TargetRelativeDirectPointer<Runtime, const char> ExtendedContext;

using TrailingGenericContextObjects::getGenericContext;

Expand Down Expand Up @@ -3527,10 +3527,10 @@ struct TargetGenericValueMetadataPattern final :

/// The value-witness table. Indirectable so that we can re-use tables
/// from other libraries if that seems wise.
TargetRelativeIndirectablePointer<Runtime, const ValueWitnessTable>
TargetRelativeIndirectablePointer<Runtime, const TargetValueWitnessTable<Runtime>>
ValueWitnesses;

const ValueWitnessTable *getValueWitnessesPattern() const {
const TargetValueWitnessTable<Runtime> *getValueWitnessesPattern() const {
return ValueWitnesses.get();
}

Expand Down Expand Up @@ -3825,9 +3825,11 @@ class swift_ptrauth_struct_context_descriptor(TypeContextDescriptor)
/*Nullable*/ true> AccessFunctionPtr;

/// A pointer to the field descriptor for the type, if any.
TargetRelativeDirectPointer<Runtime, const reflection::FieldDescriptor,
/*nullable*/ true> Fields;

TargetRelativeDirectPointer<Runtime,
const reflection::TargetFieldDescriptor<Runtime>,
/*nullable*/ true>
Fields;

bool isReflectable() const { return (bool)Fields; }

MetadataAccessFunction getAccessFunction() const {
Expand Down
3 changes: 2 additions & 1 deletion include/swift/ABI/TargetLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ struct RuntimeTarget<8> {
};

namespace reflection {
class FieldDescriptor;
template <typename Runtime>
class TargetFieldDescriptor;
}

/// In-process native runtime target.
Expand Down
7 changes: 6 additions & 1 deletion include/swift/Basic/RelativePointer.h
Original file line number Diff line number Diff line change
Expand Up @@ -590,8 +590,12 @@ class RelativeDirectPointerIntPairImpl {
using ValueTy = PointeeTy;
using PointerTy = PointeeTy*;

Offset getOffset() const & {
return RelativeOffsetPlusInt & ~getMask();
}

PointerTy getPointer() const & {
Offset offset = (RelativeOffsetPlusInt & ~getMask());
Offset offset = getOffset();

// Check for null.
if (Nullable && offset == 0)
Expand Down Expand Up @@ -624,6 +628,7 @@ class RelativeDirectPointerIntPair<PointeeTy, IntTy, Nullable, Offset,
{
using super = RelativeDirectPointerIntPairImpl<PointeeTy, IntTy, Nullable, Offset>;
public:
using super::getOffset;
using super::getPointer;
using super::getInt;
using super::getOpaqueValue;
Expand Down
2 changes: 2 additions & 0 deletions include/swift/Demangling/Demangle.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ class Node {
// Only to be used by the demangler parsers.
void removeChildAt(unsigned Pos);

void replaceChild(unsigned Pos, NodePointer Child);

// Reverses the order of children.
void reverseChildren(size_t StartingAt = 0);

Expand Down
56 changes: 30 additions & 26 deletions include/swift/RemoteInspection/Records.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#ifndef SWIFT_REFLECTION_RECORDS_H
#define SWIFT_REFLECTION_RECORDS_H

#include "swift/Basic/RelativePointer.h"
#include "swift/ABI/TargetLayout.h"
#include "swift/Demangling/Demangle.h"
#include "llvm/ADT/ArrayRef.h"

Expand Down Expand Up @@ -82,14 +82,15 @@ class FieldRecordFlags {
}
};

class FieldRecord {
template <typename Runtime>
class TargetFieldRecord {
const FieldRecordFlags Flags;

public:
const RelativeDirectPointer<const char> MangledTypeName;
const RelativeDirectPointer<const char> FieldName;
const TargetRelativeDirectPointer<Runtime, const char> MangledTypeName;
const TargetRelativeDirectPointer<Runtime, const char> FieldName;

FieldRecord() = delete;
TargetFieldRecord() = delete;

bool hasMangledTypeName() const {
return MangledTypeName;
Expand All @@ -111,36 +112,37 @@ class FieldRecord {
return Flags.isVar();
}
};
using FieldRecord = TargetFieldRecord<InProcess>;

struct FieldRecordIterator {
const FieldRecord *Cur;
const FieldRecord * const End;
template <typename Runtime>
struct TargetFieldRecordIterator {
const TargetFieldRecord<Runtime> *Cur;
const TargetFieldRecord<Runtime> *const End;

FieldRecordIterator(const FieldRecord *Cur, const FieldRecord * const End)
: Cur(Cur), End(End) {}
TargetFieldRecordIterator(const TargetFieldRecord<Runtime> *Cur,
const TargetFieldRecord<Runtime> *const End)
: Cur(Cur), End(End) {}

const FieldRecord &operator*() const {
return *Cur;
}
const TargetFieldRecord<Runtime> &operator*() const { return *Cur; }

const FieldRecord *operator->() const {
return Cur;
}
const TargetFieldRecord<Runtime> *operator->() const { return Cur; }

FieldRecordIterator &operator++() {
TargetFieldRecordIterator &operator++() {
++Cur;
return *this;
}

bool operator==(const FieldRecordIterator &other) const {
bool operator==(const TargetFieldRecordIterator &other) const {
return Cur == other.Cur && End == other.End;
}

bool operator!=(const FieldRecordIterator &other) const {
bool operator!=(const TargetFieldRecordIterator &other) const {
return !(*this == other);
}
};

using FieldRecordIterator = TargetFieldRecordIterator<InProcess>;

enum class FieldDescriptorKind : uint16_t {
// Swift nominal types.
Struct,
Expand Down Expand Up @@ -173,16 +175,17 @@ enum class FieldDescriptorKind : uint16_t {

// Field descriptors contain a collection of field records for a single
// class, struct or enum declaration.
class FieldDescriptor {
const FieldRecord *getFieldRecordBuffer() const {
return reinterpret_cast<const FieldRecord *>(this + 1);
template <typename Runtime>
class TargetFieldDescriptor {
const TargetFieldRecord<Runtime> *getFieldRecordBuffer() const {
return reinterpret_cast<const TargetFieldRecord<Runtime> *>(this + 1);
}

public:
const RelativeDirectPointer<const char> MangledTypeName;
const RelativeDirectPointer<const char> Superclass;
const TargetRelativeDirectPointer<Runtime, const char> MangledTypeName;
const TargetRelativeDirectPointer<Runtime, const char> Superclass;

FieldDescriptor() = delete;
TargetFieldDescriptor() = delete;

const FieldDescriptorKind Kind;
const uint16_t FieldRecordSize;
Expand Down Expand Up @@ -222,7 +225,7 @@ class FieldDescriptor {
return const_iterator { End, End };
}

llvm::ArrayRef<FieldRecord> getFields() const {
llvm::ArrayRef<TargetFieldRecord<Runtime>> getFields() const {
return {getFieldRecordBuffer(), NumFields};
}

Expand All @@ -242,6 +245,7 @@ class FieldDescriptor {
return Demangle::makeSymbolicMangledNameStringRef(Superclass.get());
}
};
using FieldDescriptor = TargetFieldDescriptor<InProcess>;

// Associated type records describe the mapping from an associated
// type to the type witness of a conformance.
Expand Down
4 changes: 2 additions & 2 deletions include/swift/Runtime/Enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "swift/Runtime/Config.h"

namespace swift {

struct OpaqueValue;
struct InProcess;

Expand Down Expand Up @@ -139,7 +139,7 @@ void swift_initEnumMetadataMultiPayloadWithLayoutString(EnumMetadata *enumType,
SWIFT_RUNTIME_EXPORT
unsigned swift_getEnumCaseMultiPayload(const OpaqueValue *value,
const EnumMetadata *enumType);

/// Store the tag value for the given case into a multi-payload enum,
/// whose associated payload (if any) has already been initialized.
SWIFT_RUNTIME_EXPORT
Expand Down
3 changes: 2 additions & 1 deletion include/swift/Runtime/EnvironmentVariables.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
//===----------------------------------------------------------------------===//

#include "swift/Threading/Once.h"
#include "swift/shims/Visibility.h"

namespace swift {
namespace runtime {
Expand Down Expand Up @@ -54,4 +55,4 @@ SWIFT_RUNTIME_STDLIB_SPI bool concurrencyValidateUncheckedContinuations();

} // end namespace environment
} // end namespace runtime
} // end namespace Swift
} // end namespace swift
Loading