Skip to content

Commit caf026f

Browse files
authored
Resolve conflicts with master (#727)
Yet another conflict with OpenBSD ifdefs 🙂
1 parent f515e52 commit caf026f

32 files changed

+319
-219
lines changed

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ ERROR(error_unsupported_target_arch, none,
3939
ERROR(error_unsupported_opt_for_target, none,
4040
"unsupported option '%0' for target '%1'", (StringRef, StringRef))
4141

42-
WARNING(warning_inferred_simulator_target,none,
43-
"inferring simulator environment for target '%0'; "
44-
"use '-target %1' instead", (StringRef, StringRef))
45-
4642
ERROR(error_argument_not_allowed_with, none,
4743
"argument '%0' is not allowed with '%1'", (StringRef, StringRef))
4844

include/swift/Basic/Platform.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ namespace swift {
4343
/// Returns true if the given triple represents watchOS running in a simulator.
4444
bool tripleIsWatchSimulator(const llvm::Triple &triple);
4545

46+
/// Return true if the given triple represents any simulator.
47+
bool tripleIsAnySimulator(const llvm::Triple &triple);
48+
4649
/// Returns true if the given triple represents a macCatalyst environment.
4750
bool tripleIsMacCatalystEnvironment(const llvm::Triple &triple);
4851

49-
/// Determine whether the triple infers the "simulator" environment.
50-
bool tripleInfersSimulatorEnvironment(const llvm::Triple &triple);
51-
5252
/// Returns true if the given -target triple and -target-variant triple
5353
/// can be zippered.
5454
bool triplesAreValidForZippering(const llvm::Triple &target,

include/swift/Frontend/Frontend.h

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -386,9 +386,25 @@ class CompilerInvocation {
386386

387387
std::string getLdAddCFileOutputPathForWholeModule() const;
388388

389+
public:
390+
/// Given the current configuration of this frontend invocation, a set of
391+
/// supplementary output paths, and a module, compute the appropriate set of
392+
/// serialization options.
393+
///
394+
/// FIXME: The \p module parameter supports the
395+
/// \c SerializeOptionsForDebugging hack.
389396
SerializationOptions
390397
computeSerializationOptions(const SupplementaryOutputPaths &outs,
391-
bool moduleIsPublic) const;
398+
const ModuleDecl *module) const;
399+
400+
/// Returns an approximation of whether the given module could be
401+
/// redistributed and consumed by external clients.
402+
///
403+
/// FIXME: The scope of this computation should be limited entirely to
404+
/// PrintAsObjC. Unfortunately, it has been co-opted to support the
405+
/// \c SerializeOptionsForDebugging hack. Once this information can be
406+
/// transferred from module files to the dSYMs, remove this.
407+
bool isModuleExternallyConsumed(const ModuleDecl *mod) const;
392408
};
393409

394410
/// A class which manages the state and execution of the compiler.
@@ -555,9 +571,7 @@ class CompilerInstance {
555571
/// Returns true if there was an error during setup.
556572
bool setup(const CompilerInvocation &Invocation);
557573

558-
const CompilerInvocation &getInvocation() {
559-
return Invocation;
560-
}
574+
const CompilerInvocation &getInvocation() const { return Invocation; }
561575

562576
/// If a code completion buffer has been set, returns the corresponding source
563577
/// file.

include/swift/Option/Options.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,10 @@ def warnings_as_errors : Flag<["-"], "warnings-as-errors">,
528528
Flags<[FrontendOption]>,
529529
HelpText<"Treat warnings as errors">;
530530

531+
def no_warnings_as_errors : Flag<["-"], "no-warnings-as-errors">,
532+
Flags<[FrontendOption]>,
533+
HelpText<"Don't treat warnings as errors">;
534+
531535
def continue_building_after_errors : Flag<["-"], "continue-building-after-errors">,
532536
Flags<[FrontendOption, DoesNotAffectIncrementalBuild]>,
533537
HelpText<"Continue building, even after errors are encountered">;

lib/Basic/LangOptions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ std::pair<bool, bool> LangOptions::setTarget(llvm::Triple triple) {
361361
// Set the "targetEnvironment" platform condition if targeting a simulator
362362
// environment. Otherwise _no_ value is present for targetEnvironment; it's
363363
// an optional disambiguating refinement of the triple.
364-
if (Target.isSimulatorEnvironment())
364+
if (swift::tripleIsAnySimulator(Target))
365365
addPlatformConditionValue(PlatformConditionKind::TargetEnvironment,
366366
"simulator");
367367

lib/Basic/Platform.cpp

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,39 +19,47 @@
1919
using namespace swift;
2020

2121
bool swift::tripleIsiOSSimulator(const llvm::Triple &triple) {
22+
llvm::Triple::ArchType arch = triple.getArch();
2223
return (triple.isiOS() &&
2324
!tripleIsMacCatalystEnvironment(triple) &&
24-
triple.isSimulatorEnvironment());
25+
// FIXME: transitional, this should eventually stop testing arch, and
26+
// switch to only checking the -environment field.
27+
(triple.isSimulatorEnvironment() ||
28+
arch == llvm::Triple::x86 || arch == llvm::Triple::x86_64));
2529
}
2630

2731
bool swift::tripleIsAppleTVSimulator(const llvm::Triple &triple) {
28-
return (triple.isTvOS() && triple.isSimulatorEnvironment());
32+
llvm::Triple::ArchType arch = triple.getArch();
33+
return (triple.isTvOS() &&
34+
// FIXME: transitional, this should eventually stop testing arch, and
35+
// switch to only checking the -environment field.
36+
(triple.isSimulatorEnvironment() ||
37+
arch == llvm::Triple::x86 || arch == llvm::Triple::x86_64));
2938
}
3039

3140
bool swift::tripleIsWatchSimulator(const llvm::Triple &triple) {
32-
return (triple.isWatchOS() && triple.isSimulatorEnvironment());
41+
llvm::Triple::ArchType arch = triple.getArch();
42+
return (triple.isWatchOS() &&
43+
// FIXME: transitional, this should eventually stop testing arch, and
44+
// switch to only checking the -environment field.
45+
(triple.isSimulatorEnvironment() ||
46+
arch == llvm::Triple::x86 || arch == llvm::Triple::x86_64));
47+
}
48+
49+
bool swift::tripleIsAnySimulator(const llvm::Triple &triple) {
50+
// FIXME: transitional, this should eventually just use the -environment
51+
// field.
52+
return triple.isSimulatorEnvironment() ||
53+
tripleIsiOSSimulator(triple) ||
54+
tripleIsWatchSimulator(triple) ||
55+
tripleIsAppleTVSimulator(triple);
3356
}
3457

3558
bool swift::tripleIsMacCatalystEnvironment(const llvm::Triple &triple) {
3659
return triple.isiOS() && !triple.isTvOS() &&
3760
triple.getEnvironment() == llvm::Triple::MacABI;
3861
}
3962

40-
bool swift::tripleInfersSimulatorEnvironment(const llvm::Triple &triple) {
41-
switch (triple.getOS()) {
42-
case llvm::Triple::IOS:
43-
case llvm::Triple::TvOS:
44-
case llvm::Triple::WatchOS:
45-
return !triple.hasEnvironment() &&
46-
(triple.getArch() == llvm::Triple::x86 ||
47-
triple.getArch() == llvm::Triple::x86_64) &&
48-
!tripleIsMacCatalystEnvironment(triple);
49-
50-
default:
51-
return false;
52-
}
53-
}
54-
5563
bool swift::triplesAreValidForZippering(const llvm::Triple &target,
5664
const llvm::Triple &targetVariant) {
5765
// The arch and vendor must match.
@@ -319,6 +327,14 @@ getOSForAppleTargetSpecificModuleTriple(const llvm::Triple &triple) {
319327
static Optional<StringRef>
320328
getEnvironmentForAppleTargetSpecificModuleTriple(const llvm::Triple &triple) {
321329
auto tripleEnvironment = triple.getEnvironmentName();
330+
331+
// If the environment is empty, infer a "simulator" environment based on the
332+
// OS and architecture combination. This feature is deprecated and exists for
333+
// backwards compatibility only; build systems should pass the "simulator"
334+
// environment explicitly if they know they're building for a simulator.
335+
if (tripleEnvironment == "" && swift::tripleIsAnySimulator(triple))
336+
return StringRef("simulator");
337+
322338
return llvm::StringSwitch<Optional<StringRef>>(tripleEnvironment)
323339
.Cases("unknown", "", None)
324340
// These values are also supported, but are handled by the default case below:

lib/Driver/DarwinToolChains.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ toolchains::Darwin::addProfileGenerationArgs(ArgStringList &Arguments,
479479
}
480480

481481
StringRef Sim;
482-
if (Triple.isSimulatorEnvironment()) {
482+
if (tripleIsAnySimulator(Triple)) {
483483
Sim = "sim";
484484
}
485485

lib/Driver/Driver.cpp

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ static void validateBridgingHeaderArgs(DiagnosticEngine &diags,
140140
static void validateWarningControlArgs(DiagnosticEngine &diags,
141141
const ArgList &args) {
142142
if (args.hasArg(options::OPT_suppress_warnings) &&
143-
args.hasArg(options::OPT_warnings_as_errors)) {
143+
args.hasFlag(options::OPT_warnings_as_errors,
144+
options::OPT_no_warnings_as_errors, false)) {
144145
diags.diagnose(SourceLoc(), diag::error_conflicting_options,
145146
"-warnings-as-errors", "-suppress-warnings");
146147
}
@@ -264,31 +265,17 @@ static void validateArgs(DiagnosticEngine &diags, const ArgList &args,
264265
std::unique_ptr<ToolChain>
265266
Driver::buildToolChain(const llvm::opt::InputArgList &ArgList) {
266267

267-
if (const Arg *A = ArgList.getLastArg(options::OPT_target)) {
268+
if (const Arg *A = ArgList.getLastArg(options::OPT_target))
268269
DefaultTargetTriple = llvm::Triple::normalize(A->getValue());
269-
}
270-
271-
llvm::Triple target(DefaultTargetTriple);
272270

273-
// Backward compatibility hack: infer "simulator" environment for x86
274-
// iOS/tvOS/watchOS.
275-
if (tripleInfersSimulatorEnvironment(target)) {
276-
// Set the simulator environment.
277-
target.setEnvironment(llvm::Triple::EnvironmentType::Simulator);
278-
279-
auto newTargetTriple = target.normalize();
280-
Diags.diagnose(SourceLoc(), diag::warning_inferred_simulator_target,
281-
DefaultTargetTriple, newTargetTriple);
282-
283-
DefaultTargetTriple = newTargetTriple;
284-
}
271+
const llvm::Triple target(DefaultTargetTriple);
285272

286273
switch (target.getOS()) {
274+
case llvm::Triple::Darwin:
275+
case llvm::Triple::MacOSX:
287276
case llvm::Triple::IOS:
288277
case llvm::Triple::TvOS:
289-
case llvm::Triple::WatchOS:
290-
case llvm::Triple::Darwin:
291-
case llvm::Triple::MacOSX: {
278+
case llvm::Triple::WatchOS: {
292279
Optional<llvm::Triple> targetVariant;
293280
if (const Arg *A = ArgList.getLastArg(options::OPT_target_variant))
294281
targetVariant = llvm::Triple(llvm::Triple::normalize(A->getValue()));

lib/Driver/ToolChains.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@ void ToolChain::addCommonFrontendArgs(const OutputInfo &OI,
216216
inputArgs.AddLastArg(arguments, options::OPT_profile_generate);
217217
inputArgs.AddLastArg(arguments, options::OPT_profile_use);
218218
inputArgs.AddLastArg(arguments, options::OPT_profile_coverage_mapping);
219-
inputArgs.AddLastArg(arguments, options::OPT_warnings_as_errors);
219+
inputArgs.AddAllArgs(arguments, options::OPT_warnings_as_errors,
220+
options::OPT_no_warnings_as_errors);
220221
inputArgs.AddLastArg(arguments, options::OPT_sanitize_EQ);
221222
inputArgs.AddLastArg(arguments, options::OPT_sanitize_recover_EQ);
222223
inputArgs.AddLastArg(arguments, options::OPT_sanitize_coverage_EQ);

lib/Frontend/CompilerInvocation.cpp

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -553,22 +553,9 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
553553

554554
llvm::Triple Target = Opts.Target;
555555
StringRef TargetArg;
556-
std::string TargetArgScratch;
557-
558556
if (const Arg *A = Args.getLastArg(OPT_target)) {
559557
Target = llvm::Triple(A->getValue());
560558
TargetArg = A->getValue();
561-
562-
// Backward compatibility hack: infer "simulator" environment for x86
563-
// iOS/tvOS/watchOS. The driver takes care of this for the frontend
564-
// most of the time, but loading of old .swiftinterface files goes
565-
// directly to the frontend.
566-
if (tripleInfersSimulatorEnvironment(Target)) {
567-
// Set the simulator environment.
568-
Target.setEnvironment(llvm::Triple::EnvironmentType::Simulator);
569-
TargetArgScratch = Target.str();
570-
TargetArg = TargetArgScratch;
571-
}
572559
}
573560

574561
if (const Arg *A = Args.getLastArg(OPT_target_variant)) {
@@ -773,7 +760,8 @@ static bool ParseClangImporterArgs(ClangImporterOptions &Opts,
773760
Opts.PCHDisableValidation |= Args.hasArg(OPT_pch_disable_validation);
774761
}
775762

776-
if (Args.hasArg(OPT_warnings_as_errors))
763+
if (Args.hasFlag(options::OPT_warnings_as_errors,
764+
options::OPT_no_warnings_as_errors, false))
777765
Opts.ExtraArgs.push_back("-Werror");
778766

779767
Opts.DebuggerSupport |= Args.hasArg(OPT_debugger_support);
@@ -858,7 +846,9 @@ static bool ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args,
858846
/*Default=*/llvm::sys::Process::StandardErrHasColors());
859847
Opts.FixitCodeForAllDiagnostics |= Args.hasArg(OPT_fixit_all);
860848
Opts.SuppressWarnings |= Args.hasArg(OPT_suppress_warnings);
861-
Opts.WarningsAsErrors |= Args.hasArg(OPT_warnings_as_errors);
849+
Opts.WarningsAsErrors = Args.hasFlag(options::OPT_warnings_as_errors,
850+
options::OPT_no_warnings_as_errors,
851+
false);
862852
Opts.PrintDiagnosticNames |= Args.hasArg(OPT_debug_diagnostic_names);
863853
Opts.PrintEducationalNotes |= Args.hasArg(OPT_print_educational_notes);
864854
Opts.EnableExperimentalFormatting |=
@@ -1714,3 +1704,30 @@ CompilerInvocation::setUpInputForSILTool(
17141704
}
17151705
return fileBufOrErr;
17161706
}
1707+
1708+
bool CompilerInvocation::isModuleExternallyConsumed(
1709+
const ModuleDecl *mod) const {
1710+
// Modules for executables aren't expected to be consumed by other modules.
1711+
// This picks up all kinds of entrypoints, including script mode,
1712+
// @UIApplicationMain and @NSApplicationMain.
1713+
if (mod->hasEntryPoint()) {
1714+
return false;
1715+
}
1716+
1717+
// If an implicit Objective-C header was needed to construct this module, it
1718+
// must be the product of a library target.
1719+
if (!getFrontendOptions().ImplicitObjCHeaderPath.empty()) {
1720+
return false;
1721+
}
1722+
1723+
// App extensions are special beasts because they build without entrypoints
1724+
// like library targets, but they behave like executable targets because
1725+
// their associated modules are not suitable for distribution.
1726+
if (mod->getASTContext().LangOpts.EnableAppExtensionRestrictions) {
1727+
return false;
1728+
}
1729+
1730+
// FIXME: This is still a lousy approximation of whether the module file will
1731+
// be externally consumed.
1732+
return true;
1733+
}

lib/Frontend/Frontend.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ CompilerInvocation::getPrivateModuleInterfaceOutputPathForWholeModule() const {
152152
}
153153

154154
SerializationOptions CompilerInvocation::computeSerializationOptions(
155-
const SupplementaryOutputPaths &outs, bool moduleIsPublic) const {
155+
const SupplementaryOutputPaths &outs, const ModuleDecl *module) const {
156156
const FrontendOptions &opts = getFrontendOptions();
157157

158158
SerializationOptions serializationOpts;
@@ -171,7 +171,8 @@ SerializationOptions CompilerInvocation::computeSerializationOptions(
171171
// so only serialize them if the module isn't going to be shipped to
172172
// the public.
173173
serializationOpts.SerializeOptionsForDebugging =
174-
opts.SerializeOptionsForDebugging.getValueOr(!moduleIsPublic);
174+
opts.SerializeOptionsForDebugging.getValueOr(
175+
!isModuleExternallyConsumed(module));
175176

176177
return serializationOpts;
177178
}

0 commit comments

Comments
 (0)