Skip to content

[SILGen] Remove incomplete support for generic bridging functions in getBridgingFn #30325

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
merged 1 commit into from
Mar 10, 2020
Merged
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
39 changes: 15 additions & 24 deletions lib/SILGen/SILGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,8 @@ getBridgingFn(Optional<SILDeclRef> &cacheSlot,
SILGenModule &SGM,
Identifier moduleName,
StringRef functionName,
Optional<std::initializer_list<Type>> inputTypes,
Optional<Type> outputType) {
// FIXME: the optionality of outputType and the presence of trustInputTypes
// are hacks for cases where coming up with those types is complicated, i.e.,
// when dealing with generic bridging functions.

std::initializer_list<Type> inputTypes,
Type outputType) {
if (!cacheSlot) {
ASTContext &ctx = SGM.M.getASTContext();
ModuleDecl *mod = ctx.getLoadedModule(moduleName);
Expand Down Expand Up @@ -122,21 +118,18 @@ getBridgingFn(Optional<SILDeclRef> &cacheSlot,
return SGM.Types.getLoweredType(ty, TypeExpansionContext::minimal());
};

if (inputTypes) {
if (fnConv.hasIndirectSILResults()
|| funcTy->getNumParameters() != inputTypes->size()
|| !std::equal(
fnConv.getParameterSILTypes().begin(),
fnConv.getParameterSILTypes().end(),
makeTransformIterator(inputTypes->begin(), toSILType))) {
SGM.diagnose(fd->getLoc(), diag::bridging_function_not_correct_type,
moduleName.str(), functionName);
llvm::report_fatal_error("unable to set up the ObjC bridge!");
}
if (fnConv.hasIndirectSILResults()
|| funcTy->getNumParameters() != inputTypes.size()
|| !std::equal(
fnConv.getParameterSILTypes().begin(),
fnConv.getParameterSILTypes().end(),
makeTransformIterator(inputTypes.begin(), toSILType))) {
SGM.diagnose(fd->getLoc(), diag::bridging_function_not_correct_type,
moduleName.str(), functionName);
llvm::report_fatal_error("unable to set up the ObjC bridge!");
}

if (outputType
&& fnConv.getSingleSILResultType() != toSILType(*outputType)) {
if (fnConv.getSingleSILResultType() != toSILType(outputType)) {
SGM.diagnose(fd->getLoc(), diag::bridging_function_not_correct_type,
moduleName.str(), functionName);
llvm::report_fatal_error("unable to set up the ObjC bridge!");
Expand All @@ -153,16 +146,15 @@ getBridgingFn(Optional<SILDeclRef> &cacheSlot,
return *cacheSlot;
}

#define REQUIRED(X) { Types.get##X##Type() }
#define OPTIONAL(X) { OptionalType::get(Types.get##X##Type()) }
#define GENERIC(X) None
#define REQUIRED(X) Types.get##X##Type()
#define OPTIONAL(X) OptionalType::get(Types.get##X##Type())

#define GET_BRIDGING_FN(Module, FromKind, FromTy, ToKind, ToTy) \
SILDeclRef SILGenModule::get##FromTy##To##ToTy##Fn() { \
return getBridgingFn(FromTy##To##ToTy##Fn, *this, \
getASTContext().Id_##Module, \
"_convert" #FromTy "To" #ToTy, \
FromKind(FromTy), \
{ FromKind(FromTy) }, \
ToKind(ToTy)); \
}

Expand All @@ -178,7 +170,6 @@ GET_BRIDGING_FN(WinSDK, REQUIRED, WindowsBool, REQUIRED, Bool)
#undef GET_BRIDGING_FN
#undef REQUIRED
#undef OPTIONAL
#undef GENERIC

static FuncDecl *diagnoseMissingIntrinsic(SILGenModule &sgm,
SILLocation loc,
Expand Down