Skip to content

Commit 2d4eac7

Browse files
committed
Simplify createStringError calls (NFC)
1 parent f303520 commit 2d4eac7

File tree

6 files changed

+88
-156
lines changed

6 files changed

+88
-156
lines changed

lldb/source/Plugins/ExpressionParser/Swift/SwiftASTManipulator.cpp

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -706,8 +706,7 @@ bool SwiftASTManipulator::IsExpressionResultNonCopyable() {
706706

707707
llvm::Error SwiftASTManipulator::FixupResultAfterTypeChecking() {
708708
if (!IsValid())
709-
return llvm::createStringError(llvm::inconvertibleErrorCode(),
710-
"Operating on invalid SwiftASTManipulator");
709+
return llvm::createStringError("Operating on invalid SwiftASTManipulator");
711710
// Run through the result decls and figure out the return type.
712711

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

739738
if (result_type.isNull())
740739
return llvm::createStringError(
741-
llvm::inconvertibleErrorCode(),
742740
"Could not find the result type for this expression.");
743741
if (result_type->is<swift::ErrorType>())
744-
return llvm::createStringError(llvm::inconvertibleErrorCode(),
745-
"Result type is the error type.");
742+
return llvm::createStringError("Result type is the error type.");
746743

747744
swift::ASTContext &ast_context = m_source_file.getASTContext();
748745
CompilerType return_ast_type = ToCompilerType(result_type.getPointer());
@@ -755,13 +752,11 @@ llvm::Error SwiftASTManipulator::FixupResultAfterTypeChecking() {
755752
AddExternalVariable(result_var_name, return_ast_type, metadata_sp);
756753
if (!result_var_or_err)
757754
return llvm::createStringError(
758-
llvm::inconvertibleErrorCode(),
759755
"Could not add external result variable." +
760-
llvm::toString(result_var_or_err.takeError()));
756+
llvm::toString(result_var_or_err.takeError()));
761757
swift::VarDecl *result_var = *result_var_or_err;
762758
if (!result_var)
763-
return llvm::createStringError(llvm::inconvertibleErrorCode(),
764-
"null result var");
759+
return llvm::createStringError("null result var");
765760

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

808803
if (!error_var_or_err)
809804
return llvm::createStringError(
810-
llvm::inconvertibleErrorCode(),
811805
"Could not add external error variable: " +
812-
llvm::toString(error_var_or_err.takeError()));
806+
llvm::toString(error_var_or_err.takeError()));
813807
swift::VarDecl *error_var = *error_var_or_err;
814808
if (!error_var)
815-
return llvm::createStringError(llvm::inconvertibleErrorCode(),
816-
"null error variable.");
809+
return llvm::createStringError("null error variable.");
817810
error_var->overwriteAccess(swift::AccessLevel::Public);
818811
error_var->overwriteSetterAccess(
819812
swift::AccessLevel::Public);
@@ -899,22 +892,19 @@ llvm::Expected<swift::Type> SwiftASTManipulator::GetSwiftTypeForVariable(
899892
variable.m_type.GetTypeSystem().dyn_cast_or_null<TypeSystemSwift>();
900893

901894
if (!type_system_swift)
902-
return llvm::make_error<llvm::StringError>("no typesystem",
903-
llvm::inconvertibleErrorCode());
895+
return llvm::createStringError("no typesystem");
904896

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

914905
auto it = m_type_aliases.find("$__lldb_builtin_ptr_t");
915906
if (it == m_type_aliases.end())
916-
return llvm::make_error<llvm::StringError>(
917-
"no $__lldb_builtin_ptr_t", llvm::inconvertibleErrorCode());
907+
return llvm::createStringError("no $__lldb_builtin_ptr_t");
918908

919909
return swift::Type(it->second);
920910
}
@@ -928,8 +918,7 @@ llvm::Expected<swift::Type> SwiftASTManipulator::GetSwiftTypeForVariable(
928918
if (!swift_type_or_err)
929919
return swift_type_or_err.takeError();
930920
if (!swift_type_or_err.get())
931-
return llvm::make_error<llvm::StringError>("null Swift type",
932-
llvm::inconvertibleErrorCode());
921+
return llvm::createStringError("null Swift type");
933922

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

12531241
// If no DeclContext was passed in make this a global typealias.
12541242
if (!decl_ctx)

lldb/source/Plugins/ExpressionParser/Swift/SwiftExpressionParser.cpp

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,6 @@ AddRequiredAliases(Block *block, lldb::StackFrameSP &stack_frame_sp,
566566
if (!self_type.IsValid() ||
567567
!self_type.GetTypeSystem()->SupportsLanguage(lldb::eLanguageTypeSwift))
568568
return llvm::createStringError(
569-
llvm::inconvertibleErrorCode(),
570569
"Unable to add the aliases the expression needs because "
571570
"self isn't valid.");
572571

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

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

@@ -587,7 +585,6 @@ AddRequiredAliases(Block *block, lldb::StackFrameSP &stack_frame_sp,
587585
*stack_frame, imported_self_type);
588586
if (!imported_self_type)
589587
return llvm::createStringError(
590-
llvm::inconvertibleErrorCode(),
591588
"Unable to add the aliases the expression needs because the Swift "
592589
"expression parser couldn't bind the type parameters for self.");
593590
}
@@ -597,7 +594,6 @@ AddRequiredAliases(Block *block, lldb::StackFrameSP &stack_frame_sp,
597594
imported_self_type.GetTypeSystem().dyn_cast_or_null<TypeSystemSwift>();
598595
if (!swift_type_system)
599596
return llvm::createStringError(
600-
llvm::inconvertibleErrorCode(),
601597
"Unable to add the aliases the expression needs because "
602598
"self is not a Swift type.");
603599

@@ -607,7 +603,6 @@ AddRequiredAliases(Block *block, lldb::StackFrameSP &stack_frame_sp,
607603
imported_self_type.GetOpaqueQualType());
608604
if (!imported_self_type)
609605
return llvm::createStringError(
610-
llvm::inconvertibleErrorCode(),
611606
"Unable to add the aliases the expression needs because "
612607
"the Swift expression parser couldn't get the referent "
613608
"type for self.");
@@ -618,7 +613,6 @@ AddRequiredAliases(Block *block, lldb::StackFrameSP &stack_frame_sp,
618613
imported_self_type.GetTypeSystem().dyn_cast_or_null<TypeSystemSwift>();
619614
if (!swift_type_system)
620615
return llvm::createStringError(
621-
llvm::inconvertibleErrorCode(),
622616
"Unable to add the aliases the expression needs because "
623617
"self is not a Swift type.");
624618

@@ -628,7 +622,6 @@ AddRequiredAliases(Block *block, lldb::StackFrameSP &stack_frame_sp,
628622
imported_self_type.GetOpaqueQualType(), stack_frame_sp.get());
629623
if (!imported_self_type)
630624
return llvm::createStringError(
631-
llvm::inconvertibleErrorCode(),
632625
"Unable to add the aliases the expression needs because the Swift "
633626
"expression parser couldn't get the instance type for self.");
634627
}
@@ -641,13 +634,11 @@ AddRequiredAliases(Block *block, lldb::StackFrameSP &stack_frame_sp,
641634
"Couldn't get SwiftASTContext type for self type {0}.",
642635
imported_self_type.GetDisplayTypeName());
643636
return llvm::createStringError(
644-
llvm::inconvertibleErrorCode(),
645637
"Unable to add the aliases the expression needs because the Swift "
646638
"expression parser couldn't get the Swift type for self.");
647639
}
648640
if (!swift_self_type.get())
649-
return llvm::createStringError(llvm::inconvertibleErrorCode(),
650-
"null self type");
641+
return llvm::createStringError("null self type");
651642

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

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

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

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

@@ -688,7 +677,6 @@ AddRequiredAliases(Block *block, lldb::StackFrameSP &stack_frame_sp,
688677
"SEP:AddRequiredAliases: Failed to resolve the self archetype - "
689678
"could not make the $__lldb_context typealias.");
690679
return llvm::createStringError(
691-
llvm::inconvertibleErrorCode(),
692680
"Unable to add the aliases the expression needs because the "
693681
"Swift expression parser couldn't resolve the self archetype.");
694682
}
@@ -702,10 +690,10 @@ AddRequiredAliases(Block *block, lldb::StackFrameSP &stack_frame_sp,
702690
"SEP:AddRequiredAliases: Failed to make the $__lldb_context "
703691
"typealias.");
704692
return llvm::createStringError(
705-
llvm::inconvertibleErrorCode(),
706693
"Unable to add the aliases the expression needs because the "
707694
"Swift expression parser couldn't create a context type "
708-
"alias for lldb. " + llvm::toString(type_alias_decl.takeError()));
695+
"alias for lldb. " +
696+
llvm::toString(type_alias_decl.takeError()));
709697
}
710698

