* [PATCHSET] Update Rust frontend 21/03/2024 3/4
@ 2025-03-21 12:05 arthur.cohen
2025-03-21 12:05 ` [COMMITTED 001/146] gccrs: Fix bad recursive operator overload call arthur.cohen
` (145 more replies)
0 siblings, 146 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:05 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust
Hi everyone,
This is our the third patchset in the series for updating upstream GCC
with the latest changes in our development repository.
Most notably this contains handling for if-let statements by Marc
Poulhiès, changes to our name-resolution pass rewrite, and massive
changes to our AST and HIR representations to allow Rust lang-item paths
to be represented. This is different from how the official Rust compiler
handles lang-items, but allows us to refer to essential Rust items
easily while we are still in the process of compiling said core crate.
These lang-item changes also enabled us to continue our work on built-in
derive macros, with Clone and Copy being fully implemented in this
patchset. The remaining built-in derive macros will be upstreamed in the
next patchset. We are still missing on PartialOrd and PartialEq, which
will be upstreamed in time for 15.1.
There are also multiple type-system fixes, and testsuite fixes for
systems with different endianness.
Kindly,
Arthur
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 001/146] gccrs: Fix bad recursive operator overload call
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
@ 2025-03-21 12:05 ` arthur.cohen
2025-03-21 12:05 ` [COMMITTED 002/146] gccrs: Insert trait names during toplevel resolution 2.0 arthur.cohen
` (144 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:05 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Philip Herron
From: Philip Herron <herron.philip@googlemail.com>
When we are typechecking the impl block for DerefMut for &mut T
the implementation follows the usual operator overload check
but this ended up just resolving directly to the Trait definition
which ends up being recursive which we usually handle. The issue
we had is that a dereference call can be for either the DEREF
or DEREF_MUT lang item here it was looking for a recurisve call
to the DEREF lang item but we were in the DEREF_MUT lang item
so this case was not accounted for.
Fixes #3032
gcc/rust/ChangeLog:
* typecheck/rust-hir-trait-reference.h: new get locus helper
* typecheck/rust-hir-trait-resolve.cc (AssociatedImplTrait::get_locus): implemention
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::resolve_operator_overload):
fix overload
gcc/testsuite/ChangeLog:
* rust/compile/nr2/exclude: nr2 cant handle this
* rust/compile/issue-3032-1.rs: New test.
* rust/compile/issue-3032-2.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
---
gcc/rust/typecheck/rust-hir-trait-reference.h | 2 +
gcc/rust/typecheck/rust-hir-trait-resolve.cc | 6 ++
.../typecheck/rust-hir-type-check-expr.cc | 21 +++++--
gcc/testsuite/rust/compile/issue-3032-1.rs | 58 +++++++++++++++++++
gcc/testsuite/rust/compile/issue-3032-2.rs | 49 ++++++++++++++++
gcc/testsuite/rust/compile/nr2/exclude | 4 +-
6 files changed, 134 insertions(+), 6 deletions(-)
create mode 100644 gcc/testsuite/rust/compile/issue-3032-1.rs
create mode 100644 gcc/testsuite/rust/compile/issue-3032-2.rs
diff --git a/gcc/rust/typecheck/rust-hir-trait-reference.h b/gcc/rust/typecheck/rust-hir-trait-reference.h
index bdfd9879111..41970335375 100644
--- a/gcc/rust/typecheck/rust-hir-trait-reference.h
+++ b/gcc/rust/typecheck/rust-hir-trait-reference.h
@@ -246,6 +246,8 @@ public:
HIR::ImplBlock *get_impl_block ();
+ location_t get_locus () const;
+
TyTy::BaseType *get_self ();
const TyTy::BaseType *get_self () const;
diff --git a/gcc/rust/typecheck/rust-hir-trait-resolve.cc b/gcc/rust/typecheck/rust-hir-trait-resolve.cc
index ec331cf6e95..91842df85b2 100644
--- a/gcc/rust/typecheck/rust-hir-trait-resolve.cc
+++ b/gcc/rust/typecheck/rust-hir-trait-resolve.cc
@@ -669,6 +669,12 @@ AssociatedImplTrait::reset_associated_types ()
trait->clear_associated_types ();
}
+location_t
+AssociatedImplTrait::get_locus () const
+{
+ return impl->get_locus ();
+}
+
Analysis::NodeMapping
TraitItemReference::get_parent_trait_mappings () const
{
diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
index ba22eaff441..dfdf85a141d 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
@@ -1822,10 +1822,20 @@ TypeCheckExpr::resolve_operator_overload (LangItem::Kind lang_item_type,
HIR::ImplBlock *parent = impl_item.first;
HIR::Function *fn = impl_item.second;
- if (parent->has_trait_ref ()
- && fn->get_function_name ().as_string ().compare (
- associated_item_name)
- == 0)
+ bool is_deref = lang_item_type == LangItem::Kind::DEREF
+ || lang_item_type == LangItem::Kind::DEREF_MUT;
+ bool is_deref_match = fn->get_function_name ().as_string ().compare (
+ LangItem::ToString (LangItem::Kind::DEREF))
+ == 0
+ || fn->get_function_name ().as_string ().compare (
+ LangItem::ToString (LangItem::Kind::DEREF_MUT))
+ == 0;
+
+ bool is_recursive_op
+ = fn->get_function_name ().as_string ().compare (associated_item_name)
+ == 0
+ || (is_deref && is_deref_match);
+ if (parent->has_trait_ref () && is_recursive_op)
{
TraitReference *trait_reference
= TraitResolver::Lookup (*parent->get_trait_ref ().get ());
@@ -1842,7 +1852,8 @@ TypeCheckExpr::resolve_operator_overload (LangItem::Kind lang_item_type,
bool is_lang_item_impl
= trait_reference->get_mappings ().get_defid ()
- == respective_lang_item_id;
+ == respective_lang_item_id
+ || (is_deref && is_deref_match);
bool self_is_lang_item_self
= fntype->get_self_type ()->is_equal (*adjusted_self);
bool recursive_operator_overload
diff --git a/gcc/testsuite/rust/compile/issue-3032-1.rs b/gcc/testsuite/rust/compile/issue-3032-1.rs
new file mode 100644
index 00000000000..e9eb02794ce
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-3032-1.rs
@@ -0,0 +1,58 @@
+#![feature(negative_impls)]
+
+#[lang = "sized"]
+trait Sized {}
+
+#[lang = "deref"]
+pub trait Deref {
+ /// The resulting type after dereferencing.
+ #[stable(feature = "rust1", since = "1.0.0")]
+ // #[rustc_diagnostic_item = "deref_target"]
+ type Target: ?Sized;
+
+ /// Dereferences the value.
+ #[must_use]
+ #[stable(feature = "rust1", since = "1.0.0")]
+ // #[rustc_diagnostic_item = "deref_method"]
+ fn deref(&self) -> &Self::Target;
+}
+
+impl<T: ?Sized> Deref for &T {
+ type Target = T;
+
+ fn deref(&self) -> &T {
+ *self
+ }
+}
+
+// this is added because of #3030
+extern "C" {
+ fn never() -> !;
+}
+
+impl<T: ?Sized> !DerefMut for &T {
+ fn deref_mut(&mut self) -> &mut T {
+ unsafe { never() }
+ }
+}
+
+impl<T: ?Sized> Deref for &mut T {
+ type Target = T;
+
+ fn deref(&self) -> &T {
+ *self
+ }
+}
+
+#[lang = "deref_mut"]
+pub trait DerefMut: Deref {
+ /// Mutably dereferences the value.
+ #[stable(feature = "rust1", since = "1.0.0")]
+ fn deref_mut(&mut self) -> &mut Self::Target;
+}
+
+impl<T: ?Sized> DerefMut for &mut T {
+ fn deref_mut(&mut self) -> &mut T {
+ *self
+ }
+}
diff --git a/gcc/testsuite/rust/compile/issue-3032-2.rs b/gcc/testsuite/rust/compile/issue-3032-2.rs
new file mode 100644
index 00000000000..9e09d419072
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-3032-2.rs
@@ -0,0 +1,49 @@
+#![feature(negative_impls)]
+
+#[lang = "sized"]
+trait Sized {}
+
+#[lang = "deref"]
+pub trait Deref {
+ /// The resulting type after dereferencing.
+ #[stable(feature = "rust1", since = "1.0.0")]
+ // #[rustc_diagnostic_item = "deref_target"]
+ type Target: ?Sized;
+
+ /// Dereferences the value.
+ #[must_use]
+ #[stable(feature = "rust1", since = "1.0.0")]
+ // #[rustc_diagnostic_item = "deref_method"]
+ fn deref(&self) -> &Self::Target;
+}
+
+impl<T: ?Sized> Deref for &T {
+ type Target = T;
+
+ fn deref(&self) -> &T {
+ *self
+ }
+}
+
+impl<T: ?Sized> !DerefMut for &T {}
+
+impl<T: ?Sized> Deref for &mut T {
+ type Target = T;
+
+ fn deref(&self) -> &T {
+ *self
+ }
+}
+
+#[lang = "deref_mut"]
+pub trait DerefMut: Deref {
+ /// Mutably dereferences the value.
+ #[stable(feature = "rust1", since = "1.0.0")]
+ fn deref_mut(&mut self) -> &mut Self::Target;
+}
+
+impl<T: ?Sized> DerefMut for &mut T {
+ fn deref_mut(&mut self) -> &mut T {
+ *self
+ }
+}
diff --git a/gcc/testsuite/rust/compile/nr2/exclude b/gcc/testsuite/rust/compile/nr2/exclude
index ecef6d2bb25..383950ca863 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -234,4 +234,6 @@ issue-3139-3.rs
issue-3036.rs
issue-2951.rs
issue-2203.rs
-issue-2499.rs
\ No newline at end of file
+issue-2499.rs
+issue-3032-1.rs
+issue-3032-2.rs
\ No newline at end of file
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 002/146] gccrs: Insert trait names during toplevel resolution 2.0
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
2025-03-21 12:05 ` [COMMITTED 001/146] gccrs: Fix bad recursive operator overload call arthur.cohen
@ 2025-03-21 12:05 ` arthur.cohen
2025-03-21 12:05 ` [COMMITTED 003/146] gccrs: Fix variable shadowing in late " arthur.cohen
` (143 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:05 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Owen Avery
From: Owen Avery <powerboat9.gamer@gmail.com>
gcc/rust/ChangeLog:
* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::visit): Insert trait names into the type namespace.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
---
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 a0d8492b7eb..fff3769cd70 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
@@ -120,6 +120,9 @@ TopLevel::visit (AST::Trait &trait)
trait.insert_implict_self (
std::unique_ptr<AST::GenericParam> (implicit_self));
+ insert_or_error_out (trait.get_identifier ().as_string (), trait,
+ Namespace::Types);
+
DefaultResolver::visit (trait);
}
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 003/146] gccrs: Fix variable shadowing in late resolution 2.0
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
2025-03-21 12:05 ` [COMMITTED 001/146] gccrs: Fix bad recursive operator overload call arthur.cohen
2025-03-21 12:05 ` [COMMITTED 002/146] gccrs: Insert trait names during toplevel resolution 2.0 arthur.cohen
@ 2025-03-21 12:05 ` arthur.cohen
2025-03-21 12:05 ` [COMMITTED 004/146] gccrs: Add a newline to the end of nr2/exclude arthur.cohen
` (142 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:05 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Owen Avery
From: Owen Avery <powerboat9.gamer@gmail.com>
gcc/rust/ChangeLog:
* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): Visit the initialization expressions of let
statements before visiting their patterns.
gcc/testsuite/ChangeLog:
* rust/compile/nr2/exclude: Remove entries.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
---
gcc/rust/resolve/rust-late-name-resolver-2.0.cc | 10 ++++++++--
gcc/testsuite/rust/compile/nr2/exclude | 3 ---
2 files changed, 8 insertions(+), 5 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 43f33dfab02..5fd49e7c2c9 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
@@ -126,8 +126,14 @@ Late::new_label (Identifier name, NodeId id)
void
Late::visit (AST::LetStmt &let)
{
- // so we don't need that method
- DefaultResolver::visit (let);
+ DefaultASTVisitor::visit_outer_attrs (let);
+ if (let.has_type ())
+ visit (let.get_type ());
+ // visit expression before pattern
+ // this makes variable shadowing work properly
+ if (let.has_init_expr ())
+ visit (let.get_init_expr ());
+ visit (let.get_pattern ());
// how do we deal with the fact that `let a = blipbloup` should look for a
// label and cannot go through function ribs, but `let a = blipbloup()` can?
diff --git a/gcc/testsuite/rust/compile/nr2/exclude b/gcc/testsuite/rust/compile/nr2/exclude
index 383950ca863..c96fde25fc5 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -74,10 +74,8 @@ issue-1589.rs
issue-1725-1.rs
issue-1725-2.rs
issue-1786.rs
-issue-1813.rs
issue-1893.rs
issue-1901.rs
-issue-1930.rs
issue-1981.rs
issue-2019-1.rs
issue-2019-2.rs
@@ -142,7 +140,6 @@ match4.rs
match5.rs
match9.rs
method2.rs
-multi_reference_type.rs
multiple_bindings1.rs
multiple_bindings2.rs
name_resolution2.rs
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 004/146] gccrs: Add a newline to the end of nr2/exclude
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (2 preceding siblings ...)
2025-03-21 12:05 ` [COMMITTED 003/146] gccrs: Fix variable shadowing in late " arthur.cohen
@ 2025-03-21 12:05 ` arthur.cohen
2025-03-21 12:05 ` [COMMITTED 005/146] gccrs: Rename some PathIdentSegment functions arthur.cohen
` (141 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:05 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Owen Avery
From: Owen Avery <powerboat9.gamer@gmail.com>
gcc/testsuite/ChangeLog:
* rust/compile/nr2/exclude: Add trailing newline along with
comment.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
---
gcc/testsuite/rust/compile/nr2/exclude | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/gcc/testsuite/rust/compile/nr2/exclude b/gcc/testsuite/rust/compile/nr2/exclude
index c96fde25fc5..57bcca0a60e 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -233,4 +233,5 @@ issue-2951.rs
issue-2203.rs
issue-2499.rs
issue-3032-1.rs
-issue-3032-2.rs
\ No newline at end of file
+issue-3032-2.rs
+# please don't delete the trailing newline
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 005/146] gccrs: Rename some PathIdentSegment functions
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (3 preceding siblings ...)
2025-03-21 12:05 ` [COMMITTED 004/146] gccrs: Add a newline to the end of nr2/exclude arthur.cohen
@ 2025-03-21 12:05 ` arthur.cohen
2025-03-21 12:05 ` [COMMITTED 006/146] gccrs: Use name resolution 2.0 in TraitItemReference arthur.cohen
` (140 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:05 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Owen Avery
From: Owen Avery <powerboat9.gamer@gmail.com>
This makes PathIdentSegment more similar to other classes used to
represent path segments.
gcc/rust/ChangeLog:
* ast/rust-path.h
(PathIdentSegment::is_super_segment): Rename to...
(PathIdentSegment::is_super_path_seg): ...here.
(PathIdentSegment::is_crate_segment): Rename to...
(PathIdentSegment::is_crate_path_seg): ...here.
(PathIdentSegment::is_lower_self): Rename to...
(PathIdentSegment::is_lower_self_seg): ...here.
(PathIdentSegment::is_big_self): Rename to...
(PathIdentSegment::is_big_self_seg): ...here.
(PathExprSegment::is_super_path_seg): Handle renames.
(PathExprSegment::is_crate_path_seg): Likewise.
(PathExprSegment::is_lower_self_seg): Likewise.
(TypePathSegment::is_crate_path_seg): Likewise.
(TypePathSegment::is_super_path_seg): Likewise.
(TypePathSegment::is_big_self_seg): Likewise.
(TypePathSegment::is_lower_self_seg): Likewise.
* ast/rust-ast-collector.cc
(TokenCollector::visit): Likewise.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
---
gcc/rust/ast/rust-ast-collector.cc | 8 ++++----
gcc/rust/ast/rust-path.h | 31 +++++++++++++++++++-----------
2 files changed, 24 insertions(+), 15 deletions(-)
diff --git a/gcc/rust/ast/rust-ast-collector.cc b/gcc/rust/ast/rust-ast-collector.cc
index 20226687846..bc76deb9a6d 100644
--- a/gcc/rust/ast/rust-ast-collector.cc
+++ b/gcc/rust/ast/rust-ast-collector.cc
@@ -711,19 +711,19 @@ TokenCollector::visit (TypePath &path)
void
TokenCollector::visit (PathIdentSegment &segment)
{
- if (segment.is_super_segment ())
+ if (segment.is_super_path_seg ())
{
push (Rust::Token::make (SUPER, segment.get_locus ()));
}
- else if (segment.is_crate_segment ())
+ else if (segment.is_crate_path_seg ())
{
push (Rust::Token::make (CRATE, segment.get_locus ()));
}
- else if (segment.is_lower_self ())
+ else if (segment.is_lower_self_seg ())
{
push (Rust::Token::make (SELF, segment.get_locus ()));
}
- else if (segment.is_big_self ())
+ else if (segment.is_big_self_seg ())
{
push (Rust::Token::make (SELF_ALIAS, segment.get_locus ()));
}
diff --git a/gcc/rust/ast/rust-path.h b/gcc/rust/ast/rust-path.h
index 98fde5a2606..2cad3955494 100644
--- a/gcc/rust/ast/rust-path.h
+++ b/gcc/rust/ast/rust-path.h
@@ -55,10 +55,16 @@ public:
location_t get_locus () const { return locus; }
- bool is_super_segment () const { return as_string ().compare ("super") == 0; }
- bool is_crate_segment () const { return as_string ().compare ("crate") == 0; }
- bool is_lower_self () const { return as_string ().compare ("self") == 0; }
- bool is_big_self () const { return as_string ().compare ("Self") == 0; }
+ bool is_super_path_seg () const
+ {
+ return as_string ().compare ("super") == 0;
+ }
+ bool is_crate_path_seg () const
+ {
+ return as_string ().compare ("crate") == 0;
+ }
+ bool is_lower_self_seg () const { return as_string ().compare ("self") == 0; }
+ bool is_big_self_seg () const { return as_string ().compare ("Self") == 0; }
};
// A binding of an identifier to a type used in generic arguments in paths
@@ -560,17 +566,17 @@ public:
bool is_super_path_seg () const
{
- return !has_generic_args () && get_ident_segment ().is_super_segment ();
+ return !has_generic_args () && get_ident_segment ().is_super_path_seg ();
}
bool is_crate_path_seg () const
{
- return !has_generic_args () && get_ident_segment ().is_crate_segment ();
+ return !has_generic_args () && get_ident_segment ().is_crate_path_seg ();
}
bool is_lower_self_seg () const
{
- return !has_generic_args () && get_ident_segment ().is_lower_self ();
+ return !has_generic_args () && get_ident_segment ().is_lower_self_seg ();
}
};
@@ -950,16 +956,19 @@ public:
bool is_crate_path_seg () const
{
- return get_ident_segment ().is_crate_segment ();
+ return get_ident_segment ().is_crate_path_seg ();
}
bool is_super_path_seg () const
{
- return get_ident_segment ().is_super_segment ();
+ return get_ident_segment ().is_super_path_seg ();
+ }
+ bool is_big_self_seg () const
+ {
+ return get_ident_segment ().is_big_self_seg ();
}
- bool is_big_self_seg () const { return get_ident_segment ().is_big_self (); }
bool is_lower_self_seg () const
{
- return get_ident_segment ().is_lower_self ();
+ return get_ident_segment ().is_lower_self_seg ();
}
};
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 006/146] gccrs: Use name resolution 2.0 in TraitItemReference
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (4 preceding siblings ...)
2025-03-21 12:05 ` [COMMITTED 005/146] gccrs: Rename some PathIdentSegment functions arthur.cohen
@ 2025-03-21 12:05 ` arthur.cohen
2025-03-21 12:05 ` [COMMITTED 007/146] gccrs: Use name resolver 2.0 in CompileTraitItem arthur.cohen
` (139 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:05 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Owen Avery
From: Owen Avery <powerboat9.gamer@gmail.com>
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check.cc: Add includes.
(TraitItemReference::get_type_from_fn): Use
ForeverStack::to_canonical_path when name resolution 2.0 is
enabled.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
---
gcc/rust/typecheck/rust-hir-type-check.cc | 23 +++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/gcc/rust/typecheck/rust-hir-type-check.cc b/gcc/rust/typecheck/rust-hir-type-check.cc
index 45cb75d87fe..51ab87d14b8 100644
--- a/gcc/rust/typecheck/rust-hir-type-check.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check.cc
@@ -23,6 +23,10 @@
#include "rust-hir-type-check-item.h"
#include "rust-hir-type-check-pattern.h"
#include "rust-hir-type-check-struct-field.h"
+#include "rust-immutable-name-resolution-context.h"
+
+// for flag_name_resolution_2_0
+#include "options.h"
extern bool
saw_errors (void);
@@ -299,8 +303,23 @@ TraitItemReference::get_type_from_fn (/*const*/ HIR::TraitItemFunc &fn) const
}
auto &mappings = Analysis::Mappings::get ();
- auto canonical_path
- = mappings.lookup_canonical_path (fn.get_mappings ().get_nodeid ());
+
+ tl::optional<CanonicalPath> canonical_path;
+ if (flag_name_resolution_2_0)
+ {
+ auto &nr_ctx
+ = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+
+ canonical_path
+ = nr_ctx.values.to_canonical_path (fn.get_mappings ().get_nodeid ());
+ }
+ else
+ {
+ canonical_path
+ = mappings.lookup_canonical_path (fn.get_mappings ().get_nodeid ());
+ }
+
+ rust_assert (canonical_path);
RustIdent ident{*canonical_path, fn.get_locus ()};
auto resolved = new TyTy::FnType (
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 007/146] gccrs: Use name resolver 2.0 in CompileTraitItem
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (5 preceding siblings ...)
2025-03-21 12:05 ` [COMMITTED 006/146] gccrs: Use name resolution 2.0 in TraitItemReference arthur.cohen
@ 2025-03-21 12:05 ` arthur.cohen
2025-03-21 12:05 ` [COMMITTED 008/146] gccrs: Improve path handling while testing name resolution 2.0 arthur.cohen
` (138 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:05 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Owen Avery
From: Owen Avery <powerboat9.gamer@gmail.com>
gcc/rust/ChangeLog:
* backend/rust-compile-implitem.cc
(CompileTraitItem::visit): Use name resolver 2.0 (when enabled)
to obtain canonical paths for instances of TraitItemConst and
TraitItemFunc.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
---
gcc/rust/backend/rust-compile-implitem.cc | 36 ++++++++++++++++++++---
1 file changed, 32 insertions(+), 4 deletions(-)
diff --git a/gcc/rust/backend/rust-compile-implitem.cc b/gcc/rust/backend/rust-compile-implitem.cc
index 4c7d8e821a1..98337c8f9bb 100644
--- a/gcc/rust/backend/rust-compile-implitem.cc
+++ b/gcc/rust/backend/rust-compile-implitem.cc
@@ -27,8 +27,22 @@ CompileTraitItem::visit (HIR::TraitItemConst &constant)
rust_assert (concrete != nullptr);
TyTy::BaseType *resolved_type = concrete;
- auto canonical_path = ctx->get_mappings ().lookup_canonical_path (
- constant.get_mappings ().get_nodeid ());
+ tl::optional<Resolver::CanonicalPath> canonical_path;
+ if (flag_name_resolution_2_0)
+ {
+ auto &nr_ctx
+ = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+
+ canonical_path = nr_ctx.values.to_canonical_path (
+ constant.get_mappings ().get_nodeid ());
+ }
+ else
+ {
+ canonical_path = ctx->get_mappings ().lookup_canonical_path (
+ constant.get_mappings ().get_nodeid ());
+ }
+
+ rust_assert (canonical_path);
HIR::Expr *const_value_expr = constant.get_expr ().get ();
tree const_expr
@@ -75,8 +89,22 @@ CompileTraitItem::visit (HIR::TraitItemFunc &func)
fntype->override_context ();
}
- auto canonical_path = ctx->get_mappings ().lookup_canonical_path (
- func.get_mappings ().get_nodeid ());
+ tl::optional<Resolver::CanonicalPath> canonical_path;
+ if (flag_name_resolution_2_0)
+ {
+ auto &nr_ctx
+ = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+
+ canonical_path
+ = nr_ctx.values.to_canonical_path (func.get_mappings ().get_nodeid ());
+ }
+ else
+ {
+ canonical_path = ctx->get_mappings ().lookup_canonical_path (
+ func.get_mappings ().get_nodeid ());
+ }
+
+ rust_assert (canonical_path);
// FIXME: How do we get the proper visibility here?
auto vis = HIR::Visibility (HIR::Visibility::VisType::PUBLIC);
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 008/146] gccrs: Improve path handling while testing name resolution 2.0
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (6 preceding siblings ...)
2025-03-21 12:05 ` [COMMITTED 007/146] gccrs: Use name resolver 2.0 in CompileTraitItem arthur.cohen
@ 2025-03-21 12:05 ` arthur.cohen
2025-03-21 12:05 ` [COMMITTED 009/146] gccrs: Fix name resolution 2.0 definition lookups in unsafe checker arthur.cohen
` (137 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:05 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Owen Avery
From: Owen Avery <powerboat9.gamer@gmail.com>
gcc/testsuite/ChangeLog:
* rust/compile/nr2/compile.exp: Handle paths using "file join"
and "file split".
* rust/compile/nr2/exclude: Remove debug-diagnostics-on.rs.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
---
gcc/testsuite/rust/compile/nr2/compile.exp | 18 +++++++++---------
gcc/testsuite/rust/compile/nr2/exclude | 5 -----
2 files changed, 9 insertions(+), 14 deletions(-)
diff --git a/gcc/testsuite/rust/compile/nr2/compile.exp b/gcc/testsuite/rust/compile/nr2/compile.exp
index 0afe36c3c40..f2724f6c454 100644
--- a/gcc/testsuite/rust/compile/nr2/compile.exp
+++ b/gcc/testsuite/rust/compile/nr2/compile.exp
@@ -44,23 +44,23 @@ namespace eval rust-nr2-ns {
# Run tests in directories
# Manually specifying these, in case some other test file
# does something weird
- set test_dirs {. compile macros/builtin macros/mbe macros/proc}
+ set test_dirs {{} {macros builtin} {macros mbe} {macros proc}}
set tests_expect_ok ""
set tests_expect_err ""
foreach test_dir $test_dirs {
- foreach test [lsort [glob -nocomplain -tails -directory $srcdir/$subdir/../$test_dir *.rs]] {
- if {$test_dir == "."} {
- set test_lbl $test
- } else {
- set test_lbl "$test_dir/$test"
- }
+ set directory [list {*}[file split $srcdir] {*}[file split $subdir]]
+ set directory [lreplace $directory end end]
+ set directory [list {*}$directory {*}$test_dir]
+ foreach test [lsort [glob -nocomplain -tails -directory [file join {*}$directory] *.rs]] {
+ # use '/' as the path seperator for entries in the exclude file
+ set test_lbl [join [list {*}$test_dir $test] "/"]
set idx [lsearch -exact -sorted $exclude $test_lbl]
if {$idx == -1} {
- lappend tests_expect_ok $srcdir/$subdir/../$test_dir/$test
+ lappend tests_expect_ok [file join {*}$directory $test]
} else {
- lappend tests_expect_err $srcdir/$subdir/../$test_dir/$test
+ lappend tests_expect_err [file join {*}$directory $test]
set exclude [lreplace $exclude $idx $idx]
}
}
diff --git a/gcc/testsuite/rust/compile/nr2/exclude b/gcc/testsuite/rust/compile/nr2/exclude
index 57bcca0a60e..450fc254452 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -1,8 +1,3 @@
-# relies on exact source file path match
-# TODO: patch this file or nr2/compile.exp to handle this
-debug-diagnostics-on.rs
-
-# main list
attr-mismatch-crate-name.rs
attr_deprecated.rs
attr_deprecated_2.rs
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 009/146] gccrs: Fix name resolution 2.0 definition lookups in unsafe checker
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (7 preceding siblings ...)
2025-03-21 12:05 ` [COMMITTED 008/146] gccrs: Improve path handling while testing name resolution 2.0 arthur.cohen
@ 2025-03-21 12:05 ` arthur.cohen
2025-03-21 12:05 ` [COMMITTED 010/146] rust: Desugar IfLet* into MatchExpr arthur.cohen
` (136 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:05 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Owen Avery
From: Owen Avery <powerboat9.gamer@gmail.com>
gcc/rust/ChangeLog:
* checks/errors/rust-unsafe-checker.cc: Add includes.
(UnsafeChecker::visit): Use 2.0 version of resolver when name
resolution 2.0 is enabled.
gcc/testsuite/ChangeLog:
* rust/compile/nr2/exclude: Remove entries.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
---
gcc/rust/checks/errors/rust-unsafe-checker.cc | 42 +++++++++++++++++--
gcc/testsuite/rust/compile/nr2/exclude | 6 ---
2 files changed, 38 insertions(+), 10 deletions(-)
diff --git a/gcc/rust/checks/errors/rust-unsafe-checker.cc b/gcc/rust/checks/errors/rust-unsafe-checker.cc
index 4c8db3a554e..9ab18e2f656 100644
--- a/gcc/rust/checks/errors/rust-unsafe-checker.cc
+++ b/gcc/rust/checks/errors/rust-unsafe-checker.cc
@@ -23,6 +23,10 @@
#include "rust-hir-item.h"
#include "rust-attribute-values.h"
#include "rust-system.h"
+#include "rust-immutable-name-resolution-context.h"
+
+// for flag_name_resolution_2_0
+#include "options.h"
namespace Rust {
namespace HIR {
@@ -216,8 +220,23 @@ UnsafeChecker::visit (PathInExpression &path)
NodeId ast_node_id = path.get_mappings ().get_nodeid ();
NodeId ref_node_id;
- if (!resolver.lookup_resolved_name (ast_node_id, &ref_node_id))
- return;
+ if (flag_name_resolution_2_0)
+ {
+ auto &nr_ctx
+ = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+
+ auto resolved = nr_ctx.lookup (ast_node_id);
+
+ if (!resolved.has_value ())
+ return;
+
+ ref_node_id = resolved.value ();
+ }
+ else
+ {
+ if (!resolver.lookup_resolved_name (ast_node_id, &ref_node_id))
+ return;
+ }
if (auto definition_id = mappings.lookup_node_to_hir (ref_node_id))
{
@@ -418,8 +437,23 @@ UnsafeChecker::visit (CallExpr &expr)
// There are no unsafe types, and functions are defined in the name resolver.
// If we can't find the name, then we're dealing with a type and should return
// early.
- if (!resolver.lookup_resolved_name (ast_node_id, &ref_node_id))
- return;
+ if (flag_name_resolution_2_0)
+ {
+ auto &nr_ctx
+ = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+
+ auto resolved = nr_ctx.lookup (ast_node_id);
+
+ if (!resolved.has_value ())
+ return;
+
+ ref_node_id = resolved.value ();
+ }
+ else
+ {
+ if (!resolver.lookup_resolved_name (ast_node_id, &ref_node_id))
+ return;
+ }
if (auto definition_id = mappings.lookup_node_to_hir (ref_node_id))
{
diff --git a/gcc/testsuite/rust/compile/nr2/exclude b/gcc/testsuite/rust/compile/nr2/exclude
index 450fc254452..47d651b22bd 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -191,12 +191,6 @@ traits9.rs
type-bindings1.rs
unconstrained_type_param.rs
undeclared_label.rs
-unsafe1.rs
-unsafe11.rs
-unsafe2.rs
-unsafe3.rs
-unsafe6.rs
-unsafe7.rs
use_1.rs
use_2.rs
v0-mangle1.rs
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 010/146] rust: Desugar IfLet* into MatchExpr
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (8 preceding siblings ...)
2025-03-21 12:05 ` [COMMITTED 009/146] gccrs: Fix name resolution 2.0 definition lookups in unsafe checker arthur.cohen
@ 2025-03-21 12:05 ` arthur.cohen
2025-03-21 12:05 ` [COMMITTED 011/146] gccrs: Use name resolution 2.0 in TraitResolver arthur.cohen
` (135 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:05 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Marc Poulhiès
From: Marc Poulhiès <dkm@kataplop.net>
Replace the "regular" AST->HIR lowering for IfLet* with a desugaring
into a MatchExpr.
Desugar a simple if let:
if let Some(y) = some_value {
bar();
}
into:
match some_value {
Some(y) => {bar();},
_ => ()
}
Same applies for IfLetExprConseqElse (if let with an else block).
Desugar:
if let Some(y) = some_value {
bar();
} else {
baz();
}
into:
match some_value {
Some(y) => {bar();},
_ => {baz();}
}
Fixes https://github.com/Rust-GCC/gccrs/issues/1177
gcc/rust/ChangeLog:
* backend/rust-compile-block.h: Adjust after removal of
HIR::IfLetExpr and HIR::IfLetExprConseqElse.
* backend/rust-compile-expr.h: Likewise.
* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc
(ExprStmtBuilder::visit): Likewise.
* checks/errors/borrowck/rust-bir-builder-expr-stmt.h: Likewise.
* checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h:
Likewise.
* checks/errors/borrowck/rust-bir-builder-struct.h: Likewise.
* checks/errors/borrowck/rust-function-collector.h: Likewise.
* checks/errors/privacy/rust-privacy-reporter.cc
(PrivacyReporter::visit): Likewise.
* checks/errors/privacy/rust-privacy-reporter.h: Likewise.
* checks/errors/rust-const-checker.cc (ConstChecker::visit):
Likewise.
* checks/errors/rust-const-checker.h: Likewise.
* checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit):
Likewise.
* checks/errors/rust-unsafe-checker.h: Likewise.
* hir/rust-ast-lower-block.h (ASTLoweringIfLetBlock::translate):
Change return type.
* hir/rust-ast-lower.cc (ASTLoweringIfLetBlock::desugar_iflet):
New.
(ASTLoweringIfLetBlock::visit(AST::IfLetExpr &)): Adjust and use
desugar_iflet.
* hir/rust-ast-lower.h: Add comment.
* hir/rust-hir-dump.cc (Dump::do_ifletexpr): Remove.
(Dump::visit(IfLetExpr&)): Remove.
(Dump::visit(IfLetExprConseqElse&)): Remove.
* hir/rust-hir-dump.h (Dump::do_ifletexpr): Remove.
(Dump::visit(IfLetExpr&)): Remove.
(Dump::visit(IfLetExprConseqElse&)): Remove.
* hir/tree/rust-hir-expr.h (class IfLetExpr): Remove.
(class IfLetExprConseqElse): Remove.
* hir/tree/rust-hir-full-decls.h (class IfLetExpr): Remove.
(class IfLetExprConseqElse): Remove.
* hir/tree/rust-hir-visitor.h: Adjust after removal of
HIR::IfLetExpr and HIR::IfLetExprConseqElse.
* hir/tree/rust-hir.cc (IfLetExpr::as_string): Remove.
(IfLetExprConseqElse::as_string): Remove.
(IfLetExpr::accept_vis): Remove.
(IfLetExprConseqElse::accept_vis): Remove.
* hir/tree/rust-hir.h: Adjust after removal of HIR::IfLetExpr and
HIR::IfLetExprConseqElse.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit):
Likewise.
* typecheck/rust-hir-type-check-expr.h: Likewise.
* checks/errors/rust-hir-pattern-analysis.cc
(PatternChecker::visit (IfLetExpr &)): Remove.
(PatternChecker::visit (IfLetExprConseqElse &)): Remove.
* checks/errors/rust-hir-pattern-analysis.h (visit(IfLetExpr &)): Remove.
(visit(IfLetExprConseqElse &)): Remove.
gcc/testsuite/ChangeLog:
* rust/compile/if_let_expr.rs: Adjust.
* rust/compile/if_let_expr_simple.rs: New test.
* rust/compile/iflet.rs: New test.
* rust/execute/torture/iflet.rs: New test.
* rust/compile/nr2/exclude: Add iflet.rs and if_let_expr_simple.rs
Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
---
gcc/rust/backend/rust-compile-block.h | 4 -
gcc/rust/backend/rust-compile-expr.h | 2 -
.../borrowck/rust-bir-builder-expr-stmt.cc | 12 --
.../borrowck/rust-bir-builder-expr-stmt.h | 2 -
.../borrowck/rust-bir-builder-lazyboolexpr.h | 8 -
.../errors/borrowck/rust-bir-builder-struct.h | 2 -
.../errors/borrowck/rust-function-collector.h | 2 -
.../errors/privacy/rust-privacy-reporter.cc | 15 --
.../errors/privacy/rust-privacy-reporter.h | 2 -
gcc/rust/checks/errors/rust-const-checker.cc | 16 --
gcc/rust/checks/errors/rust-const-checker.h | 2 -
.../errors/rust-hir-pattern-analysis.cc | 16 --
.../checks/errors/rust-hir-pattern-analysis.h | 2 -
gcc/rust/checks/errors/rust-unsafe-checker.cc | 16 --
gcc/rust/checks/errors/rust-unsafe-checker.h | 2 -
gcc/rust/hir/rust-ast-lower-block.h | 11 +-
gcc/rust/hir/rust-ast-lower.cc | 144 +++++++++++---
gcc/rust/hir/rust-ast-lower.h | 5 +
gcc/rust/hir/rust-hir-dump.cc | 28 ---
gcc/rust/hir/rust-hir-dump.h | 3 -
gcc/rust/hir/tree/rust-hir-expr.h | 176 +-----------------
gcc/rust/hir/tree/rust-hir-full-decls.h | 2 -
gcc/rust/hir/tree/rust-hir-visitor.h | 6 -
gcc/rust/hir/tree/rust-hir.cc | 59 ------
gcc/rust/hir/tree/rust-hir.h | 1 -
.../typecheck/rust-hir-type-check-expr.cc | 61 ------
gcc/rust/typecheck/rust-hir-type-check-expr.h | 2 -
gcc/testsuite/rust/compile/if_let_expr.rs | 5 +-
.../rust/compile/if_let_expr_simple.rs | 12 ++
gcc/testsuite/rust/compile/iflet.rs | 32 ++++
gcc/testsuite/rust/compile/nr2/exclude | 3 +
gcc/testsuite/rust/execute/torture/iflet.rs | 84 +++++++++
32 files changed, 260 insertions(+), 477 deletions(-)
create mode 100644 gcc/testsuite/rust/compile/if_let_expr_simple.rs
create mode 100644 gcc/testsuite/rust/compile/iflet.rs
create mode 100644 gcc/testsuite/rust/execute/torture/iflet.rs
diff --git a/gcc/rust/backend/rust-compile-block.h b/gcc/rust/backend/rust-compile-block.h
index d226b4be9f4..6616882894f 100644
--- a/gcc/rust/backend/rust-compile-block.h
+++ b/gcc/rust/backend/rust-compile-block.h
@@ -96,8 +96,6 @@ public:
void visit (HIR::LoopExpr &) override {}
void visit (HIR::WhileLoopExpr &) override {}
void visit (HIR::WhileLetLoopExpr &) override {}
- void visit (HIR::IfLetExpr &) override {}
- void visit (HIR::IfLetExprConseqElse &) override {}
void visit (HIR::MatchExpr &) override {}
void visit (HIR::AwaitExpr &) override {}
void visit (HIR::AsyncBlockExpr &) override {}
@@ -180,8 +178,6 @@ public:
void visit (HIR::LoopExpr &) override {}
void visit (HIR::WhileLoopExpr &) override {}
void visit (HIR::WhileLetLoopExpr &) override {}
- void visit (HIR::IfLetExpr &) override {}
- void visit (HIR::IfLetExprConseqElse &) override {}
void visit (HIR::MatchExpr &) override {}
void visit (HIR::AwaitExpr &) override {}
void visit (HIR::AsyncBlockExpr &) override {}
diff --git a/gcc/rust/backend/rust-compile-expr.h b/gcc/rust/backend/rust-compile-expr.h
index ef907d1ca62..2312375ff49 100644
--- a/gcc/rust/backend/rust-compile-expr.h
+++ b/gcc/rust/backend/rust-compile-expr.h
@@ -77,8 +77,6 @@ public:
// TODO
// these need to be sugared in the HIR to if statements and a match
void visit (HIR::WhileLetLoopExpr &) override {}
- void visit (HIR::IfLetExpr &) override {}
- void visit (HIR::IfLetExprConseqElse &) override {}
// lets not worry about async yet....
void visit (HIR::AwaitExpr &) override {}
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 1713bf6fcf8..df02c4b5e61 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
@@ -611,18 +611,6 @@ ExprStmtBuilder::visit (HIR::IfExprConseqElse &expr)
add_jump (else_end_bb, final_start_bb);
}
-void
-ExprStmtBuilder::visit (HIR::IfLetExpr &expr)
-{
- rust_sorry_at (expr.get_locus (), "if let expressions are not supported");
-}
-
-void
-ExprStmtBuilder::visit (HIR::IfLetExprConseqElse &expr)
-{
- rust_sorry_at (expr.get_locus (), "if let expressions are not supported");
-}
-
void
ExprStmtBuilder::visit (HIR::MatchExpr &expr)
{
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.h b/gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.h
index 574f0f36fdd..daedb680744 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.h
@@ -101,8 +101,6 @@ protected: // Expr
void visit (HIR::IfExprConseqElse &expr) override;
void visit (HIR::InlineAsm &expr) override;
- void visit (HIR::IfLetExpr &expr) override;
- void visit (HIR::IfLetExprConseqElse &expr) override;
void visit (HIR::MatchExpr &expr) override;
void visit (HIR::AwaitExpr &expr) override;
void visit (HIR::AsyncBlockExpr &expr) override;
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h b/gcc/rust/checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h
index f4995327d87..8c01c501c36 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h
@@ -193,14 +193,6 @@ public:
{
return_place (ExprStmtBuilder (ctx).build (expr), expr.get_locus ());
}
- void visit (HIR::IfLetExpr &expr) override
- {
- return_place (ExprStmtBuilder (ctx).build (expr), expr.get_locus ());
- }
- void visit (HIR::IfLetExprConseqElse &expr) override
- {
- return_place (ExprStmtBuilder (ctx).build (expr), expr.get_locus ());
- }
void visit (HIR::MatchExpr &expr) override
{
return_place (ExprStmtBuilder (ctx).build (expr), expr.get_locus ());
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-builder-struct.h b/gcc/rust/checks/errors/borrowck/rust-bir-builder-struct.h
index 53346bfe737..fefdd534cb1 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-builder-struct.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-builder-struct.h
@@ -149,8 +149,6 @@ protected:
void visit (HIR::WhileLetLoopExpr &expr) override { rust_unreachable (); }
void visit (HIR::IfExpr &expr) override { rust_unreachable (); }
void visit (HIR::IfExprConseqElse &expr) override { rust_unreachable (); }
- void visit (HIR::IfLetExpr &expr) override { rust_unreachable (); }
- void visit (HIR::IfLetExprConseqElse &expr) override { rust_unreachable (); }
void visit (HIR::MatchExpr &expr) override { rust_unreachable (); }
void visit (HIR::AwaitExpr &expr) override { rust_unreachable (); }
void visit (HIR::AsyncBlockExpr &expr) override { rust_unreachable (); }
diff --git a/gcc/rust/checks/errors/borrowck/rust-function-collector.h b/gcc/rust/checks/errors/borrowck/rust-function-collector.h
index 51109d7dbdc..bea438c5445 100644
--- a/gcc/rust/checks/errors/borrowck/rust-function-collector.h
+++ b/gcc/rust/checks/errors/borrowck/rust-function-collector.h
@@ -119,8 +119,6 @@ public:
void visit (HIR::WhileLetLoopExpr &expr) override {}
void visit (HIR::IfExpr &expr) override {}
void visit (HIR::IfExprConseqElse &expr) override {}
- void visit (HIR::IfLetExpr &expr) override {}
- void visit (HIR::IfLetExprConseqElse &expr) override {}
void visit (HIR::MatchExpr &expr) override {}
void visit (HIR::AwaitExpr &expr) override {}
void visit (HIR::AsyncBlockExpr &expr) override {}
diff --git a/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc b/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc
index 01d8ea5e87b..1ee2097b383 100644
--- a/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc
+++ b/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc
@@ -594,21 +594,6 @@ PrivacyReporter::visit (HIR::IfExprConseqElse &expr)
expr.get_else_block ()->accept_vis (*this);
}
-void
-PrivacyReporter::visit (HIR::IfLetExpr &)
-{
- // TODO: We need to visit the if_let_expr
- // TODO: We need to visit the block as well
-}
-
-void
-PrivacyReporter::visit (HIR::IfLetExprConseqElse &)
-{
- // TODO: We need to visit the if_let_expr
- // TODO: We need to visit the if_block as well
- // TODO: We need to visit the else_block as well
-}
-
void
PrivacyReporter::visit (HIR::MatchExpr &expr)
{
diff --git a/gcc/rust/checks/errors/privacy/rust-privacy-reporter.h b/gcc/rust/checks/errors/privacy/rust-privacy-reporter.h
index c4f94ab3ed7..b9cc230d5db 100644
--- a/gcc/rust/checks/errors/privacy/rust-privacy-reporter.h
+++ b/gcc/rust/checks/errors/privacy/rust-privacy-reporter.h
@@ -121,8 +121,6 @@ types
virtual void visit (HIR::WhileLetLoopExpr &expr);
virtual void visit (HIR::IfExpr &expr);
virtual void visit (HIR::IfExprConseqElse &expr);
- virtual void visit (HIR::IfLetExpr &expr);
- virtual void visit (HIR::IfLetExprConseqElse &expr);
virtual void visit (HIR::MatchExpr &expr);
virtual void visit (HIR::AwaitExpr &expr);
virtual void visit (HIR::AsyncBlockExpr &expr);
diff --git a/gcc/rust/checks/errors/rust-const-checker.cc b/gcc/rust/checks/errors/rust-const-checker.cc
index 84c09dd307e..1e0ebd29798 100644
--- a/gcc/rust/checks/errors/rust-const-checker.cc
+++ b/gcc/rust/checks/errors/rust-const-checker.cc
@@ -511,22 +511,6 @@ ConstChecker::visit (IfExprConseqElse &expr)
expr.get_else_block ()->accept_vis (*this);
}
-void
-ConstChecker::visit (IfLetExpr &expr)
-{
- expr.get_scrutinee_expr ()->accept_vis (*this);
- expr.get_if_block ()->accept_vis (*this);
-}
-
-void
-ConstChecker::visit (IfLetExprConseqElse &expr)
-{
- expr.get_scrutinee_expr ()->accept_vis (*this);
- expr.get_if_block ()->accept_vis (*this);
-
- // TODO: Visit else expression
-}
-
void
ConstChecker::visit (MatchExpr &expr)
{
diff --git a/gcc/rust/checks/errors/rust-const-checker.h b/gcc/rust/checks/errors/rust-const-checker.h
index 8890761e61d..9a618b8f96d 100644
--- a/gcc/rust/checks/errors/rust-const-checker.h
+++ b/gcc/rust/checks/errors/rust-const-checker.h
@@ -128,8 +128,6 @@ private:
virtual void visit (WhileLetLoopExpr &expr) override;
virtual void visit (IfExpr &expr) override;
virtual void visit (IfExprConseqElse &expr) override;
- virtual void visit (IfLetExpr &expr) override;
- virtual void visit (IfLetExprConseqElse &expr) override;
virtual void visit (MatchExpr &expr) override;
virtual void visit (AwaitExpr &expr) override;
virtual void visit (AsyncBlockExpr &expr) override;
diff --git a/gcc/rust/checks/errors/rust-hir-pattern-analysis.cc b/gcc/rust/checks/errors/rust-hir-pattern-analysis.cc
index f46f429e930..8fb795b7b83 100644
--- a/gcc/rust/checks/errors/rust-hir-pattern-analysis.cc
+++ b/gcc/rust/checks/errors/rust-hir-pattern-analysis.cc
@@ -389,22 +389,6 @@ PatternChecker::visit (IfExprConseqElse &expr)
expr.get_else_block ()->accept_vis (*this);
}
-void
-PatternChecker::visit (IfLetExpr &expr)
-{
- expr.get_scrutinee_expr ()->accept_vis (*this);
- expr.get_if_block ()->accept_vis (*this);
-}
-
-void
-PatternChecker::visit (IfLetExprConseqElse &expr)
-{
- expr.get_scrutinee_expr ()->accept_vis (*this);
- expr.get_if_block ()->accept_vis (*this);
-
- expr.get_else_block ()->accept_vis (*this);
-}
-
void
PatternChecker::visit (MatchExpr &expr)
{
diff --git a/gcc/rust/checks/errors/rust-hir-pattern-analysis.h b/gcc/rust/checks/errors/rust-hir-pattern-analysis.h
index 1af02baa24b..9c43d4143d2 100644
--- a/gcc/rust/checks/errors/rust-hir-pattern-analysis.h
+++ b/gcc/rust/checks/errors/rust-hir-pattern-analysis.h
@@ -102,8 +102,6 @@ private:
virtual void visit (WhileLetLoopExpr &expr) override;
virtual void visit (IfExpr &expr) override;
virtual void visit (IfExprConseqElse &expr) override;
- virtual void visit (IfLetExpr &expr) override;
- virtual void visit (IfLetExprConseqElse &expr) override;
virtual void visit (HIR::MatchExpr &expr) override;
virtual void visit (AwaitExpr &expr) override;
virtual void visit (AsyncBlockExpr &expr) override;
diff --git a/gcc/rust/checks/errors/rust-unsafe-checker.cc b/gcc/rust/checks/errors/rust-unsafe-checker.cc
index 9ab18e2f656..ee6654b4dd2 100644
--- a/gcc/rust/checks/errors/rust-unsafe-checker.cc
+++ b/gcc/rust/checks/errors/rust-unsafe-checker.cc
@@ -633,22 +633,6 @@ UnsafeChecker::visit (IfExprConseqElse &expr)
expr.get_else_block ()->accept_vis (*this);
}
-void
-UnsafeChecker::visit (IfLetExpr &expr)
-{
- expr.get_scrutinee_expr ()->accept_vis (*this);
- expr.get_if_block ()->accept_vis (*this);
-}
-
-void
-UnsafeChecker::visit (IfLetExprConseqElse &expr)
-{
- expr.get_scrutinee_expr ()->accept_vis (*this);
- expr.get_if_block ()->accept_vis (*this);
-
- // TODO: Visit else expression
-}
-
void
UnsafeChecker::visit (MatchExpr &expr)
{
diff --git a/gcc/rust/checks/errors/rust-unsafe-checker.h b/gcc/rust/checks/errors/rust-unsafe-checker.h
index 1fa1fe072da..96ccdc03c53 100644
--- a/gcc/rust/checks/errors/rust-unsafe-checker.h
+++ b/gcc/rust/checks/errors/rust-unsafe-checker.h
@@ -110,8 +110,6 @@ private:
virtual void visit (WhileLetLoopExpr &expr) override;
virtual void visit (IfExpr &expr) override;
virtual void visit (IfExprConseqElse &expr) override;
- virtual void visit (IfLetExpr &expr) override;
- virtual void visit (IfLetExprConseqElse &expr) override;
virtual void visit (MatchExpr &expr) override;
virtual void visit (AwaitExpr &expr) override;
virtual void visit (AsyncBlockExpr &expr) override;
diff --git a/gcc/rust/hir/rust-ast-lower-block.h b/gcc/rust/hir/rust-ast-lower-block.h
index be6ca64b68e..a39c010740e 100644
--- a/gcc/rust/hir/rust-ast-lower-block.h
+++ b/gcc/rust/hir/rust-ast-lower-block.h
@@ -115,7 +115,7 @@ class ASTLoweringIfLetBlock : public ASTLoweringBase
using Rust::HIR::ASTLoweringBase::visit;
public:
- static HIR::IfLetExpr *translate (AST::IfLetExpr &expr)
+ static HIR::MatchExpr *translate (AST::IfLetExpr &expr)
{
ASTLoweringIfLetBlock resolver;
expr.accept_vis (resolver);
@@ -135,7 +135,10 @@ public:
private:
ASTLoweringIfLetBlock () : ASTLoweringBase (), translated (nullptr) {}
- HIR::IfLetExpr *translated;
+ void desugar_iflet (AST::IfLetExpr &, HIR::Expr **, HIR::Expr *,
+ std::vector<HIR::MatchCase> &);
+
+ HIR::MatchExpr *translated;
};
class ASTLoweringExprWithBlock : public ASTLoweringBase
@@ -149,9 +152,7 @@ public:
ASTLoweringExprWithBlock resolver;
expr.accept_vis (resolver);
if (resolver.translated != nullptr)
- {
- resolver.mappings.insert_hir_expr (resolver.translated);
- }
+ resolver.mappings.insert_hir_expr (resolver.translated);
*terminated = resolver.terminated;
return resolver.translated;
diff --git a/gcc/rust/hir/rust-ast-lower.cc b/gcc/rust/hir/rust-ast-lower.cc
index 5a5c93fc370..c5e2250f29e 100644
--- a/gcc/rust/hir/rust-ast-lower.cc
+++ b/gcc/rust/hir/rust-ast-lower.cc
@@ -24,6 +24,8 @@
#include "rust-ast-lower-type.h"
#include "rust-ast-lower-pattern.h"
#include "rust-ast-lower-struct-field-expr.h"
+#include "rust-expr.h"
+#include "rust-hir-expr.h"
namespace Rust {
namespace HIR {
@@ -198,62 +200,144 @@ ASTLoweringIfBlock::visit (AST::IfExprConseqElse &expr)
std::unique_ptr<HIR::ExprWithBlock> (else_block), expr.get_locus ());
}
+/**
+ * Lowers the common part "if let 'pattern' = 'expr' { 'if_block' }" of
+ * IfLetExpr[ConseqElse]:
+ * - 'expr' is lowered into *BRANCH_VALUE
+ * - 'pattern' + 'if_block' are lowered and resulting ARM pushed in MATCH_ARMS
+ * - 'KASE_ELSE_EXPR' is the lowered HIR to be used in the else part.
+ *
+ * Looks like:
+ *
+ * match (expr) {
+ * pattern => {if_block}
+ * _ => kase_else_expr
+ * }
+ *
+ */
void
-ASTLoweringIfLetBlock::visit (AST::IfLetExpr &expr)
+ASTLoweringIfLetBlock::desugar_iflet (AST::IfLetExpr &expr,
+ HIR::Expr **branch_value,
+ HIR::Expr *kase_else_expr,
+ std::vector<HIR::MatchCase> &match_arms)
{
- std::vector<std::unique_ptr<HIR::Pattern>> patterns;
+ HIR::Expr *kase_expr;
+ std::vector<std::unique_ptr<HIR::Pattern>> match_arm_patterns;
+
+ *branch_value = ASTLoweringExpr::translate (expr.get_value_expr ());
+ kase_expr = ASTLoweringExpr::translate (expr.get_if_block ());
+
+ // (stable) if let only accepts a single pattern, but (unstable) if let chains
+ // need more than one pattern.
+ // We don't support if let chains, so only support a single pattern.
+ rust_assert (expr.get_patterns ().size () == 1);
+
for (auto &pattern : expr.get_patterns ())
{
HIR::Pattern *ptrn = ASTLoweringPattern::translate (*pattern);
- patterns.push_back (std::unique_ptr<HIR::Pattern> (ptrn));
+ match_arm_patterns.push_back (std::unique_ptr<HIR::Pattern> (ptrn));
}
- HIR::Expr *value_ptr = ASTLoweringExpr::translate (expr.get_value_expr ());
- bool ignored_terminated = false;
- HIR::BlockExpr *block
- = ASTLoweringBlock::translate (expr.get_if_block (), &ignored_terminated);
+ // The match arm corresponding to the if let pattern when it matches.
+ HIR::MatchArm arm (std::move (match_arm_patterns), expr.get_locus (), nullptr,
+ {});
auto crate_num = mappings.get_current_crate ();
Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
mappings.get_next_hir_id (crate_num),
UNKNOWN_LOCAL_DEFID);
- translated = new HIR::IfLetExpr (mapping, std::move (patterns),
- std::unique_ptr<HIR::Expr> (value_ptr),
- std::unique_ptr<HIR::BlockExpr> (block),
- expr.get_locus ());
+ HIR::MatchCase kase (std::move (mapping), std::move (arm),
+ std::unique_ptr<HIR::Expr> (kase_expr));
+ match_arms.push_back (std::move (kase));
+
+ // The default match arm when the if let pattern does not match
+ std::vector<std::unique_ptr<HIR::Pattern>> match_arm_patterns_wildcard;
+ Analysis::NodeMapping mapping_default (crate_num, expr.get_node_id (),
+ mappings.get_next_hir_id (crate_num),
+ UNKNOWN_LOCAL_DEFID);
+
+ std::unique_ptr<HIR::WildcardPattern> wc
+ = std::unique_ptr<HIR::WildcardPattern> (
+ new HIR::WildcardPattern (mapping_default, expr.get_locus ()));
+
+ match_arm_patterns_wildcard.push_back (std::move (wc));
+
+ HIR::MatchArm arm_default (std::move (match_arm_patterns_wildcard),
+ expr.get_locus (), nullptr, {});
+
+ HIR::MatchCase kase_else (std::move (mapping_default),
+ std::move (arm_default),
+ std::unique_ptr<HIR::Expr> (kase_else_expr));
+ match_arms.push_back (std::move (kase_else));
}
void
-ASTLoweringIfLetBlock::visit (AST::IfLetExprConseqElse &expr)
+ASTLoweringIfLetBlock::visit (AST::IfLetExpr &expr)
{
- std::vector<std::unique_ptr<HIR::Pattern>> patterns;
- for (auto &pattern : expr.get_patterns ())
- {
- HIR::Pattern *ptrn = ASTLoweringPattern::translate (*pattern);
- patterns.push_back (std::unique_ptr<HIR::Pattern> (ptrn));
- }
- HIR::Expr *value_ptr = ASTLoweringExpr::translate (expr.get_value_expr ());
+ // Desugar:
+ // if let Some(y) = some_value {
+ // bar();
+ // }
+ //
+ // into:
+ //
+ // match some_value {
+ // Some(y) => {bar();},
+ // _ => ()
+ // }
+
+ HIR::Expr *branch_value;
- bool ignored_terminated = false;
- HIR::BlockExpr *block
- = ASTLoweringBlock::translate (expr.get_if_block (), &ignored_terminated);
+ std::vector<HIR::MatchCase> match_arms;
+ auto crate_num = mappings.get_current_crate ();
+ Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
+ mappings.get_next_hir_id (crate_num),
+ UNKNOWN_LOCAL_DEFID);
- HIR::ExprWithBlock *else_block
- = ASTLoweringExprWithBlock::translate (expr.get_else_block (),
- &ignored_terminated);
+ HIR::TupleExpr *unit
+ = new HIR::TupleExpr (mapping, {}, {}, {}, expr.get_locus ());
+
+ desugar_iflet (expr, &branch_value, unit, match_arms);
- rust_assert (else_block);
+ translated
+ = new HIR::MatchExpr (mapping, std::unique_ptr<HIR::Expr> (branch_value),
+ std::move (match_arms), {}, {}, expr.get_locus ());
+}
+
+void
+ASTLoweringIfLetBlock::visit (AST::IfLetExprConseqElse &expr)
+{
+ // desugar:
+ // if let Some(y) = some_value {
+ // bar();
+ // } else {
+ // baz();
+ // }
+ //
+ // into
+ // match some_value {
+ // Some(y) => {bar();},
+ // _ => {baz();}
+ // }
+ //
+
+ HIR::Expr *branch_value;
+ std::vector<HIR::MatchCase> match_arms;
+
+ HIR::Expr *kase_else_expr
+ = ASTLoweringExpr::translate (expr.get_else_block ());
+
+ desugar_iflet (expr, &branch_value, kase_else_expr, match_arms);
auto crate_num = mappings.get_current_crate ();
Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
mappings.get_next_hir_id (crate_num),
UNKNOWN_LOCAL_DEFID);
- translated = new HIR::IfLetExprConseqElse (
- mapping, std::move (patterns), std::unique_ptr<HIR::Expr> (value_ptr),
- std::unique_ptr<HIR::BlockExpr> (block),
- std::unique_ptr<HIR::ExprWithBlock> (else_block), expr.get_locus ());
+ translated
+ = new HIR::MatchExpr (mapping, std::unique_ptr<HIR::Expr> (branch_value),
+ std::move (match_arms), {}, {}, expr.get_locus ());
}
// rust-ast-lower-struct-field-expr.h
diff --git a/gcc/rust/hir/rust-ast-lower.h b/gcc/rust/hir/rust-ast-lower.h
index 079ffa9af92..cc7408277a3 100644
--- a/gcc/rust/hir/rust-ast-lower.h
+++ b/gcc/rust/hir/rust-ast-lower.h
@@ -39,6 +39,11 @@ struct_field_name_exists (std::vector<HIR::StructField> &fields,
Visibility
translate_visibility (const AST::Visibility &vis);
+/**
+ * Main base class used for lowering AST to HIR.
+ *
+ * Every subclass should provide a translate() method that takes an AST node and
+ * lowers it to some HIR stored in the TRANSLATED member. */
class ASTLowering
{
public:
diff --git a/gcc/rust/hir/rust-hir-dump.cc b/gcc/rust/hir/rust-hir-dump.cc
index b4413773234..4fa028c07b8 100644
--- a/gcc/rust/hir/rust-hir-dump.cc
+++ b/gcc/rust/hir/rust-hir-dump.cc
@@ -463,17 +463,6 @@ Dump::do_baseloopexpr (BaseLoopExpr &e)
visit_field ("loop_block", e.get_loop_block ());
}
-void
-Dump::do_ifletexpr (IfLetExpr &e)
-{
- do_expr (e);
-
- visit_collection ("match_arm_patterns", e.get_patterns ());
-
- visit_field ("value", e.get_scrutinee_expr ());
- visit_field ("if_block", e.get_if_block ());
-}
-
void
Dump::do_struct (Struct &e)
{
@@ -1441,23 +1430,6 @@ Dump::visit (IfExprConseqElse &e)
end ("IfExprConseqElse");
}
-void
-Dump::visit (IfLetExpr &e)
-{
- begin ("IfLetExpr");
- do_ifletexpr (e);
- end ("IfLetExpr");
-}
-
-void
-Dump::visit (IfLetExprConseqElse &e)
-{
- begin ("IfLetExprConseqElse");
- do_ifletexpr (e);
- visit_field ("else_block", e.get_else_block ());
- end ("IfLetExprConseqElse");
-}
-
void
Dump::visit (MatchExpr &e)
{
diff --git a/gcc/rust/hir/rust-hir-dump.h b/gcc/rust/hir/rust-hir-dump.h
index b3a2020742f..8683dee9d6c 100644
--- a/gcc/rust/hir/rust-hir-dump.h
+++ b/gcc/rust/hir/rust-hir-dump.h
@@ -80,7 +80,6 @@ private:
void do_type (Type &);
void do_expr (Expr &);
void do_ifexpr (IfExpr &);
- void do_ifletexpr (IfLetExpr &);
void do_pathexpr (PathExpr &);
void do_pathpattern (PathPattern &);
void do_genericargs (GenericArgs &);
@@ -162,8 +161,6 @@ private:
virtual void visit (WhileLetLoopExpr &) override;
virtual void visit (IfExpr &) override;
virtual void visit (IfExprConseqElse &) override;
- virtual void visit (IfLetExpr &) override;
- virtual void visit (IfLetExprConseqElse &) override;
virtual void visit (MatchExpr &) override;
virtual void visit (AwaitExpr &) override;
diff --git a/gcc/rust/hir/tree/rust-hir-expr.h b/gcc/rust/hir/tree/rust-hir-expr.h
index 1ee10663708..a79aea58386 100644
--- a/gcc/rust/hir/tree/rust-hir-expr.h
+++ b/gcc/rust/hir/tree/rust-hir-expr.h
@@ -32,7 +32,7 @@ namespace HIR {
// TODO: inline?
class LoopLabel /*: public Node*/
{
- Lifetime label; // or type LIFETIME_OR_LABEL
+ Lifetime label; // of type LIFETIME_OR_LABEL
location_t locus;
@@ -3108,9 +3108,6 @@ protected:
}
};
-// forward decl for IfExpr
-class IfLetExpr;
-
// Base if expression with no "else" or "if let" HIR node
class IfExpr : public ExprWithBlock
{
@@ -3258,177 +3255,6 @@ protected:
}
};
-// Basic "if let" expression HIR node with no else
-class IfLetExpr : public ExprWithBlock
-{
- // MatchArmPatterns patterns;
- std::vector<std::unique_ptr<Pattern> > match_arm_patterns; // inlined
- std::unique_ptr<Expr> value;
- std::unique_ptr<BlockExpr> if_block;
-
- location_t locus;
-
-public:
- std::string as_string () const override;
-
- IfLetExpr (Analysis::NodeMapping mappings,
- std::vector<std::unique_ptr<Pattern> > match_arm_patterns,
- std::unique_ptr<Expr> value, std::unique_ptr<BlockExpr> if_block,
- location_t locus)
- : ExprWithBlock (std::move (mappings), AST::AttrVec ()),
- match_arm_patterns (std::move (match_arm_patterns)),
- value (std::move (value)), if_block (std::move (if_block)), locus (locus)
- {}
- // outer attributes not allowed on if let exprs either
-
- // copy constructor with clone
- IfLetExpr (IfLetExpr const &other)
- : ExprWithBlock (other),
- /*match_arm_patterns(other.match_arm_patterns),*/ value (
- other.value->clone_expr ()),
- if_block (other.if_block->clone_block_expr ()), locus (other.locus)
- {
- match_arm_patterns.reserve (other.match_arm_patterns.size ());
- for (const auto &e : other.match_arm_patterns)
- match_arm_patterns.push_back (e->clone_pattern ());
- }
-
- // overload assignment operator to clone
- IfLetExpr &operator= (IfLetExpr const &other)
- {
- ExprWithBlock::operator= (other);
- // match_arm_patterns = other.match_arm_patterns;
- value = other.value->clone_expr ();
- if_block = other.if_block->clone_block_expr ();
- locus = other.locus;
-
- match_arm_patterns.reserve (other.match_arm_patterns.size ());
- for (const auto &e : other.match_arm_patterns)
- match_arm_patterns.push_back (e->clone_pattern ());
-
- return *this;
- }
-
- // move constructors
- IfLetExpr (IfLetExpr &&other) = default;
- IfLetExpr &operator= (IfLetExpr &&other) = default;
-
- // Unique pointer custom clone function
- std::unique_ptr<IfLetExpr> clone_if_let_expr () const
- {
- return std::unique_ptr<IfLetExpr> (clone_if_let_expr_impl ());
- }
-
- location_t get_locus () const override final { return locus; }
-
- void accept_vis (HIRFullVisitor &vis) override;
- void accept_vis (HIRExpressionVisitor &vis) override;
-
- std::unique_ptr<Expr> &get_scrutinee_expr () { return value; }
-
- std::vector<std::unique_ptr<Pattern> > &get_patterns ()
- {
- return match_arm_patterns;
- }
-
- std::unique_ptr<BlockExpr> &get_if_block () { return if_block; }
-
- ExprType get_expression_type () const final override
- {
- return ExprType::IfLet;
- }
-
-protected:
- /* Use covariance to implement clone function as returning this object rather
- * than base */
- IfLetExpr *clone_expr_impl () const override { return new IfLetExpr (*this); }
-
- /* Use covariance to implement clone function as returning this object rather
- * than base */
- IfLetExpr *clone_expr_with_block_impl () const override
- {
- return new IfLetExpr (*this);
- }
-
- // Base clone function but still concrete as concrete base class
- virtual IfLetExpr *clone_if_let_expr_impl () const
- {
- return new IfLetExpr (*this);
- }
-};
-
-/* HIR node representing "if let" expression with an "else" expression at the
- * end */
-class IfLetExprConseqElse : public IfLetExpr
-{
- std::unique_ptr<ExprWithBlock> else_block;
-
-public:
- std::string as_string () const override;
-
- IfLetExprConseqElse (
- Analysis::NodeMapping mappings,
- std::vector<std::unique_ptr<Pattern> > match_arm_patterns,
- std::unique_ptr<Expr> value, std::unique_ptr<BlockExpr> if_block,
- std::unique_ptr<ExprWithBlock> else_block, location_t locus)
- : IfLetExpr (std::move (mappings), std::move (match_arm_patterns),
- std::move (value), std::move (if_block), locus),
- else_block (std::move (else_block))
- {}
- // outer attributes not allowed
-
- // copy constructor with clone
- IfLetExprConseqElse (IfLetExprConseqElse const &other)
- : IfLetExpr (other), else_block (other.else_block->clone_expr_with_block ())
- {}
-
- // overload assignment operator to clone
- IfLetExprConseqElse &operator= (IfLetExprConseqElse const &other)
- {
- IfLetExpr::operator= (other);
- // match_arm_patterns = other.match_arm_patterns;
- // value = other.value->clone_expr();
- // if_block = other.if_block->clone_block_expr();
- else_block = other.else_block->clone_expr_with_block ();
- // outer_attrs = other.outer_attrs;
-
- return *this;
- }
-
- // move constructors
- IfLetExprConseqElse (IfLetExprConseqElse &&other) = default;
- IfLetExprConseqElse &operator= (IfLetExprConseqElse &&other) = default;
-
- void accept_vis (HIRFullVisitor &vis) override;
- void accept_vis (HIRExpressionVisitor &vis) override;
-
- void vis_else_block (HIRFullVisitor &vis) { else_block->accept_vis (vis); }
-
- std::unique_ptr<ExprWithBlock> &get_else_block () { return else_block; }
-
-protected:
- /* Use covariance to implement clone function as returning this object rather
- * than base */
- IfLetExprConseqElse *clone_expr_impl () const override
- {
- return new IfLetExprConseqElse (*this);
- }
-
- /* Use covariance to implement clone function as returning this object rather
- * than base */
- IfLetExprConseqElse *clone_expr_with_block_impl () const override
- {
- return new IfLetExprConseqElse (*this);
- }
-
- /* Use covariance to implement clone function as returning this object rather
- * than base */
- IfLetExprConseqElse *clone_if_let_expr_impl () const override
- {
- return new IfLetExprConseqElse (*this);
- }
-};
-
// Match arm expression
struct MatchArm
{
diff --git a/gcc/rust/hir/tree/rust-hir-full-decls.h b/gcc/rust/hir/tree/rust-hir-full-decls.h
index 64be7bf93d1..c64c8bf6513 100644
--- a/gcc/rust/hir/tree/rust-hir-full-decls.h
+++ b/gcc/rust/hir/tree/rust-hir-full-decls.h
@@ -113,8 +113,6 @@ class WhileLoopExpr;
class WhileLetLoopExpr;
class IfExpr;
class IfExprConseqElse;
-class IfLetExpr;
-class IfLetExprConseqElse;
struct MatchArm;
// class MatchCase;
// class MatchCaseBlockExpr;
diff --git a/gcc/rust/hir/tree/rust-hir-visitor.h b/gcc/rust/hir/tree/rust-hir-visitor.h
index e69e951d656..9948a1555b9 100644
--- a/gcc/rust/hir/tree/rust-hir-visitor.h
+++ b/gcc/rust/hir/tree/rust-hir-visitor.h
@@ -81,8 +81,6 @@ public:
virtual void visit (WhileLetLoopExpr &expr) = 0;
virtual void visit (IfExpr &expr) = 0;
virtual void visit (IfExprConseqElse &expr) = 0;
- virtual void visit (IfLetExpr &expr) = 0;
- virtual void visit (IfLetExprConseqElse &expr) = 0;
virtual void visit (MatchExpr &expr) = 0;
virtual void visit (AwaitExpr &expr) = 0;
virtual void visit (AsyncBlockExpr &expr) = 0;
@@ -219,8 +217,6 @@ public:
virtual void visit (WhileLetLoopExpr &) override {}
virtual void visit (IfExpr &) override {}
virtual void visit (IfExprConseqElse &) override {}
- virtual void visit (IfLetExpr &) override {}
- virtual void visit (IfLetExprConseqElse &) override {}
virtual void visit (MatchExpr &) override {}
virtual void visit (AwaitExpr &) override {}
@@ -448,8 +444,6 @@ public:
virtual void visit (WhileLetLoopExpr &expr) = 0;
virtual void visit (IfExpr &expr) = 0;
virtual void visit (IfExprConseqElse &expr) = 0;
- virtual void visit (IfLetExpr &expr) = 0;
- virtual void visit (IfLetExprConseqElse &expr) = 0;
virtual void visit (InlineAsm &expr) = 0;
virtual void visit (MatchExpr &expr) = 0;
virtual void visit (AwaitExpr &expr) = 0;
diff --git a/gcc/rust/hir/tree/rust-hir.cc b/gcc/rust/hir/tree/rust-hir.cc
index f05e5065e62..9de881f6c9c 100644
--- a/gcc/rust/hir/tree/rust-hir.cc
+++ b/gcc/rust/hir/tree/rust-hir.cc
@@ -1571,41 +1571,6 @@ IfExprConseqElse::as_string () const
return str;
}
-std::string
-IfLetExpr::as_string () const
-{
- std::string str ("IfLetExpr: ");
-
- str += "\n Condition match arm patterns: ";
- if (match_arm_patterns.empty ())
- {
- str += "none";
- }
- else
- {
- for (const auto &pattern : match_arm_patterns)
- {
- str += "\n " + pattern->as_string ();
- }
- }
-
- str += "\n Scrutinee expr: " + value->as_string ();
-
- str += "\n If let block expr: " + if_block->as_string ();
-
- return str;
-}
-
-std::string
-IfLetExprConseqElse::as_string () const
-{
- std::string str = IfLetExpr::as_string ();
-
- str += "\n Else expr: " + else_block->as_string ();
-
- return str;
-}
-
std::string
RangeFromToInclExpr::as_string () const
{
@@ -4149,18 +4114,6 @@ IfExprConseqElse::accept_vis (HIRFullVisitor &vis)
vis.visit (*this);
}
-void
-IfLetExpr::accept_vis (HIRFullVisitor &vis)
-{
- vis.visit (*this);
-}
-
-void
-IfLetExprConseqElse::accept_vis (HIRFullVisitor &vis)
-{
- vis.visit (*this);
-}
-
void
MatchExpr::accept_vis (HIRFullVisitor &vis)
{
@@ -4911,18 +4864,6 @@ RangeFromToInclExpr::accept_vis (HIRExpressionVisitor &vis)
vis.visit (*this);
}
-void
-IfLetExprConseqElse::accept_vis (HIRExpressionVisitor &vis)
-{
- vis.visit (*this);
-}
-
-void
-IfLetExpr::accept_vis (HIRExpressionVisitor &vis)
-{
- vis.visit (*this);
-}
-
void
IfExprConseqElse::accept_vis (HIRExpressionVisitor &vis)
{
diff --git a/gcc/rust/hir/tree/rust-hir.h b/gcc/rust/hir/tree/rust-hir.h
index f8eb22db087..8ce5cf4d102 100644
--- a/gcc/rust/hir/tree/rust-hir.h
+++ b/gcc/rust/hir/tree/rust-hir.h
@@ -300,7 +300,6 @@ public:
UnsafeBlock,
BaseLoop,
If,
- IfLet,
Match,
Await,
AsyncBlock,
diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
index dfdf85a141d..5b64daf33b7 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
@@ -503,67 +503,6 @@ TypeCheckExpr::visit (HIR::IfExprConseqElse &expr)
}
}
-void
-TypeCheckExpr::visit (HIR::IfLetExpr &expr)
-{
- // this needs to perform a least upper bound coercion on the blocks and then
- // unify the scruintee and arms
- TyTy::BaseType *scrutinee_tyty
- = TypeCheckExpr::Resolve (expr.get_scrutinee_expr ().get ());
-
- for (auto &pattern : expr.get_patterns ())
- {
- TyTy::BaseType *kase_arm_ty
- = TypeCheckPattern::Resolve (pattern.get (), scrutinee_tyty);
-
- unify_site (expr.get_mappings ().get_hirid (),
- TyTy::TyWithLocation (scrutinee_tyty),
- TyTy::TyWithLocation (kase_arm_ty, pattern->get_locus ()),
- expr.get_locus ());
- }
-
- TypeCheckExpr::Resolve (expr.get_if_block ().get ());
-
- infered = TyTy::TupleType::get_unit_type (expr.get_mappings ().get_hirid ());
-}
-
-void
-TypeCheckExpr::visit (HIR::IfLetExprConseqElse &expr)
-{
- TyTy::BaseType *scrutinee_tyty
- = TypeCheckExpr::Resolve (expr.get_scrutinee_expr ().get ());
-
- for (auto &pattern : expr.get_patterns ())
- {
- TyTy::BaseType *kase_arm_ty
- = TypeCheckPattern::Resolve (pattern.get (), scrutinee_tyty);
-
- unify_site (expr.get_mappings ().get_hirid (),
- TyTy::TyWithLocation (scrutinee_tyty),
- TyTy::TyWithLocation (kase_arm_ty, pattern->get_locus ()),
- expr.get_locus ());
- }
-
- auto if_blk_resolved = TypeCheckExpr::Resolve (expr.get_if_block ().get ());
- auto else_blk_resolved
- = TypeCheckExpr::Resolve (expr.get_else_block ().get ());
-
- if (if_blk_resolved->get_kind () == TyTy::NEVER)
- infered = else_blk_resolved;
- else if (else_blk_resolved->get_kind () == TyTy::NEVER)
- infered = if_blk_resolved;
- else
- {
- infered = unify_site (
- expr.get_mappings ().get_hirid (),
- TyTy::TyWithLocation (if_blk_resolved,
- expr.get_if_block ()->get_locus ()),
- TyTy::TyWithLocation (else_blk_resolved,
- expr.get_else_block ()->get_locus ()),
- expr.get_locus ());
- }
-}
-
void
TypeCheckExpr::visit (HIR::UnsafeBlockExpr &expr)
{
diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.h b/gcc/rust/typecheck/rust-hir-type-check-expr.h
index 7192cf4dbda..997761144db 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.h
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.h
@@ -45,8 +45,6 @@ public:
void visit (HIR::NegationExpr &expr) override;
void visit (HIR::IfExpr &expr) override;
void visit (HIR::IfExprConseqElse &expr) override;
- void visit (HIR::IfLetExpr &expr) override;
- void visit (HIR::IfLetExprConseqElse &) override;
void visit (HIR::BlockExpr &expr) override;
void visit (HIR::UnsafeBlockExpr &expr) override;
void visit (HIR::ArrayIndexExpr &expr) override;
diff --git a/gcc/testsuite/rust/compile/if_let_expr.rs b/gcc/testsuite/rust/compile/if_let_expr.rs
index 7bab19a1ef0..b0879e5fadb 100644
--- a/gcc/testsuite/rust/compile/if_let_expr.rs
+++ b/gcc/testsuite/rust/compile/if_let_expr.rs
@@ -7,8 +7,9 @@ pub enum Option<T> {
}
fn main() {
- let x = Option::Some(3); // { dg-warning "unused name" }
- let a = if let Option::Some(1) = x {
+ let x = Option::Some(3);
+
+ let a = if let Option::Some(1) = x {// { dg-warning "unused name" }
1
} else if x == Option::Some(2) {
2
diff --git a/gcc/testsuite/rust/compile/if_let_expr_simple.rs b/gcc/testsuite/rust/compile/if_let_expr_simple.rs
new file mode 100644
index 00000000000..d7fb0afa7fd
--- /dev/null
+++ b/gcc/testsuite/rust/compile/if_let_expr_simple.rs
@@ -0,0 +1,12 @@
+enum MyOption {
+ Some(i32),
+ None,
+}
+
+pub fn toto(i : MyOption) -> i32 {
+ if let MyOption::Some(v) = i {
+ v
+ } else {
+ 23i32
+ }
+}
diff --git a/gcc/testsuite/rust/compile/iflet.rs b/gcc/testsuite/rust/compile/iflet.rs
new file mode 100644
index 00000000000..6d46339610f
--- /dev/null
+++ b/gcc/testsuite/rust/compile/iflet.rs
@@ -0,0 +1,32 @@
+pub fn simple_iflet() -> i32 {
+ let mut res = 0;
+
+ enum E {
+ X(i32),
+ }
+ let v = E::X(4);
+
+ if let E::X(n) = v {
+ res = 1;
+ }
+
+ res
+}
+
+pub fn simple_iflet_else() -> i32 {
+ let mut res = 0;
+
+ enum E {
+ X(i32),
+ Y,
+ }
+ let v = E::X(4);
+
+ if let E::Y = v {
+ res = 1;
+ } else {
+ res = 2;
+ }
+
+ res
+}
diff --git a/gcc/testsuite/rust/compile/nr2/exclude b/gcc/testsuite/rust/compile/nr2/exclude
index 47d651b22bd..424ad686094 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -223,4 +223,7 @@ issue-2203.rs
issue-2499.rs
issue-3032-1.rs
issue-3032-2.rs
+# https://github.com/Rust-GCC/gccrs/issues/3189
+if_let_expr_simple.rs
+iflet.rs
# please don't delete the trailing newline
diff --git a/gcc/testsuite/rust/execute/torture/iflet.rs b/gcc/testsuite/rust/execute/torture/iflet.rs
new file mode 100644
index 00000000000..da4e93ac398
--- /dev/null
+++ b/gcc/testsuite/rust/execute/torture/iflet.rs
@@ -0,0 +1,84 @@
+enum Res {
+ OK,
+ BAD,
+}
+
+enum LOption {
+ Some(i32),
+ None,
+}
+
+// Expect a Some(_)
+//
+// Check we can match a Some.
+fn test_can_destructure_Some(v: LOption) -> Res {
+ if let LOption::Some(v) = v {
+ return Res::OK;
+ }
+ return Res::BAD;
+}
+
+// Expect Some(100).
+//
+// Check we can destructure and the inner value is correct.
+fn test_inner_value_is_100(v: LOption) -> Res {
+ if let LOption::Some(v) = v {
+ return match v {
+ 100 => Res::OK,
+ _ => Res::BAD,
+ }
+ }
+ return Res::BAD;
+}
+
+// Expect a None as actual parameter.
+//
+// Only when we FAIL to match a Some do we take the else and return OK.
+fn test_if_else(v: LOption) -> Res {
+ if let LOption::Some(v) = v {
+ return Res::BAD;
+ } else {
+ return Res::OK;
+ }
+}
+
+fn main() -> i32 {
+
+ // Passing a None, so the function should return BAD
+ match test_can_destructure_Some(LOption::None) {
+ Res::OK => return 1,
+ Res::BAD => (),
+ }
+
+ // Same, but with a Some, should return OK
+ match test_can_destructure_Some(LOption::Some(1)) {
+ Res::OK => (),
+ Res::BAD => return 1,
+ }
+
+ // Check the destructuring is correct by looking for Some(100)
+ match test_inner_value_is_100(LOption::Some(100)) {
+ Res::OK => (),
+ Res::BAD => return 1,
+ }
+
+ // ... passing Some(1) should return BAD
+ match test_inner_value_is_100(LOption::Some(1)) {
+ Res::OK => return 1,
+ Res::BAD => (),
+ }
+
+ // ... and so does passing None
+ match test_inner_value_is_100(LOption::None) {
+ Res::OK => return 1,
+ Res::BAD => (),
+ }
+
+ // Check if let... else ...
+ match test_if_else(LOption::None) {
+ Res::OK => (),
+ Res::BAD => return 1,
+ }
+
+ 0
+}
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 011/146] gccrs: Use name resolution 2.0 in TraitResolver
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (9 preceding siblings ...)
2025-03-21 12:05 ` [COMMITTED 010/146] rust: Desugar IfLet* into MatchExpr arthur.cohen
@ 2025-03-21 12:05 ` arthur.cohen
2025-03-21 12:05 ` [COMMITTED 012/146] gccrs: Resolve SelfParam in name resolution 2.0 arthur.cohen
` (134 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:05 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Owen Avery
From: Owen Avery <powerboat9.gamer@gmail.com>
gcc/rust/ChangeLog:
* typecheck/rust-hir-trait-resolve.cc: Add includes.
(TraitResolver::resolve_path_to_trait):
Use name resolution 2.0 resolver when enabled.
gcc/testsuite/ChangeLog:
* rust/compile/nr2/exclude: Remove entries.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
---
gcc/rust/typecheck/rust-hir-trait-resolve.cc | 24 ++++++++++++++++++--
gcc/testsuite/rust/compile/nr2/exclude | 2 --
2 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/gcc/rust/typecheck/rust-hir-trait-resolve.cc b/gcc/rust/typecheck/rust-hir-trait-resolve.cc
index 91842df85b2..3d99794f3d6 100644
--- a/gcc/rust/typecheck/rust-hir-trait-resolve.cc
+++ b/gcc/rust/typecheck/rust-hir-trait-resolve.cc
@@ -20,6 +20,10 @@
#include "rust-hir-type-check-expr.h"
#include "rust-substitution-mapper.h"
#include "rust-type-util.h"
+#include "rust-immutable-name-resolution-context.h"
+
+// used for flag_name_resolution_2_0
+#include "options.h"
namespace Rust {
namespace Resolver {
@@ -110,8 +114,24 @@ TraitResolver::resolve_path_to_trait (const HIR::TypePath &path,
HIR::Trait **resolved) const
{
NodeId ref;
- if (!resolver->lookup_resolved_type (path.get_mappings ().get_nodeid (),
- &ref))
+ bool ok;
+ if (flag_name_resolution_2_0)
+ {
+ auto &nr_ctx
+ = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+
+ auto ref_opt = nr_ctx.lookup (path.get_mappings ().get_nodeid ());
+
+ if ((ok = ref_opt.has_value ()))
+ ref = *ref_opt;
+ }
+ else
+ {
+ ok = resolver->lookup_resolved_type (path.get_mappings ().get_nodeid (),
+ &ref);
+ }
+
+ if (!ok)
{
rust_error_at (path.get_locus (), "Failed to resolve path to node-id");
return false;
diff --git a/gcc/testsuite/rust/compile/nr2/exclude b/gcc/testsuite/rust/compile/nr2/exclude
index 424ad686094..f4304dae1d8 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -65,7 +65,6 @@ issue-1272.rs
issue-1289.rs
issue-1447.rs
issue-1483.rs
-issue-1589.rs
issue-1725-1.rs
issue-1725-2.rs
issue-1786.rs
@@ -175,7 +174,6 @@ sizeof-stray-infer-var-bug.rs
specify-crate-name.rs
stmt_with_block_dot.rs
struct-expr-parse.rs
-trait-cycle.rs
traits1.rs
traits10.rs
traits11.rs
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 012/146] gccrs: Resolve SelfParam in name resolution 2.0
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (10 preceding siblings ...)
2025-03-21 12:05 ` [COMMITTED 011/146] gccrs: Use name resolution 2.0 in TraitResolver arthur.cohen
@ 2025-03-21 12:05 ` arthur.cohen
2025-03-21 12:05 ` [COMMITTED 013/146] gccrs: add test case to show method resolution is working arthur.cohen
` (133 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:05 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Owen Avery
From: Owen Avery <powerboat9.gamer@gmail.com>
gcc/rust/ChangeLog:
* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): Handle SelfParam.
* resolve/rust-late-name-resolver-2.0.h
(Late::visit): Likewise.
gcc/testsuite/ChangeLog:
* rust/compile/nr2/exclude: Remove entries.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
---
gcc/rust/resolve/rust-late-name-resolver-2.0.cc | 12 ++++++++++++
gcc/rust/resolve/rust-late-name-resolver-2.0.h | 1 +
gcc/testsuite/rust/compile/nr2/exclude | 4 ----
3 files changed, 13 insertions(+), 4 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 5fd49e7c2c9..5fc97a0922b 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
@@ -164,6 +164,18 @@ Late::visit (AST::IdentifierPattern &identifier)
identifier.get_node_id ());
}
+void
+Late::visit (AST::SelfParam ¶m)
+{
+ // handle similar to AST::IdentifierPattern
+
+ DefaultResolver::visit (param);
+ // FIXME: this location should be a bit off
+ // ex: would point to the begining of "mut self" instead of the "self"
+ std::ignore = ctx.values.insert (Identifier ("self", param.get_locus ()),
+ param.get_node_id ());
+}
+
void
Late::visit (AST::IdentifierExpr &expr)
{
diff --git a/gcc/rust/resolve/rust-late-name-resolver-2.0.h b/gcc/rust/resolve/rust-late-name-resolver-2.0.h
index 7e33c965805..35fe400aeea 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.h
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.h
@@ -41,6 +41,7 @@ public:
// TODO: Do we need this?
// void visit (AST::Method &) override;
void visit (AST::IdentifierPattern &) override;
+ void visit (AST::SelfParam &) override;
// resolutions
void visit (AST::IdentifierExpr &) override;
diff --git a/gcc/testsuite/rust/compile/nr2/exclude b/gcc/testsuite/rust/compile/nr2/exclude
index f4304dae1d8..b4799edd4f5 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -34,7 +34,6 @@ derive_macro6.rs
expected_type_args2.rs
expected_type_args3.rs
feature_rust_attri0.rs
-feature_rust_attri1.rs
for_lifetimes.rs
format_args_basic_expansion.rs
generic-default1.rs
@@ -54,13 +53,11 @@ infer-crate-name.rs
issue-1019.rs
issue-1031.rs
issue-1034.rs
-issue-1128.rs
issue-1129-2.rs
issue-1130.rs
issue-1165.rs
issue-1173.rs
issue-1235.rs
-issue-1237.rs
issue-1272.rs
issue-1289.rs
issue-1447.rs
@@ -167,7 +164,6 @@ redef_error2.rs
redef_error4.rs
redef_error5.rs
redef_error6.rs
-rustc_attr1.rs
self-path1.rs
self-path2.rs
sizeof-stray-infer-var-bug.rs
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 013/146] gccrs: add test case to show method resolution is working
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (11 preceding siblings ...)
2025-03-21 12:05 ` [COMMITTED 012/146] gccrs: Resolve SelfParam in name resolution 2.0 arthur.cohen
@ 2025-03-21 12:05 ` arthur.cohen
2025-03-21 12:05 ` [COMMITTED 014/146] gccrs: Make TyTy::TupleType::get_unit_type cache its return value arthur.cohen
` (132 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:05 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Philip Herron
From: Philip Herron <herron.philip@googlemail.com>
The issue here was that the impl block for Cell<T> defines that T must have
the bound of Copy implemented. But simultaneously if you do an deref
you get direct access to the unsafe cell which also defines a get method
so these are two valid ways of accessing the method in question but
when Copy is implementet the simplest case is prefered so it does resolve
to Cell<T>::get.
Fixes #3033
gcc/testsuite/ChangeLog:
* rust/compile/nr2/exclude: nr can't handle this
* rust/compile/issue-3033.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
---
gcc/testsuite/rust/compile/issue-3033.rs | 144 +++++++++++++++++++++++
gcc/testsuite/rust/compile/nr2/exclude | 1 +
2 files changed, 145 insertions(+)
create mode 100644 gcc/testsuite/rust/compile/issue-3033.rs
diff --git a/gcc/testsuite/rust/compile/issue-3033.rs b/gcc/testsuite/rust/compile/issue-3033.rs
new file mode 100644
index 00000000000..9085b7616c0
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-3033.rs
@@ -0,0 +1,144 @@
+#![feature(negative_impls)]
+
+#[lang = "copy"]
+trait Copy {}
+
+mod copy_impls {
+ use super::Copy;
+
+ macro_rules! impl_copy {
+ ($($t:ty)*) => {
+ $(
+ impl Copy for $t {}
+ )*
+ }
+ }
+
+ impl_copy! {
+ usize u8 u16 u32 u64 // u128
+ isize i8 i16 i32 i64 // i128
+ f32 f64
+ bool char
+ }
+}
+
+#[stable(feature = "rust1", since = "1.0.0")]
+#[repr(transparent)]
+#[repr(no_niche)] // rust-lang/rust#68303.
+pub struct UnsafeCell<T: ?Sized> {
+ value: T,
+ // { dg-warning "field is never read" "" { target *-*-* } .-1 }
+}
+
+impl<T: ?Sized> UnsafeCell<T> {
+ /// Gets a mutable pointer to the wrapped value.
+ ///
+ /// This can be cast to a pointer of any kind.
+ /// Ensure that the access is unique (no active references, mutable or not)
+ /// when casting to `&mut T`, and ensure that there are no mutations
+ /// or mutable aliases going on when casting to `&T`
+ ///
+ /// # Examples
+ ///
+ ///
+ /// use std::cell::UnsafeCell;
+ ///
+ /// let uc = UnsafeCell::new(5);
+ ///
+ /// let five = uc.get();
+ ///
+ #[inline]
+ #[stable(feature = "rust1", since = "1.0.0")]
+ // #[rustc_const_stable(feature = "const_unsafecell_get", since = "1.32.0")]
+ pub const fn get(&self) -> *mut T {
+ // We can just cast the pointer from `UnsafeCell<T>` to `T` because of
+ // #[repr(transparent)]. This exploits libstd's special status, there is
+ // no guarantee for user code that this will work in future versions of the compiler!
+ self as *const UnsafeCell<T> as *const T as *mut T
+ }
+}
+
+#[stable(feature = "rust1", since = "1.0.0")]
+#[repr(transparent)]
+pub struct Cell<T: ?Sized> {
+ value: UnsafeCell<T>,
+ // { dg-warning "field is never read" "" { target *-*-* } .-1 }
+}
+
+impl<T: Copy> Cell<T> {
+ /// Returns a copy of the contained value.
+ ///
+ /// # Examples
+ ///
+ ///
+ /// use std::cell::Cell;
+ ///
+ /// let c = Cell::new(5);
+ ///
+ /// let five = c.get();
+ ///
+ #[inline]
+ #[stable(feature = "rust1", since = "1.0.0")]
+ pub fn get(&self) -> T {
+ // SAFETY: This can cause data races if called from a separate thread,
+ // but `Cell` is `!Sync` so this won't happen.
+ unsafe { *self.value.get() }
+ }
+}
+
+#[lang = "sized"]
+trait Sized {}
+
+#[lang = "deref"]
+pub trait Deref {
+ /// The resulting type after dereferencing.
+ #[stable(feature = "rust1", since = "1.0.0")]
+ // #[rustc_diagnostic_item = "deref_target"]
+ type Target: ?Sized;
+
+ /// Dereferences the value.
+ #[must_use]
+ #[stable(feature = "rust1", since = "1.0.0")]
+ // #[rustc_diagnostic_item = "deref_method"]
+ fn deref(&self) -> &Self::Target;
+}
+
+impl<T: ?Sized> Deref for &T {
+ type Target = T;
+
+ fn deref(&self) -> &T {
+ *self
+ }
+}
+
+// this is added because of #3030
+extern "C" {
+ fn never() -> !;
+}
+
+impl<T: ?Sized> !DerefMut for &T {
+ fn deref_mut(&mut self) -> &mut T {
+ unsafe { never() }
+ }
+}
+
+impl<T: ?Sized> Deref for &mut T {
+ type Target = T;
+
+ fn deref(&self) -> &T {
+ *self
+ }
+}
+
+#[lang = "deref_mut"]
+pub trait DerefMut: Deref {
+ /// Mutably dereferences the value.
+ #[stable(feature = "rust1", since = "1.0.0")]
+ fn deref_mut(&mut self) -> &mut Self::Target;
+}
+
+#[inline]
+pub fn new<'b>(borrow: &'b Cell<i32>) {
+ let b = borrow.get();
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
diff --git a/gcc/testsuite/rust/compile/nr2/exclude b/gcc/testsuite/rust/compile/nr2/exclude
index b4799edd4f5..ceada8bc51a 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -220,4 +220,5 @@ issue-3032-2.rs
# https://github.com/Rust-GCC/gccrs/issues/3189
if_let_expr_simple.rs
iflet.rs
+issue-3033.rs
# please don't delete the trailing newline
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 014/146] gccrs: Make TyTy::TupleType::get_unit_type cache its return value
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (12 preceding siblings ...)
2025-03-21 12:05 ` [COMMITTED 013/146] gccrs: add test case to show method resolution is working arthur.cohen
@ 2025-03-21 12:05 ` arthur.cohen
2025-03-21 12:05 ` [COMMITTED 015/146] gccrs: fix bad type inferencing on path's arthur.cohen
` (131 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:05 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Owen Avery
From: Owen Avery <powerboat9.gamer@gmail.com>
This removes a usage of Resolver::get_unit_type_node_id in
rust-hir-type-check-expr.cc (the HIR::TupleExpr overload of
TypeCheckExpr::visit).
gcc/rust/ChangeLog:
* typecheck/rust-tyty.cc
(TupleType::get_unit_type): Remove parameter, cache return
value.
* typecheck/rust-tyty.h
(TupleType::get_unit_type): Remove parameter.
* resolve/rust-late-name-resolver-2.0.cc
(Late::setup_builtin_types): Adjust calls to get_unit_type.
* resolve/rust-name-resolver.cc
(Resolver::generate_builtins): Likewise.
* typecheck/rust-hir-type-check-expr.cc
(TypeCheckExpr::visit): Likewise.
* typecheck/rust-hir-type-check-implitem.cc
(TypeCheckTopLevelExternItem::visit): Likewise.
(TypeCheckImplItem::visit): Likewise.
* typecheck/rust-hir-type-check-item.cc
(TypeCheckItem::visit): Likewise.
* typecheck/rust-hir-type-check-stmt.cc
(TypeCheckStmt::visit): Likewise.
* typecheck/rust-hir-type-check-type.cc
(TypeCheckType::visit): Likewise.
* typecheck/rust-hir-type-check.cc
(TraitItemReference::get_type_from_fn): Likewise.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
---
.../resolve/rust-late-name-resolver-2.0.cc | 2 +-
gcc/rust/resolve/rust-name-resolver.cc | 3 +-
.../typecheck/rust-hir-type-check-expr.cc | 43 +++++++------------
.../typecheck/rust-hir-type-check-implitem.cc | 6 +--
.../typecheck/rust-hir-type-check-item.cc | 3 +-
.../typecheck/rust-hir-type-check-stmt.cc | 4 +-
.../typecheck/rust-hir-type-check-type.cc | 2 +-
gcc/rust/typecheck/rust-hir-type-check.cc | 2 +-
gcc/rust/typecheck/rust-tyty.cc | 8 +++-
gcc/rust/typecheck/rust-tyty.h | 2 +-
10 files changed, 31 insertions(+), 44 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 5fc97a0922b..812154eaf79 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
@@ -100,7 +100,7 @@ Late::setup_builtin_types ()
}
// ...here!
- auto *unit_type = TyTy::TupleType::get_unit_type (next_hir_id ());
+ auto *unit_type = TyTy::TupleType::get_unit_type ();
ty_ctx.insert_builtin (unit_type->get_ref (), next_node_id (), unit_type);
}
diff --git a/gcc/rust/resolve/rust-name-resolver.cc b/gcc/rust/resolve/rust-name-resolver.cc
index 21147bd86fa..3b4e3111d93 100644
--- a/gcc/rust/resolve/rust-name-resolver.cc
+++ b/gcc/rust/resolve/rust-name-resolver.cc
@@ -435,8 +435,7 @@ Resolver::generate_builtins ()
set_never_type_node_id (never_node_id);
// unit type ()
- TyTy::TupleType *unit_tyty
- = TyTy::TupleType::get_unit_type (mappings.get_next_hir_id ());
+ TyTy::TupleType *unit_tyty = TyTy::TupleType::get_unit_type ();
std::vector<std::unique_ptr<AST::Type> > elems;
AST::TupleType *unit_type
= new AST::TupleType (std::move (elems), BUILTINS_LOCATION);
diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
index 5b64daf33b7..225d83624e0 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
@@ -131,12 +131,7 @@ TypeCheckExpr::visit (HIR::TupleExpr &expr)
{
if (expr.is_unit ())
{
- auto unit_node_id = resolver->get_unit_type_node_id ();
- if (!context->lookup_builtin (unit_node_id, &infered))
- {
- rust_error_at (expr.get_locus (),
- "failed to lookup builtin unit type");
- }
+ infered = TyTy::TupleType::get_unit_type ();
return;
}
@@ -165,10 +160,9 @@ TypeCheckExpr::visit (HIR::ReturnExpr &expr)
location_t expr_locus = expr.has_return_expr ()
? expr.get_expr ()->get_locus ()
: expr.get_locus ();
- TyTy::BaseType *expr_ty
- = expr.has_return_expr ()
- ? TypeCheckExpr::Resolve (expr.get_expr ().get ())
- : TyTy::TupleType::get_unit_type (expr.get_mappings ().get_hirid ());
+ TyTy::BaseType *expr_ty = expr.has_return_expr ()
+ ? TypeCheckExpr::Resolve (expr.get_expr ().get ())
+ : TyTy::TupleType::get_unit_type ();
coercion_site (expr.get_mappings ().get_hirid (),
TyTy::TyWithLocation (fn_return_tyty),
@@ -242,7 +236,7 @@ TypeCheckExpr::visit (HIR::CallExpr &expr)
void
TypeCheckExpr::visit (HIR::AssignmentExpr &expr)
{
- infered = TyTy::TupleType::get_unit_type (expr.get_mappings ().get_hirid ());
+ infered = TyTy::TupleType::get_unit_type ();
auto lhs = TypeCheckExpr::Resolve (expr.get_lhs ().get ());
auto rhs = TypeCheckExpr::Resolve (expr.get_rhs ().get ());
@@ -256,7 +250,7 @@ TypeCheckExpr::visit (HIR::AssignmentExpr &expr)
void
TypeCheckExpr::visit (HIR::CompoundAssignmentExpr &expr)
{
- infered = TyTy::TupleType::get_unit_type (expr.get_mappings ().get_hirid ());
+ infered = TyTy::TupleType::get_unit_type ();
auto lhs = TypeCheckExpr::Resolve (expr.get_lhs ().get ());
auto rhs = TypeCheckExpr::Resolve (expr.get_rhs ().get ());
@@ -465,7 +459,7 @@ TypeCheckExpr::visit (HIR::IfExpr &expr)
TypeCheckExpr::Resolve (expr.get_if_block ().get ());
- infered = TyTy::TupleType::get_unit_type (expr.get_mappings ().get_hirid ());
+ infered = TyTy::TupleType::get_unit_type ();
}
void
@@ -538,8 +532,7 @@ TypeCheckExpr::visit (HIR::BlockExpr &expr)
if (s->is_unit_check_needed () && !resolved->is_unit ())
{
- auto unit
- = TyTy::TupleType::get_unit_type (s->get_mappings ().get_hirid ());
+ auto unit = TyTy::TupleType::get_unit_type ();
resolved
= unify_site (s->get_mappings ().get_hirid (),
TyTy::TyWithLocation (unit),
@@ -550,8 +543,7 @@ TypeCheckExpr::visit (HIR::BlockExpr &expr)
if (expr.has_expr ())
infered = TypeCheckExpr::Resolve (expr.get_final_expr ().get ())->clone ();
else if (expr.is_tail_reachable ())
- infered
- = TyTy::TupleType::get_unit_type (expr.get_mappings ().get_hirid ());
+ infered = TyTy::TupleType::get_unit_type ();
else if (expr.has_label ())
{
TyTy::BaseType *loop_context_type = context->pop_loop_context ();
@@ -563,8 +555,7 @@ TypeCheckExpr::visit (HIR::BlockExpr &expr)
!= TyTy::InferType::GENERAL));
infered = loop_context_type_infered ? loop_context_type
- : TyTy::TupleType::get_unit_type (
- expr.get_mappings ().get_hirid ());
+ : TyTy::TupleType::get_unit_type ();
}
else
{
@@ -773,8 +764,7 @@ TypeCheckExpr::visit (HIR::InlineAsm &expr)
if (expr.options.count (AST::InlineAsmOption::NORETURN) == 1)
infered = new TyTy::NeverType (expr.get_mappings ().get_hirid ());
else
- infered
- = TyTy::TupleType::get_unit_type (expr.get_mappings ().get_hirid ());
+ infered = TyTy::TupleType::get_unit_type ();
}
void
@@ -1295,10 +1285,8 @@ TypeCheckExpr::visit (HIR::LoopExpr &expr)
&& (((TyTy::InferType *) loop_context_type)->get_infer_kind ()
!= TyTy::InferType::GENERAL));
- infered
- = loop_context_type_infered
- ? loop_context_type
- : TyTy::TupleType::get_unit_type (expr.get_mappings ().get_hirid ());
+ infered = loop_context_type_infered ? loop_context_type
+ : TyTy::TupleType::get_unit_type ();
}
void
@@ -1319,7 +1307,7 @@ TypeCheckExpr::visit (HIR::WhileLoopExpr &expr)
}
context->pop_loop_context ();
- infered = TyTy::TupleType::get_unit_type (expr.get_mappings ().get_hirid ());
+ infered = TyTy::TupleType::get_unit_type ();
}
void
@@ -1506,8 +1494,7 @@ TypeCheckExpr::visit (HIR::MatchExpr &expr)
if (kase_block_tys.size () == 0)
{
- infered
- = TyTy::TupleType::get_unit_type (expr.get_mappings ().get_hirid ());
+ infered = TyTy::TupleType::get_unit_type ();
return;
}
diff --git a/gcc/rust/typecheck/rust-hir-type-check-implitem.cc b/gcc/rust/typecheck/rust-hir-type-check-implitem.cc
index 0036e9a6c89..19f25e4f867 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-implitem.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-implitem.cc
@@ -113,8 +113,7 @@ TypeCheckTopLevelExternItem::visit (HIR::ExternalFunctionItem &function)
TyTy::BaseType *ret_type = nullptr;
if (!function.has_return_type ())
- ret_type
- = TyTy::TupleType::get_unit_type (function.get_mappings ().get_hirid ());
+ ret_type = TyTy::TupleType::get_unit_type ();
else
{
auto resolved
@@ -359,8 +358,7 @@ TypeCheckImplItem::visit (HIR::Function &function)
TyTy::BaseType *ret_type = nullptr;
if (!function.has_function_return_type ())
- ret_type
- = TyTy::TupleType::get_unit_type (function.get_mappings ().get_hirid ());
+ ret_type = TyTy::TupleType::get_unit_type ();
else
{
auto resolved
diff --git a/gcc/rust/typecheck/rust-hir-type-check-item.cc b/gcc/rust/typecheck/rust-hir-type-check-item.cc
index 4ea685261cb..81e2f25f73d 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-item.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-item.cc
@@ -558,8 +558,7 @@ TypeCheckItem::visit (HIR::Function &function)
TyTy::BaseType *ret_type = nullptr;
if (!function.has_function_return_type ())
- ret_type
- = TyTy::TupleType::get_unit_type (function.get_mappings ().get_hirid ());
+ ret_type = TyTy::TupleType::get_unit_type ();
else
{
auto resolved
diff --git a/gcc/rust/typecheck/rust-hir-type-check-stmt.cc b/gcc/rust/typecheck/rust-hir-type-check-stmt.cc
index 6d27d3df3af..c395ed02f88 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-stmt.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-stmt.cc
@@ -44,7 +44,7 @@ TypeCheckStmt::visit (HIR::ExprStmt &stmt)
void
TypeCheckStmt::visit (HIR::EmptyStmt &stmt)
{
- infered = TyTy::TupleType::get_unit_type (stmt.get_mappings ().get_hirid ());
+ infered = TyTy::TupleType::get_unit_type ();
}
void
@@ -74,7 +74,7 @@ TypeCheckStmt::visit (HIR::ConstantItem &constant)
void
TypeCheckStmt::visit (HIR::LetStmt &stmt)
{
- infered = TyTy::TupleType::get_unit_type (stmt.get_mappings ().get_hirid ());
+ infered = TyTy::TupleType::get_unit_type ();
HIR::Pattern &stmt_pattern = *stmt.get_pattern ();
TyTy::BaseType *init_expr_ty = nullptr;
diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.cc b/gcc/rust/typecheck/rust-hir-type-check-type.cc
index f7ae8cca612..ee17e53eb30 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-type.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-type.cc
@@ -88,7 +88,7 @@ TypeCheckType::visit (HIR::BareFunctionType &fntype)
{
// needs a new implicit ID
HirId ref = mappings.get_next_hir_id ();
- return_type = TyTy::TupleType::get_unit_type (ref);
+ return_type = TyTy::TupleType::get_unit_type ();
context->insert_implicit_type (ref, return_type);
}
diff --git a/gcc/rust/typecheck/rust-hir-type-check.cc b/gcc/rust/typecheck/rust-hir-type-check.cc
index 51ab87d14b8..628660a208c 100644
--- a/gcc/rust/typecheck/rust-hir-type-check.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check.cc
@@ -206,7 +206,7 @@ TraitItemReference::get_type_from_fn (/*const*/ HIR::TraitItemFunc &fn) const
TyTy::BaseType *ret_type = nullptr;
if (!function.has_return_type ())
- ret_type = TyTy::TupleType::get_unit_type (fn.get_mappings ().get_hirid ());
+ ret_type = TyTy::TupleType::get_unit_type ();
else
{
auto resolved
diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc
index e0a8745d3a3..1812c618dcb 100644
--- a/gcc/rust/typecheck/rust-tyty.cc
+++ b/gcc/rust/typecheck/rust-tyty.cc
@@ -1747,9 +1747,13 @@ TupleType::TupleType (HirId ref, HirId ty_ref, location_t locus,
{}
TupleType *
-TupleType::get_unit_type (HirId ref)
+TupleType::get_unit_type ()
{
- return new TupleType (ref, BUILTINS_LOCATION);
+ static TupleType *ret = nullptr;
+ if (ret == nullptr)
+ ret = new TupleType (Analysis::Mappings::get ().get_next_hir_id (),
+ BUILTINS_LOCATION);
+ return ret;
}
size_t
diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h
index 39750294cf0..d73db3d265a 100644
--- a/gcc/rust/typecheck/rust-tyty.h
+++ b/gcc/rust/typecheck/rust-tyty.h
@@ -447,7 +447,7 @@ public:
std::vector<TyVar> fields = std::vector<TyVar> (),
std::set<HirId> refs = std::set<HirId> ());
- static TupleType *get_unit_type (HirId ref);
+ static TupleType *get_unit_type ();
void accept_vis (TyVisitor &vis) override;
void accept_vis (TyConstVisitor &vis) const override;
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 015/146] gccrs: fix bad type inferencing on path's
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (13 preceding siblings ...)
2025-03-21 12:05 ` [COMMITTED 014/146] gccrs: Make TyTy::TupleType::get_unit_type cache its return value arthur.cohen
@ 2025-03-21 12:05 ` arthur.cohen
2025-03-21 12:05 ` [COMMITTED 016/146] gccrs: Remove usage of Resolver::get_builtin_types arthur.cohen
` (130 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:05 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Philip Herron
From: Philip Herron <herron.philip@googlemail.com>
This catch to inject inference variables into generic paths was a
catch all 'hack' that we needed before we handled generics correctly
as we do now.
Fixes #3009
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_segments): remove hack
gcc/testsuite/ChangeLog:
* rust/compile/nr2/exclude: nr2 cant handle this
* rust/compile/issue-3009.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
---
.../typecheck/rust-hir-type-check-path.cc | 8 -------
gcc/testsuite/rust/compile/issue-3009.rs | 24 +++++++++++++++++++
gcc/testsuite/rust/compile/nr2/exclude | 1 +
3 files changed, 25 insertions(+), 8 deletions(-)
create mode 100644 gcc/testsuite/rust/compile/issue-3009.rs
diff --git a/gcc/rust/typecheck/rust-hir-type-check-path.cc b/gcc/rust/typecheck/rust-hir-type-check-path.cc
index c6552099bed..231ddd604db 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-path.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-path.cc
@@ -490,14 +490,6 @@ TypeCheckExpr::resolve_segments (NodeId root_resolved_node_id,
}
rust_assert (resolved_node_id != UNKNOWN_NODEID);
- if (tyseg->needs_generic_substitutions () && !reciever_is_generic)
- {
- location_t locus = segments.back ().get_locus ();
- tyseg = SubstMapper::InferSubst (tyseg, locus);
- if (tyseg->get_kind () == TyTy::TypeKind::ERROR)
- return;
- }
-
context->insert_receiver (expr_mappings.get_hirid (), prev_segment);
// name scope first
diff --git a/gcc/testsuite/rust/compile/issue-3009.rs b/gcc/testsuite/rust/compile/issue-3009.rs
new file mode 100644
index 00000000000..2eb4ef39abd
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-3009.rs
@@ -0,0 +1,24 @@
+#[lang = "sized"]
+trait Sized {}
+
+struct Foo {
+ // { dg-warning "struct is never constructed" "" { target *-*-* } .-1 }
+ t: u64,
+}
+
+impl Foo {
+ fn of<T>() -> Foo {
+ // { dg-warning "associated function is never used" "" { target *-*-* } .-1 }
+ Foo { t: 14 }
+ }
+}
+
+trait Bar {
+ fn bar() -> Foo;
+}
+
+impl<T> Bar for T {
+ fn bar() -> Foo {
+ Foo::of::<T>()
+ }
+}
diff --git a/gcc/testsuite/rust/compile/nr2/exclude b/gcc/testsuite/rust/compile/nr2/exclude
index ceada8bc51a..4ba27d31f88 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -221,4 +221,5 @@ issue-3032-2.rs
if_let_expr_simple.rs
iflet.rs
issue-3033.rs
+issue-3009.rs
# please don't delete the trailing newline
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 016/146] gccrs: Remove usage of Resolver::get_builtin_types
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (14 preceding siblings ...)
2025-03-21 12:05 ` [COMMITTED 015/146] gccrs: fix bad type inferencing on path's arthur.cohen
@ 2025-03-21 12:05 ` arthur.cohen
2025-03-21 12:05 ` [COMMITTED 017/146] gccrs: Improve handling of struct expressions in nr2.0 arthur.cohen
` (129 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:05 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Owen Avery
From: Owen Avery <powerboat9.gamer@gmail.com>
gcc/rust/ChangeLog:
* backend/rust-compile-context.cc
(Context::setup_builtins): Use TypeCheckContext::get_builtins
instead of Resolver::get_builtin_types,
TypeCheckContext::lookup_type_by_node_id, and
TypeCheckContext::lookup_type.
* typecheck/rust-hir-type-check.h
(TypeCheckContext::get_builtins): Add.
* typecheck/rust-typecheck-context.cc
(TypeCheckContext::get_builtins): Add.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
---
gcc/rust/backend/rust-compile-context.cc | 15 ++-------------
gcc/rust/typecheck/rust-hir-type-check.h | 1 +
gcc/rust/typecheck/rust-typecheck-context.cc | 6 ++++++
3 files changed, 9 insertions(+), 13 deletions(-)
diff --git a/gcc/rust/backend/rust-compile-context.cc b/gcc/rust/backend/rust-compile-context.cc
index c80f95649f1..86f089440ac 100644
--- a/gcc/rust/backend/rust-compile-context.cc
+++ b/gcc/rust/backend/rust-compile-context.cc
@@ -33,19 +33,8 @@ Context::Context ()
void
Context::setup_builtins ()
{
- auto builtins = resolver->get_builtin_types ();
- for (auto it = builtins.begin (); it != builtins.end (); it++)
- {
- HirId ref;
- bool ok = tyctx->lookup_type_by_node_id ((*it)->get_node_id (), &ref);
- rust_assert (ok);
-
- TyTy::BaseType *lookup;
- ok = tyctx->lookup_type (ref, &lookup);
- rust_assert (ok);
-
- TyTyResolveCompile::compile (this, lookup);
- }
+ for (auto &builtin : tyctx->get_builtins ())
+ TyTyResolveCompile::compile (this, builtin.get ());
}
hashval_t
diff --git a/gcc/rust/typecheck/rust-hir-type-check.h b/gcc/rust/typecheck/rust-hir-type-check.h
index fa49e0689f3..5b1fe220890 100644
--- a/gcc/rust/typecheck/rust-hir-type-check.h
+++ b/gcc/rust/typecheck/rust-hir-type-check.h
@@ -135,6 +135,7 @@ public:
bool lookup_builtin (NodeId id, TyTy::BaseType **type);
bool lookup_builtin (std::string name, TyTy::BaseType **type);
void insert_builtin (HirId id, NodeId ref, TyTy::BaseType *type);
+ const std::vector<std::unique_ptr<TyTy::BaseType>> &get_builtins () const;
void insert_type (const Analysis::NodeMapping &mappings,
TyTy::BaseType *type);
diff --git a/gcc/rust/typecheck/rust-typecheck-context.cc b/gcc/rust/typecheck/rust-typecheck-context.cc
index 8f7a8a4f48f..0fb8224861e 100644
--- a/gcc/rust/typecheck/rust-typecheck-context.cc
+++ b/gcc/rust/typecheck/rust-typecheck-context.cc
@@ -73,6 +73,12 @@ TypeCheckContext::insert_builtin (HirId id, NodeId ref, TyTy::BaseType *type)
builtins.push_back (std::unique_ptr<TyTy::BaseType> (type));
}
+const std::vector<std::unique_ptr<TyTy::BaseType>> &
+TypeCheckContext::get_builtins () const
+{
+ return builtins;
+}
+
void
TypeCheckContext::insert_type (const Analysis::NodeMapping &mappings,
TyTy::BaseType *type)
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 017/146] gccrs: Improve handling of struct expressions in nr2.0
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (15 preceding siblings ...)
2025-03-21 12:05 ` [COMMITTED 016/146] gccrs: Remove usage of Resolver::get_builtin_types arthur.cohen
@ 2025-03-21 12:05 ` arthur.cohen
2025-03-21 12:05 ` [COMMITTED 018/146] gccrs: fix bad type inference on local patterns arthur.cohen
` (128 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:05 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Owen Avery
From: Owen Avery <powerboat9.gamer@gmail.com>
gcc/rust/ChangeLog:
* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): Handle StructExprStruct and use
ForeverStack::resolve_path instead of ForeverStack::get to
resolve struct expression paths.
* resolve/rust-late-name-resolver-2.0.h
(Late::visit): Handle StructExprStruct.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
---
gcc/rust/resolve/rust-late-name-resolver-2.0.cc | 13 +++++++++++--
gcc/rust/resolve/rust-late-name-resolver-2.0.h | 1 +
2 files changed, 12 insertions(+), 2 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 812154eaf79..850f96aef89 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
@@ -272,10 +272,19 @@ Late::visit (AST::StructStruct &s)
ctx.scoped (Rib::Kind::Item, s.get_node_id (), s_vis);
}
+void
+Late::visit (AST::StructExprStruct &s)
+{
+ auto resolved = ctx.types.resolve_path (s.get_struct_name ().get_segments ());
+
+ ctx.map_usage (Usage (s.get_struct_name ().get_node_id ()),
+ Definition (resolved->get_node_id ()));
+}
+
void
Late::visit (AST::StructExprStructBase &s)
{
- auto resolved = ctx.types.get (s.get_struct_name ().as_string ());
+ auto resolved = ctx.types.resolve_path (s.get_struct_name ().get_segments ());
ctx.map_usage (Usage (s.get_struct_name ().get_node_id ()),
Definition (resolved->get_node_id ()));
@@ -285,7 +294,7 @@ Late::visit (AST::StructExprStructBase &s)
void
Late::visit (AST::StructExprStructFields &s)
{
- auto resolved = ctx.types.get (s.get_struct_name ().as_string ());
+ auto resolved = ctx.types.resolve_path (s.get_struct_name ().get_segments ());
ctx.map_usage (Usage (s.get_struct_name ().get_node_id ()),
Definition (resolved->get_node_id ()));
diff --git a/gcc/rust/resolve/rust-late-name-resolver-2.0.h b/gcc/rust/resolve/rust-late-name-resolver-2.0.h
index 35fe400aeea..79572fbc4fa 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.h
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.h
@@ -47,6 +47,7 @@ public:
void visit (AST::IdentifierExpr &) override;
void visit (AST::PathInExpression &) override;
void visit (AST::TypePath &) override;
+ void visit (AST::StructExprStruct &) override;
void visit (AST::StructExprStructBase &) override;
void visit (AST::StructExprStructFields &) override;
void visit (AST::StructStruct &) override;
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 018/146] gccrs: fix bad type inference on local patterns
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (16 preceding siblings ...)
2025-03-21 12:05 ` [COMMITTED 017/146] gccrs: Improve handling of struct expressions in nr2.0 arthur.cohen
@ 2025-03-21 12:05 ` arthur.cohen
2025-03-21 12:05 ` [COMMITTED 019/146] gccrs: Use name resolver 2.0 in VisibilityResolver arthur.cohen
` (127 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:05 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Philip Herron
From: Philip Herron <herron.philip@googlemail.com>
We do not need to inject inference variables on generic patterns
with generic blocks. This will just cause unconstrained inference
variables as they may not unify against something.
Fixes Rust-GCC#2323
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_root_path): dont infer here
gcc/testsuite/ChangeLog:
* rust/compile/nr2/exclude: nr2 cant handle this
* rust/compile/issue-2323.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
---
gcc/rust/typecheck/rust-hir-type-check-path.cc | 3 ++-
gcc/testsuite/rust/compile/issue-2323.rs | 9 +++++++++
gcc/testsuite/rust/compile/nr2/exclude | 1 +
3 files changed, 12 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/rust/compile/issue-2323.rs
diff --git a/gcc/rust/typecheck/rust-hir-type-check-path.cc b/gcc/rust/typecheck/rust-hir-type-check-path.cc
index 231ddd604db..7b934b38eb3 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-path.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-path.cc
@@ -245,6 +245,7 @@ TypeCheckExpr::resolve_root_path (HIR::PathInExpression &expr, size_t *offset,
auto seg_is_module = mappings.lookup_module (ref).has_value ();
auto seg_is_crate = mappings.is_local_hirid_crate (ref);
+ auto seg_is_pattern = mappings.lookup_hir_pattern (ref).has_value ();
if (seg_is_module || seg_is_crate)
{
// A::B::C::this_is_a_module::D::E::F
@@ -321,7 +322,7 @@ TypeCheckExpr::resolve_root_path (HIR::PathInExpression &expr, size_t *offset,
if (lookup->get_kind () == TyTy::TypeKind::ERROR)
return new TyTy::ErrorType (expr.get_mappings ().get_hirid ());
}
- else if (lookup->needs_generic_substitutions ())
+ else if (lookup->needs_generic_substitutions () && !seg_is_pattern)
{
lookup = SubstMapper::InferSubst (lookup, expr.get_locus ());
}
diff --git a/gcc/testsuite/rust/compile/issue-2323.rs b/gcc/testsuite/rust/compile/issue-2323.rs
new file mode 100644
index 00000000000..02a3f90b4d8
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-2323.rs
@@ -0,0 +1,9 @@
+#[lang = "sized"]
+trait Sized {}
+
+pub struct S<T>(T);
+
+pub fn foo<T>(x: T) {
+ let y = S(x);
+ y.0;
+}
diff --git a/gcc/testsuite/rust/compile/nr2/exclude b/gcc/testsuite/rust/compile/nr2/exclude
index 4ba27d31f88..eaa2a1e0d0b 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -222,4 +222,5 @@ if_let_expr_simple.rs
iflet.rs
issue-3033.rs
issue-3009.rs
+issue-2323.rs
# please don't delete the trailing newline
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 019/146] gccrs: Use name resolver 2.0 in VisibilityResolver
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (17 preceding siblings ...)
2025-03-21 12:05 ` [COMMITTED 018/146] gccrs: fix bad type inference on local patterns arthur.cohen
@ 2025-03-21 12:05 ` arthur.cohen
2025-03-21 12:05 ` [COMMITTED 020/146] gccrs: Use name resolver 2.0 for module descendance checks arthur.cohen
` (126 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:05 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Owen Avery
From: Owen Avery <powerboat9.gamer@gmail.com>
gcc/rust/ChangeLog:
* checks/errors/privacy/rust-visibility-resolver.cc:
Add includes.
(VisibilityResolver::resolve_module_path): Use name resolver 2.0
(when enabled) to lookup path resolutions.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
---
.../privacy/rust-visibility-resolver.cc | 21 ++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/gcc/rust/checks/errors/privacy/rust-visibility-resolver.cc b/gcc/rust/checks/errors/privacy/rust-visibility-resolver.cc
index 464ce86e177..f0da7456076 100644
--- a/gcc/rust/checks/errors/privacy/rust-visibility-resolver.cc
+++ b/gcc/rust/checks/errors/privacy/rust-visibility-resolver.cc
@@ -20,6 +20,10 @@
#include "rust-ast.h"
#include "rust-hir.h"
#include "rust-hir-item.h"
+#include "rust-immutable-name-resolution-context.h"
+
+// for flag_name_resolution_2_0
+#include "options.h"
namespace Rust {
namespace Privacy {
@@ -61,7 +65,22 @@ VisibilityResolver::resolve_module_path (const HIR::SimplePath &restriction,
"cannot use non-module path as privacy restrictor");
NodeId ref_node_id = UNKNOWN_NODEID;
- if (!resolver.lookup_resolved_name (ast_node_id, &ref_node_id))
+ if (flag_name_resolution_2_0)
+ {
+ auto &nr_ctx
+ = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+
+ if (auto id = nr_ctx.lookup (ast_node_id))
+ {
+ ref_node_id = *id;
+ }
+ else
+ {
+ invalid_path.emit ();
+ return false;
+ }
+ }
+ else if (!resolver.lookup_resolved_name (ast_node_id, &ref_node_id))
{
invalid_path.emit ();
return false;
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 020/146] gccrs: Use name resolver 2.0 for module descendance checks
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (18 preceding siblings ...)
2025-03-21 12:05 ` [COMMITTED 019/146] gccrs: Use name resolver 2.0 in VisibilityResolver arthur.cohen
@ 2025-03-21 12:05 ` arthur.cohen
2025-03-21 12:05 ` [COMMITTED 021/146] gccrs: Reorganize the CPU feature detection arthur.cohen
` (125 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:05 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Owen Avery
From: Owen Avery <powerboat9.gamer@gmail.com>
gcc/rust/ChangeLog:
* checks/errors/privacy/rust-privacy-reporter.cc:
Include rust-immutable-name-resolution-context.h.
(is_child_module): Use ForeverStack::is_module_descendant if name
resolution 2.0 is enabled.
* resolve/rust-forever-stack.h
(ForeverStack::is_module_descendant): Add.
(ForeverStack::dfs_node): Add.
* resolve/rust-forever-stack.hxx
(ForeverStack::dfs_rib): Use ForeverStack::dfs_node.
(ForeverStack::dfs_node): Add.
(ForeverStack::is_module_descendant): Add.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
---
.../errors/privacy/rust-privacy-reporter.cc | 9 ++++
gcc/rust/resolve/rust-forever-stack.h | 10 +++++
gcc/rust/resolve/rust-forever-stack.hxx | 41 +++++++++++++++----
3 files changed, 53 insertions(+), 7 deletions(-)
diff --git a/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc b/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc
index 1ee2097b383..fa2de9c3f40 100644
--- a/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc
+++ b/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc
@@ -22,6 +22,7 @@
#include "rust-hir-stmt.h"
#include "rust-hir-item.h"
#include "rust-attribute-values.h"
+#include "rust-immutable-name-resolution-context.h"
namespace Rust {
namespace Privacy {
@@ -93,6 +94,14 @@ static bool
is_child_module (Analysis::Mappings &mappings, NodeId parent,
NodeId possible_child)
{
+ if (flag_name_resolution_2_0)
+ {
+ auto &nr_ctx
+ = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+
+ return nr_ctx.values.is_module_descendant (parent, possible_child);
+ }
+
auto children = mappings.lookup_module_children (parent);
if (!children)
diff --git a/gcc/rust/resolve/rust-forever-stack.h b/gcc/rust/resolve/rust-forever-stack.h
index 8c5e207a70d..28509259497 100644
--- a/gcc/rust/resolve/rust-forever-stack.h
+++ b/gcc/rust/resolve/rust-forever-stack.h
@@ -521,6 +521,12 @@ public:
std::string as_debug_string ();
+ /**
+ * Used to check if a module is a descendant of another module
+ * Intended for use in the privacy checker
+ */
+ bool is_module_descendant (NodeId parent, NodeId child) const;
+
private:
/**
* A link between two Nodes in our trie data structure. This class represents
@@ -635,6 +641,10 @@ private:
tl::optional<Rib &> dfs_rib (Node &starting_point, NodeId to_find);
tl::optional<const Rib &> dfs_rib (const Node &starting_point,
NodeId to_find) const;
+ // FIXME: Documentation
+ tl::optional<Node &> dfs_node (Node &starting_point, NodeId to_find);
+ tl::optional<const Node &> dfs_node (const Node &starting_point,
+ NodeId to_find) const;
};
} // namespace Resolver2_0
diff --git a/gcc/rust/resolve/rust-forever-stack.hxx b/gcc/rust/resolve/rust-forever-stack.hxx
index 5a5a7c73f32..31f8ba498b3 100644
--- a/gcc/rust/resolve/rust-forever-stack.hxx
+++ b/gcc/rust/resolve/rust-forever-stack.hxx
@@ -625,13 +625,33 @@ ForeverStack<N>::to_canonical_path (NodeId id) const
template <Namespace N>
tl::optional<Rib &>
ForeverStack<N>::dfs_rib (ForeverStack<N>::Node &starting_point, NodeId to_find)
+{
+ return dfs_node (starting_point, to_find).map ([] (Node &x) -> Rib & {
+ return x.rib;
+ });
+}
+
+template <Namespace N>
+tl::optional<const Rib &>
+ForeverStack<N>::dfs_rib (const ForeverStack<N>::Node &starting_point,
+ NodeId to_find) const
+{
+ return dfs_node (starting_point, to_find).map ([] (Node &x) -> Rib & {
+ return x.rib;
+ });
+}
+
+template <Namespace N>
+tl::optional<typename ForeverStack<N>::Node &>
+ForeverStack<N>::dfs_node (ForeverStack<N>::Node &starting_point,
+ NodeId to_find)
{
if (starting_point.id == to_find)
- return starting_point.rib;
+ return starting_point;
for (auto &child : starting_point.children)
{
- auto candidate = dfs_rib (child.second, to_find);
+ auto candidate = dfs_node (child.second, to_find);
if (candidate.has_value ())
return candidate;
@@ -641,16 +661,16 @@ ForeverStack<N>::dfs_rib (ForeverStack<N>::Node &starting_point, NodeId to_find)
}
template <Namespace N>
-tl::optional<const Rib &>
-ForeverStack<N>::dfs_rib (const ForeverStack<N>::Node &starting_point,
- NodeId to_find) const
+tl::optional<const typename ForeverStack<N>::Node &>
+ForeverStack<N>::dfs_node (const ForeverStack<N>::Node &starting_point,
+ NodeId to_find) const
{
if (starting_point.id == to_find)
- return starting_point.rib;
+ return starting_point;
for (auto &child : starting_point.children)
{
- auto candidate = dfs_rib (child.second, to_find);
+ auto candidate = dfs_node (child.second, to_find);
if (candidate.has_value ())
return candidate;
@@ -737,6 +757,13 @@ ForeverStack<N>::as_debug_string ()
return stream.str ();
}
+template <Namespace N>
+bool
+ForeverStack<N>::is_module_descendant (NodeId parent, NodeId child) const
+{
+ return dfs_node (dfs_node (root, parent).value (), child).has_value ();
+}
+
// FIXME: Can we add selftests?
} // namespace Resolver2_0
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 021/146] gccrs: Reorganize the CPU feature detection
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (19 preceding siblings ...)
2025-03-21 12:05 ` [COMMITTED 020/146] gccrs: Use name resolver 2.0 for module descendance checks arthur.cohen
@ 2025-03-21 12:05 ` arthur.cohen
2025-03-21 12:05 ` [COMMITTED 022/146] gccrs: fix ICE for placeholder which is not setup arthur.cohen
` (124 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:05 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Antoni Boucher
From: Antoni Boucher <bouanto@zoho.com>
Move the code from i386-rust.cc to i386-rust-and-jit.inc so that it can
be reused by libgccjit.
gcc/ChangeLog:
* config/i386/i386-rust-and-jit.inc: New file.
* config/i386/i386-rust.cc: Move code to i386-rust-and-jit.inc.
---
gcc/config/i386/i386-rust-and-jit.inc | 93 ++++++++++++++++++++++++++
gcc/config/i386/i386-rust.cc | 96 +--------------------------
2 files changed, 96 insertions(+), 93 deletions(-)
create mode 100644 gcc/config/i386/i386-rust-and-jit.inc
diff --git a/gcc/config/i386/i386-rust-and-jit.inc b/gcc/config/i386/i386-rust-and-jit.inc
new file mode 100644
index 00000000000..998f44cfa3f
--- /dev/null
+++ b/gcc/config/i386/i386-rust-and-jit.inc
@@ -0,0 +1,93 @@
+if (TARGET_64BIT)
+ ADD_TARGET_INFO ("target_arch", "x86_64");
+else
+ ADD_TARGET_INFO ("target_arch", "x86");
+
+// features officially "stabilised" in rustc
+if (TARGET_MMX)
+ ADD_TARGET_INFO ("target_feature", "mmx");
+if (TARGET_SSE)
+ ADD_TARGET_INFO ("target_feature", "sse");
+if (TARGET_SSE2)
+ ADD_TARGET_INFO ("target_feature", "sse2");
+if (TARGET_SSE3)
+ ADD_TARGET_INFO ("target_feature", "sse3");
+if (TARGET_SSSE3)
+ ADD_TARGET_INFO ("target_feature", "ssse3");
+if (TARGET_SSE4_1)
+ ADD_TARGET_INFO ("target_feature", "sse4.1");
+if (TARGET_SSE4_2)
+ ADD_TARGET_INFO ("target_feature", "sse4.2");
+if (TARGET_AES)
+ ADD_TARGET_INFO ("target_feature", "aes");
+if (TARGET_SHA)
+ ADD_TARGET_INFO ("target_feature", "sha");
+if (TARGET_AVX)
+ ADD_TARGET_INFO ("target_feature", "avx");
+if (TARGET_AVX2)
+ ADD_TARGET_INFO ("target_feature", "avx2");
+if (TARGET_AVX512F)
+ ADD_TARGET_INFO ("target_feature", "avx512f");
+if (TARGET_AVX512CD)
+ ADD_TARGET_INFO ("target_feature", "avx512cd");
+if (TARGET_AVX512DQ)
+ ADD_TARGET_INFO ("target_feature", "avx512dq");
+if (TARGET_AVX512BW)
+ ADD_TARGET_INFO ("target_feature", "avx512bw");
+if (TARGET_AVX512VL)
+ ADD_TARGET_INFO ("target_feature", "avx512vl");
+if (TARGET_AVX512VBMI)
+ ADD_TARGET_INFO ("target_feature", "avx512vbmi");
+if (TARGET_AVX512IFMA)
+ ADD_TARGET_INFO ("target_feature", "avx512ifma");
+if (TARGET_AVX512VPOPCNTDQ)
+ ADD_TARGET_INFO ("target_feature", "avx512vpopcntdq");
+if (TARGET_FMA)
+ ADD_TARGET_INFO ("target_feature", "fma");
+if (TARGET_RTM)
+ ADD_TARGET_INFO ("target_feature", "rtm");
+if (TARGET_SSE4A)
+ ADD_TARGET_INFO ("target_feature", "sse4a");
+if (TARGET_BMI)
+ {
+ ADD_TARGET_INFO ("target_feature", "bmi1");
+ ADD_TARGET_INFO ("target_feature", "bmi");
+ }
+if (TARGET_BMI2)
+ ADD_TARGET_INFO ("target_feature", "bmi2");
+if (TARGET_LZCNT)
+ ADD_TARGET_INFO ("target_feature", "lzcnt");
+if (TARGET_TBM)
+ ADD_TARGET_INFO ("target_feature", "tbm");
+if (TARGET_POPCNT)
+ ADD_TARGET_INFO ("target_feature", "popcnt");
+if (TARGET_RDRND)
+ {
+ ADD_TARGET_INFO ("target_feature", "rdrand");
+ ADD_TARGET_INFO ("target_feature", "rdrnd");
+ }
+if (TARGET_F16C)
+ ADD_TARGET_INFO ("target_feature", "f16c");
+if (TARGET_RDSEED)
+ ADD_TARGET_INFO ("target_feature", "rdseed");
+if (TARGET_ADX)
+ ADD_TARGET_INFO ("target_feature", "adx");
+if (TARGET_FXSR)
+ ADD_TARGET_INFO ("target_feature", "fxsr");
+if (TARGET_XSAVE)
+ ADD_TARGET_INFO ("target_feature", "xsave");
+if (TARGET_XSAVEOPT)
+ ADD_TARGET_INFO ("target_feature", "xsaveopt");
+if (TARGET_XSAVEC)
+ ADD_TARGET_INFO ("target_feature", "xsavec");
+if (TARGET_XSAVES)
+ ADD_TARGET_INFO ("target_feature", "xsaves");
+if (TARGET_VPCLMULQDQ)
+ {
+ ADD_TARGET_INFO ("target_feature", "pclmulqdq");
+ ADD_TARGET_INFO ("target_feature", "vpclmulqdq");
+ }
+if (TARGET_CMPXCHG16B)
+ ADD_TARGET_INFO ("target_feature", "cmpxchg16b");
+if (TARGET_MOVBE)
+ ADD_TARGET_INFO ("target_feature", "movbe");
diff --git a/gcc/config/i386/i386-rust.cc b/gcc/config/i386/i386-rust.cc
index b9099d3dfaf..de00076bff5 100644
--- a/gcc/config/i386/i386-rust.cc
+++ b/gcc/config/i386/i386-rust.cc
@@ -29,97 +29,7 @@ along with GCC; see the file COPYING3. If not see
void
ix86_rust_target_cpu_info (void)
{
- if (TARGET_64BIT)
- rust_add_target_info ("target_arch", "x86_64");
- else
- rust_add_target_info ("target_arch", "x86");
-
- // features officially "stabilised" in rustc
- if (TARGET_MMX)
- rust_add_target_info ("target_feature", "mmx");
- if (TARGET_SSE)
- rust_add_target_info ("target_feature", "sse");
- if (TARGET_SSE2)
- rust_add_target_info ("target_feature", "sse2");
- if (TARGET_SSE3)
- rust_add_target_info ("target_feature", "sse3");
- if (TARGET_SSSE3)
- rust_add_target_info ("target_feature", "ssse3");
- if (TARGET_SSE4_1)
- rust_add_target_info ("target_feature", "sse4.1");
- if (TARGET_SSE4_2)
- rust_add_target_info ("target_feature", "sse4.2");
- if (TARGET_AES)
- rust_add_target_info ("target_feature", "aes");
- if (TARGET_SHA)
- rust_add_target_info ("target_feature", "sha");
- if (TARGET_AVX)
- rust_add_target_info ("target_feature", "avx");
- if (TARGET_AVX2)
- rust_add_target_info ("target_feature", "avx2");
- if (TARGET_AVX512F)
- rust_add_target_info ("target_feature", "avx512f");
- if (TARGET_AVX512CD)
- rust_add_target_info ("target_feature", "avx512cd");
- if (TARGET_AVX512DQ)
- rust_add_target_info ("target_feature", "avx512dq");
- if (TARGET_AVX512BW)
- rust_add_target_info ("target_feature", "avx512bw");
- if (TARGET_AVX512VL)
- rust_add_target_info ("target_feature", "avx512vl");
- if (TARGET_AVX512VBMI)
- rust_add_target_info ("target_feature", "avx512vbmi");
- if (TARGET_AVX512IFMA)
- rust_add_target_info ("target_feature", "avx512ifma");
- if (TARGET_AVX512VPOPCNTDQ)
- rust_add_target_info ("target_feature", "avx512vpopcntdq");
- if (TARGET_FMA)
- rust_add_target_info ("target_feature", "fma");
- if (TARGET_RTM)
- rust_add_target_info ("target_feature", "rtm");
- if (TARGET_SSE4A)
- rust_add_target_info ("target_feature", "sse4a");
- if (TARGET_BMI)
- {
- rust_add_target_info ("target_feature", "bmi1");
- rust_add_target_info ("target_feature", "bmi");
- }
- if (TARGET_BMI2)
- rust_add_target_info ("target_feature", "bmi2");
- if (TARGET_LZCNT)
- rust_add_target_info ("target_feature", "lzcnt");
- if (TARGET_TBM)
- rust_add_target_info ("target_feature", "tbm");
- if (TARGET_POPCNT)
- rust_add_target_info ("target_feature", "popcnt");
- if (TARGET_RDRND)
- {
- rust_add_target_info ("target_feature", "rdrand");
- rust_add_target_info ("target_feature", "rdrnd");
- }
- if (TARGET_F16C)
- rust_add_target_info ("target_feature", "f16c");
- if (TARGET_RDSEED)
- rust_add_target_info ("target_feature", "rdseed");
- if (TARGET_ADX)
- rust_add_target_info ("target_feature", "adx");
- if (TARGET_FXSR)
- rust_add_target_info ("target_feature", "fxsr");
- if (TARGET_XSAVE)
- rust_add_target_info ("target_feature", "xsave");
- if (TARGET_XSAVEOPT)
- rust_add_target_info ("target_feature", "xsaveopt");
- if (TARGET_XSAVEC)
- rust_add_target_info ("target_feature", "xsavec");
- if (TARGET_XSAVES)
- rust_add_target_info ("target_feature", "xsaves");
- if (TARGET_VPCLMULQDQ)
- {
- rust_add_target_info ("target_feature", "pclmulqdq");
- rust_add_target_info ("target_feature", "vpclmulqdq");
- }
- if (TARGET_CMPXCHG16B)
- rust_add_target_info ("target_feature", "cmpxchg16b");
- if (TARGET_MOVBE)
- rust_add_target_info ("target_feature", "movbe");
+#define ADD_TARGET_INFO rust_add_target_info
+#include "i386-rust-and-jit.inc"
+#undef ADD_TARGET_INFO
}
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 022/146] gccrs: fix ICE for placeholder which is not setup
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (20 preceding siblings ...)
2025-03-21 12:05 ` [COMMITTED 021/146] gccrs: Reorganize the CPU feature detection arthur.cohen
@ 2025-03-21 12:05 ` arthur.cohen
2025-03-21 12:05 ` [COMMITTED 023/146] gccrs: fix typechecking of Fn trait calls using ADT types arthur.cohen
` (123 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:05 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Philip Herron
From: Philip Herron <herron.philip@googlemail.com>
We can have a case where the placeholder is not configred and the
can_resolve check is not detecting this case which can lead to ICE.
gcc/rust/ChangeLog:
* typecheck/rust-tyty.cc (PlaceholderType::can_resolve): check for empty mappings
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
---
gcc/rust/typecheck/rust-tyty.cc | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc
index 1812c618dcb..068e3902118 100644
--- a/gcc/rust/typecheck/rust-tyty.cc
+++ b/gcc/rust/typecheck/rust-tyty.cc
@@ -3543,7 +3543,17 @@ bool
PlaceholderType::can_resolve () const
{
auto context = Resolver::TypeCheckContext::get ();
- return context->lookup_associated_type_mapping (get_ty_ref (), nullptr);
+
+ BaseType *lookup = nullptr;
+ HirId mapping;
+
+ if (!context->lookup_associated_type_mapping (get_ty_ref (), &mapping))
+ return false;
+
+ if (!context->lookup_type (mapping, &lookup))
+ return false;
+
+ return lookup != nullptr;
}
BaseType *
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 023/146] gccrs: fix typechecking of Fn trait calls using ADT types
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (21 preceding siblings ...)
2025-03-21 12:05 ` [COMMITTED 022/146] gccrs: fix ICE for placeholder which is not setup arthur.cohen
@ 2025-03-21 12:05 ` arthur.cohen
2025-03-21 12:05 ` [COMMITTED 024/146] gccrs: Improve handling of implicit Self parameter in AST arthur.cohen
` (122 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:05 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Philip Herron
From: Philip Herron <herron.philip@googlemail.com>
Fixes RustGcc#2953
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): fix the ty_id
gcc/testsuite/ChangeLog:
* rust/compile/nr2/exclude: nr2 cant handle these
* rust/compile/issue-2953-1.rs: New test.
* rust/compile/issue-2953-2.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
---
.../typecheck/rust-hir-type-check-item.cc | 10 +++--
gcc/testsuite/rust/compile/issue-2953-1.rs | 27 ++++++++++++++
gcc/testsuite/rust/compile/issue-2953-2.rs | 37 +++++++++++++++++++
gcc/testsuite/rust/compile/nr2/exclude | 2 +
4 files changed, 72 insertions(+), 4 deletions(-)
create mode 100644 gcc/testsuite/rust/compile/issue-2953-1.rs
create mode 100644 gcc/testsuite/rust/compile/issue-2953-2.rs
diff --git a/gcc/rust/typecheck/rust-hir-type-check-item.cc b/gcc/rust/typecheck/rust-hir-type-check-item.cc
index 81e2f25f73d..28368d4730a 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-item.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-item.cc
@@ -231,7 +231,8 @@ TypeCheckItem::visit (HIR::TupleStruct &struct_decl)
= parse_repr_options (attrs, struct_decl.get_locus ());
auto *type = new TyTy::ADTType (
- struct_decl.get_mappings ().get_hirid (), mappings.get_next_hir_id (),
+ struct_decl.get_mappings ().get_hirid (),
+ struct_decl.get_mappings ().get_hirid (),
struct_decl.get_identifier ().as_string (), ident,
TyTy::ADTType::ADTKind::TUPLE_STRUCT, std::move (variants),
std::move (substitutions), repr,
@@ -312,7 +313,8 @@ TypeCheckItem::visit (HIR::StructStruct &struct_decl)
= parse_repr_options (attrs, struct_decl.get_locus ());
auto *type = new TyTy::ADTType (
- struct_decl.get_mappings ().get_hirid (), mappings.get_next_hir_id (),
+ struct_decl.get_mappings ().get_hirid (),
+ struct_decl.get_mappings ().get_hirid (),
struct_decl.get_identifier ().as_string (), ident,
TyTy::ADTType::ADTKind::STRUCT_STRUCT, std::move (variants),
std::move (substitutions), repr,
@@ -369,7 +371,7 @@ TypeCheckItem::visit (HIR::Enum &enum_decl)
// multi variant ADT
auto *type
= new TyTy::ADTType (enum_decl.get_mappings ().get_hirid (),
- mappings.get_next_hir_id (),
+ enum_decl.get_mappings ().get_hirid (),
enum_decl.get_identifier ().as_string (), ident,
TyTy::ADTType::ADTKind::ENUM, std::move (variants),
std::move (substitutions));
@@ -440,7 +442,7 @@ TypeCheckItem::visit (HIR::Union &union_decl)
auto *type
= new TyTy::ADTType (union_decl.get_mappings ().get_hirid (),
- mappings.get_next_hir_id (),
+ union_decl.get_mappings ().get_hirid (),
union_decl.get_identifier ().as_string (), ident,
TyTy::ADTType::ADTKind::UNION, std::move (variants),
std::move (substitutions));
diff --git a/gcc/testsuite/rust/compile/issue-2953-1.rs b/gcc/testsuite/rust/compile/issue-2953-1.rs
new file mode 100644
index 00000000000..d07059e440e
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-2953-1.rs
@@ -0,0 +1,27 @@
+#[lang = "sized"]
+pub trait Sized {
+ // Empty.
+}
+
+#[lang = "fn_once"]
+pub trait FnOnce<Args> {
+ /// The returned type after the call operator is used.
+ #[lang = "fn_once_output"]
+ type Output;
+
+ /// Performs the call operation.
+ extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
+}
+
+pub enum Ordering {
+ /// An ordering where a compared value is less than another.
+ Less = -1,
+ /// An ordering where a compared value is equal to another.
+ Equal = 0,
+ /// An ordering where a compared value is greater than another.
+ Greater = 1,
+}
+
+pub fn f<F: FnOnce(i32) -> Ordering>(g: F) -> Ordering {
+ g(1)
+}
diff --git a/gcc/testsuite/rust/compile/issue-2953-2.rs b/gcc/testsuite/rust/compile/issue-2953-2.rs
new file mode 100644
index 00000000000..59276246a1c
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-2953-2.rs
@@ -0,0 +1,37 @@
+#[lang = "sized"]
+pub trait Sized {
+ // Empty.
+}
+
+#[lang = "fn_once"]
+pub trait FnOnce<Args> {
+ /// The returned type after the call operator is used.
+ #[lang = "fn_once_output"]
+ type Output;
+
+ /// Performs the call operation.
+ extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
+}
+
+pub enum Ordering {
+ /// An ordering where a compared value is less than another.
+ Less = -1,
+ /// An ordering where a compared value is equal to another.
+ Equal = 0,
+ /// An ordering where a compared value is greater than another.
+ Greater = 1,
+}
+
+pub fn max_by<T, F: FnOnce(&T, &T) -> Ordering>(v1: T, v2: T, compare: F) -> T {
+ match compare(&v1, &v2) {
+ Ordering::Less | Ordering::Equal => v2,
+ Ordering::Greater => v1,
+ }
+}
+
+pub fn min_by<T, F: FnOnce(&T, &T) -> Ordering>(v1: T, v2: T, compare: F) -> T {
+ match compare(&v1, &v2) {
+ Ordering::Less | Ordering::Equal => v1,
+ Ordering::Greater => v2,
+ }
+}
diff --git a/gcc/testsuite/rust/compile/nr2/exclude b/gcc/testsuite/rust/compile/nr2/exclude
index eaa2a1e0d0b..92fa81517da 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -223,4 +223,6 @@ iflet.rs
issue-3033.rs
issue-3009.rs
issue-2323.rs
+issue-2953-1.rs
+issue-2953-2.rs
# please don't delete the trailing newline
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 024/146] gccrs: Improve handling of implicit Self parameter in AST
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (22 preceding siblings ...)
2025-03-21 12:05 ` [COMMITTED 023/146] gccrs: fix typechecking of Fn trait calls using ADT types arthur.cohen
@ 2025-03-21 12:05 ` arthur.cohen
2025-03-21 12:05 ` [COMMITTED 025/146] gccrs: add test case to show issue is fixed arthur.cohen
` (121 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:05 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Owen Avery
From: Owen Avery <powerboat9.gamer@gmail.com>
gcc/rust/ChangeLog:
* ast/rust-item.h
(Trait::self_param): Add.
(Trait::Trait): Initialize self_param.
(Trait::operator=): Copy self_param.
(Trait::insert_implicit_self): Remove.
(Trait::get_implicit_self): Add.
* hir/rust-ast-lower-item.cc
(ASTLoweringItem::visit): Make sure implicit self is still
lowered to HIR.
* resolve/rust-ast-resolve-item.cc
(ResolveItem::visit): Adjust handling of implicit self.
* resolve/rust-early-name-resolver.cc
(EarlyNameResolver::visit): Add commit to Trait visitor
mentioning that implicit self is not visited.
* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::visit): Remove call to Trait::insert_implicit_self.
gcc/testsuite/ChangeLog:
* rust/compile/nr2/exclude: Remove entries.
* rust/link/generic_function_0.rs: No longer expect failure.
* rust/link/trait_import_0.rs: Likewise.
* rust/link/trait_import_1.rs
(trait Sized): Add.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
---
gcc/rust/ast/rust-item.h | 23 ++++++-------------
gcc/rust/hir/rust-ast-lower-item.cc | 6 +++++
gcc/rust/resolve/rust-ast-resolve-item.cc | 12 +++-------
gcc/rust/resolve/rust-early-name-resolver.cc | 2 ++
.../rust-toplevel-name-resolver-2.0.cc | 17 --------------
gcc/testsuite/rust/compile/nr2/exclude | 9 --------
gcc/testsuite/rust/link/generic_function_0.rs | 3 ---
gcc/testsuite/rust/link/trait_import_0.rs | 3 ---
gcc/testsuite/rust/link/trait_import_1.rs | 3 +++
9 files changed, 21 insertions(+), 57 deletions(-)
diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h
index 2ae7c44398b..6611707a9a6 100644
--- a/gcc/rust/ast/rust-item.h
+++ b/gcc/rust/ast/rust-item.h
@@ -2831,6 +2831,7 @@ class Trait : public VisItem
bool has_auto;
Identifier name;
std::vector<std::unique_ptr<GenericParam>> generic_params;
+ TypeParam self_param;
std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds;
WhereClause where_clause;
std::vector<Attribute> inner_attrs;
@@ -2870,7 +2871,7 @@ public:
std::vector<Attribute> inner_attrs, location_t locus)
: VisItem (std::move (vis), std::move (outer_attrs)),
has_unsafe (is_unsafe), has_auto (is_auto), name (std::move (name)),
- generic_params (std::move (generic_params)),
+ generic_params (std::move (generic_params)), self_param ({"Self"}, locus),
type_param_bounds (std::move (type_param_bounds)),
where_clause (std::move (where_clause)),
inner_attrs (std::move (inner_attrs)),
@@ -2880,8 +2881,9 @@ public:
// Copy constructor with vector clone
Trait (Trait const &other)
: VisItem (other), has_unsafe (other.has_unsafe), has_auto (other.has_auto),
- name (other.name), where_clause (other.where_clause),
- inner_attrs (other.inner_attrs), locus (other.locus)
+ name (other.name), self_param (other.self_param),
+ where_clause (other.where_clause), inner_attrs (other.inner_attrs),
+ locus (other.locus)
{
generic_params.reserve (other.generic_params.size ());
for (const auto &e : other.generic_params)
@@ -2901,6 +2903,7 @@ public:
{
VisItem::operator= (other);
name = other.name;
+ self_param = other.self_param;
has_unsafe = other.has_unsafe;
has_auto = other.has_auto;
where_clause = other.where_clause;
@@ -2968,19 +2971,7 @@ public:
WhereClause &get_where_clause () { return where_clause; }
- void insert_implict_self (std::unique_ptr<AST::GenericParam> &¶m)
- {
- std::vector<std::unique_ptr<GenericParam>> new_list;
- new_list.reserve (generic_params.size () + 1);
-
- new_list.push_back (std::move (param));
- for (auto &p : generic_params)
- {
- new_list.push_back (std::move (p));
- }
-
- generic_params = std::move (new_list);
- }
+ AST::TypeParam &get_implicit_self () { return self_param; }
protected:
/* Use covariance to implement clone function as returning this object
diff --git a/gcc/rust/hir/rust-ast-lower-item.cc b/gcc/rust/hir/rust-ast-lower-item.cc
index 171737ab029..ae938d98658 100644
--- a/gcc/rust/hir/rust-ast-lower-item.cc
+++ b/gcc/rust/hir/rust-ast-lower-item.cc
@@ -572,6 +572,12 @@ ASTLoweringItem::visit (AST::Trait &trait)
generic_params = lower_generic_params (trait.get_generic_params ());
}
+ // TODO: separate "Self" from normal generic parameters
+ // in HIR as well as in AST?
+ HIR::GenericParam *self_param
+ = ASTLowerGenericParam::translate (trait.get_implicit_self ());
+ generic_params.emplace (generic_params.begin (), self_param);
+
std::vector<std::unique_ptr<HIR::TypeParamBound>> type_param_bounds;
if (trait.has_type_param_bounds ())
{
diff --git a/gcc/rust/resolve/rust-ast-resolve-item.cc b/gcc/rust/resolve/rust-ast-resolve-item.cc
index 34098bce0de..2861fb94d9f 100644
--- a/gcc/rust/resolve/rust-ast-resolve-item.cc
+++ b/gcc/rust/resolve/rust-ast-resolve-item.cc
@@ -755,20 +755,14 @@ ResolveItem::visit (AST::Trait &trait)
resolver->push_new_name_rib (resolver->get_name_scope ().peek ());
resolver->push_new_type_rib (resolver->get_type_scope ().peek ());
- // 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<AST::GenericParam> (implicit_self));
- CanonicalPath Self = CanonicalPath::get_big_self (trait.get_node_id ());
-
+ ResolveGenericParam::go (trait.get_implicit_self (), prefix,
+ canonical_prefix);
for (auto &generic : trait.get_generic_params ())
ResolveGenericParam::go (*generic, prefix, canonical_prefix);
// Self is an implicit TypeParam so lets mark it as such
resolver->get_type_scope ().append_reference_for_def (
- Self.get_node_id (), implicit_self->get_node_id ());
+ trait.get_node_id (), trait.get_implicit_self ().get_node_id ());
if (trait.has_type_param_bounds ())
{
diff --git a/gcc/rust/resolve/rust-early-name-resolver.cc b/gcc/rust/resolve/rust-early-name-resolver.cc
index ce427ddb2c8..a46b57f4448 100644
--- a/gcc/rust/resolve/rust-early-name-resolver.cc
+++ b/gcc/rust/resolve/rust-early-name-resolver.cc
@@ -353,6 +353,8 @@ EarlyNameResolver::visit (AST::TraitItemType &)
void
EarlyNameResolver::visit (AST::Trait &trait)
{
+ // shouldn't need to visit trait.get_implicit_self ()
+
for (auto &generic : trait.get_generic_params ())
generic->accept_vis (*this);
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 fff3769cd70..ef7a727dae9 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
@@ -103,23 +103,6 @@ TopLevel::visit (AST::Module &module)
void
TopLevel::visit (AST::Trait &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<AST::GenericParam> (implicit_self));
-
insert_or_error_out (trait.get_identifier ().as_string (), trait,
Namespace::Types);
diff --git a/gcc/testsuite/rust/compile/nr2/exclude b/gcc/testsuite/rust/compile/nr2/exclude
index 92fa81517da..6f8187264aa 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -1,9 +1,6 @@
attr-mismatch-crate-name.rs
attr_deprecated.rs
attr_deprecated_2.rs
-auto_trait_super_trait.rs
-auto_trait_valid.rs
-auto_trait_invalid.rs
bad=file-name.rs
bounds1.rs
break-rust2.rs
@@ -152,7 +149,6 @@ privacy1.rs
privacy3.rs
privacy4.rs
privacy5.rs
-privacy6.rs
privacy8.rs
macros/proc/attribute_non_function.rs
macros/proc/derive_non_function.rs
@@ -171,8 +167,6 @@ specify-crate-name.rs
stmt_with_block_dot.rs
struct-expr-parse.rs
traits1.rs
-traits10.rs
-traits11.rs
traits12.rs
traits2.rs
traits3.rs
@@ -181,7 +175,6 @@ traits5.rs
traits6.rs
traits7.rs
traits8.rs
-traits9.rs
type-bindings1.rs
unconstrained_type_param.rs
undeclared_label.rs
@@ -191,7 +184,6 @@ v0-mangle1.rs
v0-mangle2.rs
while_break_expr.rs
negative_impls.rs
-auto_trait.rs
exhaustiveness1.rs
exhaustiveness2.rs
exhaustiveness3.rs
@@ -199,7 +191,6 @@ trait13.rs
trait14.rs
issue-2324-1.rs
issue-2324-2.rs
-issue-2725.rs
issue-2987.rs
issue-3045-1.rs
issue-3045-2.rs
diff --git a/gcc/testsuite/rust/link/generic_function_0.rs b/gcc/testsuite/rust/link/generic_function_0.rs
index 179c822c7fc..58b8eb13db6 100644
--- a/gcc/testsuite/rust/link/generic_function_0.rs
+++ b/gcc/testsuite/rust/link/generic_function_0.rs
@@ -1,6 +1,3 @@
-// { dg-xfail-if "https://github.com/Rust-GCC/gccrs/issues/2349" { *-*-* } }
-// { dg-excess-errors "" { xfail *-*-* } }
-
extern crate generic_function_1;
use generic_function_1::generic_function;
diff --git a/gcc/testsuite/rust/link/trait_import_0.rs b/gcc/testsuite/rust/link/trait_import_0.rs
index 1b8c90a3574..ac8c5811d22 100644
--- a/gcc/testsuite/rust/link/trait_import_0.rs
+++ b/gcc/testsuite/rust/link/trait_import_0.rs
@@ -1,6 +1,3 @@
-// { dg-xfail-if "https://github.com/Rust-GCC/gccrs/issues/2349" { *-*-* } }
-// { dg-excess-errors "" { xfail *-*-* } }
-
extern crate trait_import_1;
use trait_import_1::Add;
diff --git a/gcc/testsuite/rust/link/trait_import_1.rs b/gcc/testsuite/rust/link/trait_import_1.rs
index fc7f5168ede..e54b0e19d44 100644
--- a/gcc/testsuite/rust/link/trait_import_1.rs
+++ b/gcc/testsuite/rust/link/trait_import_1.rs
@@ -1,3 +1,6 @@
+#[lang = "sized"]
+pub trait Sized {}
+
#[lang = "add"]
pub trait Add<Rhs = Self> {
type Output;
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 025/146] gccrs: add test case to show issue is fixed
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (23 preceding siblings ...)
2025-03-21 12:05 ` [COMMITTED 024/146] gccrs: Improve handling of implicit Self parameter in AST arthur.cohen
@ 2025-03-21 12:05 ` arthur.cohen
2025-03-21 12:05 ` [COMMITTED 026/146] gccrs: hir: Mark AttrVec::get_outer_attrs as override arthur.cohen
` (120 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:05 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Philip Herron
From: Philip Herron <herron.philip@googlemail.com>
The original test case 1773 has been moved to a new issue 3242 which
is still open and test-case is skipped. The original issue in 1773 is
fixed so this will close out that issue
Fixes Rust-Gcc#1773
gcc/testsuite/ChangeLog:
* rust/compile/issue-1773.rs: new test case
* rust/compile/nr2/exclude: nr2 cant handle this
* rust/compile/issue-3242.rs: old test ranamed to match issue.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
---
gcc/testsuite/rust/compile/issue-1773.rs | 23 +++++++++++++++--------
gcc/testsuite/rust/compile/issue-3242.rs | 24 ++++++++++++++++++++++++
gcc/testsuite/rust/compile/nr2/exclude | 1 +
3 files changed, 40 insertions(+), 8 deletions(-)
create mode 100644 gcc/testsuite/rust/compile/issue-3242.rs
diff --git a/gcc/testsuite/rust/compile/issue-1773.rs b/gcc/testsuite/rust/compile/issue-1773.rs
index 468497a4792..41c82f01b6d 100644
--- a/gcc/testsuite/rust/compile/issue-1773.rs
+++ b/gcc/testsuite/rust/compile/issue-1773.rs
@@ -1,8 +1,4 @@
-#[lang = "sized"]
-// { dg-skip-if "" { *-*-* } }
-pub trait Sized {}
-
-trait Foo<T> {
+trait Foo {
type A;
fn test(a: Self::A) -> Self::A {
@@ -10,9 +6,14 @@ trait Foo<T> {
}
}
-struct Bar<T>(T);
-impl<T> Foo<T> for Bar<i32> {
- type A = T;
+struct Bar(i32);
+impl Foo for Bar {
+ type A = i32;
+}
+
+struct Baz(f32);
+impl Foo for Baz {
+ type A = f32;
}
fn main() {
@@ -21,4 +22,10 @@ fn main() {
let b;
b = Bar::test(a.0);
+
+ let c;
+ c = Baz(123f32);
+
+ let d;
+ d = Baz::test(c.0);
}
diff --git a/gcc/testsuite/rust/compile/issue-3242.rs b/gcc/testsuite/rust/compile/issue-3242.rs
new file mode 100644
index 00000000000..468497a4792
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-3242.rs
@@ -0,0 +1,24 @@
+#[lang = "sized"]
+// { dg-skip-if "" { *-*-* } }
+pub trait Sized {}
+
+trait Foo<T> {
+ type A;
+
+ fn test(a: Self::A) -> Self::A {
+ a
+ }
+}
+
+struct Bar<T>(T);
+impl<T> Foo<T> for Bar<i32> {
+ type A = T;
+}
+
+fn main() {
+ let a;
+ a = Bar(123);
+
+ let b;
+ b = Bar::test(a.0);
+}
diff --git a/gcc/testsuite/rust/compile/nr2/exclude b/gcc/testsuite/rust/compile/nr2/exclude
index 6f8187264aa..efee0fd1e2d 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -216,4 +216,5 @@ issue-3009.rs
issue-2323.rs
issue-2953-1.rs
issue-2953-2.rs
+issue-1773.rs
# please don't delete the trailing newline
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 026/146] gccrs: hir: Mark AttrVec::get_outer_attrs as override
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (24 preceding siblings ...)
2025-03-21 12:05 ` [COMMITTED 025/146] gccrs: add test case to show issue is fixed arthur.cohen
@ 2025-03-21 12:05 ` arthur.cohen
2025-03-21 12:05 ` [COMMITTED 027/146] gccrs: typecheck: Remove unused parameter in TyTyCheckCallExpr arthur.cohen
` (119 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:05 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
gcc/rust/ChangeLog:
* hir/tree/rust-hir.h: Add override qualifier to overriden method.
---
gcc/rust/hir/tree/rust-hir.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/gcc/rust/hir/tree/rust-hir.h b/gcc/rust/hir/tree/rust-hir.h
index 8ce5cf4d102..8544d0d5f09 100644
--- a/gcc/rust/hir/tree/rust-hir.h
+++ b/gcc/rust/hir/tree/rust-hir.h
@@ -673,7 +673,7 @@ public:
// Returns whether the lifetime param has an outer attribute.
bool has_outer_attribute () const override { return outer_attrs.size () > 1; }
- AST::AttrVec &get_outer_attrs () { return outer_attrs; }
+ AST::AttrVec &get_outer_attrs () override { return outer_attrs; }
// Returns whether the lifetime param is in an error state.
bool is_error () const { return lifetime.is_error (); }
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 027/146] gccrs: typecheck: Remove unused parameter in TyTyCheckCallExpr
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (25 preceding siblings ...)
2025-03-21 12:05 ` [COMMITTED 026/146] gccrs: hir: Mark AttrVec::get_outer_attrs as override arthur.cohen
@ 2025-03-21 12:05 ` arthur.cohen
2025-03-21 12:05 ` [COMMITTED 028/146] gccrs: asm: Fix clang warnings arthur.cohen
` (118 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:05 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
gcc/rust/ChangeLog:
* typecheck/rust-tyty-call.h: Remove unused context member.
---
gcc/rust/typecheck/rust-tyty-call.h | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/gcc/rust/typecheck/rust-tyty-call.h b/gcc/rust/typecheck/rust-tyty-call.h
index 67cfe30057a..00ac655e5e4 100644
--- a/gcc/rust/typecheck/rust-tyty-call.h
+++ b/gcc/rust/typecheck/rust-tyty-call.h
@@ -73,14 +73,12 @@ private:
TypeCheckCallExpr (HIR::CallExpr &c, TyTy::VariantDef &variant,
Resolver::TypeCheckContext *context)
: resolved (new TyTy::ErrorType (c.get_mappings ().get_hirid ())), call (c),
- variant (variant), context (context),
- mappings (Analysis::Mappings::get ())
+ variant (variant), mappings (Analysis::Mappings::get ())
{}
BaseType *resolved;
HIR::CallExpr &call;
TyTy::VariantDef &variant;
- Resolver::TypeCheckContext *context;
Analysis::Mappings &mappings;
};
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 028/146] gccrs: asm: Fix clang warnings
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (26 preceding siblings ...)
2025-03-21 12:05 ` [COMMITTED 027/146] gccrs: typecheck: Remove unused parameter in TyTyCheckCallExpr arthur.cohen
@ 2025-03-21 12:05 ` arthur.cohen
2025-03-21 12:05 ` [COMMITTED 029/146] gccrs: Fix bad handling for recursive type query arthur.cohen
` (117 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:05 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
Fixes a couple of warnings thrown by clang, with mismatched class/struct
usages and unused members.
gcc/rust/ChangeLog:
* ast/rust-expr.h: Remove invalid usage of `struct`.
* backend/rust-compile-asm.h: Remove unused `translated` member.
* backend/rust-compile-asm.cc (CompileAsm::CompileAsm): Remove usage
of `translated` member.
* checks/errors/rust-unsafe-checker.h: Mark visitor as `override`.
* hir/tree/rust-hir-expr.h (struct AnonConst): Remove unused `locus`
member.
---
gcc/rust/ast/rust-expr.h | 24 ++++++++++----------
gcc/rust/backend/rust-compile-asm.cc | 5 ++--
gcc/rust/backend/rust-compile-asm.h | 2 --
gcc/rust/checks/errors/rust-unsafe-checker.h | 2 +-
gcc/rust/hir/tree/rust-hir-expr.h | 4 ++--
5 files changed, 17 insertions(+), 20 deletions(-)
diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h
index 438d3d3b86e..483e599652b 100644
--- a/gcc/rust/ast/rust-expr.h
+++ b/gcc/rust/ast/rust-expr.h
@@ -4810,14 +4810,14 @@ public:
rust_assert (this->expr != nullptr);
}
- In (const struct In &other)
+ In (const In &other)
{
reg = other.reg;
expr = other.expr->clone_expr ();
}
- In operator= (const struct In &other)
+ In operator= (const In &other)
{
reg = other.reg;
expr = other.expr->clone_expr ();
@@ -4843,14 +4843,14 @@ public:
rust_assert (this->expr != nullptr);
}
- Out (const struct Out &other)
+ Out (const Out &other)
{
reg = other.reg;
late = other.late;
expr = other.expr->clone_expr ();
}
- Out operator= (const struct Out &other)
+ Out operator= (const Out &other)
{
reg = other.reg;
late = other.late;
@@ -4876,14 +4876,14 @@ public:
rust_assert (this->expr != nullptr);
}
- InOut (const struct InOut &other)
+ InOut (const InOut &other)
{
reg = other.reg;
late = other.late;
expr = other.expr->clone_expr ();
}
- InOut operator= (const struct InOut &other)
+ InOut operator= (const InOut &other)
{
reg = other.reg;
late = other.late;
@@ -4913,7 +4913,7 @@ public:
rust_assert (this->out_expr != nullptr);
}
- SplitInOut (const struct SplitInOut &other)
+ SplitInOut (const SplitInOut &other)
{
reg = other.reg;
late = other.late;
@@ -4921,7 +4921,7 @@ public:
out_expr = other.out_expr->clone_expr ();
}
- SplitInOut operator= (const struct SplitInOut &other)
+ SplitInOut operator= (const SplitInOut &other)
{
reg = other.reg;
late = other.late;
@@ -4953,12 +4953,12 @@ public:
{
rust_assert (this->expr != nullptr);
}
- Sym (const struct Sym &other)
+ Sym (const Sym &other)
{
expr = std::unique_ptr<Expr> (other.expr->clone_expr ());
}
- Sym operator= (const struct Sym &other)
+ Sym operator= (const Sym &other)
{
expr = std::unique_ptr<Expr> (other.expr->clone_expr ());
return *this;
@@ -4981,12 +4981,12 @@ public:
if (label_name.has_value ())
this->label_name = label_name.value ();
}
- Label (const struct Label &other)
+ Label (const Label &other)
{
expr = std::unique_ptr<Expr> (other.expr->clone_expr ());
}
- Label operator= (const struct Label &other)
+ Label operator= (const Label &other)
{
expr = std::unique_ptr<Expr> (other.expr->clone_expr ());
return *this;
diff --git a/gcc/rust/backend/rust-compile-asm.cc b/gcc/rust/backend/rust-compile-asm.cc
index e85d08d0579..be553a3e70f 100644
--- a/gcc/rust/backend/rust-compile-asm.cc
+++ b/gcc/rust/backend/rust-compile-asm.cc
@@ -3,9 +3,8 @@
namespace Rust {
namespace Compile {
-CompileAsm::CompileAsm (Context *ctx)
- : HIRCompileBase (ctx), translated (error_mark_node)
-{}
+CompileAsm::CompileAsm (Context *ctx) : HIRCompileBase (ctx) {}
+
tree
CompileAsm::tree_codegen_asm (HIR::InlineAsm &expr)
{
diff --git a/gcc/rust/backend/rust-compile-asm.h b/gcc/rust/backend/rust-compile-asm.h
index 402d950844c..4abd24eded4 100644
--- a/gcc/rust/backend/rust-compile-asm.h
+++ b/gcc/rust/backend/rust-compile-asm.h
@@ -28,8 +28,6 @@ namespace Compile {
class CompileAsm : private HIRCompileBase
{
private:
- tree translated;
-
// RELEVANT MEMBER FUNCTIONS
// The limit is 5 because it stands for the 5 things that the C version of
diff --git a/gcc/rust/checks/errors/rust-unsafe-checker.h b/gcc/rust/checks/errors/rust-unsafe-checker.h
index 96ccdc03c53..8dc6ab79071 100644
--- a/gcc/rust/checks/errors/rust-unsafe-checker.h
+++ b/gcc/rust/checks/errors/rust-unsafe-checker.h
@@ -113,7 +113,7 @@ private:
virtual void visit (MatchExpr &expr) override;
virtual void visit (AwaitExpr &expr) override;
virtual void visit (AsyncBlockExpr &expr) override;
- virtual void visit (InlineAsm &expr);
+ virtual void visit (InlineAsm &expr) override;
virtual void visit (TypeParam ¶m) override;
virtual void visit (ConstGenericParam ¶m) override;
virtual void visit (LifetimeWhereClauseItem &item) override;
diff --git a/gcc/rust/hir/tree/rust-hir-expr.h b/gcc/rust/hir/tree/rust-hir-expr.h
index a79aea58386..0155e254688 100644
--- a/gcc/rust/hir/tree/rust-hir-expr.h
+++ b/gcc/rust/hir/tree/rust-hir-expr.h
@@ -3700,7 +3700,6 @@ struct AnonConst
return *this;
}
};
-;
class InlineAsmOperand
{
@@ -3888,7 +3887,6 @@ private:
tl::optional<struct Const> cnst;
tl::optional<struct Sym> sym;
tl::optional<struct Label> label;
- location_t locus;
public:
InlineAsmOperand (const InlineAsmOperand &other)
@@ -3931,6 +3929,7 @@ public:
struct Sym get_sym () const { return sym.value (); }
struct Label get_label () const { return label.value (); }
};
+
// Inline Assembly Node
class InlineAsm : public ExprWithoutBlock
{
@@ -4009,6 +4008,7 @@ public:
{}
};
+
} // namespace HIR
} // namespace Rust
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 029/146] gccrs: Fix bad handling for recursive type query
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (27 preceding siblings ...)
2025-03-21 12:05 ` [COMMITTED 028/146] gccrs: asm: Fix clang warnings arthur.cohen
@ 2025-03-21 12:05 ` arthur.cohen
2025-03-21 12:05 ` [COMMITTED 030/146] gccrs: Push ribs by kind rather than by value arthur.cohen
` (116 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:05 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Philip Herron
From: Philip Herron <herron.philip@googlemail.com>
When resolving a type like this which is generic it causes the argument
substitution to go through bounds checking which is expected. But this
can call a type bounds probe which again calls a type query which will be
on the Impl Type on an impl block which can result in a recursive type
query which does eventually get caught and errors correctly. But this then
triggers some old error diagnositcs which are not valid error codes but old
error messages we used to catch simple errors very early on which do not
apply for this senario.
Fixes Rust-GCC#2905
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::resolve_impl_block_substitutions):
dont check for unconstrained when the self is not resolved
* typecheck/rust-hir-type-check-type.cc (TypeCheckType::resolve_root_path):
remove bad debug error diagnostic
* typecheck/rust-tyty-subst.cc: likewise
gcc/testsuite/ChangeLog:
* rust/compile/nr2/exclude: nr2 cant handle this
* rust/compile/issue-2905-1.rs: New test.
* rust/compile/issue-2905-2.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
---
.../typecheck/rust-hir-type-check-item.cc | 8 ++
.../typecheck/rust-hir-type-check-type.cc | 7 +-
gcc/rust/typecheck/rust-tyty-subst.cc | 3 -
gcc/testsuite/rust/compile/issue-2905-1.rs | 27 ++++
gcc/testsuite/rust/compile/issue-2905-2.rs | 136 ++++++++++++++++++
gcc/testsuite/rust/compile/nr2/exclude | 2 +
6 files changed, 175 insertions(+), 8 deletions(-)
create mode 100644 gcc/testsuite/rust/compile/issue-2905-1.rs
create mode 100644 gcc/testsuite/rust/compile/issue-2905-2.rs
diff --git a/gcc/rust/typecheck/rust-hir-type-check-item.cc b/gcc/rust/typecheck/rust-hir-type-check-item.cc
index 28368d4730a..0652777c8c6 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-item.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-item.cc
@@ -724,6 +724,14 @@ TypeCheckItem::resolve_impl_block_substitutions (HIR::ImplBlock &impl_block,
}
TyTy::BaseType *self = TypeCheckType::Resolve (impl_block.get_type ().get ());
+ if (self->is<TyTy::ErrorType> ())
+ {
+ // we cannot check for unconstrained type arguments when the Self type is
+ // not resolved it will just add extra errors that dont help as well as
+ // the case where this could just be a recursive type query that should
+ // fail and will work later on anyway
+ return {substitutions, region_constraints};
+ }
// inherit the bounds
if (!specified_bound.is_error ())
diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.cc b/gcc/rust/typecheck/rust-hir-type-check-type.cc
index ee17e53eb30..0ff4ac45247 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-type.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-type.cc
@@ -426,11 +426,8 @@ TypeCheckType::resolve_root_path (HIR::TypePath &path, size_t *offset,
if (!query_type (ref, &lookup))
{
if (is_root)
- {
- rust_error_at (seg->get_locus (),
- "failed to resolve root segment");
- return new TyTy::ErrorType (path.get_mappings ().get_hirid ());
- }
+ return new TyTy::ErrorType (path.get_mappings ().get_hirid ());
+
return root_tyty;
}
diff --git a/gcc/rust/typecheck/rust-tyty-subst.cc b/gcc/rust/typecheck/rust-tyty-subst.cc
index a3ebf0aa8d5..575f04a3030 100644
--- a/gcc/rust/typecheck/rust-tyty-subst.cc
+++ b/gcc/rust/typecheck/rust-tyty-subst.cc
@@ -634,8 +634,6 @@ SubstitutionRef::get_mappings_from_generic_args (
if (resolved == nullptr
|| resolved->get_kind () == TyTy::TypeKind::ERROR)
{
- rust_error_at (binding.get_locus (),
- "failed to resolve type arguments");
return SubstitutionArgumentMappings::error ();
}
@@ -701,7 +699,6 @@ SubstitutionRef::get_mappings_from_generic_args (
BaseType *resolved = Resolver::TypeCheckType::Resolve (arg.get ());
if (resolved == nullptr || resolved->get_kind () == TyTy::TypeKind::ERROR)
{
- rust_error_at (args.get_locus (), "failed to resolve type arguments");
return SubstitutionArgumentMappings::error ();
}
diff --git a/gcc/testsuite/rust/compile/issue-2905-1.rs b/gcc/testsuite/rust/compile/issue-2905-1.rs
new file mode 100644
index 00000000000..9b0c19da9bb
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-2905-1.rs
@@ -0,0 +1,27 @@
+#![feature(lang_items)]
+
+#[lang = "sized"]
+trait Sized {}
+
+pub struct A<T>(T);
+
+pub trait B {
+ type C;
+}
+
+// ------
+// swap these two items
+
+impl B for i32 {
+ type C = Weird<i32>;
+}
+
+pub struct Weird<T>(A<(T,)>);
+
+// ------
+
+trait Foo {}
+
+impl Foo for Weird<i32> {}
+
+fn main() {}
diff --git a/gcc/testsuite/rust/compile/issue-2905-2.rs b/gcc/testsuite/rust/compile/issue-2905-2.rs
new file mode 100644
index 00000000000..83c54ed92e5
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-2905-2.rs
@@ -0,0 +1,136 @@
+// { dg-options "-w" }
+#![feature(intrinsics)]
+#![feature(lang_items)]
+
+#[lang = "sized"]
+trait Sized {}
+
+extern "rust-intrinsic" {
+ fn transmute<T, U>(_: T) -> U;
+ fn offset<T>(src: *const T, offset: isize) -> *const T;
+}
+
+pub mod core {
+ pub mod marker {
+ #[lang = "phantom_data"]
+ pub struct PhantomData<T>;
+ }
+
+ pub mod slice {
+ use core::marker::PhantomData;
+ use core::option::Option;
+
+ impl<T> core::iter::IntoIterator for &[T] {
+ type Item = &T;
+ type IntoIter = Weird<T>;
+
+ fn into_iter(self) -> Weird<T> {
+ self.iter()
+ }
+ }
+
+ pub struct Weird<T> {
+ ptr: *const T, // should be NonNull<T> but here it does not matter
+ end: *const T,
+ _marker: PhantomData<&T>,
+ }
+
+ impl<T> Weird<T> {
+ pub(super) fn new(slice: &[T]) -> Self {
+ let ptr = slice.as_ptr();
+ // SAFETY: Similar to `IterMut::new`.
+ unsafe {
+ // should be: ptr.add(slice.len())
+ let end = transmute::<*const T, usize>(ptr) + slice.len(); // TODO(Arthur): Missing `* size_of::<T>()`?
+ let end = transmute::<usize, *const T>(end);
+
+ Self {
+ ptr,
+ end,
+ _marker: PhantomData,
+ }
+ }
+ }
+
+ fn is_empty(&self) -> bool {
+ self.ptr == self.end
+ }
+
+ fn next_unchecked(&mut self) -> *const T {
+ let old = self.ptr;
+
+ self.ptr = unsafe { offset(self.ptr, 1) };
+
+ old
+ }
+ }
+
+ trait Foo {}
+
+ impl<T> Foo for Weird<T> {}
+
+ // impl<T> core::iter::Iterator for Iter<T> {
+ // type Item = &T;
+
+ // fn next(&mut self) -> Option<&T> {
+ // if self.is_empty() {
+ // Option::None
+ // } else {
+ // Option::Some(&*self.next_unchecked())
+ // }
+ // }
+ // }
+
+ union Repr<T> {
+ pub(crate) rust: *const [T],
+ rust_mut: *mut [T],
+ pub(crate) raw: FatPtr<T>,
+ }
+
+ struct FatPtr<T> {
+ data: *const T,
+ pub(crate) len: usize,
+ }
+
+ impl<T> [T] {
+ pub fn iter(&self) -> Weird<T> {
+ Weird::new(self)
+ }
+
+ pub fn as_ptr(&self) -> *const T {
+ self as *const [T] as *const T
+ }
+
+ pub fn len(&self) -> usize {
+ unsafe { Repr { rust: self }.raw.len }
+ }
+ }
+ }
+
+ pub mod iter {
+ use option::Option;
+
+ pub trait IntoIterator {
+ type Item;
+
+ type IntoIter: Iterator<Item = Self::Item>;
+
+ fn into_iter(self) -> Self::IntoIter;
+ }
+
+ pub trait Iterator {
+ type Item;
+
+ fn next(&mut self) -> Option<Self::Item>;
+ }
+ }
+
+ pub mod option {
+ pub enum Option<T> {
+ Some(T),
+ None,
+ }
+ }
+}
+
+fn main() {}
diff --git a/gcc/testsuite/rust/compile/nr2/exclude b/gcc/testsuite/rust/compile/nr2/exclude
index efee0fd1e2d..a73b1f027b1 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -217,4 +217,6 @@ issue-2323.rs
issue-2953-1.rs
issue-2953-2.rs
issue-1773.rs
+issue-2905-1.rs
+issue-2905-2.rs
# please don't delete the trailing newline
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 030/146] gccrs: Push ribs by kind rather than by value
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (28 preceding siblings ...)
2025-03-21 12:05 ` [COMMITTED 029/146] gccrs: Fix bad handling for recursive type query arthur.cohen
@ 2025-03-21 12:05 ` arthur.cohen
2025-03-21 12:05 ` [COMMITTED 031/146] gccrs: Improve handling of static items in toplevel 2.0 arthur.cohen
` (115 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:05 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Owen Avery
From: Owen Avery <powerboat9.gamer@gmail.com>
gcc/rust/ChangeLog:
* resolve/rust-forever-stack.h
(ForeverStack::push): Accept argument of type Rib::Kind rather
than Rib.
* resolve/rust-forever-stack.hxx
(ForeverStack::push): Likewise.
* resolve/rust-name-resolution-context.cc
(NameResolutionContext::scoped): Likewise.
* resolve/rust-name-resolution-context.h
(NameResolutionContext::scoped): Likewise.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
---
gcc/rust/resolve/rust-forever-stack.h | 2 +-
gcc/rust/resolve/rust-forever-stack.hxx | 5 +++--
gcc/rust/resolve/rust-name-resolution-context.cc | 15 ++++++++-------
gcc/rust/resolve/rust-name-resolution-context.h | 9 +++++----
4 files changed, 17 insertions(+), 14 deletions(-)
diff --git a/gcc/rust/resolve/rust-forever-stack.h b/gcc/rust/resolve/rust-forever-stack.h
index 28509259497..c548eeae087 100644
--- a/gcc/rust/resolve/rust-forever-stack.h
+++ b/gcc/rust/resolve/rust-forever-stack.h
@@ -416,7 +416,7 @@ public:
* @param path An optional path if the Rib was created due to a "named"
* lexical scope, like a module's.
*/
- void push (Rib rib, NodeId id, tl::optional<Identifier> path = {});
+ void push (Rib::Kind rib_kind, NodeId id, tl::optional<Identifier> path = {});
/**
* Pop the innermost Rib from the stack
diff --git a/gcc/rust/resolve/rust-forever-stack.hxx b/gcc/rust/resolve/rust-forever-stack.hxx
index 31f8ba498b3..58164a4d328 100644
--- a/gcc/rust/resolve/rust-forever-stack.hxx
+++ b/gcc/rust/resolve/rust-forever-stack.hxx
@@ -52,9 +52,10 @@ ForeverStack<N>::Node::insert_child (Link link, Node child)
template <Namespace N>
void
-ForeverStack<N>::push (Rib rib, NodeId id, tl::optional<Identifier> path)
+ForeverStack<N>::push (Rib::Kind rib_kind, NodeId id,
+ tl::optional<Identifier> path)
{
- push_inner (rib, Link (id, path));
+ push_inner (rib_kind, Link (id, path));
}
template <Namespace N>
diff --git a/gcc/rust/resolve/rust-name-resolution-context.cc b/gcc/rust/resolve/rust-name-resolution-context.cc
index 9bfaa094abe..1b375213878 100644
--- a/gcc/rust/resolve/rust-name-resolution-context.cc
+++ b/gcc/rust/resolve/rust-name-resolution-context.cc
@@ -103,13 +103,13 @@ NameResolutionContext::lookup (NodeId usage) const
}
void
-NameResolutionContext::scoped (Rib rib, NodeId id,
+NameResolutionContext::scoped (Rib::Kind rib_kind, NodeId id,
std::function<void (void)> lambda,
tl::optional<Identifier> path)
{
- values.push (rib, id, path);
- types.push (rib, id, path);
- macros.push (rib, id, path);
+ values.push (rib_kind, id, path);
+ types.push (rib_kind, id, path);
+ macros.push (rib_kind, id, path);
// labels.push (rib, id);
lambda ();
@@ -121,17 +121,18 @@ NameResolutionContext::scoped (Rib rib, NodeId id,
}
void
-NameResolutionContext::scoped (Rib rib, Namespace ns, NodeId scope_id,
+NameResolutionContext::scoped (Rib::Kind rib_kind, Namespace ns,
+ NodeId scope_id,
std::function<void (void)> lambda,
tl::optional<Identifier> path)
{
switch (ns)
{
case Namespace::Values:
- values.push (rib, scope_id, path);
+ values.push (rib_kind, scope_id, path);
break;
case Namespace::Types:
- types.push (rib, scope_id, path);
+ types.push (rib_kind, scope_id, path);
break;
case Namespace::Labels:
case Namespace::Macros:
diff --git a/gcc/rust/resolve/rust-name-resolution-context.h b/gcc/rust/resolve/rust-name-resolution-context.h
index cd6fa931be5..183ce7f3c2e 100644
--- a/gcc/rust/resolve/rust-name-resolution-context.h
+++ b/gcc/rust/resolve/rust-name-resolution-context.h
@@ -185,8 +185,8 @@ public:
* function. This variant of the function enters a new scope in *all*
* namespaces, while the second variant enters a scope in *one* namespace.
*
- * @param rib New `Rib` to create when entering this scope. A function `Rib`,
- * or an item `Rib`... etc
+ * @param rib_kind New `Rib` to create when entering this scope. A function
+ * `Rib`, or an item `Rib`... etc
* @param scope_id node ID of the scope we are entering, e.g the block's
* `NodeId`.
* @param lambda Function to run within that scope
@@ -196,9 +196,10 @@ public:
*/
// FIXME: Do we want to handle something in particular for expected within the
// scoped lambda?
- void scoped (Rib rib, NodeId scope_id, std::function<void (void)> lambda,
+ void scoped (Rib::Kind rib_kind, NodeId scope_id,
+ std::function<void (void)> lambda,
tl::optional<Identifier> path = {});
- void scoped (Rib rib, Namespace ns, NodeId scope_id,
+ void scoped (Rib::Kind rib_kind, Namespace ns, NodeId scope_id,
std::function<void (void)> lambda,
tl::optional<Identifier> path = {});
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 031/146] gccrs: Improve handling of static items in toplevel 2.0
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (29 preceding siblings ...)
2025-03-21 12:05 ` [COMMITTED 030/146] gccrs: Push ribs by kind rather than by value arthur.cohen
@ 2025-03-21 12:05 ` arthur.cohen
2025-03-21 12:05 ` [COMMITTED 032/146] gccrs: Refactor HIR to reduce the amount of raw pointers arthur.cohen
` (114 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:05 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Owen Avery
From: Owen Avery <powerboat9.gamer@gmail.com>
gcc/rust/ChangeLog:
* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::visit): Use DefaultResolver::visit and avoid a call
to Identifier::as_string while handling instances of StaticItem.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
---
gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc | 9 +++------
1 file changed, 3 insertions(+), 6 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 ef7a727dae9..a2f695e54f6 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
@@ -241,13 +241,10 @@ TopLevel::visit (AST::BlockExpr &expr)
void
TopLevel::visit (AST::StaticItem &static_item)
{
- auto sub_vis
- = [this, &static_item] () { static_item.get_expr ().accept_vis (*this); };
-
- ctx.scoped (Rib::Kind::Item, static_item.get_node_id (), sub_vis);
-
- insert_or_error_out (static_item.get_identifier ().as_string (), static_item,
+ insert_or_error_out (static_item.get_identifier (), static_item,
Namespace::Values);
+
+ DefaultResolver::visit (static_item);
}
void
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 032/146] gccrs: Refactor HIR to reduce the amount of raw pointers
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (30 preceding siblings ...)
2025-03-21 12:05 ` [COMMITTED 031/146] gccrs: Improve handling of static items in toplevel 2.0 arthur.cohen
@ 2025-03-21 12:05 ` arthur.cohen
2025-03-21 12:05 ` [COMMITTED 033/146] gccrs: Refactor HIR with optionals, references & newtypes arthur.cohen
` (113 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:05 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Pierre-Emmanuel Patry
From: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Attempt to use references and smart pointers whenever possible.
gcc/rust/ChangeLog:
* backend/rust-compile-base.cc (HIRCompileBase::compile_function_body):
Remove usage of get function to retrieve a raw pointer.
* backend/rust-compile-base.h:
Change API usage from raw pointer to a reference.
* backend/rust-compile-block.cc (CompileBlock::compile): Likewise.
(CompileBlock::visit): Likewise.
(CompileConditionalBlocks::visit): Likewise.
* backend/rust-compile-block.h: Likewise.
* backend/rust-compile-expr.cc (CompileExpr::Compile): Likewise.
(CompileExpr::visit): Likewise.
(check_match_scrutinee): Likewise.
(CompileExpr::array_value_expr): Likewise.
(CompileExpr::array_copied_expr): Likewise.
(CompileExpr::generate_closure_function): Likewise.
(CompileExpr::generate_possible_fn_trait_call): Likewise.
* backend/rust-compile-expr.h: Likewise.
* backend/rust-compile-fnparam.cc (CompileFnParam::compile): Likewise.
(CompileFnParam::visit): Likewise.
* backend/rust-compile-fnparam.h: Likewise.
* backend/rust-compile-implitem.cc (CompileTraitItem::visit): Likewise.
* backend/rust-compile-intrinsic.cc (compile_fn_params): Likewise.
* backend/rust-compile-item.cc (CompileItem::visit): Likewise.
* backend/rust-compile-pattern.cc (CompilePatternCheckExpr::visit):
Likewise.
(compile_range_pattern_bound): Likewise.
(CompilePatternBindings::visit): Likewise.
(CompilePatternLet::visit): Likewise.
* backend/rust-compile-pattern.h: Likewise.
* backend/rust-compile-resolve-path.cc (ResolvePathRef::resolve):
Likewise.
(HIRCompileBase::query_compile): Likewise.
* backend/rust-compile-stmt.cc (CompileStmt::visit): Likewise.
* backend/rust-compile-struct-field-expr.cc (CompileStructExprField::Compile):
Likewise.
(CompileStructExprField::visit): Likewise.
* backend/rust-compile-struct-field-expr.h: Likewise.
* backend/rust-compile-type.cc (TyTyResolveCompile::visit): Likewise.
* backend/rust-compile-var-decl.h: Likewise.
* backend/rust-compile.cc: Likewise.
* backend/rust-mangle-v0.cc (v0_inherent_or_trait_impl_path): Likewise.
* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::visit):
Likewise.
* checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h: Likewise.
* checks/errors/borrowck/rust-bir-builder-pattern.h: Likewise.
* checks/errors/borrowck/rust-bir-builder-struct.h: Likewise.
* checks/errors/borrowck/rust-bir-builder.h: Likewise.
* checks/errors/borrowck/rust-function-collector.h: Likewise.
* checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::check_type_privacy):
Likewise.
(PrivacyReporter::visit): Likewise.
* checks/errors/privacy/rust-privacy-reporter.h: Likewise.
* checks/errors/privacy/rust-reachability.cc (ReachabilityVisitor::visit):
Likewise.
* checks/errors/rust-const-checker.cc (ConstChecker::visit): Likewise.
* checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit):
Likewise.
* checks/lints/rust-lint-marklive.cc (MarkLive::visit): Likewise.
* checks/lints/rust-lint-marklive.h: Likewise.
* hir/rust-hir-dump.cc (Dump::visit): Likewise.
* hir/tree/rust-hir-expr.h: Likewise.
* hir/tree/rust-hir-item.h: Likewise.
* hir/tree/rust-hir-path.h: Likewise.
* hir/tree/rust-hir-pattern.h: Likewise.
* hir/tree/rust-hir-stmt.h: Likewise.
* hir/tree/rust-hir-type.h: Likewise.
* hir/tree/rust-hir.h: Likewise.
* typecheck/rust-autoderef.cc: Likewise.
* typecheck/rust-hir-dot-operator.cc (MethodResolver::select):
Likewise.
* typecheck/rust-hir-inherent-impl-overlap.h: Likewise.
* typecheck/rust-hir-path-probe.cc (PathProbeType::process_impl_item_candidate):
Likewise.
(PathProbeImplTrait::process_trait_impl_items_for_candidates): Likewise.
* typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_trait):
Likewise.
(TraitItemReference::resolve_item): Likewise.
* typecheck/rust-hir-type-check-base.cc: Likewise.
* typecheck/rust-hir-type-check-base.h: Likewise.
* typecheck/rust-hir-type-check-enumitem.cc (TypeCheckEnumItem::Resolve):
Likewise.
(TypeCheckEnumItem::visit): Likewise.
* typecheck/rust-hir-type-check-enumitem.h: Likewise.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::Resolve):
Likewise.
(TypeCheckExpr::visit): Likewise.
(TypeCheckExpr::resolve_fn_trait_call): Likewise.
* typecheck/rust-hir-type-check-expr.h: Likewise.
* typecheck/rust-hir-type-check-implitem.cc (TypeCheckTopLevelExternItem::Resolve):
Likewise.
(TypeCheckTopLevelExternItem::visit): Likewise.
(TypeCheckImplItem::visit): Likewise.
(TypeCheckImplItemWithTrait::visit): Likewise.
* typecheck/rust-hir-type-check-implitem.h: Likewise.
* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): Likewise.
(TypeCheckItem::resolve_impl_item): Likewise.
(TypeCheckItem::resolve_impl_block_substitutions): Likewise.
(TypeCheckItem::resolve_impl_block_self): Likewise.
* typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::visit): Likewise.
(TypeCheckExpr::resolve_segments): Likewise.
* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::Resolve):
Likewise.
(TypeCheckPattern::visit): Likewise.
(ClosureParamInfer::Resolve): Likewise.
(ClosureParamInfer::visit): Likewise.
* typecheck/rust-hir-type-check-pattern.h: Likewise.
* typecheck/rust-hir-type-check-stmt.cc (TypeCheckStmt::Resolve):
Likewise.
(TypeCheckStmt::visit): Likewise.
* typecheck/rust-hir-type-check-stmt.h: Likewise.
* typecheck/rust-hir-type-check-struct-field.h: Likewise.
* typecheck/rust-hir-type-check-struct.cc (TypeCheckStructExpr::TypeCheckStructExpr):
Likewise.
(TypeCheckStructExpr::Resolve): Likewise.
(TypeCheckStructExpr::resolve): Likewise.
(TypeCheckStructExpr::visit): Likewise.
* typecheck/rust-hir-type-check-type.cc (TypeCheckResolveGenericArguments::resolve):
Likewise.
(TypeCheckType::Resolve): Likewise.
(TypeCheckType::visit): Likewise.
(TypeCheckType::resolve_root_path): Likewise.
(TypeResolveGenericParam::Resolve): Likewise.
(TypeResolveGenericParam::visit): Likewise.
(ResolveWhereClauseItem::visit): Likewise.
* typecheck/rust-hir-type-check-type.h: Likewise.
* typecheck/rust-hir-type-check.cc (TraitItemReference::get_type_from_fn):
Likewise.
* typecheck/rust-hir-type-check.h: Likewise.
* typecheck/rust-type-util.cc (query_type): Likewise.
* typecheck/rust-typecheck-context.cc (TypeCheckContextItem::TypeCheckContextItem):
Likewise.
* typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::scan): Likewise.
(TypeCheckBase::get_predicate_from_bound): Likewise.
* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Likewise.
(TypeCheckMethodCallExpr::go): Likewise.
(TypeCheckMethodCallExpr::check): Likewise.
* typecheck/rust-tyty-subst.cc: Likewise.
* typecheck/rust-tyty.cc (BaseType::monomorphized_clone): Likewise.
(VariantDef::VariantDef): Remove copy constructor.
(VariantDef::operator=): Change to move operator.
(VariantDef::get_discriminant): Replace return type to a reference
instead of a reference to a unique pointer.
(VariantDef::clone): Change to references.
(VariantDef::monomorphized_clone): Likewise.
(FnType::as_string): Likewise.
(FnType::clone): Likewise.
* typecheck/rust-tyty.h: Likewise.
* util/rust-hir-map.cc (Mappings::insert_hir_impl_block): Likewise.
* backend/rust-compile-asm.cc: Use a reference instead of the raw
pointer value.
* checks/errors/borrowck/rust-bir-builder-pattern.cc: Use references.
* checks/errors/rust-hir-pattern-analysis.cc: Likewise.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
---
gcc/rust/backend/rust-compile-asm.cc | 4 +-
gcc/rust/backend/rust-compile-base.cc | 35 +--
gcc/rust/backend/rust-compile-base.h | 2 +-
gcc/rust/backend/rust-compile-block.cc | 27 +-
gcc/rust/backend/rust-compile-block.h | 4 +-
gcc/rust/backend/rust-compile-expr.cc | 208 +++++++------
gcc/rust/backend/rust-compile-expr.h | 6 +-
gcc/rust/backend/rust-compile-fnparam.cc | 14 +-
gcc/rust/backend/rust-compile-fnparam.h | 4 +-
gcc/rust/backend/rust-compile-implitem.cc | 4 +-
gcc/rust/backend/rust-compile-intrinsic.cc | 2 +-
gcc/rust/backend/rust-compile-item.cc | 9 +-
gcc/rust/backend/rust-compile-pattern.cc | 77 +++--
gcc/rust/backend/rust-compile-pattern.h | 8 +-
gcc/rust/backend/rust-compile-resolve-path.cc | 4 +-
gcc/rust/backend/rust-compile-stmt.cc | 12 +-
.../backend/rust-compile-struct-field-expr.cc | 16 +-
.../backend/rust-compile-struct-field-expr.h | 2 +-
gcc/rust/backend/rust-compile-type.cc | 2 +-
gcc/rust/backend/rust-compile-var-decl.h | 4 +-
gcc/rust/backend/rust-compile.cc | 10 +-
gcc/rust/backend/rust-mangle-v0.cc | 4 +-
.../borrowck/rust-bir-builder-expr-stmt.cc | 119 ++++----
.../borrowck/rust-bir-builder-lazyboolexpr.h | 8 +-
.../borrowck/rust-bir-builder-pattern.cc | 20 +-
.../borrowck/rust-bir-builder-pattern.h | 1 +
.../errors/borrowck/rust-bir-builder-struct.h | 4 +-
.../checks/errors/borrowck/rust-bir-builder.h | 16 +-
.../errors/borrowck/rust-function-collector.h | 4 +-
.../errors/privacy/rust-privacy-reporter.cc | 130 ++++----
.../errors/privacy/rust-privacy-reporter.h | 2 +-
.../errors/privacy/rust-reachability.cc | 2 +-
gcc/rust/checks/errors/rust-const-checker.cc | 122 ++++----
.../errors/rust-hir-pattern-analysis.cc | 203 ++++++-------
gcc/rust/checks/errors/rust-unsafe-checker.cc | 118 ++++----
gcc/rust/checks/lints/rust-lint-marklive.cc | 16 +-
gcc/rust/checks/lints/rust-lint-marklive.h | 72 ++---
gcc/rust/hir/rust-hir-dump.cc | 34 +--
gcc/rust/hir/tree/rust-hir-expr.h | 117 ++++----
gcc/rust/hir/tree/rust-hir-item.h | 59 ++--
gcc/rust/hir/tree/rust-hir-path.h | 21 +-
gcc/rust/hir/tree/rust-hir-pattern.h | 18 +-
gcc/rust/hir/tree/rust-hir-stmt.h | 8 +-
gcc/rust/hir/tree/rust-hir-type.h | 18 +-
gcc/rust/hir/tree/rust-hir.h | 7 +-
gcc/rust/typecheck/rust-autoderef.cc | 2 +-
gcc/rust/typecheck/rust-hir-dot-operator.cc | 179 ++++++-----
.../rust-hir-inherent-impl-overlap.h | 2 +-
gcc/rust/typecheck/rust-hir-path-probe.cc | 5 +-
gcc/rust/typecheck/rust-hir-trait-resolve.cc | 9 +-
.../typecheck/rust-hir-type-check-base.cc | 30 +-
gcc/rust/typecheck/rust-hir-type-check-base.h | 10 +-
.../typecheck/rust-hir-type-check-enumitem.cc | 58 ++--
.../typecheck/rust-hir-type-check-enumitem.h | 2 +-
.../typecheck/rust-hir-type-check-expr.cc | 281 +++++++++---------
gcc/rust/typecheck/rust-hir-type-check-expr.h | 2 +-
.../typecheck/rust-hir-type-check-implitem.cc | 103 +++----
.../typecheck/rust-hir-type-check-implitem.h | 14 +-
.../typecheck/rust-hir-type-check-item.cc | 79 +++--
.../typecheck/rust-hir-type-check-path.cc | 12 +-
.../typecheck/rust-hir-type-check-pattern.cc | 73 +++--
.../typecheck/rust-hir-type-check-pattern.h | 11 +-
.../typecheck/rust-hir-type-check-stmt.cc | 39 ++-
gcc/rust/typecheck/rust-hir-type-check-stmt.h | 2 +-
.../rust-hir-type-check-struct-field.h | 4 +-
.../typecheck/rust-hir-type-check-struct.cc | 22 +-
.../typecheck/rust-hir-type-check-type.cc | 137 ++++-----
gcc/rust/typecheck/rust-hir-type-check-type.h | 6 +-
gcc/rust/typecheck/rust-hir-type-check.cc | 43 +--
gcc/rust/typecheck/rust-hir-type-check.h | 2 +-
gcc/rust/typecheck/rust-type-util.cc | 5 +-
gcc/rust/typecheck/rust-typecheck-context.cc | 4 +-
gcc/rust/typecheck/rust-tyty-bounds.cc | 31 +-
gcc/rust/typecheck/rust-tyty-call.cc | 19 +-
gcc/rust/typecheck/rust-tyty-subst.cc | 4 +-
gcc/rust/typecheck/rust-tyty.cc | 51 ++--
gcc/rust/typecheck/rust-tyty.h | 23 +-
gcc/rust/util/rust-hir-map.cc | 2 +-
78 files changed, 1382 insertions(+), 1461 deletions(-)
diff --git a/gcc/rust/backend/rust-compile-asm.cc b/gcc/rust/backend/rust-compile-asm.cc
index be553a3e70f..22498bc4ea0 100644
--- a/gcc/rust/backend/rust-compile-asm.cc
+++ b/gcc/rust/backend/rust-compile-asm.cc
@@ -85,7 +85,7 @@ CompileAsm::asm_construct_outputs (HIR::InlineAsm &expr)
{
auto out = output.get_out ();
- tree out_tree = CompileExpr::Compile (out.expr.get (), this->ctx);
+ tree out_tree = CompileExpr::Compile (*out.expr, this->ctx);
// expects a tree list
// TODO: This assumes that the output is a register
std::string expr_name = "=r";
@@ -112,7 +112,7 @@ CompileAsm::asm_construct_inputs (HIR::InlineAsm &expr)
{
auto in = input.get_in ();
- tree in_tree = CompileExpr::Compile (in.expr.get (), this->ctx);
+ tree in_tree = CompileExpr::Compile (*in.expr, this->ctx);
// expects a tree list
// TODO: This assumes that the input is a register
std::string expr_name = "r";
diff --git a/gcc/rust/backend/rust-compile-base.cc b/gcc/rust/backend/rust-compile-base.cc
index 8166c3ae224..598f2e2e451 100644
--- a/gcc/rust/backend/rust-compile-base.cc
+++ b/gcc/rust/backend/rust-compile-base.cc
@@ -582,8 +582,9 @@ HIRCompileBase::compile_function_body (tree fndecl,
if (function_body.has_expr ())
{
- location_t locus = function_body.get_final_expr ()->get_locus ();
- tree return_value = CompileExpr::Compile (function_body.expr.get (), ctx);
+ location_t locus = function_body.get_final_expr ().get_locus ();
+ tree return_value
+ = CompileExpr::Compile (function_body.get_final_expr (), ctx);
// we can only return this if non unit value return type
if (!fn_return_ty->is_unit ())
@@ -709,18 +710,18 @@ HIRCompileBase::compile_function (
size_t i = is_method ? 1 : 0;
for (auto &referenced_param : function_params)
{
- auto tyty_param = fntype->param_at (i++);
+ auto &tyty_param = fntype->param_at (i++);
auto param_tyty = tyty_param.second;
auto compiled_param_type = TyTyResolveCompile::compile (ctx, param_tyty);
location_t param_locus = referenced_param.get_locus ();
Bvariable *compiled_param_var
- = CompileFnParam::compile (ctx, fndecl, &referenced_param,
+ = CompileFnParam::compile (ctx, fndecl, referenced_param,
compiled_param_type, param_locus);
param_vars.push_back (compiled_param_var);
- const HIR::Pattern ¶m_pattern = *referenced_param.get_param_name ();
+ const HIR::Pattern ¶m_pattern = referenced_param.get_param_name ();
ctx->insert_var_decl (param_pattern.get_mappings ().get_hirid (),
compiled_param_var);
}
@@ -768,14 +769,14 @@ HIRCompileBase::compile_function (
tree
HIRCompileBase::compile_constant_item (
TyTy::BaseType *resolved_type, const Resolver::CanonicalPath &canonical_path,
- HIR::Expr *const_value_expr, location_t locus)
+ HIR::Expr &const_value_expr, location_t locus)
{
const std::string &ident = canonical_path.get ();
tree type = TyTyResolveCompile::compile (ctx, resolved_type);
tree const_type = build_qualified_type (type, TYPE_QUAL_CONST);
bool is_block_expr
- = const_value_expr->get_expression_type () == HIR::Expr::ExprType::Block;
+ = const_value_expr.get_expression_type () == HIR::Expr::ExprType::Block;
// in order to compile a block expr we want to reuse as much existing
// machineary that we already have. This means the best approach is to
@@ -789,14 +790,14 @@ HIRCompileBase::compile_constant_item (
TREE_READONLY (fndecl) = 1;
tree enclosing_scope = NULL_TREE;
- location_t start_location = const_value_expr->get_locus ();
- location_t end_location = const_value_expr->get_locus ();
+ location_t start_location = const_value_expr.get_locus ();
+ location_t end_location = const_value_expr.get_locus ();
if (is_block_expr)
{
- HIR::BlockExpr *function_body
- = static_cast<HIR::BlockExpr *> (const_value_expr);
- start_location = function_body->get_locus ();
- end_location = function_body->get_end_locus ();
+ HIR::BlockExpr &function_body
+ = static_cast<HIR::BlockExpr &> (const_value_expr);
+ start_location = function_body.get_locus ();
+ end_location = function_body.get_end_locus ();
}
tree code_block = Backend::block (fndecl, enclosing_scope, {} /*locals*/,
@@ -814,9 +815,9 @@ HIRCompileBase::compile_constant_item (
if (is_block_expr)
{
- HIR::BlockExpr *function_body
- = static_cast<HIR::BlockExpr *> (const_value_expr);
- compile_function_body (fndecl, *function_body, resolved_type);
+ HIR::BlockExpr &function_body
+ = static_cast<HIR::BlockExpr &> (const_value_expr);
+ compile_function_body (fndecl, function_body, resolved_type);
}
else
{
@@ -824,7 +825,7 @@ HIRCompileBase::compile_constant_item (
tree return_expr
= Backend::return_statement (fndecl, value,
- const_value_expr->get_locus ());
+ const_value_expr.get_locus ());
ctx->add_statement (return_expr);
}
diff --git a/gcc/rust/backend/rust-compile-base.h b/gcc/rust/backend/rust-compile-base.h
index eeb3ff02619..5fb1d83f2ee 100644
--- a/gcc/rust/backend/rust-compile-base.h
+++ b/gcc/rust/backend/rust-compile-base.h
@@ -92,7 +92,7 @@ protected:
tree compile_constant_item (TyTy::BaseType *resolved_type,
const Resolver::CanonicalPath &canonical_path,
- HIR::Expr *const_value_expr, location_t locus);
+ HIR::Expr &const_value_expr, location_t locus);
tree compile_function (const std::string &fn_name, HIR::SelfParam &self_param,
std::vector<HIR::FunctionParam> &function_params,
diff --git a/gcc/rust/backend/rust-compile-block.cc b/gcc/rust/backend/rust-compile-block.cc
index eb8af2a0d3b..f844a27e989 100644
--- a/gcc/rust/backend/rust-compile-block.cc
+++ b/gcc/rust/backend/rust-compile-block.cc
@@ -28,10 +28,10 @@ CompileBlock::CompileBlock (Context *ctx, Bvariable *result)
{}
tree
-CompileBlock::compile (HIR::BlockExpr *expr, Context *ctx, Bvariable *result)
+CompileBlock::compile (HIR::BlockExpr &expr, Context *ctx, Bvariable *result)
{
CompileBlock compiler (ctx, result);
- compiler.visit (*expr);
+ compiler.visit (expr);
return compiler.translated;
}
@@ -60,10 +60,10 @@ CompileBlock::visit (HIR::BlockExpr &expr)
if (expr.has_expr ())
{
- tree compiled_expr = CompileExpr::Compile (expr.expr.get (), ctx);
+ tree compiled_expr = CompileExpr::Compile (expr.get_final_expr (), ctx);
if (result != nullptr)
{
- location_t locus = expr.get_final_expr ()->get_locus ();
+ location_t locus = expr.get_final_expr ().get_locus ();
tree result_reference = Backend::var_expression (result, locus);
tree assignment
@@ -93,10 +93,8 @@ CompileConditionalBlocks::visit (HIR::IfExpr &expr)
{
fncontext fnctx = ctx->peek_fn ();
tree fndecl = fnctx.fndecl;
- tree condition_expr
- = CompileExpr::Compile (expr.get_if_condition ().get (), ctx);
- tree then_block
- = CompileBlock::compile (expr.get_if_block ().get (), ctx, result);
+ tree condition_expr = CompileExpr::Compile (expr.get_if_condition (), ctx);
+ tree then_block = CompileBlock::compile (expr.get_if_block (), ctx, result);
translated = Backend::if_statement (fndecl, condition_expr, then_block, NULL,
expr.get_locus ());
@@ -107,23 +105,20 @@ CompileConditionalBlocks::visit (HIR::IfExprConseqElse &expr)
{
fncontext fnctx = ctx->peek_fn ();
tree fndecl = fnctx.fndecl;
- tree condition_expr
- = CompileExpr::Compile (expr.get_if_condition ().get (), ctx);
- tree then_block
- = CompileBlock::compile (expr.get_if_block ().get (), ctx, result);
+ tree condition_expr = CompileExpr::Compile (expr.get_if_condition (), ctx);
+ tree then_block = CompileBlock::compile (expr.get_if_block (), ctx, result);
// else block
std::vector<Bvariable *> locals;
- location_t start_location = expr.get_else_block ()->get_locus ();
- location_t end_location = expr.get_else_block ()->get_locus (); // FIXME
+ location_t start_location = expr.get_else_block ().get_locus ();
+ location_t end_location = expr.get_else_block ().get_locus (); // FIXME
tree enclosing_scope = ctx->peek_enclosing_scope ();
tree else_block = Backend::block (fndecl, enclosing_scope, locals,
start_location, end_location);
ctx->push_block (else_block);
tree else_stmt_decl
- = CompileExprWithBlock::compile (expr.get_else_block ().get (), ctx,
- result);
+ = CompileExprWithBlock::compile (&expr.get_else_block (), ctx, result);
ctx->add_statement (else_stmt_decl);
diff --git a/gcc/rust/backend/rust-compile-block.h b/gcc/rust/backend/rust-compile-block.h
index 6616882894f..37e3980bd6c 100644
--- a/gcc/rust/backend/rust-compile-block.h
+++ b/gcc/rust/backend/rust-compile-block.h
@@ -28,7 +28,7 @@ namespace Compile {
class CompileBlock : private HIRCompileBase
{
public:
- static tree compile (HIR::BlockExpr *expr, Context *ctx, Bvariable *result);
+ static tree compile (HIR::BlockExpr &expr, Context *ctx, Bvariable *result);
protected:
void visit (HIR::BlockExpr &expr);
@@ -134,7 +134,7 @@ public:
void visit (HIR::BlockExpr &expr) override
{
- translated = CompileBlock::compile (&expr, ctx, result);
+ translated = CompileBlock::compile (expr, ctx, result);
}
// Empty visit for unused Expression HIR nodes.
diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc
index 7251cc82d6e..c46bda954ad 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -40,24 +40,24 @@ CompileExpr::CompileExpr (Context *ctx)
{}
tree
-CompileExpr::Compile (HIR::Expr *expr, Context *ctx)
+CompileExpr::Compile (HIR::Expr &expr, Context *ctx)
{
CompileExpr compiler (ctx);
- expr->accept_vis (compiler);
+ expr.accept_vis (compiler);
return compiler.translated;
}
void
CompileExpr::visit (HIR::TupleIndexExpr &expr)
{
- HIR::Expr *tuple_expr = expr.get_tuple_expr ().get ();
+ HIR::Expr &tuple_expr = expr.get_tuple_expr ();
TupleIndex index = expr.get_tuple_index ();
tree receiver_ref = CompileExpr::Compile (tuple_expr, ctx);
TyTy::BaseType *tuple_expr_ty = nullptr;
bool ok
- = ctx->get_tyctx ()->lookup_type (tuple_expr->get_mappings ().get_hirid (),
+ = ctx->get_tyctx ()->lookup_type (tuple_expr.get_mappings ().get_hirid (),
&tuple_expr_ty);
rust_assert (ok);
@@ -97,7 +97,7 @@ CompileExpr::visit (HIR::TupleExpr &expr)
std::vector<tree> vals;
for (auto &elem : expr.get_tuple_elems ())
{
- auto e = CompileExpr::Compile (elem.get (), ctx);
+ auto e = CompileExpr::Compile (*elem, ctx);
vals.push_back (e);
}
@@ -111,7 +111,7 @@ CompileExpr::visit (HIR::ReturnExpr &expr)
auto fncontext = ctx->peek_fn ();
tree return_value = expr.has_return_expr ()
- ? CompileExpr::Compile (expr.return_expr.get (), ctx)
+ ? CompileExpr::Compile (expr.get_expr (), ctx)
: unit_expression (expr.get_locus ());
if (expr.has_return_expr ())
@@ -141,8 +141,8 @@ void
CompileExpr::visit (HIR::ArithmeticOrLogicalExpr &expr)
{
auto op = expr.get_expr_type ();
- auto lhs = CompileExpr::Compile (expr.get_lhs ().get (), ctx);
- auto rhs = CompileExpr::Compile (expr.get_rhs ().get (), ctx);
+ auto lhs = CompileExpr::Compile (expr.get_lhs (), ctx);
+ auto rhs = CompileExpr::Compile (expr.get_rhs (), ctx);
// this might be an operator overload situation lets check
TyTy::FnType *fntype;
@@ -153,8 +153,7 @@ CompileExpr::visit (HIR::ArithmeticOrLogicalExpr &expr)
auto lang_item_type
= LangItem::OperatorToLangItem (expr.get_expr_type ());
translated = resolve_operator_overload (lang_item_type, expr, lhs, rhs,
- expr.get_lhs ().get (),
- expr.get_rhs ().get ());
+ expr.get_lhs (), expr.get_rhs ());
return;
}
@@ -185,8 +184,8 @@ void
CompileExpr::visit (HIR::CompoundAssignmentExpr &expr)
{
auto op = expr.get_expr_type ();
- auto lhs = CompileExpr::Compile (expr.get_lhs ().get (), ctx);
- auto rhs = CompileExpr::Compile (expr.get_rhs ().get (), ctx);
+ auto lhs = CompileExpr::Compile (expr.get_lhs (), ctx);
+ auto rhs = CompileExpr::Compile (expr.get_rhs (), ctx);
// this might be an operator overload situation lets check
TyTy::FnType *fntype;
@@ -198,8 +197,7 @@ CompileExpr::visit (HIR::CompoundAssignmentExpr &expr)
expr.get_expr_type ());
auto compound_assignment
= resolve_operator_overload (lang_item_type, expr, lhs, rhs,
- expr.get_lhs ().get (),
- expr.get_rhs ().get ());
+ expr.get_lhs (), expr.get_rhs ());
ctx->add_statement (compound_assignment);
return;
@@ -236,18 +234,18 @@ CompileExpr::visit (HIR::NegationExpr &expr)
{
auto op = expr.get_expr_type ();
- const auto literal_expr = expr.get_expr ().get ();
+ auto &literal_expr = expr.get_expr ();
// If it's a negated integer/float literal, we can return early
if (op == NegationOperator::NEGATE
- && literal_expr->get_expression_type () == HIR::Expr::ExprType::Lit)
+ && literal_expr.get_expression_type () == HIR::Expr::ExprType::Lit)
{
- auto new_literal_expr = static_cast<HIR::LiteralExpr *> (literal_expr);
- auto lit_type = new_literal_expr->get_lit_type ();
+ auto &new_literal_expr = static_cast<HIR::LiteralExpr &> (literal_expr);
+ auto lit_type = new_literal_expr.get_lit_type ();
if (lit_type == HIR::Literal::LitType::INT
|| lit_type == HIR::Literal::LitType::FLOAT)
{
- new_literal_expr->set_negative ();
+ new_literal_expr.set_negative ();
translated = CompileExpr::Compile (literal_expr, ctx);
return;
}
@@ -265,7 +263,7 @@ CompileExpr::visit (HIR::NegationExpr &expr)
auto lang_item_type = LangItem::NegationOperatorToLangItem (op);
translated
= resolve_operator_overload (lang_item_type, expr, negated_expr,
- nullptr, expr.get_expr ().get (), nullptr);
+ nullptr, expr.get_expr (), tl::nullopt);
return;
}
@@ -276,8 +274,8 @@ void
CompileExpr::visit (HIR::ComparisonExpr &expr)
{
auto op = expr.get_expr_type ();
- auto lhs = CompileExpr::Compile (expr.get_lhs ().get (), ctx);
- auto rhs = CompileExpr::Compile (expr.get_rhs ().get (), ctx);
+ auto lhs = CompileExpr::Compile (expr.get_lhs (), ctx);
+ auto rhs = CompileExpr::Compile (expr.get_rhs (), ctx);
auto location = expr.get_locus ();
translated = Backend::comparison_expression (op, lhs, rhs, location);
@@ -287,8 +285,8 @@ void
CompileExpr::visit (HIR::LazyBooleanExpr &expr)
{
auto op = expr.get_expr_type ();
- auto lhs = CompileExpr::Compile (expr.get_lhs ().get (), ctx);
- auto rhs = CompileExpr::Compile (expr.get_rhs ().get (), ctx);
+ auto lhs = CompileExpr::Compile (expr.get_lhs (), ctx);
+ auto rhs = CompileExpr::Compile (expr.get_rhs (), ctx);
auto location = expr.get_locus ();
translated = Backend::lazy_boolean_expression (op, lhs, rhs, location);
@@ -307,14 +305,14 @@ CompileExpr::visit (HIR::TypeCastExpr &expr)
TyTy::BaseType *casted_tyty = nullptr;
if (!ctx->get_tyctx ()->lookup_type (
- expr.get_casted_expr ()->get_mappings ().get_hirid (), &casted_tyty))
+ expr.get_casted_expr ().get_mappings ().get_hirid (), &casted_tyty))
{
translated = error_mark_node;
return;
}
auto type_to_cast_to = TyTyResolveCompile::compile (ctx, type_to_cast_to_ty);
- auto casted_expr = CompileExpr::Compile (expr.get_casted_expr ().get (), ctx);
+ auto casted_expr = CompileExpr::Compile (expr.get_casted_expr (), ctx);
std::vector<Resolver::Adjustment> *adjustments = nullptr;
bool ok = ctx->get_tyctx ()->lookup_cast_autoderef_mappings (
@@ -405,7 +403,7 @@ CompileExpr::visit (HIR::BlockExpr &expr)
&ret_var_stmt);
ctx->add_statement (ret_var_stmt);
- auto block_stmt = CompileBlock::compile (&expr, ctx, tmp);
+ auto block_stmt = CompileBlock::compile (expr, ctx, tmp);
rust_assert (TREE_CODE (block_stmt) == BIND_EXPR);
ctx->add_statement (block_stmt);
@@ -415,7 +413,7 @@ CompileExpr::visit (HIR::BlockExpr &expr)
void
CompileExpr::visit (HIR::UnsafeBlockExpr &expr)
{
- expr.get_block_expr ()->accept_vis (*this);
+ expr.get_block_expr ().accept_vis (*this);
}
void
@@ -487,7 +485,7 @@ CompileExpr::visit (HIR::StructExprStructFields &struct_expr)
auto lvalue_locus
= ctx->get_mappings ().lookup_location (expected->get_ty_ref ());
auto rvalue_locus = argument->get_locus ();
- auto rvalue = CompileStructExprField::Compile (argument.get (), ctx);
+ auto rvalue = CompileStructExprField::Compile (*argument, ctx);
TyTy::BaseType *actual = nullptr;
bool ok = ctx->get_tyctx ()->lookup_type (
@@ -519,7 +517,7 @@ CompileExpr::visit (HIR::StructExprStructFields &struct_expr)
auto lvalue_locus
= ctx->get_mappings ().lookup_location (expected->get_ty_ref ());
auto rvalue_locus = argument->get_locus ();
- auto rvalue = CompileStructExprField::Compile (argument.get (), ctx);
+ auto rvalue = CompileStructExprField::Compile (*argument, ctx);
TyTy::BaseType *actual = nullptr;
bool ok = ctx->get_tyctx ()->lookup_type (
@@ -544,7 +542,7 @@ CompileExpr::visit (HIR::StructExprStructFields &struct_expr)
std::vector<tree> ctor_arguments;
if (adt->is_enum ())
{
- HIR::Expr *discrim_expr = variant->get_discriminant ();
+ 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;
@@ -563,21 +561,21 @@ CompileExpr::visit (HIR::StructExprStructFields &struct_expr)
void
CompileExpr::visit (HIR::GroupedExpr &expr)
{
- translated = CompileExpr::Compile (expr.get_expr_in_parens ().get (), ctx);
+ translated = CompileExpr::Compile (expr.get_expr_in_parens (), ctx);
}
void
CompileExpr::visit (HIR::FieldAccessExpr &expr)
{
- HIR::Expr *receiver_expr = expr.get_receiver_expr ().get ();
+ HIR::Expr &receiver_expr = expr.get_receiver_expr ();
tree receiver_ref = CompileExpr::Compile (receiver_expr, ctx);
// resolve the receiver back to ADT type
TyTy::BaseType *receiver = nullptr;
if (!ctx->get_tyctx ()->lookup_type (
- expr.get_receiver_expr ()->get_mappings ().get_hirid (), &receiver))
+ expr.get_receiver_expr ().get_mappings ().get_hirid (), &receiver))
{
- rust_error_at (expr.get_receiver_expr ()->get_locus (),
+ rust_error_at (expr.get_receiver_expr ().get_locus (),
"unresolved type for receiver");
return;
}
@@ -672,7 +670,7 @@ CompileExpr::visit (HIR::LoopExpr &expr)
ctx->push_loop_begin_label (loop_begin_label);
tree code_block
- = CompileBlock::compile (expr.get_loop_block ().get (), ctx, nullptr);
+ = CompileBlock::compile (expr.get_loop_block (), ctx, nullptr);
tree loop_expr = Backend::loop_expression (code_block, expr.get_locus ());
ctx->add_statement (loop_expr);
@@ -699,8 +697,8 @@ CompileExpr::visit (HIR::WhileLoopExpr &expr)
}
std::vector<Bvariable *> locals;
- location_t start_location = expr.get_loop_block ()->get_locus ();
- location_t end_location = expr.get_loop_block ()->get_locus (); // FIXME
+ location_t start_location = expr.get_loop_block ().get_locus ();
+ location_t end_location = expr.get_loop_block ().get_locus (); // FIXME
tree enclosing_scope = ctx->peek_enclosing_scope ();
tree loop_block = Backend::block (fnctx.fndecl, enclosing_scope, locals,
@@ -713,15 +711,14 @@ CompileExpr::visit (HIR::WhileLoopExpr &expr)
ctx->add_statement (loop_begin_label_decl);
ctx->push_loop_begin_label (loop_begin_label);
- tree condition
- = CompileExpr::Compile (expr.get_predicate_expr ().get (), ctx);
+ tree condition = CompileExpr::Compile (expr.get_predicate_expr (), ctx);
tree exit_condition = fold_build1_loc (expr.get_locus (), TRUTH_NOT_EXPR,
boolean_type_node, condition);
tree exit_expr = Backend::exit_expression (exit_condition, expr.get_locus ());
ctx->add_statement (exit_expr);
tree code_block_stmt
- = CompileBlock::compile (expr.get_loop_block ().get (), ctx, nullptr);
+ = CompileBlock::compile (expr.get_loop_block (), ctx, nullptr);
rust_assert (TREE_CODE (code_block_stmt) == BIND_EXPR);
ctx->add_statement (code_block_stmt);
@@ -737,12 +734,12 @@ CompileExpr::visit (HIR::BreakExpr &expr)
{
if (expr.has_break_expr ())
{
- tree compiled_expr = CompileExpr::Compile (expr.get_expr ().get (), ctx);
+ tree compiled_expr = CompileExpr::Compile (expr.get_expr (), ctx);
Bvariable *loop_result_holder = ctx->peek_loop_context ();
tree result_reference
= Backend::var_expression (loop_result_holder,
- expr.get_expr ()->get_locus ());
+ expr.get_expr ().get_locus ());
tree assignment
= Backend::assignment_statement (result_reference, compiled_expr,
@@ -865,7 +862,7 @@ CompileExpr::visit (HIR::ContinueExpr &expr)
void
CompileExpr::visit (HIR::BorrowExpr &expr)
{
- tree main_expr = CompileExpr::Compile (expr.get_expr ().get (), ctx);
+ tree main_expr = CompileExpr::Compile (expr.get_expr (), ctx);
if (RS_DST_FLAG_P (TREE_TYPE (main_expr)))
{
translated = main_expr;
@@ -892,7 +889,7 @@ CompileExpr::visit (HIR::DereferenceExpr &expr)
return;
}
- tree main_expr = CompileExpr::Compile (expr.get_expr ().get (), ctx);
+ tree main_expr = CompileExpr::Compile (expr.get_expr (), ctx);
// this might be an operator overload situation lets check
TyTy::FnType *fntype;
@@ -903,7 +900,7 @@ CompileExpr::visit (HIR::DereferenceExpr &expr)
auto lang_item_type = LangItem::Kind::DEREF;
tree operator_overload_call
= resolve_operator_overload (lang_item_type, expr, main_expr, nullptr,
- expr.get_expr ().get (), nullptr);
+ expr.get_expr (), tl::nullopt);
// rust deref always returns a reference from this overload then we can
// actually do the indirection
@@ -963,8 +960,8 @@ CompileExpr::visit (HIR::LiteralExpr &expr)
void
CompileExpr::visit (HIR::AssignmentExpr &expr)
{
- auto lvalue = CompileExpr::Compile (expr.get_lhs ().get (), ctx);
- auto rvalue = CompileExpr::Compile (expr.get_rhs ().get (), ctx);
+ auto lvalue = CompileExpr::Compile (expr.get_lhs (), ctx);
+ auto rvalue = CompileExpr::Compile (expr.get_rhs (), ctx);
// assignments are coercion sites so lets convert the rvalue if necessary
TyTy::BaseType *expected = nullptr;
@@ -972,16 +969,16 @@ CompileExpr::visit (HIR::AssignmentExpr &expr)
bool ok;
ok = ctx->get_tyctx ()->lookup_type (
- expr.get_lhs ()->get_mappings ().get_hirid (), &expected);
+ expr.get_lhs ().get_mappings ().get_hirid (), &expected);
rust_assert (ok);
ok = ctx->get_tyctx ()->lookup_type (
- expr.get_rhs ()->get_mappings ().get_hirid (), &actual);
+ expr.get_rhs ().get_mappings ().get_hirid (), &actual);
rust_assert (ok);
rvalue = coercion_site (expr.get_mappings ().get_hirid (), rvalue, actual,
- expected, expr.get_lhs ()->get_locus (),
- expr.get_rhs ()->get_locus ());
+ expected, expr.get_lhs ().get_locus (),
+ expr.get_rhs ().get_locus ());
// rust_debug_loc (expr.get_locus (), "XXXXXX assignment");
// debug_tree (rvalue);
@@ -1002,7 +999,7 @@ check_match_scrutinee (HIR::MatchExpr &expr, Context *ctx)
{
TyTy::BaseType *scrutinee_expr_tyty = nullptr;
if (!ctx->get_tyctx ()->lookup_type (
- expr.get_scrutinee_expr ()->get_mappings ().get_hirid (),
+ expr.get_scrutinee_expr ().get_mappings ().get_hirid (),
&scrutinee_expr_tyty))
{
return TyTy::TypeKind::ERROR;
@@ -1080,7 +1077,7 @@ CompileExpr::visit (HIR::MatchExpr &expr)
// lets compile the scrutinee expression
tree match_scrutinee_rval
- = CompileExpr::Compile (expr.get_scrutinee_expr ().get (), ctx);
+ = CompileExpr::Compile (expr.get_scrutinee_expr (), ctx);
Bvariable *match_scrutinee_tmp_var
= Backend::temporary_variable (fnctx.fndecl, enclosing_scope,
@@ -1090,7 +1087,7 @@ CompileExpr::visit (HIR::MatchExpr &expr)
ctx->add_statement (ret_var_stmt);
tree match_scrutinee_expr = match_scrutinee_tmp_var->get_tree (
- expr.get_scrutinee_expr ()->get_locus ());
+ expr.get_scrutinee_expr ().get_locus ());
tree assignment
= Backend::assignment_statement (match_scrutinee_expr, match_scrutinee_rval,
@@ -1123,14 +1120,13 @@ CompileExpr::visit (HIR::MatchExpr &expr)
ctx->push_block (arm_body_block);
// setup the bindings for the block
- CompilePatternBindings::Compile (kase_pattern.get (),
- match_scrutinee_expr, ctx);
+ CompilePatternBindings::Compile (*kase_pattern, match_scrutinee_expr,
+ ctx);
// compile the expr and setup the assignment if required when tmp !=
// NULL
location_t arm_locus = kase_arm.get_locus ();
- tree kase_expr_tree
- = CompileExpr::Compile (kase.get_expr ().get (), ctx);
+ tree kase_expr_tree = CompileExpr::Compile (kase.get_expr (), ctx);
tree result_reference = Backend::var_expression (tmp, arm_locus);
tree assignment
= Backend::assignment_statement (result_reference, kase_expr_tree,
@@ -1145,7 +1141,7 @@ CompileExpr::visit (HIR::MatchExpr &expr)
ctx->pop_block ();
tree check_expr
- = CompilePatternCheckExpr::Compile (kase_pattern.get (),
+ = CompilePatternCheckExpr::Compile (*kase_pattern,
match_scrutinee_expr, ctx);
tree check_stmt
@@ -1167,7 +1163,7 @@ CompileExpr::visit (HIR::CallExpr &expr)
{
TyTy::BaseType *tyty = nullptr;
if (!ctx->get_tyctx ()->lookup_type (
- expr.get_fnexpr ()->get_mappings ().get_hirid (), &tyty))
+ expr.get_fnexpr ().get_mappings ().get_hirid (), &tyty))
{
rust_error_at (expr.get_locus (), "unknown type");
return;
@@ -1193,7 +1189,7 @@ CompileExpr::visit (HIR::CallExpr &expr)
{
HirId variant_id;
bool ok = ctx->get_tyctx ()->lookup_variant_definition (
- expr.get_fnexpr ()->get_mappings ().get_hirid (), &variant_id);
+ expr.get_fnexpr ().get_mappings ().get_hirid (), &variant_id);
rust_assert (ok);
ok = adt->lookup_variant_by_id (variant_id, &variant,
@@ -1207,7 +1203,7 @@ CompileExpr::visit (HIR::CallExpr &expr)
for (size_t i = 0; i < expr.get_arguments ().size (); i++)
{
auto &argument = expr.get_arguments ().at (i);
- auto rvalue = CompileExpr::Compile (argument.get (), ctx);
+ auto rvalue = CompileExpr::Compile (*argument, ctx);
// assignments are coercion sites so lets convert the rvalue if
// necessary
@@ -1236,7 +1232,7 @@ CompileExpr::visit (HIR::CallExpr &expr)
std::vector<tree> ctor_arguments;
if (adt->is_enum ())
{
- HIR::Expr *discrim_expr = variant->get_discriminant ();
+ 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;
@@ -1270,13 +1266,13 @@ CompileExpr::visit (HIR::CallExpr &expr)
}
const TyTy::FnType *fn = static_cast<const TyTy::FnType *> (base);
- auto param = fn->param_at (index);
+ auto ¶m = fn->param_at (index);
*result = param.second;
return true;
};
- auto fn_address = CompileExpr::Compile (expr.get_fnexpr ().get (), ctx);
+ auto fn_address = CompileExpr::Compile (expr.get_fnexpr (), ctx);
// is this a closure call?
bool possible_trait_call
@@ -1303,7 +1299,7 @@ CompileExpr::visit (HIR::CallExpr &expr)
for (size_t i = 0; i < expr.get_arguments ().size (); i++)
{
auto &argument = expr.get_arguments ().at (i);
- auto rvalue = CompileExpr::Compile (argument.get (), ctx);
+ auto rvalue = CompileExpr::Compile (*argument, ctx);
if (is_variadic && i >= required_num_args)
{
@@ -1343,7 +1339,7 @@ void
CompileExpr::visit (HIR::MethodCallExpr &expr)
{
// method receiver
- tree self = CompileExpr::Compile (expr.get_receiver ().get (), ctx);
+ tree self = CompileExpr::Compile (expr.get_receiver (), ctx);
// lookup the expected function type
TyTy::BaseType *lookup_fntype = nullptr;
@@ -1383,7 +1379,7 @@ CompileExpr::visit (HIR::MethodCallExpr &expr)
// lookup the autoderef mappings
HirId autoderef_mappings_id
- = expr.get_receiver ()->get_mappings ().get_hirid ();
+ = expr.get_receiver ().get_mappings ().get_hirid ();
std::vector<Resolver::Adjustment> *adjustments = nullptr;
ok = ctx->get_tyctx ()->lookup_autoderef_mappings (autoderef_mappings_id,
&adjustments);
@@ -1391,7 +1387,7 @@ CompileExpr::visit (HIR::MethodCallExpr &expr)
// apply adjustments for the fn call
self = resolve_adjustements (*adjustments, self,
- expr.get_receiver ()->get_locus ());
+ expr.get_receiver ().get_locus ());
std::vector<tree> args;
args.push_back (self); // adjusted self
@@ -1400,7 +1396,7 @@ CompileExpr::visit (HIR::MethodCallExpr &expr)
for (size_t i = 0; i < expr.get_arguments ().size (); i++)
{
auto &argument = expr.get_arguments ().at (i);
- auto rvalue = CompileExpr::Compile (argument.get (), ctx);
+ auto rvalue = CompileExpr::Compile (*argument, ctx);
// assignments are coercion sites so lets convert the rvalue if
// necessary, offset from the already adjusted implicit self
@@ -1482,8 +1478,8 @@ CompileExpr::get_receiver_from_dyn (const TyTy::DynamicObjectType *dyn,
tree
CompileExpr::resolve_operator_overload (LangItem::Kind lang_item_type,
HIR::OperatorExprMeta expr, tree lhs,
- tree rhs, HIR::Expr *lhs_expr,
- HIR::Expr *rhs_expr)
+ tree rhs, HIR::Expr &lhs_expr,
+ tl::optional<HIR::Expr &> rhs_expr)
{
TyTy::FnType *fntype;
bool is_op_overload = ctx->get_tyctx ()->lookup_operator_overload (
@@ -1514,7 +1510,7 @@ CompileExpr::resolve_operator_overload (LangItem::Kind lang_item_type,
rust_assert (ok);
// apply adjustments for the fn call
- tree self = resolve_adjustements (*adjustments, lhs, lhs_expr->get_locus ());
+ tree self = resolve_adjustements (*adjustments, lhs, lhs_expr.get_locus ());
std::vector<tree> args;
args.push_back (self); // adjusted self
@@ -1829,7 +1825,7 @@ CompileExpr::visit (HIR::ArrayExpr &expr)
const TyTy::ArrayType &array_tyty
= static_cast<const TyTy::ArrayType &> (*tyty);
- HIR::ArrayElems &elements = *expr.get_internal_elements ();
+ HIR::ArrayElems &elements = expr.get_internal_elements ();
switch (elements.get_array_expr_type ())
{
case HIR::ArrayElems::ArrayExprType::VALUES: {
@@ -1858,7 +1854,7 @@ CompileExpr::array_value_expr (location_t expr_locus,
size_t i = 0;
for (auto &elem : elems.get_values ())
{
- tree translated_expr = CompileExpr::Compile (elem.get (), ctx);
+ tree translated_expr = CompileExpr::Compile (*elem, ctx);
constructor.push_back (translated_expr);
indexes.push_back (i++);
}
@@ -1885,8 +1881,7 @@ CompileExpr::array_copied_expr (location_t expr_locus,
}
ctx->push_const_context ();
- tree capacity_expr
- = CompileExpr::Compile (elems.get_num_copies_expr ().get (), ctx);
+ tree capacity_expr = CompileExpr::Compile (elems.get_num_copies_expr (), ctx);
ctx->pop_const_context ();
if (!TREE_CONSTANT (capacity_expr))
@@ -1896,8 +1891,7 @@ CompileExpr::array_copied_expr (location_t expr_locus,
}
// get the compiled value
- tree translated_expr
- = CompileExpr::Compile (elems.get_elem_to_copy ().get (), ctx);
+ tree translated_expr = CompileExpr::Compile (elems.get_elem_to_copy (), ctx);
tree max_domain = TYPE_MAX_VALUE (domain);
tree min_domain = TYPE_MIN_VALUE (domain);
@@ -2102,8 +2096,8 @@ HIRCompileBase::resolve_unsized_dyn_adjustment (
void
CompileExpr::visit (HIR::RangeFromToExpr &expr)
{
- tree from = CompileExpr::Compile (expr.get_from_expr ().get (), ctx);
- tree to = CompileExpr::Compile (expr.get_to_expr ().get (), ctx);
+ tree from = CompileExpr::Compile (expr.get_from_expr (), ctx);
+ tree to = CompileExpr::Compile (expr.get_to_expr (), ctx);
if (from == error_mark_node || to == error_mark_node)
{
translated = error_mark_node;
@@ -2125,7 +2119,7 @@ CompileExpr::visit (HIR::RangeFromToExpr &expr)
void
CompileExpr::visit (HIR::RangeFromExpr &expr)
{
- tree from = CompileExpr::Compile (expr.get_from_expr ().get (), ctx);
+ tree from = CompileExpr::Compile (expr.get_from_expr (), ctx);
if (from == error_mark_node)
{
translated = error_mark_node;
@@ -2147,7 +2141,7 @@ CompileExpr::visit (HIR::RangeFromExpr &expr)
void
CompileExpr::visit (HIR::RangeToExpr &expr)
{
- tree to = CompileExpr::Compile (expr.get_to_expr ().get (), ctx);
+ tree to = CompileExpr::Compile (expr.get_to_expr (), ctx);
if (to == error_mark_node)
{
translated = error_mark_node;
@@ -2182,8 +2176,8 @@ CompileExpr::visit (HIR::RangeFullExpr &expr)
void
CompileExpr::visit (HIR::RangeFromToInclExpr &expr)
{
- tree from = CompileExpr::Compile (expr.get_from_expr ().get (), ctx);
- tree to = CompileExpr::Compile (expr.get_to_expr ().get (), ctx);
+ tree from = CompileExpr::Compile (expr.get_from_expr (), ctx);
+ tree to = CompileExpr::Compile (expr.get_to_expr (), ctx);
if (from == error_mark_node || to == error_mark_node)
{
translated = error_mark_node;
@@ -2205,9 +2199,8 @@ CompileExpr::visit (HIR::RangeFromToInclExpr &expr)
void
CompileExpr::visit (HIR::ArrayIndexExpr &expr)
{
- tree array_reference
- = CompileExpr::Compile (expr.get_array_expr ().get (), ctx);
- tree index = CompileExpr::Compile (expr.get_index_expr ().get (), ctx);
+ tree array_reference = CompileExpr::Compile (expr.get_array_expr (), ctx);
+ tree index = CompileExpr::Compile (expr.get_index_expr (), ctx);
// this might be an core::ops::index lang item situation
TyTy::FnType *fntype;
@@ -2218,8 +2211,8 @@ CompileExpr::visit (HIR::ArrayIndexExpr &expr)
auto lang_item_type = LangItem::Kind::INDEX;
tree operator_overload_call
= resolve_operator_overload (lang_item_type, expr, array_reference,
- index, expr.get_array_expr ().get (),
- expr.get_index_expr ().get ());
+ index, expr.get_array_expr (),
+ expr.get_index_expr ());
tree actual_type = TREE_TYPE (operator_overload_call);
bool can_indirect = TYPE_PTR_P (actual_type) || TYPE_REF_P (actual_type);
@@ -2241,7 +2234,7 @@ CompileExpr::visit (HIR::ArrayIndexExpr &expr)
// indirection if required
TyTy::BaseType *array_expr_ty = nullptr;
bool ok = ctx->get_tyctx ()->lookup_type (
- expr.get_array_expr ()->get_mappings ().get_hirid (), &array_expr_ty);
+ expr.get_array_expr ().get_mappings ().get_hirid (), &array_expr_ty);
rust_assert (ok);
// do we need to add an indirect reference
@@ -2392,7 +2385,7 @@ CompileExpr::generate_closure_function (HIR::ClosureExpr &expr,
= Backend::struct_field_expression (args_param_expr, i,
closure_param.get_locus ());
- CompilePatternBindings::Compile (closure_param.get_pattern ().get (),
+ CompilePatternBindings::Compile (closure_param.get_pattern (),
compiled_param_var, ctx);
i++;
}
@@ -2404,13 +2397,13 @@ CompileExpr::generate_closure_function (HIR::ClosureExpr &expr,
}
// lookup locals
- HIR::Expr *function_body = expr.get_expr ().get ();
+ HIR::Expr &function_body = expr.get_expr ();
bool is_block_expr
- = function_body->get_expression_type () == HIR::Expr::ExprType::Block;
+ = function_body.get_expression_type () == HIR::Expr::ExprType::Block;
if (is_block_expr)
{
- auto body_mappings = function_body->get_mappings ();
+ auto body_mappings = function_body.get_mappings ();
if (flag_name_resolution_2_0)
{
auto nr_ctx
@@ -2431,13 +2424,13 @@ CompileExpr::generate_closure_function (HIR::ClosureExpr &expr,
}
tree enclosing_scope = NULL_TREE;
- location_t start_location = function_body->get_locus ();
- location_t end_location = function_body->get_locus ();
+ location_t start_location = function_body.get_locus ();
+ location_t end_location = function_body.get_locus ();
if (is_block_expr)
{
- HIR::BlockExpr *body = static_cast<HIR::BlockExpr *> (function_body);
- start_location = body->get_locus ();
- end_location = body->get_end_locus ();
+ auto &body = static_cast<HIR::BlockExpr &> (function_body);
+ start_location = body.get_locus ();
+ end_location = body.get_end_locus ();
}
tree code_block = Backend::block (fndecl, enclosing_scope, {} /*locals*/,
@@ -2462,15 +2455,14 @@ CompileExpr::generate_closure_function (HIR::ClosureExpr &expr,
if (is_block_expr)
{
- HIR::BlockExpr *body = static_cast<HIR::BlockExpr *> (function_body);
- compile_function_body (fndecl, *body, tyret);
+ auto &body = static_cast<HIR::BlockExpr &> (function_body);
+ compile_function_body (fndecl, body, tyret);
}
else
{
tree value = CompileExpr::Compile (function_body, ctx);
tree return_expr
- = Backend::return_statement (fndecl, value,
- function_body->get_locus ());
+ = Backend::return_statement (fndecl, value, function_body.get_locus ());
ctx->add_statement (return_expr);
}
@@ -2557,8 +2549,8 @@ CompileExpr::generate_possible_fn_trait_call (HIR::CallExpr &expr,
}
// need to apply any autoderef's to the self argument
- HIR::Expr *fnexpr = expr.get_fnexpr ().get ();
- HirId autoderef_mappings_id = fnexpr->get_mappings ().get_hirid ();
+ HIR::Expr &fnexpr = expr.get_fnexpr ();
+ HirId autoderef_mappings_id = fnexpr.get_mappings ().get_hirid ();
std::vector<Resolver::Adjustment> *adjustments = nullptr;
bool ok = ctx->get_tyctx ()->lookup_autoderef_mappings (autoderef_mappings_id,
&adjustments);
@@ -2571,7 +2563,7 @@ CompileExpr::generate_possible_fn_trait_call (HIR::CallExpr &expr,
std::vector<tree> tuple_arg_vals;
for (auto &argument : expr.get_arguments ())
{
- auto rvalue = CompileExpr::Compile (argument.get (), ctx);
+ auto rvalue = CompileExpr::Compile (*argument, ctx);
tuple_arg_vals.push_back (rvalue);
}
diff --git a/gcc/rust/backend/rust-compile-expr.h b/gcc/rust/backend/rust-compile-expr.h
index 2312375ff49..0178a93f144 100644
--- a/gcc/rust/backend/rust-compile-expr.h
+++ b/gcc/rust/backend/rust-compile-expr.h
@@ -28,7 +28,7 @@ namespace Compile {
class CompileExpr : private HIRCompileBase, protected HIR::HIRExpressionVisitor
{
public:
- static tree Compile (HIR::Expr *expr, Context *ctx);
+ static tree Compile (HIR::Expr &expr, Context *ctx);
void visit (HIR::TupleIndexExpr &expr) override;
void visit (HIR::TupleExpr &expr) override;
@@ -98,8 +98,8 @@ protected:
tree resolve_operator_overload (LangItem::Kind lang_item_type,
HIR::OperatorExprMeta expr, tree lhs,
- tree rhs, HIR::Expr *lhs_expr,
- HIR::Expr *rhs_expr);
+ tree rhs, HIR::Expr &lhs_expr,
+ tl::optional<HIR::Expr &> rhs_expr);
tree compile_bool_literal (const HIR::LiteralExpr &expr,
const TyTy::BaseType *tyty);
diff --git a/gcc/rust/backend/rust-compile-fnparam.cc b/gcc/rust/backend/rust-compile-fnparam.cc
index af24ca003b9..c00092d219e 100644
--- a/gcc/rust/backend/rust-compile-fnparam.cc
+++ b/gcc/rust/backend/rust-compile-fnparam.cc
@@ -31,20 +31,20 @@ CompileFnParam::CompileFnParam (Context *ctx, tree fndecl, tree decl_type,
{}
Bvariable *
-CompileFnParam::compile (Context *ctx, tree fndecl, HIR::FunctionParam *param,
+CompileFnParam::compile (Context *ctx, tree fndecl, HIR::FunctionParam ¶m,
tree decl_type, location_t locus)
{
CompileFnParam compiler (ctx, fndecl, decl_type, locus);
- param->get_param_name ()->accept_vis (compiler);
+ param.get_param_name ().accept_vis (compiler);
return compiler.compiled_param;
}
Bvariable *
-CompileFnParam::compile (Context *ctx, tree fndecl, HIR::Pattern *param,
+CompileFnParam::compile (Context *ctx, tree fndecl, HIR::Pattern ¶m,
tree decl_type, location_t locus)
{
CompileFnParam compiler (ctx, fndecl, decl_type, locus);
- param->accept_vis (compiler);
+ param.accept_vis (compiler);
return compiler.compiled_param;
}
@@ -72,21 +72,21 @@ void
CompileFnParam::visit (HIR::StructPattern &pattern)
{
tree tmp_param_var = create_tmp_param_var (decl_type);
- CompilePatternBindings::Compile (&pattern, tmp_param_var, ctx);
+ CompilePatternBindings::Compile (pattern, tmp_param_var, ctx);
}
void
CompileFnParam::visit (HIR::TupleStructPattern &pattern)
{
tree tmp_param_var = create_tmp_param_var (decl_type);
- CompilePatternBindings::Compile (&pattern, tmp_param_var, ctx);
+ CompilePatternBindings::Compile (pattern, tmp_param_var, ctx);
}
void
CompileFnParam::visit (HIR::ReferencePattern &pattern)
{
tree tmp_param_var = create_tmp_param_var (decl_type);
- CompilePatternBindings::Compile (&pattern, tmp_param_var, ctx);
+ CompilePatternBindings::Compile (pattern, tmp_param_var, ctx);
}
Bvariable *
diff --git a/gcc/rust/backend/rust-compile-fnparam.h b/gcc/rust/backend/rust-compile-fnparam.h
index 09a3e69f717..82a705fde7b 100644
--- a/gcc/rust/backend/rust-compile-fnparam.h
+++ b/gcc/rust/backend/rust-compile-fnparam.h
@@ -29,9 +29,9 @@ class CompileFnParam : private HIRCompileBase, protected HIR::HIRPatternVisitor
{
public:
static Bvariable *compile (Context *ctx, tree fndecl,
- HIR::FunctionParam *param, tree decl_type,
+ HIR::FunctionParam ¶m, tree decl_type,
location_t locus);
- static Bvariable *compile (Context *ctx, tree fndecl, HIR::Pattern *param,
+ static Bvariable *compile (Context *ctx, tree fndecl, HIR::Pattern ¶m,
tree decl_type, location_t locus);
void visit (HIR::IdentifierPattern &pattern) override;
diff --git a/gcc/rust/backend/rust-compile-implitem.cc b/gcc/rust/backend/rust-compile-implitem.cc
index 98337c8f9bb..352685e242f 100644
--- a/gcc/rust/backend/rust-compile-implitem.cc
+++ b/gcc/rust/backend/rust-compile-implitem.cc
@@ -44,7 +44,7 @@ CompileTraitItem::visit (HIR::TraitItemConst &constant)
rust_assert (canonical_path);
- HIR::Expr *const_value_expr = constant.get_expr ().get ();
+ HIR::Expr &const_value_expr = constant.get_expr ();
tree const_expr
= compile_constant_item (resolved_type, *canonical_path, const_value_expr,
constant.get_locus ());
@@ -114,7 +114,7 @@ CompileTraitItem::visit (HIR::TraitItemFunc &func)
function.get_self (), function.get_function_params (),
function.get_qualifiers (), vis,
func.get_outer_attrs (), func.get_locus (),
- func.get_block_expr ().get (), *canonical_path, fntype);
+ &func.get_block_expr (), *canonical_path, fntype);
reference = address_expression (fndecl, ref_locus);
}
diff --git a/gcc/rust/backend/rust-compile-intrinsic.cc b/gcc/rust/backend/rust-compile-intrinsic.cc
index de3bb6e3203..bf595e4fb87 100644
--- a/gcc/rust/backend/rust-compile-intrinsic.cc
+++ b/gcc/rust/backend/rust-compile-intrinsic.cc
@@ -321,7 +321,7 @@ compile_fn_params (Context *ctx, TyTy::FnType *fntype, tree fndecl,
location_t param_locus = referenced_param->get_locus ();
Bvariable *compiled_param_var
- = CompileFnParam::compile (ctx, fndecl, referenced_param,
+ = CompileFnParam::compile (ctx, fndecl, *referenced_param,
compiled_param_type, param_locus);
compiled_param_variables->push_back (compiled_param_var);
diff --git a/gcc/rust/backend/rust-compile-item.cc b/gcc/rust/backend/rust-compile-item.cc
index 08787163c2a..dd37e3997d6 100644
--- a/gcc/rust/backend/rust-compile-item.cc
+++ b/gcc/rust/backend/rust-compile-item.cc
@@ -60,7 +60,7 @@ CompileItem::visit (HIR::StaticItem &var)
rust_assert (canonical_path.has_value ());
- HIR::Expr *const_value_expr = var.get_expr ().get ();
+ HIR::Expr &const_value_expr = var.get_expr ();
ctx->push_const_context ();
tree value = compile_constant_item (resolved_type, *canonical_path,
const_value_expr, var.get_locus ());
@@ -120,7 +120,7 @@ CompileItem::visit (HIR::ConstantItem &constant)
.value ();
}
- HIR::Expr *const_value_expr = constant.get_expr ().get ();
+ HIR::Expr &const_value_expr = constant.get_expr ();
ctx->push_const_context ();
tree const_expr
= compile_constant_item (resolved_type, canonical_path, const_value_expr,
@@ -222,8 +222,7 @@ CompileItem::visit (HIR::Function &function)
function.get_function_params (),
function.get_qualifiers (), function.get_visibility (),
function.get_outer_attrs (), function.get_locus (),
- function.get_definition ().get (), canonical_path,
- fntype);
+ &function.get_definition (), canonical_path, fntype);
reference = address_expression (fndecl, ref_locus);
if (function.get_qualifiers ().is_const ())
@@ -235,7 +234,7 @@ CompileItem::visit (HIR::ImplBlock &impl_block)
{
TyTy::BaseType *self_lookup = nullptr;
if (!ctx->get_tyctx ()->lookup_type (
- impl_block.get_type ()->get_mappings ().get_hirid (), &self_lookup))
+ impl_block.get_type ().get_mappings ().get_hirid (), &self_lookup))
{
rust_error_at (impl_block.get_locus (), "failed to resolve type of impl");
return;
diff --git a/gcc/rust/backend/rust-compile-pattern.cc b/gcc/rust/backend/rust-compile-pattern.cc
index ffa1fa7f5dc..d6161bd5e83 100644
--- a/gcc/rust/backend/rust-compile-pattern.cc
+++ b/gcc/rust/backend/rust-compile-pattern.cc
@@ -67,7 +67,7 @@ CompilePatternCheckExpr::visit (HIR::PathInExpression &pattern)
// must be enum
match_scrutinee_expr = scrutinee_expr_qualifier_expr;
- HIR::Expr *discrim_expr = variant->get_discriminant ();
+ HIR::Expr &discrim_expr = variant->get_discriminant ();
tree discrim_expr_node = CompileExpr::Compile (discrim_expr, ctx);
check_expr
@@ -80,10 +80,9 @@ void
CompilePatternCheckExpr::visit (HIR::LiteralPattern &pattern)
{
// Compile the literal
- HIR::LiteralExpr *litexpr
- = new HIR::LiteralExpr (pattern.get_mappings (), pattern.get_literal (),
- pattern.get_locus (),
- std::vector<AST::Attribute> ());
+ auto litexpr = Rust::make_unique<HIR::LiteralExpr> (
+ HIR::LiteralExpr (pattern.get_mappings (), pattern.get_literal (),
+ pattern.get_locus (), std::vector<AST::Attribute> ()));
// Note: Floating point literals are currently accepted but will likely be
// forbidden in LiteralPatterns in a future version of Rust.
@@ -95,7 +94,7 @@ CompilePatternCheckExpr::visit (HIR::LiteralPattern &pattern)
rust_sorry_at (pattern.get_locus (), "floating-point literal in pattern");
}
- tree lit = CompileExpr::Compile (litexpr, ctx);
+ tree lit = CompileExpr::Compile (*litexpr, ctx);
check_expr = Backend::comparison_expression (ComparisonOperator::EQUAL,
match_scrutinee_expr, lit,
@@ -103,19 +102,17 @@ CompilePatternCheckExpr::visit (HIR::LiteralPattern &pattern)
}
static tree
-compile_range_pattern_bound (HIR::RangePatternBound *bound,
+compile_range_pattern_bound (HIR::RangePatternBound &bound,
Analysis::NodeMapping mappings, location_t locus,
Context *ctx)
{
tree result = NULL_TREE;
- switch (bound->get_bound_type ())
+ switch (bound.get_bound_type ())
{
case HIR::RangePatternBound::RangePatternBoundType::LITERAL: {
- HIR::RangePatternBoundLiteral &ref
- = *static_cast<HIR::RangePatternBoundLiteral *> (bound);
+ auto &ref = static_cast<HIR::RangePatternBoundLiteral &> (bound);
- HIR::LiteralExpr *litexpr
- = new HIR::LiteralExpr (mappings, ref.get_literal (), locus,
+ HIR::LiteralExpr litexpr (mappings, ref.get_literal (), locus,
std::vector<AST::Attribute> ());
result = CompileExpr::Compile (litexpr, ctx);
@@ -123,8 +120,7 @@ compile_range_pattern_bound (HIR::RangePatternBound *bound,
break;
case HIR::RangePatternBound::RangePatternBoundType::PATH: {
- HIR::RangePatternBoundPath &ref
- = *static_cast<HIR::RangePatternBoundPath *> (bound);
+ auto &ref = static_cast<HIR::RangePatternBoundPath &> (bound);
result = ResolvePathRef::Compile (ref.get_path (), ctx);
@@ -134,8 +130,7 @@ compile_range_pattern_bound (HIR::RangePatternBound *bound,
break;
case HIR::RangePatternBound::RangePatternBoundType::QUALPATH: {
- HIR::RangePatternBoundQualPath &ref
- = *static_cast<HIR::RangePatternBoundQualPath *> (bound);
+ auto &ref = static_cast<HIR::RangePatternBoundQualPath &> (bound);
result = ResolvePathRef::Compile (ref.get_qualified_path (), ctx);
@@ -150,10 +145,10 @@ compile_range_pattern_bound (HIR::RangePatternBound *bound,
void
CompilePatternCheckExpr::visit (HIR::RangePattern &pattern)
{
- tree upper = compile_range_pattern_bound (pattern.get_upper_bound ().get (),
+ tree upper = compile_range_pattern_bound (pattern.get_upper_bound (),
pattern.get_mappings (),
pattern.get_locus (), ctx);
- tree lower = compile_range_pattern_bound (pattern.get_lower_bound ().get (),
+ tree lower = compile_range_pattern_bound (pattern.get_lower_bound (),
pattern.get_mappings (),
pattern.get_locus (), ctx);
@@ -175,7 +170,7 @@ CompilePatternCheckExpr::visit (HIR::ReferencePattern &pattern)
{
match_scrutinee_expr
= indirect_expression (match_scrutinee_expr, pattern.get_locus ());
- pattern.get_referenced_pattern ()->accept_vis (*this);
+ pattern.get_referenced_pattern ().accept_vis (*this);
}
void
@@ -183,14 +178,13 @@ CompilePatternCheckExpr::visit (HIR::AltPattern &pattern)
{
auto &alts = pattern.get_alts ();
- check_expr = CompilePatternCheckExpr::Compile (alts.at (0).get (),
+ check_expr = CompilePatternCheckExpr::Compile (*alts.at (0),
match_scrutinee_expr, ctx);
auto end = alts.end ();
for (auto i = alts.begin () + 1; i != end; i++)
{
tree next_expr
- = CompilePatternCheckExpr::Compile (i->get (), match_scrutinee_expr,
- ctx);
+ = CompilePatternCheckExpr::Compile (**i, match_scrutinee_expr, ctx);
check_expr = Backend::arithmetic_or_logical_expression (
ArithmeticOrLogicalOperator::BITWISE_OR, check_expr, next_expr,
(*i)->get_locus ());
@@ -229,7 +223,7 @@ CompilePatternCheckExpr::visit (HIR::StructPattern &pattern)
// // would be DECL_QUALIFIER i think. For now this will just access the
// // first record field and its respective qualifier because it will
// // always be set because this is all a big special union
- HIR::Expr *discrim_expr = variant->get_discriminant ();
+ HIR::Expr &discrim_expr = variant->get_discriminant ();
tree discrim_expr_node = CompileExpr::Compile (discrim_expr, ctx);
// find discriminant field of scrutinee
@@ -282,11 +276,11 @@ CompilePatternCheckExpr::visit (HIR::StructPattern &pattern)
ident.get_locus ());
tree check_expr_sub
- = CompilePatternCheckExpr::Compile (ident.get_pattern ().get (),
+ = CompilePatternCheckExpr::Compile (ident.get_pattern (),
field_expr, ctx);
check_expr = Backend::arithmetic_or_logical_expression (
ArithmeticOrLogicalOperator::BITWISE_AND, check_expr,
- check_expr_sub, ident.get_pattern ()->get_locus ());
+ check_expr_sub, ident.get_pattern ().get_locus ());
}
break;
@@ -328,7 +322,7 @@ CompilePatternCheckExpr::visit (HIR::TupleStructPattern &pattern)
rust_assert (ok);
// find expected discriminant
- HIR::Expr *discrim_expr = variant->get_discriminant ();
+ HIR::Expr &discrim_expr = variant->get_discriminant ();
tree discrim_expr_node = CompileExpr::Compile (discrim_expr, ctx);
// find discriminant field of scrutinee
@@ -357,8 +351,8 @@ CompilePatternCheckExpr::visit (HIR::TupleStructPattern &pattern)
tuple_field_index = 0;
}
- std::unique_ptr<HIR::TupleStructItems> &items = pattern.get_items ();
- switch (items->get_item_type ())
+ HIR::TupleStructItems &items = pattern.get_items ();
+ switch (items.get_item_type ())
{
case HIR::TupleStructItems::RANGED: {
// TODO
@@ -368,7 +362,7 @@ CompilePatternCheckExpr::visit (HIR::TupleStructPattern &pattern)
case HIR::TupleStructItems::MULTIPLE: {
HIR::TupleStructItemsNoRange &items_no_range
- = static_cast<HIR::TupleStructItemsNoRange &> (*items.get ());
+ = static_cast<HIR::TupleStructItemsNoRange &> (items);
rust_assert (items_no_range.get_patterns ().size ()
== variant->num_fields ());
@@ -381,8 +375,7 @@ CompilePatternCheckExpr::visit (HIR::TupleStructPattern &pattern)
pattern->get_locus ());
tree check_expr_sub
- = CompilePatternCheckExpr::Compile (pattern.get (), field_expr,
- ctx);
+ = CompilePatternCheckExpr::Compile (*pattern, field_expr, ctx);
check_expr = Backend::arithmetic_or_logical_expression (
ArithmeticOrLogicalOperator::BITWISE_AND, check_expr,
check_expr_sub, pattern->get_locus ());
@@ -397,7 +390,7 @@ CompilePatternCheckExpr::visit (HIR::TuplePattern &pattern)
{
check_expr = boolean_true_node;
- switch (pattern.get_items ()->get_item_type ())
+ switch (pattern.get_items ().get_item_type ())
{
case HIR::TuplePatternItems::RANGED: {
// TODO
@@ -407,7 +400,7 @@ CompilePatternCheckExpr::visit (HIR::TuplePattern &pattern)
case HIR::TuplePatternItems::MULTIPLE: {
auto &items = static_cast<HIR::TuplePatternItemsMultiple &> (
- *pattern.get_items ());
+ pattern.get_items ());
size_t tuple_field_index = 0;
for (auto &pat : items.get_patterns ())
@@ -418,7 +411,7 @@ CompilePatternCheckExpr::visit (HIR::TuplePattern &pattern)
pat->get_locus ());
tree check_expr_sub
- = CompilePatternCheckExpr::Compile (pat.get (), field_expr, ctx);
+ = CompilePatternCheckExpr::Compile (*pat, field_expr, ctx);
check_expr = Backend::arithmetic_or_logical_expression (
ArithmeticOrLogicalOperator::BITWISE_AND, check_expr,
check_expr_sub, pat->get_locus ());
@@ -459,8 +452,8 @@ CompilePatternBindings::visit (HIR::TupleStructPattern &pattern)
rust_assert (variant->get_variant_type ()
== TyTy::VariantDef::VariantType::TUPLE);
- std::unique_ptr<HIR::TupleStructItems> &items = pattern.get_items ();
- switch (items->get_item_type ())
+ HIR::TupleStructItems &items = pattern.get_items ();
+ switch (items.get_item_type ())
{
case HIR::TupleStructItems::RANGED: {
// TODO
@@ -470,7 +463,7 @@ CompilePatternBindings::visit (HIR::TupleStructPattern &pattern)
case HIR::TupleStructItems::MULTIPLE: {
HIR::TupleStructItemsNoRange &items_no_range
- = static_cast<HIR::TupleStructItemsNoRange &> (*items.get ());
+ = static_cast<HIR::TupleStructItemsNoRange &> (items);
rust_assert (items_no_range.get_patterns ().size ()
== variant->num_fields ());
@@ -609,8 +602,8 @@ CompilePatternBindings::visit (HIR::ReferencePattern &pattern)
tree derefed
= indirect_expression (match_scrutinee_expr, pattern.get_locus ());
- CompilePatternBindings::Compile (pattern.get_referenced_pattern ().get (),
- derefed, ctx);
+ CompilePatternBindings::Compile (pattern.get_referenced_pattern (), derefed,
+ ctx);
}
void
@@ -670,12 +663,12 @@ CompilePatternLet::visit (HIR::TuplePattern &pattern)
tree access_expr = Backend::var_expression (tmp_var, pattern.get_locus ());
ctx->add_statement (init_stmt);
- switch (pattern.get_items ()->get_item_type ())
+ switch (pattern.get_items ().get_item_type ())
{
case HIR::TuplePatternItems::ItemType::RANGED: {
size_t tuple_idx = 0;
auto &items
- = static_cast<HIR::TuplePatternItemsRanged &> (*pattern.get_items ());
+ = static_cast<HIR::TuplePatternItemsRanged &> (pattern.get_items ());
auto &items_lower = items.get_lower_patterns ();
auto &items_upper = items.get_upper_patterns ();
@@ -719,7 +712,7 @@ CompilePatternLet::visit (HIR::TuplePattern &pattern)
case HIR::TuplePatternItems::ItemType::MULTIPLE: {
size_t tuple_idx = 0;
auto &items = static_cast<HIR::TuplePatternItemsMultiple &> (
- *pattern.get_items ());
+ pattern.get_items ());
for (auto &sub : items.get_patterns ())
{
diff --git a/gcc/rust/backend/rust-compile-pattern.h b/gcc/rust/backend/rust-compile-pattern.h
index 521ed0d6e92..0b785c6ce8c 100644
--- a/gcc/rust/backend/rust-compile-pattern.h
+++ b/gcc/rust/backend/rust-compile-pattern.h
@@ -26,11 +26,11 @@ class CompilePatternCheckExpr : public HIRCompileBase,
public HIR::HIRPatternVisitor
{
public:
- static tree Compile (HIR::Pattern *pattern, tree match_scrutinee_expr,
+ static tree Compile (HIR::Pattern &pattern, tree match_scrutinee_expr,
Context *ctx)
{
CompilePatternCheckExpr compiler (ctx, match_scrutinee_expr);
- pattern->accept_vis (compiler);
+ pattern.accept_vis (compiler);
rust_assert (compiler.check_expr);
return compiler.check_expr;
}
@@ -71,11 +71,11 @@ class CompilePatternBindings : public HIRCompileBase,
public HIR::HIRPatternVisitor
{
public:
- static void Compile (HIR::Pattern *pattern, tree match_scrutinee_expr,
+ static void Compile (HIR::Pattern &pattern, tree match_scrutinee_expr,
Context *ctx)
{
CompilePatternBindings compiler (ctx, match_scrutinee_expr);
- pattern->accept_vis (compiler);
+ pattern.accept_vis (compiler);
}
void visit (HIR::StructPattern &pattern) override;
diff --git a/gcc/rust/backend/rust-compile-resolve-path.cc b/gcc/rust/backend/rust-compile-resolve-path.cc
index 7c9b303b851..31ebbf14b74 100644
--- a/gcc/rust/backend/rust-compile-resolve-path.cc
+++ b/gcc/rust/backend/rust-compile-resolve-path.cc
@@ -81,7 +81,7 @@ ResolvePathRef::attempt_constructor_expression_lookup (
tree compiled_adt_type = TyTyResolveCompile::compile (ctx, adt);
// make the ctor for the union
- HIR::Expr *discrim_expr = variant->get_discriminant ();
+ 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;
@@ -301,7 +301,7 @@ HIRCompileBase::query_compile (HirId ref, TyTy::BaseType *lookup,
TyTy::BaseType *self = nullptr;
bool ok = ctx->get_tyctx ()->lookup_type (
- impl->get_type ()->get_mappings ().get_hirid (), &self);
+ impl->get_type ().get_mappings ().get_hirid (), &self);
rust_assert (ok);
if (!lookup->has_substitutions_defined ())
diff --git a/gcc/rust/backend/rust-compile-stmt.cc b/gcc/rust/backend/rust-compile-stmt.cc
index d8b27ffb18c..a4b5a989fc4 100644
--- a/gcc/rust/backend/rust-compile-stmt.cc
+++ b/gcc/rust/backend/rust-compile-stmt.cc
@@ -40,13 +40,13 @@ CompileStmt::Compile (HIR::Stmt *stmt, Context *ctx)
void
CompileStmt::visit (HIR::ExprStmt &stmt)
{
- translated = CompileExpr::Compile (stmt.get_expr ().get (), ctx);
+ translated = CompileExpr::Compile (stmt.get_expr (), ctx);
}
void
CompileStmt::visit (HIR::LetStmt &stmt)
{
- HIR::Pattern &stmt_pattern = *stmt.get_pattern ();
+ HIR::Pattern &stmt_pattern = stmt.get_pattern ();
HirId stmt_id = stmt_pattern.get_mappings ().get_hirid ();
TyTy::BaseType *ty = nullptr;
@@ -68,7 +68,7 @@ CompileStmt::visit (HIR::LetStmt &stmt)
if (!stmt.has_init_expr ())
return;
- tree init = CompileExpr::Compile (stmt.get_init_expr ().get (), ctx);
+ tree init = CompileExpr::Compile (stmt.get_init_expr (), ctx);
// FIXME use error_mark_node, check that CompileExpr returns error_mark_node
// on failure and make this an assertion
if (init == nullptr)
@@ -76,11 +76,11 @@ CompileStmt::visit (HIR::LetStmt &stmt)
TyTy::BaseType *actual = nullptr;
bool ok = ctx->get_tyctx ()->lookup_type (
- stmt.get_init_expr ()->get_mappings ().get_hirid (), &actual);
+ stmt.get_init_expr ().get_mappings ().get_hirid (), &actual);
rust_assert (ok);
- location_t lvalue_locus = stmt.get_pattern ()->get_locus ();
- location_t rvalue_locus = stmt.get_init_expr ()->get_locus ();
+ location_t lvalue_locus = stmt.get_pattern ().get_locus ();
+ location_t rvalue_locus = stmt.get_init_expr ().get_locus ();
TyTy::BaseType *expected = ty;
init = coercion_site (stmt.get_mappings ().get_hirid (), init, actual,
expected, lvalue_locus, rvalue_locus);
diff --git a/gcc/rust/backend/rust-compile-struct-field-expr.cc b/gcc/rust/backend/rust-compile-struct-field-expr.cc
index 4a3b26c22e2..0ac25e7a822 100644
--- a/gcc/rust/backend/rust-compile-struct-field-expr.cc
+++ b/gcc/rust/backend/rust-compile-struct-field-expr.cc
@@ -27,22 +27,22 @@ CompileStructExprField::CompileStructExprField (Context *ctx)
{}
tree
-CompileStructExprField::Compile (HIR::StructExprField *field, Context *ctx)
+CompileStructExprField::Compile (HIR::StructExprField &field, Context *ctx)
{
CompileStructExprField compiler (ctx);
- switch (field->get_kind ())
+ switch (field.get_kind ())
{
case HIR::StructExprField::StructExprFieldKind::IDENTIFIER:
- compiler.visit (static_cast<HIR::StructExprFieldIdentifier &> (*field));
+ compiler.visit (static_cast<HIR::StructExprFieldIdentifier &> (field));
break;
case HIR::StructExprField::StructExprFieldKind::IDENTIFIER_VALUE:
compiler.visit (
- static_cast<HIR::StructExprFieldIdentifierValue &> (*field));
+ static_cast<HIR::StructExprFieldIdentifierValue &> (field));
break;
case HIR::StructExprField::StructExprFieldKind::INDEX_VALUE:
- compiler.visit (static_cast<HIR::StructExprFieldIndexValue &> (*field));
+ compiler.visit (static_cast<HIR::StructExprFieldIndexValue &> (field));
break;
}
return compiler.translated;
@@ -51,13 +51,13 @@ CompileStructExprField::Compile (HIR::StructExprField *field, Context *ctx)
void
CompileStructExprField::visit (HIR::StructExprFieldIdentifierValue &field)
{
- translated = CompileExpr::Compile (field.get_value ().get (), ctx);
+ translated = CompileExpr::Compile (field.get_value (), ctx);
}
void
CompileStructExprField::visit (HIR::StructExprFieldIndexValue &field)
{
- translated = CompileExpr::Compile (field.get_value ().get (), ctx);
+ translated = CompileExpr::Compile (field.get_value (), ctx);
}
void
@@ -74,7 +74,7 @@ CompileStructExprField::visit (HIR::StructExprFieldIdentifier &field)
HIR::GenericArgs::create_empty ());
HIR::PathInExpression expr (mappings_copy2, {seg}, field.get_locus (), false,
{});
- translated = CompileExpr::Compile (&expr, ctx);
+ translated = CompileExpr::Compile (expr, ctx);
}
} // namespace Compile
diff --git a/gcc/rust/backend/rust-compile-struct-field-expr.h b/gcc/rust/backend/rust-compile-struct-field-expr.h
index f1d70552a08..055019cf1eb 100644
--- a/gcc/rust/backend/rust-compile-struct-field-expr.h
+++ b/gcc/rust/backend/rust-compile-struct-field-expr.h
@@ -27,7 +27,7 @@ namespace Compile {
class CompileStructExprField : private HIRCompileBase
{
public:
- static tree Compile (HIR::StructExprField *field, Context *ctx);
+ static tree Compile (HIR::StructExprField &field, Context *ctx);
protected:
void visit (HIR::StructExprFieldIdentifierValue &field);
diff --git a/gcc/rust/backend/rust-compile-type.cc b/gcc/rust/backend/rust-compile-type.cc
index b546a05f6a8..c53b359b01f 100644
--- a/gcc/rust/backend/rust-compile-type.cc
+++ b/gcc/rust/backend/rust-compile-type.cc
@@ -428,7 +428,7 @@ TyTyResolveCompile::visit (const TyTy::ArrayType &type)
= TyTyResolveCompile::compile (ctx, type.get_element_type ());
ctx->push_const_context ();
- tree capacity_expr = CompileExpr::Compile (&type.get_capacity_expr (), ctx);
+ tree capacity_expr = CompileExpr::Compile (type.get_capacity_expr (), ctx);
ctx->pop_const_context ();
tree folded_capacity_expr = fold_expr (capacity_expr);
diff --git a/gcc/rust/backend/rust-compile-var-decl.h b/gcc/rust/backend/rust-compile-var-decl.h
index 6b6af77a958..4c46a7b17d6 100644
--- a/gcc/rust/backend/rust-compile-var-decl.h
+++ b/gcc/rust/backend/rust-compile-var-decl.h
@@ -68,12 +68,12 @@ public:
void visit (HIR::TuplePattern &pattern) override
{
- switch (pattern.get_items ()->get_item_type ())
+ switch (pattern.get_items ().get_item_type ())
{
case HIR::TuplePatternItems::ItemType::MULTIPLE: {
rust_assert (TREE_CODE (translated_type) == RECORD_TYPE);
auto &items = static_cast<HIR::TuplePatternItemsMultiple &> (
- *pattern.get_items ());
+ pattern.get_items ());
size_t offs = 0;
for (auto &sub : items.get_patterns ())
diff --git a/gcc/rust/backend/rust-compile.cc b/gcc/rust/backend/rust-compile.cc
index 7e0a9b6920f..7b000662c8d 100644
--- a/gcc/rust/backend/rust-compile.cc
+++ b/gcc/rust/backend/rust-compile.cc
@@ -259,17 +259,17 @@ HIRCompileBase::compute_address_for_trait_item (
HIR::ImplBlock *impl_block = item.second;
rust_assert (impl_block != nullptr);
- // Lookup type for potentially associated impl.
- std::unique_ptr<HIR::Type> &self_type_path = impl_block->get_type ();
-
// Checks for empty impl blocks, triggered by Sized trait.
- if (self_type_path == nullptr)
+ if (!impl_block->has_type ())
continue;
+ // Lookup type for potentially associated impl.
+ HIR::Type &self_type_path = impl_block->get_type ();
+
// Convert HIR::Type to TyTy::BaseType
TyTy::BaseType *self = nullptr;
bool ok = ctx->get_tyctx ()->lookup_type (
- self_type_path->get_mappings ().get_hirid (), &self);
+ self_type_path.get_mappings ().get_hirid (), &self);
rust_assert (ok);
diff --git a/gcc/rust/backend/rust-mangle-v0.cc b/gcc/rust/backend/rust-mangle-v0.cc
index d604dcf725c..67d7e4d1885 100644
--- a/gcc/rust/backend/rust-mangle-v0.cc
+++ b/gcc/rust/backend/rust-mangle-v0.cc
@@ -328,7 +328,7 @@ v0_inherent_or_trait_impl_path (Rust::Compile::Context *ctx,
// lookup impl type
TyTy::BaseType *impl_ty = nullptr;
ok = ctx->get_tyctx ()->lookup_type (
- impl_block->get_type ()->get_mappings ().get_hirid (), &impl_ty);
+ impl_block->get_type ().get_mappings ().get_hirid (), &impl_ty);
rust_assert (ok);
// FIXME: dummy value for now
@@ -342,7 +342,7 @@ v0_inherent_or_trait_impl_path (Rust::Compile::Context *ctx,
TyTy::BaseType *trait_ty = nullptr;
ok = ctx->get_tyctx ()->lookup_type (
- impl_block->get_trait_ref ()->get_mappings ().get_hirid (), &trait_ty);
+ impl_block->get_trait_ref ().get_mappings ().get_hirid (), &trait_ty);
rust_assert (ok);
v0path.trait_type = v0_type_prefix (ctx, trait_ty);
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 df02c4b5e61..d6acc6abcef 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
@@ -135,7 +135,7 @@ ExprStmtBuilder::visit (HIR::LiteralExpr &expr)
void
ExprStmtBuilder::visit (HIR::BorrowExpr &expr)
{
- auto operand = visit_expr (*expr.get_expr ());
+ auto operand = visit_expr (expr.get_expr ());
if (ctx.place_db[operand].is_constant ())
{
// Cannot borrow a constant, must create a temporary copy.
@@ -150,7 +150,7 @@ ExprStmtBuilder::visit (HIR::BorrowExpr &expr)
void
ExprStmtBuilder::visit (HIR::DereferenceExpr &expr)
{
- auto operand = visit_expr (*expr.get_expr ());
+ auto operand = visit_expr (expr.get_expr ());
return_place (ctx.place_db.lookup_or_add_path (Place::DEREF,
lookup_type (expr), operand),
expr.get_locus ());
@@ -166,30 +166,31 @@ ExprStmtBuilder::visit (HIR::ErrorPropagationExpr &expr)
void
ExprStmtBuilder::visit (HIR::NegationExpr &expr)
{
- PlaceId operand = visit_expr (*expr.get_expr ());
- return_expr (new Operator<1> ({move_place (operand, expr.get_locus ())}),
+ PlaceId operand = visit_expr (expr.get_expr ());
+ return_expr (new Operator<1> (
+ {move_place (operand, expr.get_expr ().get_locus ())}),
lookup_type (expr), expr.get_locus ());
}
void
ExprStmtBuilder::visit (HIR::ArithmeticOrLogicalExpr &expr)
{
- PlaceId lhs = visit_expr (*expr.get_lhs ());
- PlaceId rhs = visit_expr (*expr.get_rhs ());
+ PlaceId lhs = visit_expr (expr.get_lhs ());
+ PlaceId rhs = visit_expr (expr.get_rhs ());
return_expr (new Operator<2> (
- {move_place (lhs, expr.get_lhs ()->get_locus ()),
- move_place (rhs, expr.get_rhs ()->get_locus ())}),
+ {move_place (lhs, expr.get_lhs ().get_locus ()),
+ move_place (rhs, expr.get_rhs ().get_locus ())}),
lookup_type (expr), expr.get_locus ());
}
void
ExprStmtBuilder::visit (HIR::ComparisonExpr &expr)
{
- PlaceId lhs = visit_expr (*expr.get_lhs ());
- PlaceId rhs = visit_expr (*expr.get_rhs ());
+ PlaceId lhs = visit_expr (expr.get_lhs ());
+ PlaceId rhs = visit_expr (expr.get_rhs ());
return_expr (new Operator<2> (
- {move_place (lhs, expr.get_lhs ()->get_locus ()),
- move_place (rhs, expr.get_rhs ()->get_locus ())}),
+ {move_place (lhs, expr.get_lhs ().get_locus ()),
+ move_place (rhs, expr.get_rhs ().get_locus ())}),
lookup_type (expr), expr.get_locus ());
}
@@ -205,7 +206,7 @@ ExprStmtBuilder::visit (HIR::LazyBooleanExpr &expr)
void
ExprStmtBuilder::visit (HIR::TypeCastExpr &expr)
{
- auto operand = visit_expr (*expr.get_expr ());
+ auto operand = visit_expr (expr.get_expr ());
return_expr (new Operator<1> ({operand}), lookup_type (expr),
expr.get_locus ());
}
@@ -213,8 +214,8 @@ ExprStmtBuilder::visit (HIR::TypeCastExpr &expr)
void
ExprStmtBuilder::visit (HIR::AssignmentExpr &expr)
{
- auto lhs = visit_expr (*expr.get_lhs ());
- auto rhs = visit_expr (*expr.get_rhs ());
+ auto lhs = visit_expr (expr.get_lhs ());
+ auto rhs = visit_expr (expr.get_rhs ());
push_assignment (lhs, rhs, expr.get_locus ());
translated = INVALID_PLACE;
}
@@ -222,25 +223,25 @@ ExprStmtBuilder::visit (HIR::AssignmentExpr &expr)
void
ExprStmtBuilder::visit (HIR::CompoundAssignmentExpr &expr)
{
- auto lhs = visit_expr (*expr.get_lhs ());
- auto rhs = visit_expr (*expr.get_rhs ());
+ auto lhs = visit_expr (expr.get_lhs ());
+ auto rhs = visit_expr (expr.get_rhs ());
push_assignment (lhs, new Operator<2> ({lhs, rhs}), expr.get_locus ());
}
void
ExprStmtBuilder::visit (HIR::GroupedExpr &expr)
{
- return_place (visit_expr (*expr.get_expr_in_parens ()), expr.get_locus ());
+ return_place (visit_expr (expr.get_expr_in_parens ()), expr.get_locus ());
}
void
ExprStmtBuilder::visit (HIR::ArrayExpr &expr)
{
auto &elems = expr.get_internal_elements ();
- switch (elems->get_array_expr_type ())
+ switch (elems.get_array_expr_type ())
{
case HIR::ArrayElems::VALUES: {
- auto &elem_vals = (static_cast<HIR::ArrayElemsValues &> (*elems));
+ auto &elem_vals = (static_cast<HIR::ArrayElemsValues &> (elems));
auto init_values = visit_list (elem_vals.get_values ());
// collect locations
std::vector<location_t> value_locations;
@@ -254,8 +255,8 @@ ExprStmtBuilder::visit (HIR::ArrayExpr &expr)
break;
}
case HIR::ArrayElems::COPIED: {
- auto &elem_copied = (static_cast<HIR::ArrayElemsCopied &> (*elems));
- auto init = visit_expr (*elem_copied.get_elem_to_copy ());
+ auto &elem_copied = (static_cast<HIR::ArrayElemsCopied &> (elems));
+ auto init = visit_expr (elem_copied.get_elem_to_copy ());
return_expr (new InitializerExpr ({init}), lookup_type (expr),
expr.get_locus ());
break;
@@ -266,8 +267,8 @@ ExprStmtBuilder::visit (HIR::ArrayExpr &expr)
void
ExprStmtBuilder::visit (HIR::ArrayIndexExpr &expr)
{
- auto lhs = visit_expr (*expr.get_array_expr ());
- auto rhs = visit_expr (*expr.get_index_expr ());
+ auto lhs = visit_expr (expr.get_array_expr ());
+ auto rhs = visit_expr (expr.get_index_expr ());
// The index is not tracked in BIR.
std::ignore = rhs;
return_place (ctx.place_db.lookup_or_add_path (Place::INDEX,
@@ -286,7 +287,7 @@ ExprStmtBuilder::visit (HIR::TupleExpr &expr)
void
ExprStmtBuilder::visit (HIR::TupleIndexExpr &expr)
{
- auto tuple = visit_expr (*expr.get_tuple_expr ());
+ auto tuple = visit_expr (expr.get_tuple_expr ());
return_place (ctx.place_db.lookup_or_add_path (Place::FIELD,
lookup_type (expr), tuple,
expr.get_tuple_index ()),
@@ -296,7 +297,7 @@ ExprStmtBuilder::visit (HIR::TupleIndexExpr &expr)
void
ExprStmtBuilder::visit (HIR::CallExpr &expr)
{
- PlaceId fn = visit_expr (*expr.get_fnexpr ());
+ PlaceId fn = visit_expr (expr.get_fnexpr ());
std::vector<PlaceId> arguments = visit_list (expr.get_arguments ());
const auto fn_type
@@ -330,7 +331,7 @@ ExprStmtBuilder::visit (HIR::MethodCallExpr &expr)
void
ExprStmtBuilder::visit (HIR::FieldAccessExpr &expr)
{
- auto receiver = visit_expr (*expr.get_receiver_expr ());
+ auto receiver = visit_expr (expr.get_receiver_expr ());
auto type = autoderef (receiver);
rust_assert (type->get_kind () == TyTy::ADT);
auto adt = type->as<TyTy::ADTType> ();
@@ -383,7 +384,7 @@ ExprStmtBuilder::visit (HIR::BlockExpr &block)
if (block.has_expr () && !unreachable)
{
push_assignment (block_ctx.label_var,
- visit_expr (*block.get_final_expr ()),
+ visit_expr (block.get_final_expr ()),
block.get_start_locus ());
}
if (!ctx.get_current_bb ().is_terminated ())
@@ -397,9 +398,9 @@ ExprStmtBuilder::visit (HIR::BlockExpr &block)
}
else if (block.has_expr () && !unreachable)
{
- return_place (visit_expr (*block.get_final_expr (),
+ return_place (visit_expr (block.get_final_expr (),
take_or_create_return_place (
- lookup_type (*block.get_final_expr ()))),
+ lookup_type (block.get_final_expr ()))),
block.get_start_locus ());
}
@@ -426,7 +427,7 @@ ExprStmtBuilder::visit (HIR::BreakExpr &brk)
LoopAndLabelCtx info = brk.has_label () ? get_label_ctx (brk.get_label ())
: get_unnamed_loop_ctx ();
if (brk.has_break_expr ())
- push_assignment (info.label_var, visit_expr (*brk.get_expr ()),
+ push_assignment (info.label_var, visit_expr (brk.get_expr ()),
brk.get_locus ());
start_new_consecutive_bb ();
@@ -438,8 +439,8 @@ ExprStmtBuilder::visit (HIR::BreakExpr &brk)
void
ExprStmtBuilder::visit (HIR::RangeFromToExpr &range)
{
- auto from = visit_expr (*range.get_from_expr ());
- auto to = visit_expr (*range.get_to_expr ());
+ auto from = visit_expr (range.get_from_expr ());
+ auto to = visit_expr (range.get_to_expr ());
return_expr (new InitializerExpr ({from, to}), lookup_type (range),
range.get_locus ());
}
@@ -447,7 +448,7 @@ ExprStmtBuilder::visit (HIR::RangeFromToExpr &range)
void
ExprStmtBuilder::visit (HIR::RangeFromExpr &expr)
{
- auto from = visit_expr (*expr.get_from_expr ());
+ auto from = visit_expr (expr.get_from_expr ());
return_expr (new InitializerExpr ({from}), lookup_type (expr),
expr.get_locus ());
}
@@ -455,7 +456,7 @@ ExprStmtBuilder::visit (HIR::RangeFromExpr &expr)
void
ExprStmtBuilder::visit (HIR::RangeToExpr &expr)
{
- auto to = visit_expr (*expr.get_to_expr ());
+ auto to = visit_expr (expr.get_to_expr ());
return_expr (new InitializerExpr ({to}), lookup_type (expr),
expr.get_locus ());
}
@@ -469,8 +470,8 @@ ExprStmtBuilder::visit (HIR::RangeFullExpr &expr)
void
ExprStmtBuilder::visit (HIR::RangeFromToInclExpr &expr)
{
- auto from = visit_expr (*expr.get_from_expr ());
- auto to = visit_expr (*expr.get_to_expr ());
+ auto from = visit_expr (expr.get_from_expr ());
+ auto to = visit_expr (expr.get_to_expr ());
return_expr (new InitializerExpr ({from, to}), lookup_type (expr),
expr.get_locus ());
}
@@ -478,7 +479,7 @@ ExprStmtBuilder::visit (HIR::RangeFromToInclExpr &expr)
void
ExprStmtBuilder::visit (HIR::RangeToInclExpr &expr)
{
- auto to = visit_expr (*expr.get_to_expr ());
+ auto to = visit_expr (expr.get_to_expr ());
return_expr (new InitializerExpr ({to}), lookup_type (expr),
expr.get_locus ());
}
@@ -489,9 +490,9 @@ ExprStmtBuilder::visit (HIR::ReturnExpr &ret)
if (ret.has_return_expr ())
{
push_assignment (RETURN_VALUE_PLACE,
- move_place (visit_expr (*ret.get_expr ()),
- ret.get_expr ()->get_locus ()),
- ret.get_expr ()->get_locus ());
+ move_place (visit_expr (ret.get_expr ()),
+ ret.get_expr ().get_locus ()),
+ ret.get_expr ().get_locus ());
}
unwind_until (ROOT_SCOPE);
push_return (ret.get_locus ());
@@ -509,7 +510,7 @@ ExprStmtBuilder::visit (HIR::LoopExpr &expr)
{
auto loop = setup_loop (expr);
- std::ignore = visit_expr (*expr.get_loop_block ());
+ std::ignore = visit_expr (expr.get_loop_block ());
if (!ctx.get_current_bb ().is_terminated ())
push_goto (loop.continue_bb);
@@ -521,12 +522,12 @@ ExprStmtBuilder::visit (HIR::WhileLoopExpr &expr)
{
auto loop = setup_loop (expr);
- auto cond_val = visit_expr (*expr.get_predicate_expr ());
+ auto cond_val = visit_expr (expr.get_predicate_expr ());
auto body_bb = new_bb ();
push_switch (cond_val, expr.get_locus (), {body_bb, loop.break_bb});
ctx.current_bb = body_bb;
- std::ignore = visit_expr (*expr.get_loop_block ());
+ std::ignore = visit_expr (expr.get_loop_block ());
push_goto (loop.continue_bb);
ctx.current_bb = loop.break_bb;
@@ -544,15 +545,15 @@ ExprStmtBuilder::visit (HIR::IfExpr &expr)
{
// If without else cannot return a non-unit value (see [E0317]).
- if (expr.get_if_block ()->statements.empty ())
+ if (expr.get_if_block ().statements.empty ())
return;
- push_switch (visit_expr (*expr.get_if_condition ()), expr.get_locus ());
+ push_switch (visit_expr (expr.get_if_condition ()), expr.get_locus ());
BasicBlockId if_block = ctx.current_bb;
ctx.current_bb = new_bb ();
BasicBlockId then_start_block = ctx.current_bb;
- std::ignore = visit_expr (*expr.get_if_block ());
+ std::ignore = visit_expr (expr.get_if_block ());
if (!ctx.get_current_bb ().is_terminated ())
push_goto (INVALID_BB); // Resolved later.
BasicBlockId then_end_block = ctx.current_bb;
@@ -573,8 +574,8 @@ ExprStmtBuilder::visit (HIR::IfExpr &expr)
void
ExprStmtBuilder::visit (HIR::IfExprConseqElse &expr)
{
- push_switch (move_place (visit_expr (*expr.get_if_condition ()),
- expr.get_if_condition ()->get_locus ()),
+ push_switch (move_place (visit_expr (expr.get_if_condition ()),
+ expr.get_if_condition ().get_locus ()),
expr.get_locus ());
BasicBlockId if_end_bb = ctx.current_bb;
@@ -582,14 +583,14 @@ ExprStmtBuilder::visit (HIR::IfExprConseqElse &expr)
ctx.current_bb = new_bb ();
BasicBlockId then_start_bb = ctx.current_bb;
- std::ignore = visit_expr (*expr.get_if_block (), result);
+ std::ignore = visit_expr (expr.get_if_block (), result);
if (!ctx.get_current_bb ().is_terminated ())
push_goto (INVALID_BB); // Resolved later.
BasicBlockId then_end_bb = ctx.current_bb;
ctx.current_bb = new_bb ();
BasicBlockId else_start_bb = ctx.current_bb;
- std::ignore = visit_expr (*expr.get_else_block (), result);
+ std::ignore = visit_expr (expr.get_else_block (), result);
if (!ctx.get_current_bb ().is_terminated ())
push_goto (INVALID_BB); // Resolved later.
BasicBlockId else_end_bb = ctx.current_bb;
@@ -690,35 +691,35 @@ ExprStmtBuilder::visit (HIR::LetStmt &stmt)
tl::optional<TyTy::BaseType *> type_annotation;
if (stmt.has_type ())
- type_annotation = lookup_type (*stmt.get_type ());
+ type_annotation = lookup_type (stmt.get_type ());
- if (stmt.get_pattern ()->get_pattern_type () == HIR::Pattern::IDENTIFIER)
+ if (stmt.get_pattern ().get_pattern_type () == HIR::Pattern::IDENTIFIER)
{
// Only if a pattern is just an identifier, no destructuring is needed.
// Hoverer PatternBindingBuilder cannot change existing temporary
// (init expr is evaluated before pattern binding) into a
// variable, so it would emit extra assignment.
- auto var = declare_variable (stmt.get_pattern ()->get_mappings ());
+ auto var = declare_variable (stmt.get_pattern ().get_mappings ());
if (stmt.has_type ())
- push_user_type_ascription (var, lookup_type (*stmt.get_type ()));
+ push_user_type_ascription (var, lookup_type (stmt.get_type ()));
if (stmt.has_init_expr ())
- std::ignore = visit_expr (*stmt.get_init_expr (), var);
+ std::ignore = visit_expr (stmt.get_init_expr (), var);
}
else
{
if (stmt.has_init_expr ())
- init = visit_expr (*stmt.get_init_expr ());
+ init = visit_expr (stmt.get_init_expr ());
PatternBindingBuilder (ctx, init, type_annotation)
- .go (*stmt.get_pattern ());
+ .go (stmt.get_pattern ());
}
}
void
ExprStmtBuilder::visit (HIR::ExprStmt &stmt)
{
- PlaceId result = visit_expr (*stmt.get_expr ());
+ PlaceId result = visit_expr (stmt.get_expr ());
// We must read the value for current liveness and we must not store it into
// the same place.
if (result != INVALID_PLACE)
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h b/gcc/rust/checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h
index 8c01c501c36..3bc622cda72 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h
@@ -63,16 +63,16 @@ public:
protected:
void visit (HIR::LazyBooleanExpr &expr) override
{
- auto lhs = visit_expr (*expr.get_lhs ());
- push_switch (move_place (lhs, expr.get_lhs ()->get_locus ()),
+ auto lhs = visit_expr (expr.get_lhs ());
+ push_switch (move_place (lhs, expr.get_lhs ().get_locus ()),
expr.get_locus (), {short_circuit_bb});
start_new_consecutive_bb ();
- return_place (visit_expr (*expr.get_rhs ()), expr.get_locus ());
+ return_place (visit_expr (expr.get_rhs ()), expr.get_locus ());
}
void visit (HIR::GroupedExpr &expr) override
{
- expr.get_expr_in_parens ()->accept_vis (*this);
+ expr.get_expr_in_parens ().accept_vis (*this);
}
protected:
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-builder-pattern.cc b/gcc/rust/checks/errors/borrowck/rust-bir-builder-pattern.cc
index 723ff7334b6..ee37bb09bc4 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-builder-pattern.cc
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-builder-pattern.cc
@@ -50,7 +50,7 @@ PatternBindingBuilder::visit (HIR::ReferencePattern &pattern)
return ty->as<TyTy::ReferenceType> ()->get_base ();
});
- pattern.get_referenced_pattern ()->accept_vis (*this);
+ pattern.get_referenced_pattern ().accept_vis (*this);
}
void
@@ -107,7 +107,7 @@ PatternBindingBuilder::visit (HIR::StructPattern &pattern)
init = init.map ([&] (PlaceId id) {
return ctx.place_db.lookup_or_add_path (
- Place::FIELD, lookup_type (*tuple->get_tuple_pattern ()), id,
+ Place::FIELD, lookup_type (tuple->get_tuple_pattern ()), id,
tuple->get_index ());
});
@@ -120,7 +120,7 @@ PatternBindingBuilder::visit (HIR::StructPattern &pattern)
->get_field_type ();
});
- tuple->get_tuple_pattern ()->accept_vis (*this);
+ tuple->get_tuple_pattern ().accept_vis (*this);
break;
}
case HIR::StructPatternField::IDENT_PAT: {
@@ -136,7 +136,7 @@ PatternBindingBuilder::visit (HIR::StructPattern &pattern)
field_ty->get_field_type (),
saved.init.value (),
field_index);
- ident_field->get_pattern ()->accept_vis (*this);
+ ident_field->get_pattern ().accept_vis (*this);
break;
}
case HIR::StructPatternField::IDENT: {
@@ -197,17 +197,17 @@ PatternBindingBuilder::visit (HIR::TuplePattern &pattern)
SavedState saved (this);
size_t index = 0;
- switch (pattern.get_items ()->get_item_type ())
+ switch (pattern.get_items ().get_item_type ())
{
case HIR::TuplePatternItems::MULTIPLE: {
auto &items = static_cast<HIR::TuplePatternItemsMultiple &> (
- *pattern.get_items ());
+ pattern.get_items ());
visit_tuple_fields (items.get_patterns (), saved, index);
break;
}
case HIR::TuplePatternItems::RANGED: {
auto &items
- = static_cast<HIR::TuplePatternItemsRanged &> (*pattern.get_items ());
+ = static_cast<HIR::TuplePatternItemsRanged &> (pattern.get_items ());
auto tyty = ctx.place_db[init.value ()].tyty;
rust_assert (tyty->get_kind () == TyTy::TUPLE);
@@ -242,11 +242,11 @@ PatternBindingBuilder::visit (HIR::TupleStructPattern &pattern)
});
size_t index = 0;
- switch (pattern.get_items ()->get_item_type ())
+ switch (pattern.get_items ().get_item_type ())
{
case HIR::TupleStructItems::RANGED: {
auto &items
- = static_cast<HIR::TupleStructItemsRange &> (*pattern.get_items ());
+ = static_cast<HIR::TupleStructItemsRange &> (pattern.get_items ());
rust_assert (type->get_kind () == TyTy::ADT);
auto adt_ty = static_cast<TyTy::ADTType *> (type);
@@ -263,7 +263,7 @@ PatternBindingBuilder::visit (HIR::TupleStructPattern &pattern)
}
case HIR::TupleStructItems::MULTIPLE: {
auto &items
- = static_cast<HIR::TupleStructItemsNoRange &> (*pattern.get_items ());
+ = static_cast<HIR::TupleStructItemsNoRange &> (pattern.get_items ());
visit_tuple_fields (items.get_patterns (), saved, index);
break;
}
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-builder-pattern.h b/gcc/rust/checks/errors/borrowck/rust-bir-builder-pattern.h
index 5d4b85a716d..33ecd2356c7 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-builder-pattern.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-builder-pattern.h
@@ -91,6 +91,7 @@ public:
void visit (HIR::QualifiedPathInExpression &expression) override {}
void visit (HIR::RangePattern &pattern) override {}
};
+
} // namespace BIR
} // namespace Rust
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-builder-struct.h b/gcc/rust/checks/errors/borrowck/rust-bir-builder-struct.h
index fefdd534cb1..18ddc19db1d 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-builder-struct.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-builder-struct.h
@@ -52,12 +52,12 @@ public:
}
void visit (HIR::StructExprFieldIdentifierValue &field) override
{
- auto value = ExprStmtBuilder (ctx).build (*field.get_value ());
+ auto value = ExprStmtBuilder (ctx).build (field.get_value ());
handle_named_field (field, value);
}
void visit (HIR::StructExprFieldIndexValue &field) override
{
- auto value = ExprStmtBuilder (ctx).build (*field.get_value ());
+ auto value = ExprStmtBuilder (ctx).build (field.get_value ());
coercion_site (value,
struct_ty->get_field_at_index (field.get_tuple_index ())
->get_field_type ());
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-builder.h b/gcc/rust/checks/errors/borrowck/rust-bir-builder.h
index 63d326278c7..e5bdb46b0be 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-builder.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-builder.h
@@ -49,7 +49,7 @@ public:
for (auto ¶m : function.get_function_params ())
handle_param (param);
- handle_body (*function.get_definition ());
+ handle_body (function.get_definition ());
auto region_hir_map
= map_region_to_hir (function.get_generic_params (), ctx.fn_free_regions);
@@ -118,14 +118,14 @@ private:
void handle_param (HIR::FunctionParam ¶m)
{
- auto param_type = lookup_type (*param.get_param_name ());
+ auto param_type = lookup_type (param.get_param_name ());
auto &pattern = param.get_param_name ();
- if (pattern->get_pattern_type () == HIR::Pattern::IDENTIFIER
- && !static_cast<HIR::IdentifierPattern &> (*pattern).get_is_ref ())
+ if (pattern.get_pattern_type () == HIR::Pattern::IDENTIFIER
+ && !static_cast<HIR::IdentifierPattern &> (pattern).get_is_ref ())
{
// Avoid useless temporary variable for parameter to look like MIR.
- translated = declare_variable (pattern->get_mappings ());
+ translated = declare_variable (pattern.get_mappings ());
ctx.arguments.push_back (translated);
}
else
@@ -133,11 +133,9 @@ private:
translated = ctx.place_db.add_temporary (param_type);
ctx.arguments.push_back (translated);
PatternBindingBuilder (ctx, translated, tl::nullopt)
- .go (*param.get_param_name ());
+ .go (param.get_param_name ());
}
- rust_assert (param.get_type () != nullptr);
-
// Set parameter place to use functions regions, not the fresh ones.
ctx.place_db[translated].regions
= bind_regions (Resolver::TypeCheckContext::get ()
@@ -159,7 +157,7 @@ private:
body.get_end_locus ());
}
auto return_location = body.has_expr ()
- ? body.get_final_expr ()->get_locus ()
+ ? body.get_final_expr ().get_locus ()
: body.get_end_locus ();
push_return (return_location);
}
diff --git a/gcc/rust/checks/errors/borrowck/rust-function-collector.h b/gcc/rust/checks/errors/borrowck/rust-function-collector.h
index bea438c5445..5de503d441c 100644
--- a/gcc/rust/checks/errors/borrowck/rust-function-collector.h
+++ b/gcc/rust/checks/errors/borrowck/rust-function-collector.h
@@ -56,13 +56,13 @@ protected:
void visit (HIR::Function &function) override
{
functions.push_back (&function);
- function.get_definition ()->accept_vis (*this);
+ function.get_definition ().accept_vis (*this);
}
void visit (HIR::ClosureExpr &closure) override
{
closures.push_back (&closure);
- closure.get_expr ()->accept_vis (*this);
+ closure.get_expr ().accept_vis (*this);
}
// TODO: recurse for nested closures and functions.
diff --git a/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc b/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc
index fa2de9c3f40..3cbf47ecc8b 100644
--- a/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc
+++ b/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc
@@ -267,16 +267,13 @@ PrivacyReporter::check_base_type_privacy (Analysis::NodeMapping &node_mappings,
}
void
-PrivacyReporter::check_type_privacy (const HIR::Type *type)
+PrivacyReporter::check_type_privacy (const HIR::Type &type)
{
- rust_assert (type);
-
TyTy::BaseType *lookup = nullptr;
- rust_assert (
- ty_ctx.lookup_type (type->get_mappings ().get_hirid (), &lookup));
+ rust_assert (ty_ctx.lookup_type (type.get_mappings ().get_hirid (), &lookup));
- auto node_mappings = type->get_mappings ();
- return check_base_type_privacy (node_mappings, lookup, type->get_locus ());
+ auto node_mappings = type.get_mappings ();
+ return check_base_type_privacy (node_mappings, lookup, type.get_locus ());
}
void
@@ -326,100 +323,98 @@ PrivacyReporter::visit (HIR::LiteralExpr &)
void
PrivacyReporter::visit (HIR::BorrowExpr &expr)
{
- expr.get_expr ()->accept_vis (*this);
+ expr.get_expr ().accept_vis (*this);
}
void
PrivacyReporter::visit (HIR::DereferenceExpr &expr)
{
- expr.get_expr ()->accept_vis (*this);
+ expr.get_expr ().accept_vis (*this);
}
void
PrivacyReporter::visit (HIR::ErrorPropagationExpr &expr)
{
- expr.get_expr ()->accept_vis (*this);
+ expr.get_expr ().accept_vis (*this);
}
void
PrivacyReporter::visit (HIR::NegationExpr &expr)
{
- expr.get_expr ()->accept_vis (*this);
+ expr.get_expr ().accept_vis (*this);
}
void
PrivacyReporter::visit (HIR::ArithmeticOrLogicalExpr &expr)
{
- expr.get_lhs ()->accept_vis (*this);
- expr.get_rhs ()->accept_vis (*this);
+ expr.get_lhs ().accept_vis (*this);
+ expr.get_rhs ().accept_vis (*this);
}
void
PrivacyReporter::visit (HIR::ComparisonExpr &expr)
{
- expr.get_lhs ()->accept_vis (*this);
- expr.get_rhs ()->accept_vis (*this);
+ expr.get_lhs ().accept_vis (*this);
+ expr.get_rhs ().accept_vis (*this);
}
void
PrivacyReporter::visit (HIR::LazyBooleanExpr &expr)
{
- expr.get_lhs ()->accept_vis (*this);
- expr.get_rhs ()->accept_vis (*this);
+ expr.get_lhs ().accept_vis (*this);
+ expr.get_rhs ().accept_vis (*this);
}
void
PrivacyReporter::visit (HIR::TypeCastExpr &expr)
{
- expr.get_expr ()->accept_vis (*this);
+ expr.get_expr ().accept_vis (*this);
}
void
PrivacyReporter::visit (HIR::AssignmentExpr &expr)
{
- expr.get_lhs ()->accept_vis (*this);
- expr.get_rhs ()->accept_vis (*this);
+ expr.get_lhs ().accept_vis (*this);
+ expr.get_rhs ().accept_vis (*this);
}
void
PrivacyReporter::visit (HIR::CompoundAssignmentExpr &expr)
{
- expr.get_lhs ()->accept_vis (*this);
- expr.get_rhs ()->accept_vis (*this);
+ expr.get_lhs ().accept_vis (*this);
+ expr.get_rhs ().accept_vis (*this);
}
void
PrivacyReporter::visit (HIR::GroupedExpr &expr)
{
- expr.get_expr_in_parens ()->accept_vis (*this);
+ expr.get_expr_in_parens ().accept_vis (*this);
}
void
PrivacyReporter::visit (HIR::ArrayExpr &expr)
{
- HIR::ArrayElems &elements = *expr.get_internal_elements ();
+ HIR::ArrayElems &elements = expr.get_internal_elements ();
switch (elements.get_array_expr_type ())
{
case HIR::ArrayElems::ArrayExprType::VALUES: {
- HIR::ArrayElemsValues &elems
- = static_cast<HIR::ArrayElemsValues &> (elements);
+ auto &elems = static_cast<HIR::ArrayElemsValues &> (elements);
for (auto &value : elems.get_values ())
value->accept_vis (*this);
}
return;
case HIR::ArrayElems::ArrayExprType::COPIED:
- HIR::ArrayElemsCopied &elems
- = static_cast<HIR::ArrayElemsCopied &> (elements);
- elems.get_elem_to_copy ()->accept_vis (*this);
+ auto &elems = static_cast<HIR::ArrayElemsCopied &> (elements);
+ elems.get_elem_to_copy ().accept_vis (*this);
}
}
void
PrivacyReporter::visit (HIR::ArrayIndexExpr &expr)
{
- expr.get_array_expr ()->accept_vis (*this);
- expr.get_index_expr ()->accept_vis (*this);
+ expr.get_array_expr ().accept_vis (*this);
+ expr.get_index_expr ().accept_vis (*this);
}
void
@@ -432,7 +427,7 @@ PrivacyReporter::visit (HIR::TupleExpr &expr)
void
PrivacyReporter::visit (HIR::TupleIndexExpr &expr)
{
- expr.get_tuple_expr ()->accept_vis (*this);
+ expr.get_tuple_expr ().accept_vis (*this);
}
void
@@ -448,13 +443,13 @@ PrivacyReporter::visit (HIR::StructExprFieldIdentifier &)
void
PrivacyReporter::visit (HIR::StructExprFieldIdentifierValue &field)
{
- field.get_value ()->accept_vis (*this);
+ field.get_value ().accept_vis (*this);
}
void
PrivacyReporter::visit (HIR::StructExprFieldIndexValue &field)
{
- field.get_value ()->accept_vis (*this);
+ field.get_value ().accept_vis (*this);
}
void
@@ -467,7 +462,7 @@ PrivacyReporter::visit (HIR::StructExprStructFields &expr)
void
PrivacyReporter::visit (HIR::CallExpr &expr)
{
- expr.get_fnexpr ()->accept_vis (*this);
+ expr.get_fnexpr ().accept_vis (*this);
for (auto ¶m : expr.get_arguments ())
param->accept_vis (*this);
@@ -476,7 +471,7 @@ PrivacyReporter::visit (HIR::CallExpr &expr)
void
PrivacyReporter::visit (HIR::MethodCallExpr &expr)
{
- expr.get_receiver ()->accept_vis (*this);
+ expr.get_receiver ().accept_vis (*this);
for (auto ¶m : expr.get_arguments ())
param->accept_vis (*this);
@@ -485,7 +480,7 @@ PrivacyReporter::visit (HIR::MethodCallExpr &expr)
void
PrivacyReporter::visit (HIR::FieldAccessExpr &expr)
{
- expr.get_receiver_expr ()->accept_vis (*this);
+ expr.get_receiver_expr ().accept_vis (*this);
// FIXME: We should also check if the field is public?
}
@@ -503,8 +498,7 @@ PrivacyReporter::visit (HIR::BlockExpr &expr)
stmt->accept_vis (*this);
auto &last_expr = expr.get_final_expr ();
- if (last_expr)
- last_expr->accept_vis (*this);
+ last_expr.accept_vis (*this);
}
void
@@ -515,27 +509,26 @@ void
PrivacyReporter::visit (HIR::BreakExpr &expr)
{
auto &break_expr = expr.get_expr ();
- if (break_expr)
- break_expr->accept_vis (*this);
+ break_expr.accept_vis (*this);
}
void
PrivacyReporter::visit (HIR::RangeFromToExpr &expr)
{
- expr.get_from_expr ()->accept_vis (*this);
- expr.get_to_expr ()->accept_vis (*this);
+ expr.get_from_expr ().accept_vis (*this);
+ expr.get_to_expr ().accept_vis (*this);
}
void
PrivacyReporter::visit (HIR::RangeFromExpr &expr)
{
- expr.get_from_expr ()->accept_vis (*this);
+ expr.get_from_expr ().accept_vis (*this);
}
void
PrivacyReporter::visit (HIR::RangeToExpr &expr)
{
- expr.get_to_expr ()->accept_vis (*this);
+ expr.get_to_expr ().accept_vis (*this);
}
void
@@ -545,8 +538,8 @@ PrivacyReporter::visit (HIR::RangeFullExpr &)
void
PrivacyReporter::visit (HIR::RangeFromToInclExpr &expr)
{
- expr.get_from_expr ()->accept_vis (*this);
- expr.get_to_expr ()->accept_vis (*this);
+ expr.get_from_expr ().accept_vis (*this);
+ expr.get_to_expr ().accept_vis (*this);
}
void
@@ -558,55 +551,54 @@ PrivacyReporter::visit (HIR::RangeToInclExpr &)
void
PrivacyReporter::visit (HIR::ReturnExpr &expr)
{
- if (expr.get_expr ())
- expr.get_expr ()->accept_vis (*this);
+ expr.get_expr ().accept_vis (*this);
}
void
PrivacyReporter::visit (HIR::UnsafeBlockExpr &expr)
{
- expr.get_block_expr ()->accept_vis (*this);
+ expr.get_block_expr ().accept_vis (*this);
}
void
PrivacyReporter::visit (HIR::LoopExpr &expr)
{
- expr.get_loop_block ()->accept_vis (*this);
+ expr.get_loop_block ().accept_vis (*this);
}
void
PrivacyReporter::visit (HIR::WhileLoopExpr &expr)
{
- expr.get_predicate_expr ()->accept_vis (*this);
- expr.get_loop_block ()->accept_vis (*this);
+ expr.get_predicate_expr ().accept_vis (*this);
+ expr.get_loop_block ().accept_vis (*this);
}
void
PrivacyReporter::visit (HIR::WhileLetLoopExpr &expr)
{
- expr.get_cond ()->accept_vis (*this);
- expr.get_loop_block ()->accept_vis (*this);
+ expr.get_cond ().accept_vis (*this);
+ expr.get_loop_block ().accept_vis (*this);
}
void
PrivacyReporter::visit (HIR::IfExpr &expr)
{
- expr.get_if_condition ()->accept_vis (*this);
- expr.get_if_block ()->accept_vis (*this);
+ expr.get_if_condition ().accept_vis (*this);
+ expr.get_if_block ().accept_vis (*this);
}
void
PrivacyReporter::visit (HIR::IfExprConseqElse &expr)
{
- expr.get_if_condition ()->accept_vis (*this);
- expr.get_if_block ()->accept_vis (*this);
- expr.get_else_block ()->accept_vis (*this);
+ expr.get_if_condition ().accept_vis (*this);
+ expr.get_if_block ().accept_vis (*this);
+ expr.get_else_block ().accept_vis (*this);
}
void
PrivacyReporter::visit (HIR::MatchExpr &expr)
{
- expr.get_scrutinee_expr ()->accept_vis (*this);
+ expr.get_scrutinee_expr ().accept_vis (*this);
}
void
@@ -649,9 +641,9 @@ void
PrivacyReporter::visit (HIR::Function &function)
{
for (auto ¶m : function.get_function_params ())
- check_type_privacy (param.get_type ().get ());
+ check_type_privacy (param.get_type ());
- function.get_definition ()->accept_vis (*this);
+ function.get_definition ().accept_vis (*this);
}
void
@@ -708,14 +700,14 @@ void
PrivacyReporter::visit (HIR::ConstantItem &const_item)
{
// TODO: We need to visit the type
- const_item.get_expr ()->accept_vis (*this);
+ const_item.get_expr ().accept_vis (*this);
}
void
PrivacyReporter::visit (HIR::StaticItem &static_item)
{
// TODO: We need to visit the type
- static_item.get_expr ()->accept_vis (*this);
+ static_item.get_expr ().accept_vis (*this);
}
void
@@ -748,17 +740,15 @@ PrivacyReporter::visit (HIR::EmptyStmt &)
void
PrivacyReporter::visit (HIR::LetStmt &stmt)
{
- if (stmt.get_type ())
- check_type_privacy (stmt.get_type ().get ());
+ check_type_privacy (stmt.get_type ());
- if (stmt.get_init_expr ())
- stmt.get_init_expr ()->accept_vis (*this);
+ stmt.get_init_expr ().accept_vis (*this);
}
void
PrivacyReporter::visit (HIR::ExprStmt &stmt)
{
- stmt.get_expr ()->accept_vis (*this);
+ stmt.get_expr ().accept_vis (*this);
}
} // namespace Privacy
diff --git a/gcc/rust/checks/errors/privacy/rust-privacy-reporter.h b/gcc/rust/checks/errors/privacy/rust-privacy-reporter.h
index b9cc230d5db..5111a3e656d 100644
--- a/gcc/rust/checks/errors/privacy/rust-privacy-reporter.h
+++ b/gcc/rust/checks/errors/privacy/rust-privacy-reporter.h
@@ -75,7 +75,7 @@ types
* @param type Reference to an explicit type used in a statement, expression
* or parameter
*/
- void check_type_privacy (const HIR::Type *type);
+ void check_type_privacy (const HIR::Type &type);
virtual void visit (HIR::StructExprFieldIdentifier &field);
virtual void visit (HIR::StructExprFieldIdentifierValue &field);
diff --git a/gcc/rust/checks/errors/privacy/rust-reachability.cc b/gcc/rust/checks/errors/privacy/rust-reachability.cc
index 9e0cb821814..1e57674b402 100644
--- a/gcc/rust/checks/errors/privacy/rust-reachability.cc
+++ b/gcc/rust/checks/errors/privacy/rust-reachability.cc
@@ -132,7 +132,7 @@ ReachabilityVisitor::visit (HIR::StructStruct &struct_item)
{
for (auto &field : struct_item.get_fields ())
if (field.get_visibility ().is_public ())
- ctx.update_reachability (field.get_field_type ()->get_mappings (),
+ ctx.update_reachability (field.get_field_type ().get_mappings (),
struct_reach);
}
diff --git a/gcc/rust/checks/errors/rust-const-checker.cc b/gcc/rust/checks/errors/rust-const-checker.cc
index 1e0ebd29798..420db8fb8b2 100644
--- a/gcc/rust/checks/errors/rust-const-checker.cc
+++ b/gcc/rust/checks/errors/rust-const-checker.cc
@@ -161,72 +161,72 @@ ConstChecker::visit (LiteralExpr &)
void
ConstChecker::visit (BorrowExpr &expr)
{
- expr.get_expr ()->accept_vis (*this);
+ expr.get_expr ().accept_vis (*this);
}
void
ConstChecker::visit (DereferenceExpr &expr)
{
- expr.get_expr ()->accept_vis (*this);
+ expr.get_expr ().accept_vis (*this);
}
void
ConstChecker::visit (ErrorPropagationExpr &expr)
{
- expr.get_expr ()->accept_vis (*this);
+ expr.get_expr ().accept_vis (*this);
}
void
ConstChecker::visit (NegationExpr &expr)
{
- expr.get_expr ()->accept_vis (*this);
+ expr.get_expr ().accept_vis (*this);
}
void
ConstChecker::visit (ArithmeticOrLogicalExpr &expr)
{
- expr.get_lhs ()->accept_vis (*this);
- expr.get_rhs ()->accept_vis (*this);
+ expr.get_lhs ().accept_vis (*this);
+ expr.get_rhs ().accept_vis (*this);
}
void
ConstChecker::visit (ComparisonExpr &expr)
{
- expr.get_lhs ()->accept_vis (*this);
- expr.get_rhs ()->accept_vis (*this);
+ expr.get_lhs ().accept_vis (*this);
+ expr.get_rhs ().accept_vis (*this);
}
void
ConstChecker::visit (LazyBooleanExpr &expr)
{
- expr.get_lhs ()->accept_vis (*this);
- expr.get_rhs ()->accept_vis (*this);
+ expr.get_lhs ().accept_vis (*this);
+ expr.get_rhs ().accept_vis (*this);
}
void
ConstChecker::visit (TypeCastExpr &expr)
{
- expr.get_expr ()->accept_vis (*this);
+ expr.get_expr ().accept_vis (*this);
}
void
ConstChecker::visit (AssignmentExpr &expr)
{
- expr.get_lhs ()->accept_vis (*this);
- expr.get_rhs ()->accept_vis (*this);
+ expr.get_lhs ().accept_vis (*this);
+ expr.get_rhs ().accept_vis (*this);
}
void
ConstChecker::visit (CompoundAssignmentExpr &expr)
{
- expr.get_lhs ()->accept_vis (*this);
- expr.get_rhs ()->accept_vis (*this);
+ expr.get_lhs ().accept_vis (*this);
+ expr.get_rhs ().accept_vis (*this);
}
void
ConstChecker::visit (GroupedExpr &expr)
{
- expr.get_expr_in_parens ()->accept_vis (*this);
+ expr.get_expr_in_parens ().accept_vis (*this);
}
void
@@ -239,11 +239,11 @@ ConstChecker::visit (ArrayElemsValues &elems)
void
ConstChecker::visit (ArrayElemsCopied &elems)
{
- elems.get_elem_to_copy ()->accept_vis (*this);
+ elems.get_elem_to_copy ().accept_vis (*this);
const_context.enter (elems.get_mappings ().get_hirid ());
- elems.get_num_copies_expr ()->accept_vis (*this);
+ elems.get_num_copies_expr ().accept_vis (*this);
const_context.exit ();
}
@@ -251,14 +251,14 @@ ConstChecker::visit (ArrayElemsCopied &elems)
void
ConstChecker::visit (ArrayExpr &expr)
{
- expr.get_internal_elements ()->accept_vis (*this);
+ expr.get_internal_elements ().accept_vis (*this);
}
void
ConstChecker::visit (ArrayIndexExpr &expr)
{
- expr.get_array_expr ()->accept_vis (*this);
- expr.get_index_expr ()->accept_vis (*this);
+ expr.get_array_expr ().accept_vis (*this);
+ expr.get_index_expr ().accept_vis (*this);
}
void
@@ -271,7 +271,7 @@ ConstChecker::visit (TupleExpr &expr)
void
ConstChecker::visit (TupleIndexExpr &expr)
{
- expr.get_tuple_expr ()->accept_vis (*this);
+ expr.get_tuple_expr ().accept_vis (*this);
}
void
@@ -285,13 +285,13 @@ ConstChecker::visit (StructExprFieldIdentifier &)
void
ConstChecker::visit (StructExprFieldIdentifierValue &field)
{
- field.get_value ()->accept_vis (*this);
+ field.get_value ().accept_vis (*this);
}
void
ConstChecker::visit (StructExprFieldIndexValue &field)
{
- field.get_value ()->accept_vis (*this);
+ field.get_value ().accept_vis (*this);
}
void
@@ -352,10 +352,10 @@ ConstChecker::check_function_call (HirId fn_id, location_t locus)
void
ConstChecker::visit (CallExpr &expr)
{
- if (!expr.get_fnexpr ())
+ if (!expr.has_fnexpr ())
return;
- NodeId ast_node_id = expr.get_fnexpr ()->get_mappings ().get_nodeid ();
+ NodeId ast_node_id = expr.get_fnexpr ().get_mappings ().get_nodeid ();
NodeId ref_node_id;
if (flag_name_resolution_2_0)
@@ -388,7 +388,7 @@ ConstChecker::visit (CallExpr &expr)
void
ConstChecker::visit (MethodCallExpr &expr)
{
- expr.get_receiver ()->accept_vis (*this);
+ expr.get_receiver ().accept_vis (*this);
for (auto &arg : expr.get_arguments ())
arg->accept_vis (*this);
@@ -397,13 +397,13 @@ ConstChecker::visit (MethodCallExpr &expr)
void
ConstChecker::visit (FieldAccessExpr &expr)
{
- expr.get_receiver_expr ()->accept_vis (*this);
+ expr.get_receiver_expr ().accept_vis (*this);
}
void
ConstChecker::visit (ClosureExpr &expr)
{
- expr.get_expr ()->accept_vis (*this);
+ expr.get_expr ().accept_vis (*this);
}
void
@@ -413,7 +413,7 @@ ConstChecker::visit (BlockExpr &expr)
stmt->accept_vis (*this);
if (expr.has_expr ())
- expr.get_final_expr ()->accept_vis (*this);
+ expr.get_final_expr ().accept_vis (*this);
}
void
@@ -424,26 +424,26 @@ void
ConstChecker::visit (BreakExpr &expr)
{
if (expr.has_break_expr ())
- expr.get_expr ()->accept_vis (*this);
+ expr.get_expr ().accept_vis (*this);
}
void
ConstChecker::visit (RangeFromToExpr &expr)
{
- expr.get_from_expr ()->accept_vis (*this);
- expr.get_to_expr ()->accept_vis (*this);
+ expr.get_from_expr ().accept_vis (*this);
+ expr.get_to_expr ().accept_vis (*this);
}
void
ConstChecker::visit (RangeFromExpr &expr)
{
- expr.get_from_expr ()->accept_vis (*this);
+ expr.get_from_expr ().accept_vis (*this);
}
void
ConstChecker::visit (RangeToExpr &expr)
{
- expr.get_to_expr ()->accept_vis (*this);
+ expr.get_to_expr ().accept_vis (*this);
}
void
@@ -453,8 +453,8 @@ ConstChecker::visit (RangeFullExpr &)
void
ConstChecker::visit (RangeFromToInclExpr &expr)
{
- expr.get_from_expr ()->accept_vis (*this);
- expr.get_to_expr ()->accept_vis (*this);
+ expr.get_from_expr ().accept_vis (*this);
+ expr.get_to_expr ().accept_vis (*this);
}
void
@@ -467,57 +467,57 @@ void
ConstChecker::visit (ReturnExpr &expr)
{
if (expr.has_return_expr ())
- expr.get_expr ()->accept_vis (*this);
+ expr.get_expr ().accept_vis (*this);
}
void
ConstChecker::visit (UnsafeBlockExpr &expr)
{
- expr.get_block_expr ()->accept_vis (*this);
+ expr.get_block_expr ().accept_vis (*this);
}
void
ConstChecker::visit (LoopExpr &expr)
{
- expr.get_loop_block ()->accept_vis (*this);
+ expr.get_loop_block ().accept_vis (*this);
}
void
ConstChecker::visit (WhileLoopExpr &expr)
{
- expr.get_predicate_expr ()->accept_vis (*this);
- expr.get_loop_block ()->accept_vis (*this);
+ expr.get_predicate_expr ().accept_vis (*this);
+ expr.get_loop_block ().accept_vis (*this);
}
void
ConstChecker::visit (WhileLetLoopExpr &expr)
{
- expr.get_cond ()->accept_vis (*this);
- expr.get_loop_block ()->accept_vis (*this);
+ expr.get_cond ().accept_vis (*this);
+ expr.get_loop_block ().accept_vis (*this);
}
void
ConstChecker::visit (IfExpr &expr)
{
- expr.get_if_condition ()->accept_vis (*this);
- expr.get_if_block ()->accept_vis (*this);
+ expr.get_if_condition ().accept_vis (*this);
+ expr.get_if_block ().accept_vis (*this);
}
void
ConstChecker::visit (IfExprConseqElse &expr)
{
- expr.get_if_condition ()->accept_vis (*this);
- expr.get_if_block ()->accept_vis (*this);
- expr.get_else_block ()->accept_vis (*this);
+ expr.get_if_condition ().accept_vis (*this);
+ expr.get_if_block ().accept_vis (*this);
+ expr.get_else_block ().accept_vis (*this);
}
void
ConstChecker::visit (MatchExpr &expr)
{
- expr.get_scrutinee_expr ()->accept_vis (*this);
+ expr.get_scrutinee_expr ().accept_vis (*this);
for (auto &match_arm : expr.get_match_cases ())
- match_arm.get_expr ()->accept_vis (*this);
+ match_arm.get_expr ().accept_vis (*this);
}
void
@@ -590,9 +590,9 @@ ConstChecker::visit (Function &function)
ConstGenericCtx::Function);
for (auto ¶m : function.get_function_params ())
- param.get_type ()->accept_vis (*this);
+ param.get_type ().accept_vis (*this);
- function.get_definition ()->accept_vis (*this);
+ function.get_definition ().accept_vis (*this);
if (const_fn)
const_context.exit ();
@@ -636,7 +636,7 @@ ConstChecker::visit (EnumItemDiscriminant &item)
{
const_context.enter (item.get_mappings ().get_hirid ());
- item.get_discriminant_expression ()->accept_vis (*this);
+ item.get_discriminant_expression ().accept_vis (*this);
const_context.exit ();
}
@@ -660,7 +660,7 @@ ConstChecker::visit (ConstantItem &const_item)
{
const_context.enter (const_item.get_mappings ().get_hirid ());
- const_item.get_expr ()->accept_vis (*this);
+ const_item.get_expr ().accept_vis (*this);
const_context.exit ();
}
@@ -670,7 +670,7 @@ ConstChecker::visit (StaticItem &static_item)
{
const_context.enter (static_item.get_mappings ().get_hirid ());
- static_item.get_expr ()->accept_vis (*this);
+ static_item.get_expr ().accept_vis (*this);
const_context.exit ();
}
@@ -679,14 +679,14 @@ void
ConstChecker::visit (TraitItemFunc &item)
{
if (item.has_block_defined ())
- item.get_block_expr ()->accept_vis (*this);
+ item.get_block_expr ().accept_vis (*this);
}
void
ConstChecker::visit (TraitItemConst &item)
{
if (item.has_expr ())
- item.get_expr ()->accept_vis (*this);
+ item.get_expr ().accept_vis (*this);
}
void
@@ -821,13 +821,13 @@ void
ConstChecker::visit (LetStmt &stmt)
{
if (stmt.has_init_expr ())
- stmt.get_init_expr ()->accept_vis (*this);
+ stmt.get_init_expr ().accept_vis (*this);
}
void
ConstChecker::visit (ExprStmt &stmt)
{
- stmt.get_expr ()->accept_vis (*this);
+ stmt.get_expr ().accept_vis (*this);
}
void
@@ -875,7 +875,7 @@ ConstChecker::visit (ArrayType &type)
{
const_context.enter (type.get_mappings ().get_hirid ());
- type.get_size_expr ()->accept_vis (*this);
+ type.get_size_expr ().accept_vis (*this);
const_context.exit ();
}
diff --git a/gcc/rust/checks/errors/rust-hir-pattern-analysis.cc b/gcc/rust/checks/errors/rust-hir-pattern-analysis.cc
index 8fb795b7b83..617d754c181 100644
--- a/gcc/rust/checks/errors/rust-hir-pattern-analysis.cc
+++ b/gcc/rust/checks/errors/rust-hir-pattern-analysis.cc
@@ -92,72 +92,72 @@ PatternChecker::visit (LiteralExpr &)
void
PatternChecker::visit (BorrowExpr &expr)
{
- expr.get_expr ()->accept_vis (*this);
+ expr.get_expr ().accept_vis (*this);
}
void
PatternChecker::visit (DereferenceExpr &expr)
{
- expr.get_expr ()->accept_vis (*this);
+ expr.get_expr ().accept_vis (*this);
}
void
PatternChecker::visit (ErrorPropagationExpr &expr)
{
- expr.get_expr ()->accept_vis (*this);
+ expr.get_expr ().accept_vis (*this);
}
void
PatternChecker::visit (NegationExpr &expr)
{
- expr.get_expr ()->accept_vis (*this);
+ expr.get_expr ().accept_vis (*this);
}
void
PatternChecker::visit (ArithmeticOrLogicalExpr &expr)
{
- expr.get_lhs ()->accept_vis (*this);
- expr.get_rhs ()->accept_vis (*this);
+ expr.get_lhs ().accept_vis (*this);
+ expr.get_rhs ().accept_vis (*this);
}
void
PatternChecker::visit (ComparisonExpr &expr)
{
- expr.get_lhs ()->accept_vis (*this);
- expr.get_rhs ()->accept_vis (*this);
+ expr.get_lhs ().accept_vis (*this);
+ expr.get_rhs ().accept_vis (*this);
}
void
PatternChecker::visit (LazyBooleanExpr &expr)
{
- expr.get_lhs ()->accept_vis (*this);
- expr.get_rhs ()->accept_vis (*this);
+ expr.get_lhs ().accept_vis (*this);
+ expr.get_rhs ().accept_vis (*this);
}
void
PatternChecker::visit (TypeCastExpr &expr)
{
- expr.get_expr ()->accept_vis (*this);
+ expr.get_expr ().accept_vis (*this);
}
void
PatternChecker::visit (AssignmentExpr &expr)
{
- expr.get_lhs ()->accept_vis (*this);
- expr.get_rhs ()->accept_vis (*this);
+ expr.get_lhs ().accept_vis (*this);
+ expr.get_rhs ().accept_vis (*this);
}
void
PatternChecker::visit (CompoundAssignmentExpr &expr)
{
- expr.get_lhs ()->accept_vis (*this);
- expr.get_rhs ()->accept_vis (*this);
+ expr.get_lhs ().accept_vis (*this);
+ expr.get_rhs ().accept_vis (*this);
}
void
PatternChecker::visit (GroupedExpr &expr)
{
- expr.get_expr_in_parens ()->accept_vis (*this);
+ expr.get_expr_in_parens ().accept_vis (*this);
}
void
@@ -170,20 +170,20 @@ PatternChecker::visit (ArrayElemsValues &elems)
void
PatternChecker::visit (ArrayElemsCopied &elems)
{
- elems.get_elem_to_copy ()->accept_vis (*this);
+ elems.get_elem_to_copy ().accept_vis (*this);
}
void
PatternChecker::visit (ArrayExpr &expr)
{
- expr.get_internal_elements ()->accept_vis (*this);
+ expr.get_internal_elements ().accept_vis (*this);
}
void
PatternChecker::visit (ArrayIndexExpr &expr)
{
- expr.get_array_expr ()->accept_vis (*this);
- expr.get_index_expr ()->accept_vis (*this);
+ expr.get_array_expr ().accept_vis (*this);
+ expr.get_index_expr ().accept_vis (*this);
}
void
@@ -196,7 +196,7 @@ PatternChecker::visit (TupleExpr &expr)
void
PatternChecker::visit (TupleIndexExpr &expr)
{
- expr.get_tuple_expr ()->accept_vis (*this);
+ expr.get_tuple_expr ().accept_vis (*this);
}
void
@@ -210,13 +210,13 @@ PatternChecker::visit (StructExprFieldIdentifier &)
void
PatternChecker::visit (StructExprFieldIdentifierValue &field)
{
- field.get_value ()->accept_vis (*this);
+ field.get_value ().accept_vis (*this);
}
void
PatternChecker::visit (StructExprFieldIndexValue &field)
{
- field.get_value ()->accept_vis (*this);
+ field.get_value ().accept_vis (*this);
}
void
@@ -233,10 +233,10 @@ PatternChecker::visit (StructExprStructBase &)
void
PatternChecker::visit (CallExpr &expr)
{
- if (!expr.get_fnexpr ())
+ if (!expr.has_fnexpr ())
return;
- NodeId ast_node_id = expr.get_fnexpr ()->get_mappings ().get_nodeid ();
+ NodeId ast_node_id = expr.get_fnexpr ().get_mappings ().get_nodeid ();
NodeId ref_node_id;
if (flag_name_resolution_2_0)
{
@@ -266,7 +266,7 @@ PatternChecker::visit (CallExpr &expr)
void
PatternChecker::visit (MethodCallExpr &expr)
{
- expr.get_receiver ()->accept_vis (*this);
+ expr.get_receiver ().accept_vis (*this);
for (auto &arg : expr.get_arguments ())
arg->accept_vis (*this);
@@ -275,13 +275,13 @@ PatternChecker::visit (MethodCallExpr &expr)
void
PatternChecker::visit (FieldAccessExpr &expr)
{
- expr.get_receiver_expr ()->accept_vis (*this);
+ expr.get_receiver_expr ().accept_vis (*this);
}
void
PatternChecker::visit (ClosureExpr &expr)
{
- expr.get_expr ()->accept_vis (*this);
+ expr.get_expr ().accept_vis (*this);
}
void
@@ -291,7 +291,7 @@ PatternChecker::visit (BlockExpr &expr)
stmt->accept_vis (*this);
if (expr.has_expr ())
- expr.get_final_expr ()->accept_vis (*this);
+ expr.get_final_expr ().accept_vis (*this);
}
void
@@ -302,26 +302,26 @@ void
PatternChecker::visit (BreakExpr &expr)
{
if (expr.has_break_expr ())
- expr.get_expr ()->accept_vis (*this);
+ expr.get_expr ().accept_vis (*this);
}
void
PatternChecker::visit (RangeFromToExpr &expr)
{
- expr.get_from_expr ()->accept_vis (*this);
- expr.get_to_expr ()->accept_vis (*this);
+ expr.get_from_expr ().accept_vis (*this);
+ expr.get_to_expr ().accept_vis (*this);
}
void
PatternChecker::visit (RangeFromExpr &expr)
{
- expr.get_from_expr ()->accept_vis (*this);
+ expr.get_from_expr ().accept_vis (*this);
}
void
PatternChecker::visit (RangeToExpr &expr)
{
- expr.get_to_expr ()->accept_vis (*this);
+ expr.get_to_expr ().accept_vis (*this);
}
void
@@ -331,76 +331,76 @@ PatternChecker::visit (RangeFullExpr &)
void
PatternChecker::visit (RangeFromToInclExpr &expr)
{
- expr.get_from_expr ()->accept_vis (*this);
- expr.get_to_expr ()->accept_vis (*this);
+ expr.get_from_expr ().accept_vis (*this);
+ expr.get_to_expr ().accept_vis (*this);
}
void
PatternChecker::visit (RangeToInclExpr &expr)
{
- expr.get_to_expr ()->accept_vis (*this);
+ expr.get_to_expr ().accept_vis (*this);
}
void
PatternChecker::visit (ReturnExpr &expr)
{
if (expr.has_return_expr ())
- expr.get_expr ()->accept_vis (*this);
+ expr.get_expr ().accept_vis (*this);
}
void
PatternChecker::visit (UnsafeBlockExpr &expr)
{
- expr.get_block_expr ()->accept_vis (*this);
+ expr.get_block_expr ().accept_vis (*this);
}
void
PatternChecker::visit (LoopExpr &expr)
{
- expr.get_loop_block ()->accept_vis (*this);
+ expr.get_loop_block ().accept_vis (*this);
}
void
PatternChecker::visit (WhileLoopExpr &expr)
{
- expr.get_predicate_expr ()->accept_vis (*this);
- expr.get_loop_block ()->accept_vis (*this);
+ expr.get_predicate_expr ().accept_vis (*this);
+ expr.get_loop_block ().accept_vis (*this);
}
void
PatternChecker::visit (WhileLetLoopExpr &expr)
{
- expr.get_cond ()->accept_vis (*this);
- expr.get_loop_block ()->accept_vis (*this);
+ expr.get_cond ().accept_vis (*this);
+ expr.get_loop_block ().accept_vis (*this);
}
void
PatternChecker::visit (IfExpr &expr)
{
- expr.get_if_condition ()->accept_vis (*this);
- expr.get_if_block ()->accept_vis (*this);
+ expr.get_if_condition ().accept_vis (*this);
+ expr.get_if_block ().accept_vis (*this);
}
void
PatternChecker::visit (IfExprConseqElse &expr)
{
- expr.get_if_condition ()->accept_vis (*this);
- expr.get_if_block ()->accept_vis (*this);
- expr.get_else_block ()->accept_vis (*this);
+ expr.get_if_condition ().accept_vis (*this);
+ expr.get_if_block ().accept_vis (*this);
+ expr.get_else_block ().accept_vis (*this);
}
void
PatternChecker::visit (MatchExpr &expr)
{
- expr.get_scrutinee_expr ()->accept_vis (*this);
+ expr.get_scrutinee_expr ().accept_vis (*this);
for (auto &match_arm : expr.get_match_cases ())
- match_arm.get_expr ()->accept_vis (*this);
+ match_arm.get_expr ().accept_vis (*this);
// match expressions are only an entrypoint
TyTy::BaseType *scrutinee_ty;
bool ok = tyctx.lookup_type (
- expr.get_scrutinee_expr ()->get_mappings ().get_hirid (), &scrutinee_ty);
+ expr.get_scrutinee_expr ().get_mappings ().get_hirid (), &scrutinee_ty);
rust_assert (ok);
check_match_usefulness (&tyctx, scrutinee_ty, expr);
@@ -468,7 +468,7 @@ PatternChecker::visit (UseDeclaration &)
void
PatternChecker::visit (Function &function)
{
- function.get_definition ()->accept_vis (*this);
+ function.get_definition ().accept_vis (*this);
}
void
@@ -510,27 +510,27 @@ PatternChecker::visit (Union &)
void
PatternChecker::visit (ConstantItem &const_item)
{
- const_item.get_expr ()->accept_vis (*this);
+ const_item.get_expr ().accept_vis (*this);
}
void
PatternChecker::visit (StaticItem &static_item)
{
- static_item.get_expr ()->accept_vis (*this);
+ static_item.get_expr ().accept_vis (*this);
}
void
PatternChecker::visit (TraitItemFunc &item)
{
if (item.has_block_defined ())
- item.get_block_expr ()->accept_vis (*this);
+ item.get_block_expr ().accept_vis (*this);
}
void
PatternChecker::visit (TraitItemConst &item)
{
if (item.has_expr ())
- item.get_expr ()->accept_vis (*this);
+ item.get_expr ().accept_vis (*this);
}
void
@@ -659,13 +659,13 @@ void
PatternChecker::visit (LetStmt &stmt)
{
if (stmt.has_init_expr ())
- stmt.get_init_expr ()->accept_vis (*this);
+ stmt.get_init_expr ().accept_vis (*this);
}
void
PatternChecker::visit (ExprStmt &stmt)
{
- stmt.get_expr ()->accept_vis (*this);
+ stmt.get_expr ().accept_vis (*this);
}
void
@@ -1161,33 +1161,34 @@ WitnessMatrix::extend (const WitnessMatrix &other)
// forward declarations
static DeconstructedPat
-lower_pattern (Resolver::TypeCheckContext *ctx, HIR::Pattern *pattern,
+lower_pattern (Resolver::TypeCheckContext *ctx, HIR::Pattern &pattern,
TyTy::BaseType *scrutinee_ty);
static DeconstructedPat
lower_tuple_pattern (Resolver::TypeCheckContext *ctx,
- HIR::TupleStructPattern *pattern,
+ HIR::TupleStructPattern &pattern,
TyTy::VariantDef *variant, Constructor &ctor)
{
int arity = variant->get_fields ().size ();
- HIR::TupleStructItems *elems = pattern->get_items ().get ();
+ HIR::TupleStructItems &elems = pattern.get_items ();
std::vector<DeconstructedPat> fields;
- switch (elems->get_item_type ())
+ switch (elems.get_item_type ())
{
case HIR::TupleStructItems::ItemType::MULTIPLE: {
- HIR::TupleStructItemsNoRange *multiple
- = static_cast<HIR::TupleStructItemsNoRange *> (elems);
+ HIR::TupleStructItemsNoRange &multiple
+ = static_cast<HIR::TupleStructItemsNoRange &> (elems);
rust_assert (variant->get_fields ().size ()
- == multiple->get_patterns ().size ());
- for (size_t i = 0; i < multiple->get_patterns ().size (); i++)
+ == multiple.get_patterns ().size ());
+
+ for (size_t i = 0; i < multiple.get_patterns ().size (); i++)
{
fields.push_back (
- lower_pattern (ctx, multiple->get_patterns ().at (i).get (),
+ lower_pattern (ctx, *multiple.get_patterns ().at (i),
variant->get_fields ().at (i)->get_field_type ()));
}
- return DeconstructedPat (ctor, arity, fields, pattern->get_locus ());
+ return DeconstructedPat (ctor, arity, fields, pattern.get_locus ());
}
break;
case HIR::TupleStructItems::ItemType::RANGED: {
@@ -1203,7 +1204,7 @@ lower_tuple_pattern (Resolver::TypeCheckContext *ctx,
static DeconstructedPat
lower_struct_pattern (Resolver::TypeCheckContext *ctx,
- HIR::StructPattern *pattern, TyTy::VariantDef *variant,
+ HIR::StructPattern &pattern, TyTy::VariantDef *variant,
Constructor ctor)
{
int arity = variant->get_fields ().size ();
@@ -1211,7 +1212,7 @@ lower_struct_pattern (Resolver::TypeCheckContext *ctx,
// Initialize all field patterns to wildcard.
std::vector<DeconstructedPat> fields
= std::vector<DeconstructedPat> (arity, DeconstructedPat::make_wildcard (
- pattern->get_locus ()));
+ pattern.get_locus ()));
std::map<std::string, int> field_map;
for (int i = 0; i < arity; i++)
@@ -1221,7 +1222,7 @@ lower_struct_pattern (Resolver::TypeCheckContext *ctx,
}
// Fill in the fields with the present patterns.
- HIR::StructPatternElements elems = pattern->get_struct_pattern_elems ();
+ HIR::StructPatternElements elems = pattern.get_struct_pattern_elems ();
for (auto &elem : elems.get_struct_pattern_fields ())
{
switch (elem->get_item_type ())
@@ -1232,7 +1233,7 @@ lower_struct_pattern (Resolver::TypeCheckContext *ctx,
int field_idx
= field_map.at (ident->get_identifier ().as_string ());
fields.at (field_idx)
- = DeconstructedPat::make_wildcard (pattern->get_locus ());
+ = DeconstructedPat::make_wildcard (pattern.get_locus ());
}
break;
case HIR::StructPatternField::ItemType::IDENT_PAT: {
@@ -1241,7 +1242,7 @@ lower_struct_pattern (Resolver::TypeCheckContext *ctx,
int field_idx
= field_map.at (ident_pat->get_identifier ().as_string ());
fields.at (field_idx) = lower_pattern (
- ctx, ident_pat->get_pattern ().get (),
+ ctx, ident_pat->get_pattern (),
variant->get_fields ().at (field_idx)->get_field_type ());
}
break;
@@ -1256,19 +1257,19 @@ lower_struct_pattern (Resolver::TypeCheckContext *ctx,
}
}
- return DeconstructedPat{ctor, arity, fields, pattern->get_locus ()};
+ return DeconstructedPat{ctor, arity, fields, pattern.get_locus ()};
};
static DeconstructedPat
-lower_pattern (Resolver::TypeCheckContext *ctx, HIR::Pattern *pattern,
+lower_pattern (Resolver::TypeCheckContext *ctx, HIR::Pattern &pattern,
TyTy::BaseType *scrutinee_ty)
{
- HIR::Pattern::PatternType pat_type = pattern->get_pattern_type ();
+ HIR::Pattern::PatternType pat_type = pattern.get_pattern_type ();
switch (pat_type)
{
case HIR::Pattern::PatternType::WILDCARD:
case HIR::Pattern::PatternType::IDENTIFIER: {
- return DeconstructedPat::make_wildcard (pattern->get_locus ());
+ return DeconstructedPat::make_wildcard (pattern.get_locus ());
}
break;
case HIR::Pattern::PatternType::PATH: {
@@ -1276,12 +1277,12 @@ lower_pattern (Resolver::TypeCheckContext *ctx, HIR::Pattern *pattern,
// structs
// https://doc.rust-lang.org/reference/patterns.html#path-patterns
// unimplemented. Treat this pattern as wildcard for now.
- return DeconstructedPat::make_wildcard (pattern->get_locus ());
+ return DeconstructedPat::make_wildcard (pattern.get_locus ());
}
break;
case HIR::Pattern::PatternType::REFERENCE: {
// TODO: unimplemented. Treat this pattern as wildcard for now.
- return DeconstructedPat::make_wildcard (pattern->get_locus ());
+ return DeconstructedPat::make_wildcard (pattern.get_locus ());
}
break;
case HIR::Pattern::PatternType::STRUCT:
@@ -1289,15 +1290,15 @@ lower_pattern (Resolver::TypeCheckContext *ctx, HIR::Pattern *pattern,
HirId path_id = UNKNOWN_HIRID;
if (pat_type == HIR::Pattern::PatternType::STRUCT)
{
- HIR::StructPattern *struct_pattern
- = static_cast<HIR::StructPattern *> (pattern);
- path_id = struct_pattern->get_path ().get_mappings ().get_hirid ();
+ HIR::StructPattern &struct_pattern
+ = static_cast<HIR::StructPattern &> (pattern);
+ path_id = struct_pattern.get_path ().get_mappings ().get_hirid ();
}
else
{
- HIR::TupleStructPattern *tuple_pattern
- = static_cast<HIR::TupleStructPattern *> (pattern);
- path_id = tuple_pattern->get_path ().get_mappings ().get_hirid ();
+ HIR::TupleStructPattern &tuple_pattern
+ = static_cast<HIR::TupleStructPattern &> (pattern);
+ path_id = tuple_pattern.get_path ().get_mappings ().get_hirid ();
}
rust_assert (scrutinee_ty->get_kind () == TyTy::TypeKind::ADT);
@@ -1330,46 +1331,46 @@ lower_pattern (Resolver::TypeCheckContext *ctx, HIR::Pattern *pattern,
if (pat_type == HIR::Pattern::PatternType::STRUCT)
{
- HIR::StructPattern *struct_pattern
- = static_cast<HIR::StructPattern *> (pattern);
+ HIR::StructPattern &struct_pattern
+ = static_cast<HIR::StructPattern &> (pattern);
return lower_struct_pattern (ctx, struct_pattern, variant, ctor);
}
else
{
- HIR::TupleStructPattern *tuple_pattern
- = static_cast<HIR::TupleStructPattern *> (pattern);
+ HIR::TupleStructPattern &tuple_pattern
+ = static_cast<HIR::TupleStructPattern &> (pattern);
return lower_tuple_pattern (ctx, tuple_pattern, variant, ctor);
}
}
break;
case HIR::Pattern::PatternType::TUPLE: {
// TODO: unimplemented. Treat this pattern as wildcard for now.
- return DeconstructedPat::make_wildcard (pattern->get_locus ());
+ return DeconstructedPat::make_wildcard (pattern.get_locus ());
}
break;
case HIR::Pattern::PatternType::SLICE: {
// TODO: unimplemented. Treat this pattern as wildcard for now.
- return DeconstructedPat::make_wildcard (pattern->get_locus ());
+ return DeconstructedPat::make_wildcard (pattern.get_locus ());
}
break;
case HIR::Pattern::PatternType::ALT: {
// TODO: unimplemented. Treat this pattern as wildcard for now.
- return DeconstructedPat::make_wildcard (pattern->get_locus ());
+ return DeconstructedPat::make_wildcard (pattern.get_locus ());
}
break;
case HIR::Pattern::PatternType::LITERAL: {
// TODO: unimplemented. Treat this pattern as wildcard for now.
- return DeconstructedPat::make_wildcard (pattern->get_locus ());
+ return DeconstructedPat::make_wildcard (pattern.get_locus ());
}
break;
case HIR::Pattern::PatternType::RANGE: {
// TODO: unimplemented. Treat this pattern as wildcard for now.
- return DeconstructedPat::make_wildcard (pattern->get_locus ());
+ return DeconstructedPat::make_wildcard (pattern.get_locus ());
}
break;
case HIR::Pattern::PatternType::GROUPED: {
// TODO: unimplemented. Treat this pattern as wildcard for now.
- return DeconstructedPat::make_wildcard (pattern->get_locus ());
+ return DeconstructedPat::make_wildcard (pattern.get_locus ());
}
break;
default: {
@@ -1385,8 +1386,7 @@ lower_arm (Resolver::TypeCheckContext *ctx, HIR::MatchCase &arm,
rust_assert (arm.get_arm ().get_patterns ().size () > 0);
DeconstructedPat pat
- = lower_pattern (ctx, arm.get_arm ().get_patterns ().at (0).get (),
- scrutinee_ty);
+ = lower_pattern (ctx, *arm.get_arm ().get_patterns ().at (0), scrutinee_ty);
return MatchArm (pat, arm.get_arm ().has_match_arm_guard ());
}
@@ -1495,8 +1495,9 @@ emit_exhaustiveness_error (Resolver::TypeCheckContext *ctx,
HIR::MatchExpr &expr, WitnessMatrix &witness)
{
TyTy::BaseType *scrutinee_ty;
- bool ok = ctx->lookup_type (
- expr.get_scrutinee_expr ()->get_mappings ().get_hirid (), &scrutinee_ty);
+ bool ok
+ = ctx->lookup_type (expr.get_scrutinee_expr ().get_mappings ().get_hirid (),
+ &scrutinee_ty);
rust_assert (ok);
if (!witness.empty ())
@@ -1514,7 +1515,7 @@ emit_exhaustiveness_error (Resolver::TypeCheckContext *ctx,
if (i != witness.get_stacks ().size () - 1)
buf << " and ";
}
- rust_error_at (expr.get_scrutinee_expr ()->get_locus (),
+ rust_error_at (expr.get_scrutinee_expr ().get_locus (),
"non-exhaustive patterns: %s not covered",
buf.str ().c_str ());
}
diff --git a/gcc/rust/checks/errors/rust-unsafe-checker.cc b/gcc/rust/checks/errors/rust-unsafe-checker.cc
index ee6654b4dd2..8f97edb6df5 100644
--- a/gcc/rust/checks/errors/rust-unsafe-checker.cc
+++ b/gcc/rust/checks/errors/rust-unsafe-checker.cc
@@ -279,14 +279,14 @@ UnsafeChecker::visit (LiteralExpr &)
void
UnsafeChecker::visit (BorrowExpr &expr)
{
- expr.get_expr ()->accept_vis (*this);
+ expr.get_expr ().accept_vis (*this);
}
void
UnsafeChecker::visit (DereferenceExpr &expr)
{
TyTy::BaseType *to_deref_type;
- auto to_deref = expr.get_expr ()->get_mappings ().get_hirid ();
+ auto to_deref = expr.get_expr ().get_mappings ().get_hirid ();
rust_assert (context.lookup_type (to_deref, &to_deref_type));
@@ -299,60 +299,60 @@ UnsafeChecker::visit (DereferenceExpr &expr)
void
UnsafeChecker::visit (ErrorPropagationExpr &expr)
{
- expr.get_expr ()->accept_vis (*this);
+ expr.get_expr ().accept_vis (*this);
}
void
UnsafeChecker::visit (NegationExpr &expr)
{
- expr.get_expr ()->accept_vis (*this);
+ expr.get_expr ().accept_vis (*this);
}
void
UnsafeChecker::visit (ArithmeticOrLogicalExpr &expr)
{
- expr.get_lhs ()->accept_vis (*this);
- expr.get_rhs ()->accept_vis (*this);
+ expr.get_lhs ().accept_vis (*this);
+ expr.get_rhs ().accept_vis (*this);
}
void
UnsafeChecker::visit (ComparisonExpr &expr)
{
- expr.get_lhs ()->accept_vis (*this);
- expr.get_rhs ()->accept_vis (*this);
+ expr.get_lhs ().accept_vis (*this);
+ expr.get_rhs ().accept_vis (*this);
}
void
UnsafeChecker::visit (LazyBooleanExpr &expr)
{
- expr.get_lhs ()->accept_vis (*this);
- expr.get_rhs ()->accept_vis (*this);
+ expr.get_lhs ().accept_vis (*this);
+ expr.get_rhs ().accept_vis (*this);
}
void
UnsafeChecker::visit (TypeCastExpr &expr)
{
- expr.get_expr ()->accept_vis (*this);
+ expr.get_expr ().accept_vis (*this);
}
void
UnsafeChecker::visit (AssignmentExpr &expr)
{
- expr.get_lhs ()->accept_vis (*this);
- expr.get_rhs ()->accept_vis (*this);
+ expr.get_lhs ().accept_vis (*this);
+ expr.get_rhs ().accept_vis (*this);
}
void
UnsafeChecker::visit (CompoundAssignmentExpr &expr)
{
- expr.get_lhs ()->accept_vis (*this);
- expr.get_rhs ()->accept_vis (*this);
+ expr.get_lhs ().accept_vis (*this);
+ expr.get_rhs ().accept_vis (*this);
}
void
UnsafeChecker::visit (GroupedExpr &expr)
{
- expr.get_expr_in_parens ()->accept_vis (*this);
+ expr.get_expr_in_parens ().accept_vis (*this);
}
void
@@ -365,20 +365,20 @@ UnsafeChecker::visit (ArrayElemsValues &elems)
void
UnsafeChecker::visit (ArrayElemsCopied &elems)
{
- elems.get_elem_to_copy ()->accept_vis (*this);
+ elems.get_elem_to_copy ().accept_vis (*this);
}
void
UnsafeChecker::visit (ArrayExpr &expr)
{
- expr.get_internal_elements ()->accept_vis (*this);
+ expr.get_internal_elements ().accept_vis (*this);
}
void
UnsafeChecker::visit (ArrayIndexExpr &expr)
{
- expr.get_array_expr ()->accept_vis (*this);
- expr.get_index_expr ()->accept_vis (*this);
+ expr.get_array_expr ().accept_vis (*this);
+ expr.get_index_expr ().accept_vis (*this);
}
void
@@ -391,7 +391,7 @@ UnsafeChecker::visit (TupleExpr &expr)
void
UnsafeChecker::visit (TupleIndexExpr &expr)
{
- expr.get_tuple_expr ()->accept_vis (*this);
+ expr.get_tuple_expr ().accept_vis (*this);
}
void
@@ -405,13 +405,13 @@ UnsafeChecker::visit (StructExprFieldIdentifier &)
void
UnsafeChecker::visit (StructExprFieldIdentifierValue &field)
{
- field.get_value ()->accept_vis (*this);
+ field.get_value ().accept_vis (*this);
}
void
UnsafeChecker::visit (StructExprFieldIndexValue &field)
{
- field.get_value ()->accept_vis (*this);
+ field.get_value ().accept_vis (*this);
}
void
@@ -428,10 +428,10 @@ UnsafeChecker::visit (StructExprStructBase &)
void
UnsafeChecker::visit (CallExpr &expr)
{
- if (!expr.get_fnexpr ())
+ if (!expr.has_fnexpr ())
return;
- NodeId ast_node_id = expr.get_fnexpr ()->get_mappings ().get_nodeid ();
+ NodeId ast_node_id = expr.get_fnexpr ().get_mappings ().get_nodeid ();
NodeId ref_node_id;
// There are no unsafe types, and functions are defined in the name resolver.
@@ -489,7 +489,7 @@ UnsafeChecker::visit (MethodCallExpr &expr)
check_unsafe_call (static_cast<Function *> (method->first),
expr.get_locus (), "method");
- expr.get_receiver ()->accept_vis (*this);
+ expr.get_receiver ().accept_vis (*this);
for (auto &arg : expr.get_arguments ())
arg->accept_vis (*this);
@@ -498,14 +498,14 @@ UnsafeChecker::visit (MethodCallExpr &expr)
void
UnsafeChecker::visit (FieldAccessExpr &expr)
{
- expr.get_receiver_expr ()->accept_vis (*this);
+ expr.get_receiver_expr ().accept_vis (*this);
if (unsafe_context.is_in_context ())
return;
TyTy::BaseType *receiver_ty;
auto ok = context.lookup_type (
- expr.get_receiver_expr ()->get_mappings ().get_hirid (), &receiver_ty);
+ expr.get_receiver_expr ().get_mappings ().get_hirid (), &receiver_ty);
rust_assert (ok);
if (receiver_ty->get_kind () == TyTy::TypeKind::ADT)
@@ -521,7 +521,7 @@ UnsafeChecker::visit (FieldAccessExpr &expr)
void
UnsafeChecker::visit (ClosureExpr &expr)
{
- expr.get_expr ()->accept_vis (*this);
+ expr.get_expr ().accept_vis (*this);
}
void
@@ -531,7 +531,7 @@ UnsafeChecker::visit (BlockExpr &expr)
stmt->accept_vis (*this);
if (expr.has_expr ())
- expr.get_final_expr ()->accept_vis (*this);
+ expr.get_final_expr ().accept_vis (*this);
}
void
@@ -542,26 +542,26 @@ void
UnsafeChecker::visit (BreakExpr &expr)
{
if (expr.has_break_expr ())
- expr.get_expr ()->accept_vis (*this);
+ expr.get_expr ().accept_vis (*this);
}
void
UnsafeChecker::visit (RangeFromToExpr &expr)
{
- expr.get_from_expr ()->accept_vis (*this);
- expr.get_to_expr ()->accept_vis (*this);
+ expr.get_from_expr ().accept_vis (*this);
+ expr.get_to_expr ().accept_vis (*this);
}
void
UnsafeChecker::visit (RangeFromExpr &expr)
{
- expr.get_from_expr ()->accept_vis (*this);
+ expr.get_from_expr ().accept_vis (*this);
}
void
UnsafeChecker::visit (RangeToExpr &expr)
{
- expr.get_to_expr ()->accept_vis (*this);
+ expr.get_to_expr ().accept_vis (*this);
}
void
@@ -571,21 +571,21 @@ UnsafeChecker::visit (RangeFullExpr &)
void
UnsafeChecker::visit (RangeFromToInclExpr &expr)
{
- expr.get_from_expr ()->accept_vis (*this);
- expr.get_to_expr ()->accept_vis (*this);
+ expr.get_from_expr ().accept_vis (*this);
+ expr.get_to_expr ().accept_vis (*this);
}
void
UnsafeChecker::visit (RangeToInclExpr &expr)
{
- expr.get_to_expr ()->accept_vis (*this);
+ expr.get_to_expr ().accept_vis (*this);
}
void
UnsafeChecker::visit (ReturnExpr &expr)
{
if (expr.has_return_expr ())
- expr.get_expr ()->accept_vis (*this);
+ expr.get_expr ().accept_vis (*this);
}
void
@@ -593,7 +593,7 @@ UnsafeChecker::visit (UnsafeBlockExpr &expr)
{
unsafe_context.enter (expr.get_mappings ().get_hirid ());
- expr.get_block_expr ()->accept_vis (*this);
+ expr.get_block_expr ().accept_vis (*this);
unsafe_context.exit ();
}
@@ -601,45 +601,45 @@ UnsafeChecker::visit (UnsafeBlockExpr &expr)
void
UnsafeChecker::visit (LoopExpr &expr)
{
- expr.get_loop_block ()->accept_vis (*this);
+ expr.get_loop_block ().accept_vis (*this);
}
void
UnsafeChecker::visit (WhileLoopExpr &expr)
{
- expr.get_predicate_expr ()->accept_vis (*this);
- expr.get_loop_block ()->accept_vis (*this);
+ expr.get_predicate_expr ().accept_vis (*this);
+ expr.get_loop_block ().accept_vis (*this);
}
void
UnsafeChecker::visit (WhileLetLoopExpr &expr)
{
- expr.get_cond ()->accept_vis (*this);
- expr.get_loop_block ()->accept_vis (*this);
+ expr.get_cond ().accept_vis (*this);
+ expr.get_loop_block ().accept_vis (*this);
}
void
UnsafeChecker::visit (IfExpr &expr)
{
- expr.get_if_condition ()->accept_vis (*this);
- expr.get_if_block ()->accept_vis (*this);
+ expr.get_if_condition ().accept_vis (*this);
+ expr.get_if_block ().accept_vis (*this);
}
void
UnsafeChecker::visit (IfExprConseqElse &expr)
{
- expr.get_if_condition ()->accept_vis (*this);
- expr.get_if_block ()->accept_vis (*this);
- expr.get_else_block ()->accept_vis (*this);
+ expr.get_if_condition ().accept_vis (*this);
+ expr.get_if_block ().accept_vis (*this);
+ expr.get_else_block ().accept_vis (*this);
}
void
UnsafeChecker::visit (MatchExpr &expr)
{
- expr.get_scrutinee_expr ()->accept_vis (*this);
+ expr.get_scrutinee_expr ().accept_vis (*this);
for (auto &match_arm : expr.get_match_cases ())
- match_arm.get_expr ()->accept_vis (*this);
+ match_arm.get_expr ().accept_vis (*this);
}
void
@@ -716,7 +716,7 @@ UnsafeChecker::visit (Function &function)
if (is_unsafe_fn)
unsafe_context.enter (function.get_mappings ().get_hirid ());
- function.get_definition ()->accept_vis (*this);
+ function.get_definition ().accept_vis (*this);
if (is_unsafe_fn)
unsafe_context.exit ();
@@ -764,27 +764,27 @@ UnsafeChecker::visit (Union &)
void
UnsafeChecker::visit (ConstantItem &const_item)
{
- const_item.get_expr ()->accept_vis (*this);
+ const_item.get_expr ().accept_vis (*this);
}
void
UnsafeChecker::visit (StaticItem &static_item)
{
- static_item.get_expr ()->accept_vis (*this);
+ static_item.get_expr ().accept_vis (*this);
}
void
UnsafeChecker::visit (TraitItemFunc &item)
{
if (item.has_block_defined ())
- item.get_block_expr ()->accept_vis (*this);
+ item.get_block_expr ().accept_vis (*this);
}
void
UnsafeChecker::visit (TraitItemConst &item)
{
if (item.has_expr ())
- item.get_expr ()->accept_vis (*this);
+ item.get_expr ().accept_vis (*this);
}
void
@@ -931,13 +931,13 @@ void
UnsafeChecker::visit (LetStmt &stmt)
{
if (stmt.has_init_expr ())
- stmt.get_init_expr ()->accept_vis (*this);
+ stmt.get_init_expr ().accept_vis (*this);
}
void
UnsafeChecker::visit (ExprStmt &stmt)
{
- stmt.get_expr ()->accept_vis (*this);
+ stmt.get_expr ().accept_vis (*this);
}
void
diff --git a/gcc/rust/checks/lints/rust-lint-marklive.cc b/gcc/rust/checks/lints/rust-lint-marklive.cc
index ca26a669003..4b524d710c9 100644
--- a/gcc/rust/checks/lints/rust-lint-marklive.cc
+++ b/gcc/rust/checks/lints/rust-lint-marklive.cc
@@ -124,7 +124,7 @@ MarkLive::visit (HIR::PathInExpression &expr)
void
MarkLive::visit (HIR::MethodCallExpr &expr)
{
- expr.get_receiver ()->accept_vis (*this);
+ expr.get_receiver ().accept_vis (*this);
visit_path_segment (expr.get_method_name ());
for (auto &argument : expr.get_arguments ())
argument->accept_vis (*this);
@@ -182,14 +182,14 @@ void
MarkLive::visit (HIR::FieldAccessExpr &expr)
{
// visit receiver at first
- expr.get_receiver_expr ()->accept_vis (*this);
+ expr.get_receiver_expr ().accept_vis (*this);
// resolve the receiver back to ADT type
TyTy::BaseType *receiver = nullptr;
if (!tyctx->lookup_type (
- expr.get_receiver_expr ()->get_mappings ().get_hirid (), &receiver))
+ expr.get_receiver_expr ().get_mappings ().get_hirid (), &receiver))
{
- rust_error_at (expr.get_receiver_expr ()->get_locus (),
+ rust_error_at (expr.get_receiver_expr ().get_locus (),
"unresolved type for receiver");
}
@@ -221,7 +221,7 @@ MarkLive::visit (HIR::FieldAccessExpr &expr)
rust_assert (ok);
if (index >= variant->num_fields ())
{
- rust_error_at (expr.get_receiver_expr ()->get_locus (),
+ rust_error_at (expr.get_receiver_expr ().get_locus (),
"cannot access struct %s by index: %lu",
adt->get_name ().c_str (), (unsigned long) index);
return;
@@ -236,7 +236,7 @@ void
MarkLive::visit (HIR::TupleIndexExpr &expr)
{
// TODO: unused tuple field detection
- expr.get_tuple_expr ()->accept_vis (*this);
+ expr.get_tuple_expr ().accept_vis (*this);
}
void
@@ -249,13 +249,13 @@ MarkLive::visit (HIR::TypeAlias &alias)
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
if (auto id = nr_ctx.lookup (
- alias.get_type_aliased ()->get_mappings ().get_nodeid ()))
+ alias.get_type_aliased ().get_mappings ().get_nodeid ()))
ast_node_id = *id;
}
else
{
resolver->lookup_resolved_type (
- alias.get_type_aliased ()->get_mappings ().get_nodeid (), &ast_node_id);
+ alias.get_type_aliased ().get_mappings ().get_nodeid (), &ast_node_id);
}
if (auto hid = mappings.lookup_node_to_hir (ast_node_id))
diff --git a/gcc/rust/checks/lints/rust-lint-marklive.h b/gcc/rust/checks/lints/rust-lint-marklive.h
index 92b4502cab6..93a5be7ed1e 100644
--- a/gcc/rust/checks/lints/rust-lint-marklive.h
+++ b/gcc/rust/checks/lints/rust-lint-marklive.h
@@ -43,44 +43,44 @@ public:
void visit (HIR::BorrowExpr &expr) override
{
- expr.get_expr ()->accept_vis (*this);
+ expr.get_expr ().accept_vis (*this);
}
void visit (HIR::DereferenceExpr &expr) override
{
- expr.get_expr ()->accept_vis (*this);
+ expr.get_expr ().accept_vis (*this);
}
void visit (HIR::NegationExpr &expr) override
{
- expr.get_expr ()->accept_vis (*this);
+ expr.get_expr ().accept_vis (*this);
}
void visit (HIR::LazyBooleanExpr &expr) override
{
- expr.get_lhs ()->accept_vis (*this);
- expr.get_rhs ()->accept_vis (*this);
+ expr.get_lhs ().accept_vis (*this);
+ expr.get_rhs ().accept_vis (*this);
}
void visit (HIR::TypeCastExpr &expr) override
{
- expr.get_expr ()->accept_vis (*this);
+ expr.get_expr ().accept_vis (*this);
}
void visit (HIR::GroupedExpr &expr) override
{
- expr.get_expr_in_parens ()->accept_vis (*this);
+ expr.get_expr_in_parens ().accept_vis (*this);
}
void visit (HIR::ArrayExpr &expr) override
{
- expr.get_internal_elements ()->accept_vis (*this);
+ expr.get_internal_elements ().accept_vis (*this);
}
void visit (HIR::ArrayIndexExpr &expr) override
{
- expr.get_array_expr ()->accept_vis (*this);
- expr.get_index_expr ()->accept_vis (*this);
+ expr.get_array_expr ().accept_vis (*this);
+ expr.get_index_expr ().accept_vis (*this);
}
void visit (HIR::ArrayElemsValues &expr) override
@@ -107,57 +107,57 @@ public:
}
if (expr.has_expr ())
{
- expr.get_final_expr ()->accept_vis (*this);
+ expr.get_final_expr ().accept_vis (*this);
}
}
void visit (HIR::UnsafeBlockExpr &expr) override
{
- expr.get_block_expr ()->accept_vis (*this);
+ expr.get_block_expr ().accept_vis (*this);
}
void visit (HIR::LoopExpr &expr) override
{
- expr.get_loop_block ()->accept_vis (*this);
+ expr.get_loop_block ().accept_vis (*this);
}
void visit (HIR::BreakExpr &expr) override
{
if (expr.has_break_expr ())
- expr.get_expr ()->accept_vis (*this);
+ expr.get_expr ().accept_vis (*this);
}
void visit (HIR::WhileLoopExpr &expr) override
{
- expr.get_loop_block ()->accept_vis (*this);
- expr.get_predicate_expr ()->accept_vis (*this);
+ expr.get_loop_block ().accept_vis (*this);
+ expr.get_predicate_expr ().accept_vis (*this);
}
void visit (HIR::Function &function) override
{
- function.get_definition ()->accept_vis (*this);
+ function.get_definition ().accept_vis (*this);
}
void visit (HIR::ReturnExpr &expr) override
{
if (expr.has_return_expr ())
- expr.get_expr ()->accept_vis (*this);
+ expr.get_expr ().accept_vis (*this);
}
void visit (HIR::WhileLetLoopExpr &expr) override
{
- expr.get_loop_block ()->accept_vis (*this);
- expr.get_cond ()->accept_vis (*this);
+ expr.get_loop_block ().accept_vis (*this);
+ expr.get_cond ().accept_vis (*this);
}
void visit (HIR::ExprStmt &stmt) override
{
- stmt.get_expr ()->accept_vis (*this);
+ stmt.get_expr ().accept_vis (*this);
}
void visit (HIR::CallExpr &expr) override
{
- expr.get_fnexpr ()->accept_vis (*this);
+ expr.get_fnexpr ().accept_vis (*this);
for (auto &argument : expr.get_arguments ())
argument->accept_vis (*this);
}
@@ -169,8 +169,8 @@ public:
}
void visit (HIR::ComparisonExpr &expr) override
{
- expr.get_lhs ()->accept_vis (*this);
- expr.get_rhs ()->accept_vis (*this);
+ expr.get_lhs ().accept_vis (*this);
+ expr.get_rhs ().accept_vis (*this);
}
void visit (HIR::AssignmentExpr &expr) override
@@ -187,33 +187,33 @@ public:
void visit (HIR::IfExpr &expr) override
{
- expr.get_if_condition ()->accept_vis (*this);
- expr.get_if_block ()->accept_vis (*this);
+ expr.get_if_condition ().accept_vis (*this);
+ expr.get_if_block ().accept_vis (*this);
}
void visit (HIR::IfExprConseqElse &expr) override
{
- expr.get_if_condition ()->accept_vis (*this);
- expr.get_if_block ()->accept_vis (*this);
- expr.get_else_block ()->accept_vis (*this);
+ expr.get_if_condition ().accept_vis (*this);
+ expr.get_if_block ().accept_vis (*this);
+ expr.get_else_block ().accept_vis (*this);
}
void visit (HIR::MatchExpr &expr) override
{
- expr.get_scrutinee_expr ()->accept_vis (*this);
+ expr.get_scrutinee_expr ().accept_vis (*this);
std::vector<HIR::MatchCase> &cases = expr.get_match_cases ();
for (auto &&caz : cases)
{
auto case_arm = caz.get_arm ();
if (case_arm.has_match_arm_guard ())
- case_arm.get_guard_expr ()->accept_vis (*this);
- caz.get_expr ()->accept_vis (*this);
+ case_arm.get_guard_expr ().accept_vis (*this);
+ caz.get_expr ().accept_vis (*this);
}
}
void visit (HIR::TraitItemFunc &item) override
{
- item.get_block_expr ()->accept_vis (*this);
+ item.get_block_expr ().accept_vis (*this);
}
void visit (HIR::ImplBlock &impl) override
@@ -228,7 +228,7 @@ public:
{
if (stmt.has_init_expr ())
{
- stmt.get_init_expr ()->accept_vis (*this);
+ stmt.get_init_expr ().accept_vis (*this);
}
}
@@ -253,7 +253,7 @@ public:
virtual void visit (HIR::StructExprFieldIdentifierValue &field) override
{
- field.get_value ()->accept_vis (*this);
+ field.get_value ().accept_vis (*this);
}
void visit (HIR::StructExprStructBase &stct) override
@@ -269,7 +269,7 @@ public:
void visit (HIR::ClosureExpr &expr) override
{
- expr.get_expr ()->accept_vis (*this);
+ expr.get_expr ().accept_vis (*this);
}
private:
diff --git a/gcc/rust/hir/rust-hir-dump.cc b/gcc/rust/hir/rust-hir-dump.cc
index 4fa028c07b8..65799e89f6b 100644
--- a/gcc/rust/hir/rust-hir-dump.cc
+++ b/gcc/rust/hir/rust-hir-dump.cc
@@ -800,7 +800,7 @@ Dump::visit (QualifiedPathInType &e)
end_field ("path_type");
begin_field ("associated_segment");
- do_typepathsegment (*e.get_associated_segment ());
+ do_typepathsegment (e.get_associated_segment ());
end_field ("associated_segment");
visit_collection ("segments", e.get_segments ());
@@ -911,7 +911,7 @@ Dump::visit (ArithmeticOrLogicalExpr &e)
}
put_field ("expr_type", str);
do_operatorexpr (e);
- visit_field ("right_expr", *e.get_rhs ());
+ visit_field ("right_expr", e.get_rhs ());
end ("ArithmeticOrLogicalExpr");
}
@@ -946,7 +946,7 @@ Dump::visit (ComparisonExpr &e)
}
put_field ("expr_type", str);
do_operatorexpr (e);
- visit_field ("right_expr", *e.get_rhs ());
+ visit_field ("right_expr", e.get_rhs ());
end ("ComparisonExpr");
}
@@ -969,7 +969,7 @@ Dump::visit (LazyBooleanExpr &e)
}
do_operatorexpr (e);
- visit_field ("right_expr", *e.get_rhs ());
+ visit_field ("right_expr", e.get_rhs ());
end ("LazyBooleanExpr");
}
@@ -987,7 +987,7 @@ Dump::visit (AssignmentExpr &e)
{
begin ("AssignmentExpr");
do_operatorexpr (e);
- visit_field ("right_expr", *e.get_rhs ());
+ visit_field ("right_expr", e.get_rhs ());
end ("AssignmentExpr");
}
@@ -997,7 +997,7 @@ Dump::visit (CompoundAssignmentExpr &e)
begin ("CompoundAssignmentExpr");
do_operatorexpr (e);
- visit_field ("right_expr", *e.get_rhs ());
+ visit_field ("right_expr", e.get_rhs ());
std::string str;
@@ -1684,7 +1684,7 @@ Dump::visit (TypeAlias &e)
else
put_field ("where clause", e.get_where_clause ().as_string ());
- put_field ("type", e.get_type_aliased ()->as_string ());
+ put_field ("type", e.get_type_aliased ().as_string ());
end ("TypeAlias");
}
@@ -2050,7 +2050,7 @@ Dump::visit (IdentifierPattern &e)
put_field ("mut", std::to_string (e.is_mut ()));
if (e.has_pattern_to_bind ())
- put_field ("to_bind", e.get_to_bind ()->as_string ());
+ put_field ("to_bind", e.get_to_bind ().as_string ());
else
put_field ("to_bind", "none");
@@ -2094,8 +2094,8 @@ Dump::visit (RangePattern &e)
{
begin ("RangePattern");
do_mappings (e.get_mappings ());
- put_field ("lower", e.get_lower_bound ()->as_string ());
- put_field ("upper", e.get_upper_bound ()->as_string ());
+ put_field ("lower", e.get_lower_bound ().as_string ());
+ put_field ("upper", e.get_upper_bound ().as_string ());
put_field ("has_ellipsis_syntax",
std::to_string (e.get_has_ellipsis_syntax ()));
end ("RangePattern");
@@ -2107,7 +2107,7 @@ Dump::visit (ReferencePattern &e)
begin ("ReferencePattern");
do_mappings (e.get_mappings ());
put_field ("mut", std::to_string (e.is_mut ()));
- put_field ("pattern", e.get_referenced_pattern ()->as_string ());
+ put_field ("pattern", e.get_referenced_pattern ().as_string ());
end ("ReferencePattern");
}
@@ -2119,7 +2119,7 @@ Dump::visit (StructPatternFieldTuplePat &e)
auto oa = e.get_outer_attrs ();
do_outer_attrs (oa);
put_field ("index", std::to_string (e.get_index ()));
- put_field ("tuple_pattern", e.get_tuple_pattern ()->as_string ());
+ put_field ("tuple_pattern", e.get_tuple_pattern ().as_string ());
end ("StructPatternFieldTuplePat");
}
@@ -2130,7 +2130,7 @@ Dump::visit (StructPatternFieldIdentPat &e)
auto oa = e.get_outer_attrs ();
do_outer_attrs (oa);
put_field ("ident", e.get_identifier ().as_string ());
- put_field ("ident_pattern", e.get_pattern ()->as_string ());
+ put_field ("ident_pattern", e.get_pattern ().as_string ());
end ("StructPatternFieldIdentPat");
}
@@ -2248,7 +2248,7 @@ Dump::visit (LetStmt &e)
auto oa = e.get_outer_attrs ();
do_outer_attrs (oa);
- put_field ("variable_pattern", e.get_pattern ()->as_string ());
+ put_field ("variable_pattern", e.get_pattern ().as_string ());
visit_field ("type", e.get_type ());
visit_field ("init_expr", e.get_init_expr ());
@@ -2309,7 +2309,7 @@ Dump::visit (ParenthesisedType &e)
{
begin ("ParenthesisedType");
do_type (e);
- put_field ("type_in_parens", e.get_type_in_parens ()->as_string ());
+ put_field ("type_in_parens", e.get_type_in_parens ().as_string ());
end ("ParenthesisedType");
}
@@ -2345,7 +2345,7 @@ Dump::visit (RawPointerType &e)
begin ("RawPointerType");
do_type (e);
put_field ("mut", Rust::enum_to_str (e.get_mut ()));
- put_field ("type", e.get_type ()->as_string ());
+ put_field ("type", e.get_type ().as_string ());
end ("RawPointerType");
}
@@ -2356,7 +2356,7 @@ Dump::visit (ReferenceType &e)
do_type (e);
put_field ("lifetime", e.get_lifetime ().as_string ());
put_field ("mut", enum_to_str (e.get_mut ()));
- put_field ("type", e.get_base_type ()->as_string ());
+ put_field ("type", e.get_base_type ().as_string ());
end ("ReferenceType");
}
diff --git a/gcc/rust/hir/tree/rust-hir-expr.h b/gcc/rust/hir/tree/rust-hir-expr.h
index 0155e254688..692b9b4a9ac 100644
--- a/gcc/rust/hir/tree/rust-hir-expr.h
+++ b/gcc/rust/hir/tree/rust-hir-expr.h
@@ -209,7 +209,7 @@ protected:
public:
location_t get_locus () const override final { return locus; }
- std::unique_ptr<Expr> &get_expr () { return main_or_left_expr; }
+ Expr &get_expr () { return *main_or_left_expr; }
ExprType get_expression_type () const override final
{
@@ -423,8 +423,8 @@ public:
void visit_lhs (HIRFullVisitor &vis) { main_or_left_expr->accept_vis (vis); }
void visit_rhs (HIRFullVisitor &vis) { right_expr->accept_vis (vis); }
- std::unique_ptr<Expr> &get_lhs () { return main_or_left_expr; }
- std::unique_ptr<Expr> &get_rhs () { return right_expr; }
+ Expr &get_lhs () { return *main_or_left_expr; }
+ Expr &get_rhs () { return *right_expr; }
std::string get_operator_str () const;
@@ -497,8 +497,8 @@ public:
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRExpressionVisitor &vis) override;
- std::unique_ptr<Expr> &get_lhs () { return main_or_left_expr; }
- std::unique_ptr<Expr> &get_rhs () { return right_expr; }
+ Expr &get_lhs () { return *main_or_left_expr; }
+ Expr &get_rhs () { return *right_expr; }
ExprType get_kind () { return expr_type; }
@@ -571,8 +571,8 @@ public:
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRExpressionVisitor &vis) override;
- std::unique_ptr<Expr> &get_lhs () { return main_or_left_expr; }
- std::unique_ptr<Expr> &get_rhs () { return right_expr; }
+ Expr &get_lhs () { return *main_or_left_expr; }
+ Expr &get_rhs () { return *right_expr; }
protected:
/* Use covariance to implement clone function as returning this object rather
@@ -633,12 +633,9 @@ public:
void accept_vis (HIRExpressionVisitor &vis) override;
// FIXME: isn't it the same as get_expr() from parent?
- std::unique_ptr<Expr> &get_casted_expr () { return main_or_left_expr; }
+ Expr &get_casted_expr () { return *main_or_left_expr; }
- std::unique_ptr<Type> &get_type_to_convert_to ()
- {
- return type_to_convert_to;
- }
+ Type &get_type_to_convert_to () { return *type_to_convert_to; }
protected:
/* Use covariance to implement clone function as returning this object rather
@@ -700,8 +697,8 @@ public:
void visit_lhs (HIRFullVisitor &vis) { main_or_left_expr->accept_vis (vis); }
void visit_rhs (HIRFullVisitor &vis) { right_expr->accept_vis (vis); }
- std::unique_ptr<Expr> &get_lhs () { return main_or_left_expr; }
- std::unique_ptr<Expr> &get_rhs () { return right_expr; }
+ Expr &get_lhs () { return *main_or_left_expr; }
+ Expr &get_rhs () { return *right_expr; }
protected:
/* Use covariance to implement clone function as returning this object rather
@@ -770,9 +767,9 @@ public:
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRExpressionVisitor &vis) override;
- std::unique_ptr<Expr> &get_lhs () { return main_or_left_expr; }
+ Expr &get_lhs () { return *main_or_left_expr; }
- std::unique_ptr<Expr> &get_rhs () { return right_expr; }
+ Expr &get_rhs () { return *right_expr; }
void visit_lhs (HIRFullVisitor &vis) { main_or_left_expr->accept_vis (vis); }
void visit_rhs (HIRFullVisitor &vis) { right_expr->accept_vis (vis); }
@@ -834,7 +831,7 @@ public:
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRExpressionVisitor &vis) override;
- std::unique_ptr<Expr> &get_expr_in_parens () { return expr_in_parens; }
+ Expr &get_expr_in_parens () { return *expr_in_parens; }
ExprType get_expression_type () const override final
{
@@ -986,9 +983,9 @@ public:
void accept_vis (HIRFullVisitor &vis) override;
- std::unique_ptr<Expr> &get_elem_to_copy () { return elem_to_copy; }
+ Expr &get_elem_to_copy () { return *elem_to_copy; }
- std::unique_ptr<Expr> &get_num_copies_expr () { return num_copies; }
+ Expr &get_num_copies_expr () { return *num_copies; }
ArrayElems::ArrayExprType get_array_expr_type () const override final
{
@@ -1056,10 +1053,7 @@ public:
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRExpressionVisitor &vis) override;
- std::unique_ptr<ArrayElems> &get_internal_elements ()
- {
- return internal_elements;
- };
+ ArrayElems &get_internal_elements () { return *internal_elements; };
ExprType get_expression_type () const override final
{
@@ -1125,8 +1119,8 @@ public:
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRExpressionVisitor &vis) override;
- std::unique_ptr<Expr> &get_array_expr () { return array_expr; }
- std::unique_ptr<Expr> &get_index_expr () { return index_expr; }
+ Expr &get_array_expr () { return *array_expr; }
+ Expr &get_index_expr () { return *index_expr; }
ExprType get_expression_type () const override final
{
@@ -1279,7 +1273,7 @@ public:
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRExpressionVisitor &vis) override;
- std::unique_ptr<Expr> &get_tuple_expr () { return tuple_expr; }
+ Expr &get_tuple_expr () { return *tuple_expr; }
ExprType get_expression_type () const override final
{
@@ -1524,7 +1518,7 @@ protected:
public:
std::string as_string () const override;
- std::unique_ptr<Expr> &get_value () { return value; }
+ Expr &get_value () { return *value; }
};
// Identifier and value variant of StructExprField HIR node
@@ -1797,7 +1791,8 @@ public:
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRExpressionVisitor &vis) override;
- std::unique_ptr<Expr> &get_fnexpr () { return function; }
+ bool has_fnexpr () const { return function != nullptr; }
+ Expr &get_fnexpr () { return *function; }
size_t num_params () const { return params.size (); }
@@ -1884,7 +1879,7 @@ public:
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRExpressionVisitor &vis) override;
- std::unique_ptr<Expr> &get_receiver () { return receiver; }
+ Expr &get_receiver () { return *receiver; }
PathExprSegment &get_method_name () { return method_name; };
const PathExprSegment &get_method_name () const { return method_name; };
@@ -1968,7 +1963,7 @@ public:
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRExpressionVisitor &vis) override;
- std::unique_ptr<Expr> &get_receiver_expr () { return receiver; }
+ Expr &get_receiver_expr () { return *receiver; }
Identifier get_field_name () const { return field; }
@@ -2058,9 +2053,9 @@ public:
}
std::vector<AST::Attribute> &get_outer_attrs () { return outer_attrs; }
- std::unique_ptr<Pattern> &get_pattern () { return pattern; }
+ Pattern &get_pattern () { return *pattern; }
- std::unique_ptr<Type> &get_type () { return type; }
+ Type &get_type () { return *type; }
location_t get_locus () const { return locus; }
};
@@ -2128,8 +2123,8 @@ public:
bool has_return_type () const { return return_type != nullptr; }
- std::unique_ptr<Type> &get_return_type () { return return_type; };
- std::unique_ptr<Expr> &get_expr () { return expr; }
+ Type &get_return_type () { return *return_type; };
+ Expr &get_expr () { return *expr; }
bool has_params () const { return !params.empty (); }
std::vector<ClosureParam> &get_params () { return params; }
@@ -2243,7 +2238,7 @@ public:
bool is_final_stmt (Stmt *stmt) { return statements.back ().get () == stmt; }
- std::unique_ptr<Expr> &get_final_expr () { return expr; }
+ Expr &get_final_expr () { return *expr; }
std::vector<std::unique_ptr<Stmt> > &get_statements () { return statements; }
@@ -2388,7 +2383,7 @@ public:
Lifetime &get_label () { return label; }
- std::unique_ptr<Expr> &get_expr () { return break_expr; }
+ Expr &get_expr () { return *break_expr; }
ExprType get_expression_type () const override final
{
@@ -2468,8 +2463,8 @@ public:
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRExpressionVisitor &vis) override;
- std::unique_ptr<Expr> &get_from_expr () { return from; }
- std::unique_ptr<Expr> &get_to_expr () { return to; }
+ Expr &get_from_expr () { return *from; }
+ Expr &get_to_expr () { return *to; }
protected:
/* Use covariance to implement clone function as returning this object rather
@@ -2522,7 +2517,7 @@ public:
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRExpressionVisitor &vis) override;
- std::unique_ptr<Expr> &get_from_expr () { return from; }
+ Expr &get_from_expr () { return *from; }
protected:
/* Use covariance to implement clone function as returning this object rather
@@ -2576,7 +2571,7 @@ public:
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRExpressionVisitor &vis) override;
- std::unique_ptr<Expr> &get_to_expr () { return to; }
+ Expr &get_to_expr () { return *to; }
protected:
/* Use covariance to implement clone function as returning this object rather
@@ -2666,8 +2661,8 @@ public:
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRExpressionVisitor &vis) override;
- std::unique_ptr<Expr> &get_from_expr () { return from; }
- std::unique_ptr<Expr> &get_to_expr () { return to; }
+ Expr &get_from_expr () { return *from; }
+ Expr &get_to_expr () { return *to; }
protected:
/* Use covariance to implement clone function as returning this object rather
@@ -2721,7 +2716,7 @@ public:
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRExpressionVisitor &vis) override;
- std::unique_ptr<Expr> &get_to_expr () { return to; };
+ Expr &get_to_expr () { return *to; };
protected:
/* Use covariance to implement clone function as returning this object rather
@@ -2790,7 +2785,7 @@ public:
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRExpressionVisitor &vis) override;
- std::unique_ptr<Expr> &get_expr () { return return_expr; }
+ Expr &get_expr () { return *return_expr; }
ExprType get_expression_type () const override final
{
@@ -2856,7 +2851,7 @@ public:
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRExpressionVisitor &vis) override;
- std::unique_ptr<BlockExpr> &get_block_expr () { return expr; }
+ BlockExpr &get_block_expr () { return *expr; }
ExprType get_expression_type () const override final
{
@@ -2932,7 +2927,7 @@ public:
location_t get_locus () const override final { return locus; }
- std::unique_ptr<HIR::BlockExpr> &get_loop_block () { return loop_block; };
+ HIR::BlockExpr &get_loop_block () { return *loop_block; };
LoopLabel &get_loop_label () { return loop_label; }
};
@@ -3010,7 +3005,7 @@ public:
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRExpressionVisitor &vis) override;
- std::unique_ptr<Expr> &get_predicate_expr () { return condition; }
+ Expr &get_predicate_expr () { return *condition; }
protected:
/* Use covariance to implement clone function as returning this object rather
@@ -3086,7 +3081,7 @@ public:
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRExpressionVisitor &vis) override;
- std::unique_ptr<Expr> &get_cond () { return condition; }
+ Expr &get_cond () { return *condition; }
std::vector<std::unique_ptr<Pattern> > &get_patterns ()
{
return match_arm_patterns;
@@ -3166,8 +3161,8 @@ public:
void vis_if_condition (HIRFullVisitor &vis) { condition->accept_vis (vis); }
void vis_if_block (HIRFullVisitor &vis) { if_block->accept_vis (vis); }
- std::unique_ptr<Expr> &get_if_condition () { return condition; }
- std::unique_ptr<BlockExpr> &get_if_block () { return if_block; }
+ Expr &get_if_condition () { return *condition; }
+ BlockExpr &get_if_block () { return *if_block; }
ExprType get_expression_type () const final override { return ExprType::If; }
@@ -3230,7 +3225,7 @@ public:
void vis_else_block (HIRFullVisitor &vis) { else_block->accept_vis (vis); }
- std::unique_ptr<ExprWithBlock> &get_else_block () { return else_block; }
+ ExprWithBlock &get_else_block () { return *else_block; }
protected:
/* Use covariance to implement clone function as returning this object rather
@@ -3330,7 +3325,7 @@ public:
return match_arm_patterns;
}
- std::unique_ptr<Expr> &get_guard_expr () { return guard_expr; }
+ Expr &get_guard_expr () { return *guard_expr; }
location_t get_locus () const { return locus; }
};
@@ -3374,7 +3369,7 @@ public:
Analysis::NodeMapping get_mappings () const { return mappings; }
MatchArm &get_arm () { return arm; }
- std::unique_ptr<Expr> &get_expr () { return expr; }
+ Expr &get_expr () { return *expr; }
};
// Match expression HIR node
@@ -3435,7 +3430,7 @@ public:
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRExpressionVisitor &vis) override;
- std::unique_ptr<Expr> &get_scrutinee_expr () { return branch_value; }
+ Expr &get_scrutinee_expr () { return *branch_value; }
AST::AttrVec get_inner_attrs () const { return inner_attrs; }
const std::vector<MatchCase> &get_match_cases () const { return match_arms; }
std::vector<MatchCase> &get_match_cases () { return match_arms; }
@@ -3499,7 +3494,7 @@ public:
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRExpressionVisitor &vis) override;
- std::unique_ptr<Expr> &get_awaited_expr () { return awaited_expr; }
+ Expr &get_awaited_expr () { return *awaited_expr; }
ExprType get_expression_type () const final override
{
@@ -3556,7 +3551,7 @@ public:
location_t get_locus () const override final { return locus; }
bool get_has_move () const { return has_move; }
- std::unique_ptr<BlockExpr> &get_block_expr () { return block_expr; }
+ BlockExpr &get_block_expr () { return *block_expr; }
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRExpressionVisitor &vis) override;
@@ -3581,31 +3576,31 @@ class OperatorExprMeta
public:
OperatorExprMeta (HIR::CompoundAssignmentExpr &expr)
: node_mappings (expr.get_mappings ()),
- lvalue_mappings (expr.get_expr ()->get_mappings ()),
+ lvalue_mappings (expr.get_expr ().get_mappings ()),
locus (expr.get_locus ())
{}
OperatorExprMeta (HIR::ArithmeticOrLogicalExpr &expr)
: node_mappings (expr.get_mappings ()),
- lvalue_mappings (expr.get_expr ()->get_mappings ()),
+ lvalue_mappings (expr.get_expr ().get_mappings ()),
locus (expr.get_locus ())
{}
OperatorExprMeta (HIR::NegationExpr &expr)
: node_mappings (expr.get_mappings ()),
- lvalue_mappings (expr.get_expr ()->get_mappings ()),
+ lvalue_mappings (expr.get_expr ().get_mappings ()),
locus (expr.get_locus ())
{}
OperatorExprMeta (HIR::DereferenceExpr &expr)
: node_mappings (expr.get_mappings ()),
- lvalue_mappings (expr.get_expr ()->get_mappings ()),
+ lvalue_mappings (expr.get_expr ().get_mappings ()),
locus (expr.get_locus ())
{}
OperatorExprMeta (HIR::ArrayIndexExpr &expr)
: node_mappings (expr.get_mappings ()),
- lvalue_mappings (expr.get_array_expr ()->get_mappings ()),
+ lvalue_mappings (expr.get_array_expr ().get_mappings ()),
locus (expr.get_locus ())
{}
diff --git a/gcc/rust/hir/tree/rust-hir-item.h b/gcc/rust/hir/tree/rust-hir-item.h
index 1f53e853dcc..3e98ad412ed 100644
--- a/gcc/rust/hir/tree/rust-hir-item.h
+++ b/gcc/rust/hir/tree/rust-hir-item.h
@@ -118,7 +118,7 @@ public:
Identifier get_type_representation () const { return type_representation; }
- std::unique_ptr<Type> &get_type () { return type; }
+ Type &get_type () { return *type; }
Analysis::NodeMapping get_type_mappings () const
{
@@ -277,7 +277,7 @@ public:
std::vector<LifetimeParam> &get_for_lifetimes () { return for_lifetimes; }
- std::unique_ptr<Type> &get_bound_type () { return bound_type; }
+ Type &get_bound_type () { return *bound_type; }
std::vector<std::unique_ptr<TypeParamBound>> &get_type_param_bounds ()
{
@@ -452,7 +452,7 @@ public:
ImplicitSelfKind get_self_kind () const { return self_kind; }
- std::unique_ptr<Type> &get_type () { return type; }
+ Type &get_type () { return *type; }
Analysis::NodeMapping get_mappings () { return mappings; }
@@ -547,9 +547,11 @@ public:
location_t get_locus () const { return locus; }
- std::unique_ptr<Pattern> &get_param_name () { return param_name; }
+ Pattern &get_param_name () { return *param_name; }
- std::unique_ptr<Type> &get_type () { return type; }
+ std::unique_ptr<Pattern> take_param_name () { return std::move (param_name); }
+
+ Type &get_type () { return *type; }
const Analysis::NodeMapping &get_mappings () const { return mappings; }
};
@@ -1056,7 +1058,7 @@ public:
location_t get_locus () const override final { return locus; }
ItemKind get_item_kind () const override { return ItemKind::UseDeclaration; }
- std::unique_ptr<UseTree> &get_use_tree () { return use_tree; }
+ UseTree &get_use_tree () { return *use_tree; }
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRStmtVisitor &vis) override;
void accept_vis (HIRVisItemVisitor &vis) override;
@@ -1210,7 +1212,7 @@ public:
}
// TODO: is this better? Or is a "vis_block" better?
- std::unique_ptr<BlockExpr> &get_definition () { return function_body; }
+ BlockExpr &get_definition () { return *function_body; }
const FunctionQualifiers &get_qualifiers () const { return qualifiers; }
@@ -1222,7 +1224,7 @@ public:
bool has_return_type () const { return return_type != nullptr; }
// TODO: is this better? Or is a "vis_block" better?
- std::unique_ptr<Type> &get_return_type () { return return_type; }
+ Type &get_return_type () { return *return_type; }
bool is_method () const { return !self.is_error (); }
@@ -1337,7 +1339,7 @@ public:
WhereClause &get_where_clause () { return where_clause; }
- std::unique_ptr<Type> &get_type_aliased () { return existing_type; }
+ Type &get_type_aliased () { return *existing_type; }
Identifier get_new_type_name () const { return new_type_name; }
@@ -1503,7 +1505,7 @@ public:
Identifier get_field_name () const { return field_name; }
- std::unique_ptr<Type> &get_field_type () { return field_type; }
+ Type &get_field_type () { return *field_type; }
Analysis::NodeMapping get_mappings () const { return mappings; }
@@ -1640,7 +1642,7 @@ public:
location_t get_locus () const { return locus; }
AST::AttrVec &get_outer_attrs () { return outer_attrs; }
- std::unique_ptr<HIR::Type> &get_field_type () { return field_type; }
+ HIR::Type &get_field_type () { return *field_type; }
};
// Rust tuple declared using struct keyword HIR node
@@ -1855,7 +1857,12 @@ public:
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRStmtVisitor &vis) override;
- std::unique_ptr<Expr> &get_discriminant_expression () { return expression; }
+ Expr &get_discriminant_expression () { return *expression; }
+
+ std::unique_ptr<Expr> take_discriminant_expression ()
+ {
+ return std::move (expression);
+ }
protected:
// Clone function implementation as (not pure) virtual method
@@ -2126,9 +2133,9 @@ public:
void accept_vis (HIRImplVisitor &vis) override;
void accept_vis (HIRVisItemVisitor &vis) override;
- std::unique_ptr<Type> &get_type () { return type; }
+ Type &get_type () { return *type; }
- std::unique_ptr<Expr> &get_expr () { return const_expr; }
+ Expr &get_expr () { return *const_expr; }
Identifier get_identifier () const { return identifier; }
@@ -2222,9 +2229,9 @@ public:
bool is_mut () const { return mut == Mutability::Mut; }
- std::unique_ptr<Expr> &get_expr () { return expr; }
+ Expr &get_expr () { return *expr; }
- std::unique_ptr<Type> &get_type () { return type; }
+ Type &get_type () { return *type; }
ItemKind get_item_kind () const override { return ItemKind::Static; }
@@ -2324,7 +2331,7 @@ public:
return generic_params;
}
- std::unique_ptr<Type> &get_return_type () { return return_type; }
+ Type &get_return_type () { return *return_type; }
std::vector<FunctionParam> &get_function_params () { return function_params; }
@@ -2391,7 +2398,7 @@ public:
bool has_block_defined () const { return block_expr != nullptr; }
- std::unique_ptr<BlockExpr> &get_block_expr () { return block_expr; }
+ BlockExpr &get_block_expr () { return *block_expr; }
const std::string trait_identifier () const override final
{
@@ -2476,9 +2483,9 @@ public:
bool has_expr () const { return expr != nullptr; }
- std::unique_ptr<Type> &get_type () { return type; }
+ Type &get_type () { return *type; }
- std::unique_ptr<Expr> &get_expr () { return expr; }
+ Expr &get_expr () { return *expr; }
const std::string trait_identifier () const override final
{
@@ -2828,7 +2835,9 @@ public:
location_t get_locus () const override final { return locus; }
- std::unique_ptr<Type> &get_type () { return impl_type; };
+ Type &get_type () { return *impl_type; };
+
+ bool has_type () { return impl_type == nullptr; }
std::vector<std::unique_ptr<GenericParam>> &get_generic_params ()
{
@@ -2837,7 +2846,7 @@ public:
bool has_trait_ref () const { return trait_ref != nullptr; }
- std::unique_ptr<TypePath> &get_trait_ref () { return trait_ref; }
+ TypePath &get_trait_ref () { return *trait_ref; }
WhereClause &get_where_clause () { return where_clause; }
@@ -2976,7 +2985,7 @@ public:
Mutability get_mut () { return mut; }
- std::unique_ptr<Type> &get_item_type () { return item_type; }
+ Type &get_item_type () { return *item_type; }
ExternKind get_extern_kind () override { return ExternKind::Static; }
@@ -3033,7 +3042,7 @@ public:
Identifier get_param_name () const { return name; }
- std::unique_ptr<Type> &get_type () { return param_type; }
+ Type &get_type () { return *param_type; }
Analysis::NodeMapping get_mappings () const { return mappings; }
};
@@ -3132,7 +3141,7 @@ public:
return generic_params;
}
- std::unique_ptr<Type> &get_return_type () { return return_type; }
+ Type &get_return_type () { return *return_type; }
std::vector<NamedFunctionParam> &get_function_params ()
{
diff --git a/gcc/rust/hir/tree/rust-hir-path.h b/gcc/rust/hir/tree/rust-hir-path.h
index e406d534f16..18197837afa 100644
--- a/gcc/rust/hir/tree/rust-hir-path.h
+++ b/gcc/rust/hir/tree/rust-hir-path.h
@@ -107,8 +107,8 @@ public:
Identifier &get_identifier () { return identifier; }
const Identifier &get_identifier () const { return identifier; }
- std::unique_ptr<Type> &get_type () { return type; }
- const std::unique_ptr<Type> &get_type () const { return type; }
+ Type &get_type () { return *type; }
+ const Type &get_type () const { return *type; }
location_t get_locus () const { return locus; }
};
@@ -574,7 +574,7 @@ public:
TypePathFunction (TypePathFunction const &other)
{
return_type = other.has_return_type ()
- ? other.get_return_type ()->clone_type ()
+ ? other.get_return_type ().clone_type ()
: nullptr;
inputs.reserve (other.inputs.size ());
@@ -588,7 +588,7 @@ public:
TypePathFunction &operator= (TypePathFunction const &other)
{
return_type = other.has_return_type ()
- ? other.get_return_type ()->clone_type ()
+ ? other.get_return_type ().clone_type ()
: nullptr;
inputs.reserve (other.inputs.size ());
@@ -610,8 +610,8 @@ public:
};
std::vector<std::unique_ptr<Type> > &get_params () { return inputs; };
- const std::unique_ptr<Type> &get_return_type () const { return return_type; };
- std::unique_ptr<Type> &get_return_type () { return return_type; };
+ const Type &get_return_type () const { return *return_type; };
+ Type &get_return_type () { return *return_type; };
};
// Segment used in type path with a function argument
@@ -811,9 +811,9 @@ public:
Analysis::NodeMapping get_mappings () const { return mappings; }
- std::unique_ptr<Type> &get_type () { return type; }
+ Type &get_type () { return *type; }
- std::unique_ptr<TypePath> &get_trait () { return trait; }
+ TypePath &get_trait () { return *trait; }
bool trait_has_generic_args () const
{
@@ -963,10 +963,7 @@ public:
QualifiedPathType &get_path_type () { return path_type; }
- std::unique_ptr<TypePathSegment> &get_associated_segment ()
- {
- return associated_segment;
- }
+ TypePathSegment &get_associated_segment () { return *associated_segment; }
std::vector<std::unique_ptr<TypePathSegment> > &get_segments ()
{
diff --git a/gcc/rust/hir/tree/rust-hir-pattern.h b/gcc/rust/hir/tree/rust-hir-pattern.h
index e5d83716edf..df26a396457 100644
--- a/gcc/rust/hir/tree/rust-hir-pattern.h
+++ b/gcc/rust/hir/tree/rust-hir-pattern.h
@@ -132,7 +132,7 @@ public:
bool is_mut () const { return mut == Mutability::Mut; }
bool get_is_ref () const { return is_ref; }
- std::unique_ptr<Pattern> &get_to_bind () { return to_bind; }
+ Pattern &get_to_bind () { return *to_bind; }
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRPatternVisitor &vis) override;
@@ -405,9 +405,9 @@ public:
return PatternType::RANGE;
}
- std::unique_ptr<RangePatternBound> &get_lower_bound () { return lower; }
+ RangePatternBound &get_lower_bound () { return *lower; }
- std::unique_ptr<RangePatternBound> &get_upper_bound () { return upper; }
+ RangePatternBound &get_upper_bound () { return *upper; }
protected:
/* Use covariance to implement clone function as returning this object rather
@@ -476,7 +476,7 @@ public:
return PatternType::REFERENCE;
}
- std::unique_ptr<Pattern> &get_referenced_pattern () { return pattern; }
+ Pattern &get_referenced_pattern () { return *pattern; }
protected:
/* Use covariance to implement clone function as returning this object rather
@@ -572,7 +572,7 @@ public:
void accept_vis (HIRFullVisitor &vis) override;
TupleIndex get_index () { return index; }
- std::unique_ptr<Pattern> &get_tuple_pattern () { return tuple_pattern; }
+ Pattern &get_tuple_pattern () { return *tuple_pattern; }
ItemType get_item_type () const override final { return ItemType::TUPLE_PAT; }
@@ -630,7 +630,7 @@ public:
Identifier get_identifier () const { return ident; }
- std::unique_ptr<Pattern> &get_pattern () { return ident_pattern; }
+ Pattern &get_pattern () { return *ident_pattern; }
protected:
/* Use covariance to implement clone function as returning this object rather
@@ -1002,7 +1002,7 @@ public:
PathInExpression &get_path () { return path; }
- std::unique_ptr<TupleStructItems> &get_items () { return items; }
+ TupleStructItems &get_items () { return *items; }
const Analysis::NodeMapping &get_mappings () const override final
{
@@ -1221,8 +1221,8 @@ public:
return PatternType::TUPLE;
}
- std::unique_ptr<TuplePatternItems> &get_items () { return items; }
- const std::unique_ptr<TuplePatternItems> &get_items () const { return items; }
+ TuplePatternItems &get_items () { return *items; }
+ const TuplePatternItems &get_items () const { return *items; }
protected:
/* Use covariance to implement clone function as returning this object rather
diff --git a/gcc/rust/hir/tree/rust-hir-stmt.h b/gcc/rust/hir/tree/rust-hir-stmt.h
index e6e844fb559..7320bb62385 100644
--- a/gcc/rust/hir/tree/rust-hir-stmt.h
+++ b/gcc/rust/hir/tree/rust-hir-stmt.h
@@ -144,11 +144,11 @@ public:
}
std::vector<AST::Attribute> &get_outer_attrs () { return outer_attrs; }
- std::unique_ptr<HIR::Type> &get_type () { return type; }
+ HIR::Type &get_type () { return *type; }
- std::unique_ptr<HIR::Expr> &get_init_expr () { return init_expr; }
+ HIR::Expr &get_init_expr () { return *init_expr; }
- std::unique_ptr<HIR::Pattern> &get_pattern () { return variables_pattern; }
+ HIR::Pattern &get_pattern () { return *variables_pattern; }
bool is_item () const override final { return false; }
@@ -186,7 +186,7 @@ public:
bool is_item () const override final { return false; }
- std::unique_ptr<Expr> &get_expr () { return expr; }
+ Expr &get_expr () { return *expr; }
// Copy constructor with clone
ExprStmt (ExprStmt const &other)
diff --git a/gcc/rust/hir/tree/rust-hir-type.h b/gcc/rust/hir/tree/rust-hir-type.h
index e4a97547b92..26c3d2dfa49 100644
--- a/gcc/rust/hir/tree/rust-hir-type.h
+++ b/gcc/rust/hir/tree/rust-hir-type.h
@@ -271,7 +271,7 @@ public:
* parenthesised type, it must be in parentheses. */
return type_in_parens->to_trait_bound (true);
}
- std::unique_ptr<Type> &get_type_in_parens () { return type_in_parens; }
+ Type &get_type_in_parens () { return *type_in_parens; }
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRTypeVisitor &vis) override;
};
@@ -439,7 +439,7 @@ public:
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRTypeVisitor &vis) override;
- std::unique_ptr<Type> &get_type () { return type; }
+ Type &get_type () { return *type; }
Mutability get_mut () const { return mut; }
@@ -447,7 +447,7 @@ public:
bool is_const () const { return mut == Mutability::Imm; }
- std::unique_ptr<Type> &get_base_type () { return type; }
+ Type &get_base_type () { return *type; }
protected:
/* Use covariance to implement clone function as returning this object rather
@@ -520,7 +520,7 @@ public:
Mutability get_mut () const { return mut; }
- std::unique_ptr<Type> &get_base_type () { return type; }
+ Type &get_base_type () { return *type; }
protected:
/* Use covariance to implement clone function as returning this object rather
@@ -578,9 +578,9 @@ public:
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRTypeVisitor &vis) override;
- std::unique_ptr<Type> &get_element_type () { return elem_type; }
+ Type &get_element_type () { return *elem_type; }
- std::unique_ptr<Expr> &get_size_expr () { return size; }
+ Expr &get_size_expr () { return *size; }
protected:
/* Use covariance to implement clone function as returning this object rather
@@ -633,7 +633,7 @@ public:
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRTypeVisitor &vis) override;
- std::unique_ptr<Type> &get_element_type () { return elem_type; }
+ Type &get_element_type () { return *elem_type; }
protected:
/* Use covariance to implement clone function as returning this object rather
@@ -743,7 +743,7 @@ public:
location_t get_locus () const { return locus; }
- std::unique_ptr<Type> &get_type () { return param_type; }
+ Type &get_type () { return *param_type; }
ParamKind get_param_kind () const { return param_kind; }
@@ -828,7 +828,7 @@ public:
}
// TODO: would a "vis_type" be better?
- std::unique_ptr<Type> &get_return_type () { return return_type; }
+ Type &get_return_type () { return *return_type; }
protected:
/* Use covariance to implement clone function as returning this object rather
diff --git a/gcc/rust/hir/tree/rust-hir.h b/gcc/rust/hir/tree/rust-hir.h
index 8544d0d5f09..7d133e135b0 100644
--- a/gcc/rust/hir/tree/rust-hir.h
+++ b/gcc/rust/hir/tree/rust-hir.h
@@ -765,11 +765,8 @@ public:
bool has_default_expression () { return default_expression != nullptr; }
std::string get_name () { return name; }
- std::unique_ptr<Type> &get_type () { return type; }
- std::unique_ptr<Expr> &get_default_expression ()
- {
- return default_expression;
- }
+ Type &get_type () { return *type; }
+ Expr &get_default_expression () { return *default_expression; }
protected:
/* Use covariance to implement clone function as returning this object rather
diff --git a/gcc/rust/typecheck/rust-autoderef.cc b/gcc/rust/typecheck/rust-autoderef.cc
index 7e80b8efddf..75da3919ea4 100644
--- a/gcc/rust/typecheck/rust-autoderef.cc
+++ b/gcc/rust/typecheck/rust-autoderef.cc
@@ -209,7 +209,7 @@ resolve_operator_overload_fn (
== 0)
{
TraitReference *trait_reference
- = TraitResolver::Lookup (*parent->get_trait_ref ().get ());
+ = TraitResolver::Lookup (parent->get_trait_ref ());
if (!trait_reference->is_error ())
{
TyTy::BaseType *lookup = nullptr;
diff --git a/gcc/rust/typecheck/rust-hir-dot-operator.cc b/gcc/rust/typecheck/rust-hir-dot-operator.cc
index 8e5473f2f2e..6af23176467 100644
--- a/gcc/rust/typecheck/rust-hir-dot-operator.cc
+++ b/gcc/rust/typecheck/rust-hir-dot-operator.cc
@@ -200,104 +200,103 @@ MethodResolver::select (TyTy::BaseType &receiver)
};
std::vector<trait_item_candidate> trait_fns;
- mappings.iterate_impl_blocks (
- [&] (HirId id, HIR::ImplBlock *impl) mutable -> bool {
- bool is_trait_impl = impl->has_trait_ref ();
- if (!is_trait_impl)
- return true;
-
- // look for impl implementation else lookup the associated trait item
- for (auto &impl_item : impl->get_impl_items ())
- {
- bool is_fn = impl_item->get_impl_item_type ()
- == HIR::ImplItem::ImplItemType::FUNCTION;
- if (!is_fn)
- continue;
-
- HIR::Function *func = static_cast<HIR::Function *> (impl_item.get ());
- if (!func->is_method ())
- continue;
-
- bool name_matches = func->get_function_name ().as_string ().compare (
- segment_name.as_string ())
- == 0;
- if (!name_matches)
- continue;
-
- TyTy::BaseType *ty = nullptr;
- if (!query_type (func->get_mappings ().get_hirid (), &ty))
- continue;
- if (ty->get_kind () == TyTy::TypeKind::ERROR)
- continue;
-
- rust_assert (ty->get_kind () == TyTy::TypeKind::FNDEF);
- TyTy::FnType *fnty = static_cast<TyTy::FnType *> (ty);
- const TyTy::BaseType *impl_self
- = TypeCheckItem::ResolveImplBlockSelf (*impl);
-
- // see:
- // https://gcc-rust.zulipchat.com/#narrow/stream/266897-general/topic/Method.20Resolution/near/338646280
- // https://github.com/rust-lang/rust/blob/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/compiler/rustc_typeck/src/check/method/probe.rs#L650-L660
- bool impl_self_is_ptr
- = impl_self->get_kind () == TyTy::TypeKind::POINTER;
- bool impl_self_is_ref = impl_self->get_kind () == TyTy::TypeKind::REF;
- if (receiver_is_raw_ptr && impl_self_is_ptr)
- {
- const TyTy::PointerType &sptr
- = *static_cast<const TyTy::PointerType *> (impl_self);
- const TyTy::PointerType &ptr
- = *static_cast<const TyTy::PointerType *> (raw);
-
- // we could do this via lang-item assemblies if we refactor this
- bool mut_match = sptr.mutability () == ptr.mutability ();
- if (!mut_match)
- continue;
- }
- else if (receiver_is_ref && impl_self_is_ref)
- {
- const TyTy::ReferenceType &sptr
- = *static_cast<const TyTy::ReferenceType *> (impl_self);
- const TyTy::ReferenceType &ptr
- = *static_cast<const TyTy::ReferenceType *> (raw);
-
- // we could do this via lang-item assemblies if we refactor this
- bool mut_match = sptr.mutability () == ptr.mutability ();
- if (!mut_match)
- continue;
- }
+ mappings.iterate_impl_blocks ([&] (HirId id,
+ HIR::ImplBlock *impl) mutable -> bool {
+ bool is_trait_impl = impl->has_trait_ref ();
+ if (!is_trait_impl)
+ return true;
- inherent_impl_fns.push_back ({func, impl, fnty});
- return true;
- }
+ // look for impl implementation else lookup the associated trait item
+ for (auto &impl_item : impl->get_impl_items ())
+ {
+ bool is_fn = impl_item->get_impl_item_type ()
+ == HIR::ImplItem::ImplItemType::FUNCTION;
+ if (!is_fn)
+ continue;
+
+ HIR::Function *func = static_cast<HIR::Function *> (impl_item.get ());
+ if (!func->is_method ())
+ continue;
+
+ bool name_matches = func->get_function_name ().as_string ().compare (
+ segment_name.as_string ())
+ == 0;
+ if (!name_matches)
+ continue;
+
+ TyTy::BaseType *ty = nullptr;
+ if (!query_type (func->get_mappings ().get_hirid (), &ty))
+ continue;
+ if (ty->get_kind () == TyTy::TypeKind::ERROR)
+ continue;
+
+ rust_assert (ty->get_kind () == TyTy::TypeKind::FNDEF);
+ TyTy::FnType *fnty = static_cast<TyTy::FnType *> (ty);
+ const TyTy::BaseType *impl_self
+ = TypeCheckItem::ResolveImplBlockSelf (*impl);
+
+ // see:
+ // https://gcc-rust.zulipchat.com/#narrow/stream/266897-general/topic/Method.20Resolution/near/338646280
+ // https://github.com/rust-lang/rust/blob/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/compiler/rustc_typeck/src/check/method/probe.rs#L650-L660
+ bool impl_self_is_ptr
+ = impl_self->get_kind () == TyTy::TypeKind::POINTER;
+ bool impl_self_is_ref = impl_self->get_kind () == TyTy::TypeKind::REF;
+ if (receiver_is_raw_ptr && impl_self_is_ptr)
+ {
+ const TyTy::PointerType &sptr
+ = *static_cast<const TyTy::PointerType *> (impl_self);
+ const TyTy::PointerType &ptr
+ = *static_cast<const TyTy::PointerType *> (raw);
+
+ // we could do this via lang-item assemblies if we refactor this
+ bool mut_match = sptr.mutability () == ptr.mutability ();
+ if (!mut_match)
+ continue;
+ }
+ else if (receiver_is_ref && impl_self_is_ref)
+ {
+ const TyTy::ReferenceType &sptr
+ = *static_cast<const TyTy::ReferenceType *> (impl_self);
+ const TyTy::ReferenceType &ptr
+ = *static_cast<const TyTy::ReferenceType *> (raw);
+
+ // we could do this via lang-item assemblies if we refactor this
+ bool mut_match = sptr.mutability () == ptr.mutability ();
+ if (!mut_match)
+ continue;
+ }
+
+ inherent_impl_fns.push_back ({func, impl, fnty});
+ return true;
+ }
- TraitReference *trait_ref
- = TraitResolver::Resolve (*impl->get_trait_ref ().get ());
- rust_assert (!trait_ref->is_error ());
+ TraitReference *trait_ref = TraitResolver::Resolve (impl->get_trait_ref ());
+ rust_assert (!trait_ref->is_error ());
- auto item_ref
- = trait_ref->lookup_trait_item (segment_name.as_string (),
- TraitItemReference::TraitItemType::FN);
- if (item_ref->is_error ())
- return true;
+ auto item_ref
+ = trait_ref->lookup_trait_item (segment_name.as_string (),
+ TraitItemReference::TraitItemType::FN);
+ if (item_ref->is_error ())
+ return true;
- const HIR::Trait *trait = trait_ref->get_hir_trait_ref ();
- HIR::TraitItem *item = item_ref->get_hir_trait_item ();
- if (item->get_item_kind () != HIR::TraitItem::TraitItemKind::FUNC)
- return true;
+ const HIR::Trait *trait = trait_ref->get_hir_trait_ref ();
+ HIR::TraitItem *item = item_ref->get_hir_trait_item ();
+ if (item->get_item_kind () != HIR::TraitItem::TraitItemKind::FUNC)
+ return true;
- HIR::TraitItemFunc *func = static_cast<HIR::TraitItemFunc *> (item);
- if (!func->get_decl ().is_method ())
- return true;
+ HIR::TraitItemFunc *func = static_cast<HIR::TraitItemFunc *> (item);
+ if (!func->get_decl ().is_method ())
+ return true;
- TyTy::BaseType *ty = item_ref->get_tyty ();
- rust_assert (ty->get_kind () == TyTy::TypeKind::FNDEF);
- TyTy::FnType *fnty = static_cast<TyTy::FnType *> (ty);
+ TyTy::BaseType *ty = item_ref->get_tyty ();
+ rust_assert (ty->get_kind () == TyTy::TypeKind::FNDEF);
+ TyTy::FnType *fnty = static_cast<TyTy::FnType *> (ty);
- trait_item_candidate candidate{func, trait, fnty, trait_ref, item_ref};
- trait_fns.push_back (candidate);
+ trait_item_candidate candidate{func, trait, fnty, trait_ref, item_ref};
+ trait_fns.push_back (candidate);
- return true;
- });
+ return true;
+ });
// lookup specified bounds for an associated item
struct precdicate_candidate
diff --git a/gcc/rust/typecheck/rust-hir-inherent-impl-overlap.h b/gcc/rust/typecheck/rust-hir-inherent-impl-overlap.h
index 5cef1c268a4..5537b14fbb2 100644
--- a/gcc/rust/typecheck/rust-hir-inherent-impl-overlap.h
+++ b/gcc/rust/typecheck/rust-hir-inherent-impl-overlap.h
@@ -54,7 +54,7 @@ public:
// impl-type -> [ (item, name), ... ]
// }
- HirId impl_type_id = impl->get_type ()->get_mappings ().get_hirid ();
+ HirId impl_type_id = impl->get_type ().get_mappings ().get_hirid ();
TyTy::BaseType *impl_type = nullptr;
bool ok = query_type (impl_type_id, &impl_type);
if (!ok)
diff --git a/gcc/rust/typecheck/rust-hir-path-probe.cc b/gcc/rust/typecheck/rust-hir-path-probe.cc
index 196cc825e0a..2e9ad95dde3 100644
--- a/gcc/rust/typecheck/rust-hir-path-probe.cc
+++ b/gcc/rust/typecheck/rust-hir-path-probe.cc
@@ -297,7 +297,7 @@ PathProbeType::process_impl_item_candidate (HirId id, HIR::ImplItem *item,
HIR::ImplBlock *impl)
{
current_impl = impl;
- HirId impl_ty_id = impl->get_type ()->get_mappings ().get_hirid ();
+ HirId impl_ty_id = impl->get_type ().get_mappings ().get_hirid ();
TyTy::BaseType *impl_block_ty = nullptr;
if (!query_type (impl_ty_id, &impl_block_ty))
return;
@@ -472,8 +472,7 @@ PathProbeImplTrait::process_trait_impl_items_for_candidates ()
if (!impl->has_trait_ref ())
return true;
- TraitReference *resolved
- = TraitResolver::Lookup (*(impl->get_trait_ref ().get ()));
+ TraitReference *resolved = TraitResolver::Lookup (impl->get_trait_ref ());
if (!trait_reference->is_equal (*resolved))
return true;
diff --git a/gcc/rust/typecheck/rust-hir-trait-resolve.cc b/gcc/rust/typecheck/rust-hir-trait-resolve.cc
index 3d99794f3d6..6f2589a0d2b 100644
--- a/gcc/rust/typecheck/rust-hir-trait-resolve.cc
+++ b/gcc/rust/typecheck/rust-hir-trait-resolve.cc
@@ -216,8 +216,7 @@ TraitResolver::resolve_trait (HIR::Trait *trait_reference)
// The one exception is the implicit Self type of a trait
bool apply_sized = !is_self;
auto param_type
- = TypeResolveGenericParam::Resolve (generic_param.get (),
- apply_sized);
+ = TypeResolveGenericParam::Resolve (*generic_param, apply_sized);
context->insert_type (generic_param->get_mappings (), param_type);
substitutions.push_back (
TyTy::SubstitutionParamMapping (typaram, param_type));
@@ -268,7 +267,7 @@ TraitResolver::resolve_trait (HIR::Trait *trait_reference)
auto predicate = get_predicate_from_bound (
b->get_path (),
- nullptr /*this will setup a PLACEHOLDER for self*/);
+ tl::nullopt /*this will setup a PLACEHOLDER for self*/);
if (predicate.is_error ())
return &TraitReference::error_node ();
@@ -384,11 +383,11 @@ TraitItemReference::resolve_item (HIR::TraitItemFunc &func)
auto expected_ret_tyty = resolved_fn_type->get_return_type ();
context->push_return_type (TypeCheckContextItem (&func), expected_ret_tyty);
- auto block_expr_ty = TypeCheckExpr::Resolve (func.get_block_expr ().get ());
+ auto block_expr_ty = TypeCheckExpr::Resolve (func.get_block_expr ());
location_t fn_return_locus
= func.get_decl ().has_return_type ()
- ? func.get_decl ().get_return_type ()->get_locus ()
+ ? func.get_decl ().get_return_type ().get_locus ()
: func.get_locus ();
coercion_site (func.get_mappings ().get_hirid (),
diff --git a/gcc/rust/typecheck/rust-hir-type-check-base.cc b/gcc/rust/typecheck/rust-hir-type-check-base.cc
index 7e34cef26c5..d8b4b23f71d 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-base.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-base.cc
@@ -374,22 +374,21 @@ TypeCheckBase::resolve_generic_params (
break;
case HIR::GenericParam::GenericKind::CONST: {
- auto param
- = static_cast<HIR::ConstGenericParam *> (generic_param.get ());
- auto specified_type
- = TypeCheckType::Resolve (param->get_type ().get ());
+ auto ¶m
+ = static_cast<HIR::ConstGenericParam &> (*generic_param);
+ auto specified_type = TypeCheckType::Resolve (param.get_type ());
- if (param->has_default_expression ())
+ if (param.has_default_expression ())
{
- auto expr_type = TypeCheckExpr::Resolve (
- param->get_default_expression ().get ());
-
- coercion_site (
- param->get_mappings ().get_hirid (),
- TyTy::TyWithLocation (specified_type),
- TyTy::TyWithLocation (
- expr_type, param->get_default_expression ()->get_locus ()),
- param->get_locus ());
+ auto expr_type
+ = TypeCheckExpr::Resolve (param.get_default_expression ());
+
+ coercion_site (param.get_mappings ().get_hirid (),
+ TyTy::TyWithLocation (specified_type),
+ TyTy::TyWithLocation (
+ expr_type,
+ param.get_default_expression ().get_locus ()),
+ param.get_locus ());
}
context->insert_type (generic_param->get_mappings (),
@@ -398,8 +397,7 @@ TypeCheckBase::resolve_generic_params (
break;
case HIR::GenericParam::GenericKind::TYPE: {
- auto param_type
- = TypeResolveGenericParam::Resolve (generic_param.get ());
+ auto param_type = TypeResolveGenericParam::Resolve (*generic_param);
context->insert_type (generic_param->get_mappings (), param_type);
substitutions.push_back (TyTy::SubstitutionParamMapping (
diff --git a/gcc/rust/typecheck/rust-hir-type-check-base.h b/gcc/rust/typecheck/rust-hir-type-check-base.h
index 0bc29053a86..e720b947916 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-base.h
+++ b/gcc/rust/typecheck/rust-hir-type-check-base.h
@@ -37,10 +37,10 @@ protected:
TraitReference *resolve_trait_path (HIR::TypePath &);
- TyTy::TypeBoundPredicate
- get_predicate_from_bound (HIR::TypePath &path, HIR::Type *associated_self,
- BoundPolarity polarity
- = BoundPolarity::RegularBound);
+ TyTy::TypeBoundPredicate get_predicate_from_bound (
+ HIR::TypePath &path,
+ tl::optional<std::reference_wrapper<HIR::Type>> associated_self,
+ BoundPolarity polarity = BoundPolarity::RegularBound);
bool check_for_unconstrained (
const std::vector<TyTy::SubstitutionParamMapping> ¶ms_to_constrain,
@@ -55,7 +55,7 @@ protected:
location_t locus);
void resolve_generic_params (
- const std::vector<std::unique_ptr<HIR::GenericParam> > &generic_params,
+ const std::vector<std::unique_ptr<HIR::GenericParam>> &generic_params,
std::vector<TyTy::SubstitutionParamMapping> &substitutions);
TyTy::TypeBoundPredicate get_marker_predicate (LangItem::Kind item_type,
diff --git a/gcc/rust/typecheck/rust-hir-type-check-enumitem.cc b/gcc/rust/typecheck/rust-hir-type-check-enumitem.cc
index a9154c64786..22025cef68a 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-enumitem.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-enumitem.cc
@@ -16,6 +16,7 @@
// along with GCC; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
+#include "rust-hir-expr.h"
#include "rust-hir-type-check-type.h"
#include "rust-hir-type-check-expr.h"
#include "rust-hir-type-check-enumitem.h"
@@ -29,25 +30,25 @@ namespace Rust {
namespace Resolver {
TyTy::VariantDef *
-TypeCheckEnumItem::Resolve (HIR::EnumItem *item, int64_t last_discriminant)
+TypeCheckEnumItem::Resolve (HIR::EnumItem &item, int64_t last_discriminant)
{
TypeCheckEnumItem resolver (last_discriminant);
- switch (item->get_enum_item_kind ())
+ switch (item.get_enum_item_kind ())
{
case HIR::EnumItem::EnumItemKind::Named:
- resolver.visit (static_cast<HIR::EnumItem &> (*item));
+ resolver.visit (static_cast<HIR::EnumItem &> (item));
break;
case HIR::EnumItem::EnumItemKind::Tuple:
- resolver.visit (static_cast<HIR::EnumItemTuple &> (*item));
+ resolver.visit (static_cast<HIR::EnumItemTuple &> (item));
break;
case HIR::EnumItem::EnumItemKind::Struct:
- resolver.visit (static_cast<HIR::EnumItemStruct &> (*item));
+ resolver.visit (static_cast<HIR::EnumItemStruct &> (item));
break;
case HIR::EnumItem::EnumItemKind::Discriminant:
- resolver.visit (static_cast<HIR::EnumItemDiscriminant &> (*item));
+ resolver.visit (static_cast<HIR::EnumItemDiscriminant &> (item));
break;
}
return resolver.variant;
@@ -68,11 +69,10 @@ TypeCheckEnumItem::visit (HIR::EnumItem &item)
mappings.get_next_hir_id (
item.get_mappings ().get_crate_num ()),
item.get_mappings ().get_local_defid ());
- HIR::LiteralExpr *discim_expr
- = new HIR::LiteralExpr (mapping, std::to_string (last_discriminant),
- HIR::Literal::LitType::INT,
- PrimitiveCoreType::CORETYPE_I64, item.get_locus (),
- {});
+ auto discim_expr = Rust::make_unique<HIR::LiteralExpr> (
+ HIR::LiteralExpr (mapping, std::to_string (last_discriminant),
+ HIR::Literal::LitType::INT,
+ PrimitiveCoreType::CORETYPE_I64, item.get_locus (), {}));
TyTy::BaseType *isize = nullptr;
bool ok = context->lookup_builtin ("isize", &isize);
@@ -101,7 +101,7 @@ TypeCheckEnumItem::visit (HIR::EnumItem &item)
variant = new TyTy::VariantDef (item.get_mappings ().get_hirid (),
item.get_mappings ().get_defid (),
item.get_identifier ().as_string (), ident,
- discim_expr);
+ std::move (discim_expr));
}
void
@@ -111,13 +111,13 @@ TypeCheckEnumItem::visit (HIR::EnumItemDiscriminant &item)
rust_error_at (item.get_locus (), "discriminant too big");
auto &discriminant = item.get_discriminant_expression ();
- auto capacity_type = TypeCheckExpr::Resolve (discriminant.get ());
+ auto capacity_type = TypeCheckExpr::Resolve (discriminant);
if (capacity_type->get_kind () == TyTy::TypeKind::ERROR)
return;
TyTy::ISizeType *expected_ty
- = new TyTy::ISizeType (discriminant->get_mappings ().get_hirid ());
- context->insert_type (discriminant->get_mappings (), expected_ty);
+ = new TyTy::ISizeType (discriminant.get_mappings ().get_hirid ());
+ context->insert_type (discriminant.get_mappings (), expected_ty);
unify_site (item.get_mappings ().get_hirid (),
TyTy::TyWithLocation (expected_ty),
@@ -145,7 +145,7 @@ TypeCheckEnumItem::visit (HIR::EnumItemDiscriminant &item)
variant = new TyTy::VariantDef (item.get_mappings ().get_hirid (),
item.get_mappings ().get_defid (),
item.get_identifier ().as_string (), ident,
- item.get_discriminant_expression ().get ());
+ item.take_discriminant_expression ());
}
void
@@ -159,7 +159,7 @@ TypeCheckEnumItem::visit (HIR::EnumItemTuple &item)
for (auto &field : item.get_tuple_fields ())
{
TyTy::BaseType *field_type
- = TypeCheckType::Resolve (field.get_field_type ().get ());
+ = TypeCheckType::Resolve (field.get_field_type ());
TyTy::StructFieldType *ty_field
= new TyTy::StructFieldType (field.get_mappings ().get_hirid (),
std::to_string (idx), field_type,
@@ -174,11 +174,10 @@ TypeCheckEnumItem::visit (HIR::EnumItemTuple &item)
mappings.get_next_hir_id (
item.get_mappings ().get_crate_num ()),
item.get_mappings ().get_local_defid ());
- HIR::LiteralExpr *discim_expr
- = new HIR::LiteralExpr (mapping, std::to_string (last_discriminant),
- HIR::Literal::LitType::INT,
- PrimitiveCoreType::CORETYPE_I64, item.get_locus (),
- {});
+ auto discim_expr = Rust::make_unique<HIR::LiteralExpr> (
+ HIR::LiteralExpr (mapping, std::to_string (last_discriminant),
+ HIR::Literal::LitType::INT,
+ PrimitiveCoreType::CORETYPE_I64, item.get_locus (), {}));
TyTy::BaseType *isize = nullptr;
bool ok = context->lookup_builtin ("isize", &isize);
@@ -208,7 +207,7 @@ TypeCheckEnumItem::visit (HIR::EnumItemTuple &item)
item.get_mappings ().get_defid (),
item.get_identifier ().as_string (), ident,
TyTy::VariantDef::VariantType::TUPLE,
- discim_expr, fields);
+ std::move (discim_expr), fields);
}
void
@@ -221,7 +220,7 @@ TypeCheckEnumItem::visit (HIR::EnumItemStruct &item)
for (auto &field : item.get_struct_fields ())
{
TyTy::BaseType *field_type
- = TypeCheckType::Resolve (field.get_field_type ().get ());
+ = TypeCheckType::Resolve (field.get_field_type ());
TyTy::StructFieldType *ty_field
= new TyTy::StructFieldType (field.get_mappings ().get_hirid (),
field.get_field_name ().as_string (),
@@ -235,11 +234,10 @@ TypeCheckEnumItem::visit (HIR::EnumItemStruct &item)
mappings.get_next_hir_id (
item.get_mappings ().get_crate_num ()),
item.get_mappings ().get_local_defid ());
- HIR::LiteralExpr *discrim_expr
- = new HIR::LiteralExpr (mapping, std::to_string (last_discriminant),
- HIR::Literal::LitType::INT,
- PrimitiveCoreType::CORETYPE_I64, item.get_locus (),
- {});
+ auto discrim_expr = Rust::make_unique<HIR::LiteralExpr> (
+ HIR::LiteralExpr (mapping, std::to_string (last_discriminant),
+ HIR::Literal::LitType::INT,
+ PrimitiveCoreType::CORETYPE_I64, item.get_locus (), {}));
TyTy::BaseType *isize = nullptr;
bool ok = context->lookup_builtin ("isize", &isize);
@@ -269,7 +267,7 @@ TypeCheckEnumItem::visit (HIR::EnumItemStruct &item)
item.get_mappings ().get_defid (),
item.get_identifier ().as_string (), ident,
TyTy::VariantDef::VariantType::STRUCT,
- discrim_expr, fields);
+ std::move (discrim_expr), fields);
}
} // namespace Resolver
diff --git a/gcc/rust/typecheck/rust-hir-type-check-enumitem.h b/gcc/rust/typecheck/rust-hir-type-check-enumitem.h
index bccffe7e8d3..6b01a49b0f3 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-enumitem.h
+++ b/gcc/rust/typecheck/rust-hir-type-check-enumitem.h
@@ -28,7 +28,7 @@ namespace Resolver {
class TypeCheckEnumItem : public TypeCheckBase
{
public:
- static TyTy::VariantDef *Resolve (HIR::EnumItem *item,
+ static TyTy::VariantDef *Resolve (HIR::EnumItem &item,
int64_t last_discriminant);
protected:
diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
index 225d83624e0..32e3839930c 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
@@ -36,17 +36,17 @@ TypeCheckExpr::TypeCheckExpr () : TypeCheckBase (), infered (nullptr) {}
// Perform type checking on expr. Also runs type unification algorithm.
// Returns the unified type of expr
TyTy::BaseType *
-TypeCheckExpr::Resolve (HIR::Expr *expr)
+TypeCheckExpr::Resolve (HIR::Expr &expr)
{
TypeCheckExpr resolver;
- expr->accept_vis (resolver);
+ expr.accept_vis (resolver);
if (resolver.infered == nullptr)
- return new TyTy::ErrorType (expr->get_mappings ().get_hirid ());
+ return new TyTy::ErrorType (expr.get_mappings ().get_hirid ());
- auto ref = expr->get_mappings ().get_hirid ();
+ auto ref = expr.get_mappings ().get_hirid ();
resolver.infered->set_ref (ref);
- resolver.context->insert_type (expr->get_mappings (), resolver.infered);
+ resolver.context->insert_type (expr.get_mappings (), resolver.infered);
return resolver.infered;
}
@@ -54,10 +54,10 @@ TypeCheckExpr::Resolve (HIR::Expr *expr)
void
TypeCheckExpr::visit (HIR::TupleIndexExpr &expr)
{
- auto resolved = TypeCheckExpr::Resolve (expr.get_tuple_expr ().get ());
+ auto resolved = TypeCheckExpr::Resolve (expr.get_tuple_expr ());
if (resolved->get_kind () == TyTy::TypeKind::ERROR)
{
- rust_error_at (expr.get_tuple_expr ()->get_locus (),
+ rust_error_at (expr.get_tuple_expr ().get_locus (),
"failed to resolve TupleIndexExpr receiver");
return;
}
@@ -73,7 +73,7 @@ TypeCheckExpr::visit (HIR::TupleIndexExpr &expr)
|| resolved->get_kind () == TyTy::TypeKind::TUPLE;
if (!is_valid_type)
{
- rust_error_at (expr.get_tuple_expr ()->get_locus (),
+ rust_error_at (expr.get_tuple_expr ().get_locus (),
"Expected Tuple or ADT got: %s",
resolved->as_string ().c_str ());
return;
@@ -138,7 +138,7 @@ TypeCheckExpr::visit (HIR::TupleExpr &expr)
std::vector<TyTy::TyVar> fields;
for (auto &elem : expr.get_tuple_elems ())
{
- auto field_ty = TypeCheckExpr::Resolve (elem.get ());
+ auto field_ty = TypeCheckExpr::Resolve (*elem);
fields.push_back (TyTy::TyVar (field_ty->get_ref ()));
}
infered = new TyTy::TupleType (expr.get_mappings ().get_hirid (),
@@ -158,10 +158,11 @@ TypeCheckExpr::visit (HIR::ReturnExpr &expr)
auto fn_return_tyty = context->peek_return_type ();
location_t expr_locus = expr.has_return_expr ()
- ? expr.get_expr ()->get_locus ()
+ ? expr.get_expr ().get_locus ()
: expr.get_locus ();
+
TyTy::BaseType *expr_ty = expr.has_return_expr ()
- ? TypeCheckExpr::Resolve (expr.get_expr ().get ())
+ ? TypeCheckExpr::Resolve (expr.get_expr ())
: TyTy::TupleType::get_unit_type ();
coercion_site (expr.get_mappings ().get_hirid (),
@@ -174,8 +175,7 @@ TypeCheckExpr::visit (HIR::ReturnExpr &expr)
void
TypeCheckExpr::visit (HIR::CallExpr &expr)
{
- TyTy::BaseType *function_tyty
- = TypeCheckExpr::Resolve (expr.get_fnexpr ().get ());
+ TyTy::BaseType *function_tyty = TypeCheckExpr::Resolve (expr.get_fnexpr ());
rust_debug_loc (expr.get_locus (), "resolved_call_expr to: {%s}",
function_tyty->get_name ().c_str ());
@@ -189,7 +189,7 @@ TypeCheckExpr::visit (HIR::CallExpr &expr)
// lookup variant id
HirId variant_id;
bool ok = context->lookup_variant_definition (
- expr.get_fnexpr ()->get_mappings ().get_hirid (), &variant_id);
+ expr.get_fnexpr ().get_mappings ().get_hirid (), &variant_id);
if (!ok)
{
@@ -203,12 +203,12 @@ TypeCheckExpr::visit (HIR::CallExpr &expr)
ok = adt->lookup_variant_by_id (variant_id, &lookup_variant);
rust_assert (ok);
- variant = *lookup_variant;
+ variant = std::move (*lookup_variant);
}
else
{
rust_assert (adt->number_of_variants () == 1);
- variant = *adt->get_variants ().at (0);
+ variant = std::move (*adt->get_variants ().at (0));
}
infered
@@ -238,12 +238,12 @@ TypeCheckExpr::visit (HIR::AssignmentExpr &expr)
{
infered = TyTy::TupleType::get_unit_type ();
- auto lhs = TypeCheckExpr::Resolve (expr.get_lhs ().get ());
- auto rhs = TypeCheckExpr::Resolve (expr.get_rhs ().get ());
+ auto lhs = TypeCheckExpr::Resolve (expr.get_lhs ());
+ auto rhs = TypeCheckExpr::Resolve (expr.get_rhs ());
coercion_site (expr.get_mappings ().get_hirid (),
- TyTy::TyWithLocation (lhs, expr.get_lhs ()->get_locus ()),
- TyTy::TyWithLocation (rhs, expr.get_rhs ()->get_locus ()),
+ TyTy::TyWithLocation (lhs, expr.get_lhs ().get_locus ()),
+ TyTy::TyWithLocation (rhs, expr.get_rhs ().get_locus ()),
expr.get_locus ());
}
@@ -252,14 +252,14 @@ TypeCheckExpr::visit (HIR::CompoundAssignmentExpr &expr)
{
infered = TyTy::TupleType::get_unit_type ();
- auto lhs = TypeCheckExpr::Resolve (expr.get_lhs ().get ());
- auto rhs = TypeCheckExpr::Resolve (expr.get_rhs ().get ());
+ auto lhs = TypeCheckExpr::Resolve (expr.get_lhs ());
+ auto rhs = TypeCheckExpr::Resolve (expr.get_rhs ());
// we dont care about the result of the unify from a compound assignment
// since this is a unit-type expr
coercion_site (expr.get_mappings ().get_hirid (),
- TyTy::TyWithLocation (lhs, expr.get_lhs ()->get_locus ()),
- TyTy::TyWithLocation (rhs, expr.get_rhs ()->get_locus ()),
+ TyTy::TyWithLocation (lhs, expr.get_lhs ().get_locus ()),
+ TyTy::TyWithLocation (rhs, expr.get_rhs ().get_locus ()),
expr.get_locus ());
auto lang_item_type
@@ -292,8 +292,8 @@ TypeCheckExpr::visit (HIR::LiteralExpr &expr)
void
TypeCheckExpr::visit (HIR::ArithmeticOrLogicalExpr &expr)
{
- auto lhs = TypeCheckExpr::Resolve (expr.get_lhs ().get ());
- auto rhs = TypeCheckExpr::Resolve (expr.get_rhs ().get ());
+ auto lhs = TypeCheckExpr::Resolve (expr.get_lhs ());
+ auto rhs = TypeCheckExpr::Resolve (expr.get_rhs ());
auto lang_item_type = LangItem::OperatorToLangItem (expr.get_expr_type ());
bool operator_overloaded
@@ -317,8 +317,8 @@ TypeCheckExpr::visit (HIR::ArithmeticOrLogicalExpr &expr)
{
case ArithmeticOrLogicalOperator::LEFT_SHIFT:
case ArithmeticOrLogicalOperator::RIGHT_SHIFT: {
- TyTy::TyWithLocation from (rhs, expr.get_rhs ()->get_locus ());
- TyTy::TyWithLocation to (lhs, expr.get_lhs ()->get_locus ());
+ TyTy::TyWithLocation from (rhs, expr.get_rhs ().get_locus ());
+ TyTy::TyWithLocation to (lhs, expr.get_lhs ().get_locus ());
infered = cast_site (expr.get_mappings ().get_hirid (), from, to,
expr.get_locus ());
}
@@ -327,8 +327,8 @@ TypeCheckExpr::visit (HIR::ArithmeticOrLogicalExpr &expr)
default: {
infered = unify_site (
expr.get_mappings ().get_hirid (),
- TyTy::TyWithLocation (lhs, expr.get_lhs ()->get_locus ()),
- TyTy::TyWithLocation (rhs, expr.get_rhs ()->get_locus ()),
+ TyTy::TyWithLocation (lhs, expr.get_lhs ().get_locus ()),
+ TyTy::TyWithLocation (rhs, expr.get_rhs ().get_locus ()),
expr.get_locus ());
}
break;
@@ -338,12 +338,12 @@ TypeCheckExpr::visit (HIR::ArithmeticOrLogicalExpr &expr)
void
TypeCheckExpr::visit (HIR::ComparisonExpr &expr)
{
- auto lhs = TypeCheckExpr::Resolve (expr.get_lhs ().get ());
- auto rhs = TypeCheckExpr::Resolve (expr.get_rhs ().get ());
+ auto lhs = TypeCheckExpr::Resolve (expr.get_lhs ());
+ auto rhs = TypeCheckExpr::Resolve (expr.get_rhs ());
unify_site (expr.get_mappings ().get_hirid (),
- TyTy::TyWithLocation (lhs, expr.get_lhs ()->get_locus ()),
- TyTy::TyWithLocation (rhs, expr.get_rhs ()->get_locus ()),
+ TyTy::TyWithLocation (lhs, expr.get_lhs ().get_locus ()),
+ TyTy::TyWithLocation (rhs, expr.get_rhs ().get_locus ()),
expr.get_locus ());
bool ok = context->lookup_builtin ("bool", &infered);
@@ -353,8 +353,8 @@ TypeCheckExpr::visit (HIR::ComparisonExpr &expr)
void
TypeCheckExpr::visit (HIR::LazyBooleanExpr &expr)
{
- auto lhs = TypeCheckExpr::Resolve (expr.get_lhs ().get ());
- auto rhs = TypeCheckExpr::Resolve (expr.get_rhs ().get ());
+ auto lhs = TypeCheckExpr::Resolve (expr.get_lhs ());
+ auto rhs = TypeCheckExpr::Resolve (expr.get_rhs ());
// we expect the lhs and rhs must be bools at this point
TyTy::BaseType *boolean_node = nullptr;
@@ -364,27 +364,27 @@ TypeCheckExpr::visit (HIR::LazyBooleanExpr &expr)
// verify the lhs and rhs before unifying together
lhs = unify_site (expr.get_mappings ().get_hirid (),
TyTy::TyWithLocation (boolean_node,
- expr.get_lhs ()->get_locus ()),
- TyTy::TyWithLocation (lhs, expr.get_lhs ()->get_locus ()),
+ expr.get_lhs ().get_locus ()),
+ TyTy::TyWithLocation (lhs, expr.get_lhs ().get_locus ()),
expr.get_locus ());
rhs = unify_site (expr.get_mappings ().get_hirid (),
TyTy::TyWithLocation (boolean_node,
- expr.get_rhs ()->get_locus ()),
- TyTy::TyWithLocation (rhs, expr.get_rhs ()->get_locus ()),
+ expr.get_rhs ().get_locus ()),
+ TyTy::TyWithLocation (rhs, expr.get_rhs ().get_locus ()),
expr.get_locus ());
infered
= unify_site (expr.get_mappings ().get_hirid (),
- TyTy::TyWithLocation (lhs, expr.get_lhs ()->get_locus ()),
- TyTy::TyWithLocation (rhs, expr.get_rhs ()->get_locus ()),
+ TyTy::TyWithLocation (lhs, expr.get_lhs ().get_locus ()),
+ TyTy::TyWithLocation (rhs, expr.get_rhs ().get_locus ()),
expr.get_locus ());
}
void
TypeCheckExpr::visit (HIR::NegationExpr &expr)
{
- auto negated_expr_ty = TypeCheckExpr::Resolve (expr.get_expr ().get ());
+ auto negated_expr_ty = TypeCheckExpr::Resolve (expr.get_expr ());
// check for operator overload
auto lang_item_type
@@ -449,15 +449,14 @@ TypeCheckExpr::visit (HIR::IfExpr &expr)
bool ok = context->lookup_builtin ("bool", &bool_ty);
rust_assert (ok);
- TyTy::BaseType *cond_type
- = TypeCheckExpr::Resolve (expr.get_if_condition ().get ());
+ TyTy::BaseType *cond_type = TypeCheckExpr::Resolve (expr.get_if_condition ());
unify_site (expr.get_mappings ().get_hirid (), TyTy::TyWithLocation (bool_ty),
TyTy::TyWithLocation (cond_type,
- expr.get_if_condition ()->get_locus ()),
+ expr.get_if_condition ().get_locus ()),
expr.get_locus ());
- TypeCheckExpr::Resolve (expr.get_if_block ().get ());
+ TypeCheckExpr::Resolve (expr.get_if_block ());
infered = TyTy::TupleType::get_unit_type ();
}
@@ -469,17 +468,15 @@ TypeCheckExpr::visit (HIR::IfExprConseqElse &expr)
bool ok = context->lookup_builtin ("bool", &bool_ty);
rust_assert (ok);
- TyTy::BaseType *cond_type
- = TypeCheckExpr::Resolve (expr.get_if_condition ().get ());
+ TyTy::BaseType *cond_type = TypeCheckExpr::Resolve (expr.get_if_condition ());
unify_site (expr.get_mappings ().get_hirid (), TyTy::TyWithLocation (bool_ty),
TyTy::TyWithLocation (cond_type,
- expr.get_if_condition ()->get_locus ()),
+ expr.get_if_condition ().get_locus ()),
expr.get_locus ());
- auto if_blk_resolved = TypeCheckExpr::Resolve (expr.get_if_block ().get ());
- auto else_blk_resolved
- = TypeCheckExpr::Resolve (expr.get_else_block ().get ());
+ auto if_blk_resolved = TypeCheckExpr::Resolve (expr.get_if_block ());
+ auto else_blk_resolved = TypeCheckExpr::Resolve (expr.get_else_block ());
if (if_blk_resolved->get_kind () == TyTy::NEVER)
infered = else_blk_resolved;
@@ -487,20 +484,20 @@ TypeCheckExpr::visit (HIR::IfExprConseqElse &expr)
infered = if_blk_resolved;
else
{
- infered = unify_site (
- expr.get_mappings ().get_hirid (),
- TyTy::TyWithLocation (if_blk_resolved,
- expr.get_if_block ()->get_locus ()),
- TyTy::TyWithLocation (else_blk_resolved,
- expr.get_else_block ()->get_locus ()),
- expr.get_locus ());
+ infered
+ = unify_site (expr.get_mappings ().get_hirid (),
+ TyTy::TyWithLocation (if_blk_resolved,
+ expr.get_if_block ().get_locus ()),
+ TyTy::TyWithLocation (
+ else_blk_resolved, expr.get_else_block ().get_locus ()),
+ expr.get_locus ());
}
}
void
TypeCheckExpr::visit (HIR::UnsafeBlockExpr &expr)
{
- infered = TypeCheckExpr::Resolve (expr.get_block_expr ().get ());
+ infered = TypeCheckExpr::Resolve (expr.get_block_expr ());
}
void
@@ -515,7 +512,7 @@ TypeCheckExpr::visit (HIR::BlockExpr &expr)
if (!s->is_item ())
continue;
- TypeCheckStmt::Resolve (s.get ());
+ TypeCheckStmt::Resolve (*s);
}
for (auto &s : expr.get_statements ())
@@ -523,7 +520,7 @@ TypeCheckExpr::visit (HIR::BlockExpr &expr)
if (s->is_item ())
continue;
- auto resolved = TypeCheckStmt::Resolve (s.get ());
+ auto resolved = TypeCheckStmt::Resolve (*s);
if (resolved == nullptr)
{
rust_error_at (s->get_locus (), "failure to resolve type");
@@ -541,7 +538,7 @@ TypeCheckExpr::visit (HIR::BlockExpr &expr)
}
if (expr.has_expr ())
- infered = TypeCheckExpr::Resolve (expr.get_final_expr ().get ())->clone ();
+ infered = TypeCheckExpr::Resolve (expr.get_final_expr ())->clone ();
else if (expr.is_tail_reachable ())
infered = TyTy::TupleType::get_unit_type ();
else if (expr.has_label ())
@@ -595,14 +592,13 @@ TypeCheckExpr::visit (HIR::RangeFromToExpr &expr)
// resolve the range expressions and these types must unify then we use that
// type to substitute into the ADT
- TyTy::BaseType *from_ty
- = TypeCheckExpr::Resolve (expr.get_from_expr ().get ());
- TyTy::BaseType *to_ty = TypeCheckExpr::Resolve (expr.get_to_expr ().get ());
+ TyTy::BaseType *from_ty = TypeCheckExpr::Resolve (expr.get_from_expr ());
+ TyTy::BaseType *to_ty = TypeCheckExpr::Resolve (expr.get_to_expr ());
TyTy::BaseType *unified = unify_site (
expr.get_mappings ().get_hirid (),
- TyTy::TyWithLocation (from_ty, expr.get_from_expr ()->get_locus ()),
- TyTy::TyWithLocation (to_ty, expr.get_to_expr ()->get_locus ()),
+ TyTy::TyWithLocation (from_ty, expr.get_from_expr ().get_locus ()),
+ TyTy::TyWithLocation (to_ty, expr.get_to_expr ().get_locus ()),
expr.get_locus ());
// substitute it in
@@ -647,8 +643,7 @@ TypeCheckExpr::visit (HIR::RangeFromExpr &expr)
// resolve the range expressions and these types must unify then we use that
// type to substitute into the ADT
- TyTy::BaseType *from_ty
- = TypeCheckExpr::Resolve (expr.get_from_expr ().get ());
+ TyTy::BaseType *from_ty = TypeCheckExpr::Resolve (expr.get_from_expr ());
// substitute it in
std::vector<TyTy::SubstitutionArg> subst_mappings;
@@ -692,7 +687,7 @@ TypeCheckExpr::visit (HIR::RangeToExpr &expr)
// resolve the range expressions and these types must unify then we use that
// type to substitute into the ADT
- TyTy::BaseType *from_ty = TypeCheckExpr::Resolve (expr.get_to_expr ().get ());
+ TyTy::BaseType *from_ty = TypeCheckExpr::Resolve (expr.get_to_expr ());
// substitute it in
std::vector<TyTy::SubstitutionArg> subst_mappings;
@@ -716,38 +711,38 @@ typecheck_inline_asm_operand (HIR::InlineAsm &expr)
{
case RegisterType::In: {
auto in = operand.get_in ();
- TypeCheckExpr::Resolve (in.expr.get ());
+ TypeCheckExpr::Resolve (*in.expr);
break;
}
case RegisterType::Out: {
auto out = operand.get_out ();
- TypeCheckExpr::Resolve (out.expr.get ());
+ TypeCheckExpr::Resolve (*out.expr);
break;
}
case RegisterType::InOut: {
auto in_out = operand.get_in_out ();
- TypeCheckExpr::Resolve (in_out.expr.get ());
+ TypeCheckExpr::Resolve (*in_out.expr);
break;
}
case RegisterType::SplitInOut: {
auto split_in_out = operand.get_split_in_out ();
- TypeCheckExpr::Resolve (split_in_out.in_expr.get ());
- TypeCheckExpr::Resolve (split_in_out.out_expr.get ());
+ TypeCheckExpr::Resolve (*split_in_out.in_expr);
+ TypeCheckExpr::Resolve (*split_in_out.out_expr);
break;
}
case RegisterType::Const: {
auto anon_const = operand.get_const ().anon_const;
- TypeCheckExpr::Resolve (anon_const.expr.get ());
+ TypeCheckExpr::Resolve (*anon_const.expr);
break;
}
case RegisterType::Sym: {
auto sym = operand.get_sym ();
- TypeCheckExpr::Resolve (sym.expr.get ());
+ TypeCheckExpr::Resolve (*sym.expr);
break;
}
case RegisterType::Label: {
auto label = operand.get_label ();
- TypeCheckExpr::Resolve (label.expr.get ());
+ TypeCheckExpr::Resolve (*label.expr);
break;
}
}
@@ -826,13 +821,12 @@ TypeCheckExpr::visit (HIR::RangeFromToInclExpr &expr)
// resolve the range expressions and these types must unify then we use that
// type to substitute into the ADT
- TyTy::BaseType *from_ty
- = TypeCheckExpr::Resolve (expr.get_from_expr ().get ());
- TyTy::BaseType *to_ty = TypeCheckExpr::Resolve (expr.get_to_expr ().get ());
+ TyTy::BaseType *from_ty = TypeCheckExpr::Resolve (expr.get_from_expr ());
+ TyTy::BaseType *to_ty = TypeCheckExpr::Resolve (expr.get_to_expr ());
TyTy::BaseType *unified = unify_site (
expr.get_mappings ().get_hirid (),
- TyTy::TyWithLocation (from_ty, expr.get_from_expr ()->get_locus ()),
- TyTy::TyWithLocation (to_ty, expr.get_to_expr ()->get_locus ()),
+ TyTy::TyWithLocation (from_ty, expr.get_from_expr ().get_locus ()),
+ TyTy::TyWithLocation (to_ty, expr.get_to_expr ().get_locus ()),
expr.get_locus ());
// substitute it in
@@ -849,11 +843,11 @@ TypeCheckExpr::visit (HIR::RangeFromToInclExpr &expr)
void
TypeCheckExpr::visit (HIR::ArrayIndexExpr &expr)
{
- auto array_expr_ty = TypeCheckExpr::Resolve (expr.get_array_expr ().get ());
+ auto array_expr_ty = TypeCheckExpr::Resolve (expr.get_array_expr ());
if (array_expr_ty->get_kind () == TyTy::TypeKind::ERROR)
return;
- auto index_expr_ty = TypeCheckExpr::Resolve (expr.get_index_expr ().get ());
+ auto index_expr_ty = TypeCheckExpr::Resolve (expr.get_index_expr ());
if (index_expr_ty->get_kind () == TyTy::TypeKind::ERROR)
return;
@@ -876,10 +870,10 @@ TypeCheckExpr::visit (HIR::ArrayIndexExpr &expr)
if (maybe_simple_array_access
&& direct_array_expr_ty->get_kind () == TyTy::TypeKind::ARRAY)
{
- unify_site (expr.get_index_expr ()->get_mappings ().get_hirid (),
+ unify_site (expr.get_index_expr ().get_mappings ().get_hirid (),
TyTy::TyWithLocation (size_ty),
TyTy::TyWithLocation (index_expr_ty,
- expr.get_index_expr ()->get_locus ()),
+ expr.get_index_expr ().get_locus ()),
expr.get_locus ());
TyTy::ArrayType *array_type
@@ -906,8 +900,8 @@ TypeCheckExpr::visit (HIR::ArrayIndexExpr &expr)
// error[E0277]: the type `[{integer}]` cannot be indexed by `u32`
rich_location r (line_table, expr.get_locus ());
- r.add_range (expr.get_array_expr ()->get_locus ());
- r.add_range (expr.get_index_expr ()->get_locus ());
+ r.add_range (expr.get_array_expr ().get_locus ());
+ r.add_range (expr.get_index_expr ().get_locus ());
rust_error_at (r, ErrorCode::E0277,
"the type %qs cannot be indexed by %qs",
array_expr_ty->get_name ().c_str (),
@@ -917,7 +911,7 @@ TypeCheckExpr::visit (HIR::ArrayIndexExpr &expr)
void
TypeCheckExpr::visit (HIR::ArrayExpr &expr)
{
- HIR::ArrayElems &elements = *expr.get_internal_elements ();
+ auto &elements = expr.get_internal_elements ();
HIR::Expr *capacity_expr = nullptr;
TyTy::BaseType *element_type = nullptr;
@@ -926,25 +920,24 @@ TypeCheckExpr::visit (HIR::ArrayExpr &expr)
case HIR::ArrayElems::ArrayExprType::COPIED: {
HIR::ArrayElemsCopied &elems
= static_cast<HIR::ArrayElemsCopied &> (elements);
- element_type
- = TypeCheckExpr::Resolve (elems.get_elem_to_copy ().get ());
+ element_type = TypeCheckExpr::Resolve (elems.get_elem_to_copy ());
auto capacity_type
- = TypeCheckExpr::Resolve (elems.get_num_copies_expr ().get ());
+ = TypeCheckExpr::Resolve (elems.get_num_copies_expr ());
TyTy::BaseType *expected_ty = nullptr;
bool ok = context->lookup_builtin ("usize", &expected_ty);
rust_assert (ok);
- context->insert_type (elems.get_num_copies_expr ()->get_mappings (),
+ context->insert_type (elems.get_num_copies_expr ().get_mappings (),
expected_ty);
- unify_site (
- expr.get_mappings ().get_hirid (), TyTy::TyWithLocation (expected_ty),
- TyTy::TyWithLocation (capacity_type,
- elems.get_num_copies_expr ()->get_locus ()),
- expr.get_locus ());
+ unify_site (expr.get_mappings ().get_hirid (),
+ TyTy::TyWithLocation (expected_ty),
+ TyTy::TyWithLocation (
+ capacity_type, elems.get_num_copies_expr ().get_locus ()),
+ expr.get_locus ());
- capacity_expr = elems.get_num_copies_expr ().get ();
+ capacity_expr = &elems.get_num_copies_expr ();
}
break;
@@ -955,7 +948,7 @@ TypeCheckExpr::visit (HIR::ArrayExpr &expr)
std::vector<TyTy::BaseType *> types;
for (auto &elem : elems.get_values ())
{
- types.push_back (TypeCheckExpr::Resolve (elem.get ()));
+ types.push_back (TypeCheckExpr::Resolve (*elem));
}
// this is a LUB
@@ -999,7 +992,7 @@ void
TypeCheckExpr::visit (HIR::StructExprStruct &struct_expr)
{
TyTy::BaseType *struct_path_ty
- = TypeCheckExpr::Resolve (&struct_expr.get_struct_name ());
+ = TypeCheckExpr::Resolve (struct_expr.get_struct_name ());
if (struct_path_ty->get_kind () != TyTy::TypeKind::ADT)
{
rust_error_at (struct_expr.get_struct_name ().get_locus (),
@@ -1031,19 +1024,19 @@ TypeCheckExpr::visit (HIR::StructExprStruct &struct_expr)
void
TypeCheckExpr::visit (HIR::StructExprStructFields &struct_expr)
{
- infered = TypeCheckStructExpr::Resolve (&struct_expr);
+ infered = TypeCheckStructExpr::Resolve (struct_expr);
}
void
TypeCheckExpr::visit (HIR::GroupedExpr &expr)
{
- infered = TypeCheckExpr::Resolve (expr.get_expr_in_parens ().get ());
+ infered = TypeCheckExpr::Resolve (expr.get_expr_in_parens ());
}
void
TypeCheckExpr::visit (HIR::FieldAccessExpr &expr)
{
- auto struct_base = TypeCheckExpr::Resolve (expr.get_receiver_expr ().get ());
+ auto struct_base = TypeCheckExpr::Resolve (expr.get_receiver_expr ());
// FIXME does this require autoderef here?
if (struct_base->get_kind () == TyTy::TypeKind::REF)
@@ -1085,10 +1078,10 @@ TypeCheckExpr::visit (HIR::FieldAccessExpr &expr)
void
TypeCheckExpr::visit (HIR::MethodCallExpr &expr)
{
- auto receiver_tyty = TypeCheckExpr::Resolve (expr.get_receiver ().get ());
+ auto receiver_tyty = TypeCheckExpr::Resolve (expr.get_receiver ());
if (receiver_tyty->get_kind () == TyTy::TypeKind::ERROR)
{
- rust_error_at (expr.get_receiver ()->get_locus (),
+ rust_error_at (expr.get_receiver ().get_locus (),
"failed to resolve receiver in MethodCallExpr");
return;
}
@@ -1147,7 +1140,7 @@ TypeCheckExpr::visit (HIR::MethodCallExpr &expr)
// stored onto the receiver to so as we don't trigger duplicate deref mappings
// ICE when an argument is a method call
HirId autoderef_mappings_id
- = expr.get_receiver ()->get_mappings ().get_hirid ();
+ = expr.get_receiver ().get_mappings ().get_hirid ();
context->insert_autoderef_mappings (autoderef_mappings_id,
std::move (candidate.adjustments));
@@ -1195,7 +1188,7 @@ TypeCheckExpr::visit (HIR::MethodCallExpr &expr)
if (impl_self_infer->get_kind () == TyTy::TypeKind::ERROR)
{
rich_location r (line_table, expr.get_locus ());
- r.add_range (impl.get_type ()->get_locus ());
+ r.add_range (impl.get_type ().get_locus ());
rust_error_at (
r, "failed to resolve impl type for method call resolution");
return;
@@ -1267,11 +1260,10 @@ TypeCheckExpr::visit (HIR::LoopExpr &expr)
{
context->push_new_loop_context (expr.get_mappings ().get_hirid (),
expr.get_locus ());
- TyTy::BaseType *block_expr
- = TypeCheckExpr::Resolve (expr.get_loop_block ().get ());
+ TyTy::BaseType *block_expr = TypeCheckExpr::Resolve (expr.get_loop_block ());
if (!block_expr->is_unit ())
{
- rust_error_at (expr.get_loop_block ()->get_locus (),
+ rust_error_at (expr.get_loop_block ().get_locus (),
"expected %<()%> got %s",
block_expr->as_string ().c_str ());
return;
@@ -1294,13 +1286,12 @@ TypeCheckExpr::visit (HIR::WhileLoopExpr &expr)
{
context->push_new_while_loop_context (expr.get_mappings ().get_hirid ());
- TypeCheckExpr::Resolve (expr.get_predicate_expr ().get ());
- TyTy::BaseType *block_expr
- = TypeCheckExpr::Resolve (expr.get_loop_block ().get ());
+ TypeCheckExpr::Resolve (expr.get_predicate_expr ());
+ TyTy::BaseType *block_expr = TypeCheckExpr::Resolve (expr.get_loop_block ());
if (!block_expr->is_unit ())
{
- rust_error_at (expr.get_loop_block ()->get_locus (),
+ rust_error_at (expr.get_loop_block ().get_locus (),
"expected %<()%> got %s",
block_expr->as_string ().c_str ());
return;
@@ -1323,7 +1314,7 @@ TypeCheckExpr::visit (HIR::BreakExpr &expr)
if (expr.has_break_expr ())
{
TyTy::BaseType *break_expr_tyty
- = TypeCheckExpr::Resolve (expr.get_expr ().get ());
+ = TypeCheckExpr::Resolve (expr.get_expr ());
TyTy::BaseType *loop_context = context->peek_loop_context ();
if (loop_context->get_kind () == TyTy::TypeKind::ERROR)
@@ -1338,7 +1329,7 @@ TypeCheckExpr::visit (HIR::BreakExpr &expr)
= unify_site (expr.get_mappings ().get_hirid (),
TyTy::TyWithLocation (loop_context),
TyTy::TyWithLocation (break_expr_tyty,
- expr.get_expr ()->get_locus ()),
+ expr.get_expr ().get_locus ()),
expr.get_locus ());
context->swap_head_loop_context (unified_ty);
}
@@ -1362,8 +1353,7 @@ TypeCheckExpr::visit (HIR::ContinueExpr &expr)
void
TypeCheckExpr::visit (HIR::BorrowExpr &expr)
{
- TyTy::BaseType *resolved_base
- = TypeCheckExpr::Resolve (expr.get_expr ().get ());
+ TyTy::BaseType *resolved_base = TypeCheckExpr::Resolve (expr.get_expr ());
// In Rust this is valid because of DST's
//
@@ -1393,8 +1383,7 @@ TypeCheckExpr::visit (HIR::BorrowExpr &expr)
void
TypeCheckExpr::visit (HIR::DereferenceExpr &expr)
{
- TyTy::BaseType *resolved_base
- = TypeCheckExpr::Resolve (expr.get_expr ().get ());
+ TyTy::BaseType *resolved_base = TypeCheckExpr::Resolve (expr.get_expr ());
rust_debug_loc (expr.get_locus (), "attempting deref operator overload");
auto lang_item_type = LangItem::Kind::DEREF;
@@ -1435,14 +1424,14 @@ void
TypeCheckExpr::visit (HIR::TypeCastExpr &expr)
{
TyTy::BaseType *expr_to_convert
- = TypeCheckExpr::Resolve (expr.get_casted_expr ().get ());
+ = TypeCheckExpr::Resolve (expr.get_casted_expr ());
TyTy::BaseType *tyty_to_convert_to
- = TypeCheckType::Resolve (expr.get_type_to_convert_to ().get ());
+ = TypeCheckType::Resolve (expr.get_type_to_convert_to ());
TyTy::TyWithLocation from (expr_to_convert,
- expr.get_casted_expr ()->get_locus ());
+ expr.get_casted_expr ().get_locus ());
TyTy::TyWithLocation to (tyty_to_convert_to,
- expr.get_type_to_convert_to ()->get_locus ());
+ expr.get_type_to_convert_to ().get_locus ());
infered = cast_site (expr.get_mappings ().get_hirid (), from, to,
expr.get_locus ());
}
@@ -1453,7 +1442,7 @@ TypeCheckExpr::visit (HIR::MatchExpr &expr)
// this needs to perform a least upper bound coercion on the blocks and then
// unify the scruintee and arms
TyTy::BaseType *scrutinee_tyty
- = TypeCheckExpr::Resolve (expr.get_scrutinee_expr ().get ());
+ = TypeCheckExpr::Resolve (expr.get_scrutinee_expr ());
bool saw_error = false;
std::vector<TyTy::BaseType *> kase_block_tys;
@@ -1464,7 +1453,7 @@ TypeCheckExpr::visit (HIR::MatchExpr &expr)
for (auto &pattern : kase_arm.get_patterns ())
{
TyTy::BaseType *kase_arm_ty
- = TypeCheckPattern::Resolve (pattern.get (), scrutinee_tyty);
+ = TypeCheckPattern::Resolve (*pattern, scrutinee_tyty);
if (kase_arm_ty->get_kind () == TyTy ::TypeKind::ERROR)
{
saw_error = true;
@@ -1474,7 +1463,7 @@ TypeCheckExpr::visit (HIR::MatchExpr &expr)
TyTy::BaseType *checked_kase = unify_site (
expr.get_mappings ().get_hirid (),
TyTy::TyWithLocation (scrutinee_tyty,
- expr.get_scrutinee_expr ()->get_locus ()),
+ expr.get_scrutinee_expr ().get_locus ()),
TyTy::TyWithLocation (kase_arm_ty, pattern->get_locus ()),
expr.get_locus ());
if (checked_kase->get_kind () == TyTy::TypeKind::ERROR)
@@ -1485,8 +1474,7 @@ TypeCheckExpr::visit (HIR::MatchExpr &expr)
}
// check the kase type
- TyTy::BaseType *kase_block_ty
- = TypeCheckExpr::Resolve (kase.get_expr ().get ());
+ TyTy::BaseType *kase_block_ty = TypeCheckExpr::Resolve (kase.get_expr ());
kase_block_tys.push_back (kase_block_ty);
}
if (saw_error)
@@ -1529,17 +1517,17 @@ TypeCheckExpr::visit (HIR::ClosureExpr &expr)
TyTy::BaseType *param_tyty = nullptr;
if (p.has_type_given ())
{
- param_tyty = TypeCheckType::Resolve (p.get_type ().get ());
+ param_tyty = TypeCheckType::Resolve (p.get_type ());
}
else
{
- param_tyty = ClosureParamInfer::Resolve (p.get_pattern ().get ());
+ param_tyty = ClosureParamInfer::Resolve (p.get_pattern ());
}
TyTy::TyVar param_ty (param_tyty->get_ref ());
parameter_types.push_back (param_ty);
- TypeCheckPattern::Resolve (p.get_pattern ().get (), param_ty.get_tyty ());
+ TypeCheckPattern::Resolve (p.get_pattern (), param_ty.get_tyty ());
}
// we generate an implicit hirid for the closure args
@@ -1550,18 +1538,17 @@ TypeCheckExpr::visit (HIR::ClosureExpr &expr)
context->insert_implicit_type (closure_args);
location_t result_type_locus = expr.has_return_type ()
- ? expr.get_return_type ()->get_locus ()
+ ? expr.get_return_type ().get_locus ()
: expr.get_locus ();
TyTy::TyVar result_type
= expr.has_return_type ()
? TyTy::TyVar (
- TypeCheckType::Resolve (expr.get_return_type ().get ())->get_ref ())
+ TypeCheckType::Resolve (expr.get_return_type ())->get_ref ())
: TyTy::TyVar::get_implicit_infer_var (expr.get_locus ());
// resolve the block
- location_t closure_expr_locus = expr.get_expr ()->get_locus ();
- TyTy::BaseType *closure_expr_ty
- = TypeCheckExpr::Resolve (expr.get_expr ().get ());
+ location_t closure_expr_locus = expr.get_expr ().get_locus ();
+ TyTy::BaseType *closure_expr_ty = TypeCheckExpr::Resolve (expr.get_expr ());
coercion_site (expr.get_mappings ().get_hirid (),
TyTy::TyWithLocation (result_type.get_tyty (),
result_type_locus),
@@ -1764,7 +1751,7 @@ TypeCheckExpr::resolve_operator_overload (LangItem::Kind lang_item_type,
if (parent->has_trait_ref () && is_recursive_op)
{
TraitReference *trait_reference
- = TraitResolver::Lookup (*parent->get_trait_ref ().get ());
+ = TraitResolver::Lookup (parent->get_trait_ref ());
if (!trait_reference->is_error ())
{
TyTy::BaseType *lookup = nullptr;
@@ -1804,7 +1791,7 @@ TypeCheckExpr::resolve_operator_overload (LangItem::Kind lang_item_type,
// type check the arguments if required
TyTy::FnType *type = static_cast<TyTy::FnType *> (lookup);
rust_assert (type->num_params () > 0);
- auto fnparam = type->param_at (0);
+ auto &fnparam = type->param_at (0);
// typecheck the self
unify_site (expr.get_mappings ().get_hirid (),
@@ -1817,7 +1804,7 @@ TypeCheckExpr::resolve_operator_overload (LangItem::Kind lang_item_type,
else
{
rust_assert (type->num_params () == 2);
- auto fnparam = type->param_at (1);
+ auto &fnparam = type->param_at (1);
unify_site (expr.get_mappings ().get_hirid (),
TyTy::TyWithLocation (fnparam.second),
TyTy::TyWithLocation (rhs), expr.get_locus ());
@@ -1933,8 +1920,8 @@ TypeCheckExpr::resolve_fn_trait_call (HIR::CallExpr &expr,
// store the adjustments for code-generation to know what to do which must be
// stored onto the receiver to so as we don't trigger duplicate deref mappings
// ICE when an argument is a method call
- HIR::Expr *fnexpr = expr.get_fnexpr ().get ();
- HirId autoderef_mappings_id = fnexpr->get_mappings ().get_hirid ();
+ HIR::Expr &fnexpr = expr.get_fnexpr ();
+ HirId autoderef_mappings_id = fnexpr.get_mappings ().get_hirid ();
context->insert_autoderef_mappings (autoderef_mappings_id,
std::move (candidate.adjustments));
context->insert_receiver (expr.get_mappings ().get_hirid (), receiver_tyty);
@@ -1971,7 +1958,7 @@ TypeCheckExpr::resolve_fn_trait_call (HIR::CallExpr &expr,
std::vector<TyTy::TyVar> call_args;
for (auto &arg : expr.get_arguments ())
{
- TyTy::BaseType *a = TypeCheckExpr::Resolve (arg.get ());
+ TyTy::BaseType *a = TypeCheckExpr::Resolve (*arg);
call_args.push_back (TyTy::TyVar (a->get_ref ()));
}
diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.h b/gcc/rust/typecheck/rust-hir-type-check-expr.h
index 997761144db..82f421e326a 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.h
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.h
@@ -29,7 +29,7 @@ namespace Resolver {
class TypeCheckExpr : private TypeCheckBase, private HIR::HIRExpressionVisitor
{
public:
- static TyTy::BaseType *Resolve (HIR::Expr *expr);
+ static TyTy::BaseType *Resolve (HIR::Expr &expr);
void visit (HIR::TupleIndexExpr &expr) override;
void visit (HIR::TupleExpr &expr) override;
diff --git a/gcc/rust/typecheck/rust-hir-type-check-implitem.cc b/gcc/rust/typecheck/rust-hir-type-check-implitem.cc
index 19f25e4f867..2173938fb15 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-implitem.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-implitem.cc
@@ -18,6 +18,8 @@
#include "rust-hir-type-check-implitem.h"
#include "rust-diagnostics.h"
+#include "rust-hir-full-decls.h"
+#include "rust-hir-pattern.h"
#include "rust-hir-type-check-base.h"
#include "rust-hir-type-check-type.h"
#include "rust-hir-type-check-expr.h"
@@ -38,27 +40,26 @@ TypeCheckTopLevelExternItem::TypeCheckTopLevelExternItem (
{}
TyTy::BaseType *
-TypeCheckTopLevelExternItem::Resolve (HIR::ExternalItem *item,
+TypeCheckTopLevelExternItem::Resolve (HIR::ExternalItem &item,
const HIR::ExternBlock &parent)
{
// is it already resolved?
auto context = TypeCheckContext::get ();
TyTy::BaseType *resolved = nullptr;
bool already_resolved
- = context->lookup_type (item->get_mappings ().get_hirid (), &resolved);
+ = context->lookup_type (item.get_mappings ().get_hirid (), &resolved);
if (already_resolved)
return resolved;
TypeCheckTopLevelExternItem resolver (parent);
- item->accept_vis (resolver);
+ item.accept_vis (resolver);
return resolver.resolved;
}
void
TypeCheckTopLevelExternItem::visit (HIR::ExternalStaticItem &item)
{
- TyTy::BaseType *actual_type
- = TypeCheckType::Resolve (item.get_item_type ().get ());
+ TyTy::BaseType *actual_type = TypeCheckType::Resolve (item.get_item_type ());
context->insert_type (item.get_mappings (), actual_type);
resolved = actual_type;
@@ -89,7 +90,7 @@ TypeCheckTopLevelExternItem::visit (HIR::ExternalFunctionItem &function)
case HIR::GenericParam::GenericKind::TYPE: {
auto param_type
- = TypeResolveGenericParam::Resolve (generic_param.get ());
+ = TypeResolveGenericParam::Resolve (*generic_param);
context->insert_type (generic_param->get_mappings (),
param_type);
@@ -106,7 +107,7 @@ TypeCheckTopLevelExternItem::visit (HIR::ExternalFunctionItem &function)
{
for (auto &where_clause_item : function.get_where_clause ().get_items ())
{
- ResolveWhereClauseItem::Resolve (*where_clause_item.get (),
+ ResolveWhereClauseItem::Resolve (*where_clause_item,
region_constraints);
}
}
@@ -116,8 +117,7 @@ TypeCheckTopLevelExternItem::visit (HIR::ExternalFunctionItem &function)
ret_type = TyTy::TupleType::get_unit_type ();
else
{
- auto resolved
- = TypeCheckType::Resolve (function.get_return_type ().get ());
+ auto resolved = TypeCheckType::Resolve (function.get_return_type ());
if (resolved == nullptr)
{
rust_error_at (function.get_locus (),
@@ -127,14 +127,15 @@ TypeCheckTopLevelExternItem::visit (HIR::ExternalFunctionItem &function)
ret_type = resolved->clone ();
ret_type->set_ref (
- function.get_return_type ()->get_mappings ().get_hirid ());
+ function.get_return_type ().get_mappings ().get_hirid ());
}
std::vector<std::pair<HIR::Pattern *, TyTy::BaseType *> > params;
+ std::unique_ptr<HIR::IdentifierPattern> param_pattern = nullptr;
for (auto ¶m : function.get_function_params ())
{
// get the name as well required for later on
- auto param_tyty = TypeCheckType::Resolve (param.get_type ().get ());
+ auto param_tyty = TypeCheckType::Resolve (param.get_type ());
// these are implicit mappings and not used
auto crate_num = mappings.get_current_crate ();
@@ -142,13 +143,13 @@ TypeCheckTopLevelExternItem::visit (HIR::ExternalFunctionItem &function)
mappings.get_next_hir_id (crate_num),
UNKNOWN_LOCAL_DEFID);
- HIR::IdentifierPattern *param_pattern
- = new HIR::IdentifierPattern (mapping, param.get_param_name (),
- UNDEF_LOCATION, false, Mutability::Imm,
- std::unique_ptr<HIR::Pattern> (nullptr));
+ param_pattern = Rust::make_unique<HIR::IdentifierPattern> (
+ HIR::IdentifierPattern (mapping, param.get_param_name (),
+ UNDEF_LOCATION, false, Mutability::Imm,
+ std::unique_ptr<HIR::Pattern> (nullptr)));
params.push_back (
- std::pair<HIR::Pattern *, TyTy::BaseType *> (param_pattern,
+ std::pair<HIR::Pattern *, TyTy::BaseType *> (param_pattern.get (),
param_tyty));
context->insert_type (param.get_mappings (), param_tyty);
@@ -316,7 +317,7 @@ TypeCheckTopLevelExternItem::visit (HIR::ExternalTypeItem &type)
}
TypeCheckImplItem::TypeCheckImplItem (
- HIR::ImplBlock *parent, TyTy::BaseType *self,
+ HIR::ImplBlock &parent, TyTy::BaseType *self,
std::vector<TyTy::SubstitutionParamMapping> substitutions)
: TypeCheckBase (), parent (parent), self (self),
substitutions (substitutions)
@@ -324,20 +325,20 @@ TypeCheckImplItem::TypeCheckImplItem (
TyTy::BaseType *
TypeCheckImplItem::Resolve (
- HIR::ImplBlock *parent, HIR::ImplItem *item, TyTy::BaseType *self,
+ HIR::ImplBlock &parent, HIR::ImplItem &item, TyTy::BaseType *self,
std::vector<TyTy::SubstitutionParamMapping> substitutions)
{
// is it already resolved?
auto context = TypeCheckContext::get ();
TyTy::BaseType *resolved = nullptr;
bool already_resolved
- = context->lookup_type (item->get_impl_mappings ().get_hirid (), &resolved);
+ = context->lookup_type (item.get_impl_mappings ().get_hirid (), &resolved);
if (already_resolved)
return resolved;
// resolve
TypeCheckImplItem resolver (parent, self, substitutions);
- item->accept_vis (resolver);
+ item.accept_vis (resolver);
return resolver.result;
}
@@ -361,8 +362,7 @@ TypeCheckImplItem::visit (HIR::Function &function)
ret_type = TyTy::TupleType::get_unit_type ();
else
{
- auto resolved
- = TypeCheckType::Resolve (function.get_return_type ().get ());
+ auto resolved = TypeCheckType::Resolve (function.get_return_type ());
if (resolved == nullptr)
{
rust_error_at (function.get_locus (),
@@ -372,10 +372,11 @@ TypeCheckImplItem::visit (HIR::Function &function)
ret_type = resolved->clone ();
ret_type->set_ref (
- function.get_return_type ()->get_mappings ().get_hirid ());
+ function.get_return_type ().get_mappings ().get_hirid ());
}
std::vector<std::pair<HIR::Pattern *, TyTy::BaseType *> > params;
+ std::unique_ptr<HIR::IdentifierPattern> self_pattern = nullptr;
if (function.is_method ())
{
// these are implicit mappings and not used
@@ -389,16 +390,17 @@ TypeCheckImplItem::visit (HIR::Function &function)
// reuse the HIR identifier pattern which requires it
HIR::SelfParam &self_param = function.get_self_param ();
// FIXME: which location should be used for Rust::Identifier for `self`?
- HIR::IdentifierPattern *self_pattern = new HIR::IdentifierPattern (
- mapping, {"self"}, self_param.get_locus (), self_param.is_ref (),
- self_param.get_mut (), std::unique_ptr<HIR::Pattern> (nullptr));
+ self_pattern = Rust::make_unique<HIR::IdentifierPattern> (
+ HIR::IdentifierPattern (mapping, {"self"}, self_param.get_locus (),
+ self_param.is_ref (), self_param.get_mut (),
+ std::unique_ptr<HIR::Pattern> (nullptr)));
// might have a specified type
TyTy::BaseType *self_type = nullptr;
if (self_param.has_type ())
{
- std::unique_ptr<HIR::Type> &specified_type = self_param.get_type ();
- self_type = TypeCheckType::Resolve (specified_type.get ());
+ auto &specified_type = self_param.get_type ();
+ self_type = TypeCheckType::Resolve (specified_type);
}
else
{
@@ -449,18 +451,21 @@ TypeCheckImplItem::visit (HIR::Function &function)
context->insert_type (self_param.get_mappings (), self_type);
params.push_back (
- std::pair<HIR::Pattern *, TyTy::BaseType *> (self_pattern, self_type));
+ std::pair<HIR::Pattern *, TyTy::BaseType *> (self_pattern.get (),
+ self_type));
}
for (auto ¶m : function.get_function_params ())
{
// get the name as well required for later on
- auto param_tyty = TypeCheckType::Resolve (param.get_type ().get ());
- params.push_back (std::pair<HIR::Pattern *, TyTy::BaseType *> (
- param.get_param_name ().get (), param_tyty));
+ auto param_tyty = TypeCheckType::Resolve (param.get_type ());
context->insert_type (param.get_mappings (), param_tyty);
- TypeCheckPattern::Resolve (param.get_param_name ().get (), param_tyty);
+ TypeCheckPattern::Resolve (param.get_param_name (), param_tyty);
+
+ params.push_back (
+ std::pair<HIR::Pattern *, TyTy::BaseType *> (¶m.get_param_name (),
+ param_tyty));
}
tl::optional<CanonicalPath> canonical_path;
@@ -502,17 +507,16 @@ TypeCheckImplItem::visit (HIR::Function &function)
context->push_return_type (TypeCheckContextItem (parent, &function),
expected_ret_tyty);
- auto block_expr_ty
- = TypeCheckExpr::Resolve (function.get_definition ().get ());
+ auto block_expr_ty = TypeCheckExpr::Resolve (function.get_definition ());
location_t fn_return_locus = function.has_function_return_type ()
- ? function.get_return_type ()->get_locus ()
+ ? function.get_return_type ().get_locus ()
: function.get_locus ();
- coercion_site (function.get_definition ()->get_mappings ().get_hirid (),
+ coercion_site (function.get_definition ().get_mappings ().get_hirid (),
TyTy::TyWithLocation (expected_ret_tyty, fn_return_locus),
TyTy::TyWithLocation (block_expr_ty),
- function.get_definition ()->get_locus ());
+ function.get_definition ().get_locus ());
context->pop_return_type ();
}
@@ -520,14 +524,13 @@ TypeCheckImplItem::visit (HIR::Function &function)
void
TypeCheckImplItem::visit (HIR::ConstantItem &constant)
{
- TyTy::BaseType *type = TypeCheckType::Resolve (constant.get_type ().get ());
- TyTy::BaseType *expr_type
- = TypeCheckExpr::Resolve (constant.get_expr ().get ());
+ TyTy::BaseType *type = TypeCheckType::Resolve (constant.get_type ());
+ TyTy::BaseType *expr_type = TypeCheckExpr::Resolve (constant.get_expr ());
TyTy::BaseType *unified = unify_site (
constant.get_mappings ().get_hirid (),
- TyTy::TyWithLocation (type, constant.get_type ()->get_locus ()),
- TyTy::TyWithLocation (expr_type, constant.get_expr ()->get_locus ()),
+ TyTy::TyWithLocation (type, constant.get_type ().get_locus ()),
+ TyTy::TyWithLocation (expr_type, constant.get_expr ().get_locus ()),
constant.get_locus ());
context->insert_type (constant.get_mappings (), unified);
result = unified;
@@ -542,7 +545,7 @@ TypeCheckImplItem::visit (HIR::TypeAlias &alias)
resolve_generic_params (alias.get_generic_params (), substitutions);
TyTy::BaseType *actual_type
- = TypeCheckType::Resolve (alias.get_type_aliased ().get ());
+ = TypeCheckType::Resolve (alias.get_type_aliased ());
context->insert_type (alias.get_mappings (), actual_type);
result = actual_type;
@@ -555,7 +558,7 @@ TypeCheckImplItem::visit (HIR::TypeAlias &alias)
}
TypeCheckImplItemWithTrait::TypeCheckImplItemWithTrait (
- HIR::ImplBlock *parent, TyTy::BaseType *self,
+ HIR::ImplBlock &parent, TyTy::BaseType *self,
TyTy::TypeBoundPredicate &trait_reference,
std::vector<TyTy::SubstitutionParamMapping> substitutions)
: TypeCheckBase (), trait_reference (trait_reference),
@@ -567,13 +570,13 @@ TypeCheckImplItemWithTrait::TypeCheckImplItemWithTrait (
TyTy::TypeBoundPredicateItem
TypeCheckImplItemWithTrait::Resolve (
- HIR::ImplBlock *parent, HIR::ImplItem *item, TyTy::BaseType *self,
+ HIR::ImplBlock &parent, HIR::ImplItem &item, TyTy::BaseType *self,
TyTy::TypeBoundPredicate &trait_reference,
std::vector<TyTy::SubstitutionParamMapping> substitutions)
{
TypeCheckImplItemWithTrait resolver (parent, self, trait_reference,
substitutions);
- item->accept_vis (resolver);
+ item.accept_vis (resolver);
return resolver.resolved_trait_item;
}
@@ -582,7 +585,7 @@ TypeCheckImplItemWithTrait::visit (HIR::ConstantItem &constant)
{
// normal resolution of the item
TyTy::BaseType *lookup
- = TypeCheckImplItem::Resolve (parent, &constant, self, substitutions);
+ = TypeCheckImplItem::Resolve (parent, constant, self, substitutions);
// map the impl item to the associated trait item
const auto tref = trait_reference.get ();
@@ -635,7 +638,7 @@ TypeCheckImplItemWithTrait::visit (HIR::TypeAlias &type)
{
// normal resolution of the item
TyTy::BaseType *lookup
- = TypeCheckImplItem::Resolve (parent, &type, self, substitutions);
+ = TypeCheckImplItem::Resolve (parent, type, self, substitutions);
// map the impl item to the associated trait item
const auto tref = trait_reference.get ();
@@ -696,7 +699,7 @@ TypeCheckImplItemWithTrait::visit (HIR::Function &function)
{
// normal resolution of the item
TyTy::BaseType *lookup
- = TypeCheckImplItem::Resolve (parent, &function, self, substitutions);
+ = TypeCheckImplItem::Resolve (parent, function, self, substitutions);
// map the impl item to the associated trait item
const auto tref = trait_reference.get ();
diff --git a/gcc/rust/typecheck/rust-hir-type-check-implitem.h b/gcc/rust/typecheck/rust-hir-type-check-implitem.h
index 4fb2256c6b4..14f6a05a00f 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-implitem.h
+++ b/gcc/rust/typecheck/rust-hir-type-check-implitem.h
@@ -29,7 +29,7 @@ class TypeCheckTopLevelExternItem : public TypeCheckBase,
public HIR::HIRExternalItemVisitor
{
public:
- static TyTy::BaseType *Resolve (HIR::ExternalItem *item,
+ static TyTy::BaseType *Resolve (HIR::ExternalItem &item,
const HIR::ExternBlock &parent);
void visit (HIR::ExternalStaticItem &item) override;
@@ -47,7 +47,7 @@ class TypeCheckImplItem : public TypeCheckBase, public HIR::HIRImplVisitor
{
public:
static TyTy::BaseType *
- Resolve (HIR::ImplBlock *parent, HIR::ImplItem *item, TyTy::BaseType *self,
+ Resolve (HIR::ImplBlock &parent, HIR::ImplItem &item, TyTy::BaseType *self,
std::vector<TyTy::SubstitutionParamMapping> substitutions);
void visit (HIR::Function &function) override;
@@ -55,10 +55,10 @@ public:
void visit (HIR::TypeAlias &type_alias) override;
protected:
- TypeCheckImplItem (HIR::ImplBlock *parent, TyTy::BaseType *self,
+ TypeCheckImplItem (HIR::ImplBlock &parent, TyTy::BaseType *self,
std::vector<TyTy::SubstitutionParamMapping> substitutions);
- HIR::ImplBlock *parent;
+ HIR::ImplBlock &parent;
TyTy::BaseType *self;
std::vector<TyTy::SubstitutionParamMapping> substitutions;
@@ -70,7 +70,7 @@ class TypeCheckImplItemWithTrait : public TypeCheckBase,
{
public:
static TyTy::TypeBoundPredicateItem
- Resolve (HIR::ImplBlock *parent, HIR::ImplItem *item, TyTy::BaseType *self,
+ Resolve (HIR::ImplBlock &parent, HIR::ImplItem &item, TyTy::BaseType *self,
TyTy::TypeBoundPredicate &trait_reference,
std::vector<TyTy::SubstitutionParamMapping> substitutions);
@@ -86,7 +86,7 @@ protected:
private:
TypeCheckImplItemWithTrait (
- HIR::ImplBlock *parent, TyTy::BaseType *self,
+ HIR::ImplBlock &parent, TyTy::BaseType *self,
TyTy::TypeBoundPredicate &trait_reference,
std::vector<TyTy::SubstitutionParamMapping> substitutions);
@@ -95,7 +95,7 @@ private:
TyTy::TypeBoundPredicate &trait_reference;
TyTy::TypeBoundPredicateItem resolved_trait_item;
- HIR::ImplBlock *parent;
+ HIR::ImplBlock &parent;
TyTy::BaseType *self;
std::vector<TyTy::SubstitutionParamMapping> substitutions;
TyTy::RegionConstraints region_constraints;
diff --git a/gcc/rust/typecheck/rust-hir-type-check-item.cc b/gcc/rust/typecheck/rust-hir-type-check-item.cc
index 0652777c8c6..e84ae333071 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-item.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-item.cc
@@ -150,7 +150,7 @@ void
TypeCheckItem::visit (HIR::TypeAlias &alias)
{
TyTy::BaseType *actual_type
- = TypeCheckType::Resolve (alias.get_type_aliased ().get ());
+ = TypeCheckType::Resolve (alias.get_type_aliased ());
context->insert_type (alias.get_mappings (), actual_type);
@@ -182,7 +182,7 @@ TypeCheckItem::visit (HIR::TupleStruct &struct_decl)
for (auto &field : struct_decl.get_fields ())
{
TyTy::BaseType *field_type
- = TypeCheckType::Resolve (field.get_field_type ().get ());
+ = TypeCheckType::Resolve (field.get_field_type ());
auto *ty_field
= new TyTy::StructFieldType (field.get_mappings ().get_hirid (),
std::to_string (idx), field_type,
@@ -265,7 +265,7 @@ TypeCheckItem::visit (HIR::StructStruct &struct_decl)
for (auto &field : struct_decl.get_fields ())
{
TyTy::BaseType *field_type
- = TypeCheckType::Resolve (field.get_field_type ().get ());
+ = TypeCheckType::Resolve (field.get_field_type ());
auto *ty_field
= new TyTy::StructFieldType (field.get_mappings ().get_hirid (),
field.get_field_name ().as_string (),
@@ -341,7 +341,7 @@ TypeCheckItem::visit (HIR::Enum &enum_decl)
for (auto &variant : enum_decl.get_variants ())
{
TyTy::VariantDef *field_type
- = TypeCheckEnumItem::Resolve (variant.get (), discriminant_value);
+ = TypeCheckEnumItem::Resolve (*variant, discriminant_value);
discriminant_value++;
variants.push_back (field_type);
@@ -400,7 +400,7 @@ TypeCheckItem::visit (HIR::Union &union_decl)
for (auto &variant : union_decl.get_variants ())
{
TyTy::BaseType *variant_type
- = TypeCheckType::Resolve (variant.get_field_type ().get ());
+ = TypeCheckType::Resolve (variant.get_field_type ());
auto *ty_variant
= new TyTy::StructFieldType (variant.get_mappings ().get_hirid (),
variant.get_field_name ().as_string (),
@@ -456,14 +456,14 @@ TypeCheckItem::visit (HIR::Union &union_decl)
void
TypeCheckItem::visit (HIR::StaticItem &var)
{
- TyTy::BaseType *type = TypeCheckType::Resolve (var.get_type ().get ());
- TyTy::BaseType *expr_type = TypeCheckExpr::Resolve (var.get_expr ().get ());
+ TyTy::BaseType *type = TypeCheckType::Resolve (var.get_type ());
+ TyTy::BaseType *expr_type = TypeCheckExpr::Resolve (var.get_expr ());
TyTy::BaseType *unified
= coercion_site (var.get_mappings ().get_hirid (),
- TyTy::TyWithLocation (type, var.get_type ()->get_locus ()),
+ TyTy::TyWithLocation (type, var.get_type ().get_locus ()),
TyTy::TyWithLocation (expr_type,
- var.get_expr ()->get_locus ()),
+ var.get_expr ().get_locus ()),
var.get_locus ());
context->insert_type (var.get_mappings (), unified);
infered = unified;
@@ -472,14 +472,13 @@ TypeCheckItem::visit (HIR::StaticItem &var)
void
TypeCheckItem::visit (HIR::ConstantItem &constant)
{
- TyTy::BaseType *type = TypeCheckType::Resolve (constant.get_type ().get ());
- TyTy::BaseType *expr_type
- = TypeCheckExpr::Resolve (constant.get_expr ().get ());
+ TyTy::BaseType *type = TypeCheckType::Resolve (constant.get_type ());
+ TyTy::BaseType *expr_type = TypeCheckExpr::Resolve (constant.get_expr ());
TyTy::BaseType *unified = unify_site (
constant.get_mappings ().get_hirid (),
- TyTy::TyWithLocation (type, constant.get_type ()->get_locus ()),
- TyTy::TyWithLocation (expr_type, constant.get_expr ()->get_locus ()),
+ TyTy::TyWithLocation (type, constant.get_type ().get_locus ()),
+ TyTy::TyWithLocation (expr_type, constant.get_expr ().get_locus ()),
constant.get_locus ());
context->insert_type (constant.get_mappings (), unified);
infered = unified;
@@ -493,8 +492,8 @@ TypeCheckItem::visit (HIR::ImplBlock &impl_block)
TraitReference *trait_reference = &TraitReference::error_node ();
if (impl_block.has_trait_ref ())
{
- std::unique_ptr<HIR::TypePath> &ref = impl_block.get_trait_ref ();
- trait_reference = TraitResolver::Resolve (*ref);
+ HIR::TypePath &ref = impl_block.get_trait_ref ();
+ trait_reference = TraitResolver::Resolve (ref);
if (trait_reference->is_error ())
return;
}
@@ -515,8 +514,7 @@ TypeCheckItem::visit (HIR::ImplBlock &impl_block)
// resolve each impl_item
for (auto &impl_item : impl_block.get_impl_items ())
{
- TypeCheckImplItem::Resolve (&impl_block, impl_item.get (), self,
- substitutions);
+ TypeCheckImplItem::Resolve (impl_block, *impl_item, self, substitutions);
}
// validate the impl items
@@ -540,7 +538,7 @@ TypeCheckItem::resolve_impl_item (HIR::ImplBlock &impl_block,
TyTy::BaseType *self = resolve_impl_block_self (impl_block);
- return TypeCheckImplItem::Resolve (&impl_block, &item, self, substitutions);
+ return TypeCheckImplItem::Resolve (impl_block, item, self, substitutions);
}
void
@@ -563,8 +561,7 @@ TypeCheckItem::visit (HIR::Function &function)
ret_type = TyTy::TupleType::get_unit_type ();
else
{
- auto resolved
- = TypeCheckType::Resolve (function.get_return_type ().get ());
+ auto resolved = TypeCheckType::Resolve (function.get_return_type ());
if (resolved->get_kind () == TyTy::TypeKind::ERROR)
{
rust_error_at (function.get_locus (),
@@ -574,18 +571,18 @@ TypeCheckItem::visit (HIR::Function &function)
ret_type = resolved->clone ();
ret_type->set_ref (
- function.get_return_type ()->get_mappings ().get_hirid ());
+ function.get_return_type ().get_mappings ().get_hirid ());
}
std::vector<std::pair<HIR::Pattern *, TyTy::BaseType *>> params;
for (auto ¶m : function.get_function_params ())
{
// get the name as well required for later on
- auto param_tyty = TypeCheckType::Resolve (param.get_type ().get ());
- params.emplace_back (param.get_param_name ().get (), param_tyty);
+ auto param_tyty = TypeCheckType::Resolve (param.get_type ());
+ params.emplace_back (¶m.get_param_name (), param_tyty);
context->insert_type (param.get_mappings (), param_tyty);
- TypeCheckPattern::Resolve (param.get_param_name ().get (), param_tyty);
+ TypeCheckPattern::Resolve (param.get_param_name (), param_tyty);
}
auto path = CanonicalPath::create_empty ();
@@ -628,16 +625,15 @@ TypeCheckItem::visit (HIR::Function &function)
expected_ret_tyty);
context->switch_to_fn_body ();
- auto block_expr_ty
- = TypeCheckExpr::Resolve (function.get_definition ().get ());
+ auto block_expr_ty = TypeCheckExpr::Resolve (function.get_definition ());
location_t fn_return_locus = function.has_function_return_type ()
- ? function.get_return_type ()->get_locus ()
+ ? function.get_return_type ().get_locus ()
: function.get_locus ();
- coercion_site (function.get_definition ()->get_mappings ().get_hirid (),
+ coercion_site (function.get_definition ().get_mappings ().get_hirid (),
TyTy::TyWithLocation (expected_ret_tyty, fn_return_locus),
TyTy::TyWithLocation (block_expr_ty),
- function.get_definition ()->get_locus ());
+ function.get_definition ().get_locus ());
context->pop_return_type ();
@@ -691,7 +687,7 @@ TypeCheckItem::visit (HIR::ExternBlock &extern_block)
{
for (auto &item : extern_block.get_extern_items ())
{
- TypeCheckTopLevelExternItem::Resolve (item.get (), extern_block);
+ TypeCheckTopLevelExternItem::Resolve (*item, extern_block);
}
}
@@ -713,17 +709,17 @@ TypeCheckItem::resolve_impl_block_substitutions (HIR::ImplBlock &impl_block,
TraitReference *trait_reference = &TraitReference::error_node ();
if (impl_block.has_trait_ref ())
{
- std::unique_ptr<HIR::TypePath> &ref = impl_block.get_trait_ref ();
- trait_reference = TraitResolver::Resolve (*ref);
+ auto &ref = impl_block.get_trait_ref ();
+ trait_reference = TraitResolver::Resolve (ref);
rust_assert (!trait_reference->is_error ());
// we don't error out here see: gcc/testsuite/rust/compile/traits2.rs
// for example
- specified_bound
- = get_predicate_from_bound (*ref, impl_block.get_type ().get ());
+ specified_bound = get_predicate_from_bound (ref, impl_block.get_type ());
}
- TyTy::BaseType *self = TypeCheckType::Resolve (impl_block.get_type ().get ());
+ TyTy::BaseType *self = TypeCheckType::Resolve (impl_block.get_type ());
+
if (self->is<TyTy::ErrorType> ())
{
// we cannot check for unconstrained type arguments when the Self type is
@@ -758,14 +754,14 @@ TypeCheckItem::validate_trait_impl_block (
auto specified_bound = TyTy::TypeBoundPredicate::error ();
if (impl_block.has_trait_ref ())
{
- std::unique_ptr<HIR::TypePath> &ref = impl_block.get_trait_ref ();
+ auto &ref = impl_block.get_trait_ref ();
+ trait_reference = TraitResolver::Resolve (ref);
if (trait_reference->is_error ())
return;
// we don't error out here see: gcc/testsuite/rust/compile/traits2.rs
// for example
- specified_bound
- = get_predicate_from_bound (*ref, impl_block.get_type ().get ());
+ specified_bound = get_predicate_from_bound (ref, impl_block.get_type ());
}
bool is_trait_impl_block = !trait_reference->is_error ();
@@ -775,8 +771,7 @@ TypeCheckItem::validate_trait_impl_block (
if (!specified_bound.is_error ())
{
auto trait_item_ref
- = TypeCheckImplItemWithTrait::Resolve (&impl_block,
- impl_item.get (), self,
+ = TypeCheckImplItemWithTrait::Resolve (impl_block, *impl_item, self,
specified_bound,
substitutions);
if (!trait_item_ref.is_error ())
@@ -849,7 +844,7 @@ TypeCheckItem::validate_trait_impl_block (
TyTy::BaseType *
TypeCheckItem::resolve_impl_block_self (HIR::ImplBlock &impl_block)
{
- return TypeCheckType::Resolve (impl_block.get_type ().get ());
+ return TypeCheckType::Resolve (impl_block.get_type ());
}
} // namespace Resolver
diff --git a/gcc/rust/typecheck/rust-hir-type-check-path.cc b/gcc/rust/typecheck/rust-hir-type-check-path.cc
index 7b934b38eb3..cc79e4d4995 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-path.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-path.cc
@@ -34,8 +34,7 @@ void
TypeCheckExpr::visit (HIR::QualifiedPathInExpression &expr)
{
HIR::QualifiedPathType qual_path_type = expr.get_path_type ();
- TyTy::BaseType *root
- = TypeCheckType::Resolve (qual_path_type.get_type ().get ());
+ TyTy::BaseType *root = TypeCheckType::Resolve (qual_path_type.get_type ());
if (root->get_kind () == TyTy::TypeKind::ERROR)
return;
@@ -48,8 +47,8 @@ TypeCheckExpr::visit (HIR::QualifiedPathInExpression &expr)
}
// Resolve the trait now
- std::unique_ptr<HIR::TypePath> &trait_path_ref = qual_path_type.get_trait ();
- TraitReference *trait_ref = TraitResolver::Resolve (*trait_path_ref.get ());
+ HIR::TypePath &trait_path_ref = qual_path_type.get_trait ();
+ TraitReference *trait_ref = TraitResolver::Resolve (trait_path_ref);
if (trait_ref->is_error ())
return;
@@ -64,8 +63,7 @@ TypeCheckExpr::visit (HIR::QualifiedPathInExpression &expr)
// get the predicate for the bound
auto specified_bound
- = get_predicate_from_bound (*trait_path_ref.get (),
- qual_path_type.get_type ().get ());
+ = get_predicate_from_bound (trait_path_ref, qual_path_type.get_type ());
if (specified_bound.is_error ())
return;
@@ -457,7 +455,7 @@ TypeCheckExpr::resolve_segments (NodeId root_resolved_node_id,
{
// we need to setup with apropriate bounds
HIR::TypePath &bound_path
- = *associated->get_impl_block ()->get_trait_ref ().get ();
+ = associated->get_impl_block ()->get_trait_ref ();
const auto &trait_ref = *TraitResolver::Resolve (bound_path);
rust_assert (!trait_ref.is_error ());
diff --git a/gcc/rust/typecheck/rust-hir-type-check-pattern.cc b/gcc/rust/typecheck/rust-hir-type-check-pattern.cc
index 88e4d32f6bc..a118d1537f8 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-pattern.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-pattern.cc
@@ -33,15 +33,15 @@ TypeCheckPattern::TypeCheckPattern (TyTy::BaseType *parent)
{}
TyTy::BaseType *
-TypeCheckPattern::Resolve (HIR::Pattern *pattern, TyTy::BaseType *parent)
+TypeCheckPattern::Resolve (HIR::Pattern &pattern, TyTy::BaseType *parent)
{
TypeCheckPattern resolver (parent);
- pattern->accept_vis (resolver);
+ pattern.accept_vis (resolver);
if (resolver.infered == nullptr)
- return new TyTy::ErrorType (pattern->get_mappings ().get_hirid ());
+ return new TyTy::ErrorType (pattern.get_mappings ().get_hirid ());
- resolver.context->insert_type (pattern->get_mappings (), resolver.infered);
+ resolver.context->insert_type (pattern.get_mappings (), resolver.infered);
return resolver.infered;
}
@@ -49,7 +49,7 @@ void
TypeCheckPattern::visit (HIR::PathInExpression &pattern)
{
// Pattern must be enum variants, sturcts, constants, or associated constansts
- TyTy::BaseType *pattern_ty = TypeCheckExpr::Resolve (&pattern);
+ TyTy::BaseType *pattern_ty = TypeCheckExpr::Resolve (pattern);
NodeId ref_node_id = UNKNOWN_NODEID;
bool maybe_item = false;
@@ -161,7 +161,7 @@ TypeCheckPattern::visit (HIR::PathInExpression &pattern)
void
TypeCheckPattern::visit (HIR::TupleStructPattern &pattern)
{
- TyTy::BaseType *pattern_ty = TypeCheckExpr::Resolve (&pattern.get_path ());
+ TyTy::BaseType *pattern_ty = TypeCheckExpr::Resolve (pattern.get_path ());
if (pattern_ty->get_kind () != TyTy::TypeKind::ADT)
{
rust_error_at (
@@ -210,8 +210,8 @@ TypeCheckPattern::visit (HIR::TupleStructPattern &pattern)
// error[E0023]: this pattern has 0 fields, but the corresponding tuple
// variant has 1 field
- std::unique_ptr<HIR::TupleStructItems> &items = pattern.get_items ();
- switch (items->get_item_type ())
+ auto &items = pattern.get_items ();
+ switch (items.get_item_type ())
{
case HIR::TupleStructItems::RANGED: {
// TODO
@@ -221,7 +221,7 @@ TypeCheckPattern::visit (HIR::TupleStructPattern &pattern)
case HIR::TupleStructItems::MULTIPLE: {
HIR::TupleStructItemsNoRange &items_no_range
- = static_cast<HIR::TupleStructItemsNoRange &> (*items.get ());
+ = static_cast<HIR::TupleStructItemsNoRange &> (items);
if (items_no_range.get_patterns ().size () != variant->num_fields ())
{
@@ -247,7 +247,7 @@ TypeCheckPattern::visit (HIR::TupleStructPattern &pattern)
// setup the type on this pattern type
context->insert_type (pattern->get_mappings (), fty);
- TypeCheckPattern::Resolve (pattern.get (), fty);
+ TypeCheckPattern::Resolve (*pattern, fty);
}
}
break;
@@ -266,7 +266,7 @@ emit_invalid_field_error (location_t loc, Rust::TyTy::VariantDef *variant,
void
TypeCheckPattern::visit (HIR::StructPattern &pattern)
{
- TyTy::BaseType *pattern_ty = TypeCheckExpr::Resolve (&pattern.get_path ());
+ TyTy::BaseType *pattern_ty = TypeCheckExpr::Resolve (pattern.get_path ());
if (pattern_ty->get_kind () != TyTy::TypeKind::ADT)
{
rust_error_at (pattern.get_locus (),
@@ -324,7 +324,7 @@ TypeCheckPattern::visit (HIR::StructPattern &pattern)
case HIR::StructPatternField::ItemType::IDENT_PAT: {
HIR::StructPatternFieldIdentPat &ident
- = static_cast<HIR::StructPatternFieldIdentPat &> (*field.get ());
+ = static_cast<HIR::StructPatternFieldIdentPat &> (*field);
TyTy::StructFieldType *field = nullptr;
if (!variant->lookup_field (ident.get_identifier ().as_string (),
@@ -337,13 +337,13 @@ TypeCheckPattern::visit (HIR::StructPattern &pattern)
named_fields.push_back (ident.get_identifier ().as_string ());
TyTy::BaseType *fty = field->get_field_type ();
- TypeCheckPattern::Resolve (ident.get_pattern ().get (), fty);
+ TypeCheckPattern::Resolve (ident.get_pattern (), fty);
}
break;
case HIR::StructPatternField::ItemType::IDENT: {
HIR::StructPatternFieldIdent &ident
- = static_cast<HIR::StructPatternFieldIdent &> (*field.get ());
+ = static_cast<HIR::StructPatternFieldIdent &> (*field);
TyTy::StructFieldType *field = nullptr;
if (!variant->lookup_field (ident.get_identifier ().as_string (),
@@ -440,12 +440,11 @@ void
TypeCheckPattern::visit (HIR::TuplePattern &pattern)
{
std::unique_ptr<HIR::TuplePatternItems> items;
- switch (pattern.get_items ()->get_item_type ())
+ switch (pattern.get_items ().get_item_type ())
{
case HIR::TuplePatternItems::ItemType::MULTIPLE: {
- HIR::TuplePatternItemsMultiple &ref
- = *static_cast<HIR::TuplePatternItemsMultiple *> (
- pattern.get_items ().get ());
+ auto &ref = static_cast<HIR::TuplePatternItemsMultiple &> (
+ pattern.get_items ());
auto resolved_parent = parent->destructure ();
if (resolved_parent->get_kind () != TyTy::TUPLE)
@@ -474,8 +473,7 @@ TypeCheckPattern::visit (HIR::TuplePattern &pattern)
auto &p = patterns[i];
TyTy::BaseType *par_type = par.get_field (i);
- TyTy::BaseType *elem
- = TypeCheckPattern::Resolve (p.get (), par_type);
+ TyTy::BaseType *elem = TypeCheckPattern::Resolve (*p, par_type);
pattern_elems.push_back (TyTy::TyVar (elem->get_ref ()));
}
infered = new TyTy::TupleType (pattern.get_mappings ().get_hirid (),
@@ -543,10 +541,10 @@ TypeCheckPattern::visit (HIR::ReferencePattern &pattern)
return;
}
- TyTy::ReferenceType *ref_ty_ty = static_cast<TyTy::ReferenceType *> (parent);
+ auto &ref_ty_ty = static_cast<TyTy::ReferenceType &> (*parent);
TyTy::BaseType *infered_base
- = TypeCheckPattern::Resolve (pattern.get_referenced_pattern ().get (),
- ref_ty_ty->get_base ());
+ = TypeCheckPattern::Resolve (pattern.get_referenced_pattern (),
+ ref_ty_ty.get_base ());
infered = new TyTy::ReferenceType (pattern.get_mappings ().get_hirid (),
TyTy::TyVar (infered_base->get_ref ()),
pattern.is_mut () ? Mutability::Mut
@@ -578,15 +576,14 @@ TypeCheckPattern::emit_pattern_size_error (const HIR::Pattern &pattern,
TyTy::BaseType *
TypeCheckPattern::typecheck_range_pattern_bound (
- std::unique_ptr<Rust::HIR::RangePatternBound> &bound,
- Analysis::NodeMapping mappings, location_t locus)
+ Rust::HIR::RangePatternBound &bound, Analysis::NodeMapping mappings,
+ location_t locus)
{
TyTy::BaseType *resolved_bound = nullptr;
- switch (bound->get_bound_type ())
+ switch (bound.get_bound_type ())
{
case HIR::RangePatternBound::RangePatternBoundType::LITERAL: {
- HIR::RangePatternBoundLiteral &ref
- = *static_cast<HIR::RangePatternBoundLiteral *> (bound.get ());
+ auto &ref = static_cast<HIR::RangePatternBoundLiteral &> (bound);
HIR::Literal lit = ref.get_literal ();
@@ -595,18 +592,16 @@ TypeCheckPattern::typecheck_range_pattern_bound (
break;
case HIR::RangePatternBound::RangePatternBoundType::PATH: {
- HIR::RangePatternBoundPath &ref
- = *static_cast<HIR::RangePatternBoundPath *> (bound.get ());
+ auto &ref = static_cast<HIR::RangePatternBoundPath &> (bound);
- resolved_bound = TypeCheckExpr::Resolve (&ref.get_path ());
+ resolved_bound = TypeCheckExpr::Resolve (ref.get_path ());
}
break;
case HIR::RangePatternBound::RangePatternBoundType::QUALPATH: {
- HIR::RangePatternBoundQualPath &ref
- = *static_cast<HIR::RangePatternBoundQualPath *> (bound.get ());
+ auto &ref = static_cast<HIR::RangePatternBoundQualPath &> (bound);
- resolved_bound = TypeCheckExpr::Resolve (&ref.get_qualified_path ());
+ resolved_bound = TypeCheckExpr::Resolve (ref.get_qualified_path ());
}
break;
}
@@ -623,7 +618,7 @@ TypeCheckPattern::visit (HIR::AltPattern &pattern)
std::vector<TyTy::BaseType *> types;
for (auto &alt_pattern : alts)
{
- types.push_back (TypeCheckPattern::Resolve (alt_pattern.get (), parent));
+ types.push_back (TypeCheckPattern::Resolve (*alt_pattern, parent));
}
TyTy::BaseType *alt_pattern_type
@@ -642,16 +637,16 @@ TypeCheckPattern::visit (HIR::AltPattern &pattern)
}
TyTy::BaseType *
-ClosureParamInfer::Resolve (HIR::Pattern *pattern)
+ClosureParamInfer::Resolve (HIR::Pattern &pattern)
{
ClosureParamInfer resolver;
- pattern->accept_vis (resolver);
+ pattern.accept_vis (resolver);
if (resolver.infered->get_kind () != TyTy::TypeKind::ERROR)
{
resolver.context->insert_implicit_type (resolver.infered);
resolver.mappings.insert_location (resolver.infered->get_ref (),
- pattern->get_locus ());
+ pattern.get_locus ());
}
return resolver.infered;
}
@@ -682,7 +677,7 @@ void
ClosureParamInfer::visit (HIR::ReferencePattern &pattern)
{
TyTy::BaseType *element
- = ClosureParamInfer::Resolve (pattern.get_referenced_pattern ().get ());
+ = ClosureParamInfer::Resolve (pattern.get_referenced_pattern ());
HirId id = pattern.get_mappings ().get_hirid ();
infered = new TyTy::ReferenceType (id, TyTy::TyVar (element->get_ref ()),
diff --git a/gcc/rust/typecheck/rust-hir-type-check-pattern.h b/gcc/rust/typecheck/rust-hir-type-check-pattern.h
index ba45b65b340..d477181360a 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-pattern.h
+++ b/gcc/rust/typecheck/rust-hir-type-check-pattern.h
@@ -28,7 +28,7 @@ namespace Resolver {
class TypeCheckPattern : public TypeCheckBase, public HIR::HIRPatternVisitor
{
public:
- static TyTy::BaseType *Resolve (HIR::Pattern *pattern,
+ static TyTy::BaseType *Resolve (HIR::Pattern &pattern,
TyTy::BaseType *parent);
void visit (HIR::PathInExpression &pattern) override;
@@ -47,9 +47,10 @@ public:
private:
TypeCheckPattern (TyTy::BaseType *parent);
- TyTy::BaseType *typecheck_range_pattern_bound (
- std::unique_ptr<Rust::HIR::RangePatternBound> &bound,
- Analysis::NodeMapping mappings, location_t locus);
+ TyTy::BaseType *
+ typecheck_range_pattern_bound (Rust::HIR::RangePatternBound &bound,
+ Analysis::NodeMapping mappings,
+ location_t locus);
void emit_pattern_size_error (const HIR::Pattern &pattern,
size_t expected_field_count,
@@ -62,7 +63,7 @@ private:
class ClosureParamInfer : private TypeCheckBase, private HIR::HIRPatternVisitor
{
public:
- static TyTy::BaseType *Resolve (HIR::Pattern *pattern);
+ static TyTy::BaseType *Resolve (HIR::Pattern &pattern);
void visit (HIR::PathInExpression &pattern) override;
void visit (HIR::StructPattern &pattern) override;
diff --git a/gcc/rust/typecheck/rust-hir-type-check-stmt.cc b/gcc/rust/typecheck/rust-hir-type-check-stmt.cc
index c395ed02f88..4e53856278f 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-stmt.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-stmt.cc
@@ -28,17 +28,17 @@ namespace Rust {
namespace Resolver {
TyTy::BaseType *
-TypeCheckStmt::Resolve (HIR::Stmt *stmt)
+TypeCheckStmt::Resolve (HIR::Stmt &stmt)
{
TypeCheckStmt resolver;
- stmt->accept_vis (resolver);
+ stmt.accept_vis (resolver);
return resolver.infered;
}
void
TypeCheckStmt::visit (HIR::ExprStmt &stmt)
{
- infered = TypeCheckExpr::Resolve (stmt.get_expr ().get ());
+ infered = TypeCheckExpr::Resolve (stmt.get_expr ());
}
void
@@ -52,21 +52,20 @@ TypeCheckStmt::visit (HIR::ExternBlock &extern_block)
{
for (auto &item : extern_block.get_extern_items ())
{
- TypeCheckTopLevelExternItem::Resolve (item.get (), extern_block);
+ TypeCheckTopLevelExternItem::Resolve (*item, extern_block);
}
}
void
TypeCheckStmt::visit (HIR::ConstantItem &constant)
{
- TyTy::BaseType *type = TypeCheckType::Resolve (constant.get_type ().get ());
- TyTy::BaseType *expr_type
- = TypeCheckExpr::Resolve (constant.get_expr ().get ());
+ TyTy::BaseType *type = TypeCheckType::Resolve (constant.get_type ());
+ TyTy::BaseType *expr_type = TypeCheckExpr::Resolve (constant.get_expr ());
infered = coercion_site (
constant.get_mappings ().get_hirid (),
- TyTy::TyWithLocation (type, constant.get_type ()->get_locus ()),
- TyTy::TyWithLocation (expr_type, constant.get_expr ()->get_locus ()),
+ TyTy::TyWithLocation (type, constant.get_type ().get_locus ()),
+ TyTy::TyWithLocation (expr_type, constant.get_expr ().get_locus ()),
constant.get_locus ());
context->insert_type (constant.get_mappings (), infered);
}
@@ -76,13 +75,13 @@ TypeCheckStmt::visit (HIR::LetStmt &stmt)
{
infered = TyTy::TupleType::get_unit_type ();
- HIR::Pattern &stmt_pattern = *stmt.get_pattern ();
+ auto &stmt_pattern = stmt.get_pattern ();
TyTy::BaseType *init_expr_ty = nullptr;
location_t init_expr_locus = UNKNOWN_LOCATION;
if (stmt.has_init_expr ())
{
- init_expr_locus = stmt.get_init_expr ()->get_locus ();
- init_expr_ty = TypeCheckExpr::Resolve (stmt.get_init_expr ().get ());
+ init_expr_locus = stmt.get_init_expr ().get_locus ();
+ init_expr_ty = TypeCheckExpr::Resolve (stmt.get_init_expr ());
if (init_expr_ty->get_kind () == TyTy::TypeKind::ERROR)
return;
@@ -94,8 +93,8 @@ TypeCheckStmt::visit (HIR::LetStmt &stmt)
location_t specified_ty_locus;
if (stmt.has_type ())
{
- specified_ty = TypeCheckType::Resolve (stmt.get_type ().get ());
- specified_ty_locus = stmt.get_type ()->get_locus ();
+ specified_ty = TypeCheckType::Resolve (stmt.get_type ());
+ specified_ty_locus = stmt.get_type ().get_locus ();
}
// let x:i32 = 123;
@@ -105,19 +104,19 @@ TypeCheckStmt::visit (HIR::LetStmt &stmt)
TyTy::TyWithLocation (specified_ty, specified_ty_locus),
TyTy::TyWithLocation (init_expr_ty, init_expr_locus),
stmt.get_locus ());
- TypeCheckPattern::Resolve (&stmt_pattern, specified_ty);
+ TypeCheckPattern::Resolve (stmt_pattern, specified_ty);
}
else
{
// let x:i32;
if (specified_ty != nullptr)
{
- TypeCheckPattern::Resolve (&stmt_pattern, specified_ty);
+ TypeCheckPattern::Resolve (stmt_pattern, specified_ty);
}
// let x = 123;
else if (init_expr_ty != nullptr)
{
- TypeCheckPattern::Resolve (&stmt_pattern, init_expr_ty);
+ TypeCheckPattern::Resolve (stmt_pattern, init_expr_ty);
}
// let x;
else
@@ -127,7 +126,7 @@ TypeCheckStmt::visit (HIR::LetStmt &stmt)
TyTy::InferType::InferTypeKind::GENERAL,
TyTy::InferType::TypeHint::Default (),
stmt.get_locus ());
- TypeCheckPattern::Resolve (&stmt_pattern, infer);
+ TypeCheckPattern::Resolve (stmt_pattern, infer);
}
}
}
@@ -135,12 +134,12 @@ TypeCheckStmt::visit (HIR::LetStmt &stmt)
void
TypeCheckStmt::visit (HIR::TypePath &path)
{
- infered = TypeCheckType::Resolve (&path);
+ infered = TypeCheckType::Resolve (path);
}
void
TypeCheckStmt::visit (HIR::QualifiedPathInType &path)
{
- infered = TypeCheckType::Resolve (&path);
+ infered = TypeCheckType::Resolve (path);
}
void
diff --git a/gcc/rust/typecheck/rust-hir-type-check-stmt.h b/gcc/rust/typecheck/rust-hir-type-check-stmt.h
index 6d913725777..d6798058d47 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-stmt.h
+++ b/gcc/rust/typecheck/rust-hir-type-check-stmt.h
@@ -28,7 +28,7 @@ namespace Resolver {
class TypeCheckStmt : private TypeCheckBase, private HIR::HIRStmtVisitor
{
public:
- static TyTy::BaseType *Resolve (HIR::Stmt *stmt);
+ static TyTy::BaseType *Resolve (HIR::Stmt &stmt);
void visit (HIR::ExprStmt &stmt) override;
void visit (HIR::EmptyStmt &stmt) override;
diff --git a/gcc/rust/typecheck/rust-hir-type-check-struct-field.h b/gcc/rust/typecheck/rust-hir-type-check-struct-field.h
index cfa17acf6e9..800f7ca4390 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-struct-field.h
+++ b/gcc/rust/typecheck/rust-hir-type-check-struct-field.h
@@ -33,7 +33,7 @@ namespace Resolver {
class TypeCheckStructExpr : public TypeCheckBase
{
public:
- static TyTy::BaseType *Resolve (HIR::StructExprStructFields *expr);
+ static TyTy::BaseType *Resolve (HIR::StructExprStructFields &expr);
// Helper for making any errors
static Error
@@ -49,7 +49,7 @@ protected:
bool visit (HIR::StructExprFieldIdentifier &field);
private:
- TypeCheckStructExpr (HIR::Expr *e);
+ TypeCheckStructExpr (HIR::Expr &e);
// result
TyTy::BaseType *resolved;
diff --git a/gcc/rust/typecheck/rust-hir-type-check-struct.cc b/gcc/rust/typecheck/rust-hir-type-check-struct.cc
index 5018829ec7d..e19925a96ee 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-struct.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-struct.cc
@@ -24,18 +24,18 @@
namespace Rust {
namespace Resolver {
-TypeCheckStructExpr::TypeCheckStructExpr (HIR::Expr *e)
+TypeCheckStructExpr::TypeCheckStructExpr (HIR::Expr &e)
: TypeCheckBase (),
- resolved (new TyTy::ErrorType (e->get_mappings ().get_hirid ())),
+ resolved (new TyTy::ErrorType (e.get_mappings ().get_hirid ())),
struct_path_resolved (nullptr),
variant (&TyTy::VariantDef::get_error_node ())
{}
TyTy::BaseType *
-TypeCheckStructExpr::Resolve (HIR::StructExprStructFields *expr)
+TypeCheckStructExpr::Resolve (HIR::StructExprStructFields &expr)
{
TypeCheckStructExpr resolver (expr);
- resolver.resolve (*expr);
+ resolver.resolve (expr);
return resolver.resolved;
}
@@ -43,7 +43,7 @@ void
TypeCheckStructExpr::resolve (HIR::StructExprStructFields &struct_expr)
{
TyTy::BaseType *struct_path_ty
- = TypeCheckExpr::Resolve (&struct_expr.get_struct_name ());
+ = TypeCheckExpr::Resolve (struct_expr.get_struct_name ());
if (struct_path_ty->get_kind () != TyTy::TypeKind::ADT)
{
rust_error_at (struct_expr.get_struct_name ().get_locus (),
@@ -56,7 +56,7 @@ TypeCheckStructExpr::resolve (HIR::StructExprStructFields &struct_expr)
if (struct_expr.has_struct_base ())
{
TyTy::BaseType *base_resolved
- = TypeCheckExpr::Resolve (struct_expr.struct_base->base_struct.get ());
+ = TypeCheckExpr::Resolve (*struct_expr.struct_base->base_struct);
TyTy::BaseType *base_unify = unify_site (
struct_expr.struct_base->base_struct->get_mappings ().get_hirid (),
TyTy::TyWithLocation (struct_path_resolved),
@@ -284,8 +284,8 @@ TypeCheckStructExpr::visit (HIR::StructExprFieldIdentifierValue &field)
return false;
}
- TyTy::BaseType *value = TypeCheckExpr::Resolve (field.get_value ().get ());
- location_t value_locus = field.get_value ()->get_locus ();
+ TyTy::BaseType *value = TypeCheckExpr::Resolve (field.get_value ());
+ location_t value_locus = field.get_value ().get_locus ();
HirId coercion_site_id = field.get_mappings ().get_hirid ();
resolved_field_value_expr
@@ -330,8 +330,8 @@ TypeCheckStructExpr::visit (HIR::StructExprFieldIndexValue &field)
return false;
}
- TyTy::BaseType *value = TypeCheckExpr::Resolve (field.get_value ().get ());
- location_t value_locus = field.get_value ()->get_locus ();
+ TyTy::BaseType *value = TypeCheckExpr::Resolve (field.get_value ());
+ location_t value_locus = field.get_value ().get_locus ();
HirId coercion_site_id = field.get_mappings ().get_hirid ();
resolved_field_value_expr
@@ -385,7 +385,7 @@ TypeCheckStructExpr::visit (HIR::StructExprFieldIdentifier &field)
HIR::GenericArgs::create_empty ());
HIR::PathInExpression expr (mappings_copy2, {seg}, field.get_locus (), false,
{});
- TyTy::BaseType *value = TypeCheckExpr::Resolve (&expr);
+ TyTy::BaseType *value = TypeCheckExpr::Resolve (expr);
location_t value_locus = expr.get_locus ();
HirId coercion_site_id = field.get_mappings ().get_hirid ();
diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.cc b/gcc/rust/typecheck/rust-hir-type-check-type.cc
index 0ff4ac45247..089a5af121a 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-type.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-type.cc
@@ -18,6 +18,7 @@
#include "rust-hir-type-check-type.h"
#include "options.h"
+#include "optional.h"
#include "rust-hir-trait-resolve.h"
#include "rust-hir-type-check-expr.h"
#include "rust-hir-path-probe.h"
@@ -26,18 +27,19 @@
#include "rust-mapping-common.h"
#include "rust-substitution-mapper.h"
#include "rust-type-util.h"
+#include <functional>
namespace Rust {
namespace Resolver {
HIR::GenericArgs
-TypeCheckResolveGenericArguments::resolve (HIR::TypePathSegment *segment)
+TypeCheckResolveGenericArguments::resolve (HIR::TypePathSegment &segment)
{
- TypeCheckResolveGenericArguments resolver (segment->get_locus ());
- switch (segment->get_type ())
+ TypeCheckResolveGenericArguments resolver (segment.get_locus ());
+ switch (segment.get_type ())
{
case HIR::TypePathSegment::SegmentType::GENERIC:
- resolver.visit (static_cast<HIR::TypePathSegmentGeneric &> (*segment));
+ resolver.visit (static_cast<HIR::TypePathSegmentGeneric &> (segment));
break;
default:
@@ -53,20 +55,20 @@ TypeCheckResolveGenericArguments::visit (HIR::TypePathSegmentGeneric &generic)
}
TyTy::BaseType *
-TypeCheckType::Resolve (HIR::Type *type)
+TypeCheckType::Resolve (HIR::Type &type)
{
// is it already resolved?
auto context = TypeCheckContext::get ();
TyTy::BaseType *resolved = nullptr;
bool already_resolved
- = context->lookup_type (type->get_mappings ().get_hirid (), &resolved);
+ = context->lookup_type (type.get_mappings ().get_hirid (), &resolved);
if (already_resolved)
return resolved;
- TypeCheckType resolver (type->get_mappings ().get_hirid ());
- type->accept_vis (resolver);
+ TypeCheckType resolver (type.get_mappings ().get_hirid ());
+ type.accept_vis (resolver);
rust_assert (resolver.translated != nullptr);
- resolver.context->insert_type (type->get_mappings (), resolver.translated);
+ resolver.context->insert_type (type.get_mappings (), resolver.translated);
return resolver.translated;
}
@@ -82,7 +84,7 @@ TypeCheckType::visit (HIR::BareFunctionType &fntype)
TyTy::BaseType *return_type;
if (fntype.has_return_type ())
{
- return_type = TypeCheckType::Resolve (fntype.get_return_type ().get ());
+ return_type = TypeCheckType::Resolve (fntype.get_return_type ());
}
else
{
@@ -95,7 +97,7 @@ TypeCheckType::visit (HIR::BareFunctionType &fntype)
std::vector<TyTy::TyVar> params;
for (auto ¶m : fntype.get_function_params ())
{
- TyTy::BaseType *ptype = TypeCheckType::Resolve (param.get_type ().get ());
+ TyTy::BaseType *ptype = TypeCheckType::Resolve (param.get_type ());
params.push_back (TyTy::TyVar (ptype->get_ref ()));
}
@@ -121,7 +123,7 @@ TypeCheckType::visit (HIR::TupleType &tuple)
std::vector<TyTy::TyVar> fields;
for (auto &elem : tuple.get_elems ())
{
- auto field_ty = TypeCheckType::Resolve (elem.get ());
+ auto field_ty = TypeCheckType::Resolve (*elem);
fields.push_back (TyTy::TyVar (field_ty->get_ref ()));
}
@@ -163,8 +165,7 @@ void
TypeCheckType::visit (HIR::QualifiedPathInType &path)
{
HIR::QualifiedPathType qual_path_type = path.get_path_type ();
- TyTy::BaseType *root
- = TypeCheckType::Resolve (qual_path_type.get_type ().get ());
+ TyTy::BaseType *root = TypeCheckType::Resolve (qual_path_type.get_type ());
if (root->get_kind () == TyTy::TypeKind::ERROR)
{
rust_debug_loc (path.get_locus (), "failed to resolve the root");
@@ -176,7 +177,7 @@ TypeCheckType::visit (HIR::QualifiedPathInType &path)
// then this is just a normal path-in-expression
NodeId root_resolved_node_id = UNKNOWN_NODEID;
bool ok = resolver->lookup_resolved_type (
- qual_path_type.get_type ()->get_mappings ().get_nodeid (),
+ qual_path_type.get_type ().get_mappings ().get_nodeid (),
&root_resolved_node_id);
rust_assert (ok);
@@ -189,8 +190,8 @@ TypeCheckType::visit (HIR::QualifiedPathInType &path)
}
// Resolve the trait now
- std::unique_ptr<HIR::TypePath> &trait_path_ref = qual_path_type.get_trait ();
- TraitReference *trait_ref = TraitResolver::Resolve (*trait_path_ref.get ());
+ auto &trait_path_ref = qual_path_type.get_trait ();
+ TraitReference *trait_ref = TraitResolver::Resolve (trait_path_ref);
if (trait_ref->is_error ())
return;
@@ -203,9 +204,8 @@ TypeCheckType::visit (HIR::QualifiedPathInType &path)
}
// get the predicate for the bound
- auto specified_bound
- = get_predicate_from_bound (*qual_path_type.get_trait ().get (),
- qual_path_type.get_type ().get ());
+ auto specified_bound = get_predicate_from_bound (qual_path_type.get_trait (),
+ qual_path_type.get_type ());
if (specified_bound.is_error ())
return;
@@ -213,18 +213,17 @@ TypeCheckType::visit (HIR::QualifiedPathInType &path)
root->inherit_bounds ({specified_bound});
// lookup the associated item from the specified bound
- std::unique_ptr<HIR::TypePathSegment> &item_seg
- = path.get_associated_segment ();
- HIR::PathIdentSegment item_seg_identifier = item_seg->get_ident_segment ();
+ HIR::TypePathSegment &item_seg = path.get_associated_segment ();
+ HIR::PathIdentSegment item_seg_identifier = item_seg.get_ident_segment ();
TyTy::TypeBoundPredicateItem item
= specified_bound.lookup_associated_item (item_seg_identifier.as_string ());
if (item.is_error ())
{
std::string item_seg_ident_name, rich_msg;
- item_seg_ident_name = qual_path_type.get_trait ()->as_string ();
+ item_seg_ident_name = qual_path_type.get_trait ().as_string ();
rich_msg = "not found in `" + item_seg_ident_name + "`";
- rich_location richloc (line_table, item_seg->get_locus ());
+ rich_location richloc (line_table, item_seg.get_locus ());
richloc.add_fixit_replace (rich_msg.c_str ());
rust_error_at (richloc, ErrorCode::E0576,
@@ -296,17 +295,16 @@ TypeCheckType::visit (HIR::QualifiedPathInType &path)
}
// turbo-fish segment path::<ty>
- if (item_seg->get_type () == HIR::TypePathSegment::SegmentType::GENERIC)
+ if (item_seg.get_type () == HIR::TypePathSegment::SegmentType::GENERIC)
{
- HIR::TypePathSegmentGeneric &generic_seg
- = static_cast<HIR::TypePathSegmentGeneric &> (*item_seg.get ());
+ auto &generic_seg = static_cast<HIR::TypePathSegmentGeneric &> (item_seg);
// turbo-fish segment path::<ty>
if (generic_seg.has_generic_args ())
{
if (!translated->has_substitutions_defined ())
{
- rust_error_at (item_seg->get_locus (),
+ rust_error_at (item_seg.get_locus (),
"substitutions not supported for %s",
translated->as_string ().c_str ());
translated
@@ -454,13 +452,13 @@ TypeCheckType::resolve_root_path (HIR::TypePath &path, size_t *offset,
// turbo-fish segment path::<ty>
if (seg->is_generic_segment ())
{
- HIR::TypePathSegmentGeneric *generic_segment
- = static_cast<HIR::TypePathSegmentGeneric *> (seg.get ());
+ auto &generic_segment
+ = static_cast<HIR::TypePathSegmentGeneric &> (*seg);
auto regions = context->regions_from_generic_args (
- generic_segment->get_generic_args ());
+ generic_segment.get_generic_args ());
lookup = SubstMapper::Resolve (lookup, path.get_locus (),
- &generic_segment->get_generic_args (),
+ &generic_segment.get_generic_args (),
regions);
if (lookup->get_kind () == TyTy::TypeKind::ERROR)
return new TyTy::ErrorType (seg->get_mappings ().get_hirid ());
@@ -569,12 +567,12 @@ TypeCheckType::resolve_segments (
if (seg->is_generic_segment ())
{
- auto *generic_segment
- = static_cast<HIR::TypePathSegmentGeneric *> (seg.get ());
+ auto &generic_segment
+ = static_cast<HIR::TypePathSegmentGeneric &> (*seg);
std::vector<TyTy::Region> regions;
for (auto &lifetime :
- generic_segment->get_generic_args ().get_lifetime_args ())
+ generic_segment.get_generic_args ().get_lifetime_args ())
{
auto region = context->lookup_and_resolve_lifetime (lifetime);
if (!region.has_value ())
@@ -587,7 +585,7 @@ TypeCheckType::resolve_segments (
}
tyseg = SubstMapper::Resolve (tyseg, expr_locus,
- &generic_segment->get_generic_args (),
+ &generic_segment.get_generic_args (),
regions);
if (tyseg->get_kind () == TyTy::TypeKind::ERROR)
return new TyTy::ErrorType (expr_id);
@@ -651,7 +649,7 @@ TypeCheckType::visit (HIR::TraitObjectType &type)
TyTy::TypeBoundPredicate predicate = get_predicate_from_bound (
trait_bound.get_path (),
- nullptr /*this will setup a PLACEHOLDER for self*/);
+ tl::nullopt /*this will setup a PLACEHOLDER for self*/);
if (!predicate.is_error ()
&& predicate.is_object_safe (true, type.get_locus ()))
@@ -667,33 +665,31 @@ TypeCheckType::visit (HIR::TraitObjectType &type)
void
TypeCheckType::visit (HIR::ArrayType &type)
{
- auto capacity_type = TypeCheckExpr::Resolve (type.get_size_expr ().get ());
+ auto capacity_type = TypeCheckExpr::Resolve (type.get_size_expr ());
if (capacity_type->get_kind () == TyTy::TypeKind::ERROR)
return;
TyTy::BaseType *expected_ty = nullptr;
bool ok = context->lookup_builtin ("usize", &expected_ty);
rust_assert (ok);
- context->insert_type (type.get_size_expr ()->get_mappings (), expected_ty);
+ context->insert_type (type.get_size_expr ().get_mappings (), expected_ty);
- unify_site (type.get_size_expr ()->get_mappings ().get_hirid (),
+ unify_site (type.get_size_expr ().get_mappings ().get_hirid (),
TyTy::TyWithLocation (expected_ty),
TyTy::TyWithLocation (capacity_type,
- type.get_size_expr ()->get_locus ()),
- type.get_size_expr ()->get_locus ());
+ type.get_size_expr ().get_locus ()),
+ type.get_size_expr ().get_locus ());
- TyTy::BaseType *base
- = TypeCheckType::Resolve (type.get_element_type ().get ());
+ TyTy::BaseType *base = TypeCheckType::Resolve (type.get_element_type ());
translated = new TyTy::ArrayType (type.get_mappings ().get_hirid (),
- type.get_locus (), *type.get_size_expr (),
+ type.get_locus (), type.get_size_expr (),
TyTy::TyVar (base->get_ref ()));
}
void
TypeCheckType::visit (HIR::SliceType &type)
{
- TyTy::BaseType *base
- = TypeCheckType::Resolve (type.get_element_type ().get ());
+ TyTy::BaseType *base = TypeCheckType::Resolve (type.get_element_type ());
translated
= new TyTy::SliceType (type.get_mappings ().get_hirid (), type.get_locus (),
TyTy::TyVar (base->get_ref ()));
@@ -701,7 +697,7 @@ TypeCheckType::visit (HIR::SliceType &type)
void
TypeCheckType::visit (HIR::ReferenceType &type)
{
- TyTy::BaseType *base = TypeCheckType::Resolve (type.get_base_type ().get ());
+ TyTy::BaseType *base = TypeCheckType::Resolve (type.get_base_type ());
rust_assert (type.has_lifetime ());
auto region = context->lookup_and_resolve_lifetime (type.get_lifetime ());
if (!region.has_value ())
@@ -718,7 +714,7 @@ TypeCheckType::visit (HIR::ReferenceType &type)
void
TypeCheckType::visit (HIR::RawPointerType &type)
{
- TyTy::BaseType *base = TypeCheckType::Resolve (type.get_base_type ().get ());
+ TyTy::BaseType *base = TypeCheckType::Resolve (type.get_base_type ());
translated
= new TyTy::PointerType (type.get_mappings ().get_hirid (),
TyTy::TyVar (base->get_ref ()), type.get_mut ());
@@ -744,21 +740,21 @@ TypeCheckType::visit (HIR::NeverType &type)
}
TyTy::ParamType *
-TypeResolveGenericParam::Resolve (HIR::GenericParam *param, bool apply_sized)
+TypeResolveGenericParam::Resolve (HIR::GenericParam ¶m, bool apply_sized)
{
TypeResolveGenericParam resolver (apply_sized);
- switch (param->get_kind ())
+ switch (param.get_kind ())
{
case HIR::GenericParam::GenericKind::TYPE:
- resolver.visit (static_cast<HIR::TypeParam &> (*param));
+ resolver.visit (static_cast<HIR::TypeParam &> (param));
break;
case HIR::GenericParam::GenericKind::CONST:
- resolver.visit (static_cast<HIR::ConstGenericParam &> (*param));
+ resolver.visit (static_cast<HIR::ConstGenericParam &> (param));
break;
case HIR::GenericParam::GenericKind::LIFETIME:
- resolver.visit (static_cast<HIR::LifetimeParam &> (*param));
+ resolver.visit (static_cast<HIR::LifetimeParam &> (param));
break;
}
return resolver.resolved;
@@ -780,9 +776,9 @@ void
TypeResolveGenericParam::visit (HIR::TypeParam ¶m)
{
if (param.has_type ())
- TypeCheckType::Resolve (param.get_type ().get ());
+ TypeCheckType::Resolve (param.get_type ());
- HIR::Type *implicit_self_bound = nullptr;
+ std::unique_ptr<HIR::Type> implicit_self_bound = nullptr;
if (param.has_type_param_bounds ())
{
// We need two possible parameter types. One with no Bounds and one with
@@ -800,8 +796,8 @@ TypeResolveGenericParam::visit (HIR::TypeParam ¶m)
param.get_mappings ().get_nodeid (),
implicit_id,
param.get_mappings ().get_local_defid ());
- implicit_self_bound
- = new HIR::TypePath (mappings, {}, BUILTINS_LOCATION, false);
+ implicit_self_bound = Rust::make_unique<HIR::TypePath> (
+ HIR::TypePath (mappings, {}, BUILTINS_LOCATION, false));
}
std::map<DefId, std::vector<TyTy::TypeBoundPredicate>> predicates;
@@ -830,13 +826,11 @@ TypeResolveGenericParam::visit (HIR::TypeParam ¶m)
switch (bound->get_bound_type ())
{
case HIR::TypeParamBound::BoundType::TRAITBOUND: {
- HIR::TraitBound *b
- = static_cast<HIR::TraitBound *> (bound.get ());
+ HIR::TraitBound &b = static_cast<HIR::TraitBound &> (*bound);
- TyTy::TypeBoundPredicate predicate
- = get_predicate_from_bound (b->get_path (),
- implicit_self_bound,
- b->get_polarity ());
+ TyTy::TypeBoundPredicate predicate = get_predicate_from_bound (
+ b.get_path (), tl::optional (std::ref (*implicit_self_bound)),
+ b.get_polarity ());
if (!predicate.is_error ())
{
switch (predicate.get_polarity ())
@@ -849,7 +843,7 @@ TypeResolveGenericParam::visit (HIR::TypeParam ¶m)
else
{
// emit error message
- rich_location r (line_table, b->get_locus ());
+ rich_location r (line_table, b.get_locus ());
r.add_range (predicate.get ()->get_locus ());
rust_error_at (
r, "antibound for %s is not applied here",
@@ -947,7 +941,7 @@ ResolveWhereClauseItem::visit (HIR::TypeBoundWhereClauseItem &item)
}
auto &binding_type_path = item.get_bound_type ();
- TyTy::BaseType *binding = TypeCheckType::Resolve (binding_type_path.get ());
+ TyTy::BaseType *binding = TypeCheckType::Resolve (binding_type_path);
// FIXME double check there might be a trait cycle here see TypeParam handling
@@ -960,8 +954,7 @@ ResolveWhereClauseItem::visit (HIR::TypeBoundWhereClauseItem &item)
auto *b = static_cast<HIR::TraitBound *> (bound.get ());
TyTy::TypeBoundPredicate predicate
- = get_predicate_from_bound (b->get_path (),
- binding_type_path.get ());
+ = get_predicate_from_bound (b->get_path (), binding_type_path);
if (!predicate.is_error ())
specified_bounds.push_back (std::move (predicate));
}
@@ -991,7 +984,7 @@ ResolveWhereClauseItem::visit (HIR::TypeBoundWhereClauseItem &item)
// When we apply these bounds we must lookup which type this binding
// resolves to, as this is the type which will be used during resolution
// of the block.
- NodeId ast_node_id = binding_type_path->get_mappings ().get_nodeid ();
+ NodeId ast_node_id = binding_type_path.get_mappings ().get_nodeid ();
// then lookup the reference_node_id
NodeId ref_node_id = UNKNOWN_NODEID;
@@ -1000,7 +993,7 @@ ResolveWhereClauseItem::visit (HIR::TypeBoundWhereClauseItem &item)
// FIXME
rust_error_at (UNDEF_LOCATION,
"Failed to lookup type reference for node: %s",
- binding_type_path->as_string ().c_str ());
+ binding_type_path.as_string ().c_str ());
return;
}
@@ -1013,7 +1006,7 @@ ResolveWhereClauseItem::visit (HIR::TypeBoundWhereClauseItem &item)
{
rust_error_at (mappings.lookup_location (*hid),
"Failed to resolve where-clause binding type: %s",
- binding_type_path->as_string ().c_str ());
+ binding_type_path.as_string ().c_str ());
return;
}
diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.h b/gcc/rust/typecheck/rust-hir-type-check-type.h
index a440250388a..ab29152ef45 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-type.h
+++ b/gcc/rust/typecheck/rust-hir-type-check-type.h
@@ -31,7 +31,7 @@ namespace Resolver {
class TypeCheckResolveGenericArguments : public TypeCheckBase
{
public:
- static HIR::GenericArgs resolve (HIR::TypePathSegment *segment);
+ static HIR::GenericArgs resolve (HIR::TypePathSegment &segment);
void visit (HIR::TypePathSegmentGeneric &generic);
@@ -46,7 +46,7 @@ private:
class TypeCheckType : public TypeCheckBase, public HIR::HIRTypeVisitor
{
public:
- static TyTy::BaseType *Resolve (HIR::Type *type);
+ static TyTy::BaseType *Resolve (HIR::Type &type);
void visit (HIR::BareFunctionType &fntype) override;
void visit (HIR::TupleType &tuple) override;
@@ -96,7 +96,7 @@ private:
class TypeResolveGenericParam : public TypeCheckBase
{
public:
- static TyTy::ParamType *Resolve (HIR::GenericParam *param,
+ static TyTy::ParamType *Resolve (HIR::GenericParam ¶m,
bool apply_sized = true);
protected:
diff --git a/gcc/rust/typecheck/rust-hir-type-check.cc b/gcc/rust/typecheck/rust-hir-type-check.cc
index 628660a208c..8e69f286d5c 100644
--- a/gcc/rust/typecheck/rust-hir-type-check.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check.cc
@@ -19,10 +19,12 @@
#include "rust-hir-type-check.h"
#include "rust-hir-full.h"
#include "rust-hir-inherent-impl-overlap.h"
+#include "rust-hir-pattern.h"
#include "rust-hir-type-check-expr.h"
#include "rust-hir-type-check-item.h"
#include "rust-hir-type-check-pattern.h"
#include "rust-hir-type-check-struct-field.h"
+#include "rust-make-unique.h"
#include "rust-immutable-name-resolution-context.h"
// for flag_name_resolution_2_0
@@ -140,11 +142,10 @@ TyTy::BaseType *
TraitItemReference::get_type_from_constant (
/*const*/ HIR::TraitItemConst &constant) const
{
- TyTy::BaseType *type = TypeCheckType::Resolve (constant.get_type ().get ());
+ TyTy::BaseType *type = TypeCheckType::Resolve (constant.get_type ());
if (constant.has_expr ())
{
- TyTy::BaseType *expr
- = TypeCheckExpr::Resolve (constant.get_expr ().get ());
+ TyTy::BaseType *expr = TypeCheckExpr::Resolve (constant.get_expr ());
return unify_site (constant.get_mappings ().get_hirid (),
TyTy::TyWithLocation (type),
@@ -185,7 +186,7 @@ TraitItemReference::get_type_from_fn (/*const*/ HIR::TraitItemFunc &fn) const
case HIR::GenericParam::GenericKind::TYPE: {
auto param_type
- = TypeResolveGenericParam::Resolve (generic_param.get ());
+ = TypeResolveGenericParam::Resolve (*generic_param);
context->insert_type (generic_param->get_mappings (),
param_type);
@@ -209,8 +210,7 @@ TraitItemReference::get_type_from_fn (/*const*/ HIR::TraitItemFunc &fn) const
ret_type = TyTy::TupleType::get_unit_type ();
else
{
- auto resolved
- = TypeCheckType::Resolve (function.get_return_type ().get ());
+ auto resolved = TypeCheckType::Resolve (function.get_return_type ());
if (resolved->get_kind () == TyTy::TypeKind::ERROR)
{
rust_error_at (fn.get_locus (), "failed to resolve return type");
@@ -219,10 +219,12 @@ TraitItemReference::get_type_from_fn (/*const*/ HIR::TraitItemFunc &fn) const
ret_type = resolved->clone ();
ret_type->set_ref (
- function.get_return_type ()->get_mappings ().get_hirid ());
+ function.get_return_type ().get_mappings ().get_hirid ());
}
std::vector<std::pair<HIR::Pattern *, TyTy::BaseType *> > params;
+
+ std::unique_ptr<HIR::IdentifierPattern> self_pattern = nullptr;
if (function.is_method ())
{
// these are implicit mappings and not used
@@ -236,16 +238,17 @@ TraitItemReference::get_type_from_fn (/*const*/ HIR::TraitItemFunc &fn) const
// for compilation to know parameter names. The types are ignored
// but we reuse the HIR identifier pattern which requires it
HIR::SelfParam &self_param = function.get_self ();
- HIR::IdentifierPattern *self_pattern = new HIR::IdentifierPattern (
- mapping, {"self"}, self_param.get_locus (), self_param.is_ref (),
- self_param.is_mut () ? Mutability::Mut : Mutability::Imm,
- std::unique_ptr<HIR::Pattern> (nullptr));
+ self_pattern
+ = Rust::make_unique<HIR::IdentifierPattern> (HIR::IdentifierPattern (
+ mapping, {"self"}, self_param.get_locus (), self_param.is_ref (),
+ self_param.is_mut () ? Mutability::Mut : Mutability::Imm,
+ std::unique_ptr<HIR::Pattern> (nullptr)));
// might have a specified type
TyTy::BaseType *self_type = nullptr;
if (self_param.has_type ())
{
- std::unique_ptr<HIR::Type> &specified_type = self_param.get_type ();
- self_type = TypeCheckType::Resolve (specified_type.get ());
+ HIR::Type &specified_type = self_param.get_type ();
+ self_type = TypeCheckType::Resolve (specified_type);
}
else
{
@@ -288,18 +291,20 @@ TraitItemReference::get_type_from_fn (/*const*/ HIR::TraitItemFunc &fn) const
context->insert_type (self_param.get_mappings (), self_type);
params.push_back (
- std::pair<HIR::Pattern *, TyTy::BaseType *> (self_pattern, self_type));
+ std::pair<HIR::Pattern *, TyTy::BaseType *> (self_pattern.get (),
+ self_type));
}
for (auto ¶m : function.get_function_params ())
{
// get the name as well required for later on
- auto param_tyty = TypeCheckType::Resolve (param.get_type ().get ());
- params.push_back (std::pair<HIR::Pattern *, TyTy::BaseType *> (
- param.get_param_name ().get (), param_tyty));
+ auto param_tyty = TypeCheckType::Resolve (param.get_type ());
+ params.push_back (
+ std::pair<HIR::Pattern *, TyTy::BaseType *> (¶m.get_param_name (),
+ param_tyty));
context->insert_type (param.get_mappings (), param_tyty);
- TypeCheckPattern::Resolve (param.get_param_name ().get (), param_tyty);
+ TypeCheckPattern::Resolve (param.get_param_name (), param_tyty);
}
auto &mappings = Analysis::Mappings::get ();
@@ -327,7 +332,7 @@ TraitItemReference::get_type_from_fn (/*const*/ HIR::TraitItemFunc &fn) const
function.get_function_name ().as_string (), ident,
function.is_method () ? TyTy::FnType::FNTYPE_IS_METHOD_FLAG
: TyTy::FnType::FNTYPE_DEFAULT_FLAGS,
- ABI::RUST, std::move (params), ret_type, substitutions,
+ ABI::RUST, params, ret_type, substitutions,
TyTy::SubstitutionArgumentMappings::empty (
context->get_lifetime_resolver ().get_num_bound_regions ()),
region_constraints);
diff --git a/gcc/rust/typecheck/rust-hir-type-check.h b/gcc/rust/typecheck/rust-hir-type-check.h
index 5b1fe220890..e0918e9d93c 100644
--- a/gcc/rust/typecheck/rust-hir-type-check.h
+++ b/gcc/rust/typecheck/rust-hir-type-check.h
@@ -42,7 +42,7 @@ public:
};
TypeCheckContextItem (HIR::Function *item);
- TypeCheckContextItem (HIR::ImplBlock *impl_block, HIR::Function *item);
+ TypeCheckContextItem (HIR::ImplBlock &impl_block, HIR::Function *item);
TypeCheckContextItem (HIR::TraitItemFunc *trait_item);
TypeCheckContextItem (const TypeCheckContextItem &other);
diff --git a/gcc/rust/typecheck/rust-type-util.cc b/gcc/rust/typecheck/rust-type-util.cc
index 0ed71247353..b7587526431 100644
--- a/gcc/rust/typecheck/rust-type-util.cc
+++ b/gcc/rust/typecheck/rust-type-util.cc
@@ -99,8 +99,9 @@ query_type (HirId reference, TyTy::BaseType **result)
auto block = mappings.lookup_hir_extern_block (extern_item->second);
rust_assert (block.has_value ());
- *result = TypeCheckTopLevelExternItem::Resolve (extern_item->first,
- *block.value ());
+ *result
+ = TypeCheckTopLevelExternItem::Resolve (*extern_item.value ().first,
+ *block.value ());
context->query_completed (reference);
return true;
}
diff --git a/gcc/rust/typecheck/rust-typecheck-context.cc b/gcc/rust/typecheck/rust-typecheck-context.cc
index 0fb8224861e..1cd5dabf822 100644
--- a/gcc/rust/typecheck/rust-typecheck-context.cc
+++ b/gcc/rust/typecheck/rust-typecheck-context.cc
@@ -646,9 +646,9 @@ TypeCheckContextItem::TypeCheckContextItem (HIR::Function *item)
: type (ItemType::ITEM), item (item)
{}
-TypeCheckContextItem::TypeCheckContextItem (HIR::ImplBlock *impl_block,
+TypeCheckContextItem::TypeCheckContextItem (HIR::ImplBlock &impl_block,
HIR::Function *item)
- : type (ItemType::IMPL_ITEM), item (impl_block, item)
+ : type (ItemType::IMPL_ITEM), item (&impl_block, item)
{}
TypeCheckContextItem::TypeCheckContextItem (HIR::TraitItemFunc *trait_item)
diff --git a/gcc/rust/typecheck/rust-tyty-bounds.cc b/gcc/rust/typecheck/rust-tyty-bounds.cc
index b73e5929129..32c55cd03f1 100644
--- a/gcc/rust/typecheck/rust-tyty-bounds.cc
+++ b/gcc/rust/typecheck/rust-tyty-bounds.cc
@@ -70,7 +70,7 @@ TypeBoundsProbe::scan ()
if (!impl->has_trait_ref ())
return true;
- HirId impl_ty_id = impl->get_type ()->get_mappings ().get_hirid ();
+ HirId impl_ty_id = impl->get_type ().get_mappings ().get_hirid ();
TyTy::BaseType *impl_type = nullptr;
if (!query_type (impl_ty_id, &impl_type))
return true;
@@ -81,7 +81,7 @@ TypeBoundsProbe::scan ()
return true;
}
- possible_trait_paths.push_back ({impl->get_trait_ref ().get (), impl});
+ possible_trait_paths.push_back ({&impl->get_trait_ref (), impl});
return true;
});
@@ -182,9 +182,10 @@ TypeCheckBase::resolve_trait_path (HIR::TypePath &path)
}
TyTy::TypeBoundPredicate
-TypeCheckBase::get_predicate_from_bound (HIR::TypePath &type_path,
- HIR::Type *associated_self,
- BoundPolarity polarity)
+TypeCheckBase::get_predicate_from_bound (
+ HIR::TypePath &type_path,
+ tl::optional<std::reference_wrapper<HIR::Type>> associated_self,
+ BoundPolarity polarity)
{
TyTy::TypeBoundPredicate lookup = TyTy::TypeBoundPredicate::error ();
bool already_resolved
@@ -215,9 +216,9 @@ TypeCheckBase::get_predicate_from_bound (HIR::TypePath &type_path,
break;
case HIR::TypePathSegment::SegmentType::FUNCTION: {
- auto final_function_seg
- = static_cast<HIR::TypePathSegmentFunction *> (final_seg.get ());
- auto &fn = final_function_seg->get_function_path ();
+ auto &final_function_seg
+ = static_cast<HIR::TypePathSegmentFunction &> (*final_seg);
+ auto &fn = final_function_seg.get_function_path ();
// we need to make implicit generic args which must be an implicit
// Tuple
@@ -243,7 +244,7 @@ TypeCheckBase::get_predicate_from_bound (HIR::TypePath &type_path,
// resolve the fn_once_output type which assumes there must be an output
// set
rust_assert (fn.has_return_type ());
- TypeCheckType::Resolve (fn.get_return_type ().get ());
+ TypeCheckType::Resolve (fn.get_return_type ());
HIR::TraitItem *trait_item
= mappings
@@ -252,10 +253,10 @@ TypeCheckBase::get_predicate_from_bound (HIR::TypePath &type_path,
.value ();
std::vector<HIR::GenericArgsBinding> bindings;
- location_t output_locus = fn.get_return_type ()->get_locus ();
+ location_t output_locus = fn.get_return_type ().get_locus ();
HIR::GenericArgsBinding binding (Identifier (
trait_item->trait_identifier ()),
- fn.get_return_type ()->clone_type (),
+ fn.get_return_type ().clone_type (),
output_locus);
bindings.push_back (std::move (binding));
@@ -271,11 +272,11 @@ TypeCheckBase::get_predicate_from_bound (HIR::TypePath &type_path,
break;
}
- if (associated_self != nullptr)
+ if (associated_self.has_value ())
{
std::vector<std::unique_ptr<HIR::Type>> type_args;
- type_args.push_back (
- std::unique_ptr<HIR::Type> (associated_self->clone_type ()));
+ type_args.push_back (std::unique_ptr<HIR::Type> (
+ associated_self.value ().get ().clone_type ()));
for (auto &arg : args.get_type_args ())
{
type_args.push_back (std::unique_ptr<HIR::Type> (arg->clone_type ()));
@@ -292,7 +293,7 @@ TypeCheckBase::get_predicate_from_bound (HIR::TypePath &type_path,
if (!args.is_empty () || predicate.requires_generic_args ())
{
// this is applying generic arguments to a trait reference
- predicate.apply_generic_arguments (&args, associated_self != nullptr);
+ predicate.apply_generic_arguments (&args, associated_self.has_value ());
}
context->insert_resolved_predicate (type_path.get_mappings ().get_hirid (),
diff --git a/gcc/rust/typecheck/rust-tyty-call.cc b/gcc/rust/typecheck/rust-tyty-call.cc
index ad3b2c3e75b..23a4a059691 100644
--- a/gcc/rust/typecheck/rust-tyty-call.cc
+++ b/gcc/rust/typecheck/rust-tyty-call.cc
@@ -80,7 +80,7 @@ TypeCheckCallExpr::visit (ADTType &type)
BaseType *field_tyty = field->get_field_type ();
location_t arg_locus = argument->get_locus ();
- BaseType *arg = Resolver::TypeCheckExpr::Resolve (argument.get ());
+ BaseType *arg = Resolver::TypeCheckExpr::Resolve (*argument);
if (arg->get_kind () == TyTy::TypeKind::ERROR)
{
rust_error_at (argument->get_locus (),
@@ -139,8 +139,7 @@ TypeCheckCallExpr::visit (FnType &type)
for (auto &argument : call.get_arguments ())
{
location_t arg_locus = argument->get_locus ();
- auto argument_expr_tyty
- = Resolver::TypeCheckExpr::Resolve (argument.get ());
+ auto argument_expr_tyty = Resolver::TypeCheckExpr::Resolve (*argument);
if (argument_expr_tyty->get_kind () == TyTy::TypeKind::ERROR)
{
rust_error_at (
@@ -152,8 +151,8 @@ TypeCheckCallExpr::visit (FnType &type)
// it might be a variadic function
if (i < type.num_params ())
{
- auto fnparam = type.param_at (i);
- HIR::Pattern *fn_param_pattern = fnparam.first;
+ auto &fnparam = type.param_at (i);
+ auto &fn_param_pattern = fnparam.first;
BaseType *param_ty = fnparam.second;
location_t param_locus
= fn_param_pattern == nullptr
@@ -272,8 +271,7 @@ TypeCheckCallExpr::visit (FnPtr &type)
{
location_t arg_locus = argument->get_locus ();
BaseType *fnparam = type.get_param_type_at (i);
- auto argument_expr_tyty
- = Resolver::TypeCheckExpr::Resolve (argument.get ());
+ auto argument_expr_tyty = Resolver::TypeCheckExpr::Resolve (*argument);
if (argument_expr_tyty->get_kind () == TyTy::TypeKind::ERROR)
{
rust_error_at (
@@ -322,8 +320,7 @@ TypeCheckMethodCallExpr::go (FnType *ref, HIR::MethodCallExpr &call,
std::vector<Argument> args;
for (auto &arg : call.get_arguments ())
{
- BaseType *argument_expr_tyty
- = Resolver::TypeCheckExpr::Resolve (arg.get ());
+ BaseType *argument_expr_tyty = Resolver::TypeCheckExpr::Resolve (*arg);
if (argument_expr_tyty->get_kind () == TyTy::TypeKind::ERROR)
{
rust_error_at (arg->get_locus (),
@@ -337,7 +334,7 @@ TypeCheckMethodCallExpr::go (FnType *ref, HIR::MethodCallExpr &call,
TypeCheckMethodCallExpr checker (call.get_mappings (), args,
call.get_locus (),
- call.get_receiver ()->get_locus (),
+ call.get_receiver ().get_locus (),
adjusted_self, context);
return checker.check (*ref);
}
@@ -377,7 +374,7 @@ TypeCheckMethodCallExpr::check (FnType &type)
{
location_t arg_locus = argument.get_locus ();
- auto fnparam = type.param_at (i);
+ auto &fnparam = type.param_at (i);
HIR::Pattern *fn_param_pattern = fnparam.first;
BaseType *param_ty = fnparam.second;
location_t param_locus
diff --git a/gcc/rust/typecheck/rust-tyty-subst.cc b/gcc/rust/typecheck/rust-tyty-subst.cc
index 575f04a3030..a12ad91192d 100644
--- a/gcc/rust/typecheck/rust-tyty-subst.cc
+++ b/gcc/rust/typecheck/rust-tyty-subst.cc
@@ -630,7 +630,7 @@ SubstitutionRef::get_mappings_from_generic_args (
for (auto &binding : args.get_binding_args ())
{
BaseType *resolved
- = Resolver::TypeCheckType::Resolve (binding.get_type ().get ());
+ = Resolver::TypeCheckType::Resolve (binding.get_type ());
if (resolved == nullptr
|| resolved->get_kind () == TyTy::TypeKind::ERROR)
{
@@ -696,7 +696,7 @@ SubstitutionRef::get_mappings_from_generic_args (
std::vector<SubstitutionArg> mappings = used_arguments.get_mappings ();
for (auto &arg : args.get_type_args ())
{
- BaseType *resolved = Resolver::TypeCheckType::Resolve (arg.get ());
+ BaseType *resolved = Resolver::TypeCheckType::Resolve (*arg);
if (resolved == nullptr || resolved->get_kind () == TyTy::TypeKind::ERROR)
{
return SubstitutionArgumentMappings::error ();
diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc
index 068e3902118..639a39bcbf9 100644
--- a/gcc/rust/typecheck/rust-tyty.cc
+++ b/gcc/rust/typecheck/rust-tyty.cc
@@ -31,6 +31,7 @@
#include "rust-hir-type-bounds.h"
#include "options.h"
+#include <functional>
namespace Rust {
namespace TyTy {
@@ -595,7 +596,8 @@ BaseType::monomorphized_clone () const
{
std::vector<std::pair<HIR::Pattern *, BaseType *>> cloned_params;
for (auto &p : fn->get_params ())
- cloned_params.push_back ({p.first, p.second->monomorphized_clone ()});
+ cloned_params.push_back (std::pair<HIR::Pattern *, BaseType *> (
+ p.first, p.second->monomorphized_clone ()));
BaseType *retty = fn->get_return_type ()->monomorphized_clone ();
return new FnType (fn->get_ref (), fn->get_ty_ref (), fn->get_id (),
@@ -1341,9 +1343,10 @@ VariantDef::variant_type_string (VariantType type)
}
VariantDef::VariantDef (HirId id, DefId defid, std::string identifier,
- RustIdent ident, HIR::Expr *discriminant)
+ RustIdent ident,
+ std::unique_ptr<HIR::Expr> &&discriminant)
: id (id), defid (defid), identifier (identifier), ident (ident),
- discriminant (discriminant)
+ discriminant (std::move (discriminant))
{
type = VariantType::NUM;
@@ -1352,34 +1355,15 @@ VariantDef::VariantDef (HirId id, DefId defid, std::string identifier,
VariantDef::VariantDef (HirId id, DefId defid, std::string identifier,
RustIdent ident, VariantType type,
- HIR::Expr *discriminant,
+ std::unique_ptr<HIR::Expr> &&discriminant,
std::vector<StructFieldType *> fields)
: id (id), defid (defid), identifier (identifier), ident (ident), type (type),
- discriminant (discriminant), fields (fields)
+ discriminant (std::move (discriminant)), fields (fields)
{
rust_assert ((type == VariantType::NUM && fields.empty ())
|| (type == VariantType::TUPLE || type == VariantType::STRUCT));
}
-VariantDef::VariantDef (const VariantDef &other)
- : id (other.id), defid (other.defid), identifier (other.identifier),
- ident (other.ident), type (other.type), discriminant (other.discriminant),
- fields (other.fields)
-{}
-
-VariantDef &
-VariantDef::operator= (const VariantDef &other)
-{
- id = other.id;
- identifier = other.identifier;
- type = other.type;
- discriminant = other.discriminant;
- fields = other.fields;
- ident = other.ident;
-
- return *this;
-}
-
VariantDef &
VariantDef::get_error_node ()
{
@@ -1475,11 +1459,11 @@ VariantDef::lookup_field (const std::string &lookup,
return false;
}
-HIR::Expr *
-VariantDef::get_discriminant () const
+HIR::Expr &
+VariantDef::get_discriminant ()
{
rust_assert (discriminant != nullptr);
- return discriminant;
+ return *discriminant;
}
std::string
@@ -1533,8 +1517,8 @@ VariantDef::clone () const
for (auto &f : fields)
cloned_fields.push_back ((StructFieldType *) f->clone ());
- return new VariantDef (id, defid, identifier, ident, type, discriminant,
- cloned_fields);
+ return new VariantDef (id, defid, identifier, ident, type,
+ discriminant->clone_expr (), cloned_fields);
}
VariantDef *
@@ -1544,8 +1528,8 @@ VariantDef::monomorphized_clone () const
for (auto &f : fields)
cloned_fields.push_back ((StructFieldType *) f->monomorphized_clone ());
- return new VariantDef (id, defid, identifier, ident, type, discriminant,
- cloned_fields);
+ return new VariantDef (id, defid, identifier, ident, type,
+ discriminant->clone_expr (), cloned_fields);
}
const RustIdent &
@@ -1895,7 +1879,7 @@ FnType::as_string () const
std::string params_str = "";
for (auto ¶m : params)
{
- auto pattern = param.first;
+ auto &pattern = param.first;
auto ty = param.second;
params_str += pattern->as_string () + " " + ty->as_string ();
params_str += ",";
@@ -1965,7 +1949,8 @@ FnType::clone () const
{
std::vector<std::pair<HIR::Pattern *, BaseType *>> cloned_params;
for (auto &p : params)
- cloned_params.push_back ({p.first, p.second->clone ()});
+ cloned_params.push_back (
+ std::pair<HIR::Pattern *, BaseType *> (p.first, p.second->clone ()));
return new FnType (get_ref (), get_ty_ref (), get_id (), get_identifier (),
ident, flags, abi, std::move (cloned_params),
diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h
index d73db3d265a..f394b8d9197 100644
--- a/gcc/rust/typecheck/rust-tyty.h
+++ b/gcc/rust/typecheck/rust-tyty.h
@@ -28,6 +28,9 @@
#include "rust-tyty-subst.h"
#include "rust-tyty-region.h"
#include "rust-system.h"
+#include "rust-hir.h"
+
+#include <limits>
namespace Rust {
@@ -567,16 +570,12 @@ public:
static std::string variant_type_string (VariantType type);
VariantDef (HirId id, DefId defid, std::string identifier, RustIdent ident,
- HIR::Expr *discriminant);
+ std::unique_ptr<HIR::Expr> &&discriminant);
VariantDef (HirId id, DefId defid, std::string identifier, RustIdent ident,
- VariantType type, HIR::Expr *discriminant,
+ VariantType type, std::unique_ptr<HIR::Expr> &&discriminant,
std::vector<StructFieldType *> fields);
- VariantDef (const VariantDef &other);
-
- VariantDef &operator= (const VariantDef &other);
-
static VariantDef &get_error_node ();
bool is_error () const;
@@ -597,7 +596,7 @@ public:
bool lookup_field (const std::string &lookup, StructFieldType **field_lookup,
size_t *index) const;
- HIR::Expr *get_discriminant () const;
+ HIR::Expr &get_discriminant ();
std::string as_string () const;
@@ -616,7 +615,7 @@ private:
RustIdent ident;
VariantType type;
// can either be a structure or a discriminant value
- HIR::Expr *discriminant;
+ std::unique_ptr<HIR::Expr> discriminant;
std::vector<StructFieldType *> fields;
};
@@ -787,8 +786,8 @@ public:
: CallableTypeInterface (ref, ref, TypeKind::FNDEF, ident, refs),
SubstitutionRef (std::move (subst_refs), substitution_argument_mappings,
region_constraints),
- params (std::move (params)), type (type), flags (flags),
- identifier (identifier), id (id), abi (abi)
+ params (params), type (type), flags (flags), identifier (identifier),
+ id (id), abi (abi)
{
LocalDefId local_def_id = id.localDefId;
rust_assert (local_def_id != UNKNOWN_LOCAL_DEFID);
@@ -804,8 +803,8 @@ public:
: CallableTypeInterface (ref, ty_ref, TypeKind::FNDEF, ident, refs),
SubstitutionRef (std::move (subst_refs), substitution_argument_mappings,
region_constraints),
- params (params), type (type), flags (flags), identifier (identifier),
- id (id), abi (abi)
+ params (std::move (params)), type (type), flags (flags),
+ identifier (identifier), id (id), abi (abi)
{
LocalDefId local_def_id = id.localDefId;
rust_assert (local_def_id != UNKNOWN_LOCAL_DEFID);
diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc
index 03b3343eaa1..d1504e108c1 100644
--- a/gcc/rust/util/rust-hir-map.cc
+++ b/gcc/rust/util/rust-hir-map.cc
@@ -459,7 +459,7 @@ Mappings::insert_hir_impl_block (HIR::ImplBlock *item)
auto id = item->get_mappings ().get_hirid ();
rust_assert (!lookup_hir_impl_block (id));
- HirId impl_type_id = item->get_type ()->get_mappings ().get_hirid ();
+ HirId impl_type_id = item->get_type ().get_mappings ().get_hirid ();
hirImplBlockMappings[id] = item;
hirImplBlockTypeMappings[impl_type_id] = item;
insert_node_to_hir (item->get_mappings ().get_nodeid (), id);
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 033/146] gccrs: Refactor HIR with optionals, references & newtypes
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (31 preceding siblings ...)
2025-03-21 12:05 ` [COMMITTED 032/146] gccrs: Refactor HIR to reduce the amount of raw pointers arthur.cohen
@ 2025-03-21 12:05 ` arthur.cohen
2025-03-21 12:05 ` [COMMITTED 034/146] gccrs: Refactor hir to avoid raw pointers and unneeded fwd arthur.cohen
` (112 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:05 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Pierre-Emmanuel Patry
From: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
The HIR made heavy use of pair and other unamed types which can be
difficult to read.
gcc/rust/ChangeLog:
* backend/rust-compile-base.cc: Use FnParam getter.
* backend/rust-compile-expr.cc (CompileExpr::visit): Likewise.
* backend/rust-compile-intrinsic.cc: Likewise.
* backend/rust-compile-type.cc: Likewise.
* checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::visit):
Only visit childrens if not missing.
* checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Use
a reference instead of a raw pointer.
* hir/tree/rust-hir-expr.h: Add presence function for return
expression.
* hir/tree/rust-hir-item.h: Remove take_param_name.
* hir/tree/rust-hir.h: Make mapping getter const.
* typecheck/rust-hir-dot-operator.cc (MethodResolver::Select): Use
getter.
* typecheck/rust-hir-type-check-expr.cc: Likewise.
* typecheck/rust-hir-type-check-implitem.cc: Use FnParam vector instead
of std::pair of Pattern and BaseType.
* typecheck/rust-hir-type-check-item.cc: Likewise.
* typecheck/rust-hir-type-check.cc: Likewise.
* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Use getters.
(TypeCheckMethodCallExpr::check): Likewise.
* typecheck/rust-tyty-cmp.h: Likewise.
* typecheck/rust-tyty.cc: Use FnParam.
* typecheck/rust-tyty.h (class FnParam): Add FnParam to handle function
parameters instead of handling std::pairs.
* typecheck/rust-unify.cc (UnifyRules::expect_fndef): Use getters.
(UnifyRules::expect_fnptr): Likewise.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
---
gcc/rust/backend/rust-compile-base.cc | 2 +-
gcc/rust/backend/rust-compile-expr.cc | 4 +-
gcc/rust/backend/rust-compile-intrinsic.cc | 17 ++---
gcc/rust/backend/rust-compile-type.cc | 4 +-
.../errors/privacy/rust-privacy-reporter.cc | 11 +--
gcc/rust/checks/errors/rust-unsafe-checker.cc | 2 +-
gcc/rust/hir/tree/rust-hir-expr.h | 2 +
gcc/rust/hir/tree/rust-hir-item.h | 2 -
gcc/rust/hir/tree/rust-hir.h | 5 +-
gcc/rust/typecheck/rust-hir-dot-operator.cc | 2 +-
.../typecheck/rust-hir-type-check-expr.cc | 4 +-
.../typecheck/rust-hir-type-check-implitem.cc | 28 +++-----
.../typecheck/rust-hir-type-check-item.cc | 6 +-
gcc/rust/typecheck/rust-hir-type-check.cc | 18 ++---
gcc/rust/typecheck/rust-tyty-call.cc | 16 ++---
gcc/rust/typecheck/rust-tyty-cmp.h | 6 +-
gcc/rust/typecheck/rust-tyty.cc | 30 ++++----
gcc/rust/typecheck/rust-tyty.h | 69 ++++++++++++-------
gcc/rust/typecheck/rust-unify.cc | 6 +-
19 files changed, 122 insertions(+), 112 deletions(-)
diff --git a/gcc/rust/backend/rust-compile-base.cc b/gcc/rust/backend/rust-compile-base.cc
index 598f2e2e451..80ea7a4ec95 100644
--- a/gcc/rust/backend/rust-compile-base.cc
+++ b/gcc/rust/backend/rust-compile-base.cc
@@ -711,7 +711,7 @@ HIRCompileBase::compile_function (
for (auto &referenced_param : function_params)
{
auto &tyty_param = fntype->param_at (i++);
- auto param_tyty = tyty_param.second;
+ auto param_tyty = tyty_param.get_type ();
auto compiled_param_type = TyTyResolveCompile::compile (ctx, param_tyty);
location_t param_locus = referenced_param.get_locus ();
diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc
index c46bda954ad..107ca2eadf5 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -1267,7 +1267,7 @@ CompileExpr::visit (HIR::CallExpr &expr)
const TyTy::FnType *fn = static_cast<const TyTy::FnType *> (base);
auto ¶m = fn->param_at (index);
- *result = param.second;
+ *result = param.get_type ();
return true;
};
@@ -1401,7 +1401,7 @@ CompileExpr::visit (HIR::MethodCallExpr &expr)
// assignments are coercion sites so lets convert the rvalue if
// necessary, offset from the already adjusted implicit self
bool ok;
- TyTy::BaseType *expected = fntype->param_at (i + 1).second;
+ TyTy::BaseType *expected = fntype->param_at (i + 1).get_type ();
TyTy::BaseType *actual = nullptr;
ok = ctx->get_tyctx ()->lookup_type (
diff --git a/gcc/rust/backend/rust-compile-intrinsic.cc b/gcc/rust/backend/rust-compile-intrinsic.cc
index bf595e4fb87..16447b29a51 100644
--- a/gcc/rust/backend/rust-compile-intrinsic.cc
+++ b/gcc/rust/backend/rust-compile-intrinsic.cc
@@ -315,13 +315,13 @@ compile_fn_params (Context *ctx, TyTy::FnType *fntype, tree fndecl,
{
for (auto &parm : fntype->get_params ())
{
- auto &referenced_param = parm.first;
- auto ¶m_tyty = parm.second;
+ auto &referenced_param = parm.get_pattern ();
+ auto param_tyty = parm.get_type ();
auto compiled_param_type = TyTyResolveCompile::compile (ctx, param_tyty);
- location_t param_locus = referenced_param->get_locus ();
+ location_t param_locus = referenced_param.get_locus ();
Bvariable *compiled_param_var
- = CompileFnParam::compile (ctx, fndecl, *referenced_param,
+ = CompileFnParam::compile (ctx, fndecl, referenced_param,
compiled_param_type, param_locus);
compiled_param_variables->push_back (compiled_param_var);
@@ -496,9 +496,10 @@ transmute_handler (Context *ctx, TyTy::FnType *fntype)
rust_error_at (fntype->get_locus (),
"cannot transmute between types of different sizes, or "
"dependently-sized types");
- rust_inform (fntype->get_ident ().locus, "source type: %qs (%lu bits)",
- fntype->get_params ().at (0).second->as_string ().c_str (),
- (unsigned long) source_size);
+ rust_inform (
+ fntype->get_ident ().locus, "source type: %qs (%lu bits)",
+ fntype->get_params ().at (0).get_type ()->as_string ().c_str (),
+ (unsigned long) source_size);
rust_inform (fntype->get_ident ().locus, "target type: %qs (%lu bits)",
fntype->get_return_type ()->as_string ().c_str (),
(unsigned long) target_size);
@@ -1226,7 +1227,7 @@ assume_handler (Context *ctx, TyTy::FnType *fntype)
// TODO: make sure this is actually helping the compiler optimize
rust_assert (fntype->get_params ().size () == 1);
- rust_assert (fntype->param_at (0).second->get_kind ()
+ rust_assert (fntype->param_at (0).get_type ()->get_kind ()
== TyTy::TypeKind::BOOL);
tree lookup = NULL_TREE;
diff --git a/gcc/rust/backend/rust-compile-type.cc b/gcc/rust/backend/rust-compile-type.cc
index c53b359b01f..56d64e1405b 100644
--- a/gcc/rust/backend/rust-compile-type.cc
+++ b/gcc/rust/backend/rust-compile-type.cc
@@ -208,12 +208,12 @@ TyTyResolveCompile::visit (const TyTy::FnType &type)
for (auto ¶m_pair : type.get_params ())
{
- auto param_tyty = param_pair.second;
+ auto param_tyty = param_pair.get_type ();
auto compiled_param_type
= TyTyResolveCompile::compile (ctx, param_tyty, trait_object_mode);
auto compiled_param = Backend::typed_identifier (
- param_pair.first->as_string (), compiled_param_type,
+ param_pair.get_pattern ().as_string (), compiled_param_type,
ctx->get_mappings ().lookup_location (param_tyty->get_ref ()));
parameters.push_back (compiled_param);
diff --git a/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc b/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc
index 3cbf47ecc8b..71030e5c7ef 100644
--- a/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc
+++ b/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc
@@ -497,8 +497,8 @@ PrivacyReporter::visit (HIR::BlockExpr &expr)
for (auto &stmt : expr.get_statements ())
stmt->accept_vis (*this);
- auto &last_expr = expr.get_final_expr ();
- last_expr.accept_vis (*this);
+ if (expr.has_final_expr ())
+ expr.get_final_expr ().accept_vis (*this);
}
void
@@ -508,8 +508,8 @@ PrivacyReporter::visit (HIR::ContinueExpr &)
void
PrivacyReporter::visit (HIR::BreakExpr &expr)
{
- auto &break_expr = expr.get_expr ();
- break_expr.accept_vis (*this);
+ if (expr.has_break_expr ())
+ expr.get_expr ().accept_vis (*this);
}
void
@@ -551,7 +551,8 @@ PrivacyReporter::visit (HIR::RangeToInclExpr &)
void
PrivacyReporter::visit (HIR::ReturnExpr &expr)
{
- expr.get_expr ().accept_vis (*this);
+ if (expr.has_expr ())
+ expr.get_expr ().accept_vis (*this);
}
void
diff --git a/gcc/rust/checks/errors/rust-unsafe-checker.cc b/gcc/rust/checks/errors/rust-unsafe-checker.cc
index 8f97edb6df5..6c9141c2dd2 100644
--- a/gcc/rust/checks/errors/rust-unsafe-checker.cc
+++ b/gcc/rust/checks/errors/rust-unsafe-checker.cc
@@ -482,7 +482,7 @@ UnsafeChecker::visit (MethodCallExpr &expr)
context.lookup_type (expr.get_method_name ().get_mappings ().get_hirid (),
&method_type);
- auto fn = *static_cast<TyTy::FnType *> (method_type);
+ auto &fn = static_cast<TyTy::FnType &> (*method_type);
auto method = mappings.lookup_hir_implitem (fn.get_ref ());
if (!unsafe_context.is_in_context () && method)
diff --git a/gcc/rust/hir/tree/rust-hir-expr.h b/gcc/rust/hir/tree/rust-hir-expr.h
index 692b9b4a9ac..c66b549a4d4 100644
--- a/gcc/rust/hir/tree/rust-hir-expr.h
+++ b/gcc/rust/hir/tree/rust-hir-expr.h
@@ -2238,6 +2238,7 @@ public:
bool is_final_stmt (Stmt *stmt) { return statements.back ().get () == stmt; }
+ bool has_final_expr () { return expr != nullptr; }
Expr &get_final_expr () { return *expr; }
std::vector<std::unique_ptr<Stmt> > &get_statements () { return statements; }
@@ -2785,6 +2786,7 @@ public:
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRExpressionVisitor &vis) override;
+ bool has_expr () { return return_expr != nullptr; }
Expr &get_expr () { return *return_expr; }
ExprType get_expression_type () const override final
diff --git a/gcc/rust/hir/tree/rust-hir-item.h b/gcc/rust/hir/tree/rust-hir-item.h
index 3e98ad412ed..7001466ade6 100644
--- a/gcc/rust/hir/tree/rust-hir-item.h
+++ b/gcc/rust/hir/tree/rust-hir-item.h
@@ -549,8 +549,6 @@ public:
Pattern &get_param_name () { return *param_name; }
- std::unique_ptr<Pattern> take_param_name () { return std::move (param_name); }
-
Type &get_type () { return *type; }
const Analysis::NodeMapping &get_mappings () const { return mappings; }
diff --git a/gcc/rust/hir/tree/rust-hir.h b/gcc/rust/hir/tree/rust-hir.h
index 7d133e135b0..d208122a0dd 100644
--- a/gcc/rust/hir/tree/rust-hir.h
+++ b/gcc/rust/hir/tree/rust-hir.h
@@ -465,7 +465,10 @@ public:
virtual void accept_vis (HIRTypeVisitor &vis) = 0;
- virtual Analysis::NodeMapping get_mappings () const { return mappings; }
+ virtual const Analysis::NodeMapping &get_mappings () const
+ {
+ return mappings;
+ }
virtual location_t get_locus () const { return locus; }
protected:
diff --git a/gcc/rust/typecheck/rust-hir-dot-operator.cc b/gcc/rust/typecheck/rust-hir-dot-operator.cc
index 6af23176467..38bd5b75fb7 100644
--- a/gcc/rust/typecheck/rust-hir-dot-operator.cc
+++ b/gcc/rust/typecheck/rust-hir-dot-operator.cc
@@ -62,7 +62,7 @@ MethodResolver::Select (std::set<MethodCandidate> &candidates,
for (size_t i = 0; i < arguments.size (); i++)
{
TyTy::BaseType *arg = arguments.at (i);
- TyTy::BaseType *param = fn.get_params ().at (i + 1).second;
+ TyTy::BaseType *param = fn.get_params ().at (i + 1).get_type ();
TyTy::BaseType *coerced
= try_coercion (0, TyTy::TyWithLocation (param),
TyTy::TyWithLocation (arg), UNDEF_LOCATION);
diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
index 32e3839930c..e93fa297fd3 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
@@ -1795,7 +1795,7 @@ TypeCheckExpr::resolve_operator_overload (LangItem::Kind lang_item_type,
// typecheck the self
unify_site (expr.get_mappings ().get_hirid (),
- TyTy::TyWithLocation (fnparam.second),
+ TyTy::TyWithLocation (fnparam.get_type ()),
TyTy::TyWithLocation (adjusted_self), expr.get_locus ());
if (rhs == nullptr)
{
@@ -1806,7 +1806,7 @@ TypeCheckExpr::resolve_operator_overload (LangItem::Kind lang_item_type,
rust_assert (type->num_params () == 2);
auto &fnparam = type->param_at (1);
unify_site (expr.get_mappings ().get_hirid (),
- TyTy::TyWithLocation (fnparam.second),
+ TyTy::TyWithLocation (fnparam.get_type ()),
TyTy::TyWithLocation (rhs), expr.get_locus ());
}
diff --git a/gcc/rust/typecheck/rust-hir-type-check-implitem.cc b/gcc/rust/typecheck/rust-hir-type-check-implitem.cc
index 2173938fb15..602076811c3 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-implitem.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-implitem.cc
@@ -130,8 +130,7 @@ TypeCheckTopLevelExternItem::visit (HIR::ExternalFunctionItem &function)
function.get_return_type ().get_mappings ().get_hirid ());
}
- std::vector<std::pair<HIR::Pattern *, TyTy::BaseType *> > params;
- std::unique_ptr<HIR::IdentifierPattern> param_pattern = nullptr;
+ std::vector<TyTy::FnParam> params;
for (auto ¶m : function.get_function_params ())
{
// get the name as well required for later on
@@ -143,14 +142,12 @@ TypeCheckTopLevelExternItem::visit (HIR::ExternalFunctionItem &function)
mappings.get_next_hir_id (crate_num),
UNKNOWN_LOCAL_DEFID);
- param_pattern = Rust::make_unique<HIR::IdentifierPattern> (
+ auto param_pattern = Rust::make_unique<HIR::IdentifierPattern> (
HIR::IdentifierPattern (mapping, param.get_param_name (),
UNDEF_LOCATION, false, Mutability::Imm,
std::unique_ptr<HIR::Pattern> (nullptr)));
- params.push_back (
- std::pair<HIR::Pattern *, TyTy::BaseType *> (param_pattern.get (),
- param_tyty));
+ params.push_back (TyTy::FnParam (std::move (param_pattern), param_tyty));
context->insert_type (param.get_mappings (), param_tyty);
@@ -375,8 +372,7 @@ TypeCheckImplItem::visit (HIR::Function &function)
function.get_return_type ().get_mappings ().get_hirid ());
}
- std::vector<std::pair<HIR::Pattern *, TyTy::BaseType *> > params;
- std::unique_ptr<HIR::IdentifierPattern> self_pattern = nullptr;
+ std::vector<TyTy::FnParam> params;
if (function.is_method ())
{
// these are implicit mappings and not used
@@ -390,10 +386,11 @@ TypeCheckImplItem::visit (HIR::Function &function)
// reuse the HIR identifier pattern which requires it
HIR::SelfParam &self_param = function.get_self_param ();
// FIXME: which location should be used for Rust::Identifier for `self`?
- self_pattern = Rust::make_unique<HIR::IdentifierPattern> (
- HIR::IdentifierPattern (mapping, {"self"}, self_param.get_locus (),
- self_param.is_ref (), self_param.get_mut (),
- std::unique_ptr<HIR::Pattern> (nullptr)));
+ std::unique_ptr<HIR::Pattern> self_pattern
+ = Rust::make_unique<HIR::IdentifierPattern> (
+ HIR::IdentifierPattern (mapping, {"self"}, self_param.get_locus (),
+ self_param.is_ref (), self_param.get_mut (),
+ std::unique_ptr<HIR::Pattern> (nullptr)));
// might have a specified type
TyTy::BaseType *self_type = nullptr;
@@ -450,9 +447,7 @@ TypeCheckImplItem::visit (HIR::Function &function)
}
context->insert_type (self_param.get_mappings (), self_type);
- params.push_back (
- std::pair<HIR::Pattern *, TyTy::BaseType *> (self_pattern.get (),
- self_type));
+ params.push_back (TyTy::FnParam (std::move (self_pattern), self_type));
}
for (auto ¶m : function.get_function_params ())
@@ -464,8 +459,7 @@ TypeCheckImplItem::visit (HIR::Function &function)
TypeCheckPattern::Resolve (param.get_param_name (), param_tyty);
params.push_back (
- std::pair<HIR::Pattern *, TyTy::BaseType *> (¶m.get_param_name (),
- param_tyty));
+ TyTy::FnParam (param.get_param_name ().clone_pattern (), param_tyty));
}
tl::optional<CanonicalPath> canonical_path;
diff --git a/gcc/rust/typecheck/rust-hir-type-check-item.cc b/gcc/rust/typecheck/rust-hir-type-check-item.cc
index e84ae333071..ab684425f27 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-item.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-item.cc
@@ -574,15 +574,15 @@ TypeCheckItem::visit (HIR::Function &function)
function.get_return_type ().get_mappings ().get_hirid ());
}
- std::vector<std::pair<HIR::Pattern *, TyTy::BaseType *>> params;
+ std::vector<TyTy::FnParam> params;
for (auto ¶m : function.get_function_params ())
{
// get the name as well required for later on
auto param_tyty = TypeCheckType::Resolve (param.get_type ());
- params.emplace_back (¶m.get_param_name (), param_tyty);
-
context->insert_type (param.get_mappings (), param_tyty);
TypeCheckPattern::Resolve (param.get_param_name (), param_tyty);
+ params.push_back (
+ TyTy::FnParam (param.get_param_name ().clone_pattern (), param_tyty));
}
auto path = CanonicalPath::create_empty ();
diff --git a/gcc/rust/typecheck/rust-hir-type-check.cc b/gcc/rust/typecheck/rust-hir-type-check.cc
index 8e69f286d5c..4bcb709de75 100644
--- a/gcc/rust/typecheck/rust-hir-type-check.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check.cc
@@ -222,9 +222,8 @@ TraitItemReference::get_type_from_fn (/*const*/ HIR::TraitItemFunc &fn) const
function.get_return_type ().get_mappings ().get_hirid ());
}
- std::vector<std::pair<HIR::Pattern *, TyTy::BaseType *> > params;
+ std::vector<TyTy::FnParam> params;
- std::unique_ptr<HIR::IdentifierPattern> self_pattern = nullptr;
if (function.is_method ())
{
// these are implicit mappings and not used
@@ -238,7 +237,7 @@ TraitItemReference::get_type_from_fn (/*const*/ HIR::TraitItemFunc &fn) const
// for compilation to know parameter names. The types are ignored
// but we reuse the HIR identifier pattern which requires it
HIR::SelfParam &self_param = function.get_self ();
- self_pattern
+ std::unique_ptr<HIR::Pattern> self_pattern
= Rust::make_unique<HIR::IdentifierPattern> (HIR::IdentifierPattern (
mapping, {"self"}, self_param.get_locus (), self_param.is_ref (),
self_param.is_mut () ? Mutability::Mut : Mutability::Imm,
@@ -290,21 +289,18 @@ TraitItemReference::get_type_from_fn (/*const*/ HIR::TraitItemFunc &fn) const
}
context->insert_type (self_param.get_mappings (), self_type);
- params.push_back (
- std::pair<HIR::Pattern *, TyTy::BaseType *> (self_pattern.get (),
- self_type));
+ params.push_back (TyTy::FnParam (std::move (self_pattern), self_type));
}
for (auto ¶m : function.get_function_params ())
{
// get the name as well required for later on
auto param_tyty = TypeCheckType::Resolve (param.get_type ());
- params.push_back (
- std::pair<HIR::Pattern *, TyTy::BaseType *> (¶m.get_param_name (),
- param_tyty));
-
context->insert_type (param.get_mappings (), param_tyty);
TypeCheckPattern::Resolve (param.get_param_name (), param_tyty);
+ // FIXME: Should we take the name ? Use a shared pointer instead ?
+ params.push_back (
+ TyTy::FnParam (param.get_param_name ().clone_pattern (), param_tyty));
}
auto &mappings = Analysis::Mappings::get ();
@@ -332,7 +328,7 @@ TraitItemReference::get_type_from_fn (/*const*/ HIR::TraitItemFunc &fn) const
function.get_function_name ().as_string (), ident,
function.is_method () ? TyTy::FnType::FNTYPE_IS_METHOD_FLAG
: TyTy::FnType::FNTYPE_DEFAULT_FLAGS,
- ABI::RUST, params, ret_type, substitutions,
+ ABI::RUST, std::move (params), ret_type, substitutions,
TyTy::SubstitutionArgumentMappings::empty (
context->get_lifetime_resolver ().get_num_bound_regions ()),
region_constraints);
diff --git a/gcc/rust/typecheck/rust-tyty-call.cc b/gcc/rust/typecheck/rust-tyty-call.cc
index 23a4a059691..725b8414671 100644
--- a/gcc/rust/typecheck/rust-tyty-call.cc
+++ b/gcc/rust/typecheck/rust-tyty-call.cc
@@ -152,12 +152,12 @@ TypeCheckCallExpr::visit (FnType &type)
if (i < type.num_params ())
{
auto &fnparam = type.param_at (i);
- auto &fn_param_pattern = fnparam.first;
- BaseType *param_ty = fnparam.second;
+ auto &fn_param_pattern = fnparam.get_pattern ();
+ BaseType *param_ty = fnparam.get_type ();
location_t param_locus
- = fn_param_pattern == nullptr
+ = fnparam.has_pattern ()
? mappings.lookup_location (param_ty->get_ref ())
- : fn_param_pattern->get_locus ();
+ : fn_param_pattern.get_locus ();
HirId coercion_side_id = argument->get_mappings ().get_hirid ();
auto resolved_argument_type
@@ -375,12 +375,12 @@ TypeCheckMethodCallExpr::check (FnType &type)
location_t arg_locus = argument.get_locus ();
auto &fnparam = type.param_at (i);
- HIR::Pattern *fn_param_pattern = fnparam.first;
- BaseType *param_ty = fnparam.second;
+ HIR::Pattern &fn_param_pattern = fnparam.get_pattern ();
+ BaseType *param_ty = fnparam.get_type ();
location_t param_locus
- = fn_param_pattern == nullptr
+ = fnparam.has_pattern ()
? mappings.lookup_location (param_ty->get_ref ())
- : fn_param_pattern->get_locus ();
+ : fn_param_pattern.get_locus ();
auto argument_expr_tyty = argument.get_argument_type ();
HirId coercion_side_id = argument.get_mappings ().get_hirid ();
diff --git a/gcc/rust/typecheck/rust-tyty-cmp.h b/gcc/rust/typecheck/rust-tyty-cmp.h
index c384287e550..7088b585eda 100644
--- a/gcc/rust/typecheck/rust-tyty-cmp.h
+++ b/gcc/rust/typecheck/rust-tyty-cmp.h
@@ -735,8 +735,8 @@ public:
for (size_t i = 0; i < base->num_params (); i++)
{
- auto a = base->param_at (i).second;
- auto b = type.param_at (i).second;
+ auto a = base->param_at (i).get_type ();
+ auto b = type.param_at (i).get_type ();
if (!a->can_eq (b, emit_error_flag))
{
@@ -831,7 +831,7 @@ public:
for (size_t i = 0; i < base->num_params (); i++)
{
auto this_param = base->get_param_type_at (i);
- auto other_param = type.param_at (i).second;
+ auto other_param = type.param_at (i).get_type ();
if (!this_param->can_eq (other_param, emit_error_flag))
{
BaseCmp::visit (type);
diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc
index 639a39bcbf9..757cfa59f62 100644
--- a/gcc/rust/typecheck/rust-tyty.cc
+++ b/gcc/rust/typecheck/rust-tyty.cc
@@ -594,10 +594,9 @@ BaseType::monomorphized_clone () const
}
else if (auto fn = x->try_as<const FnType> ())
{
- std::vector<std::pair<HIR::Pattern *, BaseType *>> cloned_params;
+ std::vector<TyTy::FnParam> cloned_params;
for (auto &p : fn->get_params ())
- cloned_params.push_back (std::pair<HIR::Pattern *, BaseType *> (
- p.first, p.second->monomorphized_clone ()));
+ cloned_params.push_back (p.clone ());
BaseType *retty = fn->get_return_type ()->monomorphized_clone ();
return new FnType (fn->get_ref (), fn->get_ty_ref (), fn->get_id (),
@@ -688,7 +687,7 @@ BaseType::is_concrete () const
{
for (const auto ¶m : fn->get_params ())
{
- if (!param.second->is_concrete ())
+ if (!param.get_type ()->is_concrete ())
return false;
}
return fn->get_return_type ()->is_concrete ();
@@ -1879,9 +1878,9 @@ FnType::as_string () const
std::string params_str = "";
for (auto ¶m : params)
{
- auto &pattern = param.first;
- auto ty = param.second;
- params_str += pattern->as_string () + " " + ty->as_string ();
+ auto &pattern = param.get_pattern ();
+ auto ty = param.get_type ();
+ params_str += pattern.as_string () + " " + ty->as_string ();
params_str += ",";
}
@@ -1902,7 +1901,7 @@ FnType::is_equal (const BaseType &other) const
if (get_kind () != other.get_kind ())
return false;
- auto other2 = static_cast<const FnType &> (other);
+ auto &other2 = static_cast<const FnType &> (other);
if (get_identifier ().compare (other2.get_identifier ()) != 0)
return false;
@@ -1936,8 +1935,8 @@ FnType::is_equal (const BaseType &other) const
for (size_t i = 0; i < num_params (); i++)
{
- auto lhs = param_at (i).second;
- auto rhs = other2.param_at (i).second;
+ auto lhs = param_at (i).get_type ();
+ auto rhs = other2.param_at (i).get_type ();
if (!lhs->is_equal (*rhs))
return false;
}
@@ -1947,10 +1946,9 @@ FnType::is_equal (const BaseType &other) const
BaseType *
FnType::clone () const
{
- std::vector<std::pair<HIR::Pattern *, BaseType *>> cloned_params;
+ std::vector<TyTy::FnParam> cloned_params;
for (auto &p : params)
- cloned_params.push_back (
- std::pair<HIR::Pattern *, BaseType *> (p.first, p.second->clone ()));
+ cloned_params.push_back (p.clone ());
return new FnType (get_ref (), get_ty_ref (), get_id (), get_identifier (),
ident, flags, abi, std::move (cloned_params),
@@ -2024,7 +2022,7 @@ FnType::handle_substitions (SubstitutionArgumentMappings &subst_mappings)
for (auto ¶m : fn->get_params ())
{
- auto fty = param.second;
+ auto fty = param.get_type ();
bool is_param_ty = fty->get_kind () == TypeKind::PARAM;
if (is_param_ty)
@@ -2043,7 +2041,7 @@ FnType::handle_substitions (SubstitutionArgumentMappings &subst_mappings)
{
auto new_field = argt->clone ();
new_field->set_ref (fty->get_ref ());
- param.second = new_field;
+ param.set_type (new_field);
}
else
{
@@ -2067,7 +2065,7 @@ FnType::handle_substitions (SubstitutionArgumentMappings &subst_mappings)
auto new_field = concrete->clone ();
new_field->set_ref (fty->get_ref ());
- param.second = new_field;
+ param.set_type (new_field);
}
}
diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h
index f394b8d9197..a74f4497f0c 100644
--- a/gcc/rust/typecheck/rust-tyty.h
+++ b/gcc/rust/typecheck/rust-tyty.h
@@ -766,6 +766,34 @@ private:
ReprOptions repr;
};
+class FnParam
+{
+public:
+ FnParam (std::unique_ptr<HIR::Pattern> pattern, BaseType *type)
+ : pattern (std::move (pattern)), type (type)
+ {}
+
+ FnParam (const FnParam &) = delete;
+ FnParam (FnParam &&) = default;
+ FnParam &operator= (FnParam &&) = default;
+
+ HIR::Pattern &get_pattern () { return *pattern; }
+ const HIR::Pattern &get_pattern () const { return *pattern; }
+
+ bool has_pattern () { return pattern != nullptr; }
+ BaseType *get_type () const { return type; }
+ void set_type (BaseType *new_type) { type = new_type; }
+
+ FnParam clone () const
+ {
+ return FnParam (pattern->clone_pattern (), type->monomorphized_clone ());
+ }
+
+private:
+ std::unique_ptr<HIR::Pattern> pattern;
+ BaseType *type;
+};
+
class FnType : public CallableTypeInterface, public SubstitutionRef
{
public:
@@ -777,25 +805,23 @@ public:
static const uint8_t FNTYPE_IS_VARADIC_FLAG = 0X04;
FnType (HirId ref, DefId id, std::string identifier, RustIdent ident,
- uint8_t flags, ABI abi,
- std::vector<std::pair<HIR::Pattern *, BaseType *>> params,
- BaseType *type, std::vector<SubstitutionParamMapping> subst_refs,
+ uint8_t flags, ABI abi, std::vector<FnParam> params, BaseType *type,
+ std::vector<SubstitutionParamMapping> subst_refs,
SubstitutionArgumentMappings substitution_argument_mappings,
RegionConstraints region_constraints,
std::set<HirId> refs = std::set<HirId> ())
: CallableTypeInterface (ref, ref, TypeKind::FNDEF, ident, refs),
SubstitutionRef (std::move (subst_refs), substitution_argument_mappings,
region_constraints),
- params (params), type (type), flags (flags), identifier (identifier),
- id (id), abi (abi)
+ params (std::move (params)), type (type), flags (flags),
+ identifier (identifier), id (id), abi (abi)
{
LocalDefId local_def_id = id.localDefId;
rust_assert (local_def_id != UNKNOWN_LOCAL_DEFID);
}
FnType (HirId ref, HirId ty_ref, DefId id, std::string identifier,
- RustIdent ident, uint8_t flags, ABI abi,
- std::vector<std::pair<HIR::Pattern *, BaseType *>> params,
+ RustIdent ident, uint8_t flags, ABI abi, std::vector<FnParam> params,
BaseType *type, std::vector<SubstitutionParamMapping> subst_refs,
SubstitutionArgumentMappings substitution_argument_mappings,
RegionConstraints region_constraints,
@@ -810,6 +836,9 @@ public:
rust_assert (local_def_id != UNKNOWN_LOCAL_DEFID);
}
+ FnType (const FnType &) = delete;
+ FnType (FnType &&) = default;
+
void accept_vis (TyVisitor &vis) override;
void accept_vis (TyConstVisitor &vis) const override;
@@ -843,28 +872,16 @@ public:
BaseType *get_self_type () const
{
rust_assert (is_method ());
- return param_at (0).second;
+ return param_at (0).get_type ();
}
- std::vector<std::pair<HIR::Pattern *, BaseType *>> &get_params ()
- {
- return params;
- }
+ std::vector<FnParam> &get_params () { return params; }
- const std::vector<std::pair<HIR::Pattern *, BaseType *>> &get_params () const
- {
- return params;
- }
+ const std::vector<FnParam> &get_params () const { return params; }
- std::pair<HIR::Pattern *, BaseType *> ¶m_at (size_t idx)
- {
- return params.at (idx);
- }
+ FnParam ¶m_at (size_t idx) { return params.at (idx); }
- const std::pair<HIR::Pattern *, BaseType *> ¶m_at (size_t idx) const
- {
- return params.at (idx);
- }
+ const FnParam ¶m_at (size_t idx) const { return params.at (idx); }
BaseType *clone () const final override;
@@ -881,7 +898,7 @@ public:
WARN_UNUSED_RESULT BaseType *get_param_type_at (size_t index) const override
{
- return param_at (index).second;
+ return param_at (index).get_type ();
}
WARN_UNUSED_RESULT BaseType *get_return_type () const override
@@ -890,7 +907,7 @@ public:
}
private:
- std::vector<std::pair<HIR::Pattern *, BaseType *>> params;
+ std::vector<FnParam> params;
BaseType *type;
uint8_t flags;
std::string identifier;
diff --git a/gcc/rust/typecheck/rust-unify.cc b/gcc/rust/typecheck/rust-unify.cc
index fa2308f1b34..8159c7d52bb 100644
--- a/gcc/rust/typecheck/rust-unify.cc
+++ b/gcc/rust/typecheck/rust-unify.cc
@@ -929,8 +929,8 @@ UnifyRules::expect_fndef (TyTy::FnType *ltype, TyTy::BaseType *rtype)
for (size_t i = 0; i < ltype->num_params (); i++)
{
- auto a = ltype->param_at (i).second;
- auto b = type.param_at (i).second;
+ auto a = ltype->param_at (i).get_type ();
+ auto b = type.param_at (i).get_type ();
auto unified_param
= UnifyRules::Resolve (TyTy::TyWithLocation (a),
@@ -1069,7 +1069,7 @@ UnifyRules::expect_fnptr (TyTy::FnPtr *ltype, TyTy::BaseType *rtype)
for (size_t i = 0; i < ltype->num_params (); i++)
{
auto this_param = ltype->get_param_type_at (i);
- auto other_param = type.param_at (i).second;
+ auto other_param = type.param_at (i).get_type ();
auto unified_param
= UnifyRules::Resolve (TyTy::TyWithLocation (this_param),
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 034/146] gccrs: Refactor hir to avoid raw pointers and unneeded fwd
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (32 preceding siblings ...)
2025-03-21 12:05 ` [COMMITTED 033/146] gccrs: Refactor HIR with optionals, references & newtypes arthur.cohen
@ 2025-03-21 12:05 ` arthur.cohen
2025-03-21 12:05 ` [COMMITTED 035/146] gccrs: Fixes some tests appearing with a moved variant arthur.cohen
` (111 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:05 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Pierre-Emmanuel Patry
From: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Refactor the hir tree files to remove raw pointer usage and most forward
declarations. Move implementation out of headers and split headers into
smaller and more manageable units.
gcc/rust/ChangeLog:
* Make-lang.in: Add new files.
* hir/tree/rust-hir-item.h: Move Item definition and remove
implementations to their corresponding cc file.
* hir/tree/rust-hir-expr.h: Move implementation to the corresponding
cc file.
* hir/tree/rust-hir-path.h: Likewise.
* hir/tree/rust-hir-pattern.h: Likewise.
* hir/tree/rust-hir-stmt.h: Likewise.
* hir/tree/rust-hir-type.h: Likewise.
* hir/tree/rust-hir-visitor.h: Likewise.
* hir/tree/rust-hir.h: Likewise.
* hir/tree/rust-hir.cc (Crate::Crate): Add implementations from Crate
and remove ConstGenericParam implementations to move them to their
own file.
* hir/tree/rust-hir-attrs.h: New file.
* hir/tree/rust-hir-bound-abstract.h: New file.
* hir/tree/rust-hir-bound.h: New file.
* hir/tree/rust-hir-expr-abstract.h: New file.
* hir/tree/rust-hir-expr.cc: New file.
* hir/tree/rust-hir-generic-param.cc: New file.
* hir/tree/rust-hir-generic-param.h: New file.
* hir/tree/rust-hir-item.cc: New file.
* hir/tree/rust-hir-literal.h: New file.
* hir/tree/rust-hir-node.h: New file.
* hir/tree/rust-hir-path.cc: New file.
* hir/tree/rust-hir-pattern-abstract.h: New file.
* hir/tree/rust-hir-simple-path.h: New file.
* hir/tree/rust-hir-stmt.cc: New file.
* hir/tree/rust-hir-trait-bound.h: New file.
* hir/tree/rust-hir-type-abstract.cc: New file.
* hir/tree/rust-hir-type-abstract.h: New file.
* hir/tree/rust-hir-type-no-bounds.h: New file.
* hir/tree/rust-hir-type.cc: New file.
* hir/tree/rust-hir-visibility.h: New file.
* hir/tree/rust-hir-visitable.h: New file.
* checks/lints/rust-lint-marklive.h: Use References.
* hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Reformat
vectors.
* hir/rust-hir-dump.cc (Dump::visit): Use reference.
* typecheck/rust-hir-type-check-struct.cc (TypeCheckStructExpr::resolve):
Use references.
* typecheck/rust-tyty-bounds.cc: Likewise.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
---
gcc/rust/Make-lang.in | 7 +
gcc/rust/checks/lints/rust-lint-marklive.h | 4 +-
gcc/rust/hir/rust-ast-lower-expr.cc | 19 +-
gcc/rust/hir/rust-hir-dump.cc | 4 +-
gcc/rust/hir/tree/rust-hir-attrs.h | 56 +
gcc/rust/hir/tree/rust-hir-bound-abstract.h | 65 +
gcc/rust/hir/tree/rust-hir-bound.h | 94 ++
gcc/rust/hir/tree/rust-hir-expr-abstract.h | 174 ++
gcc/rust/hir/tree/rust-hir-expr.cc | 1478 +++++++++++++++++
gcc/rust/hir/tree/rust-hir-expr.h | 1353 +++------------
gcc/rust/hir/tree/rust-hir-generic-param.cc | 95 ++
gcc/rust/hir/tree/rust-hir-generic-param.h | 186 +++
gcc/rust/hir/tree/rust-hir-item.cc | 1017 ++++++++++++
gcc/rust/hir/tree/rust-hir-item.h | 977 ++---------
gcc/rust/hir/tree/rust-hir-literal.h | 78 +
gcc/rust/hir/tree/rust-hir-node.h | 63 +
gcc/rust/hir/tree/rust-hir-path.cc | 383 +++++
gcc/rust/hir/tree/rust-hir-path.h | 346 +---
gcc/rust/hir/tree/rust-hir-pattern-abstract.h | 82 +
gcc/rust/hir/tree/rust-hir-pattern.h | 5 +-
gcc/rust/hir/tree/rust-hir-simple-path.h | 64 +
gcc/rust/hir/tree/rust-hir-stmt.cc | 98 ++
gcc/rust/hir/tree/rust-hir-stmt.h | 105 +-
gcc/rust/hir/tree/rust-hir-trait-bound.h | 87 +
gcc/rust/hir/tree/rust-hir-type-abstract.cc | 32 +
gcc/rust/hir/tree/rust-hir-type-abstract.h | 80 +
gcc/rust/hir/tree/rust-hir-type-no-bounds.h | 58 +
gcc/rust/hir/tree/rust-hir-type.cc | 289 ++++
gcc/rust/hir/tree/rust-hir-type.h | 306 +---
gcc/rust/hir/tree/rust-hir-visibility.h | 80 +
gcc/rust/hir/tree/rust-hir-visitable.h | 41 +
gcc/rust/hir/tree/rust-hir-visitor.h | 1 -
gcc/rust/hir/tree/rust-hir.cc | 56 +-
gcc/rust/hir/tree/rust-hir.h | 816 +--------
.../typecheck/rust-hir-type-check-struct.cc | 30 +-
gcc/rust/typecheck/rust-tyty-bounds.cc | 27 +-
36 files changed, 5214 insertions(+), 3442 deletions(-)
create mode 100644 gcc/rust/hir/tree/rust-hir-attrs.h
create mode 100644 gcc/rust/hir/tree/rust-hir-bound-abstract.h
create mode 100644 gcc/rust/hir/tree/rust-hir-bound.h
create mode 100644 gcc/rust/hir/tree/rust-hir-expr-abstract.h
create mode 100644 gcc/rust/hir/tree/rust-hir-expr.cc
create mode 100644 gcc/rust/hir/tree/rust-hir-generic-param.cc
create mode 100644 gcc/rust/hir/tree/rust-hir-generic-param.h
create mode 100644 gcc/rust/hir/tree/rust-hir-item.cc
create mode 100644 gcc/rust/hir/tree/rust-hir-literal.h
create mode 100644 gcc/rust/hir/tree/rust-hir-node.h
create mode 100644 gcc/rust/hir/tree/rust-hir-path.cc
create mode 100644 gcc/rust/hir/tree/rust-hir-pattern-abstract.h
create mode 100644 gcc/rust/hir/tree/rust-hir-simple-path.h
create mode 100644 gcc/rust/hir/tree/rust-hir-stmt.cc
create mode 100644 gcc/rust/hir/tree/rust-hir-trait-bound.h
create mode 100644 gcc/rust/hir/tree/rust-hir-type-abstract.cc
create mode 100644 gcc/rust/hir/tree/rust-hir-type-abstract.h
create mode 100644 gcc/rust/hir/tree/rust-hir-type-no-bounds.h
create mode 100644 gcc/rust/hir/tree/rust-hir-type.cc
create mode 100644 gcc/rust/hir/tree/rust-hir-visibility.h
create mode 100644 gcc/rust/hir/tree/rust-hir-visitable.h
diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in
index b1777e39963..9c5ec49ec4e 100644
--- a/gcc/rust/Make-lang.in
+++ b/gcc/rust/Make-lang.in
@@ -178,6 +178,13 @@ GRS_OBJS = \
rust/rust-polonius.o\
rust/rust-hir-dot-operator.o \
rust/rust-hir-path-probe.o \
+ rust/rust-hir-path.o \
+ rust/rust-hir-type.o \
+ rust/rust-hir-expr.o \
+ rust/rust-hir-type-abstract.o \
+ rust/rust-hir-item.o \
+ rust/rust-hir-stmt.o \
+ rust/rust-hir-generic-param.o \
rust/rust-type-util.o \
rust/rust-coercion.o \
rust/rust-casts.o \
diff --git a/gcc/rust/checks/lints/rust-lint-marklive.h b/gcc/rust/checks/lints/rust-lint-marklive.h
index 93a5be7ed1e..86d96fc9367 100644
--- a/gcc/rust/checks/lints/rust-lint-marklive.h
+++ b/gcc/rust/checks/lints/rust-lint-marklive.h
@@ -247,7 +247,7 @@ public:
stct.get_struct_name ().accept_vis (*this);
if (stct.has_struct_base ())
{
- stct.struct_base->base_struct->accept_vis (*this);
+ stct.get_struct_base ().get_base ().accept_vis (*this);
}
}
@@ -258,7 +258,7 @@ public:
void visit (HIR::StructExprStructBase &stct) override
{
- stct.get_struct_base ()->base_struct->accept_vis (*this);
+ stct.get_struct_base ().get_base ().accept_vis (*this);
}
void visit (HIR::Module &module) override
diff --git a/gcc/rust/hir/rust-ast-lower-expr.cc b/gcc/rust/hir/rust-ast-lower-expr.cc
index 9dd88b47b98..2954a31d9f4 100644
--- a/gcc/rust/hir/rust-ast-lower-expr.cc
+++ b/gcc/rust/hir/rust-ast-lower-expr.cc
@@ -17,6 +17,7 @@
// <http://www.gnu.org/licenses/>.
#include "rust-ast-lower-expr.h"
+#include "optional.h"
#include "rust-ast-lower-base.h"
#include "rust-ast-lower-block.h"
#include "rust-ast-lower-struct-field-expr.h"
@@ -77,7 +78,7 @@ ASTLoweringExpr::visit (AST::TupleIndexExpr &expr)
void
ASTLoweringExpr::visit (AST::TupleExpr &expr)
{
- std::vector<std::unique_ptr<HIR::Expr> > tuple_elements;
+ std::vector<std::unique_ptr<HIR::Expr>> tuple_elements;
for (auto &e : expr.get_tuple_elems ())
{
HIR::Expr *t = ASTLoweringExpr::translate (*e);
@@ -174,7 +175,7 @@ ASTLoweringExpr::visit (AST::CallExpr &expr)
HIR::Expr *func = ASTLoweringExpr::translate (expr.get_function_expr ());
auto const &in_params = expr.get_params ();
- std::vector<std::unique_ptr<HIR::Expr> > params;
+ std::vector<std::unique_ptr<HIR::Expr>> params;
for (auto ¶m : in_params)
{
auto trans = ASTLoweringExpr::translate (*param);
@@ -200,7 +201,7 @@ ASTLoweringExpr::visit (AST::MethodCallExpr &expr)
HIR::Expr *receiver = ASTLoweringExpr::translate (expr.get_receiver_expr ());
auto const &in_params = expr.get_params ();
- std::vector<std::unique_ptr<HIR::Expr> > params;
+ std::vector<std::unique_ptr<HIR::Expr>> params;
for (auto ¶m : in_params)
{
auto trans = ASTLoweringExpr::translate (*param);
@@ -290,7 +291,7 @@ ASTLoweringExpr::visit (AST::ArrayIndexExpr &expr)
void
ASTLoweringExpr::visit (AST::ArrayElemsValues &elems)
{
- std::vector<std::unique_ptr<HIR::Expr> > elements;
+ std::vector<std::unique_ptr<HIR::Expr>> elements;
for (auto &elem : elems.get_values ())
{
HIR::Expr *translated_elem = ASTLoweringExpr::translate (*elem);
@@ -511,16 +512,17 @@ ASTLoweringExpr::visit (AST::StructExprStructFields &struct_expr)
HIR::PathInExpression copied_path (*path);
delete path;
- HIR::StructBase *base = nullptr;
+ tl::optional<std::unique_ptr<HIR::StructBase>> base = tl::nullopt;
if (struct_expr.has_struct_base ())
{
HIR::Expr *translated_base = ASTLoweringExpr::translate (
struct_expr.get_struct_base ().get_base_struct ());
- base = new HIR::StructBase (std::unique_ptr<HIR::Expr> (translated_base));
+ base = tl::optional (Rust::make_unique<StructBase> (
+ std::unique_ptr<HIR::Expr> (translated_base)));
}
auto const &in_fields = struct_expr.get_fields ();
- std::vector<std::unique_ptr<HIR::StructExprField> > fields;
+ std::vector<std::unique_ptr<HIR::StructExprField>> fields;
for (auto &field : in_fields)
{
HIR::StructExprField *translated
@@ -535,7 +537,8 @@ ASTLoweringExpr::visit (AST::StructExprStructFields &struct_expr)
translated
= new HIR::StructExprStructFields (mapping, copied_path, std::move (fields),
- struct_expr.get_locus (), base,
+ struct_expr.get_locus (),
+ std::move (base),
struct_expr.get_inner_attrs (),
struct_expr.get_outer_attrs ());
}
diff --git a/gcc/rust/hir/rust-hir-dump.cc b/gcc/rust/hir/rust-hir-dump.cc
index 65799e89f6b..5d2a09db348 100644
--- a/gcc/rust/hir/rust-hir-dump.cc
+++ b/gcc/rust/hir/rust-hir-dump.cc
@@ -1171,7 +1171,7 @@ Dump::visit (StructExprStructFields &e)
if (!e.has_struct_base ())
put_field ("struct_base", "none");
else
- put_field ("struct_base", e.get_struct_base ()->as_string ());
+ put_field ("struct_base", e.get_struct_base ().as_string ());
end ("StructExprStructFields");
}
@@ -1182,7 +1182,7 @@ Dump::visit (StructExprStructBase &e)
begin ("StructExprStructBase");
do_structexprstruct (e);
- put_field ("struct_base", e.get_struct_base ()->as_string ());
+ put_field ("struct_base", e.get_struct_base ().as_string ());
end ("StructExprStructBase");
}
diff --git a/gcc/rust/hir/tree/rust-hir-attrs.h b/gcc/rust/hir/tree/rust-hir-attrs.h
new file mode 100644
index 00000000000..3e2b1d87cf8
--- /dev/null
+++ b/gcc/rust/hir/tree/rust-hir-attrs.h
@@ -0,0 +1,56 @@
+
+// Copyright (C) 2020-2024 Free Software Foundation, Inc.
+
+// This file is part of GCC.
+
+// GCC is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3, or (at your option) any later
+// version.
+
+// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with GCC; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#ifndef RUST_HIR_ATTRS_H
+#define RUST_HIR_ATTRS_H
+
+#include "rust-ast.h"
+
+namespace Rust {
+namespace HIR {
+
+class WithOuterAttrs
+{
+protected:
+ AST::AttrVec outer_attrs;
+
+public:
+ AST::AttrVec &get_outer_attrs () { return outer_attrs; }
+ const AST::AttrVec &get_outer_attrs () const { return outer_attrs; }
+
+ WithOuterAttrs (AST::AttrVec outer_attrs)
+ : outer_attrs (std::move (outer_attrs)){};
+};
+
+class WithInnerAttrs
+{
+protected:
+ AST::AttrVec inner_attrs;
+
+public:
+ AST::AttrVec get_inner_attrs () const { return inner_attrs; }
+
+ WithInnerAttrs (AST::AttrVec inner_attrs)
+ : inner_attrs (std::move (inner_attrs)){};
+};
+
+} // namespace HIR
+} // namespace Rust
+
+#endif
diff --git a/gcc/rust/hir/tree/rust-hir-bound-abstract.h b/gcc/rust/hir/tree/rust-hir-bound-abstract.h
new file mode 100644
index 00000000000..ffc915be919
--- /dev/null
+++ b/gcc/rust/hir/tree/rust-hir-bound-abstract.h
@@ -0,0 +1,65 @@
+// Copyright (C) 2020-2024 Free Software Foundation, Inc.
+
+// This file is part of GCC.
+
+// GCC is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3, or (at your option) any later
+// version.
+
+// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with GCC; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#ifndef RUST_HIR_BOUND_ABSTRACT_H
+#define RUST_HIR_BOUND_ABSTRACT_H
+
+#include "rust-hir-visitable.h"
+#include "rust-system.h"
+#include "rust-hir-map.h"
+
+namespace Rust {
+namespace HIR {
+
+/* Abstract base class representing a type param bound - Lifetime and TraitBound
+ * extends it */
+class TypeParamBound : public FullVisitable
+{
+public:
+ using FullVisitable::accept_vis;
+ enum BoundType
+ {
+ LIFETIME,
+ TRAITBOUND
+ };
+
+ virtual ~TypeParamBound () {}
+
+ // Unique pointer custom clone function
+ std::unique_ptr<TypeParamBound> clone_type_param_bound () const
+ {
+ return std::unique_ptr<TypeParamBound> (clone_type_param_bound_impl ());
+ }
+
+ virtual std::string as_string () const = 0;
+
+ virtual Analysis::NodeMapping get_mappings () const = 0;
+
+ virtual location_t get_locus () const = 0;
+
+ virtual BoundType get_bound_type () const = 0;
+
+protected:
+ // Clone function implementation as pure virtual method
+ virtual TypeParamBound *clone_type_param_bound_impl () const = 0;
+};
+
+} // namespace HIR
+} // namespace Rust
+
+#endif
diff --git a/gcc/rust/hir/tree/rust-hir-bound.h b/gcc/rust/hir/tree/rust-hir-bound.h
new file mode 100644
index 00000000000..78bb133f6d4
--- /dev/null
+++ b/gcc/rust/hir/tree/rust-hir-bound.h
@@ -0,0 +1,94 @@
+// Copyright (C) 2020-2024 Free Software Foundation, Inc.
+
+// This file is part of GCC.
+
+// GCC is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3, or (at your option) any later
+// version.
+
+// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with GCC; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#ifndef RUST_HIR_BOUND_H
+#define RUST_HIR_BOUND_H
+
+#include "rust-hir-bound-abstract.h"
+#include "rust-common.h"
+#include "rust-hir-path.h"
+
+namespace Rust {
+namespace HIR {
+
+// Represents a lifetime (and is also a kind of type param bound)
+class Lifetime : public TypeParamBound
+{
+private:
+ AST::Lifetime::LifetimeType lifetime_type;
+ std::string lifetime_name;
+ location_t locus;
+ Analysis::NodeMapping mappings;
+
+public:
+ // Constructor
+ Lifetime (Analysis::NodeMapping mapping, AST::Lifetime::LifetimeType type,
+ std::string name, location_t locus)
+ : lifetime_type (type), lifetime_name (std::move (name)), locus (locus),
+ mappings (mapping)
+ {}
+
+ // Returns true if the lifetime is in an error state.
+ bool is_error () const
+ {
+ return lifetime_type == AST::Lifetime::LifetimeType::NAMED
+ && lifetime_name.empty ();
+ }
+
+ static Lifetime error ()
+ {
+ return Lifetime (Analysis::NodeMapping::get_error (),
+ AST::Lifetime::LifetimeType::NAMED, "", UNDEF_LOCATION);
+ }
+
+ std::string as_string () const override;
+
+ void accept_vis (HIRFullVisitor &vis) override;
+
+ WARN_UNUSED_RESULT const std::string &get_name () const
+ {
+ return lifetime_name;
+ }
+
+ AST::Lifetime::LifetimeType get_lifetime_type () const
+ {
+ return lifetime_type;
+ }
+
+ location_t get_locus () const override final { return locus; }
+
+ Analysis::NodeMapping get_mappings () const override final
+ {
+ return mappings;
+ }
+
+ BoundType get_bound_type () const final override { return LIFETIME; }
+
+protected:
+ /* Use covariance to implement clone function as returning this object rather
+ * than base */
+ Lifetime *clone_type_param_bound_impl () const override
+ {
+ return new Lifetime (*this);
+ }
+};
+
+} // namespace HIR
+} // namespace Rust
+
+#endif
diff --git a/gcc/rust/hir/tree/rust-hir-expr-abstract.h b/gcc/rust/hir/tree/rust-hir-expr-abstract.h
new file mode 100644
index 00000000000..ecf9bd1af5d
--- /dev/null
+++ b/gcc/rust/hir/tree/rust-hir-expr-abstract.h
@@ -0,0 +1,174 @@
+// Copyright (C) 2020-2024 Free Software Foundation, Inc.
+
+// This file is part of GCC.
+
+// GCC is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3, or (at your option) any later
+// version.
+
+// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with GCC; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#ifndef RUST_HIR_EXPR_ABSTRACT_H
+#define RUST_HIR_EXPR_ABSTRACT_H
+
+#include "rust-ast.h"
+#include "rust-hir-visitable.h"
+#include "rust-hir-node.h"
+
+namespace Rust {
+namespace HIR {
+
+// Base expression HIR node - abstract
+class Expr : public Node, virtual public FullVisitable
+{
+public:
+ using FullVisitable::accept_vis;
+
+protected:
+ AST::AttrVec outer_attrs;
+ Analysis::NodeMapping mappings;
+
+public:
+ enum BlockType
+ {
+ WITH_BLOCK,
+ WITHOUT_BLOCK,
+ };
+
+ enum ExprType
+ {
+ Lit,
+ Operator,
+ Grouped,
+ Array,
+ ArrayIndex,
+ Tuple,
+ TupleIdx,
+ Struct,
+ Call,
+ MethodCall,
+ FieldAccess,
+ Closure,
+ Block,
+ Continue,
+ Break,
+ Range,
+ Return,
+ UnsafeBlock,
+ BaseLoop,
+ If,
+ IfLet,
+ Match,
+ Await,
+ AsyncBlock,
+ Path,
+ InlineAsm,
+ };
+
+ BaseKind get_hir_kind () override final { return Node::BaseKind::EXPR; }
+
+ const AST::AttrVec &get_outer_attrs () const { return outer_attrs; }
+
+ // Unique pointer custom clone function
+ std::unique_ptr<Expr> clone_expr () const
+ {
+ return std::unique_ptr<Expr> (clone_expr_impl ());
+ }
+
+ // TODO: make pure virtual if move out outer attributes to derived classes
+ virtual std::string as_string () const;
+
+ virtual ~Expr () {}
+
+ virtual location_t get_locus () const = 0;
+
+ const Analysis::NodeMapping &get_mappings () const { return mappings; }
+
+ // Clone function implementation as pure virtual method
+ virtual Expr *clone_expr_impl () const = 0;
+
+ virtual BlockType get_block_expr_type () const = 0;
+
+ virtual ExprType get_expression_type () const = 0;
+
+ virtual void accept_vis (HIRExpressionVisitor &vis) = 0;
+
+protected:
+ // Constructor
+ Expr (Analysis::NodeMapping mappings,
+ AST::AttrVec outer_attribs = AST::AttrVec ());
+
+ // TODO: think of less hacky way to implement this kind of thing
+ // Sets outer attributes.
+ void set_outer_attrs (AST::AttrVec outer_attrs_to_set)
+ {
+ outer_attrs = std::move (outer_attrs_to_set);
+ }
+};
+
+// HIR node for an expression without an accompanying block - abstract
+class ExprWithoutBlock : public Expr
+{
+protected:
+ // Constructor
+ ExprWithoutBlock (Analysis::NodeMapping mappings,
+ AST::AttrVec outer_attribs = AST::AttrVec ());
+
+ // pure virtual clone implementation
+ virtual ExprWithoutBlock *clone_expr_without_block_impl () const = 0;
+
+ /* Save having to specify two clone methods in derived classes by making expr
+ * clone return exprwithoutblock clone. Hopefully won't affect performance too
+ * much. */
+ ExprWithoutBlock *clone_expr_impl () const override
+ {
+ return clone_expr_without_block_impl ();
+ }
+
+public:
+ // Unique pointer custom clone function
+ std::unique_ptr<ExprWithoutBlock> clone_expr_without_block () const
+ {
+ return std::unique_ptr<ExprWithoutBlock> (clone_expr_without_block_impl ());
+ }
+
+ BlockType get_block_expr_type () const final override
+ {
+ return BlockType::WITHOUT_BLOCK;
+ };
+};
+
+// Base path expression HIR node - abstract
+class PathExpr : public ExprWithoutBlock
+{
+protected:
+ PathExpr (Analysis::NodeMapping mappings, AST::AttrVec outer_attribs)
+ : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs))
+ {}
+
+public:
+ /* Replaces the outer attributes of this path expression with the given outer
+ * attributes. */
+ void replace_outer_attrs (AST::AttrVec outer_attrs)
+ {
+ set_outer_attrs (std::move (outer_attrs));
+ }
+
+ ExprType get_expression_type () const final override
+ {
+ return ExprType::Path;
+ }
+};
+
+} // namespace HIR
+} // namespace Rust
+
+#endif
diff --git a/gcc/rust/hir/tree/rust-hir-expr.cc b/gcc/rust/hir/tree/rust-hir-expr.cc
new file mode 100644
index 00000000000..6c9a7a475e7
--- /dev/null
+++ b/gcc/rust/hir/tree/rust-hir-expr.cc
@@ -0,0 +1,1478 @@
+// Copyright (C) 2020-2024 Free Software Foundation, Inc.
+
+// This file is part of GCC.
+
+// GCC is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3, or (at your option) any later
+// version.
+
+// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with GCC; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include "rust-hir-expr.h"
+#include "rust-operators.h"
+#include "rust-hir-stmt.h"
+
+namespace Rust {
+namespace HIR {
+
+Expr::Expr (Analysis::NodeMapping mappings, AST::AttrVec outer_attribs)
+ : outer_attrs (std::move (outer_attribs)), mappings (std::move (mappings))
+{}
+
+ExprWithoutBlock::ExprWithoutBlock (Analysis::NodeMapping mappings,
+ AST::AttrVec outer_attribs)
+ : Expr (std::move (mappings), std::move (outer_attribs))
+{}
+
+LoopLabel::LoopLabel (Analysis::NodeMapping mapping, Lifetime loop_label,
+ location_t locus)
+ : label (std::move (loop_label)), locus (locus), mappings (mapping)
+{}
+
+ExprWithBlock::ExprWithBlock (Analysis::NodeMapping mappings,
+ AST::AttrVec outer_attrs)
+ : Expr (std::move (mappings), std::move (outer_attrs))
+{}
+
+LiteralExpr::LiteralExpr (Analysis::NodeMapping mappings,
+ std::string value_as_string, Literal::LitType type,
+ PrimitiveCoreType type_hint, location_t locus,
+ AST::AttrVec outer_attrs)
+ : ExprWithoutBlock (std::move (mappings), std::move (outer_attrs)),
+ literal (std::move (value_as_string), type, type_hint), locus (locus)
+{}
+
+LiteralExpr::LiteralExpr (Analysis::NodeMapping mappings, Literal literal,
+ location_t locus, AST::AttrVec outer_attrs)
+ : ExprWithoutBlock (std::move (mappings), std::move (outer_attrs)),
+ literal (std::move (literal)), locus (locus)
+{}
+
+OperatorExpr::OperatorExpr (Analysis::NodeMapping mappings,
+ std::unique_ptr<Expr> main_or_left_expr,
+ AST::AttrVec outer_attribs, location_t locus)
+ : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
+ locus (locus), main_or_left_expr (std::move (main_or_left_expr))
+{}
+
+OperatorExpr::OperatorExpr (OperatorExpr const &other)
+ : ExprWithoutBlock (other), locus (other.locus),
+ main_or_left_expr (other.main_or_left_expr->clone_expr ())
+{}
+
+OperatorExpr &
+OperatorExpr::operator= (OperatorExpr const &other)
+{
+ ExprWithoutBlock::operator= (other);
+ main_or_left_expr = other.main_or_left_expr->clone_expr ();
+ locus = other.locus;
+ // outer_attrs = other.outer_attrs;
+
+ return *this;
+}
+
+BorrowExpr::BorrowExpr (Analysis::NodeMapping mappings,
+ std::unique_ptr<Expr> borrow_lvalue, Mutability mut,
+ AST::AttrVec outer_attribs, location_t locus)
+ : OperatorExpr (std::move (mappings), std::move (borrow_lvalue),
+ std::move (outer_attribs), locus),
+ mut (mut)
+{}
+
+DereferenceExpr::DereferenceExpr (Analysis::NodeMapping mappings,
+ std::unique_ptr<Expr> deref_lvalue,
+ AST::AttrVec outer_attribs, location_t locus)
+ : OperatorExpr (std::move (mappings), std::move (deref_lvalue),
+ std::move (outer_attribs), locus)
+{}
+
+ErrorPropagationExpr::ErrorPropagationExpr (
+ Analysis::NodeMapping mappings, std::unique_ptr<Expr> potential_error_value,
+ AST::AttrVec outer_attribs, location_t locus)
+ : OperatorExpr (std::move (mappings), std::move (potential_error_value),
+ std::move (outer_attribs), locus)
+{}
+
+NegationExpr::NegationExpr (Analysis::NodeMapping mappings,
+ std::unique_ptr<Expr> negated_value,
+ ExprType expr_kind, AST::AttrVec outer_attribs,
+ location_t locus)
+ : OperatorExpr (std::move (mappings), std::move (negated_value),
+ std::move (outer_attribs), locus),
+ expr_type (expr_kind)
+{}
+
+ArithmeticOrLogicalExpr::ArithmeticOrLogicalExpr (
+ Analysis::NodeMapping mappings, std::unique_ptr<Expr> left_value,
+ std::unique_ptr<Expr> right_value, ExprType expr_kind, location_t locus)
+ : OperatorExpr (std::move (mappings), std::move (left_value), AST::AttrVec (),
+ locus),
+ expr_type (expr_kind), right_expr (std::move (right_value))
+{}
+
+ArithmeticOrLogicalExpr::ArithmeticOrLogicalExpr (
+ ArithmeticOrLogicalExpr const &other)
+ : OperatorExpr (other), expr_type (other.expr_type),
+ right_expr (other.right_expr->clone_expr ())
+{}
+
+ArithmeticOrLogicalExpr &
+ArithmeticOrLogicalExpr::operator= (ArithmeticOrLogicalExpr const &other)
+{
+ OperatorExpr::operator= (other);
+ // main_or_left_expr = other.main_or_left_expr->clone_expr();
+ right_expr = other.right_expr->clone_expr ();
+ expr_type = other.expr_type;
+
+ return *this;
+}
+
+ComparisonExpr::ComparisonExpr (Analysis::NodeMapping mappings,
+ std::unique_ptr<Expr> left_value,
+ std::unique_ptr<Expr> right_value,
+ ExprType comparison_kind, location_t locus)
+ : OperatorExpr (std::move (mappings), std::move (left_value), AST::AttrVec (),
+ locus),
+ expr_type (comparison_kind), right_expr (std::move (right_value))
+{}
+
+ComparisonExpr::ComparisonExpr (ComparisonExpr const &other)
+ : OperatorExpr (other), expr_type (other.expr_type),
+ right_expr (other.right_expr->clone_expr ())
+{}
+
+ComparisonExpr &
+ComparisonExpr::operator= (ComparisonExpr const &other)
+{
+ OperatorExpr::operator= (other);
+ // main_or_left_expr = other.main_or_left_expr->clone_expr();
+ right_expr = other.right_expr->clone_expr ();
+ expr_type = other.expr_type;
+ // outer_attrs = other.outer_attrs;
+
+ return *this;
+}
+
+LazyBooleanExpr::LazyBooleanExpr (Analysis::NodeMapping mappings,
+ std::unique_ptr<Expr> left_bool_expr,
+ std::unique_ptr<Expr> right_bool_expr,
+ ExprType expr_kind, location_t locus)
+ : OperatorExpr (std::move (mappings), std::move (left_bool_expr),
+ AST::AttrVec (), locus),
+ expr_type (expr_kind), right_expr (std::move (right_bool_expr))
+{}
+
+LazyBooleanExpr::LazyBooleanExpr (LazyBooleanExpr const &other)
+ : OperatorExpr (other), expr_type (other.expr_type),
+ right_expr (other.right_expr->clone_expr ())
+{}
+
+LazyBooleanExpr &
+LazyBooleanExpr::operator= (LazyBooleanExpr const &other)
+{
+ OperatorExpr::operator= (other);
+ // main_or_left_expr = other.main_or_left_expr->clone_expr();
+ right_expr = other.right_expr->clone_expr ();
+ expr_type = other.expr_type;
+
+ return *this;
+}
+
+TypeCastExpr::TypeCastExpr (Analysis::NodeMapping mappings,
+ std::unique_ptr<Expr> expr_to_cast,
+ std::unique_ptr<Type> type_to_cast_to,
+ location_t locus)
+ : OperatorExpr (std::move (mappings), std::move (expr_to_cast),
+ AST::AttrVec (), locus),
+ type_to_convert_to (std::move (type_to_cast_to))
+{}
+
+TypeCastExpr::TypeCastExpr (TypeCastExpr const &other)
+ : OperatorExpr (other),
+ type_to_convert_to (other.type_to_convert_to->clone_type ())
+{}
+
+TypeCastExpr &
+TypeCastExpr::operator= (TypeCastExpr const &other)
+{
+ OperatorExpr::operator= (other);
+ // main_or_left_expr = other.main_or_left_expr->clone_expr();
+ type_to_convert_to = other.type_to_convert_to->clone_type ();
+
+ return *this;
+}
+
+AssignmentExpr::AssignmentExpr (Analysis::NodeMapping mappings,
+ std::unique_ptr<Expr> value_to_assign_to,
+ std::unique_ptr<Expr> value_to_assign,
+ location_t locus)
+ : OperatorExpr (std::move (mappings), std::move (value_to_assign_to),
+ AST::AttrVec (), locus),
+ right_expr (std::move (value_to_assign))
+{}
+
+AssignmentExpr::AssignmentExpr (AssignmentExpr const &other)
+ : OperatorExpr (other), right_expr (other.right_expr->clone_expr ())
+{}
+
+AssignmentExpr &
+AssignmentExpr::operator= (AssignmentExpr const &other)
+{
+ OperatorExpr::operator= (other);
+ // main_or_left_expr = other.main_or_left_expr->clone_expr();
+ right_expr = other.right_expr->clone_expr ();
+ // outer_attrs = other.outer_attrs;
+
+ return *this;
+}
+
+CompoundAssignmentExpr::CompoundAssignmentExpr (
+ Analysis::NodeMapping mappings, std::unique_ptr<Expr> value_to_assign_to,
+ std::unique_ptr<Expr> value_to_assign, ExprType expr_kind, location_t locus)
+ : OperatorExpr (std::move (mappings), std::move (value_to_assign_to),
+ AST::AttrVec (), locus),
+ expr_type (expr_kind), right_expr (std::move (value_to_assign))
+{}
+
+CompoundAssignmentExpr::CompoundAssignmentExpr (
+ CompoundAssignmentExpr const &other)
+ : OperatorExpr (other), expr_type (other.expr_type),
+ right_expr (other.right_expr->clone_expr ())
+{}
+
+CompoundAssignmentExpr &
+CompoundAssignmentExpr::operator= (CompoundAssignmentExpr const &other)
+{
+ OperatorExpr::operator= (other);
+ // main_or_left_expr = other.main_or_left_expr->clone_expr();
+ right_expr = other.right_expr->clone_expr ();
+ expr_type = other.expr_type;
+ // outer_attrs = other.outer_attrs;
+
+ return *this;
+}
+
+GroupedExpr::GroupedExpr (Analysis::NodeMapping mappings,
+ std::unique_ptr<Expr> parenthesised_expr,
+ AST::AttrVec inner_attribs,
+ AST::AttrVec outer_attribs, location_t locus)
+ : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
+ WithInnerAttrs (std::move (inner_attribs)),
+ expr_in_parens (std::move (parenthesised_expr)), locus (locus)
+{}
+
+GroupedExpr::GroupedExpr (GroupedExpr const &other)
+ : ExprWithoutBlock (other), WithInnerAttrs (other.inner_attrs),
+ expr_in_parens (other.expr_in_parens->clone_expr ()), locus (other.locus)
+{}
+
+GroupedExpr &
+GroupedExpr::operator= (GroupedExpr const &other)
+{
+ ExprWithoutBlock::operator= (other);
+ inner_attrs = other.inner_attrs;
+ expr_in_parens = other.expr_in_parens->clone_expr ();
+ locus = other.locus;
+ // outer_attrs = other.outer_attrs;
+
+ return *this;
+}
+
+ArrayElemsValues::ArrayElemsValues (Analysis::NodeMapping mappings,
+ std::vector<std::unique_ptr<Expr>> elems)
+ : ArrayElems (mappings), values (std::move (elems))
+{}
+
+ArrayElemsValues::ArrayElemsValues (ArrayElemsValues const &other)
+ : ArrayElems (other)
+{
+ values.reserve (other.values.size ());
+ for (const auto &e : other.values)
+ values.push_back (e->clone_expr ());
+}
+
+ArrayElemsValues &
+ArrayElemsValues::operator= (ArrayElemsValues const &other)
+{
+ values.reserve (other.values.size ());
+ for (const auto &e : other.values)
+ values.push_back (e->clone_expr ());
+
+ return *this;
+}
+
+ArrayElemsCopied::ArrayElemsCopied (Analysis::NodeMapping mappings,
+ std::unique_ptr<Expr> copied_elem,
+ std::unique_ptr<Expr> copy_amount)
+ : ArrayElems (mappings), elem_to_copy (std::move (copied_elem)),
+ num_copies (std::move (copy_amount))
+{}
+
+ArrayElemsCopied::ArrayElemsCopied (ArrayElemsCopied const &other)
+ : ArrayElems (other), elem_to_copy (other.elem_to_copy->clone_expr ()),
+ num_copies (other.num_copies->clone_expr ())
+{}
+
+ArrayElemsCopied &
+ArrayElemsCopied::operator= (ArrayElemsCopied const &other)
+{
+ elem_to_copy = other.elem_to_copy->clone_expr ();
+ num_copies = other.num_copies->clone_expr ();
+
+ return *this;
+}
+
+ArrayExpr::ArrayExpr (Analysis::NodeMapping mappings,
+ std::unique_ptr<ArrayElems> array_elems,
+ AST::AttrVec inner_attribs, AST::AttrVec outer_attribs,
+ location_t locus)
+ : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
+ WithInnerAttrs (std::move (inner_attribs)),
+ internal_elements (std::move (array_elems)), locus (locus)
+{}
+
+ArrayExpr::ArrayExpr (ArrayExpr const &other)
+ : ExprWithoutBlock (other), WithInnerAttrs (other.inner_attrs),
+ locus (other.locus)
+{
+ if (other.has_array_elems ())
+ internal_elements = other.internal_elements->clone_array_elems ();
+}
+
+ArrayExpr &
+ArrayExpr::operator= (ArrayExpr const &other)
+{
+ ExprWithoutBlock::operator= (other);
+ inner_attrs = other.inner_attrs;
+ if (other.has_array_elems ())
+ internal_elements = other.internal_elements->clone_array_elems ();
+ locus = other.locus;
+ // outer_attrs = other.outer_attrs;
+
+ return *this;
+}
+
+ArrayIndexExpr::ArrayIndexExpr (Analysis::NodeMapping mappings,
+ std::unique_ptr<Expr> array_expr,
+ std::unique_ptr<Expr> array_index_expr,
+ AST::AttrVec outer_attribs, location_t locus)
+ : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
+ array_expr (std::move (array_expr)),
+ index_expr (std::move (array_index_expr)), locus (locus)
+{}
+
+ArrayIndexExpr::ArrayIndexExpr (ArrayIndexExpr const &other)
+ : ExprWithoutBlock (other), array_expr (other.array_expr->clone_expr ()),
+ index_expr (other.index_expr->clone_expr ()), locus (other.locus)
+{}
+
+ArrayIndexExpr &
+ArrayIndexExpr::operator= (ArrayIndexExpr const &other)
+{
+ ExprWithoutBlock::operator= (other);
+ array_expr = other.array_expr->clone_expr ();
+ index_expr = other.index_expr->clone_expr ();
+ // outer_attrs = other.outer_attrs;
+ locus = other.locus;
+
+ return *this;
+}
+
+TupleExpr::TupleExpr (Analysis::NodeMapping mappings,
+ std::vector<std::unique_ptr<Expr>> tuple_elements,
+ AST::AttrVec inner_attribs, AST::AttrVec outer_attribs,
+ location_t locus)
+ : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
+ WithInnerAttrs (std::move (inner_attribs)),
+ tuple_elems (std::move (tuple_elements)), locus (locus)
+{}
+
+TupleExpr::TupleExpr (TupleExpr const &other)
+ : ExprWithoutBlock (other), WithInnerAttrs (other.inner_attrs),
+ locus (other.locus)
+{
+ tuple_elems.reserve (other.tuple_elems.size ());
+ for (const auto &e : other.tuple_elems)
+ tuple_elems.push_back (e->clone_expr ());
+}
+
+TupleExpr &
+TupleExpr::operator= (TupleExpr const &other)
+{
+ ExprWithoutBlock::operator= (other);
+ inner_attrs = other.inner_attrs;
+ locus = other.locus;
+
+ tuple_elems.reserve (other.tuple_elems.size ());
+ for (const auto &e : other.tuple_elems)
+ tuple_elems.push_back (e->clone_expr ());
+
+ return *this;
+}
+
+TupleIndexExpr::TupleIndexExpr (Analysis::NodeMapping mappings,
+ std::unique_ptr<Expr> tuple_expr,
+ TupleIndex index, AST::AttrVec outer_attribs,
+ location_t locus)
+ : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
+ tuple_expr (std::move (tuple_expr)), tuple_index (index), locus (locus)
+{}
+
+TupleIndexExpr::TupleIndexExpr (TupleIndexExpr const &other)
+ : ExprWithoutBlock (other), tuple_expr (other.tuple_expr->clone_expr ()),
+ tuple_index (other.tuple_index), locus (other.locus)
+{}
+
+TupleIndexExpr &
+TupleIndexExpr::operator= (TupleIndexExpr const &other)
+{
+ ExprWithoutBlock::operator= (other);
+ tuple_expr = other.tuple_expr->clone_expr ();
+ tuple_index = other.tuple_index;
+ locus = other.locus;
+ // outer_attrs = other.outer_attrs;
+
+ return *this;
+}
+
+StructExpr::StructExpr (Analysis::NodeMapping mappings,
+ PathInExpression struct_path,
+ AST::AttrVec outer_attribs)
+ : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
+ struct_name (std::move (struct_path))
+{}
+
+StructExprStruct::StructExprStruct (Analysis::NodeMapping mappings,
+ PathInExpression struct_path,
+ AST::AttrVec inner_attribs,
+ AST::AttrVec outer_attribs,
+ location_t locus)
+ : StructExpr (std::move (mappings), std::move (struct_path),
+ std::move (outer_attribs)),
+ WithInnerAttrs (std::move (inner_attribs)), locus (locus)
+{}
+
+StructBase::StructBase (std::unique_ptr<Expr> base_struct_ptr)
+ : base_struct (std::move (base_struct_ptr))
+{}
+
+StructBase::StructBase (StructBase const &other)
+{
+ /* HACK: gets around base_struct pointer being null (e.g. if no struct base
+ * exists) */
+ if (other.base_struct != nullptr)
+ other.base_struct->clone_expr ();
+}
+
+StructBase &
+StructBase::operator= (StructBase const &other)
+{
+ base_struct = other.base_struct->clone_expr ();
+
+ return *this;
+}
+
+StructExprField::StructExprField (Analysis::NodeMapping mapping,
+ location_t locus)
+ : mappings (mapping), locus (locus)
+{}
+
+StructExprFieldIdentifier::StructExprFieldIdentifier (
+ Analysis::NodeMapping mapping, Identifier field_identifier, location_t locus)
+ : StructExprField (mapping, locus), field_name (std::move (field_identifier))
+{}
+
+StructExprFieldWithVal::StructExprFieldWithVal (
+ Analysis::NodeMapping mapping, std::unique_ptr<Expr> field_value,
+ location_t locus)
+ : StructExprField (mapping, locus), value (std::move (field_value))
+{}
+
+StructExprFieldWithVal::StructExprFieldWithVal (
+ StructExprFieldWithVal const &other)
+ : StructExprField (other.mappings, other.locus),
+ value (other.value->clone_expr ())
+{}
+
+StructExprFieldWithVal &
+StructExprFieldWithVal::operator= (StructExprFieldWithVal const &other)
+{
+ value = other.value->clone_expr ();
+ mappings = other.mappings;
+ locus = other.locus;
+
+ return *this;
+}
+
+StructExprFieldIdentifierValue::StructExprFieldIdentifierValue (
+ Analysis::NodeMapping mapping, Identifier field_identifier,
+ std::unique_ptr<Expr> field_value, location_t locus)
+ : StructExprFieldWithVal (mapping, std::move (field_value), locus),
+ field_name (std::move (field_identifier))
+{}
+
+StructExprFieldIndexValue::StructExprFieldIndexValue (
+ Analysis::NodeMapping mapping, TupleIndex tuple_index,
+ std::unique_ptr<Expr> field_value, location_t locus)
+ : StructExprFieldWithVal (mapping, std::move (field_value), locus),
+ index (tuple_index)
+{}
+
+StructExprStructFields::StructExprStructFields (
+ Analysis::NodeMapping mappings, PathInExpression struct_path,
+ std::vector<std::unique_ptr<StructExprField>> expr_fields, location_t locus,
+ tl::optional<std::unique_ptr<StructBase>> base_struct,
+ AST::AttrVec inner_attribs = AST::AttrVec (),
+ AST::AttrVec outer_attribs = AST::AttrVec ())
+ : StructExprStruct (std::move (mappings), std::move (struct_path),
+ std::move (inner_attribs), std::move (outer_attribs),
+ locus),
+ fields (std::move (expr_fields)), struct_base (std::move (base_struct))
+{}
+
+StructExprStructFields::StructExprStructFields (
+ StructExprStructFields const &other)
+ : StructExprStruct (other),
+ struct_base (
+ other.has_struct_base () ? tl::optional<std::unique_ptr<StructBase>> (
+ Rust::make_unique<StructBase> (*other.struct_base.value ()))
+ : tl::nullopt),
+ union_index (other.union_index)
+{
+ fields.reserve (other.fields.size ());
+ for (const auto &e : other.fields)
+ fields.push_back (e->clone_struct_expr_field ());
+}
+
+StructExprStructFields &
+StructExprStructFields::operator= (StructExprStructFields const &other)
+{
+ StructExprStruct::operator= (other);
+ struct_base = other.has_struct_base ()
+ ? tl::optional<std::unique_ptr<StructBase>> (
+ Rust::make_unique<StructBase> (*other.struct_base.value ()))
+ : tl::nullopt;
+ union_index = other.union_index;
+
+ fields.reserve (other.fields.size ());
+ for (const auto &e : other.fields)
+ fields.push_back (e->clone_struct_expr_field ());
+
+ return *this;
+}
+
+StructExprStructBase::StructExprStructBase (Analysis::NodeMapping mappings,
+ PathInExpression struct_path,
+ StructBase base_struct,
+ AST::AttrVec inner_attribs,
+ AST::AttrVec outer_attribs,
+ location_t locus)
+ : StructExprStruct (std::move (mappings), std::move (struct_path),
+ std::move (inner_attribs), std::move (outer_attribs),
+ locus),
+ struct_base (std::move (base_struct))
+{}
+
+CallExpr::CallExpr (Analysis::NodeMapping mappings,
+ std::unique_ptr<Expr> function_expr,
+ std::vector<std::unique_ptr<Expr>> function_params,
+ AST::AttrVec outer_attribs, location_t locus)
+ : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
+ function (std::move (function_expr)), params (std::move (function_params)),
+ locus (locus)
+{}
+
+CallExpr::CallExpr (CallExpr const &other)
+ : ExprWithoutBlock (other), function (other.function->clone_expr ()),
+ locus (other.locus)
+/*, params(other.params),*/ {
+ params.reserve (other.params.size ());
+ for (const auto &e : other.params)
+ params.push_back (e->clone_expr ());
+}
+
+CallExpr &
+CallExpr::operator= (CallExpr const &other)
+{
+ ExprWithoutBlock::operator= (other);
+ function = other.function->clone_expr ();
+ locus = other.locus;
+ // params = other.params;
+ // outer_attrs = other.outer_attrs;
+
+ params.reserve (other.params.size ());
+ for (const auto &e : other.params)
+ params.push_back (e->clone_expr ());
+
+ return *this;
+}
+
+MethodCallExpr::MethodCallExpr (
+ Analysis::NodeMapping mappings, std::unique_ptr<Expr> call_receiver,
+ PathExprSegment method_path, std::vector<std::unique_ptr<Expr>> method_params,
+ AST::AttrVec outer_attribs, location_t locus)
+ : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
+ receiver (std::move (call_receiver)), method_name (std::move (method_path)),
+ params (std::move (method_params)), locus (locus)
+{}
+
+MethodCallExpr::MethodCallExpr (MethodCallExpr const &other)
+ : ExprWithoutBlock (other), receiver (other.receiver->clone_expr ()),
+ method_name (other.method_name), locus (other.locus)
+/*, params(other.params),*/ {
+ params.reserve (other.params.size ());
+ for (const auto &e : other.params)
+ params.push_back (e->clone_expr ());
+}
+
+MethodCallExpr &
+MethodCallExpr::operator= (MethodCallExpr const &other)
+{
+ ExprWithoutBlock::operator= (other);
+ receiver = other.receiver->clone_expr ();
+ method_name = other.method_name;
+ locus = other.locus;
+ // params = other.params;
+ // outer_attrs = other.outer_attrs;
+
+ params.reserve (other.params.size ());
+ for (const auto &e : other.params)
+ params.push_back (e->clone_expr ());
+
+ return *this;
+}
+
+FieldAccessExpr::FieldAccessExpr (Analysis::NodeMapping mappings,
+ std::unique_ptr<Expr> field_access_receiver,
+ Identifier field_name,
+ AST::AttrVec outer_attribs, location_t locus)
+ : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
+ receiver (std::move (field_access_receiver)),
+ field (std::move (field_name)), locus (locus)
+{}
+
+FieldAccessExpr::FieldAccessExpr (FieldAccessExpr const &other)
+ : ExprWithoutBlock (other), receiver (other.receiver->clone_expr ()),
+ field (other.field), locus (other.locus)
+{}
+
+FieldAccessExpr &
+FieldAccessExpr::operator= (FieldAccessExpr const &other)
+{
+ ExprWithoutBlock::operator= (other);
+ receiver = other.receiver->clone_expr ();
+ field = other.field;
+ locus = other.locus;
+ // outer_attrs = other.outer_attrs;
+
+ return *this;
+}
+
+ClosureParam::ClosureParam (std::unique_ptr<Pattern> param_pattern,
+ location_t locus, std::unique_ptr<Type> param_type,
+ std::vector<AST::Attribute> outer_attrs)
+ : outer_attrs (std::move (outer_attrs)), pattern (std::move (param_pattern)),
+ type (std::move (param_type)), locus (locus)
+{}
+
+ClosureParam::ClosureParam (ClosureParam const &other)
+ : pattern (other.pattern->clone_pattern ())
+{
+ // guard to protect from null pointer dereference
+ if (other.pattern != nullptr)
+ pattern = other.pattern->clone_pattern ();
+ if (other.type != nullptr)
+ type = other.type->clone_type ();
+}
+
+ClosureParam &
+ClosureParam::operator= (ClosureParam const &other)
+{
+ outer_attrs = other.outer_attrs;
+
+ // guard to protect from null pointer dereference
+ if (other.pattern != nullptr)
+ pattern = other.pattern->clone_pattern ();
+ else
+ pattern = nullptr;
+ if (other.type != nullptr)
+ type = other.type->clone_type ();
+ else
+ type = nullptr;
+
+ return *this;
+}
+
+ClosureExpr::ClosureExpr (Analysis::NodeMapping mappings,
+ std::vector<ClosureParam> closure_params,
+ std::unique_ptr<Type> closure_return_type,
+ std::unique_ptr<Expr> closure_expr, bool has_move,
+ AST::AttrVec outer_attribs, location_t locus)
+ : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
+ has_move (has_move), params (std::move (closure_params)), locus (locus),
+ return_type (std::move (closure_return_type)),
+ expr (std::move (closure_expr))
+{}
+
+ClosureExpr::ClosureExpr (ClosureExpr const &other)
+ : ExprWithoutBlock (other.get_mappings (), other.get_outer_attrs ())
+{
+ return_type
+ = other.has_return_type () ? other.return_type->clone_type () : nullptr;
+ expr = other.expr->clone_expr ();
+ params = other.params;
+ has_move = other.has_move;
+}
+
+ClosureExpr &
+ClosureExpr::operator= (ClosureExpr const &other)
+{
+ mappings = other.mappings;
+ return_type
+ = other.has_return_type () ? other.return_type->clone_type () : nullptr;
+ expr = other.expr->clone_expr ();
+ params = other.params;
+ has_move = other.has_move;
+
+ return *this;
+}
+
+BlockExpr::BlockExpr (Analysis::NodeMapping mappings,
+ std::vector<std::unique_ptr<Stmt>> block_statements,
+ std::unique_ptr<Expr> block_expr, bool tail_reachable,
+ AST::AttrVec inner_attribs, AST::AttrVec outer_attribs,
+ LoopLabel label, location_t start_locus,
+ location_t end_locus)
+ : ExprWithBlock (std::move (mappings), std::move (outer_attribs)),
+ WithInnerAttrs (std::move (inner_attribs)),
+ statements (std::move (block_statements)), expr (std::move (block_expr)),
+ tail_reachable (tail_reachable), label (std::move (label)),
+ start_locus (start_locus), end_locus (end_locus)
+{}
+
+BlockExpr::BlockExpr (BlockExpr const &other)
+ : ExprWithBlock (other), /*statements(other.statements),*/
+ WithInnerAttrs (other.inner_attrs), label (other.label),
+ start_locus (other.start_locus), end_locus (other.end_locus)
+{
+ // guard to protect from null pointer dereference
+ if (other.expr != nullptr)
+ expr = other.expr->clone_expr ();
+
+ statements.reserve (other.statements.size ());
+ for (const auto &e : other.statements)
+ statements.push_back (e->clone_stmt ());
+}
+
+BlockExpr &
+BlockExpr::operator= (BlockExpr const &other)
+{
+ ExprWithBlock::operator= (other);
+ // statements = other.statements;
+ expr = other.expr->clone_expr ();
+ inner_attrs = other.inner_attrs;
+ start_locus = other.end_locus;
+ end_locus = other.end_locus;
+ // outer_attrs = other.outer_attrs;
+
+ statements.reserve (other.statements.size ());
+ for (const auto &e : other.statements)
+ statements.push_back (e->clone_stmt ());
+
+ return *this;
+}
+
+ContinueExpr::ContinueExpr (Analysis::NodeMapping mappings, location_t locus,
+ Lifetime label, AST::AttrVec outer_attribs)
+ : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
+ label (std::move (label)), locus (locus)
+{}
+
+BreakExpr::BreakExpr (Analysis::NodeMapping mappings, location_t locus,
+ Lifetime break_label, std::unique_ptr<Expr> expr_in_break,
+ AST::AttrVec outer_attribs)
+ : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
+ label (std::move (break_label)), break_expr (std::move (expr_in_break)),
+ locus (locus)
+{}
+
+BreakExpr::BreakExpr (BreakExpr const &other)
+ : ExprWithoutBlock (other), label (other.label), locus (other.locus)
+{
+ // guard to protect from null pointer dereference
+ if (other.break_expr != nullptr)
+ break_expr = other.break_expr->clone_expr ();
+}
+
+BreakExpr &
+BreakExpr::operator= (BreakExpr const &other)
+{
+ ExprWithoutBlock::operator= (other);
+ label = other.label;
+ break_expr = other.break_expr->clone_expr ();
+ locus = other.locus;
+ // outer_attrs = other.outer_attrs;
+
+ return *this;
+}
+
+RangeExpr::RangeExpr (Analysis::NodeMapping mappings, location_t locus)
+ : ExprWithoutBlock (std::move (mappings), AST::AttrVec ()), locus (locus)
+{}
+
+RangeFromToExpr::RangeFromToExpr (Analysis::NodeMapping mappings,
+ std::unique_ptr<Expr> range_from,
+ std::unique_ptr<Expr> range_to,
+ location_t locus)
+ : RangeExpr (std::move (mappings), locus), from (std::move (range_from)),
+ to (std::move (range_to))
+{}
+
+RangeFromToExpr::RangeFromToExpr (RangeFromToExpr const &other)
+ : RangeExpr (other), from (other.from->clone_expr ()),
+ to (other.to->clone_expr ())
+{}
+
+RangeFromToExpr &
+RangeFromToExpr::operator= (RangeFromToExpr const &other)
+{
+ RangeExpr::operator= (other);
+ from = other.from->clone_expr ();
+ to = other.to->clone_expr ();
+
+ return *this;
+}
+
+RangeFromExpr::RangeFromExpr (Analysis::NodeMapping mappings,
+ std::unique_ptr<Expr> range_from,
+ location_t locus)
+ : RangeExpr (std::move (mappings), locus), from (std::move (range_from))
+{}
+
+RangeFromExpr::RangeFromExpr (RangeFromExpr const &other)
+ : RangeExpr (other), from (other.from->clone_expr ())
+{}
+
+RangeFromExpr &
+RangeFromExpr::operator= (RangeFromExpr const &other)
+{
+ RangeExpr::operator= (other);
+ from = other.from->clone_expr ();
+
+ return *this;
+}
+
+RangeToExpr::RangeToExpr (Analysis::NodeMapping mappings,
+ std::unique_ptr<Expr> range_to, location_t locus)
+ : RangeExpr (std::move (mappings), locus), to (std::move (range_to))
+{}
+
+RangeToExpr::RangeToExpr (RangeToExpr const &other)
+ : RangeExpr (other), to (other.to->clone_expr ())
+{}
+
+RangeToExpr &
+RangeToExpr::operator= (RangeToExpr const &other)
+{
+ RangeExpr::operator= (other);
+ to = other.to->clone_expr ();
+
+ return *this;
+}
+
+RangeFullExpr::RangeFullExpr (Analysis::NodeMapping mappings, location_t locus)
+ : RangeExpr (std::move (mappings), locus)
+{}
+
+RangeFromToInclExpr::RangeFromToInclExpr (Analysis::NodeMapping mappings,
+ std::unique_ptr<Expr> range_from,
+ std::unique_ptr<Expr> range_to,
+ location_t locus)
+ : RangeExpr (std::move (mappings), locus), from (std::move (range_from)),
+ to (std::move (range_to))
+{}
+
+RangeFromToInclExpr::RangeFromToInclExpr (RangeFromToInclExpr const &other)
+ : RangeExpr (other), from (other.from->clone_expr ()),
+ to (other.to->clone_expr ())
+{}
+
+RangeFromToInclExpr &
+RangeFromToInclExpr::operator= (RangeFromToInclExpr const &other)
+{
+ RangeExpr::operator= (other);
+ from = other.from->clone_expr ();
+ to = other.to->clone_expr ();
+
+ return *this;
+}
+
+RangeToInclExpr::RangeToInclExpr (Analysis::NodeMapping mappings,
+ std::unique_ptr<Expr> range_to,
+ location_t locus)
+ : RangeExpr (std::move (mappings), locus), to (std::move (range_to))
+{}
+
+RangeToInclExpr::RangeToInclExpr (RangeToInclExpr const &other)
+ : RangeExpr (other), to (other.to->clone_expr ())
+{}
+
+RangeToInclExpr &
+RangeToInclExpr::operator= (RangeToInclExpr const &other)
+{
+ RangeExpr::operator= (other);
+ to = other.to->clone_expr ();
+
+ return *this;
+}
+
+ReturnExpr::ReturnExpr (Analysis::NodeMapping mappings, location_t locus,
+ std::unique_ptr<Expr> returned_expr,
+ AST::AttrVec outer_attribs)
+ : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
+ return_expr (std::move (returned_expr)), locus (locus)
+{}
+
+ReturnExpr::ReturnExpr (ReturnExpr const &other)
+ : ExprWithoutBlock (other), locus (other.locus)
+{
+ // guard to protect from null pointer dereference
+ if (other.return_expr != nullptr)
+ return_expr = other.return_expr->clone_expr ();
+}
+
+ReturnExpr &
+ReturnExpr::operator= (ReturnExpr const &other)
+{
+ ExprWithoutBlock::operator= (other);
+ return_expr = other.return_expr->clone_expr ();
+ locus = other.locus;
+ // outer_attrs = other.outer_attrs;
+
+ return *this;
+}
+
+UnsafeBlockExpr::UnsafeBlockExpr (Analysis::NodeMapping mappings,
+ std::unique_ptr<BlockExpr> block_expr,
+ AST::AttrVec outer_attribs, location_t locus)
+ : ExprWithBlock (std::move (mappings), std::move (outer_attribs)),
+ expr (std::move (block_expr)), locus (locus)
+{}
+
+UnsafeBlockExpr::UnsafeBlockExpr (UnsafeBlockExpr const &other)
+ : ExprWithBlock (other), expr (other.expr->clone_block_expr ()),
+ locus (other.locus)
+{}
+
+UnsafeBlockExpr &
+UnsafeBlockExpr::operator= (UnsafeBlockExpr const &other)
+{
+ ExprWithBlock::operator= (other);
+ expr = other.expr->clone_block_expr ();
+ locus = other.locus;
+ // outer_attrs = other.outer_attrs;
+
+ return *this;
+}
+
+BaseLoopExpr::BaseLoopExpr (Analysis::NodeMapping mappings,
+ std::unique_ptr<BlockExpr> loop_block,
+ location_t locus, LoopLabel loop_label,
+ AST::AttrVec outer_attribs)
+ : ExprWithBlock (std::move (mappings), std::move (outer_attribs)),
+ loop_label (std::move (loop_label)), loop_block (std::move (loop_block)),
+ locus (locus)
+{}
+
+BaseLoopExpr::BaseLoopExpr (BaseLoopExpr const &other)
+ : ExprWithBlock (other), loop_label (other.loop_label),
+ loop_block (other.loop_block->clone_block_expr ()), locus (other.locus)
+{}
+
+BaseLoopExpr &
+BaseLoopExpr::operator= (BaseLoopExpr const &other)
+{
+ ExprWithBlock::operator= (other);
+ loop_block = other.loop_block->clone_block_expr ();
+ loop_label = other.loop_label;
+ locus = other.locus;
+ // outer_attrs = other.outer_attrs;
+
+ return *this;
+}
+
+LoopExpr::LoopExpr (Analysis::NodeMapping mappings,
+ std::unique_ptr<BlockExpr> loop_block, location_t locus,
+ LoopLabel loop_label, AST::AttrVec outer_attribs)
+ : BaseLoopExpr (std::move (mappings), std::move (loop_block), locus,
+ std::move (loop_label), std::move (outer_attribs))
+{}
+
+WhileLoopExpr::WhileLoopExpr (Analysis::NodeMapping mappings,
+ std::unique_ptr<Expr> loop_condition,
+ std::unique_ptr<BlockExpr> loop_block,
+ location_t locus, LoopLabel loop_label,
+ AST::AttrVec outer_attribs)
+ : BaseLoopExpr (std::move (mappings), std::move (loop_block), locus,
+ std::move (loop_label), std::move (outer_attribs)),
+ condition (std::move (loop_condition))
+{}
+
+WhileLoopExpr::WhileLoopExpr (WhileLoopExpr const &other)
+ : BaseLoopExpr (other), condition (other.condition->clone_expr ())
+{}
+
+WhileLoopExpr &
+WhileLoopExpr::operator= (WhileLoopExpr const &other)
+{
+ BaseLoopExpr::operator= (other);
+ condition = other.condition->clone_expr ();
+ // loop_block = other.loop_block->clone_block_expr();
+ // loop_label = other.loop_label;
+ // outer_attrs = other.outer_attrs;
+
+ return *this;
+}
+
+WhileLetLoopExpr::WhileLetLoopExpr (
+ Analysis::NodeMapping mappings,
+ std::vector<std::unique_ptr<Pattern>> match_arm_patterns,
+ std::unique_ptr<Expr> condition, std::unique_ptr<BlockExpr> loop_block,
+ location_t locus, LoopLabel loop_label, AST::AttrVec outer_attribs)
+ : BaseLoopExpr (std::move (mappings), std::move (loop_block), locus,
+ std::move (loop_label), std::move (outer_attribs)),
+ match_arm_patterns (std::move (match_arm_patterns)),
+ condition (std::move (condition))
+{}
+
+WhileLetLoopExpr::WhileLetLoopExpr (WhileLetLoopExpr const &other)
+ : BaseLoopExpr (other),
+ /*match_arm_patterns(other.match_arm_patterns),*/ condition (
+ other.condition->clone_expr ())
+{
+ match_arm_patterns.reserve (other.match_arm_patterns.size ());
+ for (const auto &e : other.match_arm_patterns)
+ match_arm_patterns.push_back (e->clone_pattern ());
+}
+
+WhileLetLoopExpr &
+WhileLetLoopExpr::operator= (WhileLetLoopExpr const &other)
+{
+ BaseLoopExpr::operator= (other);
+ // match_arm_patterns = other.match_arm_patterns;
+ condition = other.condition->clone_expr ();
+ // loop_block = other.loop_block->clone_block_expr();
+ // loop_label = other.loop_label;
+ // outer_attrs = other.outer_attrs;
+
+ match_arm_patterns.reserve (other.match_arm_patterns.size ());
+ for (const auto &e : other.match_arm_patterns)
+ match_arm_patterns.push_back (e->clone_pattern ());
+
+ return *this;
+}
+
+IfExpr::IfExpr (Analysis::NodeMapping mappings, std::unique_ptr<Expr> condition,
+ std::unique_ptr<BlockExpr> if_block, location_t locus)
+ : ExprWithBlock (std::move (mappings), AST::AttrVec ()),
+ condition (std::move (condition)), if_block (std::move (if_block)),
+ locus (locus)
+{}
+
+IfExpr::IfExpr (IfExpr const &other)
+ : ExprWithBlock (other), condition (other.condition->clone_expr ()),
+ if_block (other.if_block->clone_block_expr ()), locus (other.locus)
+{}
+
+IfExpr &
+IfExpr::operator= (IfExpr const &other)
+{
+ ExprWithBlock::operator= (other);
+ condition = other.condition->clone_expr ();
+ if_block = other.if_block->clone_block_expr ();
+ locus = other.locus;
+
+ return *this;
+}
+
+IfExprConseqElse::IfExprConseqElse (Analysis::NodeMapping mappings,
+ std::unique_ptr<Expr> condition,
+ std::unique_ptr<BlockExpr> if_block,
+ std::unique_ptr<ExprWithBlock> else_block,
+ location_t locus)
+ : IfExpr (std::move (mappings), std::move (condition), std::move (if_block),
+ locus),
+ else_block (std::move (else_block))
+{}
+
+IfExprConseqElse::IfExprConseqElse (IfExprConseqElse const &other)
+ : IfExpr (other), else_block (other.else_block->clone_expr_with_block ())
+{}
+
+IfExprConseqElse &
+IfExprConseqElse::operator= (IfExprConseqElse const &other)
+{
+ IfExpr::operator= (other);
+ // condition = other.condition->clone_expr();
+ // if_block = other.if_block->clone_block_expr();
+ else_block = other.else_block->clone_expr_with_block ();
+
+ return *this;
+}
+
+MatchArm::MatchArm (std::vector<std::unique_ptr<Pattern>> match_arm_patterns,
+ location_t locus, std::unique_ptr<Expr> guard_expr,
+ AST::AttrVec outer_attrs)
+ : outer_attrs (std::move (outer_attrs)),
+ match_arm_patterns (std::move (match_arm_patterns)),
+ guard_expr (std::move (guard_expr)), locus (locus)
+{}
+
+MatchArm::MatchArm (MatchArm const &other) : outer_attrs (other.outer_attrs)
+{
+ // guard to protect from null pointer dereference
+ if (other.guard_expr != nullptr)
+ guard_expr = other.guard_expr->clone_expr ();
+
+ match_arm_patterns.reserve (other.match_arm_patterns.size ());
+ for (const auto &e : other.match_arm_patterns)
+ match_arm_patterns.push_back (e->clone_pattern ());
+
+ locus = other.locus;
+}
+
+MatchArm &
+MatchArm::operator= (MatchArm const &other)
+{
+ outer_attrs = other.outer_attrs;
+
+ if (other.guard_expr != nullptr)
+ guard_expr = other.guard_expr->clone_expr ();
+
+ match_arm_patterns.clear ();
+ match_arm_patterns.reserve (other.match_arm_patterns.size ());
+ for (const auto &e : other.match_arm_patterns)
+ match_arm_patterns.push_back (e->clone_pattern ());
+
+ return *this;
+}
+
+MatchCase::MatchCase (Analysis::NodeMapping mappings, MatchArm arm,
+ std::unique_ptr<Expr> expr)
+ : mappings (mappings), arm (std::move (arm)), expr (std::move (expr))
+{}
+
+MatchCase::MatchCase (const MatchCase &other)
+ : mappings (other.mappings), arm (other.arm), expr (other.expr->clone_expr ())
+{}
+
+MatchCase &
+MatchCase::operator= (const MatchCase &other)
+{
+ mappings = other.mappings;
+ arm = other.arm;
+ expr = other.expr->clone_expr ();
+
+ return *this;
+}
+
+MatchExpr::MatchExpr (Analysis::NodeMapping mappings,
+ std::unique_ptr<Expr> branch_value,
+ std::vector<MatchCase> match_arms,
+ AST::AttrVec inner_attrs, AST::AttrVec outer_attrs,
+ location_t locus)
+ : ExprWithBlock (std::move (mappings), std::move (outer_attrs)),
+ WithInnerAttrs (std::move (inner_attrs)),
+ branch_value (std::move (branch_value)),
+ match_arms (std::move (match_arms)), locus (locus)
+{}
+
+MatchExpr::MatchExpr (MatchExpr const &other)
+ : ExprWithBlock (other), WithInnerAttrs (other.inner_attrs),
+ branch_value (other.branch_value->clone_expr ()),
+ match_arms (other.match_arms), locus (other.locus)
+{
+ /*match_arms.reserve (other.match_arms.size ());
+ for (const auto &e : other.match_arms)
+ match_arms.push_back (e->clone_match_case ());*/
+}
+
+MatchExpr &
+MatchExpr::operator= (MatchExpr const &other)
+{
+ ExprWithBlock::operator= (other);
+ branch_value = other.branch_value->clone_expr ();
+ inner_attrs = other.inner_attrs;
+ match_arms = other.match_arms;
+ // outer_attrs = other.outer_attrs;
+ locus = other.locus;
+
+ /*match_arms.reserve (other.match_arms.size ());
+ for (const auto &e : other.match_arms)
+ match_arms.push_back (e->clone_match_case ());*/
+
+ return *this;
+}
+
+AwaitExpr::AwaitExpr (Analysis::NodeMapping mappings,
+ std::unique_ptr<Expr> awaited_expr,
+ AST::AttrVec outer_attrs, location_t locus)
+ : ExprWithoutBlock (std::move (mappings), std::move (outer_attrs)),
+ awaited_expr (std::move (awaited_expr)), locus (locus)
+{}
+
+AwaitExpr::AwaitExpr (AwaitExpr const &other)
+ : ExprWithoutBlock (other), awaited_expr (other.awaited_expr->clone_expr ()),
+ locus (other.locus)
+{}
+
+AwaitExpr &
+AwaitExpr::operator= (AwaitExpr const &other)
+{
+ ExprWithoutBlock::operator= (other);
+ awaited_expr = other.awaited_expr->clone_expr ();
+ locus = other.locus;
+
+ return *this;
+}
+
+AsyncBlockExpr::AsyncBlockExpr (Analysis::NodeMapping mappings,
+ std::unique_ptr<BlockExpr> block_expr,
+ bool has_move, AST::AttrVec outer_attrs,
+ location_t locus)
+ : ExprWithBlock (std::move (mappings), std::move (outer_attrs)),
+ has_move (has_move), block_expr (std::move (block_expr)), locus (locus)
+{}
+
+AsyncBlockExpr::AsyncBlockExpr (AsyncBlockExpr const &other)
+ : ExprWithBlock (other), has_move (other.has_move),
+ block_expr (other.block_expr->clone_block_expr ()), locus (other.locus)
+{}
+
+AsyncBlockExpr &
+AsyncBlockExpr::operator= (AsyncBlockExpr const &other)
+{
+ ExprWithBlock::operator= (other);
+ has_move = other.has_move;
+ block_expr = other.block_expr->clone_block_expr ();
+ locus = other.locus;
+
+ return *this;
+}
+
+OperatorExprMeta::OperatorExprMeta (HIR::CompoundAssignmentExpr &expr)
+ : node_mappings (expr.get_mappings ()),
+ lvalue_mappings (expr.get_expr ().get_mappings ()),
+ locus (expr.get_locus ())
+{}
+
+OperatorExprMeta::OperatorExprMeta (HIR::ArithmeticOrLogicalExpr &expr)
+ : node_mappings (expr.get_mappings ()),
+ lvalue_mappings (expr.get_expr ().get_mappings ()),
+ locus (expr.get_locus ())
+{}
+
+OperatorExprMeta::OperatorExprMeta (HIR::NegationExpr &expr)
+ : node_mappings (expr.get_mappings ()),
+ lvalue_mappings (expr.get_expr ().get_mappings ()),
+ locus (expr.get_locus ())
+{}
+
+OperatorExprMeta::OperatorExprMeta (HIR::DereferenceExpr &expr)
+ : node_mappings (expr.get_mappings ()),
+ lvalue_mappings (expr.get_expr ().get_mappings ()),
+ locus (expr.get_locus ())
+{}
+
+OperatorExprMeta::OperatorExprMeta (HIR::ArrayIndexExpr &expr)
+ : node_mappings (expr.get_mappings ()),
+ lvalue_mappings (expr.get_array_expr ().get_mappings ()),
+ locus (expr.get_locus ())
+{}
+
+AnonConst::AnonConst (NodeId id, std::unique_ptr<Expr> expr)
+ : id (id), expr (std::move (expr))
+{
+ rust_assert (this->expr != nullptr);
+}
+
+AnonConst::AnonConst (const AnonConst &other)
+{
+ id = other.id;
+ expr = other.expr->clone_expr ();
+}
+
+AnonConst
+AnonConst::operator= (const AnonConst &other)
+{
+ id = other.id;
+ expr = other.expr->clone_expr ();
+ return *this;
+}
+
+InlineAsmOperand::In::In (
+ const tl::optional<struct AST::InlineAsmRegOrRegClass> ®,
+ std::unique_ptr<Expr> expr)
+ : reg (reg), expr (std::move (expr))
+{
+ rust_assert (this->expr != nullptr);
+}
+
+InlineAsmOperand::In::In (const struct In &other)
+{
+ reg = other.reg;
+
+ expr = other.expr->clone_expr ();
+}
+
+InlineAsmOperand::In
+InlineAsmOperand::In::operator= (const struct In &other)
+{
+ reg = other.reg;
+ expr = other.expr->clone_expr ();
+
+ return *this;
+}
+
+InlineAsmOperand::Out::Out (
+ tl::optional<struct AST::InlineAsmRegOrRegClass> ®, bool late,
+ std::unique_ptr<Expr> expr)
+ : reg (reg), late (late), expr (std::move (expr))
+{
+ rust_assert (this->expr != nullptr);
+}
+
+InlineAsmOperand::Out::Out (const struct Out &other)
+{
+ reg = other.reg;
+ late = other.late;
+ expr = other.expr->clone_expr ();
+}
+
+InlineAsmOperand::Out
+InlineAsmOperand::Out::operator= (const struct Out &other)
+{
+ reg = other.reg;
+ late = other.late;
+ expr = other.expr->clone_expr ();
+ return *this;
+}
+
+InlineAsmOperand::InOut::InOut (
+ tl::optional<struct AST::InlineAsmRegOrRegClass> ®, bool late,
+ std::unique_ptr<Expr> expr)
+ : reg (reg), late (late), expr (std::move (expr))
+{
+ rust_assert (this->expr != nullptr);
+}
+
+InlineAsmOperand::InOut::InOut (const struct InOut &other)
+{
+ reg = other.reg;
+ late = other.late;
+ expr = other.expr->clone_expr ();
+}
+
+InlineAsmOperand::InOut
+InlineAsmOperand::InOut::operator= (const struct InOut &other)
+{
+ reg = other.reg;
+ late = other.late;
+ expr = other.expr->clone_expr ();
+
+ return *this;
+}
+
+InlineAsmOperand::SplitInOut::SplitInOut (
+ tl::optional<struct AST::InlineAsmRegOrRegClass> ®, bool late,
+ std::unique_ptr<Expr> in_expr, std::unique_ptr<Expr> out_expr)
+ : reg (reg), late (late), in_expr (std::move (in_expr)),
+ out_expr (std::move (out_expr))
+{
+ rust_assert (this->in_expr != nullptr);
+ rust_assert (this->out_expr != nullptr);
+}
+
+InlineAsmOperand::SplitInOut::SplitInOut (const struct SplitInOut &other)
+{
+ reg = other.reg;
+ late = other.late;
+ in_expr = other.in_expr->clone_expr ();
+ out_expr = other.out_expr->clone_expr ();
+}
+
+InlineAsmOperand::SplitInOut
+InlineAsmOperand::SplitInOut::operator= (const struct SplitInOut &other)
+{
+ reg = other.reg;
+ late = other.late;
+ in_expr = other.in_expr->clone_expr ();
+ out_expr = other.out_expr->clone_expr ();
+
+ return *this;
+}
+
+InlineAsmOperand::Sym::Sym (std::unique_ptr<Expr> expr)
+ : expr (std::move (expr))
+{
+ rust_assert (this->expr != nullptr);
+}
+
+InlineAsmOperand::Sym::Sym (const struct Sym &other)
+{
+ expr = std::unique_ptr<Expr> (other.expr->clone_expr ());
+}
+
+InlineAsmOperand::Sym
+InlineAsmOperand::Sym::operator= (const struct Sym &other)
+{
+ expr = std::unique_ptr<Expr> (other.expr->clone_expr ());
+ return *this;
+}
+
+InlineAsmOperand::Label::Label (tl::optional<std::string> label_name,
+ std::unique_ptr<Expr> expr)
+ : expr (std::move (expr))
+{
+ rust_assert (this->expr != nullptr);
+ if (label_name.has_value ())
+ this->label_name = label_name.value ();
+}
+
+InlineAsmOperand::Label::Label (const struct Label &other)
+{
+ expr = std::unique_ptr<Expr> (other.expr->clone_expr ());
+}
+
+InlineAsmOperand::Label
+InlineAsmOperand::Label::operator= (const struct Label &other)
+{
+ expr = std::unique_ptr<Expr> (other.expr->clone_expr ());
+ return *this;
+}
+
+InlineAsm::InlineAsm (location_t locus, bool is_global_asm,
+ std::vector<AST::InlineAsmTemplatePiece> template_,
+ std::vector<AST::TupleTemplateStr> template_strs,
+ std::vector<HIR::InlineAsmOperand> operands,
+ std::vector<AST::TupleClobber> clobber_abi,
+ std::set<AST::InlineAsmOption> options,
+ Analysis::NodeMapping mappings,
+ AST::AttrVec outer_attribs)
+ : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
+ locus (locus), is_global_asm (is_global_asm),
+ template_ (std::move (template_)),
+ template_strs (std::move (template_strs)), operands (std::move (operands)),
+ clobber_abi (std::move (clobber_abi)), options (std::move (options))
+{}
+
+} // namespace HIR
+} // namespace Rust
diff --git a/gcc/rust/hir/tree/rust-hir-expr.h b/gcc/rust/hir/tree/rust-hir-expr.h
index c66b549a4d4..1273466b74c 100644
--- a/gcc/rust/hir/tree/rust-hir-expr.h
+++ b/gcc/rust/hir/tree/rust-hir-expr.h
@@ -19,12 +19,13 @@
#ifndef RUST_HIR_EXPR_H
#define RUST_HIR_EXPR_H
+#include "rust-hir-expr-abstract.h"
+#include "rust-hir-literal.h"
#include "rust-common.h"
-#include "rust-ast-full-decls.h"
-#include "rust-hir.h"
-#include "rust-hir-path.h"
-#include "rust-operators.h"
+#include "rust-hir-bound.h"
+#include "rust-hir-attrs.h"
#include "rust-expr.h"
+
namespace Rust {
namespace HIR {
@@ -42,9 +43,7 @@ public:
std::string as_string () const;
LoopLabel (Analysis::NodeMapping mapping, Lifetime loop_label,
- location_t locus)
- : label (std::move (loop_label)), locus (locus), mappings (mapping)
- {}
+ location_t locus);
// Returns whether the LoopLabel is in an error state.
bool is_error () const { return label.is_error (); }
@@ -62,9 +61,7 @@ class ExprWithBlock : public Expr
// TODO: should this mean that a BlockExpr should be a member variable?
protected:
ExprWithBlock (Analysis::NodeMapping mappings,
- AST::AttrVec outer_attrs = AST::AttrVec ())
- : Expr (std::move (mappings), std::move (outer_attrs))
- {}
+ AST::AttrVec outer_attrs = AST::AttrVec ());
// pure virtual clone implementation
virtual ExprWithBlock *clone_expr_with_block_impl () const = 0;
@@ -106,16 +103,10 @@ public:
LiteralExpr (Analysis::NodeMapping mappings, std::string value_as_string,
Literal::LitType type, PrimitiveCoreType type_hint,
- location_t locus, AST::AttrVec outer_attrs)
- : ExprWithoutBlock (std::move (mappings), std::move (outer_attrs)),
- literal (std::move (value_as_string), type, type_hint), locus (locus)
- {}
+ location_t locus, AST::AttrVec outer_attrs);
LiteralExpr (Analysis::NodeMapping mappings, Literal literal,
- location_t locus, AST::AttrVec outer_attrs)
- : ExprWithoutBlock (std::move (mappings), std::move (outer_attrs)),
- literal (std::move (literal)), locus (locus)
- {}
+ location_t locus, AST::AttrVec outer_attrs);
// Unique pointer custom clone function
std::unique_ptr<LiteralExpr> clone_literal_expr () const
@@ -180,27 +171,13 @@ protected:
// Constructor (only for initialisation of expr purposes)
OperatorExpr (Analysis::NodeMapping mappings,
std::unique_ptr<Expr> main_or_left_expr,
- AST::AttrVec outer_attribs, location_t locus)
- : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
- locus (locus), main_or_left_expr (std::move (main_or_left_expr))
- {}
+ AST::AttrVec outer_attribs, location_t locus);
// Copy constructor (only for initialisation of expr purposes)
- OperatorExpr (OperatorExpr const &other)
- : ExprWithoutBlock (other), locus (other.locus),
- main_or_left_expr (other.main_or_left_expr->clone_expr ())
- {}
+ OperatorExpr (OperatorExpr const &other);
// Overload assignment operator to deep copy expr
- OperatorExpr &operator= (OperatorExpr const &other)
- {
- ExprWithoutBlock::operator= (other);
- main_or_left_expr = other.main_or_left_expr->clone_expr ();
- locus = other.locus;
- // outer_attrs = other.outer_attrs;
-
- return *this;
- }
+ OperatorExpr &operator= (OperatorExpr const &other);
// move constructors
OperatorExpr (OperatorExpr &&other) = default;
@@ -228,11 +205,7 @@ public:
BorrowExpr (Analysis::NodeMapping mappings,
std::unique_ptr<Expr> borrow_lvalue, Mutability mut,
- AST::AttrVec outer_attribs, location_t locus)
- : OperatorExpr (std::move (mappings), std::move (borrow_lvalue),
- std::move (outer_attribs), locus),
- mut (mut)
- {}
+ AST::AttrVec outer_attribs, location_t locus);
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRExpressionVisitor &vis) override;
@@ -265,10 +238,7 @@ public:
// Constructor calls OperatorExpr's protected constructor
DereferenceExpr (Analysis::NodeMapping mappings,
std::unique_ptr<Expr> deref_lvalue,
- AST::AttrVec outer_attribs, location_t locus)
- : OperatorExpr (std::move (mappings), std::move (deref_lvalue),
- std::move (outer_attribs), locus)
- {}
+ AST::AttrVec outer_attribs, location_t locus);
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRExpressionVisitor &vis) override;
@@ -298,10 +268,7 @@ public:
// Constructor calls OperatorExpr's protected constructor
ErrorPropagationExpr (Analysis::NodeMapping mappings,
std::unique_ptr<Expr> potential_error_value,
- AST::AttrVec outer_attribs, location_t locus)
- : OperatorExpr (std::move (mappings), std::move (potential_error_value),
- std::move (outer_attribs), locus)
- {}
+ AST::AttrVec outer_attribs, location_t locus);
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRExpressionVisitor &vis) override;
@@ -342,11 +309,7 @@ public:
// Constructor calls OperatorExpr's protected constructor
NegationExpr (Analysis::NodeMapping mappings,
std::unique_ptr<Expr> negated_value, ExprType expr_kind,
- AST::AttrVec outer_attribs, location_t locus)
- : OperatorExpr (std::move (mappings), std::move (negated_value),
- std::move (outer_attribs), locus),
- expr_type (expr_kind)
- {}
+ AST::AttrVec outer_attribs, location_t locus);
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRExpressionVisitor &vis) override;
@@ -388,29 +351,14 @@ public:
ArithmeticOrLogicalExpr (Analysis::NodeMapping mappings,
std::unique_ptr<Expr> left_value,
std::unique_ptr<Expr> right_value,
- ExprType expr_kind, location_t locus)
- : OperatorExpr (std::move (mappings), std::move (left_value),
- AST::AttrVec (), locus),
- expr_type (expr_kind), right_expr (std::move (right_value))
- {}
+ ExprType expr_kind, location_t locus);
// outer attributes not allowed
// Copy constructor - probably required due to unique pointer
- ArithmeticOrLogicalExpr (ArithmeticOrLogicalExpr const &other)
- : OperatorExpr (other), expr_type (other.expr_type),
- right_expr (other.right_expr->clone_expr ())
- {}
+ ArithmeticOrLogicalExpr (ArithmeticOrLogicalExpr const &other);
// Overload assignment operator
- ArithmeticOrLogicalExpr &operator= (ArithmeticOrLogicalExpr const &other)
- {
- OperatorExpr::operator= (other);
- // main_or_left_expr = other.main_or_left_expr->clone_expr();
- right_expr = other.right_expr->clone_expr ();
- expr_type = other.expr_type;
-
- return *this;
- }
+ ArithmeticOrLogicalExpr &operator= (ArithmeticOrLogicalExpr const &other);
// move constructors
ArithmeticOrLogicalExpr (ArithmeticOrLogicalExpr &&other) = default;
@@ -465,30 +413,14 @@ public:
ComparisonExpr (Analysis::NodeMapping mappings,
std::unique_ptr<Expr> left_value,
std::unique_ptr<Expr> right_value, ExprType comparison_kind,
- location_t locus)
- : OperatorExpr (std::move (mappings), std::move (left_value),
- AST::AttrVec (), locus),
- expr_type (comparison_kind), right_expr (std::move (right_value))
- {}
+ location_t locus);
// outer attributes not allowed
// Copy constructor also calls OperatorExpr's protected constructor
- ComparisonExpr (ComparisonExpr const &other)
- : OperatorExpr (other), expr_type (other.expr_type),
- right_expr (other.right_expr->clone_expr ())
- {}
+ ComparisonExpr (ComparisonExpr const &other);
// Overload assignment operator to deep copy
- ComparisonExpr &operator= (ComparisonExpr const &other)
- {
- OperatorExpr::operator= (other);
- // main_or_left_expr = other.main_or_left_expr->clone_expr();
- right_expr = other.right_expr->clone_expr ();
- expr_type = other.expr_type;
- // outer_attrs = other.outer_attrs;
-
- return *this;
- }
+ ComparisonExpr &operator= (ComparisonExpr const &other);
// move constructors
ComparisonExpr (ComparisonExpr &&other) = default;
@@ -536,29 +468,14 @@ public:
LazyBooleanExpr (Analysis::NodeMapping mappings,
std::unique_ptr<Expr> left_bool_expr,
std::unique_ptr<Expr> right_bool_expr, ExprType expr_kind,
- location_t locus)
- : OperatorExpr (std::move (mappings), std::move (left_bool_expr),
- AST::AttrVec (), locus),
- expr_type (expr_kind), right_expr (std::move (right_bool_expr))
- {}
+ location_t locus);
// outer attributes not allowed
// Copy constructor also calls OperatorExpr's protected constructor
- LazyBooleanExpr (LazyBooleanExpr const &other)
- : OperatorExpr (other), expr_type (other.expr_type),
- right_expr (other.right_expr->clone_expr ())
- {}
+ LazyBooleanExpr (LazyBooleanExpr const &other);
// Overload assignment operator to deep copy
- LazyBooleanExpr &operator= (LazyBooleanExpr const &other)
- {
- OperatorExpr::operator= (other);
- // main_or_left_expr = other.main_or_left_expr->clone_expr();
- right_expr = other.right_expr->clone_expr ();
- expr_type = other.expr_type;
-
- return *this;
- }
+ LazyBooleanExpr &operator= (LazyBooleanExpr const &other);
// move constructors
LazyBooleanExpr (LazyBooleanExpr &&other) = default;
@@ -602,28 +519,14 @@ public:
// Constructor requires calling protected constructor of OperatorExpr
TypeCastExpr (Analysis::NodeMapping mappings,
std::unique_ptr<Expr> expr_to_cast,
- std::unique_ptr<Type> type_to_cast_to, location_t locus)
- : OperatorExpr (std::move (mappings), std::move (expr_to_cast),
- AST::AttrVec (), locus),
- type_to_convert_to (std::move (type_to_cast_to))
- {}
+ std::unique_ptr<Type> type_to_cast_to, location_t locus);
// outer attributes not allowed
// Copy constructor also requires calling protected constructor
- TypeCastExpr (TypeCastExpr const &other)
- : OperatorExpr (other),
- type_to_convert_to (other.type_to_convert_to->clone_type ())
- {}
+ TypeCastExpr (TypeCastExpr const &other);
// Overload assignment operator to deep copy
- TypeCastExpr &operator= (TypeCastExpr const &other)
- {
- OperatorExpr::operator= (other);
- // main_or_left_expr = other.main_or_left_expr->clone_expr();
- type_to_convert_to = other.type_to_convert_to->clone_type ();
-
- return *this;
- }
+ TypeCastExpr &operator= (TypeCastExpr const &other);
// move constructors as not supported in c++03
TypeCastExpr (TypeCastExpr &&other) = default;
@@ -664,28 +567,14 @@ public:
// Call OperatorExpr constructor to initialise left_expr
AssignmentExpr (Analysis::NodeMapping mappings,
std::unique_ptr<Expr> value_to_assign_to,
- std::unique_ptr<Expr> value_to_assign, location_t locus)
- : OperatorExpr (std::move (mappings), std::move (value_to_assign_to),
- AST::AttrVec (), locus),
- right_expr (std::move (value_to_assign))
- {}
+ std::unique_ptr<Expr> value_to_assign, location_t locus);
// outer attributes not allowed
// Call OperatorExpr constructor in copy constructor, as well as clone
- AssignmentExpr (AssignmentExpr const &other)
- : OperatorExpr (other), right_expr (other.right_expr->clone_expr ())
- {}
+ AssignmentExpr (AssignmentExpr const &other);
// Overload assignment operator to clone unique_ptr right_expr
- AssignmentExpr &operator= (AssignmentExpr const &other)
- {
- OperatorExpr::operator= (other);
- // main_or_left_expr = other.main_or_left_expr->clone_expr();
- right_expr = other.right_expr->clone_expr ();
- // outer_attrs = other.outer_attrs;
-
- return *this;
- }
+ AssignmentExpr &operator= (AssignmentExpr const &other);
// move constructors
AssignmentExpr (AssignmentExpr &&other) = default;
@@ -735,30 +624,14 @@ public:
CompoundAssignmentExpr (Analysis::NodeMapping mappings,
std::unique_ptr<Expr> value_to_assign_to,
std::unique_ptr<Expr> value_to_assign,
- ExprType expr_kind, location_t locus)
- : OperatorExpr (std::move (mappings), std::move (value_to_assign_to),
- AST::AttrVec (), locus),
- expr_type (expr_kind), right_expr (std::move (value_to_assign))
- {}
+ ExprType expr_kind, location_t locus);
// outer attributes not allowed
// Have clone in copy constructor
- CompoundAssignmentExpr (CompoundAssignmentExpr const &other)
- : OperatorExpr (other), expr_type (other.expr_type),
- right_expr (other.right_expr->clone_expr ())
- {}
+ CompoundAssignmentExpr (CompoundAssignmentExpr const &other);
// Overload assignment operator to clone
- CompoundAssignmentExpr &operator= (CompoundAssignmentExpr const &other)
- {
- OperatorExpr::operator= (other);
- // main_or_left_expr = other.main_or_left_expr->clone_expr();
- right_expr = other.right_expr->clone_expr ();
- expr_type = other.expr_type;
- // outer_attrs = other.outer_attrs;
-
- return *this;
- }
+ CompoundAssignmentExpr &operator= (CompoundAssignmentExpr const &other);
// move constructors
CompoundAssignmentExpr (CompoundAssignmentExpr &&other) = default;
@@ -798,29 +671,13 @@ public:
GroupedExpr (Analysis::NodeMapping mappings,
std::unique_ptr<Expr> parenthesised_expr,
AST::AttrVec inner_attribs, AST::AttrVec outer_attribs,
- location_t locus)
- : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
- WithInnerAttrs (std::move (inner_attribs)),
- expr_in_parens (std::move (parenthesised_expr)), locus (locus)
- {}
+ location_t locus);
// Copy constructor includes clone for expr_in_parens
- GroupedExpr (GroupedExpr const &other)
- : ExprWithoutBlock (other), WithInnerAttrs (other.inner_attrs),
- expr_in_parens (other.expr_in_parens->clone_expr ()), locus (other.locus)
- {}
+ GroupedExpr (GroupedExpr const &other);
// Overloaded assignment operator to clone expr_in_parens
- GroupedExpr &operator= (GroupedExpr const &other)
- {
- ExprWithoutBlock::operator= (other);
- inner_attrs = other.inner_attrs;
- expr_in_parens = other.expr_in_parens->clone_expr ();
- locus = other.locus;
- // outer_attrs = other.outer_attrs;
-
- return *this;
- }
+ GroupedExpr &operator= (GroupedExpr const &other);
// move constructors
GroupedExpr (GroupedExpr &&other) = default;
@@ -893,33 +750,19 @@ protected:
// Value array elements
class ArrayElemsValues : public ArrayElems
{
- std::vector<std::unique_ptr<Expr> > values;
+ std::vector<std::unique_ptr<Expr>> values;
// TODO: should this store location data?
public:
ArrayElemsValues (Analysis::NodeMapping mappings,
- std::vector<std::unique_ptr<Expr> > elems)
- : ArrayElems (mappings), values (std::move (elems))
- {}
+ std::vector<std::unique_ptr<Expr>> elems);
// copy constructor with vector clone
- ArrayElemsValues (ArrayElemsValues const &other) : ArrayElems (other)
- {
- values.reserve (other.values.size ());
- for (const auto &e : other.values)
- values.push_back (e->clone_expr ());
- }
+ ArrayElemsValues (ArrayElemsValues const &other);
// overloaded assignment operator with vector clone
- ArrayElemsValues &operator= (ArrayElemsValues const &other)
- {
- values.reserve (other.values.size ());
- for (const auto &e : other.values)
- values.push_back (e->clone_expr ());
-
- return *this;
- }
+ ArrayElemsValues &operator= (ArrayElemsValues const &other);
// move constructors
ArrayElemsValues (ArrayElemsValues &&other) = default;
@@ -931,7 +774,7 @@ public:
size_t get_num_elements () const { return values.size (); }
- std::vector<std::unique_ptr<Expr> > &get_values () { return values; }
+ std::vector<std::unique_ptr<Expr>> &get_values () { return values; }
ArrayElems::ArrayExprType get_array_expr_type () const override final
{
@@ -955,25 +798,13 @@ public:
// Constructor requires pointers for polymorphism
ArrayElemsCopied (Analysis::NodeMapping mappings,
std::unique_ptr<Expr> copied_elem,
- std::unique_ptr<Expr> copy_amount)
- : ArrayElems (mappings), elem_to_copy (std::move (copied_elem)),
- num_copies (std::move (copy_amount))
- {}
+ std::unique_ptr<Expr> copy_amount);
// Copy constructor required due to unique_ptr - uses custom clone
- ArrayElemsCopied (ArrayElemsCopied const &other)
- : ArrayElems (other), elem_to_copy (other.elem_to_copy->clone_expr ()),
- num_copies (other.num_copies->clone_expr ())
- {}
+ ArrayElemsCopied (ArrayElemsCopied const &other);
// Overloaded assignment operator for deep copying
- ArrayElemsCopied &operator= (ArrayElemsCopied const &other)
- {
- elem_to_copy = other.elem_to_copy->clone_expr ();
- num_copies = other.num_copies->clone_expr ();
-
- return *this;
- }
+ ArrayElemsCopied &operator= (ArrayElemsCopied const &other);
// move constructors
ArrayElemsCopied (ArrayElemsCopied &&other) = default;
@@ -1016,33 +847,13 @@ public:
ArrayExpr (Analysis::NodeMapping mappings,
std::unique_ptr<ArrayElems> array_elems,
AST::AttrVec inner_attribs, AST::AttrVec outer_attribs,
- location_t locus)
- : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
- WithInnerAttrs (std::move (inner_attribs)),
- internal_elements (std::move (array_elems)), locus (locus)
- {}
+ location_t locus);
// Copy constructor requires cloning ArrayElems for polymorphism to hold
- ArrayExpr (ArrayExpr const &other)
- : ExprWithoutBlock (other), WithInnerAttrs (other.inner_attrs),
- locus (other.locus)
- {
- if (other.has_array_elems ())
- internal_elements = other.internal_elements->clone_array_elems ();
- }
+ ArrayExpr (ArrayExpr const &other);
// Overload assignment operator to clone internal_elements
- ArrayExpr &operator= (ArrayExpr const &other)
- {
- ExprWithoutBlock::operator= (other);
- inner_attrs = other.inner_attrs;
- if (other.has_array_elems ())
- internal_elements = other.internal_elements->clone_array_elems ();
- locus = other.locus;
- // outer_attrs = other.outer_attrs;
-
- return *this;
- }
+ ArrayExpr &operator= (ArrayExpr const &other);
// move constructors
ArrayExpr (ArrayExpr &&other) = default;
@@ -1086,29 +897,13 @@ public:
ArrayIndexExpr (Analysis::NodeMapping mappings,
std::unique_ptr<Expr> array_expr,
std::unique_ptr<Expr> array_index_expr,
- AST::AttrVec outer_attribs, location_t locus)
- : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
- array_expr (std::move (array_expr)),
- index_expr (std::move (array_index_expr)), locus (locus)
- {}
+ AST::AttrVec outer_attribs, location_t locus);
// Copy constructor requires special cloning due to unique_ptr
- ArrayIndexExpr (ArrayIndexExpr const &other)
- : ExprWithoutBlock (other), array_expr (other.array_expr->clone_expr ()),
- index_expr (other.index_expr->clone_expr ()), locus (other.locus)
- {}
+ ArrayIndexExpr (ArrayIndexExpr const &other);
// Overload assignment operator to clone unique_ptrs
- ArrayIndexExpr &operator= (ArrayIndexExpr const &other)
- {
- ExprWithoutBlock::operator= (other);
- array_expr = other.array_expr->clone_expr ();
- index_expr = other.index_expr->clone_expr ();
- // outer_attrs = other.outer_attrs;
- locus = other.locus;
-
- return *this;
- }
+ ArrayIndexExpr &operator= (ArrayIndexExpr const &other);
// move constructors
ArrayIndexExpr (ArrayIndexExpr &&other) = default;
@@ -1146,7 +941,7 @@ protected:
// HIR representation of a tuple
class TupleExpr : public ExprWithoutBlock, public WithInnerAttrs
{
- std::vector<std::unique_ptr<Expr> > tuple_elems;
+ std::vector<std::unique_ptr<Expr>> tuple_elems;
// replaces (inlined version of) TupleElements
location_t locus;
@@ -1155,37 +950,15 @@ public:
std::string as_string () const override;
TupleExpr (Analysis::NodeMapping mappings,
- std::vector<std::unique_ptr<Expr> > tuple_elements,
+ std::vector<std::unique_ptr<Expr>> tuple_elements,
AST::AttrVec inner_attribs, AST::AttrVec outer_attribs,
- location_t locus)
- : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
- WithInnerAttrs (std::move (inner_attribs)),
- tuple_elems (std::move (tuple_elements)), locus (locus)
- {}
+ location_t locus);
// copy constructor with vector clone
- TupleExpr (TupleExpr const &other)
- : ExprWithoutBlock (other), WithInnerAttrs (other.inner_attrs),
- locus (other.locus)
- {
- tuple_elems.reserve (other.tuple_elems.size ());
- for (const auto &e : other.tuple_elems)
- tuple_elems.push_back (e->clone_expr ());
- }
+ TupleExpr (TupleExpr const &other);
// overloaded assignment operator to vector clone
- TupleExpr &operator= (TupleExpr const &other)
- {
- ExprWithoutBlock::operator= (other);
- inner_attrs = other.inner_attrs;
- locus = other.locus;
-
- tuple_elems.reserve (other.tuple_elems.size ());
- for (const auto &e : other.tuple_elems)
- tuple_elems.push_back (e->clone_expr ());
-
- return *this;
- }
+ TupleExpr &operator= (TupleExpr const &other);
// move constructors
TupleExpr (TupleExpr &&other) = default;
@@ -1199,14 +972,11 @@ public:
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRExpressionVisitor &vis) override;
- const std::vector<std::unique_ptr<Expr> > &get_tuple_elems () const
- {
- return tuple_elems;
- }
- std::vector<std::unique_ptr<Expr> > &get_tuple_elems ()
+ const std::vector<std::unique_ptr<Expr>> &get_tuple_elems () const
{
return tuple_elems;
}
+ std::vector<std::unique_ptr<Expr>> &get_tuple_elems () { return tuple_elems; }
bool is_unit () const { return tuple_elems.size () == 0; }
@@ -1241,28 +1011,13 @@ public:
TupleIndexExpr (Analysis::NodeMapping mappings,
std::unique_ptr<Expr> tuple_expr, TupleIndex index,
- AST::AttrVec outer_attribs, location_t locus)
- : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
- tuple_expr (std::move (tuple_expr)), tuple_index (index), locus (locus)
- {}
+ AST::AttrVec outer_attribs, location_t locus);
// Copy constructor requires a clone for tuple_expr
- TupleIndexExpr (TupleIndexExpr const &other)
- : ExprWithoutBlock (other), tuple_expr (other.tuple_expr->clone_expr ()),
- tuple_index (other.tuple_index), locus (other.locus)
- {}
+ TupleIndexExpr (TupleIndexExpr const &other);
// Overload assignment operator in order to clone
- TupleIndexExpr &operator= (TupleIndexExpr const &other)
- {
- ExprWithoutBlock::operator= (other);
- tuple_expr = other.tuple_expr->clone_expr ();
- tuple_index = other.tuple_index;
- locus = other.locus;
- // outer_attrs = other.outer_attrs;
-
- return *this;
- }
+ TupleIndexExpr &operator= (TupleIndexExpr const &other);
// move constructors
TupleIndexExpr (TupleIndexExpr &&other) = default;
@@ -1304,10 +1059,7 @@ protected:
// Protected constructor to allow initialising struct_name
StructExpr (Analysis::NodeMapping mappings, PathInExpression struct_path,
- AST::AttrVec outer_attribs)
- : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
- struct_name (std::move (struct_path))
- {}
+ AST::AttrVec outer_attribs);
public:
PathInExpression &get_struct_name () { return struct_name; }
@@ -1331,11 +1083,7 @@ public:
// Constructor has to call protected constructor of base class
StructExprStruct (Analysis::NodeMapping mappings,
PathInExpression struct_path, AST::AttrVec inner_attribs,
- AST::AttrVec outer_attribs, location_t locus)
- : StructExpr (std::move (mappings), std::move (struct_path),
- std::move (outer_attribs)),
- WithInnerAttrs (std::move (inner_attribs)), locus (locus)
- {}
+ AST::AttrVec outer_attribs, location_t locus);
location_t get_locus () const override final { return locus; }
@@ -1362,33 +1110,21 @@ protected:
* struct */
struct StructBase
{
-public:
+private:
std::unique_ptr<Expr> base_struct;
+public:
// TODO: should this store location data?
- StructBase (std::unique_ptr<Expr> base_struct_ptr)
- : base_struct (std::move (base_struct_ptr))
- {}
+ StructBase (std::unique_ptr<Expr> base_struct_ptr);
// Copy constructor requires clone
- StructBase (StructBase const &other)
- {
- /* HACK: gets around base_struct pointer being null (e.g. if no struct base
- * exists) */
- if (other.base_struct != nullptr)
- other.base_struct->clone_expr ();
- }
+ StructBase (StructBase const &other);
// Destructor
~StructBase () = default;
// Overload assignment operator to clone base_struct
- StructBase &operator= (StructBase const &other)
- {
- base_struct = other.base_struct->clone_expr ();
-
- return *this;
- }
+ StructBase &operator= (StructBase const &other);
// move constructors
StructBase (StructBase &&other) = default;
@@ -1402,7 +1138,7 @@ public:
std::string as_string () const;
- Expr *get_base () { return base_struct.get (); }
+ Expr &get_base () { return *base_struct; }
};
/* Base HIR node for a single struct expression field (in struct instance
@@ -1440,9 +1176,7 @@ protected:
// pure virtual clone implementation
virtual StructExprField *clone_struct_expr_field_impl () const = 0;
- StructExprField (Analysis::NodeMapping mapping, location_t locus)
- : mappings (mapping), locus (locus)
- {}
+ StructExprField (Analysis::NodeMapping mapping, location_t locus);
Analysis::NodeMapping mappings;
location_t locus;
@@ -1457,10 +1191,7 @@ private:
// TODO: should this store location data?
public:
StructExprFieldIdentifier (Analysis::NodeMapping mapping,
- Identifier field_identifier, location_t locus)
- : StructExprField (mapping, locus),
- field_name (std::move (field_identifier))
- {}
+ Identifier field_identifier, location_t locus);
std::string as_string () const override { return field_name.as_string (); }
@@ -1491,25 +1222,13 @@ class StructExprFieldWithVal : public StructExprField
protected:
StructExprFieldWithVal (Analysis::NodeMapping mapping,
- std::unique_ptr<Expr> field_value, location_t locus)
- : StructExprField (mapping, locus), value (std::move (field_value))
- {}
+ std::unique_ptr<Expr> field_value, location_t locus);
// Copy constructor requires clone
- StructExprFieldWithVal (StructExprFieldWithVal const &other)
- : StructExprField (other.mappings, other.locus),
- value (other.value->clone_expr ())
- {}
+ StructExprFieldWithVal (StructExprFieldWithVal const &other);
// Overload assignment operator to clone unique_ptr
- StructExprFieldWithVal &operator= (StructExprFieldWithVal const &other)
- {
- value = other.value->clone_expr ();
- mappings = other.mappings;
- locus = other.locus;
-
- return *this;
- }
+ StructExprFieldWithVal &operator= (StructExprFieldWithVal const &other);
// move constructors
StructExprFieldWithVal (StructExprFieldWithVal &&other) = default;
@@ -1532,10 +1251,7 @@ public:
StructExprFieldIdentifierValue (Analysis::NodeMapping mapping,
Identifier field_identifier,
std::unique_ptr<Expr> field_value,
- location_t locus)
- : StructExprFieldWithVal (mapping, std::move (field_value), locus),
- field_name (std::move (field_identifier))
- {}
+ location_t locus);
std::string as_string () const override;
@@ -1569,10 +1285,7 @@ public:
StructExprFieldIndexValue (Analysis::NodeMapping mapping,
TupleIndex tuple_index,
std::unique_ptr<Expr> field_value,
- location_t locus)
- : StructExprFieldWithVal (mapping, std::move (field_value), locus),
- index (tuple_index)
- {}
+ location_t locus);
std::string as_string () const override;
@@ -1598,58 +1311,31 @@ protected:
// HIR node of a struct creator with fields
class StructExprStructFields : public StructExprStruct
{
-public:
// std::vector<StructExprField> fields;
- std::vector<std::unique_ptr<StructExprField> > fields;
-
- // bool has_struct_base;
- // FIXME make unique_ptr
- StructBase *struct_base;
+ std::vector<std::unique_ptr<StructExprField>> fields;
+ tl::optional<std::unique_ptr<StructBase>> struct_base;
+public:
// For unions there is just one field, the index
// is set when type checking
int union_index = -1;
std::string as_string () const override;
- bool has_struct_base () const { return struct_base != nullptr; }
+ bool has_struct_base () const { return struct_base.has_value (); }
// Constructor for StructExprStructFields when no struct base is used
StructExprStructFields (
Analysis::NodeMapping mappings, PathInExpression struct_path,
- std::vector<std::unique_ptr<StructExprField> > expr_fields,
- location_t locus, StructBase *base_struct,
- AST::AttrVec inner_attribs = AST::AttrVec (),
- AST::AttrVec outer_attribs = AST::AttrVec ())
- : StructExprStruct (std::move (mappings), std::move (struct_path),
- std::move (inner_attribs), std::move (outer_attribs),
- locus),
- fields (std::move (expr_fields)), struct_base (base_struct)
- {}
+ std::vector<std::unique_ptr<StructExprField>> expr_fields, location_t locus,
+ tl::optional<std::unique_ptr<StructBase>> base_struct,
+ AST::AttrVec inner_attribs, AST::AttrVec outer_attribs);
// copy constructor with vector clone
- StructExprStructFields (StructExprStructFields const &other)
- : StructExprStruct (other), struct_base (other.struct_base),
- union_index (other.union_index)
- {
- fields.reserve (other.fields.size ());
- for (const auto &e : other.fields)
- fields.push_back (e->clone_struct_expr_field ());
- }
+ StructExprStructFields (StructExprStructFields const &other);
// overloaded assignment operator with vector clone
- StructExprStructFields &operator= (StructExprStructFields const &other)
- {
- StructExprStruct::operator= (other);
- struct_base = other.struct_base;
- union_index = other.union_index;
-
- fields.reserve (other.fields.size ());
- for (const auto &e : other.fields)
- fields.push_back (e->clone_struct_expr_field ());
-
- return *this;
- }
+ StructExprStructFields &operator= (StructExprStructFields const &other);
// move constructors
StructExprStructFields (StructExprStructFields &&other) = default;
@@ -1658,20 +1344,20 @@ public:
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRExpressionVisitor &vis) override;
- std::vector<std::unique_ptr<StructExprField> > &get_fields ()
+ std::vector<std::unique_ptr<StructExprField>> &get_fields ()
{
return fields;
};
- const std::vector<std::unique_ptr<StructExprField> > &get_fields () const
+ const std::vector<std::unique_ptr<StructExprField>> &get_fields () const
{
return fields;
};
- StructBase *get_struct_base () { return struct_base; }
+ StructBase &get_struct_base () { return *struct_base.value (); }
- void set_fields_as_owner (
- std::vector<std::unique_ptr<StructExprField> > new_fields)
+ void
+ set_fields_as_owner (std::vector<std::unique_ptr<StructExprField>> new_fields)
{
fields = std::move (new_fields);
}
@@ -1698,26 +1384,15 @@ class StructExprStructBase : public StructExprStruct
StructBase struct_base;
public:
- std::string as_string () const override;
-
- /*inline StructBase get_struct_base() const {
- return struct_base;
- }*/
-
StructExprStructBase (Analysis::NodeMapping mappings,
PathInExpression struct_path, StructBase base_struct,
AST::AttrVec inner_attribs, AST::AttrVec outer_attribs,
- location_t locus)
- : StructExprStruct (std::move (mappings), std::move (struct_path),
- std::move (inner_attribs), std::move (outer_attribs),
- locus),
- struct_base (std::move (base_struct))
- {}
+ location_t locus);
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRExpressionVisitor &vis) override;
- StructBase *get_struct_base () { return &struct_base; }
+ StructBase &get_struct_base () { return struct_base; }
protected:
/* Use covariance to implement clone function as returning this object rather
@@ -1739,45 +1414,21 @@ protected:
class CallExpr : public ExprWithoutBlock
{
std::unique_ptr<Expr> function;
- std::vector<std::unique_ptr<Expr> > params;
+ std::vector<std::unique_ptr<Expr>> params;
location_t locus;
public:
std::string as_string () const override;
CallExpr (Analysis::NodeMapping mappings, std::unique_ptr<Expr> function_expr,
- std::vector<std::unique_ptr<Expr> > function_params,
- AST::AttrVec outer_attribs, location_t locus)
- : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
- function (std::move (function_expr)),
- params (std::move (function_params)), locus (locus)
- {}
+ std::vector<std::unique_ptr<Expr>> function_params,
+ AST::AttrVec outer_attribs, location_t locus);
// copy constructor requires clone
- CallExpr (CallExpr const &other)
- : ExprWithoutBlock (other), function (other.function->clone_expr ()),
- locus (other.locus)
- /*, params(other.params),*/ {
- params.reserve (other.params.size ());
- for (const auto &e : other.params)
- params.push_back (e->clone_expr ());
- }
+ CallExpr (CallExpr const &other);
// Overload assignment operator to clone
- CallExpr &operator= (CallExpr const &other)
- {
- ExprWithoutBlock::operator= (other);
- function = other.function->clone_expr ();
- locus = other.locus;
- // params = other.params;
- // outer_attrs = other.outer_attrs;
-
- params.reserve (other.params.size ());
- for (const auto &e : other.params)
- params.push_back (e->clone_expr ());
-
- return *this;
- }
+ CallExpr &operator= (CallExpr const &other);
// move constructors
CallExpr (CallExpr &&other) = default;
@@ -1796,9 +1447,9 @@ public:
size_t num_params () const { return params.size (); }
- std::vector<std::unique_ptr<Expr> > &get_arguments () { return params; }
+ std::vector<std::unique_ptr<Expr>> &get_arguments () { return params; }
- const std::vector<std::unique_ptr<Expr> > &get_arguments () const
+ const std::vector<std::unique_ptr<Expr>> &get_arguments () const
{
return params;
}
@@ -1826,7 +1477,7 @@ class MethodCallExpr : public ExprWithoutBlock
{
std::unique_ptr<Expr> receiver;
PathExprSegment method_name;
- std::vector<std::unique_ptr<Expr> > params;
+ std::vector<std::unique_ptr<Expr>> params;
location_t locus;
public:
@@ -1835,40 +1486,14 @@ public:
MethodCallExpr (Analysis::NodeMapping mappings,
std::unique_ptr<Expr> call_receiver,
PathExprSegment method_path,
- std::vector<std::unique_ptr<Expr> > method_params,
- AST::AttrVec outer_attribs, location_t locus)
- : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
- receiver (std::move (call_receiver)),
- method_name (std::move (method_path)), params (std::move (method_params)),
- locus (locus)
- {}
+ std::vector<std::unique_ptr<Expr>> method_params,
+ AST::AttrVec outer_attribs, location_t locus);
// copy constructor required due to cloning
- MethodCallExpr (MethodCallExpr const &other)
- : ExprWithoutBlock (other), receiver (other.receiver->clone_expr ()),
- method_name (other.method_name), locus (other.locus)
- /*, params(other.params),*/ {
- params.reserve (other.params.size ());
- for (const auto &e : other.params)
- params.push_back (e->clone_expr ());
- }
+ MethodCallExpr (MethodCallExpr const &other);
// Overload assignment operator to clone receiver object
- MethodCallExpr &operator= (MethodCallExpr const &other)
- {
- ExprWithoutBlock::operator= (other);
- receiver = other.receiver->clone_expr ();
- method_name = other.method_name;
- locus = other.locus;
- // params = other.params;
- // outer_attrs = other.outer_attrs;
-
- params.reserve (other.params.size ());
- for (const auto &e : other.params)
- params.push_back (e->clone_expr ());
-
- return *this;
- }
+ MethodCallExpr &operator= (MethodCallExpr const &other);
// move constructors
MethodCallExpr (MethodCallExpr &&other) = default;
@@ -1887,9 +1512,9 @@ public:
bool has_params () const { return !params.empty (); }
size_t num_params () const { return params.size (); }
- std::vector<std::unique_ptr<Expr> > &get_arguments () { return params; }
+ std::vector<std::unique_ptr<Expr>> &get_arguments () { return params; }
- const std::vector<std::unique_ptr<Expr> > &get_arguments () const
+ const std::vector<std::unique_ptr<Expr>> &get_arguments () const
{
return params;
}
@@ -1930,29 +1555,13 @@ public:
FieldAccessExpr (Analysis::NodeMapping mappings,
std::unique_ptr<Expr> field_access_receiver,
Identifier field_name, AST::AttrVec outer_attribs,
- location_t locus)
- : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
- receiver (std::move (field_access_receiver)),
- field (std::move (field_name)), locus (locus)
- {}
+ location_t locus);
// Copy constructor required due to unique_ptr cloning
- FieldAccessExpr (FieldAccessExpr const &other)
- : ExprWithoutBlock (other), receiver (other.receiver->clone_expr ()),
- field (other.field), locus (other.locus)
- {}
+ FieldAccessExpr (FieldAccessExpr const &other);
// Overload assignment operator to clone unique_ptr
- FieldAccessExpr &operator= (FieldAccessExpr const &other)
- {
- ExprWithoutBlock::operator= (other);
- receiver = other.receiver->clone_expr ();
- field = other.field;
- locus = other.locus;
- // outer_attrs = other.outer_attrs;
-
- return *this;
- }
+ FieldAccessExpr &operator= (FieldAccessExpr const &other);
// move constructors
FieldAccessExpr (FieldAccessExpr &&other) = default;
@@ -2004,42 +1613,15 @@ public:
// Constructor for closure parameter
ClosureParam (std::unique_ptr<Pattern> param_pattern, location_t locus,
std::unique_ptr<Type> param_type = nullptr,
- std::vector<AST::Attribute> outer_attrs = {})
- : outer_attrs (std::move (outer_attrs)),
- pattern (std::move (param_pattern)), type (std::move (param_type)),
- locus (locus)
- {}
+ std::vector<AST::Attribute> outer_attrs = {});
// Copy constructor required due to cloning as a result of unique_ptrs
- ClosureParam (ClosureParam const &other)
- : pattern (other.pattern->clone_pattern ())
- {
- // guard to protect from null pointer dereference
- if (other.pattern != nullptr)
- pattern = other.pattern->clone_pattern ();
- if (other.type != nullptr)
- type = other.type->clone_type ();
- }
+ ClosureParam (ClosureParam const &other);
~ClosureParam () = default;
// Assignment operator must be overloaded to clone as well
- ClosureParam &operator= (ClosureParam const &other)
- {
- outer_attrs = other.outer_attrs;
-
- // guard to protect from null pointer dereference
- if (other.pattern != nullptr)
- pattern = other.pattern->clone_pattern ();
- else
- pattern = nullptr;
- if (other.type != nullptr)
- type = other.type->clone_type ();
- else
- type = nullptr;
-
- return *this;
- }
+ ClosureParam &operator= (ClosureParam const &other);
// move constructors
ClosureParam (ClosureParam &&other) = default;
@@ -2075,36 +1657,13 @@ public:
std::vector<ClosureParam> closure_params,
std::unique_ptr<Type> closure_return_type,
std::unique_ptr<Expr> closure_expr, bool has_move,
- AST::AttrVec outer_attribs, location_t locus)
- : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
- has_move (has_move), params (std::move (closure_params)), locus (locus),
- return_type (std::move (closure_return_type)),
- expr (std::move (closure_expr))
- {}
+ AST::AttrVec outer_attribs, location_t locus);
// Copy constructor requires cloning
- ClosureExpr (ClosureExpr const &other)
- : ExprWithoutBlock (other.get_mappings (), other.get_outer_attrs ())
- {
- return_type
- = other.has_return_type () ? other.return_type->clone_type () : nullptr;
- expr = other.expr->clone_expr ();
- params = other.params;
- has_move = other.has_move;
- }
+ ClosureExpr (ClosureExpr const &other);
// Overload assignment operator to clone unique_ptrs
- ClosureExpr &operator= (ClosureExpr const &other)
- {
- mappings = other.mappings;
- return_type
- = other.has_return_type () ? other.return_type->clone_type () : nullptr;
- expr = other.expr->clone_expr ();
- params = other.params;
- has_move = other.has_move;
-
- return *this;
- }
+ ClosureExpr &operator= (ClosureExpr const &other);
// move constructors
ClosureExpr (ClosureExpr &&other) = default;
@@ -2153,7 +1712,7 @@ class BlockExpr : public ExprWithBlock, public WithInnerAttrs
{
// FIXME this should be private + get/set
public:
- std::vector<std::unique_ptr<Stmt> > statements;
+ std::vector<std::unique_ptr<Stmt>> statements;
std::unique_ptr<Expr> expr;
bool tail_reachable;
LoopLabel label;
@@ -2173,49 +1732,16 @@ public:
bool is_tail_reachable () const { return tail_reachable; }
BlockExpr (Analysis::NodeMapping mappings,
- std::vector<std::unique_ptr<Stmt> > block_statements,
+ std::vector<std::unique_ptr<Stmt>> block_statements,
std::unique_ptr<Expr> block_expr, bool tail_reachable,
AST::AttrVec inner_attribs, AST::AttrVec outer_attribs,
- LoopLabel label, location_t start_locus, location_t end_locus)
- : ExprWithBlock (std::move (mappings), std::move (outer_attribs)),
- WithInnerAttrs (std::move (inner_attribs)),
- statements (std::move (block_statements)), expr (std::move (block_expr)),
- tail_reachable (tail_reachable), label (std::move (label)),
- start_locus (start_locus), end_locus (end_locus)
- {}
+ LoopLabel label, location_t start_locus, location_t end_locus);
// Copy constructor with clone
- BlockExpr (BlockExpr const &other)
- : ExprWithBlock (other), /*statements(other.statements),*/
- WithInnerAttrs (other.inner_attrs), label (other.label),
- start_locus (other.start_locus), end_locus (other.end_locus)
- {
- // guard to protect from null pointer dereference
- if (other.expr != nullptr)
- expr = other.expr->clone_expr ();
-
- statements.reserve (other.statements.size ());
- for (const auto &e : other.statements)
- statements.push_back (e->clone_stmt ());
- }
+ BlockExpr (BlockExpr const &other);
// Overloaded assignment operator to clone pointer
- BlockExpr &operator= (BlockExpr const &other)
- {
- ExprWithBlock::operator= (other);
- // statements = other.statements;
- expr = other.expr->clone_expr ();
- inner_attrs = other.inner_attrs;
- start_locus = other.end_locus;
- end_locus = other.end_locus;
- // outer_attrs = other.outer_attrs;
-
- statements.reserve (other.statements.size ());
- for (const auto &e : other.statements)
- statements.push_back (e->clone_stmt ());
-
- return *this;
- }
+ BlockExpr &operator= (BlockExpr const &other);
// move constructors
BlockExpr (BlockExpr &&other) = default;
@@ -2241,7 +1767,7 @@ public:
bool has_final_expr () { return expr != nullptr; }
Expr &get_final_expr () { return *expr; }
- std::vector<std::unique_ptr<Stmt> > &get_statements () { return statements; }
+ std::vector<std::unique_ptr<Stmt>> &get_statements () { return statements; }
ExprType get_expression_type () const final override
{
@@ -2288,10 +1814,7 @@ public:
// Constructor for a ContinueExpr with a label.
ContinueExpr (Analysis::NodeMapping mappings, location_t locus,
- Lifetime label, AST::AttrVec outer_attribs = AST::AttrVec ())
- : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
- label (std::move (label)), locus (locus)
- {}
+ Lifetime label, AST::AttrVec outer_attribs = AST::AttrVec ());
location_t get_locus () const override final { return locus; }
@@ -2346,32 +1869,13 @@ public:
BreakExpr (Analysis::NodeMapping mappings, location_t locus,
Lifetime break_label,
std::unique_ptr<Expr> expr_in_break = nullptr,
- AST::AttrVec outer_attribs = AST::AttrVec ())
- : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
- label (std::move (break_label)), break_expr (std::move (expr_in_break)),
- locus (locus)
- {}
+ AST::AttrVec outer_attribs = AST::AttrVec ());
// Copy constructor defined to use clone for unique pointer
- BreakExpr (BreakExpr const &other)
- : ExprWithoutBlock (other), label (other.label), locus (other.locus)
- {
- // guard to protect from null pointer dereference
- if (other.break_expr != nullptr)
- break_expr = other.break_expr->clone_expr ();
- }
+ BreakExpr (BreakExpr const &other);
// Overload assignment operator to clone unique pointer
- BreakExpr &operator= (BreakExpr const &other)
- {
- ExprWithoutBlock::operator= (other);
- label = other.label;
- break_expr = other.break_expr->clone_expr ();
- locus = other.locus;
- // outer_attrs = other.outer_attrs;
-
- return *this;
- }
+ BreakExpr &operator= (BreakExpr const &other);
// move constructors
BreakExpr (BreakExpr &&other) = default;
@@ -2411,9 +1915,7 @@ class RangeExpr : public ExprWithoutBlock
protected:
// outer attributes not allowed before range expressions
- RangeExpr (Analysis::NodeMapping mappings, location_t locus)
- : ExprWithoutBlock (std::move (mappings), AST::AttrVec ()), locus (locus)
- {}
+ RangeExpr (Analysis::NodeMapping mappings, location_t locus);
public:
location_t get_locus () const override final { return locus; }
@@ -2436,26 +1938,13 @@ public:
RangeFromToExpr (Analysis::NodeMapping mappings,
std::unique_ptr<Expr> range_from,
- std::unique_ptr<Expr> range_to, location_t locus)
- : RangeExpr (std::move (mappings), locus), from (std::move (range_from)),
- to (std::move (range_to))
- {}
+ std::unique_ptr<Expr> range_to, location_t locus);
// Copy constructor with cloning
- RangeFromToExpr (RangeFromToExpr const &other)
- : RangeExpr (other), from (other.from->clone_expr ()),
- to (other.to->clone_expr ())
- {}
+ RangeFromToExpr (RangeFromToExpr const &other);
// Overload assignment operator to clone unique pointers
- RangeFromToExpr &operator= (RangeFromToExpr const &other)
- {
- RangeExpr::operator= (other);
- from = other.from->clone_expr ();
- to = other.to->clone_expr ();
-
- return *this;
- }
+ RangeFromToExpr &operator= (RangeFromToExpr const &other);
// move constructors
RangeFromToExpr (RangeFromToExpr &&other) = default;
@@ -2493,23 +1982,13 @@ public:
std::string as_string () const override;
RangeFromExpr (Analysis::NodeMapping mappings,
- std::unique_ptr<Expr> range_from, location_t locus)
- : RangeExpr (std::move (mappings), locus), from (std::move (range_from))
- {}
+ std::unique_ptr<Expr> range_from, location_t locus);
// Copy constructor with clone
- RangeFromExpr (RangeFromExpr const &other)
- : RangeExpr (other), from (other.from->clone_expr ())
- {}
+ RangeFromExpr (RangeFromExpr const &other);
// Overload assignment operator to clone unique_ptr
- RangeFromExpr &operator= (RangeFromExpr const &other)
- {
- RangeExpr::operator= (other);
- from = other.from->clone_expr ();
-
- return *this;
- }
+ RangeFromExpr &operator= (RangeFromExpr const &other);
// move constructors
RangeFromExpr (RangeFromExpr &&other) = default;
@@ -2547,23 +2026,13 @@ public:
// outer attributes not allowed
RangeToExpr (Analysis::NodeMapping mappings, std::unique_ptr<Expr> range_to,
- location_t locus)
- : RangeExpr (std::move (mappings), locus), to (std::move (range_to))
- {}
+ location_t locus);
// Copy constructor with clone
- RangeToExpr (RangeToExpr const &other)
- : RangeExpr (other), to (other.to->clone_expr ())
- {}
+ RangeToExpr (RangeToExpr const &other);
// Overload assignment operator to clone unique_ptr
- RangeToExpr &operator= (RangeToExpr const &other)
- {
- RangeExpr::operator= (other);
- to = other.to->clone_expr ();
-
- return *this;
- }
+ RangeToExpr &operator= (RangeToExpr const &other);
// move constructors
RangeToExpr (RangeToExpr &&other) = default;
@@ -2597,9 +2066,7 @@ class RangeFullExpr : public RangeExpr
public:
std::string as_string () const override;
- RangeFullExpr (Analysis::NodeMapping mappings, location_t locus)
- : RangeExpr (std::move (mappings), locus)
- {}
+ RangeFullExpr (Analysis::NodeMapping mappings, location_t locus);
// outer attributes not allowed
void accept_vis (HIRFullVisitor &vis) override;
@@ -2633,27 +2100,14 @@ public:
RangeFromToInclExpr (Analysis::NodeMapping mappings,
std::unique_ptr<Expr> range_from,
- std::unique_ptr<Expr> range_to, location_t locus)
- : RangeExpr (std::move (mappings), locus), from (std::move (range_from)),
- to (std::move (range_to))
- {}
+ std::unique_ptr<Expr> range_to, location_t locus);
// outer attributes not allowed
// Copy constructor with clone
- RangeFromToInclExpr (RangeFromToInclExpr const &other)
- : RangeExpr (other), from (other.from->clone_expr ()),
- to (other.to->clone_expr ())
- {}
+ RangeFromToInclExpr (RangeFromToInclExpr const &other);
// Overload assignment operator to use clone
- RangeFromToInclExpr &operator= (RangeFromToInclExpr const &other)
- {
- RangeExpr::operator= (other);
- from = other.from->clone_expr ();
- to = other.to->clone_expr ();
-
- return *this;
- }
+ RangeFromToInclExpr &operator= (RangeFromToInclExpr const &other);
// move constructors
RangeFromToInclExpr (RangeFromToInclExpr &&other) = default;
@@ -2691,24 +2145,14 @@ public:
std::string as_string () const override;
RangeToInclExpr (Analysis::NodeMapping mappings,
- std::unique_ptr<Expr> range_to, location_t locus)
- : RangeExpr (std::move (mappings), locus), to (std::move (range_to))
- {}
+ std::unique_ptr<Expr> range_to, location_t locus);
// outer attributes not allowed
// Copy constructor with clone
- RangeToInclExpr (RangeToInclExpr const &other)
- : RangeExpr (other), to (other.to->clone_expr ())
- {}
+ RangeToInclExpr (RangeToInclExpr const &other);
// Overload assignment operator to clone pointer
- RangeToInclExpr &operator= (RangeToInclExpr const &other)
- {
- RangeExpr::operator= (other);
- to = other.to->clone_expr ();
-
- return *this;
- }
+ RangeToInclExpr &operator= (RangeToInclExpr const &other);
// move constructors
RangeToInclExpr (RangeToInclExpr &&other) = default;
@@ -2752,30 +2196,13 @@ public:
// Constructor for ReturnExpr.
ReturnExpr (Analysis::NodeMapping mappings, location_t locus,
std::unique_ptr<Expr> returned_expr = nullptr,
- AST::AttrVec outer_attribs = AST::AttrVec ())
- : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
- return_expr (std::move (returned_expr)), locus (locus)
- {}
+ AST::AttrVec outer_attribs = AST::AttrVec ());
// Copy constructor with clone
- ReturnExpr (ReturnExpr const &other)
- : ExprWithoutBlock (other), locus (other.locus)
- {
- // guard to protect from null pointer dereference
- if (other.return_expr != nullptr)
- return_expr = other.return_expr->clone_expr ();
- }
+ ReturnExpr (ReturnExpr const &other);
// Overloaded assignment operator to clone return_expr pointer
- ReturnExpr &operator= (ReturnExpr const &other)
- {
- ExprWithoutBlock::operator= (other);
- return_expr = other.return_expr->clone_expr ();
- locus = other.locus;
- // outer_attrs = other.outer_attrs;
-
- return *this;
- }
+ ReturnExpr &operator= (ReturnExpr const &other);
// move constructors
ReturnExpr (ReturnExpr &&other) = default;
@@ -2822,27 +2249,13 @@ public:
UnsafeBlockExpr (Analysis::NodeMapping mappings,
std::unique_ptr<BlockExpr> block_expr,
- AST::AttrVec outer_attribs, location_t locus)
- : ExprWithBlock (std::move (mappings), std::move (outer_attribs)),
- expr (std::move (block_expr)), locus (locus)
- {}
+ AST::AttrVec outer_attribs, location_t locus);
// Copy constructor with clone
- UnsafeBlockExpr (UnsafeBlockExpr const &other)
- : ExprWithBlock (other), expr (other.expr->clone_block_expr ()),
- locus (other.locus)
- {}
+ UnsafeBlockExpr (UnsafeBlockExpr const &other);
// Overloaded assignment operator to clone
- UnsafeBlockExpr &operator= (UnsafeBlockExpr const &other)
- {
- ExprWithBlock::operator= (other);
- expr = other.expr->clone_block_expr ();
- locus = other.locus;
- // outer_attrs = other.outer_attrs;
-
- return *this;
- }
+ UnsafeBlockExpr &operator= (UnsafeBlockExpr const &other);
// move constructors
UnsafeBlockExpr (UnsafeBlockExpr &&other) = default;
@@ -2891,29 +2304,13 @@ protected:
BaseLoopExpr (Analysis::NodeMapping mappings,
std::unique_ptr<BlockExpr> loop_block, location_t locus,
LoopLabel loop_label,
- AST::AttrVec outer_attribs = AST::AttrVec ())
- : ExprWithBlock (std::move (mappings), std::move (outer_attribs)),
- loop_label (std::move (loop_label)), loop_block (std::move (loop_block)),
- locus (locus)
- {}
+ AST::AttrVec outer_attribs = AST::AttrVec ());
// Copy constructor for BaseLoopExpr with clone
- BaseLoopExpr (BaseLoopExpr const &other)
- : ExprWithBlock (other), loop_label (other.loop_label),
- loop_block (other.loop_block->clone_block_expr ()), locus (other.locus)
- {}
+ BaseLoopExpr (BaseLoopExpr const &other);
// Overloaded assignment operator to clone
- BaseLoopExpr &operator= (BaseLoopExpr const &other)
- {
- ExprWithBlock::operator= (other);
- loop_block = other.loop_block->clone_block_expr ();
- loop_label = other.loop_label;
- locus = other.locus;
- // outer_attrs = other.outer_attrs;
-
- return *this;
- }
+ BaseLoopExpr &operator= (BaseLoopExpr const &other);
// move constructors
BaseLoopExpr (BaseLoopExpr &&other) = default;
@@ -2943,10 +2340,7 @@ public:
// Constructor for LoopExpr
LoopExpr (Analysis::NodeMapping mappings,
std::unique_ptr<BlockExpr> loop_block, location_t locus,
- LoopLabel loop_label, AST::AttrVec outer_attribs = AST::AttrVec ())
- : BaseLoopExpr (std::move (mappings), std::move (loop_block), locus,
- std::move (loop_label), std::move (outer_attribs))
- {}
+ LoopLabel loop_label, AST::AttrVec outer_attribs = AST::AttrVec ());
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRExpressionVisitor &vis) override;
@@ -2977,28 +2371,13 @@ public:
std::unique_ptr<Expr> loop_condition,
std::unique_ptr<BlockExpr> loop_block, location_t locus,
LoopLabel loop_label,
- AST::AttrVec outer_attribs = AST::AttrVec ())
- : BaseLoopExpr (std::move (mappings), std::move (loop_block), locus,
- std::move (loop_label), std::move (outer_attribs)),
- condition (std::move (loop_condition))
- {}
+ AST::AttrVec outer_attribs = AST::AttrVec ());
// Copy constructor with clone
- WhileLoopExpr (WhileLoopExpr const &other)
- : BaseLoopExpr (other), condition (other.condition->clone_expr ())
- {}
+ WhileLoopExpr (WhileLoopExpr const &other);
// Overloaded assignment operator to clone
- WhileLoopExpr &operator= (WhileLoopExpr const &other)
- {
- BaseLoopExpr::operator= (other);
- condition = other.condition->clone_expr ();
- // loop_block = other.loop_block->clone_block_expr();
- // loop_label = other.loop_label;
- // outer_attrs = other.outer_attrs;
-
- return *this;
- }
+ WhileLoopExpr &operator= (WhileLoopExpr const &other);
// move constructors
WhileLoopExpr (WhileLoopExpr &&other) = default;
@@ -3029,7 +2408,7 @@ protected:
class WhileLetLoopExpr : public BaseLoopExpr
{
// MatchArmPatterns patterns;
- std::vector<std::unique_ptr<Pattern> > match_arm_patterns; // inlined
+ std::vector<std::unique_ptr<Pattern>> match_arm_patterns; // inlined
std::unique_ptr<Expr> condition;
public:
@@ -3037,44 +2416,17 @@ public:
// Constructor with a loop label
WhileLetLoopExpr (Analysis::NodeMapping mappings,
- std::vector<std::unique_ptr<Pattern> > match_arm_patterns,
+ std::vector<std::unique_ptr<Pattern>> match_arm_patterns,
std::unique_ptr<Expr> condition,
std::unique_ptr<BlockExpr> loop_block, location_t locus,
LoopLabel loop_label,
- AST::AttrVec outer_attribs = AST::AttrVec ())
- : BaseLoopExpr (std::move (mappings), std::move (loop_block), locus,
- std::move (loop_label), std::move (outer_attribs)),
- match_arm_patterns (std::move (match_arm_patterns)),
- condition (std::move (condition))
- {}
+ AST::AttrVec outer_attribs = AST::AttrVec ());
// Copy constructor with clone
- WhileLetLoopExpr (WhileLetLoopExpr const &other)
- : BaseLoopExpr (other),
- /*match_arm_patterns(other.match_arm_patterns),*/ condition (
- other.condition->clone_expr ())
- {
- match_arm_patterns.reserve (other.match_arm_patterns.size ());
- for (const auto &e : other.match_arm_patterns)
- match_arm_patterns.push_back (e->clone_pattern ());
- }
+ WhileLetLoopExpr (WhileLetLoopExpr const &other);
// Overloaded assignment operator to clone pointers
- WhileLetLoopExpr &operator= (WhileLetLoopExpr const &other)
- {
- BaseLoopExpr::operator= (other);
- // match_arm_patterns = other.match_arm_patterns;
- condition = other.condition->clone_expr ();
- // loop_block = other.loop_block->clone_block_expr();
- // loop_label = other.loop_label;
- // outer_attrs = other.outer_attrs;
-
- match_arm_patterns.reserve (other.match_arm_patterns.size ());
- for (const auto &e : other.match_arm_patterns)
- match_arm_patterns.push_back (e->clone_pattern ());
-
- return *this;
- }
+ WhileLetLoopExpr &operator= (WhileLetLoopExpr const &other);
// move constructors
WhileLetLoopExpr (WhileLetLoopExpr &&other) = default;
@@ -3084,7 +2436,7 @@ public:
void accept_vis (HIRExpressionVisitor &vis) override;
Expr &get_cond () { return *condition; }
- std::vector<std::unique_ptr<Pattern> > &get_patterns ()
+ std::vector<std::unique_ptr<Pattern>> &get_patterns ()
{
return match_arm_patterns;
}
@@ -3117,29 +2469,14 @@ public:
std::string as_string () const override;
IfExpr (Analysis::NodeMapping mappings, std::unique_ptr<Expr> condition,
- std::unique_ptr<BlockExpr> if_block, location_t locus)
- : ExprWithBlock (std::move (mappings), AST::AttrVec ()),
- condition (std::move (condition)), if_block (std::move (if_block)),
- locus (locus)
- {}
+ std::unique_ptr<BlockExpr> if_block, location_t locus);
// outer attributes are never allowed on IfExprs
// Copy constructor with clone
- IfExpr (IfExpr const &other)
- : ExprWithBlock (other), condition (other.condition->clone_expr ()),
- if_block (other.if_block->clone_block_expr ()), locus (other.locus)
- {}
+ IfExpr (IfExpr const &other);
// Overloaded assignment operator to clone expressions
- IfExpr &operator= (IfExpr const &other)
- {
- ExprWithBlock::operator= (other);
- condition = other.condition->clone_expr ();
- if_block = other.if_block->clone_block_expr ();
- locus = other.locus;
-
- return *this;
- }
+ IfExpr &operator= (IfExpr const &other);
// move constructors
IfExpr (IfExpr &&other) = default;
@@ -3195,28 +2532,15 @@ public:
IfExprConseqElse (Analysis::NodeMapping mappings,
std::unique_ptr<Expr> condition,
std::unique_ptr<BlockExpr> if_block,
- std::unique_ptr<ExprWithBlock> else_block, location_t locus)
- : IfExpr (std::move (mappings), std::move (condition), std::move (if_block),
- locus),
- else_block (std::move (else_block))
- {}
+ std::unique_ptr<ExprWithBlock> else_block,
+ location_t locus);
// again, outer attributes not allowed
// Copy constructor with clone
- IfExprConseqElse (IfExprConseqElse const &other)
- : IfExpr (other), else_block (other.else_block->clone_expr_with_block ())
- {}
+ IfExprConseqElse (IfExprConseqElse const &other);
// Overloaded assignment operator with cloning
- IfExprConseqElse &operator= (IfExprConseqElse const &other)
- {
- IfExpr::operator= (other);
- // condition = other.condition->clone_expr();
- // if_block = other.if_block->clone_block_expr();
- else_block = other.else_block->clone_expr_with_block ();
-
- return *this;
- }
+ IfExprConseqElse &operator= (IfExprConseqElse const &other);
// move constructors
IfExprConseqElse (IfExprConseqElse &&other) = default;
@@ -3257,7 +2581,7 @@ struct MatchArm
{
private:
AST::AttrVec outer_attrs;
- std::vector<std::unique_ptr<Pattern> > match_arm_patterns;
+ std::vector<std::unique_ptr<Pattern>> match_arm_patterns;
std::unique_ptr<Expr> guard_expr;
location_t locus;
@@ -3266,45 +2590,17 @@ public:
bool has_match_arm_guard () const { return guard_expr != nullptr; }
// Constructor for match arm with a guard expression
- MatchArm (std::vector<std::unique_ptr<Pattern> > match_arm_patterns,
+ MatchArm (std::vector<std::unique_ptr<Pattern>> match_arm_patterns,
location_t locus, std::unique_ptr<Expr> guard_expr = nullptr,
- AST::AttrVec outer_attrs = AST::AttrVec ())
- : outer_attrs (std::move (outer_attrs)),
- match_arm_patterns (std::move (match_arm_patterns)),
- guard_expr (std::move (guard_expr)), locus (locus)
- {}
+ AST::AttrVec outer_attrs = AST::AttrVec ());
// Copy constructor with clone
- MatchArm (MatchArm const &other) : outer_attrs (other.outer_attrs)
- {
- // guard to protect from null pointer dereference
- if (other.guard_expr != nullptr)
- guard_expr = other.guard_expr->clone_expr ();
-
- match_arm_patterns.reserve (other.match_arm_patterns.size ());
- for (const auto &e : other.match_arm_patterns)
- match_arm_patterns.push_back (e->clone_pattern ());
-
- locus = other.locus;
- }
+ MatchArm (MatchArm const &other);
~MatchArm () = default;
// Overload assignment operator to clone
- MatchArm &operator= (MatchArm const &other)
- {
- outer_attrs = other.outer_attrs;
-
- if (other.guard_expr != nullptr)
- guard_expr = other.guard_expr->clone_expr ();
-
- match_arm_patterns.clear ();
- match_arm_patterns.reserve (other.match_arm_patterns.size ());
- for (const auto &e : other.match_arm_patterns)
- match_arm_patterns.push_back (e->clone_pattern ());
-
- return *this;
- }
+ MatchArm &operator= (MatchArm const &other);
// move constructors
MatchArm (MatchArm &&other) = default;
@@ -3317,12 +2613,12 @@ public:
static MatchArm create_error ()
{
location_t locus = UNDEF_LOCATION;
- return MatchArm (std::vector<std::unique_ptr<Pattern> > (), locus);
+ return MatchArm (std::vector<std::unique_ptr<Pattern>> (), locus);
}
std::string as_string () const;
- std::vector<std::unique_ptr<Pattern> > &get_patterns ()
+ std::vector<std::unique_ptr<Pattern>> &get_patterns ()
{
return match_arm_patterns;
}
@@ -3343,23 +2639,11 @@ private:
public:
MatchCase (Analysis::NodeMapping mappings, MatchArm arm,
- std::unique_ptr<Expr> expr)
- : mappings (mappings), arm (std::move (arm)), expr (std::move (expr))
- {}
+ std::unique_ptr<Expr> expr);
- MatchCase (const MatchCase &other)
- : mappings (other.mappings), arm (other.arm),
- expr (other.expr->clone_expr ())
- {}
-
- MatchCase &operator= (const MatchCase &other)
- {
- mappings = other.mappings;
- arm = other.arm;
- expr = other.expr->clone_expr ();
+ MatchCase (const MatchCase &other);
- return *this;
- }
+ MatchCase &operator= (const MatchCase &other);
MatchCase (MatchCase &&other) = default;
MatchCase &operator= (MatchCase &&other) = default;
@@ -3388,40 +2672,13 @@ public:
MatchExpr (Analysis::NodeMapping mappings, std::unique_ptr<Expr> branch_value,
std::vector<MatchCase> match_arms, AST::AttrVec inner_attrs,
- AST::AttrVec outer_attrs, location_t locus)
- : ExprWithBlock (std::move (mappings), std::move (outer_attrs)),
- WithInnerAttrs (std::move (inner_attrs)),
- branch_value (std::move (branch_value)),
- match_arms (std::move (match_arms)), locus (locus)
- {}
+ AST::AttrVec outer_attrs, location_t locus);
// Copy constructor requires clone due to unique_ptr
- MatchExpr (MatchExpr const &other)
- : ExprWithBlock (other), WithInnerAttrs (other.inner_attrs),
- branch_value (other.branch_value->clone_expr ()),
- match_arms (other.match_arms), locus (other.locus)
- {
- /*match_arms.reserve (other.match_arms.size ());
- for (const auto &e : other.match_arms)
- match_arms.push_back (e->clone_match_case ());*/
- }
+ MatchExpr (MatchExpr const &other);
// Overloaded assignment operator to clone due to unique_ptr
- MatchExpr &operator= (MatchExpr const &other)
- {
- ExprWithBlock::operator= (other);
- branch_value = other.branch_value->clone_expr ();
- inner_attrs = other.inner_attrs;
- match_arms = other.match_arms;
- // outer_attrs = other.outer_attrs;
- locus = other.locus;
-
- /*match_arms.reserve (other.match_arms.size ());
- for (const auto &e : other.match_arms)
- match_arms.push_back (e->clone_match_case ());*/
-
- return *this;
- }
+ MatchExpr &operator= (MatchExpr const &other);
// move constructors
MatchExpr (MatchExpr &&other) = default;
@@ -3464,26 +2721,13 @@ class AwaitExpr : public ExprWithoutBlock
public:
// TODO: ensure outer attributes are actually allowed
AwaitExpr (Analysis::NodeMapping mappings, std::unique_ptr<Expr> awaited_expr,
- AST::AttrVec outer_attrs, location_t locus)
- : ExprWithoutBlock (std::move (mappings), std::move (outer_attrs)),
- awaited_expr (std::move (awaited_expr)), locus (locus)
- {}
+ AST::AttrVec outer_attrs, location_t locus);
// copy constructor with clone
- AwaitExpr (AwaitExpr const &other)
- : ExprWithoutBlock (other),
- awaited_expr (other.awaited_expr->clone_expr ()), locus (other.locus)
- {}
+ AwaitExpr (AwaitExpr const &other);
// overloaded assignment operator with clone
- AwaitExpr &operator= (AwaitExpr const &other)
- {
- ExprWithoutBlock::operator= (other);
- awaited_expr = other.awaited_expr->clone_expr ();
- locus = other.locus;
-
- return *this;
- }
+ AwaitExpr &operator= (AwaitExpr const &other);
// move constructors
AwaitExpr (AwaitExpr &&other) = default;
@@ -3522,27 +2766,13 @@ class AsyncBlockExpr : public ExprWithBlock
public:
AsyncBlockExpr (Analysis::NodeMapping mappings,
std::unique_ptr<BlockExpr> block_expr, bool has_move,
- AST::AttrVec outer_attrs, location_t locus)
- : ExprWithBlock (std::move (mappings), std::move (outer_attrs)),
- has_move (has_move), block_expr (std::move (block_expr)), locus (locus)
- {}
+ AST::AttrVec outer_attrs, location_t locus);
// copy constructor with clone
- AsyncBlockExpr (AsyncBlockExpr const &other)
- : ExprWithBlock (other), has_move (other.has_move),
- block_expr (other.block_expr->clone_block_expr ()), locus (other.locus)
- {}
+ AsyncBlockExpr (AsyncBlockExpr const &other);
// overloaded assignment operator to clone
- AsyncBlockExpr &operator= (AsyncBlockExpr const &other)
- {
- ExprWithBlock::operator= (other);
- has_move = other.has_move;
- block_expr = other.block_expr->clone_block_expr ();
- locus = other.locus;
-
- return *this;
- }
+ AsyncBlockExpr &operator= (AsyncBlockExpr const &other);
// move constructors
AsyncBlockExpr (AsyncBlockExpr &&other) = default;
@@ -3576,35 +2806,15 @@ protected:
class OperatorExprMeta
{
public:
- OperatorExprMeta (HIR::CompoundAssignmentExpr &expr)
- : node_mappings (expr.get_mappings ()),
- lvalue_mappings (expr.get_expr ().get_mappings ()),
- locus (expr.get_locus ())
- {}
+ OperatorExprMeta (HIR::CompoundAssignmentExpr &expr);
- OperatorExprMeta (HIR::ArithmeticOrLogicalExpr &expr)
- : node_mappings (expr.get_mappings ()),
- lvalue_mappings (expr.get_expr ().get_mappings ()),
- locus (expr.get_locus ())
- {}
+ OperatorExprMeta (HIR::ArithmeticOrLogicalExpr &expr);
- OperatorExprMeta (HIR::NegationExpr &expr)
- : node_mappings (expr.get_mappings ()),
- lvalue_mappings (expr.get_expr ().get_mappings ()),
- locus (expr.get_locus ())
- {}
+ OperatorExprMeta (HIR::NegationExpr &expr);
- OperatorExprMeta (HIR::DereferenceExpr &expr)
- : node_mappings (expr.get_mappings ()),
- lvalue_mappings (expr.get_expr ().get_mappings ()),
- locus (expr.get_locus ())
- {}
+ OperatorExprMeta (HIR::DereferenceExpr &expr);
- OperatorExprMeta (HIR::ArrayIndexExpr &expr)
- : node_mappings (expr.get_mappings ()),
- lvalue_mappings (expr.get_array_expr ().get_mappings ()),
- locus (expr.get_locus ())
- {}
+ OperatorExprMeta (HIR::ArrayIndexExpr &expr);
const Analysis::NodeMapping &get_mappings () const { return node_mappings; }
@@ -3679,23 +2889,12 @@ struct AnonConst
{
NodeId id;
std::unique_ptr<Expr> expr;
- AnonConst (NodeId id, std::unique_ptr<Expr> expr)
- : id (id), expr (std::move (expr))
- {
- rust_assert (this->expr != nullptr);
- }
- AnonConst (const AnonConst &other)
- {
- id = other.id;
- expr = other.expr->clone_expr ();
- }
- AnonConst operator= (const AnonConst &other)
- {
- id = other.id;
- expr = other.expr->clone_expr ();
- return *this;
- }
+ AnonConst (NodeId id, std::unique_ptr<Expr> expr);
+
+ AnonConst (const AnonConst &other);
+
+ AnonConst operator= (const AnonConst &other);
};
class InlineAsmOperand
@@ -3707,26 +2906,11 @@ public:
std::unique_ptr<Expr> expr;
In (const tl::optional<struct AST::InlineAsmRegOrRegClass> ®,
- std::unique_ptr<Expr> expr)
- : reg (reg), expr (std::move (expr))
- {
- rust_assert (this->expr != nullptr);
- }
-
- In (const struct In &other)
- {
- reg = other.reg;
-
- expr = other.expr->clone_expr ();
- }
-
- In operator= (const struct In &other)
- {
- reg = other.reg;
- expr = other.expr->clone_expr ();
-
- return *this;
- }
+ std::unique_ptr<Expr> expr);
+
+ In (const struct In &other);
+
+ In operator= (const struct In &other);
};
struct Out
@@ -3736,26 +2920,11 @@ public:
std::unique_ptr<Expr> expr; // can be null
Out (tl::optional<struct AST::InlineAsmRegOrRegClass> ®, bool late,
- std::unique_ptr<Expr> expr)
- : reg (reg), late (late), expr (std::move (expr))
- {
- rust_assert (this->expr != nullptr);
- }
-
- Out (const struct Out &other)
- {
- reg = other.reg;
- late = other.late;
- expr = other.expr->clone_expr ();
- }
-
- Out operator= (const struct Out &other)
- {
- reg = other.reg;
- late = other.late;
- expr = other.expr->clone_expr ();
- return *this;
- }
+ std::unique_ptr<Expr> expr);
+
+ Out (const struct Out &other);
+
+ Out operator= (const struct Out &other);
};
struct InOut
@@ -3765,27 +2934,11 @@ public:
std::unique_ptr<Expr> expr; // this can't be null
InOut (tl::optional<struct AST::InlineAsmRegOrRegClass> ®, bool late,
- std::unique_ptr<Expr> expr)
- : reg (reg), late (late), expr (std::move (expr))
- {
- rust_assert (this->expr != nullptr);
- }
-
- InOut (const struct InOut &other)
- {
- reg = other.reg;
- late = other.late;
- expr = other.expr->clone_expr ();
- }
-
- InOut operator= (const struct InOut &other)
- {
- reg = other.reg;
- late = other.late;
- expr = other.expr->clone_expr ();
-
- return *this;
- }
+ std::unique_ptr<Expr> expr);
+
+ InOut (const struct InOut &other);
+
+ InOut operator= (const struct InOut &other);
};
struct SplitInOut
@@ -3797,31 +2950,11 @@ public:
SplitInOut (tl::optional<struct AST::InlineAsmRegOrRegClass> ®,
bool late, std::unique_ptr<Expr> in_expr,
- std::unique_ptr<Expr> out_expr)
- : reg (reg), late (late), in_expr (std::move (in_expr)),
- out_expr (std::move (out_expr))
- {
- rust_assert (this->in_expr != nullptr);
- rust_assert (this->out_expr != nullptr);
- }
-
- SplitInOut (const struct SplitInOut &other)
- {
- reg = other.reg;
- late = other.late;
- in_expr = other.in_expr->clone_expr ();
- out_expr = other.out_expr->clone_expr ();
- }
-
- SplitInOut operator= (const struct SplitInOut &other)
- {
- reg = other.reg;
- late = other.late;
- in_expr = other.in_expr->clone_expr ();
- out_expr = other.out_expr->clone_expr ();
-
- return *this;
- }
+ std::unique_ptr<Expr> out_expr);
+
+ SplitInOut (const struct SplitInOut &other);
+
+ SplitInOut operator= (const struct SplitInOut &other);
};
struct Const
@@ -3833,20 +2966,11 @@ public:
{
std::unique_ptr<Expr> expr;
- Sym (std::unique_ptr<Expr> expr) : expr (std::move (expr))
- {
- rust_assert (this->expr != nullptr);
- }
- Sym (const struct Sym &other)
- {
- expr = std::unique_ptr<Expr> (other.expr->clone_expr ());
- }
-
- Sym operator= (const struct Sym &other)
- {
- expr = std::unique_ptr<Expr> (other.expr->clone_expr ());
- return *this;
- }
+ Sym (std::unique_ptr<Expr> expr);
+
+ Sym (const struct Sym &other);
+
+ Sym operator= (const struct Sym &other);
};
struct Label
@@ -3854,23 +2978,11 @@ public:
std::string label_name;
std::unique_ptr<Expr> expr;
- Label (tl::optional<std::string> label_name, std::unique_ptr<Expr> expr)
- : expr (std::move (expr))
- {
- rust_assert (this->expr != nullptr);
- if (label_name.has_value ())
- this->label_name = label_name.value ();
- }
- Label (const struct Label &other)
- {
- expr = std::unique_ptr<Expr> (other.expr->clone_expr ());
- }
-
- Label operator= (const struct Label &other)
- {
- expr = std::unique_ptr<Expr> (other.expr->clone_expr ());
- return *this;
- }
+ Label (tl::optional<std::string> label_name, std::unique_ptr<Expr> expr);
+
+ Label (const struct Label &other);
+
+ Label operator= (const struct Label &other);
};
private:
@@ -3988,6 +3100,7 @@ public:
// INFO: An inline asm is asm!, which is the opposite of a global_asm()
return !this->is_global_asm;
}
+
InlineAsm (location_t locus, bool is_global_asm,
std::vector<AST::InlineAsmTemplatePiece> template_,
std::vector<AST::TupleTemplateStr> template_strs,
@@ -3995,15 +3108,7 @@ public:
std::vector<AST::TupleClobber> clobber_abi,
std::set<AST::InlineAsmOption> options,
Analysis::NodeMapping mappings,
- AST::AttrVec outer_attribs = AST::AttrVec ())
- : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
- locus (locus), is_global_asm (is_global_asm),
- template_ (std::move (template_)),
- template_strs (std::move (template_strs)),
- operands (std::move (operands)), clobber_abi (std::move (clobber_abi)),
- options (std::move (options))
-
- {}
+ AST::AttrVec outer_attribs = AST::AttrVec ());
};
} // namespace HIR
diff --git a/gcc/rust/hir/tree/rust-hir-generic-param.cc b/gcc/rust/hir/tree/rust-hir-generic-param.cc
new file mode 100644
index 00000000000..e5afa8ee08f
--- /dev/null
+++ b/gcc/rust/hir/tree/rust-hir-generic-param.cc
@@ -0,0 +1,95 @@
+// Copyright (C) 2020-2024 Free Software Foundation, Inc.
+
+// This file is part of GCC.
+
+// GCC is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3, or (at your option) any later
+// version.
+
+// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with GCC; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include "rust-hir-generic-param.h"
+
+namespace Rust {
+namespace HIR {
+
+GenericParam::GenericParam (Analysis::NodeMapping mapping,
+ enum GenericKind kind)
+ : mappings (mapping), kind (kind)
+{}
+
+LifetimeParam::LifetimeParam (Analysis::NodeMapping mappings, Lifetime lifetime,
+ location_t locus,
+ std::vector<Lifetime> lifetime_bounds,
+ AST::AttrVec outer_attrs)
+ : GenericParam (mappings, GenericKind::LIFETIME),
+ lifetime (std::move (lifetime)),
+ lifetime_bounds (std::move (lifetime_bounds)),
+ outer_attrs (std::move (outer_attrs)), locus (locus)
+{}
+
+LifetimeParam::LifetimeParam (LifetimeParam const &other)
+ : GenericParam (other.mappings, GenericKind::LIFETIME),
+ lifetime (other.lifetime), lifetime_bounds (other.lifetime_bounds),
+ outer_attrs (other.outer_attrs), locus (other.locus)
+{}
+
+LifetimeParam &
+LifetimeParam::operator= (LifetimeParam const &other)
+{
+ lifetime = other.lifetime;
+ lifetime_bounds = other.lifetime_bounds;
+ outer_attrs = other.outer_attrs;
+ locus = other.locus;
+ mappings = other.mappings;
+
+ return *this;
+}
+
+ConstGenericParam::ConstGenericParam (std::string name,
+ std::unique_ptr<Type> type,
+ std::unique_ptr<Expr> default_expression,
+ Analysis::NodeMapping mapping,
+ location_t locus)
+ : GenericParam (mapping, GenericKind::CONST), name (std::move (name)),
+ type (std::move (type)),
+ default_expression (std::move (default_expression)), locus (locus)
+{}
+
+ConstGenericParam::ConstGenericParam (const ConstGenericParam &other)
+ : GenericParam (other)
+{
+ name = other.name;
+ locus = other.locus;
+
+ if (other.type)
+ type = other.type->clone_type ();
+ if (other.default_expression)
+ default_expression = other.default_expression->clone_expr ();
+}
+
+std::string
+ConstGenericParam::as_string () const
+{
+ auto result = "ConstGenericParam: " + name + " : " + type->as_string ();
+
+ if (default_expression)
+ result += " = " + default_expression->as_string ();
+
+ return result;
+}
+
+void
+ConstGenericParam::accept_vis (HIRFullVisitor &)
+{}
+
+} // namespace HIR
+} // namespace Rust
diff --git a/gcc/rust/hir/tree/rust-hir-generic-param.h b/gcc/rust/hir/tree/rust-hir-generic-param.h
new file mode 100644
index 00000000000..73b93d48a49
--- /dev/null
+++ b/gcc/rust/hir/tree/rust-hir-generic-param.h
@@ -0,0 +1,186 @@
+
+// Copyright (C) 2020-2024 Free Software Foundation, Inc.
+
+// This file is part of GCC.
+
+// GCC is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3, or (at your option) any later
+// version.
+
+// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with GCC; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#ifndef RUST_HIR_GENERIC_PARAM_H
+#define RUST_HIR_GENERIC_PARAM_H
+
+#include "rust-hir-visitable.h"
+#include "rust-hir-bound.h"
+
+namespace Rust {
+namespace HIR {
+
+/* Base generic parameter in HIR. Abstract - can be represented by a Lifetime or
+ * Type param */
+class GenericParam : public FullVisitable
+{
+public:
+ using FullVisitable::accept_vis;
+
+ virtual ~GenericParam () {}
+
+ enum class GenericKind
+ {
+ TYPE,
+ LIFETIME,
+ CONST,
+ };
+
+ virtual AST::AttrVec &get_outer_attrs () = 0;
+ virtual bool has_outer_attribute () const = 0;
+
+ // Unique pointer custom clone function
+ std::unique_ptr<GenericParam> clone_generic_param () const
+ {
+ return std::unique_ptr<GenericParam> (clone_generic_param_impl ());
+ }
+
+ virtual std::string as_string () const = 0;
+
+ virtual location_t get_locus () const = 0;
+
+ Analysis::NodeMapping get_mappings () const { return mappings; }
+
+ enum GenericKind get_kind () const { return kind; }
+
+protected:
+ // Clone function implementation as pure virtual method
+ virtual GenericParam *clone_generic_param_impl () const = 0;
+
+ Analysis::NodeMapping mappings;
+
+ enum GenericKind kind;
+
+ GenericParam (Analysis::NodeMapping mapping,
+ enum GenericKind kind = GenericKind::TYPE);
+};
+
+// A lifetime generic parameter (as opposed to a type generic parameter)
+class LifetimeParam : public GenericParam
+{
+ Lifetime lifetime;
+
+ // bool has_lifetime_bounds;
+ // LifetimeBounds lifetime_bounds;
+ std::vector<Lifetime> lifetime_bounds; // inlined LifetimeBounds
+
+ AST::AttrVec outer_attrs;
+
+ location_t locus;
+
+public:
+ Lifetime get_lifetime () { return lifetime; }
+
+ // Returns whether the lifetime param has any lifetime bounds.
+ bool has_lifetime_bounds () const { return !lifetime_bounds.empty (); }
+
+ std::vector<Lifetime> &get_lifetime_bounds () { return lifetime_bounds; }
+
+ // Returns whether the lifetime param has an outer attribute.
+ bool has_outer_attribute () const override { return outer_attrs.size () > 1; }
+
+ AST::AttrVec &get_outer_attrs () override { return outer_attrs; }
+
+ // Returns whether the lifetime param is in an error state.
+ bool is_error () const { return lifetime.is_error (); }
+
+ // Constructor
+ LifetimeParam (Analysis::NodeMapping mappings, Lifetime lifetime,
+ location_t locus = UNDEF_LOCATION,
+ std::vector<Lifetime> lifetime_bounds
+ = std::vector<Lifetime> (),
+ AST::AttrVec outer_attrs = std::vector<AST::Attribute> ());
+
+ // TODO: remove copy and assignment operator definitions - not required
+
+ // Copy constructor with clone
+ LifetimeParam (LifetimeParam const &other);
+
+ // Overloaded assignment operator to clone attribute
+ LifetimeParam &operator= (LifetimeParam const &other);
+
+ // move constructors
+ LifetimeParam (LifetimeParam &&other) = default;
+ LifetimeParam &operator= (LifetimeParam &&other) = default;
+
+ std::string as_string () const override;
+
+ void accept_vis (HIRFullVisitor &vis) override;
+
+ location_t get_locus () const override final { return locus; }
+
+protected:
+ /* Use covariance to implement clone function as returning this object rather
+ * than base */
+ LifetimeParam *clone_generic_param_impl () const override
+ {
+ return new LifetimeParam (*this);
+ }
+};
+
+class ConstGenericParam : public GenericParam
+{
+public:
+ ConstGenericParam (std::string name, std::unique_ptr<Type> type,
+ std::unique_ptr<Expr> default_expression,
+ Analysis::NodeMapping mapping, location_t locus);
+
+ ConstGenericParam (const ConstGenericParam &other);
+
+ bool has_outer_attribute () const override { return false; }
+
+ AST::AttrVec &get_outer_attrs () override { return outer_attrs; }
+
+ std::string as_string () const override final;
+
+ void accept_vis (HIRFullVisitor &vis) override final;
+
+ location_t get_locus () const override final { return locus; };
+
+ bool has_default_expression () { return default_expression != nullptr; }
+
+ std::string get_name () { return name; }
+ Type &get_type () { return *type; }
+ Expr &get_default_expression () { return *default_expression; }
+
+protected:
+ /* Use covariance to implement clone function as returning this object rather
+ * than base */
+ ConstGenericParam *clone_generic_param_impl () const override
+ {
+ return new ConstGenericParam (*this);
+ }
+
+private:
+ std::string name;
+ std::unique_ptr<Type> type;
+
+ /* const params have no outer attrs, should be empty */
+ AST::AttrVec outer_attrs = std::vector<AST::Attribute> ();
+
+ /* Optional - can be a null pointer if there is no default expression */
+ std::unique_ptr<Expr> default_expression;
+
+ location_t locus;
+};
+
+} // namespace HIR
+} // namespace Rust
+
+#endif
diff --git a/gcc/rust/hir/tree/rust-hir-item.cc b/gcc/rust/hir/tree/rust-hir-item.cc
new file mode 100644
index 00000000000..f81f1eae134
--- /dev/null
+++ b/gcc/rust/hir/tree/rust-hir-item.cc
@@ -0,0 +1,1017 @@
+// Copyright (C) 2020-2024 Free Software Foundation, Inc.
+
+// This file is part of GCC.
+
+// GCC is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3, or (at your option) any later
+// version.
+
+// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with GCC; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include "rust-hir-item.h"
+
+namespace Rust {
+namespace HIR {
+
+TypeParam::TypeParam (
+ Analysis::NodeMapping mappings, Identifier type_representation,
+ location_t locus,
+ std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds,
+ std::unique_ptr<Type>, AST::AttrVec outer_attrs)
+ : GenericParam (mappings), outer_attrs (std::move (outer_attrs)),
+ type_representation (std::move (type_representation)),
+ type_param_bounds (std::move (type_param_bounds)), type (std::move (type)),
+ locus (locus)
+{}
+
+TypeParam::TypeParam (TypeParam const &other)
+ : GenericParam (other.mappings), outer_attrs (other.outer_attrs),
+ type_representation (other.type_representation), locus (other.locus)
+{
+ // guard to prevent null pointer dereference
+ if (other.type != nullptr)
+ type = other.type->clone_type ();
+
+ type_param_bounds.reserve (other.type_param_bounds.size ());
+ for (const auto &e : other.type_param_bounds)
+ type_param_bounds.push_back (e->clone_type_param_bound ());
+}
+
+TypeParam &
+TypeParam::operator= (TypeParam const &other)
+{
+ type_representation = other.type_representation;
+ outer_attrs = other.outer_attrs;
+ locus = other.locus;
+ mappings = other.mappings;
+
+ // guard to prevent null pointer dereference
+ if (other.type != nullptr)
+ type = other.type->clone_type ();
+ else
+ type = nullptr;
+
+ type_param_bounds.reserve (other.type_param_bounds.size ());
+ for (const auto &e : other.type_param_bounds)
+ type_param_bounds.push_back (e->clone_type_param_bound ());
+
+ return *this;
+}
+
+Analysis::NodeMapping
+TypeParam::get_type_mappings () const
+{
+ rust_assert (type != nullptr);
+ return type->get_mappings ();
+}
+
+std::vector<std::unique_ptr<TypeParamBound>> &
+TypeParam::get_type_param_bounds ()
+{
+ return type_param_bounds;
+}
+
+TypeBoundWhereClauseItem::TypeBoundWhereClauseItem (
+ Analysis::NodeMapping mappings, std::vector<LifetimeParam> for_lifetimes,
+ std::unique_ptr<Type> bound_type,
+ std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds,
+ location_t locus)
+ : for_lifetimes (std::move (for_lifetimes)),
+ bound_type (std::move (bound_type)),
+ type_param_bounds (std::move (type_param_bounds)),
+ mappings (std::move (mappings)), locus (locus)
+{}
+
+TypeBoundWhereClauseItem::TypeBoundWhereClauseItem (
+ TypeBoundWhereClauseItem const &other)
+ : for_lifetimes (other.for_lifetimes),
+ bound_type (other.bound_type->clone_type ()), mappings (other.mappings)
+{
+ type_param_bounds.reserve (other.type_param_bounds.size ());
+ for (const auto &e : other.type_param_bounds)
+ type_param_bounds.push_back (e->clone_type_param_bound ());
+}
+
+TypeBoundWhereClauseItem &
+TypeBoundWhereClauseItem::operator= (TypeBoundWhereClauseItem const &other)
+{
+ mappings = other.mappings;
+ for_lifetimes = other.for_lifetimes;
+ bound_type = other.bound_type->clone_type ();
+ type_param_bounds.reserve (other.type_param_bounds.size ());
+ for (const auto &e : other.type_param_bounds)
+ type_param_bounds.push_back (e->clone_type_param_bound ());
+
+ return *this;
+}
+
+std::vector<std::unique_ptr<TypeParamBound>> &
+TypeBoundWhereClauseItem::get_type_param_bounds ()
+{
+ return type_param_bounds;
+}
+
+SelfParam::SelfParam (Analysis::NodeMapping mappings,
+ ImplicitSelfKind self_kind, Lifetime lifetime, Type *type)
+ : self_kind (self_kind), lifetime (std::move (lifetime)), type (type),
+ mappings (mappings)
+{}
+
+SelfParam::SelfParam (Analysis::NodeMapping mappings,
+ std::unique_ptr<Type> type, bool is_mut, location_t locus)
+ : self_kind (is_mut ? ImplicitSelfKind::MUT : ImplicitSelfKind::IMM),
+ lifetime (
+ Lifetime (mappings, AST::Lifetime::LifetimeType::NAMED, "", locus)),
+ type (std::move (type)), locus (locus), mappings (mappings)
+{}
+
+SelfParam::SelfParam (Analysis::NodeMapping mappings, Lifetime lifetime,
+ bool is_mut, location_t locus)
+ : self_kind (is_mut ? ImplicitSelfKind::MUT_REF : ImplicitSelfKind::IMM_REF),
+ lifetime (std::move (lifetime)), locus (locus), mappings (mappings)
+{}
+
+SelfParam::SelfParam (SelfParam const &other)
+ : self_kind (other.self_kind), lifetime (other.lifetime), locus (other.locus),
+ mappings (other.mappings)
+{
+ if (other.type != nullptr)
+ type = other.type->clone_type ();
+}
+
+SelfParam &
+SelfParam::operator= (SelfParam const &other)
+{
+ if (other.type != nullptr)
+ type = other.type->clone_type ();
+
+ self_kind = other.self_kind;
+ lifetime = other.lifetime;
+ locus = other.locus;
+ mappings = other.mappings;
+
+ return *this;
+}
+
+Mutability
+SelfParam::get_mut () const
+{
+ return (self_kind == ImplicitSelfKind::MUT
+ || self_kind == ImplicitSelfKind::MUT_REF)
+ ? Mutability::Mut
+ : Mutability::Imm;
+}
+
+bool
+SelfParam::is_mut () const
+{
+ return self_kind == ImplicitSelfKind::MUT
+ || self_kind == ImplicitSelfKind::MUT_REF;
+}
+
+bool
+SelfParam::is_ref () const
+{
+ return self_kind == ImplicitSelfKind::IMM_REF
+ || self_kind == ImplicitSelfKind::MUT_REF;
+}
+
+FunctionParam::FunctionParam (Analysis::NodeMapping mappings,
+ std::unique_ptr<Pattern> param_name,
+ std::unique_ptr<Type> param_type,
+ location_t locus)
+ : param_name (std::move (param_name)), type (std::move (param_type)),
+ locus (locus), mappings (mappings)
+{}
+
+FunctionParam::FunctionParam (FunctionParam const &other)
+ : param_name (other.param_name->clone_pattern ()),
+ type (other.type->clone_type ()), locus (other.locus),
+ mappings (other.mappings)
+{}
+
+FunctionParam &
+FunctionParam::operator= (FunctionParam const &other)
+{
+ param_name = other.param_name->clone_pattern ();
+ type = other.type->clone_type ();
+ locus = other.locus;
+ mappings = other.mappings;
+
+ return *this;
+}
+
+VisItem &
+VisItem::operator= (VisItem const &other)
+{
+ Item::operator= (other);
+ visibility = other.visibility;
+ // outer_attrs = other.outer_attrs;
+
+ return *this;
+}
+
+VisItem::VisItem (VisItem const &other)
+ : Item (other), visibility (other.visibility)
+{}
+
+Module::Module (Analysis::NodeMapping mappings, Identifier module_name,
+ location_t locus, std::vector<std::unique_ptr<Item>> items,
+ Visibility visibility, AST::AttrVec inner_attrs,
+ AST::AttrVec outer_attrs)
+ : VisItem (std::move (mappings), std::move (visibility),
+ std::move (outer_attrs)),
+ WithInnerAttrs (std::move (inner_attrs)), module_name (module_name),
+ locus (locus), items (std::move (items))
+{}
+
+Module::Module (Module const &other)
+ : VisItem (other), WithInnerAttrs (other.inner_attrs), module_name ("")
+{
+ items.reserve (other.items.size ());
+ for (const auto &e : other.items)
+ items.push_back (e->clone_item ());
+}
+
+Module &
+Module::operator= (Module const &other)
+{
+ VisItem::operator= (other);
+ inner_attrs = other.inner_attrs;
+
+ items.reserve (other.items.size ());
+ for (const auto &e : other.items)
+ items.push_back (e->clone_item ());
+
+ return *this;
+}
+
+Function::Function (Analysis::NodeMapping mappings, Identifier function_name,
+ FunctionQualifiers qualifiers,
+ std::vector<std::unique_ptr<GenericParam>> generic_params,
+ std::vector<FunctionParam> function_params,
+ std::unique_ptr<Type> return_type, WhereClause where_clause,
+ std::unique_ptr<BlockExpr> function_body, Visibility vis,
+ AST::AttrVec outer_attrs, SelfParam self, location_t locus)
+ : VisItem (std::move (mappings), std::move (vis), std::move (outer_attrs)),
+ qualifiers (std::move (qualifiers)),
+ function_name (std::move (function_name)),
+ generic_params (std::move (generic_params)),
+ function_params (std::move (function_params)),
+ return_type (std::move (return_type)),
+ where_clause (std::move (where_clause)),
+ function_body (std::move (function_body)), self (std::move (self)),
+ locus (locus)
+{}
+
+Function::Function (Function const &other)
+ : VisItem (other), qualifiers (other.qualifiers),
+ function_name (other.function_name),
+ function_params (other.function_params), where_clause (other.where_clause),
+ function_body (other.function_body->clone_block_expr ()), self (other.self),
+ locus (other.locus)
+{
+ // guard to prevent null dereference (always required)
+ if (other.return_type != nullptr)
+ return_type = other.return_type->clone_type ();
+ else
+ return_type = nullptr;
+
+ generic_params.reserve (other.generic_params.size ());
+ for (const auto &e : other.generic_params)
+ generic_params.push_back (e->clone_generic_param ());
+}
+
+Function &
+Function::operator= (Function const &other)
+{
+ VisItem::operator= (other);
+ function_name = other.function_name;
+ qualifiers = other.qualifiers;
+ function_params = other.function_params;
+
+ // guard to prevent null dereference (always required)
+ if (other.return_type != nullptr)
+ return_type = other.return_type->clone_type ();
+ else
+ return_type = nullptr;
+
+ where_clause = other.where_clause;
+ function_body = other.function_body->clone_block_expr ();
+ locus = other.locus;
+ self = other.self;
+
+ generic_params.reserve (other.generic_params.size ());
+ for (const auto &e : other.generic_params)
+ generic_params.push_back (e->clone_generic_param ());
+
+ return *this;
+}
+
+TypeAlias::TypeAlias (Analysis::NodeMapping mappings, Identifier new_type_name,
+ std::vector<std::unique_ptr<GenericParam>> generic_params,
+ WhereClause where_clause,
+ std::unique_ptr<Type> existing_type, Visibility vis,
+ AST::AttrVec outer_attrs, location_t locus)
+ : VisItem (std::move (mappings), std::move (vis), std::move (outer_attrs)),
+ new_type_name (std::move (new_type_name)),
+ generic_params (std::move (generic_params)),
+ where_clause (std::move (where_clause)),
+ existing_type (std::move (existing_type)), locus (locus)
+{}
+
+TypeAlias::TypeAlias (TypeAlias const &other)
+ : VisItem (other), new_type_name (other.new_type_name),
+ where_clause (other.where_clause),
+ existing_type (other.existing_type->clone_type ()), locus (other.locus)
+{
+ generic_params.reserve (other.generic_params.size ());
+ for (const auto &e : other.generic_params)
+ generic_params.push_back (e->clone_generic_param ());
+}
+
+TypeAlias &
+TypeAlias::operator= (TypeAlias const &other)
+{
+ VisItem::operator= (other);
+ new_type_name = other.new_type_name;
+ where_clause = other.where_clause;
+ existing_type = other.existing_type->clone_type ();
+ locus = other.locus;
+
+ generic_params.reserve (other.generic_params.size ());
+ for (const auto &e : other.generic_params)
+ generic_params.push_back (e->clone_generic_param ());
+
+ return *this;
+}
+
+StructField::StructField (Analysis::NodeMapping mappings, Identifier field_name,
+ std::unique_ptr<Type> field_type, Visibility vis,
+ location_t locus, AST::AttrVec outer_attrs)
+ : outer_attrs (std::move (outer_attrs)), visibility (std::move (vis)),
+ field_name (std::move (field_name)), field_type (std::move (field_type)),
+ mappings (mappings), locus (locus)
+{}
+
+StructField::StructField (StructField const &other)
+ : outer_attrs (other.outer_attrs), visibility (other.visibility),
+ field_name (other.field_name), field_type (other.field_type->clone_type ()),
+ mappings (other.mappings)
+{}
+
+StructField &
+StructField::operator= (StructField const &other)
+{
+ field_name = other.field_name;
+ field_type = other.field_type->clone_type ();
+ visibility = other.visibility;
+ outer_attrs = other.outer_attrs;
+ mappings = other.mappings;
+
+ return *this;
+}
+
+TupleField::TupleField (Analysis::NodeMapping mapping,
+ std::unique_ptr<Type> field_type, Visibility vis,
+ location_t locus, AST::AttrVec outer_attrs)
+ : outer_attrs (std::move (outer_attrs)), visibility (std::move (vis)),
+ field_type (std::move (field_type)), locus (locus), mappings (mapping)
+{}
+
+TupleField::TupleField (TupleField const &other)
+ : outer_attrs (other.outer_attrs), visibility (other.visibility),
+ field_type (other.field_type->clone_type ()), locus (other.locus),
+ mappings (other.mappings)
+{}
+
+TupleField &
+TupleField::operator= (TupleField const &other)
+{
+ field_type = other.field_type->clone_type ();
+ visibility = other.visibility;
+ outer_attrs = other.outer_attrs;
+ locus = other.locus;
+ mappings = other.mappings;
+
+ return *this;
+}
+
+TupleStruct::TupleStruct (
+ Analysis::NodeMapping mappings, std::vector<TupleField> fields,
+ Identifier struct_name,
+ std::vector<std::unique_ptr<GenericParam>> generic_params,
+ WhereClause where_clause, Visibility vis, AST::AttrVec outer_attrs,
+ location_t locus)
+ : Struct (std::move (mappings), std::move (struct_name),
+ std::move (generic_params), std::move (where_clause),
+ std::move (vis), locus, std::move (outer_attrs)),
+ fields (std::move (fields))
+{}
+
+EnumItem::EnumItem (Analysis::NodeMapping mappings, Identifier variant_name,
+ AST::AttrVec outer_attrs, location_t locus)
+ : Item (std::move (mappings), std::move (outer_attrs)),
+ variant_name (std::move (variant_name)), locus (locus)
+{}
+
+EnumItemTuple::EnumItemTuple (Analysis::NodeMapping mappings,
+ Identifier variant_name,
+ std::vector<TupleField> tuple_fields,
+ AST::AttrVec outer_attrs, location_t locus)
+ : EnumItem (std::move (mappings), std::move (variant_name),
+ std::move (outer_attrs), locus),
+ tuple_fields (std::move (tuple_fields))
+{}
+
+EnumItemStruct::EnumItemStruct (Analysis::NodeMapping mappings,
+ Identifier variant_name,
+ std::vector<StructField> struct_fields,
+ AST::AttrVec outer_attrs, location_t locus)
+ : EnumItem (std::move (mappings), std::move (variant_name),
+ std::move (outer_attrs), locus),
+ struct_fields (std::move (struct_fields))
+{}
+
+EnumItemDiscriminant::EnumItemDiscriminant (Analysis::NodeMapping mappings,
+ Identifier variant_name,
+ std::unique_ptr<Expr> expr,
+ AST::AttrVec outer_attrs,
+ location_t locus)
+ : EnumItem (std::move (mappings), std::move (variant_name),
+ std::move (outer_attrs), locus),
+ expression (std::move (expr))
+{}
+
+EnumItemDiscriminant::EnumItemDiscriminant (EnumItemDiscriminant const &other)
+ : EnumItem (other), expression (other.expression->clone_expr ())
+{}
+
+EnumItemDiscriminant &
+EnumItemDiscriminant::operator= (EnumItemDiscriminant const &other)
+{
+ EnumItem::operator= (other);
+ expression = other.expression->clone_expr ();
+ // variant_name = other.variant_name;
+ // outer_attrs = other.outer_attrs;
+
+ return *this;
+}
+
+Enum::Enum (Analysis::NodeMapping mappings, Identifier enum_name,
+ Visibility vis,
+ std::vector<std::unique_ptr<GenericParam>> generic_params,
+ WhereClause where_clause,
+ std::vector<std::unique_ptr<EnumItem>> items,
+ AST::AttrVec outer_attrs, location_t locus)
+ : VisItem (std::move (mappings), std::move (vis), std::move (outer_attrs)),
+ enum_name (std::move (enum_name)),
+ generic_params (std::move (generic_params)),
+ where_clause (std::move (where_clause)), items (std::move (items)),
+ locus (locus)
+{}
+
+Enum::Enum (Enum const &other)
+ : VisItem (other), enum_name (other.enum_name),
+ where_clause (other.where_clause), locus (other.locus)
+{
+ generic_params.reserve (other.generic_params.size ());
+ for (const auto &e : other.generic_params)
+ generic_params.push_back (e->clone_generic_param ());
+
+ items.reserve (other.items.size ());
+ for (const auto &e : other.items)
+ items.push_back (e->clone_enum_item ());
+}
+
+Enum &
+Enum::operator= (Enum const &other)
+{
+ VisItem::operator= (other);
+ enum_name = other.enum_name;
+ where_clause = other.where_clause;
+ locus = other.locus;
+
+ generic_params.reserve (other.generic_params.size ());
+ for (const auto &e : other.generic_params)
+ generic_params.push_back (e->clone_generic_param ());
+
+ items.reserve (other.items.size ());
+ for (const auto &e : other.items)
+ items.push_back (e->clone_enum_item ());
+
+ return *this;
+}
+
+Union::Union (Analysis::NodeMapping mappings, Identifier union_name,
+ Visibility vis,
+ std::vector<std::unique_ptr<GenericParam>> generic_params,
+ WhereClause where_clause, std::vector<StructField> variants,
+ AST::AttrVec outer_attrs, location_t locus)
+ : VisItem (std::move (mappings), std::move (vis), std::move (outer_attrs)),
+ union_name (std::move (union_name)),
+ generic_params (std::move (generic_params)),
+ where_clause (std::move (where_clause)), variants (std::move (variants)),
+ locus (locus)
+{}
+
+Union::Union (Union const &other)
+ : VisItem (other), union_name (other.union_name),
+ where_clause (other.where_clause), variants (other.variants),
+ locus (other.locus)
+{
+ generic_params.reserve (other.generic_params.size ());
+ for (const auto &e : other.generic_params)
+ generic_params.push_back (e->clone_generic_param ());
+}
+
+Union &
+Union::operator= (Union const &other)
+{
+ VisItem::operator= (other);
+ union_name = other.union_name;
+ where_clause = other.where_clause;
+ variants = other.variants;
+ locus = other.locus;
+
+ generic_params.reserve (other.generic_params.size ());
+ for (const auto &e : other.generic_params)
+ generic_params.push_back (e->clone_generic_param ());
+
+ return *this;
+}
+
+ConstantItem::ConstantItem (Analysis::NodeMapping mappings, Identifier ident,
+ Visibility vis, std::unique_ptr<Type> type,
+ std::unique_ptr<Expr> const_expr,
+ AST::AttrVec outer_attrs, location_t locus)
+ : VisItem (std::move (mappings), std::move (vis), std::move (outer_attrs)),
+ identifier (std::move (ident)), type (std::move (type)),
+ const_expr (std::move (const_expr)), locus (locus)
+{}
+
+ConstantItem::ConstantItem (ConstantItem const &other)
+ : VisItem (other), identifier (other.identifier),
+ type (other.type->clone_type ()),
+ const_expr (other.const_expr->clone_expr ()), locus (other.locus)
+{}
+
+ConstantItem &
+ConstantItem::operator= (ConstantItem const &other)
+{
+ VisItem::operator= (other);
+ identifier = other.identifier;
+ type = other.type->clone_type ();
+ const_expr = other.const_expr->clone_expr ();
+ locus = other.locus;
+
+ return *this;
+}
+
+StaticItem::StaticItem (Analysis::NodeMapping mappings, Identifier name,
+ Mutability mut, std::unique_ptr<Type> type,
+ std::unique_ptr<Expr> expr, Visibility vis,
+ AST::AttrVec outer_attrs, location_t locus)
+ : VisItem (std::move (mappings), std::move (vis), std::move (outer_attrs)),
+ mut (mut), name (std::move (name)), type (std::move (type)),
+ expr (std::move (expr)), locus (locus)
+{}
+
+StaticItem::StaticItem (StaticItem const &other)
+ : VisItem (other), mut (other.mut), name (other.name),
+ type (other.type->clone_type ()), expr (other.expr->clone_expr ()),
+ locus (other.locus)
+{}
+
+StaticItem &
+StaticItem::operator= (StaticItem const &other)
+{
+ VisItem::operator= (other);
+ name = other.name;
+ mut = other.mut;
+ type = other.type->clone_type ();
+ expr = other.expr->clone_expr ();
+ locus = other.locus;
+
+ return *this;
+}
+
+TraitFunctionDecl::TraitFunctionDecl (
+ Identifier function_name, FunctionQualifiers qualifiers,
+ std::vector<std::unique_ptr<GenericParam>> generic_params, SelfParam self,
+ std::vector<FunctionParam> function_params, std::unique_ptr<Type> return_type,
+ WhereClause where_clause)
+ : qualifiers (std::move (qualifiers)),
+ function_name (std::move (function_name)),
+ generic_params (std::move (generic_params)),
+ function_params (std::move (function_params)),
+ return_type (std::move (return_type)),
+ where_clause (std::move (where_clause)), self (std::move (self))
+{}
+
+TraitFunctionDecl::TraitFunctionDecl (TraitFunctionDecl const &other)
+ : qualifiers (other.qualifiers), function_name (other.function_name),
+ function_params (other.function_params),
+ return_type (other.return_type->clone_type ()),
+ where_clause (other.where_clause), self (other.self)
+{
+ generic_params.reserve (other.generic_params.size ());
+ for (const auto &e : other.generic_params)
+ generic_params.push_back (e->clone_generic_param ());
+}
+
+TraitFunctionDecl &
+TraitFunctionDecl::operator= (TraitFunctionDecl const &other)
+{
+ function_name = other.function_name;
+ qualifiers = other.qualifiers;
+ function_params = other.function_params;
+ return_type = other.return_type->clone_type ();
+ where_clause = other.where_clause;
+ self = other.self;
+
+ generic_params.reserve (other.generic_params.size ());
+ for (const auto &e : other.generic_params)
+ generic_params.push_back (e->clone_generic_param ());
+
+ return *this;
+}
+
+TraitItemFunc::TraitItemFunc (Analysis::NodeMapping mappings,
+ TraitFunctionDecl decl,
+ std::unique_ptr<BlockExpr> block_expr,
+ AST::AttrVec outer_attrs, location_t locus)
+ : TraitItem (mappings), outer_attrs (std::move (outer_attrs)),
+ decl (std::move (decl)), block_expr (std::move (block_expr)), locus (locus)
+{}
+
+TraitItemFunc::TraitItemFunc (TraitItemFunc const &other)
+ : TraitItem (other.mappings), outer_attrs (other.outer_attrs),
+ decl (other.decl), locus (other.locus)
+{
+ if (other.block_expr != nullptr)
+ block_expr = other.block_expr->clone_block_expr ();
+}
+
+TraitItemFunc &
+TraitItemFunc::operator= (TraitItemFunc const &other)
+{
+ TraitItem::operator= (other);
+ outer_attrs = other.outer_attrs;
+ decl = other.decl;
+ locus = other.locus;
+ mappings = other.mappings;
+ if (other.block_expr != nullptr)
+ block_expr = other.block_expr->clone_block_expr ();
+
+ return *this;
+}
+
+TraitItemConst::TraitItemConst (Analysis::NodeMapping mappings, Identifier name,
+ std::unique_ptr<Type> type,
+ std::unique_ptr<Expr> expr,
+ AST::AttrVec outer_attrs, location_t locus)
+ : TraitItem (mappings), outer_attrs (std::move (outer_attrs)),
+ name (std::move (name)), type (std::move (type)), expr (std::move (expr)),
+ locus (locus)
+{}
+
+TraitItemConst::TraitItemConst (TraitItemConst const &other)
+ : TraitItem (other.mappings), outer_attrs (other.outer_attrs),
+ name (other.name), type (other.type->clone_type ()),
+ expr (other.expr->clone_expr ()), locus (other.locus)
+{}
+
+TraitItemConst &
+TraitItemConst::operator= (TraitItemConst const &other)
+{
+ TraitItem::operator= (other);
+ outer_attrs = other.outer_attrs;
+ name = other.name;
+ type = other.type->clone_type ();
+ expr = other.expr->clone_expr ();
+ locus = other.locus;
+ mappings = other.mappings;
+
+ return *this;
+}
+
+TraitItemType::TraitItemType (
+ Analysis::NodeMapping mappings, Identifier name,
+ std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds,
+ AST::AttrVec outer_attrs, location_t locus)
+ : TraitItem (mappings), outer_attrs (std::move (outer_attrs)),
+ name (std::move (name)), type_param_bounds (std::move (type_param_bounds)),
+ locus (locus)
+{}
+
+TraitItemType::TraitItemType (TraitItemType const &other)
+ : TraitItem (other.mappings), outer_attrs (other.outer_attrs),
+ name (other.name), locus (other.locus)
+{
+ type_param_bounds.reserve (other.type_param_bounds.size ());
+ for (const auto &e : other.type_param_bounds)
+ type_param_bounds.push_back (e->clone_type_param_bound ());
+}
+
+TraitItemType &
+TraitItemType::operator= (TraitItemType const &other)
+{
+ TraitItem::operator= (other);
+ outer_attrs = other.outer_attrs;
+ name = other.name;
+ locus = other.locus;
+ mappings = other.mappings;
+
+ type_param_bounds.reserve (other.type_param_bounds.size ());
+ for (const auto &e : other.type_param_bounds)
+ type_param_bounds.push_back (e->clone_type_param_bound ());
+
+ return *this;
+}
+
+Trait::Trait (Analysis::NodeMapping mappings, Identifier name,
+ Unsafety unsafety,
+ std::vector<std::unique_ptr<GenericParam>> generic_params,
+ std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds,
+ WhereClause where_clause,
+ std::vector<std::unique_ptr<TraitItem>> trait_items,
+ Visibility vis, AST::AttrVec outer_attrs, location_t locus)
+ : VisItem (std::move (mappings), std::move (vis), std::move (outer_attrs)),
+ unsafety (unsafety), name (std::move (name)),
+ generic_params (std::move (generic_params)),
+ type_param_bounds (std::move (type_param_bounds)),
+ where_clause (std::move (where_clause)),
+ trait_items (std::move (trait_items)), locus (locus)
+{}
+
+Trait::Trait (Trait const &other)
+ : VisItem (other), unsafety (other.unsafety), name (other.name),
+ where_clause (other.where_clause), locus (other.locus)
+{
+ generic_params.reserve (other.generic_params.size ());
+ for (const auto &e : other.generic_params)
+ generic_params.push_back (e->clone_generic_param ());
+
+ type_param_bounds.reserve (other.type_param_bounds.size ());
+ for (const auto &e : other.type_param_bounds)
+ type_param_bounds.push_back (e->clone_type_param_bound ());
+
+ trait_items.reserve (other.trait_items.size ());
+ for (const auto &e : other.trait_items)
+ trait_items.push_back (e->clone_trait_item ());
+}
+
+Trait &
+Trait::operator= (Trait const &other)
+{
+ VisItem::operator= (other);
+ name = other.name;
+ unsafety = other.unsafety;
+ where_clause = other.where_clause;
+ locus = other.locus;
+
+ generic_params.reserve (other.generic_params.size ());
+ for (const auto &e : other.generic_params)
+ generic_params.push_back (e->clone_generic_param ());
+
+ type_param_bounds.reserve (other.type_param_bounds.size ());
+ for (const auto &e : other.type_param_bounds)
+ type_param_bounds.push_back (e->clone_type_param_bound ());
+
+ trait_items.reserve (other.trait_items.size ());
+ for (const auto &e : other.trait_items)
+ trait_items.push_back (e->clone_trait_item ());
+
+ return *this;
+}
+
+ImplBlock::ImplBlock (Analysis::NodeMapping mappings,
+ std::vector<std::unique_ptr<ImplItem>> impl_items,
+ std::vector<std::unique_ptr<GenericParam>> generic_params,
+ std::unique_ptr<Type> impl_type,
+ std::unique_ptr<TypePath> trait_ref,
+ WhereClause where_clause, BoundPolarity polarity,
+ Visibility vis, AST::AttrVec inner_attrs,
+ AST::AttrVec outer_attrs, location_t locus, bool unsafe)
+ : VisItem (std::move (mappings), std::move (vis), std::move (outer_attrs)),
+ WithInnerAttrs (std::move (inner_attrs)),
+ generic_params (std::move (generic_params)),
+ impl_type (std::move (impl_type)), trait_ref (std::move (trait_ref)),
+ where_clause (std::move (where_clause)), polarity (polarity), locus (locus),
+ impl_items (std::move (impl_items)), unsafe (unsafe)
+{}
+
+ImplBlock::ImplBlock (ImplBlock const &other)
+ : VisItem (other), WithInnerAttrs (other.inner_attrs),
+ impl_type (other.impl_type->clone_type ()),
+ where_clause (other.where_clause), polarity (other.polarity),
+ locus (other.locus), unsafe (other.unsafe)
+{
+ generic_params.reserve (other.generic_params.size ());
+ for (const auto &e : other.generic_params)
+ generic_params.push_back (e->clone_generic_param ());
+
+ impl_items.reserve (other.impl_items.size ());
+ for (const auto &e : other.impl_items)
+ impl_items.push_back (e->clone_inherent_impl_item ());
+}
+
+ImplBlock &
+ImplBlock::operator= (ImplBlock const &other)
+{
+ VisItem::operator= (other);
+ impl_type = other.impl_type->clone_type ();
+ where_clause = other.where_clause;
+ polarity = other.polarity;
+ inner_attrs = other.inner_attrs;
+ locus = other.locus;
+ unsafe = other.unsafe;
+
+ generic_params.reserve (other.generic_params.size ());
+ for (const auto &e : other.generic_params)
+ generic_params.push_back (e->clone_generic_param ());
+
+ impl_items.reserve (other.impl_items.size ());
+ for (const auto &e : other.impl_items)
+ impl_items.push_back (e->clone_inherent_impl_item ());
+
+ return *this;
+}
+
+ExternalItem::ExternalItem (Analysis::NodeMapping mappings,
+ Identifier item_name, Visibility vis,
+ AST::AttrVec outer_attrs, location_t locus)
+ : mappings (mappings), outer_attrs (std::move (outer_attrs)),
+ visibility (std::move (vis)), item_name (std::move (item_name)),
+ locus (locus)
+{}
+
+ExternalItem::ExternalItem (ExternalItem const &other)
+ : mappings (other.mappings), outer_attrs (other.outer_attrs),
+ visibility (other.visibility), item_name (other.item_name),
+ locus (other.locus)
+{}
+
+ExternalItem &
+ExternalItem::operator= (ExternalItem const &other)
+{
+ mappings = other.mappings;
+ item_name = other.item_name;
+ visibility = other.visibility;
+ outer_attrs = other.outer_attrs;
+ locus = other.locus;
+
+ return *this;
+}
+
+ExternalStaticItem::ExternalStaticItem (Analysis::NodeMapping mappings,
+ Identifier item_name,
+ std::unique_ptr<Type> item_type,
+ Mutability mut, Visibility vis,
+ AST::AttrVec outer_attrs,
+ location_t locus)
+ : ExternalItem (std::move (mappings), std::move (item_name), std::move (vis),
+ std::move (outer_attrs), locus),
+ mut (mut), item_type (std::move (item_type))
+{}
+
+ExternalStaticItem::ExternalStaticItem (ExternalStaticItem const &other)
+ : ExternalItem (other), mut (other.mut),
+ item_type (other.item_type->clone_type ())
+{}
+
+ExternalStaticItem &
+ExternalStaticItem::operator= (ExternalStaticItem const &other)
+{
+ ExternalItem::operator= (other);
+ item_type = other.item_type->clone_type ();
+ mut = other.mut;
+
+ return *this;
+}
+
+NamedFunctionParam::NamedFunctionParam (Analysis::NodeMapping mappings,
+ Identifier name,
+ std::unique_ptr<Type> param_type)
+ : name (std::move (name)), param_type (std::move (param_type)),
+ mappings (std::move (mappings))
+{}
+
+NamedFunctionParam::NamedFunctionParam (NamedFunctionParam const &other)
+ : name (other.name), param_type (other.param_type->clone_type ()),
+ mappings (other.mappings)
+{}
+
+NamedFunctionParam &
+NamedFunctionParam::operator= (NamedFunctionParam const &other)
+{
+ mappings = other.mappings;
+ name = other.name;
+ param_type = other.param_type->clone_type ();
+ // has_name = other.has_name;
+
+ return *this;
+}
+
+ExternalFunctionItem::ExternalFunctionItem (
+ Analysis::NodeMapping mappings, Identifier item_name,
+ std::vector<std::unique_ptr<GenericParam>> generic_params,
+ std::unique_ptr<Type> return_type, WhereClause where_clause,
+ std::vector<NamedFunctionParam> function_params, bool has_variadics,
+ Visibility vis, AST::AttrVec outer_attrs, location_t locus)
+ : ExternalItem (std::move (mappings), std::move (item_name), std::move (vis),
+ std::move (outer_attrs), locus),
+ generic_params (std::move (generic_params)),
+ return_type (std::move (return_type)),
+ where_clause (std::move (where_clause)),
+ function_params (std::move (function_params)), has_variadics (has_variadics)
+{}
+
+ExternalFunctionItem::ExternalFunctionItem (ExternalFunctionItem const &other)
+ : ExternalItem (other), where_clause (other.where_clause),
+ function_params (other.function_params), has_variadics (other.has_variadics)
+{
+ if (other.return_type)
+ return_type = other.return_type->clone_type ();
+
+ generic_params.reserve (other.generic_params.size ());
+ for (const auto &e : other.generic_params)
+ generic_params.push_back (e->clone_generic_param ());
+}
+
+ExternalFunctionItem &
+ExternalFunctionItem::operator= (ExternalFunctionItem const &other)
+{
+ ExternalItem::operator= (other);
+
+ where_clause = other.where_clause;
+ function_params = other.function_params;
+ has_variadics = other.has_variadics;
+
+ if (other.return_type)
+ return_type = other.return_type->clone_type ();
+
+ generic_params.reserve (other.generic_params.size ());
+ for (const auto &e : other.generic_params)
+ generic_params.push_back (e->clone_generic_param ());
+
+ return *this;
+}
+
+ExternalTypeItem::ExternalTypeItem (Analysis::NodeMapping mappings,
+ Identifier item_name, Visibility vis,
+ location_t locus)
+ : ExternalItem (std::move (mappings), std::move (item_name),
+ Visibility (std::move (vis)),
+ /* FIXME: Is that correct? */
+ {}, locus)
+{}
+
+ExternalTypeItem::ExternalTypeItem (ExternalTypeItem const &other)
+ : ExternalItem (other)
+{}
+
+ExternBlock::ExternBlock (
+ Analysis::NodeMapping mappings, ABI abi,
+ std::vector<std::unique_ptr<ExternalItem>> extern_items, Visibility vis,
+ AST::AttrVec inner_attrs, AST::AttrVec outer_attrs, location_t locus)
+ : VisItem (std::move (mappings), std::move (vis), std::move (outer_attrs)),
+ WithInnerAttrs (std::move (inner_attrs)), abi (abi),
+ extern_items (std::move (extern_items)), locus (locus)
+{}
+
+ExternBlock::ExternBlock (ExternBlock const &other)
+ : VisItem (other), WithInnerAttrs (other.inner_attrs), abi (other.abi),
+ locus (other.locus)
+{
+ extern_items.reserve (other.extern_items.size ());
+ for (const auto &e : other.extern_items)
+ extern_items.push_back (e->clone_external_item ());
+}
+
+ExternBlock &
+ExternBlock::operator= (ExternBlock const &other)
+{
+ VisItem::operator= (other);
+ abi = other.abi;
+ inner_attrs = other.inner_attrs;
+ locus = other.locus;
+
+ extern_items.reserve (other.extern_items.size ());
+ for (const auto &e : other.extern_items)
+ extern_items.push_back (e->clone_external_item ());
+
+ return *this;
+}
+
+} // namespace HIR
+} // namespace Rust
diff --git a/gcc/rust/hir/tree/rust-hir-item.h b/gcc/rust/hir/tree/rust-hir-item.h
index 7001466ade6..39097ceacae 100644
--- a/gcc/rust/hir/tree/rust-hir-item.h
+++ b/gcc/rust/hir/tree/rust-hir-item.h
@@ -20,17 +20,74 @@
#define RUST_HIR_ITEM_H
#include "rust-abi.h"
-#include "rust-ast-full-decls.h"
+#include "rust-hir-stmt.h"
#include "rust-common.h"
-#include "rust-hir-expr.h"
-#include "rust-hir.h"
-#include "rust-hir-path.h"
+#include "rust-hir-visibility.h"
+#include "rust-hir-generic-param.h"
namespace Rust {
namespace HIR {
-// forward decls
-class BlockExpr;
-class TypePath;
+
+// Rust "item" HIR node (declaration of top-level/module-level allowed stuff)
+class Item : public Stmt, public WithOuterAttrs
+{
+ // TODO: should outer attrs be defined here or in each derived class?
+public:
+ enum class ItemKind
+ {
+ Static,
+ Constant,
+ TypeAlias,
+ Function,
+ UseDeclaration,
+ ExternBlock,
+ ExternCrate,
+ Struct,
+ Union,
+ Enum,
+ EnumItem, // FIXME: ARTHUR: Do we need that?
+ Trait,
+ Impl,
+ Module,
+ };
+
+ static std::string item_kind_string (ItemKind kind);
+
+ virtual ItemKind get_item_kind () const = 0;
+
+ // Unique pointer custom clone function
+ std::unique_ptr<Item> clone_item () const
+ {
+ return std::unique_ptr<Item> (clone_item_impl ());
+ }
+
+ BaseKind get_hir_kind () override { return Node::BaseKind::ITEM; }
+
+ std::string as_string () const override;
+
+ /* Adds crate names to the vector passed by reference, if it can
+ * (polymorphism). */
+ virtual void
+ add_crate_name (std::vector<std::string> &names ATTRIBUTE_UNUSED) const
+ {}
+
+ bool is_item () const override final { return true; }
+
+protected:
+ // Constructor
+ Item (Analysis::NodeMapping mappings,
+ AST::AttrVec outer_attribs = AST::AttrVec ())
+ : Stmt (std::move (mappings)), WithOuterAttrs (std::move (outer_attribs))
+ {}
+
+ // Clone function implementation as pure virtual method
+ virtual Item *clone_item_impl () const = 0;
+
+ /* Save having to specify two clone methods in derived classes by making
+ * statement clone return item clone. Hopefully won't affect performance too
+ * much. */
+ Item *clone_stmt_impl () const override { return clone_item_impl (); }
+};
// A type generic parameter (as opposed to a lifetime generic parameter)
class TypeParam : public GenericParam
@@ -65,47 +122,13 @@ public:
std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds
= std::vector<std::unique_ptr<TypeParamBound>> (),
std::unique_ptr<Type> type = nullptr,
- AST::AttrVec outer_attrs = std::vector<AST::Attribute> ())
- : GenericParam (mappings), outer_attrs (std::move (outer_attrs)),
- type_representation (std::move (type_representation)),
- type_param_bounds (std::move (type_param_bounds)),
- type (std::move (type)), locus (locus)
- {}
+ AST::AttrVec outer_attrs = std::vector<AST::Attribute> ());
// Copy constructor uses clone
- TypeParam (TypeParam const &other)
- : GenericParam (other.mappings), outer_attrs (other.outer_attrs),
- type_representation (other.type_representation), locus (other.locus)
- {
- // guard to prevent null pointer dereference
- if (other.type != nullptr)
- type = other.type->clone_type ();
-
- type_param_bounds.reserve (other.type_param_bounds.size ());
- for (const auto &e : other.type_param_bounds)
- type_param_bounds.push_back (e->clone_type_param_bound ());
- }
+ TypeParam (TypeParam const &other);
// Overloaded assignment operator to clone
- TypeParam &operator= (TypeParam const &other)
- {
- type_representation = other.type_representation;
- outer_attrs = other.outer_attrs;
- locus = other.locus;
- mappings = other.mappings;
-
- // guard to prevent null pointer dereference
- if (other.type != nullptr)
- type = other.type->clone_type ();
- else
- type = nullptr;
-
- type_param_bounds.reserve (other.type_param_bounds.size ());
- for (const auto &e : other.type_param_bounds)
- type_param_bounds.push_back (e->clone_type_param_bound ());
-
- return *this;
- }
+ TypeParam &operator= (TypeParam const &other);
// move constructors
TypeParam (TypeParam &&other) = default;
TypeParam &operator= (TypeParam &&other) = default;
@@ -120,16 +143,9 @@ public:
Type &get_type () { return *type; }
- Analysis::NodeMapping get_type_mappings () const
- {
- rust_assert (type != nullptr);
- return type->get_mappings ();
- }
+ Analysis::NodeMapping get_type_mappings () const;
- std::vector<std::unique_ptr<TypeParamBound>> &get_type_param_bounds ()
- {
- return type_param_bounds;
- }
+ std::vector<std::unique_ptr<TypeParamBound>> &get_type_param_bounds ();
protected:
// Clone function implementation as (not pure) virtual method
@@ -234,35 +250,13 @@ public:
Analysis::NodeMapping mappings, std::vector<LifetimeParam> for_lifetimes,
std::unique_ptr<Type> bound_type,
std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds,
- location_t locus)
- : for_lifetimes (std::move (for_lifetimes)),
- bound_type (std::move (bound_type)),
- type_param_bounds (std::move (type_param_bounds)),
- mappings (std::move (mappings)), locus (locus)
- {}
+ location_t locus);
// Copy constructor requires clone
- TypeBoundWhereClauseItem (TypeBoundWhereClauseItem const &other)
- : for_lifetimes (other.for_lifetimes),
- bound_type (other.bound_type->clone_type ()), mappings (other.mappings)
- {
- type_param_bounds.reserve (other.type_param_bounds.size ());
- for (const auto &e : other.type_param_bounds)
- type_param_bounds.push_back (e->clone_type_param_bound ());
- }
+ TypeBoundWhereClauseItem (TypeBoundWhereClauseItem const &other);
// Overload assignment operator to clone
- TypeBoundWhereClauseItem &operator= (TypeBoundWhereClauseItem const &other)
- {
- mappings = other.mappings;
- for_lifetimes = other.for_lifetimes;
- bound_type = other.bound_type->clone_type ();
- type_param_bounds.reserve (other.type_param_bounds.size ());
- for (const auto &e : other.type_param_bounds)
- type_param_bounds.push_back (e->clone_type_param_bound ());
-
- return *this;
- }
+ TypeBoundWhereClauseItem &operator= (TypeBoundWhereClauseItem const &other);
// move constructors
TypeBoundWhereClauseItem (TypeBoundWhereClauseItem &&other) = default;
@@ -279,10 +273,7 @@ public:
Type &get_bound_type () { return *bound_type; }
- std::vector<std::unique_ptr<TypeParamBound>> &get_type_param_bounds ()
- {
- return type_param_bounds;
- }
+ std::vector<std::unique_ptr<TypeParamBound>> &get_type_param_bounds ();
Analysis::NodeMapping get_mappings () const override final
{
@@ -379,51 +370,22 @@ private:
Analysis::NodeMapping mappings;
SelfParam (Analysis::NodeMapping mappings, ImplicitSelfKind self_kind,
- Lifetime lifetime, Type *type)
- : self_kind (self_kind), lifetime (std::move (lifetime)), type (type),
- mappings (mappings)
- {}
+ Lifetime lifetime, Type *type);
public:
// Type-based self parameter (not ref, no lifetime)
SelfParam (Analysis::NodeMapping mappings, std::unique_ptr<Type> type,
- bool is_mut, location_t locus)
- : self_kind (is_mut ? ImplicitSelfKind::MUT : ImplicitSelfKind::IMM),
- lifetime (
- Lifetime (mappings, AST::Lifetime::LifetimeType::NAMED, "", locus)),
- type (std::move (type)), locus (locus), mappings (mappings)
- {}
+ bool is_mut, location_t locus);
// Lifetime-based self parameter (is ref, no type)
SelfParam (Analysis::NodeMapping mappings, Lifetime lifetime, bool is_mut,
- location_t locus)
- : self_kind (is_mut ? ImplicitSelfKind::MUT_REF
- : ImplicitSelfKind::IMM_REF),
- lifetime (std::move (lifetime)), locus (locus), mappings (mappings)
- {}
+ location_t locus);
// Copy constructor requires clone
- SelfParam (SelfParam const &other)
- : self_kind (other.self_kind), lifetime (other.lifetime),
- locus (other.locus), mappings (other.mappings)
- {
- if (other.type != nullptr)
- type = other.type->clone_type ();
- }
+ SelfParam (SelfParam const &other);
// Overload assignment operator to use clone
- SelfParam &operator= (SelfParam const &other)
- {
- if (other.type != nullptr)
- type = other.type->clone_type ();
-
- self_kind = other.self_kind;
- lifetime = other.lifetime;
- locus = other.locus;
- mappings = other.mappings;
-
- return *this;
- }
+ SelfParam &operator= (SelfParam const &other);
// move constructors
SelfParam (SelfParam &&other) = default;
@@ -456,25 +418,11 @@ public:
Analysis::NodeMapping get_mappings () { return mappings; }
- Mutability get_mut () const
- {
- return (self_kind == ImplicitSelfKind::MUT
- || self_kind == ImplicitSelfKind::MUT_REF)
- ? Mutability::Mut
- : Mutability::Imm;
- }
+ Mutability get_mut () const;
- bool is_mut () const
- {
- return self_kind == ImplicitSelfKind::MUT
- || self_kind == ImplicitSelfKind::MUT_REF;
- }
+ bool is_mut () const;
- bool is_ref () const
- {
- return self_kind == ImplicitSelfKind::IMM_REF
- || self_kind == ImplicitSelfKind::MUT_REF;
- }
+ bool is_ref () const;
};
// Qualifiers for function, i.e. const, unsafe, extern etc.
@@ -516,28 +464,13 @@ struct FunctionParam
public:
FunctionParam (Analysis::NodeMapping mappings,
std::unique_ptr<Pattern> param_name,
- std::unique_ptr<Type> param_type, location_t locus)
- : param_name (std::move (param_name)), type (std::move (param_type)),
- locus (locus), mappings (mappings)
- {}
+ std::unique_ptr<Type> param_type, location_t locus);
// Copy constructor uses clone
- FunctionParam (FunctionParam const &other)
- : param_name (other.param_name->clone_pattern ()),
- type (other.type->clone_type ()), locus (other.locus),
- mappings (other.mappings)
- {}
+ FunctionParam (FunctionParam const &other);
// Overload assignment operator to use clone
- FunctionParam &operator= (FunctionParam const &other)
- {
- param_name = other.param_name->clone_pattern ();
- type = other.type->clone_type ();
- locus = other.locus;
- mappings = other.mappings;
-
- return *this;
- }
+ FunctionParam &operator= (FunctionParam const &other);
// move constructors
FunctionParam (FunctionParam &&other) = default;
@@ -554,58 +487,6 @@ public:
const Analysis::NodeMapping &get_mappings () const { return mappings; }
};
-// Visibility of an item
-struct Visibility
-{
-public:
- enum VisType
- {
- PRIVATE,
- PUBLIC,
- RESTRICTED,
- ERROR,
- };
-
-private:
- VisType vis_type;
- HIR::SimplePath path;
- location_t locus;
-
- // should this store location info?
-
-public:
- Visibility (VisType vis_type,
- HIR::SimplePath path = HIR::SimplePath::create_empty (),
- location_t locus = UNDEF_LOCATION)
- : vis_type (vis_type), path (std::move (path)), locus (locus)
- {}
-
- // Returns whether visibility is in an error state.
- bool is_error () const { return vis_type == ERROR; }
-
- // Does the current visibility refer to a simple `pub <item>` entirely public
- bool is_public () const { return vis_type == PUBLIC; }
-
- // Is the current visibility public restricted to a certain path
- bool is_restricted () const { return vis_type == RESTRICTED; }
-
- // Creates an error visibility.
- static Visibility create_error ()
- {
- return Visibility (ERROR, HIR::SimplePath::create_empty ());
- }
-
- VisType get_vis_type () const { return vis_type; }
-
- const HIR::SimplePath &get_path () const
- {
- rust_assert (!is_error ());
- return path;
- }
-
- std::string as_string () const;
-};
-
// Item that supports visibility - abstract base class
class VisItem : public Item
{
@@ -620,18 +501,10 @@ protected:
{}
// Visibility copy constructor
- VisItem (VisItem const &other) : Item (other), visibility (other.visibility)
- {}
+ VisItem (VisItem const &other);
// Overload assignment operator to clone
- VisItem &operator= (VisItem const &other)
- {
- Item::operator= (other);
- visibility = other.visibility;
- // outer_attrs = other.outer_attrs;
-
- return *this;
- }
+ VisItem &operator= (VisItem const &other);
// move constructors
VisItem (VisItem &&other) = default;
@@ -673,34 +546,13 @@ public:
location_t locus, std::vector<std::unique_ptr<Item>> items,
Visibility visibility = Visibility::create_error (),
AST::AttrVec inner_attrs = AST::AttrVec (),
- AST::AttrVec outer_attrs = AST::AttrVec ())
- : VisItem (std::move (mappings), std::move (visibility),
- std::move (outer_attrs)),
- WithInnerAttrs (std::move (inner_attrs)), module_name (module_name),
- locus (locus), items (std::move (items))
- {}
+ AST::AttrVec outer_attrs = AST::AttrVec ());
// Copy constructor with vector clone
- Module (Module const &other)
- : VisItem (other), WithInnerAttrs (other.inner_attrs), module_name ("")
- {
- items.reserve (other.items.size ());
- for (const auto &e : other.items)
- items.push_back (e->clone_item ());
- }
+ Module (Module const &other);
// Overloaded assignment operator with vector clone
- Module &operator= (Module const &other)
- {
- VisItem::operator= (other);
- inner_attrs = other.inner_attrs;
-
- items.reserve (other.items.size ());
- for (const auto &e : other.items)
- items.push_back (e->clone_item ());
-
- return *this;
- }
+ Module &operator= (Module const &other);
// move constructors
Module (Module &&other) = default;
@@ -1120,63 +972,13 @@ public:
std::vector<FunctionParam> function_params,
std::unique_ptr<Type> return_type, WhereClause where_clause,
std::unique_ptr<BlockExpr> function_body, Visibility vis,
- AST::AttrVec outer_attrs, SelfParam self, location_t locus)
- : VisItem (std::move (mappings), std::move (vis), std::move (outer_attrs)),
- qualifiers (std::move (qualifiers)),
- function_name (std::move (function_name)),
- generic_params (std::move (generic_params)),
- function_params (std::move (function_params)),
- return_type (std::move (return_type)),
- where_clause (std::move (where_clause)),
- function_body (std::move (function_body)), self (std::move (self)),
- locus (locus)
- {}
+ AST::AttrVec outer_attrs, SelfParam self, location_t locus);
// Copy constructor with clone
- Function (Function const &other)
- : VisItem (other), qualifiers (other.qualifiers),
- function_name (other.function_name),
- function_params (other.function_params),
- where_clause (other.where_clause),
- function_body (other.function_body->clone_block_expr ()),
- self (other.self), locus (other.locus)
- {
- // guard to prevent null dereference (always required)
- if (other.return_type != nullptr)
- return_type = other.return_type->clone_type ();
- else
- return_type = nullptr;
-
- generic_params.reserve (other.generic_params.size ());
- for (const auto &e : other.generic_params)
- generic_params.push_back (e->clone_generic_param ());
- }
+ Function (Function const &other);
// Overloaded assignment operator to clone
- Function &operator= (Function const &other)
- {
- VisItem::operator= (other);
- function_name = other.function_name;
- qualifiers = other.qualifiers;
- function_params = other.function_params;
-
- // guard to prevent null dereference (always required)
- if (other.return_type != nullptr)
- return_type = other.return_type->clone_type ();
- else
- return_type = nullptr;
-
- where_clause = other.where_clause;
- function_body = other.function_body->clone_block_expr ();
- locus = other.locus;
- self = other.self;
-
- generic_params.reserve (other.generic_params.size ());
- for (const auto &e : other.generic_params)
- generic_params.push_back (e->clone_generic_param ());
-
- return *this;
- }
+ Function &operator= (Function const &other);
// move constructors
Function (Function &&other) = default;
@@ -1280,40 +1082,13 @@ public:
TypeAlias (Analysis::NodeMapping mappings, Identifier new_type_name,
std::vector<std::unique_ptr<GenericParam>> generic_params,
WhereClause where_clause, std::unique_ptr<Type> existing_type,
- Visibility vis, AST::AttrVec outer_attrs, location_t locus)
- : VisItem (std::move (mappings), std::move (vis), std::move (outer_attrs)),
- new_type_name (std::move (new_type_name)),
- generic_params (std::move (generic_params)),
- where_clause (std::move (where_clause)),
- existing_type (std::move (existing_type)), locus (locus)
- {}
+ Visibility vis, AST::AttrVec outer_attrs, location_t locus);
// Copy constructor
- TypeAlias (TypeAlias const &other)
- : VisItem (other), new_type_name (other.new_type_name),
- where_clause (other.where_clause),
- existing_type (other.existing_type->clone_type ()), locus (other.locus)
- {
- generic_params.reserve (other.generic_params.size ());
- for (const auto &e : other.generic_params)
- generic_params.push_back (e->clone_generic_param ());
- }
+ TypeAlias (TypeAlias const &other);
// Overloaded assignment operator to clone
- TypeAlias &operator= (TypeAlias const &other)
- {
- VisItem::operator= (other);
- new_type_name = other.new_type_name;
- where_clause = other.where_clause;
- existing_type = other.existing_type->clone_type ();
- locus = other.locus;
-
- generic_params.reserve (other.generic_params.size ());
- for (const auto &e : other.generic_params)
- generic_params.push_back (e->clone_generic_param ());
-
- return *this;
- }
+ TypeAlias &operator= (TypeAlias const &other);
// move constructors
TypeAlias (TypeAlias &&other) = default;
@@ -1468,32 +1243,15 @@ public:
StructField (Analysis::NodeMapping mappings, Identifier field_name,
std::unique_ptr<Type> field_type, Visibility vis,
- location_t locus, AST::AttrVec outer_attrs = AST::AttrVec ())
- : outer_attrs (std::move (outer_attrs)), visibility (std::move (vis)),
- field_name (std::move (field_name)), field_type (std::move (field_type)),
- mappings (mappings), locus (locus)
- {}
+ location_t locus, AST::AttrVec outer_attrs = AST::AttrVec ());
// Copy constructor
- StructField (StructField const &other)
- : outer_attrs (other.outer_attrs), visibility (other.visibility),
- field_name (other.field_name),
- field_type (other.field_type->clone_type ()), mappings (other.mappings)
- {}
+ StructField (StructField const &other);
~StructField () = default;
// Overloaded assignment operator to clone
- StructField &operator= (StructField const &other)
- {
- field_name = other.field_name;
- field_type = other.field_type->clone_type ();
- visibility = other.visibility;
- outer_attrs = other.outer_attrs;
- mappings = other.mappings;
-
- return *this;
- }
+ StructField &operator= (StructField const &other);
// move constructors
StructField (StructField &&other) = default;
@@ -1598,31 +1356,15 @@ public:
// Complete constructor
TupleField (Analysis::NodeMapping mapping, std::unique_ptr<Type> field_type,
Visibility vis, location_t locus,
- AST::AttrVec outer_attrs = AST::AttrVec ())
- : outer_attrs (std::move (outer_attrs)), visibility (std::move (vis)),
- field_type (std::move (field_type)), locus (locus), mappings (mapping)
- {}
+ AST::AttrVec outer_attrs = AST::AttrVec ());
// Copy constructor with clone
- TupleField (TupleField const &other)
- : outer_attrs (other.outer_attrs), visibility (other.visibility),
- field_type (other.field_type->clone_type ()), locus (other.locus),
- mappings (other.mappings)
- {}
+ TupleField (TupleField const &other);
~TupleField () = default;
// Overloaded assignment operator to clone
- TupleField &operator= (TupleField const &other)
- {
- field_type = other.field_type->clone_type ();
- visibility = other.visibility;
- outer_attrs = other.outer_attrs;
- locus = other.locus;
- mappings = other.mappings;
-
- return *this;
- }
+ TupleField &operator= (TupleField const &other);
// move constructors
TupleField (TupleField &&other) = default;
@@ -1656,12 +1398,7 @@ public:
Identifier struct_name,
std::vector<std::unique_ptr<GenericParam>> generic_params,
WhereClause where_clause, Visibility vis,
- AST::AttrVec outer_attrs, location_t locus)
- : Struct (std::move (mappings), std::move (struct_name),
- std::move (generic_params), std::move (where_clause),
- std::move (vis), locus, std::move (outer_attrs)),
- fields (std::move (fields))
- {}
+ AST::AttrVec outer_attrs, location_t locus);
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRStmtVisitor &vis) override;
@@ -1706,10 +1443,7 @@ public:
};
EnumItem (Analysis::NodeMapping mappings, Identifier variant_name,
- AST::AttrVec outer_attrs, location_t locus)
- : Item (std::move (mappings), std::move (outer_attrs)),
- variant_name (std::move (variant_name)), locus (locus)
- {}
+ AST::AttrVec outer_attrs, location_t locus);
// Unique pointer custom clone function
std::unique_ptr<EnumItem> clone_enum_item () const
@@ -1752,11 +1486,7 @@ public:
EnumItemTuple (Analysis::NodeMapping mappings, Identifier variant_name,
std::vector<TupleField> tuple_fields, AST::AttrVec outer_attrs,
- location_t locus)
- : EnumItem (std::move (mappings), std::move (variant_name),
- std::move (outer_attrs), locus),
- tuple_fields (std::move (tuple_fields))
- {}
+ location_t locus);
std::string as_string () const override;
@@ -1790,11 +1520,7 @@ public:
EnumItemStruct (Analysis::NodeMapping mappings, Identifier variant_name,
std::vector<StructField> struct_fields,
- AST::AttrVec outer_attrs, location_t locus)
- : EnumItem (std::move (mappings), std::move (variant_name),
- std::move (outer_attrs), locus),
- struct_fields (std::move (struct_fields))
- {}
+ AST::AttrVec outer_attrs, location_t locus);
std::string as_string () const override;
@@ -1819,27 +1545,13 @@ class EnumItemDiscriminant : public EnumItem
public:
EnumItemDiscriminant (Analysis::NodeMapping mappings, Identifier variant_name,
std::unique_ptr<Expr> expr, AST::AttrVec outer_attrs,
- location_t locus)
- : EnumItem (std::move (mappings), std::move (variant_name),
- std::move (outer_attrs), locus),
- expression (std::move (expr))
- {}
+ location_t locus);
// Copy constructor with clone
- EnumItemDiscriminant (EnumItemDiscriminant const &other)
- : EnumItem (other), expression (other.expression->clone_expr ())
- {}
+ EnumItemDiscriminant (EnumItemDiscriminant const &other);
// Overloaded assignment operator to clone
- EnumItemDiscriminant &operator= (EnumItemDiscriminant const &other)
- {
- EnumItem::operator= (other);
- expression = other.expression->clone_expr ();
- // variant_name = other.variant_name;
- // outer_attrs = other.outer_attrs;
-
- return *this;
- }
+ EnumItemDiscriminant &operator= (EnumItemDiscriminant const &other);
// move constructors
EnumItemDiscriminant (EnumItemDiscriminant &&other) = default;
@@ -1903,48 +1615,15 @@ public:
Enum (Analysis::NodeMapping mappings, Identifier enum_name, Visibility vis,
std::vector<std::unique_ptr<GenericParam>> generic_params,
WhereClause where_clause, std::vector<std::unique_ptr<EnumItem>> items,
- AST::AttrVec outer_attrs, location_t locus)
- : VisItem (std::move (mappings), std::move (vis), std::move (outer_attrs)),
- enum_name (std::move (enum_name)),
- generic_params (std::move (generic_params)),
- where_clause (std::move (where_clause)), items (std::move (items)),
- locus (locus)
- {}
+ AST::AttrVec outer_attrs, location_t locus);
// TODO: constructor with less arguments
// Copy constructor with vector clone
- Enum (Enum const &other)
- : VisItem (other), enum_name (other.enum_name),
- where_clause (other.where_clause), locus (other.locus)
- {
- generic_params.reserve (other.generic_params.size ());
- for (const auto &e : other.generic_params)
- generic_params.push_back (e->clone_generic_param ());
-
- items.reserve (other.items.size ());
- for (const auto &e : other.items)
- items.push_back (e->clone_enum_item ());
- }
+ Enum (Enum const &other);
// Overloaded assignment operator with vector clone
- Enum &operator= (Enum const &other)
- {
- VisItem::operator= (other);
- enum_name = other.enum_name;
- where_clause = other.where_clause;
- locus = other.locus;
-
- generic_params.reserve (other.generic_params.size ());
- for (const auto &e : other.generic_params)
- generic_params.push_back (e->clone_generic_param ());
-
- items.reserve (other.items.size ());
- for (const auto &e : other.items)
- items.push_back (e->clone_enum_item ());
-
- return *this;
- }
+ Enum &operator= (Enum const &other);
// Move constructors
Enum (Enum &&other) = default;
@@ -2012,40 +1691,13 @@ public:
Union (Analysis::NodeMapping mappings, Identifier union_name, Visibility vis,
std::vector<std::unique_ptr<GenericParam>> generic_params,
WhereClause where_clause, std::vector<StructField> variants,
- AST::AttrVec outer_attrs, location_t locus)
- : VisItem (std::move (mappings), std::move (vis), std::move (outer_attrs)),
- union_name (std::move (union_name)),
- generic_params (std::move (generic_params)),
- where_clause (std::move (where_clause)), variants (std::move (variants)),
- locus (locus)
- {}
+ AST::AttrVec outer_attrs, location_t locus);
// copy constructor with vector clone
- Union (Union const &other)
- : VisItem (other), union_name (other.union_name),
- where_clause (other.where_clause), variants (other.variants),
- locus (other.locus)
- {
- generic_params.reserve (other.generic_params.size ());
- for (const auto &e : other.generic_params)
- generic_params.push_back (e->clone_generic_param ());
- }
+ Union (Union const &other);
// overloaded assignment operator with vector clone
- Union &operator= (Union const &other)
- {
- VisItem::operator= (other);
- union_name = other.union_name;
- where_clause = other.where_clause;
- variants = other.variants;
- locus = other.locus;
-
- generic_params.reserve (other.generic_params.size ());
- for (const auto &e : other.generic_params)
- generic_params.push_back (e->clone_generic_param ());
-
- return *this;
- }
+ Union &operator= (Union const &other);
// move constructors
Union (Union &&other) = default;
@@ -2089,29 +1741,12 @@ public:
ConstantItem (Analysis::NodeMapping mappings, Identifier ident,
Visibility vis, std::unique_ptr<Type> type,
std::unique_ptr<Expr> const_expr, AST::AttrVec outer_attrs,
- location_t locus)
- : VisItem (std::move (mappings), std::move (vis), std::move (outer_attrs)),
- identifier (std::move (ident)), type (std::move (type)),
- const_expr (std::move (const_expr)), locus (locus)
- {}
+ location_t locus);
- ConstantItem (ConstantItem const &other)
- : VisItem (other), identifier (other.identifier),
- type (other.type->clone_type ()),
- const_expr (other.const_expr->clone_expr ()), locus (other.locus)
- {}
+ ConstantItem (ConstantItem const &other);
// Overload assignment operator to clone
- ConstantItem &operator= (ConstantItem const &other)
- {
- VisItem::operator= (other);
- identifier = other.identifier;
- type = other.type->clone_type ();
- const_expr = other.const_expr->clone_expr ();
- locus = other.locus;
-
- return *this;
- }
+ ConstantItem &operator= (ConstantItem const &other);
// move constructors
ConstantItem (ConstantItem &&other) = default;
@@ -2185,31 +1820,13 @@ public:
StaticItem (Analysis::NodeMapping mappings, Identifier name, Mutability mut,
std::unique_ptr<Type> type, std::unique_ptr<Expr> expr,
- Visibility vis, AST::AttrVec outer_attrs, location_t locus)
- : VisItem (std::move (mappings), std::move (vis), std::move (outer_attrs)),
- mut (mut), name (std::move (name)), type (std::move (type)),
- expr (std::move (expr)), locus (locus)
- {}
+ Visibility vis, AST::AttrVec outer_attrs, location_t locus);
// Copy constructor with clone
- StaticItem (StaticItem const &other)
- : VisItem (other), mut (other.mut), name (other.name),
- type (other.type->clone_type ()), expr (other.expr->clone_expr ()),
- locus (other.locus)
- {}
+ StaticItem (StaticItem const &other);
// Overloaded assignment operator to clone
- StaticItem &operator= (StaticItem const &other)
- {
- VisItem::operator= (other);
- name = other.name;
- mut = other.mut;
- type = other.type->clone_type ();
- expr = other.expr->clone_expr ();
- locus = other.locus;
-
- return *this;
- }
+ StaticItem &operator= (StaticItem const &other);
// move constructors
StaticItem (StaticItem &&other) = default;
@@ -2258,45 +1875,15 @@ public:
std::vector<std::unique_ptr<GenericParam>> generic_params,
SelfParam self, std::vector<FunctionParam> function_params,
std::unique_ptr<Type> return_type,
- WhereClause where_clause)
- : qualifiers (std::move (qualifiers)),
- function_name (std::move (function_name)),
- generic_params (std::move (generic_params)),
- function_params (std::move (function_params)),
- return_type (std::move (return_type)),
- where_clause (std::move (where_clause)), self (std::move (self))
- {}
+ WhereClause where_clause);
// Copy constructor with clone
- TraitFunctionDecl (TraitFunctionDecl const &other)
- : qualifiers (other.qualifiers), function_name (other.function_name),
- function_params (other.function_params),
- return_type (other.return_type->clone_type ()),
- where_clause (other.where_clause), self (other.self)
- {
- generic_params.reserve (other.generic_params.size ());
- for (const auto &e : other.generic_params)
- generic_params.push_back (e->clone_generic_param ());
- }
+ TraitFunctionDecl (TraitFunctionDecl const &other);
~TraitFunctionDecl () = default;
// Overloaded assignment operator with clone
- TraitFunctionDecl &operator= (TraitFunctionDecl const &other)
- {
- function_name = other.function_name;
- qualifiers = other.qualifiers;
- function_params = other.function_params;
- return_type = other.return_type->clone_type ();
- where_clause = other.where_clause;
- self = other.self;
-
- generic_params.reserve (other.generic_params.size ());
- for (const auto &e : other.generic_params)
- generic_params.push_back (e->clone_generic_param ());
-
- return *this;
- }
+ TraitFunctionDecl &operator= (TraitFunctionDecl const &other);
// move constructors
TraitFunctionDecl (TraitFunctionDecl &&other) = default;
@@ -2350,34 +1937,13 @@ public:
TraitItemFunc (Analysis::NodeMapping mappings, TraitFunctionDecl decl,
std::unique_ptr<BlockExpr> block_expr,
- AST::AttrVec outer_attrs, location_t locus)
- : TraitItem (mappings), outer_attrs (std::move (outer_attrs)),
- decl (std::move (decl)), block_expr (std::move (block_expr)),
- locus (locus)
- {}
+ AST::AttrVec outer_attrs, location_t locus);
// Copy constructor with clone
- TraitItemFunc (TraitItemFunc const &other)
- : TraitItem (other.mappings), outer_attrs (other.outer_attrs),
- decl (other.decl), locus (other.locus)
- {
- if (other.block_expr != nullptr)
- block_expr = other.block_expr->clone_block_expr ();
- }
+ TraitItemFunc (TraitItemFunc const &other);
// Overloaded assignment operator to clone
- TraitItemFunc &operator= (TraitItemFunc const &other)
- {
- TraitItem::operator= (other);
- outer_attrs = other.outer_attrs;
- decl = other.decl;
- locus = other.locus;
- mappings = other.mappings;
- if (other.block_expr != nullptr)
- block_expr = other.block_expr->clone_block_expr ();
-
- return *this;
- }
+ TraitItemFunc &operator= (TraitItemFunc const &other);
// move constructors
TraitItemFunc (TraitItemFunc &&other) = default;
@@ -2439,32 +2005,13 @@ public:
TraitItemConst (Analysis::NodeMapping mappings, Identifier name,
std::unique_ptr<Type> type, std::unique_ptr<Expr> expr,
- AST::AttrVec outer_attrs, location_t locus)
- : TraitItem (mappings), outer_attrs (std::move (outer_attrs)),
- name (std::move (name)), type (std::move (type)), expr (std::move (expr)),
- locus (locus)
- {}
+ AST::AttrVec outer_attrs, location_t locus);
// Copy constructor with clones
- TraitItemConst (TraitItemConst const &other)
- : TraitItem (other.mappings), outer_attrs (other.outer_attrs),
- name (other.name), type (other.type->clone_type ()),
- expr (other.expr->clone_expr ()), locus (other.locus)
- {}
+ TraitItemConst (TraitItemConst const &other);
// Overloaded assignment operator to clone
- TraitItemConst &operator= (TraitItemConst const &other)
- {
- TraitItem::operator= (other);
- outer_attrs = other.outer_attrs;
- name = other.name;
- type = other.type->clone_type ();
- expr = other.expr->clone_expr ();
- locus = other.locus;
- mappings = other.mappings;
-
- return *this;
- }
+ TraitItemConst &operator= (TraitItemConst const &other);
// move constructors
TraitItemConst (TraitItemConst &&other) = default;
@@ -2527,37 +2074,13 @@ public:
TraitItemType (Analysis::NodeMapping mappings, Identifier name,
std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds,
- AST::AttrVec outer_attrs, location_t locus)
- : TraitItem (mappings), outer_attrs (std::move (outer_attrs)),
- name (std::move (name)),
- type_param_bounds (std::move (type_param_bounds)), locus (locus)
- {}
+ AST::AttrVec outer_attrs, location_t locus);
// Copy constructor with vector clone
- TraitItemType (TraitItemType const &other)
- : TraitItem (other.mappings), outer_attrs (other.outer_attrs),
- name (other.name), locus (other.locus)
- {
- type_param_bounds.reserve (other.type_param_bounds.size ());
- for (const auto &e : other.type_param_bounds)
- type_param_bounds.push_back (e->clone_type_param_bound ());
- }
+ TraitItemType (TraitItemType const &other);
// Overloaded assignment operator with vector clone
- TraitItemType &operator= (TraitItemType const &other)
- {
- TraitItem::operator= (other);
- outer_attrs = other.outer_attrs;
- name = other.name;
- locus = other.locus;
- mappings = other.mappings;
-
- type_param_bounds.reserve (other.type_param_bounds.size ());
- for (const auto &e : other.type_param_bounds)
- type_param_bounds.push_back (e->clone_type_param_bound ());
-
- return *this;
- }
+ TraitItemType &operator= (TraitItemType const &other);
// default move constructors
TraitItemType (TraitItemType &&other) = default;
@@ -2645,56 +2168,13 @@ public:
std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds,
WhereClause where_clause,
std::vector<std::unique_ptr<TraitItem>> trait_items, Visibility vis,
- AST::AttrVec outer_attrs, location_t locus)
- : VisItem (std::move (mappings), std::move (vis), std::move (outer_attrs)),
- unsafety (unsafety), name (std::move (name)),
- generic_params (std::move (generic_params)),
- type_param_bounds (std::move (type_param_bounds)),
- where_clause (std::move (where_clause)),
- trait_items (std::move (trait_items)), locus (locus)
- {}
+ AST::AttrVec outer_attrs, location_t locus);
// Copy constructor with vector clone
- Trait (Trait const &other)
- : VisItem (other), unsafety (other.unsafety), name (other.name),
- where_clause (other.where_clause), locus (other.locus)
- {
- generic_params.reserve (other.generic_params.size ());
- for (const auto &e : other.generic_params)
- generic_params.push_back (e->clone_generic_param ());
-
- type_param_bounds.reserve (other.type_param_bounds.size ());
- for (const auto &e : other.type_param_bounds)
- type_param_bounds.push_back (e->clone_type_param_bound ());
-
- trait_items.reserve (other.trait_items.size ());
- for (const auto &e : other.trait_items)
- trait_items.push_back (e->clone_trait_item ());
- }
+ Trait (Trait const &other);
// Overloaded assignment operator with vector clone
- Trait &operator= (Trait const &other)
- {
- VisItem::operator= (other);
- name = other.name;
- unsafety = other.unsafety;
- where_clause = other.where_clause;
- locus = other.locus;
-
- generic_params.reserve (other.generic_params.size ());
- for (const auto &e : other.generic_params)
- generic_params.push_back (e->clone_generic_param ());
-
- type_param_bounds.reserve (other.type_param_bounds.size ());
- for (const auto &e : other.type_param_bounds)
- type_param_bounds.push_back (e->clone_type_param_bound ());
-
- trait_items.reserve (other.trait_items.size ());
- for (const auto &e : other.trait_items)
- trait_items.push_back (e->clone_trait_item ());
-
- return *this;
- }
+ Trait &operator= (Trait const &other);
// default move constructors
Trait (Trait &&other) = default;
@@ -2753,50 +2233,11 @@ public:
std::unique_ptr<Type> impl_type,
std::unique_ptr<TypePath> trait_ref, WhereClause where_clause,
BoundPolarity polarity, Visibility vis, AST::AttrVec inner_attrs,
- AST::AttrVec outer_attrs, location_t locus, bool unsafe = false)
- : VisItem (std::move (mappings), std::move (vis), std::move (outer_attrs)),
- WithInnerAttrs (std::move (inner_attrs)),
- generic_params (std::move (generic_params)),
- impl_type (std::move (impl_type)), trait_ref (std::move (trait_ref)),
- where_clause (std::move (where_clause)), polarity (polarity),
- locus (locus), impl_items (std::move (impl_items)), unsafe (unsafe)
- {}
-
- ImplBlock (ImplBlock const &other)
- : VisItem (other), WithInnerAttrs (other.inner_attrs),
- impl_type (other.impl_type->clone_type ()),
- where_clause (other.where_clause), polarity (other.polarity),
- locus (other.locus), unsafe (other.unsafe)
- {
- generic_params.reserve (other.generic_params.size ());
- for (const auto &e : other.generic_params)
- generic_params.push_back (e->clone_generic_param ());
-
- impl_items.reserve (other.impl_items.size ());
- for (const auto &e : other.impl_items)
- impl_items.push_back (e->clone_inherent_impl_item ());
- }
-
- ImplBlock &operator= (ImplBlock const &other)
- {
- VisItem::operator= (other);
- impl_type = other.impl_type->clone_type ();
- where_clause = other.where_clause;
- polarity = other.polarity;
- inner_attrs = other.inner_attrs;
- locus = other.locus;
- unsafe = other.unsafe;
-
- generic_params.reserve (other.generic_params.size ());
- for (const auto &e : other.generic_params)
- generic_params.push_back (e->clone_generic_param ());
+ AST::AttrVec outer_attrs, location_t locus, bool unsafe = false);
- impl_items.reserve (other.impl_items.size ());
- for (const auto &e : other.impl_items)
- impl_items.push_back (e->clone_inherent_impl_item ());
+ ImplBlock (ImplBlock const &other);
- return *this;
- }
+ ImplBlock &operator= (ImplBlock const &other);
ImplBlock (ImplBlock &&other) = default;
ImplBlock &operator= (ImplBlock &&other) = default;
@@ -2905,30 +2346,13 @@ public:
protected:
ExternalItem (Analysis::NodeMapping mappings, Identifier item_name,
- Visibility vis, AST::AttrVec outer_attrs, location_t locus)
- : mappings (mappings), outer_attrs (std::move (outer_attrs)),
- visibility (std::move (vis)), item_name (std::move (item_name)),
- locus (locus)
- {}
+ Visibility vis, AST::AttrVec outer_attrs, location_t locus);
// Copy constructor
- ExternalItem (ExternalItem const &other)
- : mappings (other.mappings), outer_attrs (other.outer_attrs),
- visibility (other.visibility), item_name (other.item_name),
- locus (other.locus)
- {}
+ ExternalItem (ExternalItem const &other);
// Overloaded assignment operator to clone
- ExternalItem &operator= (ExternalItem const &other)
- {
- mappings = other.mappings;
- item_name = other.item_name;
- visibility = other.visibility;
- outer_attrs = other.outer_attrs;
- locus = other.locus;
-
- return *this;
- }
+ ExternalItem &operator= (ExternalItem const &other);
// move constructors
ExternalItem (ExternalItem &&other) = default;
@@ -2948,27 +2372,13 @@ public:
ExternalStaticItem (Analysis::NodeMapping mappings, Identifier item_name,
std::unique_ptr<Type> item_type, Mutability mut,
Visibility vis, AST::AttrVec outer_attrs,
- location_t locus)
- : ExternalItem (std::move (mappings), std::move (item_name),
- std::move (vis), std::move (outer_attrs), locus),
- mut (mut), item_type (std::move (item_type))
- {}
+ location_t locus);
// Copy constructor
- ExternalStaticItem (ExternalStaticItem const &other)
- : ExternalItem (other), mut (other.mut),
- item_type (other.item_type->clone_type ())
- {}
+ ExternalStaticItem (ExternalStaticItem const &other);
// Overloaded assignment operator to clone
- ExternalStaticItem &operator= (ExternalStaticItem const &other)
- {
- ExternalItem::operator= (other);
- item_type = other.item_type->clone_type ();
- mut = other.mut;
-
- return *this;
- }
+ ExternalStaticItem &operator= (ExternalStaticItem const &other);
// move constructors
ExternalStaticItem (ExternalStaticItem &&other) = default;
@@ -3008,29 +2418,15 @@ public:
bool has_name () const { return name.as_string () != "_"; }
NamedFunctionParam (Analysis::NodeMapping mappings, Identifier name,
- std::unique_ptr<Type> param_type)
- : name (std::move (name)), param_type (std::move (param_type)),
- mappings (std::move (mappings))
- {}
+ std::unique_ptr<Type> param_type);
// Copy constructor
- NamedFunctionParam (NamedFunctionParam const &other)
- : name (other.name), param_type (other.param_type->clone_type ()),
- mappings (other.mappings)
- {}
+ NamedFunctionParam (NamedFunctionParam const &other);
~NamedFunctionParam () = default;
// Overloaded assignment operator to clone
- NamedFunctionParam &operator= (NamedFunctionParam const &other)
- {
- mappings = other.mappings;
- name = other.name;
- param_type = other.param_type->clone_type ();
- // has_name = other.has_name;
-
- return *this;
- }
+ NamedFunctionParam &operator= (NamedFunctionParam const &other);
// move constructors
NamedFunctionParam (NamedFunctionParam &&other) = default;
@@ -3082,48 +2478,13 @@ public:
std::vector<std::unique_ptr<GenericParam>> generic_params,
std::unique_ptr<Type> return_type, WhereClause where_clause,
std::vector<NamedFunctionParam> function_params, bool has_variadics,
- Visibility vis, AST::AttrVec outer_attrs, location_t locus)
- : ExternalItem (std::move (mappings), std::move (item_name),
- std::move (vis), std::move (outer_attrs), locus),
- generic_params (std::move (generic_params)),
- return_type (std::move (return_type)),
- where_clause (std::move (where_clause)),
- function_params (std::move (function_params)),
- has_variadics (has_variadics)
- {}
+ Visibility vis, AST::AttrVec outer_attrs, location_t locus);
// Copy constructor with clone
- ExternalFunctionItem (ExternalFunctionItem const &other)
- : ExternalItem (other), where_clause (other.where_clause),
- function_params (other.function_params),
- has_variadics (other.has_variadics)
- {
- if (other.return_type)
- return_type = other.return_type->clone_type ();
-
- generic_params.reserve (other.generic_params.size ());
- for (const auto &e : other.generic_params)
- generic_params.push_back (e->clone_generic_param ());
- }
+ ExternalFunctionItem (ExternalFunctionItem const &other);
// Overloaded assignment operator with clone
- ExternalFunctionItem &operator= (ExternalFunctionItem const &other)
- {
- ExternalItem::operator= (other);
-
- where_clause = other.where_clause;
- function_params = other.function_params;
- has_variadics = other.has_variadics;
-
- if (other.return_type)
- return_type = other.return_type->clone_type ();
-
- generic_params.reserve (other.generic_params.size ());
- for (const auto &e : other.generic_params)
- generic_params.push_back (e->clone_generic_param ());
-
- return *this;
- }
+ ExternalFunctionItem &operator= (ExternalFunctionItem const &other);
// move constructors
ExternalFunctionItem (ExternalFunctionItem &&other) = default;
@@ -3163,14 +2524,9 @@ class ExternalTypeItem : public ExternalItem
{
public:
ExternalTypeItem (Analysis::NodeMapping mappings, Identifier item_name,
- Visibility vis, location_t locus)
- : ExternalItem (std::move (mappings), std::move (item_name),
- Visibility (std::move (vis)),
- /* FIXME: Is that correct? */
- {}, locus)
- {}
+ Visibility vis, location_t locus);
- ExternalTypeItem (ExternalTypeItem const &other) : ExternalItem (other) {}
+ ExternalTypeItem (ExternalTypeItem const &other);
ExternalTypeItem (ExternalTypeItem &&other) = default;
ExternalTypeItem &operator= (ExternalTypeItem &&other) = default;
@@ -3210,36 +2566,13 @@ public:
ExternBlock (Analysis::NodeMapping mappings, ABI abi,
std::vector<std::unique_ptr<ExternalItem>> extern_items,
Visibility vis, AST::AttrVec inner_attrs,
- AST::AttrVec outer_attrs, location_t locus)
- : VisItem (std::move (mappings), std::move (vis), std::move (outer_attrs)),
- WithInnerAttrs (std::move (inner_attrs)), abi (abi),
- extern_items (std::move (extern_items)), locus (locus)
- {}
+ AST::AttrVec outer_attrs, location_t locus);
// Copy constructor with vector clone
- ExternBlock (ExternBlock const &other)
- : VisItem (other), WithInnerAttrs (other.inner_attrs), abi (other.abi),
- locus (other.locus)
- {
- extern_items.reserve (other.extern_items.size ());
- for (const auto &e : other.extern_items)
- extern_items.push_back (e->clone_external_item ());
- }
+ ExternBlock (ExternBlock const &other);
// Overloaded assignment operator with vector clone
- ExternBlock &operator= (ExternBlock const &other)
- {
- VisItem::operator= (other);
- abi = other.abi;
- inner_attrs = other.inner_attrs;
- locus = other.locus;
-
- extern_items.reserve (other.extern_items.size ());
- for (const auto &e : other.extern_items)
- extern_items.push_back (e->clone_external_item ());
-
- return *this;
- }
+ ExternBlock &operator= (ExternBlock const &other);
// move constructors
ExternBlock (ExternBlock &&other) = default;
diff --git a/gcc/rust/hir/tree/rust-hir-literal.h b/gcc/rust/hir/tree/rust-hir-literal.h
new file mode 100644
index 00000000000..9a97e71b719
--- /dev/null
+++ b/gcc/rust/hir/tree/rust-hir-literal.h
@@ -0,0 +1,78 @@
+// Copyright (C) 2020-2024 Free Software Foundation, Inc.
+
+// This file is part of GCC.
+
+// GCC is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3, or (at your option) any later
+// version.
+
+// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with GCC; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#ifndef RUST_HIR_LITERAL_H
+#define RUST_HIR_LITERAL_H
+
+#include "rust-token.h"
+
+namespace Rust {
+namespace HIR {
+// A literal - value with a type. Used in LiteralExpr and LiteralPattern.
+struct Literal
+{
+public:
+ enum LitType
+ {
+ CHAR,
+ STRING,
+ BYTE,
+ BYTE_STRING,
+ INT,
+ FLOAT,
+ BOOL
+ };
+
+private:
+ std::string value_as_string;
+ LitType type;
+ PrimitiveCoreType type_hint;
+
+public:
+ std::string as_string () const { return value_as_string; }
+
+ LitType get_lit_type () const { return type; }
+
+ PrimitiveCoreType get_type_hint () const { return type_hint; }
+
+ Literal (std::string value_as_string, LitType type,
+ PrimitiveCoreType type_hint)
+ : value_as_string (std::move (value_as_string)), type (type),
+ type_hint (type_hint)
+ {}
+
+ static Literal create_error ()
+ {
+ return Literal ("", CHAR, PrimitiveCoreType::CORETYPE_UNKNOWN);
+ }
+
+ void set_lit_type (LitType lt) { type = lt; }
+
+ // Returns whether literal is in an invalid state.
+ bool is_error () const { return value_as_string == ""; }
+
+ bool is_equal (Literal &other)
+ {
+ return value_as_string == other.value_as_string && type == other.type
+ && type_hint == other.type_hint;
+ }
+};
+} // namespace HIR
+} // namespace Rust
+
+#endif
diff --git a/gcc/rust/hir/tree/rust-hir-node.h b/gcc/rust/hir/tree/rust-hir-node.h
new file mode 100644
index 00000000000..4010c23db6e
--- /dev/null
+++ b/gcc/rust/hir/tree/rust-hir-node.h
@@ -0,0 +1,63 @@
+// Copyright (C) 2020-2024 Free Software Foundation, Inc.
+
+// This file is part of GCC.
+
+// GCC is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3, or (at your option) any later
+// version.
+
+// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with GCC; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#ifndef RUST_HIR_NODE_H
+#define RUST_HIR_NODE_H
+
+namespace Rust {
+
+namespace HIR {
+
+class Node
+{
+public:
+ // Kind for downcasting various HIR nodes to other base classes when visiting
+ // them
+ enum BaseKind
+ {
+ /* class ExternalItem */
+ EXTERNAL,
+ /* class TraitItem */
+ TRAIT_ITEM,
+ /* class VisItem */
+ VIS_ITEM,
+ /* class Item */
+ ITEM,
+ /* class ImplItem */
+ IMPL,
+ /* class Type */
+ TYPE,
+ /* class Stmt */
+ STMT,
+ /* class Expr */
+ EXPR,
+ /* class Pattern */
+ PATTERN,
+ };
+
+ /**
+ * Get the kind of HIR node we are dealing with. This is useful for
+ * downcasting to more precise types when necessary, i.e going from an `Item*`
+ * to a `VisItem*`
+ */
+ virtual BaseKind get_hir_kind () = 0;
+};
+
+} // namespace HIR
+} // namespace Rust
+#endif
diff --git a/gcc/rust/hir/tree/rust-hir-path.cc b/gcc/rust/hir/tree/rust-hir-path.cc
new file mode 100644
index 00000000000..c8d3079a85e
--- /dev/null
+++ b/gcc/rust/hir/tree/rust-hir-path.cc
@@ -0,0 +1,383 @@
+// Copyright (C) 2020-2024 Free Software Foundation, Inc.
+
+// This file is part of GCC.
+
+// GCC is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3, or (at your option) any later
+// version.
+
+// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with GCC; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include "rust-hir-path.h"
+#include "rust-hir-bound.h"
+
+namespace Rust {
+namespace HIR {
+
+GenericArgsBinding::GenericArgsBinding (Identifier ident,
+ std::unique_ptr<Type> type_ptr,
+ location_t locus)
+ : identifier (std::move (ident)), type (std::move (type_ptr)), locus (locus)
+{}
+
+GenericArgsBinding::GenericArgsBinding (GenericArgsBinding const &other)
+ : identifier (other.identifier), type (other.type->clone_type ()),
+ locus (other.locus)
+{}
+
+GenericArgsBinding &
+GenericArgsBinding::operator= (GenericArgsBinding const &other)
+{
+ identifier = other.identifier;
+ type = other.type->clone_type ();
+ locus = other.locus;
+ return *this;
+}
+
+ConstGenericArg::ConstGenericArg (std::unique_ptr<Expr> expression,
+ location_t locus)
+ : expression (std::move (expression)), locus (locus)
+{}
+
+ConstGenericArg::ConstGenericArg (const ConstGenericArg &other)
+ : locus (other.locus)
+{
+ expression = other.expression->clone_expr ();
+}
+
+ConstGenericArg
+ConstGenericArg::operator= (const ConstGenericArg &other)
+{
+ expression = other.expression->clone_expr ();
+ locus = other.locus;
+
+ return *this;
+}
+
+GenericArgs &
+GenericArgs::operator= (GenericArgs const &other)
+{
+ lifetime_args = other.lifetime_args;
+ binding_args = other.binding_args;
+ const_args = other.const_args;
+ locus = other.locus;
+
+ type_args.clear ();
+ type_args.reserve (other.type_args.size ());
+ for (const auto &e : other.type_args)
+ type_args.push_back (e->clone_type ());
+
+ return *this;
+}
+
+GenericArgs::GenericArgs (std::vector<Lifetime> lifetime_args,
+ std::vector<std::unique_ptr<Type> > type_args,
+ std::vector<GenericArgsBinding> binding_args,
+ std::vector<ConstGenericArg> const_args,
+ location_t locus)
+ : lifetime_args (std::move (lifetime_args)),
+ type_args (std::move (type_args)), binding_args (std::move (binding_args)),
+ const_args (std::move (const_args)), locus (locus)
+{}
+
+GenericArgs::GenericArgs (GenericArgs const &other)
+ : lifetime_args (other.lifetime_args), binding_args (other.binding_args),
+ const_args (other.const_args), locus (other.locus)
+{
+ type_args.clear ();
+ type_args.reserve (other.type_args.size ());
+
+ for (const auto &e : other.type_args)
+ type_args.push_back (e->clone_type ());
+}
+
+bool
+GenericArgs::is_empty () const
+{
+ return lifetime_args.size () == 0 && type_args.size () == 0
+ && binding_args.size () == 0;
+}
+
+PathExprSegment::PathExprSegment (Analysis::NodeMapping mappings,
+ PathIdentSegment segment_name,
+ location_t locus, GenericArgs generic_args)
+ : mappings (std::move (mappings)), segment_name (std::move (segment_name)),
+ generic_args (std::move (generic_args)), locus (locus)
+{}
+
+PathExprSegment::PathExprSegment (PathExprSegment const &other)
+ : mappings (other.mappings), segment_name (other.segment_name),
+ generic_args (other.generic_args), locus (other.locus)
+{}
+
+PathExprSegment &
+PathExprSegment::operator= (PathExprSegment const &other)
+{
+ mappings = other.mappings;
+ segment_name = other.segment_name;
+ generic_args = other.generic_args;
+ locus = other.locus;
+
+ return *this;
+}
+
+void
+PathPattern::iterate_path_segments (std::function<bool (PathExprSegment &)> cb)
+{
+ for (auto it = segments.begin (); it != segments.end (); it++)
+ {
+ if (!cb (*it))
+ return;
+ }
+}
+
+PathInExpression::PathInExpression (Analysis::NodeMapping mappings,
+ std::vector<PathExprSegment> path_segments,
+ location_t locus,
+ bool has_opening_scope_resolution,
+ std::vector<AST::Attribute> outer_attrs)
+ : PathPattern (std::move (path_segments)),
+ PathExpr (std::move (mappings), std::move (outer_attrs)),
+ has_opening_scope_resolution (has_opening_scope_resolution), locus (locus)
+{}
+
+bool
+PathInExpression::is_self () const
+
+{
+ if (!is_single_segment ())
+ return false;
+
+ return get_final_segment ().get_segment ().as_string ().compare ("self") == 0;
+}
+
+TypePathSegment::TypePathSegment (Analysis::NodeMapping mappings,
+ PathIdentSegment ident_segment,
+ bool has_separating_scope_resolution,
+ location_t locus)
+ : mappings (std::move (mappings)), ident_segment (std::move (ident_segment)),
+ locus (locus),
+ has_separating_scope_resolution (has_separating_scope_resolution),
+ type (SegmentType::REG)
+{}
+
+TypePathSegment::TypePathSegment (Analysis::NodeMapping mappings,
+ std::string segment_name,
+ bool has_separating_scope_resolution,
+ location_t locus)
+ : mappings (std::move (mappings)),
+ ident_segment (PathIdentSegment (std::move (segment_name))), locus (locus),
+ has_separating_scope_resolution (has_separating_scope_resolution),
+ type (SegmentType::REG)
+{}
+
+TypePathSegmentGeneric::TypePathSegmentGeneric (
+ Analysis::NodeMapping mappings, PathIdentSegment ident_segment,
+ bool has_separating_scope_resolution, GenericArgs generic_args,
+ location_t locus)
+ : TypePathSegment (std::move (mappings), std::move (ident_segment),
+ has_separating_scope_resolution, locus),
+ generic_args (std::move (generic_args))
+{}
+
+TypePathSegmentGeneric::TypePathSegmentGeneric (
+ Analysis::NodeMapping mappings, std::string segment_name,
+ bool has_separating_scope_resolution, std::vector<Lifetime> lifetime_args,
+ std::vector<std::unique_ptr<Type> > type_args,
+ std::vector<GenericArgsBinding> binding_args,
+ std::vector<ConstGenericArg> const_args, location_t locus)
+ : TypePathSegment (std::move (mappings), std::move (segment_name),
+ has_separating_scope_resolution, locus),
+ generic_args (GenericArgs (std::move (lifetime_args), std::move (type_args),
+ std::move (binding_args), std::move (const_args),
+ locus))
+{}
+
+TypePathFunction::TypePathFunction (std::vector<std::unique_ptr<Type> > inputs,
+ std::unique_ptr<Type> type)
+ : inputs (std::move (inputs)), return_type (std::move (type))
+{}
+
+TypePathFunction::TypePathFunction (TypePathFunction const &other)
+{
+ return_type = other.has_return_type ()
+ ? other.get_return_type ().clone_type ()
+ : nullptr;
+
+ inputs.reserve (other.inputs.size ());
+ for (const auto &e : other.inputs)
+ inputs.push_back (e->clone_type ());
+}
+
+TypePathFunction &
+TypePathFunction::operator= (TypePathFunction const &other)
+{
+ return_type = other.has_return_type ()
+ ? other.get_return_type ().clone_type ()
+ : nullptr;
+
+ inputs.reserve (other.inputs.size ());
+ for (const auto &e : other.inputs)
+ inputs.push_back (e->clone_type ());
+
+ return *this;
+}
+
+TypePathSegmentFunction::TypePathSegmentFunction (
+ Analysis::NodeMapping mappings, PathIdentSegment ident_segment,
+ bool has_separating_scope_resolution, TypePathFunction function_path,
+ location_t locus)
+ : TypePathSegment (std::move (mappings), std::move (ident_segment),
+ has_separating_scope_resolution, locus),
+ function_path (std::move (function_path))
+{}
+
+TypePathSegmentFunction::TypePathSegmentFunction (
+ Analysis::NodeMapping mappings, std::string segment_name,
+ bool has_separating_scope_resolution, TypePathFunction function_path,
+ location_t locus)
+ : TypePathSegment (std::move (mappings), std::move (segment_name),
+ has_separating_scope_resolution, locus),
+ function_path (std::move (function_path))
+{}
+
+TypePath::TypePath (Analysis::NodeMapping mappings,
+ std::vector<std::unique_ptr<TypePathSegment> > segments,
+ location_t locus, bool has_opening_scope_resolution)
+ : TypeNoBounds (mappings, locus),
+ has_opening_scope_resolution (has_opening_scope_resolution),
+ segments (std::move (segments))
+{}
+
+TypePath::TypePath (TypePath const &other)
+ : TypeNoBounds (other.mappings, other.locus),
+ has_opening_scope_resolution (other.has_opening_scope_resolution)
+{
+ segments.reserve (other.segments.size ());
+ for (const auto &e : other.segments)
+ segments.push_back (e->clone_type_path_segment ());
+}
+
+TypePath &
+TypePath::operator= (TypePath const &other)
+{
+ has_opening_scope_resolution = other.has_opening_scope_resolution;
+ locus = other.locus;
+ mappings = other.mappings;
+
+ segments.reserve (other.segments.size ());
+ for (const auto &e : other.segments)
+ segments.push_back (e->clone_type_path_segment ());
+
+ return *this;
+}
+
+QualifiedPathType::QualifiedPathType (Analysis::NodeMapping mappings,
+ std::unique_ptr<Type> type,
+ std::unique_ptr<TypePath> trait,
+ location_t locus)
+ : type (std::move (type)), trait (std::move (trait)), locus (locus),
+ mappings (mappings)
+{}
+
+QualifiedPathType::QualifiedPathType (QualifiedPathType const &other)
+ : type (other.type->clone_type ()),
+ trait (other.has_as_clause ()
+ ? std::unique_ptr<HIR::TypePath> (new HIR::TypePath (*other.trait))
+ : nullptr),
+ locus (other.locus), mappings (other.mappings)
+{}
+
+QualifiedPathType &
+QualifiedPathType::operator= (QualifiedPathType const &other)
+{
+ type = other.type->clone_type ();
+ locus = other.locus;
+ mappings = other.mappings;
+ trait = other.has_as_clause ()
+ ? std::unique_ptr<HIR::TypePath> (new HIR::TypePath (*other.trait))
+ : nullptr;
+
+ return *this;
+}
+
+bool
+QualifiedPathType::trait_has_generic_args () const
+{
+ rust_assert (has_as_clause ());
+ bool is_generic_seg = trait->get_final_segment ().get_type ()
+ == TypePathSegment::SegmentType::GENERIC;
+ if (!is_generic_seg)
+ return false;
+
+ auto &seg
+ = static_cast<TypePathSegmentGeneric &> (trait->get_final_segment ());
+ return seg.has_generic_args ();
+}
+
+GenericArgs &
+QualifiedPathType::get_trait_generic_args ()
+{
+ rust_assert (trait_has_generic_args ());
+ auto &seg
+ = static_cast<TypePathSegmentGeneric &> (trait->get_final_segment ());
+ return seg.get_generic_args ();
+}
+
+QualifiedPathInExpression::QualifiedPathInExpression (
+ Analysis::NodeMapping mappings, QualifiedPathType qual_path_type,
+ std::vector<PathExprSegment> path_segments, location_t locus,
+ std::vector<AST::Attribute> outer_attrs)
+ : PathPattern (std::move (path_segments)),
+ PathExpr (std::move (mappings), std::move (outer_attrs)),
+ path_type (std::move (qual_path_type)), locus (locus)
+{}
+
+QualifiedPathInType::QualifiedPathInType (
+ Analysis::NodeMapping mappings, QualifiedPathType qual_path_type,
+ std::unique_ptr<TypePathSegment> associated_segment,
+ std::vector<std::unique_ptr<TypePathSegment> > path_segments,
+ location_t locus)
+ : TypeNoBounds (mappings, locus), path_type (std::move (qual_path_type)),
+ associated_segment (std::move (associated_segment)),
+ segments (std::move (path_segments))
+{}
+
+QualifiedPathInType::QualifiedPathInType (QualifiedPathInType const &other)
+ : TypeNoBounds (other.mappings, other.locus), path_type (other.path_type)
+{
+ auto seg = other.associated_segment->clone_type_path_segment_impl ();
+ associated_segment = std::unique_ptr<TypePathSegment> (seg);
+
+ segments.reserve (other.segments.size ());
+ for (const auto &e : other.segments)
+ segments.push_back (e->clone_type_path_segment ());
+}
+
+QualifiedPathInType &
+QualifiedPathInType::operator= (QualifiedPathInType const &other)
+{
+ auto seg = other.associated_segment->clone_type_path_segment_impl ();
+ associated_segment = std::unique_ptr<TypePathSegment> (seg);
+
+ path_type = other.path_type;
+ locus = other.locus;
+ mappings = other.mappings;
+
+ segments.reserve (other.segments.size ());
+ for (const auto &e : other.segments)
+ segments.push_back (e->clone_type_path_segment ());
+
+ return *this;
+}
+
+} // namespace HIR
+} // namespace Rust
diff --git a/gcc/rust/hir/tree/rust-hir-path.h b/gcc/rust/hir/tree/rust-hir-path.h
index 18197837afa..8b9814f227a 100644
--- a/gcc/rust/hir/tree/rust-hir-path.h
+++ b/gcc/rust/hir/tree/rust-hir-path.h
@@ -19,7 +19,10 @@
#ifndef RUST_HIR_PATH_H
#define RUST_HIR_PATH_H
-#include "rust-hir.h"
+#include "rust-hir-simple-path.h"
+#include "rust-hir-type-no-bounds.h"
+#include "rust-hir-pattern-abstract.h"
+#include "rust-hir-expr-abstract.h"
namespace Rust {
namespace HIR {
@@ -76,27 +79,16 @@ public:
// Pointer type for type in constructor to enable polymorphism
GenericArgsBinding (Identifier ident, std::unique_ptr<Type> type_ptr,
- location_t locus = UNDEF_LOCATION)
- : identifier (std::move (ident)), type (std::move (type_ptr)), locus (locus)
- {}
+ location_t locus = UNDEF_LOCATION);
// Copy constructor has to deep copy the type as it is a unique pointer
- GenericArgsBinding (GenericArgsBinding const &other)
- : identifier (other.identifier), type (other.type->clone_type ()),
- locus (other.locus)
- {}
+ GenericArgsBinding (GenericArgsBinding const &other);
// default destructor
~GenericArgsBinding () = default;
// Overload assignment operator to deep copy the pointed-to type
- GenericArgsBinding &operator= (GenericArgsBinding const &other)
- {
- identifier = other.identifier;
- type = other.type->clone_type ();
- locus = other.locus;
- return *this;
- }
+ GenericArgsBinding &operator= (GenericArgsBinding const &other);
// move constructors
GenericArgsBinding (GenericArgsBinding &&other) = default;
@@ -119,22 +111,11 @@ class ConstGenericArg
// at name-resolution, hence no need for ambiguities here
public:
- ConstGenericArg (std::unique_ptr<Expr> expression, location_t locus)
- : expression (std::move (expression)), locus (locus)
- {}
-
- ConstGenericArg (const ConstGenericArg &other) : locus (other.locus)
- {
- expression = other.expression->clone_expr ();
- }
+ ConstGenericArg (std::unique_ptr<Expr> expression, location_t locus);
- ConstGenericArg operator= (const ConstGenericArg &other)
- {
- expression = other.expression->clone_expr ();
- locus = other.locus;
+ ConstGenericArg (const ConstGenericArg &other);
- return *this;
- }
+ ConstGenericArg operator= (const ConstGenericArg &other);
std::unique_ptr<Expr> &get_expression () { return expression; }
@@ -162,42 +143,15 @@ public:
GenericArgs (std::vector<Lifetime> lifetime_args,
std::vector<std::unique_ptr<Type> > type_args,
std::vector<GenericArgsBinding> binding_args,
- std::vector<ConstGenericArg> const_args, location_t locus)
- : lifetime_args (std::move (lifetime_args)),
- type_args (std::move (type_args)),
- binding_args (std::move (binding_args)),
- const_args (std::move (const_args)), locus (locus)
- {}
+ std::vector<ConstGenericArg> const_args, location_t locus);
// copy constructor with vector clone
- GenericArgs (GenericArgs const &other)
- : lifetime_args (other.lifetime_args), binding_args (other.binding_args),
- const_args (other.const_args), locus (other.locus)
- {
- type_args.clear ();
- type_args.reserve (other.type_args.size ());
-
- for (const auto &e : other.type_args)
- type_args.push_back (e->clone_type ());
- }
+ GenericArgs (GenericArgs const &other);
~GenericArgs () = default;
// overloaded assignment operator to vector clone
- GenericArgs &operator= (GenericArgs const &other)
- {
- lifetime_args = other.lifetime_args;
- binding_args = other.binding_args;
- const_args = other.const_args;
- locus = other.locus;
-
- type_args.clear ();
- type_args.reserve (other.type_args.size ());
- for (const auto &e : other.type_args)
- type_args.push_back (e->clone_type ());
-
- return *this;
- }
+ GenericArgs &operator= (GenericArgs const &other);
// move constructors
GenericArgs (GenericArgs &&other) = default;
@@ -209,11 +163,7 @@ public:
return GenericArgs ({}, {}, {}, {}, locus);
}
- bool is_empty () const
- {
- return lifetime_args.size () == 0 && type_args.size () == 0
- && binding_args.size () == 0;
- }
+ bool is_empty () const;
std::string as_string () const;
@@ -245,25 +195,11 @@ private:
public:
PathExprSegment (Analysis::NodeMapping mappings,
PathIdentSegment segment_name, location_t locus,
- GenericArgs generic_args)
- : mappings (std::move (mappings)), segment_name (std::move (segment_name)),
- generic_args (std::move (generic_args)), locus (locus)
- {}
+ GenericArgs generic_args);
- PathExprSegment (PathExprSegment const &other)
- : mappings (other.mappings), segment_name (other.segment_name),
- generic_args (other.generic_args), locus (other.locus)
- {}
-
- PathExprSegment &operator= (PathExprSegment const &other)
- {
- mappings = other.mappings;
- segment_name = other.segment_name;
- generic_args = other.generic_args;
- locus = other.locus;
+ PathExprSegment (PathExprSegment const &other);
- return *this;
- }
+ PathExprSegment &operator= (PathExprSegment const &other);
// move constructors
PathExprSegment (PathExprSegment &&other) = default;
@@ -308,14 +244,7 @@ public:
std::string as_string () const override;
- void iterate_path_segments (std::function<bool (PathExprSegment &)> cb)
- {
- for (auto it = segments.begin (); it != segments.end (); it++)
- {
- if (!cb (*it))
- return;
- }
- }
+ void iterate_path_segments (std::function<bool (PathExprSegment &)> cb);
size_t get_num_segments () const { return segments.size (); }
@@ -349,11 +278,7 @@ public:
location_t locus = UNDEF_LOCATION,
bool has_opening_scope_resolution = false,
std::vector<AST::Attribute> outer_attrs
- = std::vector<AST::Attribute> ())
- : PathPattern (std::move (path_segments)),
- PathExpr (std::move (mappings), std::move (outer_attrs)),
- has_opening_scope_resolution (has_opening_scope_resolution), locus (locus)
- {}
+ = std::vector<AST::Attribute> ());
// Creates an error state path in expression.
static PathInExpression create_error ()
@@ -385,14 +310,7 @@ public:
bool opening_scope_resolution () { return has_opening_scope_resolution; }
- bool is_self () const
- {
- if (!is_single_segment ())
- return false;
-
- return get_final_segment ().get_segment ().as_string ().compare ("self")
- == 0;
- }
+ bool is_self () const;
const Analysis::NodeMapping &get_mappings () const override final
{
@@ -456,21 +374,10 @@ public:
TypePathSegment (Analysis::NodeMapping mappings,
PathIdentSegment ident_segment,
- bool has_separating_scope_resolution, location_t locus)
- : mappings (std::move (mappings)),
- ident_segment (std::move (ident_segment)), locus (locus),
- has_separating_scope_resolution (has_separating_scope_resolution),
- type (SegmentType::REG)
- {}
+ bool has_separating_scope_resolution, location_t locus);
TypePathSegment (Analysis::NodeMapping mappings, std::string segment_name,
- bool has_separating_scope_resolution, location_t locus)
- : mappings (std::move (mappings)),
- ident_segment (PathIdentSegment (std::move (segment_name))),
- locus (locus),
- has_separating_scope_resolution (has_separating_scope_resolution),
- type (SegmentType::REG)
- {}
+ bool has_separating_scope_resolution, location_t locus);
virtual std::string as_string () const { return ident_segment.as_string (); }
@@ -511,11 +418,7 @@ public:
TypePathSegmentGeneric (Analysis::NodeMapping mappings,
PathIdentSegment ident_segment,
bool has_separating_scope_resolution,
- GenericArgs generic_args, location_t locus)
- : TypePathSegment (std::move (mappings), std::move (ident_segment),
- has_separating_scope_resolution, locus),
- generic_args (std::move (generic_args))
- {}
+ GenericArgs generic_args, location_t locus);
// Constructor from segment name and all args
TypePathSegmentGeneric (Analysis::NodeMapping mappings,
@@ -525,13 +428,7 @@ public:
std::vector<std::unique_ptr<Type> > type_args,
std::vector<GenericArgsBinding> binding_args,
std::vector<ConstGenericArg> const_args,
- location_t locus)
- : TypePathSegment (std::move (mappings), std::move (segment_name),
- has_separating_scope_resolution, locus),
- generic_args (
- GenericArgs (std::move (lifetime_args), std::move (type_args),
- std::move (binding_args), std::move (const_args), locus))
- {}
+ location_t locus);
std::string as_string () const override;
@@ -566,37 +463,15 @@ public:
// Constructor
TypePathFunction (std::vector<std::unique_ptr<Type> > inputs,
- std::unique_ptr<Type> type)
- : inputs (std::move (inputs)), return_type (std::move (type))
- {}
+ std::unique_ptr<Type> type);
// Copy constructor with clone
- TypePathFunction (TypePathFunction const &other)
- {
- return_type = other.has_return_type ()
- ? other.get_return_type ().clone_type ()
- : nullptr;
-
- inputs.reserve (other.inputs.size ());
- for (const auto &e : other.inputs)
- inputs.push_back (e->clone_type ());
- }
+ TypePathFunction (TypePathFunction const &other);
~TypePathFunction () = default;
// Overloaded assignment operator to clone type
- TypePathFunction &operator= (TypePathFunction const &other)
- {
- return_type = other.has_return_type ()
- ? other.get_return_type ().clone_type ()
- : nullptr;
-
- inputs.reserve (other.inputs.size ());
- for (const auto &e : other.inputs)
- inputs.push_back (e->clone_type ());
-
- return *this;
- }
+ TypePathFunction &operator= (TypePathFunction const &other);
// move constructors
TypePathFunction (TypePathFunction &&other) = default;
@@ -624,21 +499,13 @@ public:
TypePathSegmentFunction (Analysis::NodeMapping mappings,
PathIdentSegment ident_segment,
bool has_separating_scope_resolution,
- TypePathFunction function_path, location_t locus)
- : TypePathSegment (std::move (mappings), std::move (ident_segment),
- has_separating_scope_resolution, locus),
- function_path (std::move (function_path))
- {}
+ TypePathFunction function_path, location_t locus);
// Constructor with segment name and TypePathFn
TypePathSegmentFunction (Analysis::NodeMapping mappings,
std::string segment_name,
bool has_separating_scope_resolution,
- TypePathFunction function_path, location_t locus)
- : TypePathSegment (std::move (mappings), std::move (segment_name),
- has_separating_scope_resolution, locus),
- function_path (std::move (function_path))
- {}
+ TypePathFunction function_path, location_t locus);
std::string as_string () const override;
@@ -698,35 +565,13 @@ public:
// Constructor
TypePath (Analysis::NodeMapping mappings,
std::vector<std::unique_ptr<TypePathSegment> > segments,
- location_t locus, bool has_opening_scope_resolution = false)
- : TypeNoBounds (mappings, locus),
- has_opening_scope_resolution (has_opening_scope_resolution),
- segments (std::move (segments))
- {}
+ location_t locus, bool has_opening_scope_resolution = false);
// Copy constructor with vector clone
- TypePath (TypePath const &other)
- : TypeNoBounds (other.mappings, other.locus),
- has_opening_scope_resolution (other.has_opening_scope_resolution)
- {
- segments.reserve (other.segments.size ());
- for (const auto &e : other.segments)
- segments.push_back (e->clone_type_path_segment ());
- }
+ TypePath (TypePath const &other);
// Overloaded assignment operator with clone
- TypePath &operator= (TypePath const &other)
- {
- has_opening_scope_resolution = other.has_opening_scope_resolution;
- locus = other.locus;
- mappings = other.mappings;
-
- segments.reserve (other.segments.size ());
- for (const auto &e : other.segments)
- segments.push_back (e->clone_type_path_segment ());
-
- return *this;
- }
+ TypePath &operator= (TypePath const &other);
// move constructors
TypePath (TypePath &&other) = default;
@@ -739,7 +584,7 @@ public:
AST::SimplePath as_simple_path () const;
// Creates a trait bound with a clone of this type path as its only element.
- TraitBound *to_trait_bound (bool in_parens) const override;
+ std::unique_ptr<TraitBound> to_trait_bound (bool in_parens) const override;
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRTypeVisitor &vis) override;
@@ -751,10 +596,7 @@ public:
return segments;
}
- std::unique_ptr<TypePathSegment> &get_final_segment ()
- {
- return segments.back ();
- }
+ TypePathSegment &get_final_segment () { return *segments.back (); }
};
class QualifiedPathType
@@ -767,36 +609,16 @@ class QualifiedPathType
public:
// Constructor
QualifiedPathType (Analysis::NodeMapping mappings, std::unique_ptr<Type> type,
- std::unique_ptr<TypePath> trait, location_t locus)
- : type (std::move (type)), trait (std::move (trait)), locus (locus),
- mappings (mappings)
- {}
+ std::unique_ptr<TypePath> trait, location_t locus);
// Copy constructor uses custom deep copy for Type to preserve polymorphism
- QualifiedPathType (QualifiedPathType const &other)
- : type (other.type->clone_type ()),
- trait (other.has_as_clause () ? std::unique_ptr<HIR::TypePath> (
- new HIR::TypePath (*other.trait))
- : nullptr),
- locus (other.locus), mappings (other.mappings)
- {}
+ QualifiedPathType (QualifiedPathType const &other);
// default destructor
~QualifiedPathType () = default;
// overload assignment operator to use custom clone method
- QualifiedPathType &operator= (QualifiedPathType const &other)
- {
- type = other.type->clone_type ();
- locus = other.locus;
- mappings = other.mappings;
- trait
- = other.has_as_clause ()
- ? std::unique_ptr<HIR::TypePath> (new HIR::TypePath (*other.trait))
- : nullptr;
-
- return *this;
- }
+ QualifiedPathType &operator= (QualifiedPathType const &other);
// move constructor
QualifiedPathType (QualifiedPathType &&other) = default;
@@ -815,26 +637,9 @@ public:
TypePath &get_trait () { return *trait; }
- bool trait_has_generic_args () const
- {
- rust_assert (has_as_clause ());
- bool is_generic_seg = trait->get_final_segment ()->get_type ()
- == TypePathSegment::SegmentType::GENERIC;
- if (!is_generic_seg)
- return false;
-
- TypePathSegmentGeneric *seg = static_cast<TypePathSegmentGeneric *> (
- trait->get_final_segment ().get ());
- return seg->has_generic_args ();
- }
+ bool trait_has_generic_args () const;
- GenericArgs &get_trait_generic_args ()
- {
- rust_assert (trait_has_generic_args ());
- TypePathSegmentGeneric *seg = static_cast<TypePathSegmentGeneric *> (
- trait->get_final_segment ().get ());
- return seg->get_generic_args ();
- }
+ GenericArgs &get_trait_generic_args ();
};
/* HIR node representing a qualified path-in-expression pattern (path that
@@ -852,11 +657,7 @@ public:
std::vector<PathExprSegment> path_segments,
location_t locus = UNDEF_LOCATION,
std::vector<AST::Attribute> outer_attrs
- = std::vector<AST::Attribute> ())
- : PathPattern (std::move (path_segments)),
- PathExpr (std::move (mappings), std::move (outer_attrs)),
- path_type (std::move (qual_path_type)), locus (locus)
- {}
+ = std::vector<AST::Attribute> ());
location_t get_locus () const override final { return locus; }
@@ -917,40 +718,13 @@ public:
Analysis::NodeMapping mappings, QualifiedPathType qual_path_type,
std::unique_ptr<TypePathSegment> associated_segment,
std::vector<std::unique_ptr<TypePathSegment> > path_segments,
- location_t locus = UNDEF_LOCATION)
- : TypeNoBounds (mappings, locus), path_type (std::move (qual_path_type)),
- associated_segment (std::move (associated_segment)),
- segments (std::move (path_segments))
- {}
+ location_t locus = UNDEF_LOCATION);
// Copy constructor with vector clone
- QualifiedPathInType (QualifiedPathInType const &other)
- : TypeNoBounds (other.mappings, other.locus), path_type (other.path_type)
- {
- auto seg = other.associated_segment->clone_type_path_segment_impl ();
- associated_segment = std::unique_ptr<TypePathSegment> (seg);
-
- segments.reserve (other.segments.size ());
- for (const auto &e : other.segments)
- segments.push_back (e->clone_type_path_segment ());
- }
+ QualifiedPathInType (QualifiedPathInType const &other);
// Overloaded assignment operator with vector clone
- QualifiedPathInType &operator= (QualifiedPathInType const &other)
- {
- auto seg = other.associated_segment->clone_type_path_segment_impl ();
- associated_segment = std::unique_ptr<TypePathSegment> (seg);
-
- path_type = other.path_type;
- locus = other.locus;
- mappings = other.mappings;
-
- segments.reserve (other.segments.size ());
- for (const auto &e : other.segments)
- segments.push_back (e->clone_type_path_segment ());
-
- return *this;
- }
+ QualifiedPathInType &operator= (QualifiedPathInType const &other);
// move constructors
QualifiedPathInType (QualifiedPathInType &&other) = default;
@@ -971,40 +745,6 @@ public:
}
};
-class SimplePathSegment
-{
- Analysis::NodeMapping mappings;
-
-public:
- SimplePathSegment (Analysis::NodeMapping mappings) : mappings (mappings) {}
-
- const Analysis::NodeMapping &get_mappings () const { return mappings; }
-};
-
-class SimplePath
-{
- std::vector<SimplePathSegment> segments;
- Analysis::NodeMapping mappings;
- location_t locus;
-
-public:
- SimplePath (std::vector<SimplePathSegment> segments,
- Analysis::NodeMapping mappings, location_t locus)
- : segments (std::move (segments)), mappings (mappings), locus (locus)
- {}
-
- static HIR::SimplePath create_empty ()
- {
- return HIR::SimplePath ({}, Analysis::NodeMapping::get_error (),
- UNDEF_LOCATION);
- }
-
- bool is_error () const { return segments.empty (); }
-
- const Analysis::NodeMapping &get_mappings () const { return mappings; }
- location_t get_locus () const { return locus; }
-};
-
} // namespace HIR
} // namespace Rust
diff --git a/gcc/rust/hir/tree/rust-hir-pattern-abstract.h b/gcc/rust/hir/tree/rust-hir-pattern-abstract.h
new file mode 100644
index 00000000000..b156a807239
--- /dev/null
+++ b/gcc/rust/hir/tree/rust-hir-pattern-abstract.h
@@ -0,0 +1,82 @@
+// Copyright (C) 2020-2024 Free Software Foundation, Inc.
+
+// This file is part of GCC.
+
+// GCC is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3, or (at your option) any later
+// version.
+
+// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with GCC; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#ifndef RUST_HIR_PATTERN_ABSTRACT_H
+#define RUST_HIR_PATTERN_ABSTRACT_H
+
+#include "rust-hir-visitable.h"
+#include "rust-hir-visitor.h"
+#include "rust-hir-node.h"
+#include "rust-system.h"
+
+namespace Rust {
+namespace HIR {
+
+// Pattern base HIR node
+class Pattern : public Node, virtual public FullVisitable
+{
+public:
+ using FullVisitable::accept_vis;
+
+ enum PatternType
+ {
+ PATH,
+ LITERAL,
+ IDENTIFIER,
+ WILDCARD,
+ RANGE,
+ REFERENCE,
+ STRUCT,
+ TUPLE_STRUCT,
+ TUPLE,
+ GROUPED,
+ SLICE,
+ ALT
+ };
+
+ BaseKind get_hir_kind () override final { return PATTERN; }
+
+ // Unique pointer custom clone function
+ std::unique_ptr<Pattern> clone_pattern () const
+ {
+ return std::unique_ptr<Pattern> (clone_pattern_impl ());
+ }
+
+ // possible virtual methods: is_refutable()
+
+ virtual ~Pattern () {}
+
+ virtual std::string as_string () const = 0;
+
+ virtual void accept_vis (HIRPatternVisitor &vis) = 0;
+
+ virtual const Analysis::NodeMapping &get_mappings () const = 0;
+
+ virtual location_t get_locus () const = 0;
+
+ virtual PatternType get_pattern_type () const = 0;
+
+protected:
+ // Clone pattern implementation as pure virtual method
+ virtual Pattern *clone_pattern_impl () const = 0;
+};
+
+} // namespace HIR
+} // namespace Rust
+
+#endif
diff --git a/gcc/rust/hir/tree/rust-hir-pattern.h b/gcc/rust/hir/tree/rust-hir-pattern.h
index df26a396457..5cc5c9512ec 100644
--- a/gcc/rust/hir/tree/rust-hir-pattern.h
+++ b/gcc/rust/hir/tree/rust-hir-pattern.h
@@ -19,12 +19,13 @@
#ifndef RUST_HIR_PATTERN_H
#define RUST_HIR_PATTERN_H
+#include "rust-hir-pattern-abstract.h"
#include "rust-common.h"
-#include "rust-hir.h"
+#include "rust-hir-literal.h"
+#include "rust-hir-path.h"
namespace Rust {
namespace HIR {
-
// Literal pattern HIR node (comparing to a literal)
class LiteralPattern : public Pattern
{
diff --git a/gcc/rust/hir/tree/rust-hir-simple-path.h b/gcc/rust/hir/tree/rust-hir-simple-path.h
new file mode 100644
index 00000000000..7f832ff0850
--- /dev/null
+++ b/gcc/rust/hir/tree/rust-hir-simple-path.h
@@ -0,0 +1,64 @@
+// Copyright (C) 2020-2024 Free Software Foundation, Inc.
+
+// This file is part of GCC.
+
+// GCC is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3, or (at your option) any later
+// version.
+
+// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with GCC; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#ifndef RUST_HIR_SIMPLE_PATH_H
+#define RUST_HIR_SIMPLE_PATH_H
+
+#include "rust-hir-map.h"
+
+namespace Rust {
+namespace HIR {
+
+class SimplePathSegment
+{
+ Analysis::NodeMapping mappings;
+
+public:
+ SimplePathSegment (Analysis::NodeMapping mappings) : mappings (mappings) {}
+
+ const Analysis::NodeMapping &get_mappings () const { return mappings; }
+};
+
+class SimplePath
+{
+ std::vector<SimplePathSegment> segments;
+ Analysis::NodeMapping mappings;
+ location_t locus;
+
+public:
+ SimplePath (std::vector<SimplePathSegment> segments,
+ Analysis::NodeMapping mappings, location_t locus)
+ : segments (std::move (segments)), mappings (mappings), locus (locus)
+ {}
+
+ static HIR::SimplePath create_empty ()
+ {
+ return HIR::SimplePath ({}, Analysis::NodeMapping::get_error (),
+ UNDEF_LOCATION);
+ }
+
+ bool is_error () const { return segments.empty (); }
+
+ const Analysis::NodeMapping &get_mappings () const { return mappings; }
+ location_t get_locus () const { return locus; }
+};
+
+} // namespace HIR
+} // namespace Rust
+
+#endif
diff --git a/gcc/rust/hir/tree/rust-hir-stmt.cc b/gcc/rust/hir/tree/rust-hir-stmt.cc
new file mode 100644
index 00000000000..764ea118ceb
--- /dev/null
+++ b/gcc/rust/hir/tree/rust-hir-stmt.cc
@@ -0,0 +1,98 @@
+// Copyright (C) 2020-2024 Free Software Foundation, Inc.
+
+// This file is part of GCC.
+
+// GCC is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3, or (at your option) any later
+// version.
+
+// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with GCC; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include "rust-hir-stmt.h"
+
+namespace Rust {
+namespace HIR {
+
+LetStmt::LetStmt (Analysis::NodeMapping mappings,
+ std::unique_ptr<Pattern> variables_pattern,
+ std::unique_ptr<Expr> init_expr, std::unique_ptr<Type> type,
+ AST::AttrVec outer_attrs, location_t locus)
+ : Stmt (std::move (mappings)), outer_attrs (std::move (outer_attrs)),
+ variables_pattern (std::move (variables_pattern)), type (std::move (type)),
+ init_expr (std::move (init_expr)), locus (locus)
+{}
+
+LetStmt::LetStmt (LetStmt const &other)
+ : Stmt (other.mappings), outer_attrs (other.outer_attrs), locus (other.locus)
+{
+ // guard to prevent null dereference (only required if error state)
+ if (other.variables_pattern != nullptr)
+ variables_pattern = other.variables_pattern->clone_pattern ();
+
+ // guard to prevent null dereference (always required)
+ if (other.init_expr != nullptr)
+ init_expr = other.init_expr->clone_expr ();
+ if (other.type != nullptr)
+ type = other.type->clone_type ();
+}
+
+LetStmt &
+LetStmt::operator= (LetStmt const &other)
+{
+ outer_attrs = other.outer_attrs;
+ locus = other.locus;
+
+ // guard to prevent null dereference (only required if error state)
+ if (other.variables_pattern != nullptr)
+ variables_pattern = other.variables_pattern->clone_pattern ();
+ else
+ variables_pattern = nullptr;
+
+ // guard to prevent null dereference (always required)
+ if (other.init_expr != nullptr)
+ init_expr = other.init_expr->clone_expr ();
+ else
+ init_expr = nullptr;
+ if (other.type != nullptr)
+ type = other.type->clone_type ();
+ else
+ type = nullptr;
+
+ return *this;
+}
+
+ExprStmt::ExprStmt (Analysis::NodeMapping mappings, std::unique_ptr<Expr> expr,
+ location_t locus, bool must_be_unit)
+ : Stmt (std::move (mappings)), expr (std::move (expr)), locus (locus),
+ must_be_unit (must_be_unit)
+{}
+
+ExprStmt::ExprStmt (Analysis::NodeMapping mappings, std::unique_ptr<Expr> expr,
+ location_t locus)
+ : ExprStmt (std::move (mappings), std::move (expr), locus, false)
+{}
+
+ExprStmt::ExprStmt (ExprStmt const &other)
+ : Stmt (other), expr (other.expr->clone_expr ()), locus (other.locus)
+{}
+
+ExprStmt &
+ExprStmt::operator= (ExprStmt const &other)
+{
+ Stmt::operator= (other);
+ expr = other.expr->clone_expr ();
+ locus = other.locus;
+
+ return *this;
+}
+
+} // namespace HIR
+} // namespace Rust
diff --git a/gcc/rust/hir/tree/rust-hir-stmt.h b/gcc/rust/hir/tree/rust-hir-stmt.h
index 7320bb62385..7540dfaaf34 100644
--- a/gcc/rust/hir/tree/rust-hir-stmt.h
+++ b/gcc/rust/hir/tree/rust-hir-stmt.h
@@ -25,6 +25,44 @@
namespace Rust {
namespace HIR {
+/* Base statement abstract class. Note that most "statements" are not allowed in
+ * top-level module scope - only a subclass of statements called "items" are. */
+class Stmt : public Node, public FullVisitable
+{
+public:
+ using FullVisitable::accept_vis;
+
+ // Unique pointer custom clone function
+ std::unique_ptr<Stmt> clone_stmt () const
+ {
+ return std::unique_ptr<Stmt> (clone_stmt_impl ());
+ }
+
+ BaseKind get_hir_kind () override { return STMT; }
+
+ virtual ~Stmt () {}
+
+ virtual std::string as_string () const = 0;
+
+ virtual void accept_vis (HIRStmtVisitor &vis) = 0;
+
+ virtual location_t get_locus () const = 0;
+
+ virtual bool is_unit_check_needed () const { return false; }
+
+ const Analysis::NodeMapping &get_mappings () const { return mappings; }
+
+ virtual bool is_item () const = 0;
+
+protected:
+ Stmt (Analysis::NodeMapping mappings) : mappings (std::move (mappings)) {}
+
+ // Clone function implementation as pure virtual method
+ virtual Stmt *clone_stmt_impl () const = 0;
+
+ Analysis::NodeMapping mappings;
+};
+
// Just a semi-colon, which apparently is a statement.
class EmptyStmt : public Stmt
{
@@ -82,52 +120,13 @@ public:
LetStmt (Analysis::NodeMapping mappings,
std::unique_ptr<Pattern> variables_pattern,
std::unique_ptr<Expr> init_expr, std::unique_ptr<Type> type,
- AST::AttrVec outer_attrs, location_t locus)
- : Stmt (std::move (mappings)), outer_attrs (std::move (outer_attrs)),
- variables_pattern (std::move (variables_pattern)),
- type (std::move (type)), init_expr (std::move (init_expr)), locus (locus)
- {}
+ AST::AttrVec outer_attrs, location_t locus);
// Copy constructor with clone
- LetStmt (LetStmt const &other)
- : Stmt (other.mappings), outer_attrs (other.outer_attrs),
- locus (other.locus)
- {
- // guard to prevent null dereference (only required if error state)
- if (other.variables_pattern != nullptr)
- variables_pattern = other.variables_pattern->clone_pattern ();
-
- // guard to prevent null dereference (always required)
- if (other.init_expr != nullptr)
- init_expr = other.init_expr->clone_expr ();
- if (other.type != nullptr)
- type = other.type->clone_type ();
- }
+ LetStmt (LetStmt const &other);
// Overloaded assignment operator to clone
- LetStmt &operator= (LetStmt const &other)
- {
- outer_attrs = other.outer_attrs;
- locus = other.locus;
-
- // guard to prevent null dereference (only required if error state)
- if (other.variables_pattern != nullptr)
- variables_pattern = other.variables_pattern->clone_pattern ();
- else
- variables_pattern = nullptr;
-
- // guard to prevent null dereference (always required)
- if (other.init_expr != nullptr)
- init_expr = other.init_expr->clone_expr ();
- else
- init_expr = nullptr;
- if (other.type != nullptr)
- type = other.type->clone_type ();
- else
- type = nullptr;
-
- return *this;
- }
+ LetStmt &operator= (LetStmt const &other);
// move constructors
LetStmt (LetStmt &&other) = default;
@@ -167,15 +166,10 @@ class ExprStmt : public Stmt
public:
ExprStmt (Analysis::NodeMapping mappings, std::unique_ptr<Expr> expr,
- location_t locus, bool must_be_unit)
- : Stmt (std::move (mappings)), expr (std::move (expr)), locus (locus),
- must_be_unit (must_be_unit)
- {}
+ location_t locus, bool must_be_unit);
ExprStmt (Analysis::NodeMapping mappings, std::unique_ptr<Expr> expr,
- location_t locus)
- : ExprStmt (std::move (mappings), std::move (expr), locus, false)
- {}
+ location_t locus);
std::string as_string () const override;
@@ -189,19 +183,10 @@ public:
Expr &get_expr () { return *expr; }
// Copy constructor with clone
- ExprStmt (ExprStmt const &other)
- : Stmt (other), expr (other.expr->clone_expr ()), locus (other.locus)
- {}
+ ExprStmt (ExprStmt const &other);
// Overloaded assignment operator to clone
- ExprStmt &operator= (ExprStmt const &other)
- {
- Stmt::operator= (other);
- expr = other.expr->clone_expr ();
- locus = other.locus;
-
- return *this;
- }
+ ExprStmt &operator= (ExprStmt const &other);
// move constructors
ExprStmt (ExprStmt &&other) = default;
diff --git a/gcc/rust/hir/tree/rust-hir-trait-bound.h b/gcc/rust/hir/tree/rust-hir-trait-bound.h
new file mode 100644
index 00000000000..d20fa794f58
--- /dev/null
+++ b/gcc/rust/hir/tree/rust-hir-trait-bound.h
@@ -0,0 +1,87 @@
+// Copyright (C) 2020-2024 Free Software Foundation, Inc.
+
+// This file is part of GCC.
+
+// GCC is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3, or (at your option) any later
+// version.
+
+// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with GCC; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#ifndef RUST_HIR_TRAIT_BOUND_H
+#define RUST_HIR_TRAIT_BOUND_H
+
+#include "rust-hir-bound-abstract.h"
+#include "rust-hir-path.h"
+#include "rust-hir-generic-param.h"
+
+namespace Rust {
+namespace HIR {
+
+// A trait bound
+class TraitBound : public TypeParamBound
+{
+ bool in_parens;
+ BoundPolarity polarity;
+ std::vector<LifetimeParam> for_lifetimes;
+ TypePath type_path;
+ location_t locus;
+
+ Analysis::NodeMapping mappings;
+
+public:
+ // Returns whether trait bound has "for" lifetimes
+ bool has_for_lifetimes () const { return !for_lifetimes.empty (); }
+
+ TraitBound (Analysis::NodeMapping mapping, TypePath type_path,
+ location_t locus, bool in_parens = false,
+ BoundPolarity polarity = BoundPolarity::RegularBound,
+ std::vector<LifetimeParam> for_lifetimes
+ = std::vector<LifetimeParam> ())
+ : in_parens (in_parens), polarity (polarity),
+ for_lifetimes (std::move (for_lifetimes)),
+ type_path (std::move (type_path)), locus (locus), mappings (mapping)
+ {}
+
+ std::string as_string () const override;
+
+ location_t get_locus () const override final { return locus; }
+
+ void accept_vis (HIRFullVisitor &vis) override;
+
+ Analysis::NodeMapping get_mappings () const override final
+ {
+ return mappings;
+ }
+
+ std::vector<LifetimeParam> &get_for_lifetimes () { return for_lifetimes; }
+ bool get_in_parens () { return in_parens; }
+ BoundPolarity get_polarity () { return polarity; }
+
+ BoundType get_bound_type () const final override { return TRAITBOUND; }
+
+ TypePath &get_path () { return type_path; }
+
+ const TypePath &get_path () const { return type_path; }
+
+protected:
+ /* Use covariance to implement clone function as returning this object rather
+ * than base */
+ TraitBound *clone_type_param_bound_impl () const override
+ {
+ return new TraitBound (*this);
+ }
+};
+
+} // namespace HIR
+} // namespace Rust
+
+#endif
diff --git a/gcc/rust/hir/tree/rust-hir-type-abstract.cc b/gcc/rust/hir/tree/rust-hir-type-abstract.cc
new file mode 100644
index 00000000000..901c603c383
--- /dev/null
+++ b/gcc/rust/hir/tree/rust-hir-type-abstract.cc
@@ -0,0 +1,32 @@
+// Copyright (C) 2020-2024 Free Software Foundation, Inc.
+
+// This file is part of GCC.
+
+// GCC is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3, or (at your option) any later
+// version.
+
+// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with GCC; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include "rust-hir-type-abstract.h"
+#include "rust-hir-trait-bound.h"
+
+namespace Rust {
+namespace HIR {
+
+std::unique_ptr<TraitBound>
+Type::to_trait_bound (bool in_parens ATTRIBUTE_UNUSED) const
+{
+ return std::unique_ptr<TraitBound> (nullptr);
+}
+
+} // namespace HIR
+} // namespace Rust
diff --git a/gcc/rust/hir/tree/rust-hir-type-abstract.h b/gcc/rust/hir/tree/rust-hir-type-abstract.h
new file mode 100644
index 00000000000..6142d88b972
--- /dev/null
+++ b/gcc/rust/hir/tree/rust-hir-type-abstract.h
@@ -0,0 +1,80 @@
+// Copyright (C) 2020-2024 Free Software Foundation, Inc.
+
+// This file is part of GCC.
+
+// GCC is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3, or (at your option) any later
+// version.
+
+// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with GCC; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#ifndef RUST_HIR_TYPE_ABSTRACT_H
+#define RUST_HIR_TYPE_ABSTRACT_H
+
+#include "rust-hir-node.h"
+#include "rust-hir-visitable.h"
+#include "rust-system.h"
+#include "rust-hir-map.h"
+
+namespace Rust {
+namespace HIR {
+
+class TraitBound;
+
+// Base class for types as represented in HIR - abstract
+class Type : public Node, public FullVisitable
+{
+public:
+ using FullVisitable::accept_vis;
+ // Unique pointer custom clone function
+ std::unique_ptr<Type> clone_type () const
+ {
+ return std::unique_ptr<Type> (clone_type_impl ());
+ }
+
+ // virtual destructor
+ virtual ~Type () {}
+
+ BaseKind get_hir_kind () override final { return TYPE; }
+
+ virtual std::string as_string () const = 0;
+
+ /* HACK: convert to trait bound. Virtual method overriden by classes that
+ * enable this. */
+ virtual std::unique_ptr<TraitBound>
+ to_trait_bound (bool in_parens ATTRIBUTE_UNUSED) const;
+ /* as pointer, shouldn't require definition beforehand, only forward
+ * declaration. */
+
+ virtual void accept_vis (HIRTypeVisitor &vis) = 0;
+
+ virtual const Analysis::NodeMapping &get_mappings () const
+ {
+ return mappings;
+ }
+ virtual location_t get_locus () const { return locus; }
+
+protected:
+ Type (Analysis::NodeMapping mappings, location_t locus)
+ : mappings (mappings), locus (locus)
+ {}
+
+ // Clone function implementation as pure virtual method
+ virtual Type *clone_type_impl () const = 0;
+
+ Analysis::NodeMapping mappings;
+ location_t locus;
+};
+
+} // namespace HIR
+} // namespace Rust
+
+#endif
diff --git a/gcc/rust/hir/tree/rust-hir-type-no-bounds.h b/gcc/rust/hir/tree/rust-hir-type-no-bounds.h
new file mode 100644
index 00000000000..b86ff30fd85
--- /dev/null
+++ b/gcc/rust/hir/tree/rust-hir-type-no-bounds.h
@@ -0,0 +1,58 @@
+
+// Copyright (C) 2020-2024 Free Software Foundation, Inc.
+
+// This file is part of GCC.
+
+// GCC is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3, or (at your option) any later
+// version.
+
+// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with GCC; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#ifndef RUST_HIR_TYPE_NO_BOUNDS_H
+#define RUST_HIR_TYPE_NO_BOUNDS_H
+
+#include "rust-hir-type-abstract.h"
+
+namespace Rust {
+namespace HIR {
+
+// A type without parentheses? - abstract
+class TypeNoBounds : public Type
+{
+public:
+ // Unique pointer custom clone function
+ std::unique_ptr<TypeNoBounds> clone_type_no_bounds () const
+ {
+ return std::unique_ptr<TypeNoBounds> (clone_type_no_bounds_impl ());
+ }
+
+protected:
+ TypeNoBounds (Analysis::NodeMapping mappings, location_t locus)
+ : Type (mappings, locus)
+ {}
+
+ // Clone function implementation as pure virtual method
+ virtual TypeNoBounds *clone_type_no_bounds_impl () const = 0;
+
+ /* Save having to specify two clone methods in derived classes by making type
+ * clone return typenobounds clone. Hopefully won't affect performance too
+ * much. */
+ TypeNoBounds *clone_type_impl () const override
+ {
+ return clone_type_no_bounds_impl ();
+ }
+};
+
+} // namespace HIR
+} // namespace Rust
+
+#endif
diff --git a/gcc/rust/hir/tree/rust-hir-type.cc b/gcc/rust/hir/tree/rust-hir-type.cc
new file mode 100644
index 00000000000..689d86b7372
--- /dev/null
+++ b/gcc/rust/hir/tree/rust-hir-type.cc
@@ -0,0 +1,289 @@
+
+// Copyright (C) 2020-2024 Free Software Foundation, Inc.
+
+// This file is part of GCC.
+
+// GCC is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3, or (at your option) any later
+// version.
+
+// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with GCC; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include "rust-hir-type.h"
+
+namespace Rust {
+namespace HIR {
+
+ImplTraitType::ImplTraitType (
+ Analysis::NodeMapping mappings,
+ std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds,
+ location_t locus)
+ : Type (mappings, locus), type_param_bounds (std::move (type_param_bounds))
+{}
+
+ImplTraitType::ImplTraitType (ImplTraitType const &other)
+ : Type (other.mappings, other.locus)
+{
+ type_param_bounds.reserve (other.type_param_bounds.size ());
+ for (const auto &e : other.type_param_bounds)
+ type_param_bounds.push_back (e->clone_type_param_bound ());
+}
+
+ImplTraitType &
+ImplTraitType::operator= (ImplTraitType const &other)
+{
+ locus = other.locus;
+ mappings = other.mappings;
+
+ type_param_bounds.reserve (other.type_param_bounds.size ());
+ for (const auto &e : other.type_param_bounds)
+ type_param_bounds.push_back (e->clone_type_param_bound ());
+
+ return *this;
+}
+
+TraitObjectType::TraitObjectType (
+ Analysis::NodeMapping mappings,
+ std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds,
+ location_t locus, bool is_dyn_dispatch)
+ : Type (mappings, locus), has_dyn (is_dyn_dispatch),
+ type_param_bounds (std::move (type_param_bounds))
+{}
+
+TraitObjectType::TraitObjectType (TraitObjectType const &other)
+ : Type (other.mappings, other.locus), has_dyn (other.has_dyn)
+{
+ type_param_bounds.reserve (other.type_param_bounds.size ());
+ for (const auto &e : other.type_param_bounds)
+ type_param_bounds.push_back (e->clone_type_param_bound ());
+}
+
+TraitObjectType &
+TraitObjectType::operator= (TraitObjectType const &other)
+{
+ mappings = other.mappings;
+ has_dyn = other.has_dyn;
+ locus = other.locus;
+ type_param_bounds.reserve (other.type_param_bounds.size ());
+ for (const auto &e : other.type_param_bounds)
+ type_param_bounds.push_back (e->clone_type_param_bound ());
+
+ return *this;
+}
+
+ParenthesisedType::ParenthesisedType (Analysis::NodeMapping mappings,
+ std::unique_ptr<Type> type_inside_parens,
+ location_t locus)
+ : TypeNoBounds (mappings, locus),
+ type_in_parens (std::move (type_inside_parens))
+{}
+
+ParenthesisedType::ParenthesisedType (ParenthesisedType const &other)
+ : TypeNoBounds (other.mappings, other.locus),
+ type_in_parens (other.type_in_parens->clone_type ())
+{}
+
+ParenthesisedType &
+ParenthesisedType::operator= (ParenthesisedType const &other)
+{
+ mappings = other.mappings;
+ type_in_parens = other.type_in_parens->clone_type ();
+ locus = other.locus;
+ return *this;
+}
+
+std::unique_ptr<TraitBound>
+ParenthesisedType::to_trait_bound (bool in_parens ATTRIBUTE_UNUSED) const
+{
+ /* NOTE: obviously it is unknown whether the internal type is a trait bound
+ * due to polymorphism, so just let the internal type handle it. As
+ * parenthesised type, it must be in parentheses. */
+ return type_in_parens->to_trait_bound (true);
+}
+
+TupleType::TupleType (Analysis::NodeMapping mappings,
+ std::vector<std::unique_ptr<Type>> elems,
+ location_t locus)
+ : TypeNoBounds (mappings, locus), elems (std::move (elems))
+{}
+
+TupleType::TupleType (TupleType const &other)
+ : TypeNoBounds (other.mappings, other.locus)
+{
+ mappings = other.mappings;
+ elems.reserve (other.elems.size ());
+ for (const auto &e : other.elems)
+ elems.push_back (e->clone_type ());
+}
+
+TupleType &
+TupleType::operator= (TupleType const &other)
+{
+ locus = other.locus;
+
+ elems.reserve (other.elems.size ());
+ for (const auto &e : other.elems)
+ elems.push_back (e->clone_type ());
+
+ return *this;
+}
+
+NeverType::NeverType (Analysis::NodeMapping mappings, location_t locus)
+ : TypeNoBounds (mappings, locus)
+{}
+
+RawPointerType::RawPointerType (Analysis::NodeMapping mappings, Mutability mut,
+ std::unique_ptr<Type> type, location_t locus)
+ : TypeNoBounds (mappings, locus), mut (mut), type (std::move (type))
+{}
+
+RawPointerType::RawPointerType (RawPointerType const &other)
+ : TypeNoBounds (other.mappings, other.locus), mut (other.mut),
+ type (other.type->clone_type ())
+{}
+
+RawPointerType &
+RawPointerType::operator= (RawPointerType const &other)
+{
+ mappings = other.mappings;
+ mut = other.mut;
+ type = other.type->clone_type ();
+ locus = other.locus;
+ return *this;
+}
+
+ReferenceType::ReferenceType (Analysis::NodeMapping mappings, Mutability mut,
+ std::unique_ptr<Type> type_no_bounds,
+ location_t locus, Lifetime lifetime)
+ : TypeNoBounds (mappings, locus), lifetime (std::move (lifetime)), mut (mut),
+ type (std::move (type_no_bounds))
+{}
+
+ReferenceType::ReferenceType (ReferenceType const &other)
+ : TypeNoBounds (other.mappings, other.locus), lifetime (other.lifetime),
+ mut (other.mut), type (other.type->clone_type ())
+{}
+
+ReferenceType &
+ReferenceType::operator= (ReferenceType const &other)
+{
+ mappings = other.mappings;
+ lifetime = other.lifetime;
+ mut = other.mut;
+ type = other.type->clone_type ();
+ locus = other.locus;
+
+ return *this;
+}
+
+ArrayType::ArrayType (Analysis::NodeMapping mappings,
+ std::unique_ptr<Type> type,
+ std::unique_ptr<Expr> array_size, location_t locus)
+ : TypeNoBounds (mappings, locus), elem_type (std::move (type)),
+ size (std::move (array_size))
+{}
+
+ArrayType::ArrayType (ArrayType const &other)
+ : TypeNoBounds (other.mappings, other.locus),
+ elem_type (other.elem_type->clone_type ()), size (other.size->clone_expr ())
+{}
+
+ArrayType &
+ArrayType::operator= (ArrayType const &other)
+{
+ mappings = other.mappings;
+ elem_type = other.elem_type->clone_type ();
+ size = other.size->clone_expr ();
+ locus = other.locus;
+ return *this;
+}
+
+SliceType::SliceType (Analysis::NodeMapping mappings,
+ std::unique_ptr<Type> type, location_t locus)
+ : TypeNoBounds (mappings, locus), elem_type (std::move (type))
+{}
+
+SliceType::SliceType (SliceType const &other)
+ : TypeNoBounds (other.mappings, other.locus),
+ elem_type (other.elem_type->clone_type ())
+{}
+
+SliceType &
+SliceType::operator= (SliceType const &other)
+{
+ mappings = other.mappings;
+ elem_type = other.elem_type->clone_type ();
+ locus = other.locus;
+
+ return *this;
+}
+
+InferredType::InferredType (Analysis::NodeMapping mappings, location_t locus)
+ : TypeNoBounds (mappings, locus)
+{}
+
+MaybeNamedParam::MaybeNamedParam (Identifier name, ParamKind param_kind,
+ std::unique_ptr<Type> param_type,
+ location_t locus)
+ : param_type (std::move (param_type)), param_kind (param_kind),
+ name (std::move (name)), locus (locus)
+{}
+
+MaybeNamedParam::MaybeNamedParam (MaybeNamedParam const &other)
+ : param_type (other.param_type->clone_type ()), param_kind (other.param_kind),
+ name (other.name), locus (other.locus)
+{}
+
+MaybeNamedParam &
+MaybeNamedParam::operator= (MaybeNamedParam const &other)
+{
+ name = other.name;
+ param_kind = other.param_kind;
+ param_type = other.param_type->clone_type ();
+ locus = other.locus;
+
+ return *this;
+}
+
+BareFunctionType::BareFunctionType (
+ Analysis::NodeMapping mappings, std::vector<LifetimeParam> lifetime_params,
+ FunctionQualifiers qualifiers, std::vector<MaybeNamedParam> named_params,
+ bool is_variadic, std::unique_ptr<Type> type, location_t locus)
+ : TypeNoBounds (mappings, locus), for_lifetimes (std::move (lifetime_params)),
+ function_qualifiers (std::move (qualifiers)),
+ params (std::move (named_params)), is_variadic (is_variadic),
+ return_type (std::move (type))
+{}
+
+BareFunctionType::BareFunctionType (BareFunctionType const &other)
+ : TypeNoBounds (other.mappings, other.locus),
+ for_lifetimes (other.for_lifetimes),
+ function_qualifiers (other.function_qualifiers), params (other.params),
+ is_variadic (other.is_variadic),
+ return_type (other.return_type->clone_type ())
+{}
+
+BareFunctionType &
+BareFunctionType::operator= (BareFunctionType const &other)
+{
+ mappings = other.mappings;
+ for_lifetimes = other.for_lifetimes;
+ function_qualifiers = other.function_qualifiers;
+ params = other.params;
+ is_variadic = other.is_variadic;
+ return_type = other.return_type->clone_type ();
+ locus = other.locus;
+
+ return *this;
+}
+
+} // namespace HIR
+} // namespace Rust
diff --git a/gcc/rust/hir/tree/rust-hir-type.h b/gcc/rust/hir/tree/rust-hir-type.h
index 26c3d2dfa49..e231d78b2ce 100644
--- a/gcc/rust/hir/tree/rust-hir-type.h
+++ b/gcc/rust/hir/tree/rust-hir-type.h
@@ -19,73 +19,13 @@
#ifndef RUST_HIR_TYPE_H
#define RUST_HIR_TYPE_H
+#include "rust-hir-type-abstract.h"
#include "rust-common.h"
-#include "rust-hir.h"
-#include "rust-hir-path.h"
+#include "rust-hir-trait-bound.h"
+#include "rust-hir-item.h"
namespace Rust {
namespace HIR {
-// definitions moved to rust-ast.h
-class TypeParamBound;
-class Lifetime;
-
-// A trait bound
-class TraitBound : public TypeParamBound
-{
- bool in_parens;
- BoundPolarity polarity;
- std::vector<LifetimeParam> for_lifetimes;
- TypePath type_path;
- location_t locus;
-
- Analysis::NodeMapping mappings;
-
-public:
- // Returns whether trait bound has "for" lifetimes
- bool has_for_lifetimes () const { return !for_lifetimes.empty (); }
-
- TraitBound (Analysis::NodeMapping mapping, TypePath type_path,
- location_t locus, bool in_parens = false,
- BoundPolarity polarity = BoundPolarity::RegularBound,
- std::vector<LifetimeParam> for_lifetimes
- = std::vector<LifetimeParam> ())
- : in_parens (in_parens), polarity (polarity),
- for_lifetimes (std::move (for_lifetimes)),
- type_path (std::move (type_path)), locus (locus), mappings (mapping)
- {}
-
- std::string as_string () const override;
-
- location_t get_locus () const override final { return locus; }
-
- void accept_vis (HIRFullVisitor &vis) override;
-
- Analysis::NodeMapping get_mappings () const override final
- {
- return mappings;
- }
-
- std::vector<LifetimeParam> &get_for_lifetimes () { return for_lifetimes; }
- bool get_in_parens () { return in_parens; }
- BoundPolarity get_polarity () { return polarity; }
-
- BoundType get_bound_type () const final override { return TRAITBOUND; }
-
- TypePath &get_path () { return type_path; }
-
- const TypePath &get_path () const { return type_path; }
-
-protected:
- /* Use covariance to implement clone function as returning this object rather
- * than base */
- TraitBound *clone_type_param_bound_impl () const override
- {
- return new TraitBound (*this);
- }
-};
-
-// definition moved to rust-ast.h
-class TypeNoBounds;
// An impl trait? Poor reference material here.
class ImplTraitType : public Type
@@ -105,31 +45,13 @@ protected:
public:
ImplTraitType (Analysis::NodeMapping mappings,
std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds,
- location_t locus)
- : Type (mappings, locus), type_param_bounds (std::move (type_param_bounds))
- {}
+ location_t locus);
// copy constructor with vector clone
- ImplTraitType (ImplTraitType const &other)
- : Type (other.mappings, other.locus)
- {
- type_param_bounds.reserve (other.type_param_bounds.size ());
- for (const auto &e : other.type_param_bounds)
- type_param_bounds.push_back (e->clone_type_param_bound ());
- }
+ ImplTraitType (ImplTraitType const &other);
// overloaded assignment operator to clone
- ImplTraitType &operator= (ImplTraitType const &other)
- {
- locus = other.locus;
- mappings = other.mappings;
-
- type_param_bounds.reserve (other.type_param_bounds.size ());
- for (const auto &e : other.type_param_bounds)
- type_param_bounds.push_back (e->clone_type_param_bound ());
-
- return *this;
- }
+ ImplTraitType &operator= (ImplTraitType const &other);
// move constructors
ImplTraitType (ImplTraitType &&other) = default;
@@ -162,32 +84,13 @@ public:
TraitObjectType (
Analysis::NodeMapping mappings,
std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds,
- location_t locus, bool is_dyn_dispatch)
- : Type (mappings, locus), has_dyn (is_dyn_dispatch),
- type_param_bounds (std::move (type_param_bounds))
- {}
+ location_t locus, bool is_dyn_dispatch);
// copy constructor with vector clone
- TraitObjectType (TraitObjectType const &other)
- : Type (other.mappings, other.locus), has_dyn (other.has_dyn)
- {
- type_param_bounds.reserve (other.type_param_bounds.size ());
- for (const auto &e : other.type_param_bounds)
- type_param_bounds.push_back (e->clone_type_param_bound ());
- }
+ TraitObjectType (TraitObjectType const &other);
// overloaded assignment operator to clone
- TraitObjectType &operator= (TraitObjectType const &other)
- {
- mappings = other.mappings;
- has_dyn = other.has_dyn;
- locus = other.locus;
- type_param_bounds.reserve (other.type_param_bounds.size ());
- for (const auto &e : other.type_param_bounds)
- type_param_bounds.push_back (e->clone_type_param_bound ());
-
- return *this;
- }
+ TraitObjectType &operator= (TraitObjectType const &other);
// move constructors
TraitObjectType (TraitObjectType &&other) = default;
@@ -233,26 +136,15 @@ protected:
public:
// Constructor uses Type pointer for polymorphism
ParenthesisedType (Analysis::NodeMapping mappings,
- std::unique_ptr<Type> type_inside_parens, location_t locus)
- : TypeNoBounds (mappings, locus),
- type_in_parens (std::move (type_inside_parens))
- {}
+ std::unique_ptr<Type> type_inside_parens,
+ location_t locus);
/* Copy constructor uses custom deep copy method for type to preserve
* polymorphism */
- ParenthesisedType (ParenthesisedType const &other)
- : TypeNoBounds (other.mappings, other.locus),
- type_in_parens (other.type_in_parens->clone_type ())
- {}
+ ParenthesisedType (ParenthesisedType const &other);
// overload assignment operator to use custom clone method
- ParenthesisedType &operator= (ParenthesisedType const &other)
- {
- mappings = other.mappings;
- type_in_parens = other.type_in_parens->clone_type ();
- locus = other.locus;
- return *this;
- }
+ ParenthesisedType &operator= (ParenthesisedType const &other);
// default move semantics
ParenthesisedType (ParenthesisedType &&other) = default;
@@ -264,13 +156,9 @@ public:
}
// Creates a trait bound (clone of this one's trait bound) - HACK
- TraitBound *to_trait_bound (bool in_parens ATTRIBUTE_UNUSED) const override
- {
- /* NOTE: obviously it is unknown whether the internal type is a trait bound
- * due to polymorphism, so just let the internal type handle it. As
- * parenthesised type, it must be in parentheses. */
- return type_in_parens->to_trait_bound (true);
- }
+ std::unique_ptr<TraitBound>
+ to_trait_bound (bool in_parens ATTRIBUTE_UNUSED) const override;
+
Type &get_type_in_parens () { return *type_in_parens; }
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRTypeVisitor &vis) override;
@@ -308,8 +196,6 @@ public:
void accept_vis (HIRTypeVisitor &vis) override;
};
-class TypePath; // definition moved to "rust-path.h"
-
/* A type consisting of the "product" of others (the tuple's elements) in a
* specific order */
class TupleType : public TypeNoBounds
@@ -321,31 +207,13 @@ public:
bool is_unit_type () const { return elems.empty (); }
TupleType (Analysis::NodeMapping mappings,
- std::vector<std::unique_ptr<Type>> elems, location_t locus)
- : TypeNoBounds (mappings, locus), elems (std::move (elems))
- {}
+ std::vector<std::unique_ptr<Type>> elems, location_t locus);
// copy constructor with vector clone
- TupleType (TupleType const &other)
- : TypeNoBounds (other.mappings, other.locus)
- {
- mappings = other.mappings;
- elems.reserve (other.elems.size ());
- for (const auto &e : other.elems)
- elems.push_back (e->clone_type ());
- }
+ TupleType (TupleType const &other);
// overloaded assignment operator to clone
- TupleType &operator= (TupleType const &other)
- {
- locus = other.locus;
-
- elems.reserve (other.elems.size ());
- for (const auto &e : other.elems)
- elems.push_back (e->clone_type ());
-
- return *this;
- }
+ TupleType &operator= (TupleType const &other);
// move constructors
TupleType (TupleType &&other) = default;
@@ -390,9 +258,7 @@ protected:
}
public:
- NeverType (Analysis::NodeMapping mappings, location_t locus)
- : TypeNoBounds (mappings, locus)
- {}
+ NeverType (Analysis::NodeMapping mappings, location_t locus);
std::string as_string () const override { return "! (never type)"; }
@@ -410,25 +276,13 @@ private:
public:
// Constructor requires pointer for polymorphism reasons
RawPointerType (Analysis::NodeMapping mappings, Mutability mut,
- std::unique_ptr<Type> type, location_t locus)
- : TypeNoBounds (mappings, locus), mut (mut), type (std::move (type))
- {}
+ std::unique_ptr<Type> type, location_t locus);
// Copy constructor calls custom polymorphic clone function
- RawPointerType (RawPointerType const &other)
- : TypeNoBounds (other.mappings, other.locus), mut (other.mut),
- type (other.type->clone_type ())
- {}
+ RawPointerType (RawPointerType const &other);
// overload assignment operator to use custom clone method
- RawPointerType &operator= (RawPointerType const &other)
- {
- mappings = other.mappings;
- mut = other.mut;
- type = other.type->clone_type ();
- locus = other.locus;
- return *this;
- }
+ RawPointerType &operator= (RawPointerType const &other);
// default move semantics
RawPointerType (RawPointerType &&other) = default;
@@ -484,28 +338,13 @@ public:
// Constructor
ReferenceType (Analysis::NodeMapping mappings, Mutability mut,
std::unique_ptr<Type> type_no_bounds, location_t locus,
- Lifetime lifetime)
- : TypeNoBounds (mappings, locus), lifetime (std::move (lifetime)),
- mut (mut), type (std::move (type_no_bounds))
- {}
+ Lifetime lifetime);
// Copy constructor with custom clone method
- ReferenceType (ReferenceType const &other)
- : TypeNoBounds (other.mappings, other.locus), lifetime (other.lifetime),
- mut (other.mut), type (other.type->clone_type ())
- {}
+ ReferenceType (ReferenceType const &other);
// Operator overload assignment operator to custom clone the unique pointer
- ReferenceType &operator= (ReferenceType const &other)
- {
- mappings = other.mappings;
- lifetime = other.lifetime;
- mut = other.mut;
- type = other.type->clone_type ();
- locus = other.locus;
-
- return *this;
- }
+ ReferenceType &operator= (ReferenceType const &other);
// move constructors
ReferenceType (ReferenceType &&other) = default;
@@ -547,27 +386,13 @@ class ArrayType : public TypeNoBounds
public:
// Constructor requires pointers for polymorphism
ArrayType (Analysis::NodeMapping mappings, std::unique_ptr<Type> type,
- std::unique_ptr<Expr> array_size, location_t locus)
- : TypeNoBounds (mappings, locus), elem_type (std::move (type)),
- size (std::move (array_size))
- {}
+ std::unique_ptr<Expr> array_size, location_t locus);
// Copy constructor requires deep copies of both unique pointers
- ArrayType (ArrayType const &other)
- : TypeNoBounds (other.mappings, other.locus),
- elem_type (other.elem_type->clone_type ()),
- size (other.size->clone_expr ())
- {}
+ ArrayType (ArrayType const &other);
// Overload assignment operator to deep copy pointers
- ArrayType &operator= (ArrayType const &other)
- {
- mappings = other.mappings;
- elem_type = other.elem_type->clone_type ();
- size = other.size->clone_expr ();
- locus = other.locus;
- return *this;
- }
+ ArrayType &operator= (ArrayType const &other);
// move constructors
ArrayType (ArrayType &&other) = default;
@@ -604,25 +429,13 @@ class SliceType : public TypeNoBounds
public:
// Constructor requires pointer for polymorphism
SliceType (Analysis::NodeMapping mappings, std::unique_ptr<Type> type,
- location_t locus)
- : TypeNoBounds (mappings, locus), elem_type (std::move (type))
- {}
+ location_t locus);
// Copy constructor requires deep copy of Type smart pointer
- SliceType (SliceType const &other)
- : TypeNoBounds (other.mappings, other.locus),
- elem_type (other.elem_type->clone_type ())
- {}
+ SliceType (SliceType const &other);
// Overload assignment operator to deep copy
- SliceType &operator= (SliceType const &other)
- {
- mappings = other.mappings;
- elem_type = other.elem_type->clone_type ();
- locus = other.locus;
-
- return *this;
- }
+ SliceType &operator= (SliceType const &other);
// move constructors
SliceType (SliceType &&other) = default;
@@ -669,9 +482,7 @@ protected:
}
public:
- InferredType (Analysis::NodeMapping mappings, location_t locus)
- : TypeNoBounds (mappings, locus)
- {}
+ InferredType (Analysis::NodeMapping mappings, location_t locus);
std::string as_string () const override;
@@ -679,8 +490,6 @@ public:
void accept_vis (HIRTypeVisitor &vis) override;
};
-class QualifiedPathInType; // definition moved to "rust-path.h"
-
// A possibly named param used in a BaseFunctionType
struct MaybeNamedParam
{
@@ -702,29 +511,15 @@ private:
public:
MaybeNamedParam (Identifier name, ParamKind param_kind,
- std::unique_ptr<Type> param_type, location_t locus)
- : param_type (std::move (param_type)), param_kind (param_kind),
- name (std::move (name)), locus (locus)
- {}
+ std::unique_ptr<Type> param_type, location_t locus);
// Copy constructor with clone
- MaybeNamedParam (MaybeNamedParam const &other)
- : param_type (other.param_type->clone_type ()),
- param_kind (other.param_kind), name (other.name), locus (other.locus)
- {}
+ MaybeNamedParam (MaybeNamedParam const &other);
~MaybeNamedParam () = default;
// Overloaded assignment operator with clone
- MaybeNamedParam &operator= (MaybeNamedParam const &other)
- {
- name = other.name;
- param_kind = other.param_kind;
- param_type = other.param_type->clone_type ();
- locus = other.locus;
-
- return *this;
- }
+ MaybeNamedParam &operator= (MaybeNamedParam const &other);
// move constructors
MaybeNamedParam (MaybeNamedParam &&other) = default;
@@ -777,36 +572,13 @@ public:
std::vector<LifetimeParam> lifetime_params,
FunctionQualifiers qualifiers,
std::vector<MaybeNamedParam> named_params, bool is_variadic,
- std::unique_ptr<Type> type, location_t locus)
- : TypeNoBounds (mappings, locus),
- for_lifetimes (std::move (lifetime_params)),
- function_qualifiers (std::move (qualifiers)),
- params (std::move (named_params)), is_variadic (is_variadic),
- return_type (std::move (type))
- {}
+ std::unique_ptr<Type> type, location_t locus);
// Copy constructor with clone
- BareFunctionType (BareFunctionType const &other)
- : TypeNoBounds (other.mappings, other.locus),
- for_lifetimes (other.for_lifetimes),
- function_qualifiers (other.function_qualifiers), params (other.params),
- is_variadic (other.is_variadic),
- return_type (other.return_type->clone_type ())
- {}
+ BareFunctionType (BareFunctionType const &other);
// Overload assignment operator to deep copy
- BareFunctionType &operator= (BareFunctionType const &other)
- {
- mappings = other.mappings;
- for_lifetimes = other.for_lifetimes;
- function_qualifiers = other.function_qualifiers;
- params = other.params;
- is_variadic = other.is_variadic;
- return_type = other.return_type->clone_type ();
- locus = other.locus;
-
- return *this;
- }
+ BareFunctionType &operator= (BareFunctionType const &other);
// move constructors
BareFunctionType (BareFunctionType &&other) = default;
diff --git a/gcc/rust/hir/tree/rust-hir-visibility.h b/gcc/rust/hir/tree/rust-hir-visibility.h
new file mode 100644
index 00000000000..a750d88f284
--- /dev/null
+++ b/gcc/rust/hir/tree/rust-hir-visibility.h
@@ -0,0 +1,80 @@
+// Copyright (C) 2020-2024 Free Software Foundation, Inc.
+
+// This file is part of GCC.
+
+// GCC is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3, or (at your option) any later
+// version.
+
+// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with GCC; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#ifndef RUST_HIR_VISIBILITY_H
+#define RUST_HIR_VISIBILITY_H
+
+#include "rust-hir-simple-path.h"
+
+namespace Rust {
+namespace HIR {
+// Visibility of an item
+struct Visibility
+{
+public:
+ enum VisType
+ {
+ PRIVATE,
+ PUBLIC,
+ RESTRICTED,
+ ERROR,
+ };
+
+private:
+ VisType vis_type;
+ HIR::SimplePath path;
+ location_t locus;
+
+ // should this store location info?
+
+public:
+ Visibility (VisType vis_type,
+ HIR::SimplePath path = HIR::SimplePath::create_empty (),
+ location_t locus = UNDEF_LOCATION)
+ : vis_type (vis_type), path (std::move (path)), locus (locus)
+ {}
+
+ // Returns whether visibility is in an error state.
+ bool is_error () const { return vis_type == ERROR; }
+
+ // Does the current visibility refer to a simple `pub <item>` entirely public
+ bool is_public () const { return vis_type == PUBLIC; }
+
+ // Is the current visibility public restricted to a certain path
+ bool is_restricted () const { return vis_type == RESTRICTED; }
+
+ // Creates an error visibility.
+ static Visibility create_error ()
+ {
+ return Visibility (ERROR, HIR::SimplePath::create_empty ());
+ }
+
+ VisType get_vis_type () const { return vis_type; }
+
+ const HIR::SimplePath &get_path () const
+ {
+ rust_assert (!is_error ());
+ return path;
+ }
+
+ std::string as_string () const;
+};
+} // namespace HIR
+} // namespace Rust
+
+#endif
diff --git a/gcc/rust/hir/tree/rust-hir-visitable.h b/gcc/rust/hir/tree/rust-hir-visitable.h
new file mode 100644
index 00000000000..9c05cbf8124
--- /dev/null
+++ b/gcc/rust/hir/tree/rust-hir-visitable.h
@@ -0,0 +1,41 @@
+// Copyright (C) 2020-2024 Free Software Foundation, Inc.
+
+// This file is part of GCC.
+
+// GCC is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3, or (at your option) any later
+// version.
+
+// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with GCC; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#ifndef RUST_HIR_VISITABLE_H
+#define RUST_HIR_VISITABLE_H
+
+namespace Rust {
+namespace HIR {
+
+class HIRFullVisitor;
+class HIRTraitItemVisitor;
+class HIRImplVisitor;
+class HIRStmtVisitor;
+class HIRExpressionVisitor;
+class HIRTypeVisitor;
+class HIRPatternVisitor;
+
+class FullVisitable
+{
+public:
+ virtual void accept_vis (HIRFullVisitor &vis) = 0;
+};
+} // namespace HIR
+} // namespace Rust
+
+#endif
diff --git a/gcc/rust/hir/tree/rust-hir-visitor.h b/gcc/rust/hir/tree/rust-hir-visitor.h
index 9948a1555b9..33e6b7bc708 100644
--- a/gcc/rust/hir/tree/rust-hir-visitor.h
+++ b/gcc/rust/hir/tree/rust-hir-visitor.h
@@ -19,7 +19,6 @@
#ifndef RUST_HIR_VISITOR_H
#define RUST_HIR_VISITOR_H
-#include "rust-hir-expr.h"
#include "rust-hir-full-decls.h"
namespace Rust {
diff --git a/gcc/rust/hir/tree/rust-hir.cc b/gcc/rust/hir/tree/rust-hir.cc
index 9de881f6c9c..ea09111bddc 100644
--- a/gcc/rust/hir/tree/rust-hir.cc
+++ b/gcc/rust/hir/tree/rust-hir.cc
@@ -70,6 +70,33 @@ get_string_in_delims (std::string str_input, AST::DelimType delim_type)
rust_unreachable ();
}
+Crate::Crate (std::vector<std::unique_ptr<Item>> items,
+ AST::AttrVec inner_attrs, Analysis::NodeMapping mappings)
+ : WithInnerAttrs (std::move (inner_attrs)), items (std::move (items)),
+ mappings (mappings)
+{}
+
+Crate::Crate (Crate const &other)
+ : WithInnerAttrs (other.inner_attrs), mappings (other.mappings)
+{
+ items.reserve (other.items.size ());
+ for (const auto &e : other.items)
+ items.push_back (e->clone_item ());
+}
+
+Crate &
+Crate::operator= (Crate const &other)
+{
+ inner_attrs = other.inner_attrs;
+ mappings = other.mappings;
+
+ items.reserve (other.items.size ());
+ for (const auto &e : other.items)
+ items.push_back (e->clone_item ());
+
+ return *this;
+}
+
std::string
Crate::as_string () const
{
@@ -2677,14 +2704,14 @@ Expr::as_string () const
}
// hopefully definition here will prevent circular dependency issue
-TraitBound *
+std::unique_ptr<TraitBound>
TypePath::to_trait_bound (bool in_parens) const
{
// create clone FIXME is this required? or is copy constructor automatically
// called?
TypePath copy (*this);
- return new TraitBound (mappings, std::move (copy), copy.get_locus (),
- in_parens);
+ return Rust::make_unique<TraitBound> (mappings, std::move (copy),
+ copy.get_locus (), in_parens);
}
std::string
@@ -3012,7 +3039,7 @@ StructExprStructFields::as_string () const
}
else
{
- str += struct_base->as_string ();
+ str += (*struct_base)->as_string ();
}
return str;
@@ -3994,6 +4021,12 @@ StructExprStructBase::accept_vis (HIRFullVisitor &vis)
vis.visit (*this);
}
+void
+StructExprStructBase::accept_vis (HIRExpressionVisitor &vis)
+{
+ vis.visit (*this);
+}
+
void
CallExpr::accept_vis (HIRFullVisitor &vis)
{
@@ -5152,20 +5185,5 @@ StaticItem::accept_vis (HIRVisItemVisitor &vis)
vis.visit (*this);
}
-std::string
-ConstGenericParam::as_string () const
-{
- auto result = "ConstGenericParam: " + name + " : " + type->as_string ();
-
- if (default_expression)
- result += " = " + default_expression->as_string ();
-
- return result;
-}
-
-void
-ConstGenericParam::accept_vis (HIRFullVisitor &)
-{}
-
} // namespace HIR
} // namespace Rust
diff --git a/gcc/rust/hir/tree/rust-hir.h b/gcc/rust/hir/tree/rust-hir.h
index d208122a0dd..ffab5ffd6a4 100644
--- a/gcc/rust/hir/tree/rust-hir.h
+++ b/gcc/rust/hir/tree/rust-hir.h
@@ -19,778 +19,24 @@
#ifndef RUST_HIR_BASE_H
#define RUST_HIR_BASE_H
-#include "rust-ast.h"
#include "rust-system.h"
+#include "rust-ast.h"
+#include "rust-hir-visitable.h"
+#include "rust-hir-attrs.h"
+
#include "rust-token.h"
+
#include "rust-location.h"
+
#include "rust-hir-map.h"
#include "rust-diagnostics.h"
+#include "rust-hir-bound.h"
namespace Rust {
+
typedef int TupleIndex;
namespace HIR {
-// foward decl: ast visitor
-class HIRFullVisitor;
-class HIRStmtVisitor;
-class HIRTraitItemVisitor;
-class HIRExternalItemVisitor;
-class HIRVisItemVisitor;
-class HIRExpressionVisitor;
-class HIRPatternVisitor;
-class HIRImplVisitor;
-class HIRTypeVisitor;
-
-class WithOuterAttrs
-{
-protected:
- AST::AttrVec outer_attrs;
-
-public:
- AST::AttrVec &get_outer_attrs () { return outer_attrs; }
- const AST::AttrVec &get_outer_attrs () const { return outer_attrs; }
-
- WithOuterAttrs (AST::AttrVec outer_attrs)
- : outer_attrs (std::move (outer_attrs)){};
-};
-
-class WithInnerAttrs
-{
-protected:
- AST::AttrVec inner_attrs;
-
-public:
- AST::AttrVec get_inner_attrs () const { return inner_attrs; }
- WithInnerAttrs (AST::AttrVec inner_attrs)
- : inner_attrs (std::move (inner_attrs)){};
-};
-
-class FullVisitable
-{
-public:
- virtual void accept_vis (HIRFullVisitor &vis) = 0;
-};
-
-// forward decl for use in token tree method
-class Token;
-
-class Node
-{
-public:
- // Kind for downcasting various HIR nodes to other base classes when visiting
- // them
- enum BaseKind
- {
- /* class ExternalItem */
- EXTERNAL,
- /* class TraitItem */
- TRAIT_ITEM,
- /* class VisItem */
- VIS_ITEM,
- /* class Item */
- ITEM,
- /* class ImplItem */
- IMPL,
- /* class Type */
- TYPE,
- /* class Stmt */
- STMT,
- /* class Expr */
- EXPR,
- /* class Pattern */
- PATTERN,
- };
-
- /**
- * Get the kind of HIR node we are dealing with. This is useful for
- * downcasting to more precise types when necessary, i.e going from an `Item*`
- * to a `VisItem*`
- */
- virtual BaseKind get_hir_kind () = 0;
-};
-
-// A literal - value with a type. Used in LiteralExpr and LiteralPattern.
-struct Literal
-{
-public:
- enum LitType
- {
- CHAR,
- STRING,
- BYTE,
- BYTE_STRING,
- INT,
- FLOAT,
- BOOL
- };
-
-private:
- std::string value_as_string;
- LitType type;
- PrimitiveCoreType type_hint;
-
-public:
- std::string as_string () const { return value_as_string; }
-
- LitType get_lit_type () const { return type; }
-
- PrimitiveCoreType get_type_hint () const { return type_hint; }
-
- Literal (std::string value_as_string, LitType type,
- PrimitiveCoreType type_hint)
- : value_as_string (std::move (value_as_string)), type (type),
- type_hint (type_hint)
- {}
-
- static Literal create_error ()
- {
- return Literal ("", CHAR, PrimitiveCoreType::CORETYPE_UNKNOWN);
- }
-
- void set_lit_type (LitType lt) { type = lt; }
-
- // Returns whether literal is in an invalid state.
- bool is_error () const { return value_as_string == ""; }
-
- bool is_equal (Literal &other)
- {
- return value_as_string == other.value_as_string && type == other.type
- && type_hint == other.type_hint;
- }
-};
-
-/* Base statement abstract class. Note that most "statements" are not allowed in
- * top-level module scope - only a subclass of statements called "items" are. */
-class Stmt : public Node, public FullVisitable
-{
-public:
- using FullVisitable::accept_vis;
-
- // Unique pointer custom clone function
- std::unique_ptr<Stmt> clone_stmt () const
- {
- return std::unique_ptr<Stmt> (clone_stmt_impl ());
- }
-
- BaseKind get_hir_kind () override { return STMT; }
-
- virtual ~Stmt () {}
-
- virtual std::string as_string () const = 0;
-
- virtual void accept_vis (HIRStmtVisitor &vis) = 0;
-
- virtual location_t get_locus () const = 0;
-
- virtual bool is_unit_check_needed () const { return false; }
-
- const Analysis::NodeMapping &get_mappings () const { return mappings; }
-
- virtual bool is_item () const = 0;
-
-protected:
- Stmt (Analysis::NodeMapping mappings) : mappings (std::move (mappings)) {}
-
- // Clone function implementation as pure virtual method
- virtual Stmt *clone_stmt_impl () const = 0;
-
- Analysis::NodeMapping mappings;
-};
-
-// Rust "item" HIR node (declaration of top-level/module-level allowed stuff)
-class Item : public Stmt, public WithOuterAttrs
-{
- // TODO: should outer attrs be defined here or in each derived class?
-public:
- enum class ItemKind
- {
- Static,
- Constant,
- TypeAlias,
- Function,
- UseDeclaration,
- ExternBlock,
- ExternCrate,
- Struct,
- Union,
- Enum,
- EnumItem, // FIXME: ARTHUR: Do we need that?
- Trait,
- Impl,
- Module,
- };
-
- static std::string item_kind_string (ItemKind kind);
-
- virtual ItemKind get_item_kind () const = 0;
-
- // Unique pointer custom clone function
- std::unique_ptr<Item> clone_item () const
- {
- return std::unique_ptr<Item> (clone_item_impl ());
- }
-
- BaseKind get_hir_kind () override { return ITEM; }
-
- std::string as_string () const override;
-
- /* Adds crate names to the vector passed by reference, if it can
- * (polymorphism). */
- virtual void
- add_crate_name (std::vector<std::string> &names ATTRIBUTE_UNUSED) const
- {}
-
- bool is_item () const override final { return true; }
-
-protected:
- // Constructor
- Item (Analysis::NodeMapping mappings,
- AST::AttrVec outer_attribs = AST::AttrVec ())
- : Stmt (std::move (mappings)), WithOuterAttrs (std::move (outer_attribs))
- {}
-
- // Clone function implementation as pure virtual method
- virtual Item *clone_item_impl () const = 0;
-
- /* Save having to specify two clone methods in derived classes by making
- * statement clone return item clone. Hopefully won't affect performance too
- * much. */
- Item *clone_stmt_impl () const override { return clone_item_impl (); }
-};
-
-// forward decl of ExprWithoutBlock
-class ExprWithoutBlock;
-
-// Base expression HIR node - abstract
-class Expr : public Node, virtual public FullVisitable
-{
-public:
- using FullVisitable::accept_vis;
-
-protected:
- AST::AttrVec outer_attrs;
- Analysis::NodeMapping mappings;
-
-public:
- enum BlockType
- {
- WITH_BLOCK,
- WITHOUT_BLOCK,
- };
-
- enum ExprType
- {
- Lit,
- Operator,
- Grouped,
- Array,
- ArrayIndex,
- Tuple,
- TupleIdx,
- Struct,
- Call,
- MethodCall,
- FieldAccess,
- Closure,
- Block,
- Continue,
- Break,
- Range,
- Return,
- UnsafeBlock,
- BaseLoop,
- If,
- Match,
- Await,
- AsyncBlock,
- Path,
- InlineAsm,
- };
-
- BaseKind get_hir_kind () override final { return EXPR; }
-
- const AST::AttrVec &get_outer_attrs () const { return outer_attrs; }
-
- // Unique pointer custom clone function
- std::unique_ptr<Expr> clone_expr () const
- {
- return std::unique_ptr<Expr> (clone_expr_impl ());
- }
-
- // TODO: make pure virtual if move out outer attributes to derived classes
- virtual std::string as_string () const;
-
- virtual ~Expr () {}
-
- virtual location_t get_locus () const = 0;
-
- const Analysis::NodeMapping &get_mappings () const { return mappings; }
-
- // Clone function implementation as pure virtual method
- virtual Expr *clone_expr_impl () const = 0;
-
- virtual BlockType get_block_expr_type () const = 0;
-
- virtual ExprType get_expression_type () const = 0;
-
- virtual void accept_vis (HIRExpressionVisitor &vis) = 0;
-
-protected:
- // Constructor
- Expr (Analysis::NodeMapping mappings,
- AST::AttrVec outer_attribs = AST::AttrVec ())
- : outer_attrs (std::move (outer_attribs)), mappings (std::move (mappings))
- {}
-
- // TODO: think of less hacky way to implement this kind of thing
- // Sets outer attributes.
- void set_outer_attrs (AST::AttrVec outer_attrs_to_set)
- {
- outer_attrs = std::move (outer_attrs_to_set);
- }
-};
-
-// HIR node for an expression without an accompanying block - abstract
-class ExprWithoutBlock : public Expr
-{
-protected:
- // Constructor
- ExprWithoutBlock (Analysis::NodeMapping mappings,
- AST::AttrVec outer_attribs = AST::AttrVec ())
- : Expr (std::move (mappings), std::move (outer_attribs))
- {}
-
- // pure virtual clone implementation
- virtual ExprWithoutBlock *clone_expr_without_block_impl () const = 0;
-
- /* Save having to specify two clone methods in derived classes by making expr
- * clone return exprwithoutblock clone. Hopefully won't affect performance too
- * much. */
- ExprWithoutBlock *clone_expr_impl () const override
- {
- return clone_expr_without_block_impl ();
- }
-
-public:
- // Unique pointer custom clone function
- std::unique_ptr<ExprWithoutBlock> clone_expr_without_block () const
- {
- return std::unique_ptr<ExprWithoutBlock> (clone_expr_without_block_impl ());
- }
-
- BlockType get_block_expr_type () const final override
- {
- return BlockType::WITHOUT_BLOCK;
- };
-};
-
-// Pattern base HIR node
-class Pattern : public Node, virtual public FullVisitable
-{
-public:
- using FullVisitable::accept_vis;
-
- enum PatternType
- {
- PATH,
- LITERAL,
- IDENTIFIER,
- WILDCARD,
- RANGE,
- REFERENCE,
- STRUCT,
- TUPLE_STRUCT,
- TUPLE,
- GROUPED,
- SLICE,
- ALT
- };
-
- BaseKind get_hir_kind () override final { return PATTERN; }
-
- // Unique pointer custom clone function
- std::unique_ptr<Pattern> clone_pattern () const
- {
- return std::unique_ptr<Pattern> (clone_pattern_impl ());
- }
-
- // possible virtual methods: is_refutable()
-
- virtual ~Pattern () {}
-
- virtual std::string as_string () const = 0;
-
- virtual void accept_vis (HIRPatternVisitor &vis) = 0;
-
- virtual const Analysis::NodeMapping &get_mappings () const = 0;
-
- virtual location_t get_locus () const = 0;
-
- virtual PatternType get_pattern_type () const = 0;
-
-protected:
- // Clone pattern implementation as pure virtual method
- virtual Pattern *clone_pattern_impl () const = 0;
-};
-
-// forward decl for Type
-class TraitBound;
-
-// Base class for types as represented in HIR - abstract
-class Type : public Node, public FullVisitable
-{
-public:
- using FullVisitable::accept_vis;
- // Unique pointer custom clone function
- std::unique_ptr<Type> clone_type () const
- {
- return std::unique_ptr<Type> (clone_type_impl ());
- }
-
- // virtual destructor
- virtual ~Type () {}
-
- BaseKind get_hir_kind () override final { return TYPE; }
-
- virtual std::string as_string () const = 0;
-
- /* HACK: convert to trait bound. Virtual method overriden by classes that
- * enable this. */
- virtual TraitBound *to_trait_bound (bool in_parens ATTRIBUTE_UNUSED) const
- {
- return nullptr;
- }
- /* as pointer, shouldn't require definition beforehand, only forward
- * declaration. */
-
- virtual void accept_vis (HIRTypeVisitor &vis) = 0;
-
- virtual const Analysis::NodeMapping &get_mappings () const
- {
- return mappings;
- }
- virtual location_t get_locus () const { return locus; }
-
-protected:
- Type (Analysis::NodeMapping mappings, location_t locus)
- : mappings (mappings), locus (locus)
- {}
-
- // Clone function implementation as pure virtual method
- virtual Type *clone_type_impl () const = 0;
-
- Analysis::NodeMapping mappings;
- location_t locus;
-};
-
-// A type without parentheses? - abstract
-class TypeNoBounds : public Type
-{
-public:
- // Unique pointer custom clone function
- std::unique_ptr<TypeNoBounds> clone_type_no_bounds () const
- {
- return std::unique_ptr<TypeNoBounds> (clone_type_no_bounds_impl ());
- }
-
-protected:
- TypeNoBounds (Analysis::NodeMapping mappings, location_t locus)
- : Type (mappings, locus)
- {}
-
- // Clone function implementation as pure virtual method
- virtual TypeNoBounds *clone_type_no_bounds_impl () const = 0;
-
- /* Save having to specify two clone methods in derived classes by making type
- * clone return typenobounds clone. Hopefully won't affect performance too
- * much. */
- TypeNoBounds *clone_type_impl () const override
- {
- return clone_type_no_bounds_impl ();
- }
-};
-
-/* Abstract base class representing a type param bound - Lifetime and TraitBound
- * extends it */
-class TypeParamBound : public FullVisitable
-{
-public:
- using FullVisitable::accept_vis;
- enum BoundType
- {
- LIFETIME,
- TRAITBOUND
- };
-
- virtual ~TypeParamBound () {}
-
- // Unique pointer custom clone function
- std::unique_ptr<TypeParamBound> clone_type_param_bound () const
- {
- return std::unique_ptr<TypeParamBound> (clone_type_param_bound_impl ());
- }
-
- virtual std::string as_string () const = 0;
-
- virtual Analysis::NodeMapping get_mappings () const = 0;
-
- virtual location_t get_locus () const = 0;
-
- virtual BoundType get_bound_type () const = 0;
-
-protected:
- // Clone function implementation as pure virtual method
- virtual TypeParamBound *clone_type_param_bound_impl () const = 0;
-};
-
-// Represents a lifetime (and is also a kind of type param bound)
-class Lifetime : public TypeParamBound
-{
-private:
- AST::Lifetime::LifetimeType lifetime_type;
- std::string lifetime_name;
- location_t locus;
- Analysis::NodeMapping mappings;
-
-public:
- // Constructor
- Lifetime (Analysis::NodeMapping mapping, AST::Lifetime::LifetimeType type,
- std::string name, location_t locus)
- : lifetime_type (type), lifetime_name (std::move (name)), locus (locus),
- mappings (mapping)
- {}
-
- // Returns true if the lifetime is in an error state.
- bool is_error () const
- {
- return lifetime_type == AST::Lifetime::LifetimeType::NAMED
- && lifetime_name.empty ();
- }
-
- static Lifetime error ()
- {
- return Lifetime (Analysis::NodeMapping::get_error (),
- AST::Lifetime::LifetimeType::NAMED, "", UNDEF_LOCATION);
- }
-
- std::string as_string () const override;
-
- void accept_vis (HIRFullVisitor &vis) override;
-
- WARN_UNUSED_RESULT const std::string &get_name () const
- {
- return lifetime_name;
- }
-
- AST::Lifetime::LifetimeType get_lifetime_type () const
- {
- return lifetime_type;
- }
-
- location_t get_locus () const override final { return locus; }
-
- Analysis::NodeMapping get_mappings () const override final
- {
- return mappings;
- }
-
- BoundType get_bound_type () const final override { return LIFETIME; }
-
-protected:
- /* Use covariance to implement clone function as returning this object rather
- * than base */
- Lifetime *clone_type_param_bound_impl () const override
- {
- return new Lifetime (*this);
- }
-};
-
-/* Base generic parameter in HIR. Abstract - can be represented by a Lifetime or
- * Type param */
-class GenericParam : public FullVisitable
-{
-public:
- using FullVisitable::accept_vis;
-
- virtual ~GenericParam () {}
-
- enum class GenericKind
- {
- TYPE,
- LIFETIME,
- CONST,
- };
-
- virtual AST::AttrVec &get_outer_attrs () = 0;
- virtual bool has_outer_attribute () const = 0;
-
- // Unique pointer custom clone function
- std::unique_ptr<GenericParam> clone_generic_param () const
- {
- return std::unique_ptr<GenericParam> (clone_generic_param_impl ());
- }
-
- virtual std::string as_string () const = 0;
-
- virtual location_t get_locus () const = 0;
-
- Analysis::NodeMapping get_mappings () const { return mappings; }
-
- enum GenericKind get_kind () const { return kind; }
-
-protected:
- // Clone function implementation as pure virtual method
- virtual GenericParam *clone_generic_param_impl () const = 0;
-
- Analysis::NodeMapping mappings;
-
- enum GenericKind kind;
-
- GenericParam (Analysis::NodeMapping mapping,
- enum GenericKind kind = GenericKind::TYPE)
- : mappings (mapping), kind (kind)
- {}
-};
-
-// A lifetime generic parameter (as opposed to a type generic parameter)
-class LifetimeParam : public GenericParam
-{
- Lifetime lifetime;
-
- // bool has_lifetime_bounds;
- // LifetimeBounds lifetime_bounds;
- std::vector<Lifetime> lifetime_bounds; // inlined LifetimeBounds
-
- AST::AttrVec outer_attrs;
-
- location_t locus;
-
-public:
- Lifetime get_lifetime () { return lifetime; }
-
- // Returns whether the lifetime param has any lifetime bounds.
- bool has_lifetime_bounds () const { return !lifetime_bounds.empty (); }
-
- std::vector<Lifetime> &get_lifetime_bounds () { return lifetime_bounds; }
-
- // Returns whether the lifetime param has an outer attribute.
- bool has_outer_attribute () const override { return outer_attrs.size () > 1; }
-
- AST::AttrVec &get_outer_attrs () override { return outer_attrs; }
-
- // Returns whether the lifetime param is in an error state.
- bool is_error () const { return lifetime.is_error (); }
-
- // Constructor
- LifetimeParam (Analysis::NodeMapping mappings, Lifetime lifetime,
- location_t locus = UNDEF_LOCATION,
- std::vector<Lifetime> lifetime_bounds
- = std::vector<Lifetime> (),
- AST::AttrVec outer_attrs = std::vector<AST::Attribute> ())
- : GenericParam (mappings, GenericKind::LIFETIME),
- lifetime (std::move (lifetime)),
- lifetime_bounds (std::move (lifetime_bounds)),
- outer_attrs (std::move (outer_attrs)), locus (locus)
- {}
-
- // TODO: remove copy and assignment operator definitions - not required
-
- // Copy constructor with clone
- LifetimeParam (LifetimeParam const &other)
- : GenericParam (other.mappings, GenericKind::LIFETIME),
- lifetime (other.lifetime), lifetime_bounds (other.lifetime_bounds),
- outer_attrs (other.outer_attrs), locus (other.locus)
- {}
-
- // Overloaded assignment operator to clone attribute
- LifetimeParam &operator= (LifetimeParam const &other)
- {
- lifetime = other.lifetime;
- lifetime_bounds = other.lifetime_bounds;
- outer_attrs = other.outer_attrs;
- locus = other.locus;
- mappings = other.mappings;
-
- return *this;
- }
-
- // move constructors
- LifetimeParam (LifetimeParam &&other) = default;
- LifetimeParam &operator= (LifetimeParam &&other) = default;
-
- std::string as_string () const override;
-
- void accept_vis (HIRFullVisitor &vis) override;
-
- location_t get_locus () const override final { return locus; }
-
-protected:
- /* Use covariance to implement clone function as returning this object rather
- * than base */
- LifetimeParam *clone_generic_param_impl () const override
- {
- return new LifetimeParam (*this);
- }
-};
-
-class ConstGenericParam : public GenericParam
-{
-public:
- ConstGenericParam (std::string name, std::unique_ptr<Type> type,
- std::unique_ptr<Expr> default_expression,
- Analysis::NodeMapping mapping, location_t locus)
- : GenericParam (mapping, GenericKind::CONST), name (std::move (name)),
- type (std::move (type)),
- default_expression (std::move (default_expression)), locus (locus)
- {}
-
- ConstGenericParam (const ConstGenericParam &other) : GenericParam (other)
- {
- name = other.name;
- locus = other.locus;
-
- if (other.type)
- type = other.type->clone_type ();
- if (other.default_expression)
- default_expression = other.default_expression->clone_expr ();
- }
-
- bool has_outer_attribute () const override { return false; }
-
- AST::AttrVec &get_outer_attrs () override { return outer_attrs; }
-
- std::string as_string () const override final;
-
- void accept_vis (HIRFullVisitor &vis) override final;
-
- location_t get_locus () const override final { return locus; };
-
- bool has_default_expression () { return default_expression != nullptr; }
-
- std::string get_name () { return name; }
- Type &get_type () { return *type; }
- Expr &get_default_expression () { return *default_expression; }
-
-protected:
- /* Use covariance to implement clone function as returning this object rather
- * than base */
- ConstGenericParam *clone_generic_param_impl () const override
- {
- return new ConstGenericParam (*this);
- }
-
-private:
- std::string name;
- std::unique_ptr<Type> type;
-
- /* const params have no outer attrs, should be empty */
- AST::AttrVec outer_attrs = std::vector<AST::Attribute> ();
-
- /* Optional - can be a null pointer if there is no default expression */
- std::unique_ptr<Expr> default_expression;
-
- location_t locus;
-};
// Item used in trait declarations - abstract base class
class TraitItem : public Node, public FullVisitable
@@ -891,34 +137,15 @@ class Crate : public WithInnerAttrs
public:
// Constructor
Crate (std::vector<std::unique_ptr<Item>> items, AST::AttrVec inner_attrs,
- Analysis::NodeMapping mappings)
- : WithInnerAttrs (std::move (inner_attrs)), items (std::move (items)),
- mappings (mappings)
- {}
+ Analysis::NodeMapping mappings);
// Copy constructor with vector clone
- Crate (Crate const &other)
- : WithInnerAttrs (other.inner_attrs), mappings (other.mappings)
- {
- items.reserve (other.items.size ());
- for (const auto &e : other.items)
- items.push_back (e->clone_item ());
- }
+ Crate (Crate const &other);
~Crate () = default;
// Overloaded assignment operator with vector clone
- Crate &operator= (Crate const &other)
- {
- inner_attrs = other.inner_attrs;
- mappings = other.mappings;
-
- items.reserve (other.items.size ());
- for (const auto &e : other.items)
- items.push_back (e->clone_item ());
-
- return *this;
- }
+ Crate &operator= (Crate const &other);
// Move constructors
Crate (Crate &&other) = default;
@@ -931,27 +158,6 @@ public:
std::vector<std::unique_ptr<Item>> &get_items () { return items; }
};
-// Base path expression HIR node - abstract
-class PathExpr : public ExprWithoutBlock
-{
-protected:
- PathExpr (Analysis::NodeMapping mappings, AST::AttrVec outer_attribs)
- : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs))
- {}
-
-public:
- /* Replaces the outer attributes of this path expression with the given outer
- * attributes. */
- void replace_outer_attrs (AST::AttrVec outer_attrs)
- {
- set_outer_attrs (std::move (outer_attrs));
- }
-
- ExprType get_expression_type () const final override
- {
- return ExprType::Path;
- }
-};
} // namespace HIR
} // namespace Rust
diff --git a/gcc/rust/typecheck/rust-hir-type-check-struct.cc b/gcc/rust/typecheck/rust-hir-type-check-struct.cc
index e19925a96ee..40c42b27980 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-struct.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-struct.cc
@@ -56,17 +56,18 @@ TypeCheckStructExpr::resolve (HIR::StructExprStructFields &struct_expr)
if (struct_expr.has_struct_base ())
{
TyTy::BaseType *base_resolved
- = TypeCheckExpr::Resolve (*struct_expr.struct_base->base_struct);
+ = TypeCheckExpr::Resolve (struct_expr.get_struct_base ().get_base ());
TyTy::BaseType *base_unify = unify_site (
- struct_expr.struct_base->base_struct->get_mappings ().get_hirid (),
+ struct_expr.get_struct_base ().get_base ().get_mappings ().get_hirid (),
TyTy::TyWithLocation (struct_path_resolved),
TyTy::TyWithLocation (base_resolved),
- struct_expr.struct_base->base_struct->get_locus ());
+ struct_expr.get_struct_base ().get_base ().get_locus ());
if (base_unify->get_kind () != struct_path_ty->get_kind ())
{
- rust_fatal_error (struct_expr.struct_base->base_struct->get_locus (),
- "incompatible types for base struct reference");
+ rust_fatal_error (
+ struct_expr.get_struct_base ().get_base ().get_locus (),
+ "incompatible types for base struct reference");
return;
}
@@ -190,26 +191,29 @@ TypeCheckStructExpr::resolve (HIR::StructExprStructFields &struct_expr)
for (auto &missing : missing_fields)
{
HIR::Expr *receiver
- = struct_expr.struct_base->base_struct->clone_expr_impl ();
+ = struct_expr.get_struct_base ().get_base ().clone_expr_impl ();
HIR::StructExprField *implicit_field = nullptr;
AST::AttrVec outer_attribs;
auto crate_num = mappings.get_current_crate ();
- Analysis::NodeMapping mapping (
- crate_num,
- struct_expr.struct_base->base_struct->get_mappings ()
- .get_nodeid (),
- mappings.get_next_hir_id (crate_num), UNKNOWN_LOCAL_DEFID);
+ Analysis::NodeMapping mapping (crate_num,
+ struct_expr.get_struct_base ()
+ .get_base ()
+ .get_mappings ()
+ .get_nodeid (),
+ mappings.get_next_hir_id (
+ crate_num),
+ UNKNOWN_LOCAL_DEFID);
HIR::Expr *field_value = new HIR::FieldAccessExpr (
mapping, std::unique_ptr<HIR::Expr> (receiver), missing,
std::move (outer_attribs),
- struct_expr.struct_base->base_struct->get_locus ());
+ struct_expr.get_struct_base ().get_base ().get_locus ());
implicit_field = new HIR::StructExprFieldIdentifierValue (
mapping, missing, std::unique_ptr<HIR::Expr> (field_value),
- struct_expr.struct_base->base_struct->get_locus ());
+ struct_expr.get_struct_base ().get_base ().get_locus ());
size_t field_index;
bool ok = variant->lookup_field (missing, nullptr, &field_index);
diff --git a/gcc/rust/typecheck/rust-tyty-bounds.cc b/gcc/rust/typecheck/rust-tyty-bounds.cc
index 32c55cd03f1..41844ea741a 100644
--- a/gcc/rust/typecheck/rust-tyty-bounds.cc
+++ b/gcc/rust/typecheck/rust-tyty-bounds.cc
@@ -16,6 +16,7 @@
// along with GCC; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
+#include "rust-hir-full-decls.h"
#include "rust-hir-type-bounds.h"
#include "rust-hir-trait-resolve.h"
#include "rust-substitution-mapper.h"
@@ -203,21 +204,21 @@ TypeCheckBase::get_predicate_from_bound (
= HIR::GenericArgs::create_empty (type_path.get_locus ());
auto &final_seg = type_path.get_final_segment ();
- switch (final_seg->get_type ())
+ switch (final_seg.get_type ())
{
case HIR::TypePathSegment::SegmentType::GENERIC: {
- auto final_generic_seg
- = static_cast<HIR::TypePathSegmentGeneric *> (final_seg.get ());
- if (final_generic_seg->has_generic_args ())
+ auto &final_generic_seg
+ = static_cast<HIR::TypePathSegmentGeneric &> (final_seg);
+ if (final_generic_seg.has_generic_args ())
{
- args = final_generic_seg->get_generic_args ();
+ args = final_generic_seg.get_generic_args ();
}
}
break;
case HIR::TypePathSegment::SegmentType::FUNCTION: {
auto &final_function_seg
- = static_cast<HIR::TypePathSegmentFunction &> (*final_seg);
+ = static_cast<HIR::TypePathSegmentFunction &> (final_seg);
auto &fn = final_function_seg.get_function_path ();
// we need to make implicit generic args which must be an implicit
@@ -225,7 +226,7 @@ TypeCheckBase::get_predicate_from_bound (
auto crate_num = mappings.get_current_crate ();
HirId implicit_args_id = mappings.get_next_hir_id ();
Analysis::NodeMapping mapping (crate_num,
- final_seg->get_mappings ().get_nodeid (),
+ final_seg.get_mappings ().get_nodeid (),
implicit_args_id, UNKNOWN_LOCAL_DEFID);
std::vector<std::unique_ptr<HIR::Type>> params_copy;
@@ -234,12 +235,10 @@ TypeCheckBase::get_predicate_from_bound (
params_copy.push_back (p->clone_type ());
}
- HIR::TupleType *implicit_tuple
- = new HIR::TupleType (mapping, std::move (params_copy),
- final_seg->get_locus ());
-
std::vector<std::unique_ptr<HIR::Type>> inputs;
- inputs.push_back (std::unique_ptr<HIR::Type> (implicit_tuple));
+ inputs.push_back (
+ Rust::make_unique<HIR::TupleType> (mapping, std::move (params_copy),
+ final_seg.get_locus ()));
// resolve the fn_once_output type which assumes there must be an output
// set
@@ -249,7 +248,7 @@ TypeCheckBase::get_predicate_from_bound (
HIR::TraitItem *trait_item
= mappings
.lookup_trait_item_lang_item (LangItem::Kind::FN_ONCE_OUTPUT,
- final_seg->get_locus ())
+ final_seg.get_locus ())
.value ();
std::vector<HIR::GenericArgsBinding> bindings;
@@ -263,7 +262,7 @@ TypeCheckBase::get_predicate_from_bound (
args = HIR::GenericArgs ({} /* lifetimes */,
std::move (inputs) /* type_args*/,
std::move (bindings) /* binding_args*/,
- {} /* const_args */, final_seg->get_locus ());
+ {} /* const_args */, final_seg.get_locus ());
}
break;
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 035/146] gccrs: Fixes some tests appearing with a moved variant
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (33 preceding siblings ...)
2025-03-21 12:05 ` [COMMITTED 034/146] gccrs: Refactor hir to avoid raw pointers and unneeded fwd arthur.cohen
@ 2025-03-21 12:05 ` arthur.cohen
2025-03-21 12:05 ` [COMMITTED 036/146] gccrs: Fix Generic type retrieval arthur.cohen
` (110 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:05 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Pierre-Emmanuel Patry
From: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
A variant being moved lead to a null being created and a segfault later
down the line.
gcc/rust/ChangeLog:
* backend/rust-compile-expr.cc (CompileExpr::visit): Call getter
instead of size function.
* checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::visit):
Only check privacy if the type is present.
* hir/rust-ast-lower-stmt.cc (ASTLoweringStmt::visit): Use an optional.
* hir/tree/rust-hir-generic-param.h: Assert type before getting it.
* hir/tree/rust-hir-item.h: Assert pointers before dereference, fix
has_type condition.
* hir/tree/rust-hir-path.h: Add more assertions.
* hir/tree/rust-hir-stmt.cc: Change constructor with optionals.
* hir/tree/rust-hir-stmt.h: Use optionals over smart pointers to
emphasize these fields might be missing.
* hir/tree/rust-hir.cc (LetStmt::as_string): Use getters.
* typecheck/rust-hir-type-check-expr.cc: Clone structures to prevent
parent's fields from being nulled by the move operation.
* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): Use
optionals.
* typecheck/rust-tyty.cc: Likewise.
* typecheck/rust-tyty.h: Likewise.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
---
gcc/rust/backend/rust-compile-expr.cc | 2 +-
.../errors/privacy/rust-privacy-reporter.cc | 6 +-
gcc/rust/hir/rust-ast-lower-stmt.cc | 20 +++---
gcc/rust/hir/tree/rust-hir-generic-param.h | 6 +-
gcc/rust/hir/tree/rust-hir-item.h | 69 +++++++++++++++----
gcc/rust/hir/tree/rust-hir-path.h | 18 ++++-
gcc/rust/hir/tree/rust-hir-stmt.cc | 26 ++++---
gcc/rust/hir/tree/rust-hir-stmt.h | 40 ++++++++---
gcc/rust/hir/tree/rust-hir.cc | 4 +-
.../typecheck/rust-hir-type-check-expr.cc | 5 +-
.../typecheck/rust-hir-type-check-item.cc | 7 +-
gcc/rust/typecheck/rust-tyty.cc | 40 ++++++++---
gcc/rust/typecheck/rust-tyty.h | 12 +++-
13 files changed, 189 insertions(+), 66 deletions(-)
diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc
index 107ca2eadf5..673acdeefb5 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -1200,7 +1200,7 @@ CompileExpr::visit (HIR::CallExpr &expr)
// this assumes all fields are in order from type resolution and if a
// base struct was specified those fields are filed via accessors
std::vector<tree> arguments;
- for (size_t i = 0; i < expr.get_arguments ().size (); i++)
+ for (size_t i = 0; i < expr.num_params (); i++)
{
auto &argument = expr.get_arguments ().at (i);
auto rvalue = CompileExpr::Compile (*argument, ctx);
diff --git a/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc b/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc
index 71030e5c7ef..3413e5ab3dd 100644
--- a/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc
+++ b/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc
@@ -741,9 +741,11 @@ PrivacyReporter::visit (HIR::EmptyStmt &)
void
PrivacyReporter::visit (HIR::LetStmt &stmt)
{
- check_type_privacy (stmt.get_type ());
+ if (stmt.has_type ())
+ check_type_privacy (stmt.get_type ());
- stmt.get_init_expr ().accept_vis (*this);
+ if (stmt.has_init_expr ())
+ stmt.get_init_expr ().accept_vis (*this);
}
void
diff --git a/gcc/rust/hir/rust-ast-lower-stmt.cc b/gcc/rust/hir/rust-ast-lower-stmt.cc
index c3594594bf1..5a825fd1139 100644
--- a/gcc/rust/hir/rust-ast-lower-stmt.cc
+++ b/gcc/rust/hir/rust-ast-lower-stmt.cc
@@ -16,6 +16,7 @@
// along with GCC; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
+#include "optional.h"
#include "rust-ast-lower-item.h"
#include "rust-ast-lower-stmt.h"
#include "rust-ast-lower-type.h"
@@ -68,12 +69,16 @@ ASTLoweringStmt::visit (AST::LetStmt &stmt)
{
HIR::Pattern *variables
= ASTLoweringPattern::translate (stmt.get_pattern (), true);
- HIR::Type *type = stmt.has_type ()
- ? ASTLoweringType::translate (stmt.get_type ())
- : nullptr;
- HIR::Expr *init_expression
- = stmt.has_init_expr () ? ASTLoweringExpr::translate (stmt.get_init_expr ())
- : nullptr;
+
+ auto type
+ = stmt.has_type () ? tl::optional<std::unique_ptr<Type>> (
+ std::unique_ptr<Type> (ASTLoweringType::translate (stmt.get_type ())))
+ : tl::nullopt;
+ auto init_expression
+ = stmt.has_init_expr ()
+ ? tl::optional<std::unique_ptr<Expr>> (std::unique_ptr<HIR::Expr> (
+ ASTLoweringExpr::translate (stmt.get_init_expr ())))
+ : tl::nullopt;
auto crate_num = mappings.get_current_crate ();
Analysis::NodeMapping mapping (crate_num, stmt.get_node_id (),
@@ -81,8 +86,7 @@ ASTLoweringStmt::visit (AST::LetStmt &stmt)
UNKNOWN_LOCAL_DEFID);
translated
= new HIR::LetStmt (mapping, std::unique_ptr<HIR::Pattern> (variables),
- std::unique_ptr<HIR::Expr> (init_expression),
- std::unique_ptr<HIR::Type> (type),
+ std::move (init_expression), std::move (type),
stmt.get_outer_attrs (), stmt.get_locus ());
}
diff --git a/gcc/rust/hir/tree/rust-hir-generic-param.h b/gcc/rust/hir/tree/rust-hir-generic-param.h
index 73b93d48a49..a1c59bf0d6b 100644
--- a/gcc/rust/hir/tree/rust-hir-generic-param.h
+++ b/gcc/rust/hir/tree/rust-hir-generic-param.h
@@ -156,7 +156,11 @@ public:
bool has_default_expression () { return default_expression != nullptr; }
std::string get_name () { return name; }
- Type &get_type () { return *type; }
+ Type &get_type ()
+ {
+ rust_assert (type);
+ return *type;
+ }
Expr &get_default_expression () { return *default_expression; }
protected:
diff --git a/gcc/rust/hir/tree/rust-hir-item.h b/gcc/rust/hir/tree/rust-hir-item.h
index 39097ceacae..bb300e9ed23 100644
--- a/gcc/rust/hir/tree/rust-hir-item.h
+++ b/gcc/rust/hir/tree/rust-hir-item.h
@@ -24,6 +24,7 @@
#include "rust-common.h"
#include "rust-hir-visibility.h"
#include "rust-hir-generic-param.h"
+#include "rust-system.h"
namespace Rust {
namespace HIR {
@@ -141,7 +142,11 @@ public:
Identifier get_type_representation () const { return type_representation; }
- Type &get_type () { return *type; }
+ Type &get_type ()
+ {
+ rust_assert (type);
+ return *type;
+ }
Analysis::NodeMapping get_type_mappings () const;
@@ -414,7 +419,11 @@ public:
ImplicitSelfKind get_self_kind () const { return self_kind; }
- Type &get_type () { return *type; }
+ Type &get_type ()
+ {
+ rust_assert (type);
+ return *type;
+ }
Analysis::NodeMapping get_mappings () { return mappings; }
@@ -482,7 +491,11 @@ public:
Pattern &get_param_name () { return *param_name; }
- Type &get_type () { return *type; }
+ Type &get_type ()
+ {
+ rust_assert (type);
+ return *type;
+ }
const Analysis::NodeMapping &get_mappings () const { return mappings; }
};
@@ -1112,7 +1125,11 @@ public:
WhereClause &get_where_clause () { return where_clause; }
- Type &get_type_aliased () { return *existing_type; }
+ Type &get_type_aliased ()
+ {
+ rust_assert (existing_type);
+ return *existing_type;
+ }
Identifier get_new_type_name () const { return new_type_name; }
@@ -1766,7 +1783,11 @@ public:
void accept_vis (HIRImplVisitor &vis) override;
void accept_vis (HIRVisItemVisitor &vis) override;
- Type &get_type () { return *type; }
+ Type &get_type ()
+ {
+ rust_assert (type);
+ return *type;
+ }
Expr &get_expr () { return *const_expr; }
@@ -1844,9 +1865,17 @@ public:
bool is_mut () const { return mut == Mutability::Mut; }
- Expr &get_expr () { return *expr; }
+ Expr &get_expr ()
+ {
+ rust_assert (expr);
+ return *expr;
+ }
- Type &get_type () { return *type; }
+ Type &get_type ()
+ {
+ rust_assert (type);
+ return *type;
+ }
ItemKind get_item_kind () const override { return ItemKind::Static; }
@@ -2028,9 +2057,17 @@ public:
bool has_expr () const { return expr != nullptr; }
- Type &get_type () { return *type; }
+ Type &get_type ()
+ {
+ rust_assert (type);
+ return *type;
+ }
- Expr &get_expr () { return *expr; }
+ Expr &get_expr ()
+ {
+ rust_assert (expr);
+ return *expr;
+ }
const std::string trait_identifier () const override final
{
@@ -2274,9 +2311,13 @@ public:
location_t get_locus () const override final { return locus; }
- Type &get_type () { return *impl_type; };
+ Type &get_type ()
+ {
+ rust_assert (impl_type);
+ return *impl_type;
+ };
- bool has_type () { return impl_type == nullptr; }
+ bool has_type () { return impl_type != nullptr; }
std::vector<std::unique_ptr<GenericParam>> &get_generic_params ()
{
@@ -2436,7 +2477,11 @@ public:
Identifier get_param_name () const { return name; }
- Type &get_type () { return *param_type; }
+ Type &get_type ()
+ {
+ rust_assert (param_type);
+ return *param_type;
+ }
Analysis::NodeMapping get_mappings () const { return mappings; }
};
diff --git a/gcc/rust/hir/tree/rust-hir-path.h b/gcc/rust/hir/tree/rust-hir-path.h
index 8b9814f227a..7ef66b86ab0 100644
--- a/gcc/rust/hir/tree/rust-hir-path.h
+++ b/gcc/rust/hir/tree/rust-hir-path.h
@@ -99,8 +99,16 @@ public:
Identifier &get_identifier () { return identifier; }
const Identifier &get_identifier () const { return identifier; }
- Type &get_type () { return *type; }
- const Type &get_type () const { return *type; }
+ Type &get_type ()
+ {
+ rust_assert (type);
+ return *type;
+ }
+ const Type &get_type () const
+ {
+ rust_assert (type);
+ return *type;
+ }
location_t get_locus () const { return locus; }
};
@@ -633,7 +641,11 @@ public:
Analysis::NodeMapping get_mappings () const { return mappings; }
- Type &get_type () { return *type; }
+ Type &get_type ()
+ {
+ rust_assert (type);
+ return *type;
+ }
TypePath &get_trait () { return *trait; }
diff --git a/gcc/rust/hir/tree/rust-hir-stmt.cc b/gcc/rust/hir/tree/rust-hir-stmt.cc
index 764ea118ceb..025f67e2c9b 100644
--- a/gcc/rust/hir/tree/rust-hir-stmt.cc
+++ b/gcc/rust/hir/tree/rust-hir-stmt.cc
@@ -17,13 +17,16 @@
// <http://www.gnu.org/licenses/>.
#include "rust-hir-stmt.h"
+#include "optional.h"
+#include "rust-system.h"
namespace Rust {
namespace HIR {
LetStmt::LetStmt (Analysis::NodeMapping mappings,
std::unique_ptr<Pattern> variables_pattern,
- std::unique_ptr<Expr> init_expr, std::unique_ptr<Type> type,
+ tl::optional<std::unique_ptr<Expr>> init_expr,
+ tl::optional<std::unique_ptr<Type>> type,
AST::AttrVec outer_attrs, location_t locus)
: Stmt (std::move (mappings)), outer_attrs (std::move (outer_attrs)),
variables_pattern (std::move (variables_pattern)), type (std::move (type)),
@@ -38,10 +41,13 @@ LetStmt::LetStmt (LetStmt const &other)
variables_pattern = other.variables_pattern->clone_pattern ();
// guard to prevent null dereference (always required)
- if (other.init_expr != nullptr)
- init_expr = other.init_expr->clone_expr ();
- if (other.type != nullptr)
- type = other.type->clone_type ();
+ if (other.has_init_expr ())
+ init_expr = other.get_init_expr ().clone_expr ();
+
+ if (other.has_type ())
+ type = other.get_type ().clone_type ();
+ else
+ type = tl::nullopt;
}
LetStmt &
@@ -57,14 +63,14 @@ LetStmt::operator= (LetStmt const &other)
variables_pattern = nullptr;
// guard to prevent null dereference (always required)
- if (other.init_expr != nullptr)
- init_expr = other.init_expr->clone_expr ();
+ if (other.has_init_expr ())
+ init_expr = other.get_init_expr ().clone_expr ();
else
init_expr = nullptr;
- if (other.type != nullptr)
- type = other.type->clone_type ();
+ if (other.has_type ())
+ type = other.get_type ().clone_type ();
else
- type = nullptr;
+ type = tl::nullopt;
return *this;
}
diff --git a/gcc/rust/hir/tree/rust-hir-stmt.h b/gcc/rust/hir/tree/rust-hir-stmt.h
index 7540dfaaf34..3db1728202e 100644
--- a/gcc/rust/hir/tree/rust-hir-stmt.h
+++ b/gcc/rust/hir/tree/rust-hir-stmt.h
@@ -22,6 +22,7 @@
#include "rust-hir.h"
#include "rust-hir-path.h"
#include "rust-hir-expr.h"
+#include "rust-system.h"
namespace Rust {
namespace HIR {
@@ -97,11 +98,9 @@ class LetStmt : public Stmt
std::unique_ptr<Pattern> variables_pattern;
- // bool has_type;
- std::unique_ptr<Type> type;
+ tl::optional<std::unique_ptr<Type>> type;
- // bool has_init_expr;
- std::unique_ptr<Expr> init_expr;
+ tl::optional<std::unique_ptr<Expr>> init_expr;
location_t locus;
@@ -110,17 +109,18 @@ public:
bool has_outer_attrs () const { return !outer_attrs.empty (); }
// Returns whether let statement has a given return type.
- bool has_type () const { return type != nullptr; }
+ bool has_type () const { return type.has_value (); }
// Returns whether let statement has an initialisation expression.
- bool has_init_expr () const { return init_expr != nullptr; }
+ bool has_init_expr () const { return init_expr.has_value (); }
std::string as_string () const override;
LetStmt (Analysis::NodeMapping mappings,
std::unique_ptr<Pattern> variables_pattern,
- std::unique_ptr<Expr> init_expr, std::unique_ptr<Type> type,
- AST::AttrVec outer_attrs, location_t locus);
+ tl::optional<std::unique_ptr<Expr>> init_expr,
+ tl::optional<std::unique_ptr<Type>> type, AST::AttrVec outer_attrs,
+ location_t locus);
// Copy constructor with clone
LetStmt (LetStmt const &other);
@@ -143,9 +143,29 @@ public:
}
std::vector<AST::Attribute> &get_outer_attrs () { return outer_attrs; }
- HIR::Type &get_type () { return *type; }
+ HIR::Type &get_type ()
+ {
+ rust_assert (*type);
+ return *type.value ();
+ }
+
+ const HIR::Type &get_type () const
+ {
+ rust_assert (*type);
+ return *type.value ();
+ }
- HIR::Expr &get_init_expr () { return *init_expr; }
+ HIR::Expr &get_init_expr ()
+ {
+ rust_assert (*init_expr);
+ return *init_expr.value ();
+ }
+
+ const HIR::Expr &get_init_expr () const
+ {
+ rust_assert (*init_expr);
+ return *init_expr.value ();
+ }
HIR::Pattern &get_pattern () { return *variables_pattern; }
diff --git a/gcc/rust/hir/tree/rust-hir.cc b/gcc/rust/hir/tree/rust-hir.cc
index ea09111bddc..bccfc526164 100644
--- a/gcc/rust/hir/tree/rust-hir.cc
+++ b/gcc/rust/hir/tree/rust-hir.cc
@@ -2669,12 +2669,12 @@ LetStmt::as_string () const
if (has_type ())
{
- str += " : " + type->as_string ();
+ str += " : " + get_type ().as_string ();
}
if (has_init_expr ())
{
- str += " = " + init_expr->as_string ();
+ str += " = " + get_init_expr ().as_string ();
}
return str;
diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
index e93fa297fd3..d9f0361389f 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
@@ -203,14 +203,13 @@ TypeCheckExpr::visit (HIR::CallExpr &expr)
ok = adt->lookup_variant_by_id (variant_id, &lookup_variant);
rust_assert (ok);
- variant = std::move (*lookup_variant);
+ variant = std::move (*lookup_variant->clone ());
}
else
{
rust_assert (adt->number_of_variants () == 1);
- variant = std::move (*adt->get_variants ().at (0));
+ variant = std::move (*adt->get_variants ().at (0)->clone ());
}
-
infered
= TyTy::TypeCheckCallExpr::go (function_tyty, expr, variant, context);
return;
diff --git a/gcc/rust/typecheck/rust-hir-type-check-item.cc b/gcc/rust/typecheck/rust-hir-type-check-item.cc
index ab684425f27..85ffb9fa5c7 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-item.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-item.cc
@@ -17,6 +17,7 @@
// <http://www.gnu.org/licenses/>.
#include "rust-hir-type-check-item.h"
+#include "optional.h"
#include "rust-canonical-path.h"
#include "rust-diagnostics.h"
#include "rust-hir-type-check-enumitem.h"
@@ -222,7 +223,7 @@ TypeCheckItem::visit (HIR::TupleStruct &struct_decl)
new TyTy::VariantDef (struct_decl.get_mappings ().get_hirid (),
struct_decl.get_mappings ().get_defid (),
struct_decl.get_identifier ().as_string (), ident,
- TyTy::VariantDef::VariantType::TUPLE, nullptr,
+ TyTy::VariantDef::VariantType::TUPLE, tl::nullopt,
std::move (fields)));
// Process #[repr(X)] attribute, if any
@@ -304,7 +305,7 @@ TypeCheckItem::visit (HIR::StructStruct &struct_decl)
new TyTy::VariantDef (struct_decl.get_mappings ().get_hirid (),
struct_decl.get_mappings ().get_defid (),
struct_decl.get_identifier ().as_string (), ident,
- TyTy::VariantDef::VariantType::STRUCT, nullptr,
+ TyTy::VariantDef::VariantType::STRUCT, tl::nullopt,
std::move (fields)));
// Process #[repr(X)] attribute, if any
@@ -437,7 +438,7 @@ TypeCheckItem::visit (HIR::Union &union_decl)
new TyTy::VariantDef (union_decl.get_mappings ().get_hirid (),
union_decl.get_mappings ().get_defid (),
union_decl.get_identifier ().as_string (), ident,
- TyTy::VariantDef::VariantType::STRUCT, nullptr,
+ TyTy::VariantDef::VariantType::STRUCT, tl::nullopt,
std::move (fields)));
auto *type
diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc
index 757cfa59f62..e2f1361a78e 100644
--- a/gcc/rust/typecheck/rust-tyty.cc
+++ b/gcc/rust/typecheck/rust-tyty.cc
@@ -18,6 +18,7 @@
#include "rust-tyty.h"
+#include "optional.h"
#include "rust-tyty-visitor.h"
#include "rust-hir-map.h"
#include "rust-location.h"
@@ -1343,7 +1344,7 @@ VariantDef::variant_type_string (VariantType type)
VariantDef::VariantDef (HirId id, DefId defid, std::string identifier,
RustIdent ident,
- std::unique_ptr<HIR::Expr> &&discriminant)
+ tl::optional<std::unique_ptr<HIR::Expr>> &&discriminant)
: id (id), defid (defid), identifier (identifier), ident (ident),
discriminant (std::move (discriminant))
@@ -1354,7 +1355,7 @@ VariantDef::VariantDef (HirId id, DefId defid, std::string identifier,
VariantDef::VariantDef (HirId id, DefId defid, std::string identifier,
RustIdent ident, VariantType type,
- std::unique_ptr<HIR::Expr> &&discriminant,
+ tl::optional<std::unique_ptr<HIR::Expr>> &&discriminant,
std::vector<StructFieldType *> fields)
: id (id), defid (defid), identifier (identifier), ident (ident), type (type),
discriminant (std::move (discriminant)), fields (fields)
@@ -1369,7 +1370,7 @@ VariantDef::get_error_node ()
static VariantDef node
= VariantDef (UNKNOWN_HIRID, UNKNOWN_DEFID, "",
{Resolver::CanonicalPath::create_empty (), UNKNOWN_LOCATION},
- nullptr);
+ tl::nullopt);
return node;
}
@@ -1461,15 +1462,28 @@ VariantDef::lookup_field (const std::string &lookup,
HIR::Expr &
VariantDef::get_discriminant ()
{
- rust_assert (discriminant != nullptr);
- return *discriminant;
+ return *discriminant.value ();
+}
+
+const HIR::Expr &
+VariantDef::get_discriminant () const
+{
+ return *discriminant.value ();
+}
+
+bool
+VariantDef::has_discriminant () const
+{
+ return discriminant.has_value ();
}
std::string
VariantDef::as_string () const
{
if (type == VariantType::NUM)
- return identifier + " = " + discriminant->as_string ();
+ return identifier
+ + (has_discriminant () ? " = " + get_discriminant ().as_string ()
+ : "");
std::string buffer;
for (size_t i = 0; i < fields.size (); ++i)
@@ -1516,8 +1530,13 @@ VariantDef::clone () const
for (auto &f : fields)
cloned_fields.push_back ((StructFieldType *) f->clone ());
+ auto &&discriminant_opt = has_discriminant ()
+ ? tl::optional<std::unique_ptr<HIR::Expr>> (
+ get_discriminant ().clone_expr ())
+ : tl::nullopt;
+
return new VariantDef (id, defid, identifier, ident, type,
- discriminant->clone_expr (), cloned_fields);
+ std::move (discriminant_opt), cloned_fields);
}
VariantDef *
@@ -1527,8 +1546,13 @@ VariantDef::monomorphized_clone () const
for (auto &f : fields)
cloned_fields.push_back ((StructFieldType *) f->monomorphized_clone ());
+ auto discriminant_opt = has_discriminant ()
+ ? tl::optional<std::unique_ptr<HIR::Expr>> (
+ get_discriminant ().clone_expr ())
+ : tl::nullopt;
+
return new VariantDef (id, defid, identifier, ident, type,
- discriminant->clone_expr (), cloned_fields);
+ std::move (discriminant_opt), cloned_fields);
}
const RustIdent &
diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h
index a74f4497f0c..4d1a082f80d 100644
--- a/gcc/rust/typecheck/rust-tyty.h
+++ b/gcc/rust/typecheck/rust-tyty.h
@@ -570,10 +570,11 @@ public:
static std::string variant_type_string (VariantType type);
VariantDef (HirId id, DefId defid, std::string identifier, RustIdent ident,
- std::unique_ptr<HIR::Expr> &&discriminant);
+ tl::optional<std::unique_ptr<HIR::Expr>> &&discriminant);
VariantDef (HirId id, DefId defid, std::string identifier, RustIdent ident,
- VariantType type, std::unique_ptr<HIR::Expr> &&discriminant,
+ VariantType type,
+ tl::optional<std::unique_ptr<HIR::Expr>> &&discriminant,
std::vector<StructFieldType *> fields);
static VariantDef &get_error_node ();
@@ -596,7 +597,10 @@ public:
bool lookup_field (const std::string &lookup, StructFieldType **field_lookup,
size_t *index) const;
+ bool has_discriminant () const;
+
HIR::Expr &get_discriminant ();
+ const HIR::Expr &get_discriminant () const;
std::string as_string () const;
@@ -614,8 +618,10 @@ private:
std::string identifier;
RustIdent ident;
VariantType type;
+
// can either be a structure or a discriminant value
- std::unique_ptr<HIR::Expr> discriminant;
+ tl::optional<std::unique_ptr<HIR::Expr>> discriminant;
+
std::vector<StructFieldType *> fields;
};
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 036/146] gccrs: Fix Generic type retrieval
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (34 preceding siblings ...)
2025-03-21 12:05 ` [COMMITTED 035/146] gccrs: Fixes some tests appearing with a moved variant arthur.cohen
@ 2025-03-21 12:05 ` arthur.cohen
2025-03-21 12:05 ` [COMMITTED 037/146] gccrs: FnParam cloning now keeps projections arthur.cohen
` (109 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:05 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Pierre-Emmanuel Patry
From: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
gcc/rust/ChangeLog:
* hir/rust-ast-lower-type.cc (ASTLowerGenericParam::visit): Forward
an optional to the constructor.
* hir/tree/rust-hir-item.cc (TypeParam::TypeParam): Use an optional
in the constructor.
(TypeParam::operator=): Ensure the TypeParam has a type properly.
(TypeParam::get_type_mappings): Likewise.
* hir/tree/rust-hir-item.h: Wrap the type smart pointer into an
optional.
* hir/tree/rust-hir.cc (TypeParam::as_string): Unwrap optional type
correctly.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
---
gcc/rust/hir/rust-ast-lower-type.cc | 10 +++++-----
gcc/rust/hir/tree/rust-hir-item.cc | 19 +++++++++++--------
gcc/rust/hir/tree/rust-hir-item.h | 14 ++++++++------
gcc/rust/hir/tree/rust-hir.cc | 2 +-
4 files changed, 25 insertions(+), 20 deletions(-)
diff --git a/gcc/rust/hir/rust-ast-lower-type.cc b/gcc/rust/hir/rust-ast-lower-type.cc
index 7d6ac5ddffa..5836c1ac148 100644
--- a/gcc/rust/hir/rust-ast-lower-type.cc
+++ b/gcc/rust/hir/rust-ast-lower-type.cc
@@ -17,6 +17,7 @@
// <http://www.gnu.org/licenses/>.
#include "rust-ast-lower-type.h"
+#include "optional.h"
#include "rust-attribute-values.h"
namespace Rust {
@@ -502,9 +503,9 @@ ASTLowerGenericParam::visit (AST::TypeParam ¶m)
}
}
- HIR::Type *type = param.has_type ()
- ? ASTLoweringType::translate (param.get_type ())
- : nullptr;
+ auto type = param.has_type () ? tl::optional (std::unique_ptr<HIR::Type> (
+ ASTLoweringType::translate (param.get_type ())))
+ : tl::nullopt;
auto crate_num = mappings.get_current_crate ();
Analysis::NodeMapping mapping (crate_num, param.get_node_id (),
@@ -514,8 +515,7 @@ ASTLowerGenericParam::visit (AST::TypeParam ¶m)
translated
= new HIR::TypeParam (mapping, param.get_type_representation (),
param.get_locus (), std::move (type_param_bounds),
- std::unique_ptr<Type> (type),
- param.get_outer_attrs ());
+ std::move (type), param.get_outer_attrs ());
}
HIR::TypeParamBound *
diff --git a/gcc/rust/hir/tree/rust-hir-item.cc b/gcc/rust/hir/tree/rust-hir-item.cc
index f81f1eae134..cff06d35269 100644
--- a/gcc/rust/hir/tree/rust-hir-item.cc
+++ b/gcc/rust/hir/tree/rust-hir-item.cc
@@ -17,6 +17,7 @@
// <http://www.gnu.org/licenses/>.
#include "rust-hir-item.h"
+#include "optional.h"
namespace Rust {
namespace HIR {
@@ -25,7 +26,7 @@ TypeParam::TypeParam (
Analysis::NodeMapping mappings, Identifier type_representation,
location_t locus,
std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds,
- std::unique_ptr<Type>, AST::AttrVec outer_attrs)
+ tl::optional<std::unique_ptr<Type>> type, AST::AttrVec outer_attrs)
: GenericParam (mappings), outer_attrs (std::move (outer_attrs)),
type_representation (std::move (type_representation)),
type_param_bounds (std::move (type_param_bounds)), type (std::move (type)),
@@ -37,8 +38,10 @@ TypeParam::TypeParam (TypeParam const &other)
type_representation (other.type_representation), locus (other.locus)
{
// guard to prevent null pointer dereference
- if (other.type != nullptr)
- type = other.type->clone_type ();
+ if (other.has_type ())
+ type = {other.type.value ()->clone_type ()};
+ else
+ type = tl::nullopt;
type_param_bounds.reserve (other.type_param_bounds.size ());
for (const auto &e : other.type_param_bounds)
@@ -54,10 +57,10 @@ TypeParam::operator= (TypeParam const &other)
mappings = other.mappings;
// guard to prevent null pointer dereference
- if (other.type != nullptr)
- type = other.type->clone_type ();
+ if (other.has_type ())
+ type = {other.type.value ()->clone_type ()};
else
- type = nullptr;
+ type = tl::nullopt;
type_param_bounds.reserve (other.type_param_bounds.size ());
for (const auto &e : other.type_param_bounds)
@@ -69,8 +72,8 @@ TypeParam::operator= (TypeParam const &other)
Analysis::NodeMapping
TypeParam::get_type_mappings () const
{
- rust_assert (type != nullptr);
- return type->get_mappings ();
+ rust_assert (type.has_value ());
+ return type.value ()->get_mappings ();
}
std::vector<std::unique_ptr<TypeParamBound>> &
diff --git a/gcc/rust/hir/tree/rust-hir-item.h b/gcc/rust/hir/tree/rust-hir-item.h
index bb300e9ed23..0fda1672b74 100644
--- a/gcc/rust/hir/tree/rust-hir-item.h
+++ b/gcc/rust/hir/tree/rust-hir-item.h
@@ -19,6 +19,7 @@
#ifndef RUST_HIR_ITEM_H
#define RUST_HIR_ITEM_H
+#include "optional.h"
#include "rust-abi.h"
#include "rust-hir-stmt.h"
#include "rust-common.h"
@@ -102,14 +103,13 @@ class TypeParam : public GenericParam
std::vector<std::unique_ptr<TypeParamBound>>
type_param_bounds; // inlined form
- // bool has_type;
- std::unique_ptr<Type> type;
+ tl::optional<std::unique_ptr<Type>> type;
location_t locus;
public:
// Returns whether the type of the type param has been specified.
- bool has_type () const { return type != nullptr; }
+ bool has_type () const { return type.has_value (); }
// Returns whether the type param has type param bounds.
bool has_type_param_bounds () const { return !type_param_bounds.empty (); }
@@ -122,7 +122,7 @@ public:
location_t locus = UNDEF_LOCATION,
std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds
= std::vector<std::unique_ptr<TypeParamBound>> (),
- std::unique_ptr<Type> type = nullptr,
+ tl::optional<std::unique_ptr<Type>> type = tl::nullopt,
AST::AttrVec outer_attrs = std::vector<AST::Attribute> ());
// Copy constructor uses clone
@@ -130,8 +130,10 @@ public:
// Overloaded assignment operator to clone
TypeParam &operator= (TypeParam const &other);
+
// move constructors
TypeParam (TypeParam &&other) = default;
+
TypeParam &operator= (TypeParam &&other) = default;
std::string as_string () const override;
@@ -144,8 +146,8 @@ public:
Type &get_type ()
{
- rust_assert (type);
- return *type;
+ rust_assert (*type);
+ return *type.value ();
}
Analysis::NodeMapping get_type_mappings () const;
diff --git a/gcc/rust/hir/tree/rust-hir.cc b/gcc/rust/hir/tree/rust-hir.cc
index bccfc526164..c20d69d2146 100644
--- a/gcc/rust/hir/tree/rust-hir.cc
+++ b/gcc/rust/hir/tree/rust-hir.cc
@@ -2178,7 +2178,7 @@ TypeParam::as_string () const
}
else
{
- str += type->as_string ();
+ str += type.value ()->as_string ();
}
return str;
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 037/146] gccrs: FnParam cloning now keeps projections
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (35 preceding siblings ...)
2025-03-21 12:05 ` [COMMITTED 036/146] gccrs: Fix Generic type retrieval arthur.cohen
@ 2025-03-21 12:05 ` arthur.cohen
2025-03-21 12:05 ` [COMMITTED 038/146] gccrs: Refactor optional initializers arthur.cohen
` (108 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:05 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Pierre-Emmanuel Patry
From: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
FnParam type where monomorphized during cloning.
gcc/rust/ChangeLog:
* typecheck/rust-tyty.h: Reverse monomorphization during cloning and
make a new function to explicitly monomorphize.
* typecheck/rust-tyty.cc: Use monomorphization when required.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
---
gcc/rust/typecheck/rust-tyty.cc | 2 +-
gcc/rust/typecheck/rust-tyty.h | 5 +++++
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc
index e2f1361a78e..1073dfa6adc 100644
--- a/gcc/rust/typecheck/rust-tyty.cc
+++ b/gcc/rust/typecheck/rust-tyty.cc
@@ -597,7 +597,7 @@ BaseType::monomorphized_clone () const
{
std::vector<TyTy::FnParam> cloned_params;
for (auto &p : fn->get_params ())
- cloned_params.push_back (p.clone ());
+ cloned_params.push_back (p.monomorphized_clone ());
BaseType *retty = fn->get_return_type ()->monomorphized_clone ();
return new FnType (fn->get_ref (), fn->get_ty_ref (), fn->get_id (),
diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h
index 4d1a082f80d..94f7bce00f8 100644
--- a/gcc/rust/typecheck/rust-tyty.h
+++ b/gcc/rust/typecheck/rust-tyty.h
@@ -791,6 +791,11 @@ public:
void set_type (BaseType *new_type) { type = new_type; }
FnParam clone () const
+ {
+ return FnParam (pattern->clone_pattern (), type->clone ());
+ }
+
+ FnParam monomorphized_clone () const
{
return FnParam (pattern->clone_pattern (), type->monomorphized_clone ());
}
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 038/146] gccrs: Refactor optional initializers
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (36 preceding siblings ...)
2025-03-21 12:05 ` [COMMITTED 037/146] gccrs: FnParam cloning now keeps projections arthur.cohen
@ 2025-03-21 12:05 ` arthur.cohen
2025-03-21 12:05 ` [COMMITTED 039/146] gccrs: Fix FnParam pattern location ternary logic arthur.cohen
` (107 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:05 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Pierre-Emmanuel Patry
From: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Refactor some optional initializer in the lowering stage to make them
more readable.
gcc/rust/ChangeLog:
* hir/rust-ast-lower-stmt.cc (ASTLoweringStmt::visit): Change the
ternary expression with a more readable if.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
---
gcc/rust/hir/rust-ast-lower-stmt.cc | 20 +++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)
diff --git a/gcc/rust/hir/rust-ast-lower-stmt.cc b/gcc/rust/hir/rust-ast-lower-stmt.cc
index 5a825fd1139..8244e8ae2ba 100644
--- a/gcc/rust/hir/rust-ast-lower-stmt.cc
+++ b/gcc/rust/hir/rust-ast-lower-stmt.cc
@@ -70,15 +70,17 @@ ASTLoweringStmt::visit (AST::LetStmt &stmt)
HIR::Pattern *variables
= ASTLoweringPattern::translate (stmt.get_pattern (), true);
- auto type
- = stmt.has_type () ? tl::optional<std::unique_ptr<Type>> (
- std::unique_ptr<Type> (ASTLoweringType::translate (stmt.get_type ())))
- : tl::nullopt;
- auto init_expression
- = stmt.has_init_expr ()
- ? tl::optional<std::unique_ptr<Expr>> (std::unique_ptr<HIR::Expr> (
- ASTLoweringExpr::translate (stmt.get_init_expr ())))
- : tl::nullopt;
+ tl::optional<std::unique_ptr<Type>> type = tl::nullopt;
+
+ if (stmt.has_type ())
+ type
+ = std::unique_ptr<Type> (ASTLoweringType::translate (stmt.get_type ()));
+
+ tl::optional<std::unique_ptr<HIR::Expr>> init_expression = tl::nullopt;
+
+ if (stmt.has_init_expr ())
+ init_expression = std::unique_ptr<HIR::Expr> (
+ ASTLoweringExpr::translate (stmt.get_init_expr ()));
auto crate_num = mappings.get_current_crate ();
Analysis::NodeMapping mapping (crate_num, stmt.get_node_id (),
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 039/146] gccrs: Fix FnParam pattern location ternary logic
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (37 preceding siblings ...)
2025-03-21 12:05 ` [COMMITTED 038/146] gccrs: Refactor optional initializers arthur.cohen
@ 2025-03-21 12:05 ` arthur.cohen
2025-03-21 12:05 ` [COMMITTED 040/146] gccrs: Add optional template arguments to please GCC4.8 arthur.cohen
` (106 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:05 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Pierre-Emmanuel Patry
From: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Condition was inverted, we should retrieve the locus only if we have a
pattern.
gcc/rust/ChangeLog:
* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Do not
get a reference if the pattern does not exist.
(TypeCheckMethodCallExpr::check): Likewise.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
---
gcc/rust/typecheck/rust-tyty-call.cc | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/gcc/rust/typecheck/rust-tyty-call.cc b/gcc/rust/typecheck/rust-tyty-call.cc
index 725b8414671..5fea34de40a 100644
--- a/gcc/rust/typecheck/rust-tyty-call.cc
+++ b/gcc/rust/typecheck/rust-tyty-call.cc
@@ -152,12 +152,11 @@ TypeCheckCallExpr::visit (FnType &type)
if (i < type.num_params ())
{
auto &fnparam = type.param_at (i);
- auto &fn_param_pattern = fnparam.get_pattern ();
BaseType *param_ty = fnparam.get_type ();
location_t param_locus
= fnparam.has_pattern ()
- ? mappings.lookup_location (param_ty->get_ref ())
- : fn_param_pattern.get_locus ();
+ ? fnparam.get_pattern ().get_locus ()
+ : mappings.lookup_location (param_ty->get_ref ());
HirId coercion_side_id = argument->get_mappings ().get_hirid ();
auto resolved_argument_type
@@ -375,12 +374,11 @@ TypeCheckMethodCallExpr::check (FnType &type)
location_t arg_locus = argument.get_locus ();
auto &fnparam = type.param_at (i);
- HIR::Pattern &fn_param_pattern = fnparam.get_pattern ();
BaseType *param_ty = fnparam.get_type ();
location_t param_locus
= fnparam.has_pattern ()
- ? mappings.lookup_location (param_ty->get_ref ())
- : fn_param_pattern.get_locus ();
+ ? fnparam.get_pattern ().get_locus ()
+ : mappings.lookup_location (param_ty->get_ref ());
auto argument_expr_tyty = argument.get_argument_type ();
HirId coercion_side_id = argument.get_mappings ().get_hirid ();
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 040/146] gccrs: Add optional template arguments to please GCC4.8
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (38 preceding siblings ...)
2025-03-21 12:05 ` [COMMITTED 039/146] gccrs: Fix FnParam pattern location ternary logic arthur.cohen
@ 2025-03-21 12:05 ` arthur.cohen
2025-03-21 12:05 ` [COMMITTED 041/146] gccrs: Use default constructor for default arguments arthur.cohen
` (105 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:05 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Pierre-Emmanuel Patry
From: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Clang on macos as well as GCC 4.8 complains when those templates are
missing.
gcc/rust/ChangeLog:
* hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Add template
to tl::optional.
* hir/rust-ast-lower-type.cc (ASTLowerGenericParam::visit): Likewise.
* typecheck/rust-hir-type-check-type.cc (TypeResolveGenericParam::visit):
Likewise.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
---
gcc/rust/hir/rust-ast-lower-expr.cc | 5 +++--
gcc/rust/hir/rust-ast-lower-type.cc | 8 +++++---
gcc/rust/typecheck/rust-hir-type-check-type.cc | 4 +++-
3 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/gcc/rust/hir/rust-ast-lower-expr.cc b/gcc/rust/hir/rust-ast-lower-expr.cc
index 2954a31d9f4..b45b5f925df 100644
--- a/gcc/rust/hir/rust-ast-lower-expr.cc
+++ b/gcc/rust/hir/rust-ast-lower-expr.cc
@@ -517,8 +517,9 @@ ASTLoweringExpr::visit (AST::StructExprStructFields &struct_expr)
{
HIR::Expr *translated_base = ASTLoweringExpr::translate (
struct_expr.get_struct_base ().get_base_struct ());
- base = tl::optional (Rust::make_unique<StructBase> (
- std::unique_ptr<HIR::Expr> (translated_base)));
+ base = tl::optional<std::unique_ptr<HIR::StructBase>> (
+ Rust::make_unique<StructBase> (
+ std::unique_ptr<HIR::Expr> (translated_base)));
}
auto const &in_fields = struct_expr.get_fields ();
diff --git a/gcc/rust/hir/rust-ast-lower-type.cc b/gcc/rust/hir/rust-ast-lower-type.cc
index 5836c1ac148..58c93b9e25d 100644
--- a/gcc/rust/hir/rust-ast-lower-type.cc
+++ b/gcc/rust/hir/rust-ast-lower-type.cc
@@ -503,9 +503,11 @@ ASTLowerGenericParam::visit (AST::TypeParam ¶m)
}
}
- auto type = param.has_type () ? tl::optional (std::unique_ptr<HIR::Type> (
- ASTLoweringType::translate (param.get_type ())))
- : tl::nullopt;
+ tl::optional<std::unique_ptr<HIR::Type>> type = tl::nullopt;
+ if (param.has_type ())
+ type
+ = tl::optional<std::unique_ptr<HIR::Type>> (std::unique_ptr<HIR::Type> (
+ ASTLoweringType::translate (param.get_type ())));
auto crate_num = mappings.get_current_crate ();
Analysis::NodeMapping mapping (crate_num, param.get_node_id (),
diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.cc b/gcc/rust/typecheck/rust-hir-type-check-type.cc
index 089a5af121a..6e859e5d719 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-type.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-type.cc
@@ -829,7 +829,9 @@ TypeResolveGenericParam::visit (HIR::TypeParam ¶m)
HIR::TraitBound &b = static_cast<HIR::TraitBound &> (*bound);
TyTy::TypeBoundPredicate predicate = get_predicate_from_bound (
- b.get_path (), tl::optional (std::ref (*implicit_self_bound)),
+ b.get_path (),
+ tl::optional<std::reference_wrapper<HIR::Type>> (
+ std::ref (*implicit_self_bound)),
b.get_polarity ());
if (!predicate.is_error ())
{
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 041/146] gccrs: Use default constructor for default arguments
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (39 preceding siblings ...)
2025-03-21 12:05 ` [COMMITTED 040/146] gccrs: Add optional template arguments to please GCC4.8 arthur.cohen
@ 2025-03-21 12:05 ` arthur.cohen
2025-03-21 12:05 ` [COMMITTED 042/146] gccrs: Use a reference wrapper to please GCC 4.8 arthur.cohen
` (104 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:05 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Pierre-Emmanuel Patry
From: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
GCC 4.8 complains about the initializer list.
gcc/rust/ChangeLog:
* typecheck/rust-tyty.h: Change initializer list to default constructor
call.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
---
gcc/rust/typecheck/rust-tyty.h | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h
index 94f7bce00f8..49cd00c9174 100644
--- a/gcc/rust/typecheck/rust-tyty.h
+++ b/gcc/rust/typecheck/rust-tyty.h
@@ -657,7 +657,7 @@ public:
std::vector<SubstitutionParamMapping> subst_refs,
SubstitutionArgumentMappings generic_arguments
= SubstitutionArgumentMappings::error (),
- RegionConstraints region_constraints = {},
+ RegionConstraints region_constraints = RegionConstraints{},
std::set<HirId> refs = std::set<HirId> ())
: BaseType (ref, ref, TypeKind::ADT, ident, refs),
SubstitutionRef (std::move (subst_refs), std::move (generic_arguments),
@@ -670,7 +670,7 @@ public:
std::vector<SubstitutionParamMapping> subst_refs,
SubstitutionArgumentMappings generic_arguments
= SubstitutionArgumentMappings::error (),
- RegionConstraints region_constraints = {},
+ RegionConstraints region_constraints = RegionConstraints{},
std::set<HirId> refs = std::set<HirId> ())
: BaseType (ref, ty_ref, TypeKind::ADT, ident, refs),
SubstitutionRef (std::move (subst_refs), std::move (generic_arguments),
@@ -683,7 +683,7 @@ public:
std::vector<SubstitutionParamMapping> subst_refs, ReprOptions repr,
SubstitutionArgumentMappings generic_arguments
= SubstitutionArgumentMappings::error (),
- RegionConstraints region_constraints = {},
+ RegionConstraints region_constraints = RegionConstraints{},
std::set<HirId> refs = std::set<HirId> ())
: BaseType (ref, ty_ref, TypeKind::ADT, ident, refs),
SubstitutionRef (std::move (subst_refs), std::move (generic_arguments),
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 042/146] gccrs: Use a reference wrapper to please GCC 4.8
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (40 preceding siblings ...)
2025-03-21 12:05 ` [COMMITTED 041/146] gccrs: Use default constructor for default arguments arthur.cohen
@ 2025-03-21 12:05 ` arthur.cohen
2025-03-21 12:05 ` [COMMITTED 043/146] gccrs: Use nr2.0 in PrivacyReporter arthur.cohen
` (103 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:05 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Pierre-Emmanuel Patry
From: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
gcc/rust/ChangeLog:
* backend/rust-compile-expr.cc (CompileExpr::visit): Change call.
(CompileExpr::resolve_operator_overload): Update function arguments.
* backend/rust-compile-expr.h: Change the function's prototype to use
a reference wrapper instead of a reference within the optional.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
---
gcc/rust/backend/rust-compile-expr.cc | 13 +++++++------
gcc/rust/backend/rust-compile-expr.h | 8 ++++----
2 files changed, 11 insertions(+), 10 deletions(-)
diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc
index 673acdeefb5..05c52261cf7 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -31,6 +31,7 @@
#include "convert.h"
#include "print-tree.h"
#include "rust-system.h"
+#include <functional>
namespace Rust {
namespace Compile {
@@ -152,8 +153,9 @@ CompileExpr::visit (HIR::ArithmeticOrLogicalExpr &expr)
{
auto lang_item_type
= LangItem::OperatorToLangItem (expr.get_expr_type ());
- translated = resolve_operator_overload (lang_item_type, expr, lhs, rhs,
- expr.get_lhs (), expr.get_rhs ());
+ translated = resolve_operator_overload (
+ lang_item_type, expr, lhs, rhs, expr.get_lhs (),
+ tl::optional<std::reference_wrapper<HIR::Expr>> (expr.get_rhs ()));
return;
}
@@ -1476,10 +1478,9 @@ CompileExpr::get_receiver_from_dyn (const TyTy::DynamicObjectType *dyn,
}
tree
-CompileExpr::resolve_operator_overload (LangItem::Kind lang_item_type,
- HIR::OperatorExprMeta expr, tree lhs,
- tree rhs, HIR::Expr &lhs_expr,
- tl::optional<HIR::Expr &> rhs_expr)
+CompileExpr::resolve_operator_overload (
+ LangItem::Kind lang_item_type, HIR::OperatorExprMeta expr, tree lhs, tree rhs,
+ HIR::Expr &lhs_expr, tl::optional<std::reference_wrapper<HIR::Expr>> rhs_expr)
{
TyTy::FnType *fntype;
bool is_op_overload = ctx->get_tyctx ()->lookup_operator_overload (
diff --git a/gcc/rust/backend/rust-compile-expr.h b/gcc/rust/backend/rust-compile-expr.h
index 0178a93f144..b8c4220ded7 100644
--- a/gcc/rust/backend/rust-compile-expr.h
+++ b/gcc/rust/backend/rust-compile-expr.h
@@ -96,10 +96,10 @@ protected:
TyTy::BaseType *receiver, TyTy::FnType *fntype,
tree receiver_ref, location_t expr_locus);
- tree resolve_operator_overload (LangItem::Kind lang_item_type,
- HIR::OperatorExprMeta expr, tree lhs,
- tree rhs, HIR::Expr &lhs_expr,
- tl::optional<HIR::Expr &> rhs_expr);
+ tree resolve_operator_overload (
+ LangItem::Kind lang_item_type, HIR::OperatorExprMeta expr, tree lhs,
+ tree rhs, HIR::Expr &lhs_expr,
+ tl::optional<std::reference_wrapper<HIR::Expr>> rhs_expr);
tree compile_bool_literal (const HIR::LiteralExpr &expr,
const TyTy::BaseType *tyty);
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 043/146] gccrs: Use nr2.0 in PrivacyReporter
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (41 preceding siblings ...)
2025-03-21 12:05 ` [COMMITTED 042/146] gccrs: Use a reference wrapper to please GCC 4.8 arthur.cohen
@ 2025-03-21 12:05 ` arthur.cohen
2025-03-21 12:05 ` [COMMITTED 044/146] gccrs: Handle type path segments during late resolution 2.0 arthur.cohen
` (102 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:05 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Owen Avery
From: Owen Avery <powerboat9.gamer@gmail.com>
gcc/rust/ChangeLog:
* checks/errors/privacy/rust-privacy-reporter.cc
(PrivacyReporter::check_for_privacy_violation): Use name
resolver 2.0.
gcc/testsuite/ChangeLog:
* rust/compile/nr2/exclude: Remove entries.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
---
.../checks/errors/privacy/rust-privacy-reporter.cc | 10 +++++++++-
gcc/testsuite/rust/compile/nr2/exclude | 2 --
2 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc b/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc
index 3413e5ab3dd..dcc768ffff1 100644
--- a/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc
+++ b/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc
@@ -127,8 +127,16 @@ PrivacyReporter::check_for_privacy_violation (const NodeId &use_id,
{
NodeId ref_node_id = UNKNOWN_NODEID;
+ if (flag_name_resolution_2_0)
+ {
+ auto &nr_ctx
+ = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+
+ if (auto id = nr_ctx.lookup (use_id))
+ ref_node_id = *id;
+ }
// FIXME: Don't assert here - we might be dealing with a type
- if (!resolver.lookup_resolved_name (use_id, &ref_node_id))
+ else if (!resolver.lookup_resolved_name (use_id, &ref_node_id))
resolver.lookup_resolved_type (use_id, &ref_node_id);
// FIXME: Assert here. For now, we return since this causes issues when
diff --git a/gcc/testsuite/rust/compile/nr2/exclude b/gcc/testsuite/rust/compile/nr2/exclude
index a73b1f027b1..2e956960dad 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -145,8 +145,6 @@ parse_complex_generic_application.rs
parse_complex_generic_application2.rs
path_as_generic_arg.rs
pattern-struct.rs
-privacy1.rs
-privacy3.rs
privacy4.rs
privacy5.rs
privacy8.rs
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 044/146] gccrs: Handle type path segments during late resolution 2.0
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (42 preceding siblings ...)
2025-03-21 12:05 ` [COMMITTED 043/146] gccrs: Use nr2.0 in PrivacyReporter arthur.cohen
@ 2025-03-21 12:05 ` arthur.cohen
2025-03-21 12:05 ` [COMMITTED 045/146] gccrs: Use nr2.0 in typechecker arthur.cohen
` (101 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:05 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Owen Avery
From: Owen Avery <powerboat9.gamer@gmail.com>
gcc/rust/ChangeLog:
* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): Call DefaultResolver::visit when visiting
TypePath.
gcc/testsuite/ChangeLog:
* rust/compile/nr2/exclude: Remove entries.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
---
gcc/rust/resolve/rust-late-name-resolver-2.0.cc | 2 ++
gcc/testsuite/rust/compile/nr2/exclude | 2 --
2 files changed, 2 insertions(+), 2 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 850f96aef89..3af8496288d 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
@@ -263,6 +263,8 @@ Late::visit (AST::TypePath &type)
Definition (resolved->get_node_id ()));
else
rust_unreachable ();
+
+ DefaultResolver::visit (type);
}
void
diff --git a/gcc/testsuite/rust/compile/nr2/exclude b/gcc/testsuite/rust/compile/nr2/exclude
index 2e956960dad..3dbebc703c4 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -42,7 +42,6 @@ generics3.rs
generics4.rs
generics5.rs
generics6.rs
-generics7.rs
generics8.rs
generics9.rs
if_let_expr.rs
@@ -83,7 +82,6 @@ issue-2165.rs
issue-2166.rs
issue-2190-1.rs
issue-2190-2.rs
-issue-2195.rs
issue-2238.rs
issue-2304.rs
issue-2330.rs
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 045/146] gccrs: Use nr2.0 in typechecker
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (43 preceding siblings ...)
2025-03-21 12:05 ` [COMMITTED 044/146] gccrs: Handle type path segments during late resolution 2.0 arthur.cohen
@ 2025-03-21 12:05 ` arthur.cohen
2025-03-21 12:05 ` [COMMITTED 046/146] gccrs: Clean up some system includes arthur.cohen
` (100 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:05 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Owen Avery
From: Owen Avery <powerboat9.gamer@gmail.com>
I probably missed a few spots, but this should cover most of the type
checker.
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-expr.cc: Add includes.
(TypeCheckExpr::visit): Use name resolver 2.0.
(TypeCheckExpr::resolve_operator_overload): Likewise.
(TypeCheckExpr::resolve_fn_trait_call): Likewise.
* typecheck/rust-hir-type-check-path.cc
(TypeCheckExpr::visit): Likewise.
(TypeCheckExpr::resolve_segments): Likewise.
* typecheck/rust-hir-type-check-type.cc
(TypeCheckType::resolve_segments): Likewise.
(ResolveWhereClauseItem::visit): Likewise.
(TypeCheckType::visit): Avoid usage of
Resolver::get_unit_type_node_id when handling TupleType, use
name resolver 2.0 when handling QualifiedPathInType.
gcc/testsuite/ChangeLog:
* rust/compile/nr2/exclude: Remove entries.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
---
.../typecheck/rust-hir-type-check-expr.cc | 45 ++++++-
.../typecheck/rust-hir-type-check-path.cc | 27 +++-
.../typecheck/rust-hir-type-check-type.cc | 122 +++++++++++++-----
gcc/testsuite/rust/compile/nr2/exclude | 4 -
4 files changed, 155 insertions(+), 43 deletions(-)
diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
index d9f0361389f..03922bb554c 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
@@ -27,6 +27,10 @@
#include "rust-hir-type-check-stmt.h"
#include "rust-hir-type-check-item.h"
#include "rust-type-util.h"
+#include "rust-immutable-name-resolution-context.h"
+
+// for flag_name_resolution_2_0
+#include "options.h"
namespace Rust {
namespace Resolver {
@@ -1238,8 +1242,17 @@ TypeCheckExpr::visit (HIR::MethodCallExpr &expr)
// store the expected fntype
context->insert_type (expr.get_method_name ().get_mappings (), lookup);
+ if (flag_name_resolution_2_0)
+ {
+ auto &nr_ctx = const_cast<Resolver2_0::NameResolutionContext &> (
+ Resolver2_0::ImmutableNameResolutionContext::get ().resolver ());
+
+ nr_ctx.map_usage (Resolver2_0::Usage (expr.get_mappings ().get_nodeid ()),
+ Resolver2_0::Definition (resolved_node_id));
+ }
// set up the resolved name on the path
- if (resolver->get_name_scope ().decl_was_declared_here (resolved_node_id))
+ else if (resolver->get_name_scope ().decl_was_declared_here (
+ resolved_node_id))
{
resolver->insert_resolved_name (expr.get_mappings ().get_nodeid (),
resolved_node_id);
@@ -1821,8 +1834,19 @@ TypeCheckExpr::resolve_operator_overload (LangItem::Kind lang_item_type,
context->insert_operator_overload (expr.get_mappings ().get_hirid (), type);
// set up the resolved name on the path
- resolver->insert_resolved_name (expr.get_mappings ().get_nodeid (),
- resolved_node_id);
+ if (flag_name_resolution_2_0)
+ {
+ auto &nr_ctx = const_cast<Resolver2_0::NameResolutionContext &> (
+ Resolver2_0::ImmutableNameResolutionContext::get ().resolver ());
+
+ nr_ctx.map_usage (Resolver2_0::Usage (expr.get_mappings ().get_nodeid ()),
+ Resolver2_0::Definition (resolved_node_id));
+ }
+ else
+ {
+ resolver->insert_resolved_name (expr.get_mappings ().get_nodeid (),
+ resolved_node_id);
+ }
// return the result of the function back
infered = function_ret_tyty;
@@ -1991,8 +2015,19 @@ TypeCheckExpr::resolve_fn_trait_call (HIR::CallExpr &expr,
context->insert_operator_overload (expr.get_mappings ().get_hirid (), fn);
// set up the resolved name on the path
- resolver->insert_resolved_name (expr.get_mappings ().get_nodeid (),
- resolved_node_id);
+ if (flag_name_resolution_2_0)
+ {
+ auto &nr_ctx = const_cast<Resolver2_0::NameResolutionContext &> (
+ Resolver2_0::ImmutableNameResolutionContext::get ().resolver ());
+
+ nr_ctx.map_usage (Resolver2_0::Usage (expr.get_mappings ().get_nodeid ()),
+ Resolver2_0::Definition (resolved_node_id));
+ }
+ else
+ {
+ resolver->insert_resolved_name (expr.get_mappings ().get_nodeid (),
+ resolved_node_id);
+ }
// return the result of the function back
*result = function_ret_tyty;
diff --git a/gcc/rust/typecheck/rust-hir-type-check-path.cc b/gcc/rust/typecheck/rust-hir-type-check-path.cc
index cc79e4d4995..cd0e941edd6 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-path.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-path.cc
@@ -153,8 +153,20 @@ TypeCheckExpr::visit (HIR::QualifiedPathInExpression &expr)
bool fully_resolved = expr.get_segments ().size () <= 1;
if (fully_resolved)
{
- resolver->insert_resolved_name (expr.get_mappings ().get_nodeid (),
- root_resolved_node_id);
+ if (flag_name_resolution_2_0)
+ {
+ auto &nr_ctx = const_cast<Resolver2_0::NameResolutionContext &> (
+ Resolver2_0::ImmutableNameResolutionContext::get ().resolver ());
+
+ nr_ctx.map_usage (Resolver2_0::Usage (
+ expr.get_mappings ().get_nodeid ()),
+ Resolver2_0::Definition (root_resolved_node_id));
+ }
+ else
+ {
+ resolver->insert_resolved_name (expr.get_mappings ().get_nodeid (),
+ root_resolved_node_id);
+ }
context->insert_receiver (expr.get_mappings ().get_hirid (), root);
return;
}
@@ -491,8 +503,17 @@ TypeCheckExpr::resolve_segments (NodeId root_resolved_node_id,
rust_assert (resolved_node_id != UNKNOWN_NODEID);
context->insert_receiver (expr_mappings.get_hirid (), prev_segment);
+ if (flag_name_resolution_2_0)
+ {
+ auto &nr_ctx = const_cast<Resolver2_0::NameResolutionContext &> (
+ Resolver2_0::ImmutableNameResolutionContext::get ().resolver ());
+
+ nr_ctx.map_usage (Resolver2_0::Usage (expr_mappings.get_nodeid ()),
+ Resolver2_0::Definition (resolved_node_id));
+ }
// name scope first
- if (resolver->get_name_scope ().decl_was_declared_here (resolved_node_id))
+ else if (resolver->get_name_scope ().decl_was_declared_here (
+ resolved_node_id))
{
resolver->insert_resolved_name (expr_mappings.get_nodeid (),
resolved_node_id);
diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.cc b/gcc/rust/typecheck/rust-hir-type-check-type.cc
index 6e859e5d719..4ebbaf6d836 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-type.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-type.cc
@@ -111,12 +111,7 @@ TypeCheckType::visit (HIR::TupleType &tuple)
{
if (tuple.is_unit_type ())
{
- auto unit_node_id = resolver->get_unit_type_node_id ();
- if (!context->lookup_builtin (unit_node_id, &translated))
- {
- rust_error_at (tuple.get_locus (),
- "failed to lookup builtin unit type");
- }
+ translated = TyTy::TupleType::get_unit_type ();
return;
}
@@ -176,9 +171,25 @@ TypeCheckType::visit (HIR::QualifiedPathInType &path)
{
// then this is just a normal path-in-expression
NodeId root_resolved_node_id = UNKNOWN_NODEID;
- bool ok = resolver->lookup_resolved_type (
- qual_path_type.get_type ().get_mappings ().get_nodeid (),
- &root_resolved_node_id);
+ bool ok = false;
+ if (flag_name_resolution_2_0)
+ {
+ auto &nr_ctx
+ = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+
+ if (auto id = nr_ctx.lookup (
+ qual_path_type.get_type ().get_mappings ().get_nodeid ()))
+ {
+ root_resolved_node_id = *id;
+ ok = true;
+ }
+ }
+ else
+ {
+ ok = resolver->lookup_resolved_type (
+ qual_path_type.get_type ().get_mappings ().get_nodeid (),
+ &root_resolved_node_id);
+ }
rust_assert (ok);
translated = resolve_segments (root_resolved_node_id,
@@ -323,8 +334,21 @@ TypeCheckType::visit (HIR::QualifiedPathInType &path)
bool fully_resolved = path.get_segments ().empty ();
if (fully_resolved)
{
- resolver->insert_resolved_type (path.get_mappings ().get_nodeid (),
- root_resolved_node_id);
+ if (flag_name_resolution_2_0)
+ {
+ auto &nr_ctx = const_cast<Resolver2_0::NameResolutionContext &> (
+ Resolver2_0::ImmutableNameResolutionContext::get ().resolver ());
+
+ nr_ctx.map_usage (Resolver2_0::Usage (
+ path.get_mappings ().get_nodeid ()),
+ Resolver2_0::Definition (root_resolved_node_id));
+ }
+ else
+ {
+ resolver->insert_resolved_type (path.get_mappings ().get_nodeid (),
+ root_resolved_node_id);
+ }
+
context->insert_receiver (path.get_mappings ().get_hirid (), root);
return;
}
@@ -595,33 +619,53 @@ TypeCheckType::resolve_segments (
context->insert_receiver (expr_mappings.get_hirid (), prev_segment);
rust_assert (resolved_node_id != UNKNOWN_NODEID);
- // lookup if the name resolver was able to canonically resolve this or not
- NodeId path_resolved_id = UNKNOWN_NODEID;
- if (resolver->lookup_resolved_name (expr_mappings.get_nodeid (),
- &path_resolved_id))
- {
- rust_assert (path_resolved_id == resolved_node_id);
- }
- // check the type scope
- else if (resolver->lookup_resolved_type (expr_mappings.get_nodeid (),
- &path_resolved_id))
+ if (flag_name_resolution_2_0)
{
- rust_assert (path_resolved_id == resolved_node_id);
+ auto &nr_ctx = const_cast<Resolver2_0::NameResolutionContext &> (
+ Resolver2_0::ImmutableNameResolutionContext::get ().resolver ());
+
+ auto old = nr_ctx.lookup (expr_mappings.get_nodeid ());
+ if (old.has_value ())
+ {
+ rust_assert (*old == resolved_node_id);
+ }
+ else
+ {
+ nr_ctx.map_usage (Resolver2_0::Usage (expr_mappings.get_nodeid ()),
+ Resolver2_0::Definition (resolved_node_id));
+ }
}
else
{
- // name scope first
- if (resolver->get_name_scope ().decl_was_declared_here (resolved_node_id))
+ // lookup if the name resolver was able to canonically resolve this or not
+ NodeId path_resolved_id = UNKNOWN_NODEID;
+ if (resolver->lookup_resolved_name (expr_mappings.get_nodeid (),
+ &path_resolved_id))
{
- resolver->insert_resolved_name (expr_mappings.get_nodeid (),
- resolved_node_id);
+ rust_assert (path_resolved_id == resolved_node_id);
}
// check the type scope
- else if (resolver->get_type_scope ().decl_was_declared_here (
- resolved_node_id))
+ else if (resolver->lookup_resolved_type (expr_mappings.get_nodeid (),
+ &path_resolved_id))
{
- resolver->insert_resolved_type (expr_mappings.get_nodeid (),
- resolved_node_id);
+ rust_assert (path_resolved_id == resolved_node_id);
+ }
+ else
+ {
+ // name scope first
+ if (resolver->get_name_scope ().decl_was_declared_here (
+ resolved_node_id))
+ {
+ resolver->insert_resolved_name (expr_mappings.get_nodeid (),
+ resolved_node_id);
+ }
+ // check the type scope
+ else if (resolver->get_type_scope ().decl_was_declared_here (
+ resolved_node_id))
+ {
+ resolver->insert_resolved_type (expr_mappings.get_nodeid (),
+ resolved_node_id);
+ }
}
}
@@ -990,7 +1034,23 @@ ResolveWhereClauseItem::visit (HIR::TypeBoundWhereClauseItem &item)
// then lookup the reference_node_id
NodeId ref_node_id = UNKNOWN_NODEID;
- if (!resolver->lookup_resolved_type (ast_node_id, &ref_node_id))
+ if (flag_name_resolution_2_0)
+ {
+ auto &nr_ctx
+ = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+
+ if (auto id = nr_ctx.lookup (ast_node_id))
+ ref_node_id = *id;
+ }
+ else
+ {
+ NodeId id = UNKNOWN_NODEID;
+
+ if (resolver->lookup_resolved_type (ast_node_id, &id))
+ ref_node_id = id;
+ }
+
+ if (ref_node_id == UNKNOWN_NODEID)
{
// FIXME
rust_error_at (UNDEF_LOCATION,
diff --git a/gcc/testsuite/rust/compile/nr2/exclude b/gcc/testsuite/rust/compile/nr2/exclude
index 3dbebc703c4..6c589e4ab4e 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -72,7 +72,6 @@ issue-2037.rs
issue-2043.rs
issue-2070.rs
issue-2105.rs
-issue-2106.rs
issue-2135.rs
issue-2136-1.rs
issue-2136-2.rs
@@ -88,10 +87,8 @@ issue-2330.rs
issue-2375.rs
issue-2478.rs
issue-2479.rs
-issue-2514.rs
issue-2723-1.rs
issue-2723-2.rs
-issue-2772-1.rs
issue-2772-2.rs
issue-2775.rs
issue-2747.rs
@@ -194,7 +191,6 @@ issue-3046.rs
unknown-associated-item.rs
issue-3030.rs
issue-3035.rs
-issue-3082.rs
issue-3139-1.rs
issue-3139-2.rs
issue-3139-3.rs
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 046/146] gccrs: Clean up some system includes
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (44 preceding siblings ...)
2025-03-21 12:05 ` [COMMITTED 045/146] gccrs: Use nr2.0 in typechecker arthur.cohen
@ 2025-03-21 12:05 ` arthur.cohen
2025-03-21 12:05 ` [COMMITTED 047/146] gccrs: fix crashes in hir dump since move to references arthur.cohen
` (99 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:05 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Pierre-Emmanuel Patry
From: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
System includes shall use rust-system header instead.
gcc/rust/ChangeLog:
* ast/rust-stmt.h: Remove stdlib include and use rust-system instead.
* backend/rust-compile-expr.cc: Likewise.
* backend/rust-mangle-legacy.cc: Likewise.
* backend/rust-mangle-v0.cc: Likewise.
* hir/rust-hir-dump.cc: Likewise.
* typecheck/rust-hir-type-check-type.cc: Likewise.
* typecheck/rust-tyty.cc: Likewise.
* typecheck/rust-tyty.h: Likewise.
* util/rust-common.h: Likewise.
* util/rust-token-converter.cc: Likewise.
* util/rust-token-converter.h: Likewise.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
---
gcc/rust/ast/rust-stmt.h | 2 +-
gcc/rust/backend/rust-compile-expr.cc | 1 -
gcc/rust/backend/rust-mangle-legacy.cc | 1 -
gcc/rust/backend/rust-mangle-v0.cc | 1 -
gcc/rust/hir/rust-hir-dump.cc | 2 +-
gcc/rust/typecheck/rust-hir-type-check-type.cc | 2 +-
gcc/rust/typecheck/rust-tyty.cc | 2 +-
gcc/rust/typecheck/rust-tyty.h | 2 --
gcc/rust/util/rust-common.h | 1 -
gcc/rust/util/rust-token-converter.cc | 3 +--
gcc/rust/util/rust-token-converter.h | 2 +-
11 files changed, 6 insertions(+), 13 deletions(-)
diff --git a/gcc/rust/ast/rust-stmt.h b/gcc/rust/ast/rust-stmt.h
index e8aec34d47e..6cbecaffd03 100644
--- a/gcc/rust/ast/rust-stmt.h
+++ b/gcc/rust/ast/rust-stmt.h
@@ -22,7 +22,7 @@
#include "rust-ast.h"
#include "rust-path.h"
#include "rust-expr.h"
-#include <memory>
+#include "rust-system.h"
namespace Rust {
namespace AST {
diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc
index 05c52261cf7..7ea2a675522 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -31,7 +31,6 @@
#include "convert.h"
#include "print-tree.h"
#include "rust-system.h"
-#include <functional>
namespace Rust {
namespace Compile {
diff --git a/gcc/rust/backend/rust-mangle-legacy.cc b/gcc/rust/backend/rust-mangle-legacy.cc
index 2c0ddd92df0..7671982da3f 100644
--- a/gcc/rust/backend/rust-mangle-legacy.cc
+++ b/gcc/rust/backend/rust-mangle-legacy.cc
@@ -21,7 +21,6 @@
#include "rust-unicode.h"
#include "rust-diagnostics.h"
#include "rust-system.h"
-#include <sstream>
namespace Rust {
namespace Compile {
diff --git a/gcc/rust/backend/rust-mangle-v0.cc b/gcc/rust/backend/rust-mangle-v0.cc
index 67d7e4d1885..d0df4aba27c 100644
--- a/gcc/rust/backend/rust-mangle-v0.cc
+++ b/gcc/rust/backend/rust-mangle-v0.cc
@@ -25,7 +25,6 @@
#include "rust-unicode.h"
#include "rust-punycode.h"
#include "rust-compile-type.h"
-#include <sstream>
namespace Rust {
namespace Compile {
diff --git a/gcc/rust/hir/rust-hir-dump.cc b/gcc/rust/hir/rust-hir-dump.cc
index 5d2a09db348..81cb881268f 100644
--- a/gcc/rust/hir/rust-hir-dump.cc
+++ b/gcc/rust/hir/rust-hir-dump.cc
@@ -22,9 +22,9 @@
#include "rust-hir-path.h"
#include "rust-hir-type.h"
#include "rust-hir.h"
-#include <string>
#include "rust-attribute-values.h"
#include "tree/rust-hir-expr.h"
+#include "rust-system.h"
namespace Rust {
namespace HIR {
diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.cc b/gcc/rust/typecheck/rust-hir-type-check-type.cc
index 4ebbaf6d836..0360c5504b7 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-type.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-type.cc
@@ -27,7 +27,7 @@
#include "rust-mapping-common.h"
#include "rust-substitution-mapper.h"
#include "rust-type-util.h"
-#include <functional>
+#include "rust-system.h"
namespace Rust {
namespace Resolver {
diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc
index 1073dfa6adc..f0c967e0949 100644
--- a/gcc/rust/typecheck/rust-tyty.cc
+++ b/gcc/rust/typecheck/rust-tyty.cc
@@ -32,7 +32,7 @@
#include "rust-hir-type-bounds.h"
#include "options.h"
-#include <functional>
+#include "rust-system.h"
namespace Rust {
namespace TyTy {
diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h
index 49cd00c9174..a41837e35af 100644
--- a/gcc/rust/typecheck/rust-tyty.h
+++ b/gcc/rust/typecheck/rust-tyty.h
@@ -30,8 +30,6 @@
#include "rust-system.h"
#include "rust-hir.h"
-#include <limits>
-
namespace Rust {
namespace Resolver {
diff --git a/gcc/rust/util/rust-common.h b/gcc/rust/util/rust-common.h
index 2033694156e..71637cee68e 100644
--- a/gcc/rust/util/rust-common.h
+++ b/gcc/rust/util/rust-common.h
@@ -21,7 +21,6 @@
#ifndef RUST_COMMON
#define RUST_COMMON
#include "rust-system.h"
-#include <string>
namespace Rust {
diff --git a/gcc/rust/util/rust-token-converter.cc b/gcc/rust/util/rust-token-converter.cc
index 220e891247f..fc34adb9b19 100644
--- a/gcc/rust/util/rust-token-converter.cc
+++ b/gcc/rust/util/rust-token-converter.cc
@@ -18,8 +18,7 @@
#include "rust-token-converter.h"
#include "bi-map.h"
#include "line-map.h"
-
-#include <string>
+#include "rust-system.h"
namespace Rust {
diff --git a/gcc/rust/util/rust-token-converter.h b/gcc/rust/util/rust-token-converter.h
index 0498041b46c..5405d6e59d6 100644
--- a/gcc/rust/util/rust-token-converter.h
+++ b/gcc/rust/util/rust-token-converter.h
@@ -17,7 +17,7 @@
#ifndef RUST_TOKEN_CONVERTER_H
#define RUST_TOKEN_CONVERTER_H
-#include <vector>
+#include "rust-system.h"
#include "rust-token.h"
#include "libproc_macro_internal/proc_macro.h"
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 047/146] gccrs: fix crashes in hir dump since move to references
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (45 preceding siblings ...)
2025-03-21 12:05 ` [COMMITTED 046/146] gccrs: Clean up some system includes arthur.cohen
@ 2025-03-21 12:05 ` arthur.cohen
2025-03-21 12:05 ` [COMMITTED 048/146] gccrs: empty match expressions should resolve to ! arthur.cohen
` (98 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:05 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Philip Herron
From: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:
* hir/rust-hir-dump.cc (Dump::visit): add guards
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
---
gcc/rust/hir/rust-hir-dump.cc | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/gcc/rust/hir/rust-hir-dump.cc b/gcc/rust/hir/rust-hir-dump.cc
index 81cb881268f..1b48b294008 100644
--- a/gcc/rust/hir/rust-hir-dump.cc
+++ b/gcc/rust/hir/rust-hir-dump.cc
@@ -359,7 +359,8 @@ Dump::do_matcharm (MatchArm &e)
// FIXME Can't remember how to handle that. Let's see later.
// do_outer_attrs(e);
visit_collection ("match_arm_patterns", e.get_patterns ());
- visit_field ("guard_expr", e.get_guard_expr ());
+ if (e.has_match_arm_guard ())
+ visit_field ("guard_expr", e.get_guard_expr ());
end ("MatchArm");
}
@@ -1264,7 +1265,8 @@ Dump::visit (BlockExpr &e)
visit_collection ("statements", e.get_statements ());
- visit_field ("expr", e.get_final_expr ());
+ if (e.has_final_expr ())
+ visit_field ("expr", e.get_final_expr ());
end ("BlockExpr");
}
@@ -1489,7 +1491,8 @@ Dump::visit (TypeParam &e)
visit_collection ("type_param_bounds", e.get_type_param_bounds ());
- visit_field ("type", e.get_type ());
+ if (e.has_type ())
+ visit_field ("type", e.get_type ());
end ("TypeParam");
}
@@ -1655,7 +1658,8 @@ Dump::visit (Function &e)
put_field ("function_params", "empty");
}
- visit_field ("return_type", e.get_return_type ());
+ if (e.has_function_return_type ())
+ visit_field ("return_type", e.get_return_type ());
if (!e.has_where_clause ())
put_field ("where_clause", "none");
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 048/146] gccrs: empty match expressions should resolve to !
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (46 preceding siblings ...)
2025-03-21 12:05 ` [COMMITTED 047/146] gccrs: fix crashes in hir dump since move to references arthur.cohen
@ 2025-03-21 12:05 ` arthur.cohen
2025-03-21 12:05 ` [COMMITTED 049/146] gccrs: Prevent execution of some nr1.0 functions with nr2.0 arthur.cohen
` (97 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:05 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Philip Herron
From: Philip Herron <herron.philip@googlemail.com>
This is a special case in Rust and the ! type can unify with pretty much
anything its almost a inference variable and a unit-type for special cases.
Fixes Rust-GCC/gccrs#3231
Fixes Rust-GCC/gccrs#2567
gcc/rust/ChangeLog:
* backend/rust-compile-expr.cc (check_match_scrutinee): check for empty match
(CompileExpr::visit): fix assertion
* checks/errors/rust-hir-pattern-analysis.cc (check_match_usefulness): check for empty
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): resolve to !
gcc/testsuite/ChangeLog:
* rust/compile/exhaustiveness1.rs: remove bad check
* rust/compile/issue-2567-1.rs: New test.
* rust/compile/issue-2567-2.rs: New test.
* rust/compile/issue-2567-3.rs: New test.
* rust/compile/issue-3231.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
---
gcc/rust/backend/rust-compile-expr.cc | 21 +++++++++----------
.../errors/rust-hir-pattern-analysis.cc | 3 +++
.../typecheck/rust-hir-type-check-expr.cc | 12 +++++++++++
gcc/testsuite/rust/compile/exhaustiveness1.rs | 4 +---
gcc/testsuite/rust/compile/issue-2567-1.rs | 8 +++++++
gcc/testsuite/rust/compile/issue-2567-2.rs | 8 +++++++
gcc/testsuite/rust/compile/issue-2567-3.rs | 8 +++++++
gcc/testsuite/rust/compile/issue-3231.rs | 8 +++++++
8 files changed, 58 insertions(+), 14 deletions(-)
create mode 100644 gcc/testsuite/rust/compile/issue-2567-1.rs
create mode 100644 gcc/testsuite/rust/compile/issue-2567-2.rs
create mode 100644 gcc/testsuite/rust/compile/issue-2567-3.rs
create mode 100644 gcc/testsuite/rust/compile/issue-3231.rs
diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc
index 7ea2a675522..e0fb1da3feb 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -1013,17 +1013,7 @@ check_match_scrutinee (HIR::MatchExpr &expr, Context *ctx)
|| scrutinee_kind == TyTy::TypeKind::TUPLE
|| scrutinee_kind == TyTy::TypeKind::REF);
- if (scrutinee_kind == TyTy::TypeKind::ADT)
- {
- // this will need to change but for now the first pass implementation,
- // lets assert this is the case
- TyTy::ADTType *adt = static_cast<TyTy::ADTType *> (scrutinee_expr_tyty);
- if (adt->is_enum ())
- rust_assert (adt->number_of_variants () > 0);
- else
- rust_assert (adt->number_of_variants () == 1);
- }
- else if (scrutinee_kind == TyTy::TypeKind::FLOAT)
+ if (scrutinee_kind == TyTy::TypeKind::FLOAT)
{
// FIXME: CASE_LABEL_EXPR does not support floating point types.
// Find another way to compile these.
@@ -1064,6 +1054,15 @@ CompileExpr::visit (HIR::MatchExpr &expr)
return;
}
+ // if the result of this expression is meant to be never type then we can
+ // optimise this away but there is the case where match arms resolve to !
+ // because of return statements we need to special case this
+ if (!expr.has_match_arms () && expr_tyty->is<TyTy::NeverType> ())
+ {
+ translated = unit_expression (expr.get_locus ());
+ return;
+ }
+
fncontext fnctx = ctx->peek_fn ();
Bvariable *tmp = NULL;
tree enclosing_scope = ctx->peek_enclosing_scope ();
diff --git a/gcc/rust/checks/errors/rust-hir-pattern-analysis.cc b/gcc/rust/checks/errors/rust-hir-pattern-analysis.cc
index 617d754c181..db1e7272556 100644
--- a/gcc/rust/checks/errors/rust-hir-pattern-analysis.cc
+++ b/gcc/rust/checks/errors/rust-hir-pattern-analysis.cc
@@ -1530,6 +1530,9 @@ void
check_match_usefulness (Resolver::TypeCheckContext *ctx,
TyTy::BaseType *scrutinee_ty, HIR::MatchExpr &expr)
{
+ if (!expr.has_match_arms ())
+ return;
+
// Lower the arms to a more convenient representation.
std::vector<MatrixRow> rows;
for (auto &arm : expr.get_match_cases ())
diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
index 03922bb554c..5a96c359d7c 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
@@ -1456,6 +1456,18 @@ TypeCheckExpr::visit (HIR::MatchExpr &expr)
TyTy::BaseType *scrutinee_tyty
= TypeCheckExpr::Resolve (expr.get_scrutinee_expr ());
+ // https://github.com/Rust-GCC/gccrs/issues/3231#issuecomment-2462660048
+ // https://github.com/rust-lang/rust/blob/3d1dba830a564d1118361345d7ada47a05241f45/compiler/rustc_hir_typeck/src/_match.rs#L32-L36
+ if (!expr.has_match_arms ())
+ {
+ // this is a special case where rustc returns !
+ TyTy::BaseType *lookup = nullptr;
+ bool ok = context->lookup_builtin ("!", &lookup);
+ rust_assert (ok);
+ infered = lookup->clone ();
+ return;
+ }
+
bool saw_error = false;
std::vector<TyTy::BaseType *> kase_block_tys;
for (auto &kase : expr.get_match_cases ())
diff --git a/gcc/testsuite/rust/compile/exhaustiveness1.rs b/gcc/testsuite/rust/compile/exhaustiveness1.rs
index fe95ea3c9d9..356636b4e1f 100644
--- a/gcc/testsuite/rust/compile/exhaustiveness1.rs
+++ b/gcc/testsuite/rust/compile/exhaustiveness1.rs
@@ -15,9 +15,7 @@ fn s2(s: S) {
}
fn s3(s: S) {
- match s {
- // { dg-error "non-exhaustive patterns: '_' not covered" "" { target *-*-* } .-1 }
- }
+ match s {}
}
enum E {
diff --git a/gcc/testsuite/rust/compile/issue-2567-1.rs b/gcc/testsuite/rust/compile/issue-2567-1.rs
new file mode 100644
index 00000000000..f5af2493619
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-2567-1.rs
@@ -0,0 +1,8 @@
+// { dg-options "-w" }
+enum Empty {}
+
+fn foo(x: Empty) {
+ let x: Empty = match x {
+ // empty
+ };
+}
diff --git a/gcc/testsuite/rust/compile/issue-2567-2.rs b/gcc/testsuite/rust/compile/issue-2567-2.rs
new file mode 100644
index 00000000000..719511d49d3
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-2567-2.rs
@@ -0,0 +1,8 @@
+// { dg-options "-w" }
+enum Empty {}
+
+fn foo(x: Empty) {
+ let x: i32 = match x {
+ // empty
+ };
+}
diff --git a/gcc/testsuite/rust/compile/issue-2567-3.rs b/gcc/testsuite/rust/compile/issue-2567-3.rs
new file mode 100644
index 00000000000..09efaf0af8b
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-2567-3.rs
@@ -0,0 +1,8 @@
+// { dg-options "-w" }
+enum Empty {}
+
+fn foo(x: Empty) {
+ match x {
+ // empty
+ }
+}
diff --git a/gcc/testsuite/rust/compile/issue-3231.rs b/gcc/testsuite/rust/compile/issue-3231.rs
new file mode 100644
index 00000000000..59726cb7b75
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-3231.rs
@@ -0,0 +1,8 @@
+// { dg-options "-w" }
+pub enum X {}
+
+pub fn foo(x: X) {
+ let _a: i32 = match x {};
+}
+
+pub fn main() {}
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 049/146] gccrs: Prevent execution of some nr1.0 functions with nr2.0
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (47 preceding siblings ...)
2025-03-21 12:05 ` [COMMITTED 048/146] gccrs: empty match expressions should resolve to ! arthur.cohen
@ 2025-03-21 12:05 ` arthur.cohen
2025-03-21 12:05 ` [COMMITTED 050/146] gccrs: Prepend crate name to functions with nr2 arthur.cohen
` (96 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:05 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Owen Avery
From: Owen Avery <powerboat9.gamer@gmail.com>
gcc/rust/ChangeLog:
* resolve/rust-name-resolver.cc: Include options.txt.
(Resolver::insert_resolved_name): Assert that name resolution
2.0 is disabled.
(Resolver::lookup_resolved_name): Likewise.
(Resolver::insert_resolved_type): Likewise.
(Resolver::lookup_resolved_type): Likewise.
(Resolver::insert_resolved_label): Likewise.
(Resolver::lookup_resolved_label): Likewise.
(Resolver::insert_resolved_macro): Likewise.
(Resolver::lookup_resolved_macro): Likewise.
(Resolver::insert_resolved_misc): Likewise.
(Resolver::lookup_resolved_misc): Likewise.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
---
gcc/rust/resolve/rust-name-resolver.cc | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/gcc/rust/resolve/rust-name-resolver.cc b/gcc/rust/resolve/rust-name-resolver.cc
index 3b4e3111d93..0f5b1084774 100644
--- a/gcc/rust/resolve/rust-name-resolver.cc
+++ b/gcc/rust/resolve/rust-name-resolver.cc
@@ -19,6 +19,9 @@
#include "rust-name-resolver.h"
#include "rust-ast-full.h"
+// for flag_name_resolution_2_0
+#include "options.h"
+
namespace Rust {
namespace Resolver {
@@ -468,6 +471,7 @@ Resolver::setup_builtin (const std::string &name, TyTy::BaseType *tyty)
void
Resolver::insert_resolved_name (NodeId refId, NodeId defId)
{
+ rust_assert (!flag_name_resolution_2_0);
resolved_names[refId] = defId;
get_name_scope ().append_reference_for_def (refId, defId);
insert_captured_item (defId);
@@ -476,6 +480,7 @@ Resolver::insert_resolved_name (NodeId refId, NodeId defId)
bool
Resolver::lookup_resolved_name (NodeId refId, NodeId *defId)
{
+ rust_assert (!flag_name_resolution_2_0);
auto it = resolved_names.find (refId);
if (it == resolved_names.end ())
return false;
@@ -489,6 +494,7 @@ Resolver::insert_resolved_type (NodeId refId, NodeId defId)
{
// auto it = resolved_types.find (refId);
// rust_assert (it == resolved_types.end ());
+ rust_assert (!flag_name_resolution_2_0);
resolved_types[refId] = defId;
get_type_scope ().append_reference_for_def (refId, defId);
@@ -497,6 +503,7 @@ Resolver::insert_resolved_type (NodeId refId, NodeId defId)
bool
Resolver::lookup_resolved_type (NodeId refId, NodeId *defId)
{
+ rust_assert (!flag_name_resolution_2_0);
auto it = resolved_types.find (refId);
if (it == resolved_types.end ())
return false;
@@ -508,6 +515,7 @@ Resolver::lookup_resolved_type (NodeId refId, NodeId *defId)
void
Resolver::insert_resolved_label (NodeId refId, NodeId defId)
{
+ rust_assert (!flag_name_resolution_2_0);
auto it = resolved_labels.find (refId);
rust_assert (it == resolved_labels.end ());
@@ -518,6 +526,7 @@ Resolver::insert_resolved_label (NodeId refId, NodeId defId)
bool
Resolver::lookup_resolved_label (NodeId refId, NodeId *defId)
{
+ rust_assert (!flag_name_resolution_2_0);
auto it = resolved_labels.find (refId);
if (it == resolved_labels.end ())
return false;
@@ -529,6 +538,7 @@ Resolver::lookup_resolved_label (NodeId refId, NodeId *defId)
void
Resolver::insert_resolved_macro (NodeId refId, NodeId defId)
{
+ rust_assert (!flag_name_resolution_2_0);
auto it = resolved_macros.find (refId);
rust_assert (it == resolved_macros.end ());
@@ -539,6 +549,7 @@ Resolver::insert_resolved_macro (NodeId refId, NodeId defId)
bool
Resolver::lookup_resolved_macro (NodeId refId, NodeId *defId)
{
+ rust_assert (!flag_name_resolution_2_0);
auto it = resolved_macros.find (refId);
if (it == resolved_macros.end ())
return false;
@@ -550,6 +561,7 @@ Resolver::lookup_resolved_macro (NodeId refId, NodeId *defId)
void
Resolver::insert_resolved_misc (NodeId refId, NodeId defId)
{
+ rust_assert (!flag_name_resolution_2_0);
auto it = misc_resolved_items.find (refId);
rust_assert (it == misc_resolved_items.end ());
@@ -559,6 +571,7 @@ Resolver::insert_resolved_misc (NodeId refId, NodeId defId)
bool
Resolver::lookup_resolved_misc (NodeId refId, NodeId *defId)
{
+ rust_assert (!flag_name_resolution_2_0);
auto it = misc_resolved_items.find (refId);
if (it == misc_resolved_items.end ())
return false;
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 050/146] gccrs: Prepend crate name to functions with nr2
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (48 preceding siblings ...)
2025-03-21 12:05 ` [COMMITTED 049/146] gccrs: Prevent execution of some nr1.0 functions with nr2.0 arthur.cohen
@ 2025-03-21 12:05 ` arthur.cohen
2025-03-21 12:05 ` [COMMITTED 051/146] gccrs: fix crash in hir dump with missing guards arthur.cohen
` (95 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:05 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Pierre-Emmanuel Patry
From: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
gcc/rust/ChangeLog:
* backend/rust-compile-base.cc: Prepend crate name to function's ir
name.
gcc/testsuite/ChangeLog:
* rust/compile/nr2/exclude: Remove passing tests from exclude list.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
---
gcc/rust/backend/rust-compile-base.cc | 11 ++++++++++-
gcc/testsuite/rust/compile/nr2/exclude | 6 ------
2 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/gcc/rust/backend/rust-compile-base.cc b/gcc/rust/backend/rust-compile-base.cc
index 80ea7a4ec95..fb4aace9555 100644
--- a/gcc/rust/backend/rust-compile-base.cc
+++ b/gcc/rust/backend/rust-compile-base.cc
@@ -25,7 +25,8 @@
#include "rust-compile-type.h"
#include "rust-constexpr.h"
#include "rust-diagnostics.h"
-#include "rust-expr.h" // for AST::AttrInputLiteral
+#include "rust-expr.h" // for AST::AttrInputLiteral
+#include "rust-hir-map.h"
#include "rust-macro.h" // for AST::MetaNameValueStr
#include "rust-hir-path-probe.h"
#include "rust-type-util.h"
@@ -39,6 +40,9 @@
#include "tree.h"
#include "print-tree.h"
+// rust-name-resolution-2.0
+#include "options.h"
+
namespace Rust {
namespace Compile {
@@ -667,6 +671,11 @@ HIRCompileBase::compile_function (
}
std::string asm_name = fn_name;
+ auto &mappings = Analysis::Mappings::get ();
+
+ if (flag_name_resolution_2_0)
+ ir_symbol_name = mappings.get_current_crate_name () + "::" + ir_symbol_name;
+
unsigned int flags = 0;
tree fndecl = Backend::function (compiled_fn_type, ir_symbol_name,
"" /* asm_name */, flags, locus);
diff --git a/gcc/testsuite/rust/compile/nr2/exclude b/gcc/testsuite/rust/compile/nr2/exclude
index 6c589e4ab4e..b282f05637d 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -1,7 +1,3 @@
-attr-mismatch-crate-name.rs
-attr_deprecated.rs
-attr_deprecated_2.rs
-bad=file-name.rs
bounds1.rs
break-rust2.rs
break-rust3.rs
@@ -45,7 +41,6 @@ generics6.rs
generics8.rs
generics9.rs
if_let_expr.rs
-infer-crate-name.rs
issue-1019.rs
issue-1031.rs
issue-1034.rs
@@ -156,7 +151,6 @@ redef_error6.rs
self-path1.rs
self-path2.rs
sizeof-stray-infer-var-bug.rs
-specify-crate-name.rs
stmt_with_block_dot.rs
struct-expr-parse.rs
traits1.rs
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 051/146] gccrs: fix crash in hir dump with missing guards
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (49 preceding siblings ...)
2025-03-21 12:05 ` [COMMITTED 050/146] gccrs: Prepend crate name to functions with nr2 arthur.cohen
@ 2025-03-21 12:05 ` arthur.cohen
2025-03-21 12:05 ` [COMMITTED 052/146] gccrs: improve handling of Self Type paths arthur.cohen
` (94 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:05 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Philip Herron
From: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:
* hir/rust-hir-dump.cc (Dump::visit): add missing null checks
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
---
gcc/rust/hir/rust-hir-dump.cc | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/gcc/rust/hir/rust-hir-dump.cc b/gcc/rust/hir/rust-hir-dump.cc
index 1b48b294008..be785b9ebec 100644
--- a/gcc/rust/hir/rust-hir-dump.cc
+++ b/gcc/rust/hir/rust-hir-dump.cc
@@ -1892,7 +1892,8 @@ Dump::visit (TraitItemFunc &e)
do_traitfunctiondecl (e.get_decl ());
- visit_field ("block_expr", e.get_block_expr ());
+ if (e.has_definition ())
+ visit_field ("block_expr", e.get_block_expr ());
end ("TraitItemFunc");
}
@@ -2007,7 +2008,8 @@ Dump::visit (ExternalFunctionItem &e)
put_field ("has_variadics", std::to_string (e.is_variadic ()));
- visit_field ("return_type", e.get_return_type ());
+ if (e.has_return_type ())
+ visit_field ("return_type", e.get_return_type ());
end ("ExternalFunctionItem");
}
@@ -2254,8 +2256,10 @@ Dump::visit (LetStmt &e)
put_field ("variable_pattern", e.get_pattern ().as_string ());
- visit_field ("type", e.get_type ());
- visit_field ("init_expr", e.get_init_expr ());
+ if (e.has_type ())
+ visit_field ("type", e.get_type ());
+ if (e.has_init_expr ())
+ visit_field ("init_expr", e.get_init_expr ());
end ("LetStmt");
}
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 052/146] gccrs: improve handling of Self Type paths
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (50 preceding siblings ...)
2025-03-21 12:05 ` [COMMITTED 051/146] gccrs: fix crash in hir dump with missing guards arthur.cohen
@ 2025-03-21 12:05 ` arthur.cohen
2025-03-21 12:05 ` [COMMITTED 053/146] gccrs: allow casts from numeric types to floats arthur.cohen
` (93 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:05 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Philip Herron
From: Philip Herron <herron.philip@googlemail.com>
TypePaths have special handling for Self where we can look at the current ctx
for more acurate TypeAlias information if required. We cant do this for Impl
contexts but not for Traits as we might as well fall back to the TypePathProbe.
The other issue was the dyn type comming in because Foo::foo and Foo is a trait
reference we represent this as a dyn type as the root resolved path but then find
the associated impl block for this but we cannot do this when we have resolved to
a Dyn because this is just a representation that we know we are talking about a
trait not because we are actually working with a real Dyn type.
Fixes Rust-GCC#2907
gcc/rust/ChangeLog:
* typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_trait): track trait
* typecheck/rust-hir-type-check-implitem.cc: trait block
* typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_segments): dont when dyn
* typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit): look at Self contenxt
(TypeCheckType::resolve_root_path): track if Self
(TypeCheckType::resolve_associated_type): look at current context for associated types
* typecheck/rust-hir-type-check-type.h: change prototype
* typecheck/rust-hir-type-check.h (class TypeCheckBlockContextItem):
new context system to track current state
* typecheck/rust-typecheck-context.cc (TypeCheckContext::have_block_context): likewise
(TypeCheckContext::peek_block_context): likewise
(TypeCheckContext::push_block_context): likewise
(TypeCheckContext::pop_block_context): likewise
(TypeCheckBlockContextItem::Item::Item): likewise
(TypeCheckBlockContextItem::TypeCheckBlockContextItem): likewise
(TypeCheckBlockContextItem::is_impl_block): likewise
(TypeCheckBlockContextItem::is_trait_block): likewise
(TypeCheckBlockContextItem::get_impl_block): likewise
(TypeCheckBlockContextItem::get_trait): likewise
gcc/testsuite/ChangeLog:
* rust/compile/nr2/exclude: nr2 cant handle this
* rust/compile/issue-2907.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
---
gcc/rust/typecheck/rust-hir-trait-resolve.cc | 2 +
.../typecheck/rust-hir-type-check-implitem.cc | 3 +
.../typecheck/rust-hir-type-check-path.cc | 3 +-
.../typecheck/rust-hir-type-check-type.cc | 195 ++++++++++++------
gcc/rust/typecheck/rust-hir-type-check-type.h | 9 +-
gcc/rust/typecheck/rust-hir-type-check.h | 38 ++++
gcc/rust/typecheck/rust-typecheck-context.cc | 64 ++++++
gcc/testsuite/rust/compile/issue-2907.rs | 33 +++
gcc/testsuite/rust/compile/nr2/exclude | 1 +
9 files changed, 287 insertions(+), 61 deletions(-)
create mode 100644 gcc/testsuite/rust/compile/issue-2907.rs
diff --git a/gcc/rust/typecheck/rust-hir-trait-resolve.cc b/gcc/rust/typecheck/rust-hir-trait-resolve.cc
index 6f2589a0d2b..2fbf123aa77 100644
--- a/gcc/rust/typecheck/rust-hir-trait-resolve.cc
+++ b/gcc/rust/typecheck/rust-hir-trait-resolve.cc
@@ -278,6 +278,7 @@ TraitResolver::resolve_trait (HIR::Trait *trait_reference)
}
self->inherit_bounds (specified_bounds);
+ context->push_block_context (TypeCheckBlockContextItem (trait_reference));
std::vector<TraitItemReference> item_refs;
for (auto &item : trait_reference->get_trait_items ())
{
@@ -307,6 +308,7 @@ TraitResolver::resolve_trait (HIR::Trait *trait_reference)
// resolve the blocks of functions etc because it can end up in a recursive
// loop of trying to resolve traits as required by the types
tref->on_resolved ();
+ context->pop_block_context ();
return tref;
}
diff --git a/gcc/rust/typecheck/rust-hir-type-check-implitem.cc b/gcc/rust/typecheck/rust-hir-type-check-implitem.cc
index 602076811c3..5da88b890f3 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-implitem.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-implitem.cc
@@ -335,7 +335,10 @@ TypeCheckImplItem::Resolve (
// resolve
TypeCheckImplItem resolver (parent, self, substitutions);
+ resolver.context->push_block_context (TypeCheckBlockContextItem (&parent));
item.accept_vis (resolver);
+ resolver.context->pop_block_context ();
+
return resolver.result;
}
diff --git a/gcc/rust/typecheck/rust-hir-type-check-path.cc b/gcc/rust/typecheck/rust-hir-type-check-path.cc
index cd0e941edd6..4746e7d730d 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-path.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-path.cc
@@ -355,6 +355,7 @@ TypeCheckExpr::resolve_segments (NodeId root_resolved_node_id,
NodeId resolved_node_id = root_resolved_node_id;
TyTy::BaseType *prev_segment = tyseg;
bool reciever_is_generic = prev_segment->get_kind () == TyTy::TypeKind::PARAM;
+ bool reciever_is_dyn = prev_segment->get_kind () == TyTy::TypeKind::DYNAMIC;
for (size_t i = offset; i < segments.size (); i++)
{
@@ -434,7 +435,7 @@ TypeCheckExpr::resolve_segments (NodeId root_resolved_node_id,
}
}
- if (associated_impl_block != nullptr)
+ if (associated_impl_block != nullptr && !reciever_is_dyn)
{
// associated types
HirId impl_block_id
diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.cc b/gcc/rust/typecheck/rust-hir-type-check-type.cc
index 0360c5504b7..89ede4e3013 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-type.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-type.cc
@@ -133,11 +133,16 @@ TypeCheckType::visit (HIR::TypePath &path)
// this can happen so we need to look up the root then resolve the
// remaining segments if possible
+ bool wasBigSelf = false;
size_t offset = 0;
NodeId resolved_node_id = UNKNOWN_NODEID;
- TyTy::BaseType *root = resolve_root_path (path, &offset, &resolved_node_id);
+ TyTy::BaseType *root
+ = resolve_root_path (path, &offset, &resolved_node_id, &wasBigSelf);
if (root->get_kind () == TyTy::TypeKind::ERROR)
- return;
+ {
+ rust_debug_loc (path.get_locus (), "failed to resolve type-path type");
+ return;
+ }
TyTy::BaseType *path_type = root->clone ();
path_type->set_ref (path.get_mappings ().get_hirid ());
@@ -147,13 +152,18 @@ TypeCheckType::visit (HIR::TypePath &path)
if (fully_resolved)
{
translated = path_type;
+ rust_debug_loc (path.get_locus (), "root resolved type-path to: [%s]",
+ translated->debug_str ().c_str ());
return;
}
translated
= resolve_segments (resolved_node_id, path.get_mappings ().get_hirid (),
path.get_segments (), offset, path_type,
- path.get_mappings (), path.get_locus ());
+ path.get_mappings (), path.get_locus (), wasBigSelf);
+
+ rust_debug_loc (path.get_locus (), "resolved type-path to: [%s]",
+ translated->debug_str ().c_str ());
}
void
@@ -192,10 +202,11 @@ TypeCheckType::visit (HIR::QualifiedPathInType &path)
}
rust_assert (ok);
- translated = resolve_segments (root_resolved_node_id,
- path.get_mappings ().get_hirid (),
- path.get_segments (), 0, translated,
- path.get_mappings (), path.get_locus ());
+ translated
+ = resolve_segments (root_resolved_node_id,
+ path.get_mappings ().get_hirid (),
+ path.get_segments (), 0, translated,
+ path.get_mappings (), path.get_locus (), false);
return;
}
@@ -356,12 +367,14 @@ TypeCheckType::visit (HIR::QualifiedPathInType &path)
translated
= resolve_segments (root_resolved_node_id,
path.get_mappings ().get_hirid (), path.get_segments (),
- 0, translated, path.get_mappings (), path.get_locus ());
+ 0, translated, path.get_mappings (), path.get_locus (),
+ false);
}
TyTy::BaseType *
TypeCheckType::resolve_root_path (HIR::TypePath &path, size_t *offset,
- NodeId *root_resolved_node_id)
+ NodeId *root_resolved_node_id,
+ bool *wasBigSelf)
{
TyTy::BaseType *root_tyty = nullptr;
*offset = 0;
@@ -403,6 +416,9 @@ TypeCheckType::resolve_root_path (HIR::TypePath &path, size_t *offset,
return root_tyty;
}
+ if (seg->is_ident_only () && seg->as_string () == "Self")
+ *wasBigSelf = true;
+
// node back to HIR
tl::optional<HirId> hid = mappings.lookup_node_to_hir (ref_node_id);
if (!hid.has_value ())
@@ -509,12 +525,57 @@ TypeCheckType::resolve_root_path (HIR::TypePath &path, size_t *offset,
return root_tyty;
}
+bool
+TypeCheckType::resolve_associated_type (const std::string &search,
+ TypeCheckBlockContextItem &ctx,
+ TyTy::BaseType **result)
+{
+ if (ctx.is_trait_block ())
+ {
+ HIR::Trait &trait = ctx.get_trait ();
+ for (auto &item : trait.get_trait_items ())
+ {
+ if (item->get_item_kind () != HIR::TraitItem::TraitItemKind::TYPE)
+ continue;
+
+ if (item->trait_identifier () == search)
+ {
+ HirId item_id = item->get_mappings ().get_hirid ();
+ if (query_type (item_id, result))
+ return true;
+ }
+ }
+
+ // FIXME
+ // query any parent trait?
+
+ return false;
+ }
+
+ // look for any segment in here which matches
+ HIR::ImplBlock &block = ctx.get_impl_block ();
+ for (auto &item : block.get_impl_items ())
+ {
+ if (item->get_impl_item_type () != HIR::ImplItem::TYPE_ALIAS)
+ continue;
+
+ if (item->get_impl_item_name () == search)
+ {
+ HirId item_id = item->get_impl_mappings ().get_hirid ();
+ if (query_type (item_id, result))
+ return true;
+ }
+ }
+
+ return false;
+}
+
TyTy::BaseType *
TypeCheckType::resolve_segments (
NodeId root_resolved_node_id, HirId expr_id,
std::vector<std::unique_ptr<HIR::TypePathSegment>> &segments, size_t offset,
TyTy::BaseType *tyseg, const Analysis::NodeMapping &expr_mappings,
- location_t expr_locus)
+ location_t expr_locus, bool tySegIsBigSelf)
{
NodeId resolved_node_id = root_resolved_node_id;
TyTy::BaseType *prev_segment = tyseg;
@@ -527,66 +588,84 @@ TypeCheckType::resolve_segments (
bool probe_bounds = true;
bool probe_impls = !reciever_is_generic;
bool ignore_mandatory_trait_items = !reciever_is_generic;
+ bool first_segment = i == offset;
+ bool selfResolveOk = false;
- // probe the path is done in two parts one where we search impls if no
- // candidate is found then we search extensions from traits
- auto candidates
- = PathProbeType::Probe (prev_segment, seg->get_ident_segment (),
- probe_impls, false,
- ignore_mandatory_trait_items);
- if (candidates.size () == 0)
+ if (first_segment && tySegIsBigSelf && context->have_block_context ()
+ && context->peek_block_context ().is_impl_block ())
+ {
+ TypeCheckBlockContextItem ctx = context->peek_block_context ();
+ TyTy::BaseType *lookup = nullptr;
+ selfResolveOk
+ = resolve_associated_type (seg->as_string (), ctx, &lookup);
+ if (selfResolveOk)
+ {
+ prev_segment = tyseg;
+ tyseg = lookup;
+ }
+ }
+ if (!selfResolveOk)
{
- candidates
+ // probe the path is done in two parts one where we search impls if no
+ // candidate is found then we search extensions from traits
+ auto candidates
= PathProbeType::Probe (prev_segment, seg->get_ident_segment (),
- false, probe_bounds,
+ probe_impls, false,
ignore_mandatory_trait_items);
-
if (candidates.size () == 0)
{
- rust_error_at (
- seg->get_locus (),
- "failed to resolve path segment using an impl Probe");
+ candidates
+ = PathProbeType::Probe (prev_segment, seg->get_ident_segment (),
+ false, probe_bounds,
+ ignore_mandatory_trait_items);
+ if (candidates.size () == 0)
+ {
+ rust_error_at (
+ seg->get_locus (),
+ "failed to resolve path segment using an impl Probe");
+ return new TyTy::ErrorType (expr_id);
+ }
+ }
+
+ if (candidates.size () > 1)
+ {
+ ReportMultipleCandidateError::Report (candidates,
+ seg->get_ident_segment (),
+ seg->get_locus ());
return new TyTy::ErrorType (expr_id);
}
- }
- if (candidates.size () > 1)
- {
- ReportMultipleCandidateError::Report (candidates,
- seg->get_ident_segment (),
- seg->get_locus ());
- return new TyTy::ErrorType (expr_id);
- }
+ auto &candidate = *candidates.begin ();
+ prev_segment = tyseg;
+ tyseg = candidate.ty;
- auto &candidate = *candidates.begin ();
- prev_segment = tyseg;
- tyseg = candidate.ty;
+ if (candidate.is_enum_candidate ())
+ {
+ TyTy::ADTType *adt = static_cast<TyTy::ADTType *> (tyseg);
+ auto last_variant = adt->get_variants ();
+ TyTy::VariantDef *variant = last_variant.back ();
- if (candidate.is_enum_candidate ())
- {
- TyTy::ADTType *adt = static_cast<TyTy::ADTType *> (tyseg);
- auto last_variant = adt->get_variants ();
- TyTy::VariantDef *variant = last_variant.back ();
-
- rich_location richloc (line_table, seg->get_locus ());
- richloc.add_fixit_replace ("not a type");
-
- rust_error_at (richloc, ErrorCode::E0573,
- "expected type, found variant of %<%s::%s%>",
- adt->get_name ().c_str (),
- variant->get_identifier ().c_str ());
- return new TyTy::ErrorType (expr_id);
- }
+ rich_location richloc (line_table, seg->get_locus ());
+ richloc.add_fixit_replace ("not a type");
- if (candidate.is_impl_candidate ())
- {
- resolved_node_id
- = candidate.item.impl.impl_item->get_impl_mappings ().get_nodeid ();
- }
- else
- {
- resolved_node_id
- = candidate.item.trait.item_ref->get_mappings ().get_nodeid ();
+ rust_error_at (richloc, ErrorCode::E0573,
+ "expected type, found variant of %<%s::%s%>",
+ adt->get_name ().c_str (),
+ variant->get_identifier ().c_str ());
+ return new TyTy::ErrorType (expr_id);
+ }
+
+ if (candidate.is_impl_candidate ())
+ {
+ resolved_node_id
+ = candidate.item.impl.impl_item->get_impl_mappings ()
+ .get_nodeid ();
+ }
+ else
+ {
+ resolved_node_id
+ = candidate.item.trait.item_ref->get_mappings ().get_nodeid ();
+ }
}
if (seg->is_generic_segment ())
diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.h b/gcc/rust/typecheck/rust-hir-type-check-type.h
index ab29152ef45..bf5589cbbab 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-type.h
+++ b/gcc/rust/typecheck/rust-hir-type-check-type.h
@@ -82,13 +82,18 @@ private:
{}
TyTy::BaseType *resolve_root_path (HIR::TypePath &path, size_t *offset,
- NodeId *root_resolved_node_id);
+ NodeId *root_resolved_node_id,
+ bool *wasBigSelf);
TyTy::BaseType *resolve_segments (
NodeId root_resolved_node_id, HirId expr_id,
std::vector<std::unique_ptr<HIR::TypePathSegment>> &segments, size_t offset,
TyTy::BaseType *tyseg, const Analysis::NodeMapping &expr_mappings,
- location_t expr_locus);
+ location_t expr_locus, bool tySegIsBigSelf);
+
+ bool resolve_associated_type (const std::string &search,
+ TypeCheckBlockContextItem &ctx,
+ TyTy::BaseType **result);
TyTy::BaseType *translated;
};
diff --git a/gcc/rust/typecheck/rust-hir-type-check.h b/gcc/rust/typecheck/rust-hir-type-check.h
index e0918e9d93c..08c3d354f79 100644
--- a/gcc/rust/typecheck/rust-hir-type-check.h
+++ b/gcc/rust/typecheck/rust-hir-type-check.h
@@ -82,6 +82,37 @@ private:
Item item;
};
+class TypeCheckBlockContextItem
+{
+public:
+ enum ItemType
+ {
+ IMPL_BLOCK,
+ TRAIT
+ };
+
+ TypeCheckBlockContextItem (HIR::ImplBlock *block);
+ TypeCheckBlockContextItem (HIR::Trait *trait);
+
+ bool is_impl_block () const;
+ bool is_trait_block () const;
+
+ HIR::ImplBlock &get_impl_block ();
+ HIR::Trait &get_trait ();
+
+private:
+ union Item
+ {
+ HIR::ImplBlock *block;
+ HIR::Trait *trait;
+
+ Item (HIR::ImplBlock *block);
+ Item (HIR::Trait *trait);
+ };
+ ItemType type;
+ Item item;
+};
+
/**
* Interned lifetime representation in TyTy
*
@@ -154,6 +185,12 @@ public:
void push_return_type (TypeCheckContextItem item,
TyTy::BaseType *return_type);
void pop_return_type ();
+
+ bool have_block_context () const;
+ TypeCheckBlockContextItem peek_block_context ();
+ void push_block_context (TypeCheckBlockContextItem item);
+ void pop_block_context ();
+
void iterate (std::function<bool (HirId, TyTy::BaseType *)> cb);
bool have_loop_context () const;
@@ -245,6 +282,7 @@ private:
std::vector<std::pair<TypeCheckContextItem, TyTy::BaseType *>>
return_type_stack;
std::vector<TyTy::BaseType *> loop_type_stack;
+ std::vector<TypeCheckBlockContextItem> block_stack;
std::map<DefId, TraitReference> trait_context;
std::map<HirId, TyTy::BaseType *> receiver_context;
std::map<HirId, AssociatedImplTrait> associated_impl_traits;
diff --git a/gcc/rust/typecheck/rust-typecheck-context.cc b/gcc/rust/typecheck/rust-typecheck-context.cc
index 1cd5dabf822..e72ce41606d 100644
--- a/gcc/rust/typecheck/rust-typecheck-context.cc
+++ b/gcc/rust/typecheck/rust-typecheck-context.cc
@@ -177,6 +177,32 @@ TypeCheckContext::peek_context ()
return return_type_stack.back ().first;
}
+bool
+TypeCheckContext::have_block_context () const
+{
+ return !block_stack.empty ();
+}
+
+TypeCheckBlockContextItem
+TypeCheckContext::peek_block_context ()
+{
+ rust_assert (!block_stack.empty ());
+ return block_stack.back ();
+}
+
+void
+TypeCheckContext::push_block_context (TypeCheckBlockContextItem block)
+{
+ block_stack.push_back (block);
+}
+
+void
+TypeCheckContext::pop_block_context ()
+{
+ rust_assert (!block_stack.empty ());
+ block_stack.pop_back ();
+}
+
void
TypeCheckContext::iterate (std::function<bool (HirId, TyTy::BaseType *)> cb)
{
@@ -802,5 +828,43 @@ TypeCheckContextItem::get_defid () const
return UNKNOWN_DEFID;
}
+// TypeCheckBlockContextItem
+
+TypeCheckBlockContextItem::Item::Item (HIR::ImplBlock *b) : block (b) {}
+
+TypeCheckBlockContextItem::Item::Item (HIR::Trait *t) : trait (t) {}
+
+TypeCheckBlockContextItem::TypeCheckBlockContextItem (HIR::ImplBlock *block)
+ : type (TypeCheckBlockContextItem::ItemType::IMPL_BLOCK), item (block)
+{}
+
+TypeCheckBlockContextItem::TypeCheckBlockContextItem (HIR::Trait *trait)
+ : type (TypeCheckBlockContextItem::ItemType::TRAIT), item (trait)
+{}
+
+bool
+TypeCheckBlockContextItem::is_impl_block () const
+{
+ return type == IMPL_BLOCK;
+}
+
+bool
+TypeCheckBlockContextItem::is_trait_block () const
+{
+ return type == TRAIT;
+}
+
+HIR::ImplBlock &
+TypeCheckBlockContextItem::get_impl_block ()
+{
+ return *(item.block);
+}
+
+HIR::Trait &
+TypeCheckBlockContextItem::get_trait ()
+{
+ return *(item.trait);
+}
+
} // namespace Resolver
} // namespace Rust
diff --git a/gcc/testsuite/rust/compile/issue-2907.rs b/gcc/testsuite/rust/compile/issue-2907.rs
new file mode 100644
index 00000000000..1af843f582e
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-2907.rs
@@ -0,0 +1,33 @@
+#![feature(lang_items)]
+
+#[lang = "sized"]
+pub trait Sized {}
+
+pub trait Bar {}
+
+pub trait Foo {
+ type Ty;
+
+ fn foo(self) -> Self::Ty;
+}
+
+impl<B: Bar> Foo for B {
+ type Ty = u32;
+
+ fn foo(self) -> Self::Ty {
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ 14
+ }
+}
+
+struct Qux;
+
+impl Bar for Qux {}
+
+fn main() {
+ let a = Qux;
+ a.foo();
+
+ let b = Qux;
+ Foo::foo(b);
+}
diff --git a/gcc/testsuite/rust/compile/nr2/exclude b/gcc/testsuite/rust/compile/nr2/exclude
index b282f05637d..00ac704fec2 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -205,4 +205,5 @@ issue-2953-2.rs
issue-1773.rs
issue-2905-1.rs
issue-2905-2.rs
+issue-2907.rs
# please don't delete the trailing newline
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 053/146] gccrs: allow casts from numeric types to floats
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (51 preceding siblings ...)
2025-03-21 12:05 ` [COMMITTED 052/146] gccrs: improve handling of Self Type paths arthur.cohen
@ 2025-03-21 12:05 ` arthur.cohen
2025-03-21 12:05 ` [COMMITTED 054/146] gccrs: ensure packed and aligned is applied properly arthur.cohen
` (92 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:05 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Philip Herron
From: Philip Herron <herron.philip@googlemail.com>
Fixes Rust-GCC#3261
gcc/rust/ChangeLog:
* typecheck/rust-casts.cc (TypeCastRules::cast_rules): allow casts to float
gcc/testsuite/ChangeLog:
* rust/compile/issue-3261.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
---
gcc/rust/typecheck/rust-casts.cc | 10 ++++++++++
gcc/testsuite/rust/compile/issue-3261.rs | 18 ++++++++++++++++++
2 files changed, 28 insertions(+)
create mode 100644 gcc/testsuite/rust/compile/issue-3261.rs
diff --git a/gcc/rust/typecheck/rust-casts.cc b/gcc/rust/typecheck/rust-casts.cc
index 5235069fa23..cf4de4b3320 100644
--- a/gcc/rust/typecheck/rust-casts.cc
+++ b/gcc/rust/typecheck/rust-casts.cc
@@ -200,6 +200,16 @@ TypeCastRules::cast_rules ()
}
break;
+ case TyTy::TypeKind::FLOAT: {
+ // can only do this for number types not char
+ bool from_char
+ = from.get_ty ()->get_kind () == TyTy::TypeKind::CHAR;
+ if (!from_char)
+ return TypeCoercionRules::CoercionResult{{},
+ to.get_ty ()->clone ()};
+ }
+ break;
+
case TyTy::TypeKind::INFER:
case TyTy::TypeKind::USIZE:
case TyTy::TypeKind::ISIZE:
diff --git a/gcc/testsuite/rust/compile/issue-3261.rs b/gcc/testsuite/rust/compile/issue-3261.rs
new file mode 100644
index 00000000000..37e974d6169
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-3261.rs
@@ -0,0 +1,18 @@
+// { dg-options "-w" }
+fn main() {
+ let a: i8 = 50;
+ let b = a as f32;
+ let c = a as f64;
+
+ let a: i16 = 1337;
+ let b = a as f32;
+ let c = a as f64;
+
+ let a: i32 = 1337;
+ let b = a as f32;
+ let c = a as f64;
+
+ let a: i64 = 1337;
+ let b = a as f32;
+ let c = a as f64;
+}
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 054/146] gccrs: ensure packed and aligned is applied properly
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (52 preceding siblings ...)
2025-03-21 12:05 ` [COMMITTED 053/146] gccrs: allow casts from numeric types to floats arthur.cohen
@ 2025-03-21 12:05 ` arthur.cohen
2025-03-21 12:05 ` [COMMITTED 055/146] gccrs: lang-items: Move comment about arithmetic lang items arthur.cohen
` (91 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:05 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Philip Herron
From: Philip Herron <herron.philip@googlemail.com>
We cannot apply aligned or packed after layout_type is called you need
to set this up first then call it.
Fixes Rust-GCC#3260
gcc/rust/ChangeLog:
* backend/rust-compile-type.cc (TyTyResolveCompile::visit): call lauout type directly
* rust-backend.h (struct_type): add optional layout parameter
(union_type): likewise
(fill_in_fields): likewise
* rust-gcc.cc (struct_type): likewise
(union_type): likewise
(fill_in_fields): only layout if we required
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
---
gcc/rust/backend/rust-compile-type.cc | 8 +++++---
gcc/rust/rust-backend.h | 6 +++---
gcc/rust/rust-gcc.cc | 15 +++++++++------
3 files changed, 17 insertions(+), 12 deletions(-)
diff --git a/gcc/rust/backend/rust-compile-type.cc b/gcc/rust/backend/rust-compile-type.cc
index 56d64e1405b..50b52fbd37f 100644
--- a/gcc/rust/backend/rust-compile-type.cc
+++ b/gcc/rust/backend/rust-compile-type.cc
@@ -22,6 +22,7 @@
#include "rust-gcc.h"
#include "tree.h"
+#include "stor-layout.h"
namespace Rust {
namespace Compile {
@@ -268,8 +269,8 @@ TyTyResolveCompile::visit (const TyTy::ADTType &type)
fields.push_back (std::move (f));
}
- type_record = type.is_union () ? Backend::union_type (fields)
- : Backend::struct_type (fields);
+ type_record = type.is_union () ? Backend::union_type (fields, false)
+ : Backend::struct_type (fields, false);
}
else
{
@@ -359,7 +360,7 @@ TyTyResolveCompile::visit (const TyTy::ADTType &type)
}
// finally make the union or the enum
- type_record = Backend::union_type (enum_fields);
+ type_record = Backend::union_type (enum_fields, false);
}
// Handle repr options
@@ -381,6 +382,7 @@ TyTyResolveCompile::visit (const TyTy::ADTType &type)
SET_TYPE_ALIGN (type_record, repr.align * 8);
TYPE_USER_ALIGN (type_record) = 1;
}
+ layout_type (type_record);
std::string named_struct_str
= type.get_ident ().path.get () + type.subst_as_string ();
diff --git a/gcc/rust/rust-backend.h b/gcc/rust/rust-backend.h
index 9d28cf6d393..414799edefe 100644
--- a/gcc/rust/rust-backend.h
+++ b/gcc/rust/rust-backend.h
@@ -133,11 +133,11 @@ function_ptr_type (tree result, const std::vector<tree> &praameters,
// Get a struct type.
tree
-struct_type (const std::vector<typed_identifier> &fields);
+struct_type (const std::vector<typed_identifier> &fields, bool layout = true);
// Get a union type.
tree
-union_type (const std::vector<typed_identifier> &fields);
+union_type (const std::vector<typed_identifier> &fields, bool layout = true);
// Get an array type.
tree
@@ -496,7 +496,7 @@ write_global_definitions (const std::vector<tree> &type_decls,
// TODO: make static
tree
-fill_in_fields (tree, const std::vector<typed_identifier> &);
+fill_in_fields (tree, const std::vector<typed_identifier> &, bool);
tree fill_in_array (tree, tree, tree);
diff --git a/gcc/rust/rust-gcc.cc b/gcc/rust/rust-gcc.cc
index 273ab7889b0..59983ede97d 100644
--- a/gcc/rust/rust-gcc.cc
+++ b/gcc/rust/rust-gcc.cc
@@ -592,23 +592,24 @@ function_ptr_type (tree result_type, const std::vector<tree> ¶meters,
// Make a struct type.
tree
-struct_type (const std::vector<typed_identifier> &fields)
+struct_type (const std::vector<typed_identifier> &fields, bool layout)
{
- return fill_in_fields (make_node (RECORD_TYPE), fields);
+ return fill_in_fields (make_node (RECORD_TYPE), fields, layout);
}
// Make a union type.
tree
-union_type (const std::vector<typed_identifier> &fields)
+union_type (const std::vector<typed_identifier> &fields, bool layout)
{
- return fill_in_fields (make_node (UNION_TYPE), fields);
+ return fill_in_fields (make_node (UNION_TYPE), fields, layout);
}
// Fill in the fields of a struct or union type.
tree
-fill_in_fields (tree fill, const std::vector<typed_identifier> &fields)
+fill_in_fields (tree fill, const std::vector<typed_identifier> &fields,
+ bool layout)
{
tree field_trees = NULL_TREE;
tree *pp = &field_trees;
@@ -625,7 +626,9 @@ fill_in_fields (tree fill, const std::vector<typed_identifier> &fields)
pp = &DECL_CHAIN (field);
}
TYPE_FIELDS (fill) = field_trees;
- layout_type (fill);
+
+ if (layout)
+ layout_type (fill);
// Because Rust permits converting between named struct types and
// equivalent struct types, for which we use VIEW_CONVERT_EXPR, and
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 055/146] gccrs: lang-items: Move comment about arithmetic lang items
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (53 preceding siblings ...)
2025-03-21 12:05 ` [COMMITTED 054/146] gccrs: ensure packed and aligned is applied properly arthur.cohen
@ 2025-03-21 12:05 ` arthur.cohen
2025-03-21 12:05 ` [COMMITTED 056/146] gccrs: mappings: Move lang_item definitions to .cc arthur.cohen
` (90 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:05 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
gcc/rust/ChangeLog:
* util/rust-lang-item.h: Fix comment location to align with other comments.
---
gcc/rust/util/rust-lang-item.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/gcc/rust/util/rust-lang-item.h b/gcc/rust/util/rust-lang-item.h
index 951e4a3ceaf..92c70bbddf4 100644
--- a/gcc/rust/util/rust-lang-item.h
+++ b/gcc/rust/util/rust-lang-item.h
@@ -23,12 +23,12 @@
namespace Rust {
-// https://github.com/rust-lang/rust/blob/master/library/core/src/ops/arith.rs
class LangItem
{
public:
enum class Kind
{
+ // https://github.com/rust-lang/rust/blob/master/library/core/src/ops/arith.rs
ADD,
SUBTRACT,
MULTIPLY,
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 056/146] gccrs: mappings: Move lang_item definitions to .cc
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (54 preceding siblings ...)
2025-03-21 12:05 ` [COMMITTED 055/146] gccrs: lang-items: Move comment about arithmetic lang items arthur.cohen
@ 2025-03-21 12:05 ` arthur.cohen
2025-03-21 12:05 ` [COMMITTED 057/146] gccrs: hir: Remove duplicate function in TraitItemFunc arthur.cohen
` (89 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:05 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
gcc/rust/ChangeLog:
* util/rust-hir-map.h: Move definitions from header...
* util/rust-hir-map.cc: ...to source file.
---
gcc/rust/util/rust-hir-map.cc | 19 +++++++++++++++++++
gcc/rust/util/rust-hir-map.h | 18 ++----------------
2 files changed, 21 insertions(+), 16 deletions(-)
diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc
index d1504e108c1..5f77f570073 100644
--- a/gcc/rust/util/rust-hir-map.cc
+++ b/gcc/rust/util/rust-hir-map.cc
@@ -1258,5 +1258,24 @@ Mappings::lookup_trait_item_lang_item (LangItem::Kind item, location_t locus)
return lookup_trait_item_defid (trait_item_id);
}
+void
+Mappings::insert_lang_item (LangItem::Kind item_type, DefId id)
+{
+ auto it = lang_item_mappings.find (item_type);
+ rust_assert (it == lang_item_mappings.end ());
+
+ lang_item_mappings[item_type] = id;
+}
+
+tl::optional<DefId &>
+Mappings::lookup_lang_item (LangItem::Kind item_type)
+{
+ auto it = lang_item_mappings.find (item_type);
+ if (it == lang_item_mappings.end ())
+ return tl::nullopt;
+
+ return it->second;
+}
+
} // namespace Analysis
} // namespace Rust
diff --git a/gcc/rust/util/rust-hir-map.h b/gcc/rust/util/rust-hir-map.h
index bb7318e32ec..14a0514338b 100644
--- a/gcc/rust/util/rust-hir-map.h
+++ b/gcc/rust/util/rust-hir-map.h
@@ -256,22 +256,8 @@ public:
return it->second;
}
- void insert_lang_item (LangItem::Kind item_type, DefId id)
- {
- auto it = lang_item_mappings.find (item_type);
- rust_assert (it == lang_item_mappings.end ());
-
- lang_item_mappings[item_type] = id;
- }
-
- tl::optional<DefId &> lookup_lang_item (LangItem::Kind item_type)
- {
- auto it = lang_item_mappings.find (item_type);
- if (it == lang_item_mappings.end ())
- return tl::nullopt;
-
- return it->second;
- }
+ void insert_lang_item (LangItem::Kind item_type, DefId id);
+ tl::optional<DefId &> lookup_lang_item (LangItem::Kind item_type);
// This will fatal_error when this lang item does not exist
DefId get_lang_item (LangItem::Kind item_type, location_t locus);
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 057/146] gccrs: hir: Remove duplicate function in TraitItemFunc
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (55 preceding siblings ...)
2025-03-21 12:05 ` [COMMITTED 056/146] gccrs: mappings: Move lang_item definitions to .cc arthur.cohen
@ 2025-03-21 12:05 ` arthur.cohen
2025-03-21 12:05 ` [COMMITTED 058/146] gccrs: stacked-contexts: Add peek() method arthur.cohen
` (88 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:05 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
Both TraitItemFunc::has_definition() and TraitItemFunc::has_block_defined()
were exactly the same implementation, so remove one.
gcc/rust/ChangeLog:
* hir/tree/rust-hir-item.h: Remove TraitItemFunc::has_block_defined()
* backend/rust-compile-implitem.cc (CompileTraitItem::visit):
Call TraitItemFunc::has_definition() instead.
* checks/errors/rust-const-checker.cc (ConstChecker::visit): Likewise.
* checks/errors/rust-hir-pattern-analysis.cc (PatternChecker::visit): Likewise.
* checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Likewise.
* typecheck/rust-hir-trait-resolve.cc (ResolveTraitItemToRef::visit): Likewise.
---
gcc/rust/backend/rust-compile-implitem.cc | 2 +-
gcc/rust/checks/errors/rust-const-checker.cc | 2 +-
gcc/rust/checks/errors/rust-hir-pattern-analysis.cc | 2 +-
gcc/rust/checks/errors/rust-unsafe-checker.cc | 2 +-
gcc/rust/hir/tree/rust-hir-item.h | 2 --
gcc/rust/typecheck/rust-hir-trait-resolve.cc | 2 +-
6 files changed, 5 insertions(+), 7 deletions(-)
diff --git a/gcc/rust/backend/rust-compile-implitem.cc b/gcc/rust/backend/rust-compile-implitem.cc
index 352685e242f..129e97879fa 100644
--- a/gcc/rust/backend/rust-compile-implitem.cc
+++ b/gcc/rust/backend/rust-compile-implitem.cc
@@ -57,7 +57,7 @@ CompileTraitItem::visit (HIR::TraitItemConst &constant)
void
CompileTraitItem::visit (HIR::TraitItemFunc &func)
{
- rust_assert (func.has_block_defined ());
+ rust_assert (func.has_definition ());
rust_assert (concrete->get_kind () == TyTy::TypeKind::FNDEF);
TyTy::FnType *fntype = static_cast<TyTy::FnType *> (concrete);
diff --git a/gcc/rust/checks/errors/rust-const-checker.cc b/gcc/rust/checks/errors/rust-const-checker.cc
index 420db8fb8b2..97b35288bae 100644
--- a/gcc/rust/checks/errors/rust-const-checker.cc
+++ b/gcc/rust/checks/errors/rust-const-checker.cc
@@ -678,7 +678,7 @@ ConstChecker::visit (StaticItem &static_item)
void
ConstChecker::visit (TraitItemFunc &item)
{
- if (item.has_block_defined ())
+ if (item.has_definition ())
item.get_block_expr ().accept_vis (*this);
}
diff --git a/gcc/rust/checks/errors/rust-hir-pattern-analysis.cc b/gcc/rust/checks/errors/rust-hir-pattern-analysis.cc
index db1e7272556..79416b5d50a 100644
--- a/gcc/rust/checks/errors/rust-hir-pattern-analysis.cc
+++ b/gcc/rust/checks/errors/rust-hir-pattern-analysis.cc
@@ -522,7 +522,7 @@ PatternChecker::visit (StaticItem &static_item)
void
PatternChecker::visit (TraitItemFunc &item)
{
- if (item.has_block_defined ())
+ if (item.has_definition ())
item.get_block_expr ().accept_vis (*this);
}
diff --git a/gcc/rust/checks/errors/rust-unsafe-checker.cc b/gcc/rust/checks/errors/rust-unsafe-checker.cc
index 6c9141c2dd2..fadfd9dea83 100644
--- a/gcc/rust/checks/errors/rust-unsafe-checker.cc
+++ b/gcc/rust/checks/errors/rust-unsafe-checker.cc
@@ -776,7 +776,7 @@ UnsafeChecker::visit (StaticItem &static_item)
void
UnsafeChecker::visit (TraitItemFunc &item)
{
- if (item.has_block_defined ())
+ if (item.has_definition ())
item.get_block_expr ().accept_vis (*this);
}
diff --git a/gcc/rust/hir/tree/rust-hir-item.h b/gcc/rust/hir/tree/rust-hir-item.h
index 0fda1672b74..47447174215 100644
--- a/gcc/rust/hir/tree/rust-hir-item.h
+++ b/gcc/rust/hir/tree/rust-hir-item.h
@@ -1991,8 +1991,6 @@ public:
const TraitFunctionDecl &get_decl () const { return decl; }
- bool has_block_defined () const { return block_expr != nullptr; }
-
BlockExpr &get_block_expr () { return *block_expr; }
const std::string trait_identifier () const override final
diff --git a/gcc/rust/typecheck/rust-hir-trait-resolve.cc b/gcc/rust/typecheck/rust-hir-trait-resolve.cc
index 2fbf123aa77..14e26f4512b 100644
--- a/gcc/rust/typecheck/rust-hir-trait-resolve.cc
+++ b/gcc/rust/typecheck/rust-hir-trait-resolve.cc
@@ -69,7 +69,7 @@ ResolveTraitItemToRef::visit (HIR::TraitItemFunc &fn)
{
// create trait-item-ref
location_t locus = fn.get_locus ();
- bool is_optional = fn.has_block_defined ();
+ bool is_optional = fn.has_definition ();
std::string identifier = fn.get_decl ().get_function_name ().as_string ();
resolved = TraitItemReference (identifier, is_optional,
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 058/146] gccrs: stacked-contexts: Add peek() method
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (56 preceding siblings ...)
2025-03-21 12:05 ` [COMMITTED 057/146] gccrs: hir: Remove duplicate function in TraitItemFunc arthur.cohen
@ 2025-03-21 12:05 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 059/146] gccrs: ast: Use StackedContexts class in ContextualASTVisitor arthur.cohen
` (87 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:05 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
gcc/rust/ChangeLog:
* util/rust-stacked-contexts.h: Add new method to see what context we are currently in.
---
gcc/rust/util/rust-stacked-contexts.h | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/gcc/rust/util/rust-stacked-contexts.h b/gcc/rust/util/rust-stacked-contexts.h
index 39a0c08de79..fe0bc8a291b 100644
--- a/gcc/rust/util/rust-stacked-contexts.h
+++ b/gcc/rust/util/rust-stacked-contexts.h
@@ -71,6 +71,13 @@ public:
return last;
}
+ const T &peek ()
+ {
+ rust_assert (!stack.empty ());
+
+ return stack.back ();
+ }
+
/**
* Are we currently inside of a special context?
*/
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 059/146] gccrs: ast: Use StackedContexts class in ContextualASTVisitor
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (57 preceding siblings ...)
2025-03-21 12:05 ` [COMMITTED 058/146] gccrs: stacked-contexts: Add peek() method arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 060/146] gccrs: Remove bad assertion in name resolution arthur.cohen
` (86 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
gcc/rust/ChangeLog:
* ast/rust-ast-visitor.h: Replace context with StackedContexts.
* ast/rust-ast-visitor.cc (ContextualASTVisitor::visit): Use new APIs.
* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Likewise.
---
gcc/rust/ast/rust-ast-visitor.cc | 16 +++++++--------
gcc/rust/ast/rust-ast-visitor.h | 10 ++++------
gcc/rust/checks/errors/rust-ast-validation.cc | 20 ++++++++-----------
3 files changed, 20 insertions(+), 26 deletions(-)
diff --git a/gcc/rust/ast/rust-ast-visitor.cc b/gcc/rust/ast/rust-ast-visitor.cc
index 8f53e528131..a390aa20bcb 100644
--- a/gcc/rust/ast/rust-ast-visitor.cc
+++ b/gcc/rust/ast/rust-ast-visitor.cc
@@ -1453,33 +1453,33 @@ DefaultASTVisitor::visit (AST::VariadicParam ¶m)
void
ContextualASTVisitor::visit (AST::Crate &crate)
{
- push_context (Context::CRATE);
+ ctx.enter (Kind::CRATE);
DefaultASTVisitor::visit (crate);
- pop_context ();
+ ctx.exit ();
}
void
ContextualASTVisitor::visit (AST::InherentImpl &impl)
{
- push_context (Context::INHERENT_IMPL);
+ ctx.enter (Kind::INHERENT_IMPL);
DefaultASTVisitor::visit (impl);
- pop_context ();
+ ctx.exit ();
}
void
ContextualASTVisitor::visit (AST::TraitImpl &impl)
{
- push_context (Context::TRAIT_IMPL);
+ ctx.enter (Kind::TRAIT_IMPL);
DefaultASTVisitor::visit (impl);
- pop_context ();
+ ctx.exit ();
}
void
ContextualASTVisitor::visit (AST::Trait &trait)
{
- push_context (Context::TRAIT);
+ ctx.enter (Kind::TRAIT);
DefaultASTVisitor::visit (trait);
- pop_context ();
+ ctx.exit ();
}
} // namespace AST
diff --git a/gcc/rust/ast/rust-ast-visitor.h b/gcc/rust/ast/rust-ast-visitor.h
index 50b93016d62..7e3423cd493 100644
--- a/gcc/rust/ast/rust-ast-visitor.h
+++ b/gcc/rust/ast/rust-ast-visitor.h
@@ -26,6 +26,7 @@
#include "rust-item.h"
#include "rust-path.h"
#include "rust-system.h"
+#include "rust-stacked-contexts.h"
namespace Rust {
namespace AST {
@@ -452,7 +453,7 @@ public:
class ContextualASTVisitor : public DefaultASTVisitor
{
protected:
- enum class Context
+ enum class Kind
{
FUNCTION,
INHERENT_IMPL,
@@ -461,6 +462,7 @@ protected:
MODULE,
CRATE,
};
+
using DefaultASTVisitor::visit;
virtual void visit (AST::Crate &crate) override;
@@ -476,11 +478,7 @@ protected:
DefaultASTVisitor::visit (item);
}
- std::vector<Context> context;
-
- void push_context (Context ctx) { context.push_back (ctx); }
-
- void pop_context () { context.pop_back (); }
+ StackedContexts<Kind> ctx;
};
} // namespace AST
diff --git a/gcc/rust/checks/errors/rust-ast-validation.cc b/gcc/rust/checks/errors/rust-ast-validation.cc
index 7938286ffb5..59b28057bab 100644
--- a/gcc/rust/checks/errors/rust-ast-validation.cc
+++ b/gcc/rust/checks/errors/rust-ast-validation.cc
@@ -56,7 +56,7 @@ ASTValidation::visit (AST::LoopLabel &label)
void
ASTValidation::visit (AST::ConstantItem &const_item)
{
- if (!const_item.has_expr () && context.back () != Context::TRAIT_IMPL)
+ if (!const_item.has_expr () && ctx.peek () != Kind::TRAIT_IMPL)
{
rust_error_at (const_item.get_locus (),
"associated constant in %<impl%> without body");
@@ -82,23 +82,19 @@ ASTValidation::visit (AST::Function &function)
"functions cannot be both %<const%> and %<async%>");
if (qualifiers.is_const ()
- && (context.back () == Context::TRAIT_IMPL
- || context.back () == Context::TRAIT))
+ && (ctx.peek () == Kind::TRAIT_IMPL || ctx.peek () == Kind::TRAIT))
rust_error_at (function.get_locus (), ErrorCode::E0379,
"functions in traits cannot be declared %<const%>");
// may change soon
if (qualifiers.is_async ()
- && (context.back () == Context::TRAIT_IMPL
- || context.back () == Context::TRAIT))
+ && (ctx.peek () == Kind::TRAIT_IMPL || ctx.peek () == Kind::TRAIT))
rust_error_at (function.get_locus (), ErrorCode::E0706,
"functions in traits cannot be declared %<async%>");
// if not an associated function but has a self parameter
- if (context.back () != Context::TRAIT
- && context.back () != Context::TRAIT_IMPL
- && context.back () != Context::INHERENT_IMPL
- && function.has_self_param ())
+ if (ctx.peek () != Kind::TRAIT && ctx.peek () != Kind::TRAIT_IMPL
+ && ctx.peek () != Kind::INHERENT_IMPL && function.has_self_param ())
rust_error_at (
function.get_self_param ().get_locus (),
"%<self%> parameter is only allowed in associated functions");
@@ -140,11 +136,11 @@ ASTValidation::visit (AST::Function &function)
{
if (!function.has_body ())
{
- if (context.back () == Context::INHERENT_IMPL
- || context.back () == Context::TRAIT_IMPL)
+ if (ctx.peek () == Kind::INHERENT_IMPL
+ || ctx.peek () == Kind::TRAIT_IMPL)
rust_error_at (function.get_locus (),
"associated function in %<impl%> without body");
- else if (context.back () != Context::TRAIT)
+ else if (ctx.peek () != Kind::TRAIT)
rust_error_at (function.get_locus (),
"free function without a body");
}
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 060/146] gccrs: Remove bad assertion in name resolution
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (58 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 059/146] gccrs: ast: Use StackedContexts class in ContextualASTVisitor arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 061/146] gccrs: constant evaluation like these are coercion sites arthur.cohen
` (85 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Philip Herron
From: Philip Herron <herron.philip@googlemail.com>
This was a handy debug assertion but only works for valid rust code. This
needs to handle the case where the type is not resolved which is a valid
case.
Fixes Rust-GCC#2423
gcc/rust/ChangeLog:
* resolve/rust-ast-resolve-item.cc (ResolveItem::visit): remove assertions
gcc/testsuite/ChangeLog:
* rust/compile/nr2/exclude: nr2 can't handle this
* rust/compile/issue-2423.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
---
gcc/rust/resolve/rust-ast-resolve-item.cc | 30 ++++++++++++++++++-----
gcc/testsuite/rust/compile/issue-2423.rs | 14 +++++++++++
gcc/testsuite/rust/compile/nr2/exclude | 1 +
3 files changed, 39 insertions(+), 6 deletions(-)
create mode 100644 gcc/testsuite/rust/compile/issue-2423.rs
diff --git a/gcc/rust/resolve/rust-ast-resolve-item.cc b/gcc/rust/resolve/rust-ast-resolve-item.cc
index 2861fb94d9f..245523ae5aa 100644
--- a/gcc/rust/resolve/rust-ast-resolve-item.cc
+++ b/gcc/rust/resolve/rust-ast-resolve-item.cc
@@ -582,7 +582,14 @@ ResolveItem::visit (AST::InherentImpl &impl_block)
// Setup paths
CanonicalPath self_cpath = CanonicalPath::create_empty ();
bool ok = ResolveTypeToCanonicalPath::go (impl_block.get_type (), self_cpath);
- rust_assert (ok);
+ if (!ok)
+ {
+ resolver->get_name_scope ().pop ();
+ resolver->get_type_scope ().pop ();
+ resolver->get_label_scope ().pop ();
+ return;
+ }
+
rust_debug ("AST::InherentImpl resolve Self: {%s}",
self_cpath.get ().c_str ());
@@ -671,12 +678,17 @@ ResolveItem::visit (AST::TraitImpl &impl_block)
return;
}
- bool ok;
// setup paths
CanonicalPath canonical_trait_type = CanonicalPath::create_empty ();
- ok = ResolveTypeToCanonicalPath::go (impl_block.get_trait_path (),
- canonical_trait_type);
- rust_assert (ok);
+ bool ok = ResolveTypeToCanonicalPath::go (impl_block.get_trait_path (),
+ canonical_trait_type);
+ if (!ok)
+ {
+ resolver->get_name_scope ().pop ();
+ resolver->get_type_scope ().pop ();
+ resolver->get_label_scope ().pop ();
+ return;
+ }
rust_debug ("AST::TraitImpl resolve trait type: {%s}",
canonical_trait_type.get ().c_str ());
@@ -684,7 +696,13 @@ ResolveItem::visit (AST::TraitImpl &impl_block)
CanonicalPath canonical_impl_type = CanonicalPath::create_empty ();
ok = ResolveTypeToCanonicalPath::go (impl_block.get_type (),
canonical_impl_type);
- rust_assert (ok);
+ if (!ok)
+ {
+ resolver->get_name_scope ().pop ();
+ resolver->get_type_scope ().pop ();
+ resolver->get_label_scope ().pop ();
+ return;
+ }
rust_debug ("AST::TraitImpl resolve self: {%s}",
canonical_impl_type.get ().c_str ());
diff --git a/gcc/testsuite/rust/compile/issue-2423.rs b/gcc/testsuite/rust/compile/issue-2423.rs
new file mode 100644
index 00000000000..ae7897c1170
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-2423.rs
@@ -0,0 +1,14 @@
+impl NonExistant {
+ // { dg-error "failed to resolve" "" { target *-*-* } .-1 }
+ fn test() {}
+}
+
+impl NotFound for NonExistant {
+ // { dg-error "failed to resolve" "" { target *-*-* } .-1 }
+ fn test() {}
+}
+
+trait A {}
+
+impl A for NotFound {}
+// { dg-error "failed to resolve" "" { target *-*-* } .-1 }
diff --git a/gcc/testsuite/rust/compile/nr2/exclude b/gcc/testsuite/rust/compile/nr2/exclude
index 00ac704fec2..bf4506f25d2 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -206,4 +206,5 @@ issue-1773.rs
issue-2905-1.rs
issue-2905-2.rs
issue-2907.rs
+issue-2423.rs
# please don't delete the trailing newline
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 061/146] gccrs: constant evaluation like these are coercion sites
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (59 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 060/146] gccrs: Remove bad assertion in name resolution arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 062/146] gccrs: add checks for division by zero and left shift overflow arthur.cohen
` (84 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Philip Herron
From: Philip Herron <herron.philip@googlemail.com>
The code here was wrongly assuming the decl type from the folding of the
expression would be the type of the constant decl. This is not the case for
unsized coercions for slices, where the expression here is a reference to
an array then we require the coercion to fix the result up to the expected
type.
Fixes Rust-GCC#1525
gcc/rust/ChangeLog:
* backend/rust-compile-base.cc: apply coercion site to result
* backend/rust-compile-base.h: update prototype
* backend/rust-compile-implitem.cc (CompileTraitItem::visit): send in coercion info
* backend/rust-compile-item.cc (CompileItem::visit): likewise
gcc/testsuite/ChangeLog:
* rust/compile/issue-1525.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
---
gcc/rust/backend/rust-compile-base.cc | 15 +++++++++---
gcc/rust/backend/rust-compile-base.h | 6 +++--
gcc/rust/backend/rust-compile-implitem.cc | 11 +++++++--
gcc/rust/backend/rust-compile-item.cc | 29 ++++++++++++++++-------
gcc/testsuite/rust/compile/issue-1525.rs | 4 ++++
5 files changed, 50 insertions(+), 15 deletions(-)
create mode 100644 gcc/testsuite/rust/compile/issue-1525.rs
diff --git a/gcc/rust/backend/rust-compile-base.cc b/gcc/rust/backend/rust-compile-base.cc
index fb4aace9555..bcc7fc4fcbf 100644
--- a/gcc/rust/backend/rust-compile-base.cc
+++ b/gcc/rust/backend/rust-compile-base.cc
@@ -777,13 +777,18 @@ HIRCompileBase::compile_function (
tree
HIRCompileBase::compile_constant_item (
- TyTy::BaseType *resolved_type, const Resolver::CanonicalPath &canonical_path,
- HIR::Expr &const_value_expr, location_t locus)
+ HirId coercion_id, TyTy::BaseType *resolved_type,
+ TyTy::BaseType *expected_type, const Resolver::CanonicalPath &canonical_path,
+ HIR::Expr &const_value_expr, location_t locus, location_t expr_locus)
{
const std::string &ident = canonical_path.get ();
tree type = TyTyResolveCompile::compile (ctx, resolved_type);
tree const_type = build_qualified_type (type, TYPE_QUAL_CONST);
+
+ tree actual_type = TyTyResolveCompile::compile (ctx, expected_type);
+ tree actual_const_type = build_qualified_type (actual_type, TYPE_QUAL_CONST);
+
bool is_block_expr
= const_value_expr.get_expression_type () == HIR::Expr::ExprType::Block;
@@ -851,7 +856,11 @@ HIRCompileBase::compile_constant_item (
tree call = build_call_array_loc (locus, const_type, fndecl, 0, NULL);
tree folded_expr = fold_expr (call);
- return named_constant_expression (const_type, ident, folded_expr, locus);
+ // coercion site
+ tree coerced = coercion_site (coercion_id, folded_expr, resolved_type,
+ expected_type, locus, expr_locus);
+
+ return named_constant_expression (actual_const_type, ident, coerced, locus);
}
tree
diff --git a/gcc/rust/backend/rust-compile-base.h b/gcc/rust/backend/rust-compile-base.h
index 5fb1d83f2ee..9328a7f7483 100644
--- a/gcc/rust/backend/rust-compile-base.h
+++ b/gcc/rust/backend/rust-compile-base.h
@@ -90,9 +90,11 @@ protected:
void compile_function_body (tree fndecl, HIR::BlockExpr &function_body,
TyTy::BaseType *fn_return_ty);
- tree compile_constant_item (TyTy::BaseType *resolved_type,
+ tree compile_constant_item (HirId coercion_id, TyTy::BaseType *resolved_type,
+ TyTy::BaseType *expected_type,
const Resolver::CanonicalPath &canonical_path,
- HIR::Expr &const_value_expr, location_t locus);
+ HIR::Expr &const_value_expr, location_t locus,
+ location_t expr_locus);
tree compile_function (const std::string &fn_name, HIR::SelfParam &self_param,
std::vector<HIR::FunctionParam> &function_params,
diff --git a/gcc/rust/backend/rust-compile-implitem.cc b/gcc/rust/backend/rust-compile-implitem.cc
index 129e97879fa..71b3e8d3002 100644
--- a/gcc/rust/backend/rust-compile-implitem.cc
+++ b/gcc/rust/backend/rust-compile-implitem.cc
@@ -45,9 +45,16 @@ CompileTraitItem::visit (HIR::TraitItemConst &constant)
rust_assert (canonical_path);
HIR::Expr &const_value_expr = constant.get_expr ();
+ TyTy::BaseType *expr_type = nullptr;
+ bool ok = ctx->get_tyctx ()->lookup_type (
+ const_value_expr.get_mappings ().get_hirid (), &expr_type);
+ rust_assert (ok);
+
tree const_expr
- = compile_constant_item (resolved_type, *canonical_path, const_value_expr,
- constant.get_locus ());
+ = compile_constant_item (constant.get_mappings ().get_hirid (), expr_type,
+ resolved_type, *canonical_path, const_value_expr,
+ constant.get_locus (),
+ const_value_expr.get_locus ());
ctx->push_const (const_expr);
ctx->insert_const_decl (constant.get_mappings ().get_hirid (), const_expr);
diff --git a/gcc/rust/backend/rust-compile-item.cc b/gcc/rust/backend/rust-compile-item.cc
index dd37e3997d6..52cd59f94e4 100644
--- a/gcc/rust/backend/rust-compile-item.cc
+++ b/gcc/rust/backend/rust-compile-item.cc
@@ -35,10 +35,16 @@ CompileItem::visit (HIR::StaticItem &var)
return;
}
+ HIR::Expr &const_value_expr = var.get_expr ();
+
TyTy::BaseType *resolved_type = nullptr;
+ TyTy::BaseType *expr_type = nullptr;
bool ok = ctx->get_tyctx ()->lookup_type (var.get_mappings ().get_hirid (),
&resolved_type);
rust_assert (ok);
+ ok = ctx->get_tyctx ()->lookup_type (
+ const_value_expr.get_mappings ().get_hirid (), &expr_type);
+ rust_assert (ok);
tree type = TyTyResolveCompile::compile (ctx, resolved_type);
@@ -60,10 +66,11 @@ CompileItem::visit (HIR::StaticItem &var)
rust_assert (canonical_path.has_value ());
- HIR::Expr &const_value_expr = var.get_expr ();
ctx->push_const_context ();
- tree value = compile_constant_item (resolved_type, *canonical_path,
- const_value_expr, var.get_locus ());
+ tree value
+ = compile_constant_item (var.get_mappings ().get_hirid (), expr_type,
+ resolved_type, *canonical_path, const_value_expr,
+ var.get_locus (), const_value_expr.get_locus ());
ctx->pop_const_context ();
std::string name = canonical_path->get ();
@@ -89,16 +96,21 @@ CompileItem::visit (HIR::StaticItem &var)
void
CompileItem::visit (HIR::ConstantItem &constant)
{
+ HIR::Expr &const_value_expr = constant.get_expr ();
auto &mappings = constant.get_mappings ();
if (ctx->lookup_const_decl (mappings.get_hirid (), &reference))
return;
// resolve the type
- TyTy::BaseType *resolved_type = nullptr;
+ TyTy::BaseType *constant_type = nullptr;
+ TyTy::BaseType *expr_type = nullptr;
bool ok
- = ctx->get_tyctx ()->lookup_type (mappings.get_hirid (), &resolved_type);
+ = ctx->get_tyctx ()->lookup_type (mappings.get_hirid (), &constant_type);
+ rust_assert (ok);
+ ok = ctx->get_tyctx ()->lookup_type (
+ const_value_expr.get_mappings ().get_hirid (), &expr_type);
rust_assert (ok);
// canonical path
@@ -120,11 +132,12 @@ CompileItem::visit (HIR::ConstantItem &constant)
.value ();
}
- HIR::Expr &const_value_expr = constant.get_expr ();
ctx->push_const_context ();
tree const_expr
- = compile_constant_item (resolved_type, canonical_path, const_value_expr,
- constant.get_locus ());
+ = compile_constant_item (mappings.get_hirid (), expr_type, constant_type,
+ canonical_path, const_value_expr,
+ constant.get_locus (),
+ const_value_expr.get_locus ());
ctx->pop_const_context ();
ctx->push_const (const_expr);
diff --git a/gcc/testsuite/rust/compile/issue-1525.rs b/gcc/testsuite/rust/compile/issue-1525.rs
new file mode 100644
index 00000000000..b2247cd9e7d
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-1525.rs
@@ -0,0 +1,4 @@
+fn main() {
+ const slice: &[i32] = &[1, 2, 3];
+ let _slice2: &[i32] = slice;
+}
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 062/146] gccrs: add checks for division by zero and left shift overflow
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (60 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 061/146] gccrs: constant evaluation like these are coercion sites arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 063/146] gccrs: add test case to show issue is fixed arthur.cohen
` (83 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Philip Herron
From: Philip Herron <herron.philip@googlemail.com>
These are ported from the c-family code c-warn.cc and c/c-typchk.cc
Fixes Rust-GCC#2394
gcc/rust/ChangeLog:
* backend/rust-constexpr.cc (eval_store_expression): check for null
(eval_call_expression): remove bad warning
* rust-gcc.cc (arithmetic_or_logical_expression): add warnings
gcc/testsuite/ChangeLog:
* rust/compile/issue-2394.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
---
gcc/rust/backend/rust-constexpr.cc | 8 +++++---
gcc/rust/rust-gcc.cc | 11 +++++++++++
gcc/testsuite/rust/compile/issue-2394.rs | 14 ++++++++++++++
3 files changed, 30 insertions(+), 3 deletions(-)
create mode 100644 gcc/testsuite/rust/compile/issue-2394.rs
diff --git a/gcc/rust/backend/rust-constexpr.cc b/gcc/rust/backend/rust-constexpr.cc
index bfd7d959aa8..2f2bbbd921d 100644
--- a/gcc/rust/backend/rust-constexpr.cc
+++ b/gcc/rust/backend/rust-constexpr.cc
@@ -2929,8 +2929,13 @@ eval_store_expression (const constexpr_ctx *ctx, tree t, bool lval,
}
}
+ if (*non_constant_p)
+ return t;
+
/* Don't share a CONSTRUCTOR that might be changed later. */
init = unshare_constructor (init);
+ if (init == NULL_TREE)
+ return t;
if (*valp && TREE_CODE (*valp) == CONSTRUCTOR
&& TREE_CODE (init) == CONSTRUCTOR)
@@ -3585,9 +3590,6 @@ eval_call_expression (const constexpr_ctx *ctx, tree t, bool lval,
result = *ctx->global->values.get (res);
if (result == NULL_TREE && !*non_constant_p)
{
- if (!ctx->quiet)
- error ("%<constexpr%> call flows off the end "
- "of the function");
*non_constant_p = true;
}
}
diff --git a/gcc/rust/rust-gcc.cc b/gcc/rust/rust-gcc.cc
index 59983ede97d..7da5e2c5637 100644
--- a/gcc/rust/rust-gcc.cc
+++ b/gcc/rust/rust-gcc.cc
@@ -1106,6 +1106,17 @@ arithmetic_or_logical_expression (ArithmeticOrLogicalOperator op, tree left,
if (floating_point && extended_type != NULL_TREE)
ret = convert (original_type, ret);
+ if (op == ArithmeticOrLogicalOperator::DIVIDE
+ && (integer_zerop (right) || fixed_zerop (right)))
+ {
+ rust_error_at (location, "division by zero");
+ }
+ else if (op == ArithmeticOrLogicalOperator::LEFT_SHIFT
+ && (compare_tree_int (right, TYPE_PRECISION (TREE_TYPE (ret))) >= 0))
+ {
+ rust_error_at (location, "left shift count >= width of type");
+ }
+
return ret;
}
diff --git a/gcc/testsuite/rust/compile/issue-2394.rs b/gcc/testsuite/rust/compile/issue-2394.rs
new file mode 100644
index 00000000000..92f7afc6507
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-2394.rs
@@ -0,0 +1,14 @@
+const A: i32 = (1 / 0);
+// { dg-error "division by zero" "" { target *-*-* } .-1 }
+
+fn main() {
+ let a = 1 / 0;
+ // { dg-error "division by zero" "" { target *-*-* } .-1 }
+
+ let b = 3;
+ let c = b / 0;
+ // { dg-error "division by zero" "" { target *-*-* } .-1 }
+
+ let a = 1 << 500;
+ // { dg-error "left shift count >= width of type" "" { target *-*-* } .-1 }
+}
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 063/146] gccrs: add test case to show issue is fixed
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (61 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 062/146] gccrs: add checks for division by zero and left shift overflow arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 064/146] gccrs: fix crash in hir dump arthur.cohen
` (82 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Philip Herron
From: Philip Herron <herron.philip@googlemail.com>
Fixes Rust-GCC#266
gcc/testsuite/ChangeLog:
* rust/compile/nr2/exclude: nr2 cant handle this
* rust/compile/issue-266.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
---
gcc/testsuite/rust/compile/issue-266.rs | 3 +++
gcc/testsuite/rust/compile/nr2/exclude | 1 +
2 files changed, 4 insertions(+)
create mode 100644 gcc/testsuite/rust/compile/issue-266.rs
diff --git a/gcc/testsuite/rust/compile/issue-266.rs b/gcc/testsuite/rust/compile/issue-266.rs
new file mode 100644
index 00000000000..11196cb7d73
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-266.rs
@@ -0,0 +1,3 @@
+fn main() {
+ 'label: while break 'label {}
+}
diff --git a/gcc/testsuite/rust/compile/nr2/exclude b/gcc/testsuite/rust/compile/nr2/exclude
index bf4506f25d2..797e59a5c58 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -207,4 +207,5 @@ issue-2905-1.rs
issue-2905-2.rs
issue-2907.rs
issue-2423.rs
+issue-266.rs
# please don't delete the trailing newline
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 064/146] gccrs: fix crash in hir dump
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (62 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 063/146] gccrs: add test case to show issue is fixed arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 065/146] gccrs: lang-items: Store NodeId mappings for lang items arthur.cohen
` (81 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Philip Herron
From: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:
* hir/rust-hir-dump.cc (Dump::visit): add missing check for no return value
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
---
gcc/rust/hir/rust-hir-dump.cc | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/gcc/rust/hir/rust-hir-dump.cc b/gcc/rust/hir/rust-hir-dump.cc
index be785b9ebec..2590eed19ae 100644
--- a/gcc/rust/hir/rust-hir-dump.cc
+++ b/gcc/rust/hir/rust-hir-dump.cc
@@ -1365,7 +1365,8 @@ Dump::visit (ReturnExpr &e)
begin ("ReturnExpr");
do_mappings (e.get_mappings ());
- visit_field ("return_expr", e.get_expr ());
+ if (e.has_return_expr ())
+ visit_field ("return_expr", e.get_expr ());
end ("ReturnExpr");
}
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 065/146] gccrs: lang-items: Store NodeId mappings for lang items
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (63 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 064/146] gccrs: fix crash in hir dump arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 066/146] gccrs: lang-items: Add lang-items AST collector arthur.cohen
` (80 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
gcc/rust/ChangeLog:
* util/rust-hir-map.h: Keep a NodeId mappings for lang items.
* util/rust-hir-map.cc (Mappings::insert_lang_item_node): New function.
(Mappings::lookup_lang_item_node): Likewise.
---
gcc/rust/util/rust-hir-map.cc | 22 ++++++++++++++++++++++
gcc/rust/util/rust-hir-map.h | 8 ++++++++
2 files changed, 30 insertions(+)
diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc
index 5f77f570073..f11a77954ae 100644
--- a/gcc/rust/util/rust-hir-map.cc
+++ b/gcc/rust/util/rust-hir-map.cc
@@ -1241,6 +1241,9 @@ Mappings::lookup_builtin_marker ()
return builtinMarker;
}
+// FIXME: Before merging: Should we remove the `locus` parameter here? since
+// lang items are looked up mostly for code generation, it doesn't make sense to
+// error out on the locus of the node trying to access an inexistant lang item
DefId
Mappings::get_lang_item (LangItem::Kind item_type, location_t locus)
{
@@ -1277,5 +1280,24 @@ Mappings::lookup_lang_item (LangItem::Kind item_type)
return it->second;
}
+void
+Mappings::insert_lang_item_node (LangItem::Kind item_type, NodeId node_id)
+{
+ auto it = lang_item_nodes.find (item_type);
+ rust_assert (it == lang_item_nodes.end ());
+
+ lang_item_nodes.insert ({item_type, node_id});
+}
+
+tl::optional<NodeId &>
+Mappings::lookup_lang_item_node (LangItem::Kind item_type)
+{
+ auto it = lang_item_nodes.find (item_type);
+ if (it == lang_item_nodes.end ())
+ return tl::nullopt;
+
+ return it->second;
+}
+
} // namespace Analysis
} // namespace Rust
diff --git a/gcc/rust/util/rust-hir-map.h b/gcc/rust/util/rust-hir-map.h
index 14a0514338b..aba51be4827 100644
--- a/gcc/rust/util/rust-hir-map.h
+++ b/gcc/rust/util/rust-hir-map.h
@@ -259,6 +259,9 @@ public:
void insert_lang_item (LangItem::Kind item_type, DefId id);
tl::optional<DefId &> lookup_lang_item (LangItem::Kind item_type);
+ void insert_lang_item_node (LangItem::Kind item_type, NodeId node_id);
+ tl::optional<NodeId &> lookup_lang_item_node (LangItem::Kind item_type);
+
// This will fatal_error when this lang item does not exist
DefId get_lang_item (LangItem::Kind item_type, location_t locus);
@@ -375,7 +378,12 @@ private:
std::map<HirId, HIR::GenericParam *> hirGenericParamMappings;
std::map<HirId, HIR::Trait *> hirTraitItemsToTraitMappings;
std::map<HirId, HIR::Pattern *> hirPatternMappings;
+
+ // We need to have two maps here, as lang-items need to be used for both AST
+ // passes and HIR passes. Thus those two maps are created at different times.
std::map<LangItem::Kind, DefId> lang_item_mappings;
+ std::map<LangItem::Kind, NodeId> lang_item_nodes;
+
std::map<NodeId, Resolver::CanonicalPath> paths;
std::map<NodeId, location_t> locations;
std::map<NodeId, HirId> nodeIdToHirMappings;
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 066/146] gccrs: lang-items: Add lang-items AST collector
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (64 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 065/146] gccrs: lang-items: Store NodeId mappings for lang items arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 067/146] gccrs: attributes: Add class for sharing methods on attributes arthur.cohen
` (79 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
gcc/rust/ChangeLog:
* Make-lang.in: Add new object file.
* rust-session-manager.cc (Session::compile_crate): Call CollectLangItems.
* ast/rust-collect-lang-items.cc: New file.
* ast/rust-collect-lang-items.h: New file.
---
gcc/rust/Make-lang.in | 3 +-
gcc/rust/ast/rust-collect-lang-items.cc | 97 +++++++++++++++++++++++++
gcc/rust/ast/rust-collect-lang-items.h | 58 +++++++++++++++
gcc/rust/rust-session-manager.cc | 3 +
4 files changed, 160 insertions(+), 1 deletion(-)
create mode 100644 gcc/rust/ast/rust-collect-lang-items.cc
create mode 100644 gcc/rust/ast/rust-collect-lang-items.h
diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in
index 9c5ec49ec4e..8771cdf91e1 100644
--- a/gcc/rust/Make-lang.in
+++ b/gcc/rust/Make-lang.in
@@ -227,8 +227,9 @@ GRS_OBJS = \
rust/rust-dir-owner.o \
rust/rust-unicode.o \
rust/rust-punycode.o \
- rust/rust-lang-item.o \
rust/rust-expand-format-args.o \
+ rust/rust-lang-item.o \
+ rust/rust-collect-lang-items.o \
$(END)
# removed object files from here
diff --git a/gcc/rust/ast/rust-collect-lang-items.cc b/gcc/rust/ast/rust-collect-lang-items.cc
new file mode 100644
index 00000000000..11a30aa37a7
--- /dev/null
+++ b/gcc/rust/ast/rust-collect-lang-items.cc
@@ -0,0 +1,97 @@
+// 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
+// <http://www.gnu.org/licenses/>.
+
+#include "rust-collect-lang-items.h"
+#include "optional.h"
+#include "rust-ast-collector.h"
+#include "rust-ast.h"
+#include "rust-attribute-values.h"
+#include "rust-attributes.h"
+#include "rust-hir-map.h"
+
+namespace Rust {
+namespace AST {
+
+// FIXME: Before merging: De-duplicate with function in rust-ast-lower-base.cc
+bool
+is_known_attribute (const std::string &attribute_path)
+{
+ const auto &lookup
+ = Analysis::BuiltinAttributeMappings::get ()->lookup_builtin (
+ attribute_path);
+
+ return !lookup.is_error ();
+}
+
+template <typename T>
+tl::optional<LangItem::Kind>
+get_lang_item_attr (const T &maybe_lang_item)
+{
+ for (const auto &attr : maybe_lang_item.get_outer_attrs ())
+ {
+ const auto &str_path = attr.get_path ().as_string ();
+ if (!is_known_attribute (str_path))
+ {
+ rust_error_at (attr.get_locus (), "unknown attribute");
+ continue;
+ }
+
+ bool is_lang_item = str_path == Values::Attributes::LANG
+ && attr.has_attr_input ()
+ && attr.get_attr_input ().get_attr_input_type ()
+ == AST::AttrInput::AttrInputType::LITERAL;
+
+ if (is_lang_item)
+ {
+ auto &literal
+ = static_cast<AST::AttrInputLiteral &> (attr.get_attr_input ());
+ const auto &lang_item_type_str = literal.get_literal ().as_string ();
+
+ return LangItem::Parse (lang_item_type_str);
+ }
+ }
+
+ return tl::nullopt;
+}
+
+template <typename T>
+void
+CollectLangItems::maybe_add_lang_item (const T &item)
+{
+ if (auto lang_item = get_lang_item_attr (item))
+ mappings.insert_lang_item_node (lang_item.value (), item.get_node_id ());
+}
+
+void
+CollectLangItems::visit (AST::Trait &item)
+{
+ maybe_add_lang_item (item);
+
+ DefaultASTVisitor::visit (item);
+}
+
+void
+CollectLangItems::visit (AST::TraitItemType &item)
+{
+ maybe_add_lang_item (item);
+
+ DefaultASTVisitor::visit (item);
+}
+
+} // namespace AST
+} // namespace Rust
diff --git a/gcc/rust/ast/rust-collect-lang-items.h b/gcc/rust/ast/rust-collect-lang-items.h
new file mode 100644
index 00000000000..552648f04ed
--- /dev/null
+++ b/gcc/rust/ast/rust-collect-lang-items.h
@@ -0,0 +1,58 @@
+// 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
+// <http://www.gnu.org/licenses/>.
+
+#ifndef RUST_COLLECT_LANG_ITEMS_H
+#define RUST_COLLECT_LANG_ITEMS_H
+
+#include "rust-ast-visitor.h"
+#include "rust-ast.h"
+#include "rust-hir-map.h"
+#include "rust-item.h"
+
+namespace Rust {
+namespace AST {
+
+// This class collects lang items ahead of lowering, as they are now needed for
+// some parts of name resolution
+class CollectLangItems : public DefaultASTVisitor
+{
+public:
+ CollectLangItems () : mappings (Analysis::Mappings::get ()){};
+
+ void go (AST::Crate &crate) { DefaultASTVisitor::visit (crate); }
+
+ Analysis::Mappings &mappings;
+
+ // We must implement visitors for all constructs that could be lang items.
+ // Lang items can be traits, but also enums, and even enum variants.
+ //
+ // https://github.com/rust-lang/rust/blob/master/compiler/rustc_hir/src/lang_items.rs
+
+ using DefaultASTVisitor::visit;
+
+ void visit (AST::Trait &item) override;
+ void visit (AST::TraitItemType &item) override;
+
+private:
+ template <typename T> void maybe_add_lang_item (const T &item);
+};
+
+} // namespace AST
+} // namespace Rust
+
+#endif // ! RUST_COLLECT_LANG_ITEMS_H
diff --git a/gcc/rust/rust-session-manager.cc b/gcc/rust/rust-session-manager.cc
index 11ff25062d0..c0b4796c4e9 100644
--- a/gcc/rust/rust-session-manager.cc
+++ b/gcc/rust/rust-session-manager.cc
@@ -17,6 +17,7 @@
// <http://www.gnu.org/licenses/>.
#include "rust-session-manager.h"
+#include "rust-collect-lang-items.h"
#include "rust-diagnostics.h"
#include "rust-hir-pattern-analysis.h"
#include "rust-immutable-name-resolution-context.h"
@@ -600,6 +601,8 @@ Session::compile_crate (const char *filename)
if (last_step == CompileOptions::CompileStep::Expansion)
return;
+ AST::CollectLangItems ().go (parsed_crate);
+
auto name_resolution_ctx = Resolver2_0::NameResolutionContext ();
// expansion pipeline stage
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 067/146] gccrs: attributes: Add class for sharing methods on attributes.
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (65 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 066/146] gccrs: lang-items: Add lang-items AST collector arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 068/146] gccrs: type-check: Remove unused capture in nr2.0 arthur.cohen
` (78 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
gcc/rust/ChangeLog:
* util/rust-attributes.h (class Attributes): New.
* util/rust-attributes.cc: Implement Attributes::is_known().
* ast/rust-collect-lang-items.cc (is_known_attribute): Remove.
(get_lang_item_attr): Call Attributes::is_known() instead.
* hir/rust-ast-lower-base.cc (ASTLoweringBase::handle_outer_attributes): Likewise.
(ASTLoweringBase::is_known_attribute): Remove.
---
gcc/rust/ast/rust-collect-lang-items.cc | 13 +------------
gcc/rust/hir/rust-ast-lower-base.cc | 10 ++--------
gcc/rust/util/rust-attributes.cc | 9 +++++++++
gcc/rust/util/rust-attributes.h | 6 ++++++
4 files changed, 18 insertions(+), 20 deletions(-)
diff --git a/gcc/rust/ast/rust-collect-lang-items.cc b/gcc/rust/ast/rust-collect-lang-items.cc
index 11a30aa37a7..308720ae69a 100644
--- a/gcc/rust/ast/rust-collect-lang-items.cc
+++ b/gcc/rust/ast/rust-collect-lang-items.cc
@@ -27,17 +27,6 @@
namespace Rust {
namespace AST {
-// FIXME: Before merging: De-duplicate with function in rust-ast-lower-base.cc
-bool
-is_known_attribute (const std::string &attribute_path)
-{
- const auto &lookup
- = Analysis::BuiltinAttributeMappings::get ()->lookup_builtin (
- attribute_path);
-
- return !lookup.is_error ();
-}
-
template <typename T>
tl::optional<LangItem::Kind>
get_lang_item_attr (const T &maybe_lang_item)
@@ -45,7 +34,7 @@ get_lang_item_attr (const T &maybe_lang_item)
for (const auto &attr : maybe_lang_item.get_outer_attrs ())
{
const auto &str_path = attr.get_path ().as_string ();
- if (!is_known_attribute (str_path))
+ if (!Analysis::Attributes::is_known (str_path))
{
rust_error_at (attr.get_locus (), "unknown attribute");
continue;
diff --git a/gcc/rust/hir/rust-ast-lower-base.cc b/gcc/rust/hir/rust-ast-lower-base.cc
index 18e6fff6f44..f6d7f0caf5b 100644
--- a/gcc/rust/hir/rust-ast-lower-base.cc
+++ b/gcc/rust/hir/rust-ast-lower-base.cc
@@ -25,6 +25,7 @@
#include "rust-diagnostics.h"
#include "rust-item.h"
#include "rust-system.h"
+#include "rust-attributes.h"
namespace Rust {
namespace HIR {
@@ -751,7 +752,7 @@ ASTLoweringBase::handle_outer_attributes (const ItemWrapper &item)
for (const auto &attr : item.get_outer_attrs ())
{
const auto &str_path = attr.get_path ().as_string ();
- if (!is_known_attribute (str_path))
+ if (!Analysis::Attributes::is_known (str_path))
{
rust_error_at (attr.get_locus (), "unknown attribute");
continue;
@@ -814,13 +815,6 @@ ASTLoweringBase::handle_lang_item_attribute (const ItemWrapper &item,
rust_error_at (attr.get_locus (), "unknown lang item");
}
-bool
-ASTLoweringBase::is_known_attribute (const std::string &attribute_path) const
-{
- const auto &lookup = attr_mappings->lookup_builtin (attribute_path);
- return !lookup.is_error ();
-}
-
bool
ASTLoweringBase::attribute_handled_in_another_pass (
const std::string &attribute_path) const
diff --git a/gcc/rust/util/rust-attributes.cc b/gcc/rust/util/rust-attributes.cc
index 958f7c35284..9f63234112c 100644
--- a/gcc/rust/util/rust-attributes.cc
+++ b/gcc/rust/util/rust-attributes.cc
@@ -29,6 +29,15 @@
namespace Rust {
namespace Analysis {
+bool
+Attributes::is_known (const std::string &attribute_path)
+{
+ const auto &lookup
+ = BuiltinAttributeMappings::get ()->lookup_builtin (attribute_path);
+
+ return !lookup.is_error ();
+}
+
using Attrs = Values::Attributes;
// https://doc.rust-lang.org/stable/nightly-rustc/src/rustc_feature/builtin_attrs.rs.html#248
diff --git a/gcc/rust/util/rust-attributes.h b/gcc/rust/util/rust-attributes.h
index 1345168cdea..c928c8eb9d2 100644
--- a/gcc/rust/util/rust-attributes.h
+++ b/gcc/rust/util/rust-attributes.h
@@ -25,6 +25,12 @@
namespace Rust {
namespace Analysis {
+class Attributes
+{
+public:
+ static bool is_known (const std::string &attribute_path);
+};
+
enum CompilerPass
{
UNKNOWN,
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 068/146] gccrs: type-check: Remove unused capture in nr2.0
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (66 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 067/146] gccrs: attributes: Add class for sharing methods on attributes arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 069/146] gccrs: Fix ForeverStack::find_starting_point output parameter arthur.cohen
` (77 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-type.cc (TypeCheckType::resolve_root_path):
Remove unused capture in lambda.
---
gcc/rust/typecheck/rust-hir-type-check-type.cc | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.cc b/gcc/rust/typecheck/rust-hir-type-check-type.cc
index 89ede4e3013..e9859a71f83 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-type.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-type.cc
@@ -19,6 +19,7 @@
#include "rust-hir-type-check-type.h"
#include "options.h"
#include "optional.h"
+#include "rust-hir-map.h"
#include "rust-hir-trait-resolve.h"
#include "rust-hir-type-check-expr.h"
#include "rust-hir-path-probe.h"
@@ -394,11 +395,10 @@ TypeCheckType::resolve_root_path (HIR::TypePath &path, size_t *offset,
{
auto nr_ctx
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+
// assign the ref_node_id if we've found something
nr_ctx.lookup (path.get_mappings ().get_nodeid ())
- .map ([&ref_node_id, &path] (NodeId resolved) {
- ref_node_id = resolved;
- });
+ .map ([&ref_node_id] (NodeId resolved) { ref_node_id = resolved; });
}
else if (!resolver->lookup_resolved_name (ast_node_id, &ref_node_id))
resolver->lookup_resolved_type (ast_node_id, &ref_node_id);
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 069/146] gccrs: Fix ForeverStack::find_starting_point output parameter
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (67 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 068/146] gccrs: type-check: Remove unused capture in nr2.0 arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 070/146] gccrs: ast: Add LangItemPath class arthur.cohen
` (76 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Owen Avery
From: Owen Avery <powerboat9.gamer@gmail.com>
gcc/rust/ChangeLog:
* resolve/rust-forever-stack.h
(ForeverStack::find_starting_point): Use type
'std::reference_wrapper<Node> &' instead of 'Node &' for
parameter starting_point.
* resolve/rust-forever-stack.hxx
(ForeverStack::find_starting_point): Likewise.
(ForeverStack::resolve_path): Handle change to
ForeverStack::find_starting_point.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
---
gcc/rust/resolve/rust-forever-stack.h | 3 ++-
gcc/rust/resolve/rust-forever-stack.hxx | 13 +++++++------
2 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/gcc/rust/resolve/rust-forever-stack.h b/gcc/rust/resolve/rust-forever-stack.h
index c548eeae087..064d1ab2bb3 100644
--- a/gcc/rust/resolve/rust-forever-stack.h
+++ b/gcc/rust/resolve/rust-forever-stack.h
@@ -614,7 +614,8 @@ private:
template <typename S>
tl::optional<SegIterator<S>>
- find_starting_point (const std::vector<S> &segments, Node &starting_point);
+ find_starting_point (const std::vector<S> &segments,
+ std::reference_wrapper<Node> &starting_point);
template <typename S>
tl::optional<Node &> resolve_segments (Node &starting_point,
diff --git a/gcc/rust/resolve/rust-forever-stack.hxx b/gcc/rust/resolve/rust-forever-stack.hxx
index 58164a4d328..d3d78894671 100644
--- a/gcc/rust/resolve/rust-forever-stack.hxx
+++ b/gcc/rust/resolve/rust-forever-stack.hxx
@@ -374,8 +374,8 @@ check_leading_kw_at_start (const S &segment, bool condition)
template <Namespace N>
template <typename S>
tl::optional<typename std::vector<S>::const_iterator>
-ForeverStack<N>::find_starting_point (const std::vector<S> &segments,
- Node &starting_point)
+ForeverStack<N>::find_starting_point (
+ const std::vector<S> &segments, std::reference_wrapper<Node> &starting_point)
{
auto iterator = segments.begin ();
@@ -412,14 +412,15 @@ ForeverStack<N>::find_starting_point (const std::vector<S> &segments,
}
if (seg.is_super_path_seg ())
{
- if (starting_point.is_root ())
+ if (starting_point.get ().is_root ())
{
rust_error_at (seg.get_locus (), ErrorCode::E0433,
"too many leading %<super%> keywords");
return tl::nullopt;
}
- starting_point = find_closest_module (starting_point.parent.value ());
+ starting_point
+ = find_closest_module (starting_point.get ().parent.value ());
continue;
}
@@ -494,12 +495,12 @@ ForeverStack<N>::resolve_path (const std::vector<S> &segments)
if (segments.size () == 1)
return get (segments.back ().as_string ());
- auto starting_point = cursor ();
+ std::reference_wrapper<Node> starting_point = cursor ();
return find_starting_point (segments, starting_point)
.and_then ([this, &segments, &starting_point] (
typename std::vector<S>::const_iterator iterator) {
- return resolve_segments (starting_point, segments, iterator);
+ return resolve_segments (starting_point.get (), segments, iterator);
})
.and_then ([&segments] (Node final_node) {
return final_node.rib.get (segments.back ().as_string ());
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 070/146] gccrs: ast: Add LangItemPath class
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (68 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 069/146] gccrs: Fix ForeverStack::find_starting_point output parameter arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 071/146] gccrs: derive(Copy): Use new LangItemPath arthur.cohen
` (75 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
This commit adds a new kind of Path, changes the base Path class and turns TypePath
into a child of the base Path class.
gcc/rust/ChangeLog:
* ast/rust-path.h (class LangItemPath): New.
(class TypePath): Adapt to accomodate LangItemPath.
* ast/rust-ast.cc (TraitImpl::as_string): Use new checks for lang items.
(QualifiedPathType::as_string): Likewise.
(FormatArgs::set_outer_attrs): Likewise.
* ast/rust-item.h (class TraitImpl): Likewise.
---
gcc/rust/ast/rust-ast.cc | 4 +--
gcc/rust/ast/rust-item.h | 28 +++++++++++----
gcc/rust/ast/rust-path.h | 73 ++++++++++++++++++++++++++--------------
3 files changed, 71 insertions(+), 34 deletions(-)
diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc
index 1d52352daaa..f1298d0f3e9 100644
--- a/gcc/rust/ast/rust-ast.cc
+++ b/gcc/rust/ast/rust-ast.cc
@@ -1299,7 +1299,7 @@ TraitImpl::as_string () const
else
str += "false";
- str += "\n TypePath (to trait): " + trait_path.as_string ();
+ str += "\n TypePath (to trait): " + trait_path->as_string ();
str += "\n Type (struct to impl on): " + trait_type->as_string ();
@@ -1561,7 +1561,7 @@ QualifiedPathType::as_string () const
str += type_to_invoke_on->as_string ();
if (has_as_clause ())
- str += " as " + trait_path.as_string ();
+ str += " as " + trait_path->as_string ();
return str + ">";
}
diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h
index 6611707a9a6..a6276a72d8d 100644
--- a/gcc/rust/ast/rust-item.h
+++ b/gcc/rust/ast/rust-item.h
@@ -3172,7 +3172,7 @@ class TraitImpl : public Impl
{
bool has_unsafe;
bool has_exclam;
- TypePath trait_path;
+ std::unique_ptr<Path> trait_path;
// bool has_impl_items;
std::vector<std::unique_ptr<AssociatedItem>> impl_items;
@@ -3184,7 +3184,7 @@ public:
bool has_impl_items () const { return !impl_items.empty (); }
// Mega-constructor
- TraitImpl (TypePath trait_path, bool is_unsafe, bool has_exclam,
+ TraitImpl (std::unique_ptr<Path> trait_path, bool is_unsafe, bool has_exclam,
std::vector<std::unique_ptr<AssociatedItem>> impl_items,
std::vector<std::unique_ptr<GenericParam>> generic_params,
std::unique_ptr<Type> trait_type, WhereClause where_clause,
@@ -3197,10 +3197,26 @@ public:
trait_path (std::move (trait_path)), impl_items (std::move (impl_items))
{}
+ // Helper constructor with a typepath
+ TraitImpl (TypePath trait_path, bool is_unsafe, bool has_exclam,
+ std::vector<std::unique_ptr<AssociatedItem>> impl_items,
+ std::vector<std::unique_ptr<GenericParam>> generic_params,
+ std::unique_ptr<Type> trait_type, WhereClause where_clause,
+ Visibility vis, std::vector<Attribute> inner_attrs,
+ std::vector<Attribute> outer_attrs, location_t locus)
+ : Impl (std::move (generic_params), std::move (trait_type),
+ std::move (where_clause), std::move (vis), std::move (inner_attrs),
+ std::move (outer_attrs), locus),
+ has_unsafe (is_unsafe), has_exclam (has_exclam),
+ trait_path (std::unique_ptr<TypePath> (new TypePath (trait_path))),
+ impl_items (std::move (impl_items))
+ {}
+
// Copy constructor with vector clone
TraitImpl (TraitImpl const &other)
: Impl (other), has_unsafe (other.has_unsafe),
- has_exclam (other.has_exclam), trait_path (other.trait_path)
+ has_exclam (other.has_exclam),
+ trait_path (other.trait_path->clone_path ())
{
impl_items.reserve (other.impl_items.size ());
for (const auto &e : other.impl_items)
@@ -3211,7 +3227,7 @@ public:
TraitImpl &operator= (TraitImpl const &other)
{
Impl::operator= (other);
- trait_path = other.trait_path;
+ trait_path = other.trait_path->clone_path ();
has_unsafe = other.has_unsafe;
has_exclam = other.has_exclam;
@@ -3242,10 +3258,10 @@ public:
}
// TODO: is this better? Or is a "vis_block" better?
- TypePath &get_trait_path ()
+ Path &get_trait_path ()
{
// TODO: assert that trait path is not empty?
- return trait_path;
+ return *trait_path;
}
protected:
diff --git a/gcc/rust/ast/rust-path.h b/gcc/rust/ast/rust-path.h
index 2cad3955494..bece60f95ed 100644
--- a/gcc/rust/ast/rust-path.h
+++ b/gcc/rust/ast/rust-path.h
@@ -589,6 +589,7 @@ public:
{
LangItem,
Regular,
+ Type,
};
virtual Kind get_path_kind () const = 0;
@@ -598,8 +599,8 @@ public:
return Pattern::Kind::Path;
}
- location_t get_locus () const override final { return locus; }
- NodeId get_node_id () const override final { return node_id; }
+ location_t get_locus () const override { return locus; }
+ NodeId get_node_id () const override { return node_id; }
std::unique_ptr<Path> clone_path ()
{
@@ -661,11 +662,12 @@ public:
class LangItemPath : public Path
{
NodeId lang_item;
- // TODO: Add LangItemKind or w/ever here as well
- // TODO: This constructor is wrong
- explicit LangItemPath (NodeId lang_item, location_t locus)
- : Path (locus, lang_item), lang_item (lang_item)
+ LangItem::Kind kind;
+
+public:
+ explicit LangItemPath (LangItem::Kind kind, location_t locus)
+ : Path (locus, Analysis::Mappings::get ().get_next_node_id ()), kind (kind)
{}
Path::Kind get_path_kind () const override { return Path::Kind::LangItem; }
@@ -674,10 +676,12 @@ class LangItemPath : public Path
Path *clone_path_impl () const override
{
- return new LangItemPath (lang_item, locus);
+ return new LangItemPath (kind, locus);
}
std::string as_string () const override;
+
+ LangItem::Kind get_lang_item_kind () { return kind; }
};
/* AST node representing a path-in-expression pattern (path that allows
@@ -1198,13 +1202,16 @@ public:
};
// Path used inside types
-class TypePath : public TypeNoBounds
+class TypePath : public TypeNoBounds, public Path
{
bool has_opening_scope_resolution;
std::vector<std::unique_ptr<TypePathSegment> > segments;
- location_t locus;
protected:
+ Kind get_path_kind () const override { return Kind::Type; }
+
+ Path *clone_path_impl () const override { return new TypePath (*this); }
+
/* Use covariance to implement clone function as returning this object
* rather than base */
TypePath *clone_type_no_bounds_impl () const override
@@ -1227,23 +1234,23 @@ public:
static TypePath create_error ()
{
return TypePath (std::vector<std::unique_ptr<TypePathSegment> > (),
- UNDEF_LOCATION);
+ UNKNOWN_LOCATION);
}
// Constructor
TypePath (std::vector<std::unique_ptr<TypePathSegment> > segments,
location_t locus, bool has_opening_scope_resolution = false)
: TypeNoBounds (),
+ Path (locus, Analysis::Mappings::get ().get_next_node_id ()),
has_opening_scope_resolution (has_opening_scope_resolution),
- segments (std::move (segments)), locus (locus)
+ segments (std::move (segments))
{}
// Copy constructor with vector clone
TypePath (TypePath const &other)
- : has_opening_scope_resolution (other.has_opening_scope_resolution),
- locus (other.locus)
+ : Path (other.locus, other.Path::get_node_id ()),
+ has_opening_scope_resolution (other.has_opening_scope_resolution)
{
- node_id = other.node_id;
segments.reserve (other.segments.size ());
for (const auto &e : other.segments)
segments.push_back (e->clone_type_path_segment ());
@@ -1252,9 +1259,7 @@ public:
// Overloaded assignment operator with clone
TypePath &operator= (TypePath const &other)
{
- node_id = other.node_id;
has_opening_scope_resolution = other.has_opening_scope_resolution;
- locus = other.locus;
segments.reserve (other.segments.size ());
for (const auto &e : other.segments)
@@ -1276,8 +1281,6 @@ public:
// Creates a trait bound with a clone of this type path as its only element.
TraitBound *to_trait_bound (bool in_parens) const override;
- location_t get_locus () const override final { return locus; }
-
void accept_vis (ASTVisitor &vis) override;
// TODO: this seems kinda dodgy
@@ -1291,13 +1294,27 @@ public:
}
size_t get_num_segments () const { return segments.size (); }
+ location_t get_locus () const override { return Path::get_locus (); }
+
+ // TypePath is both a Type and a Path, which is really annoying for a few
+ // methods. We need to override them and manually call either of them, which
+ // sucks. Oh well.
+
+ void mark_for_strip () override { TypeNoBounds::mark_for_strip (); }
+
+ bool is_marked_for_strip () const override
+ {
+ return TypeNoBounds::is_marked_for_strip ();
+ }
+
+ NodeId get_node_id () const override { return TypeNoBounds::get_node_id (); }
};
struct QualifiedPathType
{
private:
std::unique_ptr<Type> type_to_invoke_on;
- TypePath trait_path;
+ std::unique_ptr<Path> trait_path;
location_t locus;
NodeId node_id;
@@ -1307,13 +1324,13 @@ public:
location_t locus = UNDEF_LOCATION,
TypePath trait_path = TypePath::create_error ())
: type_to_invoke_on (std::move (invoke_on_type)),
- trait_path (std::move (trait_path)), locus (locus),
- node_id (Analysis::Mappings::get ().get_next_node_id ())
+ trait_path (std::unique_ptr<TypePath> (new TypePath (trait_path))),
+ locus (locus), node_id (Analysis::Mappings::get ().get_next_node_id ())
{}
// Copy constructor uses custom deep copy for Type to preserve polymorphism
QualifiedPathType (QualifiedPathType const &other)
- : trait_path (other.trait_path), locus (other.locus)
+ : trait_path (other.trait_path->clone_path ()), locus (other.locus)
{
node_id = other.node_id;
// guard to prevent null dereference
@@ -1328,7 +1345,7 @@ public:
QualifiedPathType &operator= (QualifiedPathType const &other)
{
node_id = other.node_id;
- trait_path = other.trait_path;
+ trait_path = other.trait_path->clone_path ();
locus = other.locus;
// guard to prevent null dereference
@@ -1345,7 +1362,11 @@ public:
QualifiedPathType &operator= (QualifiedPathType &&other) = default;
// Returns whether the qualified path type has a rebind as clause.
- bool has_as_clause () const { return !trait_path.is_error (); }
+ bool has_as_clause () const
+ {
+ rust_assert (trait_path->get_path_kind () == Path::Kind::Type);
+ return !static_cast<TypePath &> (*trait_path).is_error ();
+ }
// Returns whether the qualified path type is in an error state.
bool is_error () const { return type_to_invoke_on == nullptr; }
@@ -1374,10 +1395,10 @@ public:
}
// TODO: is this better? Or is a "vis_pattern" better?
- TypePath &get_as_type_path ()
+ Path &get_as_type_path ()
{
rust_assert (has_as_clause ());
- return trait_path;
+ return *trait_path;
}
NodeId get_node_id () const { return node_id; }
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 071/146] gccrs: derive(Copy): Use new LangItemPath
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (69 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 070/146] gccrs: ast: Add LangItemPath class arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 072/146] gccrs: hir: Start adapting visitors to accept multiple kinds of Paths arthur.cohen
` (74 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
gcc/rust/ChangeLog:
* expand/rust-derive-copy.cc: Use new LangItemPath for derive(Copy).
---
gcc/rust/expand/rust-derive-copy.cc | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/gcc/rust/expand/rust-derive-copy.cc b/gcc/rust/expand/rust-derive-copy.cc
index 1de72900d04..02817250db1 100644
--- a/gcc/rust/expand/rust-derive-copy.cc
+++ b/gcc/rust/expand/rust-derive-copy.cc
@@ -18,6 +18,8 @@
#include "rust-derive-copy.h"
#include "rust-ast-full.h"
+#include "rust-mapping-common.h"
+#include "rust-path.h"
namespace Rust {
namespace AST {
@@ -44,7 +46,7 @@ DeriveCopy::copy_impl (
// `$crate::core::marker::Copy` instead
auto segments = std::vector<std::unique_ptr<TypePathSegment>> ();
segments.emplace_back (builder.type_path_segment ("Copy"));
- auto copy = TypePath (std::move (segments), loc);
+ auto copy = Rust::make_unique<LangItemPath> (LangItem::Kind::COPY, loc);
// we need to build up the generics for this impl block which will be just a
// clone of the types specified ones
@@ -116,7 +118,7 @@ DeriveCopy::copy_impl (
: builder.single_generic_type_path (name, generic_args_for_self);
return std::unique_ptr<Item> (
- new TraitImpl (copy, /* unsafe */ false,
+ new TraitImpl (std::move (copy), /* unsafe */ false,
/* exclam */ false, /* trait items */ {},
std::move (impl_generics), std::move (self_type_path),
WhereClause::create_empty (), Visibility::create_private (),
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 072/146] gccrs: hir: Start adapting visitors to accept multiple kinds of Paths
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (70 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 071/146] gccrs: derive(Copy): Use new LangItemPath arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 073/146] gccrs: nr1.0: Resolve lang item paths properly arthur.cohen
` (73 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
gcc/rust/ChangeLog:
* ast/rust-item.h: Add new method to specifically get a type-path.
* ast/rust-path.cc (LangItemPath::as_string): Implement properly.
* hir/rust-ast-lower-type.cc (ASTLowerTypePath::translate): Adapt
visitor to use the new LangItemPath.
* hir/rust-ast-lower-type.h: Likewise.
* resolve/rust-ast-resolve-item.cc (ResolveItem::visit): Likewise.
* resolve/rust-ast-resolve-type.h: Likewise.
---
gcc/rust/ast/rust-item.h | 7 ++++++
gcc/rust/ast/rust-path.cc | 3 +--
gcc/rust/hir/rust-ast-lower-type.cc | 9 ++++++++
gcc/rust/hir/rust-ast-lower-type.h | 1 +
gcc/rust/resolve/rust-ast-resolve-item.cc | 2 +-
gcc/rust/resolve/rust-ast-resolve-type.h | 28 +++++++++++++++++++++++
6 files changed, 47 insertions(+), 3 deletions(-)
diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h
index a6276a72d8d..dca4aab45c8 100644
--- a/gcc/rust/ast/rust-item.h
+++ b/gcc/rust/ast/rust-item.h
@@ -3264,6 +3264,13 @@ public:
return *trait_path;
}
+ Type &get_trait_path_type ()
+ {
+ rust_assert (trait_path->get_path_kind () == Path::Kind::Type);
+
+ return (AST::Type &) static_cast<AST::TypePath &> (*trait_path);
+ }
+
protected:
/* Use covariance to implement clone function as returning this object
* rather than base */
diff --git a/gcc/rust/ast/rust-path.cc b/gcc/rust/ast/rust-path.cc
index 06c98cdcc2d..94cf2bb1514 100644
--- a/gcc/rust/ast/rust-path.cc
+++ b/gcc/rust/ast/rust-path.cc
@@ -152,8 +152,7 @@ RegularPath::as_string () const
std::string
LangItemPath::as_string () const
{
- // FIXME: Handle #[lang] paths
- rust_unreachable ();
+ return "#[lang = \"" + LangItem::ToString (kind) + "\"]";
}
SimplePath
diff --git a/gcc/rust/hir/rust-ast-lower-type.cc b/gcc/rust/hir/rust-ast-lower-type.cc
index 58c93b9e25d..c09d60fafc6 100644
--- a/gcc/rust/hir/rust-ast-lower-type.cc
+++ b/gcc/rust/hir/rust-ast-lower-type.cc
@@ -19,10 +19,19 @@
#include "rust-ast-lower-type.h"
#include "optional.h"
#include "rust-attribute-values.h"
+#include "rust-path.h"
namespace Rust {
namespace HIR {
+HIR::TypePath *
+ASTLowerTypePath::translate (AST::Path &type)
+{
+ rust_assert (type.get_path_kind () == AST::Path::Kind::Type);
+
+ return ASTLowerTypePath::translate (static_cast<AST::TypePath &> (type));
+}
+
HIR::TypePath *
ASTLowerTypePath::translate (AST::TypePath &type)
{
diff --git a/gcc/rust/hir/rust-ast-lower-type.h b/gcc/rust/hir/rust-ast-lower-type.h
index 5bb9a7e5f7c..72c6b29d7dd 100644
--- a/gcc/rust/hir/rust-ast-lower-type.h
+++ b/gcc/rust/hir/rust-ast-lower-type.h
@@ -31,6 +31,7 @@ protected:
using Rust::HIR::ASTLoweringBase::visit;
public:
+ static HIR::TypePath *translate (AST::Path &type);
static HIR::TypePath *translate (AST::TypePath &type);
void visit (AST::TypePathSegmentFunction &segment) override;
diff --git a/gcc/rust/resolve/rust-ast-resolve-item.cc b/gcc/rust/resolve/rust-ast-resolve-item.cc
index 245523ae5aa..a330541b682 100644
--- a/gcc/rust/resolve/rust-ast-resolve-item.cc
+++ b/gcc/rust/resolve/rust-ast-resolve-item.cc
@@ -680,7 +680,7 @@ ResolveItem::visit (AST::TraitImpl &impl_block)
// setup paths
CanonicalPath canonical_trait_type = CanonicalPath::create_empty ();
- bool ok = ResolveTypeToCanonicalPath::go (impl_block.get_trait_path (),
+ bool ok = ResolveTypeToCanonicalPath::go (impl_block.get_trait_path_type (),
canonical_trait_type);
if (!ok)
{
diff --git a/gcc/rust/resolve/rust-ast-resolve-type.h b/gcc/rust/resolve/rust-ast-resolve-type.h
index 561948e85b8..ed055a1f04e 100644
--- a/gcc/rust/resolve/rust-ast-resolve-type.h
+++ b/gcc/rust/resolve/rust-ast-resolve-type.h
@@ -21,6 +21,8 @@
#include "rust-ast-resolve-base.h"
#include "rust-ast-resolve-expr.h"
+#include "rust-hir-map.h"
+#include "rust-path.h"
namespace Rust {
namespace Resolver {
@@ -56,6 +58,32 @@ class ResolveType : public ResolverBase
using Rust::Resolver::ResolverBase::visit;
public:
+ static NodeId go (AST::TypePath &type_path)
+ {
+ return ResolveType::go ((AST::Type &) type_path);
+ }
+
+ static NodeId go (AST::Path &type_path)
+ {
+ if (type_path.get_path_kind () == AST::Path::Kind::LangItem)
+ {
+ auto &type = static_cast<AST::LangItemPath &> (type_path);
+
+ Analysis::Mappings::get_lang_item (type);
+
+ type.get_node_id ();
+ }
+
+ rust_assert (type_path.get_path_kind () == AST::Path::Kind::Type);
+
+ // We have to do this dance to first downcast to a typepath, and then upcast
+ // to a Type. The altnernative is to split `go` into `go` and `go_inner` or
+ // something, but eventually this will need to change as we'll need
+ // `ResolveType::` to resolve other kinds of `Path`s as well.
+ return ResolveType::go (
+ (AST::Type &) static_cast<AST::TypePath &> (type_path));
+ }
+
static NodeId go (AST::Type &type)
{
ResolveType resolver;
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 073/146] gccrs: nr1.0: Resolve lang item paths properly.
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (71 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 072/146] gccrs: hir: Start adapting visitors to accept multiple kinds of Paths arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 074/146] gccrs: hir: Lower lang-item paths arthur.cohen
` (72 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
gcc/rust/ChangeLog:
* resolve/rust-ast-resolve-item.cc (ResolveItem::visit): Adapt resolver
to lang item paths.
* resolve/rust-ast-resolve-type.h: Likewise.
---
gcc/rust/resolve/rust-ast-resolve-item.cc | 30 +++++++++++++++++------
gcc/rust/resolve/rust-ast-resolve-type.h | 11 +++++++--
2 files changed, 32 insertions(+), 9 deletions(-)
diff --git a/gcc/rust/resolve/rust-ast-resolve-item.cc b/gcc/rust/resolve/rust-ast-resolve-item.cc
index a330541b682..33b4fc9b979 100644
--- a/gcc/rust/resolve/rust-ast-resolve-item.cc
+++ b/gcc/rust/resolve/rust-ast-resolve-item.cc
@@ -678,16 +678,32 @@ ResolveItem::visit (AST::TraitImpl &impl_block)
return;
}
+ bool ok = true;
+
// setup paths
CanonicalPath canonical_trait_type = CanonicalPath::create_empty ();
- bool ok = ResolveTypeToCanonicalPath::go (impl_block.get_trait_path_type (),
- canonical_trait_type);
- if (!ok)
+ if (impl_block.get_trait_path ().get_path_kind ()
+ == AST::Path::Kind::LangItem)
{
- resolver->get_name_scope ().pop ();
- resolver->get_type_scope ().pop ();
- resolver->get_label_scope ().pop ();
- return;
+ auto &lang_item
+ = static_cast<AST::LangItemPath &> (impl_block.get_trait_path ());
+
+ canonical_trait_type
+ = CanonicalPath::new_seg (lang_item.get_node_id (),
+ LangItem::ToString (
+ lang_item.get_lang_item_kind ()));
+ }
+ else
+ {
+ ok = ResolveTypeToCanonicalPath::go (impl_block.get_trait_path_type (),
+ canonical_trait_type);
+ if (!ok)
+ {
+ resolver->get_name_scope ().pop ();
+ resolver->get_type_scope ().pop ();
+ resolver->get_label_scope ().pop ();
+ return;
+ }
}
rust_debug ("AST::TraitImpl resolve trait type: {%s}",
diff --git a/gcc/rust/resolve/rust-ast-resolve-type.h b/gcc/rust/resolve/rust-ast-resolve-type.h
index ed055a1f04e..7c3831a2829 100644
--- a/gcc/rust/resolve/rust-ast-resolve-type.h
+++ b/gcc/rust/resolve/rust-ast-resolve-type.h
@@ -21,8 +21,10 @@
#include "rust-ast-resolve-base.h"
#include "rust-ast-resolve-expr.h"
+#include "rust-diagnostics.h"
#include "rust-hir-map.h"
#include "rust-path.h"
+#include "util/rust-hir-map.h"
namespace Rust {
namespace Resolver {
@@ -69,9 +71,14 @@ public:
{
auto &type = static_cast<AST::LangItemPath &> (type_path);
- Analysis::Mappings::get_lang_item (type);
+ rust_debug ("[ARTHUR]: lang item kind: %s",
+ LangItem::ToString (type.get_lang_item_kind ()).c_str ());
- type.get_node_id ();
+ auto lang_item = Analysis::Mappings::get ()
+ .lookup_lang_item_node (type.get_lang_item_kind ())
+ .value ();
+
+ return lang_item;
}
rust_assert (type_path.get_path_kind () == AST::Path::Kind::Type);
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 074/146] gccrs: hir: Lower lang-item paths
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (72 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 073/146] gccrs: nr1.0: Resolve lang item paths properly arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 075/146] gccrs: nr2.0: Resolve lang item paths properly arthur.cohen
` (71 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
gcc/rust/ChangeLog:
* hir/rust-ast-lower-type.cc (ASTLowerTypePath::translate): Adapt to
handle lang item paths.
(ASTLowerTypePath::visit): Likewise.
(ASTLowerTypePath::translate_type_path): New.
(ASTLowerTypePath::translate_lang_item_type_path): New.
* hir/rust-ast-lower-type.h: Adapt to handle lang item paths.
* resolve/rust-ast-resolve-type.h: Likewise.
---
gcc/rust/hir/rust-ast-lower-type.cc | 45 ++++++++++++++++++------
gcc/rust/hir/rust-ast-lower-type.h | 6 +++-
gcc/rust/resolve/rust-ast-resolve-type.h | 6 ++--
3 files changed, 43 insertions(+), 14 deletions(-)
diff --git a/gcc/rust/hir/rust-ast-lower-type.cc b/gcc/rust/hir/rust-ast-lower-type.cc
index c09d60fafc6..df06e48b801 100644
--- a/gcc/rust/hir/rust-ast-lower-type.cc
+++ b/gcc/rust/hir/rust-ast-lower-type.cc
@@ -17,9 +17,10 @@
// <http://www.gnu.org/licenses/>.
#include "rust-ast-lower-type.h"
-#include "optional.h"
-#include "rust-attribute-values.h"
+#include "rust-hir-map.h"
+#include "rust-hir-path.h"
#include "rust-path.h"
+#include "rust-pattern.h"
namespace Rust {
namespace HIR {
@@ -27,16 +28,20 @@ namespace HIR {
HIR::TypePath *
ASTLowerTypePath::translate (AST::Path &type)
{
- rust_assert (type.get_path_kind () == AST::Path::Kind::Type);
+ ASTLowerTypePath resolver;
- return ASTLowerTypePath::translate (static_cast<AST::TypePath &> (type));
-}
+ switch (type.get_path_kind ())
+ {
+ case AST::Path::Kind::LangItem:
+ resolver.visit (static_cast<AST::LangItemPath &> (type));
+ break;
+ case AST::Path::Kind::Type:
+ resolver.visit (static_cast<AST::TypePath &> (type));
+ break;
+ default:
+ rust_unreachable ();
+ }
-HIR::TypePath *
-ASTLowerTypePath::translate (AST::TypePath &type)
-{
- ASTLowerTypePath resolver;
- type.accept_vis (resolver);
rust_assert (resolver.translated != nullptr);
return resolver.translated;
}
@@ -135,6 +140,26 @@ ASTLowerTypePath::visit (AST::TypePath &path)
path.has_opening_scope_resolution_op ());
}
+void
+ASTLowerTypePath::visit (AST::LangItemPath &path)
+{
+ auto crate_num = mappings.get_current_crate ();
+ auto hirid = mappings.get_next_hir_id (crate_num);
+
+ Analysis::NodeMapping mapping (crate_num, path.get_node_id (), hirid,
+ mappings.get_next_localdef_id (crate_num));
+
+ std::vector<std::unique_ptr<HIR::TypePathSegment>> translated_segments;
+ translated_segments.emplace_back (std::unique_ptr<HIR::TypePathSegment> (
+ new HIR::TypePathSegment (mapping,
+ LangItem::ToString (path.get_lang_item_kind ()),
+ false, path.get_locus ())));
+
+ translated
+ = new HIR::TypePath (std::move (mapping), std::move (translated_segments),
+ path.get_locus ());
+}
+
HIR::QualifiedPathInType *
ASTLowerQualifiedPathInType::translate (AST::QualifiedPathInType &type)
{
diff --git a/gcc/rust/hir/rust-ast-lower-type.h b/gcc/rust/hir/rust-ast-lower-type.h
index 72c6b29d7dd..0429e3fcf98 100644
--- a/gcc/rust/hir/rust-ast-lower-type.h
+++ b/gcc/rust/hir/rust-ast-lower-type.h
@@ -21,6 +21,7 @@
#include "rust-ast-lower-base.h"
#include "rust-ast-lower-expr.h"
+#include "rust-hir-path.h"
namespace Rust {
namespace HIR {
@@ -32,18 +33,21 @@ protected:
public:
static HIR::TypePath *translate (AST::Path &type);
- static HIR::TypePath *translate (AST::TypePath &type);
void visit (AST::TypePathSegmentFunction &segment) override;
void visit (AST::TypePathSegment &segment) override;
void visit (AST::TypePathSegmentGeneric &segment) override;
void visit (AST::TypePath &path) override;
+ void visit (AST::LangItemPath &path) override;
protected:
HIR::TypePathSegment *translated_segment;
private:
HIR::TypePath *translated;
+
+ static HIR::TypePath *translate_type_path (AST::TypePath &type);
+ static HIR::TypePath *translate_lang_item_type_path (AST::LangItemPath &type);
};
class ASTLowerQualifiedPathInType : public ASTLowerTypePath
diff --git a/gcc/rust/resolve/rust-ast-resolve-type.h b/gcc/rust/resolve/rust-ast-resolve-type.h
index 7c3831a2829..518c0d80b14 100644
--- a/gcc/rust/resolve/rust-ast-resolve-type.h
+++ b/gcc/rust/resolve/rust-ast-resolve-type.h
@@ -71,13 +71,13 @@ public:
{
auto &type = static_cast<AST::LangItemPath &> (type_path);
- rust_debug ("[ARTHUR]: lang item kind: %s",
- LangItem::ToString (type.get_lang_item_kind ()).c_str ());
-
auto lang_item = Analysis::Mappings::get ()
.lookup_lang_item_node (type.get_lang_item_kind ())
.value ();
+ auto resolver = Resolver::get ();
+ resolver->insert_resolved_type (type.get_node_id (), lang_item);
+
return lang_item;
}
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 075/146] gccrs: nr2.0: Resolve lang item paths properly.
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (73 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 074/146] gccrs: hir: Lower lang-item paths arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 076/146] gccrs: lang-item: Remove unused NodeId from LangItemPath arthur.cohen
` (70 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
gcc/rust/ChangeLog:
* resolve/rust-late-name-resolver-2.0.cc (Late::visit): New.
* resolve/rust-late-name-resolver-2.0.h: New.
---
.../resolve/rust-late-name-resolver-2.0.cc | 20 +++++++++++++++++++
.../resolve/rust-late-name-resolver-2.0.h | 1 +
2 files changed, 21 insertions(+)
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 3af8496288d..ac5f1c57546 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
@@ -18,6 +18,7 @@
#include "optional.h"
#include "rust-ast-full.h"
+#include "rust-diagnostics.h"
#include "rust-hir-map.h"
#include "rust-late-name-resolver-2.0.h"
#include "rust-default-resolver.h"
@@ -247,6 +248,25 @@ Late::visit (AST::PathInExpression &expr)
Definition (resolved->get_node_id ()));
}
+void
+Late::visit (AST::LangItemPath &type)
+{
+ auto &mappings = Rust::Analysis::Mappings::get ();
+ auto lang_item = mappings.lookup_lang_item_node (type.get_lang_item_kind ());
+
+ if (!lang_item)
+ {
+ rust_fatal_error (
+ type.get_locus (), "use of undeclared lang item %qs",
+ LangItem::ToString (type.get_lang_item_kind ()).c_str ());
+ return;
+ }
+
+ ctx.map_usage (Usage (type.get_node_id ()), Definition (lang_item.value ()));
+
+ DefaultResolver::visit (type);
+}
+
void
Late::visit (AST::TypePath &type)
{
diff --git a/gcc/rust/resolve/rust-late-name-resolver-2.0.h b/gcc/rust/resolve/rust-late-name-resolver-2.0.h
index 79572fbc4fa..6f1191662cc 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.h
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.h
@@ -46,6 +46,7 @@ public:
// resolutions
void visit (AST::IdentifierExpr &) override;
void visit (AST::PathInExpression &) override;
+ void visit (AST::LangItemPath &) override;
void visit (AST::TypePath &) override;
void visit (AST::StructExprStruct &) override;
void visit (AST::StructExprStructBase &) override;
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 076/146] gccrs: lang-item: Remove unused NodeId from LangItemPath
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (74 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 075/146] gccrs: nr2.0: Resolve lang item paths properly arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 077/146] gccrs: fix bad not expression in rust arthur.cohen
` (69 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
gcc/rust/ChangeLog:
* ast/rust-path.h: Adapt children of Path to fix some NodeId issues.
---
gcc/rust/ast/rust-path.h | 76 +++++++++++++++++++---------------------
1 file changed, 37 insertions(+), 39 deletions(-)
diff --git a/gcc/rust/ast/rust-path.h b/gcc/rust/ast/rust-path.h
index bece60f95ed..563ad52a9d6 100644
--- a/gcc/rust/ast/rust-path.h
+++ b/gcc/rust/ast/rust-path.h
@@ -599,9 +599,6 @@ public:
return Pattern::Kind::Path;
}
- location_t get_locus () const override { return locus; }
- NodeId get_node_id () const override { return node_id; }
-
std::unique_ptr<Path> clone_path ()
{
return std::unique_ptr<Path> (clone_path_impl ());
@@ -613,22 +610,19 @@ public:
}
protected:
- location_t locus;
- NodeId node_id;
-
- Path (location_t locus, NodeId node_id) : locus (locus), node_id (node_id) {}
-
virtual Path *clone_path_impl () const = 0;
};
class RegularPath : public Path
{
std::vector<PathExprSegment> segments;
+ NodeId node_id;
+ location_t locus;
public:
explicit RegularPath (std::vector<PathExprSegment> &&segments,
location_t locus, NodeId node_id)
- : Path (locus, node_id), segments (std::move (segments))
+ : segments (std::move (segments)), node_id (node_id), locus (locus)
{}
std::string as_string () const override;
@@ -657,17 +651,25 @@ public:
return new RegularPath (std::vector<PathExprSegment> (segments), locus,
node_id);
}
+
+ NodeId get_node_id () const override { return node_id; }
+ location_t get_locus () const override { return locus; }
};
class LangItemPath : public Path
{
- NodeId lang_item;
-
LangItem::Kind kind;
+ NodeId node_id;
+ location_t locus;
+
+ LangItemPath (LangItem::Kind kind, NodeId node_id, location_t locus)
+ : kind (kind), node_id (node_id), locus (locus)
+ {}
public:
explicit LangItemPath (LangItem::Kind kind, location_t locus)
- : Path (locus, Analysis::Mappings::get ().get_next_node_id ()), kind (kind)
+ : kind (kind), node_id (Analysis::Mappings::get ().get_next_node_id ()),
+ locus (locus)
{}
Path::Kind get_path_kind () const override { return Path::Kind::LangItem; }
@@ -676,12 +678,15 @@ public:
Path *clone_path_impl () const override
{
- return new LangItemPath (kind, locus);
+ return new LangItemPath (kind, node_id, locus);
}
std::string as_string () const override;
LangItem::Kind get_lang_item_kind () { return kind; }
+
+ NodeId get_node_id () const override { return node_id; }
+ location_t get_locus () const override { return locus; }
};
/* AST node representing a path-in-expression pattern (path that allows
@@ -739,11 +744,10 @@ public:
// Returns whether path in expression is in an error state.
bool is_error () const
{
- // FIXME: Cleanup
if (path->get_path_kind () == Path::Kind::Regular)
return !static_cast<RegularPath &> (*path).has_segments ();
- return false;
+ rust_unreachable ();
}
/* Converts PathInExpression to SimplePath if possible (i.e. no generic
@@ -822,7 +826,7 @@ public:
if (path->get_path_kind () == Path::Kind::Regular)
return static_cast<RegularPath &> (*path).get_segments ().size () == 1;
- return false;
+ rust_unreachable ();
}
Pattern::Kind get_pattern_kind () override { return Pattern::Kind::Path; }
@@ -1201,17 +1205,13 @@ public:
}
};
-// Path used inside types
class TypePath : public TypeNoBounds, public Path
{
bool has_opening_scope_resolution;
std::vector<std::unique_ptr<TypePathSegment> > segments;
+ location_t locus;
protected:
- Kind get_path_kind () const override { return Kind::Type; }
-
- Path *clone_path_impl () const override { return new TypePath (*this); }
-
/* Use covariance to implement clone function as returning this object
* rather than base */
TypePath *clone_type_no_bounds_impl () const override
@@ -1234,23 +1234,23 @@ public:
static TypePath create_error ()
{
return TypePath (std::vector<std::unique_ptr<TypePathSegment> > (),
- UNKNOWN_LOCATION);
+ UNDEF_LOCATION);
}
// Constructor
TypePath (std::vector<std::unique_ptr<TypePathSegment> > segments,
location_t locus, bool has_opening_scope_resolution = false)
: TypeNoBounds (),
- Path (locus, Analysis::Mappings::get ().get_next_node_id ()),
has_opening_scope_resolution (has_opening_scope_resolution),
- segments (std::move (segments))
+ segments (std::move (segments)), locus (locus)
{}
// Copy constructor with vector clone
TypePath (TypePath const &other)
- : Path (other.locus, other.Path::get_node_id ()),
- has_opening_scope_resolution (other.has_opening_scope_resolution)
+ : has_opening_scope_resolution (other.has_opening_scope_resolution),
+ locus (other.locus)
{
+ node_id = other.node_id;
segments.reserve (other.segments.size ());
for (const auto &e : other.segments)
segments.push_back (e->clone_type_path_segment ());
@@ -1259,7 +1259,9 @@ public:
// Overloaded assignment operator with clone
TypePath &operator= (TypePath const &other)
{
+ node_id = other.node_id;
has_opening_scope_resolution = other.has_opening_scope_resolution;
+ locus = other.locus;
segments.reserve (other.segments.size ());
for (const auto &e : other.segments)
@@ -1281,6 +1283,12 @@ public:
// Creates a trait bound with a clone of this type path as its only element.
TraitBound *to_trait_bound (bool in_parens) const override;
+ location_t get_locus () const override final { return locus; }
+ NodeId get_node_id () const override final { return node_id; }
+
+ void mark_for_strip () override {}
+ bool is_marked_for_strip () const override { return false; }
+
void accept_vis (ASTVisitor &vis) override;
// TODO: this seems kinda dodgy
@@ -1294,20 +1302,10 @@ public:
}
size_t get_num_segments () const { return segments.size (); }
- location_t get_locus () const override { return Path::get_locus (); }
-
- // TypePath is both a Type and a Path, which is really annoying for a few
- // methods. We need to override them and manually call either of them, which
- // sucks. Oh well.
- void mark_for_strip () override { TypeNoBounds::mark_for_strip (); }
+ Path::Kind get_path_kind () const override { return Path::Kind::Type; }
- bool is_marked_for_strip () const override
- {
- return TypeNoBounds::is_marked_for_strip ();
- }
-
- NodeId get_node_id () const override { return TypeNoBounds::get_node_id (); }
+ Path *clone_path_impl () const override { return new TypePath (*this); }
};
struct QualifiedPathType
@@ -1496,7 +1494,7 @@ public:
if (path->get_path_kind () == Path::Kind::Regular)
return static_cast<RegularPath &> (*path).get_segments ().size () == 1;
- return false;
+ rust_unreachable ();
}
protected:
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 077/146] gccrs: fix bad not expression in rust
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (75 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 076/146] gccrs: lang-item: Remove unused NodeId from LangItemPath arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 078/146] gccrs: implement the TuplePattern and use it for function patterns arthur.cohen
` (68 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Philip Herron
From: Philip Herron <herron.philip@googlemail.com>
Fixes Rust-GCC#3229
gcc/rust/ChangeLog:
* rust-gcc.cc (operator_to_tree_code): ! expressions are BIT_NOT_EXPR
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
---
gcc/rust/rust-gcc.cc | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/gcc/rust/rust-gcc.cc b/gcc/rust/rust-gcc.cc
index 7da5e2c5637..37d51e58c08 100644
--- a/gcc/rust/rust-gcc.cc
+++ b/gcc/rust/rust-gcc.cc
@@ -942,7 +942,7 @@ operator_to_tree_code (NegationOperator op)
case NegationOperator::NEGATE:
return NEGATE_EXPR;
case NegationOperator::NOT:
- return TRUTH_NOT_EXPR;
+ return BIT_NOT_EXPR;
default:
rust_unreachable ();
}
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 078/146] gccrs: implement the TuplePattern and use it for function patterns
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (76 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 077/146] gccrs: fix bad not expression in rust arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 079/146] gccrs: Made changes to AST::TraitImpl constructor for TypePath arthur.cohen
` (67 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Philip Herron
From: Philip Herron <herron.philip@googlemail.com>
In order to handle the tuple pattern of: fn test ((x _) : (i32, i32)) -> i32 { x }
we need to recognize that ABI wise this function still takes a tuple as the parameter
to this function its just how we can address the "pattern" of the tuple changes.
So reall if this was C it would look like:
void test (struct tuple_type __prameter)
{
return __parameter.0
}
The code here reuses our existing pattern code so that we generate these implicit
bindings of the paramter with a field access so any time x is referenced it's really
just emplacing __parameter.0 for the field access into the struct which is a tuple.
Fixes Rust-GCC#2847
gcc/rust/ChangeLog:
* backend/rust-compile-fnparam.cc (CompileFnParam::visit): compile tuple patterns
(CompileSelfParam::compile): update return type
(CompileFnParam::create_tmp_param_var): return Bvariable not tree to stop ICE
* backend/rust-compile-fnparam.h: update prototype
* backend/rust-compile-pattern.cc (CompilePatternBindings::visit): implement TuplePattern
* backend/rust-compile-pattern.h: update prototype
gcc/testsuite/ChangeLog:
* rust/compile/issue-2847.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
---
gcc/rust/backend/rust-compile-fnparam.cc | 31 ++++++---
gcc/rust/backend/rust-compile-fnparam.h | 4 +-
gcc/rust/backend/rust-compile-pattern.cc | 86 ++++++++++++++++++++++++
gcc/rust/backend/rust-compile-pattern.h | 2 +-
gcc/testsuite/rust/compile/issue-2847.rs | 8 +++
5 files changed, 117 insertions(+), 14 deletions(-)
create mode 100644 gcc/testsuite/rust/compile/issue-2847.rs
diff --git a/gcc/rust/backend/rust-compile-fnparam.cc b/gcc/rust/backend/rust-compile-fnparam.cc
index c00092d219e..b40065e110d 100644
--- a/gcc/rust/backend/rust-compile-fnparam.cc
+++ b/gcc/rust/backend/rust-compile-fnparam.cc
@@ -68,25 +68,36 @@ CompileFnParam::visit (HIR::WildcardPattern &pattern)
compiled_param = Backend::parameter_variable (fndecl, "_", decl_type, locus);
}
+void
+CompileFnParam::visit (HIR::TuplePattern &pattern)
+{
+ compiled_param = create_tmp_param_var (decl_type);
+ CompilePatternBindings::Compile (
+ pattern, Backend::var_expression (compiled_param, locus), ctx);
+}
+
void
CompileFnParam::visit (HIR::StructPattern &pattern)
{
- tree tmp_param_var = create_tmp_param_var (decl_type);
- CompilePatternBindings::Compile (pattern, tmp_param_var, ctx);
+ compiled_param = create_tmp_param_var (decl_type);
+ CompilePatternBindings::Compile (
+ pattern, Backend::var_expression (compiled_param, locus), ctx);
}
void
CompileFnParam::visit (HIR::TupleStructPattern &pattern)
{
- tree tmp_param_var = create_tmp_param_var (decl_type);
- CompilePatternBindings::Compile (pattern, tmp_param_var, ctx);
+ compiled_param = create_tmp_param_var (decl_type);
+ CompilePatternBindings::Compile (
+ pattern, Backend::var_expression (compiled_param, locus), ctx);
}
void
CompileFnParam::visit (HIR::ReferencePattern &pattern)
{
- tree tmp_param_var = create_tmp_param_var (decl_type);
- CompilePatternBindings::Compile (pattern, tmp_param_var, ctx);
+ compiled_param = create_tmp_param_var (decl_type);
+ CompilePatternBindings::Compile (
+ pattern, Backend::var_expression (compiled_param, locus), ctx);
}
Bvariable *
@@ -102,7 +113,7 @@ CompileSelfParam::compile (Context *ctx, tree fndecl, HIR::SelfParam &self,
return Backend::parameter_variable (fndecl, "self", decl_type, locus);
}
-tree
+Bvariable *
CompileFnParam::create_tmp_param_var (tree decl_type)
{
// generate the anon param
@@ -110,10 +121,8 @@ CompileFnParam::create_tmp_param_var (tree decl_type)
std::string cpp_str_identifier = std::string (IDENTIFIER_POINTER (tmp_ident));
decl_type = Backend::immutable_type (decl_type);
- compiled_param = Backend::parameter_variable (fndecl, cpp_str_identifier,
- decl_type, locus);
-
- return Backend::var_expression (compiled_param, locus);
+ return Backend::parameter_variable (fndecl, cpp_str_identifier, decl_type,
+ locus);
}
} // namespace Compile
diff --git a/gcc/rust/backend/rust-compile-fnparam.h b/gcc/rust/backend/rust-compile-fnparam.h
index 82a705fde7b..189216c9ba4 100644
--- a/gcc/rust/backend/rust-compile-fnparam.h
+++ b/gcc/rust/backend/rust-compile-fnparam.h
@@ -47,12 +47,12 @@ public:
void visit (HIR::QualifiedPathInExpression &) override {}
void visit (HIR::RangePattern &) override {}
void visit (HIR::SlicePattern &) override {}
- void visit (HIR::TuplePattern &) override {}
+ void visit (HIR::TuplePattern &) override;
private:
CompileFnParam (Context *ctx, tree fndecl, tree decl_type, location_t locus);
- tree create_tmp_param_var (tree decl_type);
+ Bvariable *create_tmp_param_var (tree decl_type);
tree fndecl;
tree decl_type;
diff --git a/gcc/rust/backend/rust-compile-pattern.cc b/gcc/rust/backend/rust-compile-pattern.cc
index d6161bd5e83..b2e7c351f95 100644
--- a/gcc/rust/backend/rust-compile-pattern.cc
+++ b/gcc/rust/backend/rust-compile-pattern.cc
@@ -613,6 +613,92 @@ CompilePatternBindings::visit (HIR::IdentifierPattern &pattern)
match_scrutinee_expr);
}
+void
+CompilePatternBindings::visit (HIR::TuplePattern &pattern)
+{
+ rust_assert (pattern.has_tuple_pattern_items ());
+
+ // lookup the type
+ TyTy::BaseType *ty = nullptr;
+ bool ok
+ = ctx->get_tyctx ()->lookup_type (pattern.get_mappings ().get_hirid (),
+ &ty);
+ rust_assert (ok);
+
+ switch (pattern.get_items ().get_item_type ())
+ {
+ case HIR::TuplePatternItems::ItemType::RANGED: {
+ size_t tuple_idx = 0;
+ auto &items
+ = static_cast<HIR::TuplePatternItemsRanged &> (pattern.get_items ());
+
+ auto &items_lower = items.get_lower_patterns ();
+ auto &items_upper = items.get_upper_patterns ();
+
+ for (auto &sub : items_lower)
+ {
+ TyTy::BaseType *ty_sub = nullptr;
+ HirId sub_id = sub->get_mappings ().get_hirid ();
+ bool ok = ctx->get_tyctx ()->lookup_type (sub_id, &ty_sub);
+ rust_assert (ok);
+
+ tree sub_init
+ = Backend::struct_field_expression (match_scrutinee_expr,
+ tuple_idx, sub->get_locus ());
+
+ CompilePatternBindings::Compile (*sub.get (), sub_init, ctx);
+ tuple_idx++;
+ }
+
+ rust_assert (ty->get_kind () == TyTy::TypeKind::TUPLE);
+ tuple_idx = static_cast<TyTy::TupleType &> (*ty).num_fields ()
+ - items_upper.size ();
+
+ for (auto &sub : items_upper)
+ {
+ TyTy::BaseType *ty_sub = nullptr;
+ HirId sub_id = sub->get_mappings ().get_hirid ();
+ bool ok = ctx->get_tyctx ()->lookup_type (sub_id, &ty_sub);
+ rust_assert (ok);
+
+ tree sub_init
+ = Backend::struct_field_expression (match_scrutinee_expr,
+ tuple_idx, sub->get_locus ());
+ CompilePatternBindings::Compile (*sub.get (), sub_init, ctx);
+ tuple_idx++;
+ }
+
+ return;
+ }
+ case HIR::TuplePatternItems::ItemType::MULTIPLE: {
+ size_t tuple_idx = 0;
+ auto &items = static_cast<HIR::TuplePatternItemsMultiple &> (
+ pattern.get_items ());
+
+ for (auto &sub : items.get_patterns ())
+ {
+ TyTy::BaseType *ty_sub = nullptr;
+ HirId sub_id = sub->get_mappings ().get_hirid ();
+ bool ok = ctx->get_tyctx ()->lookup_type (sub_id, &ty_sub);
+ rust_assert (ok);
+
+ tree sub_init
+ = Backend::struct_field_expression (match_scrutinee_expr,
+ tuple_idx, sub->get_locus ());
+ CompilePatternBindings::Compile (*sub.get (), sub_init, ctx);
+ tuple_idx++;
+ }
+
+ return;
+ }
+ default: {
+ rust_unreachable ();
+ }
+ }
+}
+
+//
+
void
CompilePatternLet::visit (HIR::IdentifierPattern &pattern)
{
diff --git a/gcc/rust/backend/rust-compile-pattern.h b/gcc/rust/backend/rust-compile-pattern.h
index 0b785c6ce8c..c7a62fcbc53 100644
--- a/gcc/rust/backend/rust-compile-pattern.h
+++ b/gcc/rust/backend/rust-compile-pattern.h
@@ -82,6 +82,7 @@ public:
void visit (HIR::TupleStructPattern &pattern) override;
void visit (HIR::ReferencePattern &pattern) override;
void visit (HIR::IdentifierPattern &) override;
+ void visit (HIR::TuplePattern &pattern) override;
// Empty visit for unused Pattern HIR nodes.
void visit (HIR::AltPattern &) override {}
@@ -90,7 +91,6 @@ public:
void visit (HIR::QualifiedPathInExpression &) override {}
void visit (HIR::RangePattern &) override {}
void visit (HIR::SlicePattern &) override {}
- void visit (HIR::TuplePattern &) override {}
void visit (HIR::WildcardPattern &) override {}
protected:
diff --git a/gcc/testsuite/rust/compile/issue-2847.rs b/gcc/testsuite/rust/compile/issue-2847.rs
new file mode 100644
index 00000000000..2bc556666c1
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-2847.rs
@@ -0,0 +1,8 @@
+pub fn myfun1((x, _): (i32, i32)) -> i32 {
+ x
+}
+
+pub fn myfun2() -> i32 {
+ let (x, _) = (1, 2);
+ x
+}
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 079/146] gccrs: Made changes to AST::TraitImpl constructor for TypePath
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (77 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 078/146] gccrs: implement the TuplePattern and use it for function patterns arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 080/146] gccrs: add ptr to int and int to ptr type cast rules arthur.cohen
` (66 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Sri Ganesh Thota
From: Sri Ganesh Thota <sriganeshthota12345@gmail.com>
gcc/rust/ChangeLog:
* ast/rust-item.h: I have changed helper constructor for typepath
to be a delegating constructor.
Signed-off-by: Sri Ganesh Thota <sriganeshthota12345@gmail.com>
---
gcc/rust/ast/rust-item.h | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h
index dca4aab45c8..6b77449eb8d 100644
--- a/gcc/rust/ast/rust-item.h
+++ b/gcc/rust/ast/rust-item.h
@@ -3197,19 +3197,18 @@ public:
trait_path (std::move (trait_path)), impl_items (std::move (impl_items))
{}
- // Helper constructor with a typepath
+ // Delegating constructor for TypePath
TraitImpl (TypePath trait_path, bool is_unsafe, bool has_exclam,
std::vector<std::unique_ptr<AssociatedItem>> impl_items,
std::vector<std::unique_ptr<GenericParam>> generic_params,
std::unique_ptr<Type> trait_type, WhereClause where_clause,
Visibility vis, std::vector<Attribute> inner_attrs,
std::vector<Attribute> outer_attrs, location_t locus)
- : Impl (std::move (generic_params), std::move (trait_type),
- std::move (where_clause), std::move (vis), std::move (inner_attrs),
- std::move (outer_attrs), locus),
- has_unsafe (is_unsafe), has_exclam (has_exclam),
- trait_path (std::unique_ptr<TypePath> (new TypePath (trait_path))),
- impl_items (std::move (impl_items))
+ : TraitImpl (std::unique_ptr<Path> (new TypePath (trait_path)), is_unsafe,
+ has_exclam, std::move (impl_items), std::move (generic_params),
+ std::move (trait_type), std::move (where_clause),
+ std::move (vis), std::move (inner_attrs),
+ std::move (outer_attrs), locus)
{}
// Copy constructor with vector clone
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 080/146] gccrs: add ptr to int and int to ptr type cast rules
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (78 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 079/146] gccrs: Made changes to AST::TraitImpl constructor for TypePath arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 081/146] gccrs: typecheck-path: Fix typo (reciever -> receiver) arthur.cohen
` (65 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Nobel
From: Nobel <nobel2073@gmail.com>
Added rules to allow type casting pointer as integer types (u*,i*)
and integer types to be casted as pointer.
gcc/rust/ChangeLog:
* typecheck/rust-casts.cc (TypeCastRules::cast_rules): Add rule.
gcc/testsuite/ChangeLog:
* rust/compile/ptr_int_cast.rs: New test.
Signed-off-by: Nobel Singh <nobel2073@gmail.com>
---
gcc/rust/typecheck/rust-casts.cc | 27 ++++++++++++++++++++--
gcc/testsuite/rust/compile/ptr_int_cast.rs | 18 +++++++++++++++
2 files changed, 43 insertions(+), 2 deletions(-)
create mode 100644 gcc/testsuite/rust/compile/ptr_int_cast.rs
diff --git a/gcc/rust/typecheck/rust-casts.cc b/gcc/rust/typecheck/rust-casts.cc
index cf4de4b3320..694cbaa5db6 100644
--- a/gcc/rust/typecheck/rust-casts.cc
+++ b/gcc/rust/typecheck/rust-casts.cc
@@ -210,6 +210,16 @@ TypeCastRules::cast_rules ()
}
break;
+ case TyTy::TypeKind::POINTER: {
+ // char can't be casted as a ptr
+ bool from_char
+ = from.get_ty ()->get_kind () == TyTy::TypeKind::CHAR;
+ if (!from_char)
+ return TypeCoercionRules::CoercionResult{{},
+ to.get_ty ()->clone ()};
+ }
+ break;
+
case TyTy::TypeKind::INFER:
case TyTy::TypeKind::USIZE:
case TyTy::TypeKind::ISIZE:
@@ -254,12 +264,25 @@ TypeCastRules::cast_rules ()
case TyTy::TypeKind::POINTER:
switch (to.get_ty ()->get_kind ())
{
+ case TyTy::TypeKind::USIZE:
+ case TyTy::TypeKind::ISIZE:
+ case TyTy::TypeKind::UINT:
+ case TyTy::TypeKind::INT: {
+ // refs should not cast to numeric type
+ bool from_ptr
+ = from.get_ty ()->get_kind () == TyTy::TypeKind::POINTER;
+ if (from_ptr)
+ {
+ return TypeCoercionRules::CoercionResult{
+ {}, to.get_ty ()->clone ()};
+ }
+ }
+ break;
+
case TyTy::TypeKind::REF:
case TyTy::TypeKind::POINTER:
return check_ptr_ptr_cast ();
- // FIXME can you cast a pointer to a integral type?
-
default:
return TypeCoercionRules::CoercionResult::get_error ();
}
diff --git a/gcc/testsuite/rust/compile/ptr_int_cast.rs b/gcc/testsuite/rust/compile/ptr_int_cast.rs
new file mode 100644
index 00000000000..3a2a5d563d6
--- /dev/null
+++ b/gcc/testsuite/rust/compile/ptr_int_cast.rs
@@ -0,0 +1,18 @@
+fn main(){
+ let foo = 1337;
+ let bar_ptr = &foo as *const i32;
+
+ let bar_ptr_usize = bar_ptr as usize;
+ let bar_ptr_isize = bar_ptr as isize;
+ let bar_ptr_u64 = bar_ptr as u64;
+ let bar_ptr_i64 = bar_ptr as i64;
+ let bar_ptr_i8 = bar_ptr as i8;
+ let bar_ptr_u8 = bar_ptr as u8;
+
+ let _ = bar_ptr_usize as *const i32;
+ let _ = bar_ptr_isize as *const i32;
+ let _ = bar_ptr_u64 as *const i32;
+ let _ = bar_ptr_i64 as *const i32;
+ let _ = bar_ptr_i8 as *const i32;
+ let _ = bar_ptr_u8 as *const i32;
+}
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 081/146] gccrs: typecheck-path: Fix typo (reciever -> receiver)
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (79 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 080/146] gccrs: add ptr to int and int to ptr type cast rules arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 082/146] gccrs: parser: Add testcases for multiline strings arthur.cohen
` (64 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
gcc/rust/ChangeLog:
* typecheck/rust-hir-path-probe.cc: Fix typos.
* typecheck/rust-hir-path-probe.h: Likewise.
* typecheck/rust-hir-type-check-path.cc: Likewise.
---
gcc/rust/typecheck/rust-hir-path-probe.cc | 4 ++--
gcc/rust/typecheck/rust-hir-path-probe.h | 2 +-
gcc/rust/typecheck/rust-hir-type-check-path.cc | 10 +++++-----
3 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/gcc/rust/typecheck/rust-hir-path-probe.cc b/gcc/rust/typecheck/rust-hir-path-probe.cc
index 2e9ad95dde3..1148b24b010 100644
--- a/gcc/rust/typecheck/rust-hir-path-probe.cc
+++ b/gcc/rust/typecheck/rust-hir-path-probe.cc
@@ -168,7 +168,7 @@ PathProbeType::Probe (const TyTy::BaseType *receiver,
if (!probe_bounds)
return probe.candidates;
- if (!probe.is_reciever_generic ())
+ if (!probe.is_receiver_generic ())
{
std::vector<std::pair<TraitReference *, HIR::ImplBlock *>> probed_bounds
= TypeBoundsProbe::Probe (receiver);
@@ -433,7 +433,7 @@ PathProbeType::union_bounds (
}
bool
-PathProbeType::is_reciever_generic () const
+PathProbeType::is_receiver_generic () const
{
const TyTy::BaseType *root = receiver->get_root ();
bool receiver_is_type_param = root->get_kind () == TyTy::TypeKind::PARAM;
diff --git a/gcc/rust/typecheck/rust-hir-path-probe.h b/gcc/rust/typecheck/rust-hir-path-probe.h
index 09a6492596d..59ffeb114e0 100644
--- a/gcc/rust/typecheck/rust-hir-path-probe.h
+++ b/gcc/rust/typecheck/rust-hir-path-probe.h
@@ -145,7 +145,7 @@ protected:
const std::vector<std::pair<const TraitReference *, HIR::ImplBlock *>> b)
const;
- bool is_reciever_generic () const;
+ bool is_receiver_generic () const;
const TyTy::BaseType *receiver;
const HIR::PathIdentSegment &search;
diff --git a/gcc/rust/typecheck/rust-hir-type-check-path.cc b/gcc/rust/typecheck/rust-hir-type-check-path.cc
index 4746e7d730d..4c7dec1dea3 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-path.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-path.cc
@@ -354,13 +354,13 @@ TypeCheckExpr::resolve_segments (NodeId root_resolved_node_id,
{
NodeId resolved_node_id = root_resolved_node_id;
TyTy::BaseType *prev_segment = tyseg;
- bool reciever_is_generic = prev_segment->get_kind () == TyTy::TypeKind::PARAM;
- bool reciever_is_dyn = prev_segment->get_kind () == TyTy::TypeKind::DYNAMIC;
+ bool receiver_is_generic = prev_segment->get_kind () == TyTy::TypeKind::PARAM;
+ bool receiver_is_dyn = prev_segment->get_kind () == TyTy::TypeKind::DYNAMIC;
for (size_t i = offset; i < segments.size (); i++)
{
HIR::PathExprSegment &seg = segments.at (i);
- bool probe_impls = !reciever_is_generic;
+ bool probe_impls = !receiver_is_generic;
// probe the path is done in two parts one where we search impls if no
// candidate is found then we search extensions from traits
@@ -435,7 +435,7 @@ TypeCheckExpr::resolve_segments (NodeId root_resolved_node_id,
}
}
- if (associated_impl_block != nullptr && !reciever_is_dyn)
+ if (associated_impl_block != nullptr && !receiver_is_dyn)
{
// associated types
HirId impl_block_id
@@ -492,7 +492,7 @@ TypeCheckExpr::resolve_segments (NodeId root_resolved_node_id,
if (tyseg->get_kind () == TyTy::TypeKind::ERROR)
return;
}
- else if (tyseg->needs_generic_substitutions () && !reciever_is_generic)
+ else if (tyseg->needs_generic_substitutions () && !receiver_is_generic)
{
location_t locus = seg.get_locus ();
tyseg = SubstMapper::InferSubst (tyseg, locus);
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 082/146] gccrs: parser: Add testcases for multiline strings
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (80 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 081/146] gccrs: typecheck-path: Fix typo (reciever -> receiver) arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 083/146] gccrs: resolve: Name resolve trait bounds properly arthur.cohen
` (63 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
Regression checks for Rust-GCC#1399
gcc/testsuite/ChangeLog:
* rust/compile/multiline-string.rs: New test.
* rust/execute/torture/multiline-string.rs: New test.
---
gcc/testsuite/rust/compile/multiline-string.rs | 14 ++++++++++++++
.../rust/execute/torture/multiline-string.rs | 15 +++++++++++++++
2 files changed, 29 insertions(+)
create mode 100644 gcc/testsuite/rust/compile/multiline-string.rs
create mode 100644 gcc/testsuite/rust/execute/torture/multiline-string.rs
diff --git a/gcc/testsuite/rust/compile/multiline-string.rs b/gcc/testsuite/rust/compile/multiline-string.rs
new file mode 100644
index 00000000000..fcd6fa812ed
--- /dev/null
+++ b/gcc/testsuite/rust/compile/multiline-string.rs
@@ -0,0 +1,14 @@
+fn main() {
+ let _a = "gcc
+
+ rs";
+
+ let _b = "rust
+
+ c
+ gcc
+
+
+
+ rs";
+}
diff --git a/gcc/testsuite/rust/execute/torture/multiline-string.rs b/gcc/testsuite/rust/execute/torture/multiline-string.rs
new file mode 100644
index 00000000000..4d22f991ad3
--- /dev/null
+++ b/gcc/testsuite/rust/execute/torture/multiline-string.rs
@@ -0,0 +1,15 @@
+// { dg-output "gcc\n\nrs\n" }
+
+extern "C" {
+ fn printf(fmt: *const i8, ...);
+}
+
+fn main() -> i32 {
+ let a = "gcc
+
+rs\0";
+
+ unsafe { printf("%s\n\0" as *const str as *const i8, a as *const str as *const i8); }
+
+ 0
+}
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 083/146] gccrs: resolve: Name resolve trait bounds properly
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (81 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 082/146] gccrs: parser: Add testcases for multiline strings arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 084/146] gccrs: typecheck: Add note about erorring out on additional trait bounds arthur.cohen
` (62 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
gcc/rust/ChangeLog:
* resolve/rust-ast-resolve-type.cc (ResolveTypeToCanonicalPath::visit): Resolve additional
trait bounds.
* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Error out properly on unresolved
type-path instead of crashing.
gcc/testsuite/ChangeLog:
* rust/compile/nr2/exclude: Exclude additional-trait-bounds2 for different error message.
* rust/compile/additional-trait-bounds1.rs: New test.
* rust/compile/additional-trait-bounds2.rs: New test.
* rust/compile/additional-trait-bounds2nr2.rs: New test.
---
gcc/rust/resolve/rust-ast-resolve-type.cc | 57 ++++++++++++++++++-
.../resolve/rust-late-name-resolver-2.0.cc | 3 +-
.../rust/compile/additional-trait-bounds1.rs | 10 ++++
.../rust/compile/additional-trait-bounds2.rs | 9 +++
.../compile/additional-trait-bounds2nr2.rs | 11 ++++
gcc/testsuite/rust/compile/nr2/exclude | 1 +
6 files changed, 87 insertions(+), 4 deletions(-)
create mode 100644 gcc/testsuite/rust/compile/additional-trait-bounds1.rs
create mode 100644 gcc/testsuite/rust/compile/additional-trait-bounds2.rs
create mode 100644 gcc/testsuite/rust/compile/additional-trait-bounds2nr2.rs
diff --git a/gcc/rust/resolve/rust-ast-resolve-type.cc b/gcc/rust/resolve/rust-ast-resolve-type.cc
index ec5e8a762a7..cb5a18d5d47 100644
--- a/gcc/rust/resolve/rust-ast-resolve-type.cc
+++ b/gcc/rust/resolve/rust-ast-resolve-type.cc
@@ -18,6 +18,8 @@
#include "rust-ast-resolve-type.h"
#include "rust-ast-resolve-expr.h"
+#include "rust-canonical-path.h"
+#include "rust-type.h"
namespace Rust {
namespace Resolver {
@@ -495,10 +497,59 @@ ResolveTypeToCanonicalPath::visit (AST::TraitObjectTypeOneBound &type)
}
void
-ResolveTypeToCanonicalPath::visit (AST::TraitObjectType &)
+ResolveTypeToCanonicalPath::visit (AST::TraitObjectType &type)
{
- // FIXME is this actually allowed? dyn A+B
- rust_unreachable ();
+ rust_assert (!type.get_type_param_bounds ().empty ());
+
+ auto &first_bound = type.get_type_param_bounds ().front ();
+
+ // Is it allowed or even possible to have a lifetime bound as a first bound?
+ if (first_bound->get_bound_type () == AST::TraitBound::LIFETIME)
+ rust_unreachable ();
+
+ auto &trait = static_cast<AST::TraitBound &> (*first_bound);
+
+ CanonicalPath path = CanonicalPath::create_empty ();
+ bool ok = ResolveTypeToCanonicalPath::go (trait.get_type_path (), path);
+
+ // right?
+ rust_assert (ok);
+
+ auto slice_path = "<dyn " + path.get ();
+
+ for (size_t idx = 1; idx < type.get_type_param_bounds ().size (); idx++)
+ {
+ auto &additional_bound = type.get_type_param_bounds ()[idx];
+
+ std::string str;
+
+ switch (additional_bound->get_bound_type ())
+ {
+ case AST::TypeParamBound::TRAIT: {
+ auto bound_path = CanonicalPath::create_empty ();
+
+ auto &bound_type_path
+ = static_cast<AST::TraitBound &> (*additional_bound)
+ .get_type_path ();
+ bool ok
+ = ResolveTypeToCanonicalPath::go (bound_type_path, bound_path);
+
+ if (!ok)
+ continue;
+
+ str = bound_path.get ();
+ break;
+ }
+ case AST::TypeParamBound::LIFETIME:
+ rust_unreachable ();
+ break;
+ }
+ slice_path += " + " + str;
+ }
+
+ slice_path += ">";
+
+ result = CanonicalPath::new_seg (type.get_node_id (), slice_path);
}
void
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 ac5f1c57546..40f067319b5 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
@@ -282,7 +282,8 @@ Late::visit (AST::TypePath &type)
ctx.map_usage (Usage (type.get_node_id ()),
Definition (resolved->get_node_id ()));
else
- rust_unreachable ();
+ rust_error_at (type.get_locus (), "could not resolve type path %qs",
+ str.c_str ());
DefaultResolver::visit (type);
}
diff --git a/gcc/testsuite/rust/compile/additional-trait-bounds1.rs b/gcc/testsuite/rust/compile/additional-trait-bounds1.rs
new file mode 100644
index 00000000000..449a72fe461
--- /dev/null
+++ b/gcc/testsuite/rust/compile/additional-trait-bounds1.rs
@@ -0,0 +1,10 @@
+#![feature(optin_builtin_traits)]
+
+pub unsafe auto trait Send {}
+#[lang = "sync"]
+pub unsafe auto trait Sync {}
+
+trait A {}
+
+impl dyn A + Send {}
+impl dyn A + Send + Sync {}
diff --git a/gcc/testsuite/rust/compile/additional-trait-bounds2.rs b/gcc/testsuite/rust/compile/additional-trait-bounds2.rs
new file mode 100644
index 00000000000..843228ae9a6
--- /dev/null
+++ b/gcc/testsuite/rust/compile/additional-trait-bounds2.rs
@@ -0,0 +1,9 @@
+#![feature(optin_builtin_traits)]
+
+pub unsafe auto trait Send {}
+#[lang = "sync"]
+pub unsafe auto trait Sync {}
+
+trait A {}
+
+impl dyn A + Send + Sync + NonExist {} // { dg-error "failed to resolve TypePath: NonExist in this scope" }
diff --git a/gcc/testsuite/rust/compile/additional-trait-bounds2nr2.rs b/gcc/testsuite/rust/compile/additional-trait-bounds2nr2.rs
new file mode 100644
index 00000000000..6764f6e8012
--- /dev/null
+++ b/gcc/testsuite/rust/compile/additional-trait-bounds2nr2.rs
@@ -0,0 +1,11 @@
+// { dg-additional-options "-frust-name-resolution-2.0" }
+
+#![feature(optin_builtin_traits)]
+
+pub unsafe auto trait Send {}
+#[lang = "sync"]
+pub unsafe auto trait Sync {}
+
+trait A {}
+
+impl dyn A + Send + Sync + NonExist {} // { dg-error "could not resolve type path .NonExist." }
diff --git a/gcc/testsuite/rust/compile/nr2/exclude b/gcc/testsuite/rust/compile/nr2/exclude
index 797e59a5c58..8bdcc8ac338 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -208,4 +208,5 @@ issue-2905-2.rs
issue-2907.rs
issue-2423.rs
issue-266.rs
+additional-trait-bounds2.rs
# please don't delete the trailing newline
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 084/146] gccrs: typecheck: Add note about erorring out on additional trait bounds.
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (82 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 083/146] gccrs: resolve: Name resolve trait bounds properly arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 085/146] gccrs: lang-item: Add Sync trait arthur.cohen
` (61 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
If additional trait bounds aren't auto traits, then the typechecker
must error out (Rust-GCC#3008)
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-type.cc: Add TODO note.
---
gcc/rust/typecheck/rust-hir-type-check-type.cc | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.cc b/gcc/rust/typecheck/rust-hir-type-check-type.cc
index e9859a71f83..e9207effafb 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-type.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-type.cc
@@ -757,6 +757,11 @@ TypeCheckType::visit (HIR::TraitObjectType &type)
std::vector<TyTy::TypeBoundPredicate> specified_bounds;
for (auto &bound : type.get_type_param_bounds ())
{
+ // TODO: here we need to check if there are additional bounds that aren't
+ // auto traits. this is an error. for example, `dyn A + Sized + Sync` is
+ // okay, because Sized and Sync are both auto traits but `dyn A + Copy +
+ // Clone` is not okay and should error out.
+
if (bound->get_bound_type ()
!= HIR::TypeParamBound::BoundType::TRAITBOUND)
continue;
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 085/146] gccrs: lang-item: Add Sync trait
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (83 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 084/146] gccrs: typecheck: Add note about erorring out on additional trait bounds arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 086/146] gccrs: lang-item: Add Option::{None, Some}, Iterator::next, IntoIter::into_iter arthur.cohen
` (60 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
gcc/rust/ChangeLog:
* util/rust-lang-item.h: Add Sync marker trait.
* util/rust-lang-item.cc: Likewise.
---
gcc/rust/util/rust-lang-item.cc | 1 +
gcc/rust/util/rust-lang-item.h | 1 +
2 files changed, 2 insertions(+)
diff --git a/gcc/rust/util/rust-lang-item.cc b/gcc/rust/util/rust-lang-item.cc
index 5ddffaa59d4..216202af926 100644
--- a/gcc/rust/util/rust-lang-item.cc
+++ b/gcc/rust/util/rust-lang-item.cc
@@ -62,6 +62,7 @@ const BiMap<std::string, LangItem::Kind> Rust::LangItem::lang_items = {{
{"copy", Kind::COPY},
{"clone", Kind::CLONE},
{"sized", Kind::SIZED},
+ {"sync", Kind::SYNC},
{"slice_alloc", Kind::SLICE_ALLOC},
{"slice_u8_alloc", Kind::SLICE_U8_ALLOC},
{"str_alloc", Kind::STR_ALLOC},
diff --git a/gcc/rust/util/rust-lang-item.h b/gcc/rust/util/rust-lang-item.h
index 92c70bbddf4..66d26d03907 100644
--- a/gcc/rust/util/rust-lang-item.h
+++ b/gcc/rust/util/rust-lang-item.h
@@ -82,6 +82,7 @@ public:
COPY,
CLONE,
SIZED,
+ SYNC,
// https://github.com/Rust-GCC/gccrs/issues/1896
// https://github.com/rust-lang/rust/commit/afbecc0f68c4dcfc4878ba5bcb1ac942544a1bdc
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 086/146] gccrs: lang-item: Add Option::{None, Some}, Iterator::next, IntoIter::into_iter
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (84 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 085/146] gccrs: lang-item: Add Sync trait arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 087/146] gccrs: lang-items: Collect trait functions that are lang items arthur.cohen
` (59 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
gcc/rust/ChangeLog:
* util/rust-lang-item.h: Add new lang items.
* util/rust-lang-item.cc: Likewise.
---
gcc/rust/util/rust-lang-item.cc | 6 ++++++
gcc/rust/util/rust-lang-item.h | 9 +++++++++
2 files changed, 15 insertions(+)
diff --git a/gcc/rust/util/rust-lang-item.cc b/gcc/rust/util/rust-lang-item.cc
index 216202af926..c4c1d1c093a 100644
--- a/gcc/rust/util/rust-lang-item.cc
+++ b/gcc/rust/util/rust-lang-item.cc
@@ -92,6 +92,12 @@ const BiMap<std::string, LangItem::Kind> Rust::LangItem::lang_items = {{
{"str", Kind::STR},
{"f32_runtime", Kind::F32_RUNTIME},
{"f64_runtime", Kind::F64_RUNTIME},
+
+ {"Some", Kind::OPTION_SOME},
+ {"None", Kind::OPTION_NONE},
+
+ {"into_iter", Kind::INTOITER_INTOITER},
+ {"next", Kind::ITERATOR_NEXT},
}};
tl::optional<LangItem::Kind>
diff --git a/gcc/rust/util/rust-lang-item.h b/gcc/rust/util/rust-lang-item.h
index 66d26d03907..9e432e2ccc6 100644
--- a/gcc/rust/util/rust-lang-item.h
+++ b/gcc/rust/util/rust-lang-item.h
@@ -26,6 +26,9 @@ namespace Rust {
class LangItem
{
public:
+ // FIXME: We should clean up that enum to make it more inline with the list of
+ // lang-items in Rust 1.49
+ // https://github.com/rust-lang/rust/blob/1.49.0/compiler/rustc_hir/src/lang_items.rs
enum class Kind
{
// https://github.com/rust-lang/rust/blob/master/library/core/src/ops/arith.rs
@@ -117,6 +120,12 @@ public:
STR,
F32_RUNTIME,
F64_RUNTIME,
+
+ OPTION_SOME,
+ OPTION_NONE,
+
+ INTOITER_INTOITER,
+ ITERATOR_NEXT,
};
static const BiMap<std::string, Kind> lang_items;
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 087/146] gccrs: lang-items: Collect trait functions that are lang items
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (85 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 086/146] gccrs: lang-item: Add Option::{None, Some}, Iterator::next, IntoIter::into_iter arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 088/146] gccrs: ast: Add new constructors for PathInExpression arthur.cohen
` (58 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
gcc/rust/ChangeLog:
* ast/rust-collect-lang-items.cc (CollectLangItems::visit): Add visitor for collecting
functions that might be lang items.
* ast/rust-collect-lang-items.h: Likewise.
---
gcc/rust/ast/rust-collect-lang-items.cc | 8 ++++++++
gcc/rust/ast/rust-collect-lang-items.h | 1 +
2 files changed, 9 insertions(+)
diff --git a/gcc/rust/ast/rust-collect-lang-items.cc b/gcc/rust/ast/rust-collect-lang-items.cc
index 308720ae69a..50d134a429f 100644
--- a/gcc/rust/ast/rust-collect-lang-items.cc
+++ b/gcc/rust/ast/rust-collect-lang-items.cc
@@ -82,5 +82,13 @@ CollectLangItems::visit (AST::TraitItemType &item)
DefaultASTVisitor::visit (item);
}
+void
+CollectLangItems::visit (AST::Function &item)
+{
+ maybe_add_lang_item (item);
+
+ DefaultASTVisitor::visit (item);
+}
+
} // namespace AST
} // namespace Rust
diff --git a/gcc/rust/ast/rust-collect-lang-items.h b/gcc/rust/ast/rust-collect-lang-items.h
index 552648f04ed..1d021b1d9c5 100644
--- a/gcc/rust/ast/rust-collect-lang-items.h
+++ b/gcc/rust/ast/rust-collect-lang-items.h
@@ -47,6 +47,7 @@ public:
void visit (AST::Trait &item) override;
void visit (AST::TraitItemType &item) override;
+ void visit (AST::Function &item) override;
private:
template <typename T> void maybe_add_lang_item (const T &item);
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 088/146] gccrs: ast: Add new constructors for PathInExpression
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (86 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 087/146] gccrs: lang-items: Collect trait functions that are lang items arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 089/146] gccrs: ast-builder: Add more methods arthur.cohen
` (57 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
This commit adds two new constructors for AST::PathInExpression: One using a provided lang-item, and one with an already built std::unique_ptr<Path>
gcc/rust/ChangeLog:
* ast/rust-path.h: Add two new constructors.
---
gcc/rust/ast/rust-path.h | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/gcc/rust/ast/rust-path.h b/gcc/rust/ast/rust-path.h
index 563ad52a9d6..39d42fd7e15 100644
--- a/gcc/rust/ast/rust-path.h
+++ b/gcc/rust/ast/rust-path.h
@@ -715,6 +715,24 @@ public:
marked_for_strip (false)
{}
+ PathInExpression (LangItem::Kind lang_item_kind,
+ std::vector<Attribute> outer_attrs, location_t locus)
+ : outer_attrs (std::move (outer_attrs)),
+ has_opening_scope_resolution (false), locus (locus),
+ _node_id (Analysis::Mappings::get ().get_next_node_id ()),
+ path (Rust::make_unique<LangItemPath> (lang_item_kind, locus)),
+ marked_for_strip (false)
+ {}
+
+ PathInExpression (std::unique_ptr<Path> path,
+ std::vector<Attribute> outer_attrs, location_t locus,
+ bool has_opening_scope_resolution = false)
+ : outer_attrs (std::move (outer_attrs)),
+ has_opening_scope_resolution (has_opening_scope_resolution),
+ locus (locus), _node_id (Analysis::Mappings::get ().get_next_node_id ()),
+ path (std::move (path)), marked_for_strip (false)
+ {}
+
PathInExpression (const PathInExpression &other)
: outer_attrs (other.outer_attrs),
has_opening_scope_resolution (other.has_opening_scope_resolution),
@@ -738,7 +756,8 @@ public:
// Creates an error state path in expression.
static PathInExpression create_error ()
{
- return PathInExpression ({}, {}, UNDEF_LOCATION);
+ return PathInExpression (std::vector<PathExprSegment> (), {},
+ UNDEF_LOCATION);
}
// Returns whether path in expression is in an error state.
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 089/146] gccrs: ast-builder: Add more methods
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (87 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 088/146] gccrs: ast: Add new constructors for PathInExpression arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 090/146] gccrs: Fix NR2.0 compiler ICE caused by Generics in Enums arthur.cohen
` (56 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
This commit adds new methods for building pattern nodes, match expressions and more precise call expressions.
gcc/rust/ChangeLog:
* ast/rust-ast-builder.cc: Add new functions.
* ast/rust-ast-builder.h: Declare them.
---
gcc/rust/ast/rust-ast-builder.cc | 91 ++++++++++++++++++++++++++++++++
gcc/rust/ast/rust-ast-builder.h | 30 +++++++++++
2 files changed, 121 insertions(+)
diff --git a/gcc/rust/ast/rust-ast-builder.cc b/gcc/rust/ast/rust-ast-builder.cc
index 529c686db1b..2fb041abcc0 100644
--- a/gcc/rust/ast/rust-ast-builder.cc
+++ b/gcc/rust/ast/rust-ast-builder.cc
@@ -20,6 +20,7 @@
#include "rust-ast-builder-type.h"
#include "rust-common.h"
#include "rust-expr.h"
+#include "rust-path.h"
#include "rust-token.h"
#include "rust-make-unique.h"
@@ -42,6 +43,33 @@ Builder::call (std::unique_ptr<Expr> &&path,
new CallExpr (std::move (path), std::move (args), {}, loc));
}
+std::unique_ptr<Expr>
+Builder::call (std::unique_ptr<Path> &&path,
+ std::vector<std::unique_ptr<Expr>> &&args) const
+{
+ return call (std::unique_ptr<Expr> (
+ new PathInExpression (std::move (path), {}, loc)),
+ std::move (args));
+}
+
+std::unique_ptr<Expr>
+Builder::call (std::unique_ptr<Expr> &&path, std::unique_ptr<Expr> &&arg) const
+{
+ auto args = std::vector<std::unique_ptr<Expr>> ();
+ args.emplace_back (std::move (arg));
+
+ return call (std::move (path), std::move (args));
+}
+
+std::unique_ptr<Expr>
+Builder::call (std::unique_ptr<Path> &&path, std::unique_ptr<Expr> &&arg) const
+{
+ auto args = std::vector<std::unique_ptr<Expr>> ();
+ args.emplace_back (std::move (arg));
+
+ return call (std::move (path), std::move (args));
+}
+
std::unique_ptr<Expr>
Builder::array (std::vector<std::unique_ptr<Expr>> &&members) const
{
@@ -56,6 +84,13 @@ Builder::identifier (std::string name) const
return std::unique_ptr<Expr> (new IdentifierExpr (name, {}, loc));
}
+std::unique_ptr<Pattern>
+Builder::identifier_pattern (std::string name, bool mut) const
+{
+ return std::unique_ptr<Pattern> (
+ new IdentifierPattern (name, loc, false, mut));
+}
+
std::unique_ptr<Expr>
Builder::tuple_idx (std::string receiver, int idx) const
{
@@ -117,6 +152,22 @@ Builder::path_in_expression (std::vector<std::string> &&segments) const
return PathInExpression (std::move (path_segments), {}, loc);
}
+PathInExpression
+Builder::path_in_expression (LangItem::Kind lang_item) const
+{
+ return PathInExpression (lang_item, {}, loc);
+}
+
+std::unique_ptr<Expr>
+Builder::block (std::unique_ptr<Stmt> &&stmt,
+ std::unique_ptr<Expr> &&tail_expr) const
+{
+ auto stmts = std::vector<std::unique_ptr<Stmt>> ();
+ stmts.emplace_back (std::move (stmt));
+
+ return block (std::move (stmts), std::move (tail_expr));
+}
+
std::unique_ptr<Expr>
Builder::block (std::vector<std::unique_ptr<Stmt>> &&stmts,
std::unique_ptr<Expr> &&tail_expr) const
@@ -189,6 +240,46 @@ Builder::wildcard () const
return std::unique_ptr<Pattern> (new WildcardPattern (loc));
}
+std::unique_ptr<Path>
+Builder::lang_item_path (LangItem::Kind kind) const
+{
+ return std::unique_ptr<Path> (new LangItemPath (kind, loc));
+}
+
+std::unique_ptr<Expr>
+Builder::match (std::unique_ptr<Expr> &&scrutinee,
+ std::vector<MatchCase> &&cases)
+{
+ return std::unique_ptr<Expr> (
+ new MatchExpr (std::move (scrutinee), std::move (cases), {}, {}, loc));
+}
+
+MatchArm
+Builder::match_arm (std::unique_ptr<Pattern> &&pattern)
+{
+ auto patterns = std::vector<std::unique_ptr<Pattern>> ();
+ patterns.emplace_back (std::move (pattern));
+
+ return MatchArm (std::move (patterns), loc);
+}
+
+MatchCase
+Builder::match_case (std::unique_ptr<Pattern> &&pattern,
+ std::unique_ptr<Expr> &&expr)
+{
+ return MatchCase (match_arm (std::move (pattern)), std::move (expr));
+}
+
+std::unique_ptr<Expr>
+Builder::loop (std::vector<std::unique_ptr<Stmt>> &&stmts)
+{
+ auto block = std::unique_ptr<BlockExpr> (
+ new BlockExpr (std::move (stmts), nullptr, {}, {}, LoopLabel::error (), loc,
+ loc));
+
+ return std::unique_ptr<Expr> (new LoopExpr (std::move (block), loc));
+}
+
std::unique_ptr<Type>
Builder::new_type (Type &type)
{
diff --git a/gcc/rust/ast/rust-ast-builder.h b/gcc/rust/ast/rust-ast-builder.h
index bad79d067ad..6e07df6e182 100644
--- a/gcc/rust/ast/rust-ast-builder.h
+++ b/gcc/rust/ast/rust-ast-builder.h
@@ -20,6 +20,7 @@
#define AST_BUILDER_H
#include "rust-ast-full.h"
+#include "rust-expr.h"
namespace Rust {
namespace AST {
@@ -38,6 +39,8 @@ public:
/* Create an identifier expression (`variable`) */
std::unique_ptr<Expr> identifier (std::string name) const;
+ std::unique_ptr<Pattern> identifier_pattern (std::string name,
+ bool mut = false) const;
/* Create a tuple index expression (`receiver.0`) */
std::unique_ptr<Expr> tuple_idx (std::string receiver, int idx) const;
@@ -53,6 +56,9 @@ public:
std::unique_ptr<Expr> block (std::vector<std::unique_ptr<Stmt>> &&stmts,
std::unique_ptr<Expr> &&tail_expr
= nullptr) const;
+ std::unique_ptr<Expr> block (std::unique_ptr<Stmt> &&stmt,
+ std::unique_ptr<Expr> &&tail_expr
+ = nullptr) const;
/* Create a let binding with an optional type and initializer (`let <name> :
* <type> = <init>`) */
@@ -66,6 +72,12 @@ public:
*/
std::unique_ptr<Expr> call (std::unique_ptr<Expr> &&path,
std::vector<std::unique_ptr<Expr>> &&args) const;
+ std::unique_ptr<Expr> call (std::unique_ptr<Path> &&path,
+ std::vector<std::unique_ptr<Expr>> &&args) const;
+ std::unique_ptr<Expr> call (std::unique_ptr<Expr> &&path,
+ std::unique_ptr<Expr> &&arg) const;
+ std::unique_ptr<Expr> call (std::unique_ptr<Path> &&path,
+ std::unique_ptr<Expr> &&arg) const;
/**
* Create an array expression (`[member0, member1, member2]`)
@@ -100,6 +112,11 @@ public:
PathInExpression
path_in_expression (std::vector<std::string> &&segments) const;
+ /**
+ * Create a path in expression from a lang item.
+ */
+ PathInExpression path_in_expression (LangItem::Kind lang_item) const;
+
/* Create a struct expression for unit structs (`S`) */
std::unique_ptr<Expr> struct_expr_struct (std::string struct_name) const;
@@ -122,6 +139,19 @@ public:
/* Create a wildcard pattern (`_`) */
std::unique_ptr<Pattern> wildcard () const;
+ /* Create a lang item path usable as a general path */
+ std::unique_ptr<Path> lang_item_path (LangItem::Kind) const;
+
+ /* Create match expressions and their components */
+ std::unique_ptr<Expr> match (std::unique_ptr<Expr> &&scrutinee,
+ std::vector<MatchCase> &&cases);
+ MatchArm match_arm (std::unique_ptr<Pattern> &&pattern);
+ MatchCase match_case (std::unique_ptr<Pattern> &&pattern,
+ std::unique_ptr<Expr> &&expr);
+
+ /* Create a loop expression */
+ std::unique_ptr<Expr> loop (std::vector<std::unique_ptr<Stmt>> &&stmts);
+
static std::unique_ptr<Type> new_type (Type &type);
static std::unique_ptr<GenericParam>
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 090/146] gccrs: Fix NR2.0 compiler ICE caused by Generics in Enums
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (88 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 089/146] gccrs: ast-builder: Add more methods arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 091/146] gccrs: nr2.0: Handle "Self" properly in trait definitions arthur.cohen
` (55 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Liam Naddell, Liam Naddell
From: Liam Naddell <liamnprg@gmail.com>
gcc/rust/ChangeLog:
* resolve/rust-late-name-resolver-2.0.cc:
Change the late name resolver to enter proper lexical scope during typechecking
* resolve/rust-late-name-resolver-2.0.h:
Add needed prototype to header
* resolve/rust-toplevel-name-resolver-2.0.cc:
Add generic parameters to enum's scoped RIB to allow for proper name resolution on types.
gcc/testsuite/ChangeLog:
* rust/compile/issue-3304.rs:
Add small test for generics+enums combination for NR2.0
Signed-off-by: Liam Naddell <liam.naddell@mail.utoronto.ca>
---
gcc/rust/resolve/rust-late-name-resolver-2.0.cc | 7 +++++++
gcc/rust/resolve/rust-late-name-resolver-2.0.h | 1 +
gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc | 9 +++++++++
gcc/testsuite/rust/compile/issue-3304.rs | 10 ++++++++++
4 files changed, 27 insertions(+)
create mode 100644 gcc/testsuite/rust/compile/issue-3304.rs
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 40f067319b5..38515cdc0fd 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
@@ -295,6 +295,13 @@ Late::visit (AST::StructStruct &s)
ctx.scoped (Rib::Kind::Item, s.get_node_id (), s_vis);
}
+void
+Late::visit (AST::Enum &s)
+{
+ auto s_vis = [this, &s] () { AST::DefaultASTVisitor::visit (s); };
+ ctx.scoped (Rib::Kind::Item, s.get_node_id (), s_vis);
+}
+
void
Late::visit (AST::StructExprStruct &s)
{
diff --git a/gcc/rust/resolve/rust-late-name-resolver-2.0.h b/gcc/rust/resolve/rust-late-name-resolver-2.0.h
index 6f1191662cc..1dbca3648da 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.h
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.h
@@ -52,6 +52,7 @@ public:
void visit (AST::StructExprStructBase &) override;
void visit (AST::StructExprStructFields &) override;
void visit (AST::StructStruct &) override;
+ void visit (AST::Enum &) override;
void visit (AST::GenericArgs &) override;
void visit (AST::GenericArg &);
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 a2f695e54f6..a76c098f2df 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
@@ -332,6 +332,15 @@ TopLevel::visit (AST::EnumItemDiscriminant &variant)
void
TopLevel::visit (AST::Enum &enum_item)
{
+ auto generic_vis = [this, &enum_item] () {
+ for (auto &g : enum_item.get_generic_params ())
+ {
+ g->accept_vis (*this);
+ }
+ };
+
+ ctx.scoped (Rib::Kind::Item, enum_item.get_node_id (), generic_vis);
+
insert_or_error_out (enum_item.get_identifier (), enum_item,
Namespace::Types);
diff --git a/gcc/testsuite/rust/compile/issue-3304.rs b/gcc/testsuite/rust/compile/issue-3304.rs
new file mode 100644
index 00000000000..6ab614fa2d5
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-3304.rs
@@ -0,0 +1,10 @@
+// { dg-additional-options "-frust-name-resolution-2.0" }
+#[lang = "sized"]
+trait Sized {}
+
+pub enum ROption<T> {
+ RSome(T),
+ RNone,
+}
+
+fn main() {}
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 091/146] gccrs: nr2.0: Handle "Self" properly in trait definitions
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (89 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 090/146] gccrs: Fix NR2.0 compiler ICE caused by Generics in Enums arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 092/146] gccrs: ast: Add EnumItem::Kind arthur.cohen
` (54 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Owen Avery
From: Owen Avery <powerboat9.gamer@gmail.com>
gcc/rust/ChangeLog:
* ast/rust-ast-visitor.cc
(DefaultASTVisitor::visit): Visit implicit Self parameters of
traits.
* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): Resolve implicit Self parameters of traits.
* resolve/rust-late-name-resolver-2.0.h:
(Late::visit): Add trait visitor.
* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::visit): Insert resolutions for Self type parameters
as well.
gcc/testsuite/ChangeLog:
* rust/compile/nr2/exclude: Remove entries.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
---
gcc/rust/ast/rust-ast-visitor.cc | 2 ++
gcc/rust/resolve/rust-late-name-resolver-2.0.cc | 13 +++++++++++++
gcc/rust/resolve/rust-late-name-resolver-2.0.h | 1 +
gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc | 7 ++-----
gcc/testsuite/rust/compile/nr2/exclude | 2 --
5 files changed, 18 insertions(+), 7 deletions(-)
diff --git a/gcc/rust/ast/rust-ast-visitor.cc b/gcc/rust/ast/rust-ast-visitor.cc
index a390aa20bcb..32e8025e9b2 100644
--- a/gcc/rust/ast/rust-ast-visitor.cc
+++ b/gcc/rust/ast/rust-ast-visitor.cc
@@ -997,6 +997,8 @@ DefaultASTVisitor::visit (AST::Trait &trait)
visit_inner_attrs (trait);
+ visit (trait.get_implicit_self ());
+
for (auto &generic : trait.get_generic_params ())
visit (generic);
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 38515cdc0fd..86fd5f12173 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
@@ -288,6 +288,19 @@ Late::visit (AST::TypePath &type)
DefaultResolver::visit (type);
}
+void
+Late::visit (AST::Trait &trait)
+{
+ // kind of weird how this is done
+ // names are resolved to the node id of trait.get_implicit_self ()
+ // which is then resolved to the node id of trait
+ // we set up the latter mapping here
+ ctx.map_usage (Usage (trait.get_implicit_self ().get_node_id ()),
+ Definition (trait.get_node_id ()));
+
+ DefaultResolver::visit (trait);
+}
+
void
Late::visit (AST::StructStruct &s)
{
diff --git a/gcc/rust/resolve/rust-late-name-resolver-2.0.h b/gcc/rust/resolve/rust-late-name-resolver-2.0.h
index 1dbca3648da..803a5ec1c00 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.h
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.h
@@ -48,6 +48,7 @@ public:
void visit (AST::PathInExpression &) override;
void visit (AST::LangItemPath &) override;
void visit (AST::TypePath &) override;
+ void visit (AST::Trait &) override;
void visit (AST::StructExprStruct &) override;
void visit (AST::StructExprStructBase &) override;
void visit (AST::StructExprStructFields &) override;
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 a76c098f2df..6d52fcaaac8 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
@@ -280,11 +280,8 @@ TopLevel::visit (AST::StructStruct &struct_item)
void
TopLevel::visit (AST::TypeParam &type_param)
{
- // Hacky and weird, find a better solution
- // We should probably not even insert self in the first place ?
- if (type_param.get_type_representation ().as_string () != "Self")
- insert_or_error_out (type_param.get_type_representation (), type_param,
- Namespace::Types);
+ insert_or_error_out (type_param.get_type_representation (), type_param,
+ Namespace::Types);
}
void
diff --git a/gcc/testsuite/rust/compile/nr2/exclude b/gcc/testsuite/rust/compile/nr2/exclude
index 8bdcc8ac338..2a5bc94b646 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -79,7 +79,6 @@ issue-2190-2.rs
issue-2238.rs
issue-2304.rs
issue-2330.rs
-issue-2375.rs
issue-2478.rs
issue-2479.rs
issue-2723-1.rs
@@ -182,7 +181,6 @@ issue-2987.rs
issue-3045-1.rs
issue-3045-2.rs
issue-3046.rs
-unknown-associated-item.rs
issue-3030.rs
issue-3035.rs
issue-3139-1.rs
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 092/146] gccrs: ast: Add EnumItem::Kind
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (90 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 091/146] gccrs: nr2.0: Handle "Self" properly in trait definitions arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 093/146] gccrs: Remove Rust::make_unique arthur.cohen
` (53 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
gcc/rust/ChangeLog:
* ast/rust-item.h: Add EnumItem::Kind for differentiating all variants that may be
used inside an enum declaration.
---
gcc/rust/ast/rust-item.h | 52 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 52 insertions(+)
diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h
index 6b77449eb8d..ecd355f6b8a 100644
--- a/gcc/rust/ast/rust-item.h
+++ b/gcc/rust/ast/rust-item.h
@@ -1994,6 +1994,41 @@ class EnumItem : public VisItem
location_t locus;
public:
+ enum class Kind
+ {
+ Identifier,
+ Tuple,
+ Struct,
+
+ // FIXME: In the future, we'll need to remove this possibility as well as
+ // remove the EnumItemDiscriminant class. The feature for arbitrary
+ // discriminants on all kinds of variants has been stabilized, and a
+ // "discriminant" is no longer an enum item variant - it's simply an
+ // optional part of all variants.
+ //
+ // Per the reference:
+ //
+ // EnumItem :
+ // OuterAttribute* Visibility?
+ // IDENTIFIER ( EnumItemTuple | EnumItemStruct )? EnumItemDiscriminant?
+ //
+ // EnumItemTuple :
+ // ( TupleFields? )
+ //
+ // EnumItemStruct :
+ // { StructFields? }
+ //
+ // EnumItemDiscriminant :
+ // = Expression
+ //
+ // So we instead need to remove the class, and add an optional expression to
+ // the base EnumItem class
+ //
+ // gccrs#3340
+
+ Discriminant,
+ };
+
virtual ~EnumItem () {}
EnumItem (Identifier variant_name, Visibility vis,
@@ -2002,6 +2037,8 @@ public:
variant_name (std::move (variant_name)), locus (locus)
{}
+ virtual Kind get_enum_item_kind () const { return Kind::Identifier; }
+
// Unique pointer custom clone function
std::unique_ptr<EnumItem> clone_enum_item () const
{
@@ -2043,6 +2080,11 @@ public:
tuple_fields (std::move (tuple_fields))
{}
+ EnumItem::Kind get_enum_item_kind () const override
+ {
+ return EnumItem::Kind::Tuple;
+ }
+
std::string as_string () const override;
void accept_vis (ASTVisitor &vis) override;
@@ -2080,6 +2122,11 @@ public:
struct_fields (std::move (struct_fields))
{}
+ EnumItem::Kind get_enum_item_kind () const override
+ {
+ return EnumItem::Kind::Struct;
+ }
+
std::string as_string () const override;
void accept_vis (ASTVisitor &vis) override;
@@ -2133,6 +2180,11 @@ public:
EnumItemDiscriminant (EnumItemDiscriminant &&other) = default;
EnumItemDiscriminant &operator= (EnumItemDiscriminant &&other) = default;
+ EnumItem::Kind get_enum_item_kind () const override
+ {
+ return EnumItem::Kind::Discriminant;
+ }
+
std::string as_string () const override;
void accept_vis (ASTVisitor &vis) override;
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 093/146] gccrs: Remove Rust::make_unique
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (91 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 092/146] gccrs: ast: Add EnumItem::Kind arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 094/146] gccrs: lower: Correctly lower parenthesized types arthur.cohen
` (52 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Owen Avery
From: Owen Avery <powerboat9.gamer@gmail.com>
Since our bootstrap requirement has been bumped to C++14, we don't need
a custom implementation of std::make_unique anymore.
gcc/rust/ChangeLog:
* ast/rust-ast-builder-type.cc: Remove inclusion of
rust-make-unique.h.
* ast/rust-ast-builder.cc: Likewise.
(Builder::array): Use std::make_unique instead of
Rust::make_unique.
* ast/rust-ast.cc (Attribute::get_traits_to_derive): Likewise.
* ast/rust-macro.h: Remove inclusion of rust-make-unique.h.
(MacroRulesDefinition::mbe): Use std::make_unique instead of
Rust::make_unique.
(MacroRulesDefinition::decl_macro): Likewise.
* ast/rust-path.h
(PathInExpression::PathInExpression): Likewise.
(QualifiedPathInExpression::QualifiedPathInExpression):
Likewise.
* backend/rust-compile-pattern.cc
(CompilePatternCheckExpr::visit): Likewise.
* expand/rust-derive-copy.cc
(DeriveCopy::copy_impl): Likewise.
* expand/rust-expand-format-args.cc
(expand_format_args): Likewise.
* expand/rust-macro-builtins-asm.cc: Remove inclusion of
rust-make-unique.h.
(parse_asm): Use std::make_unique instead of Rust::make_unique.
* hir/rust-ast-lower-expr.cc
(ASTLoweringExpr::visit): Likewise.
* hir/tree/rust-hir-expr.cc
(StructExprStructFields::StructExprStructFields): Likewise.
(StructExprStructFields::operator=): Likewise.
* hir/tree/rust-hir.cc
(TypePath::to_trait_bound): Likewise.
* lex/rust-token.h: Remove inclusion of rust-make-unique.h.
(Token::Token): Use std::make_unique instead of
Rust::make_unique.
* metadata/rust-import-archive.cc: Remove inclusion of
rust-make-unique.h.
(Import::find_archive_export_data): Use std::make_unique instead
of Rust::make_unique.
* metadata/rust-imports.cc: Remove inclusion of
rust-make-unique.h.
(Import::find_export_data): Use std::make_unique instead of
Rust::make_unique.
(Import::find_object_export_data): Likewise.
* parse/rust-parse-impl.h: Remove inclusion of
rust-make-unique.h.
(Parser::parse_function_param): Use std::make_unique instead of
Rust::make_unique.
(Parser::parse_self_param): Likewise.
(Parser::parse_array_expr): Likewise.
* typecheck/rust-hir-type-check-enumitem.cc
(TypeCheckEnumItem::visit): Likewise.
* typecheck/rust-hir-type-check-implitem.cc
(TypeCheckTopLevelExternItem::visit): Likewise.
(TypeCheckImplItem::visit): Likewise.
* typecheck/rust-hir-type-check-type.cc
(TypeResolveGenericParam::visit): Likewise.
* typecheck/rust-hir-type-check.cc: Remove inclusion of
rust-make-unique.h.
(TraitItemReference::get_type_from_fn): Use std::make_unique
instead of Rust::make_unique.
* typecheck/rust-tyty-bounds.cc
(TypeCheckBase::get_predicate_from_bound): Likewise.
* util/rust-make-unique.h: Removed.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
---
gcc/rust/ast/rust-ast-builder-type.cc | 1 -
gcc/rust/ast/rust-ast-builder.cc | 3 +-
gcc/rust/ast/rust-ast.cc | 4 +--
gcc/rust/ast/rust-macro.h | 5 ++-
gcc/rust/ast/rust-path.h | 8 ++---
gcc/rust/backend/rust-compile-pattern.cc | 2 +-
gcc/rust/expand/rust-derive-copy.cc | 2 +-
gcc/rust/expand/rust-expand-format-args.cc | 2 +-
gcc/rust/expand/rust-macro-builtins-asm.cc | 7 ++--
gcc/rust/hir/rust-ast-lower-expr.cc | 2 +-
gcc/rust/hir/tree/rust-hir-expr.cc | 10 +++---
gcc/rust/hir/tree/rust-hir.cc | 4 +--
gcc/rust/lex/rust-token.h | 7 ++--
gcc/rust/metadata/rust-import-archive.cc | 5 ++-
gcc/rust/metadata/rust-imports.cc | 5 ++-
gcc/rust/parse/rust-parse-impl.h | 23 ++++++------
.../typecheck/rust-hir-type-check-enumitem.cc | 6 ++--
.../typecheck/rust-hir-type-check-implitem.cc | 4 +--
.../typecheck/rust-hir-type-check-type.cc | 2 +-
gcc/rust/typecheck/rust-hir-type-check.cc | 3 +-
gcc/rust/typecheck/rust-tyty-bounds.cc | 4 +--
gcc/rust/util/rust-make-unique.h | 35 -------------------
22 files changed, 50 insertions(+), 94 deletions(-)
delete mode 100644 gcc/rust/util/rust-make-unique.h
diff --git a/gcc/rust/ast/rust-ast-builder-type.cc b/gcc/rust/ast/rust-ast-builder-type.cc
index e76d0de0e9a..13126b44057 100644
--- a/gcc/rust/ast/rust-ast-builder-type.cc
+++ b/gcc/rust/ast/rust-ast-builder-type.cc
@@ -20,7 +20,6 @@
#include "rust-ast-builder.h"
#include "rust-ast-full.h"
#include "rust-common.h"
-#include "rust-make-unique.h"
namespace Rust {
namespace AST {
diff --git a/gcc/rust/ast/rust-ast-builder.cc b/gcc/rust/ast/rust-ast-builder.cc
index 2fb041abcc0..22fb0d83f97 100644
--- a/gcc/rust/ast/rust-ast-builder.cc
+++ b/gcc/rust/ast/rust-ast-builder.cc
@@ -22,7 +22,6 @@
#include "rust-expr.h"
#include "rust-path.h"
#include "rust-token.h"
-#include "rust-make-unique.h"
namespace Rust {
namespace AST {
@@ -73,7 +72,7 @@ Builder::call (std::unique_ptr<Path> &&path, std::unique_ptr<Expr> &&arg) const
std::unique_ptr<Expr>
Builder::array (std::vector<std::unique_ptr<Expr>> &&members) const
{
- auto elts = Rust::make_unique<ArrayElemsValues> (std::move (members), loc);
+ auto elts = std::make_unique<ArrayElemsValues> (std::move (members), loc);
return std::unique_ptr<Expr> (new ArrayExpr (std::move (elts), {}, {}, loc));
}
diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc
index f1298d0f3e9..06a7a097cfb 100644
--- a/gcc/rust/ast/rust-ast.cc
+++ b/gcc/rust/ast/rust-ast.cc
@@ -272,8 +272,8 @@ Attribute::get_traits_to_derive ()
case AST::MetaItem::ItemKind::Word: {
auto word = static_cast<AST::MetaWord *> (meta_item);
// Convert current word to path
- current
- = make_unique<AST::MetaItemPath> (AST::MetaItemPath (
+ current = std::make_unique<AST::MetaItemPath> (
+ AST::MetaItemPath (
AST::SimplePath (word->get_ident ())));
auto path
= static_cast<AST::MetaItemPath *> (current.get ());
diff --git a/gcc/rust/ast/rust-macro.h b/gcc/rust/ast/rust-macro.h
index 76b3b2a3a8f..a953b75155c 100644
--- a/gcc/rust/ast/rust-macro.h
+++ b/gcc/rust/ast/rust-macro.h
@@ -24,7 +24,6 @@
#include "rust-ast-fragment.h"
#include "rust-location.h"
#include "rust-item.h"
-#include "rust-make-unique.h"
#include "rust-macro-builtins.h"
namespace Rust {
@@ -521,7 +520,7 @@ public:
mbe (Identifier rule_name, DelimType delim_type, std::vector<MacroRule> rules,
std::vector<Attribute> outer_attrs, location_t locus)
{
- return Rust::make_unique<MacroRulesDefinition> (
+ return std::make_unique<MacroRulesDefinition> (
MacroRulesDefinition (rule_name, delim_type, rules, outer_attrs, locus,
AST::MacroRulesDefinition::MacroKind::MBE,
AST::Visibility::create_error ()));
@@ -532,7 +531,7 @@ public:
std::vector<Attribute> outer_attrs, location_t locus,
Visibility vis)
{
- return Rust::make_unique<MacroRulesDefinition> (MacroRulesDefinition (
+ return std::make_unique<MacroRulesDefinition> (MacroRulesDefinition (
rule_name, AST::DelimType::CURLY, rules, outer_attrs, locus,
AST::MacroRulesDefinition::MacroKind::DeclMacro, vis));
}
diff --git a/gcc/rust/ast/rust-path.h b/gcc/rust/ast/rust-path.h
index 39d42fd7e15..4e26b2f9f3b 100644
--- a/gcc/rust/ast/rust-path.h
+++ b/gcc/rust/ast/rust-path.h
@@ -710,8 +710,8 @@ public:
: outer_attrs (std::move (outer_attrs)),
has_opening_scope_resolution (has_opening_scope_resolution),
locus (locus), _node_id (Analysis::Mappings::get ().get_next_node_id ()),
- path (Rust::make_unique<RegularPath> (std::move (path_segments), locus,
- _node_id)),
+ path (std::make_unique<RegularPath> (std::move (path_segments), locus,
+ _node_id)),
marked_for_strip (false)
{}
@@ -720,7 +720,7 @@ public:
: outer_attrs (std::move (outer_attrs)),
has_opening_scope_resolution (false), locus (locus),
_node_id (Analysis::Mappings::get ().get_next_node_id ()),
- path (Rust::make_unique<LangItemPath> (lang_item_kind, locus)),
+ path (std::make_unique<LangItemPath> (lang_item_kind, locus)),
marked_for_strip (false)
{}
@@ -1439,7 +1439,7 @@ public:
location_t locus)
: outer_attrs (std::move (outer_attrs)),
path_type (std::move (qual_path_type)),
- path (Rust::make_unique<RegularPath> (
+ path (std::make_unique<RegularPath> (
std::move (path_segments), locus,
Analysis::Mappings::get ().get_next_node_id ()))
{}
diff --git a/gcc/rust/backend/rust-compile-pattern.cc b/gcc/rust/backend/rust-compile-pattern.cc
index b2e7c351f95..bd534ff3bef 100644
--- a/gcc/rust/backend/rust-compile-pattern.cc
+++ b/gcc/rust/backend/rust-compile-pattern.cc
@@ -80,7 +80,7 @@ void
CompilePatternCheckExpr::visit (HIR::LiteralPattern &pattern)
{
// Compile the literal
- auto litexpr = Rust::make_unique<HIR::LiteralExpr> (
+ auto litexpr = std::make_unique<HIR::LiteralExpr> (
HIR::LiteralExpr (pattern.get_mappings (), pattern.get_literal (),
pattern.get_locus (), std::vector<AST::Attribute> ()));
diff --git a/gcc/rust/expand/rust-derive-copy.cc b/gcc/rust/expand/rust-derive-copy.cc
index 02817250db1..f8007abd575 100644
--- a/gcc/rust/expand/rust-derive-copy.cc
+++ b/gcc/rust/expand/rust-derive-copy.cc
@@ -46,7 +46,7 @@ DeriveCopy::copy_impl (
// `$crate::core::marker::Copy` instead
auto segments = std::vector<std::unique_ptr<TypePathSegment>> ();
segments.emplace_back (builder.type_path_segment ("Copy"));
- auto copy = Rust::make_unique<LangItemPath> (LangItem::Kind::COPY, loc);
+ auto copy = std::make_unique<LangItemPath> (LangItem::Kind::COPY, loc);
// we need to build up the generics for this impl block which will be just a
// clone of the types specified ones
diff --git a/gcc/rust/expand/rust-expand-format-args.cc b/gcc/rust/expand/rust-expand-format-args.cc
index c8087eef6da..af6182f627f 100644
--- a/gcc/rust/expand/rust-expand-format-args.cc
+++ b/gcc/rust/expand/rust-expand-format-args.cc
@@ -120,7 +120,7 @@ expand_format_args (AST::FormatArgs &fmt,
auto pieces = builder.ref (builder.array (std::move (static_pieces)));
auto args_slice = builder.ref (builder.array (std::move (args_array)));
- auto final_path = make_unique<AST::PathInExpression> (
+ auto final_path = std::make_unique<AST::PathInExpression> (
builder.path_in_expression ({"core", "fmt", "Arguments", "new_v1"}));
auto final_args = std::vector<std::unique_ptr<AST::Expr>> ();
final_args.emplace_back (std::move (pieces));
diff --git a/gcc/rust/expand/rust-macro-builtins-asm.cc b/gcc/rust/expand/rust-macro-builtins-asm.cc
index 5ed24d641ce..78e308a6654 100644
--- a/gcc/rust/expand/rust-macro-builtins-asm.cc
+++ b/gcc/rust/expand/rust-macro-builtins-asm.cc
@@ -17,7 +17,6 @@
// <http://www.gnu.org/licenses/>.
#include "expected.h"
-#include "rust-make-unique.h"
#include "rust-macro-builtins-asm.h"
#include "rust-ast-fragment.h"
#include "rust-ast.h"
@@ -858,9 +857,9 @@ parse_asm (location_t invoc_locus, AST::MacroInvocData &invoc,
// properly.
if (semicolon == AST::InvocKind::Semicoloned)
single_vec.emplace_back (AST::SingleASTNode (
- Rust::make_unique<AST::ExprStmt> (std::move (node), invoc_locus,
- semicolon
- == AST::InvocKind::Semicoloned)));
+ std::make_unique<AST::ExprStmt> (std::move (node), invoc_locus,
+ semicolon
+ == AST::InvocKind::Semicoloned)));
else
single_vec.emplace_back (AST::SingleASTNode (std::move (node)));
diff --git a/gcc/rust/hir/rust-ast-lower-expr.cc b/gcc/rust/hir/rust-ast-lower-expr.cc
index b45b5f925df..7ccb251e0e6 100644
--- a/gcc/rust/hir/rust-ast-lower-expr.cc
+++ b/gcc/rust/hir/rust-ast-lower-expr.cc
@@ -518,7 +518,7 @@ ASTLoweringExpr::visit (AST::StructExprStructFields &struct_expr)
HIR::Expr *translated_base = ASTLoweringExpr::translate (
struct_expr.get_struct_base ().get_base_struct ());
base = tl::optional<std::unique_ptr<HIR::StructBase>> (
- Rust::make_unique<StructBase> (
+ std::make_unique<StructBase> (
std::unique_ptr<HIR::Expr> (translated_base)));
}
diff --git a/gcc/rust/hir/tree/rust-hir-expr.cc b/gcc/rust/hir/tree/rust-hir-expr.cc
index 6c9a7a475e7..4a902c65594 100644
--- a/gcc/rust/hir/tree/rust-hir-expr.cc
+++ b/gcc/rust/hir/tree/rust-hir-expr.cc
@@ -541,10 +541,10 @@ StructExprStructFields::StructExprStructFields (
StructExprStructFields::StructExprStructFields (
StructExprStructFields const &other)
: StructExprStruct (other),
- struct_base (
- other.has_struct_base () ? tl::optional<std::unique_ptr<StructBase>> (
- Rust::make_unique<StructBase> (*other.struct_base.value ()))
- : tl::nullopt),
+ struct_base (other.has_struct_base ()
+ ? tl::optional<std::unique_ptr<StructBase>> (
+ std::make_unique<StructBase> (*other.struct_base.value ()))
+ : tl::nullopt),
union_index (other.union_index)
{
fields.reserve (other.fields.size ());
@@ -558,7 +558,7 @@ StructExprStructFields::operator= (StructExprStructFields const &other)
StructExprStruct::operator= (other);
struct_base = other.has_struct_base ()
? tl::optional<std::unique_ptr<StructBase>> (
- Rust::make_unique<StructBase> (*other.struct_base.value ()))
+ std::make_unique<StructBase> (*other.struct_base.value ()))
: tl::nullopt;
union_index = other.union_index;
diff --git a/gcc/rust/hir/tree/rust-hir.cc b/gcc/rust/hir/tree/rust-hir.cc
index c20d69d2146..da1c8b9ab1b 100644
--- a/gcc/rust/hir/tree/rust-hir.cc
+++ b/gcc/rust/hir/tree/rust-hir.cc
@@ -2710,8 +2710,8 @@ TypePath::to_trait_bound (bool in_parens) const
// create clone FIXME is this required? or is copy constructor automatically
// called?
TypePath copy (*this);
- return Rust::make_unique<TraitBound> (mappings, std::move (copy),
- copy.get_locus (), in_parens);
+ return std::make_unique<TraitBound> (mappings, std::move (copy),
+ copy.get_locus (), in_parens);
}
std::string
diff --git a/gcc/rust/lex/rust-token.h b/gcc/rust/lex/rust-token.h
index aa2f308dd88..c683ecd446e 100644
--- a/gcc/rust/lex/rust-token.h
+++ b/gcc/rust/lex/rust-token.h
@@ -21,7 +21,6 @@
#include "rust-system.h"
#include "rust-linemap.h"
-#include "rust-make-unique.h"
#include "rust-unicode.h"
namespace Rust {
@@ -268,7 +267,7 @@ private:
: token_id (token_id), locus (location), type_hint (CORETYPE_UNKNOWN)
{
// Normalize identifier tokens
- str = Rust::make_unique<std::string> (
+ str = std::make_unique<std::string> (
nfc_normalize_token_string (location, token_id, paramStr));
}
@@ -285,7 +284,7 @@ private:
: token_id (token_id), locus (location), type_hint (CORETYPE_UNKNOWN)
{
// Normalize identifier tokens
- str = Rust::make_unique<std::string> (
+ str = std::make_unique<std::string> (
nfc_normalize_token_string (location, token_id,
paramCodepoint.as_string ()));
}
@@ -296,7 +295,7 @@ private:
: token_id (token_id), locus (location), type_hint (parType)
{
// Normalize identifier tokens
- str = Rust::make_unique<std::string> (
+ str = std::make_unique<std::string> (
nfc_normalize_token_string (location, token_id, paramStr));
}
diff --git a/gcc/rust/metadata/rust-import-archive.cc b/gcc/rust/metadata/rust-import-archive.cc
index 6c392b00b4b..cf24607f099 100644
--- a/gcc/rust/metadata/rust-import-archive.cc
+++ b/gcc/rust/metadata/rust-import-archive.cc
@@ -7,7 +7,6 @@
#include "rust-system.h"
#include "rust-diagnostics.h"
#include "rust-imports.h"
-#include "rust-make-unique.h"
#ifndef O_BINARY
#define O_BINARY 0
@@ -844,7 +843,7 @@ Import::find_archive_export_data (const std::string &filename, int fd,
if (!afile.initialize ())
return nullptr;
- auto ret = Rust::make_unique<Stream_concatenate> ();
+ auto ret = std::make_unique<Stream_concatenate> ();
bool any_data = false;
bool any_members = false;
@@ -872,7 +871,7 @@ Import::find_archive_export_data (const std::string &filename, int fd,
if (!any_members)
{
// It's normal to have an empty archive file when using gobuild.
- return Rust::make_unique<Stream_from_string> ("");
+ return std::make_unique<Stream_from_string> ("");
}
if (!any_data)
diff --git a/gcc/rust/metadata/rust-imports.cc b/gcc/rust/metadata/rust-imports.cc
index f2ab105bb1d..8d5c381ef4c 100644
--- a/gcc/rust/metadata/rust-imports.cc
+++ b/gcc/rust/metadata/rust-imports.cc
@@ -21,7 +21,6 @@
#include "rust-imports.h"
#include "rust-object-export.h"
#include "rust-export-metadata.h"
-#include "rust-make-unique.h"
#ifndef O_BINARY
#define O_BINARY 0
@@ -259,7 +258,7 @@ Import::find_export_data (const std::string &filename, int fd,
//
if (memcmp (buf, Metadata::kMagicHeader, sizeof (Metadata::kMagicHeader))
== 0)
- return Rust::make_unique<Stream_from_file> (fd);
+ return std::make_unique<Stream_from_file> (fd);
// See if we can read this as an archive.
if (Import::is_archive_magic (buf))
@@ -291,7 +290,7 @@ Import::find_object_export_data (const std::string &filename, int fd,
if (buf == nullptr)
return nullptr;
- return Rust::make_unique<Stream_from_buffer> (buf, len);
+ return std::make_unique<Stream_from_buffer> (buf, len);
}
// Class Import.
diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index d5383ada21e..185217a7b9b 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -29,7 +29,6 @@
#include "rust-token.h"
#define INCLUDE_ALGORITHM
#include "rust-diagnostics.h"
-#include "rust-make-unique.h"
#include "rust-dir-owner.h"
#include "rust-attribute-values.h"
#include "rust-keyword-values.h"
@@ -3683,7 +3682,7 @@ Parser<ManagedTokenSource>::parse_function_param ()
if (lexer.peek_token ()->get_id () == ELLIPSIS) // Unnamed variadic
{
lexer.skip_token (); // Skip ellipsis
- return Rust::make_unique<AST::VariadicParam> (
+ return std::make_unique<AST::VariadicParam> (
AST::VariadicParam (std::move (outer_attrs), locus));
}
@@ -3705,7 +3704,7 @@ Parser<ManagedTokenSource>::parse_function_param ()
if (lexer.peek_token ()->get_id () == ELLIPSIS) // Named variadic
{
lexer.skip_token (); // Skip ellipsis
- return Rust::make_unique<AST::VariadicParam> (
+ return std::make_unique<AST::VariadicParam> (
AST::VariadicParam (std::move (param_pattern), std::move (outer_attrs),
locus));
}
@@ -3716,7 +3715,7 @@ Parser<ManagedTokenSource>::parse_function_param ()
{
return nullptr;
}
- return Rust::make_unique<AST::FunctionParam> (
+ return std::make_unique<AST::FunctionParam> (
AST::FunctionParam (std::move (param_pattern), std::move (param_type),
std::move (outer_attrs), locus));
}
@@ -7124,14 +7123,14 @@ Parser<ManagedTokenSource>::parse_self_param ()
if (has_reference)
{
- return Rust::make_unique<AST::SelfParam> (std::move (lifetime), has_mut,
- locus);
+ return std::make_unique<AST::SelfParam> (std::move (lifetime), has_mut,
+ locus);
}
else
{
// note that type may be nullptr here and that's fine
- return Rust::make_unique<AST::SelfParam> (std::move (type), has_mut,
- locus);
+ return std::make_unique<AST::SelfParam> (std::move (type), has_mut,
+ locus);
}
}
@@ -8693,10 +8692,10 @@ Parser<ManagedTokenSource>::parse_array_expr (AST::AttrVec outer_attrs,
std::vector<std::unique_ptr<AST::Expr>> exprs;
auto array_elems
- = Rust::make_unique<AST::ArrayElemsValues> (std::move (exprs), locus);
- return Rust::make_unique<AST::ArrayExpr> (std::move (array_elems),
- std::move (inner_attrs),
- std::move (outer_attrs), locus);
+ = std::make_unique<AST::ArrayElemsValues> (std::move (exprs), locus);
+ return std::make_unique<AST::ArrayExpr> (std::move (array_elems),
+ std::move (inner_attrs),
+ std::move (outer_attrs), locus);
}
else
{
diff --git a/gcc/rust/typecheck/rust-hir-type-check-enumitem.cc b/gcc/rust/typecheck/rust-hir-type-check-enumitem.cc
index 22025cef68a..4bf7b72c1e9 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-enumitem.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-enumitem.cc
@@ -69,7 +69,7 @@ TypeCheckEnumItem::visit (HIR::EnumItem &item)
mappings.get_next_hir_id (
item.get_mappings ().get_crate_num ()),
item.get_mappings ().get_local_defid ());
- auto discim_expr = Rust::make_unique<HIR::LiteralExpr> (
+ auto discim_expr = std::make_unique<HIR::LiteralExpr> (
HIR::LiteralExpr (mapping, std::to_string (last_discriminant),
HIR::Literal::LitType::INT,
PrimitiveCoreType::CORETYPE_I64, item.get_locus (), {}));
@@ -174,7 +174,7 @@ TypeCheckEnumItem::visit (HIR::EnumItemTuple &item)
mappings.get_next_hir_id (
item.get_mappings ().get_crate_num ()),
item.get_mappings ().get_local_defid ());
- auto discim_expr = Rust::make_unique<HIR::LiteralExpr> (
+ auto discim_expr = std::make_unique<HIR::LiteralExpr> (
HIR::LiteralExpr (mapping, std::to_string (last_discriminant),
HIR::Literal::LitType::INT,
PrimitiveCoreType::CORETYPE_I64, item.get_locus (), {}));
@@ -234,7 +234,7 @@ TypeCheckEnumItem::visit (HIR::EnumItemStruct &item)
mappings.get_next_hir_id (
item.get_mappings ().get_crate_num ()),
item.get_mappings ().get_local_defid ());
- auto discrim_expr = Rust::make_unique<HIR::LiteralExpr> (
+ auto discrim_expr = std::make_unique<HIR::LiteralExpr> (
HIR::LiteralExpr (mapping, std::to_string (last_discriminant),
HIR::Literal::LitType::INT,
PrimitiveCoreType::CORETYPE_I64, item.get_locus (), {}));
diff --git a/gcc/rust/typecheck/rust-hir-type-check-implitem.cc b/gcc/rust/typecheck/rust-hir-type-check-implitem.cc
index 5da88b890f3..4521822410c 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-implitem.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-implitem.cc
@@ -142,7 +142,7 @@ TypeCheckTopLevelExternItem::visit (HIR::ExternalFunctionItem &function)
mappings.get_next_hir_id (crate_num),
UNKNOWN_LOCAL_DEFID);
- auto param_pattern = Rust::make_unique<HIR::IdentifierPattern> (
+ auto param_pattern = std::make_unique<HIR::IdentifierPattern> (
HIR::IdentifierPattern (mapping, param.get_param_name (),
UNDEF_LOCATION, false, Mutability::Imm,
std::unique_ptr<HIR::Pattern> (nullptr)));
@@ -390,7 +390,7 @@ TypeCheckImplItem::visit (HIR::Function &function)
HIR::SelfParam &self_param = function.get_self_param ();
// FIXME: which location should be used for Rust::Identifier for `self`?
std::unique_ptr<HIR::Pattern> self_pattern
- = Rust::make_unique<HIR::IdentifierPattern> (
+ = std::make_unique<HIR::IdentifierPattern> (
HIR::IdentifierPattern (mapping, {"self"}, self_param.get_locus (),
self_param.is_ref (), self_param.get_mut (),
std::unique_ptr<HIR::Pattern> (nullptr)));
diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.cc b/gcc/rust/typecheck/rust-hir-type-check-type.cc
index e9207effafb..4ea1a493fa8 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-type.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-type.cc
@@ -924,7 +924,7 @@ TypeResolveGenericParam::visit (HIR::TypeParam ¶m)
param.get_mappings ().get_nodeid (),
implicit_id,
param.get_mappings ().get_local_defid ());
- implicit_self_bound = Rust::make_unique<HIR::TypePath> (
+ implicit_self_bound = std::make_unique<HIR::TypePath> (
HIR::TypePath (mappings, {}, BUILTINS_LOCATION, false));
}
diff --git a/gcc/rust/typecheck/rust-hir-type-check.cc b/gcc/rust/typecheck/rust-hir-type-check.cc
index 4bcb709de75..a198ad3d66d 100644
--- a/gcc/rust/typecheck/rust-hir-type-check.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check.cc
@@ -24,7 +24,6 @@
#include "rust-hir-type-check-item.h"
#include "rust-hir-type-check-pattern.h"
#include "rust-hir-type-check-struct-field.h"
-#include "rust-make-unique.h"
#include "rust-immutable-name-resolution-context.h"
// for flag_name_resolution_2_0
@@ -238,7 +237,7 @@ TraitItemReference::get_type_from_fn (/*const*/ HIR::TraitItemFunc &fn) const
// but we reuse the HIR identifier pattern which requires it
HIR::SelfParam &self_param = function.get_self ();
std::unique_ptr<HIR::Pattern> self_pattern
- = Rust::make_unique<HIR::IdentifierPattern> (HIR::IdentifierPattern (
+ = std::make_unique<HIR::IdentifierPattern> (HIR::IdentifierPattern (
mapping, {"self"}, self_param.get_locus (), self_param.is_ref (),
self_param.is_mut () ? Mutability::Mut : Mutability::Imm,
std::unique_ptr<HIR::Pattern> (nullptr)));
diff --git a/gcc/rust/typecheck/rust-tyty-bounds.cc b/gcc/rust/typecheck/rust-tyty-bounds.cc
index 41844ea741a..5db96cc7b41 100644
--- a/gcc/rust/typecheck/rust-tyty-bounds.cc
+++ b/gcc/rust/typecheck/rust-tyty-bounds.cc
@@ -237,8 +237,8 @@ TypeCheckBase::get_predicate_from_bound (
std::vector<std::unique_ptr<HIR::Type>> inputs;
inputs.push_back (
- Rust::make_unique<HIR::TupleType> (mapping, std::move (params_copy),
- final_seg.get_locus ()));
+ std::make_unique<HIR::TupleType> (mapping, std::move (params_copy),
+ final_seg.get_locus ()));
// resolve the fn_once_output type which assumes there must be an output
// set
diff --git a/gcc/rust/util/rust-make-unique.h b/gcc/rust/util/rust-make-unique.h
deleted file mode 100644
index ef589911bed..00000000000
--- a/gcc/rust/util/rust-make-unique.h
+++ /dev/null
@@ -1,35 +0,0 @@
-// Copyright (C) 2020-2025 Free Software Foundation, Inc.
-
-// This file is part of GCC.
-
-// GCC is free software; you can redistribute it and/or modify it under
-// the terms of the GNU General Public License as published by the Free
-// Software Foundation; either version 3, or (at your option) any later
-// version.
-
-// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
-// WARRANTY; without even the implied warranty of MERCHANTABILITY or
-// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
-// for more details.
-
-// You should have received a copy of the GNU General Public License
-// along with GCC; see the file COPYING3. If not see
-// <http://www.gnu.org/licenses/>.
-
-#ifndef RUST_MAKE_UNIQUE_H
-#define RUST_MAKE_UNIQUE_H
-
-#include "rust-system.h"
-
-namespace Rust {
-
-template <typename T, typename... Ts>
-std::unique_ptr<T>
-make_unique (Ts &&...params)
-{
- return std::unique_ptr<T> (new T (std::forward<Ts> (params)...));
-}
-
-} // namespace Rust
-
-#endif // RUST_MAKE_UNIQUE_H
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 094/146] gccrs: lower: Correctly lower parenthesized types
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (92 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 093/146] gccrs: Remove Rust::make_unique arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 095/146] gccrs: tychk: Add more support for additional trait bounds in functions arthur.cohen
` (51 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
This is useful for handling multiple trait bounds, and required for better handling of auto traits.
gcc/rust/ChangeLog:
* hir/rust-ast-lower-type.cc (ASTLoweringType::visit): Add implementation for
ParenthesizedType.
* hir/rust-ast-lower-type.h: Declare that new visitor.
gcc/testsuite/ChangeLog:
* rust/compile/auto_traits1.rs: New test.
---
gcc/rust/hir/rust-ast-lower-type.cc | 19 +++++++++++++++
gcc/rust/hir/rust-ast-lower-type.h | 2 ++
gcc/testsuite/rust/compile/auto_traits1.rs | 27 ++++++++++++++++++++++
3 files changed, 48 insertions(+)
create mode 100644 gcc/testsuite/rust/compile/auto_traits1.rs
diff --git a/gcc/rust/hir/rust-ast-lower-type.cc b/gcc/rust/hir/rust-ast-lower-type.cc
index df06e48b801..d1f95edc345 100644
--- a/gcc/rust/hir/rust-ast-lower-type.cc
+++ b/gcc/rust/hir/rust-ast-lower-type.cc
@@ -19,6 +19,7 @@
#include "rust-ast-lower-type.h"
#include "rust-hir-map.h"
#include "rust-hir-path.h"
+#include "rust-hir-type.h"
#include "rust-path.h"
#include "rust-pattern.h"
@@ -471,6 +472,24 @@ ASTLoweringType::visit (AST::TraitObjectType &type)
type.get_locus (), type.is_dyn ());
}
+void
+ASTLoweringType::visit (AST::ParenthesisedType &type)
+{
+ auto *inner = ASTLoweringType::translate (*type.get_type_in_parens (),
+ default_to_static_lifetime);
+
+ auto crate_num = mappings.get_current_crate ();
+ Analysis::NodeMapping mapping (crate_num, type.get_node_id (),
+ mappings.get_next_hir_id (crate_num),
+ mappings.get_next_localdef_id (crate_num));
+
+ // FIXME: Do we actually need to know if a type is parenthesized in the HIR?
+ // or can we just use the type in parens?
+ translated
+ = new HIR::ParenthesisedType (mapping, std::unique_ptr<HIR::Type> (inner),
+ type.get_locus ());
+}
+
HIR::GenericParam *
ASTLowerGenericParam::translate (AST::GenericParam ¶m)
{
diff --git a/gcc/rust/hir/rust-ast-lower-type.h b/gcc/rust/hir/rust-ast-lower-type.h
index 0429e3fcf98..26ca8684083 100644
--- a/gcc/rust/hir/rust-ast-lower-type.h
+++ b/gcc/rust/hir/rust-ast-lower-type.h
@@ -22,6 +22,7 @@
#include "rust-ast-lower-base.h"
#include "rust-ast-lower-expr.h"
#include "rust-hir-path.h"
+#include "rust-type.h"
namespace Rust {
namespace HIR {
@@ -83,6 +84,7 @@ public:
void visit (AST::NeverType &type) override;
void visit (AST::TraitObjectTypeOneBound &type) override;
void visit (AST::TraitObjectType &type) override;
+ void visit (AST::ParenthesisedType &type) override;
private:
ASTLoweringType (bool default_to_static_lifetime)
diff --git a/gcc/testsuite/rust/compile/auto_traits1.rs b/gcc/testsuite/rust/compile/auto_traits1.rs
new file mode 100644
index 00000000000..192052d4815
--- /dev/null
+++ b/gcc/testsuite/rust/compile/auto_traits1.rs
@@ -0,0 +1,27 @@
+// { dg-additional-options "-frust-compile-until=typecheck" }
+
+#![feature(optin_builtin_traits)]
+
+pub unsafe auto trait Send {}
+#[lang = "sync"]
+pub unsafe auto trait Sync {}
+
+trait A {
+ fn a_method(&self) {}
+}
+
+fn foo(a: &(dyn A + Send + Sync)) {
+ a.a_method();
+}
+
+struct S;
+
+impl A for S {
+ fn a_method(&self) {}
+}
+
+fn main() {
+ let s = S;
+
+ foo(&s);
+}
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 095/146] gccrs: tychk: Add more support for additional trait bounds in functions
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (93 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 094/146] gccrs: lower: Correctly lower parenthesized types arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 096/146] gccrs: nr2.0: Resolve type aliases inside trait definitions arthur.cohen
` (50 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
This commit correctly lowers and typechecks parenthesized types, which are used for trait objects with additional bounds.
gcc/rust/ChangeLog:
* resolve/rust-ast-resolve-type.cc (ResolveType::visit): New visitor to handle
ParenthesizedType.
* resolve/rust-ast-resolve-type.h: Likewise.
* typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit): Likewise.
* typecheck/rust-hir-type-check-type.h: Likewise.
gcc/testsuite/ChangeLog:
* rust/compile/auto_traits2.rs: New test.
* rust/compile/auto_traits3.rs: New test.
* rust/compile/nr2/exclude: Add auto_traits2 test.
---
gcc/rust/resolve/rust-ast-resolve-type.cc | 6 ++++
gcc/rust/resolve/rust-ast-resolve-type.h | 3 ++
.../typecheck/rust-hir-type-check-type.cc | 6 ++++
gcc/rust/typecheck/rust-hir-type-check-type.h | 4 +--
gcc/testsuite/rust/compile/auto_traits2.rs | 26 ++++++++++++++
gcc/testsuite/rust/compile/auto_traits3.rs | 34 +++++++++++++++++++
gcc/testsuite/rust/compile/nr2/exclude | 2 ++
7 files changed, 78 insertions(+), 3 deletions(-)
create mode 100644 gcc/testsuite/rust/compile/auto_traits2.rs
create mode 100644 gcc/testsuite/rust/compile/auto_traits3.rs
diff --git a/gcc/rust/resolve/rust-ast-resolve-type.cc b/gcc/rust/resolve/rust-ast-resolve-type.cc
index cb5a18d5d47..1d004b1ba9b 100644
--- a/gcc/rust/resolve/rust-ast-resolve-type.cc
+++ b/gcc/rust/resolve/rust-ast-resolve-type.cc
@@ -50,6 +50,12 @@ ResolveType::visit (AST::TraitObjectType &type)
}
}
+void
+ResolveType::visit (AST::ParenthesisedType &type)
+{
+ resolved_node = ResolveType::go (*type.get_type_in_parens ());
+}
+
void
ResolveType::visit (AST::ReferenceType &type)
{
diff --git a/gcc/rust/resolve/rust-ast-resolve-type.h b/gcc/rust/resolve/rust-ast-resolve-type.h
index 518c0d80b14..5e8cdb11b2d 100644
--- a/gcc/rust/resolve/rust-ast-resolve-type.h
+++ b/gcc/rust/resolve/rust-ast-resolve-type.h
@@ -24,6 +24,7 @@
#include "rust-diagnostics.h"
#include "rust-hir-map.h"
#include "rust-path.h"
+#include "rust-type.h"
#include "util/rust-hir-map.h"
namespace Rust {
@@ -143,6 +144,8 @@ public:
void visit (AST::TraitObjectType &type) override;
+ void visit (AST::ParenthesisedType &type) override;
+
void visit (AST::SliceType &type) override;
private:
diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.cc b/gcc/rust/typecheck/rust-hir-type-check-type.cc
index 4ea1a493fa8..859cdfedcd0 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-type.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-type.cc
@@ -790,6 +790,12 @@ TypeCheckType::visit (HIR::TraitObjectType &type)
std::move (specified_bounds));
}
+void
+TypeCheckType::visit (HIR::ParenthesisedType &type)
+{
+ translated = TypeCheckType::Resolve (type.get_type_in_parens ());
+}
+
void
TypeCheckType::visit (HIR::ArrayType &type)
{
diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.h b/gcc/rust/typecheck/rust-hir-type-check-type.h
index bf5589cbbab..1da01b869dd 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-type.h
+++ b/gcc/rust/typecheck/rust-hir-type-check-type.h
@@ -59,6 +59,7 @@ public:
void visit (HIR::InferredType &type) override;
void visit (HIR::NeverType &type) override;
void visit (HIR::TraitObjectType &type) override;
+ void visit (HIR::ParenthesisedType &type) override;
void visit (HIR::TypePathSegmentFunction &segment) override
{ /* TODO */
@@ -69,9 +70,6 @@ public:
void visit (HIR::ImplTraitType &type) override
{ /* TODO */
}
- void visit (HIR::ParenthesisedType &type) override
- { /* TODO */
- }
void visit (HIR::ImplTraitTypeOneBound &type) override
{ /* TODO */
}
diff --git a/gcc/testsuite/rust/compile/auto_traits2.rs b/gcc/testsuite/rust/compile/auto_traits2.rs
new file mode 100644
index 00000000000..7d0dcc11cd2
--- /dev/null
+++ b/gcc/testsuite/rust/compile/auto_traits2.rs
@@ -0,0 +1,26 @@
+#![feature(optin_builtin_traits)]
+
+pub unsafe auto trait Send {}
+#[lang = "sync"]
+pub unsafe auto trait Sync {}
+
+trait A {
+ fn a_method(&self) {}
+}
+
+fn foo(a: &(dyn A + Send + Sync)) {
+ a.a_method();
+}
+
+struct S;
+
+impl A for S {
+ fn a_method(&self) {}
+}
+
+fn main() {
+ let s = S;
+
+ foo(&s); // { dg-error "bounds not satisfied" }
+ // { dg-error "mismatched type" "" { target *-*-* } .-1 }
+}
diff --git a/gcc/testsuite/rust/compile/auto_traits3.rs b/gcc/testsuite/rust/compile/auto_traits3.rs
new file mode 100644
index 00000000000..81c39ecda7f
--- /dev/null
+++ b/gcc/testsuite/rust/compile/auto_traits3.rs
@@ -0,0 +1,34 @@
+#![feature(optin_builtin_traits)]
+
+pub unsafe auto trait Send {}
+#[lang = "sync"]
+pub unsafe auto trait Sync {}
+
+trait A {
+ fn a_method(&self) {}
+}
+
+fn foo(a: &(dyn A + Send + Sync)) {
+ a.a_method();
+}
+
+struct S;
+
+impl A for S {
+ fn a_method(&self) {} // { dg-warning "unused" }
+}
+
+// These should not be necessary because they are both auto traits
+// They need to be removed once we figure out the proper implementation for each of them
+// However, it'd be silly to implement other traits in order to ensure the test is okay,
+// as these extra trait bounds are only allowed to use auto traits
+// FIXME: #3327
+// FIXME: #3326
+unsafe impl Send for S {}
+unsafe impl Sync for S {}
+
+fn main() {
+ let s = S;
+
+ foo(&s);
+}
diff --git a/gcc/testsuite/rust/compile/nr2/exclude b/gcc/testsuite/rust/compile/nr2/exclude
index 2a5bc94b646..e23669f309b 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -207,4 +207,6 @@ issue-2907.rs
issue-2423.rs
issue-266.rs
additional-trait-bounds2.rs
+auto_traits2.rs
+auto_traits3.rs
# please don't delete the trailing newline
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 096/146] gccrs: nr2.0: Resolve type aliases inside trait definitions
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (94 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 095/146] gccrs: tychk: Add more support for additional trait bounds in functions arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 097/146] gccrs: ast: Add new Kind enums for more precise downcasting arthur.cohen
` (49 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Owen Avery
From: Owen Avery <powerboat9.gamer@gmail.com>
gcc/rust/ChangeLog:
* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::visit): Add visitor for TraitItemType.
* resolve/rust-toplevel-name-resolver-2.0.h
(TopLevel::visit): Likewise.
gcc/testsuite/ChangeLog:
* rust/compile/nr2/exclude: Remove entries.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
---
gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc | 9 +++++++++
gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h | 1 +
gcc/testsuite/rust/compile/nr2/exclude | 5 -----
3 files changed, 10 insertions(+), 5 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 6d52fcaaac8..4833233e025 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
@@ -109,6 +109,15 @@ TopLevel::visit (AST::Trait &trait)
DefaultResolver::visit (trait);
}
+void
+TopLevel::visit (AST::TraitItemType &trait_item)
+{
+ insert_or_error_out (trait_item.get_identifier ().as_string (), trait_item,
+ Namespace::Types);
+
+ DefaultResolver::visit (trait_item);
+}
+
template <typename PROC_MACRO>
static void
insert_macros (std::vector<PROC_MACRO> ¯os, NameResolutionContext &ctx)
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 7f4e29585de..f540ab9ae61 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h
@@ -148,6 +148,7 @@ private:
void visit (AST::Module &module) override;
void visit (AST::Trait &trait) override;
+ void visit (AST::TraitItemType &trait_item) override;
void visit (AST::MacroRulesDefinition ¯o) override;
void visit (AST::Function &function) override;
void visit (AST::BlockExpr &expr) override;
diff --git a/gcc/testsuite/rust/compile/nr2/exclude b/gcc/testsuite/rust/compile/nr2/exclude
index e23669f309b..da5880d9a57 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -74,8 +74,6 @@ issue-2139.rs
issue-2142.rs
issue-2165.rs
issue-2166.rs
-issue-2190-1.rs
-issue-2190-2.rs
issue-2238.rs
issue-2304.rs
issue-2330.rs
@@ -85,7 +83,6 @@ issue-2723-1.rs
issue-2723-2.rs
issue-2772-2.rs
issue-2775.rs
-issue-2747.rs
issue-2782.rs
issue-2812.rs
issue-850.rs
@@ -98,7 +95,6 @@ macros/mbe/macro-issue1233.rs
macros/mbe/macro-issue1400.rs
macros/mbe/macro13.rs
macros/mbe/macro15.rs
-macros/mbe/macro20.rs
macros/mbe/macro23.rs
macros/mbe/macro40.rs
macros/mbe/macro43.rs
@@ -198,7 +194,6 @@ iflet.rs
issue-3033.rs
issue-3009.rs
issue-2323.rs
-issue-2953-1.rs
issue-2953-2.rs
issue-1773.rs
issue-2905-1.rs
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 097/146] gccrs: ast: Add new Kind enums for more precise downcasting
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (95 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 096/146] gccrs: nr2.0: Resolve type aliases inside trait definitions arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 098/146] gccrs: use StackedContexts for block context arthur.cohen
` (48 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
This commit adds things like Item::Kind, Expr::Kind, etc, and implements the associated `get_*_kind` functions.
It also removes the more generic AST::Kind enum we were using, which was incomplete and painful to use.
gcc/rust/ChangeLog:
* ast/rust-ast.h: Add new Kind enums, remove Node class.
* ast/rust-builtin-ast-nodes.h: Use new Kind enums.
* ast/rust-expr.h (class LoopLabel): Likewise.
* ast/rust-item.h: Likewise.
* ast/rust-macro.h: Likewise.
* ast/rust-path.h: Likewise.
* expand/rust-macro-builtins-helpers.cc: Likewise.
* expand/rust-macro-builtins-utility.cc (MacroBuiltin::concat_handler): Likewise.
(MacroBuiltin::stringify_handler): Likewise.
* resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit): Likewise.
* resolve/rust-early-name-resolver.cc: Likewise.
* hir/rust-ast-lower.cc (ASTLoweringBlock::visit): Likewise.
---
gcc/rust/ast/rust-ast.h | 94 +++++++++++++------
gcc/rust/ast/rust-builtin-ast-nodes.h | 2 +
gcc/rust/ast/rust-expr.h | 84 ++++++++++++++++-
gcc/rust/ast/rust-item.h | 36 ++++++-
gcc/rust/ast/rust-macro.h | 34 ++++---
gcc/rust/ast/rust-path.h | 10 ++
.../expand/rust-macro-builtins-helpers.cc | 2 +-
.../expand/rust-macro-builtins-utility.cc | 4 +-
gcc/rust/hir/rust-ast-lower.cc | 6 +-
gcc/rust/resolve/rust-ast-resolve-expr.cc | 2 +-
gcc/rust/resolve/rust-early-name-resolver.cc | 10 +-
11 files changed, 229 insertions(+), 55 deletions(-)
diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h
index 42ad0119231..5e724d184de 100644
--- a/gcc/rust/ast/rust-ast.h
+++ b/gcc/rust/ast/rust-ast.h
@@ -70,16 +70,6 @@ namespace AST {
class ASTVisitor;
using AttrVec = std::vector<Attribute>;
-// The available kinds of AST Nodes
-enum class Kind
-{
- UNKNOWN,
- MODULE,
- MACRO_RULES_DEFINITION,
- MACRO_INVOCATION,
- IDENTIFIER,
-};
-
class Visitable
{
public:
@@ -87,20 +77,6 @@ public:
virtual void accept_vis (ASTVisitor &vis) = 0;
};
-// Abstract base class for all AST elements
-class Node : public Visitable
-{
-public:
- /**
- * Get the kind of Node this is. This is used to differentiate various AST
- * elements with very little overhead when extracting the derived type
- * through static casting is not necessary.
- */
- // FIXME: Mark this as `= 0` in the future to make sure every node
- // implements it
- virtual Kind get_ast_kind () const { return Kind::UNKNOWN; }
-};
-
// Delimiter types - used in macros and whatever.
enum DelimType
{
@@ -1092,7 +1068,7 @@ class MetaListNameValueStr;
/* Base statement abstract class. Note that most "statements" are not allowed
* in top-level module scope - only a subclass of statements called "items"
* are. */
-class Stmt : public Node
+class Stmt : public Visitable
{
public:
enum class Kind
@@ -1141,6 +1117,28 @@ protected:
class Item : public Stmt
{
public:
+ enum class Kind
+ {
+ MacroRulesDefinition,
+ MacroInvocation,
+ Module,
+ ExternCrate,
+ UseDeclaration,
+ Function,
+ TypeAlias,
+ Struct,
+ EnumItem,
+ Enum,
+ Union,
+ ConstantItem,
+ StaticItem,
+ Trait,
+ Impl,
+ ExternBlock,
+ };
+
+ virtual Kind get_item_kind () const = 0;
+
// Unique pointer custom clone function
std::unique_ptr<Item> clone_item () const
{
@@ -1221,14 +1219,54 @@ public:
{
return outer_attrs;
}
+
+ virtual Item::Kind get_item_kind () const override = 0;
};
+
// forward decl of ExprWithoutBlock
class ExprWithoutBlock;
// Base expression AST node - abstract
-class Expr : public Node
+class Expr : public Visitable
{
public:
+ enum class Kind
+ {
+ PathInExpression,
+ QualifiedPathInExpression,
+ Literal,
+ Operator,
+ Grouped,
+ Array,
+ ArrayIndex,
+ Tuple,
+ TupleIndex,
+ Struct,
+ Call,
+ MethodCall,
+ FieldAccess,
+ Closure,
+ Block,
+ Continue,
+ Break,
+ Range,
+ Box,
+ Return,
+ UnsafeBlock,
+ Loop,
+ If,
+ IfLet,
+ Match,
+ Await,
+ AsyncBlock,
+ InlineAsm,
+ Identifier,
+ FormatArgs,
+ MacroInvocation,
+ };
+
+ virtual Kind get_expr_kind () const = 0;
+
// Unique pointer custom clone function
std::unique_ptr<Expr> clone_expr () const
{
@@ -1343,7 +1381,7 @@ public:
outer_attrs = std::move (new_attrs);
}
- Kind get_ast_kind () const override { return Kind::IDENTIFIER; }
+ Expr::Kind get_expr_kind () const override { return Expr::Kind::Identifier; }
protected:
// Clone method implementation
@@ -1410,7 +1448,7 @@ protected:
class TraitBound;
// Base class for types as represented in AST - abstract
-class Type : public Node
+class Type : public Visitable
{
public:
// Unique pointer custom clone function
diff --git a/gcc/rust/ast/rust-builtin-ast-nodes.h b/gcc/rust/ast/rust-builtin-ast-nodes.h
index 7ebd656b584..3684092aca2 100644
--- a/gcc/rust/ast/rust-builtin-ast-nodes.h
+++ b/gcc/rust/ast/rust-builtin-ast-nodes.h
@@ -202,6 +202,8 @@ public:
const FormatArguments &get_arguments () const { return arguments; }
virtual location_t get_locus () const override;
+ Expr::Kind get_expr_kind () const override { return Expr::Kind::FormatArgs; }
+
private:
location_t loc;
// FIXME: This probably needs to be a separate type - it is one in rustc's
diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h
index 483e599652b..852c3f3a3a4 100644
--- a/gcc/rust/ast/rust-expr.h
+++ b/gcc/rust/ast/rust-expr.h
@@ -15,7 +15,7 @@ namespace AST {
// Loop label expression AST node used with break and continue expressions
// TODO: inline?
-class LoopLabel /*: public Node*/
+class LoopLabel /*: public Visitable*/
{
Lifetime label; // or type LIFETIME_OR_LABEL
location_t locus;
@@ -117,6 +117,8 @@ public:
outer_attrs = std::move (new_attrs);
}
+ Expr::Kind get_expr_kind () const override { return Expr::Kind::Literal; }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -365,6 +367,8 @@ public:
{
outer_attrs = std::move (new_attrs);
}
+
+ Expr::Kind get_expr_kind () const override { return Expr::Kind::Operator; }
};
/* Unary prefix & or &mut (or && and &&mut) borrow operator. Cannot be
@@ -1090,6 +1094,8 @@ public:
return expr_in_parens;
}
+ Expr::Kind get_expr_kind () const override { return Expr::Kind::Grouped; }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -1319,6 +1325,8 @@ public:
return internal_elements;
}
+ Expr::Kind get_expr_kind () const override { return Expr::Kind::Array; }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -1424,6 +1432,8 @@ public:
outer_attrs = std::move (new_attrs);
}
+ Expr::Kind get_expr_kind () const override { return Expr::Kind::ArrayIndex; }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -1520,6 +1530,8 @@ public:
bool is_unit () const { return tuple_elems.size () == 0; }
+ Expr::Kind get_expr_kind () const override { return Expr::Kind::Tuple; }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -1607,6 +1619,8 @@ public:
outer_attrs = std::move (new_attrs);
}
+ Expr::Kind get_expr_kind () const override { return Expr::Kind::TupleIndex; }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -1650,6 +1664,8 @@ public:
{
outer_attrs = std::move (new_attrs);
}
+
+ Expr::Kind get_expr_kind () const override { return Expr::Kind::Struct; }
};
// Actual AST node of the struct creator (with no fields). Not abstract!
@@ -2131,6 +2147,8 @@ public:
outer_attrs = std::move (new_attrs);
}
+ Expr::Kind get_expr_kind () const override { return Expr::Kind::Call; }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -2234,6 +2252,8 @@ public:
outer_attrs = std::move (new_attrs);
}
+ Expr::Kind get_expr_kind () const override { return Expr::Kind::MethodCall; }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -2319,6 +2339,8 @@ public:
outer_attrs = std::move (new_attrs);
}
+ Expr::Kind get_expr_kind () const override { return Expr::Kind::FieldAccess; }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -2454,6 +2476,8 @@ public:
}
bool get_has_move () const { return has_move; }
+
+ Expr::Kind get_expr_kind () const override { return Expr::Kind::Closure; }
};
// Represents a non-type-specified closure expression AST node
@@ -2675,6 +2699,8 @@ public:
bool has_label () { return !label.is_error (); }
LoopLabel &get_label () { return label; }
+ Expr::Kind get_expr_kind () const override { return Expr::Kind::Block; }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -2828,6 +2854,8 @@ public:
Lifetime &get_label () { return label; }
+ Expr::Kind get_expr_kind () const override { return Expr::Kind::Continue; }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -2924,6 +2952,8 @@ public:
LoopLabel &get_label () { return label; }
+ Expr::Kind get_expr_kind () const override { return Expr::Kind::Break; }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -2956,6 +2986,8 @@ public:
{
rust_assert (false);
}
+
+ Expr::Kind get_expr_kind () const override { return Expr::Kind::Range; }
};
// Range from (inclusive) and to (exclusive) expression AST node object
@@ -3404,6 +3436,8 @@ public:
return *expr;
}
+ Expr::Kind get_expr_kind () const override { return Expr::Kind::Box; }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -3491,6 +3525,8 @@ public:
outer_attrs = std::move (new_attrs);
}
+ Expr::Kind get_expr_kind () const override { return Expr::Kind::Return; }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -3573,6 +3609,8 @@ public:
outer_attrs = std::move (new_attrs);
}
+ Expr::Kind get_expr_kind () const override { return Expr::Kind::UnsafeBlock; }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -3661,6 +3699,18 @@ public:
{
outer_attrs = std::move (new_attrs);
}
+
+ Expr::Kind get_expr_kind () const override { return Expr::Kind::Loop; }
+
+ enum class Kind
+ {
+ Loop,
+ While,
+ WhileLet,
+ For
+ };
+
+ virtual Kind get_loop_kind () const = 0;
};
// 'Loop' expression (i.e. the infinite loop) AST node
@@ -3679,6 +3729,11 @@ public:
void accept_vis (ASTVisitor &vis) override;
+ BaseLoopExpr::Kind get_loop_kind () const override
+ {
+ return BaseLoopExpr::Kind::Loop;
+ }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -3737,6 +3792,11 @@ public:
return *condition;
}
+ BaseLoopExpr::Kind get_loop_kind () const override
+ {
+ return BaseLoopExpr::Kind::While;
+ }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -3820,6 +3880,11 @@ public:
return match_arm_patterns;
}
+ BaseLoopExpr::Kind get_loop_kind () const override
+ {
+ return BaseLoopExpr::Kind::WhileLet;
+ }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -3889,6 +3954,11 @@ public:
return *pattern;
}
+ BaseLoopExpr::Kind get_loop_kind () const override
+ {
+ return BaseLoopExpr::Kind::For;
+ }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -4012,6 +4082,8 @@ public:
const std::vector<Attribute> &get_outer_attrs () const { return outer_attrs; }
std::vector<Attribute> &get_outer_attrs () override { return outer_attrs; }
+ Expr::Kind get_expr_kind () const override { return Expr::Kind::If; }
+
protected:
// Base clone function but still concrete as concrete base class
virtual IfExpr *clone_if_expr_impl () const { return new IfExpr (*this); }
@@ -4206,6 +4278,8 @@ public:
const std::vector<Attribute> &get_outer_attrs () const { return outer_attrs; }
std::vector<Attribute> &get_outer_attrs () override { return outer_attrs; }
+ Expr::Kind get_expr_kind () const override { return Expr::Kind::IfLet; }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base (or rather this or any derived object) */
@@ -4535,6 +4609,8 @@ public:
const std::vector<MatchCase> &get_match_cases () const { return match_arms; }
std::vector<MatchCase> &get_match_cases () { return match_arms; }
+ Expr::Kind get_expr_kind () const override { return Expr::Kind::Match; }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -4614,6 +4690,8 @@ public:
outer_attrs = std::move (new_attrs);
}
+ Expr::Kind get_expr_kind () const override { return Expr::Kind::Await; }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -4696,6 +4774,8 @@ public:
outer_attrs = std::move (new_attrs);
}
+ Expr::Kind get_expr_kind () const override { return Expr::Kind::AsyncBlock; }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -5209,6 +5289,8 @@ public:
{
return new InlineAsm (*this);
}
+
+ Expr::Kind get_expr_kind () const override { return Expr::Kind::InlineAsm; }
};
} // namespace AST
diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h
index ecd355f6b8a..0baefdc367c 100644
--- a/gcc/rust/ast/rust-item.h
+++ b/gcc/rust/ast/rust-item.h
@@ -758,8 +758,6 @@ public:
Identifier get_name () const { return module_name; }
- AST::Kind get_ast_kind () const override { return AST::Kind::MODULE; }
-
private:
Identifier module_name;
location_t locus;
@@ -899,6 +897,8 @@ public:
void mark_for_strip () override { module_name = {""}; }
bool is_marked_for_strip () const override { return module_name.empty (); }
+ Item::Kind get_item_kind () const override { return Item::Kind::Module; }
+
protected:
/* Use covariance to implement clone function as returning this object
* rather than base */
@@ -960,6 +960,8 @@ public:
return referenced_crate.empty ();
}
+ Item::Kind get_item_kind () const override { return Item::Kind::ExternCrate; }
+
protected:
/* Use covariance to implement clone function as returning this object
* rather than base */
@@ -1301,6 +1303,11 @@ public:
void mark_for_strip () override { use_tree = nullptr; }
bool is_marked_for_strip () const override { return use_tree == nullptr; }
+ Item::Kind get_item_kind () const override
+ {
+ return Item::Kind::UseDeclaration;
+ }
+
protected:
/* Use covariance to implement clone function as returning this object
* rather than base */
@@ -1459,6 +1466,8 @@ public:
// ExternalItem::node_id is same as Stmt::node_id
NodeId get_node_id () const override { return Stmt::node_id; }
+ Item::Kind get_item_kind () const override { return Item::Kind::Function; }
+
protected:
/* Use covariance to implement clone function as returning this object
* rather than base */
@@ -1590,6 +1599,8 @@ public:
Identifier get_new_type_name () const { return new_type_name; }
+ Item::Kind get_item_kind () const override { return Item::Kind::TypeAlias; }
+
protected:
/* Use covariance to implement clone function as returning this object
* rather than base */
@@ -1649,6 +1660,8 @@ public:
Identifier get_identifier () const { return struct_name; }
+ Item::Kind get_item_kind () const override { return Item::Kind::Struct; }
+
protected:
Struct (Identifier struct_name,
std::vector<std::unique_ptr<GenericParam>> generic_params,
@@ -2058,6 +2071,8 @@ public:
void mark_for_strip () override { variant_name = {""}; }
bool is_marked_for_strip () const override { return variant_name.empty (); }
+ Item::Kind get_item_kind () const override { return Item::Kind::EnumItem; }
+
protected:
EnumItem *clone_item_impl () const override { return new EnumItem (*this); }
};
@@ -2321,6 +2336,8 @@ public:
// TODO: is this better? Or is a "vis_block" better?
WhereClause &get_where_clause () { return where_clause; }
+ Item::Kind get_item_kind () const override { return Item::Kind::Enum; }
+
protected:
/* Use covariance to implement clone function as returning this object
* rather than base */
@@ -2420,6 +2437,8 @@ public:
Identifier get_identifier () const { return union_name; }
+ Item::Kind get_item_kind () const override { return Item::Kind::Union; }
+
protected:
/* Use covariance to implement clone function as returning this object
* rather than base */
@@ -2541,6 +2560,11 @@ public:
std::string get_identifier () const { return identifier; }
+ Item::Kind get_item_kind () const override
+ {
+ return Item::Kind::ConstantItem;
+ }
+
protected:
/* Use covariance to implement clone function as returning this object
* rather than base */
@@ -2662,6 +2686,8 @@ public:
Identifier get_identifier () const { return name; }
+ Item::Kind get_item_kind () const override { return Item::Kind::StaticItem; }
+
protected:
/* Use covariance to implement clone function as returning this object
* rather than base */
@@ -3025,6 +3051,8 @@ public:
AST::TypeParam &get_implicit_self () { return self_param; }
+ Item::Kind get_item_kind () const override { return Item::Kind::Trait; }
+
protected:
/* Use covariance to implement clone function as returning this object
* rather than base */
@@ -3097,6 +3125,8 @@ public:
return trait_type;
}
+ Item::Kind get_item_kind () const override { return Item::Kind::Impl; }
+
protected:
// Mega-constructor
Impl (std::vector<std::unique_ptr<GenericParam>> generic_params,
@@ -3982,6 +4012,8 @@ public:
const std::vector<Attribute> &get_inner_attrs () const { return inner_attrs; }
std::vector<Attribute> &get_inner_attrs () { return inner_attrs; }
+ Item::Kind get_item_kind () const override { return Item::Kind::ExternBlock; }
+
protected:
/* Use covariance to implement clone function as returning this object
* rather than base */
diff --git a/gcc/rust/ast/rust-macro.h b/gcc/rust/ast/rust-macro.h
index a953b75155c..fc01e571b91 100644
--- a/gcc/rust/ast/rust-macro.h
+++ b/gcc/rust/ast/rust-macro.h
@@ -28,6 +28,7 @@
namespace Rust {
namespace AST {
+
class MacroFragSpec
{
public:
@@ -571,13 +572,13 @@ public:
is_builtin_rule = true;
}
- AST::Kind get_ast_kind () const override
+ MacroKind get_kind () const { return kind; }
+
+ Item::Kind get_item_kind () const override
{
- return AST::Kind::MACRO_RULES_DEFINITION;
+ return Item::Kind::MacroRulesDefinition;
}
- MacroKind get_kind () const { return kind; }
-
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -609,11 +610,6 @@ public:
std::string as_string () const override;
- Pattern::Kind get_pattern_kind () override
- {
- return Pattern::Kind::MacroInvocation;
- }
-
/**
* The default constructor you should use. Whenever we parse a macro call, we
* cannot possibly know whether or not this call refers to a builtin macro or
@@ -676,11 +672,6 @@ public:
return ExprWithoutBlock::get_node_id ();
}
- AST::Kind get_ast_kind () const override
- {
- return AST::Kind::MACRO_INVOCATION;
- }
-
NodeId get_macro_node_id () const { return node_id; }
MacroInvocData &get_invoc_data () { return invoc_data; }
@@ -799,6 +790,21 @@ public:
void add_semicolon () override { is_semi_coloned = true; }
+ Pattern::Kind get_pattern_kind () override
+ {
+ return Pattern::Kind::MacroInvocation;
+ }
+
+ Expr::Kind get_expr_kind () const override
+ {
+ return Expr::Kind::MacroInvocation;
+ }
+
+ Item::Kind get_item_kind () const override
+ {
+ return Item::Kind::MacroInvocation;
+ }
+
protected:
Item *clone_item_impl () const override
{
diff --git a/gcc/rust/ast/rust-path.h b/gcc/rust/ast/rust-path.h
index 4e26b2f9f3b..b7eba446540 100644
--- a/gcc/rust/ast/rust-path.h
+++ b/gcc/rust/ast/rust-path.h
@@ -850,6 +850,11 @@ public:
Pattern::Kind get_pattern_kind () override { return Pattern::Kind::Path; }
+ Expr::Kind get_expr_kind () const override
+ {
+ return Expr::Kind::PathInExpression;
+ }
+
protected:
PathInExpression (std::vector<Attribute> &&outer_attrs,
bool has_opening_scope_resolution, location_t locus,
@@ -1516,6 +1521,11 @@ public:
rust_unreachable ();
}
+ Expr::Kind get_expr_kind () const override
+ {
+ return Expr::Kind::QualifiedPathInExpression;
+ }
+
protected:
/* Use covariance to implement clone function as returning this object
* rather than base */
diff --git a/gcc/rust/expand/rust-macro-builtins-helpers.cc b/gcc/rust/expand/rust-macro-builtins-helpers.cc
index 55d113c81c3..864379a3ffa 100644
--- a/gcc/rust/expand/rust-macro-builtins-helpers.cc
+++ b/gcc/rust/expand/rust-macro-builtins-helpers.cc
@@ -36,7 +36,7 @@ check_for_eager_invocations (
std::vector<std::unique_ptr<AST::MacroInvocation>> pending;
for (auto &expr : expressions)
- if (expr->get_ast_kind () == AST::Kind::MACRO_INVOCATION)
+ if (expr->get_expr_kind () == AST::Expr::Kind::MacroInvocation)
pending.emplace_back (std::unique_ptr<AST::MacroInvocation> (
static_cast<AST::MacroInvocation *> (expr->clone_expr ().release ())));
diff --git a/gcc/rust/expand/rust-macro-builtins-utility.cc b/gcc/rust/expand/rust-macro-builtins-utility.cc
index 2da7d1865de..9ea854ef42d 100644
--- a/gcc/rust/expand/rust-macro-builtins-utility.cc
+++ b/gcc/rust/expand/rust-macro-builtins-utility.cc
@@ -117,7 +117,7 @@ MacroBuiltin::concat_handler (location_t invoc_locus,
for (auto &expr : expanded_expr)
{
if (!expr->is_literal ()
- && expr->get_ast_kind () != AST::Kind::MACRO_INVOCATION)
+ && expr->get_expr_kind () != AST::Expr::Kind::MacroInvocation)
{
has_error = true;
rust_error_at (expr->get_locus (), "expected a literal");
@@ -296,4 +296,4 @@ MacroBuiltin::stringify_handler (location_t invoc_locus,
return AST::Fragment ({node}, std::move (token));
}
-} // namespace Rust
\ No newline at end of file
+} // namespace Rust
diff --git a/gcc/rust/hir/rust-ast-lower.cc b/gcc/rust/hir/rust-ast-lower.cc
index c5e2250f29e..a94a8432273 100644
--- a/gcc/rust/hir/rust-ast-lower.cc
+++ b/gcc/rust/hir/rust-ast-lower.cc
@@ -104,7 +104,11 @@ ASTLoweringBlock::visit (AST::BlockExpr &expr)
for (auto &s : expr.get_statements ())
{
- if (s->get_ast_kind () == AST::Kind::MACRO_INVOCATION)
+ // FIXME: We basically need to do that check for *every* single node in
+ // the AST. this isn't realistic and this should be turned into an
+ // optional, debug-visitor instead, which goes through the entire AST and
+ // checks if any of the nodes are macro invocations
+ if (s->get_stmt_kind () == AST::Stmt::Kind::MacroInvocation)
rust_fatal_error (
s->get_locus (),
"macro invocations should not get lowered to HIR - At "
diff --git a/gcc/rust/resolve/rust-ast-resolve-expr.cc b/gcc/rust/resolve/rust-ast-resolve-expr.cc
index 7ddf4a98f22..6524376a011 100644
--- a/gcc/rust/resolve/rust-ast-resolve-expr.cc
+++ b/gcc/rust/resolve/rust-ast-resolve-expr.cc
@@ -537,7 +537,7 @@ ResolveExpr::visit (AST::BreakExpr &expr)
{
bool funny_error = false;
auto &break_expr = expr.get_break_expr ();
- if (break_expr.get_ast_kind () == AST::Kind::IDENTIFIER)
+ if (break_expr.get_expr_kind () == AST::Expr::Kind::Identifier)
{
/* This is a break with an expression, and the expression is
just a single identifier. See if the identifier is either
diff --git a/gcc/rust/resolve/rust-early-name-resolver.cc b/gcc/rust/resolve/rust-early-name-resolver.cc
index a46b57f4448..34bac98534c 100644
--- a/gcc/rust/resolve/rust-early-name-resolver.cc
+++ b/gcc/rust/resolve/rust-early-name-resolver.cc
@@ -17,7 +17,7 @@
// <http://www.gnu.org/licenses/>.
#include "rust-early-name-resolver.h"
-#include "rust-ast-full.h"
+#include "rust-pattern.h"
#include "rust-name-resolver.h"
#include "rust-macro-builtins.h"
#include "rust-attribute-values.h"
@@ -53,7 +53,7 @@ EarlyNameResolver::accumulate_escaped_macros (AST::Module &module)
scoped (module.get_node_id (), [&module, &escaped_macros, this] {
for (auto &item : module.get_items ())
{
- if (item->get_ast_kind () == AST::Kind::MODULE)
+ if (item->get_item_kind () == AST::Item::Kind::Module)
{
auto &module = *static_cast<AST::Module *> (item.get ());
auto new_macros = accumulate_escaped_macros (module);
@@ -64,7 +64,7 @@ EarlyNameResolver::accumulate_escaped_macros (AST::Module &module)
continue;
}
- if (item->get_ast_kind () == AST::Kind::MACRO_RULES_DEFINITION)
+ if (item->get_item_kind () == AST::Item::Kind::MacroRulesDefinition)
escaped_macros.emplace_back (item->clone_item ());
}
});
@@ -113,7 +113,7 @@ EarlyNameResolver::visit (AST::Crate &crate)
{
auto new_macros = std::vector<std::unique_ptr<AST::Item>> ();
- if (item->get_ast_kind () == AST::Kind::MODULE)
+ if (item->get_item_kind () == AST::Item::Kind::Module)
new_macros = accumulate_escaped_macros (
*static_cast<AST::Module *> (item.get ()));
@@ -300,7 +300,7 @@ EarlyNameResolver::visit (AST::Module &module)
{
auto new_macros = std::vector<std::unique_ptr<AST::Item>> ();
- if (item->get_ast_kind () == AST::Kind::MODULE)
+ if (item->get_item_kind () == AST::Item::Kind::Module)
new_macros = accumulate_escaped_macros (
*static_cast<AST::Module *> (item.get ()));
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 098/146] gccrs: use StackedContexts for block context
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (96 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 097/146] gccrs: ast: Add new Kind enums for more precise downcasting arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 099/146] gccrs: fix ICE during HIR dump arthur.cohen
` (47 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Prajwal S N
From: Prajwal S N <prajwalnadig21@gmail.com>
Replaces the DIY vector stack with a StackedContexts object for block
scopes in the type checker context.
Fixes #3284.
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check.h (class TypeCheckContext): add
header file and use StackedContexts for blocks
* typecheck/rust-typecheck-context.cc: update methods
* typecheck/rust-hir-trait-resolve.cc: refactor function calls
* typecheck/rust-hir-type-check-implitem.cc: refactor function calls
* typecheck/rust-hir-type-check-type.cc: refactor function calls
Signed-off-by: Prajwal S N <prajwalnadig21@gmail.com>
---
gcc/rust/typecheck/rust-hir-trait-resolve.cc | 4 +--
.../typecheck/rust-hir-type-check-implitem.cc | 5 ++--
.../typecheck/rust-hir-type-check-type.cc | 7 ++---
gcc/rust/typecheck/rust-hir-type-check.h | 8 +++---
gcc/rust/typecheck/rust-typecheck-context.cc | 26 +++----------------
5 files changed, 15 insertions(+), 35 deletions(-)
diff --git a/gcc/rust/typecheck/rust-hir-trait-resolve.cc b/gcc/rust/typecheck/rust-hir-trait-resolve.cc
index 14e26f4512b..82019328e16 100644
--- a/gcc/rust/typecheck/rust-hir-trait-resolve.cc
+++ b/gcc/rust/typecheck/rust-hir-trait-resolve.cc
@@ -278,7 +278,7 @@ TraitResolver::resolve_trait (HIR::Trait *trait_reference)
}
self->inherit_bounds (specified_bounds);
- context->push_block_context (TypeCheckBlockContextItem (trait_reference));
+ context->block_context ().enter (TypeCheckBlockContextItem (trait_reference));
std::vector<TraitItemReference> item_refs;
for (auto &item : trait_reference->get_trait_items ())
{
@@ -308,7 +308,7 @@ TraitResolver::resolve_trait (HIR::Trait *trait_reference)
// resolve the blocks of functions etc because it can end up in a recursive
// loop of trying to resolve traits as required by the types
tref->on_resolved ();
- context->pop_block_context ();
+ context->block_context ().exit ();
return tref;
}
diff --git a/gcc/rust/typecheck/rust-hir-type-check-implitem.cc b/gcc/rust/typecheck/rust-hir-type-check-implitem.cc
index 4521822410c..937a8a8d0ef 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-implitem.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-implitem.cc
@@ -335,9 +335,10 @@ TypeCheckImplItem::Resolve (
// resolve
TypeCheckImplItem resolver (parent, self, substitutions);
- resolver.context->push_block_context (TypeCheckBlockContextItem (&parent));
+ resolver.context->block_context ().enter (
+ TypeCheckBlockContextItem (&parent));
item.accept_vis (resolver);
- resolver.context->pop_block_context ();
+ resolver.context->block_context ().exit ();
return resolver.result;
}
diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.cc b/gcc/rust/typecheck/rust-hir-type-check-type.cc
index 859cdfedcd0..bb23f8441ed 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-type.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-type.cc
@@ -591,10 +591,11 @@ TypeCheckType::resolve_segments (
bool first_segment = i == offset;
bool selfResolveOk = false;
- if (first_segment && tySegIsBigSelf && context->have_block_context ()
- && context->peek_block_context ().is_impl_block ())
+ if (first_segment && tySegIsBigSelf
+ && context->block_context ().is_in_context ()
+ && context->block_context ().peek ().is_impl_block ())
{
- TypeCheckBlockContextItem ctx = context->peek_block_context ();
+ TypeCheckBlockContextItem ctx = context->block_context ().peek ();
TyTy::BaseType *lookup = nullptr;
selfResolveOk
= resolve_associated_type (seg->as_string (), ctx, &lookup);
diff --git a/gcc/rust/typecheck/rust-hir-type-check.h b/gcc/rust/typecheck/rust-hir-type-check.h
index 08c3d354f79..ef1f2dd0214 100644
--- a/gcc/rust/typecheck/rust-hir-type-check.h
+++ b/gcc/rust/typecheck/rust-hir-type-check.h
@@ -22,6 +22,7 @@
#include "rust-hir-map.h"
#include "rust-tyty.h"
#include "rust-hir-trait-reference.h"
+#include "rust-stacked-contexts.h"
#include "rust-autoderef.h"
#include "rust-tyty-region.h"
#include "rust-tyty-variance-analysis.h"
@@ -186,10 +187,7 @@ public:
TyTy::BaseType *return_type);
void pop_return_type ();
- bool have_block_context () const;
- TypeCheckBlockContextItem peek_block_context ();
- void push_block_context (TypeCheckBlockContextItem item);
- void pop_block_context ();
+ StackedContexts<TypeCheckBlockContextItem> &block_context ();
void iterate (std::function<bool (HirId, TyTy::BaseType *)> cb);
@@ -282,7 +280,7 @@ private:
std::vector<std::pair<TypeCheckContextItem, TyTy::BaseType *>>
return_type_stack;
std::vector<TyTy::BaseType *> loop_type_stack;
- std::vector<TypeCheckBlockContextItem> block_stack;
+ StackedContexts<TypeCheckBlockContextItem> block_stack;
std::map<DefId, TraitReference> trait_context;
std::map<HirId, TyTy::BaseType *> receiver_context;
std::map<HirId, AssociatedImplTrait> associated_impl_traits;
diff --git a/gcc/rust/typecheck/rust-typecheck-context.cc b/gcc/rust/typecheck/rust-typecheck-context.cc
index e72ce41606d..8ff8839f733 100644
--- a/gcc/rust/typecheck/rust-typecheck-context.cc
+++ b/gcc/rust/typecheck/rust-typecheck-context.cc
@@ -177,30 +177,10 @@ TypeCheckContext::peek_context ()
return return_type_stack.back ().first;
}
-bool
-TypeCheckContext::have_block_context () const
-{
- return !block_stack.empty ();
-}
-
-TypeCheckBlockContextItem
-TypeCheckContext::peek_block_context ()
-{
- rust_assert (!block_stack.empty ());
- return block_stack.back ();
-}
-
-void
-TypeCheckContext::push_block_context (TypeCheckBlockContextItem block)
-{
- block_stack.push_back (block);
-}
-
-void
-TypeCheckContext::pop_block_context ()
+StackedContexts<TypeCheckBlockContextItem> &
+TypeCheckContext::block_context ()
{
- rust_assert (!block_stack.empty ());
- block_stack.pop_back ();
+ return block_stack;
}
void
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 099/146] gccrs: fix ICE during HIR dump
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (97 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 098/146] gccrs: use StackedContexts for block context arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 100/146] gccrs: nr2.0: Improve default, top-level, and late resolvers arthur.cohen
` (46 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Philip Herron
From: Philip Herron <herron.philip@googlemail.com>
These hir nodes have optional expressions which need guarded
gcc/rust/ChangeLog:
* hir/rust-hir-dump.cc (Dump::do_qualifiedpathtype): add guard
(Dump::do_traitfunctiondecl): likewise
(Dump::visit): likewise
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
---
gcc/rust/hir/rust-hir-dump.cc | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/gcc/rust/hir/rust-hir-dump.cc b/gcc/rust/hir/rust-hir-dump.cc
index 2590eed19ae..5acf53e9296 100644
--- a/gcc/rust/hir/rust-hir-dump.cc
+++ b/gcc/rust/hir/rust-hir-dump.cc
@@ -404,7 +404,8 @@ Dump::do_qualifiedpathtype (QualifiedPathType &e)
do_mappings (e.get_mappings ());
visit_field ("type", e.get_type ());
- visit_field ("trait", e.get_trait ());
+ if (e.has_as_clause ())
+ visit_field ("trait", e.get_trait ());
}
void
@@ -521,7 +522,8 @@ Dump::do_traitfunctiondecl (TraitFunctionDecl &e)
else
put_field ("function_params", "empty");
- visit_field ("return_type", e.get_return_type ());
+ if (e.has_return_type ())
+ visit_field ("return_type", e.get_return_type ());
if (e.has_where_clause ())
put_field ("where_clause", e.get_where_clause ().as_string ());
@@ -1295,7 +1297,8 @@ Dump::visit (BreakExpr &e)
else
put_field ("label", "none");
- visit_field ("break_expr ", e.get_expr ());
+ if (e.has_break_expr ())
+ visit_field ("break_expr ", e.get_expr ());
end ("BreakExpr");
}
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 100/146] gccrs: nr2.0: Improve default, top-level, and late resolvers
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (98 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 099/146] gccrs: fix ICE during HIR dump arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 101/146] gccrs: fix ICE in borrows to invalid expressions arthur.cohen
` (45 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Owen Avery
From: Owen Avery <powerboat9.gamer@gmail.com>
gcc/rust/ChangeLog:
* resolve/rust-default-resolver.cc
(DefaultResolver::visit): Make sure to scope visitation of the
children of type definition items.
* resolve/rust-default-resolver.h
(DefaultResolver::visit): Add overrides for TupleStruct, Union,
and TypeAlias.
* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): Remove override for Enum.
* resolve/rust-late-name-resolver-2.0.h
(Late::visit): Likewise.
* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::visit): Rely more on DefaultResolver::visit.
* resolve/rust-toplevel-name-resolver-2.0.h
(TopLevel::visit): Remove override for BlockExpr.
gcc/testsuite/ChangeLog:
* rust/compile/nr2/exclude: Remove entries.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
---
gcc/rust/resolve/rust-default-resolver.cc | 35 ++++++++++---
gcc/rust/resolve/rust-default-resolver.h | 3 ++
.../resolve/rust-late-name-resolver-2.0.cc | 7 ---
.../resolve/rust-late-name-resolver-2.0.h | 1 -
.../rust-toplevel-name-resolver-2.0.cc | 50 ++++---------------
.../resolve/rust-toplevel-name-resolver-2.0.h | 1 -
gcc/testsuite/rust/compile/nr2/exclude | 9 ----
7 files changed, 41 insertions(+), 65 deletions(-)
diff --git a/gcc/rust/resolve/rust-default-resolver.cc b/gcc/rust/resolve/rust-default-resolver.cc
index 57b1cc44815..7528e7950e6 100644
--- a/gcc/rust/resolve/rust-default-resolver.cc
+++ b/gcc/rust/resolve/rust-default-resolver.cc
@@ -88,27 +88,48 @@ DefaultResolver::visit (AST::TraitImpl &impl)
void
DefaultResolver::visit (AST::StructStruct &type)
{
- // do we need to scope anything here? no, right?
+ auto inner_fn = [this, &type] () { AST::DefaultASTVisitor::visit (type); };
- // we also can't visit `StructField`s by default, so there's nothing to do -
- // correct? or should we do something like
+ ctx.scoped (Rib::Kind::Item /* FIXME: Correct? */, type.get_node_id (),
+ inner_fn, type.get_struct_name ());
+}
- AST::DefaultASTVisitor::visit (type);
+void
+DefaultResolver::visit (AST::TupleStruct &type)
+{
+ auto inner_fn = [this, &type] () { AST::DefaultASTVisitor::visit (type); };
- // FIXME: ???
+ ctx.scoped (Rib::Kind::Item /* FIXME: Correct? */, type.get_node_id (),
+ inner_fn, type.get_struct_name ());
}
void
DefaultResolver::visit (AST::Enum &type)
{
- // FIXME: Do we need to scope anything by default?
-
auto variant_fn = [this, &type] () { AST::DefaultASTVisitor::visit (type); };
ctx.scoped (Rib::Kind::Item /* FIXME: Correct? */, type.get_node_id (),
variant_fn, type.get_identifier ());
}
+void
+DefaultResolver::visit (AST::Union &type)
+{
+ auto inner_fn = [this, &type] () { AST::DefaultASTVisitor::visit (type); };
+
+ ctx.scoped (Rib::Kind::Item /* FIXME: Correct? */, type.get_node_id (),
+ inner_fn, type.get_identifier ());
+}
+
+void
+DefaultResolver::visit (AST::TypeAlias &type)
+{
+ auto inner_fn = [this, &type] () { AST::DefaultASTVisitor::visit (type); };
+
+ ctx.scoped (Rib::Kind::Item /* FIXME: Correct? */, type.get_node_id (),
+ inner_fn, type.get_new_type_name ());
+}
+
void
DefaultResolver::visit (AST::ClosureExprInner &expr)
{
diff --git a/gcc/rust/resolve/rust-default-resolver.h b/gcc/rust/resolve/rust-default-resolver.h
index 9fcddd15851..587d7d45803 100644
--- a/gcc/rust/resolve/rust-default-resolver.h
+++ b/gcc/rust/resolve/rust-default-resolver.h
@@ -52,7 +52,10 @@ public:
// type dec nodes, which visit their fields or variants by default
void visit (AST::StructStruct &) override;
+ void visit (AST::TupleStruct &) override;
void visit (AST::Enum &) override;
+ void visit (AST::Union &) override;
+ void visit (AST::TypeAlias &) override;
// Visitors that visit their expression node(s)
void visit (AST::ClosureExprInner &) override;
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 86fd5f12173..bb099ab68ae 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
@@ -308,13 +308,6 @@ Late::visit (AST::StructStruct &s)
ctx.scoped (Rib::Kind::Item, s.get_node_id (), s_vis);
}
-void
-Late::visit (AST::Enum &s)
-{
- auto s_vis = [this, &s] () { AST::DefaultASTVisitor::visit (s); };
- ctx.scoped (Rib::Kind::Item, s.get_node_id (), s_vis);
-}
-
void
Late::visit (AST::StructExprStruct &s)
{
diff --git a/gcc/rust/resolve/rust-late-name-resolver-2.0.h b/gcc/rust/resolve/rust-late-name-resolver-2.0.h
index 803a5ec1c00..2af73c38286 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.h
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.h
@@ -53,7 +53,6 @@ public:
void visit (AST::StructExprStructBase &) override;
void visit (AST::StructExprStructFields &) override;
void visit (AST::StructStruct &) override;
- void visit (AST::Enum &) override;
void visit (AST::GenericArgs &) override;
void visit (AST::GenericArg &);
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 4833233e025..4aca709263c 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
@@ -87,13 +87,7 @@ TopLevel::visit (AST::Module &module)
if (module.get_kind () == AST::Module::UNLOADED)
module.load_items ();
- auto sub_visitor = [this, &module] () {
- for (auto &item : module.get_items ())
- item->accept_vis (*this);
- };
-
- ctx.scoped (Rib::Kind::Module, module.get_node_id (), sub_visitor,
- module.get_name ());
+ DefaultResolver::visit (module);
if (Analysis::Mappings::get ().lookup_ast_module (module.get_node_id ())
== tl::nullopt)
@@ -230,23 +224,6 @@ TopLevel::visit (AST::Function &function)
DefaultResolver::visit (function);
}
-void
-TopLevel::visit (AST::BlockExpr &expr)
-{
- // extracting the lambda from the `scoped` call otherwise the code looks like
- // a hot turd thanks to our .clang-format
-
- auto sub_vis = [this, &expr] () {
- for (auto &stmt : expr.get_statements ())
- stmt->accept_vis (*this);
-
- if (expr.has_tail_expr ())
- expr.get_tail_expr ().accept_vis (*this);
- };
-
- ctx.scoped (Rib::Kind::Normal, expr.get_node_id (), sub_vis);
-}
-
void
TopLevel::visit (AST::StaticItem &static_item)
{
@@ -261,6 +238,8 @@ TopLevel::visit (AST::ExternalStaticItem &static_item)
{
insert_or_error_out (static_item.get_identifier ().as_string (), static_item,
Namespace::Values);
+
+ DefaultResolver::visit (static_item);
}
void
@@ -291,6 +270,8 @@ TopLevel::visit (AST::TypeParam &type_param)
{
insert_or_error_out (type_param.get_type_representation (), type_param,
Namespace::Types);
+
+ DefaultResolver::visit (type_param);
}
void
@@ -309,6 +290,8 @@ TopLevel::visit (AST::TupleStruct &tuple_struct)
insert_or_error_out (tuple_struct.get_struct_name (), tuple_struct,
Namespace::Values);
+
+ DefaultResolver::visit (tuple_struct);
}
void
@@ -338,25 +321,10 @@ TopLevel::visit (AST::EnumItemDiscriminant &variant)
void
TopLevel::visit (AST::Enum &enum_item)
{
- auto generic_vis = [this, &enum_item] () {
- for (auto &g : enum_item.get_generic_params ())
- {
- g->accept_vis (*this);
- }
- };
-
- ctx.scoped (Rib::Kind::Item, enum_item.get_node_id (), generic_vis);
-
insert_or_error_out (enum_item.get_identifier (), enum_item,
Namespace::Types);
- auto field_vis = [this, &enum_item] () {
- for (auto &variant : enum_item.get_variants ())
- variant->accept_vis (*this);
- };
-
- ctx.scoped (Rib::Kind::Item /* FIXME: Is that correct? */,
- enum_item.get_node_id (), field_vis, enum_item.get_identifier ());
+ DefaultResolver::visit (enum_item);
}
void
@@ -364,6 +332,8 @@ TopLevel::visit (AST::Union &union_item)
{
insert_or_error_out (union_item.get_identifier (), union_item,
Namespace::Types);
+
+ DefaultResolver::visit (union_item);
}
void
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 f540ab9ae61..64d2174a7be 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h
@@ -151,7 +151,6 @@ private:
void visit (AST::TraitItemType &trait_item) override;
void visit (AST::MacroRulesDefinition ¯o) override;
void visit (AST::Function &function) override;
- void visit (AST::BlockExpr &expr) override;
void visit (AST::StaticItem &static_item) override;
void visit (AST::ExternalStaticItem &static_item) override;
void visit (AST::StructStruct &struct_item) override;
diff --git a/gcc/testsuite/rust/compile/nr2/exclude b/gcc/testsuite/rust/compile/nr2/exclude
index da5880d9a57..945a697f677 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -25,7 +25,6 @@ derive_macro3.rs
derive_macro4.rs
derive_macro6.rs
expected_type_args2.rs
-expected_type_args3.rs
feature_rust_attri0.rs
for_lifetimes.rs
format_args_basic_expansion.rs
@@ -33,12 +32,10 @@ generic-default1.rs
generics1.rs
generics10.rs
generics11.rs
-generics2.rs
generics3.rs
generics4.rs
generics5.rs
generics6.rs
-generics8.rs
generics9.rs
if_let_expr.rs
issue-1019.rs
@@ -46,9 +43,7 @@ issue-1031.rs
issue-1034.rs
issue-1129-2.rs
issue-1130.rs
-issue-1165.rs
issue-1173.rs
-issue-1235.rs
issue-1272.rs
issue-1289.rs
issue-1447.rs
@@ -66,7 +61,6 @@ issue-2036.rs
issue-2037.rs
issue-2043.rs
issue-2070.rs
-issue-2105.rs
issue-2135.rs
issue-2136-1.rs
issue-2136-2.rs
@@ -117,7 +111,6 @@ multiple_bindings1.rs
multiple_bindings2.rs
name_resolution2.rs
name_resolution4.rs
-nested_generic.rs
nested_macro_use1.rs
nested_macro_use2.rs
nested_macro_use3.rs
@@ -142,7 +135,6 @@ pub_restricted_3.rs
redef_error2.rs
redef_error4.rs
redef_error5.rs
-redef_error6.rs
self-path1.rs
self-path2.rs
sizeof-stray-infer-var-bug.rs
@@ -193,7 +185,6 @@ if_let_expr_simple.rs
iflet.rs
issue-3033.rs
issue-3009.rs
-issue-2323.rs
issue-2953-2.rs
issue-1773.rs
issue-2905-1.rs
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 101/146] gccrs: fix ICE in borrows to invalid expressions
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (99 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 100/146] gccrs: nr2.0: Improve default, top-level, and late resolvers arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 102/146] gccrs: add support for lang_item eq and PartialEq trait arthur.cohen
` (44 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Philip Herron
From: Philip Herron <herron.philip@googlemail.com>
We need to check if the borrowed value is valid before creating the
reference type. Otherwise this will lead to an ICE.
Fixes Rust-GCC#3140
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): check for error
* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): likewise and remove debug error
gcc/testsuite/ChangeLog:
* rust/compile/issue-3046.rs: remove old error message
* rust/compile/nr2/exclude: nr2 cant handle this
* rust/compile/issue-3140.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
---
.../typecheck/rust-hir-type-check-expr.cc | 2 ++
gcc/rust/typecheck/rust-tyty-call.cc | 9 ++-----
gcc/testsuite/rust/compile/issue-3046.rs | 4 +--
gcc/testsuite/rust/compile/issue-3140.rs | 27 +++++++++++++++++++
gcc/testsuite/rust/compile/nr2/exclude | 1 +
5 files changed, 33 insertions(+), 10 deletions(-)
create mode 100644 gcc/testsuite/rust/compile/issue-3140.rs
diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
index 5a96c359d7c..2ea8b4127e6 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
@@ -1366,6 +1366,8 @@ void
TypeCheckExpr::visit (HIR::BorrowExpr &expr)
{
TyTy::BaseType *resolved_base = TypeCheckExpr::Resolve (expr.get_expr ());
+ if (resolved_base->is<TyTy::ErrorType> ())
+ return;
// In Rust this is valid because of DST's
//
diff --git a/gcc/rust/typecheck/rust-tyty-call.cc b/gcc/rust/typecheck/rust-tyty-call.cc
index 5fea34de40a..2e0830e4ada 100644
--- a/gcc/rust/typecheck/rust-tyty-call.cc
+++ b/gcc/rust/typecheck/rust-tyty-call.cc
@@ -140,13 +140,8 @@ TypeCheckCallExpr::visit (FnType &type)
{
location_t arg_locus = argument->get_locus ();
auto argument_expr_tyty = Resolver::TypeCheckExpr::Resolve (*argument);
- if (argument_expr_tyty->get_kind () == TyTy::TypeKind::ERROR)
- {
- rust_error_at (
- argument->get_locus (),
- "failed to resolve type for argument expr in CallExpr");
- return;
- }
+ if (argument_expr_tyty->is<TyTy::ErrorType> ())
+ return;
// it might be a variadic function
if (i < type.num_params ())
diff --git a/gcc/testsuite/rust/compile/issue-3046.rs b/gcc/testsuite/rust/compile/issue-3046.rs
index c982cc98f58..f0c72a3cef4 100644
--- a/gcc/testsuite/rust/compile/issue-3046.rs
+++ b/gcc/testsuite/rust/compile/issue-3046.rs
@@ -12,12 +12,10 @@ fn test(v: LOption) -> Res {
return Res::BAD;
}
-
fn main() {
// Should be:
// test(LOption::Some(2));
- //
+ //
test(LOption(2));
// { dg-error "expected function, tuple struct or tuple variant, found enum" "" { target *-*-* } .-1 }
- // { dg-error "failed to resolve type for argument expr in CallExpr" "" { target *-*-* } .-2 }
}
diff --git a/gcc/testsuite/rust/compile/issue-3140.rs b/gcc/testsuite/rust/compile/issue-3140.rs
new file mode 100644
index 00000000000..dcf86db5616
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-3140.rs
@@ -0,0 +1,27 @@
+enum State {
+ Succeeded,
+ Failed,
+}
+
+fn print_on_failure(state: &State) {
+ let mut num = 0;
+ match *state {
+ // error: expected unit struct, unit variant or constant, found tuple
+ // variant `State::Failed`
+ State::Failed => {
+ num = 1;
+ }
+ State::Succeeded => {
+ num = 2;
+ }
+ _ => (),
+ }
+}
+
+fn main() {
+ let b = State::Failed(1);
+ // { dg-error "expected function, tuple struct or tuple variant, found struct .State." "" { target *-*-* } .-1 }
+
+ print_on_failure(&b);
+ // { dg-error "cannot find value .b. in this scope" "" { target *-*-* } .-1 }
+}
diff --git a/gcc/testsuite/rust/compile/nr2/exclude b/gcc/testsuite/rust/compile/nr2/exclude
index 945a697f677..e7344ed0d59 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -195,4 +195,5 @@ issue-266.rs
additional-trait-bounds2.rs
auto_traits2.rs
auto_traits3.rs
+issue-3140.rs
# please don't delete the trailing newline
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 102/146] gccrs: add support for lang_item eq and PartialEq trait
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (100 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 101/146] gccrs: fix ICE in borrows to invalid expressions arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 103/146] gccrs: fix ICE with hir dump on closure arthur.cohen
` (43 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Philip Herron
From: Philip Herron <herron.philip@googlemail.com>
The Eq and Partial Ord are very similar to the operator overloads
we support for add/sub/etc... but they differ in that usually the
function call name matches the name of the lang item. This time
we need to have support to send in a new path for the method call
on the lang item we want instead of just the name of the lang item.
NOTE: this test case doesnt work correctly yet we need to support
the derive of partial eq on enums to generate the correct comparison
code for that.
Fixes Rust-GCC#3302
gcc/rust/ChangeLog:
* backend/rust-compile-expr.cc (CompileExpr::visit): handle partial_eq possible call
* backend/rust-compile-expr.h: handle case where lang item calls differ from name
* hir/tree/rust-hir-expr.cc (OperatorExprMeta::OperatorExprMeta): new helper
* hir/tree/rust-hir-expr.h: likewise
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): handle partial_eq
(TypeCheckExpr::resolve_operator_overload): likewise
* typecheck/rust-hir-type-check-expr.h: likewise
* util/rust-lang-item.cc (LangItem::ComparisonToLangItem): map comparison to lang item
(LangItem::ComparisonToSegment): likewise
* util/rust-lang-item.h: new lang items PartialOrd and Eq
* util/rust-operators.h (enum class): likewise
gcc/testsuite/ChangeLog:
* rust/compile/nr2/exclude: nr2 cant handle this
* rust/compile/cmp1.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
---
gcc/rust/backend/rust-compile-expr.cc | 28 ++++++-
gcc/rust/backend/rust-compile-expr.h | 4 +-
gcc/rust/hir/tree/rust-hir-expr.cc | 6 ++
gcc/rust/hir/tree/rust-hir-expr.h | 2 +
.../typecheck/rust-hir-type-check-expr.cc | 27 +++++--
gcc/rust/typecheck/rust-hir-type-check-expr.h | 4 +-
gcc/rust/util/rust-lang-item.cc | 44 +++++++++++
gcc/rust/util/rust-lang-item.h | 5 ++
gcc/rust/util/rust-operators.h | 8 +-
gcc/testsuite/rust/compile/cmp1.rs | 78 +++++++++++++++++++
gcc/testsuite/rust/compile/nr2/exclude | 1 +
11 files changed, 194 insertions(+), 13 deletions(-)
create mode 100644 gcc/testsuite/rust/compile/cmp1.rs
diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc
index e0fb1da3feb..900e080ea0e 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -279,6 +279,26 @@ CompileExpr::visit (HIR::ComparisonExpr &expr)
auto rhs = CompileExpr::Compile (expr.get_rhs (), ctx);
auto location = expr.get_locus ();
+ // this might be an operator overload situation lets check
+ TyTy::FnType *fntype;
+ bool is_op_overload = ctx->get_tyctx ()->lookup_operator_overload (
+ expr.get_mappings ().get_hirid (), &fntype);
+ if (is_op_overload)
+ {
+ auto seg_name = LangItem::ComparisonToSegment (expr.get_expr_type ());
+ auto segment = HIR::PathIdentSegment (seg_name);
+ auto lang_item_type
+ = LangItem::ComparisonToLangItem (expr.get_expr_type ());
+
+ rhs = address_expression (rhs, EXPR_LOCATION (rhs));
+
+ translated = resolve_operator_overload (
+ lang_item_type, expr, lhs, rhs, expr.get_lhs (),
+ tl::optional<std::reference_wrapper<HIR::Expr>> (expr.get_rhs ()),
+ segment);
+ return;
+ }
+
translated = Backend::comparison_expression (op, lhs, rhs, location);
}
@@ -1478,7 +1498,8 @@ CompileExpr::get_receiver_from_dyn (const TyTy::DynamicObjectType *dyn,
tree
CompileExpr::resolve_operator_overload (
LangItem::Kind lang_item_type, HIR::OperatorExprMeta expr, tree lhs, tree rhs,
- HIR::Expr &lhs_expr, tl::optional<std::reference_wrapper<HIR::Expr>> rhs_expr)
+ HIR::Expr &lhs_expr, tl::optional<std::reference_wrapper<HIR::Expr>> rhs_expr,
+ HIR::PathIdentSegment specified_segment)
{
TyTy::FnType *fntype;
bool is_op_overload = ctx->get_tyctx ()->lookup_operator_overload (
@@ -1499,7 +1520,10 @@ CompileExpr::resolve_operator_overload (
}
// lookup compiled functions since it may have already been compiled
- HIR::PathIdentSegment segment_name (LangItem::ToString (lang_item_type));
+ HIR::PathIdentSegment segment_name
+ = specified_segment.is_error ()
+ ? HIR::PathIdentSegment (LangItem::ToString (lang_item_type))
+ : specified_segment;
tree fn_expr = resolve_method_address (fntype, receiver, expr.get_locus ());
// lookup the autoderef mappings
diff --git a/gcc/rust/backend/rust-compile-expr.h b/gcc/rust/backend/rust-compile-expr.h
index b8c4220ded7..dc78dee3c8f 100644
--- a/gcc/rust/backend/rust-compile-expr.h
+++ b/gcc/rust/backend/rust-compile-expr.h
@@ -99,7 +99,9 @@ protected:
tree resolve_operator_overload (
LangItem::Kind lang_item_type, HIR::OperatorExprMeta expr, tree lhs,
tree rhs, HIR::Expr &lhs_expr,
- tl::optional<std::reference_wrapper<HIR::Expr>> rhs_expr);
+ tl::optional<std::reference_wrapper<HIR::Expr>> rhs_expr,
+ HIR::PathIdentSegment specified_segment
+ = HIR::PathIdentSegment::create_error ());
tree compile_bool_literal (const HIR::LiteralExpr &expr,
const TyTy::BaseType *tyty);
diff --git a/gcc/rust/hir/tree/rust-hir-expr.cc b/gcc/rust/hir/tree/rust-hir-expr.cc
index 4a902c65594..2ded789e60b 100644
--- a/gcc/rust/hir/tree/rust-hir-expr.cc
+++ b/gcc/rust/hir/tree/rust-hir-expr.cc
@@ -1298,6 +1298,12 @@ OperatorExprMeta::OperatorExprMeta (HIR::ArrayIndexExpr &expr)
locus (expr.get_locus ())
{}
+OperatorExprMeta::OperatorExprMeta (HIR::ComparisonExpr &expr)
+ : node_mappings (expr.get_mappings ()),
+ lvalue_mappings (expr.get_expr ().get_mappings ()),
+ locus (expr.get_locus ())
+{}
+
AnonConst::AnonConst (NodeId id, std::unique_ptr<Expr> expr)
: id (id), expr (std::move (expr))
{
diff --git a/gcc/rust/hir/tree/rust-hir-expr.h b/gcc/rust/hir/tree/rust-hir-expr.h
index 1273466b74c..f8f212884b6 100644
--- a/gcc/rust/hir/tree/rust-hir-expr.h
+++ b/gcc/rust/hir/tree/rust-hir-expr.h
@@ -2816,6 +2816,8 @@ public:
OperatorExprMeta (HIR::ArrayIndexExpr &expr);
+ OperatorExprMeta (HIR::ComparisonExpr &expr);
+
const Analysis::NodeMapping &get_mappings () const { return node_mappings; }
const Analysis::NodeMapping &get_lvalue_mappings () const
diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
index 2ea8b4127e6..7899b1a7943 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
@@ -344,6 +344,21 @@ TypeCheckExpr::visit (HIR::ComparisonExpr &expr)
auto lhs = TypeCheckExpr::Resolve (expr.get_lhs ());
auto rhs = TypeCheckExpr::Resolve (expr.get_rhs ());
+ auto borrowed_rhs
+ = new TyTy::ReferenceType (mappings.get_next_hir_id (),
+ TyTy::TyVar (rhs->get_ref ()), Mutability::Imm);
+ context->insert_implicit_type (borrowed_rhs->get_ref (), borrowed_rhs);
+
+ auto seg_name = LangItem::ComparisonToSegment (expr.get_expr_type ());
+ auto segment = HIR::PathIdentSegment (seg_name);
+ auto lang_item_type = LangItem::ComparisonToLangItem (expr.get_expr_type ());
+
+ bool operator_overloaded
+ = resolve_operator_overload (lang_item_type, expr, lhs, borrowed_rhs,
+ segment);
+ if (operator_overloaded)
+ return;
+
unify_site (expr.get_mappings ().get_hirid (),
TyTy::TyWithLocation (lhs, expr.get_lhs ().get_locus ()),
TyTy::TyWithLocation (rhs, expr.get_rhs ().get_locus ()),
@@ -1640,10 +1655,10 @@ TypeCheckExpr::visit (HIR::ClosureExpr &expr)
}
bool
-TypeCheckExpr::resolve_operator_overload (LangItem::Kind lang_item_type,
- HIR::OperatorExprMeta expr,
- TyTy::BaseType *lhs,
- TyTy::BaseType *rhs)
+TypeCheckExpr::resolve_operator_overload (
+ LangItem::Kind lang_item_type, HIR::OperatorExprMeta expr,
+ TyTy::BaseType *lhs, TyTy::BaseType *rhs,
+ HIR::PathIdentSegment specified_segment)
{
// look up lang item for arithmetic type
std::string associated_item_name = LangItem::ToString (lang_item_type);
@@ -1661,7 +1676,9 @@ TypeCheckExpr::resolve_operator_overload (LangItem::Kind lang_item_type,
current_context = context->peek_context ();
}
- auto segment = HIR::PathIdentSegment (associated_item_name);
+ auto segment = specified_segment.is_error ()
+ ? HIR::PathIdentSegment (associated_item_name)
+ : specified_segment;
auto candidates = MethodResolver::Probe (lhs, segment);
// remove any recursive candidates
diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.h b/gcc/rust/typecheck/rust-hir-type-check-expr.h
index 82f421e326a..2a0022ce701 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.h
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.h
@@ -97,7 +97,9 @@ public:
protected:
bool resolve_operator_overload (LangItem::Kind lang_item_type,
HIR::OperatorExprMeta expr,
- TyTy::BaseType *lhs, TyTy::BaseType *rhs);
+ TyTy::BaseType *lhs, TyTy::BaseType *rhs,
+ HIR::PathIdentSegment specified_segment
+ = HIR::PathIdentSegment::create_error ());
bool resolve_fn_trait_call (HIR::CallExpr &expr,
TyTy::BaseType *function_tyty,
diff --git a/gcc/rust/util/rust-lang-item.cc b/gcc/rust/util/rust-lang-item.cc
index c4c1d1c093a..4a609096144 100644
--- a/gcc/rust/util/rust-lang-item.cc
+++ b/gcc/rust/util/rust-lang-item.cc
@@ -98,6 +98,9 @@ const BiMap<std::string, LangItem::Kind> Rust::LangItem::lang_items = {{
{"into_iter", Kind::INTOITER_INTOITER},
{"next", Kind::ITERATOR_NEXT},
+
+ {"eq", Kind::EQ},
+ {"partial_ord", Kind::PARTIAL_ORD},
}};
tl::optional<LangItem::Kind>
@@ -145,6 +148,47 @@ LangItem::OperatorToLangItem (ArithmeticOrLogicalOperator op)
rust_unreachable ();
}
+LangItem::Kind
+LangItem::ComparisonToLangItem (ComparisonOperator op)
+{
+ switch (op)
+ {
+ case ComparisonOperator::NOT_EQUAL:
+ case ComparisonOperator::EQUAL:
+ return LangItem::Kind::EQ;
+
+ case ComparisonOperator::GREATER_THAN:
+ case ComparisonOperator::LESS_THAN:
+ case ComparisonOperator::GREATER_OR_EQUAL:
+ case ComparisonOperator::LESS_OR_EQUAL:
+ return LangItem::Kind::PARTIAL_ORD;
+ }
+
+ rust_unreachable ();
+}
+
+std::string
+LangItem::ComparisonToSegment (ComparisonOperator op)
+{
+ switch (op)
+ {
+ case ComparisonOperator::NOT_EQUAL:
+ return "ne";
+ case ComparisonOperator::EQUAL:
+ return "eq";
+ case ComparisonOperator::GREATER_THAN:
+ return "gt";
+ case ComparisonOperator::LESS_THAN:
+ return "lt";
+ case ComparisonOperator::GREATER_OR_EQUAL:
+ return "ge";
+ case ComparisonOperator::LESS_OR_EQUAL:
+ return "le";
+ }
+
+ rust_unreachable ();
+}
+
LangItem::Kind
LangItem::CompoundAssignmentOperatorToLangItem (ArithmeticOrLogicalOperator op)
{
diff --git a/gcc/rust/util/rust-lang-item.h b/gcc/rust/util/rust-lang-item.h
index 9e432e2ccc6..62b15d7b3fc 100644
--- a/gcc/rust/util/rust-lang-item.h
+++ b/gcc/rust/util/rust-lang-item.h
@@ -45,6 +45,8 @@ public:
NEGATION,
NOT,
+ EQ,
+ PARTIAL_ORD,
ADD_ASSIGN,
SUB_ASSIGN,
@@ -136,6 +138,9 @@ public:
static Kind
CompoundAssignmentOperatorToLangItem (ArithmeticOrLogicalOperator op);
static Kind NegationOperatorToLangItem (NegationOperator op);
+ static Kind ComparisonToLangItem (ComparisonOperator op);
+
+ static std::string ComparisonToSegment (ComparisonOperator op);
};
} // namespace Rust
diff --git a/gcc/rust/util/rust-operators.h b/gcc/rust/util/rust-operators.h
index 608e771828a..02b1820b28c 100644
--- a/gcc/rust/util/rust-operators.h
+++ b/gcc/rust/util/rust-operators.h
@@ -43,10 +43,10 @@ enum class ComparisonOperator
{
EQUAL, // std::cmp::PartialEq::eq
NOT_EQUAL, // std::cmp::PartialEq::ne
- GREATER_THAN, // std::cmp::PartialEq::gt
- LESS_THAN, // std::cmp::PartialEq::lt
- GREATER_OR_EQUAL, // std::cmp::PartialEq::ge
- LESS_OR_EQUAL // std::cmp::PartialEq::le
+ GREATER_THAN, // std::cmp::PartialOrd::gt
+ LESS_THAN, // std::cmp::PartialOrd::lt
+ GREATER_OR_EQUAL, // std::cmp::PartialOrd::ge
+ LESS_OR_EQUAL // std::cmp::PartialOrd::le
};
enum class LazyBooleanOperator
diff --git a/gcc/testsuite/rust/compile/cmp1.rs b/gcc/testsuite/rust/compile/cmp1.rs
new file mode 100644
index 00000000000..4da5b1c01fc
--- /dev/null
+++ b/gcc/testsuite/rust/compile/cmp1.rs
@@ -0,0 +1,78 @@
+// { dg-options "-w" }
+// taken from https://github.com/rust-lang/rust/blob/e1884a8e3c3e813aada8254edfa120e85bf5ffca/library/core/src/cmp.rs#L98
+
+#[lang = "sized"]
+pub trait Sized {}
+
+#[lang = "eq"]
+#[stable(feature = "rust1", since = "1.0.0")]
+#[doc(alias = "==")]
+#[doc(alias = "!=")]
+pub trait PartialEq<Rhs: ?Sized = Self> {
+ /// This method tests for `self` and `other` values to be equal, and is used
+ /// by `==`.
+ #[must_use]
+ #[stable(feature = "rust1", since = "1.0.0")]
+ fn eq(&self, other: &Rhs) -> bool;
+
+ /// This method tests for `!=`.
+ #[inline]
+ #[must_use]
+ #[stable(feature = "rust1", since = "1.0.0")]
+ fn ne(&self, other: &Rhs) -> bool {
+ !self.eq(other)
+ }
+}
+
+enum BookFormat {
+ Paperback,
+ Hardback,
+ Ebook,
+}
+
+impl PartialEq<BookFormat> for BookFormat {
+ fn eq(&self, other: &BookFormat) -> bool {
+ self == other
+ }
+}
+
+pub struct Book {
+ isbn: i32,
+ format: BookFormat,
+}
+
+// Implement <Book> == <BookFormat> comparisons
+impl PartialEq<BookFormat> for Book {
+ fn eq(&self, other: &BookFormat) -> bool {
+ self.format == *other
+ }
+}
+
+// Implement <BookFormat> == <Book> comparisons
+impl PartialEq<Book> for BookFormat {
+ fn eq(&self, other: &Book) -> bool {
+ *self == other.format
+ }
+}
+
+// Implement <Book> == <Book> comparisons
+impl PartialEq<Book> for Book {
+ fn eq(&self, other: &Book) -> bool {
+ self.isbn == other.isbn
+ }
+}
+
+pub fn main() {
+ let b1 = Book {
+ isbn: 1,
+ format: BookFormat::Paperback,
+ };
+ let b2 = Book {
+ isbn: 2,
+ format: BookFormat::Paperback,
+ };
+
+ let _c1: bool = b1 == BookFormat::Paperback;
+ let _c2: bool = BookFormat::Paperback == b2;
+ let _c3: bool = b1 != b2;
+}
diff --git a/gcc/testsuite/rust/compile/nr2/exclude b/gcc/testsuite/rust/compile/nr2/exclude
index e7344ed0d59..af7d105debc 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -196,4 +196,5 @@ additional-trait-bounds2.rs
auto_traits2.rs
auto_traits3.rs
issue-3140.rs
+cmp1.rs
# please don't delete the trailing newline
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 103/146] gccrs: fix ICE with hir dump on closure
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (101 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 102/146] gccrs: add support for lang_item eq and PartialEq trait arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 104/146] gccrs: nr2.0: Resolve Self inside impl blocks arthur.cohen
` (42 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Philip Herron
From: Philip Herron <herron.philip@googlemail.com>
Return type and parameter types are optional on closures.
gcc/rust/ChangeLog:
* hir/rust-hir-dump.cc (Dump::visit): add null guard
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
---
gcc/rust/hir/rust-hir-dump.cc | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/gcc/rust/hir/rust-hir-dump.cc b/gcc/rust/hir/rust-hir-dump.cc
index 5acf53e9296..798179d172e 100644
--- a/gcc/rust/hir/rust-hir-dump.cc
+++ b/gcc/rust/hir/rust-hir-dump.cc
@@ -1244,13 +1244,17 @@ Dump::visit (ClosureExpr &e)
auto oa = param.get_outer_attrs ();
do_outer_attrs (oa);
visit_field ("pattern", param.get_pattern ());
- visit_field ("type", param.get_type ());
+
+ if (param.has_type_given ())
+ visit_field ("type", param.get_type ());
+
end ("ClosureParam");
}
end_field ("params");
}
- visit_field ("return_type", e.get_return_type ());
+ if (e.has_return_type ())
+ visit_field ("return_type", e.get_return_type ());
visit_field ("expr", e.get_expr ());
end ("ClosureExpr");
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 104/146] gccrs: nr2.0: Resolve Self inside impl blocks
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (102 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 103/146] gccrs: fix ICE with hir dump on closure arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 105/146] gccrs: cleanup our enum type layout to be closer to rustc arthur.cohen
` (41 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Owen Avery
From: Owen Avery <powerboat9.gamer@gmail.com>
gcc/rust/ChangeLog:
* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::visit): Insert a definition for Self when visiting
InherentImpl and TraitImpl instances.
* resolve/rust-toplevel-name-resolver-2.0.h
(TopLevel::visit): Add visitors for InherentImpl and TraitImpl.
gcc/testsuite/ChangeLog:
* rust/compile/nr2/exclude: Remove entries.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
---
.../rust-toplevel-name-resolver-2.0.cc | 26 +++++++++++++++++++
.../resolve/rust-toplevel-name-resolver-2.0.h | 2 ++
gcc/testsuite/rust/compile/nr2/exclude | 3 ---
3 files changed, 28 insertions(+), 3 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 4aca709263c..4c6664f104b 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
@@ -103,6 +103,32 @@ TopLevel::visit (AST::Trait &trait)
DefaultResolver::visit (trait);
}
+void
+TopLevel::visit (AST::InherentImpl &impl)
+{
+ auto inner_fn = [this, &impl] () {
+ insert_or_error_out (Identifier ("Self", impl.get_type ().get_locus ()),
+ impl.get_type (), Namespace::Types);
+
+ AST::DefaultASTVisitor::visit (impl);
+ };
+
+ ctx.scoped (Rib::Kind::TraitOrImpl, impl.get_node_id (), inner_fn);
+}
+
+void
+TopLevel::visit (AST::TraitImpl &impl)
+{
+ auto inner_fn = [this, &impl] () {
+ insert_or_error_out (Identifier ("Self", impl.get_type ().get_locus ()),
+ impl.get_type (), Namespace::Types);
+
+ AST::DefaultASTVisitor::visit (impl);
+ };
+
+ ctx.scoped (Rib::Kind::TraitOrImpl, impl.get_node_id (), inner_fn);
+}
+
void
TopLevel::visit (AST::TraitItemType &trait_item)
{
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 64d2174a7be..fabcb5bf707 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h
@@ -148,6 +148,8 @@ private:
void visit (AST::Module &module) override;
void visit (AST::Trait &trait) override;
+ void visit (AST::InherentImpl &impl) override;
+ void visit (AST::TraitImpl &impl) override;
void visit (AST::TraitItemType &trait_item) override;
void visit (AST::MacroRulesDefinition ¯o) override;
void visit (AST::Function &function) override;
diff --git a/gcc/testsuite/rust/compile/nr2/exclude b/gcc/testsuite/rust/compile/nr2/exclude
index af7d105debc..9b1ee7ceaf9 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -39,13 +39,11 @@ generics6.rs
generics9.rs
if_let_expr.rs
issue-1019.rs
-issue-1031.rs
issue-1034.rs
issue-1129-2.rs
issue-1130.rs
issue-1173.rs
issue-1272.rs
-issue-1289.rs
issue-1447.rs
issue-1483.rs
issue-1725-1.rs
@@ -85,7 +83,6 @@ issue-855.rs
issue-925.rs
iterators1.rs
lookup_err1.rs
-macros/mbe/macro-issue1233.rs
macros/mbe/macro-issue1400.rs
macros/mbe/macro13.rs
macros/mbe/macro15.rs
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 105/146] gccrs: cleanup our enum type layout to be closer to rustc
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (103 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 104/146] gccrs: nr2.0: Resolve Self inside impl blocks arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 106/146] gccrs: Allow float type to be casted as integer type arthur.cohen
` (40 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Philip Herron
From: Philip Herron <herron.philip@googlemail.com>
This changes our enum type layout so for example:
enum Foo {
A,
B,
C(char),
D { x: i32, y: i32 },
}
Used to get layed out like this in gccrs:
union {
struct A { int RUST$ENUM$DISR; };
struct B { int RUST$ENUM$DISR; };
struct C { int RUST$ENUM$DISR; char __0; };
struct D { int RUST$ENUM$DISR; i64 x; i64 y; };
}
This has some issues notably with the constexpr because this is just a
giant union it means its not simple to constify what enum variant we are
looking at because the discriminant is a mess.
This now gets layed out as:
struct {
int RUST$ENUM$DISR;
union {
struct A { };
struct B { };
struct C { char __0; };
struct D { i64 x; i64 y; };
} payload;
}
This layout is much cleaner and allows for our constexpr to work properly.
gcc/rust/ChangeLog:
* backend/rust-compile-expr.cc (CompileExpr::visit): new layout
* backend/rust-compile-pattern.cc (CompilePatternCheckExpr::visit): likewise
(CompilePatternBindings::visit): likewise
* backend/rust-compile-resolve-path.cc: likewise
* backend/rust-compile-type.cc (TyTyResolveCompile::visit): implement new layout
* rust-gcc.cc (constructor_expression): get rid of useless assert
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
---
gcc/rust/backend/rust-compile-expr.cc | 74 +++++++++++--------
gcc/rust/backend/rust-compile-pattern.cc | 64 ++++++++--------
gcc/rust/backend/rust-compile-resolve-path.cc | 5 +-
gcc/rust/backend/rust-compile-type.cc | 62 ++++++++++++----
gcc/rust/rust-gcc.cc | 2 +-
5 files changed, 128 insertions(+), 79 deletions(-)
diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc
index 900e080ea0e..b40aa33866e 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -558,24 +558,32 @@ CompileExpr::visit (HIR::StructExprStructFields &struct_expr)
}
}
- // the constructor depends on whether this is actually an enum or not if
- // its an enum we need to setup the discriminator
- std::vector<tree> ctor_arguments;
- if (adt->is_enum ())
+ if (!adt->is_enum ())
{
- 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;
-
- ctor_arguments.push_back (qualifier);
+ translated
+ = Backend::constructor_expression (compiled_adt_type, adt->is_enum (),
+ arguments, union_disriminator,
+ struct_expr.get_locus ());
+ return;
}
- for (auto &arg : arguments)
- ctor_arguments.push_back (arg);
+
+ 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;
+
+ tree enum_root_files = TYPE_FIELDS (compiled_adt_type);
+ tree payload_root = DECL_CHAIN (enum_root_files);
+
+ tree payload = Backend::constructor_expression (TREE_TYPE (payload_root),
+ adt->is_enum (), arguments,
+ union_disriminator,
+ struct_expr.get_locus ());
+
+ std::vector<tree> ctor_arguments = {qualifier, payload};
translated
- = Backend::constructor_expression (compiled_adt_type, adt->is_enum (),
- ctor_arguments, union_disriminator,
+ = Backend::constructor_expression (compiled_adt_type, 0, ctor_arguments, -1,
struct_expr.get_locus ());
}
@@ -1247,26 +1255,34 @@ CompileExpr::visit (HIR::CallExpr &expr)
arguments.push_back (rvalue);
}
- // the constructor depends on whether this is actually an enum or not if
- // its an enum we need to setup the discriminator
- std::vector<tree> ctor_arguments;
- if (adt->is_enum ())
+ if (!adt->is_enum ())
{
- 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;
-
- ctor_arguments.push_back (qualifier);
+ translated
+ = Backend::constructor_expression (compiled_adt_type,
+ adt->is_enum (), arguments,
+ union_disriminator,
+ expr.get_locus ());
+ return;
}
- for (auto &arg : arguments)
- ctor_arguments.push_back (arg);
- translated
- = Backend::constructor_expression (compiled_adt_type, adt->is_enum (),
- ctor_arguments, union_disriminator,
+ 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;
+
+ tree enum_root_files = TYPE_FIELDS (compiled_adt_type);
+ tree payload_root = DECL_CHAIN (enum_root_files);
+
+ tree payload
+ = Backend::constructor_expression (TREE_TYPE (payload_root), true,
+ {arguments}, union_disriminator,
expr.get_locus ());
+ std::vector<tree> ctor_arguments = {qualifier, payload};
+ translated = Backend::constructor_expression (compiled_adt_type, false,
+ ctor_arguments, -1,
+ expr.get_locus ());
+
return;
}
diff --git a/gcc/rust/backend/rust-compile-pattern.cc b/gcc/rust/backend/rust-compile-pattern.cc
index bd534ff3bef..4e352fd3da3 100644
--- a/gcc/rust/backend/rust-compile-pattern.cc
+++ b/gcc/rust/backend/rust-compile-pattern.cc
@@ -21,6 +21,7 @@
#include "rust-compile-resolve-path.h"
#include "rust-constexpr.h"
#include "rust-compile-type.h"
+#include "print-tree.h"
namespace Rust {
namespace Compile {
@@ -57,11 +58,8 @@ CompilePatternCheckExpr::visit (HIR::PathInExpression &pattern)
rust_assert (ok);
// find discriminant field of scrutinee
- tree scrutinee_record_expr
- = Backend::struct_field_expression (match_scrutinee_expr, 0,
- pattern.get_locus ());
tree scrutinee_expr_qualifier_expr
- = Backend::struct_field_expression (scrutinee_record_expr, 0,
+ = Backend::struct_field_expression (match_scrutinee_expr, 0,
pattern.get_locus ());
// must be enum
@@ -227,11 +225,8 @@ CompilePatternCheckExpr::visit (HIR::StructPattern &pattern)
tree discrim_expr_node = CompileExpr::Compile (discrim_expr, ctx);
// find discriminant field of scrutinee
- tree scrutinee_record_expr
- = Backend::struct_field_expression (match_scrutinee_expr, variant_index,
- pattern.get_path ().get_locus ());
tree scrutinee_expr_qualifier_expr
- = Backend::struct_field_expression (scrutinee_record_expr, 0,
+ = Backend::struct_field_expression (match_scrutinee_expr, 0,
pattern.get_path ().get_locus ());
check_expr
@@ -240,7 +235,7 @@ CompilePatternCheckExpr::visit (HIR::StructPattern &pattern)
discrim_expr_node,
pattern.get_path ().get_locus ());
- match_scrutinee_expr = scrutinee_record_expr;
+ match_scrutinee_expr = scrutinee_expr_qualifier_expr;
}
else
{
@@ -295,8 +290,6 @@ CompilePatternCheckExpr::visit (HIR::StructPattern &pattern)
void
CompilePatternCheckExpr::visit (HIR::TupleStructPattern &pattern)
{
- size_t tuple_field_index;
-
// lookup the type
TyTy::BaseType *lookup = nullptr;
bool ok = ctx->get_tyctx ()->lookup_type (
@@ -307,6 +300,7 @@ CompilePatternCheckExpr::visit (HIR::TupleStructPattern &pattern)
rust_assert (lookup->get_kind () == TyTy::TypeKind::ADT);
TyTy::ADTType *adt = static_cast<TyTy::ADTType *> (lookup);
+ int variant_index = 0;
rust_assert (adt->number_of_variants () > 0);
TyTy::VariantDef *variant = nullptr;
if (adt->is_enum ())
@@ -317,7 +311,6 @@ CompilePatternCheckExpr::visit (HIR::TupleStructPattern &pattern)
pattern.get_path ().get_mappings ().get_hirid (), &variant_id);
rust_assert (ok);
- int variant_index = 0;
ok = adt->lookup_variant_by_id (variant_id, &variant, &variant_index);
rust_assert (ok);
@@ -326,11 +319,8 @@ CompilePatternCheckExpr::visit (HIR::TupleStructPattern &pattern)
tree discrim_expr_node = CompileExpr::Compile (discrim_expr, ctx);
// find discriminant field of scrutinee
- tree scrutinee_record_expr
- = Backend::struct_field_expression (match_scrutinee_expr, variant_index,
- pattern.get_path ().get_locus ());
tree scrutinee_expr_qualifier_expr
- = Backend::struct_field_expression (scrutinee_record_expr, 0,
+ = Backend::struct_field_expression (match_scrutinee_expr, 0,
pattern.get_path ().get_locus ());
check_expr
@@ -338,17 +328,11 @@ CompilePatternCheckExpr::visit (HIR::TupleStructPattern &pattern)
scrutinee_expr_qualifier_expr,
discrim_expr_node,
pattern.get_path ().get_locus ());
-
- match_scrutinee_expr = scrutinee_record_expr;
- // we are offsetting by + 1 here since the first field in the record
- // is always the discriminator
- tuple_field_index = 1;
}
else
{
variant = adt->get_variants ().at (0);
check_expr = boolean_true_node;
- tuple_field_index = 0;
}
HIR::TupleStructItems &items = pattern.get_items ();
@@ -367,10 +351,20 @@ CompilePatternCheckExpr::visit (HIR::TupleStructPattern &pattern)
rust_assert (items_no_range.get_patterns ().size ()
== variant->num_fields ());
+ size_t tuple_field_index = 0;
for (auto &pattern : items_no_range.get_patterns ())
{
+ // find payload union field of scrutinee
+ tree payload_ref
+ = Backend::struct_field_expression (match_scrutinee_expr, 1,
+ pattern->get_locus ());
+
+ tree variant_ref
+ = Backend::struct_field_expression (payload_ref, variant_index,
+ pattern->get_locus ());
+
tree field_expr
- = Backend::struct_field_expression (match_scrutinee_expr,
+ = Backend::struct_field_expression (variant_ref,
tuple_field_index++,
pattern->get_locus ());
@@ -470,13 +464,15 @@ CompilePatternBindings::visit (HIR::TupleStructPattern &pattern)
if (adt->is_enum ())
{
- // we are offsetting by + 1 here since the first field in the record
- // is always the discriminator
- size_t tuple_field_index = 1;
+ size_t tuple_field_index = 0;
for (auto &pattern : items_no_range.get_patterns ())
{
+ tree payload_accessor_union
+ = Backend::struct_field_expression (match_scrutinee_expr, 1,
+ pattern->get_locus ());
+
tree variant_accessor
- = Backend::struct_field_expression (match_scrutinee_expr,
+ = Backend::struct_field_expression (payload_accessor_union,
variant_index,
pattern->get_locus ());
@@ -569,16 +565,18 @@ CompilePatternBindings::visit (HIR::StructPattern &pattern)
tree binding = error_mark_node;
if (adt->is_enum ())
{
+ tree payload_accessor_union
+ = Backend::struct_field_expression (match_scrutinee_expr, 1,
+ ident.get_locus ());
+
tree variant_accessor
- = Backend::struct_field_expression (match_scrutinee_expr,
+ = Backend::struct_field_expression (payload_accessor_union,
variant_index,
ident.get_locus ());
- // we are offsetting by + 1 here since the first field in the
- // record is always the discriminator
- binding = Backend::struct_field_expression (variant_accessor,
- offs + 1,
- ident.get_locus ());
+ binding
+ = Backend::struct_field_expression (variant_accessor, offs,
+ ident.get_locus ());
}
else
{
diff --git a/gcc/rust/backend/rust-compile-resolve-path.cc b/gcc/rust/backend/rust-compile-resolve-path.cc
index 31ebbf14b74..69599cc6185 100644
--- a/gcc/rust/backend/rust-compile-resolve-path.cc
+++ b/gcc/rust/backend/rust-compile-resolve-path.cc
@@ -86,8 +86,9 @@ ResolvePathRef::attempt_constructor_expression_lookup (
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);
+ // false for is enum but this is an enum but we have a new layout
+ return Backend::constructor_expression (compiled_adt_type, false, {qualifier},
+ -1, expr_locus);
}
tree
diff --git a/gcc/rust/backend/rust-compile-type.cc b/gcc/rust/backend/rust-compile-type.cc
index 50b52fbd37f..85e78658335 100644
--- a/gcc/rust/backend/rust-compile-type.cc
+++ b/gcc/rust/backend/rust-compile-type.cc
@@ -298,21 +298,39 @@ TyTyResolveCompile::visit (const TyTy::ADTType &type)
// Ada, qual_union_types might still work for this but I am not 100% sure.
// I ran into some issues lets reuse our normal union and ask Ada people
// about it.
+ //
+ // I think the above is actually wrong and it should actually be this
+ //
+ // struct {
+ // int RUST$ENUM$DISR; // take into account the repr for this TODO
+ // union {
+ // // Variant A
+ // struct {
+ // // No additional fields
+ // } A;
+
+ // // Variant B
+ // struct {
+ // // No additional fields
+ // } B;
+
+ // // Variant C
+ // struct {
+ // char c;
+ // } C;
+
+ // // Variant D
+ // struct {
+ // int64_t x;
+ // int64_t y;
+ // } D;
+ // } payload; // The union of all variant data
+ // };
std::vector<tree> variant_records;
for (auto &variant : type.get_variants ())
{
std::vector<Backend::typed_identifier> fields;
-
- // add in the qualifier field for the variant
- tree enumeral_type
- = TyTyResolveCompile::get_implicit_enumeral_node_type ();
- Backend::typed_identifier f (RUST_ENUM_DISR_FIELD_NAME, enumeral_type,
- ctx->get_mappings ().lookup_location (
- variant->get_id ()));
- fields.push_back (std::move (f));
-
- // compile the rest of the fields
for (size_t i = 0; i < variant->num_fields (); i++)
{
const TyTy::StructFieldType *field
@@ -336,9 +354,6 @@ TyTyResolveCompile::visit (const TyTy::ADTType &type)
= Backend::named_type (variant->get_ident ().path.get (),
variant_record, variant->get_ident ().locus);
- // set the qualifier to be a builtin
- DECL_ARTIFICIAL (TYPE_FIELDS (variant_record)) = 1;
-
// add them to the list
variant_records.push_back (named_variant_record);
}
@@ -359,8 +374,27 @@ TyTyResolveCompile::visit (const TyTy::ADTType &type)
enum_fields.push_back (std::move (f));
}
+ //
+ location_t locus = ctx->get_mappings ().lookup_location (type.get_ref ());
+
// finally make the union or the enum
- type_record = Backend::union_type (enum_fields, false);
+ tree variants_union = Backend::union_type (enum_fields, false);
+ layout_type (variants_union);
+ tree named_union_record
+ = Backend::named_type ("payload", variants_union, locus);
+
+ // create the overall struct
+ tree enumeral_type
+ = TyTyResolveCompile::get_implicit_enumeral_node_type ();
+ Backend::typed_identifier discrim (RUST_ENUM_DISR_FIELD_NAME,
+ enumeral_type, locus);
+ Backend::typed_identifier variants_union_field ("payload",
+ named_union_record,
+ locus);
+
+ std::vector<Backend::typed_identifier> fields
+ = {discrim, variants_union_field};
+ type_record = Backend::struct_type (fields, false);
}
// Handle repr options
diff --git a/gcc/rust/rust-gcc.cc b/gcc/rust/rust-gcc.cc
index 37d51e58c08..a6e8ea904a8 100644
--- a/gcc/rust/rust-gcc.cc
+++ b/gcc/rust/rust-gcc.cc
@@ -1352,7 +1352,7 @@ constructor_expression (tree type_tree, bool is_variant,
if (!TREE_CONSTANT (elt->value))
is_constant = false;
}
- gcc_assert (field == NULL_TREE);
+ // gcc_assert (field == NULL_TREE);
}
}
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 106/146] gccrs: Allow float type to be casted as integer type
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (104 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 105/146] gccrs: cleanup our enum type layout to be closer to rustc arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 107/146] gccrs: match arms are a LUB arthur.cohen
` (39 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Nobel
From: Nobel <nobel2073@gmail.com>
gccrs now should be able to cast float types as numeric.
gcc/rust/ChangeLog:
* typecheck/rust-casts.cc (TypeCastRules::cast_rules): Add rule.
gcc/testsuite/ChangeLog:
* rust/compile/cast_float_as_integer.rs: New test.
Signed-off-by: Nobel Singh <nobel2073@gmail.com>
---
gcc/rust/typecheck/rust-casts.cc | 6 ++++++
gcc/testsuite/rust/compile/cast_float_as_integer.rs | 10 ++++++++++
2 files changed, 16 insertions(+)
create mode 100644 gcc/testsuite/rust/compile/cast_float_as_integer.rs
diff --git a/gcc/rust/typecheck/rust-casts.cc b/gcc/rust/typecheck/rust-casts.cc
index 694cbaa5db6..90bdef1fd3c 100644
--- a/gcc/rust/typecheck/rust-casts.cc
+++ b/gcc/rust/typecheck/rust-casts.cc
@@ -235,6 +235,12 @@ TypeCastRules::cast_rules ()
case TyTy::TypeKind::FLOAT:
switch (to.get_ty ()->get_kind ())
{
+ case TyTy::TypeKind::USIZE:
+ case TyTy::TypeKind::ISIZE:
+ case TyTy::TypeKind::UINT:
+ case TyTy::TypeKind::INT:
+ return TypeCoercionRules::CoercionResult{{}, to.get_ty ()->clone ()};
+
case TyTy::TypeKind::FLOAT:
return TypeCoercionRules::CoercionResult{{}, to.get_ty ()->clone ()};
diff --git a/gcc/testsuite/rust/compile/cast_float_as_integer.rs b/gcc/testsuite/rust/compile/cast_float_as_integer.rs
new file mode 100644
index 00000000000..e6b86db8a66
--- /dev/null
+++ b/gcc/testsuite/rust/compile/cast_float_as_integer.rs
@@ -0,0 +1,10 @@
+// { dg-options "-w" }
+fn main(){
+ let foo:f64 = 13.37;
+ let _ = foo as i64;
+ let _ = foo as u64;
+ let _ = foo as isize;
+ let _ = foo as usize;
+ let _ = foo as i8;
+ let _ = foo as u8;
+}
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 107/146] gccrs: match arms are a LUB
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (105 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 106/146] gccrs: Allow float type to be casted as integer type arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 108/146] gccrs: rust/intrinsic: add try intrinsic and panic strategy options arthur.cohen
` (38 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Philip Herron
From: Philip Herron <herron.philip@googlemail.com>
Unify rules are not the same as coercion rules. The coercion of ! is
allowed to any type but not for a unify site which is different.
Match arms are another least upper bound coercion.
gcc/rust/ChangeLog:
* backend/rust-compile-expr.cc (CompileExpr::visit): implement coercion
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): this is an LUB
* typecheck/rust-unify.cc (UnifyRules::go): remove unify ! coercion
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
---
gcc/rust/backend/rust-compile-expr.cc | 13 ++++++++++++-
gcc/rust/typecheck/rust-hir-type-check-expr.cc | 7 ++++---
gcc/rust/typecheck/rust-unify.cc | 10 ----------
3 files changed, 16 insertions(+), 14 deletions(-)
diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc
index b40aa33866e..353a498dc4e 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -1156,8 +1156,19 @@ CompileExpr::visit (HIR::MatchExpr &expr)
location_t arm_locus = kase_arm.get_locus ();
tree kase_expr_tree = CompileExpr::Compile (kase.get_expr (), ctx);
tree result_reference = Backend::var_expression (tmp, arm_locus);
+
+ TyTy::BaseType *actual = nullptr;
+ bool ok = ctx->get_tyctx ()->lookup_type (
+ kase.get_expr ().get_mappings ().get_hirid (), &actual);
+ rust_assert (ok);
+
+ tree coerced_result
+ = coercion_site (kase.get_expr ().get_mappings ().get_hirid (),
+ kase_expr_tree, actual, expr_tyty,
+ expr.get_locus (), arm_locus);
+
tree assignment
- = Backend::assignment_statement (result_reference, kase_expr_tree,
+ = Backend::assignment_statement (result_reference, coerced_result,
arm_locus);
ctx->add_statement (assignment);
diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
index 7899b1a7943..113f43f6c72 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
@@ -1532,9 +1532,10 @@ TypeCheckExpr::visit (HIR::MatchExpr &expr)
for (size_t i = 1; i < kase_block_tys.size (); i++)
{
TyTy::BaseType *kase_ty = kase_block_tys.at (i);
- infered = unify_site (expr.get_mappings ().get_hirid (),
- TyTy::TyWithLocation (infered),
- TyTy::TyWithLocation (kase_ty), expr.get_locus ());
+ infered
+ = coercion_site (expr.get_mappings ().get_hirid (),
+ TyTy::TyWithLocation (infered),
+ TyTy::TyWithLocation (kase_ty), expr.get_locus ());
}
}
diff --git a/gcc/rust/typecheck/rust-unify.cc b/gcc/rust/typecheck/rust-unify.cc
index 8159c7d52bb..b779e7d4614 100644
--- a/gcc/rust/typecheck/rust-unify.cc
+++ b/gcc/rust/typecheck/rust-unify.cc
@@ -17,7 +17,6 @@
// <http://www.gnu.org/licenses/>.
#include "rust-unify.h"
-#include "rust-tyty.h"
namespace Rust {
namespace Resolver {
@@ -238,15 +237,6 @@ 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:
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 108/146] gccrs: rust/intrinsic: add try intrinsic and panic strategy options
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (106 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 107/146] gccrs: match arms are a LUB arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 109/146] gccrs: rust/intrinsic: add new "catch_unwind" variant of API arthur.cohen
` (37 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, liushuyu
From: liushuyu <liushuyu011@gmail.com>
gcc/rust/ChangeLog:
* backend/rust-compile-intrinsic.cc: add `try` intrinsic handler.
* lang.opt: add `-frust-panic` option.
* rust-lang.cc: enable exception handler code generation.
* rust-session-manager.cc: add getter and setter for panic
strategy option.
* rust-session-manager.h: Likewise.
Signed-off-by: Zixing Liu <liushuyu011@gmail.com>
---
gcc/rust/backend/rust-compile-intrinsic.cc | 72 ++++++++++++++++++++++
gcc/rust/lang.opt | 13 ++++
gcc/rust/rust-lang.cc | 2 +
gcc/rust/rust-session-manager.cc | 3 +
gcc/rust/rust-session-manager.h | 14 +++++
5 files changed, 104 insertions(+)
diff --git a/gcc/rust/backend/rust-compile-intrinsic.cc b/gcc/rust/backend/rust-compile-intrinsic.cc
index 16447b29a51..77b67c36c3e 100644
--- a/gcc/rust/backend/rust-compile-intrinsic.cc
+++ b/gcc/rust/backend/rust-compile-intrinsic.cc
@@ -23,6 +23,7 @@
#include "rust-diagnostics.h"
#include "rust-location.h"
#include "rust-constexpr.h"
+#include "rust-session-manager.h"
#include "rust-tree.h"
#include "tree-core.h"
#include "rust-gcc.h"
@@ -194,6 +195,9 @@ expect_handler (bool likely)
};
}
+static tree
+try_handler (Context *ctx, TyTy::FnType *fntype);
+
inline tree
sorry_handler (Context *ctx, TyTy::FnType *fntype)
{
@@ -241,6 +245,7 @@ static const std::map<std::string,
{"likely", expect_handler (true)},
{"unlikely", expect_handler (false)},
{"assume", assume_handler},
+ {"try", try_handler},
};
Intrinsics::Intrinsics (Context *ctx) : ctx (ctx) {}
@@ -1266,5 +1271,72 @@ assume_handler (Context *ctx, TyTy::FnType *fntype)
return fndecl;
}
+static tree
+try_handler (Context *ctx, TyTy::FnType *fntype)
+{
+ rust_assert (fntype->get_params ().size () == 3);
+
+ tree lookup = NULL_TREE;
+ if (check_for_cached_intrinsic (ctx, fntype, &lookup))
+ return lookup;
+ auto fndecl = compile_intrinsic_function (ctx, fntype);
+
+ enter_intrinsic_block (ctx, fndecl);
+
+ // BUILTIN try_handler FN BODY BEGIN
+ // setup the params
+ std::vector<Bvariable *> param_vars;
+ compile_fn_params (ctx, fntype, fndecl, ¶m_vars);
+ if (!Backend::function_set_parameters (fndecl, param_vars))
+ return error_mark_node;
+ tree enclosing_scope = NULL_TREE;
+
+ bool panic_is_abort = Session::get_instance ().options.get_panic_strategy ()
+ == CompileOptions::PanicStrategy::Abort;
+ tree try_fn = Backend::var_expression (param_vars[0], UNDEF_LOCATION);
+ tree user_data = Backend::var_expression (param_vars[1], UNDEF_LOCATION);
+ tree catch_fn = Backend::var_expression (param_vars[2], UNDEF_LOCATION);
+ tree normal_return_stmt
+ = Backend::return_statement (fndecl, integer_zero_node, BUILTINS_LOCATION);
+ tree error_return_stmt
+ = Backend::return_statement (fndecl, integer_one_node, BUILTINS_LOCATION);
+ tree try_call = Backend::call_expression (try_fn, {user_data}, nullptr,
+ BUILTINS_LOCATION);
+ tree catch_call = NULL_TREE;
+ tree try_block = Backend::block (fndecl, enclosing_scope, {}, UNDEF_LOCATION,
+ UNDEF_LOCATION);
+ Backend::block_add_statements (try_block,
+ std::vector<tree>{try_call,
+ normal_return_stmt});
+ if (panic_is_abort)
+ {
+ // skip building the try-catch construct
+ ctx->add_statement (try_block);
+ finalize_intrinsic_block (ctx, fndecl);
+ return fndecl;
+ }
+
+ tree eh_pointer
+ = build_call_expr (builtin_decl_explicit (BUILT_IN_EH_POINTER), 1,
+ integer_zero_node);
+ catch_call = Backend::call_expression (catch_fn, {user_data, eh_pointer},
+ nullptr, BUILTINS_LOCATION);
+
+ tree catch_block = Backend::block (fndecl, enclosing_scope, {},
+ UNDEF_LOCATION, UNDEF_LOCATION);
+ Backend::block_add_statements (catch_block,
+ std::vector<tree>{catch_call,
+ error_return_stmt});
+ // TODO(liushuyu): eh_personality needs to be implemented as a runtime thing
+ auto eh_construct
+ = Backend::exception_handler_statement (try_block, catch_block, NULL_TREE,
+ BUILTINS_LOCATION);
+ ctx->add_statement (eh_construct);
+ // BUILTIN try_handler FN BODY END
+ finalize_intrinsic_block (ctx, fndecl);
+
+ return fndecl;
+}
+
} // namespace Compile
} // namespace Rust
diff --git a/gcc/rust/lang.opt b/gcc/rust/lang.opt
index ae601eb13ad..0e9aab48dfb 100644
--- a/gcc/rust/lang.opt
+++ b/gcc/rust/lang.opt
@@ -212,4 +212,17 @@ frust-borrowcheck
Rust Var(flag_borrowcheck)
Use the WIP borrow checker.
+frust-panic=
+Rust Joined RejectNegative Enum(frust_panic) Var(flag_rust_panic)
+-frust-edition=[unwind|abort] Panic strategy to compile crate with
+
+Enum
+Name(frust_panic) Type(int) UnknownError(unknown panic strategy %qs)
+
+EnumValue
+Enum(frust_panic) String(unwind) Value(0)
+
+EnumValue
+Enum(frust_panic) String(abort) Value(1)
+
; This comment is to ensure we retain the blank line above.
diff --git a/gcc/rust/rust-lang.cc b/gcc/rust/rust-lang.cc
index b84e114390a..f3a155dbad1 100644
--- a/gcc/rust/rust-lang.cc
+++ b/gcc/rust/rust-lang.cc
@@ -143,6 +143,8 @@ grs_langhook_init_options_struct (struct gcc_options *opts)
opts->x_warn_unused_result = 1;
/* lets warn for infinite recursion*/
opts->x_warn_infinite_recursion = 1;
+ /* Enable exception handling (aka `panic!` in Rust) */
+ opts->x_flag_exceptions = 1;
// nothing yet - used by frontends to change specific options for the language
Rust::Session::get_instance ().init_options ();
diff --git a/gcc/rust/rust-session-manager.cc b/gcc/rust/rust-session-manager.cc
index c0b4796c4e9..1039fdfb5b9 100644
--- a/gcc/rust/rust-session-manager.cc
+++ b/gcc/rust/rust-session-manager.cc
@@ -266,6 +266,9 @@ Session::handle_option (
case OPT_frust_metadata_output_:
options.set_metadata_output (arg);
break;
+ case OPT_frust_panic_:
+ options.set_panic_strategy (flag_rust_panic);
+ break;
default:
break;
diff --git a/gcc/rust/rust-session-manager.h b/gcc/rust/rust-session-manager.h
index b5a715ca4d6..73a85b32e97 100644
--- a/gcc/rust/rust-session-manager.h
+++ b/gcc/rust/rust-session-manager.h
@@ -264,6 +264,13 @@ struct CompileOptions
} compile_until
= CompileStep::End;
+ enum class PanicStrategy
+ {
+ Unwind,
+ Abort,
+ } panic_strategy
+ = PanicStrategy::Unwind;
+
bool dump_option_enabled (DumpOption option) const
{
return dump_options.find (option) != dump_options.end ();
@@ -320,6 +327,13 @@ struct CompileOptions
const CompileStep &get_compile_until () const { return compile_until; }
+ void set_panic_strategy (int strategy)
+ {
+ panic_strategy = static_cast<PanicStrategy> (strategy);
+ }
+
+ const PanicStrategy &get_panic_strategy () const { return panic_strategy; }
+
void set_metadata_output (const std::string &path)
{
metadata_output_path = path;
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 109/146] gccrs: rust/intrinsic: add new "catch_unwind" variant of API
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (107 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 108/146] gccrs: rust/intrinsic: add try intrinsic and panic strategy options arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 110/146] gccrs: add two more tests to test try-catch (unwind) code generation arthur.cohen
` (36 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, liushuyu
From: liushuyu <liushuyu011@gmail.com>
gcc/rust/ChangeLog:
* backend/rust-compile-intrinsic.cc: add the new `catch_unwind` variant
of the `try` intrinsic: this variant can be seen on Rust 1.78+
and returns `()` instead of `i32`.
---
gcc/rust/backend/rust-compile-intrinsic.cc | 57 ++++++++++++++++++----
1 file changed, 47 insertions(+), 10 deletions(-)
diff --git a/gcc/rust/backend/rust-compile-intrinsic.cc b/gcc/rust/backend/rust-compile-intrinsic.cc
index 77b67c36c3e..0f054588220 100644
--- a/gcc/rust/backend/rust-compile-intrinsic.cc
+++ b/gcc/rust/backend/rust-compile-intrinsic.cc
@@ -196,7 +196,15 @@ expect_handler (bool likely)
}
static tree
-try_handler (Context *ctx, TyTy::FnType *fntype);
+try_handler_inner (Context *ctx, TyTy::FnType *fntype, bool is_new_api);
+
+const static std::function<tree (Context *, TyTy::FnType *)>
+try_handler (bool is_new_api)
+{
+ return [is_new_api] (Context *ctx, TyTy::FnType *fntype) {
+ return try_handler_inner (ctx, fntype, is_new_api);
+ };
+}
inline tree
sorry_handler (Context *ctx, TyTy::FnType *fntype)
@@ -245,7 +253,8 @@ static const std::map<std::string,
{"likely", expect_handler (true)},
{"unlikely", expect_handler (false)},
{"assume", assume_handler},
- {"try", try_handler},
+ {"try", try_handler (false)},
+ {"catch_unwind", try_handler (true)},
};
Intrinsics::Intrinsics (Context *ctx) : ctx (ctx) {}
@@ -1272,7 +1281,7 @@ assume_handler (Context *ctx, TyTy::FnType *fntype)
}
static tree
-try_handler (Context *ctx, TyTy::FnType *fntype)
+try_handler_inner (Context *ctx, TyTy::FnType *fntype, bool is_new_api)
{
rust_assert (fntype->get_params ().size () == 3);
@@ -1283,6 +1292,13 @@ try_handler (Context *ctx, TyTy::FnType *fntype)
enter_intrinsic_block (ctx, fndecl);
+ // The following tricks are needed to make sure the try-catch blocks are not
+ // optimized away
+ TREE_READONLY (fndecl) = 0;
+ DECL_DISREGARD_INLINE_LIMITS (fndecl) = 1;
+ DECL_ATTRIBUTES (fndecl) = tree_cons (get_identifier ("always_inline"),
+ NULL_TREE, DECL_ATTRIBUTES (fndecl));
+
// BUILTIN try_handler FN BODY BEGIN
// setup the params
std::vector<Bvariable *> param_vars;
@@ -1296,15 +1312,31 @@ try_handler (Context *ctx, TyTy::FnType *fntype)
tree try_fn = Backend::var_expression (param_vars[0], UNDEF_LOCATION);
tree user_data = Backend::var_expression (param_vars[1], UNDEF_LOCATION);
tree catch_fn = Backend::var_expression (param_vars[2], UNDEF_LOCATION);
- tree normal_return_stmt
- = Backend::return_statement (fndecl, integer_zero_node, BUILTINS_LOCATION);
- tree error_return_stmt
- = Backend::return_statement (fndecl, integer_one_node, BUILTINS_LOCATION);
+ tree normal_return_stmt = NULL_TREE;
+ tree error_return_stmt = NULL_TREE;
tree try_call = Backend::call_expression (try_fn, {user_data}, nullptr,
BUILTINS_LOCATION);
tree catch_call = NULL_TREE;
tree try_block = Backend::block (fndecl, enclosing_scope, {}, UNDEF_LOCATION,
UNDEF_LOCATION);
+
+ if (is_new_api)
+ {
+ auto ret_type = TyTyResolveCompile::get_unit_type ();
+ auto ret_expr = Backend::constructor_expression (ret_type, false, {}, -1,
+ UNDEF_LOCATION);
+ normal_return_stmt
+ = Backend::return_statement (fndecl, ret_expr, BUILTINS_LOCATION);
+ error_return_stmt
+ = Backend::return_statement (fndecl, ret_expr, BUILTINS_LOCATION);
+ }
+ else
+ {
+ normal_return_stmt = Backend::return_statement (fndecl, integer_zero_node,
+ BUILTINS_LOCATION);
+ error_return_stmt = Backend::return_statement (fndecl, integer_one_node,
+ BUILTINS_LOCATION);
+ }
Backend::block_add_statements (try_block,
std::vector<tree>{try_call,
normal_return_stmt});
@@ -1320,17 +1352,22 @@ try_handler (Context *ctx, TyTy::FnType *fntype)
= build_call_expr (builtin_decl_explicit (BUILT_IN_EH_POINTER), 1,
integer_zero_node);
catch_call = Backend::call_expression (catch_fn, {user_data, eh_pointer},
- nullptr, BUILTINS_LOCATION);
+ NULL_TREE, BUILTINS_LOCATION);
tree catch_block = Backend::block (fndecl, enclosing_scope, {},
UNDEF_LOCATION, UNDEF_LOCATION);
Backend::block_add_statements (catch_block,
std::vector<tree>{catch_call,
error_return_stmt});
+ // emulate what cc1plus is doing for C++ try-catch
+ tree inner_eh_construct
+ = Backend::exception_handler_statement (catch_call, NULL_TREE,
+ error_return_stmt,
+ BUILTINS_LOCATION);
// TODO(liushuyu): eh_personality needs to be implemented as a runtime thing
auto eh_construct
- = Backend::exception_handler_statement (try_block, catch_block, NULL_TREE,
- BUILTINS_LOCATION);
+ = Backend::exception_handler_statement (try_block, inner_eh_construct,
+ NULL_TREE, BUILTINS_LOCATION);
ctx->add_statement (eh_construct);
// BUILTIN try_handler FN BODY END
finalize_intrinsic_block (ctx, fndecl);
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 110/146] gccrs: add two more tests to test try-catch (unwind) code generation
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (108 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 109/146] gccrs: rust/intrinsic: add new "catch_unwind" variant of API arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 111/146] gccrs: Visit the trait paths of trait implementations arthur.cohen
` (35 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, liushuyu
From: liushuyu <liushuyu011@gmail.com>
gcc/testsuite/ChangeLog:
* rust/compile/try-catch-unwind-old.rs: add a test to test the older
try intrinsics from plain old Rust to v1.78.0
* rust/compile/try-catch-unwind-new.rs: add a test to test the newer
catch_unwind instrinsics since Rust v1.78.0
---
.../rust/compile/try-catch-unwind-new.rs | 20 ++++++++++++++++++
.../rust/compile/try-catch-unwind-old.rs | 21 +++++++++++++++++++
2 files changed, 41 insertions(+)
create mode 100644 gcc/testsuite/rust/compile/try-catch-unwind-new.rs
create mode 100644 gcc/testsuite/rust/compile/try-catch-unwind-old.rs
diff --git a/gcc/testsuite/rust/compile/try-catch-unwind-new.rs b/gcc/testsuite/rust/compile/try-catch-unwind-new.rs
new file mode 100644
index 00000000000..b176f7a100b
--- /dev/null
+++ b/gcc/testsuite/rust/compile/try-catch-unwind-new.rs
@@ -0,0 +1,20 @@
+// { dg-options "-O2 -w -fdump-tree-optimized" }
+#![feature(intrinsics)]
+
+extern "rust-intrinsic" {
+ // { dg-final { scan-tree-dump-times "__builtin_eh_pointer" 1 "optimized" } }
+ fn catch_unwind(try_fn: fn(_: *mut u8), data: *mut u8, catch_fn: fn(_: *mut u8, _: *mut u8));
+}
+
+extern "C" {
+ fn try_fn(data: *mut u8);
+ fn catch_fn(data: *mut u8, ex: *mut u8);
+}
+
+pub fn not_main(d: &mut u8) {
+ unsafe {
+ // { dg-final { scan-tree-dump-times "try_fn" 1 "optimized" } }
+ catch_unwind(try_fn, d, catch_fn);
+ // { dg-final { scan-tree-dump-times "catch_fn" 1 "optimized" } }
+ }
+}
diff --git a/gcc/testsuite/rust/compile/try-catch-unwind-old.rs b/gcc/testsuite/rust/compile/try-catch-unwind-old.rs
new file mode 100644
index 00000000000..e97d52cd64e
--- /dev/null
+++ b/gcc/testsuite/rust/compile/try-catch-unwind-old.rs
@@ -0,0 +1,21 @@
+// { dg-options "-O2 -w -fdump-tree-optimized" }
+#![feature(intrinsics)]
+
+extern "rust-intrinsic" {
+ // { dg-final { scan-tree-dump-times "__builtin_eh_pointer" 1 "optimized" } }
+ fn r#try(try_fn: fn(_: *mut u8), data: *mut u8, catch_fn: fn(_: *mut u8, _: *mut u8)) -> i32;
+}
+
+extern "C" {
+ fn try_fn(data: *mut u8);
+ fn catch_fn(data: *mut u8, ex: *mut u8);
+}
+
+pub fn not_main(d: &mut u8) -> i32 {
+ unsafe {
+ // { dg-final { scan-tree-dump-times "try_fn" 1 "optimized" } }
+ let _: i32 = r#try(try_fn, d, catch_fn);
+ // { dg-final { scan-tree-dump-times "catch_fn" 1 "optimized" } }
+ }
+ 42
+}
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 111/146] gccrs: Visit the trait paths of trait implementations
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (109 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 110/146] gccrs: add two more tests to test try-catch (unwind) code generation arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 112/146] gccrs: improve mutability checks arthur.cohen
` (34 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Owen Avery
From: Owen Avery <powerboat9.gamer@gmail.com>
gcc/rust/ChangeLog:
* ast/rust-ast-visitor.cc
(DefaultASTVisitor::visit): When visiting a TraitImpl, visit its
trait path.
gcc/testsuite/ChangeLog:
* rust/compile/nr2/exclude: Remove entries.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
---
gcc/rust/ast/rust-ast-visitor.cc | 1 +
gcc/testsuite/rust/compile/nr2/exclude | 46 --------------------------
2 files changed, 1 insertion(+), 46 deletions(-)
diff --git a/gcc/rust/ast/rust-ast-visitor.cc b/gcc/rust/ast/rust-ast-visitor.cc
index 32e8025e9b2..d10ca6ca07b 100644
--- a/gcc/rust/ast/rust-ast-visitor.cc
+++ b/gcc/rust/ast/rust-ast-visitor.cc
@@ -1039,6 +1039,7 @@ DefaultASTVisitor::visit (AST::TraitImpl &impl)
if (impl.has_where_clause ())
visit (impl.get_where_clause ());
visit (impl.get_type ());
+ visit (impl.get_trait_path ());
visit_inner_attrs (impl);
for (auto &item : impl.get_impl_items ())
visit (item);
diff --git a/gcc/testsuite/rust/compile/nr2/exclude b/gcc/testsuite/rust/compile/nr2/exclude
index 9b1ee7ceaf9..9b490c18bab 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -13,7 +13,6 @@ cfg4.rs
cfg5.rs
closure_no_type_anno.rs
complex-path1.rs
-complex_qualified_path_in_expr.rs
const-issue1440.rs
const_generics_3.rs
const_generics_4.rs
@@ -21,12 +20,8 @@ const_generics_5.rs
const_generics_7.rs
derive_empty.rs
derive_macro1.rs
-derive_macro3.rs
-derive_macro4.rs
-derive_macro6.rs
expected_type_args2.rs
feature_rust_attri0.rs
-for_lifetimes.rs
format_args_basic_expansion.rs
generic-default1.rs
generics1.rs
@@ -38,9 +33,6 @@ generics5.rs
generics6.rs
generics9.rs
if_let_expr.rs
-issue-1019.rs
-issue-1034.rs
-issue-1129-2.rs
issue-1130.rs
issue-1173.rs
issue-1272.rs
@@ -52,24 +44,12 @@ issue-1786.rs
issue-1893.rs
issue-1901.rs
issue-1981.rs
-issue-2019-1.rs
-issue-2019-2.rs
-issue-2019-3.rs
issue-2036.rs
-issue-2037.rs
issue-2043.rs
-issue-2070.rs
-issue-2135.rs
-issue-2136-1.rs
issue-2136-2.rs
-issue-2139.rs
issue-2142.rs
-issue-2165.rs
-issue-2166.rs
issue-2238.rs
-issue-2304.rs
issue-2330.rs
-issue-2478.rs
issue-2479.rs
issue-2723-1.rs
issue-2723-2.rs
@@ -80,10 +60,8 @@ issue-2812.rs
issue-850.rs
issue-852.rs
issue-855.rs
-issue-925.rs
iterators1.rs
lookup_err1.rs
-macros/mbe/macro-issue1400.rs
macros/mbe/macro13.rs
macros/mbe/macro15.rs
macros/mbe/macro23.rs
@@ -111,7 +89,6 @@ name_resolution4.rs
nested_macro_use1.rs
nested_macro_use2.rs
nested_macro_use3.rs
-non_member_const.rs
not_find_value_in_scope.rs
parse_associated_type_as_generic_arg.rs
parse_associated_type_as_generic_arg2.rs
@@ -135,17 +112,10 @@ redef_error5.rs
self-path1.rs
self-path2.rs
sizeof-stray-infer-var-bug.rs
-stmt_with_block_dot.rs
struct-expr-parse.rs
-traits1.rs
-traits12.rs
-traits2.rs
traits3.rs
-traits4.rs
-traits5.rs
traits6.rs
traits7.rs
-traits8.rs
type-bindings1.rs
unconstrained_type_param.rs
undeclared_label.rs
@@ -154,27 +124,13 @@ use_2.rs
v0-mangle1.rs
v0-mangle2.rs
while_break_expr.rs
-negative_impls.rs
exhaustiveness1.rs
exhaustiveness2.rs
exhaustiveness3.rs
-trait13.rs
-trait14.rs
issue-2324-1.rs
issue-2324-2.rs
-issue-2987.rs
-issue-3045-1.rs
-issue-3045-2.rs
issue-3046.rs
-issue-3030.rs
-issue-3035.rs
-issue-3139-1.rs
issue-3139-2.rs
-issue-3139-3.rs
-issue-3036.rs
-issue-2951.rs
-issue-2203.rs
-issue-2499.rs
issue-3032-1.rs
issue-3032-2.rs
# https://github.com/Rust-GCC/gccrs/issues/3189
@@ -184,13 +140,11 @@ issue-3033.rs
issue-3009.rs
issue-2953-2.rs
issue-1773.rs
-issue-2905-1.rs
issue-2905-2.rs
issue-2907.rs
issue-2423.rs
issue-266.rs
additional-trait-bounds2.rs
-auto_traits2.rs
auto_traits3.rs
issue-3140.rs
cmp1.rs
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 112/146] gccrs: improve mutability checks
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (110 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 111/146] gccrs: Visit the trait paths of trait implementations arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 113/146] gccrs: gcc/rust/ChangeLog: arthur.cohen
` (33 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Philip Herron
From: Philip Herron <herron.philip@googlemail.com>
This ensures that we handle var decls readonly checks much better
Addresses: Rust-GCC#807 Rust-GCC#3287
gcc/rust/ChangeLog:
* checks/errors/rust-readonly-check.cc (check_decl): improve mut check
(emit_error): helper
(check_modify_expr): likewise
(readonly_walk_fn): reuse helper
(ReadonlyCheck::Lint): cleanup context each run
gcc/testsuite/ChangeLog:
* rust/execute/torture/builtin_macro_include_bytes.rs: needs mut
* rust/compile/mutability_checks1.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
---
gcc/rust/checks/errors/rust-readonly-check.cc | 54 +++++++++++++++----
.../rust/compile/mutability_checks1.rs | 15 ++++++
.../torture/builtin_macro_include_bytes.rs | 2 +-
3 files changed, 61 insertions(+), 10 deletions(-)
create mode 100644 gcc/testsuite/rust/compile/mutability_checks1.rs
diff --git a/gcc/rust/checks/errors/rust-readonly-check.cc b/gcc/rust/checks/errors/rust-readonly-check.cc
index b8998985d89..c1289332116 100644
--- a/gcc/rust/checks/errors/rust-readonly-check.cc
+++ b/gcc/rust/checks/errors/rust-readonly-check.cc
@@ -19,10 +19,13 @@
#include "rust-readonly-check.h"
#include "rust-tree.h"
#include "rust-gcc.h"
+#include "print-tree.h"
namespace Rust {
namespace Analysis {
+static std::map<tree, int> assignment_map = {};
+
// ported over from c-family/c-warn.cc
void
readonly_error (location_t loc, tree arg, enum lvalue_use use)
@@ -106,37 +109,68 @@ readonly_error (location_t loc, tree arg, enum lvalue_use use)
}
static void
-check_decl (tree *t)
+emit_error (tree *t, tree lhs, enum lvalue_use use)
{
- if (TREE_CODE (*t) == MODIFY_EXPR)
+ readonly_error (EXPR_LOCATION (*t), lhs, use);
+ TREE_OPERAND (*t, 0) = error_mark_node;
+}
+
+static void
+check_modify_expr (tree *t)
+{
+ tree lhs = TREE_OPERAND (*t, 0);
+ if (TREE_CODE (lhs) == ARRAY_REF || TREE_CODE (lhs) == COMPONENT_REF)
+ lhs = TREE_OPERAND (lhs, 0);
+
+ tree lhs_type = TREE_TYPE (lhs);
+ if (TYPE_READONLY (lhs_type) || TREE_READONLY (lhs) || TREE_CONSTANT (lhs))
{
- tree lhs = TREE_OPERAND (*t, 0);
- if (TREE_READONLY (lhs) || TREE_CONSTANT (lhs))
+ if (TREE_CODE (lhs) != VAR_DECL)
+ emit_error (t, lhs, lv_assign);
+ else if (!DECL_ARTIFICIAL (lhs))
{
- readonly_error (EXPR_LOCATION (*t), lhs, lv_assign);
- TREE_OPERAND (*t, 0) = error_mark_node;
+ if (DECL_INITIAL (lhs) != NULL)
+ emit_error (t, lhs, lv_assign);
+ else
+ {
+ if (assignment_map.find (lhs) == assignment_map.end ())
+ {
+ assignment_map.insert ({lhs, 0});
+ }
+ assignment_map[lhs]++;
+
+ if (assignment_map[lhs] > 1)
+ emit_error (t, lhs, lv_assign);
+ }
}
}
}
-static tree
-readonly_walk_fn (tree *t, int *, void *)
+static void
+check_decl (tree *t)
{
switch (TREE_CODE (*t))
{
case MODIFY_EXPR:
- check_decl (t);
+ check_modify_expr (t);
break;
default:
break;
}
+}
+
+static tree
+readonly_walk_fn (tree *t, int *, void *)
+{
+ check_decl (t);
return NULL_TREE;
}
void
ReadonlyCheck::Lint (Compile::Context &ctx)
{
+ assignment_map.clear ();
for (auto &fndecl : ctx.get_func_decls ())
{
for (tree p = DECL_ARGUMENTS (fndecl); p != NULL_TREE; p = DECL_CHAIN (p))
@@ -148,12 +182,14 @@ ReadonlyCheck::Lint (Compile::Context &ctx)
&readonly_walk_fn, &ctx);
}
+ assignment_map.clear ();
for (auto &var : ctx.get_var_decls ())
{
tree decl = var->get_decl ();
check_decl (&decl);
}
+ assignment_map.clear ();
for (auto &const_decl : ctx.get_const_decls ())
{
check_decl (&const_decl);
diff --git a/gcc/testsuite/rust/compile/mutability_checks1.rs b/gcc/testsuite/rust/compile/mutability_checks1.rs
new file mode 100644
index 00000000000..4affae03053
--- /dev/null
+++ b/gcc/testsuite/rust/compile/mutability_checks1.rs
@@ -0,0 +1,15 @@
+pub fn test() {
+ let a;
+ a = 1;
+ a = 2 + 1;
+ // { dg-error "assignment of read-only variable" "" { target *-*-* } .-1 }
+
+ struct Foo(i32);
+ let a = Foo(1);
+ a.0 = 2;
+ // { dg-error "assignment of read-only variable" "" { target *-*-* } .-1 }
+
+ let a = [1, 2, 3, 4];
+ a[0] = 1 + 2;
+ // { dg-error "assignment of read-only variable" "" { target *-*-* } .-1 }
+}
diff --git a/gcc/testsuite/rust/execute/torture/builtin_macro_include_bytes.rs b/gcc/testsuite/rust/execute/torture/builtin_macro_include_bytes.rs
index 6aec417e94f..c8a2daeccd9 100644
--- a/gcc/testsuite/rust/execute/torture/builtin_macro_include_bytes.rs
+++ b/gcc/testsuite/rust/execute/torture/builtin_macro_include_bytes.rs
@@ -25,7 +25,7 @@ fn print_int(value: i32) {
fn check_bytes(bytes: &[u8; 16]) {
let the_bytes = b"hello, include!\n";
- let x = true;
+ let mut x = true;
let mut i = 0;
// X is true iff bytes == the_bytes
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 113/146] gccrs: gcc/rust/ChangeLog:
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (111 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 112/146] gccrs: improve mutability checks arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 114/146] gccrs: Add ForeverStackStore arthur.cohen
` (32 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Om Swaroop Nayak
From: Om Swaroop Nayak <96killerat96@gmail.com>
* ast/rust-collect-lang-items.cc (get_lang_item_attr): "removed checker fn"
* util/rust-attributes.cc (Attributes::is_lang_item): "added fn"
* util/rust-attributes.h: "added fn"
Signed-off-by: Om Swaroop Nayak <96killerat96@gmail.com>
---
gcc/rust/ast/rust-collect-lang-items.cc | 7 +------
gcc/rust/util/rust-attributes.cc | 8 ++++++++
gcc/rust/util/rust-attributes.h | 2 ++
3 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/gcc/rust/ast/rust-collect-lang-items.cc b/gcc/rust/ast/rust-collect-lang-items.cc
index 50d134a429f..ec6919dca14 100644
--- a/gcc/rust/ast/rust-collect-lang-items.cc
+++ b/gcc/rust/ast/rust-collect-lang-items.cc
@@ -40,12 +40,7 @@ get_lang_item_attr (const T &maybe_lang_item)
continue;
}
- bool is_lang_item = str_path == Values::Attributes::LANG
- && attr.has_attr_input ()
- && attr.get_attr_input ().get_attr_input_type ()
- == AST::AttrInput::AttrInputType::LITERAL;
-
- if (is_lang_item)
+ if (Analysis::Attributes::is_lang_item (str_path, attr))
{
auto &literal
= static_cast<AST::AttrInputLiteral &> (attr.get_attr_input ());
diff --git a/gcc/rust/util/rust-attributes.cc b/gcc/rust/util/rust-attributes.cc
index 9f63234112c..0234903ba58 100644
--- a/gcc/rust/util/rust-attributes.cc
+++ b/gcc/rust/util/rust-attributes.cc
@@ -37,6 +37,14 @@ Attributes::is_known (const std::string &attribute_path)
return !lookup.is_error ();
}
+bool
+Attributes::is_lang_item (const std::string &attribute_path,
+ const AST::Attribute &attr)
+{
+ return ((attribute_path == Values::Attributes::LANG) && attr.has_attr_input ()
+ && (attr.get_attr_input ().get_attr_input_type ()
+ == AST::AttrInput::AttrInputType::LITERAL));
+}
using Attrs = Values::Attributes;
diff --git a/gcc/rust/util/rust-attributes.h b/gcc/rust/util/rust-attributes.h
index c928c8eb9d2..30f9eef213b 100644
--- a/gcc/rust/util/rust-attributes.h
+++ b/gcc/rust/util/rust-attributes.h
@@ -29,6 +29,8 @@ class Attributes
{
public:
static bool is_known (const std::string &attribute_path);
+ static bool is_lang_item (const std::string &attribute_path,
+ const AST::Attribute &attr);
};
enum CompilerPass
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 114/146] gccrs: Add ForeverStackStore
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (112 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 113/146] gccrs: gcc/rust/ChangeLog: arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 115/146] gccrs: testsuite: Fix missing handling of little endian arthur.cohen
` (31 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Owen Avery
From: Owen Avery <powerboat9.gamer@gmail.com>
ForeverStackStore is meant to partially unify the internal states of
per-namespace ForeverStack instances. This commit does not contain
modifications to ForeverStack which would allow it to rely on a
ForeverStackStore to store nodes, but a future commit should address
this.
gcc/rust/ChangeLog:
* Make-lang.in: Handle rust-forever-stack.cc.
* resolve/rust-forever-stack.h
(class ForeverStackStore): Add.
* resolve/rust-forever-stack.cc: New file, based on
rust-forever-stack.hxx.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
---
gcc/rust/Make-lang.in | 1 +
gcc/rust/resolve/rust-forever-stack.cc | 318 +++++++++++++++++++++++++
gcc/rust/resolve/rust-forever-stack.h | 151 ++++++++++++
3 files changed, 470 insertions(+)
create mode 100644 gcc/rust/resolve/rust-forever-stack.cc
diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in
index 8771cdf91e1..b6f3a35e4e6 100644
--- a/gcc/rust/Make-lang.in
+++ b/gcc/rust/Make-lang.in
@@ -146,6 +146,7 @@ GRS_OBJS = \
rust/rust-ast-resolve-path.o \
rust/rust-ast-resolve-stmt.o \
rust/rust-ast-resolve-struct-expr-field.o \
+ rust/rust-forever-stack.o \
rust/rust-hir-type-check.o \
rust/rust-privacy-check.o \
rust/rust-privacy-ctx.o \
diff --git a/gcc/rust/resolve/rust-forever-stack.cc b/gcc/rust/resolve/rust-forever-stack.cc
new file mode 100644
index 00000000000..725ae0ea018
--- /dev/null
+++ b/gcc/rust/resolve/rust-forever-stack.cc
@@ -0,0 +1,318 @@
+// 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
+// <http://www.gnu.org/licenses/>.
+
+#include "expected.h"
+#include "rust-ast.h"
+#include "rust-diagnostics.h"
+#include "rust-forever-stack.h"
+#include "rust-rib.h"
+#include "optional.h"
+
+namespace Rust {
+namespace Resolver2_0 {
+
+bool
+ForeverStackStore::Node::is_root () const
+{
+ return !parent.has_value ();
+}
+
+bool
+ForeverStackStore::Node::is_leaf () const
+{
+ return children.empty ();
+}
+
+NodeId
+ForeverStackStore::Node::get_id () const
+{
+ return id;
+}
+
+ForeverStackStore::Node &
+ForeverStackStore::Node::insert_child (NodeId id, tl::optional<Identifier> path,
+ Rib::Kind kind)
+{
+ auto res = children.insert ({Link (id, path), Node (kind, id, *this)});
+
+ rust_debug ("inserting link: Link(%d [%s]): existed? %s", id,
+ path.has_value () ? path.value ().as_string ().c_str ()
+ : "<anon>",
+ !res.second ? "yes" : "no");
+
+ // sanity check on rib kind
+ // pick the value rib, since all ribs should have the same kind anyways
+ rust_assert (res.second || res.first->second.value_rib.kind == kind);
+
+ // verify, if we're using an existing node, our paths don't contradict
+ if (!res.second && path.has_value ())
+ {
+ auto other_path = res.first->first.path;
+ rust_assert (!other_path.has_value ()
+ || other_path.value ().as_string ()
+ == path.value ().as_string ());
+ }
+
+ return res.first->second;
+}
+
+tl::optional<ForeverStackStore::Node &>
+ForeverStackStore::Node::get_child (const Identifier &path)
+{
+ for (auto &ent : children)
+ {
+ if (ent.first.path.has_value ()
+ && ent.first.path->as_string () == path.as_string ())
+ return ent.second;
+ }
+ return tl::nullopt;
+}
+
+tl::optional<const ForeverStackStore::Node &>
+ForeverStackStore::Node::get_child (const Identifier &path) const
+{
+ for (auto &ent : children)
+ {
+ if (ent.first.path.has_value ()
+ && ent.first.path->as_string () == path.as_string ())
+ return ent.second;
+ }
+ return tl::nullopt;
+}
+
+tl::optional<ForeverStackStore::Node &>
+ForeverStackStore::Node::get_parent ()
+{
+ return parent;
+}
+
+tl::optional<const ForeverStackStore::Node &>
+ForeverStackStore::Node::get_parent () const
+{
+ if (parent)
+ return *parent;
+ return tl::nullopt;
+}
+
+tl::optional<const Identifier &>
+ForeverStackStore::Node::get_parent_path () const
+{
+ if (parent.has_value ())
+ for (auto &ent : parent->children)
+ if (ent.first.id == id && ent.first.path.has_value ())
+ return ent.first.path.value ();
+ return tl::nullopt;
+}
+
+Rib &
+ForeverStackStore::Node::get_rib (Namespace ns)
+{
+ switch (ns)
+ {
+ case Namespace::Values:
+ return value_rib;
+ case Namespace::Types:
+ return type_rib;
+ case Namespace::Labels:
+ return label_rib;
+ case Namespace::Macros:
+ return macro_rib;
+ default:
+ rust_unreachable ();
+ }
+}
+
+const Rib &
+ForeverStackStore::Node::get_rib (Namespace ns) const
+{
+ switch (ns)
+ {
+ case Namespace::Values:
+ return value_rib;
+ case Namespace::Types:
+ return type_rib;
+ case Namespace::Labels:
+ return label_rib;
+ case Namespace::Macros:
+ return macro_rib;
+ default:
+ rust_unreachable ();
+ }
+}
+
+tl::expected<NodeId, DuplicateNameError>
+ForeverStackStore::Node::insert (const Identifier &name, NodeId node,
+ Namespace ns)
+{
+ // So what do we do here - if the Rib has already been pushed in an earlier
+ // 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 get_rib (ns).insert (name.as_string (),
+ Rib::Definition::NonShadowable (node));
+}
+
+tl::expected<NodeId, DuplicateNameError>
+ForeverStackStore::Node::insert_shadowable (const Identifier &name, NodeId node,
+ Namespace ns)
+{
+ return get_rib (ns).insert (name.as_string (),
+ Rib::Definition::Shadowable (node));
+}
+
+tl::expected<NodeId, DuplicateNameError>
+ForeverStackStore::Node::insert_globbed (const Identifier &name, NodeId node,
+ Namespace ns)
+{
+ return get_rib (ns).insert (name.as_string (),
+ Rib::Definition::Globbed (node));
+}
+
+void
+ForeverStackStore::Node::reverse_iter (std::function<KeepGoing (Node &)> lambda)
+{
+ for (Node *tmp = this; lambda (*tmp) == KeepGoing::Yes && !tmp->is_root ();
+ tmp = &tmp->parent.value ())
+ ;
+}
+
+void
+ForeverStackStore::Node::reverse_iter (
+ std::function<KeepGoing (const Node &)> lambda) const
+{
+ for (const Node *tmp = this;
+ lambda (*tmp) == KeepGoing::Yes && !tmp->is_root ();
+ tmp = &tmp->parent.value ())
+ ;
+}
+
+void
+ForeverStackStore::Node::child_iter (
+ std::function<KeepGoing (NodeId, tl::optional<const Identifier &>, Node &)>
+ lambda)
+{
+ for (auto &ent : children)
+ {
+ tl::optional<const Identifier &> path;
+ if (ent.first.path.has_value ())
+ path = ent.first.path.value ();
+ auto keep_going = lambda (ent.first.id, path, ent.second);
+ if (keep_going == KeepGoing::No)
+ return;
+ }
+}
+
+void
+ForeverStackStore::Node::child_iter (
+ std::function<KeepGoing (NodeId, tl::optional<const Identifier &>,
+ const Node &)>
+ lambda) const
+{
+ for (auto &ent : children)
+ {
+ tl::optional<const Identifier &> path;
+ if (ent.first.path.has_value ())
+ path = ent.first.path.value ();
+ auto keep_going = lambda (ent.first.id, path, ent.second);
+ if (keep_going == KeepGoing::No)
+ return;
+ }
+}
+
+ForeverStackStore::Node &
+ForeverStackStore::Node::find_closest_module ()
+{
+ // get kind of value_rib
+ // but all ribs should share the same kind anyways
+ if (value_rib.kind == Rib::Kind::Module || !parent.has_value ())
+ return *this;
+ else
+ return parent->find_closest_module ();
+}
+
+const ForeverStackStore::Node &
+ForeverStackStore::Node::find_closest_module () const
+{
+ // get kind of value_rib
+ // but all ribs should share the same kind anyways
+ if (value_rib.kind != Rib::Kind::Module || !parent.has_value ())
+ return *this;
+ else
+ return parent->find_closest_module ();
+}
+
+tl::optional<ForeverStackStore::Node &>
+ForeverStackStore::Node::dfs_node (NodeId to_find)
+{
+ if (id == to_find)
+ return *this;
+
+ for (auto &child : children)
+ {
+ auto candidate = child.second.dfs_node (to_find);
+
+ if (candidate.has_value ())
+ return candidate;
+ }
+
+ return tl::nullopt;
+}
+
+tl::optional<const ForeverStackStore::Node &>
+ForeverStackStore::Node::dfs_node (NodeId to_find) const
+{
+ if (id == to_find)
+ return *this;
+
+ for (auto &child : children)
+ {
+ auto candidate = child.second.dfs_node (to_find);
+
+ if (candidate.has_value ())
+ return candidate;
+ }
+
+ return tl::nullopt;
+}
+
+ForeverStackStore::Node &
+ForeverStackStore::get_root ()
+{
+ return root;
+}
+
+const ForeverStackStore::Node &
+ForeverStackStore::get_root () const
+{
+ return root;
+}
+
+tl::optional<ForeverStackStore::Node &>
+ForeverStackStore::get_node (NodeId node_id)
+{
+ return root.dfs_node (node_id);
+}
+
+tl::optional<const ForeverStackStore::Node &>
+ForeverStackStore::get_node (NodeId node_id) const
+{
+ return root.dfs_node (node_id);
+}
+
+} // namespace Resolver2_0
+} // namespace Rust
diff --git a/gcc/rust/resolve/rust-forever-stack.h b/gcc/rust/resolve/rust-forever-stack.h
index 064d1ab2bb3..66e12668f71 100644
--- a/gcc/rust/resolve/rust-forever-stack.h
+++ b/gcc/rust/resolve/rust-forever-stack.h
@@ -392,6 +392,157 @@ not contain any imports, macro definitions or macro invocations. You can look at
this pass's documentation for more details on this resolution process.
**/
+
+/**
+ * Intended for use by ForeverStack to store Nodes
+ * Unlike ForeverStack, does not store a cursor reference
+ * Intended to make path resolution in multiple namespaces simpler
+ **/
+class ForeverStackStore
+{
+public:
+ ForeverStackStore (NodeId crate_id) : root (Rib::Kind::Normal, crate_id)
+ {
+ rust_assert (root.is_root ());
+ rust_assert (root.is_leaf ());
+ }
+
+private:
+ /**
+ * A link between two Nodes in our trie data structure. This class represents
+ * the edges of the graph
+ */
+ class Link
+ {
+ public:
+ Link (NodeId id, tl::optional<Identifier> path) : id (id), path (path) {}
+
+ bool compare (const Link &other) const { return id < other.id; }
+
+ NodeId id;
+ tl::optional<Identifier> path;
+ };
+
+ /* Link comparison class, which we use in a Node's `children` map */
+ class LinkCmp
+ {
+ public:
+ bool operator() (const Link &lhs, const Link &rhs) const
+ {
+ return lhs.compare (rhs);
+ }
+ };
+
+public:
+ class Node;
+
+ struct DfsResult
+ {
+ Node &first;
+ std::string second;
+ };
+
+ struct ConstDfsResult
+ {
+ const Node &first;
+ std::string second;
+ };
+
+ /* Should we keep going upon seeing a Rib? */
+ enum class KeepGoing
+ {
+ Yes,
+ No,
+ };
+
+ class Node
+ {
+ private:
+ friend class ForeverStackStore::ForeverStackStore;
+
+ Node (Rib::Kind rib_kind, NodeId id, tl::optional<Node &> parent)
+ : value_rib (rib_kind), type_rib (rib_kind), label_rib (rib_kind),
+ macro_rib (rib_kind), id (id), parent (parent)
+ {}
+ Node (Rib::Kind rib_kind, NodeId id) : Node (rib_kind, id, tl::nullopt) {}
+ Node (Rib::Kind rib_kind, NodeId id, Node &parent)
+ : Node (rib_kind, id, tl::optional<Node &> (parent))
+ {}
+
+ public:
+ Node (const Node &) = default;
+ Node (Node &&) = default;
+ Node &operator= (const Node &) = delete;
+ Node &operator= (Node &&) = default;
+
+ bool is_root () const;
+ bool is_leaf () const;
+
+ NodeId get_id () const;
+
+ Node &insert_child (NodeId id, tl::optional<Identifier> path,
+ Rib::Kind kind);
+
+ tl::optional<Node &> get_child (const Identifier &path);
+ tl::optional<const Node &> get_child (const Identifier &path) const;
+
+ tl::optional<Node &> get_parent ();
+ tl::optional<const Node &> get_parent () const;
+
+ // finds the identifier, if any, used to link
+ // this node's parent to this node
+ tl::optional<const Identifier &> get_parent_path () const;
+
+ Rib &get_rib (Namespace ns);
+ const Rib &get_rib (Namespace ns) const;
+
+ tl::expected<NodeId, DuplicateNameError> insert (const Identifier &name,
+ NodeId node, Namespace ns);
+ tl::expected<NodeId, DuplicateNameError>
+ insert_shadowable (const Identifier &name, NodeId node, Namespace ns);
+ tl::expected<NodeId, DuplicateNameError>
+ insert_globbed (const Identifier &name, NodeId node, Namespace ns);
+
+ void reverse_iter (std::function<KeepGoing (Node &)> lambda);
+ void reverse_iter (std::function<KeepGoing (const Node &)> lambda) const;
+
+ void child_iter (std::function<KeepGoing (
+ NodeId, tl::optional<const Identifier &>, Node &)>
+ lambda);
+ void child_iter (std::function<KeepGoing (
+ NodeId, tl::optional<const Identifier &>, const Node &)>
+ lambda) const;
+
+ Node &find_closest_module ();
+ const Node &find_closest_module () const;
+
+ tl::optional<Node &> dfs_node (NodeId to_find);
+ tl::optional<const Node &> dfs_node (NodeId to_find) const;
+
+ private:
+ // per-namespace ribs
+ Rib value_rib;
+ Rib type_rib;
+ Rib label_rib;
+ Rib macro_rib;
+ // all linked nodes
+ std::map<Link, Node, LinkCmp> children;
+
+ NodeId id; // The node id of the Node's scope
+
+ tl::optional<Node &> parent; // `None` only if the node is a root
+ };
+
+ Node &get_root ();
+ const Node &get_root () const;
+
+ tl::optional<Node &> get_node (NodeId node_id);
+ tl::optional<const Node &> get_node (NodeId node_id) const;
+
+private:
+ Node root;
+};
+
template <Namespace N> class ForeverStack
{
public:
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 115/146] gccrs: testsuite: Fix missing handling of little endian.
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (113 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 114/146] gccrs: Add ForeverStackStore arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 116/146] gccrs: Fix scan-gimple testcases on LE platforms arthur.cohen
` (30 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
Some failures occur in the testsuite because we
did not account for the little-endian case.
gcc/testsuite/ChangeLog:
* rust/compile/issue-1446.rs: Add swap_bytes function.
* rust/compile/iterators1.rs: Remove unused {to, from}_le functions.
---
gcc/testsuite/rust/compile/issue-1446.rs | 10 +++++++++-
gcc/testsuite/rust/compile/iterators1.rs | 18 ------------------
2 files changed, 9 insertions(+), 19 deletions(-)
diff --git a/gcc/testsuite/rust/compile/issue-1446.rs b/gcc/testsuite/rust/compile/issue-1446.rs
index 8bfa42b9dac..969ad380ee6 100644
--- a/gcc/testsuite/rust/compile/issue-1446.rs
+++ b/gcc/testsuite/rust/compile/issue-1446.rs
@@ -1,3 +1,11 @@
+// fake function
+pub fn swap_bytes(this: u32) -> u32 {
+ (((this) & 0xff000000) >> 24)
+ | (((this) & 0x00ff0000) >> 8)
+ | (((this) & 0x0000ff00) << 8)
+ | (((this) & 0x000000ff) << 24)
+}
+
pub fn to_le(this: u32) -> u32 {
#[cfg(target_endian = "little")]
{
@@ -5,6 +13,6 @@ pub fn to_le(this: u32) -> u32 {
}
#[cfg(not(target_endian = "little"))]
{
- this.swap_bytes()
+ swap_bytes(this)
}
}
diff --git a/gcc/testsuite/rust/compile/iterators1.rs b/gcc/testsuite/rust/compile/iterators1.rs
index 35fea5a0493..1141758b14a 100644
--- a/gcc/testsuite/rust/compile/iterators1.rs
+++ b/gcc/testsuite/rust/compile/iterators1.rs
@@ -232,24 +232,6 @@ macro_rules! impl_uint {
}
}
- pub fn to_le(self) -> Self {
- #[cfg(target_endian = "little")]
- {
- self
- }
- }
-
- pub const fn from_le_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
- Self::from_le(Self::from_ne_bytes(bytes))
- }
-
- pub const fn from_le(x: Self) -> Self {
- #[cfg(target_endian = "little")]
- {
- x
- }
- }
-
pub const fn from_ne_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
unsafe { mem::transmute(bytes) }
}
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 116/146] gccrs: Fix scan-gimple testcases on LE platforms.
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (114 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 115/146] gccrs: testsuite: Fix missing handling of little endian arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 117/146] gccrs: Revert "gcc/rust/ChangeLog:" arthur.cohen
` (29 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
gcc/testsuite/ChangeLog:
* rust/compile/macros/builtin/eager1.rs: Switch to scan-assembler directive as the
GIMPLE dump does not contain strings on LE.
* rust/compile/macros/builtin/recurse2.rs: Likewise.
---
.../rust/compile/macros/builtin/eager1.rs | 2 +-
.../rust/compile/macros/builtin/recurse2.rs | 26 +++++++++++++++++--
2 files changed, 25 insertions(+), 3 deletions(-)
diff --git a/gcc/testsuite/rust/compile/macros/builtin/eager1.rs b/gcc/testsuite/rust/compile/macros/builtin/eager1.rs
index 65a80fda62e..7c6f6f95d61 100644
--- a/gcc/testsuite/rust/compile/macros/builtin/eager1.rs
+++ b/gcc/testsuite/rust/compile/macros/builtin/eager1.rs
@@ -15,7 +15,7 @@ macro_rules! b {
}
fn main() {
- // { dg-final { scan-tree-dump-times {"test1canary"} 1 gimple } }
+ // { dg-final { scan-assembler {"test1canary"} } }
let _ = concat!(a!(), 1, b!());
// should not error
concat!(a!(), true, b!(),);
diff --git a/gcc/testsuite/rust/compile/macros/builtin/recurse2.rs b/gcc/testsuite/rust/compile/macros/builtin/recurse2.rs
index 2e73ab54fb6..73e6ab4aa6c 100644
--- a/gcc/testsuite/rust/compile/macros/builtin/recurse2.rs
+++ b/gcc/testsuite/rust/compile/macros/builtin/recurse2.rs
@@ -15,7 +15,29 @@ macro_rules! a {
};
}
+extern "C" {
+ fn printf(fmt: *const i8, ...);
+}
+
+fn print_ptr(s: &str) {
+ unsafe {
+ printf("%p\n\0" as *const str as *const i8, s as *const str);
+ }
+}
+
+fn print_str(s: &str) {
+ unsafe {
+ printf(
+ "%s\n\0" as *const str as *const i8,
+ s as *const str as *const i8,
+ );
+ }
+}
+
+// { dg-final { scan-assembler {"abheyho"} } }
+static S: &str = concat!("a", 'b', a!(), a!(b c d e f a!()), '\0');
+
fn main() {
- // { dg-final { scan-tree-dump-times {"abheyho"} 1 gimple } }
- let _ = concat!("a", 'b', a!(), a!(b c d e f a!()), '\0');
+ print_ptr(S);
+ print_str(S);
}
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 117/146] gccrs: Revert "gcc/rust/ChangeLog:"
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (115 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 116/146] gccrs: Fix scan-gimple testcases on LE platforms arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:06 ` [COMMITTED 118/146] gccrs: Add missing name resolution to static items in blocks arthur.cohen
` (28 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, CohenArthur
From: CohenArthur <cohenarthur.dev@gmail.com>
This reverts commit 600fd806b8821ea24103ea0f31d666077245c6b7.
---
gcc/rust/ast/rust-collect-lang-items.cc | 7 ++++++-
gcc/rust/util/rust-attributes.cc | 8 --------
gcc/rust/util/rust-attributes.h | 2 --
3 files changed, 6 insertions(+), 11 deletions(-)
diff --git a/gcc/rust/ast/rust-collect-lang-items.cc b/gcc/rust/ast/rust-collect-lang-items.cc
index ec6919dca14..50d134a429f 100644
--- a/gcc/rust/ast/rust-collect-lang-items.cc
+++ b/gcc/rust/ast/rust-collect-lang-items.cc
@@ -40,7 +40,12 @@ get_lang_item_attr (const T &maybe_lang_item)
continue;
}
- if (Analysis::Attributes::is_lang_item (str_path, attr))
+ bool is_lang_item = str_path == Values::Attributes::LANG
+ && attr.has_attr_input ()
+ && attr.get_attr_input ().get_attr_input_type ()
+ == AST::AttrInput::AttrInputType::LITERAL;
+
+ if (is_lang_item)
{
auto &literal
= static_cast<AST::AttrInputLiteral &> (attr.get_attr_input ());
diff --git a/gcc/rust/util/rust-attributes.cc b/gcc/rust/util/rust-attributes.cc
index 0234903ba58..9f63234112c 100644
--- a/gcc/rust/util/rust-attributes.cc
+++ b/gcc/rust/util/rust-attributes.cc
@@ -37,14 +37,6 @@ Attributes::is_known (const std::string &attribute_path)
return !lookup.is_error ();
}
-bool
-Attributes::is_lang_item (const std::string &attribute_path,
- const AST::Attribute &attr)
-{
- return ((attribute_path == Values::Attributes::LANG) && attr.has_attr_input ()
- && (attr.get_attr_input ().get_attr_input_type ()
- == AST::AttrInput::AttrInputType::LITERAL));
-}
using Attrs = Values::Attributes;
diff --git a/gcc/rust/util/rust-attributes.h b/gcc/rust/util/rust-attributes.h
index 30f9eef213b..c928c8eb9d2 100644
--- a/gcc/rust/util/rust-attributes.h
+++ b/gcc/rust/util/rust-attributes.h
@@ -29,8 +29,6 @@ class Attributes
{
public:
static bool is_known (const std::string &attribute_path);
- static bool is_lang_item (const std::string &attribute_path,
- const AST::Attribute &attr);
};
enum CompilerPass
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 118/146] gccrs: Add missing name resolution to static items in blocks
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (116 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 117/146] gccrs: Revert "gcc/rust/ChangeLog:" arthur.cohen
@ 2025-03-21 12:06 ` arthur.cohen
2025-03-21 12:07 ` [COMMITTED 119/146] gccrs: nr2.0: Early resolve pending eager macro invocations arthur.cohen
` (27 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:06 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Philip Herron
From: Philip Herron <herron.philip@googlemail.com>
We need to add name resolution and hir lowering for items as part of blocks
in order to typecheck and compile them correctly.
Fixes Rust-GCC#3350
gcc/rust/ChangeLog:
* hir/rust-ast-lower-stmt.cc (ASTLoweringStmt::visit): hir lowering
* hir/rust-ast-lower-stmt.h: likewise
* resolve/rust-ast-resolve-stmt.cc (ResolveStmt::visit): name resolution
* resolve/rust-ast-resolve-stmt.h: likewise
gcc/testsuite/ChangeLog:
* rust/compile/issue-3350.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
---
gcc/rust/hir/rust-ast-lower-stmt.cc | 6 ++++++
gcc/rust/hir/rust-ast-lower-stmt.h | 1 +
gcc/rust/resolve/rust-ast-resolve-stmt.cc | 21 +++++++++++++++++++++
gcc/rust/resolve/rust-ast-resolve-stmt.h | 1 +
gcc/testsuite/rust/compile/issue-3350.rs | 10 ++++++++++
5 files changed, 39 insertions(+)
create mode 100644 gcc/testsuite/rust/compile/issue-3350.rs
diff --git a/gcc/rust/hir/rust-ast-lower-stmt.cc b/gcc/rust/hir/rust-ast-lower-stmt.cc
index 8244e8ae2ba..fd2cdfb0f11 100644
--- a/gcc/rust/hir/rust-ast-lower-stmt.cc
+++ b/gcc/rust/hir/rust-ast-lower-stmt.cc
@@ -163,5 +163,11 @@ ASTLoweringStmt::visit (AST::TraitImpl &impl_block)
translated = ASTLoweringItem::translate (impl_block);
}
+void
+ASTLoweringStmt::visit (AST::StaticItem &var)
+{
+ translated = ASTLoweringItem::translate (var);
+}
+
} // namespace HIR
} // namespace Rust
diff --git a/gcc/rust/hir/rust-ast-lower-stmt.h b/gcc/rust/hir/rust-ast-lower-stmt.h
index 5b1e1b9c99a..737a5f8dc4b 100644
--- a/gcc/rust/hir/rust-ast-lower-stmt.h
+++ b/gcc/rust/hir/rust-ast-lower-stmt.h
@@ -45,6 +45,7 @@ public:
void visit (AST::Trait &trait) override;
void visit (AST::InherentImpl &impl_block) override;
void visit (AST::TraitImpl &impl_block) override;
+ void visit (AST::StaticItem &var) override;
private:
ASTLoweringStmt () : translated (nullptr), terminated (false) {}
diff --git a/gcc/rust/resolve/rust-ast-resolve-stmt.cc b/gcc/rust/resolve/rust-ast-resolve-stmt.cc
index 28852910c71..226d8e8e2f4 100644
--- a/gcc/rust/resolve/rust-ast-resolve-stmt.cc
+++ b/gcc/rust/resolve/rust-ast-resolve-stmt.cc
@@ -56,5 +56,26 @@ ResolveStmt::visit (AST::TraitImpl &impl_block)
ResolveItem::go (impl_block, prefix, canonical_prefix);
}
+void
+ResolveStmt::visit (AST::StaticItem &var)
+{
+ auto decl = CanonicalPath::new_seg (var.get_node_id (),
+ var.get_identifier ().as_string ());
+ auto path = decl;
+ auto cpath = canonical_prefix.append (decl);
+ mappings.insert_canonical_path (var.get_node_id (), cpath);
+
+ resolver->get_name_scope ().insert (
+ path, var.get_node_id (), var.get_locus (), false, Rib::ItemType::Static,
+ [&] (const CanonicalPath &, NodeId, location_t locus) -> void {
+ rich_location r (line_table, var.get_locus ());
+ r.add_range (locus);
+ rust_error_at (r, "redefined multiple times");
+ });
+
+ ResolveType::go (var.get_type ());
+ ResolveExpr::go (var.get_expr (), path, cpath);
+}
+
} // namespace Resolver
} // namespace Rust
diff --git a/gcc/rust/resolve/rust-ast-resolve-stmt.h b/gcc/rust/resolve/rust-ast-resolve-stmt.h
index 8e64a7691d9..6dfac9179d7 100644
--- a/gcc/rust/resolve/rust-ast-resolve-stmt.h
+++ b/gcc/rust/resolve/rust-ast-resolve-stmt.h
@@ -388,6 +388,7 @@ public:
void visit (AST::Trait &trait) override;
void visit (AST::InherentImpl &impl_block) override;
void visit (AST::TraitImpl &impl_block) override;
+ void visit (AST::StaticItem &var) override;
private:
ResolveStmt (const CanonicalPath &prefix,
diff --git a/gcc/testsuite/rust/compile/issue-3350.rs b/gcc/testsuite/rust/compile/issue-3350.rs
new file mode 100644
index 00000000000..8880659afe6
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-3350.rs
@@ -0,0 +1,10 @@
+static FOO: i32 = 0;
+
+pub fn bar() -> i32 {
+ FOO
+}
+
+pub fn baz() -> i32 {
+ static QUX: i32 = 0;
+ QUX
+}
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 119/146] gccrs: nr2.0: Early resolve pending eager macro invocations
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (117 preceding siblings ...)
2025-03-21 12:06 ` [COMMITTED 118/146] gccrs: Add missing name resolution to static items in blocks arthur.cohen
@ 2025-03-21 12:07 ` arthur.cohen
2025-03-21 12:07 ` [COMMITTED 120/146] gccrs: Remove dead code related to external functions arthur.cohen
` (26 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:07 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Owen Avery
From: Owen Avery <powerboat9.gamer@gmail.com>
gcc/rust/ChangeLog:
* resolve/rust-early-name-resolver-2.0.cc
(Early::visit): Resolve the pending eager invocations inside
builtin macro invocations.
gcc/testsuite/ChangeLog:
* rust/compile/nr2/exclude: Remove entries.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
---
gcc/rust/resolve/rust-early-name-resolver-2.0.cc | 4 ++++
gcc/testsuite/rust/compile/nr2/exclude | 5 -----
2 files changed, 4 insertions(+), 5 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 55330487fd7..342f1027273 100644
--- a/gcc/rust/resolve/rust-early-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-early-name-resolver-2.0.cc
@@ -238,6 +238,10 @@ Early::visit (AST::MacroInvocation &invoc)
{
auto path = invoc.get_invoc_data ().get_path ();
+ if (invoc.get_kind () == AST::MacroInvocation::InvocKind::Builtin)
+ for (auto &pending_invoc : invoc.get_pending_eager_invocations ())
+ pending_invoc->accept_vis (*this);
+
// When a macro is invoked by an unqualified identifier (not part of a
// multi-part path), it is first looked up in textual scoping. If this does
// not yield any results, then it is looked up in path-based scoping. If the
diff --git a/gcc/testsuite/rust/compile/nr2/exclude b/gcc/testsuite/rust/compile/nr2/exclude
index 9b490c18bab..0f482df2f00 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -1,11 +1,6 @@
bounds1.rs
break-rust2.rs
break-rust3.rs
-macros/builtin/eager1.rs
-macros/builtin/eager2.rs
-macros/builtin/recurse2.rs
-macros/builtin/include3.rs
-macros/builtin/include4.rs
canonical_paths1.rs
cfg1.rs
cfg3.rs
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 120/146] gccrs: Remove dead code related to external functions
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (118 preceding siblings ...)
2025-03-21 12:07 ` [COMMITTED 119/146] gccrs: nr2.0: Early resolve pending eager macro invocations arthur.cohen
@ 2025-03-21 12:07 ` arthur.cohen
2025-03-21 12:07 ` [COMMITTED 121/146] gccrs: ast: Fix warning about copy elision for moved expr arthur.cohen
` (25 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:07 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Owen Avery
From: Owen Avery <powerboat9.gamer@gmail.com>
gcc/rust/ChangeLog:
* ast/rust-ast-collector.cc
(TokenCollector::visit): Remove visitor for NamedFunctionParam.
* ast/rust-ast-collector.h
(TokenCollector::visit): Likewise.
* ast/rust-ast-full-decls.h
(class NamedFunctionParam): Remove forward declaration.
* ast/rust-ast-visitor.cc
(DefaultASTVisitor::visit): Remove visitor for
NamedFunctionParam.
* ast/rust-ast-visitor.h
(DefaultASTVisitor::visit): Likewise.
* ast/rust-ast.cc
(NamedFunctionParam::as_string): Remove.
* ast/rust-item.h
(class NamedFunctionParam): Remove.
(class ExternalFunctionItem): Remove.
* parse/rust-parse-impl.h
(Parser::parse_named_function_param): Remove.
(Parser::parse_named_function_params): Remove.
* parse/rust-parse.h
(Parser::parse_named_function_param): Remove.
(Parser::parse_named_function_params): Remove.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
---
gcc/rust/ast/rust-ast-collector.cc | 23 ---
gcc/rust/ast/rust-ast-collector.h | 1 -
gcc/rust/ast/rust-ast-full-decls.h | 1 -
gcc/rust/ast/rust-ast-visitor.cc | 8 -
gcc/rust/ast/rust-ast-visitor.h | 1 -
gcc/rust/ast/rust-ast.cc | 16 --
gcc/rust/ast/rust-item.h | 297 -----------------------------
gcc/rust/parse/rust-parse-impl.h | 100 ----------
gcc/rust/parse/rust-parse.h | 4 -
9 files changed, 451 deletions(-)
diff --git a/gcc/rust/ast/rust-ast-collector.cc b/gcc/rust/ast/rust-ast-collector.cc
index bc76deb9a6d..320611614e9 100644
--- a/gcc/rust/ast/rust-ast-collector.cc
+++ b/gcc/rust/ast/rust-ast-collector.cc
@@ -250,29 +250,6 @@ TokenCollector::visit (Visibility &vis)
}
}
-void
-TokenCollector::visit (NamedFunctionParam ¶m)
-{
- auto name = param.get_name ();
- if (!param.is_variadic ())
- {
- push (
- Rust::Token::make_identifier (param.get_locus (), std::move (name)));
- push (Rust::Token::make (COLON, UNDEF_LOCATION));
- visit (param.get_type ());
- }
- else
- {
- if (name != "")
- {
- push (Rust::Token::make_identifier (param.get_locus (),
- std::move (name)));
- push (Rust::Token::make (COLON, UNDEF_LOCATION));
- }
- push (Rust::Token::make (ELLIPSIS, UNDEF_LOCATION));
- }
-}
-
void
TokenCollector::visit (std::vector<std::unique_ptr<GenericParam>> ¶ms)
{
diff --git a/gcc/rust/ast/rust-ast-collector.h b/gcc/rust/ast/rust-ast-collector.h
index 32a5bd33da7..30aff985105 100644
--- a/gcc/rust/ast/rust-ast-collector.h
+++ b/gcc/rust/ast/rust-ast-collector.h
@@ -210,7 +210,6 @@ public:
void visit (TupleField &field);
void visit (StructField &field);
void visit (SimplePathSegment &segment);
- void visit (NamedFunctionParam ¶m);
void visit (MacroRule &rule);
void visit (WhereClause &rule);
void visit (std::vector<LifetimeParam> &for_lifetimes);
diff --git a/gcc/rust/ast/rust-ast-full-decls.h b/gcc/rust/ast/rust-ast-full-decls.h
index 80d217e0c52..9359248aabd 100644
--- a/gcc/rust/ast/rust-ast-full-decls.h
+++ b/gcc/rust/ast/rust-ast-full-decls.h
@@ -202,7 +202,6 @@ class TraitImpl;
class ExternalItem;
class ExternalTypeItem;
class ExternalStaticItem;
-class NamedFunctionParam;
class ExternBlock;
// rust-macro.h
diff --git a/gcc/rust/ast/rust-ast-visitor.cc b/gcc/rust/ast/rust-ast-visitor.cc
index d10ca6ca07b..6959c49d66a 100644
--- a/gcc/rust/ast/rust-ast-visitor.cc
+++ b/gcc/rust/ast/rust-ast-visitor.cc
@@ -1060,14 +1060,6 @@ DefaultASTVisitor::visit (AST::ExternalStaticItem &item)
visit (item.get_type ());
}
-void
-DefaultASTVisitor::visit (AST::NamedFunctionParam ¶m)
-{
- visit_outer_attrs (param);
- if (!param.is_variadic ())
- visit (param.get_type ());
-}
-
void
DefaultASTVisitor::visit (AST::ExternBlock &block)
{
diff --git a/gcc/rust/ast/rust-ast-visitor.h b/gcc/rust/ast/rust-ast-visitor.h
index 7e3423cd493..a7c1cc9c62b 100644
--- a/gcc/rust/ast/rust-ast-visitor.h
+++ b/gcc/rust/ast/rust-ast-visitor.h
@@ -428,7 +428,6 @@ public:
virtual void visit (AST::WhereClause &where);
virtual void visit (AST::StructField &field);
virtual void visit (AST::TupleField &field);
- virtual void visit (AST::NamedFunctionParam ¶m);
virtual void visit (AST::MacroRule &rule);
virtual void visit (AST::MacroInvocData &data);
virtual void visit (AST::MacroTranscriber &transcriber);
diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc
index 06a7a097cfb..25e522bf948 100644
--- a/gcc/rust/ast/rust-ast.cc
+++ b/gcc/rust/ast/rust-ast.cc
@@ -2997,22 +2997,6 @@ ExternalStaticItem::as_string () const
return str;
}
-std::string
-NamedFunctionParam::as_string () const
-{
- std::string str = append_attributes (outer_attrs, OUTER);
-
- if (has_name ())
- str += "\n" + name;
-
- if (is_variadic ())
- str += "...";
- else
- str += "\n Type: " + param_type->as_string ();
-
- return str;
-}
-
std::string
TraitItemConst::as_string () const
{
diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h
index 0baefdc367c..261e64e4242 100644
--- a/gcc/rust/ast/rust-item.h
+++ b/gcc/rust/ast/rust-item.h
@@ -3623,303 +3623,6 @@ protected:
}
};
-// A named function parameter used in external functions
-class NamedFunctionParam
-{
- // bool has_name; // otherwise is _
- std::string name;
-
- std::unique_ptr<Type> param_type;
-
- // seemingly new since writing this node
- std::vector<Attribute> outer_attrs;
-
- NodeId node_id;
- location_t locus;
- bool variadic;
-
-public:
- /* Returns whether the named function parameter has a name (i.e. name is not
- * '_'). */
- bool has_name () const { return name != "_" && name != ""; }
-
- bool has_outer_attrs () const { return !outer_attrs.empty (); }
-
- // Returns whether the named function parameter is in an error state.
- bool is_error () const
- {
- // also if identifier is "" but that is probably more costly to compute
- return param_type == nullptr && !variadic;
- }
-
- bool is_variadic () const { return variadic; }
-
- std::string get_name () const { return name; }
-
- location_t get_locus () { return locus; }
-
- // Creates an error state named function parameter.
- static NamedFunctionParam create_error ()
- {
- return NamedFunctionParam ("", nullptr, {}, UNDEF_LOCATION);
- }
-
- NamedFunctionParam (std::string name, std::unique_ptr<Type> param_type,
- std::vector<Attribute> outer_attrs, location_t locus)
- : name (std::move (name)), param_type (std::move (param_type)),
- outer_attrs (std::move (outer_attrs)),
- node_id (Analysis::Mappings::get ().get_next_node_id ()), locus (locus),
- variadic (false)
- {}
-
- NamedFunctionParam (std::string name, std::vector<Attribute> outer_attrs,
- location_t locus)
- : name (std::move (name)), param_type (nullptr),
- outer_attrs (std::move (outer_attrs)),
- node_id (Analysis::Mappings::get ().get_next_node_id ()), locus (locus),
- variadic (true)
- {}
-
- NamedFunctionParam (std::vector<Attribute> outer_attrs, location_t locus)
- : name (""), param_type (nullptr), outer_attrs (std::move (outer_attrs)),
- node_id (Analysis::Mappings::get ().get_next_node_id ()), locus (locus),
- variadic (true)
- {}
-
- // Copy constructor
- NamedFunctionParam (NamedFunctionParam const &other)
- : name (other.name), outer_attrs (other.outer_attrs),
- variadic (other.variadic)
- {
- node_id = other.node_id;
- // guard to prevent null dereference (only required if error state)
- if (other.param_type != nullptr)
- param_type = other.param_type->clone_type ();
- else
- param_type = nullptr;
- }
-
- ~NamedFunctionParam () = default;
-
- // Overloaded assignment operator to clone
- NamedFunctionParam &operator= (NamedFunctionParam const &other)
- {
- node_id = other.node_id;
- name = other.name;
- // has_name = other.has_name;
- outer_attrs = other.outer_attrs;
-
- // guard to prevent null dereference (only required if error state)
- if (other.param_type != nullptr)
- param_type = other.param_type->clone_type ();
- else
- param_type = nullptr;
-
- return *this;
- }
-
- // move constructors
- NamedFunctionParam (NamedFunctionParam &&other) = default;
- NamedFunctionParam &operator= (NamedFunctionParam &&other) = default;
-
- std::string as_string () const;
-
- // Based on idea that nane should never be empty.
- void mark_for_strip () { param_type = nullptr; };
- bool is_marked_for_strip () const { return is_error (); };
-
- // TODO: this mutable getter seems really dodgy. Think up better way.
- std::vector<Attribute> &get_outer_attrs () { return outer_attrs; }
- const std::vector<Attribute> &get_outer_attrs () const { return outer_attrs; }
-
- // TODO: is this better? Or is a "vis_block" better?
- Type &get_type ()
- {
- rust_assert (param_type != nullptr);
- return *param_type;
- }
-
- std::unique_ptr<Type> &get_type_ptr ()
- {
- rust_assert (param_type != nullptr);
- return param_type;
- }
-
- NodeId get_node_id () const { return node_id; }
-};
-
-// A function item used in an extern block
-class ExternalFunctionItem : public ExternalItem
-{
- // bool has_outer_attrs;
- std::vector<Attribute> outer_attrs;
-
- // bool has_visibility;
- Visibility visibility;
-
- Identifier item_name;
- location_t locus;
-
- // bool has_generics;
- // Generics generic_params;
- std::vector<std::unique_ptr<GenericParam>> generic_params; // inlined
-
- // bool has_return_type;
- // FunctionReturnType return_type;
- std::unique_ptr<Type> return_type; // inlined
-
- // bool has_where_clause;
- WhereClause where_clause;
-
- std::vector<NamedFunctionParam> function_params;
-
-public:
- // Returns whether item has generic parameters.
- bool has_generics () const { return !generic_params.empty (); }
-
- // Returns whether item has a return type (otherwise void).
- bool has_return_type () const { return return_type != nullptr; }
-
- // Returns whether item has a where clause.
- bool has_where_clause () const { return !where_clause.is_empty (); }
-
- // Returns whether item has outer attributes.
- bool has_outer_attrs () const { return !outer_attrs.empty (); }
-
- // Returns whether item has non-default visibility.
- bool has_visibility () const { return !visibility.is_error (); }
-
- // Returns whether item has variadic parameters.
- bool is_variadic () const
- {
- return function_params.size () != 0
- && function_params.back ().is_variadic ();
- }
-
- location_t get_locus () const { return locus; }
-
- Visibility &get_visibility () { return visibility; }
- const Visibility &get_visibility () const { return visibility; }
-
- ExternalFunctionItem (
- Identifier item_name,
- std::vector<std::unique_ptr<GenericParam>> generic_params,
- std::unique_ptr<Type> return_type, WhereClause where_clause,
- std::vector<NamedFunctionParam> function_params, Visibility vis,
- std::vector<Attribute> outer_attrs, location_t locus)
- : ExternalItem (), outer_attrs (std::move (outer_attrs)),
- visibility (std::move (vis)), item_name (std::move (item_name)),
- locus (locus), generic_params (std::move (generic_params)),
- return_type (std::move (return_type)),
- where_clause (std::move (where_clause)),
- function_params (std::move (function_params))
- {
- // TODO: assert that if has variadic outer attrs, then has_variadics is
- // true?
- }
-
- // Copy constructor with clone
- ExternalFunctionItem (ExternalFunctionItem const &other)
- : ExternalItem (other.get_node_id ()), outer_attrs (other.outer_attrs),
- visibility (other.visibility), item_name (other.item_name),
- locus (other.locus), where_clause (other.where_clause),
- function_params (other.function_params)
- {
- node_id = other.node_id;
- // guard to prevent null pointer dereference
- if (other.return_type != nullptr)
- return_type = other.return_type->clone_type ();
-
- generic_params.reserve (other.generic_params.size ());
- for (const auto &e : other.generic_params)
- generic_params.push_back (e->clone_generic_param ());
- }
-
- // Overloaded assignment operator with clone
- ExternalFunctionItem &operator= (ExternalFunctionItem const &other)
- {
- outer_attrs = other.outer_attrs;
- visibility = other.visibility;
- item_name = other.item_name;
- locus = other.locus;
- where_clause = other.where_clause;
- function_params = other.function_params;
- node_id = other.node_id;
-
- // guard to prevent null pointer dereference
- if (other.return_type != nullptr)
- return_type = other.return_type->clone_type ();
- else
- return_type = nullptr;
-
- generic_params.reserve (other.generic_params.size ());
- for (const auto &e : other.generic_params)
- generic_params.push_back (e->clone_generic_param ());
-
- return *this;
- }
-
- // move constructors
- ExternalFunctionItem (ExternalFunctionItem &&other) = default;
- ExternalFunctionItem &operator= (ExternalFunctionItem &&other) = default;
-
- std::string as_string () const override;
-
- void accept_vis (ASTVisitor &vis) override;
-
- // Based on idea that nane should never be empty.
- void mark_for_strip () override { item_name = {""}; };
- bool is_marked_for_strip () const override { return item_name.empty (); };
-
- // TODO: this mutable getter seems really dodgy. Think up better way.
- std::vector<Attribute> &get_outer_attrs () { return outer_attrs; }
- const std::vector<Attribute> &get_outer_attrs () const { return outer_attrs; }
-
- std::vector<NamedFunctionParam> &get_function_params ()
- {
- return function_params;
- }
- const std::vector<NamedFunctionParam> &get_function_params () const
- {
- return function_params;
- }
-
- std::vector<std::unique_ptr<GenericParam>> &get_generic_params ()
- {
- return generic_params;
- }
- const std::vector<std::unique_ptr<GenericParam>> &get_generic_params () const
- {
- return generic_params;
- }
-
- // TODO: is this better? Or is a "vis_block" better?
- WhereClause &get_where_clause () { return where_clause; }
-
- // TODO: is this better? Or is a "vis_block" better?
- Type &get_return_type ()
- {
- rust_assert (has_return_type ());
- return *return_type;
- }
-
- std::unique_ptr<Type> &get_return_type_ptr ()
- {
- rust_assert (has_return_type ());
- return return_type;
- }
-
- Identifier get_identifier () const { return item_name; };
-
-protected:
- /* Use covariance to implement clone function as returning this object
- * rather than base */
- ExternalFunctionItem *clone_external_item_impl () const override
- {
- return new ExternalFunctionItem (*this);
- }
-};
-
// An extern block AST node
class ExternBlock : public VisItem
{
diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index 185217a7b9b..353e859f013 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -5936,106 +5936,6 @@ Parser<ManagedTokenSource>::parse_extern_block (AST::Visibility vis,
std::move (outer_attrs), locus));
}
-template <typename ManagedTokenSource>
-AST::NamedFunctionParam
-Parser<ManagedTokenSource>::parse_named_function_param ()
-{
- AST::AttrVec outer_attrs = parse_outer_attributes ();
- location_t locus = lexer.peek_token ()->get_locus ();
-
- if (lexer.peek_token ()->get_id () == ELLIPSIS) // Unnamed variadic
- {
- lexer.skip_token (); // Skip ellipsis
- return AST::NamedFunctionParam (std::move (outer_attrs), locus);
- }
-
- // parse identifier/_
- std::string name;
-
- const_TokenPtr t = lexer.peek_token ();
- location_t name_location = t->get_locus ();
- switch (t->get_id ())
- {
- case IDENTIFIER:
- name = t->get_str ();
- lexer.skip_token ();
- break;
- case UNDERSCORE:
- name = "_";
- lexer.skip_token ();
- break;
- default:
- // this is not a function param, but not necessarily an error
- return AST::NamedFunctionParam::create_error ();
- }
-
- if (!skip_token (COLON))
- {
- // skip after somewhere?
- return AST::NamedFunctionParam::create_error ();
- }
-
- if (lexer.peek_token ()->get_id () == ELLIPSIS) // Named variadic
- {
- lexer.skip_token (); // Skip ellipsis
- return AST::NamedFunctionParam (std::move (name), std::move (outer_attrs),
- locus);
- }
-
- // parse (required) type
- std::unique_ptr<AST::Type> param_type = parse_type ();
- if (param_type == nullptr)
- {
- Error error (
- lexer.peek_token ()->get_locus (),
- "could not parse param type in extern block function declaration");
- add_error (std::move (error));
-
- skip_after_semicolon ();
- return AST::NamedFunctionParam::create_error ();
- }
-
- return AST::NamedFunctionParam (std::move (name), std::move (param_type),
- std::move (outer_attrs), name_location);
-}
-
-template <typename ManagedTokenSource>
-template <typename EndTokenPred>
-std::vector<AST::NamedFunctionParam>
-Parser<ManagedTokenSource>::parse_named_function_params (
- EndTokenPred is_end_token)
-{
- std::vector<AST::NamedFunctionParam> params;
- if (is_end_token (lexer.peek_token ()->get_id ()))
- return params;
-
- auto initial_param = parse_named_function_param ();
- if (initial_param.is_error ())
- return params;
-
- params.push_back (std::move (initial_param));
- auto t = lexer.peek_token ();
- while (t->get_id () == COMMA)
- {
- lexer.skip_token ();
- if (is_end_token (lexer.peek_token ()->get_id ()))
- break;
-
- auto param = parse_named_function_param ();
- if (param.is_error ())
- {
- Error error (lexer.peek_token ()->get_locus (),
- "failed to parse param in c function params");
- add_error (error);
- return std::vector<AST::NamedFunctionParam> ();
- }
- params.push_back (std::move (param));
- t = lexer.peek_token ();
- }
- params.shrink_to_fit ();
- return params;
-}
-
// Parses a single extern block item (static or function declaration).
template <typename ManagedTokenSource>
std::unique_ptr<AST::ExternalItem>
diff --git a/gcc/rust/parse/rust-parse.h b/gcc/rust/parse/rust-parse.h
index 95c0a0b9428..6c50ba9523d 100644
--- a/gcc/rust/parse/rust-parse.h
+++ b/gcc/rust/parse/rust-parse.h
@@ -310,10 +310,6 @@ private:
AST::Lifetime lifetime_from_token (const_TokenPtr tok);
std::unique_ptr<AST::ExternalTypeItem>
parse_external_type_item (AST::Visibility vis, AST::AttrVec outer_attrs);
- AST::NamedFunctionParam parse_named_function_param ();
- template <typename EndTokenPred>
- std::vector<AST::NamedFunctionParam>
- parse_named_function_params (EndTokenPred is_end_token);
std::unique_ptr<AST::TypeAlias> parse_type_alias (AST::Visibility vis,
AST::AttrVec outer_attrs);
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 121/146] gccrs: ast: Fix warning about copy elision for moved expr
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (119 preceding siblings ...)
2025-03-21 12:07 ` [COMMITTED 120/146] gccrs: Remove dead code related to external functions arthur.cohen
@ 2025-03-21 12:07 ` arthur.cohen
2025-03-21 12:07 ` [COMMITTED 122/146] gccrs: attributes: Add #[derive] as a built-in attribute arthur.cohen
` (24 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:07 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
gcc/rust/ChangeLog:
* ast/rust-ast.cc (BlockExpr::normalize_tail_expr): Remove overzealous
std::move
---
gcc/rust/ast/rust-ast.cc | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc
index 25e522bf948..45189a1a4b3 100644
--- a/gcc/rust/ast/rust-ast.cc
+++ b/gcc/rust/ast/rust-ast.cc
@@ -4270,7 +4270,7 @@ BlockExpr::normalize_tail_expr ()
if (!stmt.is_semicolon_followed ())
{
- expr = std::move (stmt.take_expr ());
+ expr = stmt.take_expr ();
statements.pop_back ();
}
}
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 122/146] gccrs: attributes: Add #[derive] as a built-in attribute
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (120 preceding siblings ...)
2025-03-21 12:07 ` [COMMITTED 121/146] gccrs: ast: Fix warning about copy elision for moved expr arthur.cohen
@ 2025-03-21 12:07 ` arthur.cohen
2025-03-21 12:07 ` [COMMITTED 123/146] gccrs: collect-lang-items: Display attribute upon error finding it arthur.cohen
` (23 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:07 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
gcc/rust/ChangeLog:
* util/rust-attribute-values.h: Declare new attribute value.
* util/rust-attributes.cc: Use it.
---
gcc/rust/util/rust-attribute-values.h | 1 +
gcc/rust/util/rust-attributes.cc | 1 +
2 files changed, 2 insertions(+)
diff --git a/gcc/rust/util/rust-attribute-values.h b/gcc/rust/util/rust-attribute-values.h
index ef01e67dc52..9ef5cc52e81 100644
--- a/gcc/rust/util/rust-attribute-values.h
+++ b/gcc/rust/util/rust-attribute-values.h
@@ -29,6 +29,7 @@ public:
static constexpr auto &COLD = "cold";
static constexpr auto &CFG = "cfg";
static constexpr auto &CFG_ATTR = "cfg_attr";
+ static constexpr auto &DERIVE_ATTR = "derive";
static constexpr auto &DEPRECATED = "deprecated";
static constexpr auto &ALLOW = "allow";
static constexpr auto &ALLOW_INTERNAL_UNSTABLE = "allow_internal_unstable";
diff --git a/gcc/rust/util/rust-attributes.cc b/gcc/rust/util/rust-attributes.cc
index 9f63234112c..03452c75bd8 100644
--- a/gcc/rust/util/rust-attributes.cc
+++ b/gcc/rust/util/rust-attributes.cc
@@ -46,6 +46,7 @@ static const BuiltinAttrDefinition __definitions[]
{Attrs::COLD, CODE_GENERATION},
{Attrs::CFG, EXPANSION},
{Attrs::CFG_ATTR, EXPANSION},
+ {Attrs::DERIVE_ATTR, EXPANSION},
{Attrs::DEPRECATED, STATIC_ANALYSIS},
{Attrs::ALLOW, STATIC_ANALYSIS},
{Attrs::ALLOW_INTERNAL_UNSTABLE, STATIC_ANALYSIS},
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 123/146] gccrs: collect-lang-items: Display attribute upon error finding it
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (121 preceding siblings ...)
2025-03-21 12:07 ` [COMMITTED 122/146] gccrs: attributes: Add #[derive] as a built-in attribute arthur.cohen
@ 2025-03-21 12:07 ` arthur.cohen
2025-03-21 12:07 ` [COMMITTED 124/146] gccrs: ast: Refactor how lang item paths are handled arthur.cohen
` (22 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:07 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
gcc/rust/ChangeLog:
* ast/rust-collect-lang-items.cc (get_lang_item_attr): Show unknown attribute upon error.
---
gcc/rust/ast/rust-collect-lang-items.cc | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/gcc/rust/ast/rust-collect-lang-items.cc b/gcc/rust/ast/rust-collect-lang-items.cc
index 50d134a429f..168123ee56e 100644
--- a/gcc/rust/ast/rust-collect-lang-items.cc
+++ b/gcc/rust/ast/rust-collect-lang-items.cc
@@ -36,7 +36,8 @@ get_lang_item_attr (const T &maybe_lang_item)
const auto &str_path = attr.get_path ().as_string ();
if (!Analysis::Attributes::is_known (str_path))
{
- rust_error_at (attr.get_locus (), "unknown attribute");
+ rust_error_at (attr.get_locus (), "unknown attribute %qs",
+ str_path.c_str ());
continue;
}
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 124/146] gccrs: ast: Refactor how lang item paths are handled.
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (122 preceding siblings ...)
2025-03-21 12:07 ` [COMMITTED 123/146] gccrs: collect-lang-items: Display attribute upon error finding it arthur.cohen
@ 2025-03-21 12:07 ` arthur.cohen
2025-03-21 12:07 ` [COMMITTED 125/146] gccrs: tychk: resolve lang item type paths properly arthur.cohen
` (21 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:07 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
Lang item typepaths were not handled properly, and required a complete overhaul.
All old classes that concerned lang item paths are now modified to use a simpler
version of `AST::LangItemPath`, which has been removed. TypePath segments can now
be lang items, as this is requied for having generic lang item paths such as
PhantomData<T>.
gcc/rust/ChangeLog:
* ast/rust-path.h: Rework how lang item paths are represented.
* ast/rust-path.cc: Likewise.
* ast/rust-item.h: Likewise.
* ast/rust-ast.cc: Likewise.
* ast/rust-ast-collector.cc: Adapt to new lang item path system.
* ast/rust-ast-collector.h: Likewise.
* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Likewise.
* ast/rust-ast-visitor.h: Likewise.
* expand/rust-derive-copy.cc: Likewise.
* expand/rust-derive.h: Likewise.
* hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Likewise.
* hir/rust-ast-lower-base.h: Likewise.
* hir/rust-ast-lower-type.cc (ASTLowerTypePath::translate): Likewise.
(ASTLowerTypePath::visit): Likewise.
* hir/rust-ast-lower-type.h: Likewise.
* resolve/rust-ast-resolve-base.cc (ResolverBase::visit): Likewise.
* resolve/rust-ast-resolve-base.h: Likewise.
* resolve/rust-ast-resolve-item.cc (ResolveItem::visit): Likewise.
* resolve/rust-ast-resolve-type.h: Likewise.
* resolve/rust-ast-resolve-type.cc (ResolveRelativeTypePath::go): Likewise.
* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Likewise.
* resolve/rust-late-name-resolver-2.0.h: Likewise.
* hir/tree/rust-hir-path.cc (TypePathSegment::TypePathSegment): Likewise.
(TypePathSegmentGeneric::TypePathSegmentGeneric): Likewise.
* hir/tree/rust-hir-path.h: Likewise.
* typecheck/rust-hir-type-check-type.cc (TypeCheckType::resolve_root_path): Likewise.
* ast/rust-ast-builder.cc: Likewise.
* ast/rust-ast-builder.h: Likewise.
---
gcc/rust/ast/rust-ast-builder.cc | 20 +-
gcc/rust/ast/rust-ast-builder.h | 4 -
gcc/rust/ast/rust-ast-collector.cc | 13 -
gcc/rust/ast/rust-ast-collector.h | 2 -
gcc/rust/ast/rust-ast-visitor.cc | 11 -
gcc/rust/ast/rust-ast-visitor.h | 4 -
gcc/rust/ast/rust-ast.cc | 4 +-
gcc/rust/ast/rust-item.h | 40 +-
gcc/rust/ast/rust-path.cc | 31 +-
gcc/rust/ast/rust-path.h | 405 +++++++-----------
gcc/rust/expand/rust-derive-copy.cc | 4 +-
gcc/rust/expand/rust-derive.h | 2 -
gcc/rust/hir/rust-ast-lower-base.cc | 6 -
gcc/rust/hir/rust-ast-lower-base.h | 2 -
gcc/rust/hir/rust-ast-lower-type.cc | 75 ++--
gcc/rust/hir/rust-ast-lower-type.h | 6 +-
gcc/rust/hir/tree/rust-hir-path.cc | 21 +-
gcc/rust/hir/tree/rust-hir-path.h | 38 +-
gcc/rust/resolve/rust-ast-resolve-base.cc | 8 -
gcc/rust/resolve/rust-ast-resolve-base.h | 2 -
gcc/rust/resolve/rust-ast-resolve-item.cc | 27 +-
gcc/rust/resolve/rust-ast-resolve-type.cc | 79 ++--
gcc/rust/resolve/rust-ast-resolve-type.h | 31 --
.../resolve/rust-late-name-resolver-2.0.cc | 19 -
.../resolve/rust-late-name-resolver-2.0.h | 1 -
.../typecheck/rust-hir-type-check-type.cc | 2 +-
26 files changed, 311 insertions(+), 546 deletions(-)
diff --git a/gcc/rust/ast/rust-ast-builder.cc b/gcc/rust/ast/rust-ast-builder.cc
index 22fb0d83f97..f6d0f0dc4ae 100644
--- a/gcc/rust/ast/rust-ast-builder.cc
+++ b/gcc/rust/ast/rust-ast-builder.cc
@@ -42,15 +42,6 @@ Builder::call (std::unique_ptr<Expr> &&path,
new CallExpr (std::move (path), std::move (args), {}, loc));
}
-std::unique_ptr<Expr>
-Builder::call (std::unique_ptr<Path> &&path,
- std::vector<std::unique_ptr<Expr>> &&args) const
-{
- return call (std::unique_ptr<Expr> (
- new PathInExpression (std::move (path), {}, loc)),
- std::move (args));
-}
-
std::unique_ptr<Expr>
Builder::call (std::unique_ptr<Expr> &&path, std::unique_ptr<Expr> &&arg) const
{
@@ -60,15 +51,6 @@ Builder::call (std::unique_ptr<Expr> &&path, std::unique_ptr<Expr> &&arg) const
return call (std::move (path), std::move (args));
}
-std::unique_ptr<Expr>
-Builder::call (std::unique_ptr<Path> &&path, std::unique_ptr<Expr> &&arg) const
-{
- auto args = std::vector<std::unique_ptr<Expr>> ();
- args.emplace_back (std::move (arg));
-
- return call (std::move (path), std::move (args));
-}
-
std::unique_ptr<Expr>
Builder::array (std::vector<std::unique_ptr<Expr>> &&members) const
{
@@ -242,7 +224,7 @@ Builder::wildcard () const
std::unique_ptr<Path>
Builder::lang_item_path (LangItem::Kind kind) const
{
- return std::unique_ptr<Path> (new LangItemPath (kind, loc));
+ return std::unique_ptr<Path> (new PathInExpression (kind, {}, loc));
}
std::unique_ptr<Expr>
diff --git a/gcc/rust/ast/rust-ast-builder.h b/gcc/rust/ast/rust-ast-builder.h
index 6e07df6e182..aaf05c6d1fb 100644
--- a/gcc/rust/ast/rust-ast-builder.h
+++ b/gcc/rust/ast/rust-ast-builder.h
@@ -72,12 +72,8 @@ public:
*/
std::unique_ptr<Expr> call (std::unique_ptr<Expr> &&path,
std::vector<std::unique_ptr<Expr>> &&args) const;
- std::unique_ptr<Expr> call (std::unique_ptr<Path> &&path,
- std::vector<std::unique_ptr<Expr>> &&args) const;
std::unique_ptr<Expr> call (std::unique_ptr<Expr> &&path,
std::unique_ptr<Expr> &&arg) const;
- std::unique_ptr<Expr> call (std::unique_ptr<Path> &&path,
- std::unique_ptr<Expr> &&arg) const;
/**
* Create an array expression (`[member0, member1, member2]`)
diff --git a/gcc/rust/ast/rust-ast-collector.cc b/gcc/rust/ast/rust-ast-collector.cc
index 320611614e9..f493da3fa3f 100644
--- a/gcc/rust/ast/rust-ast-collector.cc
+++ b/gcc/rust/ast/rust-ast-collector.cc
@@ -538,19 +538,6 @@ TokenCollector::visit (PathInExpression &path)
visit_items_joined_by_separator (path.get_segments (), SCOPE_RESOLUTION);
}
-void
-TokenCollector::visit (RegularPath &path)
-{
- // FIXME: We probably want to have a proper implementation here, and call this
- // function from things like the PathInExpression visitor
-}
-
-void
-TokenCollector::visit (LangItemPath &path)
-{
- // TODO: Implement proper token collection for lang item paths
-}
-
void
TokenCollector::visit (TypePathSegment &segment)
{
diff --git a/gcc/rust/ast/rust-ast-collector.h b/gcc/rust/ast/rust-ast-collector.h
index 30aff985105..b014c23ed0b 100644
--- a/gcc/rust/ast/rust-ast-collector.h
+++ b/gcc/rust/ast/rust-ast-collector.h
@@ -233,8 +233,6 @@ public:
void visit (PathExprSegment &segment);
void visit (PathIdentSegment &segment);
void visit (PathInExpression &path);
- void visit (RegularPath &path);
- void visit (LangItemPath &path);
void visit (TypePathSegment &segment);
void visit (TypePathSegmentGeneric &segment);
void visit (TypePathSegmentFunction &segment);
diff --git a/gcc/rust/ast/rust-ast-visitor.cc b/gcc/rust/ast/rust-ast-visitor.cc
index 6959c49d66a..e2e2d9dda37 100644
--- a/gcc/rust/ast/rust-ast-visitor.cc
+++ b/gcc/rust/ast/rust-ast-visitor.cc
@@ -85,17 +85,6 @@ DefaultASTVisitor::visit (AST::ConstGenericParam &const_param)
visit (const_param.get_default_value ());
}
-void
-DefaultASTVisitor::visit (AST::RegularPath &path)
-{
- for (auto &segment : path.get_segments ())
- visit (segment);
-}
-
-void
-DefaultASTVisitor::visit (AST::LangItemPath &path)
-{}
-
void
DefaultASTVisitor::visit (AST::PathInExpression &path)
{
diff --git a/gcc/rust/ast/rust-ast-visitor.h b/gcc/rust/ast/rust-ast-visitor.h
index a7c1cc9c62b..51661df76b4 100644
--- a/gcc/rust/ast/rust-ast-visitor.h
+++ b/gcc/rust/ast/rust-ast-visitor.h
@@ -60,8 +60,6 @@ public:
// virtual void visit(TraitImplItem& trait_impl_item) = 0;
// rust-path.h
- virtual void visit (RegularPath &path) = 0;
- virtual void visit (LangItemPath &path) = 0;
virtual void visit (PathInExpression &path) = 0;
virtual void visit (TypePathSegment &segment) = 0;
virtual void visit (TypePathSegmentGeneric &segment) = 0;
@@ -252,8 +250,6 @@ public:
virtual void visit (AST::Lifetime &lifetime) override;
virtual void visit (AST::LifetimeParam &lifetime_param) override;
virtual void visit (AST::ConstGenericParam &const_param) override;
- virtual void visit (AST::RegularPath &path) override;
- virtual void visit (AST::LangItemPath &path) override;
virtual void visit (AST::PathInExpression &path) override;
virtual void visit (AST::TypePathSegment &segment) override;
virtual void visit (AST::TypePathSegmentGeneric &segment) override;
diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc
index 45189a1a4b3..ab82303879c 100644
--- a/gcc/rust/ast/rust-ast.cc
+++ b/gcc/rust/ast/rust-ast.cc
@@ -1299,7 +1299,7 @@ TraitImpl::as_string () const
else
str += "false";
- str += "\n TypePath (to trait): " + trait_path->as_string ();
+ str += "\n TypePath (to trait): " + trait_path.as_string ();
str += "\n Type (struct to impl on): " + trait_type->as_string ();
@@ -1561,7 +1561,7 @@ QualifiedPathType::as_string () const
str += type_to_invoke_on->as_string ();
if (has_as_clause ())
- str += " as " + trait_path->as_string ();
+ str += " as " + trait_path.as_string ();
return str + ">";
}
diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h
index 261e64e4242..8eb0cc51d5d 100644
--- a/gcc/rust/ast/rust-item.h
+++ b/gcc/rust/ast/rust-item.h
@@ -3254,7 +3254,7 @@ class TraitImpl : public Impl
{
bool has_unsafe;
bool has_exclam;
- std::unique_ptr<Path> trait_path;
+ TypePath trait_path;
// bool has_impl_items;
std::vector<std::unique_ptr<AssociatedItem>> impl_items;
@@ -3266,7 +3266,7 @@ public:
bool has_impl_items () const { return !impl_items.empty (); }
// Mega-constructor
- TraitImpl (std::unique_ptr<Path> trait_path, bool is_unsafe, bool has_exclam,
+ TraitImpl (TypePath trait_path, bool is_unsafe, bool has_exclam,
std::vector<std::unique_ptr<AssociatedItem>> impl_items,
std::vector<std::unique_ptr<GenericParam>> generic_params,
std::unique_ptr<Type> trait_type, WhereClause where_clause,
@@ -3275,29 +3275,14 @@ public:
: Impl (std::move (generic_params), std::move (trait_type),
std::move (where_clause), std::move (vis), std::move (inner_attrs),
std::move (outer_attrs), locus),
- has_unsafe (is_unsafe), has_exclam (has_exclam),
- trait_path (std::move (trait_path)), impl_items (std::move (impl_items))
- {}
-
- // Delegating constructor for TypePath
- TraitImpl (TypePath trait_path, bool is_unsafe, bool has_exclam,
- std::vector<std::unique_ptr<AssociatedItem>> impl_items,
- std::vector<std::unique_ptr<GenericParam>> generic_params,
- std::unique_ptr<Type> trait_type, WhereClause where_clause,
- Visibility vis, std::vector<Attribute> inner_attrs,
- std::vector<Attribute> outer_attrs, location_t locus)
- : TraitImpl (std::unique_ptr<Path> (new TypePath (trait_path)), is_unsafe,
- has_exclam, std::move (impl_items), std::move (generic_params),
- std::move (trait_type), std::move (where_clause),
- std::move (vis), std::move (inner_attrs),
- std::move (outer_attrs), locus)
+ has_unsafe (is_unsafe), has_exclam (has_exclam), trait_path (trait_path),
+ impl_items (std::move (impl_items))
{}
// Copy constructor with vector clone
TraitImpl (TraitImpl const &other)
: Impl (other), has_unsafe (other.has_unsafe),
- has_exclam (other.has_exclam),
- trait_path (other.trait_path->clone_path ())
+ has_exclam (other.has_exclam), trait_path (other.trait_path)
{
impl_items.reserve (other.impl_items.size ());
for (const auto &e : other.impl_items)
@@ -3308,7 +3293,7 @@ public:
TraitImpl &operator= (TraitImpl const &other)
{
Impl::operator= (other);
- trait_path = other.trait_path->clone_path ();
+ trait_path = other.trait_path;
has_unsafe = other.has_unsafe;
has_exclam = other.has_exclam;
@@ -3339,18 +3324,7 @@ public:
}
// TODO: is this better? Or is a "vis_block" better?
- Path &get_trait_path ()
- {
- // TODO: assert that trait path is not empty?
- return *trait_path;
- }
-
- Type &get_trait_path_type ()
- {
- rust_assert (trait_path->get_path_kind () == Path::Kind::Type);
-
- return (AST::Type &) static_cast<AST::TypePath &> (*trait_path);
- }
+ TypePath &get_trait_path () { return trait_path; }
protected:
/* Use covariance to implement clone function as returning this object
diff --git a/gcc/rust/ast/rust-path.cc b/gcc/rust/ast/rust-path.cc
index 94cf2bb1514..69627be81af 100644
--- a/gcc/rust/ast/rust-path.cc
+++ b/gcc/rust/ast/rust-path.cc
@@ -136,8 +136,11 @@ PathExprSegment::as_string () const
}
std::string
-RegularPath::as_string () const
+Path::as_string () const
{
+ // FIXME: Impl for lang items
+ rust_assert (kind == Kind::Regular);
+
std::string str;
for (const auto &segment : segments)
@@ -149,15 +152,11 @@ RegularPath::as_string () const
return str;
}
-std::string
-LangItemPath::as_string () const
-{
- return "#[lang = \"" + LangItem::ToString (kind) + "\"]";
-}
-
SimplePath
-RegularPath::convert_to_simple_path (bool with_opening_scope_resolution) const
+Path::convert_to_simple_path (bool with_opening_scope_resolution) const
{
+ rust_assert (kind == Kind::Regular);
+
if (!has_segments ())
return SimplePath::create_empty ();
@@ -190,18 +189,6 @@ RegularPath::convert_to_simple_path (bool with_opening_scope_resolution) const
locus);
}
-void
-RegularPath::accept_vis (ASTVisitor &vis)
-{
- vis.visit (*this);
-}
-
-void
-LangItemPath::accept_vis (ASTVisitor &vis)
-{
- vis.visit (*this);
-}
-
void
PathInExpression::accept_vis (ASTVisitor &vis)
{
@@ -216,7 +203,7 @@ PathInExpression::as_string () const
if (has_opening_scope_resolution)
str = "::";
- return str + path->as_string ();
+ return str + Path::as_string ();
}
std::string
@@ -316,7 +303,7 @@ TypePathFunction::as_string () const
std::string
QualifiedPathInExpression::as_string () const
{
- return path_type.as_string () + "::" + path->as_string ();
+ return path_type.as_string () + "::" + Path::as_string ();
}
std::string
diff --git a/gcc/rust/ast/rust-path.h b/gcc/rust/ast/rust-path.h
index b7eba446540..2a76acc48c3 100644
--- a/gcc/rust/ast/rust-path.h
+++ b/gcc/rust/ast/rust-path.h
@@ -21,6 +21,7 @@
/* "Path" (identifier within namespaces, essentially) handling. Required include
* for virtually all AST-related functionality. */
+#include "optional.h"
#include "rust-ast.h"
#include "rust-hir-map.h"
#include "rust-mapping-common.h"
@@ -589,115 +590,75 @@ public:
{
LangItem,
Regular,
- Type,
};
- virtual Kind get_path_kind () const = 0;
-
- Pattern::Kind get_pattern_kind () override final
- {
- return Pattern::Kind::Path;
- }
-
- std::unique_ptr<Path> clone_path ()
- {
- return std::unique_ptr<Path> (clone_path_impl ());
- }
-
- Pattern *clone_pattern_impl () const override final
- {
- return clone_path_impl ();
- }
-
-protected:
- virtual Path *clone_path_impl () const = 0;
-};
-
-class RegularPath : public Path
-{
- std::vector<PathExprSegment> segments;
- NodeId node_id;
- location_t locus;
-
-public:
- explicit RegularPath (std::vector<PathExprSegment> &&segments,
- location_t locus, NodeId node_id)
- : segments (std::move (segments)), node_id (node_id), locus (locus)
+ Path (std::vector<PathExprSegment> segments)
+ : segments (std::move (segments)), lang_item (tl::nullopt),
+ kind (Kind::Regular)
{}
- std::string as_string () const override;
+ Path (LangItem::Kind lang_item)
+ : segments ({}), lang_item (lang_item), kind (Kind::LangItem)
+ {}
// Returns whether path has segments.
- bool has_segments () const { return !segments.empty (); }
-
- std::vector<PathExprSegment> &get_segments () { return segments; }
-
- const std::vector<PathExprSegment> &get_segments () const { return segments; }
-
- /* Returns whether the path is a single segment (excluding qualified path
- * initial as segment). */
- bool is_single_segment () const { return segments.size () == 1; }
+ bool has_segments () const
+ {
+ rust_assert (kind == Kind::Regular);
+ return !segments.empty ();
+ }
/* Converts path segments to their equivalent SimplePath segments if
* possible, and creates a SimplePath from them. */
SimplePath convert_to_simple_path (bool with_opening_scope_resolution) const;
- Path::Kind get_path_kind () const override { return Path::Kind::Regular; }
-
- void accept_vis (ASTVisitor &vis) override;
-
- Path *clone_path_impl () const override
+ /* Returns whether the path is a single segment (excluding qualified path
+ * initial as segment). */
+ bool is_single_segment () const
{
- return new RegularPath (std::vector<PathExprSegment> (segments), locus,
- node_id);
+ rust_assert (kind == Kind::Regular);
+ return segments.size () == 1;
}
- NodeId get_node_id () const override { return node_id; }
- location_t get_locus () const override { return locus; }
-};
-
-class LangItemPath : public Path
-{
- LangItem::Kind kind;
- NodeId node_id;
- location_t locus;
-
- LangItemPath (LangItem::Kind kind, NodeId node_id, location_t locus)
- : kind (kind), node_id (node_id), locus (locus)
- {}
-
-public:
- explicit LangItemPath (LangItem::Kind kind, location_t locus)
- : kind (kind), node_id (Analysis::Mappings::get ().get_next_node_id ()),
- locus (locus)
- {}
-
- Path::Kind get_path_kind () const override { return Path::Kind::LangItem; }
+ std::string as_string () const override;
- void accept_vis (ASTVisitor &vis) override;
+ // TODO: this seems kinda dodgy
+ std::vector<PathExprSegment> &get_segments ()
+ {
+ rust_assert (kind == Kind::Regular);
+ return segments;
+ }
+ const std::vector<PathExprSegment> &get_segments () const
+ {
+ rust_assert (kind == Kind::Regular);
+ return segments;
+ }
- Path *clone_path_impl () const override
+ LangItem::Kind get_lang_item () const
{
- return new LangItemPath (kind, node_id, locus);
+ rust_assert (kind == Kind::LangItem);
+ return *lang_item;
}
- std::string as_string () const override;
+ Pattern::Kind get_pattern_kind () override { return Pattern::Kind::Path; }
+ Path::Kind get_path_kind () { return kind; }
- LangItem::Kind get_lang_item_kind () { return kind; }
+protected:
+ std::vector<PathExprSegment> segments;
+ tl::optional<LangItem::Kind> lang_item;
- NodeId get_node_id () const override { return node_id; }
- location_t get_locus () const override { return locus; }
+ Path::Kind kind;
};
/* AST node representing a path-in-expression pattern (path that allows
* generic arguments) */
-class PathInExpression : public Pattern, public ExprWithoutBlock
+class PathInExpression : public Path, public ExprWithoutBlock
{
std::vector<Attribute> outer_attrs;
bool has_opening_scope_resolution;
location_t locus;
NodeId _node_id;
- std::unique_ptr<Path> path;
+
bool marked_for_strip;
public:
@@ -707,52 +668,20 @@ public:
PathInExpression (std::vector<PathExprSegment> path_segments,
std::vector<Attribute> outer_attrs, location_t locus,
bool has_opening_scope_resolution = false)
- : outer_attrs (std::move (outer_attrs)),
+ : Path (std::move (path_segments)), outer_attrs (std::move (outer_attrs)),
has_opening_scope_resolution (has_opening_scope_resolution),
locus (locus), _node_id (Analysis::Mappings::get ().get_next_node_id ()),
- path (std::make_unique<RegularPath> (std::move (path_segments), locus,
- _node_id)),
marked_for_strip (false)
{}
- PathInExpression (LangItem::Kind lang_item_kind,
+ PathInExpression (LangItem::Kind lang_item,
std::vector<Attribute> outer_attrs, location_t locus)
- : outer_attrs (std::move (outer_attrs)),
+ : Path (lang_item), outer_attrs (std::move (outer_attrs)),
has_opening_scope_resolution (false), locus (locus),
_node_id (Analysis::Mappings::get ().get_next_node_id ()),
- path (std::make_unique<LangItemPath> (lang_item_kind, locus)),
marked_for_strip (false)
{}
- PathInExpression (std::unique_ptr<Path> path,
- std::vector<Attribute> outer_attrs, location_t locus,
- bool has_opening_scope_resolution = false)
- : outer_attrs (std::move (outer_attrs)),
- has_opening_scope_resolution (has_opening_scope_resolution),
- locus (locus), _node_id (Analysis::Mappings::get ().get_next_node_id ()),
- path (std::move (path)), marked_for_strip (false)
- {}
-
- PathInExpression (const PathInExpression &other)
- : outer_attrs (other.outer_attrs),
- has_opening_scope_resolution (other.has_opening_scope_resolution),
- locus (other.locus), _node_id (other._node_id),
- path (other.path->clone_path ()),
- marked_for_strip (other.marked_for_strip)
- {}
-
- PathInExpression &operator= (const PathInExpression &other)
- {
- outer_attrs = other.outer_attrs;
- has_opening_scope_resolution = other.has_opening_scope_resolution;
- locus = other.locus;
- _node_id = other._node_id;
- path = other.path->clone_path ();
- marked_for_strip = other.marked_for_strip;
-
- return *this;
- }
-
// Creates an error state path in expression.
static PathInExpression create_error ()
{
@@ -761,25 +690,19 @@ public:
}
// Returns whether path in expression is in an error state.
- bool is_error () const
- {
- if (path->get_path_kind () == Path::Kind::Regular)
- return !static_cast<RegularPath &> (*path).has_segments ();
-
- rust_unreachable ();
- }
+ bool is_error () const { return !has_segments (); }
/* Converts PathInExpression to SimplePath if possible (i.e. no generic
* arguments). Otherwise returns an empty SimplePath. */
SimplePath as_simple_path () const
{
- // FIXME: Cleanup
- if (path->get_path_kind () == Path::Kind::Regular)
- return static_cast<RegularPath &> (*path).convert_to_simple_path (
- has_opening_scope_resolution);
- else
- // FIXME: lang item to simple path?
- rust_unreachable ();
+ /* delegate to parent class as can't access segments. however,
+ * QualifiedPathInExpression conversion to simple path wouldn't make
+ * sense, so the method in the parent class should be protected, not
+ * public. Have to pass in opening scope resolution as parent class has no
+ * access to it.
+ */
+ return convert_to_simple_path (has_opening_scope_resolution);
}
location_t get_locus () const override final { return locus; }
@@ -806,66 +729,18 @@ public:
NodeId get_pattern_node_id () const { return get_node_id (); }
- PathExprSegment &get_final_segment ()
- {
- if (path->get_path_kind () == Path::Kind::Regular)
- return static_cast<RegularPath &> (*path).get_segments ().back ();
-
- // lang item segment?
- rust_unreachable ();
- }
-
+ PathExprSegment &get_final_segment () { return get_segments ().back (); }
const PathExprSegment &get_final_segment () const
{
- if (path->get_path_kind () == Path::Kind::Regular)
- return static_cast<RegularPath &> (*path).get_segments ().back ();
-
- // lang item segment?
- rust_unreachable ();
+ return get_segments ().back ();
}
- const std::vector<PathExprSegment> &get_segments () const
- {
- if (path->get_path_kind () == Path::Kind::Regular)
- return static_cast<RegularPath &> (*path).get_segments ();
-
- rust_unreachable ();
- }
-
- std::vector<PathExprSegment> &get_segments ()
- {
- if (path->get_path_kind () == Path::Kind::Regular)
- return static_cast<RegularPath &> (*path).get_segments ();
-
- rust_unreachable ();
- }
-
- bool is_single_segment () const
- {
- if (path->get_path_kind () == Path::Kind::Regular)
- return static_cast<RegularPath &> (*path).get_segments ().size () == 1;
-
- rust_unreachable ();
- }
-
- Pattern::Kind get_pattern_kind () override { return Pattern::Kind::Path; }
-
Expr::Kind get_expr_kind () const override
{
return Expr::Kind::PathInExpression;
}
protected:
- PathInExpression (std::vector<Attribute> &&outer_attrs,
- bool has_opening_scope_resolution, location_t locus,
- NodeId node_id, std::unique_ptr<Path> &&path,
- bool marked_for_strip)
- : outer_attrs (std::move (outer_attrs)),
- has_opening_scope_resolution (has_opening_scope_resolution),
- locus (locus), _node_id (node_id), path (std::move (path)),
- marked_for_strip (marked_for_strip)
- {}
-
/* Use covariance to implement clone function as returning this object
* rather than base */
PathInExpression *clone_pattern_impl () const final override
@@ -899,7 +774,8 @@ public:
};
private:
- PathIdentSegment ident_segment;
+ tl::optional<LangItem::Kind> lang_item;
+ tl::optional<PathIdentSegment> ident_segment;
location_t locus;
protected:
@@ -929,21 +805,30 @@ public:
TypePathSegment (PathIdentSegment ident_segment,
bool has_separating_scope_resolution, location_t locus)
- : ident_segment (std::move (ident_segment)), locus (locus),
+ : lang_item (tl::nullopt), ident_segment (std::move (ident_segment)),
+ locus (locus),
has_separating_scope_resolution (has_separating_scope_resolution),
node_id (Analysis::Mappings::get ().get_next_node_id ())
{}
+ TypePathSegment (LangItem::Kind lang_item, location_t locus)
+ : lang_item (lang_item), ident_segment (tl::nullopt), locus (locus),
+ has_separating_scope_resolution (false),
+ node_id (Analysis::Mappings::get ().get_next_node_id ())
+ {}
+
TypePathSegment (std::string segment_name,
bool has_separating_scope_resolution, location_t locus)
- : ident_segment (PathIdentSegment (std::move (segment_name), locus)),
+ : lang_item (tl::nullopt),
+ ident_segment (PathIdentSegment (std::move (segment_name), locus)),
locus (locus),
has_separating_scope_resolution (has_separating_scope_resolution),
node_id (Analysis::Mappings::get ().get_next_node_id ())
{}
TypePathSegment (TypePathSegment const &other)
- : ident_segment (other.ident_segment), locus (other.locus),
+ : lang_item (other.lang_item), ident_segment (other.ident_segment),
+ locus (other.locus),
has_separating_scope_resolution (other.has_separating_scope_resolution),
node_id (other.node_id)
{}
@@ -951,6 +836,7 @@ public:
TypePathSegment &operator= (TypePathSegment const &other)
{
ident_segment = other.ident_segment;
+ lang_item = other.lang_item;
locus = other.locus;
has_separating_scope_resolution = other.has_separating_scope_resolution;
node_id = other.node_id;
@@ -961,16 +847,28 @@ public:
TypePathSegment (TypePathSegment &&other) = default;
TypePathSegment &operator= (TypePathSegment &&other) = default;
- virtual std::string as_string () const { return ident_segment.as_string (); }
+ virtual std::string as_string () const
+ {
+ if (lang_item.has_value ())
+ return LangItem::PrettyString (*lang_item);
+
+ return ident_segment->as_string ();
+ }
/* Returns whether the type path segment is in an error state. May be
* virtual in future. */
- bool is_error () const { return ident_segment.is_error (); }
+ bool is_error () const
+ {
+ rust_assert (ident_segment);
+ return ident_segment->is_error ();
+ }
/* Returns whether segment is identifier only (as opposed to generic args or
* function). Overridden in derived classes with other segments. */
virtual bool is_ident_only () const { return true; }
+ bool is_lang_item () const { return lang_item.has_value (); }
+
location_t get_locus () const { return locus; }
// not pure virtual as class not abstract
@@ -981,8 +879,23 @@ public:
return has_separating_scope_resolution;
}
- PathIdentSegment &get_ident_segment () { return ident_segment; };
- const PathIdentSegment &get_ident_segment () const { return ident_segment; };
+ PathIdentSegment &get_ident_segment ()
+ {
+ rust_assert (!is_lang_item ());
+ return *ident_segment;
+ };
+
+ const PathIdentSegment &get_ident_segment () const
+ {
+ rust_assert (!is_lang_item ());
+ return *ident_segment;
+ };
+
+ LangItem::Kind get_lang_item () const
+ {
+ rust_assert (is_lang_item ());
+ return *lang_item;
+ }
NodeId get_node_id () const { return node_id; }
@@ -1025,6 +938,12 @@ public:
generic_args (std::move (generic_args))
{}
+ TypePathSegmentGeneric (LangItem::Kind lang_item, GenericArgs generic_args,
+ location_t locus)
+ : TypePathSegment (lang_item, locus),
+ generic_args (std::move (generic_args))
+ {}
+
// Constructor from segment name and all args
TypePathSegmentGeneric (std::string segment_name,
bool has_separating_scope_resolution,
@@ -1082,7 +1001,7 @@ private:
/*bool has_inputs;
TypePathFnInputs inputs;*/
// inlined from TypePathFnInputs
- std::vector<std::unique_ptr<Type> > inputs;
+ std::vector<std::unique_ptr<Type>> inputs;
// bool has_type;
std::unique_ptr<Type> return_type;
@@ -1115,8 +1034,8 @@ public:
}
// Constructor
- TypePathFunction (std::vector<std::unique_ptr<Type> > inputs,
- location_t locus, std::unique_ptr<Type> type = nullptr)
+ TypePathFunction (std::vector<std::unique_ptr<Type>> inputs, location_t locus,
+ std::unique_ptr<Type> type = nullptr)
: inputs (std::move (inputs)), return_type (std::move (type)),
is_invalid (false), locus (locus)
{}
@@ -1161,11 +1080,11 @@ public:
std::string as_string () const;
// TODO: this mutable getter seems really dodgy. Think up better way.
- const std::vector<std::unique_ptr<Type> > &get_params () const
+ const std::vector<std::unique_ptr<Type>> &get_params () const
{
return inputs;
}
- std::vector<std::unique_ptr<Type> > &get_params () { return inputs; }
+ std::vector<std::unique_ptr<Type>> &get_params () { return inputs; }
// TODO: is this better? Or is a "vis_pattern" better?
Type &get_return_type ()
@@ -1229,10 +1148,10 @@ public:
}
};
-class TypePath : public TypeNoBounds, public Path
+class TypePath : public TypeNoBounds
{
bool has_opening_scope_resolution;
- std::vector<std::unique_ptr<TypePathSegment> > segments;
+ std::vector<std::unique_ptr<TypePathSegment>> segments;
location_t locus;
protected:
@@ -1257,12 +1176,20 @@ public:
// Creates an error state TypePath.
static TypePath create_error ()
{
- return TypePath (std::vector<std::unique_ptr<TypePathSegment> > (),
+ return TypePath (std::vector<std::unique_ptr<TypePathSegment>> (),
UNDEF_LOCATION);
}
// Constructor
- TypePath (std::vector<std::unique_ptr<TypePathSegment> > segments,
+ TypePath (std::vector<std::unique_ptr<TypePathSegment>> segments,
+ location_t locus, bool has_opening_scope_resolution = false)
+ : TypeNoBounds (),
+ has_opening_scope_resolution (has_opening_scope_resolution),
+ segments (std::move (segments)), locus (locus)
+ {}
+
+ TypePath (LangItem::Kind lang_item,
+ std::vector<std::unique_ptr<TypePathSegment>> segments,
location_t locus, bool has_opening_scope_resolution = false)
: TypeNoBounds (),
has_opening_scope_resolution (has_opening_scope_resolution),
@@ -1308,7 +1235,7 @@ public:
TraitBound *to_trait_bound (bool in_parens) const override;
location_t get_locus () const override final { return locus; }
- NodeId get_node_id () const override final { return node_id; }
+ NodeId get_node_id () const { return node_id; }
void mark_for_strip () override {}
bool is_marked_for_strip () const override { return false; }
@@ -1316,27 +1243,23 @@ public:
void accept_vis (ASTVisitor &vis) override;
// TODO: this seems kinda dodgy
- std::vector<std::unique_ptr<TypePathSegment> > &get_segments ()
+ std::vector<std::unique_ptr<TypePathSegment>> &get_segments ()
{
return segments;
}
- const std::vector<std::unique_ptr<TypePathSegment> > &get_segments () const
+ const std::vector<std::unique_ptr<TypePathSegment>> &get_segments () const
{
return segments;
}
size_t get_num_segments () const { return segments.size (); }
-
- Path::Kind get_path_kind () const override { return Path::Kind::Type; }
-
- Path *clone_path_impl () const override { return new TypePath (*this); }
};
struct QualifiedPathType
{
private:
std::unique_ptr<Type> type_to_invoke_on;
- std::unique_ptr<Path> trait_path;
+ TypePath trait_path;
location_t locus;
NodeId node_id;
@@ -1345,14 +1268,13 @@ public:
QualifiedPathType (std::unique_ptr<Type> invoke_on_type,
location_t locus = UNDEF_LOCATION,
TypePath trait_path = TypePath::create_error ())
- : type_to_invoke_on (std::move (invoke_on_type)),
- trait_path (std::unique_ptr<TypePath> (new TypePath (trait_path))),
+ : type_to_invoke_on (std::move (invoke_on_type)), trait_path (trait_path),
locus (locus), node_id (Analysis::Mappings::get ().get_next_node_id ())
{}
// Copy constructor uses custom deep copy for Type to preserve polymorphism
QualifiedPathType (QualifiedPathType const &other)
- : trait_path (other.trait_path->clone_path ()), locus (other.locus)
+ : trait_path (other.trait_path), locus (other.locus)
{
node_id = other.node_id;
// guard to prevent null dereference
@@ -1367,7 +1289,7 @@ public:
QualifiedPathType &operator= (QualifiedPathType const &other)
{
node_id = other.node_id;
- trait_path = other.trait_path->clone_path ();
+ trait_path = other.trait_path;
locus = other.locus;
// guard to prevent null dereference
@@ -1384,11 +1306,7 @@ public:
QualifiedPathType &operator= (QualifiedPathType &&other) = default;
// Returns whether the qualified path type has a rebind as clause.
- bool has_as_clause () const
- {
- rust_assert (trait_path->get_path_kind () == Path::Kind::Type);
- return !static_cast<TypePath &> (*trait_path).is_error ();
- }
+ bool has_as_clause () const { return !trait_path.is_error (); }
// Returns whether the qualified path type is in an error state.
bool is_error () const { return type_to_invoke_on == nullptr; }
@@ -1417,10 +1335,10 @@ public:
}
// TODO: is this better? Or is a "vis_pattern" better?
- Path &get_as_type_path ()
+ TypePath &get_as_type_path ()
{
rust_assert (has_as_clause ());
- return *trait_path;
+ return trait_path;
}
NodeId get_node_id () const { return node_id; }
@@ -1428,12 +1346,12 @@ public:
/* AST node representing a qualified path-in-expression pattern (path that
* allows specifying trait functions) */
-class QualifiedPathInExpression : public Pattern, public ExprWithoutBlock
+class QualifiedPathInExpression : public Path, public ExprWithoutBlock
{
std::vector<Attribute> outer_attrs;
QualifiedPathType path_type;
-
- std::unique_ptr<Path> path;
+ location_t locus;
+ NodeId _node_id;
public:
std::string as_string () const override;
@@ -1442,16 +1360,9 @@ public:
std::vector<PathExprSegment> path_segments,
std::vector<Attribute> outer_attrs,
location_t locus)
- : outer_attrs (std::move (outer_attrs)),
- path_type (std::move (qual_path_type)),
- path (std::make_unique<RegularPath> (
- std::move (path_segments), locus,
- Analysis::Mappings::get ().get_next_node_id ()))
- {}
-
- QualifiedPathInExpression (const QualifiedPathInExpression &other)
- : outer_attrs (other.outer_attrs), path_type (other.path_type),
- path (other.path->clone_path ())
+ : Path (std::move (path_segments)), outer_attrs (std::move (outer_attrs)),
+ path_type (std::move (qual_path_type)), locus (locus),
+ _node_id (Analysis::Mappings::get ().get_next_node_id ())
{}
/* TODO: maybe make a shortcut constructor that has QualifiedPathType
@@ -1467,9 +1378,7 @@ public:
{}, UNDEF_LOCATION);
}
- Pattern::Kind get_pattern_kind () override { return Pattern::Kind::Path; }
-
- location_t get_locus () const override final { return path->get_locus (); }
+ location_t get_locus () const override final { return locus; }
void accept_vis (ASTVisitor &vis) override;
@@ -1495,31 +1404,7 @@ public:
outer_attrs = std::move (new_attrs);
}
- NodeId get_node_id () const override { return path->get_node_id (); }
-
- const std::vector<PathExprSegment> &get_segments () const
- {
- if (path->get_path_kind () == Path::Kind::Regular)
- return static_cast<RegularPath &> (*path).get_segments ();
-
- rust_unreachable ();
- }
-
- std::vector<PathExprSegment> &get_segments ()
- {
- if (path->get_path_kind () == Path::Kind::Regular)
- return static_cast<RegularPath &> (*path).get_segments ();
-
- rust_unreachable ();
- }
-
- bool is_single_segment () const
- {
- if (path->get_path_kind () == Path::Kind::Regular)
- return static_cast<RegularPath &> (*path).get_segments ().size () == 1;
-
- rust_unreachable ();
- }
+ NodeId get_node_id () const override { return _node_id; }
Expr::Kind get_expr_kind () const override
{
@@ -1555,7 +1440,7 @@ class QualifiedPathInType : public TypeNoBounds
{
QualifiedPathType path_type;
std::unique_ptr<TypePathSegment> associated_segment;
- std::vector<std::unique_ptr<TypePathSegment> > segments;
+ std::vector<std::unique_ptr<TypePathSegment>> segments;
location_t locus;
protected:
@@ -1570,7 +1455,7 @@ public:
QualifiedPathInType (
QualifiedPathType qual_path_type,
std::unique_ptr<TypePathSegment> associated_segment,
- std::vector<std::unique_ptr<TypePathSegment> > path_segments,
+ std::vector<std::unique_ptr<TypePathSegment>> path_segments,
location_t locus)
: path_type (std::move (qual_path_type)),
associated_segment (std::move (associated_segment)),
@@ -1617,7 +1502,7 @@ public:
{
return QualifiedPathInType (
QualifiedPathType::create_error (), nullptr,
- std::vector<std::unique_ptr<TypePathSegment> > (), UNDEF_LOCATION);
+ std::vector<std::unique_ptr<TypePathSegment>> (), UNDEF_LOCATION);
}
std::string as_string () const override;
@@ -1637,11 +1522,11 @@ public:
}
// TODO: this seems kinda dodgy
- std::vector<std::unique_ptr<TypePathSegment> > &get_segments ()
+ std::vector<std::unique_ptr<TypePathSegment>> &get_segments ()
{
return segments;
}
- const std::vector<std::unique_ptr<TypePathSegment> > &get_segments () const
+ const std::vector<std::unique_ptr<TypePathSegment>> &get_segments () const
{
return segments;
}
diff --git a/gcc/rust/expand/rust-derive-copy.cc b/gcc/rust/expand/rust-derive-copy.cc
index f8007abd575..bcfe1db6b4a 100644
--- a/gcc/rust/expand/rust-derive-copy.cc
+++ b/gcc/rust/expand/rust-derive-copy.cc
@@ -46,7 +46,9 @@ DeriveCopy::copy_impl (
// `$crate::core::marker::Copy` instead
auto segments = std::vector<std::unique_ptr<TypePathSegment>> ();
segments.emplace_back (builder.type_path_segment ("Copy"));
- auto copy = std::make_unique<LangItemPath> (LangItem::Kind::COPY, loc);
+
+ auto copy = TypePath (std::move (segments), loc);
+ // auto copy = TypePath (LangItem::Kind::COPY, loc);
// we need to build up the generics for this impl block which will be just a
// clone of the types specified ones
diff --git a/gcc/rust/expand/rust-derive.h b/gcc/rust/expand/rust-derive.h
index 967064c0420..1924432d8ed 100644
--- a/gcc/rust/expand/rust-derive.h
+++ b/gcc/rust/expand/rust-derive.h
@@ -81,8 +81,6 @@ private:
virtual void visit (Lifetime &lifetime) override final{};
virtual void visit (LifetimeParam &lifetime_param) override final{};
virtual void visit (ConstGenericParam &const_param) override final{};
- virtual void visit (RegularPath &path) override final{};
- virtual void visit (LangItemPath &path) override final{};
virtual void visit (PathInExpression &path) override final{};
virtual void visit (TypePathSegment &segment) override final{};
virtual void visit (TypePathSegmentGeneric &segment) override final{};
diff --git a/gcc/rust/hir/rust-ast-lower-base.cc b/gcc/rust/hir/rust-ast-lower-base.cc
index f6d7f0caf5b..35a25093b73 100644
--- a/gcc/rust/hir/rust-ast-lower-base.cc
+++ b/gcc/rust/hir/rust-ast-lower-base.cc
@@ -64,12 +64,6 @@ ASTLoweringBase::visit (AST::ConstGenericParam &)
// rust-path.h
void
-ASTLoweringBase::visit (AST::RegularPath &)
-{}
-void
-ASTLoweringBase::visit (AST::LangItemPath &)
-{}
-void
ASTLoweringBase::visit (AST::PathInExpression &)
{}
void
diff --git a/gcc/rust/hir/rust-ast-lower-base.h b/gcc/rust/hir/rust-ast-lower-base.h
index 4cb098b7ab8..1bd1343bd16 100644
--- a/gcc/rust/hir/rust-ast-lower-base.h
+++ b/gcc/rust/hir/rust-ast-lower-base.h
@@ -84,8 +84,6 @@ public:
// virtual void visit(TraitImplItem& trait_impl_item);
// rust-path.h
- virtual void visit (AST::RegularPath &path);
- virtual void visit (AST::LangItemPath &path);
virtual void visit (AST::PathInExpression &path);
virtual void visit (AST::TypePathSegment &segment);
virtual void visit (AST::TypePathSegmentGeneric &segment);
diff --git a/gcc/rust/hir/rust-ast-lower-type.cc b/gcc/rust/hir/rust-ast-lower-type.cc
index d1f95edc345..e78c1307523 100644
--- a/gcc/rust/hir/rust-ast-lower-type.cc
+++ b/gcc/rust/hir/rust-ast-lower-type.cc
@@ -27,22 +27,10 @@ namespace Rust {
namespace HIR {
HIR::TypePath *
-ASTLowerTypePath::translate (AST::Path &type)
+ASTLowerTypePath::translate (AST::TypePath &type)
{
ASTLowerTypePath resolver;
-
- switch (type.get_path_kind ())
- {
- case AST::Path::Kind::LangItem:
- resolver.visit (static_cast<AST::LangItemPath &> (type));
- break;
- case AST::Path::Kind::Type:
- resolver.visit (static_cast<AST::TypePath &> (type));
- break;
- default:
- rust_unreachable ();
- }
-
+ type.accept_vis (resolver);
rust_assert (resolver.translated != nullptr);
return resolver.translated;
}
@@ -98,10 +86,6 @@ ASTLowerTypePath::visit (AST::TypePathSegmentGeneric &segment)
{
std::vector<HIR::GenericArgsBinding> binding_args; // TODO
- std::string segment_name = segment.get_ident_segment ().as_string ();
- bool has_separating_scope_resolution
- = segment.get_separating_scope_resolution ();
-
auto generic_args = lower_generic_args (segment.get_generic_args ());
auto crate_num = mappings.get_current_crate ();
@@ -109,10 +93,24 @@ ASTLowerTypePath::visit (AST::TypePathSegmentGeneric &segment)
Analysis::NodeMapping mapping (crate_num, segment.get_node_id (), hirid,
UNKNOWN_LOCAL_DEFID);
- translated_segment
- = new HIR::TypePathSegmentGeneric (std::move (mapping), segment_name,
- has_separating_scope_resolution,
- generic_args, segment.get_locus ());
+ if (segment.is_lang_item ())
+ {
+ translated_segment
+ = new HIR::TypePathSegmentGeneric (std::move (mapping),
+ segment.get_lang_item (),
+ generic_args, segment.get_locus ());
+ }
+ else
+ {
+ std::string segment_name = segment.get_ident_segment ().as_string ();
+ bool has_separating_scope_resolution
+ = segment.get_separating_scope_resolution ();
+
+ translated_segment
+ = new HIR::TypePathSegmentGeneric (std::move (mapping), segment_name,
+ has_separating_scope_resolution,
+ generic_args, segment.get_locus ());
+ }
}
void
@@ -141,25 +139,26 @@ ASTLowerTypePath::visit (AST::TypePath &path)
path.has_opening_scope_resolution_op ());
}
-void
-ASTLowerTypePath::visit (AST::LangItemPath &path)
-{
- auto crate_num = mappings.get_current_crate ();
- auto hirid = mappings.get_next_hir_id (crate_num);
+// void
+// ASTLowerTypePath::visit (AST::LangItemPath &path)
+// {
+// auto crate_num = mappings.get_current_crate ();
+// auto hirid = mappings.get_next_hir_id (crate_num);
- Analysis::NodeMapping mapping (crate_num, path.get_node_id (), hirid,
- mappings.get_next_localdef_id (crate_num));
+// Analysis::NodeMapping mapping (crate_num, path.get_node_id (), hirid,
+// mappings.get_next_localdef_id (crate_num));
- std::vector<std::unique_ptr<HIR::TypePathSegment>> translated_segments;
- translated_segments.emplace_back (std::unique_ptr<HIR::TypePathSegment> (
- new HIR::TypePathSegment (mapping,
- LangItem::ToString (path.get_lang_item_kind ()),
- false, path.get_locus ())));
+// std::vector<std::unique_ptr<HIR::TypePathSegment>> translated_segments;
+// translated_segments.emplace_back (std::unique_ptr<HIR::TypePathSegment> (
+// new HIR::TypePathSegment (mapping,
+// LangItem::ToString (path.get_lang_item_kind ()),
+// false, path.get_locus ())));
- translated
- = new HIR::TypePath (std::move (mapping), std::move (translated_segments),
- path.get_locus ());
-}
+// translated
+// = new HIR::TypePath (std::move (mapping), std::move
+// (translated_segments),
+// path.get_locus ());
+// }
HIR::QualifiedPathInType *
ASTLowerQualifiedPathInType::translate (AST::QualifiedPathInType &type)
diff --git a/gcc/rust/hir/rust-ast-lower-type.h b/gcc/rust/hir/rust-ast-lower-type.h
index 26ca8684083..af0b4bec919 100644
--- a/gcc/rust/hir/rust-ast-lower-type.h
+++ b/gcc/rust/hir/rust-ast-lower-type.h
@@ -33,22 +33,18 @@ protected:
using Rust::HIR::ASTLoweringBase::visit;
public:
- static HIR::TypePath *translate (AST::Path &type);
+ static HIR::TypePath *translate (AST::TypePath &type);
void visit (AST::TypePathSegmentFunction &segment) override;
void visit (AST::TypePathSegment &segment) override;
void visit (AST::TypePathSegmentGeneric &segment) override;
void visit (AST::TypePath &path) override;
- void visit (AST::LangItemPath &path) override;
protected:
HIR::TypePathSegment *translated_segment;
private:
HIR::TypePath *translated;
-
- static HIR::TypePath *translate_type_path (AST::TypePath &type);
- static HIR::TypePath *translate_lang_item_type_path (AST::LangItemPath &type);
};
class ASTLowerQualifiedPathInType : public ASTLowerTypePath
diff --git a/gcc/rust/hir/tree/rust-hir-path.cc b/gcc/rust/hir/tree/rust-hir-path.cc
index c8d3079a85e..7db2b25b5aa 100644
--- a/gcc/rust/hir/tree/rust-hir-path.cc
+++ b/gcc/rust/hir/tree/rust-hir-path.cc
@@ -17,6 +17,7 @@
// <http://www.gnu.org/licenses/>.
#include "rust-hir-path.h"
+#include "optional.h"
#include "rust-hir-bound.h"
namespace Rust {
@@ -164,17 +165,25 @@ TypePathSegment::TypePathSegment (Analysis::NodeMapping mappings,
bool has_separating_scope_resolution,
location_t locus)
: mappings (std::move (mappings)), ident_segment (std::move (ident_segment)),
- locus (locus),
+ lang_item (tl::nullopt), locus (locus),
has_separating_scope_resolution (has_separating_scope_resolution),
type (SegmentType::REG)
{}
+TypePathSegment::TypePathSegment (Analysis::NodeMapping mappings,
+ LangItem::Kind lang_item, location_t locus)
+ : mappings (std::move (mappings)), ident_segment (tl::nullopt),
+ lang_item (lang_item), locus (locus),
+ has_separating_scope_resolution (false), type (SegmentType::REG)
+{}
+
TypePathSegment::TypePathSegment (Analysis::NodeMapping mappings,
std::string segment_name,
bool has_separating_scope_resolution,
location_t locus)
: mappings (std::move (mappings)),
- ident_segment (PathIdentSegment (std::move (segment_name))), locus (locus),
+ ident_segment (PathIdentSegment (std::move (segment_name))),
+ lang_item (tl::nullopt), locus (locus),
has_separating_scope_resolution (has_separating_scope_resolution),
type (SegmentType::REG)
{}
@@ -188,6 +197,14 @@ TypePathSegmentGeneric::TypePathSegmentGeneric (
generic_args (std::move (generic_args))
{}
+TypePathSegmentGeneric::TypePathSegmentGeneric (Analysis::NodeMapping mappings,
+ LangItem::Kind lang_item,
+ GenericArgs generic_args,
+ location_t locus)
+ : TypePathSegment (std::move (mappings), lang_item, locus),
+ generic_args (std::move (generic_args))
+{}
+
TypePathSegmentGeneric::TypePathSegmentGeneric (
Analysis::NodeMapping mappings, std::string segment_name,
bool has_separating_scope_resolution, std::vector<Lifetime> lifetime_args,
diff --git a/gcc/rust/hir/tree/rust-hir-path.h b/gcc/rust/hir/tree/rust-hir-path.h
index 7ef66b86ab0..bbb9c2d6077 100644
--- a/gcc/rust/hir/tree/rust-hir-path.h
+++ b/gcc/rust/hir/tree/rust-hir-path.h
@@ -355,7 +355,8 @@ public:
private:
Analysis::NodeMapping mappings;
- PathIdentSegment ident_segment;
+ tl::optional<PathIdentSegment> ident_segment;
+ tl::optional<LangItem::Kind> lang_item;
location_t locus;
protected:
@@ -384,14 +385,27 @@ public:
PathIdentSegment ident_segment,
bool has_separating_scope_resolution, location_t locus);
+ TypePathSegment (Analysis::NodeMapping mappings, LangItem::Kind lang_item,
+ location_t locus);
+
TypePathSegment (Analysis::NodeMapping mappings, std::string segment_name,
bool has_separating_scope_resolution, location_t locus);
- virtual std::string as_string () const { return ident_segment.as_string (); }
+ virtual std::string as_string () const
+ {
+ if (ident_segment)
+ return ident_segment->as_string ();
+
+ return LangItem::PrettyString (*lang_item);
+ }
/* Returns whether the type path segment is in an error state. May be virtual
* in future. */
- bool is_error () const { return ident_segment.is_error (); }
+ bool is_error () const
+ {
+ rust_assert (ident_segment);
+ return ident_segment->is_error ();
+ }
/* Returns whether segment is identifier only (as opposed to generic args or
* function). Overriden in derived classes with other segments. */
@@ -404,12 +418,24 @@ public:
const Analysis::NodeMapping &get_mappings () const { return mappings; }
- const PathIdentSegment &get_ident_segment () const { return ident_segment; }
+ const PathIdentSegment &get_ident_segment () const
+ {
+ rust_assert (ident_segment);
+ return *ident_segment;
+ }
+
+ const LangItem::Kind &get_lang_item () const
+ {
+ rust_assert (lang_item);
+ return *lang_item;
+ }
bool is_generic_segment () const
{
return get_type () == SegmentType::GENERIC;
}
+
+ bool is_lang_item () const { return lang_item.has_value (); }
};
// Segment used in type path with generic args
@@ -428,6 +454,10 @@ public:
bool has_separating_scope_resolution,
GenericArgs generic_args, location_t locus);
+ TypePathSegmentGeneric (Analysis::NodeMapping mappings,
+ LangItem::Kind lang_item, GenericArgs generic_args,
+ location_t locus);
+
// Constructor from segment name and all args
TypePathSegmentGeneric (Analysis::NodeMapping mappings,
std::string segment_name,
diff --git a/gcc/rust/resolve/rust-ast-resolve-base.cc b/gcc/rust/resolve/rust-ast-resolve-base.cc
index b23c1eba112..6c35a22b7f6 100644
--- a/gcc/rust/resolve/rust-ast-resolve-base.cc
+++ b/gcc/rust/resolve/rust-ast-resolve-base.cc
@@ -71,14 +71,6 @@ void
ResolverBase::visit (AST::ConstGenericParam &)
{}
-void
-ResolverBase::visit (AST::RegularPath &)
-{}
-
-void
-ResolverBase::visit (AST::LangItemPath &)
-{}
-
void
ResolverBase::visit (AST::PathInExpression &)
{}
diff --git a/gcc/rust/resolve/rust-ast-resolve-base.h b/gcc/rust/resolve/rust-ast-resolve-base.h
index 703460ad0d9..0d497f81eac 100644
--- a/gcc/rust/resolve/rust-ast-resolve-base.h
+++ b/gcc/rust/resolve/rust-ast-resolve-base.h
@@ -40,8 +40,6 @@ public:
void visit (AST::Lifetime &);
void visit (AST::LifetimeParam &);
void visit (AST::ConstGenericParam &);
- void visit (AST::RegularPath &);
- void visit (AST::LangItemPath &);
void visit (AST::PathInExpression &);
void visit (AST::TypePathSegment &);
void visit (AST::TypePathSegmentGeneric &);
diff --git a/gcc/rust/resolve/rust-ast-resolve-item.cc b/gcc/rust/resolve/rust-ast-resolve-item.cc
index 33b4fc9b979..b26ac340e92 100644
--- a/gcc/rust/resolve/rust-ast-resolve-item.cc
+++ b/gcc/rust/resolve/rust-ast-resolve-item.cc
@@ -682,28 +682,15 @@ ResolveItem::visit (AST::TraitImpl &impl_block)
// setup paths
CanonicalPath canonical_trait_type = CanonicalPath::create_empty ();
- if (impl_block.get_trait_path ().get_path_kind ()
- == AST::Path::Kind::LangItem)
- {
- auto &lang_item
- = static_cast<AST::LangItemPath &> (impl_block.get_trait_path ());
- canonical_trait_type
- = CanonicalPath::new_seg (lang_item.get_node_id (),
- LangItem::ToString (
- lang_item.get_lang_item_kind ()));
- }
- else
+ ok = ResolveTypeToCanonicalPath::go (impl_block.get_trait_path (),
+ canonical_trait_type);
+ if (!ok)
{
- ok = ResolveTypeToCanonicalPath::go (impl_block.get_trait_path_type (),
- canonical_trait_type);
- if (!ok)
- {
- resolver->get_name_scope ().pop ();
- resolver->get_type_scope ().pop ();
- resolver->get_label_scope ().pop ();
- return;
- }
+ resolver->get_name_scope ().pop ();
+ resolver->get_type_scope ().pop ();
+ resolver->get_label_scope ().pop ();
+ return;
}
rust_debug ("AST::TraitImpl resolve trait type: {%s}",
diff --git a/gcc/rust/resolve/rust-ast-resolve-type.cc b/gcc/rust/resolve/rust-ast-resolve-type.cc
index 1d004b1ba9b..63c9daca565 100644
--- a/gcc/rust/resolve/rust-ast-resolve-type.cc
+++ b/gcc/rust/resolve/rust-ast-resolve-type.cc
@@ -20,6 +20,7 @@
#include "rust-ast-resolve-expr.h"
#include "rust-canonical-path.h"
#include "rust-type.h"
+#include "rust-hir-map.h"
namespace Rust {
namespace Resolver {
@@ -99,45 +100,57 @@ ResolveRelativeTypePath::go (AST::TypePath &path, NodeId &resolved_node_id)
for (size_t i = 0; i < path.get_segments ().size (); i++)
{
auto &segment = path.get_segments ().at (i);
- const AST::PathIdentSegment &ident_seg = segment->get_ident_segment ();
bool is_first_segment = i == 0;
- resolved_node_id = UNKNOWN_NODEID;
+ NodeId crate_scope_id = resolver->peek_crate_module_scope ();
+ auto ident_string = segment->is_lang_item ()
+ ? LangItem::PrettyString (segment->get_lang_item ())
+ : segment->get_ident_segment ().as_string ();
- bool in_middle_of_path = i > 0;
- if (in_middle_of_path && segment->is_lower_self_seg ())
- {
- rust_error_at (segment->get_locus (), ErrorCode::E0433,
- "failed to resolve: %qs in paths can only be used "
- "in start position",
- segment->as_string ().c_str ());
- return false;
- }
+ resolved_node_id = UNKNOWN_NODEID;
- NodeId crate_scope_id = resolver->peek_crate_module_scope ();
- if (segment->is_crate_path_seg ())
+ if (segment->is_lang_item ())
{
- // what is the current crate scope node id?
- module_scope_id = crate_scope_id;
- previous_resolved_node_id = module_scope_id;
- resolver->insert_resolved_name (segment->get_node_id (),
- module_scope_id);
-
- continue;
+ resolved_node_id = Analysis::Mappings::get ().get_lang_item_node (
+ segment->get_lang_item ());
+ previous_resolved_node_id = resolved_node_id;
}
- else if (segment->is_super_path_seg ())
+ else
{
- if (module_scope_id == crate_scope_id)
+ bool in_middle_of_path = i > 0;
+ if (in_middle_of_path && segment->is_lower_self_seg ())
{
- rust_error_at (segment->get_locus (),
- "cannot use super at the crate scope");
+ rust_error_at (segment->get_locus (), ErrorCode::E0433,
+ "failed to resolve: %qs in paths can only be used "
+ "in start position",
+ segment->as_string ().c_str ());
return false;
}
- module_scope_id = resolver->peek_parent_module_scope ();
- previous_resolved_node_id = module_scope_id;
- resolver->insert_resolved_name (segment->get_node_id (),
- module_scope_id);
- continue;
+ if (segment->is_crate_path_seg ())
+ {
+ // what is the current crate scope node id?
+ module_scope_id = crate_scope_id;
+ previous_resolved_node_id = module_scope_id;
+ resolver->insert_resolved_name (segment->get_node_id (),
+ module_scope_id);
+
+ continue;
+ }
+ else if (segment->is_super_path_seg ())
+ {
+ if (module_scope_id == crate_scope_id)
+ {
+ rust_error_at (segment->get_locus (),
+ "cannot use super at the crate scope");
+ return false;
+ }
+
+ module_scope_id = resolver->peek_parent_module_scope ();
+ previous_resolved_node_id = module_scope_id;
+ resolver->insert_resolved_name (segment->get_node_id (),
+ module_scope_id);
+ continue;
+ }
}
switch (segment->get_type ())
@@ -177,8 +190,7 @@ ResolveRelativeTypePath::go (AST::TypePath &path, NodeId &resolved_node_id)
// name scope first
NodeId resolved_node = UNKNOWN_NODEID;
const CanonicalPath path
- = CanonicalPath::new_seg (segment->get_node_id (),
- ident_seg.as_string ());
+ = CanonicalPath::new_seg (segment->get_node_id (), ident_string);
if (resolver->get_type_scope ().lookup (path, &resolved_node))
{
resolver->insert_resolved_type (segment->get_node_id (),
@@ -191,7 +203,7 @@ ResolveRelativeTypePath::go (AST::TypePath &path, NodeId &resolved_node_id)
resolved_node);
resolved_node_id = resolved_node;
}
- else if (segment->is_lower_self_seg ())
+ else if (!segment->is_lang_item () && segment->is_lower_self_seg ())
{
// what is the current crate scope node id?
module_scope_id = crate_scope_id;
@@ -207,8 +219,7 @@ ResolveRelativeTypePath::go (AST::TypePath &path, NodeId &resolved_node_id)
&& previous_resolved_node_id == module_scope_id)
{
tl::optional<CanonicalPath &> resolved_child
- = mappings.lookup_module_child (module_scope_id,
- ident_seg.as_string ());
+ = mappings.lookup_module_child (module_scope_id, ident_string);
if (resolved_child.has_value ())
{
NodeId resolved_node = resolved_child->get_node_id ();
diff --git a/gcc/rust/resolve/rust-ast-resolve-type.h b/gcc/rust/resolve/rust-ast-resolve-type.h
index 5e8cdb11b2d..662f2f5a668 100644
--- a/gcc/rust/resolve/rust-ast-resolve-type.h
+++ b/gcc/rust/resolve/rust-ast-resolve-type.h
@@ -61,37 +61,6 @@ class ResolveType : public ResolverBase
using Rust::Resolver::ResolverBase::visit;
public:
- static NodeId go (AST::TypePath &type_path)
- {
- return ResolveType::go ((AST::Type &) type_path);
- }
-
- static NodeId go (AST::Path &type_path)
- {
- if (type_path.get_path_kind () == AST::Path::Kind::LangItem)
- {
- auto &type = static_cast<AST::LangItemPath &> (type_path);
-
- auto lang_item = Analysis::Mappings::get ()
- .lookup_lang_item_node (type.get_lang_item_kind ())
- .value ();
-
- auto resolver = Resolver::get ();
- resolver->insert_resolved_type (type.get_node_id (), lang_item);
-
- return lang_item;
- }
-
- rust_assert (type_path.get_path_kind () == AST::Path::Kind::Type);
-
- // We have to do this dance to first downcast to a typepath, and then upcast
- // to a Type. The altnernative is to split `go` into `go` and `go_inner` or
- // something, but eventually this will need to change as we'll need
- // `ResolveType::` to resolve other kinds of `Path`s as well.
- return ResolveType::go (
- (AST::Type &) static_cast<AST::TypePath &> (type_path));
- }
-
static NodeId go (AST::Type &type)
{
ResolveType resolver;
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 bb099ab68ae..9da56ea3214 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
@@ -248,25 +248,6 @@ Late::visit (AST::PathInExpression &expr)
Definition (resolved->get_node_id ()));
}
-void
-Late::visit (AST::LangItemPath &type)
-{
- auto &mappings = Rust::Analysis::Mappings::get ();
- auto lang_item = mappings.lookup_lang_item_node (type.get_lang_item_kind ());
-
- if (!lang_item)
- {
- rust_fatal_error (
- type.get_locus (), "use of undeclared lang item %qs",
- LangItem::ToString (type.get_lang_item_kind ()).c_str ());
- return;
- }
-
- ctx.map_usage (Usage (type.get_node_id ()), Definition (lang_item.value ()));
-
- DefaultResolver::visit (type);
-}
-
void
Late::visit (AST::TypePath &type)
{
diff --git a/gcc/rust/resolve/rust-late-name-resolver-2.0.h b/gcc/rust/resolve/rust-late-name-resolver-2.0.h
index 2af73c38286..ade78c5bc5f 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.h
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.h
@@ -46,7 +46,6 @@ public:
// resolutions
void visit (AST::IdentifierExpr &) override;
void visit (AST::PathInExpression &) override;
- void visit (AST::LangItemPath &) override;
void visit (AST::TypePath &) override;
void visit (AST::Trait &) override;
void visit (AST::StructExprStruct &) override;
diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.cc b/gcc/rust/typecheck/rust-hir-type-check-type.cc
index bb23f8441ed..9f19facdffe 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-type.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-type.cc
@@ -410,7 +410,7 @@ TypeCheckType::resolve_root_path (HIR::TypePath &path, size_t *offset,
{
rust_error_at (seg->get_locus (),
"unknown reference for resolved name: %qs",
- seg->get_ident_segment ().as_string ().c_str ());
+ seg->as_string ().c_str ());
return new TyTy::ErrorType (path.get_mappings ().get_hirid ());
}
return root_tyty;
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 125/146] gccrs: tychk: resolve lang item type paths properly
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (123 preceding siblings ...)
2025-03-21 12:07 ` [COMMITTED 124/146] gccrs: ast: Refactor how lang item paths are handled arthur.cohen
@ 2025-03-21 12:07 ` arthur.cohen
2025-03-21 12:07 ` [COMMITTED 126/146] gccrs: lower: Properly lower non-generic lang item type path segments arthur.cohen
` (20 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:07 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-type.cc (TypeCheckType::resolve_root_path): Adapt
code to handle lang item type paths.
---
.../typecheck/rust-hir-type-check-type.cc | 26 ++++++++++++-------
1 file changed, 17 insertions(+), 9 deletions(-)
diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.cc b/gcc/rust/typecheck/rust-hir-type-check-type.cc
index 9f19facdffe..a7d28a67121 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-type.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-type.cc
@@ -379,6 +379,7 @@ TypeCheckType::resolve_root_path (HIR::TypePath &path, size_t *offset,
{
TyTy::BaseType *root_tyty = nullptr;
*offset = 0;
+
for (size_t i = 0; i < path.get_num_segments (); i++)
{
std::unique_ptr<HIR::TypePathSegment> &seg = path.get_segments ().at (i);
@@ -390,18 +391,25 @@ TypeCheckType::resolve_root_path (HIR::TypePath &path, size_t *offset,
// then lookup the reference_node_id
NodeId ref_node_id = UNKNOWN_NODEID;
- // FIXME: HACK: ARTHUR: Remove this
- if (flag_name_resolution_2_0)
+ if (seg->is_lang_item ())
+ ref_node_id = Analysis::Mappings::get ().get_lang_item_node (
+ seg->get_lang_item ());
+ else
{
- auto nr_ctx
- = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+ // FIXME: HACK: ARTHUR: Remove this
+ if (flag_name_resolution_2_0)
+ {
+ auto nr_ctx = Resolver2_0::ImmutableNameResolutionContext::get ()
+ .resolver ();
- // assign the ref_node_id if we've found something
- nr_ctx.lookup (path.get_mappings ().get_nodeid ())
- .map ([&ref_node_id] (NodeId resolved) { ref_node_id = resolved; });
+ // assign the ref_node_id if we've found something
+ nr_ctx.lookup (path.get_mappings ().get_nodeid ())
+ .map (
+ [&ref_node_id] (NodeId resolved) { ref_node_id = resolved; });
+ }
+ else if (!resolver->lookup_resolved_name (ast_node_id, &ref_node_id))
+ resolver->lookup_resolved_type (ast_node_id, &ref_node_id);
}
- else if (!resolver->lookup_resolved_name (ast_node_id, &ref_node_id))
- resolver->lookup_resolved_type (ast_node_id, &ref_node_id);
// ref_node_id is the NodeId that the segments refers to.
if (ref_node_id == UNKNOWN_NODEID)
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 126/146] gccrs: lower: Properly lower non-generic lang item type path segments.
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (124 preceding siblings ...)
2025-03-21 12:07 ` [COMMITTED 125/146] gccrs: tychk: resolve lang item type paths properly arthur.cohen
@ 2025-03-21 12:07 ` arthur.cohen
2025-03-21 12:07 ` [COMMITTED 127/146] gccrs: lang-items: Collect struct lang items arthur.cohen
` (19 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:07 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
gcc/rust/ChangeLog:
* hir/rust-ast-lower-type.cc (ASTLowerTypePath::visit): Adapt code to lang item
type path segments.
---
gcc/rust/hir/rust-ast-lower-type.cc | 40 ++++++++++-------------------
1 file changed, 14 insertions(+), 26 deletions(-)
diff --git a/gcc/rust/hir/rust-ast-lower-type.cc b/gcc/rust/hir/rust-ast-lower-type.cc
index e78c1307523..8df418b272d 100644
--- a/gcc/rust/hir/rust-ast-lower-type.cc
+++ b/gcc/rust/hir/rust-ast-lower-type.cc
@@ -74,11 +74,20 @@ ASTLowerTypePath::visit (AST::TypePathSegment &segment)
Analysis::NodeMapping mapping (crate_num, segment.get_node_id (), hirid,
UNKNOWN_LOCAL_DEFID);
- HIR::PathIdentSegment ident (segment.get_ident_segment ().as_string ());
- translated_segment
- = new HIR::TypePathSegment (std::move (mapping), ident,
- segment.get_separating_scope_resolution (),
- segment.get_locus ());
+ if (segment.is_lang_item ())
+ {
+ translated_segment = new HIR::TypePathSegment (std::move (mapping),
+ segment.get_lang_item (),
+ segment.get_locus ());
+ }
+ else
+ {
+ HIR::PathIdentSegment ident (segment.get_ident_segment ().as_string ());
+ translated_segment
+ = new HIR::TypePathSegment (std::move (mapping), ident,
+ segment.get_separating_scope_resolution (),
+ segment.get_locus ());
+ }
}
void
@@ -139,27 +148,6 @@ ASTLowerTypePath::visit (AST::TypePath &path)
path.has_opening_scope_resolution_op ());
}
-// void
-// ASTLowerTypePath::visit (AST::LangItemPath &path)
-// {
-// auto crate_num = mappings.get_current_crate ();
-// auto hirid = mappings.get_next_hir_id (crate_num);
-
-// Analysis::NodeMapping mapping (crate_num, path.get_node_id (), hirid,
-// mappings.get_next_localdef_id (crate_num));
-
-// std::vector<std::unique_ptr<HIR::TypePathSegment>> translated_segments;
-// translated_segments.emplace_back (std::unique_ptr<HIR::TypePathSegment> (
-// new HIR::TypePathSegment (mapping,
-// LangItem::ToString (path.get_lang_item_kind ()),
-// false, path.get_locus ())));
-
-// translated
-// = new HIR::TypePath (std::move (mapping), std::move
-// (translated_segments),
-// path.get_locus ());
-// }
-
HIR::QualifiedPathInType *
ASTLowerQualifiedPathInType::translate (AST::QualifiedPathInType &type)
{
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 127/146] gccrs: lang-items: Collect struct lang items.
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (125 preceding siblings ...)
2025-03-21 12:07 ` [COMMITTED 126/146] gccrs: lower: Properly lower non-generic lang item type path segments arthur.cohen
@ 2025-03-21 12:07 ` arthur.cohen
2025-03-21 12:07 ` [COMMITTED 128/146] gccrs: lang-item: Add LangItem::PrettyString arthur.cohen
` (18 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:07 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
gcc/rust/ChangeLog:
* ast/rust-collect-lang-items.cc (CollectLangItems::visit): New.
* ast/rust-collect-lang-items.h: New.
---
gcc/rust/ast/rust-collect-lang-items.cc | 9 +++++++++
gcc/rust/ast/rust-collect-lang-items.h | 1 +
2 files changed, 10 insertions(+)
diff --git a/gcc/rust/ast/rust-collect-lang-items.cc b/gcc/rust/ast/rust-collect-lang-items.cc
index 168123ee56e..11c3297d2a9 100644
--- a/gcc/rust/ast/rust-collect-lang-items.cc
+++ b/gcc/rust/ast/rust-collect-lang-items.cc
@@ -23,6 +23,7 @@
#include "rust-attribute-values.h"
#include "rust-attributes.h"
#include "rust-hir-map.h"
+#include "rust-item.h"
namespace Rust {
namespace AST {
@@ -91,5 +92,13 @@ CollectLangItems::visit (AST::Function &item)
DefaultASTVisitor::visit (item);
}
+void
+CollectLangItems::visit (AST::StructStruct &item)
+{
+ maybe_add_lang_item (item);
+
+ DefaultASTVisitor::visit (item);
+}
+
} // namespace AST
} // namespace Rust
diff --git a/gcc/rust/ast/rust-collect-lang-items.h b/gcc/rust/ast/rust-collect-lang-items.h
index 1d021b1d9c5..39cb4be31a0 100644
--- a/gcc/rust/ast/rust-collect-lang-items.h
+++ b/gcc/rust/ast/rust-collect-lang-items.h
@@ -48,6 +48,7 @@ public:
void visit (AST::Trait &item) override;
void visit (AST::TraitItemType &item) override;
void visit (AST::Function &item) override;
+ void visit (AST::StructStruct &item) override;
private:
template <typename T> void maybe_add_lang_item (const T &item);
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 128/146] gccrs: lang-item: Add LangItem::PrettyString
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (126 preceding siblings ...)
2025-03-21 12:07 ` [COMMITTED 127/146] gccrs: lang-items: Collect struct lang items arthur.cohen
@ 2025-03-21 12:07 ` arthur.cohen
2025-03-21 12:07 ` [COMMITTED 129/146] gccrs: mappings: Add get_lang_item_node arthur.cohen
` (17 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:07 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
Which formats a lang item as it appears in source code.
gcc/rust/ChangeLog:
* util/rust-lang-item.cc (LangItem::PrettyString): New.
* util/rust-lang-item.h: New.
---
gcc/rust/util/rust-lang-item.cc | 6 ++++++
gcc/rust/util/rust-lang-item.h | 1 +
2 files changed, 7 insertions(+)
diff --git a/gcc/rust/util/rust-lang-item.cc b/gcc/rust/util/rust-lang-item.cc
index 4a609096144..e038e900f94 100644
--- a/gcc/rust/util/rust-lang-item.cc
+++ b/gcc/rust/util/rust-lang-item.cc
@@ -118,6 +118,12 @@ LangItem::ToString (LangItem::Kind type)
return str.value ();
}
+std::string
+LangItem::PrettyString (LangItem::Kind type)
+{
+ return "#[lang = \"" + LangItem::ToString (type) + "\"]";
+}
+
LangItem::Kind
LangItem::OperatorToLangItem (ArithmeticOrLogicalOperator op)
{
diff --git a/gcc/rust/util/rust-lang-item.h b/gcc/rust/util/rust-lang-item.h
index 62b15d7b3fc..f947f3f021c 100644
--- a/gcc/rust/util/rust-lang-item.h
+++ b/gcc/rust/util/rust-lang-item.h
@@ -134,6 +134,7 @@ public:
static tl::optional<Kind> Parse (const std::string &item);
static std::string ToString (Kind type);
+ static std::string PrettyString (Kind type);
static Kind OperatorToLangItem (ArithmeticOrLogicalOperator op);
static Kind
CompoundAssignmentOperatorToLangItem (ArithmeticOrLogicalOperator op);
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 129/146] gccrs: mappings: Add get_lang_item_node
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (127 preceding siblings ...)
2025-03-21 12:07 ` [COMMITTED 128/146] gccrs: lang-item: Add LangItem::PrettyString arthur.cohen
@ 2025-03-21 12:07 ` arthur.cohen
2025-03-21 12:07 ` [COMMITTED 130/146] gccrs: ast-collector: Adapt to lang item type path segments arthur.cohen
` (16 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:07 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
This method errors out if the lang item has not been declared yet.
gcc/rust/ChangeLog:
* util/rust-hir-map.cc (Mappings::get_lang_item_node): New.
* util/rust-hir-map.h: New function.
---
gcc/rust/util/rust-hir-map.cc | 10 ++++++++++
gcc/rust/util/rust-hir-map.h | 1 +
2 files changed, 11 insertions(+)
diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc
index f11a77954ae..b94591e014c 100644
--- a/gcc/rust/util/rust-hir-map.cc
+++ b/gcc/rust/util/rust-hir-map.cc
@@ -1299,5 +1299,15 @@ Mappings::lookup_lang_item_node (LangItem::Kind item_type)
return it->second;
}
+NodeId
+Mappings::get_lang_item_node (LangItem::Kind item_type)
+{
+ if (auto lookup = lookup_lang_item_node (item_type))
+ return *lookup;
+
+ rust_fatal_error (UNKNOWN_LOCATION, "failed to find lang item %qs",
+ LangItem::ToString (item_type).c_str ());
+}
+
} // namespace Analysis
} // namespace Rust
diff --git a/gcc/rust/util/rust-hir-map.h b/gcc/rust/util/rust-hir-map.h
index aba51be4827..21e532812ff 100644
--- a/gcc/rust/util/rust-hir-map.h
+++ b/gcc/rust/util/rust-hir-map.h
@@ -261,6 +261,7 @@ public:
void insert_lang_item_node (LangItem::Kind item_type, NodeId node_id);
tl::optional<NodeId &> lookup_lang_item_node (LangItem::Kind item_type);
+ NodeId get_lang_item_node (LangItem::Kind item_type);
// This will fatal_error when this lang item does not exist
DefId get_lang_item (LangItem::Kind item_type, location_t locus);
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 130/146] gccrs: ast-collector: Adapt to lang item type path segments
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (128 preceding siblings ...)
2025-03-21 12:07 ` [COMMITTED 129/146] gccrs: mappings: Add get_lang_item_node arthur.cohen
@ 2025-03-21 12:07 ` arthur.cohen
2025-03-21 12:07 ` [COMMITTED 131/146] gccrs: ast-collector: Fix tuple struct pattern collection arthur.cohen
` (15 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:07 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
gcc/rust/ChangeLog:
* ast/rust-ast-collector.cc (TokenCollector::visit): Fix collector to better
handle lang item type path segments.
---
gcc/rust/ast/rust-ast-collector.cc | 23 +++++++++++++++--------
1 file changed, 15 insertions(+), 8 deletions(-)
diff --git a/gcc/rust/ast/rust-ast-collector.cc b/gcc/rust/ast/rust-ast-collector.cc
index f493da3fa3f..4c9c360c04d 100644
--- a/gcc/rust/ast/rust-ast-collector.cc
+++ b/gcc/rust/ast/rust-ast-collector.cc
@@ -543,10 +543,14 @@ TokenCollector::visit (TypePathSegment &segment)
{
// Syntax:
// PathIdentSegment
- auto ident_segment = segment.get_ident_segment ();
- auto id = ident_segment.as_string ();
- push (
- Rust::Token::make_identifier (ident_segment.get_locus (), std::move (id)));
+
+ auto locus = segment.is_lang_item ()
+ ? segment.get_locus ()
+ : segment.get_ident_segment ().get_locus ();
+ auto segment_string = segment.is_lang_item ()
+ ? LangItem::PrettyString (segment.get_lang_item ())
+ : segment.get_ident_segment ().as_string ();
+ push (Rust::Token::make_identifier (locus, std::move (segment_string)));
}
void
@@ -558,10 +562,13 @@ TokenCollector::visit (TypePathSegmentGeneric &segment)
// `<` `>`
// | `<` ( GenericArg `,` )* GenericArg `,`? `>`
- auto ident_segment = segment.get_ident_segment ();
- auto id = ident_segment.as_string ();
- push (
- Rust::Token::make_identifier (ident_segment.get_locus (), std::move (id)));
+ auto locus = segment.is_lang_item ()
+ ? segment.get_locus ()
+ : segment.get_ident_segment ().get_locus ();
+ auto segment_string = segment.is_lang_item ()
+ ? LangItem::PrettyString (segment.get_lang_item ())
+ : segment.get_ident_segment ().as_string ();
+ push (Rust::Token::make_identifier (locus, std::move (segment_string)));
if (segment.get_separating_scope_resolution ())
push (Rust::Token::make (SCOPE_RESOLUTION, UNDEF_LOCATION));
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 131/146] gccrs: ast-collector: Fix tuple struct pattern collection
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (129 preceding siblings ...)
2025-03-21 12:07 ` [COMMITTED 130/146] gccrs: ast-collector: Adapt to lang item type path segments arthur.cohen
@ 2025-03-21 12:07 ` arthur.cohen
2025-03-21 12:07 ` [COMMITTED 132/146] gccrs: lang-items: Mark Clone trait as a lang item in testsuite arthur.cohen
` (14 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:07 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
gcc/rust/ChangeLog:
* ast/rust-ast-collector.cc (TokenCollector::visit): Visit tuple pattern items as
separated by commas.
---
gcc/rust/ast/rust-ast-collector.cc | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/gcc/rust/ast/rust-ast-collector.cc b/gcc/rust/ast/rust-ast-collector.cc
index 4c9c360c04d..978de648a58 100644
--- a/gcc/rust/ast/rust-ast-collector.cc
+++ b/gcc/rust/ast/rust-ast-collector.cc
@@ -2470,10 +2470,7 @@ TokenCollector::visit (StructPattern &pattern)
void
TokenCollector::visit (TupleStructItemsNoRange &pattern)
{
- for (auto &pat : pattern.get_patterns ())
- {
- visit (pat);
- }
+ visit_items_joined_by_separator (pattern.get_patterns ());
}
void
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 132/146] gccrs: lang-items: Mark Clone trait as a lang item in testsuite
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (130 preceding siblings ...)
2025-03-21 12:07 ` [COMMITTED 131/146] gccrs: ast-collector: Fix tuple struct pattern collection arthur.cohen
@ 2025-03-21 12:07 ` arthur.cohen
2025-03-21 12:07 ` [COMMITTED 133/146] gccrs: builder: Allow generating struct statements arthur.cohen
` (13 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:07 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
gcc/testsuite/ChangeLog:
* rust/compile/derive_macro1.rs: Add #[lang = "clone"] to Clone trait.
* rust/compile/derive_macro3.rs: Likewise.
* rust/compile/derive_macro6.rs: Likewise.
* rust/execute/torture/derive_macro3.rs: Likewise.
---
gcc/testsuite/rust/compile/derive_macro1.rs | 1 +
gcc/testsuite/rust/compile/derive_macro3.rs | 1 +
gcc/testsuite/rust/compile/derive_macro6.rs | 7 +++----
gcc/testsuite/rust/execute/torture/derive_macro3.rs | 1 +
4 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/gcc/testsuite/rust/compile/derive_macro1.rs b/gcc/testsuite/rust/compile/derive_macro1.rs
index 779aad78e11..bc10d601bb8 100644
--- a/gcc/testsuite/rust/compile/derive_macro1.rs
+++ b/gcc/testsuite/rust/compile/derive_macro1.rs
@@ -1,6 +1,7 @@
#[lang = "sized"]
pub trait Sized {}
+#[lang = "clone"]
pub trait Clone {
fn clone(&self) -> Self;
}
diff --git a/gcc/testsuite/rust/compile/derive_macro3.rs b/gcc/testsuite/rust/compile/derive_macro3.rs
index 1c7d4737bfe..ad40cae94b5 100644
--- a/gcc/testsuite/rust/compile/derive_macro3.rs
+++ b/gcc/testsuite/rust/compile/derive_macro3.rs
@@ -1,6 +1,7 @@
#[lang = "sized"]
pub trait Sized {}
+#[lang = "clone"]
pub trait Clone {
fn clone(&self) -> Self;
}
diff --git a/gcc/testsuite/rust/compile/derive_macro6.rs b/gcc/testsuite/rust/compile/derive_macro6.rs
index b7bf7a78acd..35327c03b54 100644
--- a/gcc/testsuite/rust/compile/derive_macro6.rs
+++ b/gcc/testsuite/rust/compile/derive_macro6.rs
@@ -2,6 +2,9 @@
pub trait Sized {}
pub trait Copy {}
+
+
+#[lang = "clone"]
pub trait Clone {
fn clone(&self) -> Self;
}
@@ -9,10 +12,6 @@ pub trait Clone {
#[lang = "phantom_data"]
pub struct PhantomData<T>;
-pub struct AssertParamIsCopy<T: Copy> {
- pub _field: PhantomData<T>,
-}
-
impl Copy for i32 {}
impl Copy for i64 {}
impl Copy for U {}
diff --git a/gcc/testsuite/rust/execute/torture/derive_macro3.rs b/gcc/testsuite/rust/execute/torture/derive_macro3.rs
index 7b3a089d751..4138a5bf7e4 100644
--- a/gcc/testsuite/rust/execute/torture/derive_macro3.rs
+++ b/gcc/testsuite/rust/execute/torture/derive_macro3.rs
@@ -1,6 +1,7 @@
#[lang = "sized"]
pub trait Sized {}
+#[lang = "clone"]
pub trait Clone {
fn clone(&self) -> Self;
}
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 133/146] gccrs: builder: Allow generating struct statements
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (131 preceding siblings ...)
2025-03-21 12:07 ` [COMMITTED 132/146] gccrs: lang-items: Mark Clone trait as a lang item in testsuite arthur.cohen
@ 2025-03-21 12:07 ` arthur.cohen
2025-03-21 12:07 ` [COMMITTED 134/146] gccrs: derive(Clone): Manually generate AssertParamIsCopy struct for unions arthur.cohen
` (12 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:07 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
gcc/rust/ChangeLog:
* ast/rust-ast-builder.cc (Builder::struct_struct): New function.
* ast/rust-ast-builder.h (vec): New function.
---
gcc/rust/ast/rust-ast-builder.cc | 15 +++++++++++++++
gcc/rust/ast/rust-ast-builder.h | 31 +++++++++++++++++++++++++++++++
2 files changed, 46 insertions(+)
diff --git a/gcc/rust/ast/rust-ast-builder.cc b/gcc/rust/ast/rust-ast-builder.cc
index f6d0f0dc4ae..55d59c94b52 100644
--- a/gcc/rust/ast/rust-ast-builder.cc
+++ b/gcc/rust/ast/rust-ast-builder.cc
@@ -18,9 +18,11 @@
#include "rust-ast-builder.h"
#include "rust-ast-builder-type.h"
+#include "rust-ast.h"
#include "rust-common.h"
#include "rust-expr.h"
#include "rust-path.h"
+#include "rust-item.h"
#include "rust-token.h"
namespace Rust {
@@ -182,6 +184,19 @@ Builder::deref (std::unique_ptr<Expr> &&of) const
return std::unique_ptr<Expr> (new DereferenceExpr (std::move (of), {}, loc));
}
+std::unique_ptr<Stmt>
+Builder::struct_struct (std::string struct_name,
+ std::vector<std::unique_ptr<GenericParam>> &&generics,
+ std::vector<StructField> &&fields)
+{
+ auto is_unit = fields.empty ();
+
+ return std::unique_ptr<Stmt> (
+ new StructStruct (std::move (fields), struct_name, std::move (generics),
+ WhereClause::create_empty (), is_unit,
+ Visibility::create_private (), {}, loc));
+}
+
std::unique_ptr<Expr>
Builder::struct_expr_struct (std::string struct_name) const
{
diff --git a/gcc/rust/ast/rust-ast-builder.h b/gcc/rust/ast/rust-ast-builder.h
index aaf05c6d1fb..36c0da2cff2 100644
--- a/gcc/rust/ast/rust-ast-builder.h
+++ b/gcc/rust/ast/rust-ast-builder.h
@@ -21,10 +21,35 @@
#include "rust-ast-full.h"
#include "rust-expr.h"
+#include "rust-ast.h"
+#include "rust-item.h"
namespace Rust {
namespace AST {
+template <typename T>
+std::vector<std::unique_ptr<T>>
+vec (std::unique_ptr<T> &&t)
+{
+ auto v = std::vector<std::unique_ptr<T>> ();
+
+ v.emplace_back (std::move (t));
+
+ return v;
+}
+
+template <typename T>
+std::vector<std::unique_ptr<T>>
+vec (std::unique_ptr<T> &&t1, std::unique_ptr<T> &&t2)
+{
+ auto v = std::vector<std::unique_ptr<T>> ();
+
+ v.emplace_back (std::move (t1));
+ v.emplace_back (std::move (t2));
+
+ return v;
+}
+
// TODO: Use this builder when expanding regular macros
/* Builder class with helper methods to create AST nodes. This builder is
* tailored towards generating multiple AST nodes from a single location, and
@@ -113,6 +138,12 @@ public:
*/
PathInExpression path_in_expression (LangItem::Kind lang_item) const;
+ /* Create a new struct */
+ std::unique_ptr<Stmt>
+ struct_struct (std::string struct_name,
+ std::vector<std::unique_ptr<GenericParam>> &&generics,
+ std::vector<StructField> &&fields);
+
/* Create a struct expression for unit structs (`S`) */
std::unique_ptr<Expr> struct_expr_struct (std::string struct_name) const;
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 134/146] gccrs: derive(Clone): Manually generate AssertParamIsCopy struct for unions
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (132 preceding siblings ...)
2025-03-21 12:07 ` [COMMITTED 133/146] gccrs: builder: Allow generating struct statements arthur.cohen
@ 2025-03-21 12:07 ` arthur.cohen
2025-03-21 12:07 ` [COMMITTED 135/146] gccrs: derive(Clone): Mark PhantomData as a lang item arthur.cohen
` (11 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:07 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
gcc/rust/ChangeLog:
* expand/rust-derive-clone.cc (DeriveClone::visit_union): Manually generate
the struct used for asserting a union implements Copy.
---
gcc/rust/expand/rust-derive-clone.cc | 38 +++++++++++++++++++++++++---
1 file changed, 34 insertions(+), 4 deletions(-)
diff --git a/gcc/rust/expand/rust-derive-clone.cc b/gcc/rust/expand/rust-derive-clone.cc
index 18436be4bf7..8093bf67ff0 100644
--- a/gcc/rust/expand/rust-derive-clone.cc
+++ b/gcc/rust/expand/rust-derive-clone.cc
@@ -17,6 +17,8 @@
// <http://www.gnu.org/licenses/>.
#include "rust-derive-clone.h"
+#include "rust-ast.h"
+#include "rust-ast-dump.h"
#include "rust-item.h"
namespace Rust {
@@ -238,13 +240,40 @@ void
DeriveClone::visit_union (Union &item)
{
// FIXME: Should be $crate::core::clone::AssertParamIsCopy (or similar)
+ // (Rust-GCC#3329)
+
+ auto copy_path = TypePath (vec (builder.type_path_segment ("Copy")), loc);
+ auto sized_path = TypePath (vec (builder.type_path_segment ("Sized")), loc);
+
+ auto copy_bound = std::unique_ptr<TypeParamBound> (
+ new TraitBound (copy_path, item.get_locus ()));
+ auto sized_bound = std::unique_ptr<TypeParamBound> (
+ new TraitBound (sized_path, item.get_locus (), false, true));
+
+ auto bounds = std::vector<std::unique_ptr<TypeParamBound>> ();
+ bounds.emplace_back (std::move (copy_bound));
+ bounds.emplace_back (std::move (sized_bound));
+
+ // struct AssertParamIsCopy<T: Copy + ?Sized> { _t: PhantomData<T> }
+ auto assert_param_is_copy = "AssertParamIsCopy";
+ auto t = std::unique_ptr<GenericParam> (
+ new TypeParam (Identifier ("T"), item.get_locus (), std::move (bounds)));
+ auto assert_param_is_copy_struct = builder.struct_struct (
+ assert_param_is_copy, vec (std::move (t)),
+ {StructField (
+ Identifier ("_t"),
+ builder.single_generic_type_path (
+ "PhantomData",
+ GenericArgs (
+ {}, {GenericArg::create_type (builder.single_type_path ("T"))}, {})),
+ Visibility::create_private (), item.get_locus ())});
// <Self>
auto arg = GenericArg::create_type (builder.single_type_path ("Self"));
// AssertParamIsCopy::<Self>
auto type = std::unique_ptr<TypePathSegment> (
- new TypePathSegmentGeneric (PathIdentSegment ("AssertParamIsCopy", loc),
+ new TypePathSegmentGeneric (PathIdentSegment (assert_param_is_copy, loc),
false, GenericArgs ({}, {arg}, {}, loc), loc));
auto type_paths = std::vector<std::unique_ptr<TypePathSegment>> ();
type_paths.emplace_back (std::move (type));
@@ -252,11 +281,12 @@ DeriveClone::visit_union (Union &item)
auto full_path
= std::unique_ptr<Type> (new TypePath ({std::move (type_paths)}, loc));
- auto stmts = std::vector<std::unique_ptr<Stmt>> ();
- stmts.emplace_back (
- builder.let (builder.wildcard (), std::move (full_path), nullptr));
auto tail_expr = builder.deref (builder.identifier ("self"));
+ auto stmts
+ = vec (std::move (assert_param_is_copy_struct),
+ builder.let (builder.wildcard (), std::move (full_path), nullptr));
+
auto block = builder.block (std::move (stmts), std::move (tail_expr));
expanded = clone_impl (clone_fn (std::move (block)),
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 135/146] gccrs: derive(Clone): Mark PhantomData as a lang item
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (133 preceding siblings ...)
2025-03-21 12:07 ` [COMMITTED 134/146] gccrs: derive(Clone): Manually generate AssertParamIsCopy struct for unions arthur.cohen
@ 2025-03-21 12:07 ` arthur.cohen
2025-03-21 12:07 ` [COMMITTED 136/146] gccrs: derive(Copy): Use copy lang item when deriving Copy arthur.cohen
` (10 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:07 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
gcc/testsuite/ChangeLog:
* rust/compile/derive_macro4.rs: Make PhantomData a lang item.
---
gcc/testsuite/rust/compile/derive_macro4.rs | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/gcc/testsuite/rust/compile/derive_macro4.rs b/gcc/testsuite/rust/compile/derive_macro4.rs
index 7802e8fd800..b20043ba927 100644
--- a/gcc/testsuite/rust/compile/derive_macro4.rs
+++ b/gcc/testsuite/rust/compile/derive_macro4.rs
@@ -6,12 +6,9 @@ pub trait Clone {
fn clone(&self) -> Self;
}
+#[lang = "phantom_data"]
struct PhantomData<T>;
-pub struct AssertParamIsCopy<T: Copy> {
- _field: PhantomData<T>,
-}
-
#[derive(Clone)] // { dg-error "bounds not satisfied for U .Copy. is not satisfied" }
union U {
i: i32,
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 136/146] gccrs: derive(Copy): Use copy lang item when deriving Copy.
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (134 preceding siblings ...)
2025-03-21 12:07 ` [COMMITTED 135/146] gccrs: derive(Clone): Mark PhantomData as a lang item arthur.cohen
@ 2025-03-21 12:07 ` arthur.cohen
2025-03-21 12:07 ` [COMMITTED 137/146] gccrs: ast-builder: Add new methods around type paths arthur.cohen
` (9 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:07 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
gcc/rust/ChangeLog:
* expand/rust-derive-copy.cc: Use lang item path.
---
gcc/rust/expand/rust-derive-copy.cc | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/gcc/rust/expand/rust-derive-copy.cc b/gcc/rust/expand/rust-derive-copy.cc
index bcfe1db6b4a..31b4819c042 100644
--- a/gcc/rust/expand/rust-derive-copy.cc
+++ b/gcc/rust/expand/rust-derive-copy.cc
@@ -18,6 +18,7 @@
#include "rust-derive-copy.h"
#include "rust-ast-full.h"
+#include "rust-hir-map.h"
#include "rust-mapping-common.h"
#include "rust-path.h"
@@ -43,12 +44,7 @@ DeriveCopy::copy_impl (
std::string name,
const std::vector<std::unique_ptr<GenericParam>> &type_generics)
{
- // `$crate::core::marker::Copy` instead
- auto segments = std::vector<std::unique_ptr<TypePathSegment>> ();
- segments.emplace_back (builder.type_path_segment ("Copy"));
-
- auto copy = TypePath (std::move (segments), loc);
- // auto copy = TypePath (LangItem::Kind::COPY, loc);
+ auto copy = builder.type_path (LangItem::Kind::COPY);
// we need to build up the generics for this impl block which will be just a
// clone of the types specified ones
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 137/146] gccrs: ast-builder: Add new methods around type paths.
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (135 preceding siblings ...)
2025-03-21 12:07 ` [COMMITTED 136/146] gccrs: derive(Copy): Use copy lang item when deriving Copy arthur.cohen
@ 2025-03-21 12:07 ` arthur.cohen
2025-03-21 12:07 ` [COMMITTED 138/146] gccrs: derive(Clone): Use lang item for PhantomData in Clone arthur.cohen
` (8 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:07 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
gcc/rust/ChangeLog:
* ast/rust-ast-builder.cc: New functions.
* ast/rust-ast-builder.h: Declare them.
---
gcc/rust/ast/rust-ast-builder.cc | 57 ++++++++++++++++++++++++++++++--
gcc/rust/ast/rust-ast-builder.h | 13 +++++++-
2 files changed, 67 insertions(+), 3 deletions(-)
diff --git a/gcc/rust/ast/rust-ast-builder.cc b/gcc/rust/ast/rust-ast-builder.cc
index 55d59c94b52..fe80924fece 100644
--- a/gcc/rust/ast/rust-ast-builder.cc
+++ b/gcc/rust/ast/rust-ast-builder.cc
@@ -23,6 +23,7 @@
#include "rust-expr.h"
#include "rust-path.h"
#include "rust-item.h"
+#include "rust-path.h"
#include "rust-token.h"
namespace Rust {
@@ -101,12 +102,27 @@ Builder::type_path_segment (std::string seg) const
}
std::unique_ptr<TypePathSegment>
-Builder::generic_type_path_segment (std::string seg, GenericArgs args) const
+Builder::type_path_segment (LangItem::Kind lang_item) const
+{
+ return std::unique_ptr<TypePathSegment> (
+ new TypePathSegment (lang_item, loc));
+}
+
+std::unique_ptr<TypePathSegment>
+Builder::type_path_segment_generic (std::string seg, GenericArgs args) const
{
return std::unique_ptr<TypePathSegment> (
new TypePathSegmentGeneric (PathIdentSegment (seg, loc), false, args, loc));
}
+std::unique_ptr<TypePathSegment>
+Builder::type_path_segment_generic (LangItem::Kind lang_item,
+ GenericArgs args) const
+{
+ return std::unique_ptr<TypePathSegment> (
+ new TypePathSegmentGeneric (lang_item, args, loc));
+}
+
std::unique_ptr<Type>
Builder::single_type_path (std::string type) const
{
@@ -116,15 +132,52 @@ Builder::single_type_path (std::string type) const
return std::unique_ptr<Type> (new TypePath (std::move (segments), loc));
}
+std::unique_ptr<Type>
+Builder::single_type_path (LangItem::Kind lang_item) const
+{
+ return std::unique_ptr<Type> (new TypePath (lang_item, {}, loc));
+}
+
std::unique_ptr<Type>
Builder::single_generic_type_path (std::string type, GenericArgs args) const
{
auto segments = std::vector<std::unique_ptr<TypePathSegment>> ();
- segments.emplace_back (generic_type_path_segment (type, args));
+ segments.emplace_back (type_path_segment_generic (type, args));
return std::unique_ptr<Type> (new TypePath (std::move (segments), loc));
}
+std::unique_ptr<Type>
+Builder::single_generic_type_path (LangItem::Kind lang_item,
+ GenericArgs args) const
+{
+ auto segments = std::vector<std::unique_ptr<TypePathSegment>> ();
+ segments.emplace_back (type_path_segment_generic (lang_item, args));
+
+ return std::unique_ptr<Type> (new TypePath (std::move (segments), loc));
+}
+
+TypePath
+Builder::type_path (std::unique_ptr<TypePathSegment> &&segment) const
+{
+ auto segments = std::vector<std::unique_ptr<TypePathSegment>> ();
+ segments.emplace_back (std::move (segment));
+
+ return TypePath (std::move (segments), loc);
+}
+
+TypePath
+Builder::type_path (std::string type) const
+{
+ return type_path (type_path_segment (type));
+}
+
+TypePath
+Builder::type_path (LangItem::Kind lang_item) const
+{
+ return type_path (type_path_segment (lang_item));
+}
+
PathInExpression
Builder::path_in_expression (std::vector<std::string> &&segments) const
{
diff --git a/gcc/rust/ast/rust-ast-builder.h b/gcc/rust/ast/rust-ast-builder.h
index 36c0da2cff2..624cd715181 100644
--- a/gcc/rust/ast/rust-ast-builder.h
+++ b/gcc/rust/ast/rust-ast-builder.h
@@ -114,16 +114,27 @@ public:
/* And similarly for type path segments */
std::unique_ptr<TypePathSegment> type_path_segment (std::string seg) const;
+ std::unique_ptr<TypePathSegment>
+ type_path_segment (LangItem::Kind lang_item) const;
std::unique_ptr<TypePathSegment>
- generic_type_path_segment (std::string seg, GenericArgs args) const;
+ type_path_segment_generic (std::string seg, GenericArgs args) const;
+ std::unique_ptr<TypePathSegment>
+ type_path_segment_generic (LangItem::Kind lang_item, GenericArgs args) const;
/* Create a Type from a single string - the most basic kind of type in our AST
*/
std::unique_ptr<Type> single_type_path (std::string type) const;
+ std::unique_ptr<Type> single_type_path (LangItem::Kind lang_item) const;
std::unique_ptr<Type> single_generic_type_path (std::string type,
GenericArgs args) const;
+ std::unique_ptr<Type> single_generic_type_path (LangItem::Kind lang_item,
+ GenericArgs args) const;
+
+ TypePath type_path (std::unique_ptr<TypePathSegment> &&segment) const;
+ TypePath type_path (std::string type) const;
+ TypePath type_path (LangItem::Kind lang_item) const;
/**
* Create a path in expression from multiple segments (`Clone::clone`). You
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 138/146] gccrs: derive(Clone): Use lang item for PhantomData in Clone
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (136 preceding siblings ...)
2025-03-21 12:07 ` [COMMITTED 137/146] gccrs: ast-builder: Add new methods around type paths arthur.cohen
@ 2025-03-21 12:07 ` arthur.cohen
2025-03-21 12:07 ` [COMMITTED 139/146] gccrs: derive(Clone): Add note about Clone::clone() arthur.cohen
` (7 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:07 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
gcc/rust/ChangeLog:
* expand/rust-derive-clone.cc (DeriveClone::visit_union): Create a lang item path
instead of a regular path.
---
gcc/rust/expand/rust-derive-clone.cc | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/gcc/rust/expand/rust-derive-clone.cc b/gcc/rust/expand/rust-derive-clone.cc
index 8093bf67ff0..2f733fae910 100644
--- a/gcc/rust/expand/rust-derive-clone.cc
+++ b/gcc/rust/expand/rust-derive-clone.cc
@@ -263,7 +263,7 @@ DeriveClone::visit_union (Union &item)
{StructField (
Identifier ("_t"),
builder.single_generic_type_path (
- "PhantomData",
+ LangItem::Kind::PHANTOM_DATA,
GenericArgs (
{}, {GenericArg::create_type (builder.single_type_path ("T"))}, {})),
Visibility::create_private (), item.get_locus ())});
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 139/146] gccrs: derive(Clone): Add note about Clone::clone()
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (137 preceding siblings ...)
2025-03-21 12:07 ` [COMMITTED 138/146] gccrs: derive(Clone): Use lang item for PhantomData in Clone arthur.cohen
@ 2025-03-21 12:07 ` arthur.cohen
2025-03-21 12:07 ` [COMMITTED 140/146] gccrs: derive(Clone): Improve existing testcase arthur.cohen
` (6 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:07 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
gcc/rust/ChangeLog:
* expand/rust-derive-clone.cc (DeriveClone::clone_call): Mention using `clone_fn`
lang item in the future.
---
gcc/rust/expand/rust-derive-clone.cc | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/gcc/rust/expand/rust-derive-clone.cc b/gcc/rust/expand/rust-derive-clone.cc
index 2f733fae910..b8c92dcc6fe 100644
--- a/gcc/rust/expand/rust-derive-clone.cc
+++ b/gcc/rust/expand/rust-derive-clone.cc
@@ -30,6 +30,15 @@ DeriveClone::clone_call (std::unique_ptr<Expr> &&to_clone)
// $crate::core::clone::Clone::clone for the fully qualified path - we don't
// link with `core` yet so that might be an issue. Use `Clone::clone` for now?
// TODO: Factor this function inside the DeriveAccumulator
+
+ // Interestingly, later versions of Rust have a `clone_fn` lang item which
+ // corresponds to this. But because we are first targeting 1.49, we cannot use
+ // it yet. Once we target a new, more recent version of the language, we'll
+ // have figured out how to compile and distribute `core`, meaning we'll be
+ // able to directly call `::core::clone::Clone::clone()`
+
+ // Not sure how to call it properly in the meantime...
+
auto path = std::unique_ptr<Expr> (
new PathInExpression (builder.path_in_expression ({"Clone", "clone"})));
@@ -79,10 +88,7 @@ DeriveClone::clone_impl (
std::unique_ptr<AssociatedItem> &&clone_fn, std::string name,
const std::vector<std::unique_ptr<GenericParam>> &type_generics)
{
- // should that be `$crate::core::clone::Clone` instead?
- auto segments = std::vector<std::unique_ptr<TypePathSegment>> ();
- segments.emplace_back (builder.type_path_segment ("Clone"));
- auto clone = TypePath (std::move (segments), loc);
+ auto clone = builder.type_path (LangItem::Kind::CLONE);
auto trait_items = std::vector<std::unique_ptr<AssociatedItem>> ();
trait_items.emplace_back (std::move (clone_fn));
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 140/146] gccrs: derive(Clone): Improve existing testcase
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (138 preceding siblings ...)
2025-03-21 12:07 ` [COMMITTED 139/146] gccrs: derive(Clone): Add note about Clone::clone() arthur.cohen
@ 2025-03-21 12:07 ` arthur.cohen
2025-03-21 12:07 ` [COMMITTED 141/146] gccrs: derive(Clone): Add deriving of simple enum variants arthur.cohen
` (5 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:07 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
gcc/testsuite/ChangeLog:
* rust/compile/derive_macro4.rs: Mark Copy and Clone as lang items.
---
gcc/testsuite/rust/compile/derive_macro4.rs | 3 +++
1 file changed, 3 insertions(+)
diff --git a/gcc/testsuite/rust/compile/derive_macro4.rs b/gcc/testsuite/rust/compile/derive_macro4.rs
index b20043ba927..8bf1bcaf5f7 100644
--- a/gcc/testsuite/rust/compile/derive_macro4.rs
+++ b/gcc/testsuite/rust/compile/derive_macro4.rs
@@ -1,7 +1,10 @@
#[lang = "sized"]
pub trait Sized {}
+#[lang = "copy"]
pub trait Copy {}
+
+#[lang = "clone"]
pub trait Clone {
fn clone(&self) -> Self;
}
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 141/146] gccrs: derive(Clone): Add deriving of simple enum variants
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (139 preceding siblings ...)
2025-03-21 12:07 ` [COMMITTED 140/146] gccrs: derive(Clone): Improve existing testcase arthur.cohen
@ 2025-03-21 12:07 ` arthur.cohen
2025-03-21 12:07 ` [COMMITTED 142/146] gccrs: ast-builder: Add new methods for building structs arthur.cohen
` (4 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:07 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
gcc/rust/ChangeLog:
* expand/rust-derive-clone.cc: Clone enum identifier variants properly
* expand/rust-derive-clone.h: Declare new functions used.
---
gcc/rust/expand/rust-derive-clone.cc | 52 ++++++++++++++++++++++++++--
gcc/rust/expand/rust-derive-clone.h | 3 ++
2 files changed, 53 insertions(+), 2 deletions(-)
diff --git a/gcc/rust/expand/rust-derive-clone.cc b/gcc/rust/expand/rust-derive-clone.cc
index b8c92dcc6fe..e4702d8a818 100644
--- a/gcc/rust/expand/rust-derive-clone.cc
+++ b/gcc/rust/expand/rust-derive-clone.cc
@@ -20,6 +20,7 @@
#include "rust-ast.h"
#include "rust-ast-dump.h"
#include "rust-item.h"
+#include "rust-path.h"
namespace Rust {
namespace AST {
@@ -235,11 +236,58 @@ DeriveClone::visit_struct (StructStruct &item)
item.get_generic_params ());
}
+MatchCase
+DeriveClone::clone_enum_identifier (Enum &item,
+ const std::unique_ptr<EnumItem> &variant)
+{
+ auto variant_path = PathInExpression (
+ {builder.path_segment (item.get_identifier ().as_string ()),
+ builder.path_segment (variant->get_identifier ().as_string ())},
+ {}, loc, false);
+
+ auto pattern = std::unique_ptr<Pattern> (new ReferencePattern (
+ std::unique_ptr<Pattern> (new PathInExpression (variant_path)), false,
+ false, loc));
+ auto expr = std::unique_ptr<Expr> (new PathInExpression (variant_path));
+
+ return builder.match_case (std::move (pattern), std::move (expr));
+}
+
void
DeriveClone::visit_enum (Enum &item)
{
- rust_sorry_at (item.get_locus (), "cannot derive %qs for these items yet",
- "Clone");
+ // Create an arm for each variant of the enum
+ // For enum item variants, just create the same variant
+ // For struct and tuple variants, destructure the pattern and call clone for
+ // each field
+
+ auto cases = std::vector<MatchCase> ();
+
+ for (const auto &variant : item.get_variants ())
+ {
+ switch (variant->get_enum_item_kind ())
+ {
+ // Identifiers and discriminated variants are the same for a clone - we
+ // just return the same variant
+ case EnumItem::Kind::Identifier:
+ case EnumItem::Kind::Discriminant:
+ cases.emplace_back (clone_enum_identifier (item, variant));
+ break;
+ case EnumItem::Kind::Tuple:
+ case EnumItem::Kind::Struct:
+ rust_unreachable ();
+ break;
+ }
+ }
+
+ // match self { ... }
+ auto match = builder.match (builder.identifier ("self"), std::move (cases));
+
+ expanded = clone_impl (clone_fn (std::move (match)),
+ item.get_identifier ().as_string (),
+ item.get_generic_params ());
+
+ AST::Dump::debug (*expanded);
}
void
diff --git a/gcc/rust/expand/rust-derive-clone.h b/gcc/rust/expand/rust-derive-clone.h
index 4a43b2ac1fc..339cf6357ae 100644
--- a/gcc/rust/expand/rust-derive-clone.h
+++ b/gcc/rust/expand/rust-derive-clone.h
@@ -63,6 +63,9 @@ private:
clone_impl (std::unique_ptr<AssociatedItem> &&clone_fn, std::string name,
const std::vector<std::unique_ptr<GenericParam>> &type_generics);
+ MatchCase clone_enum_identifier (Enum &item,
+ const std::unique_ptr<EnumItem> &variant);
+
virtual void visit_struct (StructStruct &item);
virtual void visit_tuple (TupleStruct &item);
virtual void visit_enum (Enum &item);
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 142/146] gccrs: ast-builder: Add new methods for building structs
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (140 preceding siblings ...)
2025-03-21 12:07 ` [COMMITTED 141/146] gccrs: derive(Clone): Add deriving of simple enum variants arthur.cohen
@ 2025-03-21 12:07 ` arthur.cohen
2025-03-21 12:07 ` [COMMITTED 143/146] gccrs: derive(Clone): Implement clone for enum tuple variants arthur.cohen
` (3 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:07 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
gcc/rust/ChangeLog:
* ast/rust-ast-builder.cc: Add new methods for constructing struct exprs.
* ast/rust-ast-builder.h: Mention how to build tuple expressions.
---
gcc/rust/ast/rust-ast-builder.cc | 12 ++++++++++--
gcc/rust/ast/rust-ast-builder.h | 5 +++++
2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/gcc/rust/ast/rust-ast-builder.cc b/gcc/rust/ast/rust-ast-builder.cc
index fe80924fece..47044df9171 100644
--- a/gcc/rust/ast/rust-ast-builder.cc
+++ b/gcc/rust/ast/rust-ast-builder.cc
@@ -24,6 +24,7 @@
#include "rust-path.h"
#include "rust-item.h"
#include "rust-path.h"
+#include "rust-system.h"
#include "rust-token.h"
namespace Rust {
@@ -261,10 +262,17 @@ std::unique_ptr<Expr>
Builder::struct_expr (
std::string struct_name,
std::vector<std::unique_ptr<StructExprField>> &&fields) const
+{
+ return struct_expr (path_in_expression ({struct_name}), std::move (fields));
+}
+
+std::unique_ptr<Expr>
+Builder::struct_expr (
+ PathInExpression struct_name,
+ std::vector<std::unique_ptr<StructExprField>> &&fields) const
{
return std::unique_ptr<Expr> (
- new StructExprStructFields (path_in_expression ({struct_name}),
- std::move (fields), loc));
+ new StructExprStructFields (struct_name, std::move (fields), loc));
}
std::unique_ptr<StructExprField>
diff --git a/gcc/rust/ast/rust-ast-builder.h b/gcc/rust/ast/rust-ast-builder.h
index 624cd715181..e5bae6ed6e9 100644
--- a/gcc/rust/ast/rust-ast-builder.h
+++ b/gcc/rust/ast/rust-ast-builder.h
@@ -160,10 +160,15 @@ public:
/**
* Create an expression for struct instantiation with fields (`S { a, b: c }`)
+ * Tuple expressions are call expressions and can thus be constructed with
+ * `call`
*/
std::unique_ptr<Expr>
struct_expr (std::string struct_name,
std::vector<std::unique_ptr<StructExprField>> &&fields) const;
+ std::unique_ptr<Expr>
+ struct_expr (PathInExpression struct_name,
+ std::vector<std::unique_ptr<StructExprField>> &&fields) const;
/* Create a field expression for struct instantiation (`field_name: value`) */
std::unique_ptr<StructExprField>
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 143/146] gccrs: derive(Clone): Implement clone for enum tuple variants
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (141 preceding siblings ...)
2025-03-21 12:07 ` [COMMITTED 142/146] gccrs: ast-builder: Add new methods for building structs arthur.cohen
@ 2025-03-21 12:07 ` arthur.cohen
2025-03-21 12:07 ` [COMMITTED 144/146] gccrs: derive(Clone): Implement derive clone for enum struct variants arthur.cohen
` (2 subsequent siblings)
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:07 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
gcc/rust/ChangeLog:
* expand/rust-derive-clone.cc (DeriveClone::variant_match_path): New function.
(DeriveClone::clone_enum_identifier): Rename.
(DeriveClone::clone_enum_tuple): New function.
(DeriveClone::visit_enum): Visit tuple variants properly.
* expand/rust-derive-clone.h: Declare new functions.
---
gcc/rust/expand/rust-derive-clone.cc | 58 ++++++++++++++++++++++++++--
gcc/rust/expand/rust-derive-clone.h | 12 ++++++
2 files changed, 66 insertions(+), 4 deletions(-)
diff --git a/gcc/rust/expand/rust-derive-clone.cc b/gcc/rust/expand/rust-derive-clone.cc
index e4702d8a818..c2994b7b4f8 100644
--- a/gcc/rust/expand/rust-derive-clone.cc
+++ b/gcc/rust/expand/rust-derive-clone.cc
@@ -21,6 +21,8 @@
#include "rust-ast-dump.h"
#include "rust-item.h"
#include "rust-path.h"
+#include "rust-pattern.h"
+#include "rust-system.h"
namespace Rust {
namespace AST {
@@ -236,14 +238,20 @@ DeriveClone::visit_struct (StructStruct &item)
item.get_generic_params ());
}
+PathInExpression
+DeriveClone::variant_match_path (Enum &item, const Identifier &variant)
+{
+ return PathInExpression ({builder.path_segment (
+ item.get_identifier ().as_string ()),
+ builder.path_segment (variant.as_string ())},
+ {}, loc, false);
+}
+
MatchCase
DeriveClone::clone_enum_identifier (Enum &item,
const std::unique_ptr<EnumItem> &variant)
{
- auto variant_path = PathInExpression (
- {builder.path_segment (item.get_identifier ().as_string ()),
- builder.path_segment (variant->get_identifier ().as_string ())},
- {}, loc, false);
+ auto variant_path = variant_match_path (item, variant->get_identifier ());
auto pattern = std::unique_ptr<Pattern> (new ReferencePattern (
std::unique_ptr<Pattern> (new PathInExpression (variant_path)), false,
@@ -253,6 +261,45 @@ DeriveClone::clone_enum_identifier (Enum &item,
return builder.match_case (std::move (pattern), std::move (expr));
}
+MatchCase
+DeriveClone::clone_enum_tuple (Enum &item, const EnumItemTuple &variant)
+{
+ auto variant_path = variant_match_path (item, variant.get_identifier ());
+
+ auto patterns = std::vector<std::unique_ptr<Pattern>> ();
+ auto cloned_patterns = std::vector<std::unique_ptr<Expr>> ();
+
+ for (size_t i = 0; i < variant.get_tuple_fields ().size (); i++)
+ {
+ // The pattern we're creating for each field is `self_<i>` where `i` is
+ // the index of the field. It doesn't actually matter what we use, as long
+ // as it's ordered, unique, and that we can reuse it in the match case's
+ // return expression to clone the field.
+ auto pattern_str = "__self_" + std::to_string (i);
+
+ patterns.emplace_back (builder.identifier_pattern (pattern_str));
+
+ // Now, for each tuple's element, we create a new expression calling
+ // `clone` on it for the match case's return expression
+ cloned_patterns.emplace_back (
+ clone_call (builder.ref (builder.identifier (pattern_str))));
+ }
+
+ auto pattern_items = std::unique_ptr<TupleStructItems> (
+ new TupleStructItemsNoRange (std::move (patterns)));
+
+ auto pattern = std::unique_ptr<Pattern> (
+ new ReferencePattern (std::unique_ptr<Pattern> (new TupleStructPattern (
+ variant_path, std::move (pattern_items))),
+ false, false, loc));
+
+ auto expr
+ = builder.call (std::unique_ptr<Expr> (new PathInExpression (variant_path)),
+ std::move (cloned_patterns));
+
+ return builder.match_case (std::move (pattern), std::move (expr));
+}
+
void
DeriveClone::visit_enum (Enum &item)
{
@@ -274,6 +321,9 @@ DeriveClone::visit_enum (Enum &item)
cases.emplace_back (clone_enum_identifier (item, variant));
break;
case EnumItem::Kind::Tuple:
+ cases.emplace_back (
+ clone_enum_tuple (item, static_cast<EnumItemTuple &> (*variant)));
+ break;
case EnumItem::Kind::Struct:
rust_unreachable ();
break;
diff --git a/gcc/rust/expand/rust-derive-clone.h b/gcc/rust/expand/rust-derive-clone.h
index 339cf6357ae..d48ec5d2889 100644
--- a/gcc/rust/expand/rust-derive-clone.h
+++ b/gcc/rust/expand/rust-derive-clone.h
@@ -63,8 +63,20 @@ private:
clone_impl (std::unique_ptr<AssociatedItem> &&clone_fn, std::string name,
const std::vector<std::unique_ptr<GenericParam>> &type_generics);
+ /**
+ * Get the path to use for matching and creating a variant when matching on an
+ * enum. E.g. for the `Option` enum, with the `None` variant, this will create
+ * a path `Option::None`
+ */
+ PathInExpression variant_match_path (Enum &item, const Identifier &variant);
+
+ /**
+ * Implementation of clone for all possible variants of an enum
+ */
MatchCase clone_enum_identifier (Enum &item,
const std::unique_ptr<EnumItem> &variant);
+ MatchCase clone_enum_tuple (Enum &item, const EnumItemTuple &variant);
+ MatchCase clone_enum_struct (Enum &item, const EnumItemStruct &variant);
virtual void visit_struct (StructStruct &item);
virtual void visit_tuple (TupleStruct &item);
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 144/146] gccrs: derive(Clone): Implement derive clone for enum struct variants
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (142 preceding siblings ...)
2025-03-21 12:07 ` [COMMITTED 143/146] gccrs: derive(Clone): Implement clone for enum tuple variants arthur.cohen
@ 2025-03-21 12:07 ` arthur.cohen
2025-03-21 12:07 ` [COMMITTED 145/146] gccrs: derive(Clone): Add lang item typepaths failure testcases to nr2 exclude arthur.cohen
2025-03-21 12:07 ` [COMMITTED 146/146] gccrs: nr2.0: late: Better format PathInExpression resolution arthur.cohen
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:07 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
gcc/rust/ChangeLog:
* expand/rust-derive-clone.cc (DeriveClone::clone_enum_struct): New function for deriving
enum struct variants.
(DeriveClone::visit_enum): Call into the new function.
gcc/testsuite/ChangeLog:
* rust/compile/nr2/exclude:
* rust/compile/derive_clone_enum1.rs: New test.
* rust/compile/derive_clone_enum2.rs: New test.
* rust/compile/derive_clone_enum3.rs: New test.
* rust/execute/torture/derive_clone_enum1.rs: New test.
---
gcc/rust/expand/rust-derive-clone.cc | 85 +++++++++++++++++--
.../rust/compile/derive_clone_enum1.rs | 16 ++++
.../rust/compile/derive_clone_enum2.rs | 16 ++++
.../rust/compile/derive_clone_enum3.rs | 16 ++++
gcc/testsuite/rust/compile/nr2/exclude | 3 +
.../execute/torture/derive_clone_enum1.rs | 51 +++++++++++
6 files changed, 180 insertions(+), 7 deletions(-)
create mode 100644 gcc/testsuite/rust/compile/derive_clone_enum1.rs
create mode 100644 gcc/testsuite/rust/compile/derive_clone_enum2.rs
create mode 100644 gcc/testsuite/rust/compile/derive_clone_enum3.rs
create mode 100644 gcc/testsuite/rust/execute/torture/derive_clone_enum1.rs
diff --git a/gcc/rust/expand/rust-derive-clone.cc b/gcc/rust/expand/rust-derive-clone.cc
index c2994b7b4f8..7620abe4e13 100644
--- a/gcc/rust/expand/rust-derive-clone.cc
+++ b/gcc/rust/expand/rust-derive-clone.cc
@@ -19,6 +19,7 @@
#include "rust-derive-clone.h"
#include "rust-ast.h"
#include "rust-ast-dump.h"
+#include "rust-expr.h"
#include "rust-item.h"
#include "rust-path.h"
#include "rust-pattern.h"
@@ -300,13 +301,84 @@ DeriveClone::clone_enum_tuple (Enum &item, const EnumItemTuple &variant)
return builder.match_case (std::move (pattern), std::move (expr));
}
+MatchCase
+DeriveClone::clone_enum_struct (Enum &item, const EnumItemStruct &variant)
+{
+ auto variant_path = variant_match_path (item, variant.get_identifier ());
+
+ auto field_patterns = std::vector<std::unique_ptr<StructPatternField>> ();
+ auto cloned_fields = std::vector<std::unique_ptr<StructExprField>> ();
+
+#if 0
+ // NOTE: We currently do not support compiling struct patterns where an
+ // identifier is assigned a new pattern, e.g. Bloop { f0: x }
+ // This is the code we should eventually produce as it mimics what rustc does
+ // - which is probably here for a good reason. In the meantime, we can just
+ // use the field's identifier as the pattern: Bloop { f0 }
+ // We can then clone the field directly instead of calling `clone()` on the
+ // new pattern.
+ // TODO: Figure out if that is actually needed and why rustc does it?
+
+ for (size_t i = 0; i < variant.get_struct_fields ().size (); i++)
+ {
+ auto &field = variant.get_struct_fields ()[i];
+
+ // Just like for tuples, the pattern we're creating for each field is
+ // `self_<i>` where `i` is the index of the field. It doesn't actually
+ // matter what we use, as long as it's ordered, unique, and that we can
+ // reuse it in the match case's return expression to clone the field.
+ auto pattern_str = "__self_" + std::to_string (i);
+
+ field_patterns.emplace_back (
+ std::unique_ptr<StructPatternField> (new StructPatternFieldIdentPat (
+ field.get_field_name (), builder.identifier_pattern (pattern_str), {},
+ loc)));
+
+ cloned_fields.emplace_back (
+ std::unique_ptr<StructExprField> (new StructExprFieldIdentifierValue (
+ field.get_field_name (),
+ clone_call (builder.ref (builder.identifier (pattern_str))), {},
+ loc)));
+ }
+#endif
+
+ for (const auto &field : variant.get_struct_fields ())
+ {
+ // We match on the struct's fields, and then recreate an instance of that
+ // struct, cloning each field
+
+ field_patterns.emplace_back (
+ std::unique_ptr<StructPatternField> (new StructPatternFieldIdent (
+ field.get_field_name (), false /* is_ref? true? */, false, {}, loc)));
+
+ cloned_fields.emplace_back (
+ std::unique_ptr<StructExprField> (new StructExprFieldIdentifierValue (
+ field.get_field_name (),
+ clone_call (builder.ref (
+ builder.identifier (field.get_field_name ().as_string ()))),
+ {}, loc)));
+ }
+
+ auto pattern_elts = StructPatternElements (std::move (field_patterns));
+
+ auto pattern = std::unique_ptr<Pattern> (
+ new ReferencePattern (std::unique_ptr<Pattern> (new StructPattern (
+ variant_path, loc, pattern_elts)),
+ false, false, loc));
+ auto expr = std::unique_ptr<Expr> (
+ new StructExprStructFields (variant_path, std::move (cloned_fields), loc));
+
+ return builder.match_case (std::move (pattern), std::move (expr));
+}
+
void
DeriveClone::visit_enum (Enum &item)
{
- // Create an arm for each variant of the enum
- // For enum item variants, just create the same variant
- // For struct and tuple variants, destructure the pattern and call clone for
- // each field
+ // Create an arm for each variant of the enum:
+ // - For enum item variants (simple identifiers), just create the same
+ // variant.
+ // - For struct and tuple variants, destructure the pattern and call clone for
+ // each field.
auto cases = std::vector<MatchCase> ();
@@ -325,7 +397,8 @@ DeriveClone::visit_enum (Enum &item)
clone_enum_tuple (item, static_cast<EnumItemTuple &> (*variant)));
break;
case EnumItem::Kind::Struct:
- rust_unreachable ();
+ cases.emplace_back (
+ clone_enum_struct (item, static_cast<EnumItemStruct &> (*variant)));
break;
}
}
@@ -336,8 +409,6 @@ DeriveClone::visit_enum (Enum &item)
expanded = clone_impl (clone_fn (std::move (match)),
item.get_identifier ().as_string (),
item.get_generic_params ());
-
- AST::Dump::debug (*expanded);
}
void
diff --git a/gcc/testsuite/rust/compile/derive_clone_enum1.rs b/gcc/testsuite/rust/compile/derive_clone_enum1.rs
new file mode 100644
index 00000000000..947dc5c694c
--- /dev/null
+++ b/gcc/testsuite/rust/compile/derive_clone_enum1.rs
@@ -0,0 +1,16 @@
+#[lang = "clone"]
+trait Clone {
+ pub fn clone(&self) -> Self;
+}
+
+impl Clone for i32 {
+ fn clone(&self) -> Self {
+ *self
+ }
+}
+
+#[derive(Clone)]
+enum AllIdentifiers {
+ A,
+ B
+}
diff --git a/gcc/testsuite/rust/compile/derive_clone_enum2.rs b/gcc/testsuite/rust/compile/derive_clone_enum2.rs
new file mode 100644
index 00000000000..c7a4ad5fd64
--- /dev/null
+++ b/gcc/testsuite/rust/compile/derive_clone_enum2.rs
@@ -0,0 +1,16 @@
+#[lang = "clone"]
+trait Clone {
+ pub fn clone(&self) -> Self;
+}
+
+impl Clone for i32 {
+ fn clone(&self) -> Self {
+ *self
+ }
+}
+
+#[derive(Clone)]
+enum TupleEnum {
+ A(i32),
+ B(i32, i32, i32)
+}
diff --git a/gcc/testsuite/rust/compile/derive_clone_enum3.rs b/gcc/testsuite/rust/compile/derive_clone_enum3.rs
new file mode 100644
index 00000000000..92fd6eeeb2b
--- /dev/null
+++ b/gcc/testsuite/rust/compile/derive_clone_enum3.rs
@@ -0,0 +1,16 @@
+#[lang = "clone"]
+trait Clone {
+ pub fn clone(&self) -> Self;
+}
+
+impl Clone for i32 {
+ fn clone(&self) -> Self {
+ *self
+ }
+}
+
+#[derive(Clone)]
+enum StructEnum {
+ A { i0: i32 },
+ B { i0: i32, i1: i32, i2: i32 }
+}
diff --git a/gcc/testsuite/rust/compile/nr2/exclude b/gcc/testsuite/rust/compile/nr2/exclude
index 0f482df2f00..1a9c8e7113a 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -143,4 +143,7 @@ additional-trait-bounds2.rs
auto_traits3.rs
issue-3140.rs
cmp1.rs
+derive_clone_enum1.rs
+derive_clone_enum2.rs
+derive_clone_enum3.rs
# please don't delete the trailing newline
diff --git a/gcc/testsuite/rust/execute/torture/derive_clone_enum1.rs b/gcc/testsuite/rust/execute/torture/derive_clone_enum1.rs
new file mode 100644
index 00000000000..542ecd83db0
--- /dev/null
+++ b/gcc/testsuite/rust/execute/torture/derive_clone_enum1.rs
@@ -0,0 +1,51 @@
+#[lang = "clone"]
+trait Clone {
+ pub fn clone(&self) -> Self;
+}
+
+impl Clone for i32 {
+ fn clone(&self) -> Self {
+ *self
+ }
+}
+
+#[derive(Clone)]
+enum MixAndMatch {
+ A,
+ B(i32),
+ C { inner: i32 }
+}
+
+fn main() -> i32 {
+ let a = MixAndMatch::A;
+ let a_copy = a.clone();
+
+ // we want res to stay at zero - when we don't match on the right thing, increase it
+
+ let mut res = match a_copy {
+ MixAndMatch::A => 0,
+ _ => 1,
+ };
+
+ let a = MixAndMatch::B(15);
+ let a_copy = a.clone();
+
+ match a_copy {
+ MixAndMatch::B(15) => {},
+ _ => res += 1,
+ };
+
+ let a = MixAndMatch::C { inner: 15 };
+ let a_copy = a.clone();
+
+ match a_copy {
+ MixAndMatch::C { inner } => {
+ if inner != 15 {
+ res += 1;
+ }
+ },
+ _ => res += 1,
+ };
+
+ res
+}
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 145/146] gccrs: derive(Clone): Add lang item typepaths failure testcases to nr2 exclude
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (143 preceding siblings ...)
2025-03-21 12:07 ` [COMMITTED 144/146] gccrs: derive(Clone): Implement derive clone for enum struct variants arthur.cohen
@ 2025-03-21 12:07 ` arthur.cohen
2025-03-21 12:07 ` [COMMITTED 146/146] gccrs: nr2.0: late: Better format PathInExpression resolution arthur.cohen
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:07 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
gcc/testsuite/ChangeLog:
* rust/compile/nr2/exclude: Add failing lang item typepaths tests.
* rust/execute/torture/derive_macro4.rs: Mark Clone as lang item.
---
gcc/testsuite/rust/compile/nr2/exclude | 5 +++++
gcc/testsuite/rust/execute/torture/derive_macro4.rs | 1 +
2 files changed, 6 insertions(+)
diff --git a/gcc/testsuite/rust/compile/nr2/exclude b/gcc/testsuite/rust/compile/nr2/exclude
index 1a9c8e7113a..60322f3276a 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -146,4 +146,9 @@ cmp1.rs
derive_clone_enum1.rs
derive_clone_enum2.rs
derive_clone_enum3.rs
+derive_macro4.rs
+derive_macro6.rs
+issue-2987.rs
+issue-3139-1.rs
+issue-3139-3.rs
# please don't delete the trailing newline
diff --git a/gcc/testsuite/rust/execute/torture/derive_macro4.rs b/gcc/testsuite/rust/execute/torture/derive_macro4.rs
index c355ac7905f..38c4808574a 100644
--- a/gcc/testsuite/rust/execute/torture/derive_macro4.rs
+++ b/gcc/testsuite/rust/execute/torture/derive_macro4.rs
@@ -1,6 +1,7 @@
#[lang = "sized"]
pub trait Sized {}
+#[lang = "clone"]
pub trait Clone {
fn clone(&self) -> Self;
}
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
* [COMMITTED 146/146] gccrs: nr2.0: late: Better format PathInExpression resolution
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
` (144 preceding siblings ...)
2025-03-21 12:07 ` [COMMITTED 145/146] gccrs: derive(Clone): Add lang item typepaths failure testcases to nr2 exclude arthur.cohen
@ 2025-03-21 12:07 ` arthur.cohen
145 siblings, 0 replies; 147+ messages in thread
From: arthur.cohen @ 2025-03-21 12:07 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
From: Arthur Cohen <arthur.cohen@embecosm.com>
gcc/rust/ChangeLog:
* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Improve formatting.
---
.../resolve/rust-late-name-resolver-2.0.cc | 18 ++++++------------
1 file changed, 6 insertions(+), 12 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 9da56ea3214..5aea6a43ed6 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
@@ -218,19 +218,12 @@ Late::visit (AST::PathInExpression &expr)
// in a function item` error here?
// do we emit it in `get<Namespace::Labels>`?
- rust_debug ("[ARTHUR]: %s", expr.as_simple_path ().as_string ().c_str ());
+ auto resolved
+ = ctx.values.resolve_path (expr.get_segments ()).or_else ([&] () {
+ return ctx.types.resolve_path (expr.get_segments ());
+ });
- tl::optional<Rib::Definition> resolved = tl::nullopt;
-
- if (auto value = ctx.values.resolve_path (expr.get_segments ()))
- {
- resolved = value;
- }
- else if (auto type = ctx.types.resolve_path (expr.get_segments ()))
- {
- resolved = type;
- }
- else
+ if (!resolved)
{
rust_error_at (expr.get_locus (),
"could not resolve path expression: %qs",
@@ -244,6 +237,7 @@ Late::visit (AST::PathInExpression &expr)
expr.as_string ().c_str ());
return;
}
+
ctx.map_usage (Usage (expr.get_node_id ()),
Definition (resolved->get_node_id ()));
}
--
2.45.2
^ permalink raw reply [flat|nested] 147+ messages in thread
end of thread, other threads:[~2025-03-21 12:39 UTC | newest]
Thread overview: 147+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-21 12:05 [PATCHSET] Update Rust frontend 21/03/2024 3/4 arthur.cohen
2025-03-21 12:05 ` [COMMITTED 001/146] gccrs: Fix bad recursive operator overload call arthur.cohen
2025-03-21 12:05 ` [COMMITTED 002/146] gccrs: Insert trait names during toplevel resolution 2.0 arthur.cohen
2025-03-21 12:05 ` [COMMITTED 003/146] gccrs: Fix variable shadowing in late " arthur.cohen
2025-03-21 12:05 ` [COMMITTED 004/146] gccrs: Add a newline to the end of nr2/exclude arthur.cohen
2025-03-21 12:05 ` [COMMITTED 005/146] gccrs: Rename some PathIdentSegment functions arthur.cohen
2025-03-21 12:05 ` [COMMITTED 006/146] gccrs: Use name resolution 2.0 in TraitItemReference arthur.cohen
2025-03-21 12:05 ` [COMMITTED 007/146] gccrs: Use name resolver 2.0 in CompileTraitItem arthur.cohen
2025-03-21 12:05 ` [COMMITTED 008/146] gccrs: Improve path handling while testing name resolution 2.0 arthur.cohen
2025-03-21 12:05 ` [COMMITTED 009/146] gccrs: Fix name resolution 2.0 definition lookups in unsafe checker arthur.cohen
2025-03-21 12:05 ` [COMMITTED 010/146] rust: Desugar IfLet* into MatchExpr arthur.cohen
2025-03-21 12:05 ` [COMMITTED 011/146] gccrs: Use name resolution 2.0 in TraitResolver arthur.cohen
2025-03-21 12:05 ` [COMMITTED 012/146] gccrs: Resolve SelfParam in name resolution 2.0 arthur.cohen
2025-03-21 12:05 ` [COMMITTED 013/146] gccrs: add test case to show method resolution is working arthur.cohen
2025-03-21 12:05 ` [COMMITTED 014/146] gccrs: Make TyTy::TupleType::get_unit_type cache its return value arthur.cohen
2025-03-21 12:05 ` [COMMITTED 015/146] gccrs: fix bad type inferencing on path's arthur.cohen
2025-03-21 12:05 ` [COMMITTED 016/146] gccrs: Remove usage of Resolver::get_builtin_types arthur.cohen
2025-03-21 12:05 ` [COMMITTED 017/146] gccrs: Improve handling of struct expressions in nr2.0 arthur.cohen
2025-03-21 12:05 ` [COMMITTED 018/146] gccrs: fix bad type inference on local patterns arthur.cohen
2025-03-21 12:05 ` [COMMITTED 019/146] gccrs: Use name resolver 2.0 in VisibilityResolver arthur.cohen
2025-03-21 12:05 ` [COMMITTED 020/146] gccrs: Use name resolver 2.0 for module descendance checks arthur.cohen
2025-03-21 12:05 ` [COMMITTED 021/146] gccrs: Reorganize the CPU feature detection arthur.cohen
2025-03-21 12:05 ` [COMMITTED 022/146] gccrs: fix ICE for placeholder which is not setup arthur.cohen
2025-03-21 12:05 ` [COMMITTED 023/146] gccrs: fix typechecking of Fn trait calls using ADT types arthur.cohen
2025-03-21 12:05 ` [COMMITTED 024/146] gccrs: Improve handling of implicit Self parameter in AST arthur.cohen
2025-03-21 12:05 ` [COMMITTED 025/146] gccrs: add test case to show issue is fixed arthur.cohen
2025-03-21 12:05 ` [COMMITTED 026/146] gccrs: hir: Mark AttrVec::get_outer_attrs as override arthur.cohen
2025-03-21 12:05 ` [COMMITTED 027/146] gccrs: typecheck: Remove unused parameter in TyTyCheckCallExpr arthur.cohen
2025-03-21 12:05 ` [COMMITTED 028/146] gccrs: asm: Fix clang warnings arthur.cohen
2025-03-21 12:05 ` [COMMITTED 029/146] gccrs: Fix bad handling for recursive type query arthur.cohen
2025-03-21 12:05 ` [COMMITTED 030/146] gccrs: Push ribs by kind rather than by value arthur.cohen
2025-03-21 12:05 ` [COMMITTED 031/146] gccrs: Improve handling of static items in toplevel 2.0 arthur.cohen
2025-03-21 12:05 ` [COMMITTED 032/146] gccrs: Refactor HIR to reduce the amount of raw pointers arthur.cohen
2025-03-21 12:05 ` [COMMITTED 033/146] gccrs: Refactor HIR with optionals, references & newtypes arthur.cohen
2025-03-21 12:05 ` [COMMITTED 034/146] gccrs: Refactor hir to avoid raw pointers and unneeded fwd arthur.cohen
2025-03-21 12:05 ` [COMMITTED 035/146] gccrs: Fixes some tests appearing with a moved variant arthur.cohen
2025-03-21 12:05 ` [COMMITTED 036/146] gccrs: Fix Generic type retrieval arthur.cohen
2025-03-21 12:05 ` [COMMITTED 037/146] gccrs: FnParam cloning now keeps projections arthur.cohen
2025-03-21 12:05 ` [COMMITTED 038/146] gccrs: Refactor optional initializers arthur.cohen
2025-03-21 12:05 ` [COMMITTED 039/146] gccrs: Fix FnParam pattern location ternary logic arthur.cohen
2025-03-21 12:05 ` [COMMITTED 040/146] gccrs: Add optional template arguments to please GCC4.8 arthur.cohen
2025-03-21 12:05 ` [COMMITTED 041/146] gccrs: Use default constructor for default arguments arthur.cohen
2025-03-21 12:05 ` [COMMITTED 042/146] gccrs: Use a reference wrapper to please GCC 4.8 arthur.cohen
2025-03-21 12:05 ` [COMMITTED 043/146] gccrs: Use nr2.0 in PrivacyReporter arthur.cohen
2025-03-21 12:05 ` [COMMITTED 044/146] gccrs: Handle type path segments during late resolution 2.0 arthur.cohen
2025-03-21 12:05 ` [COMMITTED 045/146] gccrs: Use nr2.0 in typechecker arthur.cohen
2025-03-21 12:05 ` [COMMITTED 046/146] gccrs: Clean up some system includes arthur.cohen
2025-03-21 12:05 ` [COMMITTED 047/146] gccrs: fix crashes in hir dump since move to references arthur.cohen
2025-03-21 12:05 ` [COMMITTED 048/146] gccrs: empty match expressions should resolve to ! arthur.cohen
2025-03-21 12:05 ` [COMMITTED 049/146] gccrs: Prevent execution of some nr1.0 functions with nr2.0 arthur.cohen
2025-03-21 12:05 ` [COMMITTED 050/146] gccrs: Prepend crate name to functions with nr2 arthur.cohen
2025-03-21 12:05 ` [COMMITTED 051/146] gccrs: fix crash in hir dump with missing guards arthur.cohen
2025-03-21 12:05 ` [COMMITTED 052/146] gccrs: improve handling of Self Type paths arthur.cohen
2025-03-21 12:05 ` [COMMITTED 053/146] gccrs: allow casts from numeric types to floats arthur.cohen
2025-03-21 12:05 ` [COMMITTED 054/146] gccrs: ensure packed and aligned is applied properly arthur.cohen
2025-03-21 12:05 ` [COMMITTED 055/146] gccrs: lang-items: Move comment about arithmetic lang items arthur.cohen
2025-03-21 12:05 ` [COMMITTED 056/146] gccrs: mappings: Move lang_item definitions to .cc arthur.cohen
2025-03-21 12:05 ` [COMMITTED 057/146] gccrs: hir: Remove duplicate function in TraitItemFunc arthur.cohen
2025-03-21 12:05 ` [COMMITTED 058/146] gccrs: stacked-contexts: Add peek() method arthur.cohen
2025-03-21 12:06 ` [COMMITTED 059/146] gccrs: ast: Use StackedContexts class in ContextualASTVisitor arthur.cohen
2025-03-21 12:06 ` [COMMITTED 060/146] gccrs: Remove bad assertion in name resolution arthur.cohen
2025-03-21 12:06 ` [COMMITTED 061/146] gccrs: constant evaluation like these are coercion sites arthur.cohen
2025-03-21 12:06 ` [COMMITTED 062/146] gccrs: add checks for division by zero and left shift overflow arthur.cohen
2025-03-21 12:06 ` [COMMITTED 063/146] gccrs: add test case to show issue is fixed arthur.cohen
2025-03-21 12:06 ` [COMMITTED 064/146] gccrs: fix crash in hir dump arthur.cohen
2025-03-21 12:06 ` [COMMITTED 065/146] gccrs: lang-items: Store NodeId mappings for lang items arthur.cohen
2025-03-21 12:06 ` [COMMITTED 066/146] gccrs: lang-items: Add lang-items AST collector arthur.cohen
2025-03-21 12:06 ` [COMMITTED 067/146] gccrs: attributes: Add class for sharing methods on attributes arthur.cohen
2025-03-21 12:06 ` [COMMITTED 068/146] gccrs: type-check: Remove unused capture in nr2.0 arthur.cohen
2025-03-21 12:06 ` [COMMITTED 069/146] gccrs: Fix ForeverStack::find_starting_point output parameter arthur.cohen
2025-03-21 12:06 ` [COMMITTED 070/146] gccrs: ast: Add LangItemPath class arthur.cohen
2025-03-21 12:06 ` [COMMITTED 071/146] gccrs: derive(Copy): Use new LangItemPath arthur.cohen
2025-03-21 12:06 ` [COMMITTED 072/146] gccrs: hir: Start adapting visitors to accept multiple kinds of Paths arthur.cohen
2025-03-21 12:06 ` [COMMITTED 073/146] gccrs: nr1.0: Resolve lang item paths properly arthur.cohen
2025-03-21 12:06 ` [COMMITTED 074/146] gccrs: hir: Lower lang-item paths arthur.cohen
2025-03-21 12:06 ` [COMMITTED 075/146] gccrs: nr2.0: Resolve lang item paths properly arthur.cohen
2025-03-21 12:06 ` [COMMITTED 076/146] gccrs: lang-item: Remove unused NodeId from LangItemPath arthur.cohen
2025-03-21 12:06 ` [COMMITTED 077/146] gccrs: fix bad not expression in rust arthur.cohen
2025-03-21 12:06 ` [COMMITTED 078/146] gccrs: implement the TuplePattern and use it for function patterns arthur.cohen
2025-03-21 12:06 ` [COMMITTED 079/146] gccrs: Made changes to AST::TraitImpl constructor for TypePath arthur.cohen
2025-03-21 12:06 ` [COMMITTED 080/146] gccrs: add ptr to int and int to ptr type cast rules arthur.cohen
2025-03-21 12:06 ` [COMMITTED 081/146] gccrs: typecheck-path: Fix typo (reciever -> receiver) arthur.cohen
2025-03-21 12:06 ` [COMMITTED 082/146] gccrs: parser: Add testcases for multiline strings arthur.cohen
2025-03-21 12:06 ` [COMMITTED 083/146] gccrs: resolve: Name resolve trait bounds properly arthur.cohen
2025-03-21 12:06 ` [COMMITTED 084/146] gccrs: typecheck: Add note about erorring out on additional trait bounds arthur.cohen
2025-03-21 12:06 ` [COMMITTED 085/146] gccrs: lang-item: Add Sync trait arthur.cohen
2025-03-21 12:06 ` [COMMITTED 086/146] gccrs: lang-item: Add Option::{None, Some}, Iterator::next, IntoIter::into_iter arthur.cohen
2025-03-21 12:06 ` [COMMITTED 087/146] gccrs: lang-items: Collect trait functions that are lang items arthur.cohen
2025-03-21 12:06 ` [COMMITTED 088/146] gccrs: ast: Add new constructors for PathInExpression arthur.cohen
2025-03-21 12:06 ` [COMMITTED 089/146] gccrs: ast-builder: Add more methods arthur.cohen
2025-03-21 12:06 ` [COMMITTED 090/146] gccrs: Fix NR2.0 compiler ICE caused by Generics in Enums arthur.cohen
2025-03-21 12:06 ` [COMMITTED 091/146] gccrs: nr2.0: Handle "Self" properly in trait definitions arthur.cohen
2025-03-21 12:06 ` [COMMITTED 092/146] gccrs: ast: Add EnumItem::Kind arthur.cohen
2025-03-21 12:06 ` [COMMITTED 093/146] gccrs: Remove Rust::make_unique arthur.cohen
2025-03-21 12:06 ` [COMMITTED 094/146] gccrs: lower: Correctly lower parenthesized types arthur.cohen
2025-03-21 12:06 ` [COMMITTED 095/146] gccrs: tychk: Add more support for additional trait bounds in functions arthur.cohen
2025-03-21 12:06 ` [COMMITTED 096/146] gccrs: nr2.0: Resolve type aliases inside trait definitions arthur.cohen
2025-03-21 12:06 ` [COMMITTED 097/146] gccrs: ast: Add new Kind enums for more precise downcasting arthur.cohen
2025-03-21 12:06 ` [COMMITTED 098/146] gccrs: use StackedContexts for block context arthur.cohen
2025-03-21 12:06 ` [COMMITTED 099/146] gccrs: fix ICE during HIR dump arthur.cohen
2025-03-21 12:06 ` [COMMITTED 100/146] gccrs: nr2.0: Improve default, top-level, and late resolvers arthur.cohen
2025-03-21 12:06 ` [COMMITTED 101/146] gccrs: fix ICE in borrows to invalid expressions arthur.cohen
2025-03-21 12:06 ` [COMMITTED 102/146] gccrs: add support for lang_item eq and PartialEq trait arthur.cohen
2025-03-21 12:06 ` [COMMITTED 103/146] gccrs: fix ICE with hir dump on closure arthur.cohen
2025-03-21 12:06 ` [COMMITTED 104/146] gccrs: nr2.0: Resolve Self inside impl blocks arthur.cohen
2025-03-21 12:06 ` [COMMITTED 105/146] gccrs: cleanup our enum type layout to be closer to rustc arthur.cohen
2025-03-21 12:06 ` [COMMITTED 106/146] gccrs: Allow float type to be casted as integer type arthur.cohen
2025-03-21 12:06 ` [COMMITTED 107/146] gccrs: match arms are a LUB arthur.cohen
2025-03-21 12:06 ` [COMMITTED 108/146] gccrs: rust/intrinsic: add try intrinsic and panic strategy options arthur.cohen
2025-03-21 12:06 ` [COMMITTED 109/146] gccrs: rust/intrinsic: add new "catch_unwind" variant of API arthur.cohen
2025-03-21 12:06 ` [COMMITTED 110/146] gccrs: add two more tests to test try-catch (unwind) code generation arthur.cohen
2025-03-21 12:06 ` [COMMITTED 111/146] gccrs: Visit the trait paths of trait implementations arthur.cohen
2025-03-21 12:06 ` [COMMITTED 112/146] gccrs: improve mutability checks arthur.cohen
2025-03-21 12:06 ` [COMMITTED 113/146] gccrs: gcc/rust/ChangeLog: arthur.cohen
2025-03-21 12:06 ` [COMMITTED 114/146] gccrs: Add ForeverStackStore arthur.cohen
2025-03-21 12:06 ` [COMMITTED 115/146] gccrs: testsuite: Fix missing handling of little endian arthur.cohen
2025-03-21 12:06 ` [COMMITTED 116/146] gccrs: Fix scan-gimple testcases on LE platforms arthur.cohen
2025-03-21 12:06 ` [COMMITTED 117/146] gccrs: Revert "gcc/rust/ChangeLog:" arthur.cohen
2025-03-21 12:06 ` [COMMITTED 118/146] gccrs: Add missing name resolution to static items in blocks arthur.cohen
2025-03-21 12:07 ` [COMMITTED 119/146] gccrs: nr2.0: Early resolve pending eager macro invocations arthur.cohen
2025-03-21 12:07 ` [COMMITTED 120/146] gccrs: Remove dead code related to external functions arthur.cohen
2025-03-21 12:07 ` [COMMITTED 121/146] gccrs: ast: Fix warning about copy elision for moved expr arthur.cohen
2025-03-21 12:07 ` [COMMITTED 122/146] gccrs: attributes: Add #[derive] as a built-in attribute arthur.cohen
2025-03-21 12:07 ` [COMMITTED 123/146] gccrs: collect-lang-items: Display attribute upon error finding it arthur.cohen
2025-03-21 12:07 ` [COMMITTED 124/146] gccrs: ast: Refactor how lang item paths are handled arthur.cohen
2025-03-21 12:07 ` [COMMITTED 125/146] gccrs: tychk: resolve lang item type paths properly arthur.cohen
2025-03-21 12:07 ` [COMMITTED 126/146] gccrs: lower: Properly lower non-generic lang item type path segments arthur.cohen
2025-03-21 12:07 ` [COMMITTED 127/146] gccrs: lang-items: Collect struct lang items arthur.cohen
2025-03-21 12:07 ` [COMMITTED 128/146] gccrs: lang-item: Add LangItem::PrettyString arthur.cohen
2025-03-21 12:07 ` [COMMITTED 129/146] gccrs: mappings: Add get_lang_item_node arthur.cohen
2025-03-21 12:07 ` [COMMITTED 130/146] gccrs: ast-collector: Adapt to lang item type path segments arthur.cohen
2025-03-21 12:07 ` [COMMITTED 131/146] gccrs: ast-collector: Fix tuple struct pattern collection arthur.cohen
2025-03-21 12:07 ` [COMMITTED 132/146] gccrs: lang-items: Mark Clone trait as a lang item in testsuite arthur.cohen
2025-03-21 12:07 ` [COMMITTED 133/146] gccrs: builder: Allow generating struct statements arthur.cohen
2025-03-21 12:07 ` [COMMITTED 134/146] gccrs: derive(Clone): Manually generate AssertParamIsCopy struct for unions arthur.cohen
2025-03-21 12:07 ` [COMMITTED 135/146] gccrs: derive(Clone): Mark PhantomData as a lang item arthur.cohen
2025-03-21 12:07 ` [COMMITTED 136/146] gccrs: derive(Copy): Use copy lang item when deriving Copy arthur.cohen
2025-03-21 12:07 ` [COMMITTED 137/146] gccrs: ast-builder: Add new methods around type paths arthur.cohen
2025-03-21 12:07 ` [COMMITTED 138/146] gccrs: derive(Clone): Use lang item for PhantomData in Clone arthur.cohen
2025-03-21 12:07 ` [COMMITTED 139/146] gccrs: derive(Clone): Add note about Clone::clone() arthur.cohen
2025-03-21 12:07 ` [COMMITTED 140/146] gccrs: derive(Clone): Improve existing testcase arthur.cohen
2025-03-21 12:07 ` [COMMITTED 141/146] gccrs: derive(Clone): Add deriving of simple enum variants arthur.cohen
2025-03-21 12:07 ` [COMMITTED 142/146] gccrs: ast-builder: Add new methods for building structs arthur.cohen
2025-03-21 12:07 ` [COMMITTED 143/146] gccrs: derive(Clone): Implement clone for enum tuple variants arthur.cohen
2025-03-21 12:07 ` [COMMITTED 144/146] gccrs: derive(Clone): Implement derive clone for enum struct variants arthur.cohen
2025-03-21 12:07 ` [COMMITTED 145/146] gccrs: derive(Clone): Add lang item typepaths failure testcases to nr2 exclude arthur.cohen
2025-03-21 12:07 ` [COMMITTED 146/146] gccrs: nr2.0: late: Better format PathInExpression resolution arthur.cohen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).