Skip to content

change to the new llvm::Optional APIs #63211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions include/swift/SIL/FieldSensitivePrunedLiveness.h
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ class FieldSensitiveSSAPrunedLiveRange

bool isDef(SILInstruction *inst, TypeTreeLeafTypeRange span) const {
return inst == defInst.first &&
defInst.second->setIntersection(span).hasValue();
defInst.second->setIntersection(span).has_value();
}

bool isDefBlock(SILBasicBlock *block, unsigned bit) const {
Expand Down Expand Up @@ -764,7 +764,7 @@ class FieldSensitiveMultiDefPrunedLiveRange
if (!iter)
return false;
return llvm::any_of(*iter, [&](TypeTreeLeafTypeRange storedSpan) {
return span.setIntersection(storedSpan).hasValue();
return span.setIntersection(storedSpan).has_value();
});
}

Expand All @@ -789,7 +789,7 @@ class FieldSensitiveMultiDefPrunedLiveRange
if (!iter)
return false;
return llvm::any_of(*iter, [&](TypeTreeLeafTypeRange storedSpan) {
return span.setIntersection(storedSpan).hasValue();
return span.setIntersection(storedSpan).has_value();
});
}

Expand All @@ -798,7 +798,7 @@ class FieldSensitiveMultiDefPrunedLiveRange
if (!iter)
return false;
return llvm::any_of(*iter, [&](TypeTreeLeafTypeRange storedSpan) {
return span.setIntersection(storedSpan).hasValue();
return span.setIntersection(storedSpan).has_value();
});
}