711699
return llvm::Error::success();
@@ -1135,12 +1123,10 @@ AddArchetypeTypeAliases(std::unique_ptr<SwiftASTManipulator> &code_manipulator,
11351123
llvm::SmallVector<swift::TypeAliasDecl *> type_aliases;
11361124
lldb::ProcessSP process_sp(stack_frame.CalculateProcess());
11371125
if (!process_sp)
1138-
return llvm::createStringError(llvm::inconvertibleErrorCode(),
1139-
"no process");
1126+
return llvm::createStringError("no process");
11401127
auto *runtime = SwiftLanguageRuntime::Get(process_sp);
11411128
if (!runtime)
1142-
return llvm::createStringError(llvm::inconvertibleErrorCode(),
1143-
"no runtime");
1129+
return llvm::createStringError("no runtime");
11441130

11451131
auto &typeref_typesystem = swift_ast_context.GetTypeSystemSwiftTypeRef();
11461132

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

11581143
struct MetadataPointerInfo {

lldb/source/Plugins/ExpressionParser/Swift/SwiftUserExpression.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -328,24 +328,21 @@ static llvm::Error AddVariableInfo(
328328
if (!target_type.IsValid()) {
329329
// Treat an invalid type for self as a fatal error.
330330
if (is_self)
331-
return llvm::createStringError(llvm::inconvertibleErrorCode(),
332-
"type for self is invalid");
331+
return llvm::createStringError("type for self is invalid");
333332
return llvm::Error::success();
334333
}
335334

336335
// Report a fatal error if self can't be reconstructed as a Swift AST type.
337336
if (is_self) {
338337
auto self_ty = ast_context.GetSwiftType(target_type);
339338
if (!self_ty)
340-
return llvm::createStringError(llvm::inconvertibleErrorCode(),
341-
"type for self cannot be reconstructed: " +
342-
llvm::toString(self_ty.takeError()));
339+
return llvm::createStringError("type for self cannot be reconstructed: " +
340+
llvm::toString(self_ty.takeError()));
343341
}
344342

345343
auto ts = target_type.GetTypeSystem().dyn_cast_or_null<TypeSystemSwift>();
346344
if (!ts)
347-
return llvm::createStringError(llvm::inconvertibleErrorCode(),
348-
"type for self has no type system");
345+
return llvm::createStringError("type for self has no type system");
349346

350347
// If we couldn't fully realize the type, then we aren't going
351348
// to get very far making a local out of it, so discard it here.

lldb/source/Plugins/Language/Swift/SwiftArray.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,8 +475,7 @@ llvm::Expected<uint32_t> lldb_private::formatters::swift::
475475
ArraySyntheticFrontEnd::CalculateNumChildren() {
476476
if (m_array_buffer)
477477
return m_array_buffer->GetCount();
478-
return llvm::make_error<llvm::StringError>("failed to update array data",
479-
llvm::inconvertibleErrorCode());
478+
return llvm::createStringError("failed to update array data");
480479
}
481480

482481
lldb::ValueObjectSP

0 commit comments

Comments
 (0)