[gcc/devel/rust/master] Merge commit 'f89186f962421f6d972035fc4b4c20490e7b1c5b^' into HEAD

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:1af2c40d7595c91f8c8f3573c1bec30556e35bb6

commit 1af2c40d7595c91f8c8f3573c1bec30556e35bb6
Merge: 17ee9c68cbc9 830d4659604e
Author: Thomas Schwinge 
Date:   Wed Apr 10 10:55:56 2024 +0200

Merge commit 'f89186f962421f6d972035fc4b4c20490e7b1c5b^' into HEAD

Diff:

 ChangeLog  |8 +
 MAINTAINERS|6 +-
 contrib/ChangeLog  |   10 +
 contrib/test_installed |4 +
 contrib/unicode/gen_libstdcxx_unicode_data.py  |   30 +-
 gcc/ChangeLog  |  762 ++
 gcc/DATESTAMP  |2 +-
 gcc/analyzer/ChangeLog |   36 +
 gcc/analyzer/checker-event.cc  |   59 +-
 gcc/analyzer/region-model.cc   |  111 +-
 gcc/analyzer/state-purge.cc|9 +
 gcc/analyzer/supergraph.cc |4 +
 gcc/asan.h |7 +-
 gcc/builtins.cc|8 +-
 gcc/c-family/ChangeLog |   12 +
 gcc/c-family/c-opts.cc |5 +
 gcc/c-family/c-pch.cc  |   23 +-
 gcc/c/ChangeLog|   32 +
 gcc/c/c-convert.cc |3 +-
 gcc/c/c-decl.cc|9 +-
 gcc/c/c-tree.h |3 +-
 gcc/c/c-typeck.cc  |   36 +-
 gcc/common/config/riscv/riscv-common.cc|   14 +
 gcc/config/aarch64/aarch64-simd.md |   11 +-
 gcc/config/aarch64/aarch64.cc  |  129 +-
 gcc/config/arm/arm.cc  |2 +
 gcc/config/avr/avr-mcus.def|8 +-
 gcc/config/avr/avr.cc  | 7434 +++
 gcc/config/gcn/gcn.cc  |6 +-
 gcc/config/gcn/gcn.h   |   16 +-
 gcc/config/gcn/gcn.md  |   17 +-
 gcc/config/i386/constraints.md |4 +
 gcc/config/i386/i386-expand.cc |2 +-
 gcc/config/i386/i386-features.cc   |   26 +
 gcc/config/i386/i386.cc|   91 +-
 gcc/config/i386/i386.md|4 -
 gcc/config/loongarch/larchintrin.h |   16 +-
 gcc/config/loongarch/lasx.md   |   16 -
 gcc/config/loongarch/loongarch-def.h   |3 +
 gcc/config/loongarch/loongarch-opts.cc |2 -
 gcc/config/loongarch/loongarch-protos.h|1 +
 gcc/config/loongarch/loongarch.cc  |  577 +-
 gcc/config/loongarch/loongarch.md  |  125 +-
 gcc/config/loongarch/lsx.md|   11 -
 gcc/config/loongarch/predicates.md |   12 +
 gcc/config/loongarch/simd.md   |   18 +
 gcc/config/mips/mips-msa.md|   18 +-
 gcc/config/pa/pa.cc|  215 +-
 gcc/config/pa/pa.md|   90 +-
 gcc/config/riscv/generic-ooo.md|2 +-
 gcc/config/riscv/generic.md|2 +-
 gcc/config/riscv/riscv-c.cc|3 +-
 gcc/config/riscv/riscv-cores.def   |   11 +
 gcc/config/riscv/riscv-opts.h  |2 +
 gcc/config/riscv/riscv-protos.h|2 +-
 gcc/config/riscv/riscv-v.cc|   12 +-
 gcc/config/riscv/riscv-vector-builtins.cc  |   23 +-
 gcc/config/riscv/riscv-vsetvl.cc   |  255 +-
 gcc/config/riscv/riscv.cc  |  151 +-
 gcc/config/riscv/riscv.h   |5 +-
 gcc/config/riscv/riscv.md  |   20 +-
 gcc/config/riscv/riscv.opt |   14 +
 gcc/config/riscv/sifive-7.md   |2 +-
 gcc/config/riscv/sifive-p400.md|  174 +
 gcc/config/riscv/sifive-p600.md|  178 +
 gcc/config/riscv/thead.cc  |3 +-
 gcc/config/sol2.h  |2 +-
 gcc/config/sparc/sparc.h   |7 +
 gcc/config/xtensa/constraints.md   |   26 +-
 gcc/config/xtensa/predicates.md|7 +-
 gcc/config/xtensa/xtensa.cc|   46 +-
 gcc/config/xtensa/xtensa.md|   41 +-
 gcc/config/xtensa/xtensa.opt   |4 +-
 gcc/cp/ChangeLog   |  111 +
 gcc/cp/call.cc |   18 +-
 gcc/cp/constexpr.cc|1 +
 gcc/cp

[gcc/devel/rust/master] Change error message to match test

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:124d56a328163a8de49e01e9d88aaf6f6c5aa3e9

commit 124d56a328163a8de49e01e9d88aaf6f6c5aa3e9
Author: Pierre-Emmanuel Patry 
Date:   Wed Jan 17 13:53:21 2024 +0100

Change error message to match test

Error message did not match the test from the previous name resolver when
a given path cannot be resolved.

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-path.cc 
(TypeCheckExpr::resolve_root_path):
Change error message to match old resolver and test case.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/typecheck/rust-hir-type-check-path.cc | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/gcc/rust/typecheck/rust-hir-type-check-path.cc 
b/gcc/rust/typecheck/rust-hir-type-check-path.cc
index cdb506dacbe5..b0e52c454e9d 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-path.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-path.cc
@@ -266,8 +266,10 @@ TypeCheckExpr::resolve_root_path (HIR::PathInExpression 
, size_t *offset,
{
  if (is_root)
{
- rust_error_at (seg.get_locus (),
-"failed to resolve root segment");
+ rust_error_at (expr.get_locus (), ErrorCode::E0425,
+"cannot find value %qs in this scope",
+expr.as_simple_path ().as_string ().c_str ());
+
  return new TyTy::ErrorType (expr.get_mappings ().get_hirid ());
}
  return root_tyty;


[gcc/devel/rust/master] Add support for ambiguous use declarations

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:6b1d14b72e1b38ce55389683436781b229ed51f8

commit 6b1d14b72e1b38ce55389683436781b229ed51f8
Author: Pierre-Emmanuel Patry 
Date:   Tue Jan 16 13:55:02 2024 +0100

Add support for ambiguous use declarations

Glob use declarations may lead to ambiguous situation where two
definitions with the same name are imported in a given scope. The
compiler now handles shadowable items inserted after non shadowable
items. An error is now thrown when multiple shadowable items are imported
and used in the same rib.

gcc/rust/ChangeLog:

* resolve/rust-early-name-resolver-2.0.cc (Early::visit): Adapt
resolved type to the new API.
(Early::visit_attributes): Retrieve the node id from the definition.
* resolve/rust-forever-stack.h: Change the return type of getter
functions. Those functions now return a definition type instead of a
node id.
* resolve/rust-forever-stack.hxx: Change member function 
implementation
in the forever stack to accomodate it's API changes.
* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Use internal
node id. Emit an error when resolving multiple ambiguous values.
* resolve/rust-rib.cc (Rib::Definition::Definition): Add a default
constructor.
(Rib::Definition::is_ambiguous): Add a new function to determine
whether a function definition is ambiguous or not.
(Rib::Definition::to_string): Add a member function to convert a 
given
definition to a string.
(Rib::insert): Add new rules for value insertion in a rib. Insertion
order does not impact the result anymore: inserting a shadowable 
value
after a non shadowable one does not trigger an error anymore. All
shadowable values inserted in a rib are kepts until being replaced 
by a
non shadowable one.
(Rib::get): Return a definition instead of a node id.
* resolve/rust-rib.h: Update function prototypes.
* resolve/rust-toplevel-name-resolver-2.0.cc 
(TopLevel::handle_use_glob):
Update return value container to match the new function's prototype.
(TopLevel::handle_use_dec): Likewise.
(flatten_glob): Likewise.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/resolve/rust-early-name-resolver-2.0.cc   | 18 +++---
 gcc/rust/resolve/rust-forever-stack.h  | 10 ++--
 gcc/rust/resolve/rust-forever-stack.hxx| 39 ++--
 gcc/rust/resolve/rust-late-name-resolver-2.0.cc| 17 --
 gcc/rust/resolve/rust-rib.cc   | 69 +-
 gcc/rust/resolve/rust-rib.h| 19 +-
 .../resolve/rust-toplevel-name-resolver-2.0.cc | 41 +++--
 7 files changed, 142 insertions(+), 71 deletions(-)

diff --git a/gcc/rust/resolve/rust-early-name-resolver-2.0.cc 
b/gcc/rust/resolve/rust-early-name-resolver-2.0.cc
index 982c696d2af1..af148b0c1c0d 100644
--- a/gcc/rust/resolve/rust-early-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-early-name-resolver-2.0.cc
@@ -152,9 +152,11 @@ Early::visit (AST::MacroInvocation )
 
   // 
https://doc.rust-lang.org/reference/macros-by-example.html#path-based-scope
 
-  tl::optional definition = tl::nullopt;
+  tl::optional definition = tl::nullopt;
   if (path.get_segments ().size () == 1)
-definition = textual_scope.get (path.get_final_segment ().as_string ());
+definition
+  = textual_scope.get (path.get_final_segment ().as_string ())
+ .map ([] (NodeId id) { return Rib::Definition::NonShadowable (id); });
 
   // we won't have changed `definition` from `nullopt` if there are more
   // than one segments in our path
@@ -169,13 +171,13 @@ Early::visit (AST::MacroInvocation )
   return;
 }
 
-  insert_once (invoc, *definition);
+  insert_once (invoc, definition->get_node_id ());
 
   // now do we need to keep mappings or something? or insert "uses" into our
   // ForeverStack? can we do that? are mappings simpler?
   auto mappings = Analysis::Mappings::get ();
   AST::MacroRulesDefinition *rules_def = nullptr;
-  if (!mappings->lookup_macro_def (definition.value (), _def))
+  if (!mappings->lookup_macro_def (definition->get_node_id (), _def))
 {
   // Macro definition not found, maybe it is not expanded yet.
   return;
@@ -212,8 +214,8 @@ Early::visit_attributes (std::vector )
  continue;
}
 
- auto pm_def
-   = mappings->lookup_derive_proc_macro_def (definition.value ());
+ auto pm_def = mappings->lookup_derive_proc_macro_def (
+   definition->get_node_id ());
 
  rust_assert (pm_def.has_value ());
 
@@ -234,8 +236,8 @@ Early::visit_attributes (std::vector )
 "could not resolve attribute macro 

[gcc/devel/rust/master] Merge commit '2341df1cb9b3681bfefe29207887b2b3dc271a95' into HEAD [#2801]

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:0de2032ecf451e9fed2ad16c3ce771663fbc37a5

commit 0de2032ecf451e9fed2ad16c3ce771663fbc37a5
Merge: d1a0609b7e62 2341df1cb9b3
Author: Thomas Schwinge 
Date:   Wed Apr 10 10:52:58 2024 +0200

Merge commit '2341df1cb9b3681bfefe29207887b2b3dc271a95' into HEAD [#2801]

Diff:


[gcc/devel/rust/master] Merge commit '4bd09ce06f50d266c992c984cc993384d5e6655e' into HEAD

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:ca224bde2989de54fc33fae46df560b7f5af835e

commit ca224bde2989de54fc33fae46df560b7f5af835e
Merge: 4966574bdc77 4bd09ce06f50
Author: Thomas Schwinge 
Date:   Wed Apr 10 10:45:29 2024 +0200

Merge commit '4bd09ce06f50d266c992c984cc993384d5e6655e' into HEAD

Diff:


[gcc/devel/rust/master] Merge commit '2341df1cb9b3681bfefe29207887b2b3dc271a95^' into HEAD

2024-05-07 Thread Thomas Schwinge via Libstdc++-cvs
https://gcc.gnu.org/g:d1a0609b7e62b21d747dfaa0c0f84e51099bd952

commit d1a0609b7e62b21d747dfaa0c0f84e51099bd952
Merge: c9e59de17dd4 484f48f03cf9
Author: Thomas Schwinge 
Date:   Wed Apr 10 10:51:48 2024 +0200

Merge commit '2341df1cb9b3681bfefe29207887b2b3dc271a95^' into HEAD

Diff:

 ChangeLog  |   10 +
 gcc/ChangeLog  |  214 +
 gcc/DATESTAMP  |2 +-
 gcc/attribs.h  |2 +-
 gcc/c-family/ChangeLog |6 +
 gcc/common.opt |2 +-
 gcc/config/aarch64/aarch64-cores.def   |1 +
 gcc/config/aarch64/aarch64-tune.md |2 +-
 gcc/config/aarch64/predicates.md   |6 +-
 gcc/config/i386/i386-options.cc|2 +-
 gcc/config/loongarch/loongarch.cc  |5 +
 gcc/config/mips/mips.cc|2 +
 gcc/config/riscv/riscv-opts.h  |9 +
 gcc/config/riscv/riscv-vsetvl.cc   |   63 +-
 gcc/config/riscv/riscv.opt |   14 +
 gcc/cp/ChangeLog   |   50 +
 gcc/cp/decl.cc |7 +-
 gcc/cp/decl2.cc|   10 +-
 gcc/cp/module.cc   |   24 +-
 gcc/cp/name-lookup.cc  |   15 +-
 gcc/cp/name-lookup.h   |3 +-
 gcc/cp/parser.cc   |   21 +-
 gcc/cp/pt.cc   |4 +-
 gcc/doc/extend.texi|  821 +-
 gcc/doc/invoke.texi|  233 +-
 gcc/gengtype.cc|4 +-
 gcc/gimple-lower-bitint.cc |   18 +-
 gcc/gimple-ssa-warn-access.cc  |9 +
 gcc/ipa-polymorphic-call.cc|1 -
 gcc/ipa-strub.cc   |   19 +-
 gcc/omp-expand.cc  |6 +-
 gcc/omp-general.cc |   21 +-
 gcc/predict.cc |  131 +-
 gcc/predict.def|   10 +
 gcc/rust/ChangeLog | 8325 
 gcc/sched-deps.cc  |   48 +-
 gcc/testsuite/ChangeLog| 1781 +
 .../g++.dg/cpp23/explicit-obj-diagnostics3.C   |  106 +-
 .../g++.dg/cpp23/explicit-obj-diagnostics9.C   |6 +
 gcc/testsuite/g++.dg/cpp2a/nontype-class61.C   |   25 +
 gcc/testsuite/g++.dg/cpp2a/nontype-class62.C   |8 +
 gcc/testsuite/g++.dg/modules/merge-16.h|   10 +
 gcc/testsuite/g++.dg/modules/merge-16_a.C  |7 +
 gcc/testsuite/g++.dg/modules/merge-16_b.C  |5 +
 gcc/testsuite/g++.dg/modules/pr113292_a.H  |   34 +
 gcc/testsuite/g++.dg/modules/pr113292_b.C  |   13 +
 gcc/testsuite/g++.dg/modules/pr113292_c.C  |   11 +
 gcc/testsuite/g++.dg/pr99966.C |2 +-
 gcc/testsuite/g++.target/loongarch/got-load.C  |   19 +
 gcc/testsuite/gcc.c-torture/compile/pr110251.c |   27 +
 gcc/testsuite/gcc.c-torture/compile/pr113221-1.c   |   12 +
 gcc/testsuite/gcc.dg/array-quals-1.c   |   20 +-
 gcc/testsuite/gcc.dg/atomic/stdatomic-flag-2.c |2 +-
 gcc/testsuite/gcc.dg/atomic/stdatomic-flag.c   |2 +-
 gcc/testsuite/gcc.dg/bitint-70.c   |   14 +
 gcc/testsuite/gcc.dg/bitint-71.c   |   18 +
 gcc/testsuite/gcc.dg/bitint-72.c   |   16 +
 gcc/testsuite/gcc.dg/c23-tag-alias-2.c |2 +-
 gcc/testsuite/gcc.dg/c23-tag-alias-3.c |2 +-
 gcc/testsuite/gcc.dg/cmp-mem-const-3.c |2 +-
 gcc/testsuite/gcc.dg/cmp-mem-const-4.c |2 +-
 gcc/testsuite/gcc.dg/cmp-mem-const-5.c |2 +-
 gcc/testsuite/gcc.dg/cmp-mem-const-6.c |2 +-
 gcc/testsuite/gcc.dg/gnu23-tag-alias-3.c   |2 +-
 gcc/testsuite/gcc.dg/memcmp-1.c|   35 +
 gcc/testsuite/gcc.dg/pr111409.c|2 +-
 gcc/testsuite/gcc.dg/predict-18.c  |6 +-
 gcc/testsuite/gcc.dg/predict-23.c  |   11 +
 gcc/testsuite/gcc.dg/scantest-lto.c|1 +
 gcc/testsuite/gcc.dg/torture/bitint-50.c   |   31 +
 gcc/testsuite/gcc.dg/torture/inline-mem-cpy-1.c|1 +
 gcc/testsuite/gcc.dg/tree-ssa/gen-vect-2.c |2 +
 gcc/testsuite/gcc.dg/tree-ssa/gen-vect-25.c|2 +
 gcc/testsuite/gcc.dg/tree-ssa/predict-1.c  |   10 +
 gcc/testsuite/gcc.dg/tree-ssa/predict-2.c  |   11 +
 gcc/testsuite/gcc.dg/tree-ssa/predict-3.c  |   15 +
 gcc

[gcc/devel/rust/master] borrowck: Remove block braces to satisfy GNU style

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:c90a9ada247d96025562be15780dba3f3d1f9ec0

commit c90a9ada247d96025562be15780dba3f3d1f9ec0
Author: Jakub Dupak 
Date:   Mon Apr 1 14:06:33 2024 +0200

borrowck: Remove block braces to satisfy GNU style

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-dump.cc (renumber_places):
Remove unecessary braces.
(Dump::go): Remove unecessary braces.
(Dump::visit): Remove unecessary braces.
(Dump::visit_scope): Remove unecessary braces.
* checks/errors/borrowck/rust-bir-fact-collector.h (class 
FactCollector):
Remove unecessary braces.
(points): Remove unecessary braces.
* checks/errors/borrowck/rust-bir-free-region.h: Remove unecessary 
braces.
* checks/errors/borrowck/rust-bir-place.h: Remove unecessary braces.
* checks/errors/borrowck/rust-borrow-checker.cc (BorrowChecker::go):
Remove unecessary braces.
* checks/errors/borrowck/rust-function-collector.h: Remove 
unecessary braces.

Signed-off-by: Jakub Dupak 

Diff:
---
 gcc/rust/checks/errors/borrowck/rust-bir-dump.cc   | 47 +---
 .../errors/borrowck/rust-bir-fact-collector.h  | 87 +++---
 .../checks/errors/borrowck/rust-bir-free-region.h  | 16 +---
 gcc/rust/checks/errors/borrowck/rust-bir-place.h   | 17 ++---
 .../checks/errors/borrowck/rust-borrow-checker.cc  |  6 +-
 .../errors/borrowck/rust-function-collector.h  |  4 +-
 6 files changed, 56 insertions(+), 121 deletions(-)

diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc 
b/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc
index 51dd14363506..a39f145f8f95 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc
@@ -42,13 +42,9 @@ renumber_places (const Function , std::vector 
_map)
 {
   const Place  = func.place_db[in_id];
   if (place.kind == Place::VARIABLE || place.kind == Place::TEMPORARY)
-   {
- place_map[in_id] = next_out_id++;
-   }
+   place_map[in_id] = next_out_id++;
   else
-   {
- place_map[in_id] = INVALID_PLACE;
-   }
+   place_map[in_id] = INVALID_PLACE;
 }
 }
 
@@ -138,10 +134,9 @@ Dump::go (bool enable_simplify_cfg)
  stream << ";\n";
}
   if (!bb_terminated)
-   {
- stream << indentation << indentation << "goto -> bb"
-<< bb_fold_map[bb.successors.at (0)] << ";\t\t" << i++ << "\n";
-   }
+   stream << indentation << indentation << "goto -> bb"
+  << bb_fold_map[bb.successors.at (0)] << ";\t\t" << i++ << "\n";
+
   stream << indentation << "}\n";
 }
 
