@@ -448,7 +448,7 @@ static CompilerType GetSwiftTypeForVariableValueObject(
448
448
CompilerType result = valobj_sp->GetCompilerType ();
449
449
if (!result)
450
450
return {};
451
- if (bind_generic_types != lldb::eDontBind )
451
+ if (SwiftASTManipulator::ShouldBindGenericTypes (bind_generic_types) )
452
452
result = runtime->BindGenericTypeParameters (*stack_frame_sp, result);
453
453
if (!result)
454
454
return {};
@@ -489,7 +489,8 @@ CompilerType SwiftExpressionParser::ResolveVariable(
489
489
// though, as we don't bind the generic parameters in that case.
490
490
if (swift_type_system->IsMeaninglessWithoutDynamicResolution (
491
491
var_type.GetOpaqueQualType ()) &&
492
- bind_generic_types != lldb::eDontBind && use_dynamic_value) {
492
+ SwiftASTManipulator::ShouldBindGenericTypes (bind_generic_types) &&
493
+ use_dynamic_value) {
493
494
var_type = GetSwiftTypeForVariableValueObject (
494
495
valobj_sp->GetDynamicValue (use_dynamic), stack_frame_sp, runtime,
495
496
bind_generic_types);
@@ -583,7 +584,7 @@ AddRequiredAliases(Block *block, lldb::StackFrameSP &stack_frame_sp,
583
584
" self type from an import isn't valid." );
584
585
585
586
auto *stack_frame = stack_frame_sp.get ();
586
- if (bind_generic_types != lldb::eDontBind ) {
587
+ if (SwiftASTManipulator::ShouldBindGenericTypes (bind_generic_types) ) {
587
588
imported_self_type = swift_runtime->BindGenericTypeParameters (
588
589
*stack_frame, imported_self_type);
589
590
if (!imported_self_type)
@@ -1710,6 +1711,11 @@ SwiftExpressionParser::Parse(DiagnosticManager &diagnostic_manager,
1710
1711
auto expr_diagnostics = m_swift_ast_ctx.getScopedDiagnosticConsumer ();
1711
1712
m_swift_ast_ctx.GetDiagnosticEngine ().resetHadAnyError ();
1712
1713
1714
+ // The result in case parsing the expression fails. If the option is auto
1715
+ // expression evaluation should retry by binding the generic types.
1716
+ auto parse_result_failure = m_options.GetBindGenericTypes () == lldb::eBindAuto
1717
+ ? ParseResult::retry_bind_generic_params
1718
+ : ParseResult::unrecoverable_error;
1713
1719
// Helper function to diagnose errors in m_swift_scratch_context.
1714
1720
unsigned buffer_id = UINT32_MAX;
1715
1721
auto DiagnoseSwiftASTContextError = [&]() {
@@ -1726,7 +1732,7 @@ SwiftExpressionParser::Parse(DiagnosticManager &diagnostic_manager,
1726
1732
const bool playground = m_options.GetPlaygroundTransformEnabled ();
1727
1733
1728
1734
if (!m_exe_scope)
1729
- return ParseResult::unrecoverable_error ;
1735
+ return parse_result_failure ;
1730
1736
1731
1737
// Parse the expression and import all nececssary swift modules.
1732
1738
auto parsed_expr = ParseAndImport (*expr_diagnostics, variable_map, buffer_id,
@@ -1767,7 +1773,7 @@ SwiftExpressionParser::Parse(DiagnosticManager &diagnostic_manager,
1767
1773
return ParseResult::retry_fresh_context;
1768
1774
1769
1775
// Unrecoverable error.
1770
- return ParseResult::unrecoverable_error ;
1776
+ return parse_result_failure ;
1771
1777
}
1772
1778
1773
1779
// If any generics are present, this expression is not parseable.
@@ -1809,11 +1815,11 @@ SwiftExpressionParser::Parse(DiagnosticManager &diagnostic_manager,
1809
1815
" Missing type debug information for variable \" %s\" : %s" ,
1810
1816
var.GetName ().str ().str ().c_str (),
1811
1817
llvm::toString (std::move (error)).c_str ());
1812
- return ParseResult::unrecoverable_error ;
1818
+ return parse_result_failure ;
1813
1819
}
1814
1820
// Otherwise print the diagnostics from the Swift compiler.
1815
1821
DiagnoseSwiftASTContextError ();
1816
- return ParseResult::unrecoverable_error ;
1822
+ return parse_result_failure ;
1817
1823
}
1818
1824
1819
1825
if (repl)
@@ -1826,7 +1832,7 @@ SwiftExpressionParser::Parse(DiagnosticManager &diagnostic_manager,
1826
1832
if (error) {
1827
1833
diagnostic_manager.PutString (eSeverityError,
1828
1834
llvm::toString (std::move (error)));
1829
- return ParseResult::unrecoverable_error ;
1835
+ return parse_result_failure ;
1830
1836
}
1831
1837
} else {
1832
1838
swift::performPlaygroundTransform (
@@ -1842,7 +1848,7 @@ SwiftExpressionParser::Parse(DiagnosticManager &diagnostic_manager,
1842
1848
diagnostic_manager.PutString (
1843
1849
eSeverityError,
1844
1850
" Cannot evaluate an expression that results in a ~Copyable type" );
1845
- return ParseResult::unrecoverable_error ;
1851
+ return parse_result_failure ;
1846
1852
}
1847
1853
1848
1854
// FIXME: We now should have to do the name binding and type
@@ -1965,10 +1971,9 @@ SwiftExpressionParser::Parse(DiagnosticManager &diagnostic_manager,
1965
1971
if (!var_info) {
1966
1972
auto error_string = llvm::toString (var_info.takeError ());
1967
1973
LLDB_LOG (log, " Variable info failzed to materialize with error: {0}" ,
1968
- error_string);
1969
-
1974
+ error_string);
1970
1975
1971
- return ParseResult::unrecoverable_error ;
1976
+ return parse_result_failure ;
1972
1977
}
1973
1978
1974
1979
const char *name = ConstString (variable.GetName ().get ()).GetCString ();
@@ -2001,7 +2006,7 @@ SwiftExpressionParser::Parse(DiagnosticManager &diagnostic_manager,
2001
2006
2002
2007
if (expr_diagnostics->HasErrors ()) {
2003
2008
DiagnoseSwiftASTContextError ();
2004
- return ParseResult::unrecoverable_error ;
2009
+ return parse_result_failure ;
2005
2010
}
2006
2011
2007
2012
if (log) {
@@ -2025,7 +2030,7 @@ SwiftExpressionParser::Parse(DiagnosticManager &diagnostic_manager,
2025
2030
2026
2031
if (expr_diagnostics->HasErrors ()) {
2027
2032
DiagnoseSwiftASTContextError ();
2028
- return ParseResult::unrecoverable_error ;
2033
+ return parse_result_failure ;
2029
2034
}
2030
2035
2031
2036
{
@@ -2063,14 +2068,14 @@ SwiftExpressionParser::Parse(DiagnosticManager &diagnostic_manager,
2063
2068
diagnostic_manager.PutString (
2064
2069
eSeverityInfo, " couldn't IRGen expression: Clang importer error" );
2065
2070
DiagnoseSwiftASTContextError ();
2066
- return ParseResult::unrecoverable_error ;
2071
+ return parse_result_failure ;
2067
2072
}
2068
2073
2069
2074
if (error_kind == ErrorKind::swift) {
2070
2075
diagnostic_manager.PutString (eSeverityInfo,
2071
2076
" couldn't IRGen expression: Swift error" );
2072
2077
DiagnoseSwiftASTContextError ();
2073
- return ParseResult::unrecoverable_error ;
2078
+ return parse_result_failure ;
2074
2079
}
2075
2080
2076
2081
if (!m_module) {
@@ -2079,7 +2084,7 @@ SwiftExpressionParser::Parse(DiagnosticManager &diagnostic_manager,
2079
2084
" couldn't IRGen expression. Please enable the expression log by "
2080
2085
" running \" log enable lldb expr\" , then run the failing expression "
2081
2086
" again, and file a bug report with the log output." );
2082
- return ParseResult::unrecoverable_error ;
2087
+ return parse_result_failure ;
2083
2088
}
2084
2089
2085
2090
if (log) {
@@ -2091,7 +2096,8 @@ SwiftExpressionParser::Parse(DiagnosticManager &diagnostic_manager,
2091
2096
}
2092
2097
2093
2098
if (ThreadSafeASTContext ast_ctx = m_swift_ast_ctx.GetASTContext ()) {
2094
- if (m_options.GetBindGenericTypes () == lldb::eDontBind &&
2099
+ if (!SwiftASTManipulator::ShouldBindGenericTypes (
2100
+ m_options.GetBindGenericTypes ()) &&
2095
2101
!RedirectCallFromSinkToTrampolineFunction (
2096
2102
*m_module.get (), *parsed_expr->code_manipulator .get (), **ast_ctx)) {
2097
2103
diagnostic_manager.Printf (
@@ -2100,7 +2106,7 @@ SwiftExpressionParser::Parse(DiagnosticManager &diagnostic_manager,
2100
2106
" expression log by running \" log enable lldb "
2101
2107
" expr\" , then run the failing expression again, and file a "
2102
2108
" bugreport with the log output." );
2103
- return ParseResult::unrecoverable_error ;
2109
+ return parse_result_failure ;
2104
2110
}
2105
2111
}
2106
2112
@@ -2120,14 +2126,14 @@ SwiftExpressionParser::Parse(DiagnosticManager &diagnostic_manager,
2120
2126
LLVMReturnStatusAction, nullptr );
2121
2127
if (has_errors) {
2122
2128
diagnostic_manager.PutString (eSeverityInfo, " LLVM verification error" );
2123
- return ParseResult::unrecoverable_error ;
2129
+ return parse_result_failure ;
2124
2130
}
2125
2131
}
2126
2132
2127
2133
if (expr_diagnostics->HasErrors ()) {
2128
2134
diagnostic_manager.PutString (eSeverityInfo, " post-IRGen error" );
2129
2135
DiagnoseSwiftASTContextError ();
2130
- return ParseResult::unrecoverable_error ;
2136
+ return parse_result_failure ;
2131
2137
}
2132
2138
2133
2139
// The Parse succeeded! Now put this module into the context's list
0 commit comments