AbstractionPattern AbstractionPattern::getOptional(AbstractionPattern object) { switch (object.getKind()) { case Kind::Invalid: llvm_unreachable("querying invalid abstraction pattern!"); case Kind::Tuple: case Kind::PartialCurriedObjCMethodType: case Kind::CurriedObjCMethodType: case Kind::CFunctionAsMethodType: case Kind::PartialCurriedCFunctionAsMethodType: case Kind::CurriedCFunctionAsMethodType: case Kind::ObjCMethodType: llvm_unreachable("cannot add optionality to non-type abstraction"); case Kind::Opaque: return AbstractionPattern::getOpaque(); case Kind::ClangType: return AbstractionPattern(object.getGenericSignature(), OptionalType::get(object.getType()) ->getCanonicalType(), object.getClangType()); case Kind::Type: return AbstractionPattern(object.getGenericSignature(), OptionalType::get(object.getType()) ->getCanonicalType()); case Kind::Discard: return AbstractionPattern::getDiscard(object.getGenericSignature(), OptionalType::get(object.getType()) ->getCanonicalType()); } llvm_unreachable("bad kind"); }
SILType SILType::getFieldType(VarDecl *field, SILModule &M) const { assert(field->getDeclContext() == getNominalOrBoundGenericNominal()); AbstractionPattern origFieldTy = M.Types.getAbstractionPattern(field); CanType substFieldTy; if (field->hasClangNode()) { substFieldTy = origFieldTy.getType(); } else { substFieldTy = getSwiftRValueType()->getTypeOfMember(M.getSwiftModule(), field, nullptr)->getCanonicalType(); } auto loweredTy = M.Types.getLoweredType(origFieldTy, substFieldTy); if (isAddress() || getClassOrBoundGenericClass() != nullptr) { return loweredTy.getAddressType(); } else { return loweredTy.getObjectType(); } }
SILType TypeConverter::getLoweredTypeOfGlobal(VarDecl *var) { AbstractionPattern origType = getAbstractionPattern(var); assert(!origType.isTypeParameter()); return getLoweredType(origType, origType.getType()).getObjectType(); }