Commit graph

199079 commits

Author SHA1 Message Date
Philip Herron
21d19d2cf6 gccrs: Support Closure calls as generic trait bounds
gcc/rust/ChangeLog:

	* backend/rust-compile-expr.cc (CompileExpr::visit): Refactor checking of closures.
	(CompileExpr::generate_possible_fn_trait_call): New function.
	* backend/rust-compile-expr.h: Declare `generate_possible_fn_trait_call`.

gcc/testsuite/ChangeLog:

	* rust/execute/torture/closure2.rs: New test.
2023-02-21 12:36:41 +01:00
Philip Herron
51d180fcd7 gccrs: Add missing type resolution for function type segments
gcc/rust/ChangeLog:

	* typecheck/rust-tyty-bounds.cc (TypeCheckBase::get_predicate_from_bound): Add missing
	implementation.
2023-02-21 12:36:40 +01:00
Philip Herron
875f722de5 gccrs: Add missing hir lowering to function type-path segments
gcc/rust/ChangeLog:

	* Make-lang.in: Compile rust-ast-lower-type.cc.
	* ast/rust-path.h: Add `get_locus` method to `TypePathFunction`.
	* hir/rust-ast-lower-base.cc (ASTLowerTypePath::visit): Move implementation to
	rust-ast-lower-type.cc.
	(ASTLowerQualifiedPathInType::visit): Likewise.
	(ASTLoweringType::visit): Likewise.
	* hir/rust-ast-lower-type.h: Move implementations to source file.
	* hir/tree/rust-hir-path.h: Likewise.
	* hir/rust-ast-lower-type.cc: New file.
2023-02-21 12:36:40 +01:00
Philip Herron
12e94515f8 gccrs: Add missing name resolution to Function type-path segments
gcc/rust/ChangeLog:

	* resolve/rust-ast-resolve-type.cc (ResolveRelativeTypePath::go): Add missing handling of
	function case.
2023-02-21 12:36:40 +01:00
Philip Herron
699e7e8627 gccrs: Closure support at CallExpr
gcc/rust/ChangeLog:

	* backend/rust-compile-context.h: Add new functions: `insert_closure_decl` and
	`lookup_closure_decl`.
	* backend/rust-compile-expr.cc (CompileExpr::visit): Start compiling Closures properly.
	(CompileExpr::generate_closure_function): New function.
	(CompileExpr::generate_closure_fntype): Likewise.
	* backend/rust-compile-expr.h: Declare `generate_closure_function` and
	`generate_closure_fntype`.
	* backend/rust-compile-type.cc (TyTyResolveCompile::visit): Visit closure types properly.
	* backend/rust-mangle.cc (legacy_mangle_name): Add support for closures.
	* backend/rust-tree.h (RS_CLOSURE_FLAG): Add new tree macro.
	(RS_CLOSURE_TYPE_P): And checking for it on tree nodes.
	* typecheck/rust-tyty.cc (ClosureType::is_equal): Add implementation.

gcc/testsuite/ChangeLog:

	* rust/execute/torture/closure1.rs: New test.
2023-02-21 12:36:40 +01:00
Philip Herron
740a199722 gccrs: Initial Type resolution for closures
gcc/rust/ChangeLog:

	* hir/tree/rust-hir-expr.h: Add `get_params` method.
	* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Typecheck closure nodes.
	(TypeCheckExpr::resolve_fn_trait_call): New function.
	* typecheck/rust-hir-type-check-expr.h: Declare `resolve_fn_trait_call` and
	`resolve_possible_fn_trait_call_method_name`.
	* typecheck/rust-hir-type-check.h: Declare `get_context_type`.
	* typecheck/rust-tyctx.cc (TypeCheckContextItem::get_context_type): New function.
	* typecheck/rust-tyty-cmp.h: Visit closures properly.
	* typecheck/rust-tyty-rules.h: Likewise.
	* typecheck/rust-tyty.cc (BaseType::bounds_compatible): Add commented out assertin.
	(ClosureType::as_string): Implement it.
	(ClosureType::clone): Fix closure cloning.
	(ClosureType::setup_fn_once_output): New function.
	* typecheck/rust-tyty.h: Improve `ClosureType` class and declare `setup_fn_once_output`.
