Skip to content

Commit f9570b2

Browse files
[NFC] Pass full convention printing boolean for types etc.
When -experimental-print-full-convention is set, we should be printing the full convention in diagnostics, doc comments etc.
1 parent 56b38b9 commit f9570b2

13 files changed

+73
-36
lines changed

Diff for: include/swift/AST/PrintOptions.h

+14-9
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,8 @@ struct PrintOptions {
504504
}
505505

506506
/// Retrieve the set of options suitable for diagnostics printing.
507-
static PrintOptions printForDiagnostics(AccessLevel accessFilter) {
507+
static PrintOptions printForDiagnostics(AccessLevel accessFilter,
508+
bool printFullConvention) {
508509
PrintOptions result = printVerbose();
509510
result.PrintAccess = true;
510511
result.Indent = 4;
@@ -523,12 +524,16 @@ struct PrintOptions {
523524
QualifyNestedDeclarations::TypesOnly;
524525
result.PrintDocumentationComments = false;
525526
result.PrintCurrentMembersOnly = true;
527+
if (printFullConvention)
528+
result.PrintFunctionRepresentationAttrs =
529+
PrintOptions::FunctionRepresentationMode::Full;
526530
return result;
527531
}
528532

529533
/// Retrieve the set of options suitable for interface generation.
530-
static PrintOptions printInterface() {
531-
PrintOptions result = printForDiagnostics(AccessLevel::Public);
534+
static PrintOptions printInterface(bool printFullConvention) {
535+
PrintOptions result =
536+
printForDiagnostics(AccessLevel::Public, printFullConvention);
532537
result.SkipUnavailable = true;
533538
result.SkipImplicit = true;
534539
result.SkipSwiftPrivateClangDecls = true;
@@ -565,8 +570,8 @@ struct PrintOptions {
565570
/// Retrieve the set of options suitable for "Generated Interfaces", which
566571
/// are a prettified representation of the public API of a module, to be
567572
/// displayed to users in an editor.
568-
static PrintOptions printModuleInterface();
569-
static PrintOptions printTypeInterface(Type T);
573+
static PrintOptions printModuleInterface(bool printFullConvention);
574+
static PrintOptions printTypeInterface(Type T, bool printFullConvention);
570575

571576
void setBaseType(Type T);
572577

@@ -582,16 +587,16 @@ struct PrintOptions {
582587
}
583588

584589
/// Retrieve the print options that are suitable to print the testable interface.
585-
static PrintOptions printTestableInterface() {
586-
PrintOptions result = printInterface();
590+
static PrintOptions printTestableInterface(bool printFullConvention) {
591+
PrintOptions result = printInterface(printFullConvention);
587592
result.AccessFilter = AccessLevel::Internal;
588593
return result;
589594
}
590595

591596
/// Retrieve the print options that are suitable to print interface for a
592597
/// swift file.
593-
static PrintOptions printSwiftFileInterface() {
594-
PrintOptions result = printInterface();
598+
static PrintOptions printSwiftFileInterface(bool printFullConvention) {
599+
PrintOptions result = printInterface(printFullConvention);
595600
result.AccessFilter = AccessLevel::Internal;
596601
result.EmptyLineBetweenMembers = true;
597602
return result;

Diff for: include/swift/Basic/LangOptions.h

+3
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,9 @@ namespace swift {
547547
/// Enable experimental support for one-way constraints for the
548548
/// parameters of closures.
549549
bool EnableOneWayClosureParameters = false;
550+
551+
/// See \ref FrontendOptions.PrintFullConvention
552+
bool PrintFullConvention = false;
550553
};
551554

552555
/// Options for controlling the behavior of the Clang importer.

Diff for: lib/AST/DiagnosticEngine.cpp

+20-7
Original file line numberDiff line numberDiff line change
@@ -442,12 +442,13 @@ static bool shouldShowAKA(Type type, StringRef typeName) {
442442
/// with the same string representation, it should be qualified during
443443
/// formatting.
444444
static bool typeSpellingIsAmbiguous(Type type,
445-
ArrayRef<DiagnosticArgument> Args) {
445+
ArrayRef<DiagnosticArgument> Args,
446+
PrintOptions &PO) {
446447
for (auto arg : Args) {
447448
if (arg.getKind() == DiagnosticArgumentKind::Type) {
448449
auto argType = arg.getAsType();
449450
if (argType && !argType->isEqual(type) &&
450-
argType->getWithoutParens().getString() == type.getString()) {
451+
argType->getWithoutParens().getString(PO) == type.getString(PO)) {
451452
return true;
452453
}
453454
}
@@ -543,12 +544,22 @@ static void formatDiagnosticArgument(StringRef Modifier,
543544
Type type;
544545
bool needsQualification = false;
545546

547+
// TODO: We should use PrintOptions::printForDiagnostic here, or we should
548+
// rename that method.
549+
PrintOptions printOptions{};
550+
546551
if (Arg.getKind() == DiagnosticArgumentKind::Type) {
547552
type = Arg.getAsType()->getWithoutParens();
548-
needsQualification = typeSpellingIsAmbiguous(type, Args);
553+
if (type->getASTContext().TypeCheckerOpts.PrintFullConvention)
554+
printOptions.PrintFunctionRepresentationAttrs =
555+
PrintOptions::FunctionRepresentationMode::Full;
556+
needsQualification = typeSpellingIsAmbiguous(type, Args, printOptions);
549557
} else {
550558
assert(Arg.getKind() == DiagnosticArgumentKind::FullyQualifiedType);
551559
type = Arg.getAsFullyQualifiedType().getType()->getWithoutParens();
560+
if (type->getASTContext().TypeCheckerOpts.PrintFullConvention)
561+
printOptions.PrintFunctionRepresentationAttrs =
562+
PrintOptions::FunctionRepresentationMode::Full;
552563
needsQualification = true;
553564
}
554565

@@ -574,12 +585,11 @@ static void formatDiagnosticArgument(StringRef Modifier,
574585
auto descriptiveKind = opaqueTypeDecl->getDescriptiveKind();
575586

576587
Out << llvm::format(FormatOpts.OpaqueResultFormatString.c_str(),
577-
type->getString().c_str(),
588+
type->getString(printOptions).c_str(),
578589
Decl::getDescriptiveKindName(descriptiveKind).data(),
579590
NamingDeclText.c_str());
580591

581592
} else {
582-
auto printOptions = PrintOptions();
583593
printOptions.FullyQualifiedTypes = needsQualification;
584594
std::string typeName = type->getString(printOptions);
585595

@@ -1016,8 +1026,11 @@ DiagnosticEngine::diagnosticInfoForDiagnostic(const Diagnostic &diagnostic) {
10161026
// Pretty-print the declaration we've picked.
10171027
llvm::raw_svector_ostream out(buffer);
10181028
TrackingPrinter printer(entries, out, bufferAccessLevel);
1019-
ppDecl->print(printer,
1020-
PrintOptions::printForDiagnostics(bufferAccessLevel));
1029+
ppDecl->print(
1030+
printer,
1031+
PrintOptions::printForDiagnostics(
1032+
bufferAccessLevel,
1033+
decl->getASTContext().TypeCheckerOpts.PrintFullConvention));
10211034
}
10221035

10231036
// Build a buffer with the pretty-printed declaration.

Diff for: lib/Frontend/CompilerInvocation.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,9 @@ static bool ParseTypeCheckerArgs(TypeCheckerOptions &Opts, ArgList &Args,
770770
Opts.EnableOneWayClosureParameters |=
771771
Args.hasArg(OPT_experimental_one_way_closure_params);
772772

773+
Opts.PrintFullConvention |=
774+
Args.hasArg(OPT_experimental_print_full_convention);
775+
773776
Opts.DebugConstraintSolver |= Args.hasArg(OPT_debug_constraints);
774777
Opts.DebugGenericSignatures |= Args.hasArg(OPT_debug_generic_signatures);
775778

Diff for: lib/FrontendTool/FrontendTool.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,8 @@ static void dumpAPIIfNeeded(const CompilerInstance &Instance) {
900900
SmallString<512> TempBuf;
901901
llvm::raw_svector_ostream TempOS(TempBuf);
902902

903-
PrintOptions PO = PrintOptions::printInterface();
903+
PrintOptions PO = PrintOptions::printInterface(
904+
Invocation.getFrontendOptions().PrintFullConvention);
904905
PO.PrintOriginalSourceText = true;
905906
PO.Indent = 2;
906907
PO.PrintAccess = false;

Diff for: lib/IDE/CommentConversion.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,8 @@ visitDocComment(const DocComment *DC, TypeOrExtensionDecl SynthesizedTarget) {
359359
}
360360

361361
{
362-
PrintOptions PO = PrintOptions::printInterface();
362+
PrintOptions PO = PrintOptions::printInterface(
363+
D->getASTContext().TypeCheckerOpts.PrintFullConvention);
363364
PO.PrintAccess = false;
364365
PO.AccessFilter = AccessLevel::Private;
365366
PO.PrintDocumentationComments = false;

Diff for: lib/IDE/IDETypeChecking.cpp

+7-5
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,15 @@ class ModulePrinterPrintableChecker: public ShouldPrintChecker {
5858
}
5959
};
6060

61-
PrintOptions PrintOptions::printModuleInterface() {
62-
PrintOptions result = printInterface();
61+
PrintOptions PrintOptions::printModuleInterface(bool printFullConvention) {
62+
PrintOptions result = printInterface(printFullConvention);
6363
result.CurrentPrintabilityChecker.reset(new ModulePrinterPrintableChecker());
6464
return result;
6565
}
6666

67-
PrintOptions PrintOptions::printTypeInterface(Type T) {
68-
PrintOptions result = printModuleInterface();
67+
PrintOptions PrintOptions::printTypeInterface(Type T,
68+
bool printFullConvention) {
69+
PrintOptions result = printModuleInterface(printFullConvention);
6970
result.PrintExtensionFromConformingProtocols = true;
7071
result.TransformContext = TypeTransformContext(T);
7172
result.printExtensionContentAsMembers = [T](const ExtensionDecl *ED) {
@@ -77,7 +78,8 @@ PrintOptions PrintOptions::printTypeInterface(Type T) {
7778
}
7879

7980
PrintOptions PrintOptions::printDocInterface() {
80-
PrintOptions result = PrintOptions::printModuleInterface();
81+
PrintOptions result =
82+
PrintOptions::printModuleInterface(/*printFullConvention*/ false);
8183
result.PrintAccess = false;
8284
result.SkipUnavailable = false;
8385
result.ExcludeAttrList.push_back(DAK_Available);

Diff for: lib/IDE/ModuleInterfacePrinting.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,9 @@ printTypeInterface(ModuleDecl *M, Type Ty, ASTPrinter &Printer,
172172
}
173173
Ty = Ty->getRValueType();
174174
if (auto ND = Ty->getNominalOrBoundGenericNominal()) {
175-
PrintOptions Options = PrintOptions::printTypeInterface(Ty.getPointer());
175+
PrintOptions Options = PrintOptions::printTypeInterface(
176+
Ty.getPointer(),
177+
Ty->getASTContext().TypeCheckerOpts.PrintFullConvention);
176178
ND->print(Printer, Options);
177179
printTypeNameToString(Ty, TypeName);
178180
return false;

Diff for: lib/Sema/TypeCheckProtocol.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -3085,8 +3085,8 @@ printRequirementStub(ValueDecl *Requirement, DeclContext *Adopter,
30853085
}
30863086
}
30873087

3088-
PrintOptions Options =
3089-
PrintOptions::printForDiagnostics(AccessLevel::Private);
3088+
PrintOptions Options = PrintOptions::printForDiagnostics(
3089+
AccessLevel::Private, Ctx.TypeCheckerOpts.PrintFullConvention);
30903090
Options.PrintDocumentationComments = false;
30913091
Options.PrintAccess = false;
30923092
Options.SkipAttributes = true;

Diff for: lib/SymbolGraphGen/SymbolGraph.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -339,9 +339,10 @@ void SymbolGraph::recordConformanceSynthesizedMemberRelationships(Symbol S) {
339339
return;
340340
}
341341

342-
SynthesizedExtensionAnalyzer
343-
ExtensionAnalyzer(const_cast<NominalTypeDecl*>(OwningNominal),
344-
PrintOptions::printModuleInterface());
342+
SynthesizedExtensionAnalyzer ExtensionAnalyzer(
343+
const_cast<NominalTypeDecl *>(OwningNominal),
344+
PrintOptions::printModuleInterface(
345+
OwningNominal->getASTContext().TypeCheckerOpts.PrintFullConvention));
345346
auto MergeGroupKind = SynthesizedExtensionAnalyzer::MergeGroupKind::All;
346347
ExtensionAnalyzer.forEachExtensionMergeGroup(MergeGroupKind,
347348
[&](ArrayRef<ExtensionInfo> ExtensionInfos){

Diff for: tools/SourceKit/lib/SwiftLang/SwiftEditorInterfaceGen.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,8 @@ static bool getModuleInterfaceInfo(ASTContext &Ctx,
286286
return true;
287287
}
288288

289-
PrintOptions Options = PrintOptions::printModuleInterface();
289+
PrintOptions Options = PrintOptions::printModuleInterface(
290+
Ctx.TypeCheckerOpts.PrintFullConvention);
290291
ModuleTraversalOptions TraversalOptions = None; // Don't print submodules.
291292
SmallString<128> Text;
292293
llvm::raw_svector_ostream OS(Text);
@@ -313,7 +314,8 @@ static bool getHeaderInterfaceInfo(ASTContext &Ctx,
313314
return true;
314315
}
315316

316-
PrintOptions Options = PrintOptions::printModuleInterface();
317+
PrintOptions Options = PrintOptions::printModuleInterface(
318+
Ctx.TypeCheckerOpts.PrintFullConvention);
317319

318320
SmallString<128> Text;
319321
llvm::raw_svector_ostream OS(Text);
@@ -336,7 +338,8 @@ SwiftInterfaceGenContext::createForSwiftSource(StringRef DocumentName,
336338
IFaceGenCtx->Impl.ModuleOrHeaderName = SourceFileName.str();
337339
IFaceGenCtx->Impl.AstUnit = AstUnit;
338340

339-
PrintOptions Options = PrintOptions::printSwiftFileInterface();
341+
PrintOptions Options = PrintOptions::printSwiftFileInterface(
342+
Invocation.getFrontendOptions().PrintFullConvention);
340343
SmallString<128> Text;
341344
llvm::raw_svector_ostream OS(Text);
342345
AnnotatingPrinter Printer(IFaceGenCtx->Impl.Info, OS);

Diff for: tools/SourceKit/lib/SwiftLang/SwiftSourceDocInfo.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -760,8 +760,9 @@ static bool passCursorInfoForDecl(SourceFile* SF,
760760
bool InSynthesizedExtension = false;
761761
if (BaseType) {
762762
if (auto Target = BaseType->getAnyNominal()) {
763-
SynthesizedExtensionAnalyzer Analyzer(Target,
764-
PrintOptions::printModuleInterface());
763+
SynthesizedExtensionAnalyzer Analyzer(
764+
Target, PrintOptions::printModuleInterface(
765+
Invoc.getFrontendOptions().PrintFullConvention));
765766
InSynthesizedExtension = Analyzer.isInSynthesizedExtension(VD);
766767
}
767768
}

Diff for: tools/swift-ide-test/swift-ide-test.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -2733,7 +2733,8 @@ static int doPrintSwiftFileInterface(const CompilerInvocation &InitInvok,
27332733
else
27342734
Printer.reset(new StreamPrinter(llvm::outs()));
27352735

2736-
PrintOptions Options = PrintOptions::printSwiftFileInterface();
2736+
PrintOptions Options = PrintOptions::printSwiftFileInterface(
2737+
InitInvok.getFrontendOptions().PrintFullConvention);
27372738
if (options::PrintOriginalSourceText)
27382739
Options.PrintOriginalSourceText = true;
27392740
printSwiftSourceInterface(*CI.getPrimarySourceFile(), *Printer, Options);
@@ -3946,7 +3947,8 @@ int main(int argc, char *argv[]) {
39463947

39473948
PrintOptions PrintOpts;
39483949
if (options::PrintInterface) {
3949-
PrintOpts = PrintOptions::printModuleInterface();
3950+
PrintOpts = PrintOptions::printModuleInterface(
3951+
InitInvok.getFrontendOptions().PrintFullConvention);
39503952
} else if (options::PrintInterfaceForDoc) {
39513953
PrintOpts = PrintOptions::printDocInterface();
39523954
} else {

0 commit comments

Comments
 (0)