/// Add a 32-bit relative offset to a mangled typeref string /// in the typeref reflection section. void addTypeRef(ModuleDecl *ModuleContext, CanType type, CanGenericSignature Context = {}) { assert(type); // Generic parameters should be written in terms of interface types // for the purposes of reflection metadata assert(!type->hasArchetype() && "Forgot to map typeref out of context"); // TODO: As a compatibility hack, mangle single-field boxes with the legacy // mangling in reflection metadata. bool isSingleFieldOfBox = false; auto boxTy = dyn_cast<SILBoxType>(type); if (boxTy && boxTy->getLayout()->getFields().size() == 1) { GenericContextScope scope(IGM, Context); type = boxTy->getFieldLoweredType(IGM.getSILModule(), 0); isSingleFieldOfBox = true; } IRGenMangler mangler; std::string MangledStr = mangler.mangleTypeForReflection(type, ModuleContext, isSingleFieldOfBox); auto mangledName = IGM.getAddrOfStringForTypeRef(MangledStr); addRelativeAddress(mangledName); }
llvm::Constant *IRGenModule::getTypeRef(CanType type) { IRGenMangler Mangler; auto SymbolicName = Mangler.mangleTypeForReflection(*this, type); return getAddrOfStringForTypeRef(SymbolicName); }