Skip to content

Commit 18324fe

Browse files
authored
Merge pull request #1105 from swiftwasm/master
[pull] swiftwasm from master
2 parents 7f9d9f6 + 45a78e4 commit 18324fe

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+288
-145
lines changed

include/swift/AST/SILGenRequests.h

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -40,38 +40,39 @@ template<typename Request>
4040
void reportEvaluatedRequest(UnifiedStatsReporter &stats,
4141
const Request &request);
4242

43-
struct SILGenDescriptor {
43+
/// Describes a file or module to be lowered to SIL.
44+
struct ASTLoweringDescriptor {
4445
llvm::PointerUnion<FileUnit *, ModuleDecl *> context;
4546
Lowering::TypeConverter &conv;
4647
const SILOptions &opts;
4748

48-
friend llvm::hash_code hash_value(const SILGenDescriptor &owner) {
49+
friend llvm::hash_code hash_value(const ASTLoweringDescriptor &owner) {
4950
return llvm::hash_combine(owner.context, (void *)&owner.conv,
5051
(void *)&owner.opts);
5152
}
5253

53-
friend bool operator==(const SILGenDescriptor &lhs,
54-
const SILGenDescriptor &rhs) {
54+
friend bool operator==(const ASTLoweringDescriptor &lhs,
55+
const ASTLoweringDescriptor &rhs) {
5556
return lhs.context == rhs.context &&
5657
&lhs.conv == &rhs.conv &&
5758
&lhs.opts == &rhs.opts;
5859
}
5960

60-
friend bool operator!=(const SILGenDescriptor &lhs,
61-
const SILGenDescriptor &rhs) {
61+
friend bool operator!=(const ASTLoweringDescriptor &lhs,
62+
const ASTLoweringDescriptor &rhs) {
6263
return !(lhs == rhs);
6364
}
6465

6566
public:
66-
static SILGenDescriptor forFile(FileUnit &sf, Lowering::TypeConverter &conv,
67-
const SILOptions &opts) {
68-
return SILGenDescriptor{&sf, conv, opts};
67+
static ASTLoweringDescriptor
68+
forFile(FileUnit &sf, Lowering::TypeConverter &conv, const SILOptions &opts) {
69+
return ASTLoweringDescriptor{&sf, conv, opts};
6970
}
7071

71-
static SILGenDescriptor forWholeModule(ModuleDecl *mod,
72-
Lowering::TypeConverter &conv,
73-
const SILOptions &opts) {
74-
return SILGenDescriptor{mod, conv, opts};
72+
static ASTLoweringDescriptor forWholeModule(ModuleDecl *mod,
73+
Lowering::TypeConverter &conv,
74+
const SILOptions &opts) {
75+
return ASTLoweringDescriptor{mod, conv, opts};
7576
}
7677

7778
/// For a single file input, returns a single element array containing that
@@ -83,13 +84,17 @@ struct SILGenDescriptor {
8384
SourceFile *getSourceFileToParse() const;
8485
};
8586

86-
void simple_display(llvm::raw_ostream &out, const SILGenDescriptor &d);
87+
void simple_display(llvm::raw_ostream &out, const ASTLoweringDescriptor &d);
8788

88-
SourceLoc extractNearestSourceLoc(const SILGenDescriptor &desc);
89+
SourceLoc extractNearestSourceLoc(const ASTLoweringDescriptor &desc);
8990

90-
class SILGenerationRequest
91+
/// Lowers a file or module to SIL. In most cases this involves transforming
92+
/// a file's AST into SIL, through SILGen. However it can also handle files
93+
/// containing SIL in textual or binary form, which will be parsed or
94+
/// deserialized as needed.
95+
class ASTLoweringRequest
9196
: public SimpleRequest<
92-
SILGenerationRequest, std::unique_ptr<SILModule>(SILGenDescriptor),
97+
ASTLoweringRequest, std::unique_ptr<SILModule>(ASTLoweringDescriptor),
9398
RequestFlags::Uncached | RequestFlags::DependencySource> {
9499
public:
95100
using SimpleRequest::SimpleRequest;
@@ -98,8 +103,8 @@ class SILGenerationRequest
98103
friend SimpleRequest;
99104

100105
// Evaluation.
101-
std::unique_ptr<SILModule>
102-
evaluate(Evaluator &evaluator, SILGenDescriptor desc) const;
106+
std::unique_ptr<SILModule> evaluate(Evaluator &evaluator,
107+
ASTLoweringDescriptor desc) const;
103108

104109
public:
105110
// Incremental dependencies.
@@ -110,7 +115,7 @@ class SILGenerationRequest
110115
/// Parses a .sil file into a SILModule.
111116
class ParseSILModuleRequest
112117
: public SimpleRequest<ParseSILModuleRequest,
113-
std::unique_ptr<SILModule>(SILGenDescriptor),
118+
std::unique_ptr<SILModule>(ASTLoweringDescriptor),
114119
RequestFlags::Uncached> {
115120
public:
116121
using SimpleRequest::SimpleRequest;
@@ -119,8 +124,8 @@ class ParseSILModuleRequest
119124
friend SimpleRequest;
120125

121126
// Evaluation.
122-
std::unique_ptr<SILModule>
123-
evaluate(Evaluator &evaluator, SILGenDescriptor desc) const;
127+
std::unique_ptr<SILModule> evaluate(Evaluator &evaluator,
128+
ASTLoweringDescriptor desc) const;
124129
};
125130

126131
/// The zone number for SILGen.

include/swift/AST/SILGenTypeIDZone.def

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
//
1515
//===----------------------------------------------------------------------===//
1616

17-
SWIFT_REQUEST(SILGen, SILGenerationRequest,
18-
std::unique_ptr<SILModule>(SILGenDescriptor),
17+
SWIFT_REQUEST(SILGen, ASTLoweringRequest,
18+
std::unique_ptr<SILModule>(ASTLoweringDescriptor),
1919
Uncached, NoLocationInfo)
2020
SWIFT_REQUEST(SILGen, ParseSILModuleRequest,
21-
std::unique_ptr<SILModule>(SILGenDescriptor),
21+
std::unique_ptr<SILModule>(ASTLoweringDescriptor),
2222
Uncached, NoLocationInfo)

include/swift/Basic/DiagnosticOptions.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ class DiagnosticOptions {
3232
VerifyAndApplyFixes
3333
} VerifyMode = NoVerify;
3434

35+
enum FormattingStyle { LLVM, Swift };
36+
3537
/// Indicates whether to allow diagnostics for \c <unknown> locations if
3638
/// \c VerifyMode is not \c NoVerify.
3739
bool VerifyIgnoreUnknown = false;
@@ -61,7 +63,7 @@ class DiagnosticOptions {
6163

6264
// If set to true, use the more descriptive experimental formatting style for
6365
// diagnostics.
64-
bool EnableExperimentalFormatting = false;
66+
FormattingStyle PrintedFormattingStyle = FormattingStyle::LLVM;
6567

6668
std::string DiagnosticDocumentationPath = "";
6769

include/swift/Frontend/PrintingDiagnosticConsumer.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
#ifndef SWIFT_PRINTINGDIAGNOSTICCONSUMER_H
1919
#define SWIFT_PRINTINGDIAGNOSTICCONSUMER_H
2020

21-
#include "swift/Basic/LLVM.h"
2221
#include "swift/AST/DiagnosticConsumer.h"
22+
#include "swift/Basic/DiagnosticOptions.h"
23+
#include "swift/Basic/LLVM.h"
2324

2425
#include "llvm/Support/raw_ostream.h"
2526
#include "llvm/Support/Process.h"
@@ -33,7 +34,8 @@ class PrintingDiagnosticConsumer : public DiagnosticConsumer {
3334
bool ForceColors = false;
3435
bool PrintEducationalNotes = false;
3536
bool DidErrorOccur = false;
36-
bool ExperimentalFormattingEnabled = false;
37+
DiagnosticOptions::FormattingStyle FormattingStyle =
38+
DiagnosticOptions::FormattingStyle::LLVM;
3739
// The current snippet used to display an error/warning/remark and the notes
3840
// implicitly associated with it. Uses `std::unique_ptr` so that
3941
// `AnnotatedSourceSnippet` can be forward declared.
@@ -65,7 +67,9 @@ class PrintingDiagnosticConsumer : public DiagnosticConsumer {
6567
PrintEducationalNotes = ShouldPrint;
6668
}
6769

68-
void enableExperimentalFormatting() { ExperimentalFormattingEnabled = true; }
70+
void setFormattingStyle(DiagnosticOptions::FormattingStyle style) {
71+
FormattingStyle = style;
72+
}
6973

7074
bool didErrorOccur() {
7175
return DidErrorOccur;

include/swift/Option/FrontendOptions.td

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,6 @@ def enable_cross_import_overlays : Flag<["-"], "enable-cross-import-overlays">,
131131
def disable_cross_import_overlays : Flag<["-"], "disable-cross-import-overlays">,
132132
HelpText<"Do not automatically import declared cross-import overlays.">;
133133

134-
def enable_experimental_diagnostic_formatting :
135-
Flag<["-"], "enable-experimental-diagnostic-formatting">,
136-
HelpText<"Enable experimental diagnostic formatting features.">;
137-
138134
def diagnostic_documentation_path
139135
: Separate<["-"], "diagnostic-documentation-path">, MetaVarName<"<path>">,
140136
HelpText<"Path to diagnostic documentation resources">;

include/swift/Option/Options.td

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,13 @@ def debug_diagnostic_names : Flag<["-"], "debug-diagnostic-names">,
370370
def print_educational_notes : Flag<["-"], "print-educational-notes">,
371371
Flags<[FrontendOption, DoesNotAffectIncrementalBuild]>,
372372
HelpText<"Include educational notes in printed diagnostic output, if available">;
373+
def diagnostic_style : Separate<["-"], "diagnostic-style">,
374+
Flags<[FrontendOption, DoesNotAffectIncrementalBuild]>,
375+
MetaVarName<"<style>">,
376+
HelpText<"The formatting style used when printing diagnostics ('swift' or 'llvm')">;
377+
def diagnostic_style_EQ : Joined<["-"], "diagnostic-style=">,
378+
Flags<[FrontendOption, DoesNotAffectIncrementalBuild]>,
379+
MetaVarName<"<style>">, Alias<diagnostic_style>;
373380

374381
def module_cache_path : Separate<["-"], "module-cache-path">,
375382
Flags<[FrontendOption, DoesNotAffectIncrementalBuild, ArgumentIsPath]>,

include/swift/Subsystems.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,13 @@ namespace swift {
172172
/// The module must contain source files. The optimizer will assume that the
173173
/// SIL of all files in the module is present in the SILModule.
174174
std::unique_ptr<SILModule>
175-
performSILGeneration(ModuleDecl *M, Lowering::TypeConverter &TC,
176-
const SILOptions &options);
175+
performASTLowering(ModuleDecl *M, Lowering::TypeConverter &TC,
176+
const SILOptions &options);
177177

178178
/// Turn a source file into SIL IR.
179179
std::unique_ptr<SILModule>
180-
performSILGeneration(FileUnit &SF, Lowering::TypeConverter &TC,
181-
const SILOptions &options);
180+
performASTLowering(FileUnit &SF, Lowering::TypeConverter &TC,
181+
const SILOptions &options);
182182

183183
using ModuleOrSourceFile = PointerUnion<ModuleDecl *, SourceFile *>;
184184

lib/Driver/ToolChains.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ void ToolChain::addCommonFrontendArgs(const OutputInfo &OI,
244244
inputArgs.AddLastArg(arguments, options::OPT_serialize_diagnostics_path);
245245
inputArgs.AddLastArg(arguments, options::OPT_debug_diagnostic_names);
246246
inputArgs.AddLastArg(arguments, options::OPT_print_educational_notes);
247+
inputArgs.AddLastArg(arguments, options::OPT_diagnostic_style);
247248
inputArgs.AddLastArg(arguments, options::OPT_enable_astscope_lookup);
248249
inputArgs.AddLastArg(arguments, options::OPT_disable_astscope_lookup);
249250
inputArgs.AddLastArg(arguments, options::OPT_disable_parser_lookup);

lib/Frontend/CompilerInvocation.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -874,19 +874,33 @@ static bool ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args,
874874
Opts.SkipDiagnosticPasses |= Args.hasArg(OPT_disable_diagnostic_passes);
875875
Opts.ShowDiagnosticsAfterFatalError |=
876876
Args.hasArg(OPT_show_diagnostics_after_fatal);
877+
877878
Opts.UseColor |=
878879
Args.hasFlag(OPT_color_diagnostics,
879880
OPT_no_color_diagnostics,
880881
/*Default=*/llvm::sys::Process::StandardErrHasColors());
882+
// If no style options are specified, default to LLVM style.
883+
Opts.PrintedFormattingStyle = DiagnosticOptions::FormattingStyle::LLVM;
884+
if (const Arg *arg = Args.getLastArg(OPT_diagnostic_style)) {
885+
StringRef contents = arg->getValue();
886+
if (contents == "llvm") {
887+
Opts.PrintedFormattingStyle = DiagnosticOptions::FormattingStyle::LLVM;
888+
} else if (contents == "swift") {
889+
Opts.PrintedFormattingStyle = DiagnosticOptions::FormattingStyle::Swift;
890+
} else {
891+
Diags.diagnose(SourceLoc(), diag::error_unsupported_option_argument,
892+
arg->getOption().getPrefixedName(), arg->getValue());
893+
return true;
894+
}
895+
}
896+
881897
Opts.FixitCodeForAllDiagnostics |= Args.hasArg(OPT_fixit_all);
882898
Opts.SuppressWarnings |= Args.hasArg(OPT_suppress_warnings);
883899
Opts.WarningsAsErrors = Args.hasFlag(options::OPT_warnings_as_errors,
884900
options::OPT_no_warnings_as_errors,
885901
false);
886902
Opts.PrintDiagnosticNames |= Args.hasArg(OPT_debug_diagnostic_names);
887903
Opts.PrintEducationalNotes |= Args.hasArg(OPT_print_educational_notes);
888-
Opts.EnableExperimentalFormatting |=
889-
Args.hasArg(OPT_enable_experimental_diagnostic_formatting);
890904
if (Arg *A = Args.getLastArg(OPT_diagnostic_documentation_path)) {
891905
Opts.DiagnosticDocumentationPath = A->getValue();
892906
}

lib/Frontend/ModuleInterfaceBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ bool ModuleInterfaceBuilder::buildSwiftModuleInternal(
209209
SILOptions &SILOpts = subInvocation.getSILOptions();
210210
auto Mod = SubInstance.getMainModule();
211211
auto &TC = SubInstance.getSILTypes();
212-
auto SILMod = performSILGeneration(Mod, TC, SILOpts);
212+
auto SILMod = performASTLowering(Mod, TC, SILOpts);
213213
if (!SILMod) {
214214
LLVM_DEBUG(llvm::dbgs() << "SILGen did not produce a module\n");
215215
return true;

0 commit comments

Comments
 (0)