2023-02-21 12:36:39 +01:00
Philip Herron
898240946c gccrs: Add closures to lints and error checking
gcc/rust/ChangeLog:

	* checks/errors/rust-const-checker.cc (ConstChecker::visit): Visit closures properly.
	* checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Likewise.
	* checks/lints/rust-lint-marklive.h: Likewise.
2023-02-21 12:36:39 +01:00
Philip Herron
4d021d9e01 gccrs: Refactor method call type checking
gcc/rust/ChangeLog:

	* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Simplify method
	call type checking 	by removing visitor and instead using one static cast. Use the
	new interface.
	* typecheck/rust-tyty-call.cc (TypeCheckMethodCallExpr::visit): Likewise.
	(TypeCheckMethodCallExpr::go): Likewise.
	(TypeCheckMethodCallExpr::check): Likewise.
	* typecheck/rust-tyty-call.h (class TypeCheckMethodCallExpr): Likewise.
	(class Argument): Likewise.
2023-02-21 12:36:39 +01:00
Philip Herron
977e0e5227 gccrs: Add name resolution for closures
gcc/rust/ChangeLog:

	* resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit): Visit closure properly when
	name resolving.
	(ResolveExpr::resolve_closure_param): Implement closure name resolving.
	* resolve/rust-ast-resolve-expr.h: Declare visitors for closure types.
2023-02-21 12:36:38 +01:00
Philip Herron
9e19f329e5 gccrs: Formatting cleanup in HIR lowering pattern
gcc/rust/ChangeLog:

	* hir/rust-ast-lower-pattern.cc (ASTLoweringPattern::ASTLoweringPattern):
	Improve formatting.
	(ASTLoweringPattern::translate): Likewise.
	* hir/rust-ast-lower-pattern.h: Likewise.
	* resolve/rust-ast-resolve-expr.h: Likewise.
2023-02-21 12:36:38 +01:00
Philip Herron
870dd9d5d3 gccrs: Refactor expression hir lowering into cc file
gcc/rust/ChangeLog:

	* Make-lang.in: Add new object file for expression lowering.
	* ast/rust-expr.h: Move implementation of expr lowering to source file.
	* backend/rust-compile-block.h: Likewise.
	* backend/rust-compile-expr.cc (CompileExpr::visit): Likewise.
	* backend/rust-compile-expr.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-base.h: Likewise.
	* hir/rust-ast-lower-expr.h (RUST_AST_LOWER_EXPR): Likewise.
	* hir/rust-ast-lower.cc (ASTLoweringBase::lower_closure_param): Likewise.
	* hir/rust-hir-dump.cc (Dump::visit): Likewise.
	* hir/rust-hir-dump.h: Likewise.
	* hir/tree/rust-hir-expr.h (class ClosureExpr): Likewise.
	(class ClosureExprInner): Likewise.
	(class ClosureExprInnerTyped): Likewise.
	* hir/tree/rust-hir-full-decls.h (class ClosureExprInner): Likewise.
	(class ClosureExprInnerTyped): Likewise.
	* hir/tree/rust-hir-full-test.cc (ClosureExprInnerTyped::as_string): Likewise.
	(ClosureExprInner::as_string): Likewise.
	(ClosureExprInner::accept_vis): Likewise.
	(ClosureExpr::accept_vis): Likewise.
	(ClosureExprInnerTyped::accept_vis): Likewise.
	* hir/tree/rust-hir-visitor.h: Likewise.
	* hir/tree/rust-hir.h (class Expr): Likewise.
	* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise.
	* typecheck/rust-hir-type-check-expr.h: Likewise.
	* hir/rust-ast-lower-expr.cc: New file.
2023-02-21 12:36:38 +01:00
Philip Herron
ed75e142a7 gccrs: Add missing fn_once_output langitem
gcc/rust/ChangeLog:

	* util/rust-lang-item.h: Add handling for `fn_once_output`.