@@ -276,15 +271,13 @@ void
 Dump::visit (const CallExpr )
 {
   stream << "Call(";
-  if (auto fn_type
-  = func.place_db[expr.get_callable ()].tyty->try_as ())
-{
-  stream << fn_type->get_identifier ();
-}
+  auto maybe_fn_type
+= func.place_db[expr.get_callable ()].tyty->try_as ();
+  if (maybe_fn_type)
+stream << maybe_fn_type->get_identifier ();
   else
-{
-  visit_move_place (expr.get_callable ());
-}
+visit_move_place (expr.get_callable ());
+
   stream << ")(";
   print_comma_separated (stream, expr.get_arguments (),
 [this] (PlaceId place_id) {
@@ -321,13 +314,9 @@ void
 Dump::visit (const Assignment )
 {
   if (func.place_db[expr.get_rhs ()].is_rvalue ())
-{
-  visit_move_place (expr.get_rhs ());
-}
+visit_move_place (expr.get_rhs ());
   else
-{
-  visit_place (expr.get_rhs ());
-}
+visit_place (expr.get_rhs ());
 }
 
 std::ostream &
@@ -346,9 +335,8 @@ Dump::visit_scope (ScopeId id, size_t depth)
 return;
 
   if (id > 1)
-{
-  indent (depth) << "scope " << id - 1 << " {\n";
-}
+indent (depth) << "scope " << id - 1 << " {\n";
+
   for (auto  : scope.locals)
 {
   indent (depth + 1) << "let _";
@@ -357,9 +345,8 @@ Dump::visit_scope (ScopeId id, size_t depth)
   stream << ";\n";
 }
   for (auto  : scope.children)
-{
-  visit_scope (child, (id >= 1) ? depth + 1 : depth);
-}
+visit_scope (child, (id >= 1) ? depth + 1 : depth);
+
   if (id > 1)
 indent (depth) << "}\n";
 }
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 17c198e0fa7f..527ae65606cc 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-fact-collector.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-fact-collector.h
@@ -67,9 +67,8 @@ class FactCollector : public Visitor
   {
 std::vector free_regions;
 for (size_t i = 0; i < size; i++)
-  {
-   free_regions.push_back (region_binder.get_next_free_region ());
-  }
+  free_regions.push_back (region_binder.get_next_free_region ());
+
 return FreeRegions (std::move (free_regions));
   }
 
@@ -129,9 +128,8 @@ protected: // 

[gcc/devel/rust/master] Merge commit 'a5258f3a11ab577835ef5e93be5cb65ec9e44132^' into HEAD

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:d2bcecd7fd914adf55daac7d36745b03b3279c49

commit d2bcecd7fd914adf55daac7d36745b03b3279c49
Merge: ca224bde2989 db4e496aadf1
Author: Thomas Schwinge 
Date:   Wed Apr 10 10:45:56 2024 +0200

Merge commit 'a5258f3a11ab577835ef5e93be5cb65ec9e44132^' into HEAD

Diff:

 gcc/config/aarch64/aarch64.cc   | 11 +++
 gcc/testsuite/gcc.target/aarch64/pr112573.c | 15 +++
 2 files changed, 26 insertions(+)


[gcc/devel/rust/master] borrowck: BIR: make BIR visitor const

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:42ec29cacf4a16586bd30611b116cfff5a549c5e

commit 42ec29cacf4a16586bd30611b116cfff5a549c5e
Author: Jakub Dupak 
Date:   Tue Feb 27 20:22:17 2024 +0100

borrowck: BIR: make BIR visitor const

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-dump.cc (Dump::visit): const
visitor
* checks/errors/borrowck/rust-bir-dump.h: const visitor
* checks/errors/borrowck/rust-bir-visitor.h: const visitor
* checks/errors/borrowck/rust-bir.h: const getter

Signed-off-by: Jakub Dupak 

Diff:
---
 gcc/rust/checks/errors/borrowck/rust-bir-dump.cc   | 14 +++---
 gcc/rust/checks/errors/borrowck/rust-bir-dump.h| 14 +++---
 gcc/rust/checks/errors/borrowck/rust-bir-visitor.h | 14 +++---
 gcc/rust/checks/errors/borrowck/rust-bir.h |  6 +-
 4 files changed, 26 insertions(+), 22 deletions(-)

diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc 
b/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc
index 320b653f830a..6f1579df1d9e 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc
@@ -155,7 +155,7 @@ Dump::go (bool enable_simplify_cfg)
   stream << "}\n";
 }
 void
-Dump::visit (Statement )
+Dump::visit (const Statement )
 {
   statement_place = stmt.get_place ();
   switch (stmt.get_kind ())
@@ -247,7 +247,7 @@ Dump::visit_move_place (PlaceId place_id)
 }
 
 void
-Dump::visit (BorrowExpr )
+Dump::visit (const BorrowExpr )
 {
   stream << "&";
   visit_lifetime (statement_place);
@@ -268,7 +268,7 @@ Dump::visit_lifetime (PlaceId place_id)
 }
 
 void
-Dump::visit (InitializerExpr )
+Dump::visit (const InitializerExpr )
 {
   stream << "{";
   print_comma_separated (stream, expr.get_values (), [this] (PlaceId place_id) 
{
@@ -278,7 +278,7 @@ Dump::visit (InitializerExpr )
 }
 
 void
-Dump::visit (CallExpr )
+Dump::visit (const CallExpr )
 {
   stream << "Call(";
   if (auto fn_type
@@ -305,7 +305,7 @@ Dump::visit (CallExpr )
 }
 
 void
-Dump::visit (Operator<1> )
+Dump::visit (const Operator<1> )
 {
   stream << "Operator(";
   visit_move_place (expr.get_operand<0> ());
@@ -313,7 +313,7 @@ Dump::visit (Operator<1> )
 }
 
 void
-Dump::visit (Operator<2> )
+Dump::visit (const Operator<2> )
 {
   stream << "Operator(";
   visit_move_place (expr.get_operand<0> ());
@@ -323,7 +323,7 @@ Dump::visit (Operator<2> )
 }
 
 void
-Dump::visit (Assignment )
+Dump::visit (const Assignment )
 {
   if (func.place_db[expr.get_rhs ()].is_rvalue ())
 {
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-dump.h 
b/gcc/rust/checks/errors/borrowck/rust-bir-dump.h
index cc3f9cdc7386..9d6babd00535 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-dump.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-dump.h
@@ -49,16 +49,16 @@ public:
   void go (bool enable_simplify_cfg = false);
 
 protected:
-  void visit (Statement ) override;
+  void visit (const Statement ) override;
   void visit_place (PlaceId place_id);
   void visit_move_place (PlaceId place_id);
-  void visit (BorrowExpr ) override;
+  void visit (const BorrowExpr ) override;
   void visit_lifetime (PlaceId place_id);
-  void visit (InitializerExpr ) override;
-  void visit (CallExpr ) override;
-  void visit (Operator<1> ) override;
-  void visit (Operator<2> ) override;
-  void visit (Assignment ) override;
+  void visit (const InitializerExpr ) override;
+  void visit (const CallExpr ) override;
+  void visit (const Operator<1> ) override;
+  void visit (const Operator<2> ) override;
+  void visit (const Assignment ) override;
   void visit_scope (ScopeId id, size_t depth = 1);
 
   std::ostream  (size_t depth);
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-visitor.h 
b/gcc/rust/checks/errors/borrowck/rust-bir-visitor.h
index 7ad62f700dbc..2371b8bb5cec 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-visitor.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-visitor.h
@@ -32,13 +32,13 @@ class CallExpr;
 class Visitor
 {
 public:
-  virtual void visit (Statement ) = 0;
-  virtual void visit (InitializerExpr ) = 0;
-  virtual void visit (Operator<1> ) = 0;
-  virtual void visit (Operator<2> ) = 0;
-  virtual void visit (BorrowExpr ) = 0;
-  virtual void visit (Assignment ) = 0;
-  virtual void visit (CallExpr ) = 0;
+  virtual void visit (const Statement ) = 0;
+  virtual void visit (const InitializerExpr ) = 0;
+  virtual void visit (const Operator<1> ) = 0;
+  virtual void visit (const Operator<2> ) = 0;
+  virtual void visit (const BorrowExpr ) = 0;
+  virtual void visit (const Assignment ) = 0;
+  virtual void visit (const CallExpr ) = 0;
 };
 
 class Visitable
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir.h 
b/gcc/rust/checks/errors/borrowck/rust-bir.h
index f8a2151aaf8c..d21cb90abf52 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir.h
@@ -137,6 +137,10 @@ public:
 
 public:
   std::vector 

[gcc/devel/rust/master] Merge commit '7a6906c8d80e437a97c780370a8fec4e00561c7b' into HEAD [#2288]

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:4966574bdc77ab3a0e6ff8bdebb8b85ffb44c851

commit 4966574bdc77ab3a0e6ff8bdebb8b85ffb44c851
Merge: 041fef1b5810 7a6906c8d80e
Author: Thomas Schwinge 
Date:   Wed Apr 10 10:43:34 2024 +0200

Merge commit '7a6906c8d80e437a97c780370a8fec4e00561c7b' into HEAD [#2288]

Diff:


[gcc/devel/rust/master] borrowck: BIR: use callable API

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:ba7e9a78f6c0f875d94db51c9fc64fec64477874

commit ba7e9a78f6c0f875d94db51c9fc64fec64477874
Author: Jakub Dupak 
Date:   Fri Feb 2 14:33:56 2024 +0100

borrowck: BIR: use callable API

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc 
(ExprStmtBuilder::visit):
Use callable API

Signed-off-by: Jakub Dupak 

Diff:
---
 .../errors/borrowck/rust-bir-builder-expr-stmt.cc  | 23 +-
 1 file changed, 5 insertions(+), 18 deletions(-)

diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.cc 
b/gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.cc
index 2c916294ca7a..ea8107b1fb76 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.cc
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.cc
@@ -248,25 +248,12 @@ ExprStmtBuilder::visit (HIR::CallExpr )
   PlaceId fn = visit_expr (*expr.get_fnexpr ());
   std::vector arguments = visit_list (expr.get_arguments ());
 
-  auto *call_type = ctx.place_db[fn].tyty;
-  if (auto fn_type = call_type->try_as ())
-{
-  for (size_t i = 0; i < fn_type->get_params ().size (); ++i)
-   {
- coercion_site (arguments[i], fn_type->get_params ()[i].second);
-   }
-}
-  else if (auto fn_ptr_type = call_type->try_as ())
-{
-  for (size_t i = 0; i < fn_ptr_type->get_params ().size (); ++i)
-   {
- coercion_site (arguments[i],
-fn_ptr_type->get_params ()[i].get_tyty ());
-   }
-}
-  else
+  const auto fn_type
+= ctx.place_db[fn].tyty->as ();
+
+  for (size_t i = 0; i < fn_type->get_num_params (); ++i)
 {
-  rust_unreachable ();
+  coercion_site (arguments[i], fn_type->get_param_type_at (i));
 }
 
   return_expr (new CallExpr (fn, std::move (arguments)), lookup_type (expr),


[gcc/devel/rust/master] Fix grammar as pointed out by Marc

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:edd018d8c7b7a0229e10430ee61ac50f390670c2

commit edd018d8c7b7a0229e10430ee61ac50f390670c2
Author: Jasmine Tang 
Date:   Fri Apr 5 02:25:48 2024 -0700

Fix grammar as pointed out by Marc

ChangeLog:

* README.md (gccrs-workspace]): like-wise.

Diff:
---
 README.md | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/README.md b/README.md
index 502b61f0ab1e..2ba59d3a6b24 100644
--- a/README.md
+++ b/README.md
@@ -75,11 +75,11 @@ $ make
 
 ```
 
-Alternatively, a docker environment is avaiable for ARM-based Mac contributors.
+Alternatively, a docker environment is available for ARM-based Mac 
contributors.
 
 Please visit 
[gccrs-workspace](https://github.com/badumbatish/gccrs-workspace). 
  
-The image is based on Ubuntu ARM and came with dependencies all fetched.
+The image is based on Ubuntu ARM and comes with dependencies all fetched.
 
  Running GCC Rust


[gcc/devel/rust/master] Merge commit 'fc59a3995cb46c190c0efb0431ad204e399975c4' into HEAD [#2183]

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:041fef1b58109237f972d28f8225f72c0fc1a75a

commit 041fef1b58109237f972d28f8225f72c0fc1a75a
Merge: 0ba53bfa815a fc59a3995cb4
Author: Thomas Schwinge 
Date:   Wed Apr 10 10:34:02 2024 +0200

Merge commit 'fc59a3995cb46c190c0efb0431ad204e399975c4' into HEAD [#2183]

Diff:


[gcc/devel/rust/master] borrowck: Bump copyright notice

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:ff196e451c6b4eb9736b2331c6a108b85f9d260b

commit ff196e451c6b4eb9736b2331c6a108b85f9d260b
Author: Jakub Dupak 
Date:   Wed Apr 3 10:30:15 2024 +0200

borrowck: Bump copyright notice

gcc/rust/ChangeLog:

* checks/errors/borrowck/ffi-polonius/src/gccrs_ffi.rs: Bump 
copyright.
* checks/errors/borrowck/ffi-polonius/src/lib.rs: Bump copyright.
* checks/errors/borrowck/polonius/rust-polonius-ffi.h: Bump 
copyright.
* checks/errors/borrowck/polonius/rust-polonius.h: Bump copyright.
* checks/errors/borrowck/rust-bir-dump.cc: Bump copyright.
* checks/errors/borrowck/rust-bir-fact-collector.h: Bump copyright.
* checks/errors/borrowck/rust-bir-free-region.h: Bump copyright.

Signed-off-by: Jakub Dupak 

Diff:
---
 .../errors/borrowck/ffi-polonius/src/gccrs_ffi.rs  |  2 +-
 .../checks/errors/borrowck/ffi-polonius/src/lib.rs |  2 +-
 .../errors/borrowck/polonius/rust-polonius-ffi.h   |  2 +-
 .../checks/errors/borrowck/polonius/rust-polonius.h|  2 +-
 gcc/rust/checks/errors/borrowck/rust-bir-dump.cc   | 18 ++
 .../checks/errors/borrowck/rust-bir-fact-collector.h   |  2 +-
 gcc/rust/checks/errors/borrowck/rust-bir-free-region.h | 18 ++
 7 files changed, 41 insertions(+), 5 deletions(-)

diff --git a/gcc/rust/checks/errors/borrowck/ffi-polonius/src/gccrs_ffi.rs 
b/gcc/rust/checks/errors/borrowck/ffi-polonius/src/gccrs_ffi.rs
index 3a849444bbc3..5b4e6d39d21c 100644
--- a/gcc/rust/checks/errors/borrowck/ffi-polonius/src/gccrs_ffi.rs
+++ b/gcc/rust/checks/errors/borrowck/ffi-polonius/src/gccrs_ffi.rs
@@ -1,4 +1,4 @@
-// Copyright (C) 2020-2023 Free Software Foundation, Inc.
+// Copyright (C) 2020-2024 Free Software Foundation, Inc.
 
 // This file is part of GCC.
 
diff --git a/gcc/rust/checks/errors/borrowck/ffi-polonius/src/lib.rs 
b/gcc/rust/checks/errors/borrowck/ffi-polonius/src/lib.rs
index a9aa8106b69a..819c34a93749 100644
--- a/gcc/rust/checks/errors/borrowck/ffi-polonius/src/lib.rs
+++ b/gcc/rust/checks/errors/borrowck/ffi-polonius/src/lib.rs
@@ -1,4 +1,4 @@
-// Copyright (C) 2020-2023 Free Software Foundation, Inc.
+// Copyright (C) 2020-2024 Free Software Foundation, Inc.
 
 // This file is part of GCC.
 
diff --git a/gcc/rust/checks/errors/borrowck/polonius/rust-polonius-ffi.h 
b/gcc/rust/checks/errors/borrowck/polonius/rust-polonius-ffi.h
index 500d25a3222e..ebfddab76170 100644
--- a/gcc/rust/checks/errors/borrowck/polonius/rust-polonius-ffi.h
+++ b/gcc/rust/checks/errors/borrowck/polonius/rust-polonius-ffi.h
@@ -1,4 +1,4 @@
-// Copyright (C) 2020-2023 Free Software Foundation, Inc.
+// Copyright (C) 2020-2024 Free Software Foundation, Inc.
 
 // This file is part of GCC.
 
diff --git a/gcc/rust/checks/errors/borrowck/polonius/rust-polonius.h 
b/gcc/rust/checks/errors/borrowck/polonius/rust-polonius.h
index df746dd0c767..239cc3440117 100644
--- a/gcc/rust/checks/errors/borrowck/polonius/rust-polonius.h
+++ b/gcc/rust/checks/errors/borrowck/polonius/rust-polonius.h
@@ -1,4 +1,4 @@
-// Copyright (C) 2020-2022 Free Software Foundation, Inc.
+// Copyright (C) 2020-2024 Free Software Foundation, Inc.
 
 // This file is part of GCC.
 
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc 
b/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc
index a39f145f8f95..d3398b6f405a 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc
@@ -1,3 +1,21 @@
+// 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
+// 
+
 #include "rust-system.h"
 #include "rust-bir-dump.h"
 #include "rust-diagnostics.h"
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 527ae65606cc..bb8fedaf3db7 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-fact-collector.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-fact-collector.h
@@ -1,4 +1,4 @@
-// Copyright (C) 2020-2023 Free Software Foundation, Inc.
+// Copyright (C) 2020-2024 Free Software Foundation, Inc.
 
 // This file is part of GCC.
 
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 e5d6ef3c98be..b8d73c9c070d 100644

[gcc/devel/rust/master] Improve parsing of raw string literals

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:e36c3ece68cecba3170ab2d35de6e0a0c8bac40e

commit e36c3ece68cecba3170ab2d35de6e0a0c8bac40e
Author: Owen Avery 
Date:   Tue Mar 26 21:10:05 2024 -0400

Improve parsing of raw string literals

gcc/rust/ChangeLog:

* lex/rust-lex.cc
(Lexer::parse_raw_string):
Bring handling of edge cases to par with parse_raw_byte_string.

gcc/testsuite/ChangeLog:

* rust/compile/raw-string-loc.rs: New test.

Signed-off-by: Owen Avery 

Diff:
---
 gcc/rust/lex/rust-lex.cc | 21 ++---
 gcc/testsuite/rust/compile/raw-string-loc.rs |  6 ++
 2 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/gcc/rust/lex/rust-lex.cc b/gcc/rust/lex/rust-lex.cc
index 7c37e83d6cb7..e5c9148976c1 100644
--- a/gcc/rust/lex/rust-lex.cc
+++ b/gcc/rust/lex/rust-lex.cc
@@ -2152,6 +2152,9 @@ Lexer::parse_raw_string (location_t loc, int 
initial_hash_count)
   str.reserve (16); // some sensible default
 
   int length = 1 + initial_hash_count;
+  current_column += length;
+
+  const location_t string_begin_locus = get_current_location ();
 
   if (initial_hash_count > 0)
 skip_input (initial_hash_count - 1);
@@ -2162,10 +2165,11 @@ Lexer::parse_raw_string (location_t loc, int 
initial_hash_count)
 rust_error_at (get_current_location (), "raw string has no opening 
%<\"%>");
 
   length++;
+  current_column++;
   skip_input ();
   current_char = peek_input ();
 
-  while (!current_char.is_eof ())
+  while (true)
 {
   if (current_char.value == '"')
{
@@ -2186,19 +2190,30 @@ Lexer::parse_raw_string (location_t loc, int 
initial_hash_count)
  skip_input (initial_hash_count);
  current_char = peek_input ();
  length += initial_hash_count + 1;
+ current_column += initial_hash_count + 1;
  break;
}
}
+  else if (current_char.is_eof ())
+   {
+ rust_error_at (string_begin_locus, "unended raw string literal");
+ return Token::make (END_OF_FILE, get_current_location ());
+   }
 
   length++;
+  current_column++;
+  if (current_char == '\n')
+   {
+ current_line++;
+ current_column = 1;
+ start_line (current_line, max_column_hint);
+   }
 
   str += current_char.as_string ();
   skip_input ();
   current_char = peek_input ();
 }
 
-  current_column += length;
-
   loc += length - 1;
 
   str.shrink_to_fit ();
diff --git a/gcc/testsuite/rust/compile/raw-string-loc.rs 
b/gcc/testsuite/rust/compile/raw-string-loc.rs
new file mode 100644
index ..70977510ba38
--- /dev/null
+++ b/gcc/testsuite/rust/compile/raw-string-loc.rs
@@ -0,0 +1,6 @@
+const X: &'static str = r#"12
+12"#;
+
+BREAK
+// { dg-error "unrecognised token" "" { target *-*-* } .-1 }
+// { dg-excess-errors "error 'failed to parse item' does not have location" }


[gcc/devel/rust/master] Merge commit 'fc59a3995cb46c190c0efb0431ad204e399975c4^' into HEAD

2024-05-07 Thread Thomas Schwinge via Libstdc++-cvs
https://gcc.gnu.org/g:0ba53bfa815ad64c834ad726a8cf81d7acf1c49f

commit 0ba53bfa815ad64c834ad726a8cf81d7acf1c49f
Merge: edd018d8c7b7 ee0717da1eb5
Author: Thomas Schwinge 
Date:   Wed Apr 10 10:20:22 2024 +0200

Merge commit 'fc59a3995cb46c190c0efb0431ad204e399975c4^' into HEAD

Diff:

 ChangeLog  |   15 +
 MAINTAINERS|1 +
 config/ChangeLog   |4 +
 config/acinclude.m4|   22 -
 contrib/ChangeLog  |   10 +
 contrib/dg-extract-results.py  |3 +-
 contrib/unicode/gen_libstdcxx_unicode_data.py  |5 +-
 gcc/BASE-VER   |2 +-
 gcc/ChangeLog  | 1125 +++
 gcc/DATESTAMP  |2 +-
 gcc/ada/ChangeLog  |  201 ++
 gcc/analyzer/ChangeLog |   20 +
 gcc/analyzer/analyzer.h|3 +
 gcc/analyzer/constraint-manager.cc |2 +-
 gcc/analyzer/region-model-manager.cc   |6 +
 gcc/analyzer/sm-taint.cc   |  114 +-
 gcc/builtins.cc|5 +-
 gcc/c-family/ChangeLog |   30 +
 gcc/c-family/c-ada-spec.cc |2 +
 gcc/c-family/c-cppbuiltin.cc   |1 +
 gcc/c-family/c-pretty-print.cc |   12 +
 gcc/c/ChangeLog|   43 +
 gcc/c/c-parser.cc  |  155 +-
 gcc/c/c-tree.h |2 +
 gcc/c/c-typeck.cc  |  113 +-
 gcc/cfgexpand.cc   |   30 +-
 gcc/config.gcc |2 +-
 gcc/config.in  |   12 +
 gcc/config/aarch64/aarch64-ldp-fusion.cc   |   76 +-
 gcc/config/aarch64/aarch64-protos.h|1 +
 gcc/config/aarch64/aarch64-simd.md |  134 +-
 gcc/config/aarch64/aarch64-sve-builtins-sme.def|   53 +-
 gcc/config/aarch64/aarch64-sve-builtins-sve2.def   |1 +
 gcc/config/aarch64/aarch64-sve-builtins.cc |   48 +-
 gcc/config/aarch64/aarch64-sve-builtins.def|   13 -
 gcc/config/aarch64/aarch64-sve-builtins.h  |4 -
 gcc/config/aarch64/aarch64.cc  |  124 +-
 gcc/config/aarch64/aarch64.h   |6 +
 gcc/config/aarch64/aarch64.opt |4 +-
 gcc/config/aarch64/iterators.md|2 +
 gcc/config/arm/arm_neon.h  | 2032 +---
 gcc/config/arm/arm_neon_builtins.def   |   12 +
 gcc/config/arm/iterators.md|6 +
 gcc/config/arm/neon.md |  249 +++
 gcc/config/arm/unspecs.md  |8 +
 gcc/config/avr/avr-arch.h  |   40 +-
 gcc/config/avr/avr-devices.cc  |   20 +-
 gcc/config/avr/avr-mcus.def|   56 +-
 gcc/config/avr/avr.cc  |   75 +-
 gcc/config/avr/avr.h   |2 +
 gcc/config/avr/avr.opt |   16 +-
 gcc/config/avr/driver-avr.cc   |   27 +-
 gcc/config/avr/gen-avr-mmcu-specs.cc   |  115 +-
 gcc/config/avr/gen-avr-mmcu-texi.cc|3 +-
 gcc/config/avr/specs.h |   10 +-
 gcc/config/i386/i386-c.cc  |7 +
 gcc/config/i386/i386.opt   |3 +-
 gcc/config/i386/sse.md |4 -
 gcc/config/loongarch/genopts/genstr.sh |2 +-
 gcc/config/loongarch/genopts/loongarch-strings |8 +-
 gcc/config/loongarch/genopts/loongarch.opt.in  |   54 +-
 gcc/config/loongarch/lasx.md   |4 +-
 gcc/config/loongarch/loongarch-builtins.cc |6 +-
 gcc/config/loongarch/loongarch-c.cc|2 +-
 gcc/config/loongarch/loongarch-cpu.cc  |2 +-
 gcc/config/loongarch/loongarch-def.cc  |   14 +-
 gcc/config/loongarch/loongarch-def.h   |  120 +-
 gcc/config/loongarch/loongarch-driver.cc   |5 +-
 gcc/config/loongarch/loongarch-opts.cc |   34 +-
 gcc/config/loongarch/loongarch-opts.h  |   26 +-
 gcc/config/loongarch/loongarch-str.h   |7 +-
 gcc/config/loongarch/loongarch.cc  |  122 +-
 gcc/config/loongarch/loongarch.h   |2 +-
 gcc/config/loongarch/loongarch.md  |  198 +-
 gcc/config/loongarch/loongarch.opt |   58 +-
 gcc/config/loongarch/lsx.md|4

[gcc/devel/rust/master] borrowck: Free region representation

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:b783c3ce70167c218213fad90a61dba7eec733db

commit b783c3ce70167c218213fad90a61dba7eec733db
Author: Jakub Dupak 
Date:   Tue Feb 27 21:07:03 2024 +0100

borrowck: Free region representation

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-free-region.h: New file.

Signed-off-by: Jakub Dupak 

Diff:
---
 .../checks/errors/borrowck/rust-bir-free-region.h  | 107 +
 1 file changed, 107 insertions(+)

diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-free-region.h 
b/gcc/rust/checks/errors/borrowck/rust-bir-free-region.h
new file mode 100644
index ..0560a894ab06
--- /dev/null
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-free-region.h
@@ -0,0 +1,107 @@
+#ifndef RUST_BIR_FREE_REGION_H
+#define RUST_BIR_FREE_REGION_H
+
+#include "rust-diagnostics.h"
+#include "polonius/rust-polonius-ffi.h"
+
+namespace Rust {
+
+using FreeRegion = size_t;
+
+class FreeRegions
+{
+  std::vector regions;
+
+public:
+  WARN_UNUSED_RESULT bool has_regions () const { return !regions.empty (); }
+  decltype (regions)::const_iterator begin () const { return regions.begin (); 
}
+  decltype (regions)::const_iterator end () const { return regions.end (); }
+  size_t size () const { return regions.size (); }
+  FreeRegion [] (size_t i) { return regions.at (i); }
+  const FreeRegion [] (size_t i) const { return regions.at (i); }
+  const std::vector _regions () const { return regions; }
+  void set_from (std::vector &)
+  {
+this->regions.clear ();
+for (auto  : regions)
+  {
+   this->regions.push_back ({region});
+  }
+  }
+
+  WARN_UNUSED_RESULT FreeRegions prepend (FreeRegion region) const
+  {
+std::vector new_regions = {region};
+new_regions.insert (new_regions.end (), regions.begin (), regions.end ());
+return FreeRegions (std::move (new_regions));
+  }
+
+  FreeRegions (std::vector &) : regions (regions) {}
+
+  WARN_UNUSED_RESULT std::string to_string () const
+  {
+std::stringstream result;
+for (auto  : regions)
+  {
+   result << region;
+   result << ", ";
+  }
+// Remove the last ", " from the string.
+if (result.tellg () > 2)
+  result.seekp (-2, std::ios_base::cur);
+
+return result.str ();
+  }
+};
+
+class RegionBinder
+{
+  FreeRegion _free_region;
+
+public:
+  explicit RegionBinder (FreeRegion _free_region)
+: next_free_region (next_free_region)
+  {}
+
+  WARN_UNUSED_RESULT FreeRegion get_next_free_region () const
+  {
+return next_free_region++;
+  }
+
+  FreeRegions bind_regions (std::vector regions,
+   FreeRegions parent_free_regions)
+  {
+std::vector free_regions;
+for (auto  : regions)
+  {
+   if (region.is_early_bound ())
+ {
+   free_regions.push_back (parent_free_regions[region.get_index ()]);
+ }
+   else if (region.is_static ())
+ {
+   free_regions.push_back (0);
+ }
+   else if (region.is_anonymous ())
+ {
+   free_regions.push_back (get_next_free_region ());
+ }
+   else if (region.is_named ())
+ {
+   rust_unreachable (); // FIXME
+ }
+   else
+ {
+   rust_sorry_at (UNKNOWN_LOCATION, "Unimplemented");
+   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;
+  }
+};
+
+} // namespace Rust
+
+#endif // RUST_BIR_FREE_REGION_H


[gcc/devel/rust/master] Add an alternative solution on MacOS

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:19719f4f2d230b39937b6977f81164a59acabcd7

commit 19719f4f2d230b39937b6977f81164a59acabcd7
Author: Jasmine Tang 
Date:   Thu Apr 4 20:02:26 2024 -0700

Add an alternative solution on MacOS

For #2937.
ChangeLog:

* README.md (gccrs-workspace]): like-wise.

Diff:
---
 README.md | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/README.md b/README.md
index 31df8df5138a..502b61f0ab1e 100644
--- a/README.md
+++ b/README.md
@@ -75,6 +75,12 @@ $ make
 
 ```
 
+Alternatively, a docker environment is avaiable for ARM-based Mac contributors.
+
+Please visit 
[gccrs-workspace](https://github.com/badumbatish/gccrs-workspace). 
+ 
+The image is based on Ubuntu ARM and came with dependencies all fetched.
+
  Running GCC Rust
 
 Running the compiler itself without make install we can simply invoke the 
compiler proper:


[gcc/devel/rust/master] Avoid parsing const unsafe/extern functions as async

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:01092b83913733d26f2c4d9bfdc22ff2eb0b0bbb

commit 01092b83913733d26f2c4d9bfdc22ff2eb0b0bbb
Author: Owen Avery 
Date:   Tue Mar 26 15:58:48 2024 -0400

Avoid parsing const unsafe/extern functions as async

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h
(Parser::parse_vis_item):
Call parse_function instead of parse_async_item when finding
UNSAFE or EXTERN_KW during lookahead.

gcc/testsuite/ChangeLog:

* rust/compile/func-const-unsafe.rs: New test.

Signed-off-by: Owen Avery 

Diff:
---
 gcc/rust/parse/rust-parse-impl.h| 4 ++--
 gcc/testsuite/rust/compile/func-const-unsafe.rs | 1 +
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index b6c2ca3fc0c9..263ca634ea5c 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -1382,10 +1382,10 @@ Parser::parse_vis_item 
(AST::AttrVec outer_attrs)
case IDENTIFIER:
case UNDERSCORE:
  return parse_const_item (std::move (vis), std::move (outer_attrs));
-   case UNSAFE:
-   case EXTERN_KW:
case ASYNC:
  return parse_async_item (std::move (vis), std::move (outer_attrs));
+   case UNSAFE:
+   case EXTERN_KW:
case FN_KW:
  return parse_function (std::move (vis), std::move (outer_attrs));
default:
diff --git a/gcc/testsuite/rust/compile/func-const-unsafe.rs 
b/gcc/testsuite/rust/compile/func-const-unsafe.rs
new file mode 100644
index ..9c932bd1cb54
--- /dev/null
+++ b/gcc/testsuite/rust/compile/func-const-unsafe.rs
@@ -0,0 +1 @@
+pub const unsafe fn foo() {}


[gcc/devel/rust/master] borrowck: BIR: emit moves

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:400324882aaa45772930d2266c9241d45f64d251

commit 400324882aaa45772930d2266c9241d45f64d251
Author: Jakub Dupak 
Date:   Fri Feb 2 14:47:14 2024 +0100

borrowck: BIR: emit moves

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc 
(ExprStmtBuilder::visit): Emit moves.
* checks/errors/borrowck/rust-bir-builder-internal.h: Emit moves.
* checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h: Emit 
moves.
* checks/errors/borrowck/rust-bir-dump.cc (Dump::visit_move_place): 
Emit moves.
(Dump::visit): Emit moves.
* checks/errors/borrowck/rust-bir-place.h (struct Place): Emit 
moves.
* checks/errors/borrowck/rust-bir-visitor.h: Emit moves.
* checks/errors/borrowck/rust-bir.h (enum class): Emit moves.
(class AbstractExpr): Emit moves.
(BasicBlock::is_terminated): Emit moves.

Signed-off-by: Jakub Dupak 

Diff:
---
 .../errors/borrowck/rust-bir-builder-expr-stmt.cc  | 15 ++---
 .../errors/borrowck/rust-bir-builder-internal.h| 35 +---
 .../borrowck/rust-bir-builder-lazyboolexpr.h   |  2 +-
 gcc/rust/checks/errors/borrowck/rust-bir-dump.cc   | 11 +++-
 gcc/rust/checks/errors/borrowck/rust-bir-place.h   | 50 +++-
 gcc/rust/checks/errors/borrowck/rust-bir-visitor.h |  4 ++
 gcc/rust/checks/errors/borrowck/rust-bir.h | 66 +++---
 7 files changed, 103 insertions(+), 80 deletions(-)

diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.cc 
b/gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.cc
index 89352d84f6b8..922894cc5d50 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.cc
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.cc
@@ -84,7 +84,7 @@ ExprStmtBuilder::visit (HIR::ClosureExpr )
 {
   captures.push_back (ctx.place_db.lookup_variable (capture));
 }
-  make_args (captures);
+  move_all (captures);
 
   // Note: Not a coercion site for captures.
   return_expr (new InitializerExpr (std::move (captures)), lookup_type (expr));
@@ -96,7 +96,7 @@ ExprStmtBuilder::visit (HIR::StructExprStructFields )
   auto struct_ty
 = lookup_type (fields)->as ()->get_variants ().at (0);
   auto init_values = StructBuilder (ctx, struct_ty).build (fields);
-  make_args (init_values);
+  move_all (init_values);
   return_expr (new InitializerExpr (std::move (init_values)),
   lookup_type (fields));
 }
@@ -141,7 +141,7 @@ void
 ExprStmtBuilder::visit (HIR::NegationExpr )
 {
   PlaceId operand = visit_expr (*expr.get_expr ());
-  return_expr (new Operator<1> ({make_arg (operand)}), lookup_type (expr));
+  return_expr (new Operator<1> ({move_place (operand)}), lookup_type (expr));
 }
 
 void
@@ -149,7 +149,7 @@ ExprStmtBuilder::visit (HIR::ArithmeticOrLogicalExpr )
 {
   PlaceId lhs = visit_expr (*expr.get_lhs ());
   PlaceId rhs = visit_expr (*expr.get_rhs ());
-  return_expr (new Operator<2> ({make_arg (lhs), make_arg (rhs)}),
+  return_expr (new Operator<2> ({move_place (lhs), move_place (rhs)}),
   lookup_type (expr));
 }
 
@@ -158,7 +158,7 @@ ExprStmtBuilder::visit (HIR::ComparisonExpr )
 {
   PlaceId lhs = visit_expr (*expr.get_lhs ());
   PlaceId rhs = visit_expr (*expr.get_rhs ());
-  return_expr (new Operator<2> ({make_arg (lhs), make_arg (rhs)}),
+  return_expr (new Operator<2> ({move_place (lhs), move_place (rhs)}),
   lookup_type (expr));
 }
 
@@ -208,7 +208,7 @@ ExprStmtBuilder::visit (HIR::ArrayExpr )
   case HIR::ArrayElems::VALUES: {
auto _vals = (static_cast (*elems));
auto init_values = visit_list (elem_vals.get_values ());
-   make_args (init_values);
+   move_all (init_values);
return_expr (new InitializerExpr (std::move (init_values)),
 lookup_type (expr));
break;
@@ -264,6 +264,7 @@ ExprStmtBuilder::visit (HIR::CallExpr )
   coercion_site (arguments[i], fn_type->get_param_type_at (i));
 }
 
+  move_all (arguments);
   return_expr (new CallExpr (fn, std::move (arguments)), lookup_type (expr),
   true);
 }
@@ -502,7 +503,7 @@ ExprStmtBuilder::visit (HIR::IfExpr )
 void
 ExprStmtBuilder::visit (HIR::IfExprConseqElse )
 {
-  push_switch (make_arg (visit_expr (*expr.get_if_condition (;
+  push_switch (move_place (visit_expr (*expr.get_if_condition (;
   BasicBlockId if_end_bb = ctx.current_bb;
 
   PlaceId result = take_or_create_return_place (lookup_type (expr));
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 55f00aa50ac9..b421ba43fbae 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h
@@ -230,10 +230,15 @@ protected: // Helpers to add BIR statements
 push_assignment (tmp, rhs);
   }
 
+  void 

[gcc/devel/rust/master] borrowck: Fact collector

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:74745b1e354f0b1fbf3248cbf2bbc6a68f9392bb

commit 74745b1e354f0b1fbf3248cbf2bbc6a68f9392bb
Author: Jakub Dupak 
Date:   Tue Feb 27 23:19:41 2024 +0100

borrowck: Fact collector

This is the main Polonius based logic which creates the information
Polonius needs from BIR. It is largly guessed and rever engineered, so
some aspects are probably wrong.

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-fact-collector.h: New file.
* checks/errors/borrowck/rust-borrow-checker.cc (BorrowChecker::go):
Enable fact collection.

Signed-off-by: Jakub Dupak 

Diff:
---
 .../errors/borrowck/rust-bir-fact-collector.h  | 895 +
 .../checks/errors/borrowck/rust-borrow-checker.cc  |   3 +
 2 files changed, 898 insertions(+)

diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-fact-collector.h 
b/gcc/rust/checks/errors/borrowck/rust-bir-fact-collector.h
new file mode 100644
index ..17c198e0fa7f
--- /dev/null
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-fact-collector.h
@@ -0,0 +1,895 @@
+// Copyright (C) 2020-2023 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
+// .
+
+#ifndef RUST_BIR_FACT_COLLECTOR_H
+#define RUST_BIR_FACT_COLLECTOR_H
+
+#include "rust-bir-visitor.h"
+#include "rust-bir.h"
+#include "rust-bir-place.h"
+#include "polonius/rust-polonius.h"
+
+namespace Rust {
+namespace BIR {
+
+enum class PointPosition : uint8_t
+{
+  START,
+  MID
+};
+
+class FactCollector : public Visitor
+{
+  // Output.
+  Polonius::Facts facts;
+
+  // Read-only context.
+  const PlaceDB _db;
+  const std::vector _blocks;
+  const PlaceId first_local;
+  const location_t location;
+
+  Resolver::TypeCheckContext 
+
+  // Collector state.
+  BasicBlockId current_bb = 0;
+  uint32_t current_stmt = 0;
+  PlaceId lhs = INVALID_PLACE;
+
+  // PlaceDB is const in this phase, so this is used to generate fresh regions.
+  FreeRegion next_fresh_region;
+  RegionBinder region_binder{next_fresh_region};
+
+  std::vector cfg_points_all;
+
+  FreeRegions bind_regions (std::vector regions,
+   FreeRegions parent_free_regions)
+  {
+return region_binder.bind_regions (regions, parent_free_regions);
+  }
+
+  FreeRegions make_fresh_regions (size_t size)
+  {
+std::vector 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));
+  }
+
+public:
+  static Polonius::Facts collect (Function )
+  {
+FactCollector collector (func);
+collector.init_universal_regions (func.universal_regions,
+ func.universal_region_bounds);
+
+collector.visit_statemensts ();
+collector.visit_places (func.arguments);
+
+return std::move (collector.facts);
+  }
+
+protected: // Constructor and destructor.
+  explicit FactCollector (Function )
+: place_db (func.place_db), basic_blocks (func.basic_blocks),
+  first_local (func.arguments.empty () ? FIRST_VARIABLE_PLACE
+  : *func.arguments.rbegin () + 1),
+  location (func.location), tyctx (*Resolver::TypeCheckContext::get ()),
+  next_fresh_region (place_db.peek_next_free_region ())
+  {}
+  ~FactCollector () = default;
+
+protected: // Main collection entry points (for different categories).
+  void init_universal_regions (
+const FreeRegions _regions,
+const decltype (Function::universal_region_bounds) 
_region_bounds)
+  {
+size_t next_loan = place_db.get_loans ().size ();
+facts.universal_region.emplace_back (0);
+facts.placeholder.emplace_back (0, next_loan++);
+
+for (auto  : universal_regions)
+  {
+   facts.universal_region.emplace_back (region);
+   facts.placeholder.emplace_back (region, next_loan++);
+   facts.known_placeholder_subset.emplace_back (0, region);
+  }
+
+// Copy already collected subset facts, that are universally valid.
+for (auto  : universal_region_bounds)
+  facts.known_placeholder_subset.emplace_back (bound.first, bound.second);
+  }
+
+  void visit_places (const std::vector )
+  {
+for (PlaceId place_id = 0; place_id < place_db.size (); ++place_id)
+  {
+   auto  = 

[gcc/devel/rust/master] Recognize rustc_deprecated as a builtin attribute

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:581c43091873b0df860f154c53fdefba393095e9

commit 581c43091873b0df860f154c53fdefba393095e9
Author: Owen Avery 
Date:   Tue Mar 26 21:57:17 2024 -0400

Recognize rustc_deprecated as a builtin attribute

gcc/rust/ChangeLog:

* util/rust-attribute-values.h
(Attributes::RUSTC_DEPRECATED): New.
* util/rust-attributes.cc
(__definitions): Add Attributes::RUSTC_DEPRECATED.

gcc/testsuite/ChangeLog:

* rust/compile/deprecated-fn.rs: New test.

Signed-off-by: Owen Avery 

Diff:
---
 gcc/rust/util/rust-attribute-values.h   | 1 +
 gcc/rust/util/rust-attributes.cc| 1 +
 gcc/testsuite/rust/compile/deprecated-fn.rs | 4 
 3 files changed, 6 insertions(+)

diff --git a/gcc/rust/util/rust-attribute-values.h 
b/gcc/rust/util/rust-attribute-values.h
index e284cec1a161..04aef99be68f 100644
--- a/gcc/rust/util/rust-attribute-values.h
+++ b/gcc/rust/util/rust-attribute-values.h
@@ -48,6 +48,7 @@ public:
   static constexpr auto _FEATURE = "target_feature";
   // From now on, these are reserved by the compiler and gated through
   // #![feature(rustc_attrs)]
+  static constexpr auto _DEPRECATED = "rustc_deprecated";
   static constexpr auto _INHERIT_OVERFLOW_CHECKS
 = "rustc_inherit_overflow_checks";
   static constexpr auto  = "stable";
diff --git a/gcc/rust/util/rust-attributes.cc b/gcc/rust/util/rust-attributes.cc
index eac298082992..e10918b2f8d0 100644
--- a/gcc/rust/util/rust-attributes.cc
+++ b/gcc/rust/util/rust-attributes.cc
@@ -58,6 +58,7 @@ static const BuiltinAttrDefinition __definitions[]
  {Attrs::TARGET_FEATURE, CODE_GENERATION},
  // From now on, these are reserved by the compiler and gated through
  // #![feature(rustc_attrs)]
+ {Attrs::RUSTC_DEPRECATED, STATIC_ANALYSIS},
  {Attrs::RUSTC_INHERIT_OVERFLOW_CHECKS, CODE_GENERATION},
  {Attrs::STABLE, STATIC_ANALYSIS}};
 
diff --git a/gcc/testsuite/rust/compile/deprecated-fn.rs 
b/gcc/testsuite/rust/compile/deprecated-fn.rs
new file mode 100644
index ..4083593b30b5
--- /dev/null
+++ b/gcc/testsuite/rust/compile/deprecated-fn.rs
@@ -0,0 +1,4 @@
+#![feature(rustc_attrs)]
+
+#[rustc_deprecated(since = "right now", reason = "a whim")]
+pub fn foo() {}


[gcc/devel/rust/master] borrowck: BIR: Place tree traverse API

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:e023b086720b868f60fb5945c998a58ae6555265

commit e023b086720b868f60fb5945c998a58ae6555265
Author: Jakub Dupak 
Date:   Fri Feb 2 14:36:26 2024 +0100

borrowck: BIR: Place tree traverse API

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-place.h:
Create place tree traverse API.

Signed-off-by: Jakub Dupak 

Diff:
---
 gcc/rust/checks/errors/borrowck/rust-bir-place.h | 23 +++
 1 file changed, 23 insertions(+)

diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-place.h 
b/gcc/rust/checks/errors/borrowck/rust-bir-place.h
index ccc820121cc4..e62ec3557ad4 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-place.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-place.h
@@ -229,6 +229,29 @@ public:
   places[place].tyty});
   }
 
+  template  void for_each_path_from_root (PlaceId var, FN fn) 
const
+  {
+PlaceId current = var;
+current = places[current].path.first_child;
+while (current != INVALID_PLACE)
+  {
+   fn (current);
+   for_each_path_from_root (current, fn);
+   current = places[current].path.next_sibling;
+  }
+  }
+
+  template 
+  void for_each_path_segment (PlaceId place_id, FN fn) const
+  {
+PlaceId current = place_id;
+while (current != INVALID_PLACE)
+  {
+   fn (current);
+   current = places[current].path.parent;
+  }
+  }
+
 private:
   static bool is_type_copy (TyTy::BaseType *ty)
   {


[gcc/devel/rust/master] borrowck: Regions in BIR

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:da3a8fca377016e9387084e53753876eec9f384c

commit da3a8fca377016e9387084e53753876eec9f384c
Author: Jakub Dupak 
Date:   Tue Feb 27 23:01:14 2024 +0100

borrowck: Regions in BIR

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-place.h (struct Lifetime):
Extended regions and loans.
(struct Loan): Representation of loan (result of borrowing)
* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc 
(ExprStmtBuilder::visit):
Fix let stmt handling.
* checks/errors/borrowck/rust-bir-builder-pattern.h: improved
pattern translation
* checks/errors/borrowck/rust-bir-builder-internal.h: region binding
* checks/errors/borrowck/rust-bir-builder-expr-stmt.h (class 
ExprStmtBuilder):
Region support.
(class RenumberCtx): Region support.
* checks/errors/borrowck/rust-bir-builder.h (class Builder): Region 
support.
* checks/errors/borrowck/rust-bir-dump.cc (get_lifetime_name): 
Region support.
(renumber_places): Region support.
(Dump::go): Region support.
(Dump::visit): Region support.
(Dump::visit_lifetime): Region support.
(Dump::visit_scope): Region support.
* checks/errors/borrowck/rust-bir.h (class AbstractExpr): Region 
support.
(struct Function): Region support.
(class BorrowExpr): Region support.
(class CallExpr): Region support.

Signed-off-by: Jakub Dupak 

Diff:
---
 .../errors/borrowck/rust-bir-builder-expr-stmt.cc  |  73 ---
 .../errors/borrowck/rust-bir-builder-expr-stmt.h   |   7 +-
 .../errors/borrowck/rust-bir-builder-internal.h| 234 ++---
 .../errors/borrowck/rust-bir-builder-pattern.h | 154 --
 gcc/rust/checks/errors/borrowck/rust-bir-builder.h | 120 ---
 gcc/rust/checks/errors/borrowck/rust-bir-dump.cc   |  46 ++--
 gcc/rust/checks/errors/borrowck/rust-bir-place.h   | 202 +-
 gcc/rust/checks/errors/borrowck/rust-bir.h |  49 +++--
 8 files changed, 610 insertions(+), 275 deletions(-)

diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.cc 
b/gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.cc
index 922894cc5d50..d64641177d0e 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.cc
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.cc
@@ -93,8 +93,8 @@ ExprStmtBuilder::visit (HIR::ClosureExpr )
 void
 ExprStmtBuilder::visit (HIR::StructExprStructFields )
 {
-  auto struct_ty
-= lookup_type (fields)->as ()->get_variants ().at (0);
+  auto *p_adt_type = lookup_type (fields)->as ();
+  auto struct_ty = p_adt_type->get_variants ().at (0);
   auto init_values = StructBuilder (ctx, struct_ty).build (fields);
   move_all (init_values);
   return_expr (new InitializerExpr (std::move (init_values)),
@@ -119,7 +119,15 @@ void
 ExprStmtBuilder::visit (HIR::BorrowExpr )
 {
   auto operand = visit_expr (*expr.get_expr ());
-  return_expr (new BorrowExpr (operand), lookup_type (expr));
+  if (ctx.place_db[operand].is_constant ())
+{
+  // Cannot borrow a constant, must create a temporary copy.
+  push_tmp_assignment (operand);
+  operand = translated;
+}
+
+  // BorrowExpr cannot be annotated with lifetime.
+  return_borrowed (operand, lookup_type (expr));
 }
 
 void
@@ -183,6 +191,7 @@ ExprStmtBuilder::visit (HIR::AssignmentExpr )
   auto lhs = visit_expr (*expr.get_lhs ());
   auto rhs = visit_expr (*expr.get_rhs ());
   push_assignment (lhs, rhs);
+  translated = INVALID_PLACE;
 }
 
 void
@@ -265,6 +274,7 @@ ExprStmtBuilder::visit (HIR::CallExpr )
 }
 
   move_all (arguments);
+
   return_expr (new CallExpr (fn, std::move (arguments)), lookup_type (expr),
   true);
 }
@@ -346,7 +356,10 @@ ExprStmtBuilder::visit (HIR::BlockExpr )
  lookup_type (*block.get_final_expr ();
 }
 
-  pop_scope ();
+  if (!unreachable)
+pop_scope ();
+  else
+ctx.place_db.pop_scope ();
 }
 
 void
@@ -422,10 +435,12 @@ ExprStmtBuilder::visit (HIR::ReturnExpr )
 {
   if (ret.has_return_expr ())
 {
-  push_assignment (RETURN_VALUE_PLACE, visit_expr (*ret.get_expr ()));
+  push_assignment (RETURN_VALUE_PLACE,
+  move_place (visit_expr (*ret.get_expr (;
 }
   unwind_until (ROOT_SCOPE);
   ctx.get_current_bb ().statements.emplace_back (Statement::Kind::RETURN);
+  translated = INVALID_PLACE;
 }
 
 void
@@ -538,16 +553,19 @@ ExprStmtBuilder::visit (HIR::IfExprConseqElse )
   if (else_bb.is_goto_terminated () && else_bb.successors.empty ())
 add_jump (else_end_bb, final_start_bb);
 }
+
 void
 ExprStmtBuilder::visit (HIR::IfLetExpr )
 {
   rust_sorry_at (expr.get_locus (), "if let expressions are not supported");
 }
+
 void
 ExprStmtBuilder::visit (HIR::IfLetExprConseqElse )
 {
  

[gcc/devel/rust/master] nr2.0: Add new test cases.

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:db7d4991577ca94412a633613113bd14d9ce7a3e

commit db7d4991577ca94412a633613113bd14d9ce7a3e
Author: Arthur Cohen 
Date:   Wed Aug 23 17:19:28 2023 +0200

nr2.0: Add new test cases.

gcc/testsuite/ChangeLog:

* rust/compile/name_resolution13.rs: Add new module and remove 
compile
step.
* rust/compile/name_resolution14.rs: New test.
* rust/compile/name_resolution15.rs: New test.
* rust/compile/name_resolution16.rs: New test.
* rust/compile/name_resolution17.rs: New test.
* rust/compile/name_resolution18.rs: New test.
* rust/compile/name_resolution19.rs: New test.
* rust/compile/name_resolution20.rs: New test.
* rust/compile/name_resolution21.rs: New test.

Diff:
---
 gcc/testsuite/rust/compile/name_resolution13.rs |  6 +-
 gcc/testsuite/rust/compile/name_resolution14.rs | 15 +++
 gcc/testsuite/rust/compile/name_resolution15.rs | 20 
 gcc/testsuite/rust/compile/name_resolution16.rs | 18 ++
 gcc/testsuite/rust/compile/name_resolution17.rs | 10 ++
 gcc/testsuite/rust/compile/name_resolution18.rs | 15 +++
 gcc/testsuite/rust/compile/name_resolution19.rs | 20 
 gcc/testsuite/rust/compile/name_resolution20.rs | 11 +++
 gcc/testsuite/rust/compile/name_resolution21.rs | 12 
 9 files changed, 126 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/rust/compile/name_resolution13.rs 
b/gcc/testsuite/rust/compile/name_resolution13.rs
index 52a152bf51a5..33edbf9312e2 100644
--- a/gcc/testsuite/rust/compile/name_resolution13.rs
+++ b/gcc/testsuite/rust/compile/name_resolution13.rs
@@ -1,4 +1,8 @@
-// { dg-additional-options "-frust-name-resolution-2.0 
-frust-compile-until=lowering" }
+// { dg-options "-frust-name-resolution-2.0" }
+
+pub mod foo {
+pub macro bar() {}
+}
 
 fn foo() {
 let b = 10;
diff --git a/gcc/testsuite/rust/compile/name_resolution14.rs 
b/gcc/testsuite/rust/compile/name_resolution14.rs
new file mode 100644
index ..eaef6a52f160
--- /dev/null
+++ b/gcc/testsuite/rust/compile/name_resolution14.rs
@@ -0,0 +1,15 @@
+// { dg-options "-frust-name-resolution-2.0" }
+
+pub mod foo {
+pub macro bar() {}
+}
+
+use foo::biz; // { dg-error "unresolved import .foo::biz. .E0433." }
+
+use foo::{bar, baz, biz};
+// { dg-error "unresolved import .foo::baz. .E0433." "" { target *-*-* } .-1 }
+// { dg-error "unresolved import .foo::biz. .E0433." "" { target *-*-* } .-2 }
+
+fn main() {
+bar!();
+}
diff --git a/gcc/testsuite/rust/compile/name_resolution15.rs 
b/gcc/testsuite/rust/compile/name_resolution15.rs
new file mode 100644
index ..45f38da768af
--- /dev/null
+++ b/gcc/testsuite/rust/compile/name_resolution15.rs
@@ -0,0 +1,20 @@
+// { dg-additional-options "-frust-name-resolution-2.0" }
+#![feature(decl_macro)]
+
+pub mod foo {
+pub struct Foo {
+pub a: i32,
+}
+pub fn Foo() {}
+pub macro Foo() {{}}
+}
+
+pub use foo::Foo;
+
+use self::Foo as Fo;
+
+fn main() {
+let _a = Fo();
+let _b = Fo { a: 15 };
+let _c = Fo!();
+}
diff --git a/gcc/testsuite/rust/compile/name_resolution16.rs 
b/gcc/testsuite/rust/compile/name_resolution16.rs
new file mode 100644
index ..230722ef819c
--- /dev/null
+++ b/gcc/testsuite/rust/compile/name_resolution16.rs
@@ -0,0 +1,18 @@
+// { dg-additional-options "-frust-name-resolution-2.0" }
+#![feature(decl_macro)]
+
+pub mod foo {
+pub struct Foo {
+pub a: i32,
+}
+pub fn Foo() {}
+pub macro Foo() {{}}
+}
+
+pub use foo::Foo;
+
+fn main() {
+let _a = Foo();
+let _b = Foo { a: 15 };
+let _c = Foo!();
+}
diff --git a/gcc/testsuite/rust/compile/name_resolution17.rs 
b/gcc/testsuite/rust/compile/name_resolution17.rs
new file mode 100644
index ..485947647a95
--- /dev/null
+++ b/gcc/testsuite/rust/compile/name_resolution17.rs
@@ -0,0 +1,10 @@
+// { dg-options "-frust-name-resolution-2.0" }
+
+struct Foo;
+fn Foo() {} // { dg-error ".Foo. defined multiple times" }
+
+struct Marker;
+struct Bar {
+a: Marker,
+}
+fn Bar() {} // ok, since `Bar` is not a value here
diff --git a/gcc/testsuite/rust/compile/name_resolution18.rs 
b/gcc/testsuite/rust/compile/name_resolution18.rs
new file mode 100644
index ..5940149d3bbf
--- /dev/null
+++ b/gcc/testsuite/rust/compile/name_resolution18.rs
@@ -0,0 +1,15 @@
+// { dg-options "-frust-name-resolution-2.0" }
+
+struct Marker;
+
+struct Foo {
+a: Marker,
+}
+
+pub mod foo {
+struct Foo {
+b: Marker,
+}
+}
+
+use foo::Foo; // { dg-error ".Foo. defined multiple times" }
diff --git a/gcc/testsuite/rust/compile/name_resolution19.rs 
b/gcc/testsuite/rust/compile/name_resolution19.rs
new file mode 100644
index ..9a2c84375c7a
--- /dev/null
+++ b/gcc/testsuite/rust/compile/name_resolution19.rs
@@ -0,0 +1,20 @@
+struct Marker;

[gcc/devel/rust/master] unify: Always coerce `!` to the target type.

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:fbf35de5dcf89706452513b2ce2926fe95b38daa

commit fbf35de5dcf89706452513b2ce2926fe95b38daa
Author: Arthur Cohen 
Date:   Wed Mar 6 16:19:46 2024 +0100

unify: Always coerce `!` to the target type.

Never can... never... exist, so it should always be coerced to the type
it is being matched against. This is useful for breaking off of a loop
from inside a match, or an if condition, for example.

gcc/rust/ChangeLog:

* typecheck/rust-unify.cc (UnifyRules::go): Always unify to `ltype` 
if
we are matching against a `Never` in `rtype`.
(UnifyRules::expect_never): Always unify to the expected type.

gcc/testsuite/ChangeLog:

* rust/compile/match-never-ltype.rs: New test.
* rust/compile/match-never-rtype.rs: New test.

Diff:
---
 gcc/rust/typecheck/rust-unify.cc| 36 -
 gcc/testsuite/rust/compile/match-never-ltype.rs | 17 
 gcc/testsuite/rust/compile/match-never-rtype.rs | 17 
 3 files changed, 45 insertions(+), 25 deletions(-)

diff --git a/gcc/rust/typecheck/rust-unify.cc b/gcc/rust/typecheck/rust-unify.cc
index 8b43380cc592..7d1042d8e63f 100644
--- a/gcc/rust/typecheck/rust-unify.cc
+++ b/gcc/rust/typecheck/rust-unify.cc
@@ -17,6 +17,7 @@
 // .
 
 #include "rust-unify.h"
+#include "rust-tyty.h"
 
 namespace Rust {
 namespace Resolver {
@@ -237,6 +238,15 @@ UnifyRules::go ()
}
 }
 
+  // The never type should always get coerced to the type it's being matched
+  // against, so in that case, ltype. This avoids doing the same check in all
+  // the `expect_*` functions.
+  // However, this does not work if we have an annoying ltype - like INFER.
+  // TODO: Is ltype == Infer the only special case here? What about 
projections?
+  // references?
+  if (rtype->get_kind () == TyTy::NEVER && ltype->get_kind () != TyTy::INFER)
+return ltype->clone ();
+
   switch (ltype->get_kind ())
 {
 case TyTy::INFER:
@@ -1536,32 +1546,8 @@ UnifyRules::expect_never (TyTy::NeverType *ltype, 
TyTy::BaseType *rtype)
   }
   break;
 
-case TyTy::NEVER:
+default:
   return rtype->clone ();
-
-case TyTy::PLACEHOLDER:
-case TyTy::PROJECTION:
-case TyTy::DYNAMIC:
-case TyTy::CLOSURE:
-case TyTy::SLICE:
-case TyTy::PARAM:
-case TyTy::POINTER:
-case TyTy::STR:
-case TyTy::ADT:
-case TyTy::REF:
-case TyTy::ARRAY:
-case TyTy::FNDEF:
-case TyTy::FNPTR:
-case TyTy::TUPLE:
-case TyTy::BOOL:
-case TyTy::CHAR:
-case TyTy::INT:
-case TyTy::UINT:
-case TyTy::FLOAT:
-case TyTy::USIZE:
-case TyTy::ISIZE:
-case TyTy::ERROR:
-  return new TyTy::ErrorType (0);
 }
   return new TyTy::ErrorType (0);
 }
diff --git a/gcc/testsuite/rust/compile/match-never-ltype.rs 
b/gcc/testsuite/rust/compile/match-never-ltype.rs
new file mode 100644
index ..6516ab3c1ea6
--- /dev/null
+++ b/gcc/testsuite/rust/compile/match-never-ltype.rs
@@ -0,0 +1,17 @@
+fn foo() {}
+
+enum Foo {
+A,
+B,
+}
+
+fn main() {
+let a = Foo::A;
+
+loop {
+match a {
+Foo::A => break,
+Foo::B => foo(),
+}
+}
+}
diff --git a/gcc/testsuite/rust/compile/match-never-rtype.rs 
b/gcc/testsuite/rust/compile/match-never-rtype.rs
new file mode 100644
index ..6e4e7638f671
--- /dev/null
+++ b/gcc/testsuite/rust/compile/match-never-rtype.rs
@@ -0,0 +1,17 @@
+fn foo() {}
+
+enum Foo {
+A,
+B,
+}
+
+fn main() {
+let a = Foo::A;
+
+loop {
+match a {
+Foo::B => foo(),
+Foo::A => break,
+}
+}
+}


[gcc/devel/rust/master] Reinject Self parameter in new resolver

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:f95ca338eccb99f0b14ae9484e9614b9cfb333e0

commit f95ca338eccb99f0b14ae9484e9614b9cfb333e0
Author: Pierre-Emmanuel Patry 
Date:   Wed Feb 7 12:51:28 2024 +0100

Reinject Self parameter in new resolver

The old resolver injected a Self generic parameter in order to help the
trait solver. This is clearly sketchy at best and should be fixed in
the future.

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Add
Self generic parameter injection and a warning.
* resolve/rust-toplevel-name-resolver-2.0.h: Add function prototype.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 .../resolve/rust-toplevel-name-resolver-2.0.cc | 23 ++
 gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h |  1 +
 2 files changed, 24 insertions(+)

diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc 
b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
index f65ec77331ce..80b142678b95 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
@@ -186,6 +186,29 @@ TopLevel::visit (AST::Module )
 Analysis::Mappings::get ()->insert_ast_module ();
 }
 
+void
+TopLevel::visit (AST::Trait )
+{
+  // FIXME: This Self injection is dodgy. It even lead to issues with metadata
+  // export in the past (#2349). We cannot tell appart injected parameters from
+  // regular ones. Dumping generic parameters highlights this Self in metadata,
+  // during debug or proc macro collection. This is clearly a hack.
+  //
+  // For now I'll keep it here in the new name resolver even if it should
+  // probably not be there. We need to find another way to solve this.
+  // Maybe an additional attribute to Trait ?
+  //
+  // From old resolver:
+   we need to inject an implicit self TypeParam here
+   FIXME: which location should be used for Rust::Identifier `Self`?
+  AST::TypeParam *implicit_self
+= new AST::TypeParam ({"Self"}, trait.get_locus ());
+  trait.insert_implict_self (
+std::unique_ptr (implicit_self));
+
+  DefaultResolver::visit (trait);
+}
+
 template 
 static void
 insert_macros (std::vector , NameResolutionContext )
diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h 
b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h
index f5e224fa0499..e226c79dfbcd 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h
@@ -88,6 +88,7 @@ private:
   std::unordered_map node_forwarding;
 
   void visit (AST::Module ) override;
+  void visit (AST::Trait ) override;
   void visit (AST::MacroRulesDefinition ) override;
   void visit (AST::Function ) override;
   void visit (AST::BlockExpr ) override;


[gcc/devel/rust/master] borrowck: extract regions from types using VA

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:a019aa9fbde5ab752044fb7efe276aa0dde8646d

commit a019aa9fbde5ab752044fb7efe276aa0dde8646d
Author: Jakub Dupak 
Date:   Tue Feb 27 21:31:07 2024 +0100

borrowck: extract regions from types using VA

Biggybag on variance analysis to extract regions of fields from ADT
regions.

gcc/rust/ChangeLog:

* typecheck/rust-tyty-variance-analysis-private.h (class 
FieldVisitorCtx):
Region extraction.
* typecheck/rust-tyty-variance-analysis.cc (query_field_regions): 
Region extraction.
(FieldVisitorCtx::collect_regions): Region extraction.
(FieldVisitorCtx::add_constraints_from_ty): Region extraction.
(FieldVisitorCtx::add_constraints_from_region): Region
extraction.
(FieldVisitorCtx::add_constrints_from_param): Region extraction.
* typecheck/rust-tyty-variance-analysis.h (query_field_regions):
Region extraction.

Signed-off-by: Jakub Dupak 

Diff:
---
 .../rust-tyty-variance-analysis-private.h  | 41 ++
 gcc/rust/typecheck/rust-tyty-variance-analysis.cc  | 87 +-
 gcc/rust/typecheck/rust-tyty-variance-analysis.h   | 31 
 3 files changed, 140 insertions(+), 19 deletions(-)

diff --git a/gcc/rust/typecheck/rust-tyty-variance-analysis-private.h 
b/gcc/rust/typecheck/rust-tyty-variance-analysis-private.h
index ab8c039238eb..41a0d6f582fd 100644
--- a/gcc/rust/typecheck/rust-tyty-variance-analysis-private.h
+++ b/gcc/rust/typecheck/rust-tyty-variance-analysis-private.h
@@ -201,6 +201,13 @@ public: // Module internal API
 
   std::vector query_generic_variance (const ADTType );
 
+  std::vector query_field_regions (const ADTType *parent,
+  size_t variant_index,
+  size_t field_index,
+  const FreeRegions _regions);
+
+  std::vector query_type_regions (BaseType *base);
+
 public: // Data used by visitors.
   // This whole class is private, therfore members can be public.
 
@@ -296,6 +303,40 @@ private:
   std::vector regions;
 };
 
+/** Extracts regions of a field from regions of parent ADT. */
+class FieldVisitorCtx : public VarianceVisitorCtx
+{
+public:
+  using Visitor = VisitorBase;
+
+  std::vector collect_regions (BaseType );
+
+  FieldVisitorCtx (GenericTyPerCrateCtx , const SubstitutionRef ,
+  const FreeRegions _regions)
+: ctx (ctx), subst (subst), parent_regions (parent_regions)
+  {}
+
+  void add_constraints_from_ty (BaseType *ty, Variance variance) override;
+  void add_constraints_from_region (const Region ,
+   Variance variance) override;
+  void add_constraints_from_generic_args (HirId ref, SubstitutionRef ,
+ Variance variance,
+ bool invariant_args) override{};
+  void add_constrints_from_param (ParamType , Variance variance) 
override;
+
+  Variance contra (Variance variance) override
+  {
+return Variance::transform (variance, Variance::contravariant ());
+  }
+
+private:
+  GenericTyPerCrateCtx 
+  const SubstitutionRef 
+  std::vector regions;
+  FreeRegions parent_regions;
+  std::vector type_param_ranges;
+};
+
 } // namespace VarianceAnalysis
 
 } // namespace TyTy
diff --git a/gcc/rust/typecheck/rust-tyty-variance-analysis.cc 
b/gcc/rust/typecheck/rust-tyty-variance-analysis.cc
index 5a21d69651b0..d7116f5eb807 100644
--- a/gcc/rust/typecheck/rust-tyty-variance-analysis.cc
+++ b/gcc/rust/typecheck/rust-tyty-variance-analysis.cc
@@ -49,8 +49,16 @@ CrateCtx::query_type_variances (BaseType *type)
 std::vector
 CrateCtx::query_type_regions (BaseType *type)
 {
-  TyVisitorCtx ctx (*private_ctx);
-  return ctx.collect_regions (*type);
+  return private_ctx->query_type_regions (type);
+}
+
+std::vector
+CrateCtx::query_field_regions (const ADTType *parent, size_t variant_index,
+  size_t field_index,
+  const FreeRegions _regions)
+{
+  return private_ctx->query_field_regions (parent, variant_index, field_index,
+  parent_regions);
 }
 
 Variance
@@ -324,6 +332,29 @@ GenericTyPerCrateCtx::query_generic_variance (const 
ADTType )
   return result;
 }
 
+std::vector
+GenericTyPerCrateCtx::query_field_regions (const ADTType *parent,
+  size_t variant_index,
+  size_t field_index,
+  const FreeRegions _regions)
+{
+  auto orig = lookup_type (parent->get_orig_ref ());
+  FieldVisitorCtx ctx (*this, *parent->as (),
+  parent_regions);
+  return ctx.collect_regions (*orig->as ()
+->get_variants ()
+.at (variant_index)
+   

[gcc/devel/rust/master] Recognize unstable as a builtin attribute

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:fd621e11334faecd220b8d1e3e8e2fc18d55d0e7

commit fd621e11334faecd220b8d1e3e8e2fc18d55d0e7
Author: Owen Avery 
Date:   Tue Mar 26 19:28:53 2024 -0400

Recognize unstable as a builtin attribute

gcc/rust/ChangeLog:

* util/rust-attribute-values.h
(Attributes::UNSTABLE): New.
* util/rust-attributes.cc
(__definitions): Add Attributes::UNSTABLE.

gcc/testsuite/ChangeLog:

* rust/compile/unstable-fn.rs: New test.

Signed-off-by: Owen Avery 

Diff:
---
 gcc/rust/util/rust-attribute-values.h | 1 +
 gcc/rust/util/rust-attributes.cc  | 3 ++-
 gcc/testsuite/rust/compile/unstable-fn.rs | 2 ++
 3 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/util/rust-attribute-values.h 
b/gcc/rust/util/rust-attribute-values.h
index 04aef99be68f..a8551c07dba6 100644
--- a/gcc/rust/util/rust-attribute-values.h
+++ b/gcc/rust/util/rust-attribute-values.h
@@ -52,6 +52,7 @@ public:
   static constexpr auto _INHERIT_OVERFLOW_CHECKS
 = "rustc_inherit_overflow_checks";
   static constexpr auto  = "stable";
+  static constexpr auto  = "unstable";
 };
 } // namespace Values
 } // namespace Rust
diff --git a/gcc/rust/util/rust-attributes.cc b/gcc/rust/util/rust-attributes.cc
index e10918b2f8d0..84d1781d0b36 100644
--- a/gcc/rust/util/rust-attributes.cc
+++ b/gcc/rust/util/rust-attributes.cc
@@ -60,7 +60,8 @@ static const BuiltinAttrDefinition __definitions[]
  // #![feature(rustc_attrs)]
  {Attrs::RUSTC_DEPRECATED, STATIC_ANALYSIS},
  {Attrs::RUSTC_INHERIT_OVERFLOW_CHECKS, CODE_GENERATION},
- {Attrs::STABLE, STATIC_ANALYSIS}};
+ {Attrs::STABLE, STATIC_ANALYSIS},
+ {Attrs::UNSTABLE, STATIC_ANALYSIS}};
 
 BuiltinAttributeMappings *
 BuiltinAttributeMappings::get ()
diff --git a/gcc/testsuite/rust/compile/unstable-fn.rs 
b/gcc/testsuite/rust/compile/unstable-fn.rs
new file mode 100644
index ..4cbbebdb50e0
--- /dev/null
+++ b/gcc/testsuite/rust/compile/unstable-fn.rs
@@ -0,0 +1,2 @@
+#[unstable(feature = "some_feature", issue = "12345")]
+pub fn foo() {}


[gcc/devel/rust/master] Add name resolution for on globbing use decl

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:f8a6a624097e701f09912198da1a6735eac514ab

commit f8a6a624097e701f09912198da1a6735eac514ab
Author: Pierre-Emmanuel Patry 
Date:   Tue Jan 9 13:51:35 2024 +0100

Add name resolution for on globbing use decl

This is the first part of the code required to enable globbing on use
declarations.

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc 
(GlobbingVisitor::visit):
Insert names into their namespace.
(TopLevel::visit): Insert ast module.
(TopLevel::handle_use_dec): Resolve use declaration.
(TopLevel::handle_use_glob): Use globbing visitor.
(flatten_list): Use globbing path vector.
(flatten_glob): Likewise.
(flatten): Likewise.
(prefix_subpaths): Add a function to prefix subpath.
* resolve/rust-toplevel-name-resolver-2.0.h (class GlobbingVisitor):
Add globbing visitor.
* util/rust-hir-map.cc (Mappings::insert_ast_module): Add function 
to
insert module in module hashmap.
(Mappings::lookup_ast_module): Add function to retrieve ast module.
* util/rust-hir-map.h: Add module map and getter/setter prototypes.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 .../resolve/rust-toplevel-name-resolver-2.0.cc | 179 ++---
 gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h |  23 +++
 gcc/rust/util/rust-hir-map.cc  |  19 +++
 gcc/rust/util/rust-hir-map.h   |   3 +
 4 files changed, 199 insertions(+), 25 deletions(-)

diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc 
b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
index 5e6f5e9bd78a..3122d41412f7 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
@@ -25,6 +25,87 @@
 namespace Rust {
 namespace Resolver2_0 {
 
+void
+GlobbingVisitor::visit (AST::Module )
+{
+  if (module.get_visibility ().is_public ())
+ctx.insert (module.get_name (), module.get_node_id (), Namespace::Types);
+}
+
+void
+GlobbingVisitor::visit (AST::MacroRulesDefinition )
+{
+  if (macro.get_visibility ().is_public ())
+ctx.insert (macro.get_rule_name (), macro.get_node_id (),
+   Namespace::Macros);
+}
+
+void
+GlobbingVisitor::visit (AST::Function )
+{
+  if (function.get_visibility ().is_public ())
+ctx.insert (function.get_function_name (), function.get_node_id (),
+   Namespace::Values);
+}
+
+void
+GlobbingVisitor::visit (AST::StaticItem _item)
+{
+  if (static_item.get_visibility ().is_public ())
+ctx.insert (static_item.get_identifier (), static_item.get_node_id (),
+   Namespace::Values);
+}
+
+void
+GlobbingVisitor::visit (AST::StructStruct _item)
+{
+  if (struct_item.get_visibility ().is_public ())
+ctx.insert (struct_item.get_identifier (), struct_item.get_node_id (),
+   Namespace::Values);
+}
+
+void
+GlobbingVisitor::visit (AST::TupleStruct _struct)
+{
+  if (tuple_struct.get_visibility ().is_public ())
+ctx.insert (tuple_struct.get_identifier (), tuple_struct.get_node_id (),
+   Namespace::Values);
+}
+
+void
+GlobbingVisitor::visit (AST::Enum _item)
+{
+  if (enum_item.get_visibility ().is_public ())
+ctx.insert (enum_item.get_identifier (), enum_item.get_node_id (),
+   Namespace::Values);
+}
+
+void
+GlobbingVisitor::visit (AST::Union _item)
+{
+  if (union_item.get_visibility ().is_public ())
+ctx.insert (union_item.get_identifier (), union_item.get_node_id (),
+   Namespace::Values);
+}
+
+void
+GlobbingVisitor::visit (AST::ConstantItem _item)
+{
+  if (const_item.get_visibility ().is_public ())
+ctx.insert (const_item.get_identifier (), const_item.get_node_id (),
+   Namespace::Values);
+}
+
+void
+GlobbingVisitor::visit (AST::ExternCrate )
+{}
+
+void
+GlobbingVisitor::visit (AST::UseDeclaration )
+{
+  // Handle cycles ?
+}
+
 TopLevel::TopLevel (NameResolutionContext )
   : DefaultResolver (resolver)
 {}
@@ -81,6 +162,10 @@ TopLevel::visit (AST::Module )
 
   ctx.scoped (Rib::Kind::Module, module.get_node_id (), sub_visitor,
  module.get_name ());
+
+  if (Analysis::Mappings::get ()->lookup_ast_module (module.get_node_id ())
+  == tl::nullopt)
+Analysis::Mappings::get ()->insert_ast_module ();
 }
 
 template 
@@ -302,13 +387,26 @@ TopLevel::visit (AST::ConstantItem _item)
 }
 
 bool
-TopLevel::handle_use_dec (AST::SimplePath path)
+TopLevel::handle_use_glob (AST::SimplePath glob)
 {
-  // TODO: Glob imports can get shadowed by regular imports and regular items.
-  // So we need to store them in a specific way in the ForeverStack - which can
-  // also probably be used by labels and macros etc. Like store it as a
-  // `Shadowable(NodeId)` instead of just a `NodeId`
+  auto resolved = ctx.types.resolve_path (glob.get_segments 

[gcc/devel/rust/master] Raw pointer type visitor didn't require overload

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:82c7199a15109b80fcb9c9b962614d5f4ecb4693

commit 82c7199a15109b80fcb9c9b962614d5f4ecb4693
Author: Pierre-Emmanuel Patry 
Date:   Wed Jan 24 16:57:37 2024 +0100

Raw pointer type visitor didn't require overload

This overload did not dispatch the visitor to sub members of a raw
pointer like the default one. It is therefore useless as pointed type
shall be visited to be resolved correctly.

gcc/rust/ChangeLog:

* resolve/rust-default-resolver.cc (DefaultResolver::visit): Remove
function implementation.
* resolve/rust-default-resolver.h: Remove function prototype.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/resolve/rust-default-resolver.cc | 4 
 gcc/rust/resolve/rust-default-resolver.h  | 1 -
 2 files changed, 5 deletions(-)

diff --git a/gcc/rust/resolve/rust-default-resolver.cc 
b/gcc/rust/resolve/rust-default-resolver.cc
index 0c2576f6e755..f5546181b3c6 100644
--- a/gcc/rust/resolve/rust-default-resolver.cc
+++ b/gcc/rust/resolve/rust-default-resolver.cc
@@ -630,10 +630,6 @@ void
 DefaultResolver::visit (AST::TupleType &)
 {}
 
-void
-DefaultResolver::visit (AST::RawPointerType &)
-{}
-
 void
 DefaultResolver::visit (AST::ReferenceType &)
 {}
diff --git a/gcc/rust/resolve/rust-default-resolver.h 
b/gcc/rust/resolve/rust-default-resolver.h
index 97ad6d78be33..a19d70bc04d9 100644
--- a/gcc/rust/resolve/rust-default-resolver.h
+++ b/gcc/rust/resolve/rust-default-resolver.h
@@ -151,7 +151,6 @@ public:
   void visit (AST::ImplTraitTypeOneBound &);
   void visit (AST::TraitObjectTypeOneBound &);
   void visit (AST::TupleType &);
-  void visit (AST::RawPointerType &);
   void visit (AST::ReferenceType &);
   void visit (AST::ArrayType &);
   void visit (AST::SliceType &);


[gcc/devel/rust/master] Add modules to type namespace

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:c9ac90ba4fd43bbede8d14584cd71a0a84a1d02c

commit c9ac90ba4fd43bbede8d14584cd71a0a84a1d02c
Author: Pierre-Emmanuel Patry 
Date:   Mon Jan 8 15:18:36 2024 +0100

Add modules to type namespace

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): 
Module
should be added to the type namespace in order to be retrieved 
later.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc 
b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
index 3b1ccc1d3c50..5e6f5e9bd78a 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
@@ -72,7 +72,7 @@ TopLevel::go (AST::Crate )
 void
 TopLevel::visit (AST::Module )
 {
-  // FIXME: Do we need to insert the module in the type namespace?
+  insert_or_error_out (module.get_name (), module, Namespace::Types);
 
   auto sub_visitor = [this, ] () {
 for (auto  : module.get_items ())


[gcc/devel/rust/master] Change dfs function return type to support gcc 4.8

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:65f283df777fd05b5e45d054e457b271d12ec2dc

commit 65f283df777fd05b5e45d054e457b271d12ec2dc
Author: Pierre-Emmanuel Patry 
Date:   Tue Mar 26 16:32:31 2024 +0100

Change dfs function return type to support gcc 4.8

GCC 4.8 does not handle pair with references correctly. We need to use a
properly typed struct instead.

gcc/rust/ChangeLog:

* resolve/rust-forever-stack.h: Change dfs function prototype and
declare dfs return type structure.
* resolve/rust-forever-stack.hxx: Adapt dfs function to the new 
return
type.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/resolve/rust-forever-stack.h   | 8 ++--
 gcc/rust/resolve/rust-forever-stack.hxx | 4 ++--
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/gcc/rust/resolve/rust-forever-stack.h 
b/gcc/rust/resolve/rust-forever-stack.h
index 3dab45e7e779..72b96bff3b3f 100644
--- a/gcc/rust/resolve/rust-forever-stack.h
+++ b/gcc/rust/resolve/rust-forever-stack.h
@@ -596,10 +596,14 @@ private:
 SegIterator iterator);
 
   /* Helper functions for forward resolution (to_canonical_path, to_rib...) */
+  struct DfsResult
+  {
+Node 
+std::string second;
+  };
 
   // FIXME: Documentation
-  tl::optional> dfs (Node _point,
-   NodeId to_find);
+  tl::optional dfs (Node _point, NodeId to_find);
   // FIXME: Documentation
   tl::optional dfs_rib (Node _point, NodeId to_find);
 };
diff --git a/gcc/rust/resolve/rust-forever-stack.hxx 
b/gcc/rust/resolve/rust-forever-stack.hxx
index 6b622b8aef1e..2c3cba594484 100644
--- a/gcc/rust/resolve/rust-forever-stack.hxx
+++ b/gcc/rust/resolve/rust-forever-stack.hxx
@@ -468,7 +468,7 @@ ForeverStack::resolve_path (const std::vector 
)
 }
 
 template 
-tl::optional::Node &, std::string>>
+tl::optional::DfsResult>
 ForeverStack::dfs (ForeverStack::Node _point, NodeId to_find)
 {
   auto values = starting_point.rib.get_values ();
@@ -498,7 +498,7 @@ ForeverStack::to_canonical_path (NodeId id)
   // back up to the root (parent().parent().parent()...) accumulate link
   // segments reverse them that's your canonical path
 
-  return dfs (root, id).map ([this, id] (std::pair tuple) 
{
+  return dfs (root, id).map ([this, id] (DfsResult tuple) {
 auto containing_node = tuple.first;
 auto name = tuple.second;


[gcc/devel/rust/master] Add tuple struct constructor to value namespace

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:4c40ba4bb28b83061f3963f806d26f0599497f93

commit 4c40ba4bb28b83061f3963f806d26f0599497f93
Author: Pierre-Emmanuel Patry 
Date:   Wed Jan 17 13:02:51 2024 +0100

Add tuple struct constructor to value namespace

A tuple struct constructor should be inserted in the value namespace
during name resolution in order to reject multiple definitions of the
function.

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Add
the struct constructor to the value namespace.

gcc/testsuite/ChangeLog:

* rust/compile/name_resolution22.rs: New test.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc | 3 +++
 gcc/testsuite/rust/compile/name_resolution22.rs | 5 +
 2 files changed, 8 insertions(+)

diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc 
b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
index 6929bdb641e6..4134b9a46202 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
@@ -337,6 +337,9 @@ TopLevel::visit (AST::TupleStruct _struct)
 {
   insert_or_error_out (tuple_struct.get_struct_name (), tuple_struct,
   Namespace::Types);
+
+  insert_or_error_out (tuple_struct.get_struct_name (), tuple_struct,
+  Namespace::Values);
 }
 
 void
diff --git a/gcc/testsuite/rust/compile/name_resolution22.rs 
b/gcc/testsuite/rust/compile/name_resolution22.rs
new file mode 100644
index ..c49331ef38cd
--- /dev/null
+++ b/gcc/testsuite/rust/compile/name_resolution22.rs
@@ -0,0 +1,5 @@
+// { dg-options "-frust-name-resolution-2.0" }
+struct Marker;
+struct Foo(Marker);
+
+fn Foo(m: Marker) {} // { dg-error ".Foo. defined multiple times" }


[gcc/devel/rust/master] Change error message on unresolved import

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:73901b2b89baa60de6155000f042097ee72a13cd

commit 73901b2b89baa60de6155000f042097ee72a13cd
Author: Pierre-Emmanuel Patry 
Date:   Sun Mar 24 22:23:03 2024 +0100

Change error message on unresolved import

The error message did not match rustc's.

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): 
Change
error message.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc 
b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
index 94cc3cb62d94..72c3560b9daf 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
@@ -478,8 +478,7 @@ TopLevel::visit (AST::UseDeclaration )
   for (auto  : paths)
 if (!handle_use_dec (path))
   rust_error_at (path.get_final_segment ().get_locus (), ErrorCode::E0433,
-"could not resolve import %qs",
-path.as_string ().c_str ());
+"unresolved import %qs", path.as_string ().c_str ());
 }
 
 } // namespace Resolver2_0


[gcc/devel/rust/master] Remove unsafe block empty visit function

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:c14e44a53c10a8bcd3fbe87c243ac65ea5aa813b

commit c14e44a53c10a8bcd3fbe87c243ac65ea5aa813b
Author: Pierre-Emmanuel Patry 
Date:   Tue Feb 6 15:13:17 2024 +0100

Remove unsafe block empty visit function

We need to visit subcomponents in unsafe elements, this means we can
leverage the default ast visitor's code instead of duplicating it.

gcc/rust/ChangeLog:

* resolve/rust-default-resolver.cc (DefaultResolver::visit): Remove
empty visit function.
* resolve/rust-default-resolver.h: Remove function prototype.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/resolve/rust-default-resolver.cc | 4 
 gcc/rust/resolve/rust-default-resolver.h  | 1 -
 2 files changed, 5 deletions(-)

diff --git a/gcc/rust/resolve/rust-default-resolver.cc 
b/gcc/rust/resolve/rust-default-resolver.cc
index 291731be5b36..393994808ee0 100644
--- a/gcc/rust/resolve/rust-default-resolver.cc
+++ b/gcc/rust/resolve/rust-default-resolver.cc
@@ -235,10 +235,6 @@ void
 DefaultResolver::visit (AST::ReturnExpr )
 {}
 
-void
-DefaultResolver::visit (AST::UnsafeBlockExpr )
-{}
-
 void
 DefaultResolver::visit (AST::LoopExpr )
 {}
diff --git a/gcc/rust/resolve/rust-default-resolver.h 
b/gcc/rust/resolve/rust-default-resolver.h
index 0a6427ca6a61..547b5376bfc8 100644
--- a/gcc/rust/resolve/rust-default-resolver.h
+++ b/gcc/rust/resolve/rust-default-resolver.h
@@ -66,7 +66,6 @@ public:
   void visit (AST::RangeFromToInclExpr &);
   void visit (AST::RangeToInclExpr &);
   void visit (AST::ReturnExpr &);
-  void visit (AST::UnsafeBlockExpr &);
   void visit (AST::LoopExpr &);
   void visit (AST::WhileLoopExpr &);
   void visit (AST::WhileLetLoopExpr &);


[gcc/devel/rust/master] Add call to globbing visitor

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:8c771ad54e22b98551515f961844fc25b1a3944a

commit 8c771ad54e22b98551515f961844fc25b1a3944a
Author: Pierre-Emmanuel Patry 
Date:   Mon Jan 15 13:41:01 2024 +0100

Add call to globbing visitor

Globbing visitor did not visit subitems.

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Add a check
for missing item.
* resolve/rust-toplevel-name-resolver-2.0.cc (GlobbingVisitor::go):
Add a new function in the visitor to dispatch the visitor to items 
in
the given module.
(TopLevel::handle_use_glob): Change call to visitor to use the 
pointer.
* resolve/rust-toplevel-name-resolver-2.0.h: Add prototype for new
member function.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/resolve/rust-late-name-resolver-2.0.cc | 2 ++
 gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc | 9 -
 gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h  | 1 +
 3 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc 
b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
index 68eb88a1e4c9..d8bd9ac524f3 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
@@ -197,6 +197,8 @@ Late::visit (AST::PathInExpression )
   // do we emit it in `get`?
 
   auto value = ctx.values.resolve_path (expr.get_segments ());
+  if (!value.has_value ())
+rust_unreachable (); // Should have been resolved earlier
 
   ctx.map_usage (Usage (expr.get_node_id ()), Definition (*value));
 }
diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc 
b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
index 3122d41412f7..501204174f22 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
@@ -25,6 +25,13 @@
 namespace Rust {
 namespace Resolver2_0 {
 
+void
+GlobbingVisitor::go (AST::Module *module)
+{
+  for (auto  : module->get_items ())
+visit (i);
+}
+
 void
 GlobbingVisitor::visit (AST::Module )
 {
@@ -399,7 +406,7 @@ TopLevel::handle_use_glob (AST::SimplePath glob)
 return false;
 
   GlobbingVisitor gvisitor (ctx);
-  gvisitor.visit (*result.value ());
+  gvisitor.go (result.value ());
 
   return true;
 }
diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h 
b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h
index 31535a9b22e0..f5e224fa0499 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h
@@ -33,6 +33,7 @@ class GlobbingVisitor : public AST::DefaultASTVisitor
 public:
   GlobbingVisitor (NameResolutionContext ) : ctx (ctx) {}
 
+  void go (AST::Module *module);
   void visit (AST::Module ) override;
   void visit (AST::MacroRulesDefinition ) override;
   void visit (AST::Function ) override;


[gcc/devel/rust/master] Emit error on identical use declarations

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:8a5a1b4d61179b5af345e6765bd933a6af1243b3

commit 8a5a1b4d61179b5af345e6765bd933a6af1243b3
Author: Pierre-Emmanuel Patry 
Date:   Fri Sep 15 13:14:56 2023 +0200

Emit error on identical use declarations

The compiler did not emit any warning when a same target was declared
from different sources.

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc 
(TopLevel::handle_use_dec):
Use the new dict to track down already resolved use declarations.
* resolve/rust-toplevel-name-resolver-2.0.h: Add new dict to store
previous use declarations.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 .../resolve/rust-toplevel-name-resolver-2.0.cc | 76 --
 gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h |  4 ++
 2 files changed, 46 insertions(+), 34 deletions(-)

diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc 
b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
index 407892bb7bbd..94cc3cb62d94 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
@@ -319,40 +319,48 @@ TopLevel::handle_use_dec (AST::SimplePath path)
 
   auto found = false;
 
-  auto resolve_and_insert = [this, , _name,
-locus] (Namespace ns,
-const AST::SimplePath ) {
-tl::optional resolved = tl::nullopt;
-
-// FIXME: resolve_path needs to return an `expected` so
-// that we can improve it with hints or location or w/ever. and maybe
-// only emit it the first time.
-switch (ns)
-  {
-  case Namespace::Values:
-   resolved = ctx.values.resolve_path (path.get_segments ());
-   break;
-  case Namespace::Types:
-   resolved = ctx.types.resolve_path (path.get_segments ());
-   break;
-  case Namespace::Macros:
-   resolved = ctx.macros.resolve_path (path.get_segments ());
-   break;
-  case Namespace::Labels:
-   // TODO: Is that okay?
-   rust_unreachable ();
-  }
-
-// FIXME: Ugly
-(void) resolved.map ([this, , _name, locus, ns] (NodeId id) 
{
-  found = true;
-
-  // what do we do with the id?
-  insert_or_error_out (declared_name, locus, id, ns);
-
-  return id;
-});
-  };
+  auto resolve_and_insert
+= [this, , _name, locus] (Namespace ns,
+const AST::SimplePath ) {
+   tl::optional resolved = tl::nullopt;
+
+   // FIXME: resolve_path needs to return an `expected` so
+   // that we can improve it with hints or location or w/ever. and maybe
+   // only emit it the first time.
+   switch (ns)
+ {
+ case Namespace::Values:
+   resolved = ctx.values.resolve_path (path.get_segments ());
+   break;
+ case Namespace::Types:
+   resolved = ctx.types.resolve_path (path.get_segments ());
+   break;
+ case Namespace::Macros:
+   resolved = ctx.macros.resolve_path (path.get_segments ());
+   break;
+ case Namespace::Labels:
+   // TODO: Is that okay?
+   rust_unreachable ();
+ }
+
+   // FIXME: Ugly
+   (void) resolved.map (
+ [this, , _name, locus, ns, path] (NodeId id) {
+   found = true;
+
+   // what do we do with the id?
+   insert_or_error_out (declared_name, locus, id, ns);
+   auto result = node_forwarding.find (id);
+   if (result != node_forwarding.cend ()
+   && result->second != path.get_node_id ())
+ rust_error_at (path.get_locus (), "%<%s%> defined multiple times",
+declared_name.c_str ());
+   else // No previous thing has inserted this into our scope
+ node_forwarding.insert ({id, path.get_node_id ()});
+
+   return id;
+ });
+  };
 
   // do this for all namespaces (even Labels?)
 
diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h 
b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h
index ac11f3103708..0a766bab2598 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h
@@ -60,6 +60,10 @@ private:
   // FIXME: Do we move these to our mappings?
   std::unordered_map node_locations;
 
+  // Store node forwarding for use declaration, the link between a
+  // "new" local name and its definition.
+  std::unordered_map node_forwarding;
+
   void visit (AST::Module ) override;
   void visit (AST::MacroRulesDefinition ) override;
   void visit (AST::Function ) override;


[gcc/devel/rust/master] Remove extern block scoping

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:2ad57d7229d1f06f7fe05a9f296725b7269f74d7

commit 2ad57d7229d1f06f7fe05a9f296725b7269f74d7
Author: Pierre-Emmanuel Patry 
Date:   Tue Feb 6 15:10:44 2024 +0100

Remove extern block scoping

Remove extern block scoping visit function, use the default visitor visit
function instead. We do not need scoping for extern block as their
element shall be visible from the extern block scope.

gcc/rust/ChangeLog:

* resolve/rust-default-resolver.cc (DefaultResolver::visit): Remove
visitor implementation and scoping.
* resolve/rust-default-resolver.h: Remove function prototype.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/resolve/rust-default-resolver.cc | 12 
 gcc/rust/resolve/rust-default-resolver.h  |  1 -
 2 files changed, 13 deletions(-)

diff --git a/gcc/rust/resolve/rust-default-resolver.cc 
b/gcc/rust/resolve/rust-default-resolver.cc
index f5546181b3c6..291731be5b36 100644
--- a/gcc/rust/resolve/rust-default-resolver.cc
+++ b/gcc/rust/resolve/rust-default-resolver.cc
@@ -133,18 +133,6 @@ DefaultResolver::visit (AST::TraitImpl )
   ctx.scoped (Rib::Kind::TraitOrImpl, impl.get_node_id (), inner_fn);
 }
 
-void
-DefaultResolver::visit (AST::ExternBlock )
-{
-  auto inner_fn = [this, ] () {
-for (auto  : block.get_extern_items ())
-  item->accept_vis (*this);
-  };
-
-  ctx.scoped (Rib::Kind::Normal /* FIXME: Correct? */, block.get_node_id (),
- inner_fn);
-}
-
 void
 DefaultResolver::visit (AST::StructStruct )
 {
diff --git a/gcc/rust/resolve/rust-default-resolver.h 
b/gcc/rust/resolve/rust-default-resolver.h
index a19d70bc04d9..0a6427ca6a61 100644
--- a/gcc/rust/resolve/rust-default-resolver.h
+++ b/gcc/rust/resolve/rust-default-resolver.h
@@ -49,7 +49,6 @@ public:
   void visit (AST::Trait &);
   void visit (AST::InherentImpl &);
   void visit (AST::TraitImpl &);
-  void visit (AST::ExternBlock &);
 
   // type dec nodes, which visit their fields or variants by default
   void visit (AST::StructStruct &);


[gcc/devel/rust/master] Shape up name resolver for normal direct calls

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:1230910d4fc6f8ee8dcec84223d13fd4be812bdd

commit 1230910d4fc6f8ee8dcec84223d13fd4be812bdd
Author: Pierre-Emmanuel Patry 
Date:   Wed Jan 10 16:44:09 2024 +0100

Shape up name resolver for normal direct calls

Direct function calls did not work anymore due to the transition to the
new resolver.

gcc/rust/ChangeLog:

* checks/lints/rust-lint-marklive.cc (MarkLive::find_ref_node_id):
Add code path for the resolver 2.0
* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Remove 
failing
label context resolve call.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/checks/lints/rust-lint-marklive.cc | 23 +++
 gcc/rust/resolve/rust-late-name-resolver-2.0.cc |  3 ++-
 2 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/gcc/rust/checks/lints/rust-lint-marklive.cc 
b/gcc/rust/checks/lints/rust-lint-marklive.cc
index 8787a9d85502..1a0a0a2b904b 100644
--- a/gcc/rust/checks/lints/rust-lint-marklive.cc
+++ b/gcc/rust/checks/lints/rust-lint-marklive.cc
@@ -20,8 +20,10 @@
 // from live codes are live, and everything else is dead.
 
 #include "rust-lint-marklive.h"
+#include "options.h"
 #include "rust-hir-full.h"
 #include "rust-name-resolver.h"
+#include "rust-immutable-name-resolution-context.h"
 
 namespace Rust {
 namespace Analysis {
@@ -270,12 +272,25 @@ MarkLive::mark_hir_id (HirId id)
 void
 MarkLive::find_ref_node_id (NodeId ast_node_id, NodeId _node_id)
 {
-  if (!resolver->lookup_resolved_name (ast_node_id, _node_id))
+  if (flag_name_resolution_2_0)
 {
-  if (!resolver->lookup_resolved_type (ast_node_id, _node_id))
+  auto nr_ctx
+   = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+
+  nr_ctx.lookup (ast_node_id).map ([_node_id] (NodeId resolved) {
+   ref_node_id = resolved;
+  });
+}
+  else
+{
+  if (!resolver->lookup_resolved_name (ast_node_id, _node_id))
{
- bool ok = resolver->lookup_resolved_misc (ast_node_id, _node_id);
- rust_assert (ok);
+ if (!resolver->lookup_resolved_type (ast_node_id, _node_id))
+   {
+ bool ok
+   = resolver->lookup_resolved_misc (ast_node_id, _node_id);
+ rust_assert (ok);
+   }
}
 }
 }
diff --git a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc 
b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
index ee06c4efc2ea..68eb88a1e4c9 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
@@ -196,8 +196,9 @@ Late::visit (AST::PathInExpression )
   // in a function item` error here?
   // do we emit it in `get`?
 
-  auto label = ctx.labels.resolve_path (expr.get_segments ());
   auto value = ctx.values.resolve_path (expr.get_segments ());
+
+  ctx.map_usage (Usage (expr.get_node_id ()), Definition (*value));
 }
 
 void


[gcc/devel/rust/master] nr2.0: Add lookup of resolved nodes.

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:77a6a631b4b2421d0a7b7b8753b9d677ec611104

commit 77a6a631b4b2421d0a7b7b8753b9d677ec611104
Author: Arthur Cohen 
Date:   Thu Aug 24 17:51:11 2023 +0200

nr2.0: Add lookup of resolved nodes.

gcc/rust/ChangeLog:

* resolve/rust-name-resolution-context.cc 
(NameResolutionContext::lookup):
Add lookup function.
* resolve/rust-name-resolution-context.h: Include mappings and 
optional.

Diff:
---
 gcc/rust/resolve/rust-name-resolution-context.cc | 13 +
 gcc/rust/resolve/rust-name-resolution-context.h  |  3 +++
 2 files changed, 16 insertions(+)

diff --git a/gcc/rust/resolve/rust-name-resolution-context.cc 
b/gcc/rust/resolve/rust-name-resolution-context.cc
index f35db7e925e5..9fd8d52968a8 100644
--- a/gcc/rust/resolve/rust-name-resolution-context.cc
+++ b/gcc/rust/resolve/rust-name-resolution-context.cc
@@ -17,6 +17,8 @@
 // .
 
 #include "rust-name-resolution-context.h"
+#include "optional.h"
+#include "rust-mapping-common.h"
 
 namespace Rust {
 namespace Resolver2_0 {
@@ -52,6 +54,17 @@ NameResolutionContext::map_usage (NodeId usage, NodeId 
definition)
   rust_assert (inserted);
 }
 
+tl::optional
+NameResolutionContext::lookup (NodeId usage)
+{
+  auto it = resolved_nodes.find (usage);
+
+  if (it == resolved_nodes.end ())
+return tl::nullopt;
+
+  return it->second;
+}
+
 void
 NameResolutionContext::scoped (Rib rib, NodeId id,
   std::function lambda,
diff --git a/gcc/rust/resolve/rust-name-resolution-context.h 
b/gcc/rust/resolve/rust-name-resolution-context.h
index bc3c4bb5ddb7..e896ca053608 100644
--- a/gcc/rust/resolve/rust-name-resolution-context.h
+++ b/gcc/rust/resolve/rust-name-resolution-context.h
@@ -19,6 +19,7 @@
 #ifndef RUST_NAME_RESOLVER_2_0_H
 #define RUST_NAME_RESOLVER_2_0_H
 
+#include "optional.h"
 #include "rust-forever-stack.h"
 #include "rust-hir-map.h"
 
@@ -180,7 +181,9 @@ public:
   Analysis::Mappings 
 
   // TODO: Rename
+  // TODO: Use newtype pattern for Usage and Definition
   void map_usage (NodeId usage, NodeId definition);
+  tl::optional lookup (NodeId usage);
 
 private:
   /* Map of "usage" nodes which have been resolved to a "definition" node */


[gcc/devel/rust/master] Add constant identifiers to the value namespace

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:b0f27e8d81f241d66300a066ac6a133c6347ae4f

commit b0f27e8d81f241d66300a066ac6a133c6347ae4f
Author: Pierre-Emmanuel Patry 
Date:   Wed Jan 24 17:11:59 2024 +0100

Add constant identifiers to the value namespace

Constants could not be resolved without their identifier in the right
scope.

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Add
constant identifiers to the resolver.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc 
b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
index b672d448151a..f65ec77331ce 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
@@ -401,6 +401,9 @@ TopLevel::visit (AST::Union _item)
 void
 TopLevel::visit (AST::ConstantItem _item)
 {
+  insert_or_error_out (const_item.get_identifier (), const_item,
+  Namespace::Values);
+
   auto expr_vis
 = [this, _item] () { const_item.get_expr ().accept_vis (*this); };


[gcc/devel/rust/master] borrowck: Unify BIR terminilogy (node->statement)

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:02d788d14c763bbf4e439869d2a984f5d9aa4f9d

commit 02d788d14c763bbf4e439869d2a984f5d9aa4f9d
Author: Jakub Dupak 
Date:   Sat Nov 4 16:52:27 2023 +0100

borrowck: Unify BIR terminilogy (node->statement)

gcc/rust/ChangeLog:

* checks/errors/borrowck/bir-design-notes.md (nodes): Rename node 
to statement.
(Nodes): Rename node to statement.
* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc 
(ExprStmtBuilder::visit):
Rename node to statement.
* checks/errors/borrowck/rust-bir-builder-internal.h: Rename node 
to statement.
* checks/errors/borrowck/rust-bir-builder.h: Rename node to 
statement.
* checks/errors/borrowck/rust-bir-dump.cc (Dump::go): Rename node 
to statement.
(Dump::visit): Rename node to statement.
* checks/errors/borrowck/rust-bir-dump.h (class Dump): Rename node 
to statement.
* checks/errors/borrowck/rust-bir-visitor.h (class Node): Rename 
node to statement.
(class Statement): Rename node to statement.
* checks/errors/borrowck/rust-bir.h (class Node): Rename node to 
statement.
(class Statement): Rename node to statement.
(class AbstractExpr): Rename node to statement.
(struct Function): Rename node to statement.
(struct BasicBlock): Rename node to statement.

Signed-off-by: Jakub Dupak 

Diff:
---
 .../checks/errors/borrowck/bir-design-notes.md | 13 +++---
 .../errors/borrowck/rust-bir-builder-expr-stmt.cc  |  2 +-
 .../errors/borrowck/rust-bir-builder-internal.h|  7 +--
 gcc/rust/checks/errors/borrowck/rust-bir-builder.h |  4 +-
 gcc/rust/checks/errors/borrowck/rust-bir-dump.cc   | 51 +++---
 gcc/rust/checks/errors/borrowck/rust-bir-dump.h|  6 +--
 gcc/rust/checks/errors/borrowck/rust-bir-visitor.h |  4 +-
 gcc/rust/checks/errors/borrowck/rust-bir.h | 34 +++
 8 files changed, 62 insertions(+), 59 deletions(-)

diff --git a/gcc/rust/checks/errors/borrowck/bir-design-notes.md 
b/gcc/rust/checks/errors/borrowck/bir-design-notes.md
index ad622cd72285..e2edc20ffa8b 100644
--- a/gcc/rust/checks/errors/borrowck/bir-design-notes.md
+++ b/gcc/rust/checks/errors/borrowck/bir-design-notes.md
@@ -108,7 +108,7 @@ The dump consists of:
 - Declaration of locals: `let _0: i32;`, where `_0` is the return value (even 
if it is of the unit type). Arguments are not listed here, they are
   listed in the function header.
 - A list of basic blocks: `bb0: { ... }`. The basic block name is the `bb` 
prefix followed by a number.
-- Each basic block consists of a list of BIR nodes (instructions). Instruction 
can be either assigned to a local (place) or be a statement.
+- Each basic block consists of a list of BIR statements. Instruction can be 
either assigned to a local (place) or be a statement.
   Instructions take locals (places) as arguments.
 - Each basic block is terminated with a control flow instruction followed by a 
list of destinations:
 - `goto -> bb3;` - a goto instruction with a single destination.
@@ -126,16 +126,17 @@ of basic blocks, list of arguments (for dump only) and 
place database, which kee
 
 ### Basic Blocks
 
-A basic block is identified by its index in the function's basic block list. 
It contains a list of BIR nodes (instructions) and a list of successor
+A basic block is identified by its index in the function's basic block list.
+It contains a list of BIR statements and a list of successor
 basic block indices in CFG.
 
-### BIR Nodes (Instructions)
+### BIR Statements
 
-BIR nodes are of three categories:
+BIR statements are of three categories:
 
 - An assignment of an expression to a local (place).
 - A control flow operation (switch, return).
-- A special node (not executable) node, which carries additional information 
for borrow-checking (`StorageDead`, `StorageLive`).
+- A special statement (not executable), which carries additional information 
for borrow-checking (`StorageDead`, `StorageLive`).
 
  Expressions
 
@@ -147,7 +148,7 @@ lifetime) flow needs to be tracked.
 - `Operator` represents any kind of operation, except the following, 
where special information is needed either for borrow-checking or for
   better debugging.
 - `BorrowExpr` represents a borrow operation.
-- `AssignmentExpr` holds a place for a node of assignment (i.e., no operation 
is done on the place, it is just assigned).
+- `AssignmentExpr` holds a place for an assignment statement (i.e., no 
operation is done on the place, it is just assigned).
 - `CallExpr` represents a function call.
 - For functions, the callable is represented by a constant place (see 
below). (E.i. all calls use the same constant place.)
 - For closures and function pointers, the callable is represented by a 
(non-constant) place.
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.cc 

[gcc/devel/rust/master] borrowck: Use rust-system.h

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:e06d74b8bff0aa91227976c615d942be23912943

commit e06d74b8bff0aa91227976c615d942be23912943
Author: Jakub Dupak 
Date:   Fri Mar 22 16:24:30 2024 +0100

borrowck: Use rust-system.h

Replace direct usage of system headers.

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-dump.cc: Use rust-system.h
* checks/errors/borrowck/rust-bir-dump.h (RUST_BIR_DUMP_H): Use 
rust-system.h
* checks/errors/borrowck/rust-bir-place.h (RUST_BIR_PLACE_H): Use 
rust-system.h
* checks/errors/borrowck/rust-function-collector.h: Use 
rust-system.h
* rust-system.h: Use rust-system.h
* typecheck/rust-hir-type-check.h: Use rust-system.h
* typecheck/rust-tyty-subst.cc: Use rust-system.h
* typecheck/rust-tyty-subst.h: Use rust-system.h
* typecheck/rust-tyty.h: Use rust-system.h

Signed-off-by: Jakub Dupak 

Diff:
---
 gcc/rust/checks/errors/borrowck/rust-bir-dump.cc  | 2 +-
 gcc/rust/checks/errors/borrowck/rust-bir-dump.h   | 3 +--
 gcc/rust/checks/errors/borrowck/rust-bir-place.h  | 1 -
 gcc/rust/checks/errors/borrowck/rust-function-collector.h | 3 +--
 gcc/rust/rust-system.h| 3 +++
 gcc/rust/typecheck/rust-hir-type-check.h  | 3 +--
 gcc/rust/typecheck/rust-tyty-subst.cc | 2 +-
 gcc/rust/typecheck/rust-tyty-subst.h  | 3 +--
 gcc/rust/typecheck/rust-tyty.h| 3 +--
 9 files changed, 10 insertions(+), 13 deletions(-)

diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc 
b/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc
index 23aa7c6b078b..3e49bc769335 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc
@@ -1,4 +1,4 @@
-#include 
+#include "rust-system.h"
 #include "rust-bir-dump.h"
 #include "rust-diagnostics.h"
 
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-dump.h 
b/gcc/rust/checks/errors/borrowck/rust-bir-dump.h
index e8cf13726022..b6407a8528a0 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-dump.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-dump.h
@@ -19,8 +19,7 @@
 #ifndef RUST_BIR_DUMP_H
 #define RUST_BIR_DUMP_H
 
-#include 
-#include 
+#include "rust-system.h"
 #include "rust-bir-place.h"
 #include "rust-bir-visitor.h"
 #include "rust-bir.h"
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-place.h 
b/gcc/rust/checks/errors/borrowck/rust-bir-place.h
index 7b04ae408242..ccc820121cc4 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-place.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-place.h
@@ -19,7 +19,6 @@
 #ifndef RUST_BIR_PLACE_H
 #define RUST_BIR_PLACE_H
 
-#include 
 #include "rust-mapping-common.h"
 #include "rust-system.h"
 #include "rust-tyty.h"
diff --git a/gcc/rust/checks/errors/borrowck/rust-function-collector.h 
b/gcc/rust/checks/errors/borrowck/rust-function-collector.h
index 18f2f5e11d1f..272f20d5f935 100644
--- a/gcc/rust/checks/errors/borrowck/rust-function-collector.h
+++ b/gcc/rust/checks/errors/borrowck/rust-function-collector.h
@@ -22,8 +22,7 @@
 #include "rust-hir-item.h"
 #include "rust-hir-visitor.h"
 #include "rust-hir.h"
-
-#include 
+#include "rust-system.h"
 
 namespace Rust {
 
diff --git a/gcc/rust/rust-system.h b/gcc/rust/rust-system.h
index d8a421817000..2382e5b1fb4e 100644
--- a/gcc/rust/rust-system.h
+++ b/gcc/rust/rust-system.h
@@ -36,6 +36,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -45,6 +46,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 
 // Rust frontend requires C++11 minimum, so will have unordered_map and set
 #include 
diff --git a/gcc/rust/typecheck/rust-hir-type-check.h 
b/gcc/rust/typecheck/rust-hir-type-check.h
index c32fa4e84871..c85a83955b9c 100644
--- a/gcc/rust/typecheck/rust-hir-type-check.h
+++ b/gcc/rust/typecheck/rust-hir-type-check.h
@@ -25,8 +25,7 @@
 #include "rust-autoderef.h"
 #include "rust-tyty-region.h"
 #include "rust-tyty-variance-analysis.h"
-
-#include 
+#include "rust-system.h"
 
 namespace Rust {
 namespace Resolver {
diff --git a/gcc/rust/typecheck/rust-tyty-subst.cc 
b/gcc/rust/typecheck/rust-tyty-subst.cc
index 71d41d6f7960..8c801558c423 100644
--- a/gcc/rust/typecheck/rust-tyty-subst.cc
+++ b/gcc/rust/typecheck/rust-tyty-subst.cc
@@ -18,7 +18,7 @@
 
 #include "rust-tyty-subst.h"
 
-#include 
+#include "rust-system.h"
 #include "rust-tyty.h"
 #include "rust-hir-type-check.h"
 #include "rust-substitution-mapper.h"
diff --git a/gcc/rust/typecheck/rust-tyty-subst.h 
b/gcc/rust/typecheck/rust-tyty-subst.h
index 562267cd0597..4f0fab37b44f 100644
--- a/gcc/rust/typecheck/rust-tyty-subst.h
+++ b/gcc/rust/typecheck/rust-tyty-subst.h
@@ -24,8 +24,7 @@
 #include "rust-hir-full-decls.h"
 #include "rust-tyty-bounds.h"
 #include "rust-tyty-region.h"
-
-#include 
+#include "optional.h"
 
 namespace Rust {
 

[gcc/devel/rust/master] Add tuple struct to the type namespace

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:26bbc73e769f92047f68048747422770568e81e6

commit 26bbc73e769f92047f68048747422770568e81e6
Author: Pierre-Emmanuel Patry 
Date:   Wed Jan 24 17:06:56 2024 +0100

Add tuple struct to the type namespace

Only tuple struct constructor was added to the resolver.

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc 
(GlobbingVisitor::visit):
Add tuple struct type to the resolver's context.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc 
b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
index 75d9bb82131f..820ba271ae0c 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
@@ -81,8 +81,13 @@ void
 GlobbingVisitor::visit (AST::TupleStruct _struct)
 {
   if (tuple_struct.get_visibility ().is_public ())
-ctx.insert_shadowable (tuple_struct.get_identifier (),
-  tuple_struct.get_node_id (), Namespace::Values);
+{
+  ctx.insert_shadowable (tuple_struct.get_identifier (),
+tuple_struct.get_node_id (), Namespace::Types);
+
+  ctx.insert_shadowable (tuple_struct.get_identifier (),
+tuple_struct.get_node_id (), Namespace::Values);
+}
 }
 
 void


[gcc/devel/rust/master] Values shall be inserted in the value namespace

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:7bd829ea8c469192db1992d55d975dbcde149617

commit 7bd829ea8c469192db1992d55d975dbcde149617
Author: Pierre-Emmanuel Patry 
Date:   Wed Jan 24 17:00:29 2024 +0100

Values shall be inserted in the value namespace

Values were inserted in the label namespace instead of the value
namespace this lead to several bugs.

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Change the
namespace for values from "label" to "values".

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/resolve/rust-late-name-resolver-2.0.cc | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc 
b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
index 5c8d976b4170..dc7cde1b3233 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
@@ -151,7 +151,10 @@ Late::visit (AST::IdentifierPattern )
   // do we insert in labels or in values
   // but values does not allow shadowing... since functions cannot shadow
   // do we insert functions in labels as well?
-  new_label (identifier.get_ident (), identifier.get_node_id ());
+  auto ok
+= ctx.values.insert (identifier.get_ident (), identifier.get_node_id ());
+
+  rust_assert (ok);
 }
 
 void


[gcc/devel/rust/master] raw-strings: Remove dg-excess-error directive

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:d9f7604e8e8fadb4e10542d4c5f0004b19de2d96

commit d9f7604e8e8fadb4e10542d4c5f0004b19de2d96
Author: Arthur Cohen 
Date:   Fri Mar 29 12:19:10 2024 +0100

raw-strings: Remove dg-excess-error directive

The error is actually expected and uses the correct location.

gcc/testsuite/ChangeLog:

* rust/compile/raw-byte-string-loc.rs: Use dg-error instead of
dg-excess-error.
* rust/compile/raw-string-loc.rs: Likewise.

Diff:
---
 gcc/testsuite/rust/compile/raw-byte-string-loc.rs | 2 +-
 gcc/testsuite/rust/compile/raw-string-loc.rs  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/testsuite/rust/compile/raw-byte-string-loc.rs 
b/gcc/testsuite/rust/compile/raw-byte-string-loc.rs
index f37d3f9694d3..b71b6e5adedc 100644
--- a/gcc/testsuite/rust/compile/raw-byte-string-loc.rs
+++ b/gcc/testsuite/rust/compile/raw-byte-string-loc.rs
@@ -3,4 +3,4 @@ const X: &'static u8 = br#"12
 
 BREAK
 // { dg-error "unrecognised token" "" { target *-*-* } .-1 }
-// { dg-excess-errors "error 'failed to parse item' does not have location" }
+// { dg-error "failed to parse item" "" { target *-*-* } .-2 }
diff --git a/gcc/testsuite/rust/compile/raw-string-loc.rs 
b/gcc/testsuite/rust/compile/raw-string-loc.rs
index 70977510ba38..26331eafa44a 100644
--- a/gcc/testsuite/rust/compile/raw-string-loc.rs
+++ b/gcc/testsuite/rust/compile/raw-string-loc.rs
@@ -3,4 +3,4 @@ const X: &'static str = r#"12
 
 BREAK
 // { dg-error "unrecognised token" "" { target *-*-* } .-1 }
-// { dg-excess-errors "error 'failed to parse item' does not have location" }
+// { dg-error "failed to parse item" "" { target *-*-* } .-2 }


[gcc/devel/rust/master] Make globbing definition shadowable by default

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:ac867c000d46f7b13130b0cb8acc1f2ac8a4362d

commit ac867c000d46f7b13130b0cb8acc1f2ac8a4362d
Author: Pierre-Emmanuel Patry 
Date:   Mon Jan 15 16:34:36 2024 +0100

Make globbing definition shadowable by default

Elements from glob use declaration shall be shadowable by default.

gcc/rust/ChangeLog:

* resolve/rust-forever-stack.h: Add a new function prototype to 
insert
a shadowable definition.
* resolve/rust-forever-stack.hxx: Add the new insert_shadowable
function to insert shadowable definition into the forever stack.
* resolve/rust-name-resolution-context.cc 
(NameResolutionContext::insert_shadowable):
Likewise with the name resolution context.
* resolve/rust-name-resolution-context.h: Add name resolution 
context
insert_shadowable member function prototype.
* resolve/rust-toplevel-name-resolver-2.0.cc 
(GlobbingVisitor::visit):
Insert shadowable definition into the forever stack for glob use
declaration.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/resolve/rust-forever-stack.h  | 15 ++
 gcc/rust/resolve/rust-forever-stack.hxx| 10 +++
 gcc/rust/resolve/rust-name-resolution-context.cc   | 19 
 gcc/rust/resolve/rust-name-resolution-context.h|  3 ++
 .../resolve/rust-toplevel-name-resolver-2.0.cc | 35 +++---
 5 files changed, 65 insertions(+), 17 deletions(-)

diff --git a/gcc/rust/resolve/rust-forever-stack.h 
b/gcc/rust/resolve/rust-forever-stack.h
index 01371fc7bcda..bba5875d4352 100644
--- a/gcc/rust/resolve/rust-forever-stack.h
+++ b/gcc/rust/resolve/rust-forever-stack.h
@@ -437,6 +437,21 @@ public:
*/
   tl::expected insert (Identifier name, NodeId id);
 
+  /**
+   * Insert a new shadowable definition in the innermost `Rib` in this stack
+   *
+   * @param name The name of the definition
+   * @param id Its NodeId
+   *
+   * @return `DuplicateNameError` if that node was already present in the Rib,
+   * the node's `NodeId` otherwise.
+   *
+   * @aborts if there are no `Rib`s inserted in the current map, this function
+   * aborts the program.
+   */
+  tl::expected insert_shadowable (Identifier name,
+ NodeId id);
+
   /**
* Insert a new definition at the root of this stack
*
diff --git a/gcc/rust/resolve/rust-forever-stack.hxx 
b/gcc/rust/resolve/rust-forever-stack.hxx
index a2fdce983629..008adff4676c 100644
--- a/gcc/rust/resolve/rust-forever-stack.hxx
+++ b/gcc/rust/resolve/rust-forever-stack.hxx
@@ -119,6 +119,16 @@ ForeverStack::insert (Identifier name, NodeId node)
   Rib::Definition::NonShadowable (node));
 }
 
+template 
+tl::expected
+ForeverStack::insert_shadowable (Identifier name, NodeId node)
+{
+  auto _rib = peek ();
+
+  return insert_inner (innermost_rib, name.as_string (),
+  Rib::Definition::Shadowable (node));
+}
+
 template 
 tl::expected
 ForeverStack::insert_at_root (Identifier name, NodeId node)
diff --git a/gcc/rust/resolve/rust-name-resolution-context.cc 
b/gcc/rust/resolve/rust-name-resolution-context.cc
index 0340d28f1278..e8529b70bcb7 100644
--- a/gcc/rust/resolve/rust-name-resolution-context.cc
+++ b/gcc/rust/resolve/rust-name-resolution-context.cc
@@ -45,6 +45,25 @@ NameResolutionContext::insert (Identifier name, NodeId id, 
Namespace ns)
 }
 }
 
+tl::expected
+NameResolutionContext::insert_shadowable (Identifier name, NodeId id,
+ Namespace ns)
+{
+  switch (ns)
+{
+case Namespace::Values:
+  return values.insert_shadowable (name, id);
+case Namespace::Types:
+  return types.insert_shadowable (name, id);
+case Namespace::Macros:
+  return macros.insert_shadowable (name, id);
+case Namespace::Labels:
+default:
+  // return labels.insert (name, id);
+  rust_unreachable ();
+}
+}
+
 void
 NameResolutionContext::map_usage (Usage usage, Definition definition)
 {
diff --git a/gcc/rust/resolve/rust-name-resolution-context.h 
b/gcc/rust/resolve/rust-name-resolution-context.h
index 8702900d0f3a..74f110d54dee 100644
--- a/gcc/rust/resolve/rust-name-resolution-context.h
+++ b/gcc/rust/resolve/rust-name-resolution-context.h
@@ -171,6 +171,9 @@ public:
   tl::expected insert (Identifier name, NodeId id,
   Namespace ns);
 
+  tl::expected
+  insert_shadowable (Identifier name, NodeId id, Namespace ns);
+
   /**
* Run a lambda in a "scoped" context, meaning that a new `Rib` will be 
pushed
* before executing the lambda and then popped. This is useful for all kinds
diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc 
b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
index 501204174f22..7f4169a4d8e2 100644
--- 

[gcc/devel/rust/master] Adjust '.github/bors_log_expected_warnings'

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:8c40edc1a2fb836dab05eaf5cb42edb0d7b98967

commit 8c40edc1a2fb836dab05eaf5cb42edb0d7b98967
Author: Thomas Schwinge 
Date:   Sun Mar 24 23:25:31 2024 +0100

Adjust '.github/bors_log_expected_warnings'

Diff:
---
 .github/bors_log_expected_warnings | 73 +-
 1 file changed, 32 insertions(+), 41 deletions(-)

diff --git a/.github/bors_log_expected_warnings 
b/.github/bors_log_expected_warnings
index ae172cabe605..173310bb2257 100644
--- a/.github/bors_log_expected_warnings
+++ b/.github/bors_log_expected_warnings
@@ -8,8 +8,8 @@
 ../../../libcpp/lex.cc:2120:39: warning: ‘loc’ may be used uninitialized 
[-Wmaybe-uninitialized]
 ../../../libcpp/macro.cc:185:26: warning: format not a string literal and no 
format arguments [-Wformat-security]
 ../../../libcpp/macro.cc:214:34: warning: format not a string literal and no 
format arguments [-Wformat-security]
-../../../libcpp/macro.cc:3704:25: warning: format not a string literal and no 
format arguments [-Wformat-security]
-../../../libcpp/macro.cc:3719:25: warning: format not a string literal and no 
format arguments [-Wformat-security]
+../../../libcpp/macro.cc:3710:25: warning: format not a string literal and no 
format arguments [-Wformat-security]
+../../../libcpp/macro.cc:3725:25: warning: format not a string literal and no 
format arguments [-Wformat-security]
 ../../c++tools/server.cc:490:11: warning: ignoring return value of ‘ssize_t 
write(int, const void*, size_t)’ declared with attribute ‘warn_unused_result’ 
[-Wunused-result]
 ../../c++tools/server.cc:620:10: warning: ignoring return value of ‘int 
pipe(int*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
 ../../gcc/../libgcc/libgcov-util.c:455:9: warning: ignoring return value of 
‘int chdir(const char*)’ declared with attribute ‘warn_unused_result’ 
[-Wunused-result]
@@ -26,31 +26,35 @@
 ../../gcc/analyzer/call-summary.cc:123:26: warning: unknown conversion type 
character ‘E’ in format [-Wformat=]
 ../../gcc/analyzer/call-summary.cc:99:32: warning: too many arguments for 
format [-Wformat-extra-args]
 ../../gcc/analyzer/call-summary.cc:99:40: warning: unknown conversion type 
character ‘E’ in format [-Wformat=]
-../../gcc/analyzer/diagnostic-manager.cc:810:20: warning: too many arguments 
for format [-Wformat-extra-args]
-../../gcc/analyzer/diagnostic-manager.cc:810:28: warning: unknown conversion 
type character ‘E’ in format [-Wformat=]
-../../gcc/analyzer/program-state.cc:1422:15: warning: format not a string 
literal and no format arguments [-Wformat-security]
-../../gcc/analyzer/sm-malloc.cc:1647:22: warning: too many arguments for 
format [-Wformat-extra-args]
-../../gcc/analyzer/sm-malloc.cc:1647:25: warning: unknown conversion type 
character ‘E’ in format [-Wformat=]
-../../gcc/analyzer/sm-malloc.cc:1648:22: warning: too many arguments for 
format [-Wformat-extra-args]
-../../gcc/analyzer/sm-malloc.cc:1648:25: warning: unknown conversion type 
character ‘E’ in format [-Wformat=]
-../../gcc/analyzer/store.h:300:5: warning: 
‘size_in_bytes.generic_wide_int 
>::.fixed_wide_int_storage<128>::val[1]’ may be used uninitialized 
[-Wmaybe-uninitialized]
-../../gcc/c-family/c-common.cc:6639:14: warning: format not a string literal 
and no format arguments [-Wformat-security]
-../../gcc/c-family/c-common.cc:6643:16: warning: format not a string literal 
and no format arguments [-Wformat-security]
+../../gcc/analyzer/diagnostic-manager.cc:811:20: warning: too many arguments 
for format [-Wformat-extra-args]
+../../gcc/analyzer/diagnostic-manager.cc:811:28: warning: unknown conversion 
type character ‘E’ in format [-Wformat=]
+../../gcc/analyzer/program-state.cc:1437:15: warning: format not a string 
literal and no format arguments [-Wformat-security]
+../../gcc/analyzer/record-layout.h:64:24: warning: too many arguments for 
format [-Wformat-extra-args]
+../../gcc/analyzer/record-layout.h:64:41: warning: unknown conversion type 
character ‘D’ in format [-Wformat=]
+../../gcc/analyzer/record-layout.h:66:24: warning: too many arguments for 
format [-Wformat-extra-args]
+../../gcc/analyzer/record-layout.h:66:27: warning: unknown conversion type 
character ‘D’ in format [-Wformat=]
+../../gcc/analyzer/sm-malloc.cc:1624:22: warning: too many arguments for 
format [-Wformat-extra-args]
+../../gcc/analyzer/sm-malloc.cc:1624:25: warning: unknown conversion type 
character ‘E’ in format [-Wformat=]
+../../gcc/analyzer/sm-malloc.cc:1625:22: warning: too many arguments for 
format [-Wformat-extra-args]
+../../gcc/analyzer/sm-malloc.cc:1625:25: warning: unknown conversion type 
character ‘E’ in format [-Wformat=]
+../../gcc/analyzer/store.h:310:5: warning: 
‘size_in_bytes.generic_wide_int 
>::.fixed_wide_int_storage<128>::val[1]’ may be used uninitialized 
[-Wmaybe-uninitialized]
+../../gcc/c-family/c-common.cc:6763:14: warning: format not a string literal 
and no format arguments [-Wformat-security]
+../../gcc/c-

[gcc/devel/rust/master] Merge commit 'cde6f1085b7027f6a42fdb71c786d422606a8765' into HEAD

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:b177dc6b031c6b241358ff5cbf6f838200c55241

commit b177dc6b031c6b241358ff5cbf6f838200c55241
Merge: 000c6d0a37b7 cde6f1085b70
Author: Thomas Schwinge 
Date:   Fri Mar 22 09:58:10 2024 +0100

Merge commit 'cde6f1085b7027f6a42fdb71c786d422606a8765' into HEAD

Diff:

 libgrust/configure| 8 +---
 libgrust/configure.ac | 4 +++-
 2 files changed, 8 insertions(+), 4 deletions(-)


[gcc/devel/rust/master] Add globbing name resolution 2.0 test

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:2ac459165021725644e1c17b7dbec973dad13df0

commit 2ac459165021725644e1c17b7dbec973dad13df0
Author: Pierre-Emmanuel Patry 
Date:   Tue Mar 26 10:58:53 2024 +0100

Add globbing name resolution 2.0 test

Add a few test for globbing to highlight function call ambiguities.

gcc/testsuite/ChangeLog:

* rust/compile/name_resolution23.rs: New test.
* rust/compile/name_resolution24.rs: New test.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/testsuite/rust/compile/name_resolution23.rs | 19 +++
 gcc/testsuite/rust/compile/name_resolution24.rs | 15 +++
 2 files changed, 34 insertions(+)

diff --git a/gcc/testsuite/rust/compile/name_resolution23.rs 
b/gcc/testsuite/rust/compile/name_resolution23.rs
new file mode 100644
index ..50b8e8111525
--- /dev/null
+++ b/gcc/testsuite/rust/compile/name_resolution23.rs
@@ -0,0 +1,19 @@
+// { dg-options "-frust-name-resolution-2.0" }
+
+mod a {
+pub mod b {
+pub fn foo() {}
+pub fn bar() {}
+pub fn baz() {}
+}
+pub fn baz() {}
+}
+
+use a::b::*;
+use a::baz;
+
+pub fn func() {
+baz();
+foo();
+bar();
+}
diff --git a/gcc/testsuite/rust/compile/name_resolution24.rs 
b/gcc/testsuite/rust/compile/name_resolution24.rs
new file mode 100644
index ..f4eb7b2d38fd
--- /dev/null
+++ b/gcc/testsuite/rust/compile/name_resolution24.rs
@@ -0,0 +1,15 @@
+// { dg-options "-frust-name-resolution-2.0" }
+
+mod a {
+pub mod b {
+pub fn baz() {}
+}
+pub fn baz() {}
+}
+
+use a::b::*;
+use a::*;
+
+pub fn func() {
+baz(); // { dg-error ".baz. is ambiguous .E0659." }
+}


[gcc/devel/rust/master] compile: resolve-path-ref: properly resolve nodeId with nr2.0

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:e1064ca1470c1628edb667e3ccb397a8fa1ee109

commit e1064ca1470c1628edb667e3ccb397a8fa1ee109
Author: Arthur Cohen 
Date:   Fri Mar 22 14:31:24 2024 +0100

compile: resolve-path-ref: properly resolve nodeId with nr2.0

gcc/rust/ChangeLog:

* backend/rust-compile-resolve-path.cc: Attempt to resolve names
also using new name resolution context.
* backend/rust-compile-resolve-path.h: Add new declaration.

Diff:
---
 gcc/rust/backend/rust-compile-resolve-path.cc | 112 --
 gcc/rust/backend/rust-compile-resolve-path.h  |   6 ++
 2 files changed, 74 insertions(+), 44 deletions(-)

diff --git a/gcc/rust/backend/rust-compile-resolve-path.cc 
b/gcc/rust/backend/rust-compile-resolve-path.cc
index 366de59865ed..3bb45a537508 100644
--- a/gcc/rust/backend/rust-compile-resolve-path.cc
+++ b/gcc/rust/backend/rust-compile-resolve-path.cc
@@ -17,14 +17,17 @@
 // .
 
 #include "rust-compile-resolve-path.h"
+#include "options.h"
 #include "rust-compile-intrinsic.h"
 #include "rust-compile-item.h"
 #include "rust-compile-implitem.h"
 #include "rust-compile-expr.h"
+#include "rust-hir-map.h"
 #include "rust-hir-trait-resolve.h"
 #include "rust-hir-path-probe.h"
 #include "rust-compile-extern.h"
 #include "rust-constexpr.h"
+#include "rust-tyty.h"
 
 namespace Rust {
 namespace Compile {
@@ -43,6 +46,50 @@ ResolvePathRef::visit (HIR::PathInExpression )
  expr.get_mappings (), expr.get_locus (), false);
 }
 
+tree
+ResolvePathRef::attempt_constructor_expression_lookup (
+  TyTy::BaseType *lookup, Context *ctx, const Analysis::NodeMapping ,
+  location_t expr_locus)
+{
+  // it might be an enum data-less enum variant
+  if (lookup->get_kind () != TyTy::TypeKind::ADT)
+return error_mark_node;
+
+  TyTy::ADTType *adt = static_cast (lookup);
+  if (adt->is_unit ())
+return unit_expression (ctx, expr_locus);
+
+  if (!adt->is_enum ())
+return error_mark_node;
+
+  HirId variant_id;
+  if (!ctx->get_tyctx ()->lookup_variant_definition (mappings.get_hirid (),
+_id))
+return error_mark_node;
+
+  int union_disriminator = -1;
+  TyTy::VariantDef *variant = nullptr;
+  if (!adt->lookup_variant_by_id (variant_id, , _disriminator))
+return error_mark_node;
+
+  // this can only be for discriminant variants the others are built up
+  // using call-expr or struct-init
+  rust_assert (variant->get_variant_type ()
+  == TyTy::VariantDef::VariantType::NUM);
+
+  // we need the actual gcc type
+  tree compiled_adt_type = TyTyResolveCompile::compile (ctx, adt);
+
+  // make the ctor for the union
+  HIR::Expr *discrim_expr = variant->get_discriminant ();
+  tree discrim_expr_node = CompileExpr::Compile (discrim_expr, ctx);
+  tree folded_discrim_expr = fold_expr (discrim_expr_node);
+  tree qualifier = folded_discrim_expr;
+
+  return Backend::constructor_expression (compiled_adt_type, true, {qualifier},
+ union_disriminator, expr_locus);
+}
+
 tree
 ResolvePathRef::resolve (const HIR::PathIdentSegment _segment,
 const Analysis::NodeMapping ,
@@ -53,52 +100,29 @@ ResolvePathRef::resolve (const HIR::PathIdentSegment 
_segment,
   rust_assert (ok);
 
   // need to look up the reference for this identifier
+
+  // this can fail because it might be a Constructor for something
+  // in that case the caller should attempt ResolvePathType::Compile
   NodeId ref_node_id = UNKNOWN_NODEID;
-  if (!ctx->get_resolver ()->lookup_resolved_name (mappings.get_nodeid (),
-  _node_id))
+  if (flag_name_resolution_2_0)
+{
+  auto nr_ctx
+   = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+
+  auto resolved = nr_ctx.lookup (mappings.get_nodeid ());
+
+  if (!resolved)
+   return attempt_constructor_expression_lookup (lookup, ctx, mappings,
+ expr_locus);
+
+  ref_node_id = *resolved;
+}
+  else
 {
-  // this can fail because it might be a Constructor for something
-  // in that case the caller should attempt ResolvePathType::Compile
-
-  // it might be an enum data-less enum variant
-  if (lookup->get_kind () != TyTy::TypeKind::ADT)
-   return error_mark_node;
-
-  TyTy::ADTType *adt = static_cast (lookup);
-  if (adt->is_unit ())
-   return unit_expression (ctx, expr_locus);
-
-  if (!adt->is_enum ())
-   return error_mark_node;
-
-  HirId variant_id;
-  if (!ctx->get_tyctx ()->lookup_variant_definition (mappings.get_hirid (),
-_id))
-   return error_mark_node;
-
-  int union_disriminator = -1;
-  TyTy::VariantDef *variant = nullptr;
-  if (!adt->lookup_variant_by_id (variant_id, ,
-

[gcc/devel/rust/master] Merge commit 'e4f0eb725d836ef0eec780cbb9e7be0d31c6fe8b' into HEAD [#2690, #2692, #2853]

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:77d55deb8bb75cfe79b10151a17084dbf3924ea4

commit 77d55deb8bb75cfe79b10151a17084dbf3924ea4
Merge: 6eba95e99238 e4f0eb725d83
Author: Thomas Schwinge 
Date:   Tue Mar 19 16:48:09 2024 +0100

Merge commit 'e4f0eb725d836ef0eec780cbb9e7be0d31c6fe8b' into HEAD [#2690, 
#2692, #2853]

Diff:


[gcc/devel/rust/master] Update assignment operator with cratenum

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:0874163bbf8b13350ec20bcba766d436147bbfa5

commit 0874163bbf8b13350ec20bcba766d436147bbfa5
Author: Pierre-Emmanuel Patry 
Date:   Wed Mar 13 16:21:44 2024 +0100

Update assignment operator with cratenum

Crate number was not assigned with the other fields in the assignment
operator overload of a CannonicalPath.

gcc/rust/ChangeLog:

* util/rust-canonical-path.h: Also assign crate number.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/util/rust-canonical-path.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gcc/rust/util/rust-canonical-path.h 
b/gcc/rust/util/rust-canonical-path.h
index f2865eba9ae4..969ac7f7cc18 100644
--- a/gcc/rust/util/rust-canonical-path.h
+++ b/gcc/rust/util/rust-canonical-path.h
@@ -51,6 +51,7 @@ public:
   CanonicalPath = (const CanonicalPath )
   {
 segs = other.segs;
+crate_num = other.crate_num;
 return *this;
   }


[gcc/devel/rust/master] Store visibility properly in ExternalTypeItem

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:aa395781afdcf06cac36dec414e90c741ec5a00b

commit aa395781afdcf06cac36dec414e90c741ec5a00b
Author: jjasmine 
Date:   Sat Mar 9 17:16:34 2024 -0500

Store visibility properly in ExternalTypeItem

Fix issue 2897

gcc/rust/ChangeLog:

* hir/rust-ast-lower-extern.h: Add translate_visiblity
* hir/tree/rust-hir-item.h: Fix constructor of ExternalTypeItem

Diff:
---
 gcc/rust/hir/rust-ast-lower-extern.h | 4 +++-
 gcc/rust/hir/tree/rust-hir-item.h| 4 ++--
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/gcc/rust/hir/rust-ast-lower-extern.h 
b/gcc/rust/hir/rust-ast-lower-extern.h
index e92acdc44a1f..bd889e244b01 100644
--- a/gcc/rust/hir/rust-ast-lower-extern.h
+++ b/gcc/rust/hir/rust-ast-lower-extern.h
@@ -133,8 +133,10 @@ public:
   mappings->get_next_hir_id (crate_num),
   mappings->get_next_localdef_id (crate_num));
 
+HIR::Visibility vis = translate_visibility (type.get_visibility ());
+
 translated = new HIR::ExternalTypeItem (mapping, type.get_identifier (),
-   type.get_locus ());
+   vis, type.get_locus ());
   }
 
 private:
diff --git a/gcc/rust/hir/tree/rust-hir-item.h 
b/gcc/rust/hir/tree/rust-hir-item.h
index 3bd0102d4dcf..7e0c8c6ffca9 100644
--- a/gcc/rust/hir/tree/rust-hir-item.h
+++ b/gcc/rust/hir/tree/rust-hir-item.h
@@ -3154,9 +3154,9 @@ class ExternalTypeItem : public ExternalItem
 {
 public:
   ExternalTypeItem (Analysis::NodeMapping mappings, Identifier item_name,
-   location_t locus)
+   Visibility vis, location_t locus)
 : ExternalItem (std::move (mappings), std::move (item_name),
-   Visibility (Visibility::PRIVATE),
+   Visibility (std::move (vis)),
/* FIXME: Is that correct? */
{}, locus)
   {}


[gcc/devel/rust/master] Use new name resolver to compile constant items

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:4d64d55f5a8e2ed4fbeca2d56da7c51d65fe040b

commit 4d64d55f5a8e2ed4fbeca2d56da7c51d65fe040b
Author: Pierre-Emmanuel Patry 
Date:   Tue Feb 6 17:21:45 2024 +0100

Use new name resolver to compile constant items

Constant items were handled only by the old resolver, this lead to an
ICE when using the new resolver on some rust code containing a constant
item as the new and the old resolver cannot be used at the same time.

gcc/rust/ChangeLog:

* backend/rust-compile-item.cc (CompileItem::visit): Check the 
resolver
flag and use the new one when required.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/backend/rust-compile-item.cc | 36 +--
 1 file changed, 26 insertions(+), 10 deletions(-)

diff --git a/gcc/rust/backend/rust-compile-item.cc 
b/gcc/rust/backend/rust-compile-item.cc
index 8feed51efa4f..609528d86308 100644
--- a/gcc/rust/backend/rust-compile-item.cc
+++ b/gcc/rust/backend/rust-compile-item.cc
@@ -76,32 +76,48 @@ CompileItem::visit (HIR::StaticItem )
 void
 CompileItem::visit (HIR::ConstantItem )
 {
-  if (ctx->lookup_const_decl (constant.get_mappings ().get_hirid (),
- ))
+  auto  = constant.get_mappings ();
+
+  if (ctx->lookup_const_decl (mappings.get_hirid (), ))
 return;
 
   // resolve the type
   TyTy::BaseType *resolved_type = nullptr;
+
   bool ok
-= ctx->get_tyctx ()->lookup_type (constant.get_mappings ().get_hirid (),
- _type);
+= ctx->get_tyctx ()->lookup_type (mappings.get_hirid (), _type);
   rust_assert (ok);
 
   // canonical path
-  const Resolver::CanonicalPath *canonical_path = nullptr;
-  ok = ctx->get_mappings ()->lookup_canonical_path (
-constant.get_mappings ().get_nodeid (), _path);
-  rust_assert (ok);
+  Resolver::CanonicalPath canonical_path
+= Resolver::CanonicalPath::create_empty ();
+
+  if (flag_name_resolution_2_0)
+{
+  auto nr_ctx
+   = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+
+  canonical_path
+   = nr_ctx.values.to_canonical_path (mappings.get_nodeid ()).value ();
+}
+  else
+{
+  const Resolver::CanonicalPath *canonical_path_ptr = nullptr;
+  ok = ctx->get_mappings ()->lookup_canonical_path (mappings.get_nodeid (),
+   _path_ptr);
+  rust_assert (ok);
+  canonical_path = *canonical_path_ptr;
+}
 
   HIR::Expr *const_value_expr = constant.get_expr ().get ();
   ctx->push_const_context ();
   tree const_expr
-= compile_constant_item (resolved_type, canonical_path, const_value_expr,
+= compile_constant_item (resolved_type, _path, const_value_expr,
 constant.get_locus ());
   ctx->pop_const_context ();
 
   ctx->push_const (const_expr);
-  ctx->insert_const_decl (constant.get_mappings ().get_hirid (), const_expr);
+  ctx->insert_const_decl (mappings.get_hirid (), const_expr);
   reference = const_expr;
 }


[gcc/devel/rust/master] format-args: Add base for expanding FormatArgs nodes

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:da10bf56cf11207877c3a552cffb472702d1b772

commit da10bf56cf11207877c3a552cffb472702d1b772
Author: Arthur Cohen 
Date:   Thu Feb 29 13:01:32 2024 +0100

format-args: Add base for expanding FormatArgs nodes

gcc/rust/ChangeLog:

* Make-lang.in: Add new object.
* hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Remove calls 
to
FormatArgsLowering.
* expand/rust-expand-format-args.cc: New file.
* expand/rust-expand-format-args.h: New file.

Diff:
---
 gcc/rust/Make-lang.in  |  1 +
 gcc/rust/expand/rust-expand-format-args.cc | 43 ++
 gcc/rust/expand/rust-expand-format-args.h  | 32 ++
 gcc/rust/hir/rust-ast-lower-expr.cc|  4 ---
 4 files changed, 76 insertions(+), 4 deletions(-)

diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in
index 8a324c8c0792..8112b7cc3fb2 100644
--- a/gcc/rust/Make-lang.in
+++ b/gcc/rust/Make-lang.in
@@ -205,6 +205,7 @@ GRS_OBJS = \
 rust/rust-unicode.o \
 rust/rust-punycode.o \
rust/rust-lang-item.o \
+   rust/rust-expand-format-args.o \
 $(END)
 # removed object files from here
 
diff --git a/gcc/rust/expand/rust-expand-format-args.cc 
b/gcc/rust/expand/rust-expand-format-args.cc
new file mode 100644
index ..52249cb17e3d
--- /dev/null
+++ b/gcc/rust/expand/rust-expand-format-args.cc
@@ -0,0 +1,43 @@
+// Copyright (C) 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
+// .
+
+#include "rust-expand-format-args.h"
+#include "rust-builtin-ast-nodes.h"
+
+namespace Rust {
+
+tl::optional
+expand_format_args (AST::FormatArgs )
+{
+  for (const auto  : fmt.get_template ().get_pieces ())
+{
+  switch (node.tag)
+   {
+   case Fmt::Piece::Tag::String:
+ // rust_debug ("[ARTHUR]: %s", node.string._0.c_str ());
+
+   case Fmt::Piece::Tag::NextArgument:
+ rust_debug ("[ARTHUR]: NextArgument");
+ break;
+   }
+}
+
+  return tl::nullopt;
+}
+
+} // namespace Rust
diff --git a/gcc/rust/expand/rust-expand-format-args.h 
b/gcc/rust/expand/rust-expand-format-args.h
new file mode 100644
index ..1481f3605ed8
--- /dev/null
+++ b/gcc/rust/expand/rust-expand-format-args.h
@@ -0,0 +1,32 @@
+// Copyright (C) 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
+// .
+
+#ifndef RUST_EXPAND_FORMAT_ARGS_H
+#define RUST_EXPAND_FORMAT_ARGS_H
+
+#include "optional.h"
+#include "rust-ast-fragment.h"
+
+namespace Rust {
+
+tl::optional
+expand_format_args (AST::FormatArgs );
+
+} // namespace Rust
+
+#endif //! RUST_EXPAND_FORMAT_ARGS_H
diff --git a/gcc/rust/hir/rust-ast-lower-expr.cc 
b/gcc/rust/hir/rust-ast-lower-expr.cc
index 6944db9b9ccf..c414643bb915 100644
--- a/gcc/rust/hir/rust-ast-lower-expr.cc
+++ b/gcc/rust/hir/rust-ast-lower-expr.cc
@@ -19,7 +19,6 @@
 #include "rust-ast-lower-expr.h"
 #include "rust-ast-lower-base.h"
 #include "rust-ast-lower-block.h"
-#include "rust-ast-lower-format-args.h"
 #include "rust-ast-lower-struct-field-expr.h"
 #include "rust-ast-lower-pattern.h"
 #include "rust-ast-lower-type.h"
@@ -824,9 +823,6 @@ ASTLoweringExpr::visit (AST::ClosureExprInnerTyped )
 void
 ASTLoweringExpr::visit (AST::FormatArgs )
 {
-  // Lowering FormatArgs is complex, and this file is already very long
-  translated = FormatArgsLowering ().go (fmt);
-
   rust_sorry_at (fmt.get_locus (),
 "FormatArgs lowering is not implemented yet");
 }


[gcc/devel/rust/master] macro: Use MacroInvocation's node_id in ExternalItem constructor.

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:b85dc7014c821466bb411a14b7f5d6de4077eae6

commit b85dc7014c821466bb411a14b7f5d6de4077eae6
Author: Arthur Cohen 
Date:   Tue Mar 19 13:12:20 2024 +0100

macro: Use MacroInvocation's node_id in ExternalItem constructor.

gcc/rust/ChangeLog:

* ast/rust-macro.h: Use proper node id instead of the one in the 
base
Expr class - which is uninitialized.

Diff:
---
 gcc/rust/ast/rust-macro.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/rust/ast/rust-macro.h b/gcc/rust/ast/rust-macro.h
index 5b9ff3f22c88..507e595e3790 100644
--- a/gcc/rust/ast/rust-macro.h
+++ b/gcc/rust/ast/rust-macro.h
@@ -727,7 +727,7 @@ private:
   {}
 
   MacroInvocation (const MacroInvocation )
-: TraitItem (other.locus), ExternalItem (Expr::node_id),
+: TraitItem (other.locus), ExternalItem (other.node_id),
   outer_attrs (other.outer_attrs), locus (other.locus),
   node_id (other.node_id), invoc_data (other.invoc_data),
   is_semi_coloned (other.is_semi_coloned), kind (other.kind),


[gcc/devel/rust/master] ci: Install Rust directly from rustup instead of apt

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:f4379ba00a3b986eb9e7147bbbf39ebbd95f0aa5

commit f4379ba00a3b986eb9e7147bbbf39ebbd95f0aa5
Author: Arthur Cohen 
Date:   Mon Mar 18 15:10:43 2024 +0100

ci: Install Rust directly from rustup instead of apt

ChangeLog:

* .github/workflows/ccpp.yml: Install Rust manually.

Diff:
---
 .github/workflows/ccpp.yml | 24 +++-
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml
index 10a909019fbd..1955a03ab094 100644
--- a/.github/workflows/ccpp.yml
+++ b/.github/workflows/ccpp.yml
@@ -37,7 +37,9 @@ jobs:
   build-essential \
   gcc-multilib \
   g++-multilib \
-  dejagnu
+  dejagnu;
+  # install Rust directly using rustup
+  curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- 
-y --default-toolchain=1.72.0;
 
 - name: Configure
   run: |
@@ -52,6 +54,8 @@ jobs:
   shell: bash
   run: |
cd gccrs-build; \
+   # Add cargo to our path quickly
+   . "$HOME/.cargo/env";
make -Otarget -j $(nproc) 2>&1 | tee log
 
 - name: Check for new warnings
@@ -114,7 +118,9 @@ jobs:
   build-essential \
   gcc-multilib \
   g++-multilib \
-  dejagnu
+  dejagnu;
+  # install Rust directly using rustup
+  curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- 
-y --default-toolchain=1.72.0;
 
 - name: Configure
   run: |
@@ -129,6 +135,8 @@ jobs:
   shell: bash
   run: |
cd gccrs-build; \
+   # Add cargo to our path quickly
+   . "$HOME/.cargo/env";
make -Otarget -j $(nproc) 2>&1 | tee log
 
 - name: Check for new warnings
@@ -178,6 +186,7 @@ jobs:
   run: |
   apt-get update;
   apt-get install -y \
+  curl \
   automake \
   autoconf \
   libtool \
@@ -192,8 +201,9 @@ jobs:
   g++-4.8 \
   gcc-4.8-multilib \
   g++-4.8-multilib \
-  dejagnu \
-  cargo
+  dejagnu;
+  # install Rust directly using rustup
+  curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- 
-y --default-toolchain=1.72.0;
 
 - name: Configure
   run: |
@@ -209,6 +219,8 @@ jobs:
 - name: Build
   shell: bash
   run: |
+   # Add cargo to our path quickly
+   . "$HOME/.cargo/env";
make -C gccrs-build -j $(nproc)
 
 - name: Run Tests
@@ -248,7 +260,9 @@ jobs:
 
 - name: Install Deps
   run: |
-  brew install dejagnu mpfr libmpc gmp
+  brew install dejagnu mpfr libmpc gmp;
+  # install Rust directly using rustup
+  curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- 
-y --default-toolchain=1.72.0;
 
 - name: Configure
   run: |


[gcc/devel/rust/master] sra: SRA of non-escaped aggregates passed by reference to calls

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:70a5ad7506e60407a2f118f53ab979dec5baf1fc

commit 70a5ad7506e60407a2f118f53ab979dec5baf1fc
Author: Martin Jambor 
Date:   Fri Nov 24 17:32:35 2023 +0100

sra: SRA of non-escaped aggregates passed by reference to calls

PR109849 shows that a loop that heavily pushes and pops from a stack
implemented by a C++ std::vec results in slow code, mainly because the
vector structure is not split by SRA and so we end up in many loads
and stores into it.  This is because it is passed by reference
to (re)allocation methods and so needs to live in memory, even though
it does not escape from them and so we could SRA it if we
re-constructed it before the call and then separated it to distinct
replacements afterwards.

This patch does exactly that, first relaxing the selection of
candidates to also include those which are addressable but do not
escape and then adding code to deal with the calls.  The
micro-benchmark that is also the (scan-dump) testcase in this patch
runs twice as fast with it than with current trunk.  Honza measured
its effect on the libjxl benchmark and it almost closes the
performance gap between Clang and GCC while not requiring excessive
inlining and thus code growth.

The patch disallows creation of replacements for such aggregates which
are also accessed with a precision smaller than their size because I
have observed that this led to excessive zero-extending of data
leading to slow-downs of perlbench (on some CPUs).  Apart from this
case I have not noticed any regressions, at least not so far.

Gimple call argument flags can tell if an argument is unused (and then
we do not need to generate any statements for it) or if it is not
written to and then we do not need to generate statements loading
replacements from the original aggregate after the call statement.
Unfortunately, we cannot symmetrically use flags that an aggregate is
not read because to avoid re-constructing the aggregate before the
call because flags don't tell which what parts of aggregates were not
written to, so we load all replacements, and so all need to have the
correct value before the call.

This version of the patch also takes care to avoid attempts to modify
abnormal edges, something which was missing in the previosu version.

gcc/ChangeLog:

2023-11-23  Martin Jambor  

PR middle-end/109849
* tree-sra.cc (passed_by_ref_in_call): New.
(sra_initialize): Allocate passed_by_ref_in_call.
(sra_deinitialize): Free passed_by_ref_in_call.
(create_access): Add decl pool candidates only if they are not
already candidates.
(build_access_from_expr_1): Bail out on ADDR_EXPRs.
(build_access_from_call_arg): New function.
(asm_visit_addr): Rename to scan_visit_addr, change the
disqualification dump message.
(scan_function): Check taken addresses for all non-call statements,
including phi nodes.  Process all call arguments, including the 
static
chain, build_access_from_call_arg.
(maybe_add_sra_candidate): Relax need_to_live_in_memory check to 
allow
non-escaped local variables.
(sort_and_splice_var_accesses): Disallow smaller-than-precision
replacements for aggregates passed by reference to functions.
(sra_modify_expr): Use a separate stmt iterator for adding satements
before the processed statement and after it.
(enum out_edge_check): New type.
(abnormal_edge_after_stmt_p): New function.
(sra_modify_call_arg): New function.
(sra_modify_assign): Adjust calls to sra_modify_expr.
(sra_modify_function_body): Likewise, use sra_modify_call_arg to
process call arguments, including the static chain.

gcc/testsuite/ChangeLog:

2023-11-23  Martin Jambor  

PR middle-end/109849
* g++.dg/tree-ssa/pr109849.C: New test.
* g++.dg/tree-ssa/sra-eh-1.C: Likewise.
* gcc.dg/tree-ssa/pr109849.c: Likewise.
* gcc.dg/tree-ssa/sra-longjmp-1.c: Likewise.
* gfortran.dg/pr43984.f90: Added -fno-tree-sra to dg-options.

(cherry picked from commit aae723d360ca26cd9fd0b039fb0a616bd0eae363)

Diff:
---
 gcc/testsuite/g++.dg/tree-ssa/pr109849.C  |  31 +++
 gcc/testsuite/g++.dg/tree-ssa/sra-eh-1.C  | 187 +
 gcc/testsuite/gcc.dg/tree-ssa/pr109849.c  |  60 ++
 gcc/testsuite/gcc.dg/tree-ssa/sra-longjmp-1.c |  87 
 gcc/testsuite/gfortran.dg/pr43984.f90 |   2 +-
 gcc/tree-sra.cc   | 287 +-
 6 files changed, 607 insertions(+), 47 deletions(-)

diff --git a/gcc/testsuite/g++.dg/tree-ssa/pr109849.C 

[gcc/devel/rust/master] Merge commit '56ca59a03150cf44cea340f58967c990ed6bf43c' into HEAD

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:f0fdff9b6da1a17d8e1c2d83347e84c5218b1b29

commit f0fdff9b6da1a17d8e1c2d83347e84c5218b1b29
Merge: b3a137373179 56ca59a03150
Author: Thomas Schwinge 
Date:   Sun Mar 17 00:10:10 2024 +0100

Merge commit '56ca59a03150cf44cea340f58967c990ed6bf43c' into HEAD

Diff:

 Makefile.in  | 30 +++---
 Makefile.tpl | 10 +-
 2 files changed, 28 insertions(+), 12 deletions(-)


[gcc/devel/rust/master] Visit constant item type in default resolver

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:ea376da5329ee219fb2fbc127b25d28f3d11eade

commit ea376da5329ee219fb2fbc127b25d28f3d11eade
Author: Pierre-Emmanuel Patry 
Date:   Wed Jan 24 16:50:27 2024 +0100

Visit constant item type in default resolver

The type of constant item expression was not properly visited in the
default resolver.

gcc/rust/ChangeLog:

* resolve/rust-default-resolver.cc (DefaultResolver::visit): Visit
constant item's types.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/resolve/rust-default-resolver.cc | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/resolve/rust-default-resolver.cc 
b/gcc/rust/resolve/rust-default-resolver.cc
index d805bc9a511d..0c2576f6e755 100644
--- a/gcc/rust/resolve/rust-default-resolver.cc
+++ b/gcc/rust/resolve/rust-default-resolver.cc
@@ -464,7 +464,10 @@ DefaultResolver::visit (AST::EnumItemDiscriminant )
 void
 DefaultResolver::visit (AST::ConstantItem )
 {
-  auto expr_vis = [this, ] () { item.get_expr ().accept_vis (*this); };
+  auto expr_vis = [this, ] () {
+item.get_expr ().accept_vis (*this);
+visit (item.get_type ());
+  };
 
   // FIXME: Why do we need a Rib here?
   ctx.scoped (Rib::Kind::Item, item.get_node_id (), expr_vis);


[gcc/devel/rust/master] Placate clang-format re 'gcc/rust/lex/rust-lex.cc'

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:1cb7e9000ea94a9d1f6bc8e3f9c90ecef84fc6e5

commit 1cb7e9000ea94a9d1f6bc8e3f9c90ecef84fc6e5
Author: Thomas Schwinge 
Date:   Sun Mar 24 23:08:12 2024 +0100

Placate clang-format re 'gcc/rust/lex/rust-lex.cc'

Reformat the upstream GCC commit 61644aea34c4623d16273ff705f8b8b1ff2d87f0
"gccrs: tokenize Unicode identifiers" change to 'gcc/rust/lex/rust-lex.cc'
to clang-format's liking.

gcc/rust/
* lex/rust-lex.cc (is_identifier_start): Placate clang-format.

Diff:
---
 gcc/rust/lex/rust-lex.cc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/lex/rust-lex.cc b/gcc/rust/lex/rust-lex.cc
index bf6bf4c84466..9c2203160cd4 100644
--- a/gcc/rust/lex/rust-lex.cc
+++ b/gcc/rust/lex/rust-lex.cc
@@ -128,7 +128,8 @@ is_non_decimal_int_literal_separator (uint32_t character)
 bool
 is_identifier_start (uint32_t codepoint)
 {
-  return (cpp_check_xid_property (codepoint) & CPP_XID_START) || codepoint == 
'_';
+  return (cpp_check_xid_property (codepoint) & CPP_XID_START)
+|| codepoint == '_';
 }
 
 bool


[gcc/devel/rust/master] Merge commit '6a6d3817afa02bbcd2388c8e005da6faf88932f1^' into HEAD

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:155817d33e48138e2ed42616d957bf42a598bfdf

commit 155817d33e48138e2ed42616d957bf42a598bfdf
Merge: 75dc00584e0e 829b0c4cbabb
Author: Thomas Schwinge 
Date:   Sat Mar 16 23:03:21 2024 +0100

Merge commit '6a6d3817afa02bbcd2388c8e005da6faf88932f1^' into HEAD

Diff:

 gcc/ABOUT-GCC-NLS  |   16 +
 gcc/ChangeLog  |  853 +++
 gcc/DATESTAMP  |2 +-
 gcc/Makefile.in|1 +
 gcc/ada/ChangeLog  |   81 +
 gcc/ada/aspects.ads|6 +
 gcc/ada/bindusg.adb|2 +-
 gcc/ada/contracts.adb  |3 +
 gcc/ada/contracts.ads  |2 +
 .../doc/gnat_rm/implementation_defined_aspects.rst |6 +
 .../doc/gnat_rm/implementation_defined_pragmas.rst |   14 +
 .../building_executable_programs_with_gnat.rst |   29 +-
 gcc/ada/einfo-utils.adb|1 +
 gcc/ada/einfo-utils.ads|1 +
 gcc/ada/errout.ads |   18 +-
 gcc/ada/exp_aggr.adb   |2 +-
 gcc/ada/gcc-interface/trans.cc |2 +
 gcc/ada/gnat-style.texi|4 +-
 gcc/ada/gnat_rm.texi   | 1355 ++--
 gcc/ada/gnat_ugn.texi  |   41 +-
 gcc/ada/libgnat/s-imagef.adb   |   75 +-
 gcc/ada/libgnat/s-imguti.adb   |8 +
 gcc/ada/par-prag.adb   |1 +
 gcc/ada/sem_ch13.adb   |   17 +
 gcc/ada/sem_ch3.adb|8 +-
 gcc/ada/sem_ch6.adb|  103 +-
 gcc/ada/sem_ch6.ads|4 +
 gcc/ada/sem_prag.adb   |  305 +-
 gcc/ada/sem_prag.ads   |   54 +-
 gcc/ada/sem_util.adb   |   30 +
 gcc/ada/sem_util.ads   |4 +
 gcc/ada/snames.ads-tmpl|2 +
 gcc/builtins.def   |5 +
 gcc/c-family/ChangeLog |   22 +
 gcc/c-family/c-attribs.cc  |   22 +
 gcc/c-family/c-common.cc   |7 +-
 gcc/c-family/c-pragma.cc   |3 +-
 gcc/c-family/c-warn.cc |2 +-
 gcc/c/ChangeLog|   39 +
 gcc/c/c-decl.cc|3 +-
 gcc/c/c-typeck.cc  |   26 +-
 gcc/calls.cc   |3 +
 gcc/common.opt |   52 +-
 gcc/common/config/riscv/riscv-common.cc|6 +-
 gcc/config.gcc |   27 +-
 gcc/config/aarch64/aarch64.cc  |   24 +-
 gcc/config/aarch64/aarch64.md  |   22 +-
 gcc/config/aarch64/iterators.md|3 +
 gcc/config/gcn/gcn-hsa.h   |3 +-
 gcc/config/gcn/gcn-opts.h  |7 +-
 gcc/config/gcn/gcn-valu.md |   93 +-
 gcc/config/gcn/gcn.cc  |   24 +-
 gcc/config/gcn/gcn.h   |4 +
 gcc/config/gcn/gcn.md  |  130 +-
 gcc/config/gcn/gcn.opt |3 +
 gcc/config/gcn/mkoffload.cc|4 +
 gcc/config/gcn/t-gcn-hsa   |8 +-
 gcc/config/gcn/t-omp-device|2 +-
 gcc/config/i386/darwin.h   |6 +
 gcc/config/i386/i386-options.cc|   10 +-
 gcc/config/i386/i386.cc|2 +-
 gcc/config/i386/i386.h |   14 +-
 gcc/config/i386/i386.md|   15 +
 gcc/config/loongarch/genopts/loongarch.opt.in  |   15 +-
 gcc/config/loongarch/lasx.md   |  160 +-
 gcc/config/loongarch/loongarch-protos.h|1 +
 gcc/config/loongarch/loongarch.cc  |  310 +-
 gcc/config/loongarch/loongarch.md  |2 +
 gcc/config/loongarch/loongarch.opt |   15 +-
 gcc/config/loongarch/lsx.md|   78 +
 gcc/config/pru/pru.cc  |   36 +
 gcc/config/riscv/riscv-opts.h  |5 -
 gcc/config/riscv/riscv-protos.h|1 +
 gcc/config/riscv/riscv-selftests.cc|   14 +-
 gcc/config/riscv/riscv-v.cc|  141 +-
 gcc/config/riscv/riscv-vector-switch.def   |  188 +-
 gcc/config/riscv/riscv

[gcc/devel/rust/master] typecheck: Start using nr2.0 properly

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:a8b5f28aec56f355fe2db1e65d1cb380374f9ce2

commit a8b5f28aec56f355fe2db1e65d1cb380374f9ce2
Author: Arthur Cohen 
Date:   Thu Aug 24 17:51:21 2023 +0200

typecheck: Start using nr2.0 properly

Fetch the ImmutableNrCtx in order to access name resolver during
typechecking.

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): 
Start
fetching name resolution information in the typechecker.
* typecheck/rust-hir-type-check-type.cc 
(TypeCheckType::resolve_root_path):
Likewise.
* typecheck/rust-hir-type-check-path.cc: Use nr 2.0.

Diff:
---
 gcc/rust/typecheck/rust-hir-type-check-item.cc | 91 +-
 gcc/rust/typecheck/rust-hir-type-check-path.cc | 16 +++--
 gcc/rust/typecheck/rust-hir-type-check-type.cc | 24 +--
 3 files changed, 105 insertions(+), 26 deletions(-)

diff --git a/gcc/rust/typecheck/rust-hir-type-check-item.cc 
b/gcc/rust/typecheck/rust-hir-type-check-item.cc
index 4bbd28021a02..4ab946e1c2a1 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-item.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-item.cc
@@ -17,12 +17,17 @@
 // .
 
 #include "rust-hir-type-check-item.h"
+#include "rust-canonical-path.h"
+#include "rust-diagnostics.h"
 #include "rust-hir-type-check-enumitem.h"
 #include "rust-hir-type-check-implitem.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-trait-resolve.h"
+#include "rust-identifier.h"
+#include "rust-session-manager.h"
+#include "rust-immutable-name-resolution-context.h"
 #include "rust-substitution-mapper.h"
 #include "rust-type-util.h"
 #include "rust-tyty-variance-analysis.h"
@@ -185,11 +190,30 @@ TypeCheckItem::visit (HIR::TupleStruct _decl)
 }
 
   // get the path
-  const CanonicalPath *canonical_path = nullptr;
-  bool ok = mappings->lookup_canonical_path (
-struct_decl.get_mappings ().get_nodeid (), _path);
-  rust_assert (ok);
-  RustIdent ident{*canonical_path, struct_decl.get_locus ()};
+
+  auto path = CanonicalPath::create_empty ();
+
+  // FIXME: HACK: ARTHUR: Disgusting
+  if (flag_name_resolution_2_0)
+{
+  auto nr_ctx
+   = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+  auto canonical_path = nr_ctx.values.to_canonical_path (
+   struct_decl.get_mappings ().get_nodeid ());
+
+  path = canonical_path.value ();
+}
+  else
+{
+  const CanonicalPath *canonical_path = nullptr;
+  bool ok = mappings->lookup_canonical_path (
+   struct_decl.get_mappings ().get_nodeid (), _path);
+  rust_assert (ok);
+
+  path = *canonical_path;
+}
+
+  RustIdent ident{path, struct_decl.get_locus ()};
 
   // its a single variant ADT
   std::vector variants;
@@ -248,12 +272,29 @@ TypeCheckItem::visit (HIR::StructStruct _decl)
   context->insert_type (field.get_mappings (), ty_field->get_field_type 
());
 }
 
-  // get the path
-  const CanonicalPath *canonical_path = nullptr;
-  bool ok = mappings->lookup_canonical_path (
-struct_decl.get_mappings ().get_nodeid (), _path);
-  rust_assert (ok);
-  RustIdent ident{*canonical_path, struct_decl.get_locus ()};
+  auto path = CanonicalPath::create_empty ();
+
+  // FIXME: HACK: ARTHUR: Disgusting
+  if (flag_name_resolution_2_0)
+{
+  auto nr_ctx
+   = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+  auto canonical_path = nr_ctx.values.to_canonical_path (
+   struct_decl.get_mappings ().get_nodeid ());
+
+  path = canonical_path.value ();
+}
+  else
+{
+  const CanonicalPath *canonical_path = nullptr;
+  bool ok = mappings->lookup_canonical_path (
+   struct_decl.get_mappings ().get_nodeid (), _path);
+  rust_assert (ok);
+
+  path = *canonical_path;
+}
+
+  RustIdent ident{path, struct_decl.get_locus ()};
 
   // its a single variant ADT
   std::vector variants;
@@ -510,13 +551,29 @@ TypeCheckItem::visit (HIR::Function )
   TypeCheckPattern::Resolve (param.get_param_name ().get (), param_tyty);
 }
 
-  const CanonicalPath *canonical_path = nullptr;
-  bool ok
-= mappings->lookup_canonical_path (function.get_mappings ().get_nodeid (),
-  _path);
-  rust_assert (ok);
+  auto path = CanonicalPath::create_empty ();
+
+  // FIXME: HACK: ARTHUR: Disgusting
+  if (flag_name_resolution_2_0)
+{
+  auto nr_ctx
+   = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+  auto canonical_path = nr_ctx.values.to_canonical_path (
+   function.get_mappings ().get_nodeid ());
+
+  path = canonical_path.value ();
+}
+  else
+{
+  const CanonicalPath *canonical_path = nullptr;
+  bool ok = mappings->lookup_canonical_path (
+   function.get_mappings ().get_nodeid (), _path);
+  rust_assert (ok);
+
+ 

[gcc/devel/rust/master] session-manager: Dump name resolution pass.

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:111c4f0101191a767c8ed731323ab336eac33e84

commit 111c4f0101191a767c8ed731323ab336eac33e84
Author: Arthur Cohen 
Date:   Wed Aug 23 15:14:46 2023 +0200

session-manager: Dump name resolution pass.

gcc/rust/ChangeLog:

* rust-session-manager.cc: Add files for dumping name resolution, 
call
name resolution dump function.
(Session::dump_name_resolution): New.
* rust-session-manager.h: New declaration.

Diff:
---
 gcc/rust/rust-session-manager.cc | 30 +++---
 gcc/rust/rust-session-manager.h  |  1 +
 2 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/gcc/rust/rust-session-manager.cc b/gcc/rust/rust-session-manager.cc
index 40adeb20de49..64e0190f716d 100644
--- a/gcc/rust/rust-session-manager.cc
+++ b/gcc/rust/rust-session-manager.cc
@@ -69,6 +69,10 @@ const char *kASTDumpFile = "gccrs.ast.dump";
 const char *kASTPrettyDumpFile = "gccrs.ast-pretty.dump";
 const char *kASTPrettyDumpFileExpanded = "gccrs.ast-pretty-expanded.dump";
 const char *kASTExpandedDumpFile = "gccrs.ast-expanded.dump";
+const char *kASTmacroResolutionDumpFile = "gccrs.ast-macro-resolution.dump";
+const char *kASTlabelResolutionDumpFile = "gccrs.ast-label-resolution.dump";
+const char *kASTtypeResolutionDumpFile = "gccrs.ast-type-resolution.dump";
+const char *kASTvalueResolutionDumpFile = "gccrs.ast-value-resolution.dump";
 const char *kHIRDumpFile = "gccrs.hir.dump";
 const char *kHIRPrettyDumpFile = "gccrs.hir-pretty.dump";
 const char *kHIRTypeResolutionDumpFile = "gccrs.type-resolution.dump";
@@ -86,6 +90,7 @@ Session::get_instance ()
 
 static std::string
 infer_crate_name (const std::string )
+
 {
   if (filename == "-")
 return kDefaultCrateName;
@@ -626,9 +631,7 @@ Session::compile_crate (const char *filename)
 Resolver::NameResolution::Resolve (parsed_crate);
 
   if (options.dump_option_enabled (CompileOptions::RESOLUTION_DUMP))
-{
-  // TODO: what do I dump here? resolved names? AST with resolved names?
-}
+dump_name_resolution (name_resolution_ctx);
 
   if (saw_errors ())
 return;
@@ -982,6 +985,27 @@ Session::dump_ast_pretty (AST::Crate , bool 
expanded) const
   out.close ();
 }
 
+void
+Session::dump_name_resolution (Resolver2_0::NameResolutionContext ) const
+{
+  // YES this is ugly but NO GCC 4.8 does not allow us to make it fancier :(
+  std::string types_content = ctx.types.as_debug_string ();
+  std::ofstream types_stream{kASTtypeResolutionDumpFile};
+  types_stream << types_content;
+
+  std::string macros_content = ctx.macros.as_debug_string ();
+  std::ofstream macros_stream{kASTmacroResolutionDumpFile};
+  macros_stream << macros_content;
+
+  std::string labels_content = ctx.labels.as_debug_string ();
+  std::ofstream labels_stream{kASTlabelResolutionDumpFile};
+  labels_stream << labels_content;
+
+  std::string values_content = ctx.values.as_debug_string ();
+  std::ofstream values_stream{kASTvalueResolutionDumpFile};
+  values_stream << values_content;
+}
+
 void
 Session::dump_hir (HIR::Crate ) const
 {
diff --git a/gcc/rust/rust-session-manager.h b/gcc/rust/rust-session-manager.h
index 9a5691f45eeb..845b53ab6db1 100644
--- a/gcc/rust/rust-session-manager.h
+++ b/gcc/rust/rust-session-manager.h
@@ -396,6 +396,7 @@ private:
 
   void dump_lex (Parser ) const;
   void dump_ast_pretty (AST::Crate , bool expanded = false) const;
+  void dump_name_resolution (Resolver2_0::NameResolutionContext ) const;
   void dump_hir (HIR::Crate ) const;
   void dump_hir_pretty (HIR::Crate ) const;


[gcc/devel/rust/master] late: Add bool builtin type

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:5f117eec558feb301162b128fb6b613a8c842886

commit 5f117eec558feb301162b128fb6b613a8c842886
Author: Arthur Cohen 
Date:   Thu Nov 9 00:39:46 2023 +0100

late: Add bool builtin type

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc 
(Late::setup_builtin_types):
Setup bool as builtin type.

Diff:
---
 gcc/rust/resolve/rust-late-name-resolver-2.0.cc | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc 
b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
index 3090bbeff2a9..ee06c4efc2ea 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
@@ -64,6 +64,7 @@ Late::setup_builtin_types ()
   };
 
   static const LType builtins[] = {
+{LType ("bool", new TyTy::BoolType (next_hir_id ()))},
 {LType ("u8", new TyTy::UintType (next_hir_id (), TyTy::UintType::U8))},
 {LType ("u16", new TyTy::UintType (next_hir_id (), TyTy::UintType::U16))},
 {LType ("u32", new TyTy::UintType (next_hir_id (), TyTy::UintType::U32))},


[gcc/devel/rust/master] Merge commit '2f334bb12e3ba947714771408b9d49d398abb5df' into HEAD

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:f3f2065910a02b0099d3d5f2ad3389d0e479c782

commit f3f2065910a02b0099d3d5f2ad3389d0e479c782
Merge: 8c40edc1a2fb 2f334bb12e3b
Author: Thomas Schwinge 
Date:   Sun Mar 24 23:37:24 2024 +0100

Merge commit '2f334bb12e3ba947714771408b9d49d398abb5df' into HEAD

Diff:

 .github/workflows/ccpp.yml |  24 +-
 README.md  |   2 +-
 gcc/rust/Make-lang.in  |  13 +-
 gcc/rust/ast/rust-ast-builder.cc   |  66 +-
 gcc/rust/ast/rust-ast-builder.h|  51 +-
 gcc/rust/ast/rust-builtin-ast-nodes.h  |   5 +
 gcc/rust/ast/rust-fmt.cc   |  32 +-
 gcc/rust/ast/rust-fmt.h|  46 +-
 gcc/rust/expand/rust-cfg-strip.h   |   4 +
 gcc/rust/expand/rust-derive.cc |   4 +-
 gcc/rust/expand/rust-derive.h  |   2 +-
 gcc/rust/expand/rust-expand-format-args.cc | 138 +++
 gcc/rust/expand/rust-expand-format-args.h  |  35 +
 gcc/rust/expand/rust-macro-builtins-asm.cc |  20 +
 gcc/rust/expand/rust-macro-builtins-format-args.cc | 192 
 gcc/rust/expand/rust-macro-builtins-helpers.cc | 284 ++
 gcc/rust/expand/rust-macro-builtins-helpers.h  |  90 ++
 gcc/rust/expand/rust-macro-builtins-include.cc | 249 ++
 gcc/rust/expand/rust-macro-builtins-location.cc|  61 ++
 gcc/rust/expand/rust-macro-builtins-log-debug.cc   |  31 +
 gcc/rust/expand/rust-macro-builtins-test-bench.cc  |  20 +
 gcc/rust/expand/rust-macro-builtins-trait.cc   |  20 +
 gcc/rust/expand/rust-macro-builtins-utility.cc | 294 +++
 gcc/rust/expand/rust-macro-builtins.cc | 967 +
 gcc/rust/expand/rust-macro-builtins.h  |  79 +-
 gcc/rust/hir/rust-ast-lower-expr.cc|   4 -
 gcc/rust/hir/rust-ast-lower-extern.h   |   4 +-
 gcc/rust/hir/tree/rust-hir-item.h  |   4 +-
 gcc/rust/resolve/rust-ast-resolve-base.cc  |   5 +-
 gcc/rust/rust-session-manager.cc   |   3 +
 gcc/rust/typecheck/rust-hir-type-check-item.cc |  17 +-
 gcc/rust/typecheck/rust-hir-type-check.h   |   6 +
 gcc/rust/typecheck/rust-typecheck-context.cc   |   6 +
 gcc/rust/typecheck/rust-tyty-subst.cc  |  11 +
 .../rust-tyty-variance-analysis-private.h  | 304 +++
 gcc/rust/typecheck/rust-tyty-variance-analysis.cc  | 541 
 gcc/rust/typecheck/rust-tyty-variance-analysis.h   | 114 +++
 .../rust/compile/format_args_basic_expansion.rs|  47 +
 libgrust/libformat_parser/src/lib.rs   | 105 ++-
 39 files changed, 2778 insertions(+), 1122 deletions(-)


[gcc/devel/rust/master] Prevent error emission on resolver reentry

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:f88db85c0272c3f25d2638565d5f6647b64363e5

commit f88db85c0272c3f25d2638565d5f6647b64363e5
Author: Pierre-Emmanuel Patry 
Date:   Mon Sep 18 15:34:24 2023 +0200

Prevent error emission on resolver reentry

The resolver was emitting an error when meeting the same symbol twice.
What is important here is the origin of the resolved symbol, we should
emit an error when the name is similar but the symbol isn't be not when
the resolver is simply meeting the exact same symbol.

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc (insert_macros): Add
constraint over the ast node id.
(TopLevel::visit): Likewise.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc 
b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
index 72c3560b9daf..3b1ccc1d3c50 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
@@ -91,7 +91,7 @@ insert_macros (std::vector , 
NameResolutionContext )
 {
   auto res = ctx.macros.insert (macro.get_name (), macro.get_node_id ());
 
-  if (!res)
+  if (!res && res.error ().existing != macro.get_node_id ())
{
  rust_error_at (UNKNOWN_LOCATION, ErrorCode::E0428,
 "macro %qs defined multiple times",
@@ -167,7 +167,7 @@ TopLevel::visit (AST::MacroRulesDefinition )
 {
   auto res = ctx.macros.insert_at_root (macro.get_rule_name (),
macro.get_node_id ());
-  if (!res)
+  if (!res && res.error ().existing != macro.get_node_id ())
{
  // TODO: Factor this
  rich_location rich_loc (line_table, macro.get_locus ());


[gcc/devel/rust/master] Merge commit '7439f40dc17f47480620beadf5b2f5784b59aefe' into HEAD [#1543]

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:2cd7fb664ce9617c90b65b399423d330e1a78068

commit 2cd7fb664ce9617c90b65b399423d330e1a78068
Merge: ec26db53513f 7439f40dc17f
Author: Thomas Schwinge 
Date:   Mon Mar 11 01:05:15 2024 +0100

Merge commit '7439f40dc17f47480620beadf5b2f5784b59aefe' into HEAD [#1543]

Diff:


[gcc/devel/rust/master] Fix duplicate detection

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:6d4c2c9f5dd200f26d152ab8c170a930591d11ad

commit 6d4c2c9f5dd200f26d152ab8c170a930591d11ad
Author: Pierre-Emmanuel Patry 
Date:   Thu Sep 14 17:39:37 2023 +0200

Fix duplicate detection

The resolver did report duplicate symbols when being run multiple times
even if the node id was the same. This commit adds an additional
condition, the error will only be reported if the existing node id is
different from the current node id.

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc 
(TopLevel::insert_or_error_out):
Add new constraint to duplicate errors.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc 
b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
index 446a1c6a41b1..407892bb7bbd 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
@@ -47,11 +47,8 @@ TopLevel::insert_or_error_out (const Identifier ,
 
   auto result = ctx.insert (identifier, node_id, ns);
 
-  if (!result)
+  if (!result && result.error ().existing != node_id)
 {
-  // can we do something like check if the node id is the same? if it is 
the
-  // same, it's not an error, just the resolver running multiple times?
-
   rich_location rich_loc (line_table, locus);
   rich_loc.add_range (node_locations[result.error ().existing]);


[gcc/devel/rust/master] late: Setup builtin types properly, change Rib API

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:a62e1c60026ed8b7c3616c030e45377cac114609

commit a62e1c60026ed8b7c3616c030e45377cac114609
Author: Arthur Cohen 
Date:   Mon Aug 28 16:40:12 2023 +0200

late: Setup builtin types properly, change Rib API

gcc/rust/ChangeLog:

* resolve/rust-forever-stack.hxx: Start using Rib::Definition for
shadowable information.
* resolve/rust-late-name-resolver-2.0.cc (next_node_id): New.
(next_hir_id): New.
(Late::setup_builtin_types): Improve builtin type setup.
* resolve/rust-rib.cc (Rib::Definition::Definition): New 
constructor.
(Rib::Definition::Shadowable): Likewise.
(Rib::Definition::NonShadowable): Likewise.
(Rib::Rib): Fix general constructor.
(Rib::insert): Use Definition class.
(Rib::get): Likewise.
* resolve/rust-rib.h: New Definition class, new prototypes.

Diff:
---
 gcc/rust/resolve/rust-forever-stack.hxx | 22 ---
 gcc/rust/resolve/rust-late-name-resolver-2.0.cc | 84 ++---
 gcc/rust/resolve/rust-rib.cc| 38 ---
 gcc/rust/resolve/rust-rib.h | 30 +++--
 4 files changed, 126 insertions(+), 48 deletions(-)

diff --git a/gcc/rust/resolve/rust-forever-stack.hxx 
b/gcc/rust/resolve/rust-forever-stack.hxx
index 0aa9943191e8..a2fdce983629 100644
--- a/gcc/rust/resolve/rust-forever-stack.hxx
+++ b/gcc/rust/resolve/rust-forever-stack.hxx
@@ -100,9 +100,9 @@ ForeverStack::pop ()
 }
 
 static tl::expected
-insert_inner (Rib , std::string name, NodeId node, bool can_shadow)
+insert_inner (Rib , std::string name, Rib::Definition definition)
 {
-  return rib.insert (name, node, can_shadow);
+  return rib.insert (name, definition);
 }
 
 template 
@@ -115,7 +115,8 @@ ForeverStack::insert (Identifier name, NodeId node)
   // pass, we might end up in a situation where it is okay to re-add new names.
   // Do we just ignore that here? Do we keep track of if the Rib is new or not?
   // should our cursor have info on the current node like "is it newly pushed"?
-  return insert_inner (innermost_rib, name.as_string (), node, false);
+  return insert_inner (innermost_rib, name.as_string (),
+  Rib::Definition::NonShadowable (node));
 }
 
 template 
@@ -126,7 +127,8 @@ ForeverStack::insert_at_root (Identifier name, NodeId 
node)
 
   // inserting in the root of the crate is never a shadowing operation, even 
for
   // macros
-  return insert_inner (root_rib, name.as_string (), node, false);
+  return insert_inner (root_rib, name.as_string (),
+  Rib::Definition::NonShadowable (node));
 }
 
 // Specialization for Macros and Labels - where we are allowed to shadow
@@ -135,14 +137,16 @@ template <>
 inline tl::expected
 ForeverStack::insert (Identifier name, NodeId node)
 {
-  return insert_inner (peek (), name.as_string (), node, true);
+  return insert_inner (peek (), name.as_string (),
+  Rib::Definition::Shadowable (node));
 }
 
 template <>
 inline tl::expected
 ForeverStack::insert (Identifier name, NodeId node)
 {
-  return insert_inner (peek (), name.as_string (), node, true);
+  return insert_inner (peek (), name.as_string (),
+  Rib::Definition::Shadowable (node));
 }
 
 template 
@@ -455,10 +459,10 @@ template 
 tl::optional::Node &, std::string>>
 ForeverStack::dfs (ForeverStack::Node _point, NodeId to_find)
 {
-  auto  = starting_point.rib.get_values ();
+  auto values = starting_point.rib.get_values ();
 
   for (auto  : values)
-if (kv.second == to_find)
+if (kv.second.id == to_find)
   return {{starting_point, kv.first}};
 
   for (auto  : starting_point.children)
@@ -568,7 +572,7 @@ ForeverStack::stream_rib (std::stringstream , 
const Rib ,
   stream << next << "rib: {\n";
 
   for (const auto  : rib.get_values ())
-stream << next_next << kv.first << ": " << kv.second << "\n";
+stream << next_next << kv.first << ": " << kv.second.id << "\n";
 
   stream << next << "},\n";
 }
diff --git a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc 
b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
index 50034073edfe..3090bbeff2a9 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
@@ -18,8 +18,10 @@
 
 #include "optional.h"
 #include "rust-ast-full.h"
+#include "rust-hir-map.h"
 #include "rust-late-name-resolver-2.0.h"
 #include "rust-default-resolver.h"
+#include "rust-name-resolution-context.h"
 #include "rust-path.h"
 #include "rust-tyty.h"
 #include "rust-hir-type-check.h"
@@ -29,41 +31,75 @@ namespace Resolver2_0 {
 
 Late::Late (NameResolutionContext ) : DefaultResolver (ctx) {}
 
+static NodeId
+next_node_id ()
+{
+  return Analysis::Mappings::get ()->get_next_node_id ();
+};
+
+static HirId
+next_hir_id ()
+{
+  return Analysis::Mappings::get ()->get_next_hir_id ();
+};
+
 void
 

[gcc/devel/rust/master] Merge commit 'cde6f1085b7027f6a42fdb71c786d422606a8765^' into HEAD

2024-05-07 Thread Thomas Schwinge via Libstdc++-cvs
https://gcc.gnu.org/g:000c6d0a37b729c62d89f924bd6152b593bd39b9

commit 000c6d0a37b729c62d89f924bd6152b593bd39b9
Merge: 59bc3e7924ed 78dff4c25c1b
Author: Thomas Schwinge 
Date:   Fri Mar 22 09:58:02 2024 +0100

Merge commit 'cde6f1085b7027f6a42fdb71c786d422606a8765^' into HEAD

Diff:

 contrib/ChangeLog  |   25 +
 contrib/analyze_brprob.py  |2 +-
 contrib/analyze_brprob_spec.py |2 +-
 contrib/check-params-in-docs.py|2 +-
 contrib/check_GNU_style.py |2 +-
 contrib/check_GNU_style_lib.py |2 +-
 contrib/filter-clang-warnings.py   |2 +-
 contrib/gcc-changelog/git_check_commit.py  |2 +-
 contrib/gcc-changelog/git_commit.py|2 +-
 contrib/gcc-changelog/git_email.py |2 +-
 contrib/gcc-changelog/git_repository.py|2 +-
 contrib/gcc-changelog/git_update_version.py|2 +-
 contrib/gcc-changelog/test_email.py|2 +-
 contrib/gen_autofdo_event.py   |2 +-
 contrib/mark_spam.py   |2 +-
 contrib/unicode/GraphemeBreakProperty.txt  | 1475 
 contrib/unicode/README |   12 +-
 contrib/unicode/emoji-data.txt | 1320 ++
 contrib/unicode/gen-box-drawing-chars.py   |2 +-
 contrib/unicode/gen-combining-chars.py |2 +-
 contrib/unicode/gen-printable-chars.py |2 +-
 contrib/unicode/gen_libstdcxx_unicode_data.py  |  222 +++
 contrib/unicode/gen_wcwidth.py |4 +-
 gcc/ChangeLog  |  596 
 gcc/DATESTAMP  |2 +-
 gcc/ada/ChangeLog  |5 +
 gcc/analyzer/ChangeLog |   33 +
 gcc/asan.cc|6 +-
 gcc/c-family/ChangeLog |4 +
 gcc/config/aarch64/aarch64-ldp-fusion.cc   |9 +
 gcc/config/aarch64/aarch64.cc  |   15 +-
 gcc/config/aarch64/aarch64.opt |7 +-
 gcc/config/alpha/alpha.cc  |5 +-
 gcc/config/arm/aout.h  |2 +-
 gcc/config/arm/arm.cc  |2 +-
 gcc/config/arm/neon.md |   49 +
 gcc/config/bfin/bfin.h |   16 +-
 gcc/config/c6x/c6x.h   |2 +-
 gcc/config/gcn/gcn.cc  |5 +-
 gcc/config/gcn/mkoffload.cc|   52 +-
 gcc/config/h8300/h8300.h   |2 +-
 gcc/config/i386/i386-features.cc   |  364 ++---
 gcc/config/i386/i386.cc|2 +-
 gcc/config/i386/i386.opt   |3 +-
 gcc/config/ia64/ia64.cc|5 +-
 gcc/config/loongarch/lasx.md   |   35 +-
 gcc/config/loongarch/loongarch.cc  |   19 +-
 gcc/config/loongarch/lsx.md|   26 -
 gcc/config/loongarch/predicates.md |   16 -
 gcc/config/mcore/mcore-elf.h   |2 +-
 gcc/config/microblaze/microblaze.cc|3 +-
 gcc/config/mips/mips.cc|   19 +-
 gcc/config/pa/pa.cc|3 +-
 gcc/config/riscv/riscv-protos.h|1 +
 gcc/config/riscv/riscv-v.cc|   28 +-
 gcc/config/riscv/riscv-vector-costs.cc |   63 +-
 gcc/config/riscv/riscv-vsetvl.cc   |   21 +-
 gcc/config/riscv/riscv.cc  |2 +-
 gcc/config/riscv/vector.md |   13 +-
 gcc/config/rs6000/rs6000.cc|4 +-
 gcc/config/s390/s390.cc|2 +-
 gcc/cp/ChangeLog   |   22 +
 gcc/cp/module.cc   |9 +-
 gcc/cp/parser.cc   |  100 +-
 gcc/d/ChangeLog|5 +
 gcc/defaults.h |2 +-
 gcc/doc/extend.texi|6 +
 gcc/doc/invoke.texi|   25 +-
 gcc/final.cc   |3 -
 gcc/fortran/ChangeLog  |   12 +
 gcc/fortran/iresolve.cc|   10 +-
 gcc/gimple-match-head.cc   |   20 +-
 gcc/go/ChangeLog   |5 +
 gcc/internal-fn.cc |   15 +-
 gcc/lto/ChangeLog  |5 +
 gcc/m2/ChangeLog

[gcc/devel/rust/master] nr2.0: Start using newtype pattern for Usage and Declaration

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:81f2edc5d1fcc82196e2831fe1222d7d04dcb2b2

commit 81f2edc5d1fcc82196e2831fe1222d7d04dcb2b2
Author: Arthur Cohen 
Date:   Thu Sep 14 17:38:06 2023 +0200

nr2.0: Start using newtype pattern for Usage and Declaration

gcc/rust/ChangeLog:

* resolve/rust-name-resolution-context.cc 
(NameResolutionContext::map_usage):
Use newtype pattern.
(NameResolutionContext::lookup): Likewise.
* resolve/rust-name-resolution-context.h (class Usage): New class.
(class Definition): Likewise.
* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Create 
instances
of Usage and Definition.

Diff:
---
 gcc/rust/resolve/rust-late-name-resolver-2.0.cc  |  4 ++--
 gcc/rust/resolve/rust-name-resolution-context.cc |  6 +++---
 gcc/rust/resolve/rust-name-resolution-context.h  | 27 ++--
 3 files changed, 30 insertions(+), 7 deletions(-)

diff --git a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc 
b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
index e5a4f2348712..50034073edfe 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
@@ -142,7 +142,7 @@ Late::visit (AST::IdentifierExpr )
   return;
 }
 
-  ctx.map_usage (expr.get_node_id (), *resolved);
+  ctx.map_usage (Usage (expr.get_node_id ()), Definition (*resolved));
 
   // in the old resolver, resolutions are kept in the resolver, not the 
mappings
   // :/ how do we deal with that?
@@ -173,7 +173,7 @@ Late::visit (AST::TypePath )
 
   auto resolved = ctx.types.get (type.get_segments ().back ()->as_string ());
 
-  ctx.map_usage (type.get_node_id (), *resolved);
+  ctx.map_usage (Usage (type.get_node_id ()), Definition (*resolved));
 }
 
 } // namespace Resolver2_0
diff --git a/gcc/rust/resolve/rust-name-resolution-context.cc 
b/gcc/rust/resolve/rust-name-resolution-context.cc
index 9fd8d52968a8..0340d28f1278 100644
--- a/gcc/rust/resolve/rust-name-resolution-context.cc
+++ b/gcc/rust/resolve/rust-name-resolution-context.cc
@@ -46,7 +46,7 @@ NameResolutionContext::insert (Identifier name, NodeId id, 
Namespace ns)
 }
 
 void
-NameResolutionContext::map_usage (NodeId usage, NodeId definition)
+NameResolutionContext::map_usage (Usage usage, Definition definition)
 {
   auto inserted = resolved_nodes.emplace (usage, definition).second;
 
@@ -57,12 +57,12 @@ NameResolutionContext::map_usage (NodeId usage, NodeId 
definition)
 tl::optional
 NameResolutionContext::lookup (NodeId usage)
 {
-  auto it = resolved_nodes.find (usage);
+  auto it = resolved_nodes.find (Usage (usage));
 
   if (it == resolved_nodes.end ())
 return tl::nullopt;
 
-  return it->second;
+  return it->second.id;
 }
 
 void
diff --git a/gcc/rust/resolve/rust-name-resolution-context.h 
b/gcc/rust/resolve/rust-name-resolution-context.h
index e896ca053608..8702900d0f3a 100644
--- a/gcc/rust/resolve/rust-name-resolution-context.h
+++ b/gcc/rust/resolve/rust-name-resolution-context.h
@@ -133,6 +133,28 @@ change?
 correct
 */
 
+// FIXME: Documentation
+class Usage
+{
+public:
+  explicit Usage (NodeId id) : id (id) {}
+
+  // TODO: move to name-resolution-ctx.cc
+  // storing it as a key in a map
+  bool operator< (const Usage other) const { return other.id < id; }
+
+  NodeId id;
+};
+
+// FIXME: Documentation
+class Definition
+{
+public:
+  explicit Definition (NodeId id) : id (id) {}
+
+  NodeId id;
+};
+
 // Now our resolver, which keeps track of all the `ForeverStack`s we could want
 class NameResolutionContext
 {
@@ -182,12 +204,13 @@ public:
 
   // TODO: Rename
   // TODO: Use newtype pattern for Usage and Definition
-  void map_usage (NodeId usage, NodeId definition);
+  void map_usage (Usage usage, Definition definition);
+
   tl::optional lookup (NodeId usage);
 
 private:
   /* Map of "usage" nodes which have been resolved to a "definition" node */
-  std::map resolved_nodes;
+  std::map resolved_nodes;
 };
 
 } // namespace Resolver2_0


[gcc/devel/rust/master] backend: Use new name resolver where necessary

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:fd2ec3a52bba6f0232451143eecf19a3933f6ee0

commit fd2ec3a52bba6f0232451143eecf19a3933f6ee0
Author: Arthur Cohen 
Date:   Fri Aug 25 14:33:36 2023 +0200

backend: Use new name resolver where necessary

gcc/rust/ChangeLog:

* backend/rust-compile-base.cc: Use new ImmutableNrCtx.
* backend/rust-compile-context.h: Likewise.
* backend/rust-compile-expr.cc: Likewise.
* backend/rust-compile-item.cc: Likewise.

Diff:
---
 gcc/rust/backend/rust-compile-base.cc   |  1 +
 gcc/rust/backend/rust-compile-context.h |  1 +
 gcc/rust/backend/rust-compile-expr.cc   | 22 +-
 gcc/rust/backend/rust-compile-item.cc   | 31 +--
 4 files changed, 44 insertions(+), 11 deletions(-)

diff --git a/gcc/rust/backend/rust-compile-base.cc 
b/gcc/rust/backend/rust-compile-base.cc
index 4d6f0275b004..584d6a03ea95 100644
--- a/gcc/rust/backend/rust-compile-base.cc
+++ b/gcc/rust/backend/rust-compile-base.cc
@@ -31,6 +31,7 @@
 #include "rust-type-util.h"
 #include "rust-compile-implitem.h"
 #include "rust-attribute-values.h"
+#include "rust-immutable-name-resolution-context.h"
 
 #include "fold-const.h"
 #include "stringpool.h"
diff --git a/gcc/rust/backend/rust-compile-context.h 
b/gcc/rust/backend/rust-compile-context.h
index 36a36e79f680..671aee196c2a 100644
--- a/gcc/rust/backend/rust-compile-context.h
+++ b/gcc/rust/backend/rust-compile-context.h
@@ -27,6 +27,7 @@
 #include "rust-hir-full.h"
 #include "rust-mangle.h"
 #include "rust-tree.h"
+#include "rust-immutable-name-resolution-context.h"
 
 namespace Rust {
 namespace Compile {
diff --git a/gcc/rust/backend/rust-compile-expr.cc 
b/gcc/rust/backend/rust-compile-expr.cc
index 65de24bf9d8c..6a9bb73ffe0f 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -2311,11 +2311,23 @@ CompileExpr::generate_closure_function 
(HIR::ClosureExpr ,
   if (is_block_expr)
 {
   auto body_mappings = function_body->get_mappings ();
-  Resolver::Rib *rib = nullptr;
-  bool ok
-   = ctx->get_resolver ()->find_name_rib (body_mappings.get_nodeid (),
-  );
-  rust_assert (ok);
+  if (flag_name_resolution_2_0)
+   {
+ auto nr_ctx
+   = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+
+ auto candidate = nr_ctx.values.to_rib (body_mappings.get_nodeid ());
+
+ rust_assert (candidate.has_value ());
+   }
+  else
+   {
+ Resolver::Rib *rib = nullptr;
+ bool ok
+   = ctx->get_resolver ()->find_name_rib (body_mappings.get_nodeid (),
+  );
+ rust_assert (ok);
+   }
 }
 
   tree enclosing_scope = NULL_TREE;
diff --git a/gcc/rust/backend/rust-compile-item.cc 
b/gcc/rust/backend/rust-compile-item.cc
index 234ad2aa59c1..8feed51efa4f 100644
--- a/gcc/rust/backend/rust-compile-item.cc
+++ b/gcc/rust/backend/rust-compile-item.cc
@@ -19,6 +19,7 @@
 #include "rust-compile-item.h"
 #include "rust-compile-implitem.h"
 #include "rust-compile-extern.h"
+#include "rust-immutable-name-resolution-context.h"
 
 namespace Rust {
 namespace Compile {
@@ -149,12 +150,30 @@ CompileItem::visit (HIR::Function )
}
 }
 
-  const Resolver::CanonicalPath *canonical_path = nullptr;
-  bool ok = ctx->get_mappings ()->lookup_canonical_path (
-function.get_mappings ().get_nodeid (), _path);
-  rust_assert (ok);
+  Resolver::CanonicalPath canonical_path
+= Resolver::CanonicalPath::create_empty ();
+
+  if (flag_name_resolution_2_0)
+{
+  auto nr_ctx
+   = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+
+  auto path = nr_ctx.values.to_canonical_path (
+   function.get_mappings ().get_nodeid ());
+
+  canonical_path = path.value ();
+}
+  else
+{
+  const Resolver::CanonicalPath *path = nullptr;
+  bool ok = ctx->get_mappings ()->lookup_canonical_path (
+   function.get_mappings ().get_nodeid (), );
+  rust_assert (ok);
+
+  canonical_path = *path;
+}
 
-  const std::string asm_name = ctx->mangle_item (fntype, *canonical_path);
+  const std::string asm_name = ctx->mangle_item (fntype, canonical_path);
 
   // items can be forward compiled which means we may not need to invoke this
   // code. We might also have already compiled this generic function as well.
@@ -181,7 +200,7 @@ CompileItem::visit (HIR::Function )
function.get_function_params (),
function.get_qualifiers (), function.get_visibility (),
function.get_outer_attrs (), function.get_locus (),
-   function.get_definition ().get (), canonical_path,
+   function.get_definition ().get (), _path,
fntype);
   reference = address_expression (fndecl, ref_locus);


[gcc/devel/rust/master] fixed README.md , dump ast using correct option

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:f568f3b3e292892c2804c4596151ae11b5ef8c97

commit f568f3b3e292892c2804c4596151ae11b5ef8c97
Author: zhanghe9702 
Date:   Sat Mar 16 12:25:28 2024 +0800

fixed README.md , dump ast using correct option

ChangeLog:

* README.md: remove error dump option.

Signed-off-by: Zhang He 

Diff:
---
 README.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/README.md b/README.md
index bc977c2f5779..31df8df5138a 100644
--- a/README.md
+++ b/README.md
@@ -80,7 +80,7 @@ $ make
 Running the compiler itself without make install we can simply invoke the 
compiler proper:
 
 ```bash
-$ ./gcc/crab1 test.rs -frust-debug -frust-dump-parse -Warray-bounds -dumpbase 
test.rs -mtune=generic -march=x86-64 -O0 -version -fdump-tree-gimple -o test.s 
-L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu 
-L/usr/lib/../lib64 -frust-incomplete-and-experimental-compiler-do-not-use
+$ ./gcc/crab1 test.rs -frust-debug -frust-dump-ast-pretty -Warray-bounds 
-dumpbase test.rs -mtune=generic -march=x86-64 -O0 -version -fdump-tree-gimple 
-o test.s -L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu 
-L/usr/lib/../lib64 -frust-incomplete-and-experimental-compiler-do-not-use
 ```
 
 To invoke the compiler driver (gccrs) we need to:


[gcc/devel/rust/master] Merge commit 'af91934c2f6b8efc67d625c99068b4761ae5edd0' into HEAD

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:a88f4804345de28d0e3ea79fb7c1acb28a7fe453

commit a88f4804345de28d0e3ea79fb7c1acb28a7fe453
Merge: 7f7da6c240f2 af91934c2f6b
Author: Thomas Schwinge 
Date:   Mon Mar 11 00:56:06 2024 +0100

Merge commit 'af91934c2f6b8efc67d625c99068b4761ae5edd0' into HEAD

Diff:


[gcc/devel/rust/master] session manager: Init Immutable name resolver.

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:3f04e827803eabcbdec1bd9d92d653da895f0c9f

commit 3f04e827803eabcbdec1bd9d92d653da895f0c9f
Author: Arthur Cohen 
Date:   Thu Aug 24 17:50:45 2023 +0200

session manager: Init Immutable name resolver.

gcc/rust/ChangeLog:

* rust-session-manager.cc (Session::compile_crate): Create an 
immutable
view of the name resolution context.

Diff:
---
 gcc/rust/rust-session-manager.cc | 4 
 1 file changed, 4 insertions(+)

diff --git a/gcc/rust/rust-session-manager.cc b/gcc/rust/rust-session-manager.cc
index 64e0190f716d..1c7e2766d710 100644
--- a/gcc/rust/rust-session-manager.cc
+++ b/gcc/rust/rust-session-manager.cc
@@ -18,6 +18,7 @@
 
 #include "rust-session-manager.h"
 #include "rust-diagnostics.h"
+#include "rust-immutable-name-resolution-context.h"
 #include "rust-unsafe-checker.h"
 #include "rust-lex.h"
 #include "rust-parse.h"
@@ -659,6 +660,9 @@ Session::compile_crate (const char *filename)
   if (last_step == CompileOptions::CompileStep::TypeCheck)
 return;
 
+  // name resolution is done, we now freeze the name resolver for type checking
+  Resolver2_0::ImmutableNameResolutionContext::init (name_resolution_ctx);
+
   // type resolve
   Resolver::TypeResolution::Resolve (hir);


[gcc/devel/rust/master] format-args: Add basic test case

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:b4de854a5396909fe8ad757676dbaf4957c3194f

commit b4de854a5396909fe8ad757676dbaf4957c3194f
Author: Arthur Cohen 
Date:   Thu Feb 29 16:09:23 2024 +0100

format-args: Add basic test case

gcc/testsuite/ChangeLog:

* rust/compile/format_args_basic_expansion.rs: New test.

Diff:
---
 .../rust/compile/format_args_basic_expansion.rs| 47 ++
 1 file changed, 47 insertions(+)

diff --git a/gcc/testsuite/rust/compile/format_args_basic_expansion.rs 
b/gcc/testsuite/rust/compile/format_args_basic_expansion.rs
new file mode 100644
index ..40bcd3c1433e
--- /dev/null
+++ b/gcc/testsuite/rust/compile/format_args_basic_expansion.rs
@@ -0,0 +1,47 @@
+#![feature(rustc_attrs)]
+
+#[rustc_builtin_macro]
+macro_rules! format_args {
+() => {};
+}
+
+#[lang = "sized"]
+trait Sized {}
+
+pub mod core {
+pub mod fmt {
+pub struct Formatter;
+pub struct Result;
+
+pub struct Arguments<'a>;
+
+impl<'a> Arguments<'a> {
+pub fn new_v1(_: &'a [&'static str], _: &'a [ArgumentV1<'a>]) -> 
Arguments<'a> {
+Arguments
+}
+}
+
+pub struct ArgumentV1<'a>;
+
+impl<'a> ArgumentV1<'a> {
+pub fn new<'b, T>(_: &'b T, _: fn(,  Formatter) -> Result) 
-> ArgumentV1 {
+ArgumentV1
+}
+}
+
+pub trait Display {
+fn fmt(, _:  Formatter) -> Result;
+}
+
+impl Display for i32 {
+fn fmt(, _:  Formatter) -> Result {
+// { dg-warning "unused name .self." "" { target *-*-* } .-1 }
+Result
+}
+}
+}
+}
+
+fn main() {
+let _formatted = format_args!("hello {}", 15);
+}


[gcc/devel/rust/master] sesh: Add late name resolution 2.0

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:b281eb02d4caeadf087c37c3312039aa45c75da9

commit b281eb02d4caeadf087c37c3312039aa45c75da9
Author: Arthur Cohen 
Date:   Fri Aug 4 11:11:13 2023 +0200

sesh: Add late name resolution 2.0

gcc/rust/ChangeLog:

* rust-session-manager.cc (Session::compile_crate): Create name 
resolution
context for Session::expansion and subsequent name resolution 
passes.
(Session::expansion): Take name resolution context as a parameter
instead.
* rust-session-manager.h (Session::expansion): Fix declaration.

Diff:
---
 gcc/rust/rust-session-manager.cc | 14 +-
 gcc/rust/rust-session-manager.h  |  3 ++-
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/gcc/rust/rust-session-manager.cc b/gcc/rust/rust-session-manager.cc
index ea99d019f64f..40adeb20de49 100644
--- a/gcc/rust/rust-session-manager.cc
+++ b/gcc/rust/rust-session-manager.cc
@@ -42,6 +42,7 @@
 #include "rust-early-name-resolver.h"
 #include "rust-name-resolution-context.h"
 #include "rust-early-name-resolver-2.0.h"
+#include "rust-late-name-resolver-2.0.h"
 #include "rust-cfg-strip.h"
 #include "rust-expand-visitor.h"
 #include "rust-unicode.h"
@@ -591,8 +592,10 @@ Session::compile_crate (const char *filename)
   if (last_step == CompileOptions::CompileStep::Expansion)
 return;
 
+  auto name_resolution_ctx = Resolver2_0::NameResolutionContext ();
   // expansion pipeline stage
-  expansion (parsed_crate);
+
+  expansion (parsed_crate, name_resolution_ctx);
   rust_debug ("\033[0;31mSUCCESSFULLY FINISHED EXPANSION \033[0m");
   if (options.dump_option_enabled (CompileOptions::EXPANSION_DUMP))
 {
@@ -617,7 +620,10 @@ Session::compile_crate (const char *filename)
 return;
 
   // resolution pipeline stage
-  Resolver::NameResolution::Resolve (parsed_crate);
+  if (flag_name_resolution_2_0)
+Resolver2_0::Late (name_resolution_ctx).go (parsed_crate);
+  else
+Resolver::NameResolution::Resolve (parsed_crate);
 
   if (options.dump_option_enabled (CompileOptions::RESOLUTION_DUMP))
 {
@@ -881,7 +887,7 @@ Session::injection (AST::Crate )
 }
 
 void
-Session::expansion (AST::Crate )
+Session::expansion (AST::Crate , Resolver2_0::NameResolutionContext )
 {
   rust_debug ("started expansion");
 
@@ -908,8 +914,6 @@ Session::expansion (AST::Crate )
   if (saw_errors ())
break;
 
-  auto ctx = Resolver2_0::NameResolutionContext ();
-
   if (flag_name_resolution_2_0)
{
  Resolver2_0::Early early (ctx);
diff --git a/gcc/rust/rust-session-manager.h b/gcc/rust/rust-session-manager.h
index 41aad6079058..9a5691f45eeb 100644
--- a/gcc/rust/rust-session-manager.h
+++ b/gcc/rust/rust-session-manager.h
@@ -24,6 +24,7 @@
 #include "rust-backend.h"
 #include "rust-hir-map.h"
 #include "safe-ctype.h"
+#include "rust-name-resolution-context.h"
 
 #include "config.h"
 #include "rust-system.h"
@@ -413,7 +414,7 @@ private:
   /* Expansion pipeline stage. TODO maybe move to another object? Expands all
* macros, maybe build test harness in future, AST validation, maybe create
* macro crate (if not rustdoc).*/
-  void expansion (AST::Crate );
+  void expansion (AST::Crate , Resolver2_0::NameResolutionContext );
 
   // handle cfg_option
   bool handle_cfg_option (std::string );


[gcc/devel/rust/master] format-args: Start storing string in Rust memory

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:246b6316c0e1320cba90bae676675686890168a8

commit 246b6316c0e1320cba90bae676675686890168a8
Author: Arthur Cohen 
Date:   Thu Feb 22 16:26:40 2024 +0100

format-args: Start storing string in Rust memory

gcc/rust/ChangeLog:

* ast/rust-fmt.cc (ffi::RustHamster::to_string): New.
(Pieces::collect): Adapt to use new handle API.
(Pieces::~Pieces): Likewise.
(Pieces::Pieces): Likewise.
(Pieces::operator=): Likewise.
* ast/rust-fmt.h (struct RustString): Add members.
(struct FormatArgsHandle): New.
(clone_pieces): Adapt for new FFI API.
(destroy_pieces): Likewise.
(struct Pieces): Store new FormatArgsHandle type.
* expand/rust-expand-format-args.cc (expand_format_args): Use proper
namespace.
* resolve/rust-ast-resolve-base.cc (ResolverBase::visit): FormatArgs
nodes are already resolved, so do nothing.

libgrust/ChangeLog:

* libformat_parser/src/lib.rs: Use new Handle struct and expose it.

Diff:
---
 gcc/rust/ast/rust-fmt.cc   |  32 +
 gcc/rust/ast/rust-fmt.h|  46 +
 gcc/rust/expand/rust-expand-format-args.cc |   4 +-
 gcc/rust/resolve/rust-ast-resolve-base.cc  |   5 +-
 libgrust/libformat_parser/src/lib.rs   | 105 ++---
 5 files changed, 133 insertions(+), 59 deletions(-)

diff --git a/gcc/rust/ast/rust-fmt.cc b/gcc/rust/ast/rust-fmt.cc
index b82e089fc41d..fda02e530fd1 100644
--- a/gcc/rust/ast/rust-fmt.cc
+++ b/gcc/rust/ast/rust-fmt.cc
@@ -22,44 +22,48 @@
 namespace Rust {
 namespace Fmt {
 
+std::string
+ffi::RustHamster::to_string () const
+{
+  return std::string (ptr, len);
+}
+
 Pieces
-Pieces::collect (std::string &_parse, bool append_newline)
+Pieces::collect (const std::string _parse, bool append_newline)
 {
-  auto piece_slice = collect_pieces (to_parse.c_str (), append_newline);
+  auto handle = ffi::collect_pieces (to_parse.c_str (), append_newline);
 
   // this performs multiple copies, can we avoid them maybe?
   // TODO: Instead of just creating a vec of, basically, `ffi::Piece`s, we
   // should transform them into the proper C++ type which we can work with. so
   // transform all the strings into C++ strings? all the Option into
   // tl::optional?
-  auto pieces = std::vector (piece_slice.base_ptr,
-   piece_slice.base_ptr + piece_slice.len);
+  auto pieces_vector = std::vector (handle.piece_slice.base_ptr,
+   handle.piece_slice.base_ptr
+ + handle.piece_slice.len);
 
-  return Pieces (std::move (pieces), piece_slice, std::move (to_parse));
+  return Pieces (handle, std::move (pieces_vector));
 }
 
-Pieces::~Pieces () { destroy_pieces (slice); }
+Pieces::~Pieces () { ffi::destroy_pieces (handle); }
 
-Pieces::Pieces (const Pieces )
-  : pieces_vector (other.pieces_vector), to_parse (other.to_parse)
+Pieces::Pieces (const Pieces ) : pieces_vector (other.pieces_vector)
 {
-  slice = clone_pieces (other.slice.base_ptr, other.slice.len, 
other.slice.cap);
+  handle = ffi::clone_pieces (other.handle);
 }
 
 Pieces &
 Pieces::operator= (const Pieces )
 {
-  slice = clone_pieces (other.slice.base_ptr, other.slice.len, 
other.slice.cap);
-  to_parse = other.to_parse;
+  handle = ffi::clone_pieces (other.handle);
+  pieces_vector = other.pieces_vector;
 
   return *this;
 }
 
 Pieces::Pieces (Pieces &)
   : pieces_vector (std::move (other.pieces_vector)),
-slice (
-  clone_pieces (other.slice.base_ptr, other.slice.len, other.slice.cap)),
-to_parse (std::move (other.to_parse))
+handle (clone_pieces (other.handle))
 {}
 
 } // namespace Fmt
diff --git a/gcc/rust/ast/rust-fmt.h b/gcc/rust/ast/rust-fmt.h
index ba412f9958c5..6a0c116b841b 100644
--- a/gcc/rust/ast/rust-fmt.h
+++ b/gcc/rust/ast/rust-fmt.h
@@ -20,15 +20,21 @@
 #define RUST_FMT_H
 
 #include "rust-system.h"
+#include 
 
 // FIXME: How to encode Option?
 
 namespace Rust {
 namespace Fmt {
 
+namespace ffi {
+
 struct RustHamster
 {
-  // hehe
+  const char *ptr;
+  size_t len;
+
+  std::string to_string () const;
 };
 
 /// Enum of alignments which are supported.
@@ -240,21 +246,36 @@ struct PieceSlice
   size_t cap;
 };
 
+struct RustString
+{
+  const unsigned char *ptr;
+  size_t len;
+  size_t cap;
+};
+
+struct FormatArgsHandle
+{
+  PieceSlice piece_slice;
+  RustString rust_string;
+};
+
 extern "C" {
 
-PieceSlice
+FormatArgsHandle
 collect_pieces (const char *input, bool append_newline);
 
-PieceSlice
-clone_pieces (const Piece *base_ptr, size_t len, size_t cap);
+FormatArgsHandle
+clone_pieces (const FormatArgsHandle &);
 
-void destroy_pieces (PieceSlice);
+void destroy_pieces (FormatArgsHandle);
 
 } // extern "C"
 
+} // namespace ffi
+
 struct Pieces
 {
-  static Pieces collect 

[gcc/devel/rust/master] nr2.0: Add new ImmutableNameResolutionCtx class.

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:3e3f5c6602c686e2827173817dac6ebaf9f755e3

commit 3e3f5c6602c686e2827173817dac6ebaf9f755e3
Author: Arthur Cohen 
Date:   Thu Aug 24 17:49:42 2023 +0200

nr2.0: Add new ImmutableNameResolutionCtx class.

gcc/rust/ChangeLog:

* Make-lang.in: Compile it.
* resolve/rust-immutable-name-resolution-context.cc: New file.
* resolve/rust-immutable-name-resolution-context.h: New file.

Diff:
---
 gcc/rust/Make-lang.in  |  1 +
 .../rust-immutable-name-resolution-context.cc  | 56 ++
 .../rust-immutable-name-resolution-context.h   | 55 +
 3 files changed, 112 insertions(+)

diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in
index 8f752599a3f2..1efab4987db5 100644
--- a/gcc/rust/Make-lang.in
+++ b/gcc/rust/Make-lang.in
@@ -134,6 +134,7 @@ GRS_OBJS = \
 rust/rust-toplevel-name-resolver-2.0.o \
 rust/rust-early-name-resolver-2.0.o \
 rust/rust-late-name-resolver-2.0.o \
+   rust/rust-immutable-name-resolution-context.o \
 rust/rust-early-name-resolver.o \
 rust/rust-name-resolver.o \
 rust/rust-ast-resolve.o \
diff --git a/gcc/rust/resolve/rust-immutable-name-resolution-context.cc 
b/gcc/rust/resolve/rust-immutable-name-resolution-context.cc
new file mode 100644
index ..3894e27cd202
--- /dev/null
+++ b/gcc/rust/resolve/rust-immutable-name-resolution-context.cc
@@ -0,0 +1,56 @@
+// Copyright (C) 2020-2023 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
+// .
+
+#include "rust-immutable-name-resolution-context.h"
+
+namespace Rust {
+namespace Resolver2_0 {
+
+static ImmutableNameResolutionContext *instance = nullptr;
+
+const ImmutableNameResolutionContext &
+ImmutableNameResolutionContext::init (const NameResolutionContext )
+{
+  rust_assert (!instance);
+
+  instance = new ImmutableNameResolutionContext (ctx);
+
+  return *instance;
+}
+
+const ImmutableNameResolutionContext &
+ImmutableNameResolutionContext::get ()
+{
+  rust_assert (instance);
+
+  return *instance;
+}
+
+const NameResolutionContext &
+ImmutableNameResolutionContext::resolver () const
+{
+  return ctx;
+}
+
+ImmutableNameResolutionContext::ImmutableNameResolutionContext (
+  const NameResolutionContext )
+  : ctx (ctx)
+{}
+
+} // namespace Resolver2_0
+} // namespace Rust
diff --git a/gcc/rust/resolve/rust-immutable-name-resolution-context.h 
b/gcc/rust/resolve/rust-immutable-name-resolution-context.h
new file mode 100644
index ..9f9e7764cd2a
--- /dev/null
+++ b/gcc/rust/resolve/rust-immutable-name-resolution-context.h
@@ -0,0 +1,55 @@
+// Copyright (C) 2020-2023 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
+// .
+
+#ifndef RUST_IMMUTABLE_NRCTX_H
+#define RUST_IMMUTABLE_NRCTX_H
+
+#include "rust-name-resolution-context.h"
+
+namespace Rust {
+namespace Resolver2_0 {
+
+/**
+ * Once the name resolution pass is complete, the typechecker can access it
+ *
+ * FIXME: More documentation
+ */
+class ImmutableNameResolutionContext
+{
+public:
+  /** FIXME: Documentation */
+  static const ImmutableNameResolutionContext &
+  init (const NameResolutionContext );
+
+  /** FIXME: Documentation */
+  static const ImmutableNameResolutionContext  ();
+
+  const NameResolutionContext  () const;
+
+private:
+  ImmutableNameResolutionContext (const NameResolutionContext );
+  ImmutableNameResolutionContext (const ImmutableNameResolutionContext )
+= default;
+
+  const NameResolutionContext 
+};
+
+} // namespace Resolver2_0
+} // namespace Rust
+
+#endif //! RUST_IMMUTABLE_NRCTX_H


[gcc/devel/rust/master] Merge commit '9f7afa99c67f039e43019ebd08d14a7f01e2d89c' into HEAD

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:8f9b47500d79fcc1456ac6fe4cdbe0abf3ca174c

commit 8f9b47500d79fcc1456ac6fe4cdbe0abf3ca174c
Merge: b177dc6b031c 9f7afa99c67f
Author: Thomas Schwinge 
Date:   Fri Mar 22 10:07:29 2024 +0100

Merge commit '9f7afa99c67f039e43019ebd08d14a7f01e2d89c' into HEAD

Diff:

 ChangeLog  |4 +
 MAINTAINERS|   16 +-
 Makefile.def   |1 +
 Makefile.in|8 +-
 Makefile.tpl   |7 +-
 SECURITY.txt   |8 +-
 contrib/ChangeLog  |7 +
 gcc/ChangeLog  |  111 +
 gcc/DATESTAMP  |2 +-
 gcc/ada/atree.adb  |   16 +-
 gcc/ada/contracts.adb  |   12 +-
 .../doc/gnat_rm/implementation_defined_aspects.rst |6 +
 .../doc/gnat_rm/implementation_defined_pragmas.rst |   14 +
 gcc/ada/exp_aggr.adb   |  151 +-
 gcc/ada/exp_attr.adb   |   11 +-
 gcc/ada/exp_ch6.adb|  158 +-
 gcc/ada/exp_ch6.ads|3 +-
 gcc/ada/exp_util.adb   |   74 +-
 gcc/ada/freeze.adb |   13 +-
 gcc/ada/gcc-interface/decl.cc  |   51 +-
 gcc/ada/gcc-interface/gigi.h   |   12 +-
 gcc/ada/gcc-interface/utils.cc |   49 +-
 gcc/ada/gcc-interface/utils2.cc|   12 +-
 gcc/ada/gnat-style.texi|   68 +-
 gcc/ada/gnat_rm.texi   | 2821 -
 gcc/ada/gnat_ugn.texi  | 1406 +
 gcc/ada/inline.adb |   34 +-
 gcc/ada/lib-xref.adb   |   12 +-
 gcc/ada/libgnat/g-regexp.ads   |9 +-
 gcc/ada/libgnat/i-cstrin.ads   |9 +-
 gcc/ada/libgnat/s-atopri.ads   |   13 +
 gcc/ada/libgnat/s-atopri__32.ads   |   12 +
 gcc/ada/libgnat/s-finmas.adb   |   14 -
 gcc/ada/libgnat/s-finmas.ads   |4 -
 gcc/ada/pprint.adb |6 +-
 gcc/ada/rtsfind.ads|2 -
 gcc/ada/sem_aggr.adb   |   41 +-
 gcc/ada/sem_attr.adb   |8 +-
 gcc/ada/sem_ch12.adb   |  165 +-
 gcc/ada/sem_ch3.adb|   14 +-
 gcc/ada/sem_ch4.adb|4 +-
 gcc/ada/sem_ch6.adb|6 +-
 gcc/ada/sem_ch8.adb|   26 +-
 gcc/ada/sem_ch9.adb|   26 +
 gcc/ada/sem_res.adb|   11 +-
 gcc/ada/sem_scil.adb   |1 +
 gcc/ada/sem_util.adb   |5 +
 gcc/btfout.cc  |   14 +-
 gcc/c-family/c-attribs.cc  |   32 +-
 gcc/c-family/c-common.h|4 +-
 gcc/c-family/c-omp.cc  |   23 +-
 gcc/c/c-parser.cc  |2 +-
 gcc/config.gcc |4 +-
 gcc/config/aarch64/aarch64-builtins.cc |4 +-
 gcc/config/arc/arc.cc  |  350 ++-
 gcc/config/arm/arm-cpus.in |   21 +
 gcc/config/arm/arm-tables.opt  |3 +
 gcc/config/arm/arm-tune.md |6 +-
 gcc/config/avr/avr.cc  |  172 +-
 gcc/config/epiphany/constraints.md |6 +-
 gcc/config/gcn/gcn-hsa.h   |4 +-
 gcc/config/gcn/gcn-opts.h  |7 +-
 gcc/config/gcn/gcn-valu.md |   10 +-
 gcc/config/gcn/gcn.cc  |   29 +-
 gcc/config/gcn/gcn.h   |   10 +-
 gcc/config/gcn/gcn.md  |   32 +-
 gcc/config/gcn/gcn.opt |3 +
 gcc/config/gcn/mkoffload.cc|5 +
 gcc/config/gcn/t-omp-device|2 +-
 gcc/config/i386/i386-expand.cc |  124 +-
 gcc/config/loongarch/lasx.md   |   26 +-
 gcc/config/loongarch/loongarch.cc  |   44 +-
 gcc/config/mn10300/mn10300.md  |4 +-
 gcc/config/riscv/riscv-vector-builtins-bases.cc|  264 +-
 gcc/config/riscv/riscv-vector-builtins-bases.h |   28 +
 .../riscv/riscv-vector-builtins-functions.def

[gcc/devel/rust/master] Merge commit '28064d6430f3fa71e79d11ac9d4bf3e6adf52145' into HEAD

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:9d6e836c2c663956db2a51d32f8bb6a08d9d2057

commit 9d6e836c2c663956db2a51d32f8bb6a08d9d2057
Merge: 595789c2c33e 28064d6430f3
Author: Thomas Schwinge 
Date:   Sat Mar 16 23:54:33 2024 +0100

Merge commit '28064d6430f3fa71e79d11ac9d4bf3e6adf52145' into HEAD

Diff:


[gcc/devel/rust/master] Merge commit '00dea7e8c41b672730d6e2c891b6012a83d8842c' into HEAD [#2284]

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:59bc3e7924ed9dc293a77e3d9c6cdd99c252eefb

commit 59bc3e7924ed9dc293a77e3d9c6cdd99c252eefb
Merge: 4c445f0015b9 00dea7e8c41b
Author: Thomas Schwinge 
Date:   Fri Mar 22 09:55:35 2024 +0100

Merge commit '00dea7e8c41b672730d6e2c891b6012a83d8842c' into HEAD [#2284]

Diff:

 gcc/rust/lex/rust-lex.cc |  4 ++--
 libcpp/charset.cc| 22 +++---
 libcpp/include/cpplib.h  |  8 
 3 files changed, 17 insertions(+), 17 deletions(-)

diff --cc gcc/rust/lex/rust-lex.cc
index 71775e87c22a,ccc0c06d889f..bf6bf4c84466
--- a/gcc/rust/lex/rust-lex.cc
+++ b/gcc/rust/lex/rust-lex.cc
@@@ -125,21 -116,9 +125,21 @@@ is_non_decimal_int_literal_separator (u
return character == 'x' || character == 'o' || character == 'b';
  }
  
 -Lexer::Lexer (const std::string )
 +bool
 +is_identifier_start (uint32_t codepoint)
 +{
-   return (check_xid_property (codepoint) & XID_START) || codepoint == '_';
++  return (cpp_check_xid_property (codepoint) & CPP_XID_START) || codepoint == 
'_';
 +}
 +
 +bool
 +is_identifier_continue (uint32_t codepoint)
 +{
-   return check_xid_property (codepoint) & XID_CONTINUE;
++  return cpp_check_xid_property (codepoint) & CPP_XID_CONTINUE;
 +}
 +
 +Lexer::Lexer (const std::string , Linemap *linemap)
: input (RAIIFile::create_error ()), current_line (1), current_column (1),
 -line_map (nullptr), dump_lex_out (Optional::none ()),
 +line_map (linemap), dump_lex_out ({}),
  raw_input_source (new BufferInputSource (input, 0)),
  input_queue{*raw_input_source}, token_queue (TokenSource (this))
  {}


[gcc/devel/rust/master] Merge commit '00dea7e8c41b672730d6e2c891b6012a83d8842c^' into HEAD

2024-05-07 Thread Thomas Schwinge via Libstdc++-cvs
https://gcc.gnu.org/g:4c445f0015b9779d17d0ca7e8a6fc62cb5cf9e5a

commit 4c445f0015b9779d17d0ca7e8a6fc62cb5cf9e5a
Merge: 83c5b0292a9a 4ded42c2c5a5
Author: Thomas Schwinge 
Date:   Fri Mar 22 09:49:13 2024 +0100

Merge commit '00dea7e8c41b672730d6e2c891b6012a83d8842c^' into HEAD

Diff:

 contrib/ChangeLog  |5 +
 gcc/ChangeLog  |   42 +
 gcc/DATESTAMP  |2 +-
 gcc/Makefile.in|   34 +-
 gcc/ada/ChangeLog  |5 +
 gcc/ada/gcc-interface/lang.opt.urls|   30 +
 gcc/analyzer/access-diagram.cc |4 +-
 gcc/analyzer/analyzer.opt.urls |  215 +++
 gcc/analyzer/checker-event.cc  |   83 +-
 gcc/analyzer/checker-event.h   |6 +
 gcc/analyzer/inlining-iterator.h   |   40 +
 gcc/analyzer/sm-malloc.cc  |   10 +
 gcc/c-family/c.opt.urls| 1433 +++
 gcc/c/ChangeLog|5 +
 gcc/c/c-parser.cc  |4 +-
 gcc/common.opt.urls| 1862 
 gcc/config/aarch64/aarch64.opt.urls|   93 +
 gcc/config/alpha/alpha.opt.urls|   76 +
 gcc/config/alpha/elf.opt.urls  |2 +
 gcc/config/arc/arc-tables.opt.urls |2 +
 gcc/config/arc/arc.opt.urls|  260 +++
 gcc/config/arm/arm-tables.opt.urls |2 +
 gcc/config/arm/arm.opt.urls|  149 ++
 gcc/config/arm/vxworks.opt.urls|2 +
 gcc/config/avr/avr.opt.urls|   71 +
 gcc/config/bfin/bfin.opt.urls  |   61 +
 gcc/config/bpf/bpf.opt.urls|   35 +
 gcc/config/c6x/c6x-tables.opt.urls |2 +
 gcc/config/c6x/c6x.opt.urls|   18 +
 gcc/config/cris/cris.opt.urls  |   65 +
 gcc/config/cris/elf.opt.urls   |8 +
 gcc/config/csky/csky.opt.urls  |  104 ++
 gcc/config/csky/csky_tables.opt.urls   |2 +
 gcc/config/darwin.opt.urls |  224 +++
 gcc/config/dragonfly.opt.urls  |9 +
 gcc/config/epiphany/epiphany.opt.urls  |   52 +
 gcc/config/fr30/fr30.opt.urls  |8 +
 gcc/config/freebsd.opt.urls|9 +
 gcc/config/frv/frv.opt.urls|  111 ++
 gcc/config/ft32/ft32.opt.urls  |   20 +
 gcc/config/fused-madd.opt.urls |4 +
 gcc/config/g.opt.urls  |5 +
 gcc/config/gcn/gcn.opt.urls|   23 +
 gcc/config/gnu-user.opt.urls   |9 +
 gcc/config/h8300/h8300.opt.urls|   29 +
 gcc/config/hpux11.opt.urls |6 +
 gcc/config/i386/cygming.opt.urls   |   30 +
 gcc/config/i386/cygwin.opt.urls|6 +
 gcc/config/i386/djgpp.opt.urls |2 +
 gcc/config/i386/i386.opt.urls  |  611 +++
 gcc/config/i386/mingw-w64.opt.urls |5 +
 gcc/config/i386/mingw.opt.urls |   12 +
 gcc/config/i386/nto.opt.urls   |5 +
 gcc/config/ia64/ia64.opt.urls  |  122 ++
 gcc/config/ia64/ilp32.opt.urls |8 +
 gcc/config/ia64/vms.opt.urls   |2 +
 gcc/config/iq2000/iq2000.opt.urls  |   14 +
 gcc/config/linux-android.opt.urls  |   11 +
 gcc/config/linux.opt.urls  |   14 +
 gcc/config/lm32/lm32.opt.urls  |   14 +
 gcc/config/loongarch/loongarch.cc  | 1308 +++---
 gcc/config/loongarch/loongarch.opt.urls|   66 +
 gcc/config/lynx.opt.urls   |5 +
 gcc/config/m32c/m32c.opt.urls  |8 +
 gcc/config/m32r/m32r.opt.urls  |   27 +
 gcc/config/m68k/ieee.opt.urls  |4 +
 gcc/config/m68k/m68k-tables.opt.urls   |2 +
 gcc/config/m68k/m68k.opt.urls  |  107 ++
 gcc/config/m68k/uclinux.opt.urls   |2 +
 gcc/config/mcore/mcore.opt.urls|   38 +
 gcc/config/microblaze/microblaze.opt.urls  |   59 +
 gcc/config/mips/mips-tables.opt.urls   |2 +
 gcc/config/mips/mips.cc|   33 +
 gcc/config/mips/mips.md|   28 +
 gcc/config/mips/mips.opt.urls  |  269 +++
 gcc/config/mips/sde.opt.urls   |2

[gcc/devel/rust/master] Merge commit 'f3f6ff7b16861cd0651eccff14689536550762ae' into HEAD [#2414]

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:ddbb4d3a4145bd5b05ca23dd5dfb562ecab1f512

commit ddbb4d3a4145bd5b05ca23dd5dfb562ecab1f512
Merge: b2ccc44dfb39 f3f6ff7b1686
Author: Thomas Schwinge 
Date:   Mon Mar 11 00:33:08 2024 +0100

Merge commit 'f3f6ff7b16861cd0651eccff14689536550762ae' into HEAD [#2414]

Diff:

 contrib/mklog.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


[gcc/devel/rust/master] Replace reference to unique pointer with reference

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:843d7d7b46133fc471ed51d165a979c5af059aea

commit 843d7d7b46133fc471ed51d165a979c5af059aea
Author: Pierre-Emmanuel Patry 
Date:   Wed Feb 21 16:45:18 2024 +0100

Replace reference to unique pointer with reference

Reference to unique pointers are a known anti pattern, only the element
shall be taken by reference instead of the whole wrapper.

gcc/rust/ChangeLog:

* ast/rust-item.h: Change getter function prototype to return a
reference directly instead of a reference to the wrapper type.
* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Fix
the code to accept references instead.
* hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_self): Change
function implementation to return a reference.
* hir/rust-ast-lower-base.h: Accept a reference instead of a unique
pointer reference.
* resolve/rust-ast-resolve-item.cc (ResolveItem::visit): Adapt the 
code
to a reference instead of a unique pointer.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/ast/rust-item.h  |  8 
 gcc/rust/checks/errors/rust-ast-validation.cc |  2 +-
 gcc/rust/hir/rust-ast-lower-base.cc   | 24 
 gcc/rust/hir/rust-ast-lower-base.h|  2 +-
 gcc/rust/resolve/rust-ast-resolve-item.cc | 19 +--
 5 files changed, 27 insertions(+), 28 deletions(-)

diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h
index 573888bea5aa..d09f45500629 100644
--- a/gcc/rust/ast/rust-item.h
+++ b/gcc/rust/ast/rust-item.h
@@ -1415,15 +1415,15 @@ public:
 return return_type;
   }
 
-  std::unique_ptr _self_param ()
+  Param _self_param ()
   {
 rust_assert (has_self_param ());
-return function_params[0];
+return *function_params[0];
   }
-  const std::unique_ptr _self_param () const
+  const Param _self_param () const
   {
 rust_assert (has_self_param ());
-return function_params[0];
+return *function_params[0];
   }
 
   // ExternalItem::node_id is same as Stmt::node_id
diff --git a/gcc/rust/checks/errors/rust-ast-validation.cc 
b/gcc/rust/checks/errors/rust-ast-validation.cc
index d1edb890ae61..d58920878893 100644
--- a/gcc/rust/checks/errors/rust-ast-validation.cc
+++ b/gcc/rust/checks/errors/rust-ast-validation.cc
@@ -100,7 +100,7 @@ ASTValidation::visit (AST::Function )
   && context.back () != Context::INHERENT_IMPL
   && function.has_self_param ())
 rust_error_at (
-  function.get_self_param ()->get_locus (),
+  function.get_self_param ().get_locus (),
   "% parameter is only allowed in associated functions");
 
   if (function.is_external ())
diff --git a/gcc/rust/hir/rust-ast-lower-base.cc 
b/gcc/rust/hir/rust-ast-lower-base.cc
index ff6ef25a3488..652530ae7a50 100644
--- a/gcc/rust/hir/rust-ast-lower-base.cc
+++ b/gcc/rust/hir/rust-ast-lower-base.cc
@@ -648,31 +648,31 @@ ASTLoweringBase::lower_generic_args (AST::GenericArgs 
)
 }
 
 HIR::SelfParam
-ASTLoweringBase::lower_self (std::unique_ptr )
+ASTLoweringBase::lower_self (AST::Param )
 {
-  rust_assert (param->is_self ());
+  rust_assert (param.is_self ());
 
-  auto self = static_cast (param.get ());
+  auto self = static_cast (param);
   auto crate_num = mappings->get_current_crate ();
-  Analysis::NodeMapping mapping (crate_num, self->get_node_id (),
+  Analysis::NodeMapping mapping (crate_num, self.get_node_id (),
 mappings->get_next_hir_id (crate_num),
 mappings->get_next_localdef_id (crate_num));
 
-  if (self->has_type ())
+  if (self.has_type ())
 {
-  HIR::Type *type = ASTLoweringType::translate (self->get_type ().get ());
+  HIR::Type *type = ASTLoweringType::translate (self.get_type ().get ());
   return HIR::SelfParam (mapping, std::unique_ptr (type),
-self->get_is_mut (), self->get_locus ());
+self.get_is_mut (), self.get_locus ());
 }
-  else if (!self->get_has_ref ())
+  else if (!self.get_has_ref ())
 {
   return HIR::SelfParam (mapping, std::unique_ptr (nullptr),
-self->get_is_mut (), self->get_locus ());
+self.get_is_mut (), self.get_locus ());
 }
 
-  AST::Lifetime l = self->get_lifetime ();
-  return HIR::SelfParam (mapping, lower_lifetime (l), self->get_is_mut (),
-self->get_locus ());
+  AST::Lifetime l = self.get_lifetime ();
+  return HIR::SelfParam (mapping, lower_lifetime (l), self.get_is_mut (),
+self.get_locus ());
 }
 
 HIR::Type *
diff --git a/gcc/rust/hir/rust-ast-lower-base.h 
b/gcc/rust/hir/rust-ast-lower-base.h
index c19e9c03b5f2..c01c7c857678 100644
--- a/gcc/rust/hir/rust-ast-lower-base.h
+++ b/gcc/rust/hir/rust-ast-lower-base.h
@@ -278,7 +278,7 @@ protected:
 
   

[gcc/devel/rust/master] Merge commit 'a945c346f57ba40fc80c14ac59be0d43624e559d^' into HEAD

2024-05-07 Thread Thomas Schwinge via Libstdc++-cvs
https://gcc.gnu.org/g:884c2b766e4a1fd514b446aa7c39a159ec80a4a8

commit 884c2b766e4a1fd514b446aa7c39a159ec80a4a8
Merge: a8514ae513dd 9afc19159c29
Author: Thomas Schwinge 
Date:   Fri Mar 22 09:26:05 2024 +0100

Merge commit 'a945c346f57ba40fc80c14ac59be0d43624e559d^' into HEAD

Diff:

 ChangeLog  |18 +
 MAINTAINERS|16 +-
 c++tools/ChangeLog | 2 +-
 contrib/ChangeLog  |19 +
 contrib/compare_tests  | 6 +-
 contrib/gcc-git-customization.sh   | 5 +
 contrib/update-copyright.py| 6 +-
 gcc/ChangeLog  | 53041 +-
 gcc/ChangeLog-2023 | 54880 +++
 gcc/DATESTAMP  | 2 +-
 gcc/Makefile.in| 3 +
 gcc/ada/ChangeLog  |  6742 +--
 gcc/ada/ChangeLog-2023 |  6978 +++
 gcc/ada/argv.c | 2 +
 gcc/ada/bindgen.adb|91 +-
 .../doc/gnat_rm/implementation_defined_pragmas.rst | 4 +-
 gcc/ada/einfo.ads  |30 +-
 gcc/ada/errout.adb |27 +-
 gcc/ada/exp_aggr.adb   |17 +-
 gcc/ada/exp_ch3.adb| 3 +-
 gcc/ada/exp_ch4.adb|   410 +-
 gcc/ada/exp_ch6.adb|50 +-
 gcc/ada/exp_ch7.adb|14 +-
 gcc/ada/exp_ch9.adb| 4 +-
 gcc/ada/exp_spark.adb  |   146 +
 gcc/ada/exp_util.adb   |12 +-
 gcc/ada/exp_util.ads   | 8 +-
 gcc/ada/gcc-interface/Make-lang.in |35 +-
 gcc/ada/gcc-interface/decl.cc  |44 +-
 gcc/ada/gcc-interface/trans.cc |16 +-
 gcc/ada/gcc-interface/utils.cc |72 +-
 gcc/ada/gen_il-fields.ads  | 6 +-
 gcc/ada/gen_il-gen-gen_entities.adb| 4 +-
 gcc/ada/gen_il-gen-gen_nodes.adb   | 2 +-
 gcc/ada/gen_il-internals.adb   | 2 -
 gcc/ada/gnat-style.texi|68 +-
 gcc/ada/gnat_rm.texi   |  1078 +-
 gcc/ada/gnat_ugn.texi  |  1410 +-
 gcc/ada/libgnat/a-comlin.adb   |18 +-
 gcc/ada/libgnat/i-cstrin.adb   |17 +-
 gcc/ada/libgnat/s-rident.ads   | 1 -
 gcc/ada/sem_aggr.adb   |32 +-
 gcc/ada/sem_ch10.adb   | 2 +-
 gcc/ada/sem_ch12.adb   |   205 +-
 gcc/ada/sem_ch13.adb   |   103 +-
 gcc/ada/sem_ch3.adb|38 +-
 gcc/ada/sem_ch4.adb|10 +-
 gcc/ada/sem_ch8.adb|12 +-
 gcc/ada/sem_prag.adb   |50 +-
 gcc/ada/sem_res.adb|   100 -
 gcc/ada/sem_util.adb   |83 +-
 gcc/ada/sem_util.ads   |11 +-
 gcc/ada/sinfo-utils.ads|16 +
 gcc/ada/sinfo.ads  | 7 +-
 gcc/ada/sinput.adb |13 -
 gcc/ada/sinput.ads | 5 -
 gcc/ada/targparm.ads   |20 +-
 gcc/ada/treepr.adb | 2 -
 gcc/analyzer/ChangeLog |   131 +-
 gcc/analyzer/analyzer.cc   |59 +
 gcc/analyzer/analyzer.h|12 +
 gcc/analyzer/bounds-checking.cc|   493 +-
 gcc/analyzer/infinite-loop.cc  | 8 +-
 gcc/analyzer/region-model.cc   |41 +
 gcc/analyzer/region-model.h| 4 +
 gcc/analyzer/region.cc |71 +
 gcc/analyzer/region.h  |12 +-
 gcc/analyzer/sm-file.cc|12 +-
 gcc/analyzer/sm-sensitive.cc   | 6 +-
 gcc/analyzer/sm-signal.cc  | 6 +-
 gcc/analyzer/sm-taint.cc   |12 +-
 gcc/analyzer/store.cc  |   172 +-
 gcc/analyzer/store.h   |21 +-
 gcc/analyzer/varargs.cc| 6 +-
 gcc/attribs.cc

[gcc/devel/rust/master] Merge commit 'f37c55c14bc1176ef9a15fe584fb6d1bf2e6162f' into HEAD [#1913]

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:f96582527ef42d0a02b68aa956d51c2ed40fb8b6

commit f96582527ef42d0a02b68aa956d51c2ed40fb8b6
Merge: af14cc24cb5f f37c55c14bc1
Author: Thomas Schwinge 
Date:   Fri Mar 22 01:04:40 2024 +0100

Merge commit 'f37c55c14bc1176ef9a15fe584fb6d1bf2e6162f' into HEAD [#1913]

Diff:

 contrib/gcc_update  |   4 +
 libgrust/Makefile.in|   5 +
 libgrust/aclocal.m4 |   3 +
 libgrust/configure  | 193 ++--
 libgrust/configure.ac   |  14 +-
 libgrust/libproc_macro_internal/Makefile.in |   5 +
 6 files changed, 213 insertions(+), 11 deletions(-)

diff --cc libgrust/configure
index 54adb827096e,5388a0e22a6a..b1d4c8f7fc0f
--- a/libgrust/configure
+++ b/libgrust/configure
@@@ -17175,9 -17343,10 +17343,10 @@@ for ac_config_target in $ac_config_targ
  do
case $ac_config_target in
  "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;;
+ "default-1") CONFIG_COMMANDS="$CONFIG_COMMANDS default-1" ;;
  "depfiles") CONFIG_COMMANDS="$CONFIG_COMMANDS depfiles" ;;
  "libtool") CONFIG_COMMANDS="$CONFIG_COMMANDS libtool" ;;
 -"libproc_macro/Makefile") CONFIG_FILES="$CONFIG_FILES 
libproc_macro/Makefile" ;;
 +"libproc_macro_internal/Makefile") CONFIG_FILES="$CONFIG_FILES 
libproc_macro_internal/Makefile" ;;
  
*) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;;
esac
diff --cc libgrust/libproc_macro_internal/Makefile.in
index 0eccade78d48,9ff1dd69cc37..68aa46106899
--- a/libgrust/libproc_macro_internal/Makefile.in
+++ b/libgrust/libproc_macro_internal/Makefile.in
@@@ -88,11 -88,14 +88,14 @@@ POST_UNINSTALL = 
  build_triplet = @build@
  host_triplet = @host@
  target_triplet = @target@
 -subdir = libproc_macro
 +subdir = libproc_macro_internal
  ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
  am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
+   $(top_srcdir)/../config/cet.m4 \
$(top_srcdir)/../config/depstand.m4 \
+   $(top_srcdir)/../config/enable.m4 \
$(top_srcdir)/../config/lead-dot.m4 \
+   $(top_srcdir)/../config/multi.m4 \
$(top_srcdir)/../config/no-executables.m4 \
$(top_srcdir)/../config/override.m4 \
$(top_srcdir)/../config/toolexeclibdir.m4 \


[gcc/devel/rust/master] Adjust '.github/bors_log_expected_warnings'

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:3651af8535b61d79a55b228629a923763306b688

commit 3651af8535b61d79a55b228629a923763306b688
Author: Thomas Schwinge 
Date:   Mon Mar 11 23:44:18 2024 +0100

Adjust '.github/bors_log_expected_warnings'

Diff:
---
 .github/bors_log_expected_warnings | 112 +
 1 file changed, 64 insertions(+), 48 deletions(-)

diff --git a/.github/bors_log_expected_warnings 
b/.github/bors_log_expected_warnings
index e59f55f0c9b2..ae172cabe605 100644
--- a/.github/bors_log_expected_warnings
+++ b/.github/bors_log_expected_warnings
@@ -1,8 +1,11 @@
 ../../../../libgcc/generic-morestack.c:397:16: warning: comparison of integer 
expressions of different signedness: ‘unsigned int’ and ‘long int’ 
[-Wsign-compare]
-../../../libcpp/expr.cc:821:35: warning: format not a string literal and no 
format arguments [-Wformat-security]
-../../../libcpp/expr.cc:824:38: warning: format not a string literal and no 
format arguments [-Wformat-security]
-../../../libcpp/expr.cc:834:33: warning: format not a string literal and no 
format arguments [-Wformat-security]
-../../../libcpp/lex.cc:2117:39: warning: ‘loc’ may be used uninitialized 
[-Wmaybe-uninitialized]
+../../../libcpp/expr.cc:842:35: warning: format not a string literal and no 
format arguments [-Wformat-security]
+../../../libcpp/expr.cc:845:38: warning: format not a string literal and no 
format arguments [-Wformat-security]
+../../../libcpp/expr.cc:855:33: warning: format not a string literal and no 
format arguments [-Wformat-security]
+../../../libcpp/expr.cc:867:42: warning: format not a string literal and no 
format arguments [-Wformat-security]
+../../../libcpp/expr.cc:870:39: warning: format not a string literal and no 
format arguments [-Wformat-security]
+../../../libcpp/expr.cc:877:35: warning: format not a string literal and no 
format arguments [-Wformat-security]
+../../../libcpp/lex.cc:2120:39: warning: ‘loc’ may be used uninitialized 
[-Wmaybe-uninitialized]
 ../../../libcpp/macro.cc:185:26: warning: format not a string literal and no 
format arguments [-Wformat-security]
 ../../../libcpp/macro.cc:214:34: warning: format not a string literal and no 
format arguments [-Wformat-security]
 ../../../libcpp/macro.cc:3704:25: warning: format not a string literal and no 
format arguments [-Wformat-security]
@@ -10,6 +13,10 @@
 ../../c++tools/server.cc:490:11: warning: ignoring return value of ‘ssize_t 
write(int, const void*, size_t)’ declared with attribute ‘warn_unused_result’ 
[-Wunused-result]
 ../../c++tools/server.cc:620:10: warning: ignoring return value of ‘int 
pipe(int*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
 ../../gcc/../libgcc/libgcov-util.c:455:9: warning: ignoring return value of 
‘int chdir(const char*)’ declared with attribute ‘warn_unused_result’ 
[-Wunused-result]
+../../gcc/analyzer/access-diagram.cc:399:26: warning: too many arguments for 
format [-Wformat-extra-args]
+../../gcc/analyzer/access-diagram.cc:399:26: warning: unknown conversion type 
character ‘E’ in format [-Wformat=]
+../../gcc/analyzer/access-diagram.cc:401:26: warning: too many arguments for 
format [-Wformat-extra-args]
+../../gcc/analyzer/access-diagram.cc:401:26: warning: unknown conversion type 
character ‘E’ in format [-Wformat=]
 ../../gcc/analyzer/call-summary.cc:113:34: warning: too many arguments for 
format [-Wformat-extra-args]
 ../../gcc/analyzer/call-summary.cc:113:42: warning: unknown conversion type 
character ‘E’ in format [-Wformat=]
 ../../gcc/analyzer/call-summary.cc:115:34: warning: too many arguments for 
format [-Wformat-extra-args]
@@ -19,30 +26,31 @@
 ../../gcc/analyzer/call-summary.cc:123:26: warning: unknown conversion type 
character ‘E’ in format [-Wformat=]
 ../../gcc/analyzer/call-summary.cc:99:32: warning: too many arguments for 
format [-Wformat-extra-args]
 ../../gcc/analyzer/call-summary.cc:99:40: warning: unknown conversion type 
character ‘E’ in format [-Wformat=]
-../../gcc/analyzer/diagnostic-manager.cc:802:20: warning: too many arguments 
for format [-Wformat-extra-args]
-../../gcc/analyzer/diagnostic-manager.cc:802:28: warning: unknown conversion 
type character ‘E’ in format [-Wformat=]
+../../gcc/analyzer/diagnostic-manager.cc:810:20: warning: too many arguments 
for format [-Wformat-extra-args]
+../../gcc/analyzer/diagnostic-manager.cc:810:28: warning: unknown conversion 
type character ‘E’ in format [-Wformat=]
 ../../gcc/analyzer/program-state.cc:1422:15: warning: format not a string 
literal and no format arguments [-Wformat-security]
-../../gcc/analyzer/sm-malloc.cc:1627:22: warning: too many arguments for 
format [-Wformat-extra-args]
-../../gcc/analyzer/sm-malloc.cc:1627:25: warning: unknown conversion type 
character ‘E’ in format [-Wformat=]
-../../gcc/analyzer/sm-malloc.cc:1628:22: warning: too many arguments for 
format [-Wformat-extra-args]
-../../gcc/analyzer/sm-malloc.cc:1628:25: warning: unknown conversion type 
character ‘E’ in format [-Wformat

[gcc/devel/rust/master] Merge commit '725fb3595622a4ad8cd078a42fab1c395cbf90cb' into HEAD [#1913, #2288]

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:a8514ae513dd82742e10dcb6dcf5fbb627c43a90

commit a8514ae513dd82742e10dcb6dcf5fbb627c43a90
Merge: f96582527ef4 725fb3595622
Author: Thomas Schwinge 
Date:   Fri Mar 22 01:19:10 2024 +0100

Merge commit '725fb3595622a4ad8cd078a42fab1c395cbf90cb' into HEAD [#1913, 
#2288]

Diff:

 configure   | 22 +++---
 configure.ac| 22 +++---
 gcc/rust/config-lang.in |  1 +
 3 files changed, 23 insertions(+), 22 deletions(-)

diff --cc gcc/rust/config-lang.in
index ccc27d4b1173,5c9ffcd8fc70..6221ff451286
--- a/gcc/rust/config-lang.in
+++ b/gcc/rust/config-lang.in
@@@ -30,8 -30,6 +30,9 @@@ compilers="crab1\$(exeext)
  build_by_default="no"
  
  target_libs="target-libgrust"
+ lang_dirs=libgrust
  
 -gtfiles="\$(srcdir)/rust/rust-lang.cc"
 +gtfiles="\
 +\$(srcdir)/rust/rust-lang.cc \$(srcdir)/rust/backend/rust-constexpr.cc \
 +\$(srcdir)/rust/backend/rust-tree.h \$(srcdir)/rust/backend/rust-tree.cc \
 +"


[gcc/devel/rust/master] format-args: Only pass the format string to the parser.

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:677a8866e056463d2e051fea29d07d22b3b92a35

commit 677a8866e056463d2e051fea29d07d22b3b92a35
Author: Arthur Cohen 
Date:   Thu Mar 7 14:57:54 2024 +0100

format-args: Only pass the format string to the parser.

This fixes an issue we had where the generated code ended with more static
pieces than its rustc counterpart.

gcc/rust/ChangeLog:

* expand/rust-macro-builtins.cc (struct FormatArgsInput): Store the 
format_str
as a string instead of an AST::Expr.
(format_args_parse_arguments): Transform format_expr into a format 
string
properly - add note for handling eager macro invocations later on.
(MacroBuiltin::format_args_handler): Parse the correct input, append
newline to format_str if necessary.

Diff:
---
 gcc/rust/expand/rust-macro-builtins.cc | 37 --
 1 file changed, 22 insertions(+), 15 deletions(-)

diff --git a/gcc/rust/expand/rust-macro-builtins.cc 
b/gcc/rust/expand/rust-macro-builtins.cc
index 112713a4f976..a33a57752dad 100644
--- a/gcc/rust/expand/rust-macro-builtins.cc
+++ b/gcc/rust/expand/rust-macro-builtins.cc
@@ -18,6 +18,7 @@
 
 #include "expected.h"
 #include "libproc_macro_internal/tokenstream.h"
+#include "optional.h"
 #include "rust-ast-full-decls.h"
 #include "rust-builtin-ast-nodes.h"
 #include "rust-expand-format-args.h"
@@ -961,7 +962,7 @@ MacroBuiltin::stringify_handler (location_t invoc_locus,
 
 struct FormatArgsInput
 {
-  std::unique_ptr format_str;
+  std::string format_str;
   AST::FormatArguments args;
   // bool is_literal?
 };
@@ -985,12 +986,18 @@ format_args_parse_arguments (AST::MacroInvocData )
 
   auto args = AST::FormatArguments ();
   auto last_token_id = macro_end_token (invoc.get_delim_tok_tree (), parser);
-  std::unique_ptr format_str = nullptr;
+  std::unique_ptr format_expr = nullptr;
 
   // TODO: Handle the case where we're not parsing a string literal (macro
   // invocation for e.g.)
   if (parser.peek_current_token ()->get_id () == STRING_LITERAL)
-format_str = parser.parse_literal_expr ();
+format_expr = parser.parse_literal_expr ();
+
+  // TODO(Arthur): Clean this up - if we haven't parsed a string literal but a
+  // macro invocation, what do we do here? return a tl::unexpected?
+  auto format_str = static_cast (*format_expr)
+ .get_literal ()
+ .as_string ();
 
   // TODO: Allow implicit captures ONLY if the the first arg is a string 
literal
   // and not a macro invocation
@@ -1053,6 +1060,13 @@ MacroBuiltin::format_args_handler (location_t 
invoc_locus,
 {
   auto input = format_args_parse_arguments (invoc);
 
+  if (!input)
+{
+  rust_error_at (invoc_locus,
+"could not parse arguments to %");
+  return tl::nullopt;
+}
+
   // TODO(Arthur): We need to handle this
   // // if it is not a literal, it's an eager macro invocation - return it
   // if (!fmt_expr->is_literal ())
@@ -1080,20 +1094,13 @@ MacroBuiltin::format_args_handler (location_t 
invoc_locus,
   // rust_unreachable ();
   //   }
 
-  // Remove the delimiters from the macro invocation:
-  // the invoc data for `format_args!(fmt, arg1, arg2)` is `(fmt, arg1, arg2)`,
-  // so we pop the front and back to remove the parentheses (or curly brackets,
-  // or brackets)
-  auto tokens = invoc.get_delim_tok_tree ().to_token_stream ();
-  tokens.erase (tokens.begin ());
-  tokens.pop_back ();
+  bool append_newline = nl == AST::FormatArgs::Newline::Yes;
 
-  std::stringstream stream;
-  for (const auto  : tokens)
-stream << tok->as_string () << ' ';
+  auto fmt_str = std::move (input->format_str);
+  if (append_newline)
+fmt_str += '\n';
 
-  auto append_newline = nl == AST::FormatArgs::Newline::Yes ? true : false;
-  auto pieces = Fmt::Pieces::collect (stream.str (), append_newline);
+  auto pieces = Fmt::Pieces::collect (fmt_str, append_newline);
 
   // TODO:
   // do the transformation into an AST::FormatArgs node


[gcc/devel/rust/master] Merge commit 'f37c55c14bc1176ef9a15fe584fb6d1bf2e6162f^' into HEAD

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:af14cc24cb5f1a3b1a3abd6c289cb33ee8768bb8

commit af14cc24cb5f1a3b1a3abd6c289cb33ee8768bb8
Merge: 77d55deb8bb7 203efd5097b8
Author: Thomas Schwinge 
Date:   Fri Mar 22 00:30:43 2024 +0100

Merge commit 'f37c55c14bc1176ef9a15fe584fb6d1bf2e6162f^' into HEAD

Diff:

 gcc/config/riscv/riscv-vector-builtins-avail.h |  12 -
 .../riscv/riscv-vector-builtins-functions.def  | 949 ++---
 gcc/config/riscv/riscv-vector-builtins.cc  |   6 +-
 gcc/config/riscv/riscv-vector-builtins.h   |  10 -
 gcc/config/riscv/t-riscv   |   1 -
 5 files changed, 475 insertions(+), 503 deletions(-)


[gcc/devel/rust/master] Merge commit 'db50aea62595452db12565186cb520728540d987' into HEAD

2024-05-07 Thread Thomas Schwinge via Libstdc++-cvs
https://gcc.gnu.org/g:0a9e0719ea7605e54096c42af4a0b2a6fcfc81b0

commit 0a9e0719ea7605e54096c42af4a0b2a6fcfc81b0
Merge: fc5b92bc6184 db50aea62595
Author: Thomas Schwinge 
Date:   Sun Mar 17 00:06:54 2024 +0100

Merge commit 'db50aea62595452db12565186cb520728540d987' into HEAD

Diff:

 .gitignore |1 +
 Makefile.def   |   72 +-
 Makefile.in| 1660 
 config/gettext-sister.m4   |   35 +-
 config/gettext.m4  |  361 +++---
 config/iconv.m4|  313 +++--
 config/intlmacosx.m4   |   69 +
 configure  |   44 +-
 configure.ac   |   44 +-
 contrib/download_prerequisites |2 +
 contrib/prerequisites.md5  |1 +
 contrib/prerequisites.sha512   |1 +
 gcc/Makefile.in|8 +-
 gcc/aclocal.m4 |4 +
 gcc/configure  | 2761 
 gcc/doc/install.texi   |   72 +-
 libcpp/aclocal.m4  |5 +
 libcpp/configure   | 2345 +-
 libstdc++-v3/configure |  725 ---
 19 files changed, 5975 insertions(+), 2548 deletions(-)

diff --cc .gitignore
index b1c6625d645c,93a16b0b950c..1b2ecabbfe7e
--- a/.gitignore
+++ b/.gitignore
@@@ -69,11 -69,4 +69,12 @@@ stamp-
  /mpc*
  /gmp*
  /isl*
+ /gettext*
 +
 +# ADDITIONS from GCCRS front-end
 +.vscode/*
 +test.code-workspace
 +
 +gcc/rust/test3-tiny/*
 +.clang-format.swap
 +libgrust/*/target/
diff --cc Makefile.def
index fbc15cfc79d9,792f81447e1b..0e2d7869a3ab
--- a/Makefile.def
+++ b/Makefile.def
@@@ -359,8 -363,7 +365,8 @@@ dependencies = { module=configure-gcc; 
  dependencies = { module=configure-gcc; on=all-gold; };
  dependencies = { module=configure-gcc; on=all-libiconv; };
  dependencies = { module=all-gcc; on=all-libiberty; hard=true; };
 +dependencies = { module=all-gcc; on=all-libgrust; };
- dependencies = { module=all-gcc; on=all-intl; };
+ dependencies = { module=all-gcc; on=all-gettext; };
  dependencies = { module=all-gcc; on=all-mpfr; };
  dependencies = { module=all-gcc; on=all-mpc; };
  dependencies = { module=all-gcc; on=all-isl; };
diff --cc Makefile.in
index bcd46394af52,b65ab4953bce..46d310630bf7
--- a/Makefile.in
+++ b/Makefile.in
@@@ -67688,26 -65916,16 +67690,26 @@@ all-stagetrain-gcc: all-stagetrain-libi
  all-stagefeedback-gcc: all-stagefeedback-libiberty
  all-stageautoprofile-gcc: all-stageautoprofile-libiberty
  all-stageautofeedback-gcc: all-stageautofeedback-libiberty
 +all-gcc: maybe-all-libgrust
 +all-stage1-gcc: maybe-all-stage1-libgrust
 +all-stage2-gcc: maybe-all-stage2-libgrust
 +all-stage3-gcc: maybe-all-stage3-libgrust
 +all-stage4-gcc: maybe-all-stage4-libgrust
 +all-stageprofile-gcc: maybe-all-stageprofile-libgrust
 +all-stagetrain-gcc: maybe-all-stagetrain-libgrust
 +all-stagefeedback-gcc: maybe-all-stagefeedback-libgrust
 +all-stageautoprofile-gcc: maybe-all-stageautoprofile-libgrust
 +all-stageautofeedback-gcc: maybe-all-stageautofeedback-libgrust
- all-gcc: maybe-all-intl
- all-stage1-gcc: maybe-all-stage1-intl
- all-stage2-gcc: maybe-all-stage2-intl
- all-stage3-gcc: maybe-all-stage3-intl
- all-stage4-gcc: maybe-all-stage4-intl
- all-stageprofile-gcc: maybe-all-stageprofile-intl
- all-stagetrain-gcc: maybe-all-stagetrain-intl
- all-stagefeedback-gcc: maybe-all-stagefeedback-intl
- all-stageautoprofile-gcc: maybe-all-stageautoprofile-intl
- all-stageautofeedback-gcc: maybe-all-stageautofeedback-intl
+ all-gcc: maybe-all-gettext
+ all-stage1-gcc: maybe-all-stage1-gettext
+ all-stage2-gcc: maybe-all-stage2-gettext
+ all-stage3-gcc: maybe-all-stage3-gettext
+ all-stage4-gcc: maybe-all-stage4-gettext
+ all-stageprofile-gcc: maybe-all-stageprofile-gettext
+ all-stagetrain-gcc: maybe-all-stagetrain-gettext
+ all-stagefeedback-gcc: maybe-all-stagefeedback-gettext
+ all-stageautoprofile-gcc: maybe-all-stageautoprofile-gettext
+ all-stageautofeedback-gcc: maybe-all-stageautofeedback-gettext
  all-gcc: maybe-all-mpfr
  all-stage1-gcc: maybe-all-stage1-mpfr
  all-stage2-gcc: maybe-all-stage2-mpfr
diff --cc configure
index 55b1252a0305,f8abb26b4711..0ed26583b061
--- a/configure
+++ b/configure
@@@ -2829,7 -2829,7 +2829,7 @@@ build_tools="build-texinfo build-flex b
  
  # these libraries are used by various programs built for the host environment
  #f
- host_libs="intl libiberty opcodes bfd readline tcl tk itcl libgui zlib 
libbacktrace libcpp libcody libdecnumber gmp mpfr mpc isl libiconv libctf 
libsframe libgrust "
 -host_libs="gettext libiberty opcodes bfd readline tcl tk itcl libgui zlib 
libbacktrace libcpp libcody libdecnumber gmp mpfr mpc isl libiconv libctf 
libsframe"
++host_libs="gettext libiberty opcodes bfd readline tcl tk itcl libgui zlib 
libbacktrace libcpp libcody libdecnumber gmp mpfr mpc isl libiconv libctf 
libsframe libgrust "
  
  # these tools are built for the host environme

[gcc/devel/rust/master] Split up rust-macro-builtins.cc

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:2f334bb12e3ba947714771408b9d49d398abb5df

commit 2f334bb12e3ba947714771408b9d49d398abb5df
Author: jjasmine 
Date:   Sun Feb 25 03:10:37 2024 -0800

Split up rust-macro-builtins.cc

Fixes issue #2855

gcc/rust/ChangeLog:

* Make-lang.in: add new .o builds for new .cc files
* expand/rust-cfg-strip.h (RUST_CFG_STRIP_H): Add include guards
for rust-cfg-strip
* expand/rust-macro-builtins.cc (make_macro_path_str): moved to new 
respective files
(make_token): moved to new respective files
(make_string): moved to new respective files
(macro_end_token): moved to new respective files
(try_extract_string_literal_from_fragment): moved to new respective 
files
(try_expand_many_expr): moved to new respective files
(parse_single_string_literal): moved to new respective files
(source_relative_path): moved to new respective files
(load_file_bytes): moved to new respective files
(MacroBuiltin::assert_handler): moved to new respective files
(MacroBuiltin::file_handler): moved to new respective files
(MacroBuiltin::column_handler): moved to new respective files
(MacroBuiltin::include_bytes_handler): moved to new respective files
(MacroBuiltin::include_str_handler): moved to new respective files
(MacroBuiltin::compile_error_handler): moved to new respective files
(MacroBuiltin::concat_handler): moved to new respective files
(MacroBuiltin::env_handler): moved to new respective files
(MacroBuiltin::cfg_handler): moved to new respective files
(MacroBuiltin::include_handler): moved to new respective files
(MacroBuiltin::line_handler): moved to new respective files
(MacroBuiltin::stringify_handler): moved to new respective files
(struct FormatArgsInput): moved to new respective files
(struct FormatArgsParseError): moved to new respective files
(format_args_parse_arguments): moved to new respective files
(MacroBuiltin::format_args_handler): moved to new respective files
* expand/rust-macro-builtins.h (builtin_macro_from_string):
merge tl::optional from master
* expand/rust-macro-builtins-asm.cc: New file.
* expand/rust-macro-builtins-format-args.cc: New file.
* expand/rust-macro-builtins-helpers.cc: New file.
* expand/rust-macro-builtins-helpers.h: New file.
* expand/rust-macro-builtins-include.cc: New file.
* expand/rust-macro-builtins-location.cc: New file.
* expand/rust-macro-builtins-log-debug.cc: New file.
* expand/rust-macro-builtins-test-bench.cc: New file.
* expand/rust-macro-builtins-trait.cc: New file.
* expand/rust-macro-builtins-utility.cc: New file.

Diff:
---
 gcc/rust/Make-lang.in  |  11 +-
 gcc/rust/expand/rust-cfg-strip.h   |   4 +
 gcc/rust/expand/rust-macro-builtins-asm.cc |  20 +
 gcc/rust/expand/rust-macro-builtins-format-args.cc | 192 
 gcc/rust/expand/rust-macro-builtins-helpers.cc | 284 ++
 gcc/rust/expand/rust-macro-builtins-helpers.h  |  90 ++
 gcc/rust/expand/rust-macro-builtins-include.cc | 249 ++
 gcc/rust/expand/rust-macro-builtins-location.cc|  61 ++
 gcc/rust/expand/rust-macro-builtins-log-debug.cc   |  31 +
 gcc/rust/expand/rust-macro-builtins-test-bench.cc  |  20 +
 gcc/rust/expand/rust-macro-builtins-trait.cc   |  20 +
 gcc/rust/expand/rust-macro-builtins-utility.cc | 294 ++
 gcc/rust/expand/rust-macro-builtins.cc | 981 +
 gcc/rust/expand/rust-macro-builtins.h  |  79 +-
 14 files changed, 1316 insertions(+), 1020 deletions(-)

diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in
index 730598acdaa5..8f752599a3f2 100644
--- a/gcc/rust/Make-lang.in
+++ b/gcc/rust/Make-lang.in
@@ -102,6 +102,15 @@ GRS_OBJS = \
 rust/rust-proc-macro-invoc-lexer.o \
 rust/rust-macro-substitute-ctx.o \
 rust/rust-macro-builtins.o \
+rust/rust-macro-builtins-helpers.o \
+rust/rust-macro-builtins-asm.o \
+rust/rust-macro-builtins-trait.o \
+rust/rust-macro-builtins-utility.o \
+rust/rust-macro-builtins-log-debug.o \
+rust/rust-macro-builtins-test-bench.o \
+rust/rust-macro-builtins-format-args.o \
+rust/rust-macro-builtins-location.o \
+rust/rust-macro-builtins-include.o \
rust/rust-fmt.o \
 rust/rust-hir.o \
 rust/rust-hir-map.o \
@@ -408,7 +417,7 @@ rust/%.o: rust/lex/%.cc
$(COMPILE) $(RUST_CXXFLAGS) $(RUST_INCLUDES) $<
$(POSTCOMPILE)
 
-%.toml: 
+%.toml:
echo $@
 
 rust/libformat_parser.a: $(srcdir)/../libgrust/libformat_parser/Cargo.toml 
$(wildcard 

[gcc/devel/rust/master] Merge commit 'ce7a757fd9ecb99c4f54cfde5cf5ef9a9e7819fc^' into HEAD

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:20bb2dac9e47ac35252f5166f22856f73cd40d5f

commit 20bb2dac9e47ac35252f5166f22856f73cd40d5f
Merge: a88f4804345d 094091958654
Author: Thomas Schwinge 
Date:   Mon Mar 11 00:57:51 2024 +0100

Merge commit 'ce7a757fd9ecb99c4f54cfde5cf5ef9a9e7819fc^' into HEAD

Diff:

 ChangeLog  |   19 +
 MAINTAINERS|2 +
 Makefile.in|1 +
 Makefile.tpl   |1 +
 config-ml.in   |   10 -
 config/ChangeLog   |7 +
 config/mt-loongarch-elf|1 +
 config/mt-loongarch-gnu|2 +
 config/mt-loongarch-mlib   |1 +
 configure  |6 +
 configure.ac   |6 +
 contrib/ChangeLog  |   11 +
 contrib/gcc_update |2 +-
 gcc/ChangeLog  |  872 
 gcc/DATESTAMP  |2 +-
 gcc/ada/ChangeLog  |  165 +
 gcc/ada/accessibility.adb  |   92 +-
 gcc/ada/accessibility.ads  |9 -
 gcc/ada/atree.adb  |  210 +-
 gcc/ada/bindgen.adb|   10 +-
 .../building_executable_programs_with_gnat.rst |   22 -
 gcc/ada/einfo-utils.adb|6 +-
 gcc/ada/einfo-utils.ads|6 +-
 gcc/ada/exp_aggr.adb   |   21 +-
 gcc/ada/exp_ch6.adb|   20 +-
 gcc/ada/exp_ch9.adb|   38 +-
 gcc/ada/exp_util.adb   |  268 +-
 gcc/ada/exp_util.ads   |   17 +
 gcc/ada/frontend.adb   |2 -
 gcc/ada/gcc-interface/utils.cc |2 +-
 gcc/ada/gen_il-gen-gen_entities.adb|   27 +
 gcc/ada/gen_il-types.ads   |1 +
 gcc/ada/inline.adb |1 +
 gcc/ada/sem.adb|1 -
 gcc/ada/sem.ads|3 +-
 gcc/ada/sem_aggr.adb   |5 +-
 gcc/ada/sem_ch6.adb|   30 +-
 gcc/ada/sem_ch8.adb|5 +-
 gcc/ada/sem_ch8.ads|5 +-
 gcc/ada/sem_res.adb|3 +
 gcc/ada/sem_util.adb   |   21 +-
 gcc/ada/sem_util.ads   |3 +-
 gcc/analyzer/ChangeLog |   77 +
 gcc/analyzer/analyzer.cc   |2 +
 gcc/analyzer/analyzer.h|1 +
 gcc/analyzer/checker-event.h   |4 +
 gcc/analyzer/checker-path.h|   17 +-
 gcc/analyzer/diagnostic-manager.cc |   91 +-
 gcc/analyzer/diagnostic-manager.h  |   53 +-
 gcc/analyzer/engine.cc |   44 +-
 gcc/analyzer/exploded-graph.h  |9 +-
 gcc/analyzer/feasible-graph.cc |7 +-
 gcc/analyzer/feasible-graph.h  |9 +-
 gcc/analyzer/infinite-recursion.cc |6 +-
 gcc/analyzer/region-model.cc   |   46 +-
 gcc/analyzer/region-model.h|   10 +-
 gcc/c/ChangeLog|   33 +
 gcc/c/c-decl.cc|   26 +
 gcc/c/c-parser.cc  |  135 +-
 gcc/c/c-tree.h |1 +
 gcc/c/c-typeck.cc  |  282 +-
 gcc/config.gcc |9 +-
 gcc/config/aarch64/aarch64-cores.def   |6 +-
 gcc/config/aarch64/aarch64-sve.md  |   15 +-
 gcc/config/aarch64/aarch64-tune.md |2 +-
 gcc/config/aarch64/aarch64.cc  |  605 +--
 gcc/config/aarch64/aarch64.h   |   44 +-
 gcc/config/aarch64/aarch64.md  |2 +-
 gcc/config/aarch64/predicates.md   |4 -
 gcc/config/i386/i386.cc|4 +-
 gcc/config/loongarch/loongarch-def.c   |4 +-
 gcc/config/loongarch/loongarch-driver.h|   42 +
 gcc/config/loongarch/loongarch.h   |   50 -
 gcc/config/loongarch/loongarch.md  |   20 +-
 gcc/config/loongarch/t-linux   |   66 +-
 gcc/config/loongarch/t-loongarch   |2 +-
 gcc/config/loongarch/t

[gcc/devel/rust/master] Merge commit '4968e4844a3ce30143ae2e267895c418f5c636a1' into HEAD

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:79be34b6dc7385855d233c1d3d5ce347998e7f57

commit 79be34b6dc7385855d233c1d3d5ce347998e7f57
Merge: 9d6e836c2c66 4968e4844a3c
Author: Thomas Schwinge 
Date:   Sat Mar 16 23:55:02 2024 +0100

Merge commit '4968e4844a3ce30143ae2e267895c418f5c636a1' into HEAD

Diff:


[gcc/devel/rust/master] Fix typo

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:b4c3a6ca4f83733f4122ec1e56b5bc69b9fab1b4

commit b4c3a6ca4f83733f4122ec1e56b5bc69b9fab1b4
Author: Guillaume Gomez 
Date:   Tue Mar 5 20:24:30 2024 +0100

Fix typo

gcc/rust/ChangeLog:

* expand/rust-derive.cc (DeriveVisitor::derive): Fix typo

Diff:
---
 gcc/rust/expand/rust-derive.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/rust/expand/rust-derive.cc b/gcc/rust/expand/rust-derive.cc
index 4177004eccf2..e6778fea9729 100644
--- a/gcc/rust/expand/rust-derive.cc
+++ b/gcc/rust/expand/rust-derive.cc
@@ -45,7 +45,7 @@ DeriveVisitor::derive (Item , const Attribute ,
 case BuiltinMacro::PartialOrd:
 case BuiltinMacro::Hash:
 default:
-  rust_sorry_at (attr.get_locus (), "uninmplemented builtin derive macro");
+  rust_sorry_at (attr.get_locus (), "unimplemented builtin derive macro");
   return nullptr;
 };
 }


[gcc/devel/rust/master] TyTy: Collect variance info from types

2024-05-07 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:ac4544492688cc0dfcf7c7f8104907128aa75d89

commit ac4544492688cc0dfcf7c7f8104907128aa75d89
Author: Jakub Dupak 
Date:   Fri Feb 2 14:12:13 2024 +0100

TyTy: Collect variance info from types

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit):
Collect variance info from types.

Signed-off-by: Jakub Dupak 

Diff:
---
 gcc/rust/typecheck/rust-hir-type-check-item.cc | 17 +
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/gcc/rust/typecheck/rust-hir-type-check-item.cc 
b/gcc/rust/typecheck/rust-hir-type-check-item.cc
index 16b4906a3569..4bbd28021a02 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-item.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-item.cc
@@ -25,6 +25,7 @@
 #include "rust-hir-trait-resolve.h"
 #include "rust-substitution-mapper.h"
 #include "rust-type-util.h"
+#include "rust-tyty-variance-analysis.h"
 
 namespace Rust {
 namespace Resolver {
@@ -204,7 +205,7 @@ TypeCheckItem::visit (HIR::TupleStruct _decl)
   TyTy::ADTType::ReprOptions repr
 = parse_repr_options (attrs, struct_decl.get_locus ());
 
-  TyTy::BaseType *type = new TyTy::ADTType (
+  auto *type = new TyTy::ADTType (
 struct_decl.get_mappings ().get_hirid (), mappings->get_next_hir_id (),
 struct_decl.get_identifier ().as_string (), ident,
 TyTy::ADTType::ADTKind::TUPLE_STRUCT, std::move (variants),
@@ -215,6 +216,8 @@ TypeCheckItem::visit (HIR::TupleStruct _decl)
 
   context->insert_type (struct_decl.get_mappings (), type);
   infered = type;
+
+  context->get_variance_analysis_ctx ().add_type_constraints (*type);
 }
 
 void
@@ -266,7 +269,7 @@ TypeCheckItem::visit (HIR::StructStruct _decl)
   TyTy::ADTType::ReprOptions repr
 = parse_repr_options (attrs, struct_decl.get_locus ());
 
-  TyTy::BaseType *type = new TyTy::ADTType (
+  auto *type = new TyTy::ADTType (
 struct_decl.get_mappings ().get_hirid (), mappings->get_next_hir_id (),
 struct_decl.get_identifier ().as_string (), ident,
 TyTy::ADTType::ADTKind::STRUCT_STRUCT, std::move (variants),
@@ -277,6 +280,8 @@ TypeCheckItem::visit (HIR::StructStruct _decl)
 
   context->insert_type (struct_decl.get_mappings (), type);
   infered = type;
+
+  context->get_variance_analysis_ctx ().add_type_constraints (*type);
 }
 
 void
@@ -307,7 +312,7 @@ TypeCheckItem::visit (HIR::Enum _decl)
   RustIdent ident{*canonical_path, enum_decl.get_locus ()};
 
   // multi variant ADT
-  TyTy::BaseType *type
+  auto *type
 = new TyTy::ADTType (enum_decl.get_mappings ().get_hirid (),
 mappings->get_next_hir_id (),
 enum_decl.get_identifier ().as_string (), ident,
@@ -316,6 +321,8 @@ TypeCheckItem::visit (HIR::Enum _decl)
 
   context->insert_type (enum_decl.get_mappings (), type);
   infered = type;
+
+  context->get_variance_analysis_ctx ().add_type_constraints (*type);
 }
 
 void
@@ -363,7 +370,7 @@ TypeCheckItem::visit (HIR::Union _decl)
  TyTy::VariantDef::VariantType::STRUCT, nullptr,
  std::move (fields)));
 
-  TyTy::BaseType *type
+  auto *type
 = new TyTy::ADTType (union_decl.get_mappings ().get_hirid (),
 mappings->get_next_hir_id (),
 union_decl.get_identifier ().as_string (), ident,
@@ -372,6 +379,8 @@ TypeCheckItem::visit (HIR::Union _decl)
 
   context->insert_type (union_decl.get_mappings (), type);
   infered = type;
+
+  context->get_variance_analysis_ctx ().add_type_constraints (*type);
 }
 
 void


<    1   2   3   4   5   6   7   8   9   10   >