@@ -437,14 +437,13 @@ void SILType::dump() const {
437
437
}
438
438
439
439
// / Prints the name and type of the given SIL function with the given
440
- // / `PrintOptions`. Mutates `printOptions`, setting `GenericEnv` and
441
- // / `AlternativeTypeNames `.
442
- static void printSILFunctionNameAndType (llvm::raw_ostream &OS,
443
- const SILFunction *function,
444
- PrintOptions &printOptions ) {
440
+ // / `PrintOptions`. Computes mapping for sugared type names and stores the
441
+ // / result in `sugaredTypeNames `.
442
+ static void printSILFunctionNameAndType (
443
+ llvm::raw_ostream &OS, const SILFunction *function,
444
+ llvm::DenseMap<CanType, Identifier> &sugaredTypeNames ) {
445
445
function->printName (OS);
446
446
OS << " : $" ;
447
- llvm::DenseMap<CanType, Identifier> aliases;
448
447
auto genSig = function->getLoweredFunctionType ()->getSubstGenericSignature ();
449
448
auto *genEnv = function->getGenericEnvironment ();
450
449
// If `genSig` and `genEnv` are both defined, get sugared names of generic
@@ -470,22 +469,24 @@ static void printSILFunctionNameAndType(llvm::raw_ostream &OS,
470
469
continue ;
471
470
// Otherwise, add sugared name mapping for the type (and its archetype, if
472
471
// defined).
473
- aliases [paramTy->getCanonicalType ()] = name;
472
+ sugaredTypeNames [paramTy->getCanonicalType ()] = name;
474
473
if (auto *archetypeTy =
475
474
genEnv->mapTypeIntoContext (paramTy)->getAs <ArchetypeType>())
476
- aliases [archetypeTy->getCanonicalType ()] = name;
475
+ sugaredTypeNames [archetypeTy->getCanonicalType ()] = name;
477
476
}
478
477
}
478
+ auto printOptions = PrintOptions::printSIL ();
479
479
printOptions.GenericEnv = genEnv;
480
- printOptions.AlternativeTypeNames = aliases.empty () ? nullptr : &aliases;
480
+ printOptions.AlternativeTypeNames =
481
+ sugaredTypeNames.empty () ? nullptr : &sugaredTypeNames;
481
482
function->getLoweredFunctionType ()->print (OS, printOptions);
482
483
}
483
484
484
485
// / Prints the name and type of the given SIL function.
485
486
static void printSILFunctionNameAndType (llvm::raw_ostream &OS,
486
487
const SILFunction *function) {
487
- auto printOptions = PrintOptions::printSIL () ;
488
- printSILFunctionNameAndType (OS, function, printOptions );
488
+ llvm::DenseMap<CanType, Identifier> sugaredTypeNames ;
489
+ printSILFunctionNameAndType (OS, function, sugaredTypeNames );
489
490
}
490
491
491
492
namespace {
@@ -2513,16 +2514,17 @@ void SILFunction::print(SILPrintContext &PrintCtx) const {
2513
2514
if (!isExternalDeclaration () && hasOwnership ())
2514
2515
OS << " [ossa] " ;
2515
2516
2516
- auto printOptions = PrintOptions::printSIL () ;
2517
- printSILFunctionNameAndType (OS, this , printOptions );
2517
+ llvm::DenseMap<CanType, Identifier> sugaredTypeNames ;
2518
+ printSILFunctionNameAndType (OS, this , sugaredTypeNames );
2518
2519
2519
2520
if (!isExternalDeclaration ()) {
2520
2521
if (auto eCount = getEntryCount ()) {
2521
2522
OS << " !function_entry_count(" << eCount.getValue () << " )" ;
2522
2523
}
2523
2524
OS << " {\n " ;
2524
2525
2525
- SILPrinter (PrintCtx, printOptions.AlternativeTypeNames ).print (this );
2526
+ SILPrinter (PrintCtx, sugaredTypeNames.empty () ? nullptr : &sugaredTypeNames)
2527
+ .print (this );
2526
2528
OS << " } // end sil function '" << getName () << ' \' ' ;
2527
2529
}
2528
2530
0 commit comments