2023-02-21 12:36:38 +01:00
Arthur Cohen
b326cced19 gccrs: ast: Improve Fragment API
gcc/rust/ChangeLog:

	* ast/rust-ast-fragment.cc (Fragment::Fragment): Add better APIs.
	(Fragment::complete): New function.
	(Fragment::unexpanded): New function.
	* ast/rust-ast-fragment.h: Declare new APIs and add documentation.
	* expand/rust-attribute-visitor.h: Use new Fragment API.
	* expand/rust-macro-builtins.cc (MacroBuiltin::file): Likewise.
	(MacroBuiltin::column): Likewise.
	(MacroBuiltin::include_bytes): Likewise.
	(MacroBuiltin::include_str): Likewise.
	(MacroBuiltin::concat): Likewise.
	(MacroBuiltin::env): Likewise.
	(MacroBuiltin::cfg): Likewise.
	(MacroBuiltin::include): Likewise.
	(MacroBuiltin::line): Likewise.
	* expand/rust-macro-expand.cc (parse_many): Likewise.
	(transcribe_expression): Likewise.
	(transcribe_type): Likewise.
	* expand/rust-macro-expand.h (struct MacroExpander): Likewise.
2023-02-21 12:36:37 +01:00
Arthur Cohen
68e743090d gccrs: rust: Replace uses of ASTFragment -> Fragment
gcc/rust/ChangeLog:

	* ast/rust-ast.h (class ASTFragment): Remove old ASTFragment class.
	* ast/rust-macro.h (class MacroRulesDefinition): Use new Fragment API.
	* expand/rust-attribute-visitor.h: Likewise.
	* expand/rust-macro-builtins.cc (macro_end_token): Likewise.
	(MacroBuiltin::assert): Likewise.
	(MacroBuiltin::file): Likewise.
	(MacroBuiltin::column): Likewise.
	(MacroBuiltin::include_bytes): Likewise.
	(MacroBuiltin::include_str): Likewise.
	(MacroBuiltin::compile_error): Likewise.
	(MacroBuiltin::concat): Likewise.
	(MacroBuiltin::env): Likewise.
	(MacroBuiltin::cfg): Likewise.
	(MacroBuiltin::include): Likewise.
	(MacroBuiltin::line): Likewise.
	* expand/rust-macro-builtins.h: Likewise.
	* expand/rust-macro-expand.cc (MacroExpander::expand_decl_macro): Likewise.
	(MacroExpander::expand_invoc): Likewise.
	(MacroExpander::match_repetition): Likewise.
	(parse_many): Likewise.
	(transcribe_many_items): Likewise.
	(transcribe_many_ext): Likewise.
	(transcribe_many_trait_items): Likewise.
	(transcribe_many_impl_items): Likewise.
	(transcribe_many_trait_impl_items): Likewise.
	(transcribe_expression): Likewise.
	(transcribe_type): Likewise.
	(transcribe_on_delimiter): Likewise.
	(tokens_to_str): Likewise.
	* expand/rust-macro-expand.h (struct MacroExpander): Likewise.
	* util/rust-hir-map.cc (Mappings::insert_macro_def): Likewise.
2023-02-21 12:36:37 +01:00
Arthur Cohen
e2647e5e5a gccrs: ast: Refactor ASTFragment -> Fragment class
gcc/rust/ChangeLog:

	* Make-lang.in: Add `rust-ast-fragment.o` object file.
	* ast/rust-ast-fragment.cc: New file.
	* ast/rust-ast-fragment.h: New file.
2023-02-21 12:36:36 +01:00
Philip Herron
643ec1c253 gccrs: Add check for recursive trait cycles
gcc/rust/ChangeLog:

	* typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_trait): Check if a
	trait query is currently in progress.
	* typecheck/rust-hir-type-check.h (class TraitQueryGuard): Add helpers around
	checking for trait queries and inserting them.

gcc/testsuite/ChangeLog:

	* rust/compile/issue-1589.rs: New test.
2023-02-21 12:36:36 +01:00
Arthur Cohen
ec28fdb6aa gccrs: dump: Dump macro rules definition
gcc/rust/ChangeLog:

	* ast/rust-ast-dump.cc (Dump::visit): Add missing visitors for macro definition dumping.
	(get_delimiters): New function.
	* ast/rust-ast-dump.h: Declare `get_delimiters` and add documentation.
	* ast/rust-macro.h: Add `get_token_tree` method.
