aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorKushal Pal <kushalpal109@gmail.com>2024-08-08 07:12:00 +0000
committerP-E-P <32375388+P-E-P@users.noreply.github.com>2024-09-09 08:33:02 +0000
commit5b8299d7694f0b251dbff422f78f4f706f0dbbe9 (patch)
treea2afa6c1a65e479e50e08a6ae1f783e61c51aee6 /gcc
parentd479eb583efdb83525e2ca2a3f113dfc17fc458f (diff)
downloadgcc-5b8299d7694f0b251dbff422f78f4f706f0dbbe9.zip
gcc-5b8299d7694f0b251dbff422f78f4f706f0dbbe9.tar.gz
gcc-5b8299d7694f0b251dbff422f78f4f706f0dbbe9.tar.bz2
Use FreeRegions inplace of `std::vector<FreeRegion>`
gcc/rust/ChangeLog: * checks/errors/borrowck/rust-bir-builder-internal.h: Use FreeRegions instead of making a temporary vector of FreeRegion. * checks/errors/borrowck/rust-bir-builder.h: Likewise. * checks/errors/borrowck/rust-bir-fact-collector.h (class FactCollector): Likewise. (points): Likewise. * checks/errors/borrowck/rust-bir-free-region.h: Remove obsolete set_from() helpers, add push_back(). * checks/errors/borrowck/rust-bir-place.h: Use FreeRegions instead of making a temporary vector of Origin. * typecheck/rust-tyty-variance-analysis-private.h: Change type of `regions`. * typecheck/rust-tyty-variance-analysis.cc (CrateCtx::query_type_regions): Use new type. (GenericTyPerCrateCtx::query_generic_variance): Likewise. (TyVisitorCtx::add_constraints_from_generic_args): Likewise. (FieldVisitorCtx::add_constraints_from_region): Likewise. (FieldVisitorCtx::add_constrints_from_param): Likewise. * typecheck/rust-tyty-variance-analysis.h: Likewise. Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h6
-rw-r--r--gcc/rust/checks/errors/borrowck/rust-bir-builder.h6
-rw-r--r--gcc/rust/checks/errors/borrowck/rust-bir-fact-collector.h20
-rw-r--r--gcc/rust/checks/errors/borrowck/rust-bir-free-region.h26
-rw-r--r--gcc/rust/checks/errors/borrowck/rust-bir-place.h9
-rw-r--r--gcc/rust/typecheck/rust-tyty-variance-analysis-private.h11
-rw-r--r--gcc/rust/typecheck/rust-tyty-variance-analysis.cc10
-rw-r--r--gcc/rust/typecheck/rust-tyty-variance-analysis.h7
8 files changed, 38 insertions, 57 deletions
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h b/gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h
index ac93714..d03bdeb 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h
@@ -206,7 +206,7 @@ protected:
FreeRegions bind_regions (std::vector<TyTy::Region> regions,
FreeRegions parent_free_regions)
{
- std::vector<FreeRegion> free_regions;
+ FreeRegions free_regions;
for (auto &region : regions)
{
if (region.is_early_bound ())
@@ -231,9 +231,7 @@ protected:
rust_unreachable ();
}
}
- // This is necesarry because of clash of current gcc and gcc4.8.
- FreeRegions free_regions_final{std::move (free_regions)};
- return free_regions_final;
+ return free_regions;
}
protected: // Helpers to add BIR statements
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-builder.h b/gcc/rust/checks/errors/borrowck/rust-bir-builder.h
index 9509e00..19d8ce5 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-builder.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-builder.h
@@ -68,15 +68,15 @@ private:
/** Instantiate `num_lifetime_params` free regions. */
void handle_lifetime_params (size_t num_lifetime_params)
{
- std::vector<FreeRegion> function_free_regions;
+ FreeRegions regions;
for (size_t i = 0; i < num_lifetime_params; i++)
{
- function_free_regions.push_back (ctx.place_db.get_next_free_region ());
+ regions.push_back (ctx.place_db.get_next_free_region ());
}
rust_debug ("\tctx.fn_free_region={%s}",
ctx.fn_free_regions.to_string ().c_str ());
- ctx.fn_free_regions.set_from (std::move (function_free_regions));
+ ctx.fn_free_regions = regions;
}
void handle_lifetime_param_constraints (
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-fact-collector.h b/gcc/rust/checks/errors/borrowck/rust-bir-fact-collector.h
index 6ca5404..aae41ad 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-fact-collector.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-fact-collector.h
@@ -65,11 +65,11 @@ class FactCollector : public Visitor
FreeRegions make_fresh_regions (size_t size)
{
- std::vector<FreeRegion> free_regions;
+ FreeRegions free_regions;
for (size_t i = 0; i < size; i++)
free_regions.push_back (region_binder.get_next_free_region ());
- return FreeRegions (std::move (free_regions));
+ return free_regions;
}
public:
@@ -179,12 +179,12 @@ protected: // Main collection entry points (for different categories).
rust_debug ("\tSanitize deref of %s", base.tyty->as_string ().c_str ());
- std::vector<FreeRegion> regions;
- regions.insert (regions.end (), base.regions.begin () + 1,
- base.regions.end ());
- FreeRegions r;
- r.set_from (std::move (regions));
- push_subset_all (place.tyty, r, place.regions);
+ FreeRegions regions;
+ for (auto it = base.regions.begin () + 1; it != base.regions.end (); ++it)
+ {
+ regions.push_back (*it);
+ }
+ push_subset_all (place.tyty, regions, place.regions);
}
void sanizite_field (PlaceId place_id)
{
@@ -201,9 +201,7 @@ protected: // Main collection entry points (for different categories).
.query_field_regions (base.tyty->as<TyTy::ADTType> (), 0,
place.variable_or_field_index,
base.regions); // FIXME
- FreeRegions f;
- f.set_from (std::move (r));
- push_subset_all (place.tyty, f, place.regions);
+ push_subset_all (place.tyty, r, place.regions);
}
void visit_statemensts ()
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-free-region.h b/gcc/rust/checks/errors/borrowck/rust-bir-free-region.h
index 95d4e11..22235ea 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-free-region.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-free-region.h
@@ -50,22 +50,6 @@ public:
FreeRegion &operator[] (size_t i) { return regions.at (i); }
const FreeRegion &operator[] (size_t i) const { return regions.at (i); }
const std::vector<FreeRegion> &get_regions () const { return regions; }
- void set_from (std::vector<Rust::Polonius::Origin> &&regions)
- {
- this->regions.clear ();
- for (auto &region : regions)
- {
- this->regions.push_back ({region});
- }
- }
- void set_from (std::vector<FreeRegion> &&regions)
- {
- this->regions.clear ();
- for (auto &region : regions)
- {
- this->regions.push_back (region);
- }
- }
WARN_UNUSED_RESULT FreeRegions prepend (FreeRegion region) const
{
@@ -74,8 +58,10 @@ public:
return FreeRegions (std::move (new_regions));
}
- FreeRegions (std::vector<FreeRegion> &&regions) : regions (regions) {}
+ void push_back (FreeRegion region) { regions.push_back (region); }
+
FreeRegions () {}
+ FreeRegions (std::vector<FreeRegion> &&regions) : regions (regions) {}
WARN_UNUSED_RESULT std::string to_string () const
{
@@ -111,7 +97,7 @@ public:
FreeRegions bind_regions (std::vector<TyTy::Region> regions,
FreeRegions parent_free_regions)
{
- std::vector<FreeRegion> free_regions;
+ FreeRegions free_regions;
for (auto &region : regions)
{
if (region.is_early_bound ())
@@ -128,9 +114,7 @@ public:
rust_unreachable ();
}
}
- // This is necesarry because of clash of current gcc and gcc4.8.
- FreeRegions free_regions_final{std::move (free_regions)};
- return free_regions_final;
+ return free_regions;
}
};
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-place.h b/gcc/rust/checks/errors/borrowck/rust-bir-place.h
index 589aaf0..d857528 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-place.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-place.h
@@ -259,11 +259,14 @@ public:
auto variances = Resolver::TypeCheckContext::get ()
->get_variance_analysis_ctx ()
.query_type_variances (new_place_ref.tyty);
- std::vector<Polonius::Origin> regions;
+ FreeRegions regions;
for (size_t i = 0; i < variances.size (); ++i)
- regions.push_back (next_free_region.value++);
+ {
+ regions.push_back (next_free_region);
+ ++next_free_region.value;
+ }
- new_place_ref.regions.set_from (std::move (regions));
+ new_place_ref.regions = regions;
return new_place;
}
diff --git a/gcc/rust/typecheck/rust-tyty-variance-analysis-private.h b/gcc/rust/typecheck/rust-tyty-variance-analysis-private.h
index 41a0d6f..450e53e 100644
--- a/gcc/rust/typecheck/rust-tyty-variance-analysis-private.h
+++ b/gcc/rust/typecheck/rust-tyty-variance-analysis-private.h
@@ -201,10 +201,9 @@ public: // Module internal API
std::vector<Variance> query_generic_variance (const ADTType &type);
- std::vector<size_t> query_field_regions (const ADTType *parent,
- size_t variant_index,
- size_t field_index,
- const FreeRegions &parent_regions);
+ FreeRegions query_field_regions (const ADTType *parent, size_t variant_index,
+ size_t field_index,
+ const FreeRegions &parent_regions);
std::vector<Region> query_type_regions (BaseType *base);
@@ -309,7 +308,7 @@ class FieldVisitorCtx : public VarianceVisitorCtx<Variance>
public:
using Visitor = VisitorBase<Variance>;
- std::vector<size_t> collect_regions (BaseType &ty);
+ FreeRegions collect_regions (BaseType &ty);
FieldVisitorCtx (GenericTyPerCrateCtx &ctx, const SubstitutionRef &subst,
const FreeRegions &parent_regions)
@@ -332,7 +331,7 @@ public:
private:
GenericTyPerCrateCtx &ctx;
const SubstitutionRef &subst;
- std::vector<size_t> regions;
+ FreeRegions regions;
FreeRegions parent_regions;
std::vector<size_t> type_param_ranges;
};
diff --git a/gcc/rust/typecheck/rust-tyty-variance-analysis.cc b/gcc/rust/typecheck/rust-tyty-variance-analysis.cc
index 15c16db..1aba576 100644
--- a/gcc/rust/typecheck/rust-tyty-variance-analysis.cc
+++ b/gcc/rust/typecheck/rust-tyty-variance-analysis.cc
@@ -52,7 +52,7 @@ CrateCtx::query_type_regions (BaseType *type)
return private_ctx->query_type_regions (type);
}
-std::vector<size_t>
+FreeRegions
CrateCtx::query_field_regions (const ADTType *parent, size_t variant_index,
size_t field_index,
const FreeRegions &parent_regions)
@@ -332,7 +332,7 @@ GenericTyPerCrateCtx::query_generic_variance (const ADTType &type)
return result;
}
-std::vector<size_t>
+FreeRegions
GenericTyPerCrateCtx::query_field_regions (const ADTType *parent,
size_t variant_index,
size_t field_index,
@@ -537,7 +537,7 @@ TyVisitorCtx::add_constraints_from_generic_args (HirId ref,
}
}
-std::vector<size_t>
+FreeRegions
FieldVisitorCtx::collect_regions (BaseType &ty)
{
// Segment the regions into ranges for each type parameter. Type parameter
@@ -570,7 +570,7 @@ FieldVisitorCtx::add_constraints_from_region (const Region &region,
{
if (region.is_early_bound ())
{
- regions.push_back (parent_regions[region.get_index ()].value);
+ regions.push_back (parent_regions[region.get_index ()]);
}
else if (region.is_late_bound ())
{
@@ -585,7 +585,7 @@ FieldVisitorCtx::add_constrints_from_param (ParamType &param, Variance variance)
for (size_t i = type_param_ranges[param_i];
i < type_param_ranges[param_i + 1]; i++)
{
- regions.push_back (parent_regions[i].value);
+ regions.push_back (parent_regions[i]);
}
}
diff --git a/gcc/rust/typecheck/rust-tyty-variance-analysis.h b/gcc/rust/typecheck/rust-tyty-variance-analysis.h
index 27e8d8b..9059a2f 100644
--- a/gcc/rust/typecheck/rust-tyty-variance-analysis.h
+++ b/gcc/rust/typecheck/rust-tyty-variance-analysis.h
@@ -33,10 +33,9 @@ public:
/** Get regions mentioned in a type. */
std::vector<Region> query_type_regions (BaseType *type);
- std::vector<size_t> query_field_regions (const ADTType *parent,
- size_t variant_index,
- size_t field_index,
- const FreeRegions &parent_regions);
+ FreeRegions query_field_regions (const ADTType *parent, size_t variant_index,
+ size_t field_index,
+ const FreeRegions &parent_regions);
private:
std::unique_ptr<GenericTyPerCrateCtx> private_ctx;