@@ -117,7 +117,12 @@ struct PrintSExpression : public UnifiedExpressionVisitor<PrintSExpression> {
117117
118118 Module* currModule = nullptr ;
119119 Function* currFunction = nullptr ;
120- Function::DebugLocation lastPrintedLocation;
120+ // Keep track of the last printed debug location to avoid printing
121+ // repeated debug locations for children. nullopt means that we have
122+ // not yet printed any debug location, or that we last printed an
123+ // annotation indicating that the expression had no associated
124+ // debug location.
125+ std::optional<Function::DebugLocation> lastPrintedLocation;
121126 bool debugInfo;
122127
123128 // Used to print delegate's depth argument when it throws to the caller
@@ -247,7 +252,8 @@ struct PrintSExpression : public UnifiedExpressionVisitor<PrintSExpression> {
247252 return o;
248253 }
249254
250- void printDebugLocation (const Function::DebugLocation& location);
255+ void
256+ printDebugLocation (const std::optional<Function::DebugLocation>& location);
251257 void printDebugLocation (Expression* curr);
252258
253259 // Prints debug info for a delimiter in an expression.
@@ -2475,17 +2481,24 @@ std::ostream& PrintSExpression::printPrefixedTypes(const char* prefix,
24752481}
24762482
24772483void PrintSExpression::printDebugLocation (
2478- const Function::DebugLocation& location) {
2484+ const std::optional<Function::DebugLocation>& location) {
2485+ if (minify) {
2486+ return ;
2487+ }
24792488 // Do not skip repeated debug info in full mode, for less-confusing debugging:
24802489 // full mode prints out everything in the most verbose manner.
24812490 if (lastPrintedLocation == location && indent > lastPrintIndent && !full) {
24822491 return ;
24832492 }
24842493 lastPrintedLocation = location;
24852494 lastPrintIndent = indent;
2486- auto fileName = currModule->debugInfoFileNames [location.fileIndex ];
2487- o << " ;;@ " << fileName << " :" << location.lineNumber << " :"
2488- << location.columnNumber << ' \n ' ;
2495+ if (!location) {
2496+ o << " ;;@\n " ;
2497+ } else {
2498+ auto fileName = currModule->debugInfoFileNames [location->fileIndex ];
2499+ o << " ;;@ " << fileName << " :" << location->lineNumber << " :"
2500+ << location->columnNumber << ' \n ' ;
2501+ }
24892502 doIndent (o, indent);
24902503}
24912504
@@ -2496,6 +2509,8 @@ void PrintSExpression::printDebugLocation(Expression* curr) {
24962509 auto iter = debugLocations.find (curr);
24972510 if (iter != debugLocations.end ()) {
24982511 printDebugLocation (iter->second );
2512+ } else {
2513+ printDebugLocation (std::nullopt );
24992514 }
25002515 // show a binary position, if there is one
25012516 if (debugInfo) {
@@ -2958,7 +2973,7 @@ void PrintSExpression::visitFunction(Function* curr) {
29582973void PrintSExpression::visitImportedFunction (Function* curr) {
29592974 doIndent (o, indent);
29602975 currFunction = curr;
2961- lastPrintedLocation = { 0 , 0 , 0 } ;
2976+ lastPrintedLocation = std:: nullopt ;
29622977 o << ' (' ;
29632978 emitImportHeader (curr);
29642979 handleSignature (curr->type , curr->name );
@@ -2969,7 +2984,8 @@ void PrintSExpression::visitImportedFunction(Function* curr) {
29692984void PrintSExpression::visitDefinedFunction (Function* curr) {
29702985 doIndent (o, indent);
29712986 currFunction = curr;
2972- lastPrintedLocation = {0 , 0 , 0 };
2987+ lastPrintedLocation = std::nullopt ;
2988+ lastPrintIndent = 0 ;
29732989 if (currFunction->prologLocation .size ()) {
29742990 printDebugLocation (*currFunction->prologLocation .begin ());
29752991 }
0 commit comments