mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[NFC] add llvm namespace to Optional and None
This is phase-1 of switching from llvm::Optional to std::optional in the
next rebranch. llvm::Optional was removed from upstream LLVM, so we need
to migrate off rather soon. On Darwin, std::optional, and llvm::Optional
have the same layout, so we don't need to be as concerned about ABI
beyond the name mangling. `llvm::Optional` is only returned from one
function in
```
getStandardTypeSubst(StringRef TypeName,
bool allowConcurrencyManglings);
```
It's the return value, so it should not impact the mangling of the
function, and the layout is the same as `std::optional`, so it should be
mostly okay. This function doesn't appear to have users, and the ABI was
already broken 2 years ago for concurrency and no one seemed to notice
so this should be "okay".
I'm doing the migration incrementally so that folks working on main can
cherry-pick back to the release/5.9 branch. Once 5.9 is done and locked
away, then we can go through and finish the replacement. Since `None`
and `Optional` show up in contexts where they are not `llvm::None` and
`llvm::Optional`, I'm preparing the work now by going through and
removing the namespace unwrapping and making the `llvm` namespace
explicit. This should make it fairly mechanical to go through and
replace llvm::Optional with std::optional, and llvm::None with
std::nullopt. It's also a change that can be brought onto the
release/5.9 with minimal impact. This should be an NFC change.
This commit is contained in:
@@ -103,7 +103,7 @@ void CompilerInvocation::setMainExecutablePath(StringRef Path) {
|
||||
}
|
||||
|
||||
static std::string
|
||||
getVersionedPrebuiltModulePath(Optional<llvm::VersionTuple> sdkVer,
|
||||
getVersionedPrebuiltModulePath(llvm::Optional<llvm::VersionTuple> sdkVer,
|
||||
StringRef defaultPrebuiltPath) {
|
||||
if (!sdkVer.has_value())
|
||||
return defaultPrebuiltPath.str();
|
||||
@@ -124,7 +124,7 @@ getVersionedPrebuiltModulePath(Optional<llvm::VersionTuple> sdkVer,
|
||||
|
||||
std::string CompilerInvocation::computePrebuiltCachePath(
|
||||
StringRef RuntimeResourcePath, llvm::Triple target,
|
||||
Optional<llvm::VersionTuple> sdkVer) {
|
||||
llvm::Optional<llvm::VersionTuple> sdkVer) {
|
||||
SmallString<64> defaultPrebuiltPath{RuntimeResourcePath};
|
||||
StringRef platform;
|
||||
if (tripleIsMacCatalystEnvironment(target)) {
|
||||
@@ -323,7 +323,7 @@ static bool ParseFrontendArgs(
|
||||
return converter.convert(buffers);
|
||||
}
|
||||
|
||||
static void diagnoseSwiftVersion(Optional<version::Version> &vers, Arg *verArg,
|
||||
static void diagnoseSwiftVersion(llvm::Optional<version::Version> &vers, Arg *verArg,
|
||||
ArgList &Args, DiagnosticEngine &diags) {
|
||||
// General invalid version error
|
||||
diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
|
||||
@@ -630,11 +630,11 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
|
||||
|
||||
if (const Arg *A = Args.getLastArg(OPT_unavailable_decl_optimization_EQ)) {
|
||||
auto value =
|
||||
llvm::StringSwitch<Optional<UnavailableDeclOptimization>>(A->getValue())
|
||||
llvm::StringSwitch<llvm::Optional<UnavailableDeclOptimization>>(A->getValue())
|
||||
.Case("none", UnavailableDeclOptimization::None)
|
||||
.Case("stub", UnavailableDeclOptimization::Stub)
|
||||
.Case("complete", UnavailableDeclOptimization::Complete)
|
||||
.Default(None);
|
||||
.Default(llvm::None);
|
||||
|
||||
if (value)
|
||||
Opts.UnavailableDeclOptimizationMode = *value;
|
||||
@@ -878,7 +878,7 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
|
||||
} else if (diagLevel == "error") {
|
||||
Opts.RequireExplicitAvailability = DiagnosticBehavior::Error;
|
||||
} else if (diagLevel == "ignore") {
|
||||
Opts.RequireExplicitAvailability = None;
|
||||
Opts.RequireExplicitAvailability = llvm::None;
|
||||
} else {
|
||||
Diags.diagnose(SourceLoc(),
|
||||
diag::error_unknown_require_explicit_availability,
|
||||
@@ -911,11 +911,11 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
|
||||
if (Opts.isSwiftVersionAtLeast(6)) {
|
||||
Opts.StrictConcurrencyLevel = StrictConcurrency::Complete;
|
||||
} else if (const Arg *A = Args.getLastArg(OPT_strict_concurrency)) {
|
||||
auto value = llvm::StringSwitch<Optional<StrictConcurrency>>(A->getValue())
|
||||
auto value = llvm::StringSwitch<llvm::Optional<StrictConcurrency>>(A->getValue())
|
||||
.Case("minimal", StrictConcurrency::Minimal)
|
||||
.Case("targeted", StrictConcurrency::Targeted)
|
||||
.Case("complete", StrictConcurrency::Complete)
|
||||
.Default(None);
|
||||
.Default(llvm::None);
|
||||
|
||||
if (value)
|
||||
Opts.StrictConcurrencyLevel = *value;
|
||||
@@ -951,12 +951,12 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
|
||||
generateOptimizationRemarkRegex(Diags, Args, A);
|
||||
|
||||
if (Arg *A = Args.getLastArg(OPT_Raccess_note)) {
|
||||
auto value = llvm::StringSwitch<Optional<AccessNoteDiagnosticBehavior>>(A->getValue())
|
||||
auto value = llvm::StringSwitch<llvm::Optional<AccessNoteDiagnosticBehavior>>(A->getValue())
|
||||
.Case("none", AccessNoteDiagnosticBehavior::Ignore)
|
||||
.Case("failures", AccessNoteDiagnosticBehavior::RemarkOnFailure)
|
||||
.Case("all", AccessNoteDiagnosticBehavior::RemarkOnFailureOrSuccess)
|
||||
.Case("all-validate", AccessNoteDiagnosticBehavior::ErrorOnFailureRemarkOnSuccess)
|
||||
.Default(None);
|
||||
.Default(llvm::None);
|
||||
|
||||
if (value)
|
||||
Opts.AccessNoteBehavior = *value;
|
||||
@@ -1098,10 +1098,10 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
|
||||
getDefaultMinimumInliningTargetVersion(Opts.Target);
|
||||
|
||||
// Parse OS version number arguments.
|
||||
auto parseVersionArg = [&](OptSpecifier opt) -> Optional<llvm::VersionTuple> {
|
||||
auto parseVersionArg = [&](OptSpecifier opt) -> llvm::Optional<llvm::VersionTuple> {
|
||||
Arg *A = Args.getLastArg(opt);
|
||||
if (!A)
|
||||
return None;
|
||||
return llvm::None;
|
||||
|
||||
if (StringRef(A->getValue()) == "min")
|
||||
return minimumAvailableOSVersionForTriple(Opts.Target);
|
||||
@@ -1114,7 +1114,7 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
|
||||
|
||||
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
|
||||
A->getAsString(Args), A->getValue());
|
||||
return None;
|
||||
return llvm::None;
|
||||
};
|
||||
|
||||
if (auto vers = parseVersionArg(OPT_min_inlining_target_version))
|
||||
@@ -1946,24 +1946,24 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
|
||||
// -Ounchecked might also set removal of runtime asserts (cond_fail).
|
||||
Opts.RemoveRuntimeAsserts |= Args.hasArg(OPT_RemoveRuntimeAsserts);
|
||||
|
||||
Optional<DestroyHoistingOption> specifiedDestroyHoistingOption;
|
||||
llvm::Optional<DestroyHoistingOption> specifiedDestroyHoistingOption;
|
||||
if (Arg *A = Args.getLastArg(OPT_enable_destroy_hoisting)) {
|
||||
specifiedDestroyHoistingOption =
|
||||
llvm::StringSwitch<Optional<DestroyHoistingOption>>(A->getValue())
|
||||
llvm::StringSwitch<llvm::Optional<DestroyHoistingOption>>(A->getValue())
|
||||
.Case("true", DestroyHoistingOption::On)
|
||||
.Case("false", DestroyHoistingOption::Off)
|
||||
.Default(None);
|
||||
.Default(llvm::None);
|
||||
}
|
||||
|
||||
Optional<CopyPropagationOption> specifiedCopyPropagationOption;
|
||||
llvm::Optional<CopyPropagationOption> specifiedCopyPropagationOption;
|
||||
if (Arg *A = Args.getLastArg(OPT_copy_propagation_state_EQ)) {
|
||||
specifiedCopyPropagationOption =
|
||||
llvm::StringSwitch<Optional<CopyPropagationOption>>(A->getValue())
|
||||
llvm::StringSwitch<llvm::Optional<CopyPropagationOption>>(A->getValue())
|
||||
.Case("true", CopyPropagationOption::On)
|
||||
.Case("false", CopyPropagationOption::Off)
|
||||
.Case("requested-passes-only",
|
||||
CopyPropagationOption::RequestedPassesOnly)
|
||||
.Default(None);
|
||||
.Default(llvm::None);
|
||||
}
|
||||
if (Args.hasArg(OPT_enable_copy_propagation)) {
|
||||
if (specifiedCopyPropagationOption) {
|
||||
@@ -1991,25 +1991,25 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
|
||||
Opts.CopyPropagation = *specifiedCopyPropagationOption;
|
||||
}
|
||||
|
||||
Optional<bool> enableLexicalBorrowScopesFlag;
|
||||
llvm::Optional<bool> enableLexicalBorrowScopesFlag;
|
||||
if (Arg *A = Args.getLastArg(OPT_enable_lexical_borrow_scopes)) {
|
||||
enableLexicalBorrowScopesFlag =
|
||||
llvm::StringSwitch<Optional<bool>>(A->getValue())
|
||||
llvm::StringSwitch<llvm::Optional<bool>>(A->getValue())
|
||||
.Case("true", true)
|
||||
.Case("false", false)
|
||||
.Default(None);
|
||||
.Default(llvm::None);
|
||||
}
|
||||
|
||||
// Allow command line flags to override the default value of
|
||||
// Opts.LexicalLifetimes. If no explicit flags are passed, then
|
||||
// Opts.LexicalLifetimes retains its initial value.
|
||||
Optional<bool> enableLexicalLifetimesFlag;
|
||||
llvm::Optional<bool> enableLexicalLifetimesFlag;
|
||||
if (Arg *A = Args.getLastArg(OPT_enable_lexical_lifetimes)) {
|
||||
enableLexicalLifetimesFlag =
|
||||
llvm::StringSwitch<Optional<bool>>(A->getValue())
|
||||
llvm::StringSwitch<llvm::Optional<bool>>(A->getValue())
|
||||
.Case("true", true)
|
||||
.Case("false", false)
|
||||
.Default(None);
|
||||
.Default(llvm::None);
|
||||
}
|
||||
if (Args.getLastArg(OPT_enable_lexical_lifetimes_noArg)) {
|
||||
if (!enableLexicalLifetimesFlag.value_or(true)) {
|
||||
@@ -2080,13 +2080,13 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
|
||||
if (specifiedDestroyHoistingOption)
|
||||
Opts.DestroyHoisting = *specifiedDestroyHoistingOption;
|
||||
|
||||
Optional<bool> enablePackMetadataStackPromotionFlag;
|
||||
llvm::Optional<bool> enablePackMetadataStackPromotionFlag;
|
||||
if (Arg *A = Args.getLastArg(OPT_enable_pack_metadata_stack_promotion)) {
|
||||
enablePackMetadataStackPromotionFlag =
|
||||
llvm::StringSwitch<Optional<bool>>(A->getValue())
|
||||
llvm::StringSwitch<llvm::Optional<bool>>(A->getValue())
|
||||
.Case("true", true)
|
||||
.Case("false", false)
|
||||
.Default(None);
|
||||
.Default(llvm::None);
|
||||
}
|
||||
if (Args.getLastArg(OPT_enable_pack_metadata_stack_promotion_noArg)) {
|
||||
if (!enablePackMetadataStackPromotionFlag.value_or(true)) {
|
||||
@@ -2472,7 +2472,7 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
|
||||
llvm::StringSwitch<llvm::Optional<swift::JITDebugArtifact>>(A->getValue())
|
||||
.Case("llvm-ir", JITDebugArtifact::LLVMIR)
|
||||
.Case("object", JITDebugArtifact::Object)
|
||||
.Default(None);
|
||||
.Default(llvm::None);
|
||||
if (!artifact) {
|
||||
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
|
||||
A->getOption().getName(), A->getValue());
|
||||
@@ -2546,7 +2546,7 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
|
||||
|
||||
if (const Arg *A = Args.getLastArg(options::OPT_lto)) {
|
||||
auto LLVMLTOKind =
|
||||
llvm::StringSwitch<Optional<IRGenLLVMLTOKind>>(A->getValue())
|
||||
llvm::StringSwitch<llvm::Optional<IRGenLLVMLTOKind>>(A->getValue())
|
||||
.Case("llvm-thin", IRGenLLVMLTOKind::Thin)
|
||||
.Case("llvm-full", IRGenLLVMLTOKind::Full)
|
||||
.Default(llvm::None);
|
||||
@@ -2652,13 +2652,13 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
|
||||
}
|
||||
}
|
||||
|
||||
auto getRuntimeCompatVersion = [&] () -> Optional<llvm::VersionTuple> {
|
||||
Optional<llvm::VersionTuple> runtimeCompatibilityVersion;
|
||||
auto getRuntimeCompatVersion = [&] () -> llvm::Optional<llvm::VersionTuple> {
|
||||
llvm::Optional<llvm::VersionTuple> runtimeCompatibilityVersion;
|
||||
if (auto versionArg = Args.getLastArg(
|
||||
options::OPT_runtime_compatibility_version)) {
|
||||
auto version = StringRef(versionArg->getValue());
|
||||
if (version.equals("none")) {
|
||||
runtimeCompatibilityVersion = None;
|
||||
runtimeCompatibilityVersion = llvm::None;
|
||||
} else if (version.equals("5.0")) {
|
||||
runtimeCompatibilityVersion = llvm::VersionTuple(5, 0);
|
||||
} else if (version.equals("5.1")) {
|
||||
|
||||
Reference in New Issue
Block a user