aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/rust
AgeCommit message (Collapse)AuthorFilesLines
2023-04-06gccrs: Fix issue with parsing unsafe block expression statementsOwen Avery1-0/+7
gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_stmt): Handle unsafe expression statements. gcc/testsuite/ChangeLog: * rust/compile/issue-1422.rs: New test. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2023-04-06gccrs: add test case to show our query-type system is workingPhilip Herron1-0/+8
Fixes #1361 Signed-off-by: Philip Herron <herron.philip@googlemail.com> gcc/testsuite/ChangeLog: * rust/compile/issue-1361.rs: New test.
2023-04-06gccrs: Fix up DejaGnu directives in 'rust/compile/issue-1830_{bytes,str}.rs' ↵Thomas Schwinge2-2/+4
test cases [#1838] 'dg-excess-errors' "indicates that the test is expected to fail due to compiler messages that are not handled by 'dg-error', [etc.]". It's argument doesn't specify the message to match but just just a comment. Here, however, we'd like to match specific compiler messages, so we should use 'dg-error', etc. Use the magic line number zero as the compiler error diagnostic doesn't tell which line the error occurred on (separate issue to resolve). This gives us: -XFAIL: rust/compile/issue-1830_str.rs (test for excess errors) +PASS: rust/compile/issue-1830_bytes.rs at line 8 (test for errors, line ) +PASS: rust/compile/issue-1830_bytes.rs (test for excess errors) -XFAIL: rust/compile/issue-1830_bytes.rs (test for excess errors) +PASS: rust/compile/issue-1830_str.rs at line 8 (test for errors, line ) +PASS: rust/compile/issue-1830_str.rs (test for excess errors) Fix-up for recent GCC/Rust master branch #1838 commit cf9ed4001eec6a22686d19a13f7de8ac94f9cb2a "testsuite: Add empty string macro test". gcc/testsuite/ * rust/compile/issue-1830_bytes.rs: Fix up DejaGnu directives. * rust/compile/issue-1830_str.rs: Likewise.
2023-04-06gccrs: builtins: Return empty list of tokens instead of nullptrArthur Cohen2-0/+9
gcc/rust/ChangeLog: * expand/rust-macro-builtins.cc (MacroBuiltin::include_handler): Do not return nullptr token in expansion of `include!()` gcc/testsuite/ChangeLog: * rust/compile/empty.in: New test. * rust/compile/include_empty.rs: New test.
2023-04-06gccrs: Fix regression in testcasePhilip Herron1-2/+62
Fixes #776 Signed-off-by: Philip Herron <herron.philip@googlemail.com> gcc/testsuite/ChangeLog: * rust/compile/torture/traits10.rs: Fix test-case
2023-04-06gccrs: Support for Sized builtin marker traitPhilip Herron2-0/+47
When implementing general bounds checking as part of unify calls, we did not check associated types on bounds which lead to alot of missed error checking. This now recursively checks the bounds and the associated types with a decent error message. This also required us to implement the Sized marker trait to keep existing test-cases happy. Fixes #1725 Signed-off-by: Philip Herron <herron.philip@googlemail.com> gcc/rust/ChangeLog: * typecheck/rust-hir-trait-reference.cc (TraitReference::clear_associated_types): make const (TraitReference::clear_associated_type_projections): new interface * typecheck/rust-hir-trait-reference.h: * typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_trait): refactor (TraitItemReference::associated_type_reset): reset projections * typecheck/rust-hir-type-bounds.h: * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): fix bounds * typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::TypeBoundsProbe): refactor into cc file (TypeBoundsProbe::Probe): refactor (TypeBoundsProbe::is_bound_satisfied_for_type): likewise (TypeBoundsProbe::assemble_sized_builtin): add builtin for Sized (TypeCheckBase::get_predicate_from_bound): refactor (TypeBoundPredicate::lookup_associated_type): refactor * typecheck/rust-tyty-subst.cc (SubstitutionRef::lookup_associated_impl) (SubstitutionRef::prepare_higher_ranked_bounds): new interface to clear hanging bounds (SubstitutionRef::monomorphize): refactor * typecheck/rust-tyty-subst.h: * typecheck/rust-tyty.cc (BaseType::get_locus): helper (BaseType::satisfies_bound): ensure bounds are satisfied and assoicated types (ParamType::ParamType): new field in constructor (ParamType::clone): update clone (ParamType::set_implicit_self_trait): new interface (ParamType::is_implicit_self_trait): likewise * typecheck/rust-tyty.h: cleanup * util/rust-hir-map.cc (Mappings::Mappings): builtin marker (Mappings::~Mappings): delete marker (Mappings::lookup_builtin_marker): lookup * util/rust-hir-map.h: update header gcc/testsuite/ChangeLog: * rust/compile/issue-1725-1.rs: New test. * rust/compile/issue-1725-2.rs: New test.
2023-04-06gccrs: Implemented UTF-8 checking for include_str!()Owen Avery2-0/+2
gcc/rust/ChangeLog: * expand/rust-macro-builtins.cc (MacroBuiltin::include_str_handler): Add check for valid UTF-8. gcc/testsuite/ChangeLog: * rust/compile/builtin_macro_include_str.rs: Include test of invalid UTF-8. * rust/compile/invalid_utf8: File with invalid UTF-8. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2023-04-06gccrs: Add support for parsing empty tuple patterns.Owen Avery1-0/+3
gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_grouped_or_tuple_pattern): Add support for empty tuple patterns. gcc/testsuite/ChangeLog: * rust/compile/parse_empty_tuple_pattern.rs: New test. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2023-04-06gccrs: testsuite: Add empty string macro testPierre-Emmanuel Patry2-0/+16
Add two new tests with empty string for include_str and include_bytes macros. gcc/testsuite/ChangeLog: * rust/compile/issue-1830_bytes.rs: New test. * rust/compile/issue-1830_str.rs: New test. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-04-06gccrs: Add testOwen Avery1-0/+8
gcc/testsuite/ChangeLog: * rust/compile/variadic.rs: New test. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2023-04-06gccrs: Add variadic argument type checkingOwen Avery1-1/+1
gcc/rust/ChangeLog: * typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Add variadic argument type checking. (TypeCheckCallExpr::visit): Fix comment spelling ("varadic"). gcc/testsuite/ChangeLog: * rust/execute/torture/overflow1.rs: Fix test. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2023-04-06gccrs: Add feature gate for "rust-intrinsic".mxlol23329-0/+60
This commit implemented a feature gate to check `intrinsics`. gcc/rust/ChangeLog: * checks/errors/rust-feature-gate.cc: Add implementation for `void FeatureGate::visit (AST::ExternBlock &block)`. Add `valid_feature` construction process in `FeatureGate::check`. * checks/errors/rust-feature-gate.h: Add declaration for `void FeatureGate::visit (AST::ExternBlock &block)`. Add private variable `valid_feature`. * checks/errors/rust-feature.h: Change `issue` to `m_issue`. gcc/testsuite/ChangeLog: * rust/compile/const-issue1440.rs: Add crate feature: `intrinsics`. * rust/compile/feature_intrinsics.rs: New file. * rust/compile/issue-1031.rs: Add crate feature: `intrinsics`. * rust/compile/issue-1130.rs: Add crate feature: `intrinsics`. * rust/compile/issue-1131.rs: Add crate feature: `intrinsics`. * rust/compile/issue-1237.rs: Add crate feature: `intrinsics`. * rust/compile/issue-1289.rs: Add crate feature: `intrinsics`. * rust/compile/rust-const-blog-issue.rs: Add crate feature: `intrinsics`. * rust/compile/torture/intrinsics-3.rs: Add crate feature: `intrinsics`. * rust/compile/torture/intrinsics-4.rs: Add crate feature: `intrinsics`. * rust/compile/torture/intrinsics-5.rs: Add crate feature: `intrinsics`. * rust/compile/torture/intrinsics-6.rs: Add crate feature: `intrinsics`. * rust/compile/torture/intrinsics-7.rs: Add crate feature: `intrinsics`. * rust/compile/torture/issue-1024.rs: Add crate feature: `intrinsics`. * rust/compile/torture/issue-1075.rs: Add crate feature: `intrinsics`. * rust/compile/torture/issue-1432.rs: Add crate feature: `intrinsics`. * rust/compile/unsafe10.rs: Add crate feature: `intrinsics`. * rust/execute/torture/atomic_load.rs: Add crate feature: `intrinsics`. * rust/execute/torture/atomic_store.rs: Add crate feature: `intrinsics`. * rust/execute/torture/copy_nonoverlapping1.rs: Add crate feature: `intrinsics`. * rust/execute/torture/issue-1120.rs: Add crate feature: `intrinsics`. * rust/execute/torture/issue-1133.rs: Add crate feature: `intrinsics`. * rust/execute/torture/issue-1232.rs: Add crate feature: `intrinsics`. * rust/execute/torture/slice-magic.rs: Add crate feature: `intrinsics`. * rust/execute/torture/slice-magic2.rs: Add crate feature: `intrinsics`. * rust/execute/torture/str-layout1.rs: Add crate feature: `intrinsics`. * rust/execute/torture/transmute1.rs: Add crate feature: `intrinsics`. * rust/execute/torture/wrapping_op1.rs: Add crate feature: `intrinsics`. * rust/execute/torture/wrapping_op2.rs: Add crate feature: `intrinsics`. Signed-off-by: Xiao Ma <mxlol233@outlook.com>
2023-04-06gccrs: macros: Perform macro expansion in a fixed-point fashion.Arthur Cohen6-6/+61
This commit changes our macro expansion system from an eager and recursive macro expansion to a fixed-point like system. Instead of, when seeing a macro invocation, expanding it and all of the macros within it, we now perform multiple passes of expansion on the entire crate. This, however, leads to a problem. Rust macros are expanded lazily, but Rust builtin macros should be expanded eagerly. Due to this, we must work around the lazy expansion in builtin macros and perform eager expansion for each pass of the fixed-point, before finally expanding the builtin when there are no longer any inner macro invocations. To perform proper macro scoping, the ENR now keeps track of the current scope (`current_scope` member) and resolves macros accordingly. This is done through the use of the `scoped` method, which creates a new scope, runs a specified lambda and then exits the scope. This prevents pushing/popping errors that we've seen happen already in similar contexts. We might think about generalizing it to other classes, providing a `Scoped<EntryFn, ExitFn>` class or similar gcc/rust/ChangeLog: * ast/rust-macro.cc: New file. * Make-lang.in: Add `rust-macro.o` object * ast/rust-ast-fragment.cc (Fragment::Fragment): Change API around the construction of AST fragments. (Fragment::operator=): Correct `Fragment::operator=` to take into account the fragment tokens. (Fragment::create_error): Use new constructor. (Fragment::complete): Remove in favor of new constructor. (Fragment::unexpanded): Remove as that Fragment type is no longer used or possible. (Fragment::get_tokens): Add helper to access a fragment's tokens. * ast/rust-ast-fragment.h (enum class): Remove `FragmentKind::Unused` * ast/rust-ast.cc (MacroInvocation::as_string): Display builtin macro invocations properly. * ast/rust-ast.h: Fix `DelimTokenTree` class copy constructors and handling of its token vector. * ast/rust-macro.h (class MacroMatcher): Format. (class MetaItemSeq): Likewise. (builtin_macro_from_string): Get a `BuiltinMacroKind` from a given string, i.e the name of the macro (`assert!`, `cfg!` and so on). * expand/rust-attribute-visitor.cc (AttrVisitor::visit): Do not expand macros recursively anymore. (AttrVisitor::maybe_expand_expr): Likewise. (AttrVisitor::maybe_expand_type): Likewise. * expand/rust-attribute-visitor.h: Likewise, and remove `expand_macro_fragment_recursively` function. * expand/rust-macro-builtins.cc (make_token): Add shorthand for returning `std::unique_ptr<AST::Token>`s. (make_macro_invocation): Add shorthand for returning fragments containing builtin macro invocations. (try_expand_macro_expression): Do not expand macros recursively. (try_expand_single_string_literal): Likewise. (try_expand_many_expr): Likewise. (parse_single_string_literal): Error out more appropriately. (MacroBuiltin::compile_error_handler): Add explanation for eager invocation (MacroBuiltin::file_handler): Return the proper tokens associated with macro invocation, and builtin macros in the case of necessary eager expansion. (MacroBuiltin::column_handler): Likewise. (MacroBuiltin::include_bytes_handler): Likewise. (MacroBuiltin::include_str_handler): Likewise. (MacroBuiltin::concat_handler): Likewise. (MacroBuiltin::env_handler): Likewise. (MacroBuiltin::cfg_handler): Likewise. (MacroBuiltin::include_handler): Likewise. (MacroBuiltin::line_handler): Likewise. * expand/rust-macro-expand.cc (MacroExpander::expand_eager_invocations): Add function to expand eager invocations *once* in the fixed point pipeline. (MacroExpander::expand_invoc): Call into `expand_eager_invocations` for builtin macro invocations. (MacroExpander::expand_crate): Use new `AttrVisitor` API. (parse_many): Return tokens in `AST::Fragment`. (transcribe_expression): Likewise. (transcribe_type): Likewise. * expand/rust-macro-expand.h (struct MacroExpander): Add `has_changed` flag for fixed point checking. * resolve/rust-early-name-resolver.cc (EarlyNameResolver::EarlyNameResolver): Keep track of the current macro scope. (EarlyNameResolver::go): Use `scoped` API. (EarlyNameResolver::visit): Likewise. * resolve/rust-early-name-resolver.h: Add `scoped` API. * rust-session-manager.cc (Session::expansion): Perform macro expansion in a fixed-point fashion. gcc/testsuite/ChangeLog: * rust/compile/macro17.rs: Fix testsuite for new recursion errors. * rust/compile/macro44.rs: Fix invalid testcase assertions. * rust/compile/builtin_macro_recurse.rs: Fix invalid test. * rust/compile/builtin_macro_recurse2.rs: New test. * rust/compile/macro46.rs: New test.
2023-04-06gccrs: Add support for TuplePattern in let statementsOwen Avery1-0/+4
gcc/rust/ChangeLog: * hir/tree/rust-hir-pattern.h (TuplePatternItemsRanged::get_lower_patterns): Add method. (TuplePatternItemsRanged::get_upper_patterns): Add method. * backend/rust-compile-pattern.cc (CompilePatternLet::visit): Implement TuplePattern visitor. * backend/rust-compile-pattern.h (CompilePatternLet::visit): Move TuplePattern visitor out of header file. gcc/testsuite/ChangeLog: * rust/execute/torture/let-pattern-1.rs: New test. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2023-04-06gccrs: Add general TypeBounds checksPhilip Herron5-6/+260
Existing tests are updated to use libcore copy and clone implementation. Addresses #1725 Signed-off-by: Philip Herron <herron.philip@googlemail.com> gcc/rust/ChangeLog: * typecheck/rust-unify.cc (UnifyRules::go): ensure the bounds are checked gcc/testsuite/ChangeLog: * rust/compile/torture/intrinsics-4.rs: implement Copy trait * rust/compile/torture/intrinsics-5.rs: likewise * rust/execute/torture/atomic_load.rs: likewise * rust/execute/torture/atomic_store.rs: likewise * rust/bounds1.rs: New test.
2023-04-06gccrs: Remove bad error message on checking function argumentsPhilip Herron1-1/+0
Signed-off-by: Philip Herron <herron.philip@googlemail.com> gcc/rust/ChangeLog: * typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): remove error message gcc/testsuite/ChangeLog: * rust/compile/func3.rs: update test case
2023-04-06gccrs: Add missing Sized, Copy and Clone lang item mappingsPhilip Herron1-0/+23
We need these lang items to be defined and later down the line the mappings will be used to implement proper copy and clone logic. Fixes #1786 Signed-off-by: Philip Herron <herron.philip@googlemail.com> gcc/rust/ChangeLog: * util/rust-lang-item.h: gcc/testsuite/ChangeLog: * rust/compile/issue-1786.rs: New test.
2023-04-06gccrs: Refactor the type unification codePhilip Herron1-2/+1
This refactors the unification systems to be a consistent interface using switch statements and simple functions instead of the old clunky visitor system. This is more maintainable as it is harder to miss cases when we can take advantages of switch statements. Signed-off-by: Philip Herron <herron.philip@googlemail.com> gcc/rust/ChangeLog: * Make-lang.in: update names * backend/rust-compile-expr.cc (CompileExpr::resolve_method_address): update to use new interface * typecheck/rust-coercion.cc (TypeCoercionRules::coerce_borrowed_pointer): likewise * typecheck/rust-hir-type-check-base.cc (TypeCheckBase::unify_site): likewise * typecheck/rust-tyty.cc (BaseType::destructure): likewise (InferType::unify): removed old unify interface (ErrorType::unify): likewise (ADTType::unify): likewise (TupleType::unify): likewise (FnType::unify): likewise (FnPtr::unify): likewise (ClosureType::unify): likewise (ArrayType::unify): likewise (SliceType::unify): likewise (BoolType::unify): likewise (IntType::unify): likewise (UintType::unify): likewise (FloatType::unify): likewise (USizeType::unify): likewise (ISizeType::unify): likewise (CharType::unify): likewise (ReferenceType::unify): likewise (PointerType::unify): likewise (ParamType::unify): likewise (StrType::unify): likewise (NeverType::unify): likewise (PlaceholderType::unify): likewise (ProjectionType::unify): likewise (DynamicObjectType::unify): likewise * typecheck/rust-tyty.h: update destructure interface * typecheck/rust-tyty-rules.h: Removed. * typecheck/rust-unify.cc: New file. * typecheck/rust-unify.h: New file. gcc/testsuite/ChangeLog: * rust/compile/never_type_err1.rs: Moved to... * rust/compile/never_type1.rs: ...here. It now works
2023-04-06gccrs: Remove monomorphization hack to setup possible associated typesPhilip Herron1-0/+20
During CallExpr argument type checking we may be calling a default implementation of a trait function this will require any possible associated types to be resolved and setup. This monomoprhization call does this but it will premtivly do extra unification of types which will throw off type checking later on. This fix is required for my work into type bounds checking. Fixes #1773 Signed-off-by: Philip Herron <herron.philip@googlemail.com> gcc/rust/ChangeLog: * typecheck/rust-hir-trait-reference.h: change interface to return self * typecheck/rust-hir-trait-resolve.cc: likewise * typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_segments): likewise * typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): remove monomorphization hack gcc/testsuite/ChangeLog: * rust/compile/issue-1773.rs: New test.
2023-04-06gccrs: Add another test case for passing associated type-boundsPhilip Herron1-0/+30
This demonstrates that this also works for custom algebraic data types too. gcc/testsuite/ChangeLog: * rust/execute/torture/issue-1720-2.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2023-04-06gccrs: Add support for feature check.mxlol2331-0/+4
This commit implements a very basic feature checking module. gcc/rust/ChangeLog: * Make-lang.in: Add object files: `rust-feature.o` and `rust-feature-gate.o` * checks/errors/rust-feature-gate.cc: New file. * checks/errors/rust-feature-gate.h: New file. * checks/errors/rust-feature.cc: New file. * checks/errors/rust-feature.h: New file. * rust-session-manager.cc: Add FeatureGate check. gcc/testsuite/ChangeLog: * rust/compile/feature.rs: New test. Signed-off-by: Xiao Ma <mxlol233@outlook.com>
2023-04-06gccrs: parser: Fix parsing of closure param listArthur Cohen1-0/+9
gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_closure_expr): Advance tokens properly when parsing closure param list. gcc/testsuite/ChangeLog: * rust/compile/closure_move_expr.rs: New test.
2023-04-06gccrs: parser: Improve parsing of complex generic argumentsArthur Cohen2-0/+27
The parser was missing code for handling complex type arguments such as type paths or nested generics. gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_generic_arg): Handle type paths and nested generics properly. gcc/testsuite/ChangeLog: * rust/compile/parse_complex_generic_application.rs: New test. * rust/compile/parse_complex_generic_application2.rs: New test.
2023-04-06gccrs: parser: Allow parsing multiple reference typesArthur Cohen1-0/+12
The parser now recursively tries to parse a reference type after seeing a `&` or `&&` token. gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_type): Handle double ampersan properly (Parser::parse_reference_type): Call into `parse_reference_type_inner` and wrap double reference types in another `AST::ReferenceType` node (Parser::parse_reference_type_inner): Add parsing implementation which does not care about the leading token (& or &&) (Parser::parse_type_no_bounds): Handle double ampersand properly * parse/rust-parse.h: Declare `parse_reference_type_inner` gcc/testsuite/ChangeLog: * rust/compile/multi_reference_type.rs: New test.
2023-04-06gccrs: fixed compiler error message on wildcard pattern within expressionAbdul Rafey1-0/+8
gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::null_denotation): Add proper error when seeing wildcard var on right side of assignment. gcc/testsuite/ChangeLog: * rust/compile/issue-867.rs: New test. Signed-off-by: Abdul Rafey <abdulrafeyq@gmail.com>
2023-04-06gccrs: Do not crash on empty macros expand. Fixes #1712Lyra1-0/+7
This commit fixes a compiler crash when expanding an empty macro into an existing AST. gcc/rust/ChangeLog: * expand/rust-macro-expand.cc (transcribe_expression): Fix ICE when expanding empty macros. gcc/testsuite/ChangeLog: * rust/compile/macro45.rs: New test. Signed-off-by: Lyra Karenai <teromene@teromene.fr>
2023-04-06gccrs: testsuite: Handle Windows carriage returns properlyArthur Cohen87-109/+104
In dg-output, check for \r* carriage returns to make sure execution tests pass on windows platforms gcc/testsuite/ChangeLog: * rust/execute/torture/builtin_macro_cfg.rs: Handle carriage returns properly. * rust/execute/torture/builtin_macro_concat.rs: Likewise. * rust/execute/torture/builtin_macro_env.rs: Likewise. * rust/execute/torture/builtin_macro_include_bytes.rs: Likewise. * rust/execute/torture/builtin_macro_include_str.rs: Likewise. * rust/execute/torture/builtin_macro_line.rs: Likewise. * rust/execute/torture/builtin_macros1.rs: Likewise. * rust/execute/torture/builtin_macros3.rs: Likewise. * rust/execute/torture/cfg1.rs: Likewise. * rust/execute/torture/cfg2.rs: Likewise. * rust/execute/torture/cfg3.rs: Likewise. * rust/execute/torture/cfg4.rs: Likewise. * rust/execute/torture/coercion1.rs: Likewise. * rust/execute/torture/coercion2.rs: Likewise. * rust/execute/torture/extern_mod4.rs: Likewise. * rust/execute/torture/helloworld1.rs: Likewise. * rust/execute/torture/helloworld2.rs: Likewise. * rust/execute/torture/issue-1198.rs: Likewise. * rust/execute/torture/issue-1231.rs: Likewise. * rust/execute/torture/issue-1232.rs: Likewise. * rust/execute/torture/issue-1249.rs: Likewise. * rust/execute/torture/issue-1436.rs: Likewise. * rust/execute/torture/issue-1496.rs: Likewise. * rust/execute/torture/issue-647.rs: Likewise. * rust/execute/torture/issue-845.rs: Likewise. * rust/execute/torture/issue-851.rs: Likewise. * rust/execute/torture/issue-858.rs: Likewise. * rust/execute/torture/issue-976.rs: Likewise. * rust/execute/torture/macros10.rs: Likewise. * rust/execute/torture/macros11.rs: Likewise. * rust/execute/torture/macros12.rs: Likewise. * rust/execute/torture/macros13.rs: Likewise. * rust/execute/torture/macros14.rs: Likewise. * rust/execute/torture/macros2.rs: Likewise. * rust/execute/torture/macros22.rs: Likewise. * rust/execute/torture/macros29.rs: Likewise. * rust/execute/torture/macros3.rs: Likewise. * rust/execute/torture/macros30.rs: Likewise. * rust/execute/torture/macros31.rs: Likewise. * rust/execute/torture/macros7.rs: Likewise. * rust/execute/torture/macros8.rs: Likewise. * rust/execute/torture/macros9.rs: Likewise. * rust/execute/torture/match1.rs: Likewise. * rust/execute/torture/match2.rs: Likewise. * rust/execute/torture/match3.rs: Likewise. * rust/execute/torture/match_bool1.rs: Likewise. * rust/execute/torture/match_byte1.rs: Likewise. * rust/execute/torture/match_char1.rs: Likewise. * rust/execute/torture/match_int1.rs: Likewise. * rust/execute/torture/match_loop1.rs: Likewise. * rust/execute/torture/match_range1.rs: Likewise. * rust/execute/torture/match_range2.rs: Likewise. * rust/execute/torture/match_tuple1.rs: Likewise. * rust/execute/torture/method1.rs: Likewise. * rust/execute/torture/method2.rs: Likewise. * rust/execute/torture/method3.rs: Likewise. * rust/execute/torture/method4.rs: Likewise. * rust/execute/torture/operator_overload_1.rs: Likewise. * rust/execute/torture/operator_overload_10.rs: Likewise. * rust/execute/torture/operator_overload_11.rs: Likewise. * rust/execute/torture/operator_overload_12.rs: Likewise. * rust/execute/torture/operator_overload_2.rs: Likewise. * rust/execute/torture/operator_overload_4.rs: Likewise. * rust/execute/torture/operator_overload_5.rs: Likewise. * rust/execute/torture/operator_overload_6.rs: Likewise. * rust/execute/torture/operator_overload_7.rs: Likewise. * rust/execute/torture/operator_overload_8.rs: Likewise. * rust/execute/torture/operator_overload_9.rs: Likewise. * rust/execute/torture/str-layout1.rs: Likewise. * rust/execute/torture/str-zero.rs: Likewise. * rust/execute/torture/trait1.rs: Likewise. * rust/execute/torture/trait10.rs: Likewise. * rust/execute/torture/trait11.rs: Likewise. * rust/execute/torture/trait12.rs: Likewise. * rust/execute/torture/trait13.rs: Likewise. * rust/execute/torture/trait2.rs: Likewise. * rust/execute/torture/trait3.rs: Likewise. * rust/execute/torture/trait4.rs: Likewise. * rust/execute/torture/trait5.rs: Likewise. * rust/execute/torture/trait6.rs: Likewise. * rust/execute/torture/trait7.rs: Likewise. * rust/execute/torture/trait8.rs: Likewise. * rust/execute/torture/trait9.rs: Likewise. * rust/execute/torture/closure2.rs: Likewise. * rust/execute/torture/closure3.rs: Likewise. * rust/execute/torture/loop-condition-eval.rs: Likewise. * rust/execute/torture/operator_overload_3.rs: Likewise.
2023-04-06gccrs: diagnostics: Add underline for tokens in diagnostics.mxlol2331-0/+15
Currently, the diagnostics only point to the corresponding token's start position by carets, and lack of underlines for full token. This commit add support for such underlines in diagnostics by encoding range information in location_t. gcc/rust/ChangeLog: * lex/rust-lex.cc (Lexer::build_token): Make location enclose entire token. (Lexer::parse_byte_char): Likewise. (Lexer::parse_byte_string): Likewise. (Lexer::parse_raw_byte_string): Likewise. (Lexer::parse_raw_identifier): Likewise. (Lexer::parse_string): Likewise. (Lexer::parse_identifier_or_keyword): Likewise. (Lexer::parse_raw_string): Likewise. (Lexer::parse_non_decimal_int_literal): Likewise. (Lexer::parse_decimal_int_or_float): Likewise. (Lexer::parse_char_or_lifetime): Likewise. gcc/testsuite/ChangeLog: * rust/compile/diagnostic_underline.rs: New test. Signed-off-by: Xiao Ma <mxlol233@outlook.com>
2023-04-06gccrs: Support associated type bound argumentsPhilip Herron2-3/+31
This patch adds support for the GenercArgsBinding type, where you can specify the associated types of a trait bound using `<Foo=i32>` style syntax. Note that the type-resolution relys on the i32 impl for Add as type resolution will resolve the `a+a` to the core::ops::Add method so code generation will require this to exist. I have ameded testsuite/rust/compile/bounds.rs as this code is wrongly creating an HIR::GenericArgs with a trait-object type and causing issues. the parsing is still correct but we dont have the mechanism to represent this in AST and HIR properly. I think we will need a new HIR::GenericArgs AssociatedTypeBindingBound or something similar. We are still lacking bounds checking during are type coercions and unifications so running this example using an f32 will wrongly pass type checking, this will need addressed next. Fixes #1720 gcc/rust/ChangeLog: * hir/tree/rust-hir-path.h: Add const get_identifier and get_type method. * typecheck/rust-hir-path-probe.h: Use new SubstitutionArgumentMappings constructor. * typecheck/rust-hir-trait-resolve.cc: Likewise. * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise. * typecheck/rust-tyty-bounds.cc (TypeCheckBase::get_predicate_from_bound): Do not assert failure on size mismatch anymore. (TypeBoundPredicate::TypeBoundPredicate): Use new SubstitutionArgumentMappings constructor. (TypeBoundPredicate::operator=): Likewise. (TypeBoundPredicate::apply_generic_arguments): Likewise. (TypeBoundPredicateItem::get_tyty_for_receiver): Likewise. (TypeBoundPredicate::get_num_associated_bindings): Likewise. (TypeBoundPredicate::lookup_associated_type): Fix implementation for new system. (TypeBoundPredicate::get_associated_type_items): Likewise. * typecheck/rust-tyty.cc (SubstitutionRef::get_mappings_from_generic_args): Add new behavior. (SubstitutionRef::infer_substitions): Use new constructor and add comment. (SubstitutionRef::solve_missing_mappings_from_this): Use new constructor. * typecheck/rust-tyty.h: Define new constructors. gcc/testsuite/ChangeLog: * rust/compile/bounds.rs: change to use -fsyntax-only * rust/execute/torture/issue-1720.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2023-04-06gccrs: Implement declarative macro 2.0 parserRaiki Tamura11-0/+73
gcc/rust/ChangeLog: * ast/rust-ast-full-decls.h (class MacroItem): Remove forward declaration. * ast/rust-ast-full-test.cc (MacroRulesDefinition): Rework MacroRulesDefinition class * ast/rust-ast.h (class MacroItem): Remove abstract class. * ast/rust-item.h (class MacroItem): Remove forward declaration. * ast/rust-macro.h (class MacroItem): Likewise. (class MacroRulesDefinition): Add MacroKind enum. (class MacroInvocation): Fix inheritance. * lex/rust-token.h: Token "macro" is now used. * parse/rust-parse-impl.h (Parser::parse_item): Add handling for MACRO. (Parser::parse_vis_item): Call into parse_decl_macro_def. (Parser::parse_macro_item): Delete function. (Parser::parse_macro_rules_def): Return MBE macros only. (Parser::parse_decl_macro_def): New function. (Parser::parse_stmt): Handle MACRO token. (Parser::parse_stmt_or_expr_without_block): Call into parse_macro_rules_def. * parse/rust-parse.h: Declare new function. gcc/testsuite/ChangeLog: * rust/compile/decl_macro1.rs: New test. * rust/compile/decl_macro2.rs: New test. * rust/compile/decl_macro3.rs: New test. * rust/compile/decl_macro4.rs: New test. * rust/compile/decl_macro5.rs: New test. * rust/compile/decl_macro6.rs: New test. * rust/compile/decl_macro7.rs: New test. * rust/execute/torture/decl_macro1.rs: New test. * rust/execute/torture/decl_macro2.rs: New test. * rust/execute/torture/decl_macro3.rs: New test. * rust/execute/torture/decl_macro4.rs: New test. Signed-off-by: Raiki Tamura <tamaron1203@gmail.com>
2023-04-06gccrs: rust: add bound parsing in parse_generic_arg.mxlol2331-0/+10
gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_generic_arg): Add proper bound parsing. gcc/testsuite/ChangeLog: * rust/compile/bounds.rs: New test. Signed-off-by: Xiao Ma <mxlol233@outlook.com>
2023-04-06gccrs: Check for mutable references in const functionsDave1-0/+3
Use StackedContext instead. Fix error string Signed-off-by: Dave Evans <dave@dmetwo.org> (Squashed commits) Check for mutable references in const functions using StackedContext gcc/rust/ChangeLog: * checks/errors/rust-const-checker.cc (ConstChecker::visit): Use StackedContext class. gcc/testsuite/ChangeLog: * rust/compile/const10.rs: New test. Signed-off-by: Dave Evans <dave@dmetwo.org>
2023-04-06gccrs: unsafe: check use of `target_feature` attributePrajwal S N1-0/+8
The `target_feature` attribute is for conditional compilation and may or may not compile on all platforms. Using it requires an unsafe function or block. gcc/rust/ChangeLog: * checks/errors/rust-unsafe-checker.cc (check_target_attr): New function. (UnsafeChecker::check_function_attr): Call into `check_target_attr`. (UnsafeChecker::visit): Check for target_feature attributes. * checks/errors/rust-unsafe-checker.h: Add declarations. * util/rust-attributes.cc: Add attribute. gcc/testsuite/ChangeLog: * rust/compile/unsafe11.rs: New test. Signed-off-by: Prajwal S N <prajwalnadig21@gmail.com>
2023-02-21gccrs: add math intrinsicsRaiki Tamura1-0/+173
gcc/rust/ChangeLog: * backend/rust-builtins.cc (BuiltinsContext::setup_math_fns): New functions. gcc/testsuite/ChangeLog: * rust/compile/torture/intrinsics-math.rs: New test.
2023-02-21gccrs: Skip this debug test case which is failing on the latest mac-os ↵Philip Herron1-7/+8
devtools and its only for debug info gcc/testsuite/ChangeLog: * rust/debug/chartype.rs: Skip testcases on Darwin architectures.
2023-02-21gccrs: Add initial support for argument capture of closuresPhilip Herron1-0/+33
When we have a closure expression that captures a parent function's variable we must setup the closure data to contain this. Ignoring moveability and mutability requires for now, this patch creates the closure structure with fields for each of the captured variables. When it comes to compilation of the closure expression in order to support nested closures we must setup a context of implicit mappings so that for all path resolution we hit this implicit closure mappings lookups code before any lookup_var_decl as this decl will not exist so the order here is important during path resolution which is a similar problem to match expression destructuring. Fixes #195 gcc/rust/ChangeLog: * backend/rust-compile-context.cc (Context::push_closure_context): New function. (Context::pop_closure_context): Likewise. (Context::insert_closure_binding): Likewise. (Context::lookup_closure_binding): Likewise. * backend/rust-compile-context.h: Declare new functions and closure mappings. * backend/rust-compile-expr.cc (CompileExpr::visit): Visit captures properly. (CompileExpr::generate_closure_function): Compile captures properly. * backend/rust-compile-resolve-path.cc (ResolvePathRef::resolve): Check for closure bindings. * backend/rust-compile-type.cc (TyTyResolveCompile::visit): Compile capture list's types as well. gcc/testsuite/ChangeLog: * rust/execute/torture/closure3.rs: New test.
2023-02-21gccrs: add lang item "phantom_data"Raiki Tamura1-0/+11
gcc/rust/ChangeLog: * util/rust-lang-item.h: Add handling for `phantom_data` lang item. gcc/testsuite/ChangeLog: * rust/compile/torture/phantom_data.rs: New test.
2023-02-21gccrs: intrinsics: Implement atomic_load intrinsicsArthur Cohen2-2/+31
gcc/rust/ChangeLog: * backend/rust-builtins.cc (BuiltinsContext::setup_atomic_fns): Declare atomic load intrinsics. * backend/rust-compile-intrinsic.cc (atomic_load_handler_inner): New handler. (atomic_load_handler): Likewise. (unchecked_op_handler): Remove `static` function qualifier. (build_atomic_builtin_name): Handle load intrinsics. (atomic_store_handler_inner): New handler. gcc/testsuite/ChangeLog: * rust/compile/torture/intrinsics-3.rs: * rust/execute/torture/atomic_load.rs: New test.
2023-02-21gccrs: intrinsics: Cleanup error handling around atomic_store_*Arthur Cohen1-2/+2
gcc/rust/ChangeLog: * backend/rust-compile-intrinsic.cc (check_for_basic_integer_type): New function. (build_atomic_builtin_name): Use HIR Type instead of `tree`. (atomic_store_handler_inner): Cleanup error handling. (unchecked_op_inner): Likewise. gcc/testsuite/ChangeLog: * rust/compile/torture/intrinsics-5.rs: Fix error message.
2023-02-21gccrs: intrinsics: Add unchecked operation intrinsicsArthur Cohen2-0/+31
gcc/rust/ChangeLog: * backend/rust-compile-intrinsic.cc (is_basic_integer_type): New function. (unchecked_op_inner): New handler. (unchecked_op_handler): New handler. gcc/testsuite/ChangeLog: * rust/compile/torture/intrinsics-6.rs: New test. * rust/compile/torture/intrinsics-7.rs: New test.
2023-02-21gccrs: intrinsics: Add early implementation for atomic_store_{seqcst, ↵Arthur Cohen3-0/+87
relaxed, release} gcc/rust/ChangeLog: * backend/rust-builtins.cc (BuiltinsContext::setup_atomic_fns): New function. (BuiltinsContext::setup): Call `setup_atomic_fns`. * backend/rust-builtins.h: Declare `setup_atomic_fns`. * backend/rust-compile-intrinsic.cc (atomic_store_handler_inner): New function. (atomic_store_handler): New handler. (make_unsigned_long_tree): Add helper around making unsigned long trees. (prefetch_data_handler): Use `make_unsigned_long_tree`. (build_atomic_builtin_name): New function. gcc/testsuite/ChangeLog: * rust/compile/torture/intrinsics-4.rs: New test. * rust/compile/torture/intrinsics-5.rs: New test. * rust/execute/torture/atomic_store.rs: New test.
2023-02-21gccrs: intrinsics: Add `sorry_handler` intrinsic handlerArthur Cohen1-0/+9
gcc/rust/ChangeLog: * backend/rust-compile-intrinsic.cc (sorry_handler): New intrinsic handler. gcc/testsuite/ChangeLog: * rust/compile/torture/intrinsics-3.rs: New test.
2023-02-21gccrs: Support Closure calls as generic trait boundsPhilip Herron1-0/+32
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-21gccrs: Closure support at CallExprPhilip Herron1-0/+18
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-21gccrs: Add check for recursive trait cyclesPhilip Herron1-0/+5
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-21gccrs: Method resolution must support multiple candidatesPhilip Herron2-3/+5
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-21gccrs: fix ICE on missing closing parenMarc Poulhiès1-0/+3
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-21gccrs: intrinsics: Add data prefetching intrinsicsArthur Cohen1-0/+17
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-21gccrs: Support looking up super traits for trait itemsPhilip Herron1-0/+48
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-21gccrs: testing: try loop in const functionFaisal Abbas1-0/+18
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>