Skip to content

SILGen: Port reabstraction thunks to the new function type representation #19384

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 0 additions & 159 deletions include/swift/SIL/AbstractionPattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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 {
Expand Down Expand Up @@ -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:
Expand All @@ -312,8 +283,6 @@ class AbstractionPattern {
case Kind::CurriedObjCMethodType:
case Kind::PartialCurriedObjCMethodType:
case Kind::ObjCMethodType:
case Kind::ObjCMethodParamTupleType:
case Kind::ObjCMethodFormalParamTupleType:
return true;

default:
Expand All @@ -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:
Expand Down Expand Up @@ -423,19 +390,6 @@ class AbstractionPattern {
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.
Expand Down Expand Up @@ -574,43 +528,6 @@ class AbstractionPattern {
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;
Expand All @@ -628,34 +545,6 @@ class AbstractionPattern {
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.
///
Expand Down Expand Up @@ -721,17 +610,12 @@ class AbstractionPattern {
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;
Expand All @@ -757,17 +641,12 @@ class AbstractionPattern {
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());
Expand All @@ -794,17 +673,12 @@ class AbstractionPattern {
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");
Expand Down Expand Up @@ -848,20 +722,15 @@ class AbstractionPattern {
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:
case Kind::ClangType:
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:
Expand All @@ -884,17 +753,12 @@ class AbstractionPattern {
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());
Expand All @@ -914,17 +778,12 @@ class AbstractionPattern {
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:
Expand All @@ -951,11 +810,6 @@ class AbstractionPattern {
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:
Expand All @@ -982,11 +836,6 @@ class AbstractionPattern {
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");
Expand All @@ -996,18 +845,10 @@ class AbstractionPattern {
/// 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;
Expand Down
14 changes: 14 additions & 0 deletions include/swift/SIL/TypeLowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
Loading