2023-02-21 12:36:36 +01:00
Jakub Dupak
e535b7b3e3 gccrs: ast: Module: unloaded module and inner attributes
gcc/rust/ChangeLog:

	* ast/rust-ast-dump.cc (Dump::visit): Properly handle unloaded modules.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2023-02-21 12:36:36 +01:00
Arthur Cohen
2f16df1b44 gccrs: dump: Fix module dumping
gcc/rust/ChangeLog:

	* ast/rust-ast-dump.cc (Dump::visit): Fix formatting when dumping modules.
2023-02-21 12:36:35 +01:00
Arthur Cohen
31150a6366 gccrs: dump: Dump items within modules
gcc/rust/ChangeLog:

	* ast/rust-ast-dump.cc (Dump::visit): Dump items in modules properly.
2023-02-21 12:36:35 +01:00
Arthur Cohen
421494b592 gccrs: dump: Emit visibility when dumping items
gcc/rust/ChangeLog:

	* ast/rust-ast-dump.cc: Emit visibility when dumping items.
2023-02-21 12:36:35 +01:00
Philip Herron
8f0b1526e0 gccrs: Support outer attribute handling on trait items just like normal items
gcc/rust/ChangeLog:

	* hir/rust-ast-lower-base.h (class ItemWrapper): New class.
	* hir/rust-ast-lower-base.cc (ASTLoweringBase::handle_outer_attributes): Use
	`ItemWrapper` class.
	(ASTLoweringBase::handle_doc_item_attribute): Likewise.
	(ASTLoweringBase::handle_lang_item_attribute): Likewise.
	* hir/rust-ast-lower-implitem.h: Check outer attributes on items.
	* hir/tree/rust-hir-item.h: Add `get_trait_locus` methods.
	* hir/tree/rust-hir.h: Likewise.
	* util/rust-hir-map.h: Add defId mappings and associated functions.
	* util/rust-hir-map.cc (Mappings::insert_defid_mapping): Implement insertion to said
	mappings.
	(Mappings::lookup_trait_item_defid): And looking up said mappings.
2023-02-21 12:36:35 +01:00
Jakub Dupak
acbaadfa46 gccrs: ast: dump TypeAlias
gcc/rust/ChangeLog:

	* ast/rust-ast-dump.cc (Dump::visit): Add code for dumping type aliases.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2023-02-21 12:36:34 +01:00
Philip Herron
74065c000e gccrs: Refactor TraitResolver to not require a visitor
gcc/rust/ChangeLog:

	* typecheck/rust-hir-trait-resolve.cc (TraitResolver::TraitResolver): Do not nullptr init
	`resolved_trait_reference` anymore.
	(TraitResolver::resolve_path): Simplify function and rename to...
	(TraitResolver::resolve_path_to_trait): ...this.
	(TraitResolver::lookup_path): Use new interface.
	* typecheck/rust-hir-trait-resolve.h (class TraitResolver): Do not inherit `HIRFullVisitor`
	class anymore.
2023-02-21 12:36:34 +01:00
David Faust
173f98ae49 gccrs: ast: dump: RangeExprs
gcc/rust/ChangeLog:

	* ast/rust-ast-dump.cc (Dump::visit): Add dump for RangeExprs.
2023-02-21 12:36:34 +01:00
David Faust
d1db46191e gccrs: ast: dump: various simple Exprs
Adds dump for:
- BorrowExpr
- DereferenceExpr
- ErrorPropagationExpr
- NegationExpr
- TypeCastExpr
- GroupedExpr

gcc/rust/ChangeLog:

	* ast/rust-ast-dump.cc (Dump::visit): Add dump for, BorrowExpr, DereferenceExpr,
	ErrorPropagationExpr, NegationExpr, TypeCastExpr and GroupedExpr.
2023-02-21 12:36:34 +01:00
David Faust
f26e9ca3e9 gccrs: ast: dump: ArrayExpr
gcc/rust/ChangeLog:

	* ast/rust-ast-dump.cc (Dump::visit): Add dump code for ArrayExpr.
