Philip Herron [Tue, 20 May 2025 17:44:57 +0000 (18:44 +0100)]
gccrs: Always emit the error highest in the type hierarchy
The unify code was a bit dumb here where we always set emit_error to false for any
subtypes for example in comparing tuples we always emitted the whole tuple didnt
match the other tuple but really its much better to say expected bool got i32 because
the element types didn't match.
gcc/rust/ChangeLog:
* typecheck/rust-coercion.cc (TypeCoercionRules::coerce_unsized): dont emit error here
* typecheck/rust-unify.cc (UnifyRules::resolve_subtype): new helper to handle emit error
(UnifyRules::expect_adt): call resolve_subtype
(UnifyRules::expect_reference): likewise
(UnifyRules::expect_pointer): likewise
(UnifyRules::expect_array): likewise
(UnifyRules::expect_slice): likewise
(UnifyRules::expect_fndef): likewise
(UnifyRules::expect_fnptr): likewise
(UnifyRules::expect_tuple): likewise
(UnifyRules::expect_closure): likewise
(UnifyRules::expect_opaque): likeiwse
* typecheck/rust-unify.h: add new helper to header
gcc/testsuite/ChangeLog:
* rust/compile/traits9.rs: update errors
* rust/compile/unify-errors1.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Owen Avery [Thu, 15 May 2025 00:03:01 +0000 (20:03 -0400)]
nr2.0: Fix IfLet pattern handling
gcc/rust/ChangeLog:
* resolve/rust-default-resolver.cc
(DefaultResolver::visit_if_let_patterns): New function
definition.
(DefaultResolver::visit): New IfLetExpr visitor definition.
* resolve/rust-default-resolver.h
(DefaultResolver::visit_if_let_patterns): New function
declaration.
(DefaultResolver::visit): New IfLetExpr visitor declaration.
* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Remove
IfLetExpr visitor definition.
(Late::visit_if_let_patterns): New function definition.
* resolve/rust-late-name-resolver-2.0.h (Late::visit): Remove
IfLetExpr visitor declaration.
(Late::visit_if_let_patterns): New function declaration.
* resolve/rust-name-resolution-context.h (BindingSource::IfLet):
New enumerator.
Owen Avery [Mon, 26 May 2025 21:11:19 +0000 (17:11 -0400)]
Adjust included headers in rust-lang.cc
This was upstreamed as part of ea34614225d4d255e58f63206eb12178b870cb4c
but never made it to our downstream repo. I've added Philip as a
co-author, since he wrote the upstream commit.
gcc/rust/ChangeLog:
* rust-lang.cc: Remove direct inclusion of "config.h" and
"system.h", move inclusion of "rust-system.h" upwards.
Co-authored-by: Philip Herron <herron.philip@googlemail.com> Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Philip Herron [Mon, 19 May 2025 17:02:13 +0000 (18:02 +0100)]
gccrs: Initial support for Return Position Impl Trait
This is the initial patch for RPIT, we can build on this to handle the
more complex cases but there are enough distinct changes going on here
that it should just get merged now.
RPIT is really a sneaky generic so for example:
fn foo() -> impl Bar {
Baz
}
This is represented as: fn () -> OpaqueType Bar. But when we handle the
coercion site for Baz on impl Bar when we type resolve the function we
know that the underlying type is Baz. Note this function is _not_ generic
so its using this special OpaqueType and keeping track of the underlying type
in its ty_ref reference hir-id which will resolve to Baz.
This also means if we have a case where maybe this was in an if statement:
fn foo(a: i32) -> impl Bar {
if a > 10 {
Baz
} else {
Qux
}
}
The rules of impl Bar is that Baz is handled but Baz and Qux are different
underlying types so this is not allowed. The reason is impl traits are not
generic and although from a programmer perspective the callers dont know what
the underlying type is, the compiler _knows_ what it is. So really when
you call a function and get its return position impl trait the compiler knows
what to do and does all whats nessecary to handle calling functions using that
type etc.
gcc/rust/ChangeLog:
* backend/rust-compile-type.cc (TyTyResolveCompile::visit): we need to resolve the
underlying type
* typecheck/rust-substitution-mapper.cc (SubstMapperInternal::visit): just clone
* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit):
ensure we monomphize to get the underlying
* typecheck/rust-tyty.cc (BaseType::destructure): handle opaque types
(OpaqueType::resolve): this is much simpler now
(OpaqueType::handle_substitions): no longer needed
* typecheck/rust-tyty.h: update header
* typecheck/rust-unify.cc (UnifyRules::expect_opaque): unify rules for opaque
gcc/testsuite/ChangeLog:
* rust/compile/bad-rpit1.rs: New test.
* rust/execute/torture/impl_rpit1.rs: New test.
* rust/execute/torture/impl_rpit2.rs: New test.
* rust/execute/torture/impl_rpit3.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Philip Herron [Mon, 26 May 2025 18:30:45 +0000 (19:30 +0100)]
gccrs: Fix non canonical type bug with tuples
When working on rpit we needed to change to use a monomorphized clone of
the result of function calls. This ended up causing a verify gimple issue
with tuples because:
fn test<A, B>(a: A, b: B) -> (A, B)
When passing for example:
let a = test::<i32, i32> (123, 456) -> (A=i32, B=i32)
The resulting gimple types became:
const struct (A=i32, B=i32) vs struct (i32, i32)
We removed the VIEW_CONVERT_EXPR support to auto fix this stuff a good
while ago because it hides these kinds of issues because the type hasher
included the A=i32, B=i32 vs the i32, i32 name so updating this to use
get_name instead keeps the naming the same as well as the fields meaning
these types are 100% equivilant and therefore no conversion is required.
This only occurs because tuples are not named types we should really add
more rust specific info on our gimple TYPES.
gcc/rust/ChangeLog:
* backend/rust-compile-type.cc (TyTyResolveCompile::visit): use get_name
* typecheck/rust-tyty.cc (TupleType::get_name): likewise
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Philip Herron [Mon, 19 May 2025 16:42:17 +0000 (17:42 +0100)]
gccrs: Remove unneeded clones untill we have an arena allocator for these tmps
Cloning inference variables is very expensive because it means we are indirectly
creating an implicit new inference variable added to the reference chain.
gcc/rust/ChangeLog:
* checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::check_base_type_privacy):
no need for unreachable here
* typecheck/rust-unify.cc (UnifyRules::commit): dont clone infer vars
(UnifyRules::expect_inference_variable): likewise
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Philip Herron [Mon, 19 May 2025 16:55:53 +0000 (17:55 +0100)]
gccrs: refactor default infer vars to be its own function
This is just a simple refactor to pull all the logic outside of the
closure which makes it more readable.
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check.h: new function
* typecheck/rust-typecheck-context.cc (TypeCheckContext::compute_inference_variables):
call the new helper
(TypeCheckContext::compute_infer_var): refactored code
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Undefined attribute macros have no proc macro definition, which results
in a failing `rust_assert`. This changes that assert to an if statement,
that returns early if there is no proc macro definition. Fixes #3661.
gcc/rust/ChangeLog:
* resolve/rust-early-name-resolver-2.0.cc (Early::visit_attributes): rust_assert to if
gcc/testsuite/ChangeLog:
* rust/compile/issue-3661.rs: Test NR2 has expected behavior
Signed-off-by: Tom Schollenberger <tss2344@g.rit.edu>
Owen Avery [Thu, 8 May 2025 21:32:05 +0000 (17:32 -0400)]
Small improvements to DefaultASTVisitor and nr2.0
gcc/rust/ChangeLog:
* ast/rust-ast-visitor.cc
(DefaultASTVisitor::visit): Only visit the path of an instance
of Visibility if the instance has a path.
* ast/rust-ast.h
(SimplePath::SimplePath): Make sure constructors are explicit.
* resolve/rust-early-name-resolver-2.0.cc
(Early::visit_attributes): Pass entire paths to
NameResolutionContext::resolve_path.
(Early::visit): Likewise and avoid copying a path.
* resolve/rust-forever-stack.hxx
(ForeverStack::resolve_path): Assert that at least one path
segment has been passed in.
Owen Avery [Sat, 10 May 2025 02:17:55 +0000 (22:17 -0400)]
Fix Attr metavariable binding
gcc/rust/ChangeLog:
* parse/rust-parse-impl.h
(Parser::parse_attr_input): Handle more delimeter tokens and the
END_OF_FILE token.
(Parser::skip_after_end_attribute): Handle the END_OF_FILE
token.
gcc/testsuite/ChangeLog:
* rust/compile/macros/mbe/meta-param.rs: New test.
Owen Avery [Fri, 9 May 2025 22:02:29 +0000 (18:02 -0400)]
nr2.0: Fix borrow checking
gcc/rust/ChangeLog:
* checks/errors/borrowck/rust-bir-builder-internal.h: Include
"rust-immutable-name-resolution-context.h" and "options.h".
(AbstractBuilder::resolve_label): Use the 2.0 name resolver when
it's enabled.
(AbstractBuilder::resolve_variable): Likewise.
(AbstractBuilder::resolve_variable_or_fn): Likewise.
Philip Herron [Wed, 7 May 2025 15:07:43 +0000 (16:07 +0100)]
gccrs: Prevent passing generic arguments to impl traits in argument position
When using impl traits in argument position (APIT), they are desugared into generics,
and supplying explicit generic arguments is not allowed. This commit adds the error
diagnostic E0632 for attempting to pass generic arguments to impl traits, completing
the implementation of the APIT feature.
gcc/rust/ChangeLog:
* ast/rust-desugar-apit.cc: track if this is a impl-trait generic
* ast/rust-item.h (class TypeParam): add field to track if from impl trait
* hir/rust-ast-lower-type.cc (ASTLowerGenericParam::visit): likewise
* hir/tree/rust-hir-item.cc (TypeParam::TypeParam): upate hir as well
(TypeParam::operator=): likewise
* hir/tree/rust-hir-item.h (class TypeParam): likewise
* typecheck/rust-tyty-subst.cc (SubstitutionParamMapping::get_generic_param): add error
* typecheck/rust-tyty-subst.h: add const getter for the associated TypeParm
gcc/testsuite/ChangeLog:
* rust/compile/nr2/exclude: nr2 cant handle this
* rust/compile/impl_trait_generic_arg.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Owen Avery [Thu, 1 May 2025 01:54:53 +0000 (21:54 -0400)]
Improve struct pattern compilation
gcc/rust/ChangeLog:
* backend/rust-compile-pattern.cc
(CompilePatternCheckExpr::visit): Fix GENERIC generation in
light of enum layout changes since this code was written.
(CompilePatternBindings::handle_struct_pattern_ident_pat):
Delegate handling of child patterns to another
CompilePatternBindings::Compile call.
(CompilePatternBindings::make_struct_access): Make field name
parameter const qualified.
* backend/rust-compile-pattern.h
(CompilePatternBindings::make_struct_access): Likewise.
gcc/testsuite/ChangeLog:
* rust/execute/torture/struct-pattern-match.rs: New test.
Owen Avery [Sat, 3 May 2025 00:28:15 +0000 (20:28 -0400)]
Improve canonical path handling for impl items
gcc/rust/ChangeLog:
* resolve/rust-ast-resolve-item.cc
(ResolveItem::visit): Use the return values of
CanonicalPath::inherent_impl_seg and
CanonicalPath::trait_impl_projection_seg more directly.
* util/rust-canonical-path.h
(CanonicalPath::trait_impl_projection_seg): Append "<impl "
instead of "<" to the beginning of the returned path segment.
(CanonicalPath::inherent_impl_seg): Likewise.
* Make-lang.in: new desugar file
* ast/rust-ast.cc (ImplTraitTypeOneBound::as_string): its a unique_ptr now
(FormatArgs::set_outer_attrs): reformat
* ast/rust-path.h: remove has_generic_args assertion (can be empty because of desugar)
* ast/rust-type.h (class ImplTraitTypeOneBound): add copy ctor and use unique_ptr
* hir/rust-ast-lower-type.cc (ASTLoweringType::visit): update to use unique_ptr
* parse/rust-parse-impl.h (Parser::parse_type): reuse the existing unique_ptr instead
(Parser::parse_type_no_bounds): likewise
(Parser::parse_pattern): likewise
* resolve/rust-ast-resolve-type.cc (ResolveType::visit): its a unique_ptr now
* rust-session-manager.cc (Session::compile_crate): call desugar
* ast/rust-desugar-apit.cc: New file.
* ast/rust-desugar-apit.h: New file.
gcc/testsuite/ChangeLog:
* rust/compile/issue-2015.rs: fully supported now
* rust/compile/nr2/exclude: nr2 cant handle some of these
* rust/compile/issue-1487.rs: New test.
* rust/compile/issue-3454.rs: New test.
* rust/execute/torture/impl_desugar-2.rs: New test.
* rust/execute/torture/impl_desugar.rs: New test.
* rust/execute/torture/impl_trait1.rs: New test.
* rust/execute/torture/impl_trait2.rs: New test.
* rust/execute/torture/impl_trait3.rs: New test.
* rust/execute/torture/impl_trait4.rs: New test.
* rust/execute/torture/issue-1482.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Philip Herron [Mon, 5 May 2025 20:07:20 +0000 (21:07 +0100)]
gccrs: Emit error diagnostic for bad impl type usage
Rust only allows impl traits to be used in the return position of
functions.
Fixes Rust-GCC#1485
gcc/rust/ChangeLog:
* hir/rust-ast-lower-implitem.cc (ASTLowerImplItem::visit): allow impl type
* hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): likewise
* hir/rust-ast-lower-type.cc (ASTLoweringType::ASTLoweringType): new flag for impl trait
(ASTLoweringType::translate): pass flag
(ASTLoweringType::visit): track impl trait tag
(ASTLoweringType::emit_impl_trait_error): new diagnostic
* hir/rust-ast-lower-type.h: add new field
gcc/testsuite/ChangeLog:
* rust/compile/impl_trait_diag.rs: New test.
* rust/compile/issue-1485.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
* checks/errors/borrowck/rust-bir-place.h
(IndexVec::size_type): Add.
(IndexVec::MAX_INDEX): Add.
(IndexVec::size): Change the return type to the type of the
internal value used by the index type.
(PlaceDB::lookup_or_add_variable): Use the return value from the
PlaceDB::add_place call.
* checks/errors/borrowck/rust-bir.h
(struct BasicBlockId): Move this definition before the
definition of the struct Function.
Owen Avery [Sat, 11 Jan 2025 05:15:05 +0000 (00:15 -0500)]
Some assorted tweaks and bug fixes
gcc/rust/ChangeLog:
* ast/rust-ast-visitor.cc
(DefaultASTVisitor::visit): Visit the loop labels of
WhileLetLoopExpr instances before visiting their scrutinee
expressions.
* resolve/rust-early-name-resolver-2.0.cc
(Early::resolve_glob_import): Pass the glob import's path
directly to NameResolutionContext::resolve_path.
* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::visit): Remove unnecessary call to
Identifier::as_string.
(flatten_glob): Improve handling of cases where a glob use tree
has no path.
This commit introduce a new public function to visit function parameters
in the default visitor. It allows visitors derived from DefaultVisitor
to override only a small part of the default visitor.
gcc/rust/ChangeLog:
* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit_function_params):
Add specialized function to visit function parameters.
(DefaultASTVisitor::visit): Remove parameter visit and call specialized
function instead.
* ast/rust-ast-visitor.h: Add function prototye.
* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Remove
function.
(Late::visit_function_params): Override specialized visit function.
* resolve/rust-late-name-resolver-2.0.h: Add overriden function
prototype.
Binding context may be stacked when a new binding group is introduced
within a const expression.
gcc/rust/ChangeLog:
* resolve/rust-name-resolution-context.h: Use BindingLayer instead.
* resolve/rust-name-resolution-context.cc (BindingLayer::BindingLayer):
Add new constructor for binding layer.
(BindingLayer::bind_test): Add a function to test a binding constraint.
(BindingLayer::push): Push a new binding group.
(BindingLayer::and_binded): Add function to test and-binding
constraint.
(BindingLayer::or_binded): Add function to test or-binding constraints.
(BindingLayer::insert_ident): Insert a new identifier in the current
binding group.
(BindingLayer::merge): Merge current binding group with it's parent.
(BindingLayer::get_source): Get the source of the current binding
group.
* resolve/rust-late-name-resolver-2.0.cc: Use stacked context for
binding group.
* util/rust-stacked-contexts.h: Add mutable peek function.
* resolve/rust-default-resolver.cc (DefaultResolver::visit): Add visit
function for TypeParam.
* resolve/rust-default-resolver.h: Add function prototype.
* resolve/rust-forever-stack.h: Add function to check for forward
declaration ban.
* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Check forward
declarations.
Thomas Schwinge [Sat, 19 Apr 2025 13:49:34 +0000 (15:49 +0200)]
Disable parallel testing for 'rust/compile/nr2/compile.exp' [PR119508]
..., using the standard idiom. This '*.exp' file doesn't adhere to the
parallel testing protocol as defined in 'gcc/testsuite/lib/gcc-defs.exp'.
This also restores proper behavior for '*.exp' files executing after (!) this
one, which erroneously caused hundreds or even thousands of individual test
cases get duplicated vs. skipped, randomly, depending on the '-jN' level.
Philip Herron [Thu, 17 Apr 2025 15:19:35 +0000 (16:19 +0100)]
gccrs: prealloc the initilizer vector
There are two cases when initilizing an array, this is the
const context which means we need to build the array ctor,
which means using lots of memory, its super inefficient
because we are using a big wrapper over the GCC internals here
but preallocating the vectors here causes a:
terminate called after throwing an instance of 'std::bad_alloc'
So this is a handy error condition to rely on for this senario.
Fixes Rust-GCC#3713
Fixes Rust-GCC#3727
gcc/rust/ChangeLog:
* backend/rust-compile-expr.cc (CompileExpr::array_copied_expr): prealloc the vector
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Philip Herron [Thu, 17 Apr 2025 14:53:58 +0000 (15:53 +0100)]
gccrs: Fix ICE with empty generic arguments
We have an assertion when accessing generic args if there are any which
is really useful so this adds the missing guards for the case where
they are specified but empty.
Philip Herron [Thu, 17 Apr 2025 12:50:55 +0000 (13:50 +0100)]
gccrs: Fix ICE when handling case of unknown field in HIR::FieldAccess
We were wrongly adding the assertion that this must not be an enum but
this is a pointless assertion we only care that there are variant in the
ADT and if the field exists in the first variant.
Fixes Rust-GCC#3581
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): fix bad assertion
gcc/testsuite/ChangeLog:
* rust/compile/nonexistent-field.rs: fix bad error message
* rust/compile/issue-3581-1.rs: New test.
* rust/compile/issue-3581-2.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Philip Herron [Thu, 17 Apr 2025 13:38:04 +0000 (14:38 +0100)]
gccrs: Fix ICE in struct expressions
The error handling here was done long ago when we didnt know how to do
any error handling very well. This removed bad fatal_errors and adds in
some nice rich_location error diagnostics instead.
Fixes Rust-GCC#3628
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-struct-field.h: keep reference to parent expression
* typecheck/rust-hir-type-check-struct.cc (TypeCheckStructExpr::TypeCheckStructExpr):
update ctor
(TypeCheckStructExpr::resolve): remove bad rust_fatal_errors
(TypeCheckStructExpr::visit): cleanup errors
Add a new HIR LlvmInlineAsm HIR node as well as some structures to
represent it's options and operands. Lower AST::LlvmInlineAsm node to it
and then create a tree from that node.
gcc/rust/ChangeLog:
* ast/rust-ast-collector.cc (TokenCollector::visit): Remove unreachable
code.
* ast/rust-expr.h (struct LlvmOperand): Add LlvmOperand struct to
represent input and outputs.
(class LlvmInlineAsm): Add input, output and clobber operands.
(struct TupleTemplateStr): Add locus getter.
* backend/rust-compile-block.h: Add visit for LlvmInlineAsm.
* backend/rust-compile-expr.cc (CompileExpr::visit): Add llvm inline
asm stmt compilation.
* backend/rust-compile-expr.h: Add function prototype.
* backend/rust-compile-asm.h (class CompileLlvmAsm): Add llvm asm hir
not to gimple.
* backend/rust-compile-asm.cc (CompileLlvmAsm::CompileLlvmAsm): Add
constructor.
(CompileLlvmAsm::construct_operands): Add function to construct operand
tree.
(CompileLlvmAsm::construct_clobbers): Add function to construct clobber
tree.
(CompileLlvmAsm::tree_codegen_asm): Generate the whole tree for a given
llvm inline assembly node.
* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::visit):
Add visit function.
* checks/errors/borrowck/rust-bir-builder-expr-stmt.h: Add function
prototype.
* checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h: Add visit
function.
* 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: Add visit function
prototype.
* checks/errors/rust-const-checker.cc (ConstChecker::visit): Add visit
function.
* checks/errors/rust-const-checker.h: Add visit function prototype.
* checks/errors/rust-hir-pattern-analysis.cc (PatternChecker::visit):
Add visit function.
* checks/errors/rust-hir-pattern-analysis.h: Add visit function
prototype.
* checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Add
visit function.
* checks/errors/rust-unsafe-checker.h: Add function prototype.
* expand/rust-macro-builtins-asm.cc (parse_llvm_templates): Parse
templates.
(parse_llvm_arguments): Add function to parse non template tokens.
(parse_llvm_operands): Add function to parse operands, either input or
output.
(parse_llvm_outputs): Add function to parse and collect llvm asm
outputs.
(parse_llvm_inputs): Likewise with inputs.
(parse_llvm_clobbers): Add function to parse llvm asm clobbers.
(parse_llvm_options): Add function to parse llvm asm options.
(parse_llvm_asm): Add function to parse llvm asm.
* expand/rust-macro-builtins-asm.h (class LlvmAsmContext): Add context
for llvm asm parser.
(parse_llvm_outputs): Add function prototype.
(parse_llvm_inputs): Likewise.
(parse_llvm_clobbers): Likewise.
(parse_llvm_options): Likewise.
* hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Lower AST llvm
asm node to HIR.
* hir/rust-ast-lower-expr.h: Add function prototype.
* hir/rust-hir-dump.cc (Dump::visit): Add visit function.
* hir/rust-hir-dump.h: Add function prototype.
* hir/tree/rust-hir-expr-abstract.h: Add HIR llvm asm node kind.
* hir/tree/rust-hir-expr.h (struct LlvmOperand): Add LlvmOperand type
to represent input and outputs.
(class LlvmInlineAsm): Add LlvmInlineAsm hir node.
* hir/tree/rust-hir-full-decls.h (class LlvmInlineAsm): Add
LlvmInlineAsm hir node forward declaration.
* hir/tree/rust-hir-visitor.h: Add visit functions for LlvmInlineAsm
hir node.
* hir/tree/rust-hir.cc (LlvmInlineAsm::accept_vis): Add hir node
visitor related functions.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit):
Type check input and output operands.
* typecheck/rust-hir-type-check-expr.h: Add function prototype.
* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Visit input and
output operand expressions.
* resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit): Resolve input
and output expressions.
* resolve/rust-ast-resolve-expr.h: Add function prototypes.
Philip Herron [Wed, 16 Apr 2025 19:38:17 +0000 (20:38 +0100)]
gccrs: Add check for placeholder (infer) type in return position
It is not allowed to have a declared inference variable in the return
position of a function as this may never get infered you need good points
of truth.
Ideally if we get a student for GSoC 25 we will get the Default Hir Visitor
so that we can grab the HIR::InferredType locus instead of using the ref
location lookups.
Fixes Rust-GCC#402
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): add diagnostic
* typecheck/rust-tyty.cc (BaseType::contains_infer): new helper to grab first infer var
* typecheck/rust-tyty.h: prototype
gcc/testsuite/ChangeLog:
* rust/compile/issue-402.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Philip Herron [Wed, 16 Apr 2025 16:13:04 +0000 (17:13 +0100)]
gccrs: Fix ICE when checking shift's which are behind array refs
I copied a bad form of this check from the c front-end this updates it
to ensure the rhs is an INTEGER_CST and the lhs needs checked in the first
place.
Fixes Rust-GCC#3664
gcc/rust/ChangeLog:
* rust-gcc.cc (arithmetic_or_logical_expression): Ensure this is an integer
gcc/testsuite/ChangeLog:
* rust/compile/issue-3664.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
* typecheck/rust-hir-type-check-base.cc: Set enum representing
type properly if repr is an integer type.
* typecheck/rust-hir-type-check-item.cc: Update comments.
* typecheck/rust-tyty.h: Add new `ReprKind` enum to
`ReprOptions`.
* typecheck/rust-hir-type-check-base.cc: Handle setting of
`repr_kind`.
* typecheck/rust-hir-type-check-item.cc: New check for
zero-variant enums.
Arthur Cohen [Wed, 9 Apr 2025 12:48:55 +0000 (14:48 +0200)]
nr2.0: Only insert derive macros if they exist
This causes an assertion failure when compiling core with nr2.0, but should
probably be improved. I'm not sure how this code enables built-in derive
macros to be resolved so this is a temporary fix.
Arthur Cohen [Fri, 4 Apr 2025 12:18:33 +0000 (14:18 +0200)]
nr2.0: Do not resolve modules this run if they are unloaded
Instead, mark the visitor as dirty and wait for the next round of the fixed point to take care of
them. This avoids issues with module items being loaded while not being stripped yet.
gcc/rust/ChangeLog:
* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Return if module
is unloaded.
Arthur Cohen [Thu, 3 Apr 2025 14:22:10 +0000 (16:22 +0200)]
typecheck: Properly select methods when dealing with specialization
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-expr.cc (is_default_fn): New.
(emit_ambiguous_resolution_error): New.
(handle_multiple_candidates): Properly handle multiple candidates in
the case of specialization.
(TypeCheckExpr::visit): Call `handle_multiple_candidates`.
gcc/testsuite/ChangeLog:
* rust/execute/torture/min_specialization2.rs: New test.
* rust/execute/torture/min_specialization3.rs: New test.
Andrew Pinski [Thu, 20 Mar 2025 00:30:02 +0000 (17:30 -0700)]
rust: Add comment inside block [PR119342]
Inside a BLOCK node, all of the variables of the scope/block
are chained together and that connects them to the block.
This just adds a comment to that effect as reading the code
it is not so obvious why they need to be chained together.
gcc/rust/ChangeLog:
PR rust/119342
* rust-gcc.cc (block): Add comment on why chaining
the variables of the scope toether.
Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
Andrew Pinski [Thu, 20 Mar 2025 00:30:01 +0000 (17:30 -0700)]
rust: use range for inside rust-gcc.cc [PR119341]
There are some places inside rust-gcc.cc which are candidates
to use range for instead of iterators directly. This changes
the locations I saw and makes the code slightly more readable.