mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
This removes the "optimization" where a function type, metatype or tuple type was split up into structural components, because it seems that in general we need this structural type metadata again. Similarly, this no longer tries to split up dependent concrete conformances and instead passes the witness table in the context. This makes the context larger potentially, but it avoids calls to metadata access functions and swift_getWitnessTable() every time the closure is invoked.
89 lines
2.9 KiB
C++
89 lines
2.9 KiB
C++
//===--- 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
|