mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Push the debug info for the artificial error inout argument up to SIL.
Previously IRGen was using a heuristic to assign the argument number to the $error variable that was not generally correct for optimizaed code. This patch inserts a debug_value instruction in SILGen and thus assigns the ArgNo together with all the other function arguments. This is more robust and faster than than the old heuristic. <rdar://problem/28748323>
This commit is contained in:
@@ -410,9 +410,9 @@ static void emitCaptureArguments(SILGenFunction &gen, CapturedValue capture,
|
||||
|
||||
void SILGenFunction::emitProlog(AnyFunctionRef TheClosure,
|
||||
ArrayRef<ParameterList*> paramPatterns,
|
||||
Type resultType) {
|
||||
unsigned ArgNo =
|
||||
emitProlog(paramPatterns, resultType, TheClosure.getAsDeclContext());
|
||||
Type resultType, bool throws) {
|
||||
unsigned ArgNo = emitProlog(paramPatterns, resultType,
|
||||
TheClosure.getAsDeclContext(), throws);
|
||||
|
||||
// Emit the capture argument variables. These are placed last because they
|
||||
// become the first curry level of the SIL function.
|
||||
@@ -457,10 +457,13 @@ static void emitIndirectResultParameters(SILGenFunction &gen, Type resultType,
|
||||
auto arg =
|
||||
new (gen.SGM.M) SILArgument(gen.F.begin(), resultTI.getLoweredType(), var);
|
||||
(void) arg;
|
||||
|
||||
|
||||
}
|
||||
|
||||
unsigned SILGenFunction::emitProlog(ArrayRef<ParameterList*> paramLists,
|
||||
Type resultType, DeclContext *DC) {
|
||||
unsigned SILGenFunction::emitProlog(ArrayRef<ParameterList *> paramLists,
|
||||
Type resultType, DeclContext *DC,
|
||||
bool throws) {
|
||||
// Create the indirect result parameters.
|
||||
emitIndirectResultParameters(*this, resultType, DC);
|
||||
|
||||
@@ -473,6 +476,21 @@ unsigned SILGenFunction::emitProlog(ArrayRef<ParameterList*> paramLists,
|
||||
for (auto ¶m : *paramList)
|
||||
emitter.emitParam(param);
|
||||
}
|
||||
return emitter.getNumArgs();
|
||||
|
||||
// Record the ArgNo of the artificial $error inout argument.
|
||||
unsigned ArgNo = emitter.getNumArgs();
|
||||
if (throws) {
|
||||
RegularLocation Loc{SourceLoc()};
|
||||
if (auto *AFD = dyn_cast<AbstractFunctionDecl>(DC))
|
||||
Loc = AFD->getThrowsLoc();
|
||||
else if (auto *ACE = dyn_cast<AbstractClosureExpr>(DC))
|
||||
Loc = ACE->getLoc();
|
||||
auto NativeErrorTy = SILType::getExceptionType(getASTContext());
|
||||
ManagedValue Undef = emitUndef(Loc, NativeErrorTy);
|
||||
B.createDebugValue(Loc, Undef.getValue(),
|
||||
{"$error", /*Constant*/ false, ++ArgNo});
|
||||
}
|
||||
|
||||
return ArgNo;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user