@@ -94,6 +94,9 @@ void SwiftASTManipulatorBase::DoInitialization() {
94
94
swift::FuncDecl *entrypoint_decl = nullptr ;
95
95
// / This is optional.
96
96
swift::FuncDecl *ext_method_decl = nullptr ;
97
+ // / When evaluating a generic expression this is the inner
98
+ // / function containing the user expression.
99
+ swift::FuncDecl *user_expr_decl = nullptr ;
97
100
// / When evaluating self as generic, this is the trampoline function that
98
101
// / calls the ext_method_decl.
99
102
swift::FuncDecl *trampoline_decl = nullptr ;
@@ -128,6 +131,8 @@ void SwiftASTManipulatorBase::DoInitialization() {
128
131
entrypoint_decl = FD;
129
132
else if (FD->getNameStr ().equals (" $__lldb_sink" ))
130
133
sink_decl = FD;
134
+ else if (FD->getNameStr ().equals (" $__lldb_user_expr" ))
135
+ user_expr_decl = FD;
131
136
return Action::SkipChildren ();
132
137
}
133
138
};
@@ -136,16 +141,17 @@ void SwiftASTManipulatorBase::DoInitialization() {
136
141
m_source_file.walk (func_finder);
137
142
138
143
m_extension_decl = func_finder.extension_decl ;
139
- if (m_extension_decl ) {
144
+ if (func_finder. ext_method_decl ) {
140
145
m_function_decl = func_finder.ext_method_decl ;
141
146
m_entrypoint_decl = func_finder.entrypoint_decl ;
142
- m_trampoline_decl = func_finder.trampoline_decl ;
143
- m_sink_decl = func_finder.sink_decl ;
144
- } else {
147
+ } else if (func_finder.user_expr_decl ) {
148
+ m_function_decl = func_finder.user_expr_decl ;
149
+ m_entrypoint_decl = func_finder.entrypoint_decl ;
150
+ } else
145
151
m_function_decl = func_finder.entrypoint_decl ;
146
- m_entrypoint_decl = nullptr ;
147
- }
148
-
152
+ m_entrypoint_decl = func_finder. entrypoint_decl ;
153
+ m_trampoline_decl = func_finder. trampoline_decl ;
154
+ m_sink_decl = func_finder. sink_decl ;
149
155
assert (m_function_decl);
150
156
151
157
// Find the body in the function
@@ -698,25 +704,24 @@ bool SwiftASTManipulator::FixupResultAfterTypeChecking(Status &error) {
698
704
swift::Type result_type;
699
705
for (size_t i = 0 ; i < num_results; i++) {
700
706
swift::VarDecl *the_decl = m_result_info[i].tmp_var_decl ;
701
- if (the_decl->hasInterfaceType ()) {
702
- swift::Type its_type = the_decl->getType ();
703
- if (result_type.isNull ()) {
704
- result_type = its_type;
705
- } else if (!its_type.getPointer ()->isEqual (result_type)) {
706
- std::string prev_type_name = result_type.getPointer ()->getString ();
707
- std::string cur_type_name = its_type.getPointer ()->getString ();
708
-
709
- error.SetErrorStringWithFormat (
710
- " Type for %zuth return value is inconsistent, previous type: %s, "
711
- " current type: %s." ,
712
- i, prev_type_name.c_str (), cur_type_name.c_str ());
713
- return false ;
714
- }
715
- } else {
707
+ if (!the_decl->hasInterfaceType ()) {
716
708
error.SetErrorStringWithFormat (
717
709
" Type of %zuth return value could not be determined." , i);
718
710
return false ;
719
711
}
712
+ swift::Type its_type = the_decl->getType ();
713
+ if (result_type.isNull ()) {
714
+ result_type = its_type;
715
+ } else if (!its_type.getPointer ()->isEqual (result_type)) {
716
+ std::string prev_type_name = result_type.getPointer ()->getString ();
717
+ std::string cur_type_name = its_type.getPointer ()->getString ();
718
+
719
+ error.SetErrorStringWithFormat (
720
+ " Type for %zuth return value is inconsistent, previous type: %s, "
721
+ " current type: %s." ,
722
+ i, prev_type_name.c_str (), cur_type_name.c_str ());
723
+ return false ;
724
+ }
720
725
}
721
726
722
727
if (result_type.isNull ()) {
@@ -728,7 +733,6 @@ bool SwiftASTManipulator::FixupResultAfterTypeChecking(Status &error) {
728
733
}
729
734
730
735
swift::ASTContext &ast_context = m_source_file.getASTContext ();
731
-
732
736
CompilerType return_ast_type = ToCompilerType (result_type.getPointer ());
733
737
swift::Identifier result_var_name =
734
738
ast_context.getIdentifier (GetResultName ());
@@ -864,7 +868,9 @@ swift::FuncDecl *SwiftASTManipulator::GetFunctionToInjectVariableInto(
864
868
// When not binding generic type parameters, we want to inject the metadata
865
869
// pointers in the wrapper, so we can pass them as opaque pointers in the
866
870
// trampoline function later on.
867
- if (m_bind_generic_types == lldb::eDontBind && variable.IsMetadataPointer ())
871
+ if (m_bind_generic_types == lldb::eDontBind &&
872
+ (variable.IsMetadataPointer () || variable.IsPackCount () ||
873
+ variable.IsUnboundPack ()))
868
874
return m_entrypoint_decl;
869
875
870
876
return m_function_decl;
@@ -878,6 +884,20 @@ llvm::Optional<swift::Type> SwiftASTManipulator::GetSwiftTypeForVariable(
878
884
if (!type_system_swift)
879
885
return {};
880
886
887
+ // When injecting a value pack or pack count into the outer
888
+ // lldb_expr function, treat it as an opaque raw pointer.
889
+ if (m_bind_generic_types == lldb::eDontBind && variable.IsUnboundPack ()) {
890
+ auto swift_ast_ctx = type_system_swift->GetSwiftASTContext ();
891
+ if (swift_ast_ctx) {
892
+ auto it = m_type_aliases.find (" $__lldb_builtin_ptr_t" );
893
+ if (it == m_type_aliases.end ())
894
+ return {};
895
+ return swift::Type (it->second );
896
+ }
897
+ // swift_ast_ctx->GetBuiltinRawPointerType());
898
+ return {};
899
+ }
900
+
881
901
// This might be a referenced type, which will confuse the type checker.
882
902
// The access pattern for these types is the same as for the referent
883
903
// type, so it is fine to just strip it off.
@@ -930,16 +950,20 @@ swift::VarDecl *SwiftASTManipulator::GetVarDeclForVariableInFunction(
930
950
const swift::Identifier name = variable.GetName ();
931
951
// We may need to mutate the self variable later, so hardcode it to a var
932
952
// in that case.
933
- const auto introducer = variable.IsSelf () ? swift::VarDecl::Introducer::Var
934
- : variable.GetVarIntroducer ();
953
+ const auto introducer = (variable.IsSelf () || variable.IsUnboundPack ())
954
+ ? swift::VarDecl::Introducer::Var
955
+ : variable.GetVarIntroducer ();
935
956
936
957
const swift::ASTContext &ast_context = m_source_file.getASTContext ();
937
958
swift::VarDecl *redirected_var_decl = new (ast_context) swift::VarDecl (
938
- /* is_staic */ false , introducer, loc, name, containing_function);
959
+ /* is_static */ false , introducer, loc, name, containing_function);
939
960
940
961
redirected_var_decl->setInterfaceType (swift_type);
941
962
redirected_var_decl->setDebuggerVar (true );
942
963
redirected_var_decl->setImplicit (true );
964
+ redirected_var_decl->setImplInfo (swift::StorageImplInfo (
965
+ swift::ReadImplKind::Stored, swift::WriteImplKind::Stored,
966
+ swift::ReadWriteImplKind::Stored));
943
967
944
968
// This avoids having local variables filtered out by
945
969
// swift::namelookup::filterForDiscriminator().
@@ -1245,6 +1269,8 @@ SwiftASTManipulator::MakeTypealias(swift::Identifier name, CompilerType &type,
1245
1269
m_source_file.addTopLevelDecl (type_alias_decl);
1246
1270
}
1247
1271
1272
+ m_type_aliases.insert (
1273
+ {name.str (), type_alias_decl->getStructuralType ().getPointer ()});
1248
1274
return type_alias_decl;
1249
1275
}
1250
1276
0 commit comments