Expand Down
6 changes: 3 additions & 3 deletions lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1897,7 +1897,7 @@ static void findPath_dfs(ModuleDependencyID X,
}
visited.insert(X);
auto optionalNode = cache.findDependency(X.first, X.second);
auto node = optionalNode.getValue();
auto node = optionalNode.value();
assert(optionalNode.has_value() && "Expected cache value for dependency.");
for (const auto &dep : node->getModuleImports()) {
Optional<ModuleDependencyKind> lookupKind = None;
Expand All @@ -1909,7 +1909,7 @@ static void findPath_dfs(ModuleDependencyID X,
auto optionalDepNode = cache.findDependency(dep, lookupKind);
if (!optionalDepNode.has_value())
continue;
auto depNode = optionalDepNode.getValue();
auto depNode = optionalDepNode.value();
auto depID = std::make_pair(dep, depNode->getKind());
if (!visited.count(depID)) {
findPath_dfs(depID, Y, visited, stack, result, cache);
Expand Down Expand Up @@ -1953,7 +1953,7 @@ static void diagnoseScannerFailure(StringRef moduleName,
const auto &entry = *it;
auto optionalEntryNode = cache.findDependency(entry.first, entry.second);
assert(optionalEntryNode.has_value());
auto entryNode = optionalEntryNode.getValue();
auto entryNode = optionalEntryNode.value();
std::string moduleFilePath = "";
bool isClang = false;
switch (entryNode->getKind()) {
Expand Down
4 changes: 2 additions & 2 deletions lib/AST/ModuleDependencies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,9 +454,9 @@ void ModuleDependenciesCache::updateDependency(
void ModuleDependenciesCache::resolveDependencyImports(ModuleDependencyID moduleID,
const std::vector<ModuleDependencyID> &dependencyIDs) {
auto optionalDependencyInfo = findDependency(moduleID.first, moduleID.second);
assert(optionalDependencyInfo.hasValue() && "Resolving unknown dependency");
assert(optionalDependencyInfo.has_value() && "Resolving unknown dependency");
// Copy the existing info to a mutable one we can then replace it with, after resolving its dependencies.
auto dependencyInfo = *(optionalDependencyInfo.getValue());
auto dependencyInfo = *(optionalDependencyInfo.value());
dependencyInfo.resolveDependencies(dependencyIDs);
updateDependency(moduleID, dependencyInfo);
}
4 changes: 2 additions & 2 deletions lib/ClangImporter/ClangModuleDependencyScanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ bool ClangImporter::addBridgingHeaderDependencies(
ModuleDependenciesCache &cache) {
auto &ctx = Impl.SwiftContext;
auto optionalTargetModule = cache.findDependency(moduleName, moduleKind);
assert(optionalTargetModule.hasValue());
auto targetModule = *(optionalTargetModule.getValue());
assert(optionalTargetModule.has_value());
auto targetModule = *(optionalTargetModule.value());

// If we've already recorded bridging header dependencies, we're done.
if (auto swiftInterfaceDeps = targetModule.getAsSwiftInterfaceModule()) {
Expand Down
18 changes: 9 additions & 9 deletions lib/ConstExtract/ConstExtract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ static std::shared_ptr<CompileTimeValue> extractCompileTimeValue(Expr *expr) {
case ExprKind::NilLiteral:
case ExprKind::StringLiteral: {
auto rawLiteral = extractRawLiteral(expr);
if (rawLiteral.hasValue()) {
if (rawLiteral.has_value()) {
return std::make_shared<RawLiteralValue>(rawLiteral.value());
}

Expand Down Expand Up @@ -569,7 +569,7 @@ void writeValue(llvm::json::OStream &JSON,
JSON.attribute("valueKind", "Enum");
JSON.attributeObject("value", [&]() {
JSON.attribute("name", enumValue->getIdentifier());
if (enumValue->getParameters().hasValue()) {
if (enumValue->getParameters().has_value()) {
auto params = enumValue->getParameters().value();
JSON.attributeArray("arguments", [&] {
for (auto FP : params) {
Expand All @@ -595,7 +595,7 @@ void writeValue(llvm::json::OStream &JSON,
void writeAttributes(
llvm::json::OStream &JSON,
llvm::Optional<std::vector<CustomAttrValue>> PropertyWrappers) {
if (!PropertyWrappers.hasValue()) {
if (!PropertyWrappers.has_value()) {
return;
}

Expand All @@ -620,18 +620,18 @@ void writeAttributes(
void writeEnumCases(
llvm::json::OStream &JSON,
llvm::Optional<std::vector<EnumElementDeclValue>> EnumElements) {
if (!EnumElements.hasValue()) {
if (!EnumElements.has_value()) {
return;
}

JSON.attributeArray("cases", [&] {
for (const auto &Case : EnumElements.value()) {
JSON.object([&] {
JSON.attribute("name", Case.Name);
if (Case.RawValue.hasValue()) {
if (Case.RawValue.has_value()) {
JSON.attribute("rawValue", Case.RawValue.value());
}
if (Case.Parameters.hasValue()) {
if (Case.Parameters.has_value()) {
JSON.attributeArray("parameters", [&] {
for (const auto &Parameter : Case.Parameters.value()) {
JSON.object([&] {
Expand Down Expand Up @@ -698,15 +698,15 @@ void writeAttrInformation(llvm::json::OStream &JSON,
if (!attr->Rename.empty())
JSON.attribute("rename", attr->Rename);

if (attr->Introduced.hasValue())
if (attr->Introduced.has_value())
JSON.attribute("introducedVersion",
attr->Introduced.value().getAsString());

if (attr->Deprecated.hasValue())
if (attr->Deprecated.has_value())
JSON.attribute("deprecatedVersion",
attr->Deprecated.value().getAsString());

if (attr->Obsoleted.hasValue())
if (attr->Obsoleted.has_value())
JSON.attribute("obsoletedVersion",
attr->Obsoleted.value().getAsString());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,7 @@ void ModuleDependenciesCacheSerializer::collectStringsAndArrays(
for (auto &moduleID : cache.getAllNonSourceModules(contextHash)) {
auto optionalDependencyInfo = cache.findDependency(moduleID.first, moduleID.second);
assert(optionalDependencyInfo.has_value() && "Expected dependency info.");
auto dependencyInfo = optionalDependencyInfo.getValue();
auto dependencyInfo = optionalDependencyInfo.value();
// Add the module's name
addIdentifier(moduleID.first);
// Add the module's dependencies
Expand Down
36 changes: 18 additions & 18 deletions lib/DependencyScan/ScanDependencies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,10 @@ static void findAllImportedClangModules(ASTContext &ctx, StringRef moduleName,
allModules.push_back(moduleName.str());
auto optionalDependencies =
cache.findDependency(moduleName, ModuleDependencyKind::Clang);
if (!optionalDependencies.hasValue())
if (!optionalDependencies.has_value())
return;

auto dependencies = optionalDependencies.getValue();
auto dependencies = optionalDependencies.value();
for (const auto &dep : dependencies->getModuleDependencies()) {
findAllImportedClangModules(ctx, dep.first, cache, allModules, knownModules);
}
Expand All @@ -165,8 +165,8 @@ resolveDirectDependencies(CompilerInstance &instance, ModuleDependencyID module,
PrettyStackTraceStringAction trace("Resolving direct dependencies of: ", module.first);
auto &ctx = instance.getASTContext();
auto optionalKnownDependencies = cache.findDependency(module.first, module.second);
assert(optionalKnownDependencies.hasValue());
auto knownDependencies = optionalKnownDependencies.getValue();
assert(optionalKnownDependencies.has_value());
auto knownDependencies = optionalKnownDependencies.value();

// If this dependency has already been resolved, return the result.
if (knownDependencies->isResolved() &&
Expand All @@ -189,7 +189,7 @@ resolveDirectDependencies(CompilerInstance &instance, ModuleDependencyID module,
} else {
if (auto found =
ctx.getModuleDependencies(dependsOn, cache, ASTDelegate, module))
result.insert({dependsOn, found.getValue()->getKind()});
result.insert({dependsOn, found.value()->getKind()});
}
}

Expand Down Expand Up @@ -241,14 +241,14 @@ resolveDirectDependencies(CompilerInstance &instance, ModuleDependencyID module,
if (auto found =
ctx.getSwiftModuleDependencies(clangDep, cache, ASTDelegate)) {
if (clangDep != module.first)
result.insert({clangDep, found.getValue()->getKind()});
result.insert({clangDep, found.value()->getKind()});
}
}
}

// Resolve the dependnecy info
cache.resolveDependencyImports(module, result.takeVector());
return cache.findDependency(module.first, module.second).getValue()->getModuleDependencies();
return cache.findDependency(module.first, module.second).value()->getModuleDependencies();
}

static void discoverCrossImportOverlayDependencies(
Expand All @@ -260,7 +260,7 @@ static void discoverCrossImportOverlayDependencies(
llvm::SetVector<Identifier> newOverlays;
for (auto dep : allDependencies) {
auto moduleName = dep.first;
auto dependencies = cache.findDependency(moduleName, dep.second).getValue();
auto dependencies = cache.findDependency(moduleName, dep.second).value();

// Collect a map from secondary module name to cross-import overlay names.
auto overlayMap = dependencies->collectCrossImportOverlayNames(
Expand Down Expand Up @@ -323,7 +323,7 @@ static void discoverCrossImportOverlayDependencies(

// Update main module's dependencies to include these new overlays.
auto mainDep = *(cache.findDependency(
mainModuleName, ModuleDependencyKind::SwiftSource).getValue());
mainModuleName, ModuleDependencyKind::SwiftSource).value());
std::for_each(/* +1 to exclude dummy main*/ allModules.begin() + 1,
allModules.end(),
[&](ModuleDependencyID dependencyID) {
Expand Down Expand Up @@ -835,8 +835,8 @@ generateFullDependencyGraph(CompilerInstance &instance,
}

auto optionalDepInfo = cache.findDependency(module.first, module.second);
assert(optionalDepInfo.hasValue() && "Missing dependency info during graph generation diagnosis.");
auto depInfo = optionalDepInfo.getValue();
assert(optionalDepInfo.has_value() && "Missing dependency info during graph generation diagnosis.");
auto depInfo = optionalDepInfo.value();
auto directDependencies = depInfo->getModuleDependencies();

// Generate a swiftscan_clang_details_t object based on the dependency kind
Expand Down Expand Up @@ -967,8 +967,8 @@ static bool diagnoseCycle(CompilerInstance &instance,
auto beforeSize = openSet.size();

auto optionalDepInfo = cache.findDependency(lastOpen.first, lastOpen.second);
assert(optionalDepInfo.hasValue() && "Missing dependency info during cycle diagnosis.");
auto depInfo = optionalDepInfo.getValue();
assert(optionalDepInfo.has_value() && "Missing dependency info during cycle diagnosis.");
auto depInfo = optionalDepInfo.value();

for (const auto &dep : depInfo->getModuleDependencies()) {
if (closeSet.count(dep))
Expand Down Expand Up @@ -1459,7 +1459,7 @@ swift::dependencies::performModuleScan(CompilerInstance &instance,
// Verify that all collected dependencies have had their
// imports resolved to module IDs
for (const auto &moduleID : allModules) {
const auto &moduleInfo = cache.findDependency(moduleID.first, moduleID.second).getValue();
const auto &moduleInfo = cache.findDependency(moduleID.first, moduleID.second).value();
assert(moduleInfo->isResolved());
}
#endif
Expand All @@ -1474,9 +1474,9 @@ swift::dependencies::performModuleScan(CompilerInstance &instance,
if (auto depTracker = instance.getDependencyTracker()) {
for (auto module : allModules) {
auto optionalDeps = cache.findDependency(module.first, module.second);
if (!optionalDeps.hasValue())
if (!optionalDeps.has_value())
continue;
auto deps = optionalDeps.getValue();
auto deps = optionalDeps.value();

if (auto swiftDeps = deps->getAsSwiftInterfaceModule()) {
depTracker->addDependency(swiftDeps->swiftInterfaceFile,
Expand Down Expand Up @@ -1557,7 +1557,7 @@ swift::dependencies::performBatchModuleScan(
rootDeps =
ctx.getSwiftModuleDependencies(moduleName, cache, ASTDelegate);
}
if (!rootDeps.hasValue()) {
if (!rootDeps.has_value()) {
// We cannot find the clang module, abort.
batchScanResult.push_back(
std::make_error_code(std::errc::invalid_argument));
Expand Down Expand Up @@ -1633,7 +1633,7 @@ swift::dependencies::performBatchModulePrescan(
}

auto *importSet = new swiftscan_import_set_s;
importSet->imports = create_set(rootDeps.getValue()->getModuleImports());
importSet->imports = create_set(rootDeps.value()->getModuleImports());
batchPrescanResult.push_back(importSet);
});

Expand Down
2 changes: 1 addition & 1 deletion lib/IDETool/DependencyChecking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ forEachDependencyUntilTrue(CompilerInstance &CI,
llvm::function_ref<bool(StringRef)> callback) {
// Check files in the current module. If 'excludeBufferID' is None, exclude
// all source files.
if (excludeBufferID.hasValue()) {
if (excludeBufferID.has_value()) {
for (FileUnit *file : CI.getMainModule()->getFiles()) {
StringRef filename;
if (auto SF = dyn_cast<SourceFile>(file)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/IDETool/IDEInspectionInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ void IDEInspectionInstance::performNewOperation(
llvm::PrettyStackTraceString trace("While performing new IDE inspection");

// If ArgsHash is None we shouldn't cache the compiler instance.
bool ShouldCacheCompilerInstance = ArgsHash.hasValue();
bool ShouldCacheCompilerInstance = ArgsHash.has_value();

auto CI = std::make_shared<CompilerInstance>();

Expand Down
Loading