Skip to content

Commit fbbf61f

Browse files
authored
Revert "[Darwin] Further restrict inference of the simulator environment"
1 parent ea142db commit fbbf61f

18 files changed

+87
-119
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,

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: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -264,31 +264,17 @@ static void validateArgs(DiagnosticEngine &diags, const ArgList &args,
264264
std::unique_ptr<ToolChain>
265265
Driver::buildToolChain(const llvm::opt::InputArgList &ArgList) {
266266

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

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-
}
270+
const llvm::Triple target(DefaultTargetTriple);
285271

286272
switch (target.getOS()) {
273+
case llvm::Triple::Darwin:
274+
case llvm::Triple::MacOSX:
287275
case llvm::Triple::IOS:
288276
case llvm::Triple::TvOS:
289-
case llvm::Triple::WatchOS:
290-
case llvm::Triple::Darwin:
291-
case llvm::Triple::MacOSX: {
277+
case llvm::Triple::WatchOS: {
292278
Optional<llvm::Triple> targetVariant;
293279
if (const Arg *A = ArgList.getLastArg(options::OPT_target_variant))
294280
targetVariant = llvm::Triple(llvm::Triple::normalize(A->getValue()));

lib/Frontend/CompilerInvocation.cpp

Lines changed: 0 additions & 13 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)) {

lib/IRGen/SwiftTargetInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ static void configureX86_64(IRGenModule &IGM, const llvm::Triple &triple,
6969
SWIFT_ABI_X86_64_SWIFT_SPARE_BITS_MASK);
7070
setToMask(target.IsObjCPointerBit, 64, SWIFT_ABI_X86_64_IS_OBJC_BIT);
7171

72-
if (triple.isSimulatorEnvironment()) {
72+
if (tripleIsAnySimulator(triple)) {
7373
setToMask(target.ObjCPointerReservedBits, 64,
7474
SWIFT_ABI_X86_64_SIMULATOR_OBJC_RESERVED_BITS_MASK);
7575
} else {

lib/Serialization/ModuleFile.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,9 +1341,6 @@ static bool areCompatibleArchitectures(const llvm::Triple &moduleTarget,
13411341

13421342
static bool areCompatibleOSs(const llvm::Triple &moduleTarget,
13431343
const llvm::Triple &ctxTarget) {
1344-
if (moduleTarget.getEnvironment() != ctxTarget.getEnvironment())
1345-
return false;
1346-
13471344
if (moduleTarget.getOS() == ctxTarget.getOS())
13481345
return true;
13491346

test/Driver/infer-simulator.swift

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)