1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
//===--- MetadataRequest.cpp - IR generation for metadata requests --------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2019 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 file implements IR generation for accessing metadata.
//
//===----------------------------------------------------------------------===//
#ifndef SWIFT_IRGEN_GENERICARGUMENTS_H
#define SWIFT_IRGEN_GENERICARGUMENTS_H
#include "Explosion.h"
#include "FixedTypeInfo.h"
#include "GenArchetype.h"
#include "GenClass.h"
#include "GenMeta.h"
#include "GenProto.h"
#include "GenType.h"
#include "GenericRequirement.h"
#include "IRGenDebugInfo.h"
#include "IRGenFunction.h"
#include "IRGenMangler.h"
#include "IRGenModule.h"
#include "MetadataRequest.h"
#include "swift/AST/ASTContext.h"
#include "swift/AST/ExistentialLayout.h"
#include "swift/AST/GenericEnvironment.h"
#include "swift/AST/IRGenOptions.h"
#include "swift/AST/SubstitutionMap.h"
#include "swift/ClangImporter/ClangModule.h"
#include "swift/IRGen/Linking.h"
#include "llvm/ADT/STLExtras.h"
namespace swift {
namespace irgen {
/// A structure for collecting generic arguments for emitting a
/// nominal metadata reference. The structure produced here is
/// consumed by swift_getGenericMetadata() and must correspond to
/// the fill operations that the compiler emits for the bound decl.
struct GenericArguments {
/// The values to use to initialize the arguments structure.
SmallVector<llvm::Value *, 8> Values;
SmallVector<llvm::Type *, 8> Types;
void collectTypes(IRGenModule &IGM, NominalTypeDecl *nominal) {
GenericTypeRequirements requirements(IGM, nominal);
collectTypes(IGM, requirements);
}
void collectTypes(IRGenModule &IGM,
const GenericTypeRequirements &requirements) {
for (auto &requirement : requirements.getRequirements()) {
Types.push_back(requirement.getType(IGM));
}
}
void collect(IRGenFunction &IGF, CanType type) {
auto decl = type.getNominalOrBoundGenericNominal();
auto subs = type->getContextSubstitutionMap(IGF.IGM.getSwiftModule(), decl);
collect(IGF, subs);
}
void collect(IRGenFunction &IGF, SubstitutionMap subs) {
GenericTypeRequirements requirements(IGF.IGM, subs.getGenericSignature());
for (auto requirement : requirements.getRequirements()) {
Values.push_back(emitGenericRequirementFromSubstitutions(
IGF, requirement, MetadataState::Abstract, subs));
}
collectTypes(IGF.IGM, requirements);
assert(Types.size() == Values.size());
}
};
} // namespace irgen
} // namespace swift
#endif
|