Skip to content

Add interface for lookup up of externally stored type descriptors #69556

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 4 commits into from
Nov 9, 2023
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
53 changes: 53 additions & 0 deletions include/swift/RemoteInspection/DescriptorFinder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//===--------------- DescriptorFinder.h -------------------------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 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_REFLECTION_DESCRIPTOR_FINDER_H
#define SWIFT_REFLECTION_DESCRIPTOR_FINDER_H

#include "llvm/ADT/StringRef.h"

namespace swift {
namespace reflection {

class TypeRef;

/// An abstract interface for a builtin type descriptor.
struct BuiltinTypeDescriptorBase {
const uint32_t Size;
const uint32_t Alignment;
const uint32_t Stride;
const uint32_t NumExtraInhabitants;
const bool IsBitwiseTakable;

BuiltinTypeDescriptorBase(uint32_t Size, uint32_t Alignment, uint32_t Stride,
uint32_t NumExtraInhabitants, bool IsBitwiseTakable)
: Size(Size), Alignment(Alignment), Stride(Stride),
NumExtraInhabitants(NumExtraInhabitants),
IsBitwiseTakable(IsBitwiseTakable) {}

virtual ~BuiltinTypeDescriptorBase(){};

virtual llvm::StringRef getMangledTypeName() = 0;
};

/// Interface for finding type descriptors. Implementors may provide descriptors
/// that live inside or outside reflection metadata.
struct DescriptorFinder {
virtual ~DescriptorFinder(){};

virtual std::unique_ptr<BuiltinTypeDescriptorBase>
getBuiltinTypeDescriptor(const TypeRef *TR) = 0;
};

} // namespace reflection
} // namespace swift
#endif
6 changes: 4 additions & 2 deletions include/swift/RemoteInspection/ReflectionContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "swift/Concurrency/Actor.h"
#include "swift/Remote/MemoryReader.h"
#include "swift/Remote/MetadataReader.h"
#include "swift/RemoteInspection/DescriptorFinder.h"
#include "swift/RemoteInspection/GenericMetadataCacheEntry.h"
#include "swift/RemoteInspection/Records.h"
#include "swift/RemoteInspection/RuntimeInternals.h"
Expand Down Expand Up @@ -214,8 +215,9 @@ class ReflectionContext

explicit ReflectionContext(
std::shared_ptr<MemoryReader> reader,
remote::ExternalTypeRefCache *externalCache = nullptr)
: super(std::move(reader), *this, externalCache) {}
remote::ExternalTypeRefCache *externalCache = nullptr,
reflection::DescriptorFinder *descriptorFinder = nullptr)
: super(std::move(reader), *this, externalCache, descriptorFinder) {}

ReflectionContext(const ReflectionContext &other) = delete;
ReflectionContext &operator=(const ReflectionContext &other) = delete;
Expand Down
3 changes: 2 additions & 1 deletion include/swift/RemoteInspection/TypeLowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "llvm/Support/Casting.h"
#include "swift/Remote/MetadataReader.h"
#include "swift/Remote/TypeInfoProvider.h"
#include "swift/RemoteInspection/DescriptorFinder.h"

#include <memory>

Expand Down Expand Up @@ -174,7 +175,7 @@ class BuiltinTypeInfo : public TypeInfo {

public:
explicit BuiltinTypeInfo(TypeRefBuilder &builder,
RemoteRef<BuiltinTypeDescriptor> descriptor);
BuiltinTypeDescriptorBase &descriptor);

/// Construct an empty builtin type info.
BuiltinTypeInfo()
Expand Down
Loading