Skip to content

Commit ddda47c

Browse files
braw-leeP-E-P
authored andcommitted
Map locations to placeholder regions
Mapped placeholder regions to their respective HIR nodes so we can fetch locations during error reporting. gcc/rust/ChangeLog: * checks/errors/borrowck/rust-bir-builder.h: Map regions to their respective HIR nodes. * checks/errors/borrowck/rust-bir.h (struct Function): Add unordered_map to maintain the mapping. Signed-off-by: Kushal Pal <[email protected]>
1 parent 44664e3 commit ddda47c

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

gcc/rust/checks/errors/borrowck/rust-bir-builder.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,16 @@ class Builder final : public AbstractBuilder
5050
handle_param (param);
5151

5252
handle_body (*function.get_definition ());
53+
auto region_hir_map
54+
= map_region_to_hir (function.get_generic_params (), ctx.fn_free_regions);
5355

5456
return Function{
5557
std::move (ctx.place_db),
5658
std::move (ctx.arguments),
5759
std::move (ctx.basic_blocks),
5860
std::move (ctx.fn_free_regions),
5961
std::move (universal_region_bounds),
62+
std::move (region_hir_map),
6063
function.get_locus (),
6164
};
6265
}
@@ -161,6 +164,26 @@ class Builder final : public AbstractBuilder
161164
push_return (return_location);
162165
}
163166
}
167+
168+
// Maps named lifetime parameters to their respective HIR node
169+
const std::unordered_map<Polonius::Origin, HIR::LifetimeParam *>
170+
map_region_to_hir (
171+
const std::vector<std::unique_ptr<HIR::GenericParam>> &generic_params,
172+
const FreeRegions &regions)
173+
{
174+
std::unordered_map<Polonius::Origin, HIR::LifetimeParam *> result;
175+
size_t region_index = 0;
176+
for (auto &generic_param : generic_params)
177+
{
178+
if (generic_param->get_kind ()
179+
== HIR::GenericParam::GenericKind::LIFETIME)
180+
{
181+
result[regions[region_index++]]
182+
= static_cast<HIR::LifetimeParam *> (generic_param.get ());
183+
}
184+
}
185+
return result;
186+
}
164187
};
165188

166189
} // namespace BIR

gcc/rust/checks/errors/borrowck/rust-bir.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ struct Function
4747
std::vector<BasicBlock> basic_blocks;
4848
FreeRegions universal_regions;
4949
std::vector<std::pair<FreeRegion, FreeRegion>> universal_region_bounds;
50+
std::unordered_map<Polonius::Origin, HIR::LifetimeParam *> region_hir_map;
5051
location_t location;
5152
};
5253

0 commit comments

Comments
 (0)