Change the function's return type to wrap it within an optional.
gcc/rust/ChangeLog:
* backend/rust-compile-base.cc: Change call site to accomodate new
return type.
* backend/rust-compile-base.h: Change parameter to use a reference.
* backend/rust-compile-extern.h: Likewise.
* backend/rust-compile-implitem.cc (CompileTraitItem::visit):
Change call site for new return type.
* backend/rust-compile-item.cc (CompileItem::visit): Likewise.
* resolve/rust-ast-resolve-type.cc (ResolveTypeToCanonicalPath::visit):
Likewise.
* typecheck/rust-hir-type-check-enumitem.cc (TypeCheckEnumItem::visit):
Likewise.
* typecheck/rust-hir-type-check-implitem.cc (TypeCheckImplItem::visit):
Likewise.
* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit):
Likewise.
* typecheck/rust-hir-type-check.cc (TraitItemReference::get_type_from_fn):
Likewise.
* util/rust-hir-map.h: Update the function's prototype and change the
function's return type.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
std::vector<HIR::FunctionParam> &function_params,
const HIR::FunctionQualifiers &qualifiers, HIR::Visibility &visibility,
AST::AttrVec &outer_attrs, location_t locus, HIR::BlockExpr *function_body,
- const Resolver::CanonicalPath *canonical_path, TyTy::FnType *fntype)
+ const Resolver::CanonicalPath &canonical_path, TyTy::FnType *fntype)
{
tree compiled_fn_type = TyTyResolveCompile::compile (ctx, fntype);
std::string ir_symbol_name
- = canonical_path->get () + fntype->subst_as_string ();
+ = canonical_path.get () + fntype->subst_as_string ();
// we don't mangle the main fn since we haven't implemented the main shim
bool is_main_fn = fn_name.compare ("main") == 0;
// conditionally mangle the function name
bool should_mangle = should_mangle_item (fndecl);
if (!is_main_fn && should_mangle)
- asm_name = ctx->mangle_item (fntype, *canonical_path);
+ asm_name = ctx->mangle_item (fntype, canonical_path);
SET_DECL_ASSEMBLER_NAME (fndecl,
get_identifier_with_length (asm_name.data (),
asm_name.length ()));
tree
HIRCompileBase::compile_constant_item (
- TyTy::BaseType *resolved_type, const Resolver::CanonicalPath *canonical_path,
+ TyTy::BaseType *resolved_type, const Resolver::CanonicalPath &canonical_path,
HIR::Expr *const_value_expr, location_t locus)
{
- const std::string &ident = canonical_path->get ();
+ const std::string &ident = canonical_path.get ();
tree type = TyTyResolveCompile::compile (ctx, resolved_type);
tree const_type = build_qualified_type (type, TYPE_QUAL_CONST);
TyTy::BaseType *fn_return_ty);
tree compile_constant_item (TyTy::BaseType *resolved_type,
- const Resolver::CanonicalPath *canonical_path,
+ const Resolver::CanonicalPath &canonical_path,
HIR::Expr *const_value_expr, location_t locus);
tree compile_function (const std::string &fn_name, HIR::SelfParam &self_param,
const HIR::FunctionQualifiers &qualifiers,
HIR::Visibility &visibility, AST::AttrVec &outer_attrs,
location_t locus, HIR::BlockExpr *function_body,
- const Resolver::CanonicalPath *canonical_path,
+ const Resolver::CanonicalPath &canonical_path,
TyTy::FnType *fntype);
static tree unit_expression (location_t locus);
if (fntype->get_abi () == ABI::RUST)
{
// then we need to get the canonical path of it and mangle it
- const Resolver::CanonicalPath *canonical_path = nullptr;
- bool ok = ctx->get_mappings ().lookup_canonical_path (
- function.get_mappings ().get_nodeid (), &canonical_path);
- rust_assert (ok);
+ auto canonical_path = ctx->get_mappings ().lookup_canonical_path (
+ function.get_mappings ().get_nodeid ());
ir_symbol_name = canonical_path->get () + fntype->subst_as_string ();
asm_name = ctx->mangle_item (fntype, *canonical_path);
rust_assert (concrete != nullptr);
TyTy::BaseType *resolved_type = concrete;
- const Resolver::CanonicalPath *canonical_path = nullptr;
- bool ok = ctx->get_mappings ().lookup_canonical_path (
- constant.get_mappings ().get_nodeid (), &canonical_path);
- rust_assert (ok);
+ auto canonical_path = ctx->get_mappings ().lookup_canonical_path (
+ constant.get_mappings ().get_nodeid ());
HIR::Expr *const_value_expr = constant.get_expr ().get ();
tree const_expr
- = compile_constant_item (resolved_type, canonical_path, const_value_expr,
+ = compile_constant_item (resolved_type, *canonical_path, const_value_expr,
constant.get_locus ());
ctx->push_const (const_expr);
ctx->insert_const_decl (constant.get_mappings ().get_hirid (), const_expr);
fntype->override_context ();
}
- const Resolver::CanonicalPath *canonical_path = nullptr;
- bool ok = ctx->get_mappings ().lookup_canonical_path (
- func.get_mappings ().get_nodeid (), &canonical_path);
- rust_assert (ok);
+ auto canonical_path = ctx->get_mappings ().lookup_canonical_path (
+ func.get_mappings ().get_nodeid ());
// FIXME: How do we get the proper visibility here?
auto vis = HIR::Visibility (HIR::Visibility::VisType::PUBLIC);
function.get_self (), function.get_function_params (),
function.get_qualifiers (), vis,
func.get_outer_attrs (), func.get_locus (),
- func.get_block_expr ().get (), canonical_path, fntype);
+ func.get_block_expr ().get (), *canonical_path, fntype);
reference = address_expression (fndecl, ref_locus);
}
tree type = TyTyResolveCompile::compile (ctx, resolved_type);
- const Resolver::CanonicalPath *canonical_path = nullptr;
- ok = ctx->get_mappings ().lookup_canonical_path (
- var.get_mappings ().get_nodeid (), &canonical_path);
- rust_assert (ok);
+ auto canonical_path = ctx->get_mappings ().lookup_canonical_path (
+ var.get_mappings ().get_nodeid ());
HIR::Expr *const_value_expr = var.get_expr ().get ();
ctx->push_const_context ();
- tree value = compile_constant_item (resolved_type, canonical_path,
+ tree value = compile_constant_item (resolved_type, *canonical_path,
const_value_expr, var.get_locus ());
ctx->pop_const_context ();
}
else
{
- const Resolver::CanonicalPath *canonical_path_ptr = nullptr;
- ok = ctx->get_mappings ().lookup_canonical_path (mappings.get_nodeid (),
- &canonical_path_ptr);
- rust_assert (ok);
- canonical_path = *canonical_path_ptr;
+ canonical_path = ctx->get_mappings ()
+ .lookup_canonical_path (mappings.get_nodeid ())
+ .value ();
}
HIR::Expr *const_value_expr = constant.get_expr ().get ();
ctx->push_const_context ();
tree const_expr
- = compile_constant_item (resolved_type, &canonical_path, const_value_expr,
+ = compile_constant_item (resolved_type, canonical_path, const_value_expr,
constant.get_locus ());
ctx->pop_const_context ();
}
else
{
- const Resolver::CanonicalPath *path = nullptr;
- bool ok = ctx->get_mappings ().lookup_canonical_path (
- function.get_mappings ().get_nodeid (), &path);
- rust_assert (ok);
+ auto path = ctx->get_mappings ().lookup_canonical_path (
+ function.get_mappings ().get_nodeid ());
canonical_path = *path;
}
function.get_function_params (),
function.get_qualifiers (), function.get_visibility (),
function.get_outer_attrs (), function.get_locus (),
- function.get_definition ().get (), &canonical_path,
+ function.get_definition ().get (), canonical_path,
fntype);
reference = address_expression (fndecl, ref_locus);
if (resolved_node == UNKNOWN_NODEID)
return;
- const CanonicalPath *type_path = nullptr;
- if (mappings.lookup_canonical_path (resolved_node, &type_path))
+ if (auto type_path = mappings.lookup_canonical_path (resolved_node))
{
auto &final_seg = path.get_segments ().back ();
switch (final_seg->get_type ())
rust_assert (ok);
context->insert_type (mapping, isize);
- const CanonicalPath *canonical_path = nullptr;
- ok = mappings.lookup_canonical_path (item.get_mappings ().get_nodeid (),
- &canonical_path);
- rust_assert (ok);
+ auto canonical_path
+ = mappings.lookup_canonical_path (item.get_mappings ().get_nodeid ());
RustIdent ident{*canonical_path, item.get_locus ()};
variant = new TyTy::VariantDef (item.get_mappings ().get_hirid (),
TyTy::TyWithLocation (expected_ty),
TyTy::TyWithLocation (capacity_type), item.get_locus ());
- const CanonicalPath *canonical_path = nullptr;
- bool ok = mappings.lookup_canonical_path (item.get_mappings ().get_nodeid (),
- &canonical_path);
- rust_assert (ok);
+ auto canonical_path
+ = mappings.lookup_canonical_path (item.get_mappings ().get_nodeid ());
RustIdent ident{*canonical_path, item.get_locus ()};
variant = new TyTy::VariantDef (item.get_mappings ().get_hirid (),
rust_assert (ok);
context->insert_type (mapping, isize);
- const CanonicalPath *canonical_path = nullptr;
- ok = mappings.lookup_canonical_path (item.get_mappings ().get_nodeid (),
- &canonical_path);
- rust_assert (ok);
+ auto canonical_path
+ = mappings.lookup_canonical_path (item.get_mappings ().get_nodeid ());
RustIdent ident{*canonical_path, item.get_locus ()};
variant = new TyTy::VariantDef (item.get_mappings ().get_hirid (),
rust_assert (ok);
context->insert_type (mapping, isize);
- const CanonicalPath *canonical_path = nullptr;
- ok = mappings.lookup_canonical_path (item.get_mappings ().get_nodeid (),
- &canonical_path);
- rust_assert (ok);
+ auto canonical_path
+ = mappings.lookup_canonical_path (item.get_mappings ().get_nodeid ());
RustIdent ident{*canonical_path, item.get_locus ()};
variant = new TyTy::VariantDef (item.get_mappings ().get_hirid (),
TypeCheckPattern::Resolve (param.get_param_name ().get (), param_tyty);
}
- const CanonicalPath *canonical_path = nullptr;
- bool ok
- = mappings.lookup_canonical_path (function.get_mappings ().get_nodeid (),
- &canonical_path);
- rust_assert (ok);
+ auto canonical_path
+ = mappings.lookup_canonical_path (function.get_mappings ().get_nodeid ());
RustIdent ident{*canonical_path, function.get_locus ()};
auto fnType = new TyTy::FnType (
{
auto nr_ctx
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
- auto canonical_path = nr_ctx.values.to_canonical_path (
- struct_decl.get_mappings ().get_nodeid ());
- path = canonical_path.value ();
+ path = nr_ctx.values
+ .to_canonical_path (struct_decl.get_mappings ().get_nodeid ())
+ .value ();
}
else
{
- const CanonicalPath *canonical_path = nullptr;
- bool ok = mappings.lookup_canonical_path (
- struct_decl.get_mappings ().get_nodeid (), &canonical_path);
- rust_assert (ok);
-
- path = *canonical_path;
+ path
+ = mappings
+ .lookup_canonical_path (struct_decl.get_mappings ().get_nodeid ())
+ .value ();
}
RustIdent ident{path, struct_decl.get_locus ()};
}
else
{
- const CanonicalPath *canonical_path = nullptr;
- bool ok = mappings.lookup_canonical_path (
- struct_decl.get_mappings ().get_nodeid (), &canonical_path);
- rust_assert (ok);
-
- path = *canonical_path;
+ path
+ = mappings
+ .lookup_canonical_path (struct_decl.get_mappings ().get_nodeid ())
+ .value ();
}
RustIdent ident{path, struct_decl.get_locus ()};
}
// get the path
- const CanonicalPath *canonical_path = nullptr;
- bool ok
- = mappings.lookup_canonical_path (enum_decl.get_mappings ().get_nodeid (),
- &canonical_path);
- rust_assert (ok);
+ auto canonical_path
+ = mappings.lookup_canonical_path (enum_decl.get_mappings ().get_nodeid ());
RustIdent ident{*canonical_path, enum_decl.get_locus ()};
// multi variant ADT
}
// get the path
- const CanonicalPath *canonical_path = nullptr;
- bool ok
- = mappings.lookup_canonical_path (union_decl.get_mappings ().get_nodeid (),
- &canonical_path);
- rust_assert (ok);
+ auto canonical_path
+ = mappings.lookup_canonical_path (union_decl.get_mappings ().get_nodeid ());
RustIdent ident{*canonical_path, union_decl.get_locus ()};
// there is only a single variant
}
else
{
- const CanonicalPath *canonical_path = nullptr;
- bool ok = mappings.lookup_canonical_path (
- function.get_mappings ().get_nodeid (), &canonical_path);
- rust_assert (ok);
-
- path = *canonical_path;
+ path = mappings
+ .lookup_canonical_path (function.get_mappings ().get_nodeid ())
+ .value ();
}
RustIdent ident{path, function.get_locus ()};
}
auto &mappings = Analysis::Mappings::get ();
- const CanonicalPath *canonical_path = nullptr;
- bool ok = mappings.lookup_canonical_path (fn.get_mappings ().get_nodeid (),
- &canonical_path);
- rust_assert (ok);
+ auto canonical_path
+ = mappings.lookup_canonical_path (fn.get_mappings ().get_nodeid ());
RustIdent ident{*canonical_path, fn.get_locus ()};
auto resolved = new TyTy::FnType (
void insert_canonical_path (NodeId id, const Resolver::CanonicalPath path)
{
- const Resolver::CanonicalPath *p = nullptr;
- if (lookup_canonical_path (id, &p))
+ if (auto p = lookup_canonical_path (id))
{
// if we have already stored a canonical path this is ok so long as
// this new path is equal or is smaller that the existing one but in
paths.emplace (id, std::move (path));
}
- bool lookup_canonical_path (NodeId id, const Resolver::CanonicalPath **path)
+ tl::optional<const Resolver::CanonicalPath &>
+ lookup_canonical_path (NodeId id)
{
auto it = paths.find (id);
if (it == paths.end ())
- return false;
+ return tl::nullopt;
- *path = &it->second;
- return true;
+ return it->second;
}
void insert_lang_item (LangItem::Kind item_type, DefId id)