Skip to content

Commit 29cace3

Browse files
committed
gccrs: Give the builtin unit struct an actual locus
This has been a pet peeve of mine for a while because the gimple never emitted the struct () name properly it was always empty which for record types they always require a real locus or they dont get a proper name. gcc/rust/ChangeLog: * backend/rust-compile-base.cc (HIRCompileBase::unit_expression): pass ctx * backend/rust-compile-base.h: cant be static * backend/rust-compile-intrinsic.cc (try_handler_inner): pass ctx * backend/rust-compile-type.cc (TyTyResolveCompile::get_unit_type): update to grab the first locus (TyTyResolveCompile::visit): pass ctx * backend/rust-compile-type.h: likewise Signed-off-by: Philip Herron <herron.philip@googlemail.com>
1 parent 1a2f56a commit 29cace3

File tree

5 files changed

+17
-8
lines changed

5 files changed

+17
-8
lines changed

gcc/rust/backend/rust-compile-base.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,7 @@ HIRCompileBase::resolve_method_address (TyTy::FnType *fntype,
10231023
tree
10241024
HIRCompileBase::unit_expression (location_t locus)
10251025
{
1026-
tree unit_type = TyTyResolveCompile::get_unit_type ();
1026+
tree unit_type = TyTyResolveCompile::get_unit_type (ctx);
10271027
return Backend::constructor_expression (unit_type, false, {}, -1, locus);
10281028
}
10291029

gcc/rust/backend/rust-compile-base.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class HIRCompileBase
110110
const Resolver::CanonicalPath &canonical_path,
111111
TyTy::FnType *fntype);
112112

113-
static tree unit_expression (location_t locus);
113+
tree unit_expression (location_t locus);
114114

115115
void setup_fndecl (tree fndecl, bool is_main_entry_point, bool is_generic_fn,
116116
HIR::Visibility &visibility,

gcc/rust/backend/rust-compile-intrinsic.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1322,7 +1322,7 @@ try_handler_inner (Context *ctx, TyTy::FnType *fntype, bool is_new_api)
13221322

13231323
if (is_new_api)
13241324
{
1325-
auto ret_type = TyTyResolveCompile::get_unit_type ();
1325+
auto ret_type = TyTyResolveCompile::get_unit_type (ctx);
13261326
auto ret_expr = Backend::constructor_expression (ret_type, false, {}, -1,
13271327
UNDEF_LOCATION);
13281328
normal_return_stmt

gcc/rust/backend/rust-compile-type.cc

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,22 @@ TyTyResolveCompile::get_implicit_enumeral_node_type (TyTy::BaseType *repr)
8181
}
8282

8383
tree
84-
TyTyResolveCompile::get_unit_type ()
84+
TyTyResolveCompile::get_unit_type (Context *ctx)
8585
{
8686
static tree unit_type;
8787
if (unit_type == nullptr)
8888
{
89+
auto cn = ctx->get_mappings ().get_current_crate ();
90+
auto &c = ctx->get_mappings ().get_ast_crate (cn);
91+
location_t locus = BUILTINS_LOCATION;
92+
if (c.items.size () > 0)
93+
{
94+
auto &item = c.items[0];
95+
locus = item->get_locus ();
96+
}
97+
8998
auto unit_type_node = Backend::struct_type ({});
90-
unit_type = Backend::named_type ("()", unit_type_node, BUILTINS_LOCATION);
99+
unit_type = Backend::named_type ("()", unit_type_node, locus);
91100
}
92101
return unit_type;
93102
}
@@ -421,7 +430,7 @@ TyTyResolveCompile::visit (const TyTy::TupleType &type)
421430
{
422431
if (type.num_fields () == 0)
423432
{
424-
translated = get_unit_type ();
433+
translated = get_unit_type (ctx);
425434
return;
426435
}
427436

@@ -724,7 +733,7 @@ TyTyResolveCompile::visit (const TyTy::StrType &type)
724733
void
725734
TyTyResolveCompile::visit (const TyTy::NeverType &)
726735
{
727-
translated = get_unit_type ();
736+
translated = get_unit_type (ctx);
728737
}
729738

730739
void

gcc/rust/backend/rust-compile-type.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class TyTyResolveCompile : protected TyTy::TyConstVisitor
3030
static tree compile (Context *ctx, const TyTy::BaseType *ty,
3131
bool trait_object_mode = false);
3232

33-
static tree get_unit_type ();
33+
static tree get_unit_type (Context *ctx);
3434

3535
void visit (const TyTy::InferType &) override;
3636
void visit (const TyTy::ADTType &) override;

0 commit comments

Comments
 (0)