aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-08-20 12:34:35 +0000
committerGitHub <noreply@github.com>2021-08-20 12:34:35 +0000
commit79754bd20bdfa64a4ce91e5b4a65154c313b2d83 (patch)
tree47dc551f706c4015c017a299a4054cb7db460857 /gcc/rust/backend
parent387f73626ae0e04c3f81d71d4de6780a4caad052 (diff)
parent048261647afd1a08f681b78c90c58a9baaeef76d (diff)
downloadgcc-79754bd20bdfa64a4ce91e5b4a65154c313b2d83.zip
gcc-79754bd20bdfa64a4ce91e5b4a65154c313b2d83.tar.gz
gcc-79754bd20bdfa64a4ce91e5b4a65154c313b2d83.tar.bz2
Merge #626
626: Optional trait items r=philberty a=philberty Optional trait items like function may contain associated types. These are dependant on the associated impl block for this type in order to correctly propagate the correct types for the associated trait item during type checking and compilation. Fixes #542 Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Diffstat (limited to 'gcc/rust/backend')
-rw-r--r--gcc/rust/backend/rust-compile-context.h9
-rw-r--r--gcc/rust/backend/rust-compile-expr.h5
-rw-r--r--gcc/rust/backend/rust-compile-implitem.h214
-rw-r--r--gcc/rust/backend/rust-compile-item.h16
-rw-r--r--gcc/rust/backend/rust-compile-resolve-path.cc103
-rw-r--r--gcc/rust/backend/rust-compile-resolve-path.h18
-rw-r--r--gcc/rust/backend/rust-compile-tyty.h2
-rw-r--r--gcc/rust/backend/rust-compile.cc47
8 files changed, 377 insertions, 37 deletions
diff --git a/gcc/rust/backend/rust-compile-context.h b/gcc/rust/backend/rust-compile-context.h
index 8007c2f..66d037d 100644
--- a/gcc/rust/backend/rust-compile-context.h
+++ b/gcc/rust/backend/rust-compile-context.h
@@ -287,7 +287,7 @@ public:
// this needs to support Legacy and V0 see github #429 or #305
std::string mangle_item (const TyTy::BaseType *ty,
- const std::string &name) const;
+ const Resolver::CanonicalPath &path) const;
std::string mangle_impl_item (const TyTy::BaseType *self,
const TyTy::BaseType *ty,
@@ -336,7 +336,12 @@ public:
void visit (TyTy::InferType &) override { gcc_unreachable (); }
- void visit (TyTy::PlaceholderType &) override { gcc_unreachable (); }
+ void visit (TyTy::ProjectionType &) override { gcc_unreachable (); }
+
+ void visit (TyTy::PlaceholderType &type) override
+ {
+ type.resolve ()->accept_vis (*this);
+ }
void visit (TyTy::ParamType &param) override
{
diff --git a/gcc/rust/backend/rust-compile-expr.h b/gcc/rust/backend/rust-compile-expr.h
index 4658295..80cdc5e 100644
--- a/gcc/rust/backend/rust-compile-expr.h
+++ b/gcc/rust/backend/rust-compile-expr.h
@@ -629,6 +629,11 @@ public:
expr.get_locus ());
}
+ void visit (HIR::QualifiedPathInExpression &expr) override
+ {
+ translated = ResolvePathRef::Compile (expr, ctx);
+ }
+
void visit (HIR::PathInExpression &expr) override
{
translated = ResolvePathRef::Compile (expr, ctx);
diff --git a/gcc/rust/backend/rust-compile-implitem.h b/gcc/rust/backend/rust-compile-implitem.h
index 7608599..7337154 100644
--- a/gcc/rust/backend/rust-compile-implitem.h
+++ b/gcc/rust/backend/rust-compile-implitem.h
@@ -297,6 +297,220 @@ private:
TyTy::BaseType *concrete;
};
+class CompileTraitItem : public HIRCompileBase
+{
+ using Rust::Compile::HIRCompileBase::visit;
+
+public:
+ static void Compile (TyTy::BaseType *self, HIR::TraitItem *item, Context *ctx,
+ TyTy::BaseType *concrete)
+ {
+ CompileTraitItem compiler (self, ctx, concrete);
+ item->accept_vis (compiler);
+ }
+
+ void visit (HIR::TraitItemFunc &func) override
+ {
+ rust_assert (func.has_block_defined ());
+
+ rust_assert (concrete->get_kind () == TyTy::TypeKind::FNDEF);
+ TyTy::FnType *fntype = static_cast<TyTy::FnType *> (concrete);
+
+ // items can be forward compiled which means we may not need to invoke this
+ // code. We might also have already compiled this generic function as well.
+ Bfunction *lookup = nullptr;
+ if (ctx->lookup_function_decl (fntype->get_ty_ref (), &lookup))
+ {
+ // has this been added to the list then it must be finished
+ if (ctx->function_completed (lookup))
+ {
+ Bfunction *dummy = nullptr;
+ if (!ctx->lookup_function_decl (fntype->get_ty_ref (), &dummy))
+ {
+ ctx->insert_function_decl (fntype->get_ty_ref (), lookup,
+ fntype);
+ }
+ return;
+ }
+ }
+
+ if (fntype->has_subsititions_defined ())
+ {
+ // override the Hir Lookups for the substituions in this context
+ fntype->override_context ();
+ }
+
+ // convert to the actual function type
+ ::Btype *compiled_fn_type = TyTyResolveCompile::compile (ctx, fntype);
+
+ HIR::TraitFunctionDecl &function = func.get_decl ();
+ unsigned int flags = 0;
+
+ const Resolver::CanonicalPath *canonical_path = nullptr;
+ rust_assert (ctx->get_mappings ()->lookup_canonical_path (
+ func.get_mappings ().get_crate_num (), func.get_mappings ().get_nodeid (),
+ &canonical_path));
+
+ std::string fn_identifier = canonical_path->get ();
+ std::string asm_name = ctx->mangle_item (fntype, *canonical_path);
+
+ Bfunction *fndecl
+ = ctx->get_backend ()->function (compiled_fn_type, fn_identifier,
+ asm_name, flags, func.get_locus ());
+ ctx->insert_function_decl (fntype->get_ty_ref (), fndecl, fntype);
+
+ // setup the params
+ TyTy::BaseType *tyret = fntype->get_return_type ();
+ std::vector<Bvariable *> param_vars;
+
+ if (function.is_method ())
+ {
+ // insert self
+ TyTy::BaseType *self_tyty_lookup = nullptr;
+ if (!ctx->get_tyctx ()->lookup_type (
+ function.get_self ().get_mappings ().get_hirid (),
+ &self_tyty_lookup))
+ {
+ rust_error_at (function.get_self ().get_locus (),
+ "failed to lookup self param type");
+ return;
+ }
+
+ Btype *self_type = TyTyResolveCompile::compile (ctx, self_tyty_lookup);
+ if (self_type == nullptr)
+ {
+ rust_error_at (function.get_self ().get_locus (),
+ "failed to compile self param type");
+ return;
+ }
+
+ Bvariable *compiled_self_param
+ = CompileSelfParam::compile (ctx, fndecl, function.get_self (),
+ self_type,
+ function.get_self ().get_locus ());
+ if (compiled_self_param == nullptr)
+ {
+ rust_error_at (function.get_self ().get_locus (),
+ "failed to compile self param variable");
+ return;
+ }
+
+ param_vars.push_back (compiled_self_param);
+ ctx->insert_var_decl (function.get_self ().get_mappings ().get_hirid (),
+ compiled_self_param);
+ }
+
+ // offset from + 1 for the TyTy::FnType being used when this is a method to
+ // skip over Self on the FnType
+ size_t i = function.is_method () ? 1 : 0;
+ for (auto referenced_param : function.get_function_params ())
+ {
+ auto tyty_param = fntype->param_at (i);
+ auto param_tyty = tyty_param.second;
+
+ auto compiled_param_type
+ = TyTyResolveCompile::compile (ctx, param_tyty);
+ if (compiled_param_type == nullptr)
+ {
+ rust_error_at (referenced_param.get_locus (),
+ "failed to compile parameter type");
+ return;
+ }
+
+ Location param_locus
+ = ctx->get_mappings ()->lookup_location (param_tyty->get_ref ());
+ Bvariable *compiled_param_var
+ = CompileFnParam::compile (ctx, fndecl, &referenced_param,
+ compiled_param_type, param_locus);
+ if (compiled_param_var == nullptr)
+ {
+ rust_error_at (param_locus, "Failed to compile parameter variable");
+ return;
+ }
+
+ param_vars.push_back (compiled_param_var);
+
+ ctx->insert_var_decl (referenced_param.get_mappings ().get_hirid (),
+ compiled_param_var);
+ i++;
+ }
+
+ if (!ctx->get_backend ()->function_set_parameters (fndecl, param_vars))
+ {
+ rust_fatal_error (func.get_locus (),
+ "failed to setup parameter variables");
+ return;
+ }
+
+ // lookup locals
+ auto block_expr = func.get_block_expr ().get ();
+ auto body_mappings = block_expr->get_mappings ();
+
+ Resolver::Rib *rib = nullptr;
+ if (!ctx->get_resolver ()->find_name_rib (body_mappings.get_nodeid (),
+ &rib))
+ {
+ rust_fatal_error (func.get_locus (),
+ "failed to setup locals per block");
+ return;
+ }
+
+ std::vector<Bvariable *> locals;
+ bool ok = compile_locals_for_block (*rib, fndecl, locals);
+ rust_assert (ok);
+
+ Bblock *enclosing_scope = NULL;
+ HIR::BlockExpr *function_body = func.get_block_expr ().get ();
+ Location start_location = function_body->get_locus ();
+ Location end_location = function_body->get_closing_locus ();
+
+ Bblock *code_block
+ = ctx->get_backend ()->block (fndecl, enclosing_scope, locals,
+ start_location, end_location);
+ ctx->push_block (code_block);
+
+ Bvariable *return_address = nullptr;
+ if (function.has_return_type ())
+ {
+ Btype *return_type = TyTyResolveCompile::compile (ctx, tyret);
+
+ bool address_is_taken = false;
+ Bstatement *ret_var_stmt = nullptr;
+
+ return_address = ctx->get_backend ()->temporary_variable (
+ fndecl, code_block, return_type, NULL, address_is_taken,
+ func.get_locus (), &ret_var_stmt);
+
+ ctx->add_statement (ret_var_stmt);
+ }
+
+ ctx->push_fn (fndecl, return_address);
+
+ compile_function_body (fndecl, func.get_block_expr (),
+ function.has_return_type ());
+
+ ctx->pop_block ();
+ auto body = ctx->get_backend ()->block_statement (code_block);
+ if (!ctx->get_backend ()->function_set_body (fndecl, body))
+ {
+ rust_error_at (func.get_locus (), "failed to set body to function");
+ return;
+ }
+
+ ctx->pop_fn ();
+ ctx->push_function (fndecl);
+ }
+
+private:
+ CompileTraitItem (TyTy::BaseType *self, Context *ctx,
+ TyTy::BaseType *concrete)
+ : HIRCompileBase (ctx), self (self), concrete (concrete)
+ {}
+
+ TyTy::BaseType *self;
+ TyTy::BaseType *concrete;
+};
+
} // namespace Compile
} // namespace Rust
diff --git a/gcc/rust/backend/rust-compile-item.h b/gcc/rust/backend/rust-compile-item.h
index 8b36289..a12e67e 100644
--- a/gcc/rust/backend/rust-compile-item.h
+++ b/gcc/rust/backend/rust-compile-item.h
@@ -59,7 +59,7 @@ public:
&canonical_path));
std::string name = canonical_path->get ();
- std::string asm_name = ctx->mangle_item (resolved_type, name);
+ std::string asm_name = ctx->mangle_item (resolved_type, *canonical_path);
bool is_external = false;
bool is_hidden = false;
@@ -168,12 +168,24 @@ public:
std::string ir_symbol_name
= canonical_path->get () + fntype->subst_as_string ();
+
std::string asm_name = function.get_function_name ();
// we don't mangle the main fn since we haven't implemented the main shim
// yet
if (!is_main_fn)
- asm_name = ctx->mangle_item (fntype, ir_symbol_name);
+ {
+ std::string substs_str = fntype->subst_as_string ();
+
+ Resolver::CanonicalPath mangle_me
+ = substs_str.empty ()
+ ? *canonical_path
+ : canonical_path->append (
+ Resolver::CanonicalPath::new_seg (0,
+ fntype->subst_as_string ()));
+
+ asm_name = ctx->mangle_item (fntype, mangle_me);
+ }
Bfunction *fndecl
= ctx->get_backend ()->function (compiled_fn_type, ir_symbol_name,
diff --git a/gcc/rust/backend/rust-compile-resolve-path.cc b/gcc/rust/backend/rust-compile-resolve-path.cc
index 5f07a2a..1539378 100644
--- a/gcc/rust/backend/rust-compile-resolve-path.cc
+++ b/gcc/rust/backend/rust-compile-resolve-path.cc
@@ -27,18 +27,33 @@ namespace Rust {
namespace Compile {
void
+ResolvePathRef::visit (HIR::QualifiedPathInExpression &expr)
+{
+ resolve (expr.get_final_segment ().get_segment (), expr.get_mappings (),
+ expr.get_locus (), true);
+}
+
+void
ResolvePathRef::visit (HIR::PathInExpression &expr)
{
+ resolve (expr.get_final_segment ().get_segment (), expr.get_mappings (),
+ expr.get_locus (), false);
+}
+
+void
+ResolvePathRef::resolve (const HIR::PathIdentSegment &final_segment,
+ const Analysis::NodeMapping &mappings,
+ Location expr_locus, bool is_qualified_path)
+{
// need to look up the reference for this identifier
NodeId ref_node_id = UNKNOWN_NODEID;
- if (ctx->get_resolver ()->lookup_resolved_name (
- expr.get_mappings ().get_nodeid (), &ref_node_id))
+ if (ctx->get_resolver ()->lookup_resolved_name (mappings.get_nodeid (),
+ &ref_node_id))
{
Resolver::Definition def;
if (!ctx->get_resolver ()->lookup_definition (ref_node_id, &def))
{
- rust_error_at (expr.get_locus (),
- "unknown reference for resolved name");
+ rust_error_at (expr_locus, "unknown reference for resolved name");
return;
}
ref_node_id = def.parent;
@@ -50,10 +65,10 @@ ResolvePathRef::visit (HIR::PathInExpression &expr)
return;
HirId ref;
- if (!ctx->get_mappings ()->lookup_node_to_hir (
- expr.get_mappings ().get_crate_num (), ref_node_id, &ref))
+ if (!ctx->get_mappings ()->lookup_node_to_hir (mappings.get_crate_num (),
+ ref_node_id, &ref))
{
- rust_error_at (expr.get_locus (), "reverse call path lookup failure");
+ rust_error_at (expr_locus, "reverse call path lookup failure");
return;
}
@@ -65,24 +80,25 @@ ResolvePathRef::visit (HIR::PathInExpression &expr)
Bvariable *var = nullptr;
if (ctx->lookup_var_decl (ref, &var))
{
- resolved = ctx->get_backend ()->var_expression (var, expr.get_locus ());
+ resolved = ctx->get_backend ()->var_expression (var, expr_locus);
return;
}
// must be a function call but it might be a generic function which needs to
// be compiled first
TyTy::BaseType *lookup = nullptr;
- bool ok = ctx->get_tyctx ()->lookup_type (expr.get_mappings ().get_hirid (),
- &lookup);
+ bool ok = ctx->get_tyctx ()->lookup_type (mappings.get_hirid (), &lookup);
rust_assert (ok);
rust_assert (lookup->get_kind () == TyTy::TypeKind::FNDEF);
+ TyTy::FnType *fntype = static_cast<TyTy::FnType *> (lookup);
Bfunction *fn = nullptr;
if (!ctx->lookup_function_decl (lookup->get_ty_ref (), &fn))
{
// it must resolve to some kind of HIR::Item or HIR::InheritImplItem
- HIR::Item *resolved_item = ctx->get_mappings ()->lookup_hir_item (
- expr.get_mappings ().get_crate_num (), ref);
+ HIR::Item *resolved_item
+ = ctx->get_mappings ()->lookup_hir_item (mappings.get_crate_num (),
+ ref);
if (resolved_item != nullptr)
{
if (!lookup->has_subsititions_defined ())
@@ -95,14 +111,14 @@ ResolvePathRef::visit (HIR::PathInExpression &expr)
HirId parent_impl_id = UNKNOWN_HIRID;
HIR::ImplItem *resolved_item
= ctx->get_mappings ()->lookup_hir_implitem (
- expr.get_mappings ().get_crate_num (), ref, &parent_impl_id);
+ mappings.get_crate_num (), ref, &parent_impl_id);
if (resolved_item == nullptr)
{
// it might be resolved to a trait item
HIR::TraitItem *trait_item
= ctx->get_mappings ()->lookup_hir_trait_item (
- expr.get_mappings ().get_crate_num (), ref);
+ mappings.get_crate_num (), ref);
HIR::Trait *trait
= ctx->get_mappings ()->lookup_trait_item_mapping (
trait_item->get_mappings ().get_hirid ());
@@ -114,8 +130,8 @@ ResolvePathRef::visit (HIR::PathInExpression &expr)
rust_assert (ok);
TyTy::BaseType *receiver = nullptr;
- ok = ctx->get_tyctx ()->lookup_receiver (
- expr.get_mappings ().get_hirid (), &receiver);
+ ok = ctx->get_tyctx ()->lookup_receiver (mappings.get_hirid (),
+ &receiver);
rust_assert (ok);
if (receiver->get_kind () == TyTy::TypeKind::PARAM)
@@ -129,17 +145,52 @@ ResolvePathRef::visit (HIR::PathInExpression &expr)
// item so its up to us to figure out if this path should resolve
// to an trait-impl-block-item or if it can be defaulted to the
// trait-impl-item's definition
- std::vector<Resolver::PathProbeCandidate> candidates
- = Resolver::PathProbeType::Probe (
- receiver, expr.get_final_segment ().get_segment (), true,
- false, true);
+ std::vector<Resolver::PathProbeCandidate> candidates;
+ if (!is_qualified_path)
+ {
+ candidates
+ = Resolver::PathProbeType::Probe (receiver, final_segment,
+ true, false, true);
+ }
if (candidates.size () == 0)
{
// this means we are defaulting back to the trait_item if
// possible
- // TODO
- gcc_unreachable ();
+ Resolver::TraitItemReference *trait_item_ref = nullptr;
+ bool ok = trait_ref->lookup_hir_trait_item (*trait_item,
+ &trait_item_ref);
+ rust_assert (ok); // found
+ rust_assert (
+ trait_item_ref->is_optional ()); // has definition
+
+ Analysis::NodeMapping trait_mappings
+ = trait_item_ref->get_parent_trait_mappings ();
+ auto associated_impl_id
+ = ctx->get_tyctx ()
+ ->lookup_associated_impl_mapping_for_self (
+ trait_mappings.get_hirid (), receiver);
+
+ rust_assert (associated_impl_id != UNKNOWN_HIRID);
+
+ Resolver::AssociatedImplTrait *associated = nullptr;
+ bool found_associated_trait_impl
+ = ctx->get_tyctx ()->lookup_associated_trait_impl (
+ associated_impl_id, &associated);
+ rust_assert (found_associated_trait_impl);
+ associated->setup_associated_types ();
+
+ CompileTraitItem::Compile (
+ receiver, trait_item_ref->get_hir_trait_item (), ctx,
+ fntype);
+
+ if (!ctx->lookup_function_decl (fntype->get_ty_ref (), &fn))
+ {
+ resolved = ctx->get_backend ()->error_expression ();
+ rust_error_at (expr_locus,
+ "forward declaration was not compiled");
+ return;
+ }
}
else
{
@@ -169,7 +220,7 @@ ResolvePathRef::visit (HIR::PathInExpression &expr)
{
rust_assert (parent_impl_id != UNKNOWN_HIRID);
HIR::Item *impl_ref = ctx->get_mappings ()->lookup_hir_item (
- expr.get_mappings ().get_crate_num (), parent_impl_id);
+ mappings.get_crate_num (), parent_impl_id);
rust_assert (impl_ref != nullptr);
HIR::ImplBlock *impl = static_cast<HIR::ImplBlock *> (impl_ref);
@@ -190,14 +241,12 @@ ResolvePathRef::visit (HIR::PathInExpression &expr)
if (!ctx->lookup_function_decl (lookup->get_ty_ref (), &fn))
{
resolved = ctx->get_backend ()->error_expression ();
- rust_error_at (expr.get_locus (),
- "forward declaration was not compiled");
+ rust_error_at (expr_locus, "forward declaration was not compiled");
return;
}
}
- resolved
- = ctx->get_backend ()->function_code_expression (fn, expr.get_locus ());
+ resolved = ctx->get_backend ()->function_code_expression (fn, expr_locus);
}
} // namespace Compile
diff --git a/gcc/rust/backend/rust-compile-resolve-path.h b/gcc/rust/backend/rust-compile-resolve-path.h
index 30486d0..41067c8 100644
--- a/gcc/rust/backend/rust-compile-resolve-path.h
+++ b/gcc/rust/backend/rust-compile-resolve-path.h
@@ -30,6 +30,14 @@ class ResolvePathRef : public HIRCompileBase
using Rust::Compile::HIRCompileBase::visit;
public:
+ static Bexpression *Compile (HIR::QualifiedPathInExpression &expr,
+ Context *ctx)
+ {
+ ResolvePathRef resolver (ctx);
+ expr.accept_vis (resolver);
+ return resolver.resolved;
+ }
+
static Bexpression *Compile (HIR::PathInExpression &expr, Context *ctx)
{
ResolvePathRef resolver (ctx);
@@ -39,8 +47,16 @@ public:
void visit (HIR::PathInExpression &expr) override;
+ void visit (HIR::QualifiedPathInExpression &expr) override;
+
private:
- ResolvePathRef (Context *ctx) : HIRCompileBase (ctx), resolved (nullptr) {}
+ ResolvePathRef (Context *ctx)
+ : HIRCompileBase (ctx), resolved (ctx->get_backend ()->error_expression ())
+ {}
+
+ void resolve (const HIR::PathIdentSegment &final_segment,
+ const Analysis::NodeMapping &mappings, Location locus,
+ bool is_qualified_path);
Bexpression *resolved;
};
diff --git a/gcc/rust/backend/rust-compile-tyty.h b/gcc/rust/backend/rust-compile-tyty.h
index 3ddc29a..1a5747a 100644
--- a/gcc/rust/backend/rust-compile-tyty.h
+++ b/gcc/rust/backend/rust-compile-tyty.h
@@ -50,6 +50,8 @@ public:
void visit (TyTy::PlaceholderType &) override { gcc_unreachable (); }
+ void visit (TyTy::ProjectionType &) override { gcc_unreachable (); }
+
void visit (TyTy::TupleType &type) override
{
if (type.num_fields () == 0)
diff --git a/gcc/rust/backend/rust-compile.cc b/gcc/rust/backend/rust-compile.cc
index b9b5084..baaccf0 100644
--- a/gcc/rust/backend/rust-compile.cc
+++ b/gcc/rust/backend/rust-compile.cc
@@ -181,8 +181,32 @@ CompileExpr::visit (HIR::MethodCallExpr &expr)
{
// this means we are defaulting back to the trait_item if
// possible
- // TODO
- gcc_unreachable ();
+ Resolver::TraitItemReference *trait_item_ref = nullptr;
+ bool ok = trait_ref->lookup_hir_trait_item (*trait_item,
+ &trait_item_ref);
+ rust_assert (ok); // found
+ rust_assert (trait_item_ref->is_optional ()); // has definition
+
+ TyTy::BaseType *self_type = nullptr;
+ if (!ctx->get_tyctx ()->lookup_type (
+ expr.get_receiver ()->get_mappings ().get_hirid (),
+ &self_type))
+ {
+ rust_error_at (expr.get_locus (),
+ "failed to resolve type for self param");
+ return;
+ }
+
+ CompileTraitItem::Compile (self_type,
+ trait_item_ref->get_hir_trait_item (),
+ ctx, fntype);
+ if (!ctx->lookup_function_decl (fntype->get_ty_ref (), &fn))
+ {
+ translated = ctx->get_backend ()->error_expression ();
+ rust_error_at (expr.get_locus (),
+ "forward declaration was not compiled");
+ return;
+ }
}
else
{
@@ -529,6 +553,17 @@ mangle_name (const std::string &name)
return std::to_string (name.size ()) + name;
}
+static std::string
+mangle_canonical_path (const Resolver::CanonicalPath &path)
+{
+ std::string buffer;
+ path.iterate_segs ([&] (const Resolver::CanonicalPath &p) -> bool {
+ buffer += mangle_name (p.get ());
+ return true;
+ });
+ return buffer;
+}
+
// rustc uses a sip128 hash for legacy mangling, but an fnv 128 was quicker to
// implement for now
static std::string
@@ -579,17 +614,19 @@ mangle_self (const TyTy::BaseType *self)
}
std::string
-Context::mangle_item (const TyTy::BaseType *ty, const std::string &name) const
+Context::mangle_item (const TyTy::BaseType *ty,
+ const Resolver::CanonicalPath &path) const
{
const std::string &crate_name = mappings->get_current_crate_name ();
const std::string hash = legacy_hash (ty->as_string ());
const std::string hash_sig = mangle_name (hash);
- return kMangledSymbolPrefix + mangle_name (crate_name) + mangle_name (name)
- + hash_sig + kMangledSymbolDelim;
+ return kMangledSymbolPrefix + mangle_name (crate_name)
+ + mangle_canonical_path (path) + hash_sig + kMangledSymbolDelim;
}
+// FIXME this is a wee bit broken
std::string
Context::mangle_impl_item (const TyTy::BaseType *self, const TyTy::BaseType *ty,
const std::string &name) const