aboutsummaryrefslogtreecommitdiff
AgeCommit message (Collapse)AuthorFilesLines
3 hoursgccrs: Add input/output from inout and split in outPierre-Emmanuel Patry1-34/+71
Inline assembly was incomplete and input/output from inout or split in out were not handled. gcc/rust/ChangeLog: * backend/rust-compile-asm.cc (get_out_expr): Return valid output from an operand. (CompileAsm::asm_construct_outputs): Handle every output (get_in_expr): Return valid input from an operand. (CompileAsm::asm_construct_inputs): Handle every input Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
3 hoursgccrs: Parse input and output expressionPierre-Emmanuel Patry1-7/+16
Previously inline assembly expected identifiers instead of expression. gcc/rust/ChangeLog: * expand/rust-macro-builtins-asm.cc (parse_reg_operand_inout): Parse expressions and build split in out. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
3 hoursgccrs: Add pretty hir dump for inline assemblyPierre-Emmanuel Patry3-11/+90
gcc/rust/ChangeLog: * hir/rust-hir-dump.cc (Dump::visit): Dump inline assembly fields * hir/tree/rust-hir-expr.h: Add non const getter and avoid operand copy from getters. * hir/tree/rust-hir-visitor.cc (DefaultHIRVisitor::walk): Use non const reference. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
3 hoursgccrs: Add indexed positional argument support in asmPierre-Emmanuel Patry1-0/+5
gcc/rust/ChangeLog: * expand/rust-macro-builtins-asm.cc (expand_inline_asm_strings): Handle transformation for indexed positional arguments. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
3 hoursgccrs: Implement compilation for SlicePattern against SliceType scrutineeYap Zhi Heng5-2/+114
006t.original output from compiling testsuite/rust/compile/match-slicepattern-slice.rs: ... RUSTTMP.3 = slice; if (RUSTTMP.3.len == 1 && *(RUSTTMP.3.data + 0 * 4) == 1) { { struct () RUSTTMP.4; { } goto <D.129>; } } if (RUSTTMP.3.len == 2 && *(RUSTTMP.3.data + 1 * 4) == 2) { { struct () RUSTTMP.5; { } goto <D.129>; } } if (1) { { struct () RUSTTMP.6; { } goto <D.129>; } } <D.129>:; ... gcc/rust/ChangeLog: * rust-backend.h: New slice_index_expression function. * rust-gcc.cc: Implementation of slice_index_expression to generate tree node for accessing slice elements. * backend/rust-compile-pattern.cc: Implement SlicePattern check expression & binding compilation against SliceType scrutinee. Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
3 hoursgccrs: Update SlicePattern typechecking against slice reference parentsYap Zhi Heng2-4/+19
gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit(SlicePattern)): Add new type check case for SliceType wrapped in ReferenceType. * backend/rust-compile-pattern.cc: Adjusted the asserts accordingly for CompilePatternCheckExpr(SlicePattern) & CompilePatternBindings(SlicePattern). Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
3 hoursgccrs: desugar: Handle try-blocksArthur Cohen5-1/+196
gcc/rust/ChangeLog: * Make-lang.in: Compile it. * ast/rust-expression-yeast.cc (ExpressionYeast::dispatch): Dispatch to try-block desugar. * ast/rust-desugar-try-block.cc: New file. * ast/rust-desugar-try-block.h: New file. gcc/testsuite/ChangeLog: * rust/compile/try_block1.rs: New test.
3 hoursgccrs: ast: Add Expr::Kind::TryArthur Cohen2-1/+2
gcc/rust/ChangeLog: * ast/rust-ast.h: Add the new variant. * ast/rust-expr.h: Use it for TryExpr class.
3 hoursgccrs: Handle IfLetExprConseqElse in DefaultResolverOwen Avery2-0/+8
This relies on the DefaultASTVisitor visitor for IfLetExprConseqElse performing a virtual call of the visitor for IfLetExpr, which doesn't hold when DefaultASTVisitor is generated by the X-macro-DSL-system I have in another patch. gcc/rust/ChangeLog: * resolve/rust-default-resolver.cc (DefaultResolver::visit): Add visitor for IfLetExprConseqElse. * resolve/rust-default-resolver.h (DefaultResolver::visit): Likewise. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
3 hoursgccrs: ast: Visit block labels if they are presentArthur Cohen1-0/+5
gcc/rust/ChangeLog: * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Visit a block's loop label if it exists.
3 hoursgccrs: desugar: Add desugar dispatch for all desugarsArthur Cohen6-56/+157
Since we are doing more and more "external" desugars, as in desugars that take a pointer and replace it with another one, rather than modifying it from within, having an external visitor dispatch to the proper desugar helps with code clarity. gcc/rust/ChangeLog: * Make-lang.in: Compile it. * rust-session-manager.cc: Call the expression desugar dispatcher. * ast/rust-desugar-question-mark.cc: Rework class API. * ast/rust-desugar-question-mark.h: Likewise. * ast/rust-expression-yeast.cc: New file. * ast/rust-expression-yeast.h: New file.
3 hoursgccrs: chore: ast: Fix formatting in rust-expr.hArthur Cohen1-46/+43
gcc/rust/ChangeLog: * ast/rust-expr.h: Fix formatting.
3 hoursgccrs: hir: Handle deferred const inference variablesArthur Cohen6-15/+67
gcc/rust/ChangeLog: * hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Handle defered consts. * hir/tree/rust-hir-expr.cc (AnonConst::AnonConst): Likewise. (AnonConst::operator=): Likewise. * hir/tree/rust-hir-expr.h: Likewise. * hir/tree/rust-hir-visitor.cc (DefaultHIRVisitor::walk): Likewise. * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise. gcc/testsuite/ChangeLog: * rust/compile/deferred_const_inference.rs: New test.
3 hoursgccrs: ast: Use AnonConst for array type sizesArthur Cohen6-28/+96
gcc/rust/ChangeLog: * ast/rust-expr.h: Add handling for deferred consts. * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Likewise. * ast/rust-ast.cc (AnonConst::as_string): Likewise. (ArrayType::as_string): Likewise. * ast/rust-type.h (class ArrayType): Use AnonConst for sizes. * parse/rust-parse-impl.h (Parser::parse_anon_const): New function. (Parser::parse_slice_or_array_type): Call it. * parse/rust-parse.h: Declare it.
3 hoursgccrs: nr2.0: Handle glob imports of enum variants.Arthur Cohen6-19/+76
gcc/rust/ChangeLog: * resolve/rust-early-name-resolver-2.0.cc (Early::resolve_glob_import): Adapt for enums. (Early::finalize_glob_import): Likewise. * resolve/rust-early-name-resolver-2.0.h: Likewise. * resolve/rust-finalize-imports-2.0.cc (GlobbingVisitor::go): Likewise. (GlobbingVisitor::visit_module_container): New function. (GlobbingVisitor::visit_enum_container): New function. * resolve/rust-finalize-imports-2.0.h: Declare them. * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Insert enums as potential containers. gcc/testsuite/ChangeLog: * rust/compile/glob_import_enum.rs: New test.
3 hoursgccrs: mappings: Change mappings to allow other items as item containers.Arthur Cohen2-10/+12
This is important for importing enum variants as items. gcc/rust/ChangeLog: * util/rust-hir-map.cc (Mappings::insert_ast_module): Rename to... (Mappings::insert_glob_container): ...this. (Mappings::lookup_ast_module): Rename to... (Mappings::lookup_glob_container): ...this. * util/rust-hir-map.h: Change declarations.
3 hoursgccrs: Load modules during CfgStrip phaseOwen Avery2-30/+10
TopLevel would ignore just-loaded modules but Early and ExpandVisitor wouldn't. The latter would produce errors when it hit attributes which should have been indirectly CfgStrip'd away. gcc/rust/ChangeLog: * expand/rust-cfg-strip.cc (CfgStrip::visit): Load unloaded modules. * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Assume modules have been loaded by CfgStrip. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
3 hoursgccrs: Specialize ExpandVisitor::expand_macro_childrenOwen Avery2-30/+13
gcc/rust/ChangeLog: * expand/rust-expand-visitor.cc (ExpandVisitor::expand_inner_items): Adjust call to expand_macro_children. (ExpandVisitor::expand_inner_stmts): Likewise. (ExpandVisitor::visit): Likewise. * expand/rust-expand-visitor.h (ExpandVisitor::expand_macro_children): Take a pointer to member function instead of a std::function. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
3 hoursgccrs: fix bad monomophization of generic pathsPhilip Herron3-4/+477
When we have generic paths like T::foobar during codegen sometimes we need to enforce an extra lookup for this generic parameter type to the mono morphized underlying type. Fixes Rust-GCC#3915 Fixes Rust-GCC#1247 gcc/rust/ChangeLog: * backend/rust-compile-resolve-path.cc (HIRCompileBase::query_compile): do another lookup gcc/testsuite/ChangeLog: * rust/compile/issue-3915.rs: New test. * rust/execute/torture/sip-hasher.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
3 hoursgccrs: Use MacroInvocLexer in AttributeParserOwen Avery2-31/+51
This should make it easier for us to handle attribute meta items of the form <SimplePath> '=' <Expression> where the expression isn't a literal. Some low hanging fruit remains here, but I think I should keep this patch small as I had some trouble debugging it as-is (see: Rust::Token::as_string vs Rust::Token::get_str vs Rust::AST::Token::as_string). gcc/rust/ChangeLog: * ast/rust-ast.cc: Include "rust-macro-invoc-lexer.h". (AttributeParser::~AttributeParser): Move function definition here. (AttributeParser::AttributeParser): Likewise and adjust member initialization. (AttributeParser::parse_meta_item_inner): Handle changes to peek_token. (AttributeParser::parse_literal): Likewise. (AttributeParser::parse_simple_path_segment): Likewise. (AttributeParser::parse_meta_item_seq): Handle changes to AttributeParser fields. (AttributeParser::peek_token): Move function definition here and wrap MacroInvocLexer. (AttributeParser::skip_token): Likewise. * ast/rust-macro.h (class MacroInvocLexer): Forward declare. (class Parser): Likewise. (AttributeParser::token_stream): Remove field. (AttributeParser::stream_pos): Likewise. (AttributeParser::lexer): New field. (AttributeParser::parser): Likewise. (AttributeParser::AttributeParser): Move definition to "rust-ast.cc". (AttributeParser::~AttributeParser): Likewise. (AttributeParser::peek_token): Likewise. (AttributeParser::skip_token): Likewise. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
3 hoursgccrs: return error node when this fails during constexpr casePhilip Herron1-1/+2
Not adding the test case here we emit more errors than rustc for the error type node so its just noisy and dejagnu is being a pain. Fixes Rust-GCC#3933 gcc/rust/ChangeLog: * backend/rust-compile-resolve-path.cc (ResolvePathRef::resolve): return error_mark_node Signed-off-by: Philip Herron <herron.philip@googlemail.com>
3 hoursgccrs: Add initial support for deffered operator overload resolutionPhilip Herron10-19/+267
In the test case: fn test (len: usize) -> u64 { let mut i = 0; let mut out = 0; if i + 3 < len { out = 123; } out } The issue is to determine the correct type of 'i', out is simple because it hits a coercion site in the resturn position for u64. But 'i + 3', 'i' is an integer infer variable and the same for the literal '3'. So when it comes to resolving the type for the Add expression we hit the resolve the operator overload code and because of this: macro_rules! add_impl { ($($t:ty)*) => ($( impl Add for $t { type Output = $t; #[inline] #[rustc_inherit_overflow_checks] fn add(self, other: $t) -> $t { self + other } } )*) } add_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 } This means the resolution for 'i + 3' is ambigious because it could be any of these Add implementations. But because we unify against the '< len' where len is defined as usize later in the resolution we determine 'i' is actually a usize. Which means if we defer the resolution of this operator overload in the ambigious case we can simply resolve it at the end. Fixes Rust-GCC#3916 gcc/rust/ChangeLog: * hir/tree/rust-hir-expr.cc (OperatorExprMeta::OperatorExprMeta): track the rhs * hir/tree/rust-hir-expr.h: likewise * hir/tree/rust-hir-path.h: get rid of old comments * typecheck/rust-hir-trait-reference.cc (TraitReference::get_trait_substs): return references instead of copy * typecheck/rust-hir-trait-reference.h: update header * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::ResolveOpOverload): write ambigious operator overloads to a table and try to resolve it at the end * typecheck/rust-hir-type-check-expr.h: new static helper * typecheck/rust-hir-type-check.h (struct DeferredOpOverload): new model to defer resolution * typecheck/rust-typecheck-context.cc (TypeCheckContext::lookup_operator_overload): new (TypeCheckContext::compute_ambigious_op_overload): likewise (TypeCheckContext::compute_inference_variables): likewise gcc/testsuite/ChangeLog: * rust/compile/issue-3916.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
3 hoursgccrs: Fix ICE with duplicate root item main functionPhilip Herron2-1/+10
Rust seems to allow duplicate HIR::Item 'main' functions but it needs to be a root item to be the true main entry point. This means we can use the canonical path to determine if this is a root one where its CrateName::main or CrateName::Module::main. Fixes Rust-GCC#3978 gcc/rust/ChangeLog: * backend/rust-compile-base.cc: check the canonical path gcc/testsuite/ChangeLog: * rust/compile/issue-3978.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
3 hoursgccrs: Improve parsing of simple pathsOwen Avery4-67/+85
gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_simple_path): Be more careful about skipping SCOPE_RESOLUTION tokens. (Parser::parse_simple_path_segment): Allow parsing from a starting offset. (Parser::parse_use_tree): Handle a non-skipped SCOPE_RESOLUTION token. * parse/rust-parse.h (Parser::parse_simple_path_segment): Add parameter for parsing from a starting offset. gcc/testsuite/ChangeLog: * rust/compile/parse_simple_path_fail_1.rs: New test. * rust/compile/parse_simple_path_fail_2.rs: New test. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
3 hoursgccrs: Add test case to show issue is fixedPhilip Herron1-0/+9
Fixes Rust-GCC#3524 gcc/testsuite/ChangeLog: * rust/compile/issue-3524.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
3 hoursgccrs: Reject loop in const/static contextlishin3-2/+16
gcc/rust/ChangeLog: * backend/rust-compile-expr.cc (CompileExpr::visit): Add a catch for const/static. gcc/testsuite/ChangeLog: * rust/compile/loop_constant_context.rs: New test. * rust/compile/issue-3618.rs: Signed-off-by: lishin <lishin1008@gmail.com>
3 hoursgccrs: Implement compilation for SlicePattern matching against ArrayType ↵Yap Zhi Heng6-2/+127
scrutinee Example GIMPLE output from compiling testsuite/rust/compile/match-pattern-array.rs: ... a[0] = 0; a[1] = 1; RUSTTMP.3 = a; _1 = RUSTTMP.3[0]; _2 = _1 == 0; _3 = RUSTTMP.3[1]; _4 = _3 == 1; _5 = _2 & _4; if (_5 != 0) goto <D.122>; else goto <D.123>; <D.122>: { { } } goto <D.117>; } <D.123>: ... gcc/rust/ChangeLog: * rust-backend.h: New size_constant_expression function. * rust-gcc.cc: Implementation of size_constant_expression function to generate tree node for array access. * backend/rust-compile-pattern.h: Remove empty visits for SlicePattern. * backend/rust-compile-pattern.cc: Implement SlicePattern check expression & binding compilation against ArrayType scrutinee. Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
3 hoursgccrs: Add size checking to SlicePatternYap Zhi Heng2-3/+25
gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-pattern.cc(TypeCheckPattern::visit(SlicePattern)): Implement size checking for SlicePattern when type checking against array parent Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
3 hoursgccrs: Add test case showing all derives working on enumPhilip Herron1-0/+465
We have more complex test cases already but this will close out this issue. Fixes Rust-GCC#2005 gcc/testsuite/ChangeLog: * rust/execute/torture/issue-2005.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
3 hoursgccrs: attributes: Add #[test] and #[simd_test]Arthur Cohen2-1/+8
gcc/rust/ChangeLog: * util/rust-attribute-values.h: Add declarations for them. * util/rust-attributes.cc: Add definitions.
3 hoursgccrs: Add test case to show issue is fixedPhilip Herron1-0/+8
Fixes Rust-GCC#1048 gcc/testsuite/ChangeLog: * rust/compile/issue-1048.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
3 hoursgccrs: Add test case to show we emit better errors nowPhilip Herron1-0/+29
Fixes Rust-GCC#3144 gcc/testsuite/ChangeLog: * rust/compile/issue-3144.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
3 hoursgccrs: add test case to show issue is fixedPhilip Herron1-0/+8
Fixes Rust-GCC#3599 gcc/testsuite/ChangeLog: * rust/compile/issue-3599.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
3 hoursgccrs: Fix ICE when handling bad constructorPhilip Herron2-1/+9
We just had a typo returning ok true when it should have been false. Fixes Rust-GCC#3876 gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-struct.cc (TypeCheckStructExpr::visit): fix typo gcc/testsuite/ChangeLog: * rust/compile/issue-3876.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
3 hoursgccrs: Fix cast rules logic to try simple casts then fall back to coercionsPhilip Herron3-15/+46
This case: let i = 1; let j = i as i64; 'i' is meant to default to i32 but the inference was making both of these i64 because the code was prefering coercion logic which can end up with a default unify which causes the ?integer to unify with i64 making them both i64. But all we need to do is allow the simple cast rules to run first then fallback to coercions but special consideration has to be made to ensure that if there are dyn objects needed then this needs a unsize coercion, but also we need to ensure the underlying types are a valid simple cast too otherwise these also need to fallback to the coercion code. Fixes Rust-GCC#2680 gcc/rust/ChangeLog: * typecheck/rust-casts.cc (TypeCastRules::resolve): optional emit_error flag (TypeCastRules::check): try the simple cast rules then fallback to coercions (TypeCastRules::check_ptr_ptr_cast): ensure the underlying's (TypeCastRules::emit_cast_error): make this a static helper * typecheck/rust-casts.h: new emit_error prototype gcc/testsuite/ChangeLog: * rust/compile/issue-2680.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
3 hoursgccrs: nr2.0: Check before visiting a for-loop's labelArthur Cohen1-1/+4
gcc/rust/ChangeLog: * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Check for a label before visiting it.
3 hoursgccrs: Fix bad bounds checking for PartialOrdPhilip Herron14-43/+1128
This was a nasty issue to debug, the issue was very eager type bounds checking. So for example: pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> The super trait of PartialEq<Rhs> is a generic substitution and we reuse our bounds code here for normal generic bounds and generics an invalid bounds check was occuring when PartialEq<Rhs> was getting substituted becase this is a trait doing proper bounds checking is not valid here because this is telling us about the bounds in this case. Fixes Rust-GCC#3836 gcc/rust/ChangeLog: * typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_trait): track is super trait * typecheck/rust-hir-type-bounds.h: refactor bounds scan * typecheck/rust-hir-type-check-base.h: track from super trait * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): likewise * typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::is_bound_satisfied_for_type): refactor (TypeBoundsProbe::scan): likewise (TypeBoundPredicate::apply_generic_arguments): likewise * typecheck/rust-tyty-subst.cc: optional bounds checking on parm subst * typecheck/rust-tyty-subst.h: likewise * typecheck/rust-tyty.h: likewise gcc/testsuite/ChangeLog: * rust/compile/derive_partial_ord1.rs: this is now fully supported * rust/execute/torture/basic_partial_ord1.rs: add missing i32 impl * rust/execute/torture/basic_partial_ord2.rs: likewise * rust/compile/issue-3836.rs: New test. * rust/execute/torture/issue-3836.rs: New test. * rust/execute/torture/partial-ord-6.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
3 hoursgccrs: Fix narrowing of Loan (size_t) into LoanId (uint32)Marc Poulhiès1-1/+1
Fix narrowing: -../../gcc/rust/checks/errors/borrowck/rust-borrow-checker-diagnostics.cc:145:46: warning: narrowing conversion of ‘loan’ from ‘Rust::Polonius::Loan’ {aka ‘long unsigned int’} to ‘uint32_t’ {aka ‘unsigned int’} [-Wnarrowing] gcc/rust/ChangeLog: * checks/errors/borrowck/rust-bir-place.h (LoanId::value): Make it size_t to match Loan's base type. Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
3 hoursgccrs: Improve LiteralPattern type checkingYap Zhi Heng1-2/+12
This change is made to ensure that LiteralPatterns in SlicePattern are type-checked against the scrutinee array/slice's element type properly. gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-pattern.cc(TypeCheckPattern::visit(LiteralPattern)): Check LiteralPattern's type against its parent. Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
3 hoursgccrs: Add type checking for SlicePatternYap Zhi Heng1-2/+38
This commit implements basic type checking support for SlicePattern, based on rustc's check_pat_slice function. gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit(SlicePattern)): Implement initial type checking for SlicePattern. Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
3 hoursgccrs: Fix ice with invalid borrow expressionPhilip Herron3-1/+8
This is an invalid test case but we just need a guard for the missing borrow expression. Fixes Rust-GCC#3874 gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit): check for missing borrow * ast/rust-expr.h: add helper gcc/testsuite/ChangeLog: * rust/compile/issue-3874.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
3 hoursgccrs: Do proper const folding during typechecking for array capacitiesPhilip Herron17-63/+127
This patch adds proper folding to the const expression for array capacity we already have the const folding mechanics and the query system needed to handle cases where the capacity is a function call in a const context. This leverages and pulls the gcc tree capacity into the TyTy::ArrayType so it can be used for more typechecking and eventually doing more const generics work. Addresses Rust-GCC#3885 Fixes Rust-GCC#3882 gcc/rust/ChangeLog: * backend/rust-compile-base.cc (HIRCompileBase::query_compile_const_expr): new wrapper * backend/rust-compile-base.h: add prototype * backend/rust-compile-context.cc (Context::get): singleton helper * backend/rust-compile-context.h: likewise * backend/rust-compile-type.cc (TyTyResolveCompile::visit): handle infer's that can default * rust-session-manager.cc (Session::compile_crate): create the gcc context earlier for tychk * typecheck/rust-hir-type-check-base.cc (TypeCheckBase::resolve_literal): const fold it * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): likewise * typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit): likewise * typecheck/rust-tyty.cc (BaseType::monomorphized_clone): fix constructor call (ArrayType::as_string): print capacity (ArrayType::clone): fix constructor call * typecheck/rust-tyty.h: track capacity * typecheck/rust-unify.cc (UnifyRules::expect_array): check the capacities gcc/testsuite/ChangeLog: * rust/compile/all-cast.rs: shows array capacity now * rust/compile/arrays2.rs: likewise * rust/compile/const3.rs: fix error message * rust/compile/const_generics_3.rs: disable until typecheck we get proper errors now! * rust/compile/usize1.rs: proper capacity error message Signed-off-by: Philip Herron <herron.philip@googlemail.com>
3 hoursgccrs: nr2.0: Add proper handling for WhileLet loops.Arthur Cohen3-0/+25
gcc/rust/ChangeLog: * resolve/rust-late-name-resolver-2.0.cc (Late::visit): New visitor. * resolve/rust-late-name-resolver-2.0.h: Declare it. * resolve/rust-name-resolution-context.h (enum class): New binding context.
3 hoursgccrs: ast: Check before visiting a while-let's labelArthur Cohen2-1/+15
gcc/rust/ChangeLog: * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Check that the WhileLet has a label before visiting it. gcc/testsuite/ChangeLog: * rust/compile/while_let_without_label.rs: New test.
3 hoursgccrs: Parse try expressionsOwen Avery14-0/+157
This doesn't do anything beyond creating TryExpr and parsing them, so try expressions shouldn't be able to make it past AST lowering yet. gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit): Add visitor for TryExpr. * ast/rust-ast-collector.h (TokenCollector::visit): Likewise. * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Likewise. * ast/rust-ast-visitor.h (ASTVisitor::visit): Likewise. (DefaultASTVisitor::visit): Likewise. * expand/rust-derive.h (DeriveVisitor::visit): Likewise. * hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Likewise. * hir/rust-ast-lower-base.h (ASTLoweringBase::visit): Likewise. * resolve/rust-ast-resolve-base.cc (ResolverBase::visit): Likewise. * resolve/rust-ast-resolve-base.h (ResolverBase::visit): Likewise. * ast/rust-ast-full-decls.h (class TryExpr): New forward class declaration. * ast/rust-ast.cc (TryExpr::as_string): New function. (TryExpr::accept_vis): Likewise. * ast/rust-expr.h (class TryExpr): New class. * parse/rust-parse.h (Parser::parse_try_expr): New function. * parse/rust-parse-impl.h (Parser::parse_try_expr): Likewise. (Parser::null_denotation_not_path): Use parse_try_expr to parse try expressions. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
3 hoursgccrs: Allow format_args to accept a raw string literalOwen Avery1-2/+9
gcc/rust/ChangeLog: * expand/rust-macro-builtins-format-args.cc (format_args_parse_arguments): Accept a RAW_STRING_LITERAL token as the first argument. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
3 hoursgccrs: Change enum to enum classPierre-Emmanuel Patry2-3/+5
gcc/rust/ChangeLog: * parse/rust-parse-impl.h: Add enum prefix. * parse/rust-parse.h (enum ParseSelfError): Change from enum... (enum class): To enum class. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
3 hoursgccrs: Remove reinterpret_cast usages in DefaultASTVisitorOwen Avery1-3/+3
gcc/rust/ChangeLog: * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Replace usages of reinterpret_cast with static_cast. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
3 hoursgccrs: Remove Late visitor override for StructStructOwen Avery2-8/+0
DefaultResolver already handles StructStruct in a more correct fashion. gcc/rust/ChangeLog: * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Remove override for StructStruct visitor. * resolve/rust-late-name-resolver-2.0.h (Late::visit): Likewise. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
3 hoursgccrs: nr1.0: Remove rust/backend supportOwen Avery6-155/+51
This is the first patch in a set intended to fully remove name resolution 1.0. As such, it should leave name resolution 1.0 technically available but broken. gcc/rust/ChangeLog: * backend/rust-compile-context.cc (Context::Context): Remove initialization of resolver field. * backend/rust-compile-context.h (Context::get_resolver): Remove function. (Context::resolver): Remove field. * backend/rust-compile-expr.cc (CompileExpr::visit): Assume name resolution 2.0 is always enabled. (CompileExpr::generate_closure_function): Likewise. * backend/rust-compile-implitem.cc (CompileTraitItem::visit): Likewise. * backend/rust-compile-item.cc (CompileItem::visit): Likewise. * backend/rust-compile-resolve-path.cc (ResolvePathRef::resolve): Likewise. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>