Skip to content

Thread llvm::Expected through SwiftASTContext::Reconstruct type #8503

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
Apr 2, 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
281 changes: 142 additions & 139 deletions lldb/source/Plugins/ExpressionParser/Swift/SwiftASTManipulator.cpp

Large diffs are not rendered by default.

51 changes: 31 additions & 20 deletions lldb/source/Plugins/ExpressionParser/Swift/SwiftASTManipulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
#ifndef liblldb_SwiftASTManipulator_h
#define liblldb_SwiftASTManipulator_h

#include "lldb/Utility/Stream.h"
#include "lldb/Expression/Expression.h"
#include "lldb/Symbol/CompilerType.h"
#include "lldb/Utility/Status.h"
#include "lldb/Utility/Stream.h"

#include "swift/AST/Decl.h"
#include "swift/Basic/SourceLoc.h"
Expand Down Expand Up @@ -103,9 +104,11 @@ class SwiftASTManipulatorBase {
struct VariableInfo {
CompilerType GetType() const { return m_type; }
swift::Identifier GetName() const { return m_name; }
VariableMetadata *GetMetadata() const { return m_metadata.get(); }
void TakeMetadata(VariableMetadata *vmd) { m_metadata.reset(vmd); }
swift::VarDecl *GetDecl() const { return m_decl; }
swift::VarDecl::Introducer GetVarIntroducer() const;
bool GetIsCaptureList() const;
bool IsCaptureList() const;
bool IsMetadataPointer() const { return m_name.str().startswith("$τ"); }
bool IsOutermostMetadataPointer() const {
return m_name.str().startswith("$τ_0_");
Expand All @@ -118,33 +121,41 @@ class SwiftASTManipulatorBase {
}
bool IsUnboundPack() const { return m_is_unbound_pack; }

VariableInfo() : m_type(), m_name(), m_metadata() {}

VariableInfo(CompilerType &type, swift::Identifier name,
VariableInfo() : m_lookup_error(llvm::Error::success()) {}
VariableInfo(CompilerType type, swift::Identifier name,
VariableMetadataSP metadata,
swift::VarDecl::Introducer introducer,
bool is_capture_list = false, bool is_unbound_pack = false)
: m_type(type), m_name(name), m_var_introducer(introducer),
: m_type(type), m_name(name), m_metadata(metadata),
m_var_introducer(introducer), m_lookup_error(llvm::Error::success()),
m_is_capture_list(is_capture_list),
m_is_unbound_pack(is_unbound_pack), m_metadata(metadata) {}
m_is_unbound_pack(is_unbound_pack) {}

VariableInfo(CompilerType type, swift::Identifier name,
swift::VarDecl *decl)
: m_type(type), m_name(name), m_decl(decl),
m_lookup_error(llvm::Error::success()) {}

void Print(Stream &stream) const;

void SetType(CompilerType new_type) { m_type = new_type; }
void SetLookupError(llvm::Error &&error) {
m_lookup_error = std::move(error);
}
llvm::Error TakeLookupError() { return m_lookup_error.ToError(); }

friend class SwiftASTManipulator;

protected:
CompilerType m_type;
swift::Identifier m_name;
VariableMetadataSP m_metadata;
swift::VarDecl *m_decl = nullptr;
swift::VarDecl::Introducer m_var_introducer =
swift::VarDecl::Introducer::Var;
Status m_lookup_error;
bool m_is_capture_list = false;
bool m_is_unbound_pack = false;

public:
VariableMetadataSP m_metadata;
};

SwiftASTManipulatorBase(swift::SourceFile &source_file,
Expand Down Expand Up @@ -205,16 +216,16 @@ class SwiftASTManipulator : public SwiftASTManipulatorBase {
void FindSpecialNames(llvm::SmallVectorImpl<swift::Identifier> &names,
llvm::StringRef prefix);

swift::VarDecl *AddExternalVariable(swift::Identifier name,
CompilerType &type,
VariableMetadataSP &metadata_sp);
llvm::Expected<swift::VarDecl *>
AddExternalVariable(swift::Identifier name, CompilerType &type,
VariableMetadataSP &metadata_sp);

swift::FuncDecl *GetFunctionToInjectVariableInto(
const SwiftASTManipulator::VariableInfo &variable) const;
swift::VarDecl *GetVarDeclForVariableInFunction(
llvm::Expected<swift::VarDecl *> GetVarDeclForVariableInFunction(
const SwiftASTManipulator::VariableInfo &variable,
swift::FuncDecl *containing_function);
std::optional<swift::Type> GetSwiftTypeForVariable(
llvm::Expected<swift::Type> GetSwiftTypeForVariable(
const SwiftASTManipulator::VariableInfo &variable) const;

bool AddExternalVariables(llvm::MutableArrayRef<VariableInfo> variables);
Expand All @@ -234,12 +245,12 @@ class SwiftASTManipulator : public SwiftASTManipulatorBase {

/// Makes a typealias binding name to type in the scope of the decl_ctx. If
/// decl_ctx is a nullptr this is a global typealias.
swift::TypeAliasDecl *MakeTypealias(swift::Identifier name,
CompilerType &type,
bool make_private = true,
swift::DeclContext *decl_ctx = nullptr);
llvm::Expected<swift::TypeAliasDecl *>
MakeTypealias(swift::Identifier name, CompilerType &type,
bool make_private = true,
swift::DeclContext *decl_ctx = nullptr);

bool FixupResultAfterTypeChecking(Status &error);
llvm::Error FixupResultAfterTypeChecking();

static const char *GetArgumentName() { return "$__lldb_arg"; }
static const char *GetResultName() { return "$__lldb_result"; }
Expand Down
Loading