mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Merge pull request #19384 from slavapestov/remove-function-input-abstraction-pattern
SILGen: Port reabstraction thunks to the new function type representation
This commit is contained in:
@@ -162,11 +162,6 @@ class AbstractionPattern {
|
||||
Discard,
|
||||
/// A type reference with a Clang type. OrigType and ClangType are valid.
|
||||
ClangType,
|
||||
/// A reference to the parameters of a Clang function type,
|
||||
/// imported as a tuple type. OrigType is valid and is a tuple
|
||||
/// type. ClangType is valid and is a function type, a function
|
||||
/// pointer type, or a block pointer type.
|
||||
ClangFunctionParamTupleType,
|
||||
/// The curried imported type of an Objective-C method (that is,
|
||||
/// 'Self -> Input -> Result'). OrigType is valid and is a function
|
||||
/// type. ObjCMethod is valid. OtherData is an encoded foreign
|
||||
@@ -181,10 +176,6 @@ class AbstractionPattern {
|
||||
/// OrigType is valid and is a function type. ClangType is valid and is
|
||||
/// a function type. OtherData is an encoded ImportAsMemberStatus.
|
||||
CFunctionAsMethodType,
|
||||
/// The uncurried parameter tuple type of a C function imported as a method.
|
||||
/// OrigType is valid and is a function type. ClangType is valid and is
|
||||
/// a tuple type. OtherData is an encoded ImportAsMemberStatus.
|
||||
CFunctionAsMethodParamTupleType,
|
||||
/// The curried imported type of a C function imported as a method.
|
||||
/// OrigType is valid and is a function type. ClangType is valid and is
|
||||
/// a function type. OtherData is an encoded ImportAsMemberStatus.
|
||||
@@ -199,23 +190,6 @@ class AbstractionPattern {
|
||||
/// type. ObjCMethod is valid. OtherData is an encoded foreign
|
||||
/// error index.
|
||||
ObjCMethodType,
|
||||
/// A reference to the uncurried parameters of a Clang Objective-C
|
||||
/// method type, imported as a tuple type (that is, '(Input,
|
||||
/// Self'). OrigType is valid and is a tuple type with two
|
||||
/// elements. ObjCMethod is valid. OtherData is an encoded
|
||||
/// foreign error index.
|
||||
ObjCMethodParamTupleType,
|
||||
/// A reference to the formal parameters of a Clang Objective-C
|
||||
/// method type when they were imported as a tuple type (that is,
|
||||
/// 'Input', if it's a tuple type). OrigType is valid and is a
|
||||
/// tuple type. ObjCMethod is valid. OtherData is an encoded
|
||||
/// foreign error index.
|
||||
ObjCMethodFormalParamTupleType,
|
||||
/// A reference to the formal method parameters of a C function that was
|
||||
/// imported as a method.
|
||||
/// OrigType is valid and is a tuple type. ClangType is valid and is
|
||||
/// a function type. OtherData is an encoded ImportAsMemberStatus.
|
||||
CFunctionAsMethodFormalParamTupleType,
|
||||
};
|
||||
|
||||
class EncodedForeignErrorInfo {
|
||||
@@ -294,12 +268,9 @@ class AbstractionPattern {
|
||||
bool hasStoredClangType() const {
|
||||
switch (getKind()) {
|
||||
case Kind::ClangType:
|
||||
case Kind::ClangFunctionParamTupleType:
|
||||
case Kind::CFunctionAsMethodType:
|
||||
case Kind::CFunctionAsMethodParamTupleType:
|
||||
case Kind::CurriedCFunctionAsMethodType:
|
||||
case Kind::PartialCurriedCFunctionAsMethodType:
|
||||
case Kind::CFunctionAsMethodFormalParamTupleType:
|
||||
return true;
|
||||
|
||||
default:
|
||||
@@ -312,8 +283,6 @@ class AbstractionPattern {
|
||||
case Kind::CurriedObjCMethodType:
|
||||
case Kind::PartialCurriedObjCMethodType:
|
||||
case Kind::ObjCMethodType:
|
||||
case Kind::ObjCMethodParamTupleType:
|
||||
case Kind::ObjCMethodFormalParamTupleType:
|
||||
return true;
|
||||
|
||||
default:
|
||||
@@ -328,10 +297,8 @@ class AbstractionPattern {
|
||||
bool hasImportAsMemberStatus() const {
|
||||
switch (getKind()) {
|
||||
case Kind::CFunctionAsMethodType:
|
||||
case Kind::CFunctionAsMethodParamTupleType:
|
||||
case Kind::CurriedCFunctionAsMethodType:
|
||||
case Kind::PartialCurriedCFunctionAsMethodType:
|
||||
case Kind::CFunctionAsMethodFormalParamTupleType:
|
||||
return true;
|
||||
|
||||
default:
|
||||
@@ -423,19 +390,6 @@ public:
|
||||
return pattern;
|
||||
}
|
||||
|
||||
private:
|
||||
/// Return an abstraction pattern for a tuple representing all the
|
||||
/// parameters to a C or block function.
|
||||
static AbstractionPattern
|
||||
getClangFunctionParamTuple(CanGenericSignature signature, CanType origType,
|
||||
const clang::Type *clangType) {
|
||||
assert(isa<TupleType>(origType));
|
||||
AbstractionPattern pattern;
|
||||
pattern.initClangType(signature, origType, clangType,
|
||||
Kind::ClangFunctionParamTupleType);
|
||||
return pattern;
|
||||
}
|
||||
|
||||
public:
|
||||
/// Return an abstraction pattern for the curried type of an
|
||||
/// Objective-C method.
|
||||
@@ -574,43 +528,6 @@ private:
|
||||
return pattern;
|
||||
}
|
||||
|
||||
/// Return an abstraction pattern for a tuple representing the
|
||||
/// uncurried parameter clauses of an Objective-C method.
|
||||
static AbstractionPattern
|
||||
getObjCMethodParamTuple(CanGenericSignature signature, CanType origType,
|
||||
const clang::ObjCMethodDecl *method,
|
||||
EncodedForeignErrorInfo errorInfo) {
|
||||
assert(isa<TupleType>(origType));
|
||||
assert(cast<TupleType>(origType)->getNumElements() == 2);
|
||||
AbstractionPattern pattern;
|
||||
pattern.initObjCMethod(signature, origType, method,
|
||||
Kind::ObjCMethodParamTupleType, errorInfo);
|
||||
return pattern;
|
||||
}
|
||||
|
||||
/// Return an abstraction pattern for a tuple representing the
|
||||
/// uncurried parameter clauses of a C function imported as a method.
|
||||
///
|
||||
/// For example, if the original function is:
|
||||
/// void CCRefrigatorSetTemperature(CCRefrigeratorRef fridge,
|
||||
/// CCRefrigeratorCompartment compartment,
|
||||
/// CCTemperature temperature);
|
||||
/// then the parameter tuple type is:
|
||||
/// ((CCRefrigeratorComponent, CCTemperature), CCRefrigerator)
|
||||
static AbstractionPattern
|
||||
getCFunctionAsMethodParamTuple(CanGenericSignature signature,
|
||||
CanType origType,
|
||||
const clang::Type *type,
|
||||
ImportAsMemberStatus memberStatus) {
|
||||
assert(isa<TupleType>(origType));
|
||||
assert(cast<TupleType>(origType)->getNumElements() == 2);
|
||||
AbstractionPattern pattern;
|
||||
pattern.initCFunctionAsMethod(signature, origType, type,
|
||||
Kind::CFunctionAsMethodParamTupleType,
|
||||
memberStatus);
|
||||
return pattern;
|
||||
}
|
||||
|
||||
/// Return a pattern corresponding to the 'self' parameter of the
|
||||
/// current Objective-C method.
|
||||
AbstractionPattern getObjCMethodSelfPattern(CanType paramType) const;
|
||||
@@ -628,34 +545,6 @@ private:
|
||||
AbstractionPattern getCFunctionAsMethodFormalParamPattern(CanType paramType)
|
||||
const;
|
||||
|
||||
/// Return an abstraction pattern for a tuple representing the
|
||||
/// formal parameters to an Objective-C method.
|
||||
static AbstractionPattern
|
||||
getObjCMethodFormalParamTuple(CanGenericSignature signature, CanType origType,
|
||||
const clang::ObjCMethodDecl *method,
|
||||
EncodedForeignErrorInfo errorInfo) {
|
||||
assert(isa<TupleType>(origType));
|
||||
AbstractionPattern pattern;
|
||||
pattern.initObjCMethod(signature, origType, method,
|
||||
Kind::ObjCMethodFormalParamTupleType, errorInfo);
|
||||
return pattern;
|
||||
}
|
||||
|
||||
/// Return an abstraction pattern for a tuple representing the
|
||||
/// formal method parameters to a C function imported as a method.
|
||||
static AbstractionPattern
|
||||
getCFunctionAsMethodFormalParamTuple(CanGenericSignature signature,
|
||||
CanType origType,
|
||||
const clang::Type *type,
|
||||
ImportAsMemberStatus memberStatus) {
|
||||
assert(isa<TupleType>(origType));
|
||||
AbstractionPattern pattern;
|
||||
pattern.initCFunctionAsMethod(signature, origType, type,
|
||||
Kind::CFunctionAsMethodFormalParamTupleType,
|
||||
memberStatus);
|
||||
return pattern;
|
||||
}
|
||||
|
||||
public:
|
||||
/// Return an abstraction pattern with an added level of optionality.
|
||||
///
|
||||
@@ -721,17 +610,12 @@ public:
|
||||
case Kind::Tuple:
|
||||
llvm_unreachable("open-coded tuple pattern has no type");
|
||||
case Kind::ClangType:
|
||||
case Kind::ClangFunctionParamTupleType:
|
||||
case Kind::CurriedObjCMethodType:
|
||||
case Kind::PartialCurriedObjCMethodType:
|
||||
case Kind::ObjCMethodType:
|
||||
case Kind::ObjCMethodParamTupleType:
|
||||
case Kind::ObjCMethodFormalParamTupleType:
|
||||
case Kind::CFunctionAsMethodType:
|
||||
case Kind::CFunctionAsMethodParamTupleType:
|
||||
case Kind::CurriedCFunctionAsMethodType:
|
||||
case Kind::PartialCurriedCFunctionAsMethodType:
|
||||
case Kind::CFunctionAsMethodFormalParamTupleType:
|
||||
case Kind::Type:
|
||||
case Kind::Discard:
|
||||
return OrigType;
|
||||
@@ -757,17 +641,12 @@ public:
|
||||
case Kind::Tuple:
|
||||
llvm_unreachable("type cannot be replaced on pattern without type");
|
||||
case Kind::ClangType:
|
||||
case Kind::ClangFunctionParamTupleType:
|
||||
case Kind::CurriedObjCMethodType:
|
||||
case Kind::PartialCurriedObjCMethodType:
|
||||
case Kind::ObjCMethodType:
|
||||
case Kind::ObjCMethodParamTupleType:
|
||||
case Kind::ObjCMethodFormalParamTupleType:
|
||||
case Kind::CFunctionAsMethodType:
|
||||
case Kind::CFunctionAsMethodParamTupleType:
|
||||
case Kind::CurriedCFunctionAsMethodType:
|
||||
case Kind::PartialCurriedCFunctionAsMethodType:
|
||||
case Kind::CFunctionAsMethodFormalParamTupleType:
|
||||
case Kind::Type:
|
||||
case Kind::Discard:
|
||||
assert(signature || !type->hasTypeParameter());
|
||||
@@ -794,17 +673,12 @@ public:
|
||||
case Kind::Discard:
|
||||
return false;
|
||||
case Kind::ClangType:
|
||||
case Kind::ClangFunctionParamTupleType:
|
||||
case Kind::PartialCurriedObjCMethodType:
|
||||
case Kind::CurriedObjCMethodType:
|
||||
case Kind::ObjCMethodType:
|
||||
case Kind::ObjCMethodParamTupleType:
|
||||
case Kind::ObjCMethodFormalParamTupleType:
|
||||
case Kind::CFunctionAsMethodType:
|
||||
case Kind::CFunctionAsMethodParamTupleType:
|
||||
case Kind::CurriedCFunctionAsMethodType:
|
||||
case Kind::PartialCurriedCFunctionAsMethodType:
|
||||
case Kind::CFunctionAsMethodFormalParamTupleType:
|
||||
return true;
|
||||
}
|
||||
llvm_unreachable("bad kind");
|
||||
@@ -848,9 +722,6 @@ public:
|
||||
case Kind::Invalid:
|
||||
llvm_unreachable("querying invalid abstraction pattern!");
|
||||
case Kind::Tuple:
|
||||
case Kind::ClangFunctionParamTupleType:
|
||||
case Kind::ObjCMethodParamTupleType:
|
||||
case Kind::ObjCMethodFormalParamTupleType:
|
||||
llvm_unreachable("querying foreign-error bits on non-function pattern");
|
||||
|
||||
case Kind::Opaque:
|
||||
@@ -858,10 +729,8 @@ public:
|
||||
case Kind::Type:
|
||||
case Kind::Discard:
|
||||
case Kind::CFunctionAsMethodType:
|
||||
case Kind::CFunctionAsMethodParamTupleType:
|
||||
case Kind::CurriedCFunctionAsMethodType:
|
||||
case Kind::PartialCurriedCFunctionAsMethodType:
|
||||
case Kind::CFunctionAsMethodFormalParamTupleType:
|
||||
return false;
|
||||
case Kind::PartialCurriedObjCMethodType:
|
||||
case Kind::CurriedObjCMethodType:
|
||||
@@ -884,17 +753,12 @@ public:
|
||||
case Kind::Tuple:
|
||||
return typename CanTypeWrapperTraits<TYPE>::type();
|
||||
case Kind::ClangType:
|
||||
case Kind::ClangFunctionParamTupleType:
|
||||
case Kind::PartialCurriedObjCMethodType:
|
||||
case Kind::CurriedObjCMethodType:
|
||||
case Kind::ObjCMethodType:
|
||||
case Kind::ObjCMethodParamTupleType:
|
||||
case Kind::ObjCMethodFormalParamTupleType:
|
||||
case Kind::CFunctionAsMethodType:
|
||||
case Kind::CFunctionAsMethodParamTupleType:
|
||||
case Kind::CurriedCFunctionAsMethodType:
|
||||
case Kind::PartialCurriedCFunctionAsMethodType:
|
||||
case Kind::CFunctionAsMethodFormalParamTupleType:
|
||||
case Kind::Type:
|
||||
case Kind::Discard:
|
||||
return dyn_cast<TYPE>(getType());
|
||||
@@ -914,17 +778,12 @@ public:
|
||||
case Kind::Opaque:
|
||||
case Kind::Tuple:
|
||||
case Kind::ClangType:
|
||||
case Kind::ClangFunctionParamTupleType:
|
||||
case Kind::PartialCurriedObjCMethodType:
|
||||
case Kind::CurriedObjCMethodType:
|
||||
case Kind::ObjCMethodType:
|
||||
case Kind::ObjCMethodParamTupleType:
|
||||
case Kind::ObjCMethodFormalParamTupleType:
|
||||
case Kind::CFunctionAsMethodType:
|
||||
case Kind::CFunctionAsMethodParamTupleType:
|
||||
case Kind::CurriedCFunctionAsMethodType:
|
||||
case Kind::PartialCurriedCFunctionAsMethodType:
|
||||
case Kind::CFunctionAsMethodFormalParamTupleType:
|
||||
// We assume that the Clang type might provide additional structure.
|
||||
return false;
|
||||
case Kind::Type:
|
||||
@@ -951,11 +810,6 @@ public:
|
||||
case Kind::ObjCMethodType:
|
||||
return false;
|
||||
case Kind::Tuple:
|
||||
case Kind::CFunctionAsMethodParamTupleType:
|
||||
case Kind::ClangFunctionParamTupleType:
|
||||
case Kind::ObjCMethodParamTupleType:
|
||||
case Kind::ObjCMethodFormalParamTupleType:
|
||||
case Kind::CFunctionAsMethodFormalParamTupleType:
|
||||
return true;
|
||||
case Kind::Type:
|
||||
case Kind::Discard:
|
||||
@@ -982,11 +836,6 @@ public:
|
||||
case Kind::Type:
|
||||
case Kind::Discard:
|
||||
case Kind::ClangType:
|
||||
case Kind::ClangFunctionParamTupleType:
|
||||
case Kind::CFunctionAsMethodParamTupleType:
|
||||
case Kind::ObjCMethodParamTupleType:
|
||||
case Kind::ObjCMethodFormalParamTupleType:
|
||||
case Kind::CFunctionAsMethodFormalParamTupleType:
|
||||
return cast<TupleType>(getType())->getNumElements();
|
||||
}
|
||||
llvm_unreachable("bad kind");
|
||||
@@ -996,18 +845,10 @@ public:
|
||||
/// the abstraction pattern for its object type.
|
||||
AbstractionPattern getTupleElementType(unsigned index) const;
|
||||
|
||||
/// Given that the value being abstracted is an l-value or inout type,
|
||||
/// return the abstraction pattern for its object type.
|
||||
AbstractionPattern getWithoutSpecifierType() const;
|
||||
|
||||
/// Given that the value being abstracted is a function, return the
|
||||
/// abstraction pattern for its result type.
|
||||
AbstractionPattern getFunctionResultType() const;
|
||||
|
||||
/// Given that the value being abstracted is a function, return the
|
||||
/// abstraction pattern for its input type.
|
||||
AbstractionPattern getFunctionInputType() const;
|
||||
|
||||
/// Given that the value being abstracted is a function type, return
|
||||
/// the abstraction pattern for one of its parameter types.
|
||||
AbstractionPattern getFunctionParamType(unsigned index) const;
|
||||
|
||||
@@ -64,6 +64,20 @@ inline bool shouldExpandTupleType(TupleType *type) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/// A version of the above for parameter lists.
|
||||
///
|
||||
/// FIXME: Should also remove this soon.
|
||||
inline bool shouldExpandParams(AnyFunctionType::CanParamArrayRef params) {
|
||||
for (auto param : params)
|
||||
if (param.getValueOwnership() != ValueOwnership::Default)
|
||||
return true;
|
||||
|
||||
if (params.size() == 1)
|
||||
return params[0].isVariadic();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// The default convention for handling the callee object on thick
|
||||
/// callees.
|
||||
const ParameterConvention DefaultThickCalleeConvention =
|
||||
|
||||
Reference in New Issue
Block a user