2023-02-21 12:36:34 +01:00
David Faust
c091fd5f4a gccrs: ast: dump: ComparisonExpr and LazyBooleanExpr
gcc/rust/ChangeLog:

	* ast/rust-ast-dump.cc (Dump::visit): Add dumps for ComparisonExpr and
	LazyBooleanExpr.
2023-02-21 12:36:34 +01:00
David Faust
0a9114c151 gccrs: ast: dump: minor fixups to IfExpr formatting
gcc/rust/ChangeLog:

	* ast/rust-ast-dump.cc (Dump::visit): Fix IfExpr formatting.
2023-02-21 12:36:33 +01:00
David Faust
b1510ce0fc gccrs: ast: dump: fix extra newline in block without tail
gcc/rust/ChangeLog:

	* ast/rust-ast-dump.cc (Dump::visit): Fix block formatting.
2023-02-21 12:36:33 +01:00
Philip Herron
59bee4d466 gccrs: Method resolution must support multiple candidates
This patch fixes bad method resolution in our operator_overload_9 case.
When we have a &mut reference to something and we deref we must resolve to
the mutable reference impl block. The interface we are using to resolve
methods is the can_eq interface which allows for permissive mutability
which means allowing for mutable reference being unified with an immutable
one. This meant we actual match against both the immutable and mutable
version leading to multiple candidate error.

The fix here adds a method resolution flag to the can_eq interface so that
we enforce mutability equality. The other hack is that we do not allow
can_eq of ParamTypes to generic Slices. I think there is some subtle thing
going on for that case. The Rustc method resolver actually filters the
impl blocks for reference types based looking up the relevant lang items
we need to do this as well but is a much larger refactor to our method
resolver which should be done seperately.

Fixes #1588

gcc/rust/ChangeLog:

	* typecheck/rust-autoderef.cc: Add support for multiple resolution candidates.
	* typecheck/rust-hir-dot-operator.cc (MethodResolver::MethodResolver): Edit
	`try_result` field and change constructor.
	(MethodResolver::Probe): Return set of candidates instead of singular candidate.
	(MethodResolver::select): Add better implementation to account for multiple
	candidates.
	* typecheck/rust-hir-dot-operator.h (struct MethodCandidate): Overload comparison
	operator in order to store them in `std::set`.
	* typecheck/rust-hir-inherent-impl-overlap.h: Do not fail assertion on missing type.
	* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Adapt code to use
	multiple candidates.
	* typecheck/rust-tyty.cc (set_cmp_autoderef_mode): Add code to handle automatic
	derefs properly.
	(reset_cmp_autoderef_mode): Add helper function to reset said mode.
	* typecheck/rust-tyty.h (set_cmp_autoderef_mode): Declare function.
	(reset_cmp_autoderef_mode): Likewise.
	* typecheck/rust-tyty-cmp.h: Add handling of `autoderef_cmp_flag`

gcc/testsuite/ChangeLog:

	* rust/compile/generics7.rs: Fix test with missing assertion.
	* rust/execute/torture/operator_overload_9.rs: Fix test assertion.
2023-02-21 12:36:33 +01:00
Philip Herron
2d7661e76e gccrs: Add ABI mappings for rust-call to map to ABI::RUST
gcc/rust/ChangeLog:

	* util/rust-abi.cc (get_abi_from_string): Add missing "rust-call"
	possibility for ABI variant.
2023-02-21 12:36:33 +01:00
Philip Herron
f49e252824 gccrs: Add mappings for fn_once lang item
gcc/rust/ChangeLog:

	* util/rust-lang-item.h: Add `fn_once` lang item.
2023-02-21 12:36:33 +01:00
Philip Herron
13556413e3 gccrs: Support type resolution on super traits on dyn objects
When checking if specified bounds satisfy other bounds we must lookup the
super traits. To finish the support for super traits we need to redo the
computation of method addresses to support super traits.

Addresses #914

gcc/rust/ChangeLog:

	* backend/rust-compile.cc: Add note about missing support for super
	traits.
	* typecheck/rust-tyty.cc (BaseType::satisfies_bound): New function.
	(BaseType::bounds_compatible): New function.
	(DynamicObjectType::get_object_items): New function.
	* typecheck/rust-hir-trait-ref.h: Use new API to perform type resolution
	on dyn objects.
