Skip to content

Typed throws minor fixes #69741

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 3 commits into from
Nov 9, 2023
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
3 changes: 2 additions & 1 deletion include/swift/SIL/SILFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -1455,7 +1455,8 @@ class SILFunction
ArrayRef<SILArgument *> getArgumentsWithoutIndirectResults() const {
assert(!empty() && "Cannot get arguments of a function without a body");
return begin()->getArguments().slice(
getConventions().getNumIndirectSILResults());
getConventions().getNumIndirectSILResults() +
getConventions().getNumIndirectSILErrorResults());
}

const SILArgument *getSelfArgument() const {
Expand Down
4 changes: 3 additions & 1 deletion include/swift/SIL/SILInstruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -2902,7 +2902,9 @@ class ApplyInstBase<Impl, Base, true>
return getSubstCalleeConv().hasIndirectSILResults();
}
unsigned getNumIndirectResults() const {
return getSubstCalleeConv().getNumIndirectSILResults();
auto fnConv = getSubstCalleeConv();
return fnConv.getNumIndirectSILResults() +
fnConv.getNumIndirectSILErrorResults();
}

bool hasSelfArgument() const {
Expand Down
1 change: 1 addition & 0 deletions lib/IRGen/IRGenDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2476,6 +2476,7 @@ IRGenDebugInfoImpl::emitFunction(const SILDebugScope *DS, llvm::Function *Fn,
llvm::DITypeArray Error = nullptr;
if (FnTy && (Opts.DebugInfoLevel > IRGenDebugInfoLevel::LineTables))
if (auto ErrorInfo = FnTy->getOptionalErrorResult()) {
GenericContextScope scope(IGM, FnTy->getInvocationGenericSignature());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this is only needed when creating the function signature and not in the body of the function?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should verify that; it didn't show up as a crash when putting typed throws into the standard library, but it might be because we aren't providing correct debug info for SIL-level indirect error results.

SILType SILTy = IGM.silConv.getSILType(
*ErrorInfo, FnTy, IGM.getMaximalTypeExpansionContext());
auto DTI = DebugTypeInfo::getFromTypeInfo(
Expand Down
23 changes: 23 additions & 0 deletions lib/SILOptimizer/Utils/SILInliner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,29 @@ void SILInlineCloner::visitTerminator(SILBasicBlock *BB) {
return;
}
}

// Modify throw_addr terminators to branch to the error-return BB, rather than
// trying to clone the ThrowAddrInst.
if (auto *TAI = dyn_cast<ThrowAddrInst>(Terminator)) {
SILLocation Loc = getOpLocation(TAI->getLoc());
switch (Apply.getKind()) {
case FullApplySiteKind::ApplyInst:
assert(cast<ApplyInst>(Apply)->isNonThrowing()
&& "apply of a function with error result must be non-throwing");
getBuilder().createUnreachable(Loc);
return;
case FullApplySiteKind::BeginApplyInst:
assert(cast<BeginApplyInst>(Apply)->isNonThrowing()
&& "apply of a function with error result must be non-throwing");
getBuilder().createUnreachable(Loc);
return;
case FullApplySiteKind::TryApplyInst:
auto tryAI = cast<TryApplyInst>(Apply);
getBuilder().createBranch(Loc, tryAI->getErrorBB());
return;
}
}

// Otherwise use normal visitor, which clones the existing instruction
// but remaps basic blocks and values.
visit(Terminator);
Expand Down