[PATCH] gccrs: Remove unused files
These files only exist upstream, and were presumably either never removed upstream or accidentally upstreamed despite being removed downstream. gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-toplevel.cc: Removed. * typecheck/rust-hir-type-check-toplevel.h: Removed. Signed-off-by: Owen Avery --- .../typecheck/rust-hir-type-check-toplevel.cc | 378 -- .../typecheck/rust-hir-type-check-toplevel.h | 56 --- 2 files changed, 434 deletions(-) delete mode 100644 gcc/rust/typecheck/rust-hir-type-check-toplevel.cc delete mode 100644 gcc/rust/typecheck/rust-hir-type-check-toplevel.h diff --git a/gcc/rust/typecheck/rust-hir-type-check-toplevel.cc b/gcc/rust/typecheck/rust-hir-type-check-toplevel.cc deleted file mode 100644 index 8224afb4b68..000 --- a/gcc/rust/typecheck/rust-hir-type-check-toplevel.cc +++ /dev/null @@ -1,378 +0,0 @@ -// Copyright (C) 2020-2024 Free Software Foundation, Inc. - -// This file is part of GCC. - -// GCC is free software; you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation; either version 3, or (at your option) any later -// version. - -// GCC is distributed in the hope that it will be useful, but WITHOUT ANY -// WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -// for more details. - -// You should have received a copy of the GNU General Public License -// along with GCC; see the file COPYING3. If not see -// <http://www.gnu.org/licenses/>. - -#include "rust-hir-type-check-toplevel.h" -#include "rust-hir-type-check-enumitem.h" -#include "rust-hir-type-check-type.h" -#include "rust-hir-type-check-expr.h" -#include "rust-hir-type-check-pattern.h" -#include "rust-hir-type-check-implitem.h" - -namespace Rust { -namespace Resolver { - -TypeCheckTopLevel::TypeCheckTopLevel () : TypeCheckBase () {} - -void -TypeCheckTopLevel::Resolve (HIR::Item &item) -{ - rust_assert (item.get_hir_kind () == HIR::Node::BaseKind::VIS_ITEM); - HIR::VisItem &vis_item = static_cast (item); - - TypeCheckTopLevel resolver; - vis_item.accept_vis (resolver); -} - -void -TypeCheckTopLevel::visit (HIR::TypeAlias &alias) -{ - TyTy::BaseType *actual_type -= TypeCheckType::Resolve (alias.get_type_aliased ().get ()); - - context->insert_type (alias.get_mappings (), actual_type); - - for (auto &where_clause_item : alias.get_where_clause ().get_items ()) -{ - ResolveWhereClauseItem::Resolve (*where_clause_item.get ()); -} -} - -void -TypeCheckTopLevel::visit (HIR::TupleStruct &struct_decl) -{ - std::vector substitutions; - if (struct_decl.has_generics ()) -resolve_generic_params (struct_decl.get_generic_params (), substitutions); - - for (auto &where_clause_item : struct_decl.get_where_clause ().get_items ()) -{ - ResolveWhereClauseItem::Resolve (*where_clause_item.get ()); -} - - std::vector fields; - size_t idx = 0; - for (auto &field : struct_decl.get_fields ()) -{ - TyTy::BaseType *field_type - = TypeCheckType::Resolve (field.get_field_type ().get ()); - TyTy::StructFieldType *ty_field - = new TyTy::StructFieldType (field.get_mappings ().get_hirid (), -std::to_string (idx), field_type, -field.get_locus ()); - fields.push_back (ty_field); - context->insert_type (field.get_mappings (), ty_field->get_field_type ()); - idx++; -} - - // get the path - const CanonicalPath *canonical_path = nullptr; - bool ok = mappings->lookup_canonical_path ( -struct_decl.get_mappings ().get_nodeid (), &canonical_path); - rust_assert (ok); - RustIdent ident{*canonical_path, struct_decl.get_locus ()}; - - // its a single variant ADT - std::vector variants; - variants.push_back (new TyTy::VariantDef ( -struct_decl.get_mappings ().get_hirid (), struct_decl.get_identifier (), -ident, TyTy::VariantDef::VariantType::TUPLE, nullptr, std::move (fields))); - - // Process #[repr(X)] attribute, if any - const AST::AttrVec &attrs = struct_decl.get_outer_attrs (); - TyTy::ADTType::ReprOptions repr -= parse_repr_options (attrs, struct_decl.get_locus ()); - - TyTy::BaseType *type -= new TyTy::ADTType (struct_decl.get_mappings ().get_hirid (), -mappings->get_next_hir_id (), -struct_decl.get_identifier (), ident, -TyTy::ADTType::ADTKind::TUPLE_STRUCT, -std::move (variants), std::move (substitutions), repr); - - context->insert_type (struct_decl.get_mappings (), type); -} - -void -TypeCheckTopLevel::visit (HIR::Module &module) -{ - for (auto &item : module.get_items ()) -TypeCheckTopLevel::Reso
[PATCH 3/3] gccrs: borrowck: Polonius dump
From: Jakub Dupak gcc/rust/ChangeLog: * checks/errors/borrowck/polonius/rust-polonius.h (struct FullPoint): Polonius facts dump. (struct Facts): Polonius facts dump. * checks/errors/borrowck/rust-bir-dump.cc (Dump::go): Polonius facts dump. (Dump::visit): Polonius facts dump. (Dump::visit_place): Polonius facts dump. (Dump::visit_move_place): Polonius facts dump. (Dump::visit_scope): Polonius facts dump. * checks/errors/borrowck/rust-borrow-checker.cc (BorrowChecker::go): Polonius facts dump. Signed-off-by: Jakub Dupak --- .../errors/borrowck/polonius/rust-polonius.h | 2 +- .../checks/errors/borrowck/rust-bir-dump.cc | 25 +-- .../errors/borrowck/rust-borrow-checker.cc| 69 ++- 3 files changed, 88 insertions(+), 8 deletions(-) diff --git a/gcc/rust/checks/errors/borrowck/polonius/rust-polonius.h b/gcc/rust/checks/errors/borrowck/polonius/rust-polonius.h index 239cc344011..1534260552b 100644 --- a/gcc/rust/checks/errors/borrowck/polonius/rust-polonius.h +++ b/gcc/rust/checks/errors/borrowck/polonius/rust-polonius.h @@ -148,7 +148,7 @@ struct Facts void dump_var_used_at (std::ostream &os) const { for (auto &e : var_used_at) - os << e.first - 1 << " " << FullPoint (e.second) << "\n"; + os << e.first << " " << FullPoint (e.second) << "\n"; } void dump_var_defined_at (std::ostream &os) const diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc b/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc index d3398b6f405..03e2b8ea404 100644 --- a/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc +++ b/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc @@ -115,7 +115,7 @@ Dump::go (bool enable_simplify_cfg) if (enable_simplify_cfg) simplify_cfg (func, bb_fold_map); - renumber_places (func, place_map); + // renumber_places (func, place_map); stream << "fn " << name << "("; print_comma_separated (stream, func.arguments, [this] (PlaceId place_id) { @@ -214,6 +214,8 @@ Dump::visit (const Statement &stmt) visit_place (stmt.get_place ()); stream << ")"; break; +default: + rust_internal_error_at (UNKNOWN_LOCATION, "Unknown statement kind."); } statement_place = INVALID_PLACE; } @@ -251,7 +253,8 @@ Dump::visit_place (PlaceId place_id) stream << "const " << get_tyty_name (place.tyty); break; case Place::INVALID: - stream << "_INVALID"; + if (place_id == INVALID_PLACE) + stream << "_INVALID"; } } @@ -259,7 +262,7 @@ void Dump::visit_move_place (PlaceId place_id) { const Place &place = func.place_db[place_id]; - if (!place.is_constant ()) + if (place.should_be_moved ()) stream << "move "; visit_place (place_id); } @@ -267,7 +270,11 @@ Dump::visit_move_place (PlaceId place_id) void Dump::visit (const BorrowExpr &expr) { - stream << "&"; + stream << "&" +<< "'?" << expr.get_origin () << " "; + if (func.place_db.get_loans ()[expr.get_loan ()].mutability + == Mutability::Mut) +stream << "mut "; visit_place (expr.get_place ()); } @@ -360,7 +367,15 @@ Dump::visit_scope (ScopeId id, size_t depth) indent (depth + 1) << "let _"; stream << place_map[local] << ": " << get_tyty_name (func.place_db[local].tyty); - stream << ";\n"; + stream << ";\t"; + + stream << "["; + print_comma_separated (stream, +func.place_db[local].regions.get_regions (), +[this] (FreeRegion region_id) { + stream << "'?" << region_id; +}); + stream << "]\n"; } for (auto &child : scope.children) visit_scope (child, (id >= 1) ? depth + 1 : depth); diff --git a/gcc/rust/checks/errors/borrowck/rust-borrow-checker.cc b/gcc/rust/checks/errors/borrowck/rust-borrow-checker.cc index ae06aadaa5b..a2351c57eb4 100644 --- a/gcc/rust/checks/errors/borrowck/rust-borrow-checker.cc +++ b/gcc/rust/checks/errors/borrowck/rust-borrow-checker.cc @@ -18,9 +18,10 @@ #include "rust-borrow-checker.h" #include "rust-function-collector.h" +#include "rust-bir-fact-collector.h" #include "rust-bir-builder.h" #include "rust-bir-dump.h" -#include "rust-bir-fact-collector.h" +#include "polonius/rust-polonius.h" namespace Rust { namespace HIR { @@ -36,7 +37,7 @@ mkdir_wrapped (const std::string &dirname) #elif __APPLE__ ret = mkdir (dirname.c_str (), 0775); #endif - (void) ret; + rust_assert (ret == 0 || errno == EEXIST); } void @@ -68,6 +69,8 @@ BorrowChecker::go (HIR::Crate &crate) = mappings->get_crate_name (crate.get_mappings ().get_crate_num (), crate_name); rust_assert (ok); + + mkdir_wrapped ("nll_facts_gccrs"); } FunctionCollector collector; @@ -75,6 +78,9 @@ BorrowChecker::go (HIR::Crate &crate) for (auto func : collector.get_functions
[PATCH 2/3] gccrs: Removed obsolete objects
From: Kushal Pal gcc/rust/ChangeLog: * backend/rust-compile-expr.cc (CompileExpr::visit): Lines removed as the objects are unused. Signed-off-by: Kushal Pal --- gcc/rust/backend/rust-compile-expr.cc | 13 ++--- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc index c8e4339bb10..5ddc2a2f719 100644 --- a/gcc/rust/backend/rust-compile-expr.cc +++ b/gcc/rust/backend/rust-compile-expr.cc @@ -1304,23 +1304,14 @@ CompileExpr::visit (HIR::MethodCallExpr &expr) { const TyTy::DynamicObjectType *dyn = static_cast (receiver->get_root ()); - - std::vector arguments; - for (auto &arg : expr.get_arguments ()) - arguments.push_back (arg.get ()); - fn_expr = get_fn_addr_from_dyn (dyn, receiver, fntype, self, expr.get_locus ()); self = get_receiver_from_dyn (dyn, receiver, fntype, self, expr.get_locus ()); } else -{ - // lookup compiled functions since it may have already been compiled - HIR::PathExprSegment method_name = expr.get_method_name (); - HIR::PathIdentSegment segment_name = method_name.get_segment (); - fn_expr = resolve_method_address (fntype, receiver, expr.get_locus ()); -} +// lookup compiled functions since it may have already been compiled +fn_expr = resolve_method_address (fntype, receiver, expr.get_locus ()); // lookup the autoderef mappings HirId autoderef_mappings_id -- 2.45.2
[PATCH 1/3] gccrs: Remove redundant macro definition
From: zhanghe9702 gcc/rust/ChangeLog: * backend/rust-tree.h: removing the CLASSTYPE_VBASECLASSES macro which is duplicated three times. Signed-off-by: Zhang He --- gcc/rust/backend/rust-tree.h | 12 1 file changed, 12 deletions(-) diff --git a/gcc/rust/backend/rust-tree.h b/gcc/rust/backend/rust-tree.h index e597c3ab81d..1b8272916ad 100644 --- a/gcc/rust/backend/rust-tree.h +++ b/gcc/rust/backend/rust-tree.h @@ -139,12 +139,6 @@ should be initialized.) */ #define CLASSTYPE_VBASECLASSES(NODE) (LANG_TYPE_CLASS_CHECK (NODE)->vbases) -/* A vector of BINFOs for the direct and indirect virtual base classes - that this type uses in a post-order depth-first left-to-right - order. (In other words, these bases appear in the order that they - should be initialized.) */ -#define CLASSTYPE_VBASECLASSES(NODE) (LANG_TYPE_CLASS_CHECK (NODE)->vbases) - /* We used to have a variant type for lang_type. Keep the name of the checking accessor for the sole survivor. */ #define LANG_TYPE_CLASS_CHECK(NODE) (TYPE_LANG_SPECIFIC (NODE)) @@ -783,12 +777,6 @@ extern GTY (()) tree cp_global_trees[CPTI_MAX]; #define CLASSTYPE_PRIMARY_BINFO(NODE) \ (LANG_TYPE_CLASS_CHECK (NODE)->primary_base) -/* A vector of BINFOs for the direct and indirect virtual base classes - that this type uses in a post-order depth-first left-to-right - order. (In other words, these bases appear in the order that they - should be initialized.) */ -#define CLASSTYPE_VBASECLASSES(NODE) (LANG_TYPE_CLASS_CHECK (NODE)->vbases) - /* The type corresponding to NODE when NODE is used as a base class, i.e., NODE without virtual base classes or tail padding. */ #define CLASSTYPE_AS_BASE(NODE) (LANG_TYPE_CLASS_CHECK (NODE)->as_base) -- 2.45.2
Re: [PATCH 3/3] gccrs: borrowck: Polonius dump
These are some of the older easier-to-upstream patches -- I've added "gccrs: " to their subject fields but they should be otherwise unmodified. On 12/3/24 01:26, Owen Avery wrote: From: Jakub Dupak gcc/rust/ChangeLog: * checks/errors/borrowck/polonius/rust-polonius.h (struct FullPoint): Polonius facts dump. (struct Facts): Polonius facts dump. * checks/errors/borrowck/rust-bir-dump.cc (Dump::go): Polonius facts dump. (Dump::visit): Polonius facts dump. (Dump::visit_place): Polonius facts dump. (Dump::visit_move_place): Polonius facts dump. (Dump::visit_scope): Polonius facts dump. * checks/errors/borrowck/rust-borrow-checker.cc (BorrowChecker::go): Polonius facts dump. Signed-off-by: Jakub Dupak --- .../errors/borrowck/polonius/rust-polonius.h | 2 +- .../checks/errors/borrowck/rust-bir-dump.cc | 25 +-- .../errors/borrowck/rust-borrow-checker.cc| 69 ++- 3 files changed, 88 insertions(+), 8 deletions(-) diff --git a/gcc/rust/checks/errors/borrowck/polonius/rust-polonius.h b/gcc/rust/checks/errors/borrowck/polonius/rust-polonius.h index 239cc344011..1534260552b 100644 --- a/gcc/rust/checks/errors/borrowck/polonius/rust-polonius.h +++ b/gcc/rust/checks/errors/borrowck/polonius/rust-polonius.h @@ -148,7 +148,7 @@ struct Facts void dump_var_used_at (std::ostream &os) const { for (auto &e : var_used_at) - os << e.first - 1 << " " << FullPoint (e.second) << "\n"; + os << e.first << " " << FullPoint (e.second) << "\n"; } void dump_var_defined_at (std::ostream &os) const diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc b/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc index d3398b6f405..03e2b8ea404 100644 --- a/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc +++ b/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc @@ -115,7 +115,7 @@ Dump::go (bool enable_simplify_cfg) if (enable_simplify_cfg) simplify_cfg (func, bb_fold_map); - renumber_places (func, place_map); + // renumber_places (func, place_map); stream << "fn " << name << "("; print_comma_separated (stream, func.arguments, [this] (PlaceId place_id) { @@ -214,6 +214,8 @@ Dump::visit (const Statement &stmt) visit_place (stmt.get_place ()); stream << ")"; break; +default: + rust_internal_error_at (UNKNOWN_LOCATION, "Unknown statement kind."); } statement_place = INVALID_PLACE; } @@ -251,7 +253,8 @@ Dump::visit_place (PlaceId place_id) stream << "const " << get_tyty_name (place.tyty); break; case Place::INVALID: - stream << "_INVALID"; + if (place_id == INVALID_PLACE) + stream << "_INVALID"; } } @@ -259,7 +262,7 @@ void Dump::visit_move_place (PlaceId place_id) { const Place &place = func.place_db[place_id]; - if (!place.is_constant ()) + if (place.should_be_moved ()) stream << "move "; visit_place (place_id); } @@ -267,7 +270,11 @@ Dump::visit_move_place (PlaceId place_id) void Dump::visit (const BorrowExpr &expr) { - stream << "&"; + stream << "&" +<< "'?" << expr.get_origin () << " "; + if (func.place_db.get_loans ()[expr.get_loan ()].mutability + == Mutability::Mut) +stream << "mut "; visit_place (expr.get_place ()); } @@ -360,7 +367,15 @@ Dump::visit_scope (ScopeId id, size_t depth) indent (depth + 1) << "let _"; stream << place_map[local] << ": " << get_tyty_name (func.place_db[local].tyty); - stream << ";\n"; + stream << ";\t"; + + stream << "["; + print_comma_separated (stream, +func.place_db[local].regions.get_regions (), +[this] (FreeRegion region_id) { + stream << "'?" << region_id; +}); + stream << "]\n"; } for (auto &child : scope.children) visit_scope (child, (id >= 1) ? depth + 1 : depth); diff --git a/gcc/rust/checks/errors/borrowck/rust-borrow-checker.cc b/gcc/rust/checks/errors/borrowck/rust-borrow-checker.cc index ae06aadaa5b..a2351c57eb4 100644 --- a/gcc/rust/checks/errors/borrowck/rust-borrow-checker.cc +++ b/gcc/rust/checks/errors/borrowck/rust-borrow-checker.cc @@ -18,9 +18,10 @@ #include "rust-borrow-checker.h" #include "rust-function-collector.h" +#include "rust-bir-f