From 4d6a0094e9b0316d80b264fa85347b29be43af68 Mon Sep 17 00:00:00 2001 From: Owen Avery Date: Tue, 19 Sep 2023 11:48:02 -0400 Subject: [PATCH 1/8] Fix spelling gcc/rust/ChangeLog: * ast/rust-expr.h: Fix spelling of "doesn't". * backend/rust-compile-expr.cc: Fix spelling of "accessors". * backend/rust-compile-implitem.h: Fix spelling of "normal". * backend/rust-constexpr.cc: Fix spelling of "actual". Signed-off-by: Owen Avery --- gcc/rust/ast/rust-expr.h | 4 ++-- gcc/rust/backend/rust-compile-expr.cc | 4 ++-- gcc/rust/backend/rust-compile-implitem.h | 2 +- gcc/rust/backend/rust-constexpr.cc | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h index 69937bf3fda4..012b05578236 100644 --- a/gcc/rust/ast/rust-expr.h +++ b/gcc/rust/ast/rust-expr.h @@ -4594,14 +4594,14 @@ struct InlineAsmTemplatePiece struct TupleClobber { - // as gccrs still doesen't contain a symbol class I have put them as strings + // as gccrs still doesn't contain a symbol class I have put them as strings std::string symbol; location_t loc; }; struct TupleTemplateStr { - // as gccrs still doesen't contain a symbol class I have put them as strings + // as gccrs still doesn't contain a symbol class I have put them as strings std::string symbol; std::string optional_symbol; location_t loc; diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc index 361941ad9efd..bd91c91c9390 100644 --- a/gcc/rust/backend/rust-compile-expr.cc +++ b/gcc/rust/backend/rust-compile-expr.cc @@ -473,7 +473,7 @@ CompileExpr::visit (HIR::StructExprStructFields &struct_expr) else { // this assumes all fields are in order from type resolution and if a - // base struct was specified those fields are filed via accesors + // base struct was specified those fields are filed via accessors for (size_t i = 0; i < struct_expr.get_fields ().size (); i++) { // assignments are coercion sites so lets convert the rvalue if @@ -1552,7 +1552,7 @@ CompileExpr::visit (HIR::CallExpr &expr) } // this assumes all fields are in order from type resolution and if a - // base struct was specified those fields are filed via accesors + // base struct was specified those fields are filed via accessors std::vector arguments; for (size_t i = 0; i < expr.get_arguments ().size (); i++) { diff --git a/gcc/rust/backend/rust-compile-implitem.h b/gcc/rust/backend/rust-compile-implitem.h index 745d73a036ac..bcd82728f733 100644 --- a/gcc/rust/backend/rust-compile-implitem.h +++ b/gcc/rust/backend/rust-compile-implitem.h @@ -24,7 +24,7 @@ namespace Rust { namespace Compile { -// this is a proxy for HIR::ImplItem's back to use the normel HIR::Item path +// this is a proxy for HIR::ImplItem's back to use the normal HIR::Item path class CompileInherentImplItem : public CompileItem { public: diff --git a/gcc/rust/backend/rust-constexpr.cc b/gcc/rust/backend/rust-constexpr.cc index e630e13f1a81..9e19566ad750 100644 --- a/gcc/rust/backend/rust-constexpr.cc +++ b/gcc/rust/backend/rust-constexpr.cc @@ -141,7 +141,7 @@ struct GTY ((for_user)) rust_constexpr_call /* Result of the call. NULL means the call is being evaluated. error_mark_node means that the evaluation was erroneous; - otherwise, the actuall value of the call. */ + otherwise, the actual value of the call. */ tree result; /* The hash of this call; we remember it here to avoid having to recalculate it when expanding the hash table. */ From d0742b3695d171fbafee44edff72409d2838b0e8 Mon Sep 17 00:00:00 2001 From: Raiki Tamura Date: Wed, 20 Sep 2023 13:42:02 +0900 Subject: [PATCH 2/8] Fix CanonicalPath for inherent impl gcc/rust/ChangeLog: * util/rust-canonical-path.h: Add new segment kind for inherent impl. * resolve/rust-ast-resolve-item.cc (ResolveItem::visit): Use it. * resolve/rust-ast-resolve-toplevel.h: Use it. Signed-off-by: Raiki Tamura --- gcc/rust/resolve/rust-ast-resolve-item.cc | 7 +++++-- gcc/rust/resolve/rust-ast-resolve-toplevel.h | 8 ++++++-- gcc/rust/util/rust-canonical-path.h | 6 ++++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/gcc/rust/resolve/rust-ast-resolve-item.cc b/gcc/rust/resolve/rust-ast-resolve-item.cc index 52adde8e8ee3..baab62209994 100644 --- a/gcc/rust/resolve/rust-ast-resolve-item.cc +++ b/gcc/rust/resolve/rust-ast-resolve-item.cc @@ -565,6 +565,7 @@ ResolveItem::visit (AST::InherentImpl &impl_block) // FIXME this needs to be protected behind nominal type-checks see: // rustc --explain E0118 + // issue #2634 ResolveType::go (impl_block.get_type ().get ()); // Setup paths @@ -576,13 +577,15 @@ ResolveItem::visit (AST::InherentImpl &impl_block) self_cpath.get ().c_str ()); CanonicalPath impl_type = self_cpath; - CanonicalPath impl_prefix = prefix.append (impl_type); + CanonicalPath impl_type_seg + = CanonicalPath::inherent_impl_seg (impl_block.get_node_id (), impl_type); + CanonicalPath impl_prefix = prefix.append (impl_type_seg); // see https://godbolt.org/z/a3vMbsT6W CanonicalPath cpath = CanonicalPath::create_empty (); if (canonical_prefix.size () <= 1) { - cpath = self_cpath; + cpath = impl_prefix; } else { diff --git a/gcc/rust/resolve/rust-ast-resolve-toplevel.h b/gcc/rust/resolve/rust-ast-resolve-toplevel.h index 9ba8bdb5caff..50f31dcc2bb8 100644 --- a/gcc/rust/resolve/rust-ast-resolve-toplevel.h +++ b/gcc/rust/resolve/rust-ast-resolve-toplevel.h @@ -344,10 +344,14 @@ class ResolveTopLevel : public ResolverBase void visit (AST::InherentImpl &impl_block) override { std::string raw_impl_type_path = impl_block.get_type ()->as_string (); - CanonicalPath impl_type + CanonicalPath impl_type_seg = CanonicalPath::new_seg (impl_block.get_type ()->get_node_id (), raw_impl_type_path); - CanonicalPath impl_prefix = prefix.append (impl_type); + + CanonicalPath impl_type + = CanonicalPath::inherent_impl_seg (impl_block.get_node_id (), + impl_type_seg); + CanonicalPath impl_prefix = prefix.append (impl_type_seg); for (auto &impl_item : impl_block.get_impl_items ()) ResolveToplevelImplItem::go (impl_item.get (), impl_prefix); diff --git a/gcc/rust/util/rust-canonical-path.h b/gcc/rust/util/rust-canonical-path.h index 2f28302c1c14..8c275a77953c 100644 --- a/gcc/rust/util/rust-canonical-path.h +++ b/gcc/rust/util/rust-canonical-path.h @@ -69,6 +69,12 @@ class CanonicalPath + trait_seg.get () + ">"); } + static CanonicalPath inherent_impl_seg (NodeId id, + const CanonicalPath &impl_type_seg) + { + return CanonicalPath::new_seg (id, "<" + impl_type_seg.get () + ">"); + } + std::string get () const { std::string buf; From 289722166ed9dabc35cf4130bdd34f803babea57 Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Patry Date: Tue, 26 Sep 2023 14:49:10 +0200 Subject: [PATCH 3/8] Fix ICE when emitting an error during cfg strip When an error was emitted during the cfg strip pass by the crate loader, it was ignored and the error state propagated until another pass (name resolver). gcc/rust/ChangeLog: * rust-session-manager.cc (Session::expansion): Add early break on error. Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/rust-session-manager.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gcc/rust/rust-session-manager.cc b/gcc/rust/rust-session-manager.cc index 8aeab4073877..c674a18d1c92 100644 --- a/gcc/rust/rust-session-manager.cc +++ b/gcc/rust/rust-session-manager.cc @@ -877,6 +877,9 @@ Session::expansion (AST::Crate &crate) while (!fixed_point_reached && iterations < cfg.recursion_limit) { CfgStrip ().go (crate); + // Errors might happen during cfg strip pass + if (saw_errors ()) + break; auto ctx = Resolver2_0::NameResolutionContext (); From 1908504f62d75e1084923c4e1ace6c3784299344 Mon Sep 17 00:00:00 2001 From: Jakub Dupak Date: Mon, 2 Oct 2023 21:54:16 +0200 Subject: [PATCH 4/8] Fix type confusion in coercion There was a mismatch between a manual discriminant test and the static cast. gcc/rust/ChangeLog: * backend/rust-compile.cc (HIRCompileBase::coercion_site1): Fix wrong cast Signed-off-by: Jakub Dupak --- gcc/rust/backend/rust-compile.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gcc/rust/backend/rust-compile.cc b/gcc/rust/backend/rust-compile.cc index 27991994b844..404b90aa01ac 100644 --- a/gcc/rust/backend/rust-compile.cc +++ b/gcc/rust/backend/rust-compile.cc @@ -115,8 +115,8 @@ HIRCompileBase::coercion_site1 (tree rvalue, TyTy::BaseType *rval, if (!valid_coercion) return error_mark_node; - const TyTy::ReferenceType *exp - = static_cast (expected); + const TyTy::PointerType *exp + = static_cast (expected); TyTy::BaseType *actual_base = nullptr; if (actual->get_kind () == TyTy::TypeKind::REF) From c7728c8020334fecb47789163ba94326aab6208c Mon Sep 17 00:00:00 2001 From: Mohammed Rizan Farooqui Date: Wed, 4 Oct 2023 13:49:24 +0530 Subject: [PATCH 5/8] Removed unnecessary comments gcc/rust/ChangeLog: * expand/rust-macro-builtins.cc (MacroBuiltin::include_str_handler): Comment removed (MacroBuiltin::env_handler): Comment removed (MacroBuiltin::cfg_handler): Comment removed (MacroBuiltin::line_handler): Comment removed Signed-off-by: Mohammed Rizan Farooqui --- gcc/rust/expand/rust-macro-builtins.cc | 4 ---- 1 file changed, 4 deletions(-) diff --git a/gcc/rust/expand/rust-macro-builtins.cc b/gcc/rust/expand/rust-macro-builtins.cc index f00b64c3bc07..d0b19d95caa6 100644 --- a/gcc/rust/expand/rust-macro-builtins.cc +++ b/gcc/rust/expand/rust-macro-builtins.cc @@ -583,7 +583,6 @@ MacroBuiltin::include_str_handler (location_t invoc_locus, auto node = AST::SingleASTNode (make_string (invoc_locus, str)); auto str_tok = make_token (Token::make_string (invoc_locus, std::move (str))); - // FIXME: Do not return an empty token vector here return AST::Fragment ({node}, std::move (str_tok)); } @@ -785,7 +784,6 @@ MacroBuiltin::env_handler (location_t invoc_locus, AST::MacroInvocData &invoc) auto tok = make_token (Token::make_string (invoc_locus, std::move (env_value))); - // FIXME: Do not return an empty token vector here return AST::Fragment ({node}, std::move (tok)); } @@ -824,7 +822,6 @@ MacroBuiltin::cfg_handler (location_t invoc_locus, AST::MacroInvocData &invoc) auto tok = make_token ( Token::make (result ? TRUE_LITERAL : FALSE_LITERAL, invoc_locus)); - // FIXME: Do not return an empty token vector here return AST::Fragment ({literal_exp}, std::move (tok)); } @@ -912,7 +909,6 @@ MacroBuiltin::line_handler (location_t invoc_locus, AST::MacroInvocData &) auto tok = make_token (Token::make_int (invoc_locus, std::to_string (current_line))); - // FIXME: Do not return an empty token vector here return AST::Fragment ({line_no}, std::move (tok)); } From 10fd060d61fdbbf38e3f174f1409f60477c58755 Mon Sep 17 00:00:00 2001 From: Jakub Dupak Date: Thu, 5 Oct 2023 12:10:37 +0200 Subject: [PATCH 6/8] Fix parser bug on tupplestruct pattern gcc/rust/ChangeLog: * parse/rust-parse-impl.h: Add missing token consumption Signed-off-by: Jakub Dupak --- gcc/rust/parse/rust-parse-impl.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index be3a7b8f3fbf..fecff6153f39 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -11452,6 +11452,8 @@ Parser::parse_struct_pattern_field_partial ( std::string index_str = t->get_str (); int index = atoi (index_str.c_str ()); + lexer.skip_token (); + if (!skip_token (COLON)) { return nullptr; From 007166ca6ceecd429f7033336af25dd679424ca2 Mon Sep 17 00:00:00 2001 From: Jakub Dupak Date: Thu, 5 Oct 2023 14:52:24 +0200 Subject: [PATCH 7/8] Add test for parser bug gcc/testsuite/ChangeLog: * rust/compile/issue-2645.rs: New test. Signed-off-by: Jakub Dupak --- gcc/testsuite/rust/compile/issue-2645.rs | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 gcc/testsuite/rust/compile/issue-2645.rs diff --git a/gcc/testsuite/rust/compile/issue-2645.rs b/gcc/testsuite/rust/compile/issue-2645.rs new file mode 100644 index 000000000000..ef1403de1a78 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-2645.rs @@ -0,0 +1,4 @@ +// { dg-additional-options "-frust-compile-until=ast" } +pub fn struct_tuple(A { 0: a, 1: ref b }: A) -> i32 { + a +} From 7292e71b61d95c0cec8378555e71a11a6e4120c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= Date: Sat, 14 Oct 2023 00:02:47 +0200 Subject: [PATCH 8/8] gccrs: minor changes (typo and minor refactor) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix a typo and merge 2 if clauses using the same condition. gcc/rust/ChangeLog: * backend/rust-compile-expr.cc (CompileExpr::visit): Merge 2 if clauses. * backend/rust-compile-extern.h: Fix typo in comment. Signed-off-by: Marc Poulhiès --- gcc/rust/backend/rust-compile-expr.cc | 8 ++------ gcc/rust/backend/rust-compile-extern.h | 6 ++---- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc index bd91c91c9390..1f0b58e60030 100644 --- a/gcc/rust/backend/rust-compile-expr.cc +++ b/gcc/rust/backend/rust-compile-expr.cc @@ -1635,17 +1635,13 @@ CompileExpr::visit (HIR::CallExpr &expr) return; bool is_variadic = false; - if (tyty->get_kind () == TyTy::TypeKind::FNDEF) - { - const TyTy::FnType *fn = static_cast (tyty); - is_variadic = fn->is_variadic (); - } - size_t required_num_args = expr.get_arguments ().size (); + if (tyty->get_kind () == TyTy::TypeKind::FNDEF) { const TyTy::FnType *fn = static_cast (tyty); required_num_args = fn->num_params (); + is_variadic = fn->is_variadic (); } else if (tyty->get_kind () == TyTy::TypeKind::FNPTR) { diff --git a/gcc/rust/backend/rust-compile-extern.h b/gcc/rust/backend/rust-compile-extern.h index be92529a1acc..1df3875541a3 100644 --- a/gcc/rust/backend/rust-compile-extern.h +++ b/gcc/rust/backend/rust-compile-extern.h @@ -115,10 +115,8 @@ class CompileExternItem : public HIRCompileBase, } if (fntype->has_substitutions_defined ()) - { - // override the Hir Lookups for the substituions in this context - fntype->override_context (); - } + // override the HIR lookups for the substitutions in this context + fntype->override_context (); if (fntype->get_abi () == ABI::INTRINSIC) {