2023-02-21 12:36:33 +01:00
Arthur Cohen
5221974691 gccrs: early-name-resolver: Add simple macro name resolution
This name resolver performs the same macro name resolution as what was
previously done by the AttrVisitor visitor and macro expander.

It also resolves macro expressions in builtin-macros properly, as well
as expanded AST nodes when necessary.

gcc/rust/ChangeLog:

	* Make-lang.in: Compile early name resolver.
	* expand/rust-attribute-visitor.cc (AttrVisitor::visit): Move macro
	name resolution.
	* expand/rust-macro-builtins.cc (try_expand_macro_expression): Run ENR
	when recursively expanding macros.
	* expand/rust-macro-expand.cc (MacroExpander::expand_invoc): No longer
	perform name resolution in `expand_invoc`.
	* expand/rust-macro-expand.h (struct MacroExpander): Keep ENR within
	MacroExpander.
	* rust-session-manager.cc (Session::expansion): Run ENR.
	* resolve/rust-early-name-resolver.cc: New file.
	* resolve/rust-early-name-resolver.h: New file.
2023-02-21 12:36:33 +01:00
Arthur Cohen
2f1035fc91 gccrs: ast: Add accept_vis() method to GenericArg
gcc/rust/ChangeLog:

	* ast/rust-path.h: Add `accept_vis` method to `GenericArg` class.
2023-02-21 12:36:33 +01:00
Arthur Cohen
295cd26508 gccrs: rust-ast-resolve-item: Add note about resolving glob uses
gcc/rust/ChangeLog:

	* resolve/rust-ast-resolve-item.cc (ResolveItem::visit): Add note for
	glob import resolving.
2023-02-21 12:36:33 +01:00
Arthur Cohen
a08f265625 gccrs: mappings: Add MacroInvocation -> MacroRulesDef mappings
gcc/rust/ChangeLog:

	* util/rust-hir-map.h: Add new mappings.
	* util/rust-hir-map.cc (Mappings::insert_macro_invocation): Add insertion
	function into mappings.
	(Mappings::lookup_macro_invocation): Add lookup function for mappings.
2023-02-21 12:36:33 +01:00
Marc Poulhiès
570415e75c gccrs: fix ICE on missing closing paren
Fix crash (segfault) on a missing closing parenthesis when parsing the
expressions in a block. The returned `expr` was missing a check before being
used.

Add corresponding test.

Signed-off-by: Marc Poulhiès <dkm@kataplop.net>

gcc/rust/ChangeLog:

	* parse/rust-parse-impl.h (Parser::parse_stmt_or_expr_without_block):
	Check if `expr` is valid after parsing it.

gcc/testsuite/ChangeLog:

	* rust/compile/missing_closing_paren.rs: New test.
2023-02-21 12:36:33 +01:00
Arthur Cohen
ab6d8ad3f5 gccrs: intrinsics: Add data prefetching intrinsics
gcc/rust/ChangeLog:

	* backend/rust-builtins.cc (BuiltinsContext::setup): Declare prefetch
	intrinsics.
	* backend/rust-compile-intrinsic.cc (enum class Prefetch): Add kinds of
	prefetch intrinsics.
	(prefetch_data_handler): New function.
	(prefetch_read_data): Likewise.
	(prefetch_write_data): Likewise.

gcc/testsuite/ChangeLog:

	* rust/execute/torture/prefetch_data.rs: New test.
2023-02-21 12:36:32 +01:00
David Faust
0a762d2049 gccrs: ast: dump structs, enums and unions
gcc/rust/ChangeLog:

	* ast/rust-ast-dump.cc (Dump::visit): Fill empty functions for
	structs, enums and unions.
2023-02-21 12:36:32 +01:00
David Faust
4c807ef70d gccrs: ast: dump: add format_{tuple,struct}_field helpers
gcc/rust/ChangeLog:

	* ast/rust-ast-dump.cc (Dump::format_tuple_field): New.
	(Dump::format_struct_field): New.
	* ast/rust-ast-dump.h (format_tuple_field): New.
	(format_struct_field): New.
