mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Now we can discern the types of values in heap boxes at runtime! Closure reference captures are a common way of creating reference cycles, so this provides some basic infrastructure for detecting those someday. A closure capture descriptor has the following: - The number of captures. - The number of sources of metadata reachable from the closure. This is important for substituting generics at runtime since we can't know precisely what will get captured until we observe a closure. - The number of types in the NecessaryBindings structure. This is a holding tank in a closure for sources of metadata that can't be gotten from the captured values themselves. - The metadata source map, a list of pairs, for each source of metadata for every generic argument needed to perform substitution at runtime. Key: The typeref for the generic parameter visible from the closure in the Swift source. Value: The metadata source, which describes how to crawl the heap from the closure to get to the metadata for that generic argument. - A list of typerefs for the captured values themselves. Follow-up: IRGen tests for various capture scenarios, which will include MetadataSource encoding tests. rdar://problem/24989531
71 lines
2.3 KiB
C++
71 lines
2.3 KiB
C++
//===--- MetadataSourceBuilder.h - Swift Metadata Source Builder --------*- C++ -*-===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See http://swift.org/LICENSE.txt for license information
|
|
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// Implements utilities for constructing MetadataSources.
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef SWIFT_REFLECTION_METADATASOURCEBUILDER_H
|
|
#define SWIFT_REFLECTION_METADATASOURCEBUILDER_H
|
|
|
|
#include "swift/Reflection/MetadataSource.h"
|
|
|
|
namespace swift {
|
|
namespace reflection {
|
|
|
|
class MetadataSourceBuilder {
|
|
std::vector<std::unique_ptr<const MetadataSource>> MetadataSourcePool;
|
|
public:
|
|
using Source = const MetadataSource *;
|
|
|
|
MetadataSourceBuilder() {}
|
|
|
|
MetadataSourceBuilder(const MetadataSourceBuilder &Other) = delete;
|
|
MetadataSourceBuilder &operator=(const MetadataSourceBuilder &Other) = delete;
|
|
|
|
template <typename MetadataSourceTy, typename... Args>
|
|
MetadataSourceTy *make_source(Args... args) {
|
|
auto MS = new MetadataSourceTy(::std::forward<Args>(args)...);
|
|
MetadataSourcePool.push_back(std::unique_ptr<const MetadataSource>(MS));
|
|
return MS;
|
|
}
|
|
|
|
const GenericArgumentMetadataSource *
|
|
createGenericArgument(unsigned Index, const MetadataSource *Source) {
|
|
return GenericArgumentMetadataSource::create(*this, Index, Source);
|
|
}
|
|
|
|
const MetadataCaptureMetadataSource *
|
|
createMetadataCapture(unsigned Index) {
|
|
return MetadataCaptureMetadataSource::create(*this, Index);
|
|
}
|
|
|
|
const ReferenceCaptureMetadataSource *
|
|
createReferenceCapture(unsigned Index) {
|
|
return ReferenceCaptureMetadataSource::create(*this, Index);
|
|
}
|
|
|
|
const ClosureBindingMetadataSource *
|
|
createClosureBinding(unsigned Index) {
|
|
return ClosureBindingMetadataSource::create(*this, Index);
|
|
}
|
|
|
|
const ParentMetadataSource *
|
|
createParent(const MetadataSource *Child) {
|
|
return ParentMetadataSource::create(*this, Child);
|
|
}
|
|
};
|
|
|
|
} // end namespace reflection
|
|
} // end namespace swift
|
|
|
|
#endif // SWIFT_REFLECTION_METADATASOURCEBUILDER_H
|