Skip to content

Simplify createStringError calls (NFC) #8801

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 3 commits into from
May 24, 2024
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
3 changes: 1 addition & 2 deletions lldb/source/Host/common/Socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ llvm::Error Socket::Initialize() {
if (err == 0) {
if (wsaData.wVersion < wVersion) {
WSACleanup();
return llvm::make_error<llvm::StringError>(
"WSASock version is not expected.", llvm::inconvertibleErrorCode());
return llvm::createStringError("WSASock version is not expected.");
}
} else {
return llvm::errorCodeToError(llvm::mapWindowsError(::WSAGetLastError()));
Expand Down
29 changes: 11 additions & 18 deletions lldb/source/Interpreter/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -931,8 +931,7 @@ llvm::Expected<Args> Options::ParseAlias(const Args &args,
Option *long_options = GetLongOptions();

if (long_options == nullptr) {
return llvm::make_error<llvm::StringError>("Invalid long options",
llvm::inconvertibleErrorCode());
return llvm::createStringError("Invalid long options");
}

std::string short_options = BuildShortOptions(long_options);
Expand All @@ -957,8 +956,7 @@ llvm::Expected<Args> Options::ParseAlias(const Args &args,
break;

if (val == '?') {
return llvm::make_error<llvm::StringError>(
"Unknown or ambiguous option", llvm::inconvertibleErrorCode());
return llvm::createStringError("Unknown or ambiguous option");
}

if (val == 0)
Expand All @@ -980,9 +978,8 @@ llvm::Expected<Args> Options::ParseAlias(const Args &args,

// See if the option takes an argument, and see if one was supplied.
if (long_options_index == -1) {
return llvm::make_error<llvm::StringError>(
llvm::formatv("Invalid option with value '{0}'.", char(val)).str(),
llvm::inconvertibleErrorCode());
return llvm::createStringError(
llvm::formatv("Invalid option with value '{0}'.", char(val)).str());
}

StreamString option_str;
Expand All @@ -995,11 +992,10 @@ llvm::Expected<Args> Options::ParseAlias(const Args &args,
switch (has_arg) {
case OptionParser::eRequiredArgument:
if (OptionParser::GetOptionArgument() == nullptr) {
return llvm::make_error<llvm::StringError>(
return llvm::createStringError(
llvm::formatv("Option '{0}' is missing argument specifier.",
option_str.GetString())
.str(),
llvm::inconvertibleErrorCode());
.str());
}
[[fallthrough]];
case OptionParser::eOptionalArgument:
Expand All @@ -1008,12 +1004,11 @@ llvm::Expected<Args> Options::ParseAlias(const Args &args,
case OptionParser::eNoArgument:
break;
default:
return llvm::make_error<llvm::StringError>(
return llvm::createStringError(
llvm::formatv("error with options table; invalid value in has_arg "
"field for option '{0}'.",
char(val))
.str(),
llvm::inconvertibleErrorCode());
.str());
}
// Find option in the argument list; also see if it was supposed to take an
// argument and if one was supplied. Remove option (and argument, if
Expand Down Expand Up @@ -1261,8 +1256,7 @@ llvm::Expected<Args> Options::Parse(const Args &args,
Status error;
Option *long_options = GetLongOptions();
if (long_options == nullptr) {
return llvm::make_error<llvm::StringError>("Invalid long options.",
llvm::inconvertibleErrorCode());
return llvm::createStringError("Invalid long options.");
}

std::string short_options = BuildShortOptions(long_options);
Expand Down Expand Up @@ -1322,9 +1316,8 @@ llvm::Expected<Args> Options::Parse(const Args &args,
if (!platform_sp && require_validation) {
// Caller requires validation but we cannot validate as we don't have
// the mandatory platform against which to validate.
return llvm::make_error<llvm::StringError>(
"cannot validate options: no platform available",
llvm::inconvertibleErrorCode());
return llvm::createStringError(
"cannot validate options: no platform available");
}

bool validation_failed = false;
Expand Down
8 changes: 3 additions & 5 deletions lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,14 +501,12 @@ class ReturnValueExtractor {
CompilerType &type) {
RegisterContext *reg_ctx = thread.GetRegisterContext().get();
if (!reg_ctx)
return llvm::make_error<llvm::StringError>(
LOG_PREFIX "Failed to get RegisterContext",
llvm::inconvertibleErrorCode());
return llvm::createStringError(LOG_PREFIX
"Failed to get RegisterContext");

ProcessSP process_sp = thread.GetProcess();
if (!process_sp)
return llvm::make_error<llvm::StringError>(
LOG_PREFIX "GetProcess() failed", llvm::inconvertibleErrorCode());
return llvm::createStringError(LOG_PREFIX "GetProcess() failed");

return ReturnValueExtractor(thread, type, reg_ctx, process_sp);
}
Expand Down
36 changes: 12 additions & 24 deletions lldb/source/Plugins/ExpressionParser/Swift/SwiftASTManipulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -706,8 +706,7 @@ bool SwiftASTManipulator::IsExpressionResultNonCopyable() {

llvm::Error SwiftASTManipulator::FixupResultAfterTypeChecking() {
if (!IsValid())
return llvm::createStringError(llvm::inconvertibleErrorCode(),
"Operating on invalid SwiftASTManipulator");
return llvm::createStringError("Operating on invalid SwiftASTManipulator");
// Run through the result decls and figure out the return type.

size_t num_results = m_result_info.size();
Expand Down Expand Up @@ -738,11 +737,9 @@ llvm::Error SwiftASTManipulator::FixupResultAfterTypeChecking() {

if (result_type.isNull())
return llvm::createStringError(
llvm::inconvertibleErrorCode(),
"Could not find the result type for this expression.");
if (result_type->is<swift::ErrorType>())
return llvm::createStringError(llvm::inconvertibleErrorCode(),
"Result type is the error type.");
return llvm::createStringError("Result type is the error type.");

swift::ASTContext &ast_context = m_source_file.getASTContext();
CompilerType return_ast_type = ToCompilerType(result_type.getPointer());
Expand All @@ -755,13 +752,11 @@ llvm::Error SwiftASTManipulator::FixupResultAfterTypeChecking() {
AddExternalVariable(result_var_name, return_ast_type, metadata_sp);
if (!result_var_or_err)
return llvm::createStringError(
llvm::inconvertibleErrorCode(),
"Could not add external result variable." +
llvm::toString(result_var_or_err.takeError()));
llvm::toString(result_var_or_err.takeError()));
swift::VarDecl *result_var = *result_var_or_err;
if (!result_var)
return llvm::createStringError(llvm::inconvertibleErrorCode(),
"null result var");
return llvm::createStringError("null result var");

result_var->overwriteAccess(swift::AccessLevel::Public);
result_var->overwriteSetterAccess(swift::AccessLevel::Public);
Expand Down Expand Up @@ -807,13 +802,11 @@ llvm::Error SwiftASTManipulator::FixupResultAfterTypeChecking() {

if (!error_var_or_err)
return llvm::createStringError(
llvm::inconvertibleErrorCode(),
"Could not add external error variable: " +
llvm::toString(error_var_or_err.takeError()));
llvm::toString(error_var_or_err.takeError()));
swift::VarDecl *error_var = *error_var_or_err;
if (!error_var)
return llvm::createStringError(llvm::inconvertibleErrorCode(),
"null error variable.");
return llvm::createStringError("null error variable.");
error_var->overwriteAccess(swift::AccessLevel::Public);
error_var->overwriteSetterAccess(
swift::AccessLevel::Public);
Expand Down Expand Up @@ -899,22 +892,19 @@ llvm::Expected<swift::Type> SwiftASTManipulator::GetSwiftTypeForVariable(
variable.m_type.GetTypeSystem().dyn_cast_or_null<TypeSystemSwift>();

if (!type_system_swift)
return llvm::make_error<llvm::StringError>("no typesystem",
llvm::inconvertibleErrorCode());
return llvm::createStringError("no typesystem");

// When injecting a value pack or pack count into the outer
// lldb_expr function, treat it as an opaque raw pointer.
if (m_bind_generic_types == lldb::eDontBind && variable.IsUnboundPack()) {
auto swift_ast_ctx = type_system_swift->GetSwiftASTContext(&m_sc);
if (!swift_ast_ctx)
return llvm::make_error<llvm::StringError>(
"no typesystem for variable " + variable.GetName().str(),
llvm::inconvertibleErrorCode());
return llvm::createStringError("no typesystem for variable " +
variable.GetName().str());

auto it = m_type_aliases.find("$__lldb_builtin_ptr_t");
if (it == m_type_aliases.end())
return llvm::make_error<llvm::StringError>(
"no $__lldb_builtin_ptr_t", llvm::inconvertibleErrorCode());
return llvm::createStringError("no $__lldb_builtin_ptr_t");

return swift::Type(it->second);
}
Expand All @@ -928,8 +918,7 @@ llvm::Expected<swift::Type> SwiftASTManipulator::GetSwiftTypeForVariable(
if (!swift_type_or_err)
return swift_type_or_err.takeError();
if (!swift_type_or_err.get())
return llvm::make_error<llvm::StringError>("null Swift type",
llvm::inconvertibleErrorCode());
return llvm::createStringError("null Swift type");

// One tricky bit here is that this var may be an argument to the
// function whose context we are emulating, and that argument might be
Expand Down Expand Up @@ -1247,8 +1236,7 @@ SwiftASTManipulator::MakeTypealias(swift::Identifier name, CompilerType &type,
bool make_private,
swift::DeclContext *decl_ctx) {
if (!IsValid())
return llvm::createStringError(llvm::inconvertibleErrorCode(),
"Invalid SwiftASTManipulator");
return llvm::createStringError("Invalid SwiftASTManipulator");

// If no DeclContext was passed in make this a global typealias.
if (!decl_ctx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,6 @@ AddRequiredAliases(Block *block, lldb::StackFrameSP &stack_frame_sp,
if (!self_type.IsValid() ||
!self_type.GetTypeSystem()->SupportsLanguage(lldb::eLanguageTypeSwift))
return llvm::createStringError(
llvm::inconvertibleErrorCode(),
"Unable to add the aliases the expression needs because "
"self isn't valid.");

Expand All @@ -577,7 +576,6 @@ AddRequiredAliases(Block *block, lldb::StackFrameSP &stack_frame_sp,

if (!imported_self_type.IsValid())
return llvm::createStringError(
llvm::inconvertibleErrorCode(),
"Unable to add the aliases the expression needs because the "
"self type from an import isn't valid.");

Expand All @@ -587,7 +585,6 @@ AddRequiredAliases(Block *block, lldb::StackFrameSP &stack_frame_sp,
*stack_frame, imported_self_type);
if (!imported_self_type)
return llvm::createStringError(
llvm::inconvertibleErrorCode(),
"Unable to add the aliases the expression needs because the Swift "
"expression parser couldn't bind the type parameters for self.");
}
Expand All @@ -597,7 +594,6 @@ AddRequiredAliases(Block *block, lldb::StackFrameSP &stack_frame_sp,
imported_self_type.GetTypeSystem().dyn_cast_or_null<TypeSystemSwift>();
if (!swift_type_system)
return llvm::createStringError(
llvm::inconvertibleErrorCode(),
"Unable to add the aliases the expression needs because "
"self is not a Swift type.");

Expand All @@ -607,7 +603,6 @@ AddRequiredAliases(Block *block, lldb::StackFrameSP &stack_frame_sp,
imported_self_type.GetOpaqueQualType());
if (!imported_self_type)
return llvm::createStringError(
llvm::inconvertibleErrorCode(),
"Unable to add the aliases the expression needs because "
"the Swift expression parser couldn't get the referent "
"type for self.");
Expand All @@ -618,7 +613,6 @@ AddRequiredAliases(Block *block, lldb::StackFrameSP &stack_frame_sp,
imported_self_type.GetTypeSystem().dyn_cast_or_null<TypeSystemSwift>();
if (!swift_type_system)
return llvm::createStringError(
llvm::inconvertibleErrorCode(),
"Unable to add the aliases the expression needs because "
"self is not a Swift type.");

Expand All @@ -628,7 +622,6 @@ AddRequiredAliases(Block *block, lldb::StackFrameSP &stack_frame_sp,
imported_self_type.GetOpaqueQualType(), stack_frame_sp.get());
if (!imported_self_type)
return llvm::createStringError(
llvm::inconvertibleErrorCode(),
"Unable to add the aliases the expression needs because the Swift "
"expression parser couldn't get the instance type for self.");
}
Expand All @@ -641,13 +634,11 @@ AddRequiredAliases(Block *block, lldb::StackFrameSP &stack_frame_sp,
"Couldn't get SwiftASTContext type for self type {0}.",
imported_self_type.GetDisplayTypeName());
return llvm::createStringError(
llvm::inconvertibleErrorCode(),
"Unable to add the aliases the expression needs because the Swift "
"expression parser couldn't get the Swift type for self.");
}
if (!swift_self_type.get())
return llvm::createStringError(llvm::inconvertibleErrorCode(),
"null self type");
return llvm::createStringError("null self type");

swift::Type object_type = swift_self_type.get()->getWithoutSpecifierType();

Expand All @@ -665,7 +656,6 @@ AddRequiredAliases(Block *block, lldb::StackFrameSP &stack_frame_sp,

if (!optional_type || optional_type->getGenericArgs().empty())
return llvm::createStringError(
llvm::inconvertibleErrorCode(),
"Unable to add the aliases the expression needs because the Swift "
"expression parser couldn't get an optional type for self.");

Expand All @@ -675,7 +665,6 @@ AddRequiredAliases(Block *block, lldb::StackFrameSP &stack_frame_sp,
if (!llvm::isa<swift::ClassType>(first_arg_type) &&
!llvm::isa<swift::BoundGenericClassType>(first_arg_type))
return llvm::createStringError(
llvm::inconvertibleErrorCode(),
"Unable to add the aliases the expression needs because "
"weakly captured type is not a class type.");

Expand All @@ -688,7 +677,6 @@ AddRequiredAliases(Block *block, lldb::StackFrameSP &stack_frame_sp,
"SEP:AddRequiredAliases: Failed to resolve the self archetype - "
"could not make the $__lldb_context typealias.");
return llvm::createStringError(
llvm::inconvertibleErrorCode(),
"Unable to add the aliases the expression needs because the "
"Swift expression parser couldn't resolve the self archetype.");
}
Expand All @@ -702,10 +690,10 @@ AddRequiredAliases(Block *block, lldb::StackFrameSP &stack_frame_sp,
"SEP:AddRequiredAliases: Failed to make the $__lldb_context "
"typealias.");
return llvm::createStringError(
llvm::inconvertibleErrorCode(),
"Unable to add the aliases the expression needs because the "
"Swift expression parser couldn't create a context type "
"alias for lldb. " + llvm::toString(type_alias_decl.takeError()));
"alias for lldb. " +
llvm::toString(type_alias_decl.takeError()));
}

return llvm::Error::success();
Expand Down Expand Up @@ -1135,12 +1123,10 @@ AddArchetypeTypeAliases(std::unique_ptr<SwiftASTManipulator> &code_manipulator,
llvm::SmallVector<swift::TypeAliasDecl *> type_aliases;
lldb::ProcessSP process_sp(stack_frame.CalculateProcess());
if (!process_sp)
return llvm::createStringError(llvm::inconvertibleErrorCode(),
"no process");
return llvm::createStringError("no process");
auto *runtime = SwiftLanguageRuntime::Get(process_sp);
if (!runtime)
return llvm::createStringError(llvm::inconvertibleErrorCode(),
"no runtime");
return llvm::createStringError("no runtime");

auto &typeref_typesystem = swift_ast_context.GetTypeSystemSwiftTypeRef();

Expand All @@ -1151,8 +1137,7 @@ AddArchetypeTypeAliases(std::unique_ptr<SwiftASTManipulator> &code_manipulator,
if (auto signature = SwiftLanguageRuntime::GetGenericSignature(
func_name.GetStringRef(), typeref_typesystem))
if (signature->pack_expansions.size())
return llvm::createStringError(llvm::inconvertibleErrorCode(),
"[AddArchetypeTypeAliases] Variadic "
return llvm::createStringError("[AddArchetypeTypeAliases] Variadic "
"generic functions are not supported.");

struct MetadataPointerInfo {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,24 +328,21 @@ static llvm::Error AddVariableInfo(
if (!target_type.IsValid()) {
// Treat an invalid type for self as a fatal error.
if (is_self)
return llvm::createStringError(llvm::inconvertibleErrorCode(),
"type for self is invalid");
return llvm::createStringError("type for self is invalid");
return llvm::Error::success();
}

// Report a fatal error if self can't be reconstructed as a Swift AST type.
if (is_self) {
auto self_ty = ast_context.GetSwiftType(target_type);
if (!self_ty)
return llvm::createStringError(llvm::inconvertibleErrorCode(),
"type for self cannot be reconstructed: " +
llvm::toString(self_ty.takeError()));
return llvm::createStringError("type for self cannot be reconstructed: " +
llvm::toString(self_ty.takeError()));
}

auto ts = target_type.GetTypeSystem().dyn_cast_or_null<TypeSystemSwift>();
if (!ts)
return llvm::createStringError(llvm::inconvertibleErrorCode(),
"type for self has no type system");
return llvm::createStringError("type for self has no type system");

// If we couldn't fully realize the type, then we aren't going
// to get very far making a local out of it, so discard it here.
Expand Down
3 changes: 1 addition & 2 deletions lldb/source/Plugins/Language/Swift/SwiftArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -475,8 +475,7 @@ llvm::Expected<uint32_t> lldb_private::formatters::swift::
ArraySyntheticFrontEnd::CalculateNumChildren() {
if (m_array_buffer)
return m_array_buffer->GetCount();
return llvm::make_error<llvm::StringError>("failed to update array data",
llvm::inconvertibleErrorCode());
return llvm::createStringError("failed to update array data");
}

lldb::ValueObjectSP
Expand Down
Loading