mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
rdar://105837040 * WIP: Store layout string in type metadata * WIP: More cases working * WIP: Layout strings almost working * Add layout string pointer to struct metadata * Fetch bytecode layout strings from metadata in runtime * More efficient bytecode layout * Add support for interpreted generics in layout strings * Layout string instantiation, take and more * Remove duplicate information from layout strings * Include size of previous object in next objects offset to reduce number of increments at runtime * Add support for existentials * Build type layout strings with StructBuilder to support target sizes and metadata pointers * Add support for resilient types * Properly cache layout strings in compiler * Generic resilient types working * Non-generic resilient types working * Instantiate resilient type in layout when possible * Fix a few issues around alignment and signing * Disable generics, fix static alignment * Fix MultiPayloadEnum size when no extra tag is necessary * Fixes after rebase * Cleanup * Fix most tests * Fix objcImplementattion and non-Darwin builds * Fix BytecodeLayouts on non-Darwin * Fix Linux build * Fix sizes in linux tests * Sign layout string pointers * Use nullptr instead of debug value
103 lines
2.9 KiB
C++
103 lines
2.9 KiB
C++
//===-- ForeignClassMetadataVisitor.h - foreign class metadata -*- 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// A CRTP class useful for laying out foreign class metadata.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef SWIFT_IRGEN_FOREIGNCLASSMETADATAVISITOR_H
|
|
#define SWIFT_IRGEN_FOREIGNCLASSMETADATAVISITOR_H
|
|
|
|
#include "NominalMetadataVisitor.h"
|
|
|
|
namespace swift {
|
|
namespace irgen {
|
|
|
|
/// A CRTP layout class for foreign class metadata.
|
|
template <class Impl>
|
|
class ForeignClassMetadataVisitor
|
|
: public NominalMetadataVisitor<Impl> {
|
|
using super = NominalMetadataVisitor<Impl>;
|
|
protected:
|
|
ClassDecl *Target;
|
|
using super::asImpl;
|
|
public:
|
|
ForeignClassMetadataVisitor(IRGenModule &IGM, ClassDecl *target)
|
|
: super(IGM), Target(target) {}
|
|
|
|
void layout() {
|
|
asImpl().addLayoutStringPointer();
|
|
super::layout();
|
|
asImpl().addNominalTypeDescriptor();
|
|
asImpl().addSuperclass();
|
|
asImpl().addReservedWord();
|
|
}
|
|
|
|
CanType getTargetType() const {
|
|
return Target->getDeclaredType()->getCanonicalType();
|
|
}
|
|
};
|
|
|
|
/// An "implementation" of ForeignClassMetadataVisitor that just scans through
|
|
/// the metadata layout, maintaining the offset of the next field.
|
|
template <class Impl>
|
|
class ForeignClassMetadataScanner : public ForeignClassMetadataVisitor<Impl> {
|
|
using super = ForeignClassMetadataVisitor<Impl>;
|
|
|
|
protected:
|
|
Size NextOffset = Size(0);
|
|
|
|
ForeignClassMetadataScanner(IRGenModule &IGM, ClassDecl *target)
|
|
: super(IGM, target) {}
|
|
|
|
public:
|
|
void addMetadataFlags() { addPointer(); }
|
|
void addLayoutStringPointer() { addPointer(); }
|
|
void addValueWitnessTable() { addPointer(); }
|
|
void addNominalTypeDescriptor() { addPointer(); }
|
|
void addSuperclass() { addPointer(); }
|
|
void addReservedWord() { addPointer(); }
|
|
|
|
private:
|
|
void addPointer() {
|
|
NextOffset += super::IGM.getPointerSize();
|
|
}
|
|
};
|
|
|
|
template <class Impl>
|
|
class ForeignReferenceTypeMetadataVisitor
|
|
: public NominalMetadataVisitor<Impl> {
|
|
using super = NominalMetadataVisitor<Impl>;
|
|
protected:
|
|
ClassDecl *Target;
|
|
using super::asImpl;
|
|
public:
|
|
ForeignReferenceTypeMetadataVisitor(IRGenModule &IGM, ClassDecl *target)
|
|
: super(IGM), Target(target) {}
|
|
|
|
void layout() {
|
|
asImpl().addLayoutStringPointer();
|
|
super::layout();
|
|
asImpl().addNominalTypeDescriptor();
|
|
asImpl().addReservedWord();
|
|
}
|
|
|
|
CanType getTargetType() const {
|
|
return Target->getDeclaredType()->getCanonicalType();
|
|
}
|
|
};
|
|
|
|
} // end namespace irgen
|
|
} // end namespace swift
|
|
|
|
#endif // SWIFT_IRGEN_FOREIGNCLASSMETADATAVISITOR_H
|