2023-02-21 12:36:32 +01:00
David Faust
8d02ef57a6 gccrs: ast: dump: add emit_generic_params helper
gcc/rust/ChangeLog:

	* ast/rust-ast-dump.cc (Dump::visit): move generic params dump ...
	(Dump::emit_generic_params): ... here.
	* ast/rust-ast-dump.h (emit_generic_params): New.
2023-02-21 12:36:32 +01:00
Philip Herron
a5d3586a9b gccrs: Support looking up super traits for trait items
When supporting calls to super traits we need to allow lookups based on
the super traits as specified on the TraitReferences.

Fixes #1555

gcc/rust/ChangeLog:

	* typecheck/rust-hir-trait-ref.h (lookup_trait_item): Add lookup
	in super_trait.

gcc/testsuite/ChangeLog:

	* rust/compile/torture/issue-1555.rs: New test.
2023-02-21 12:36:32 +01:00
Philip Herron
31b77593ed gccrs: Ensure uniqueness on Path probe's
When we lookup names in paths such as Foo::bar, foo is a type we resolve
and then we lookup 'bar' based on what type Foo is which includes probing
relevant bounds of this type. We currently return a vector of possible
candidates and this patch changes it so that we return a set of unique
items based on DefId.

Addresses #1555

gcc/rust/ChangeLog:

	* backend/rust-compile-expr.cc
	(CompileExpr::resolve_method_address): Use auto and minor change
	in candidate init.
	* typecheck/rust-hir-type-check-path.cc
	(TypeCheckExpr::resolve_segments): Likewise.
	* typecheck/rust-hir-type-check-type.cc: Likewise.
	* backend/rust-compile-resolve-path.cc
	(HIRCompileBase::query_compile): Likewise. Removecall to
	set_ty_ref.
	* typecheck/rust-hir-path-probe.h (struct PathProbeCandidate): Add
	locus initializer in ctor, implement get_defid.
	(class PathProbeType::Probe): return a set instead of vector.
	Adjust class impl.
	(class ReportMultipleCandidateError): Do not inherit from
	HIRImplVisitor anymore and remove corresponding impl. Adjust for
	change in Probe. Simplify Report handling.
	(class PathProbeImplTrait::Probe): Adjust return type.
2023-02-21 12:36:32 +01:00
Philip Herron
79434fabf7 gccrs: Track DefId on ADT variants
We must track the DefID on variants for algebraic data types as this will
allow us to enforce unique'ness on path queries relating to this.

gcc/rust/ChangeLog:

	* typecheck/rust-hir-type-check-enumitem.cc
	(TypeCheckEnumItem::visit): Adjust VariantDef ctor calls with
	DefID.
	* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit):
	Likewise.
	* typecheck/rust-tyty.h (VariantDef): Add defid parameter to ctor.
2023-02-21 12:36:32 +01:00
Arthur Cohen
00e0684a78 gccrs: builtins: Move implementation into source file
gcc/rust/ChangeLog:

	* Make-lang.in: Add `rust-builtins.o` as target
	* backend/rust-builtins.h: Refactor to new file.
	* backend/rust-builtins.cc: New file.
2023-02-21 12:36:32 +01:00
David Faust
aeed747093 gccrs: ast: dump If expressions
gcc/rust/ChangeLog:

	* ast/rust-ast-dump.cc (Dump::visit): Implement visitor for If
	expressions.
2023-02-21 12:36:32 +01:00
David Faust
980bd25e25 gccrs: ast: dump assignment and compound assignment expr
gcc/rust/ChangeLog:

	* ast/rust-ast-dump.cc (Dump::visit): Dump assignment and compound
	assignment expressions.
2023-02-21 12:36:32 +01:00
Faisal Abbas
d072b4a516 gccrs: testing: try loop in const function
Signed-off-by: Faisal Abbas <90.abbasfaisal@gmail.com>

gcc/testsuite/ChangeLog:

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

Signed-off-by: Faisal Abbas <faisal.abbas@elastica.co>
2023-02-21 12:36:32 +01:00