]>
git.ipfire.org Git - thirdparty/gcc.git/log
Philip Herron [Sat, 3 Feb 2024 16:32:13 +0000 (16:32 +0000)]
gccrs: Fix ICE accessing empty vector without check
Fixes #2747
gcc/rust/ChangeLog:
* typecheck/rust-tyty-subst.cc (SubstitutionRef::get_mappings_from_generic_args): fix
gcc/testsuite/ChangeLog:
* rust/compile/issue-2747.rs: New test.
Philip Herron [Sat, 3 Feb 2024 16:02:36 +0000 (16:02 +0000)]
gccrs: add test cases to prove type inference is working
Fixes #2772
gcc/testsuite/ChangeLog:
* rust/compile/issue-2772-1.rs: New test.
* rust/compile/issue-2772-2.rs: New test.
Philip Herron [Sat, 3 Feb 2024 15:43:59 +0000 (15:43 +0000)]
gccrs: add testcase to prove issue has already been fixed
Fixes #1483
gcc/testsuite/ChangeLog:
* rust/compile/issue-1483.rs: New test.
Nobel Singh [Fri, 19 Jan 2024 15:06:34 +0000 (20:51 +0545)]
Set the default ABI to C for extern blocks and extern functions
Previously, the default ABI was set to Rust, which is not correct for
extern blocks and extern functions. This patch changes the default
ABI to C for these cases.
gcc/rust/ChangeLog:
* hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_qualifiers):
Change default ABI to C for extern functions
(ASTLoweringBase::lower_extern_block): Likewise
Signed-off-by: Nobel Singh <nobel2073@gmail.com>
Jakub Dupak [Tue, 23 Jan 2024 13:50:57 +0000 (14:50 +0100)]
TyTy: Store reference to type before any substitutions
gcc/rust/ChangeLog:
* typecheck/rust-tyty.cc (BaseType::BaseType): Store orig ref.
(BaseType::get_orig_ref): Add getter.
* typecheck/rust-tyty.h: Store orig ref.
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Jakub Dupak [Tue, 23 Jan 2024 13:20:42 +0000 (14:20 +0100)]
TyTy: Store region constraints
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-implitem.cc (TypeCheckTopLevelExternItem::visit):
Add region constraints.
(TypeCheckImplItem::visit): Add region constraints.
* typecheck/rust-hir-type-check-implitem.h: Add region constraints.
* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::ResolveImplBlockSelf):
Add region constraints.
(TypeCheckItem::visit): Add region constraints.
(TypeCheckItem::resolve_impl_item): Add region constraints.
(TypeCheckItem::resolve_impl_block_substitutions): Add region constraints.
* typecheck/rust-hir-type-check-item.h: Add region constraints.
* typecheck/rust-hir-type-check-type.cc (ResolveWhereClauseItem::Resolve):
Add region constraints.
(ResolveWhereClauseItem::visit): Add region constraints.
* typecheck/rust-hir-type-check-type.h (class ResolveWhereClauseItem):
Add region constraints.
* typecheck/rust-hir-type-check.cc (TraitItemReference::get_type_from_fn):
Add region constraints.
* typecheck/rust-tyty-bounds.cc (TypeBoundPredicate::TypeBoundPredicate):
Add region constraints.
* typecheck/rust-tyty-subst.cc (SubstitutionRef::get_region_constraints):
Add region constraints.
* typecheck/rust-tyty-subst.h (class BaseType): Add region constraints.
(struct RegionConstraints): Add region constraints.
* typecheck/rust-tyty.cc (BaseType::monomorphized_clone): Add region constraints.
(ADTType::clone): Add region constraints.
(FnType::clone): Add region constraints.
(ProjectionType::clone): Add region constraints.
* typecheck/rust-tyty.h: Add region constraints.
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Jakub Dupak [Wed, 10 Jan 2024 13:48:22 +0000 (14:48 +0100)]
Typecheck: add regions (lifetimes) to TyTy
gcc/rust/ChangeLog:
* typecheck/rust-hir-trait-resolve.cc: add regions
* typecheck/rust-hir-type-check-base.cc (TypeCheckBase::resolve_literal):
add regions, resolve generic lifetimes
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): add regions
* typecheck/rust-hir-type-check-implitem.cc (TypeCheckTopLevelExternItem::visit):
add regions, resolve lifetimes
(TypeCheckImplItem::visit): add regions, resove lifetimes
* typecheck/rust-hir-type-check-implitem.h: add default value for result
* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): add regions,
resove lifetimes
(TypeCheckItem::resolve_impl_block_substitutions): add regions, resove lifetimes
* typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::visit): add regions,
resove lifetimes
(TypeCheckExpr::resolve_root_path): add regions, resove lifetimes
(TypeCheckExpr::resolve_segments): add regions, resove lifetimes
* typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit): add regions,
resove lifetimes
(TypeCheckType::resolve_root_path): add regions, resove lifetimes
(ResolveWhereClauseItem::Resolve): add regions, resove lifetimes
(ResolveWhereClauseItem::visit): add regions, resove lifetimes
* typecheck/rust-hir-type-check.cc (TypeCheckContext::LifetimeResolver::resolve):
add regions, resolve lifetimes
(TraitItemReference::get_type_from_fn): add regions, resove lifetimes
* typecheck/rust-hir-type-check.h: add regions, resove lifetimes
* typecheck/rust-substitution-mapper.cc (SubstMapper::SubstMapper): add regions,
resove lifetimes
(SubstMapper::Resolve): add regions, resove lifetimes
(SubstMapper::InferSubst): add regions, resove lifetimes
(SubstMapper::visit): add regions, resove lifetimes
* typecheck/rust-substitution-mapper.h: add regions, resove lifetimes
* typecheck/rust-typecheck-context.cc (TypeCheckContext::TypeCheckContext):
lifetime resolution
(TypeCheckContext::regions_from_generic_args): lifetime resolution helper
* typecheck/rust-tyty-bounds.cc (TypeBoundPredicate::TypeBoundPredicate):
add regions, resove lifetimes
(TypeBoundPredicate::operator=): add regions, resove lifetimes
(TypeBoundPredicate::apply_generic_arguments): add regions, resove lifetimes
(TypeBoundPredicateItem::get_tyty_for_receiver): add regions, resove lifetimes
* typecheck/rust-tyty-subst.cc (SubstitutionArgumentMappings::get_regions):
add regions, resove lifetimes
(SubstitutionArgumentMappings::get_mut_regions): getter
(SubstitutionArgumentMappings::error): split error and empty
(SubstitutionArgumentMappings::empty): split error and empty
(SubstitutionArgumentMappings::find_symbol): helper
(SubstitutionRef::get_num_lifetime_params): getter
(SubstitutionRef::get_num_type_params): getter
(SubstitutionRef::needs_substitution): extend to regions
(SubstitutionRef::get_mappings_from_generic_args): helper
(SubstitutionRef::infer_substitions): add regions
* typecheck/rust-tyty-subst.h (class RegionParamList): region param handler
* typecheck/rust-tyty.cc (BaseType::monomorphized_clone): add regions, resove lifetimes
(InferType::default_type): add regions, resove lifetimes
(FnType::clone): add regions, resove lifetimes
(ReferenceType::ReferenceType): add regions
(ReferenceType::get_region): getter
(ReferenceType::clone): add regions
* typecheck/rust-tyty.h: add regions, resove
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Jakub Dupak [Tue, 23 Jan 2024 12:55:20 +0000 (13:55 +0100)]
HIR: Add mising getter
gcc/rust/ChangeLog:
* hir/tree/rust-hir-item.h: Add missing getter
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Jakub Dupak [Tue, 23 Jan 2024 11:29:25 +0000 (12:29 +0100)]
TyTy: Region (lifetime) representation
gcc/rust/ChangeLog:
* typecheck/rust-tyty-region.h: New file.
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Jakub Dupak [Wed, 10 Jan 2024 12:12:48 +0000 (13:12 +0100)]
Typecheck: lifetime interning and resolution tool
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check.h (class Lifetime): add interned lifetime class
* typecheck/rust-typecheck-context.cc (TypeCheckContext::TypeCheckContext): add
resolution tool
(TypeCheckContext::intern_lifetime): add method to intern lifetime from tyctx
(TypeCheckContext::lookup_lifetime): add method to lookup lifetime from tyctx
(TypeCheckContext::intern_and_insert_lifetime): add a helper method
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Raiki Tamura [Sat, 2 Dec 2023 12:01:59 +0000 (21:01 +0900)]
gccrs: Implement quick-check for Unicode
gcc/rust/ChangeLog:
* rust-lang.cc (run_rust_tests): Add test.
* rust-system.h: Add <algorithm>.
* util/make-rust-unicode.py: Output NFC_Quick_Check table.
* util/rust-codepoint.h (struct Codepoint): Add is_supplementary
method.
* util/rust-unicode-data.h: Generated.
* util/rust-unicode.cc (binary_search_sorted_array): Removed.
(lookup_cc): Remove namespace.
(is_alphabetic): Use std::binary_search
(nfc_quick_check): New function.
(nfc_normalize): Use nfc_quick_check.
(is_nfc_qc_maybe): New function.
(is_nfc_qc_no): New function.
(rust_nfc_qc_test): New test.
* util/rust-unicode.h (is_nfc_qc_no): New function.
(is_nfc_qc_maybe): New function.
(enum class): New enum class.
(nfc_quick_check): New function.
(rust_nfc_qc_test): New test.
Signed-off-by: Raiki Tamura <tamaron1203@gmail.com>
Kushal Pal [Tue, 23 Jan 2024 11:53:05 +0000 (17:23 +0530)]
Parse normal functions with `self` parameter correctly
Fixes #2812
gcc/rust/ChangeLog:
* parse/rust-parse-impl.h (Parser::parse_function):
Skip token if its a COMMA.
gcc/testsuite/ChangeLog:
* rust/compile/issue-2812.rs: New test.
Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
Arthur Cohen [Mon, 22 Jan 2024 13:04:11 +0000 (14:04 +0100)]
gccrs: Fix output line ending patterns.
gcc/testsuite/ChangeLog:
* rust/execute/torture/builtin_macros1.rs: Fix output pattern.
* rust/execute/torture/coercion3.rs: Likewise.
* rust/execute/torture/issue-2080.rs: Likewise.
* rust/execute/torture/issue-2179.rs: Likewise.
* rust/execute/torture/issue-2180.rs: Likewise.
* rust/execute/torture/iter1.rs: Likewise.
Owen Avery [Wed, 20 Dec 2023 08:04:36 +0000 (03:04 -0500)]
Remove TraitImplItem
gcc/rust/ChangeLog:
* ast/rust-ast-full-decls.h
(class TraitImplItem): Remove forward declaration.
(class AssociatedItem): Add forward declaration.
* ast/rust-ast.h
(class TraitImplItem): Remove.
(class TraitItem): Inherit from AssociatedItem.
(SingleASTNode::take_trait_impl_item):
Return std::unique_ptr<AssociatedItem> instead of
std::unique_ptr<TraitImplItem>.
* ast/rust-item.h
(class Function): Inherit from AssociatedItem instead of
TraitImplItem.
(class TypeAlias): Likewise.
(class ConstantItem): Likewise.
(class TraitImpl): Store items as AssociatedItem.
* expand/rust-derive-clone.cc
(DeriveClone::clone_fn): Return std::unique_ptr<AssociatedItem>.
(DeriveClone::clone_impl): Take std::unique_ptr<AssociatedItem>.
* expand/rust-derive-clone.h
(DeriveClone::clone_fn): Return std::unique_ptr<AssociatedItem>.
(DeriveClone::clone_impl): Take std::unique_ptr<AssociatedItem>.
* expand/rust-expand-visitor.cc
(ExpandVisitor::visit): Handle changes to
SingleASTNode::take_trait_impl_item.
* parse/rust-parse-impl.h
(Parser::parse_impl): Parse TraitImpl as containing AssociatedItem.
(Parser::parse_trait_impl_item): Return
std::unique_ptr<AssociatedItem>.
(Parser::parse_trait_impl_function_or_method): Likewise.
* parse/rust-parse.h
(Parser::parse_trait_impl_item): Return
std::unique_ptr<AssociatedItem>.
(Parser::parse_trait_impl_function_or_method): Likewise.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Robert Goss [Sun, 14 Jan 2024 17:34:22 +0000 (17:34 +0000)]
Add improved error when no fields in initializer
If a struct type with a variant that has fields is initialized with some fields the expression HIR StructExprStructFields is checked that all the fields are assigned. However, if no fields are initialized the HIR StructExprStruct is generated. This doesn't check if the struct is a unit during typechekc and only fails at the compile stage with a ICE.
Add a check at the typecheck stage that makes sure the struct does not have a variant with fields and give an error message based on the rustc one.
We have also updated the message given in the case where one field was present to list the missing fields and match more closely the new message.
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit) Add additional check
* typecheck/rust-hir-type-check-struct-field.h: A helper method to make error added
* typecheck/rust-hir-type-check-struct.cc (TypeCheckStructExpr::resolve) Update message
gcc/testsuite/ChangeLog:
* rust/compile/missing_constructor_fields.rs: Added case with no initializers
Signed-off-by: Robert Goss <goss.robert@gmail.com>
Jakub Dupak [Thu, 18 Jan 2024 13:37:58 +0000 (14:37 +0100)]
Test: check implemented for lifetime handling
gcc/testsuite/ChangeLog:
* rust/compile/for_lifetimes.rs: New test.
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Jakub Dupak [Tue, 9 Jan 2024 14:46:41 +0000 (15:46 +0100)]
AST: Fix for lifetime lowering
gcc/rust/ChangeLog:
* hir/rust-ast-lower-type.cc (ASTLoweringTypeBounds::visit): fix for lifetimes
(ASTLowerWhereClauseItem::visit): fix for lifetimes
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Jakub Dupak [Tue, 9 Jan 2024 14:45:12 +0000 (15:45 +0100)]
AST: Fix for lifetime parsing
gcc/rust/ChangeLog:
* parse/rust-parse-impl.h (Parser::parse_where_clause): fix parsing
(Parser::parse_where_clause_item): fix parsing
(Parser::parse_type_bound_where_clause_item): fix parsing
(Parser::parse_trait_bound): fix parsing
* parse/rust-parse.h: fix parsing
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Jakub Dupak [Tue, 9 Jan 2024 14:43:01 +0000 (15:43 +0100)]
Test: fix missing lifetime in a test
This test did not compile with rustc.
gcc/testsuite/ChangeLog:
* rust/compile/torture/utf8_identifiers.rs: add mising lifetime
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Kushal Pal [Sat, 30 Dec 2023 04:10:19 +0000 (09:40 +0530)]
Added newline to get more readable lexdump
Fixes #2783
gcc/rust/ChangeLog:
* lex/rust-lex.cc (Lexer::dump_and_skip):
Changed " " to '\n'
Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
Owen Avery [Wed, 20 Dec 2023 07:30:20 +0000 (02:30 -0500)]
Unify storage of associated items in SingleASTNode
gcc/rust/ChangeLog:
* ast/rust-ast-fragment.cc
(Fragment::assert_single_fragment): Update.
* ast/rust-ast.h
(class TraitImplItem): Move definition before that of TraitItem.
(class TraitItem):
Inherit from TraitImplItem instead of AssociatedItem.
(class SingleASTNode): Unify handling of associated items.
(SingleASTNode::take_assoc_item): Move from...
(SingleASTNode::take_impl_item): ...here, but leave stub calling
take_assoc_item behind.
(SingleASTNode::take_trait_item):
Cast associated item to TraitItem.
(SingleASTNode::take_trait_impl_item):
Cast associated item to TraitImplItem.
* ast/rust-ast.cc
(SingleASTNode::SingleASTNode):
Unify handling of associated items.
(SingleASTNode::operator=): Likewise.
(SingleASTNode::accept_vis): Likewise.
(SingleASTNode::is_error): Likewise.
(SingleASTNode::as_string): Likewise.
* ast/rust-item.h
(class Function): Remove direct inheritence from AssociatedItem.
(class ConstantItem): Likewise.
* ast/rust-macro.h
(class MacroInvocation):
Remove direct inheritence from AssociatedItem and TraitImplItem.
Robert Goss [Tue, 16 Jan 2024 22:50:51 +0000 (22:50 +0000)]
Add improved error when a field is redefined in a struct constructor
Fixes #2381
If a struct type is initialized with one of it's fields repeated it will currently issue an error at the use site. However we would like to give the rust error code and (like rustc) show both the specifications for the field to help the user diagnose the issue.
We move the check after the index for the field has been established so we can look up if the field has already been defined and get it's location.
We update the visit method to return if it has handled an error otherwise we then output a second fatal error as not all the field in the specification have been processed.
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-struct-field.h: Allow visit to return a bool
* typecheck/rust-hir-type-check-struct.cc: Improve check of repeat fields
gcc/testsuite/ChangeLog:
* rust/compile/repeated_constructor_fields.rs: Added case with constructor field repeated
Signed-off-by: Robert Goss <goss.robert@gmail.com>
Arthur Cohen [Wed, 17 Jan 2024 13:15:27 +0000 (14:15 +0100)]
rust_debug: Cast size_t values to unsigned long before printing.
Using %lu to format size_t values breaks 32 bit targets, and %zu is not
supported by one of the hosts GCC aims to support - HPUX
gcc/rust/ChangeLog:
* backend/rust-compile-base.cc (HIRCompileBase::resolve_method_address):
Cast size_t value to unsigned long.
* expand/rust-proc-macro.cc (load_macros): Likewise.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise.
Kushal Pal [Sat, 6 Jan 2024 05:59:14 +0000 (11:29 +0530)]
Handle `async` keyword for regular implementations
Fixes #2788
gcc/rust/ChangeLog:
* parse/rust-parse-impl.h (Parser::parse_inherent_impl_item):
Added switch-case for ASYNC token.
gcc/testsuite/ChangeLog:
* rust/compile/issue-2788.rs: New test.
Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
Kushal Pal [Tue, 16 Jan 2024 13:36:35 +0000 (19:06 +0530)]
Fix inconsistent formatting
gcc/rust/ChangeLog:
* checks/errors/rust-ast-validation.cc (ASTValidation::visit):
Enclose const in single quotes.
gcc/testsuite/ChangeLog:
* rust/compile/const_trait_fn.rs:
Enclose const in single quotes.
Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
Kushal Pal [Wed, 3 Jan 2024 10:32:07 +0000 (16:02 +0530)]
Handle `async` functions in traits
Fixes #2785
gcc/rust/ChangeLog:
* checks/errors/rust-ast-validation.cc (ASTValidation::visit):
Added check for `async` functions inside trait.
* parse/rust-parse-impl.h (Parser::parse_trait_item):
Added switch-case for ASYNC token.
gcc/testsuite/ChangeLog:
* rust/compile/issue-2785.rs: New test.
Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
Arthur Cohen [Fri, 12 Jan 2024 12:48:43 +0000 (13:48 +0100)]
expand: C++ify proc macro decls generation
This uses a stringstream instead of the older, better and more readable
`sprintf` version as the format overflow warning in current GCC is
overzealous and triggered on that code, despite the non-zero allocation.
Even using an unsigned value instead of a signed one for the `size`
variable caused issues, so switching to this is simpler.
gcc/rust/ChangeLog:
* expand/rust-proc-macro.cc: Use stringstream instead of sprintf.
* rust-system.h: Include <iomanip>.
Nirmal Patel [Wed, 27 Dec 2023 22:49:58 +0000 (17:49 -0500)]
Handle newlines during string parsing while lexing
If newline strings are encountered while lexing, the lexer now handles
newline characters by incrementing current line number. This provides
correct line number when displaying errors. If the lexer encounters end
of file before string end, then it will use the start of the string as
the location to an report error.
gcc/rust/ChangeLog:
* lex/rust-lex.cc (Lexer::parse_byte_string): Handle newline
while parsing byte strings
(Lexer::parse_string): Handle newline while parsing strings
Signed-off-by: Nirmal Patel <nirmal@nirmal.dev>
Jakub Dupak [Thu, 14 Dec 2023 11:54:11 +0000 (12:54 +0100)]
TyTy: Refactor FnType deprecated API
gcc/rust/ChangeLog:
* backend/rust-compile-expr.cc (CompileExpr::visit): Use new API.
* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Use new API.
* typecheck/rust-tyty-cmp.h: Remove old API.
* typecheck/rust-tyty.cc (FnPtr::is_equal): Use new API.
* typecheck/rust-tyty.h: Remove old API.
* typecheck/rust-unify.cc (UnifyRules::expect_fnptr): Use new API.
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Jakub Dupak [Sun, 3 Dec 2023 11:32:55 +0000 (12:32 +0100)]
ast: Lower 'for' lifetimes
gcc/rust/ChangeLog:
* hir/rust-ast-lower-type.cc (ASTLoweringType::visit): For lifetimes.
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Jakub Dupak [Sun, 3 Dec 2023 11:30:08 +0000 (12:30 +0100)]
ast: Infer static lifetime for const and static items
(probably incomplete propagation)
gcc/rust/ChangeLog:
* hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_lifetime): Propagate static
requirement.
* hir/rust-ast-lower-base.h: Propagate static requirement.
* hir/rust-ast-lower-implitem.h: Propagate static requirement.
* hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): Propagate static requirement.
* hir/rust-ast-lower-type.cc (ASTLoweringType::translate): Propagate static requirement.
(ASTLoweringType::visit): Propagate static requirement.
* hir/rust-ast-lower-type.h: Propagate static requirement.
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Jakub Dupak [Sun, 3 Dec 2023 11:28:07 +0000 (12:28 +0100)]
ast: Full lifetime elision handling
gcc/rust/ChangeLog:
* parse/rust-parse-impl.h (Parser::parse_generic_param): Lifetime elision control.
(Parser::parse_lifetime_where_clause_item): Lifetime elision control.
(Parser::parse_type_param_bound): Lifetime elision control.
(Parser::parse_lifetime_bounds): Lifetime elision control.
(Parser::parse_lifetime): Lifetime elision control.
(Parser::parse_path_generic_args): Lifetime elision control.
(Parser::parse_self_param): Lifetime elision control.
(Parser::parse_break_expr): Lifetime elision control.
(Parser::parse_continue_expr): Lifetime elision control.
(Parser::parse_reference_type_inner): Lifetime elision control.
* parse/rust-parse.h: Lifetime elision control.
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Jakub Dupak [Sun, 3 Dec 2023 11:25:23 +0000 (12:25 +0100)]
ast: Unify explicitly and implicitly elided lifettimes
gcc/rust/ChangeLog:
* ast/rust-ast.h: Elided lifetime static constructor
* ast/rust-type.h: Default lifetime to elided.
* parse/rust-parse-impl.h (Parser::parse_lifetime_param): Use elided lifetime.
(Parser::parse_lifetime): Use elided lifetime/
(Parser::lifetime_from_token): Use elided lifetime.
(Parser::parse_self_param): Use elided lifetime.
(Parser::parse_reference_type_inner): Use elided lifetime.
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Jakub Dupak [Sun, 3 Dec 2023 11:23:17 +0000 (12:23 +0100)]
ast: Fix lifetime type parsing
There was a mismatch whether lifetime 'static is parsed as "static"
or "'static".
gcc/rust/ChangeLog:
* parse/rust-parse-impl.h (Parser::lifetime_from_token): Fix matched pattern.
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Kushal Pal [Sat, 16 Dec 2023 14:37:23 +0000 (20:07 +0530)]
Generate error for `async` trait fucntions
Fixes #2767
gcc/rust/ChangeLog:
* checks/errors/rust-ast-validation.cc (ASTValidation::visit):
Added check for `async` function inside trait.
gcc/testsuite/ChangeLog:
* rust/compile/issue-2767.rs: New test.
Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
Kushal Pal [Fri, 15 Dec 2023 19:11:09 +0000 (00:41 +0530)]
Handle `async` qualifier inside trait
Fixes #2778
gcc/rust/ChangeLog:
* parse/rust-parse-impl.h (Parser::parse_trait_impl_item):
Handled `async` items
Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
Raiki Tamura [Tue, 26 Dec 2023 04:08:42 +0000 (13:08 +0900)]
gccrs: split rust-mangle.cc into two files
gcc/rust/ChangeLog:
* Make-lang.in: Add .o files
* backend/rust-mangle.cc (struct V0Path): moved to splitted files
(v0_path): Likewise.
(legacy_mangle_name): Likewise.
(legacy_mangle_canonical_path): Likewise.
(legacy_hash): Likewise.
(v0_tuple_prefix): Likewise.
(v0_numeric_prefix): Likewise.
(v0_simple_type_prefix): Likewise.
(v0_complex_type_prefix): Likewise.
(v0_integer_62): Likewise.
(v0_opt_integer_62): Likewise.
(v0_disambiguator): Likewise.
(v0_type_prefix): Likewise.
(v0_generic_args): Likewise.
(v0_identifier): Likewise.
(v0_type_path): Likewise.
(v0_function_path): Likewise.
(v0_scope_path): Likewise.
(v0_crate_path): Likewise.
(v0_inherent_or_trait_impl_path): Likewise.
(v0_closure): Likewise.
(legacy_mangle_item): Likewise.
(v0_mangle_item): Likewise.
* backend/rust-mangle.h (legacy_mangle_item): Likewise.
(v0_mangle_item): Likewise.
* backend/rust-mangle-legacy.cc: New file.
* backend/rust-mangle-v0.cc: New file.
Signed-off-by: Raiki Tamura <tamaron1203@gmail.com>
Jakub Dupak [Mon, 11 Dec 2023 21:09:07 +0000 (22:09 +0100)]
BIR: Cleanup
gcc/rust/ChangeLog:
* checks/errors/borrowck/rust-bir-place.h: Cleanup.
* checks/errors/borrowck/rust-borrow-checker.h: Cleanup.
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Jakub Dupak [Mon, 11 Dec 2023 22:11:34 +0000 (23:11 +0100)]
TyTy: SubstitutionRef cast specialization
Allows skipping parent check when casting.
gcc/rust/ChangeLog:
* typecheck/rust-tyty.h (BaseType::is): Cast API.
(SubstitutionRef>): Cast API.
(BaseType::as): Cast API.
(BaseType::try_as): Cast API.
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Jakub Dupak [Sun, 3 Dec 2023 10:16:59 +0000 (11:16 +0100)]
TyTy: Common interface for fucntion-like types
gcc/rust/ChangeLog:
* typecheck/rust-tyty.h (class ClosureType): Inherit interface.
(class FnPtr): Inherit interface.
(class FnType): Inherit interface.
(class CallableTypeInterface): New interface.
(BaseType::is): Detect interface members API.
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Jakub Dupak [Sun, 3 Dec 2023 10:15:06 +0000 (11:15 +0100)]
TyTy: refactor to new API
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-type.cc (TypeCheckType::resolve_root_path): Refactor.
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Jakub Dupak [Mon, 11 Dec 2023 20:52:48 +0000 (21:52 +0100)]
BIR: Fix missed nodiscard
gcc/rust/ChangeLog:
* checks/errors/borrowck/rust-bir-builder-internal.h: Replace nodiscard.
* checks/errors/borrowck/rust-bir-place.h: Replace nodiscard.
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Jakub Dupak [Sun, 3 Dec 2023 10:13:04 +0000 (11:13 +0100)]
TyTy: Fix missed nodiscard
gcc/rust/ChangeLog:
* typecheck/rust-tyty.h: Fix nodiscard to warn unused.
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Jakub Dupak [Sun, 3 Dec 2023 10:07:04 +0000 (11:07 +0100)]
HIR: add missing getters
gcc/rust/ChangeLog:
* hir/tree/rust-hir-item.h: Ad lifetime getter.
* hir/tree/rust-hir-path.h: Make getter const ref.
* hir/tree/rust-hir.h: Const ref and new getter.
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Arthur Cohen [Thu, 3 Nov 2022 14:02:37 +0000 (15:02 +0100)]
gccrs: refactor builtins initialization and attributes
This commit performs builtin initialization in a more "GCC-y" way,
similarly to what the D frontend is doing. This way, we no longer have
to worry about invalid attributes or types when initializing them by
hand.
Also add attributes support through LANG_HOOKS_COMMON_ATTRIBUTE_TABLE
lang hook.
Most of these changes are based on D frontend.
gcc/rust/ChangeLog:
* Make-lang.in (GRS_OBJS): Add rust-attribs.o.
* backend/rust-builtins.cc (builtin_const, builtin_noreturn)
(builtin_novops): Remove.
(BuiltinsContext::lookup_simple_builtin): Adjust.
(BuiltinsContext::setup_overflow_fns): Remove.
(BuiltinsContext::define_function_type): Set builtin type to
errormark so the builtin is considered unavailable.
(BuiltinsContext::setup_math_fns): Remove.
(BuiltinsContext::setup_atomic_fns): Remove.
(build_c_type_nodes): Refactor based on D frontend.
(BuiltinsContext::define_builtin_types): Likewise.
(DEF_PRIMITIVE_TYPE): New.
(DEF_FUNCTION_TYPE_0): New.
(DEF_FUNCTION_TYPE_1): New.
(DEF_FUNCTION_TYPE_2): New.
(DEF_FUNCTION_TYPE_3): New.
(DEF_FUNCTION_TYPE_4): New.
(DEF_FUNCTION_TYPE_5): New.
(DEF_FUNCTION_TYPE_6): New.
(DEF_FUNCTION_TYPE_7): New.
(DEF_FUNCTION_TYPE_8): New.
(DEF_FUNCTION_TYPE_9): New.
(DEF_FUNCTION_TYPE_10): New.
(DEF_FUNCTION_TYPE_11): New.
(DEF_FUNCTION_TYPE_VAR_0): New.
(DEF_FUNCTION_TYPE_VAR_1): New.
(DEF_FUNCTION_TYPE_VAR_2): New.
(DEF_FUNCTION_TYPE_VAR_3): New.
(DEF_FUNCTION_TYPE_VAR_4): New.
(DEF_FUNCTION_TYPE_VAR_5): New.
(DEF_FUNCTION_TYPE_VAR_6): New.
(DEF_FUNCTION_TYPE_VAR_7): New.
(DEF_FUNCTION_TYPE_VAR_11): New.
(DEF_POINTER_TYPE): New.
(BuiltinsContext::setup): Adjust.
(BuiltinsContext::define_builtin_attributes): New.
(DEF_ATTR_NULL_TREE): New.
(DEF_ATTR_INT): New.
(DEF_ATTR_STRING): New.
(DEF_ATTR_IDENT): New.
(DEF_ATTR_TREE_LIST): New.
(handle_flags): Remove.
(BuiltinsContext::define_builtins): New.
(DEF_BUILTIN): New.
(BuiltinsContext::define_builtin): Remove.
(BuiltinsContext::register_rust_mappings): New. Add all missing
builtins.
(BuiltinsContext::lookup_gcc_builtin): Adjust.
* backend/rust-builtins.h (DEF_PRIMITIVE_TYPE): New.
(DEF_FUNCTION_TYPE_0): New.
(DEF_FUNCTION_TYPE_1): New.
(DEF_FUNCTION_TYPE_2): New.
(DEF_FUNCTION_TYPE_3): New.
(DEF_FUNCTION_TYPE_4): New.
(DEF_FUNCTION_TYPE_5): New.
(DEF_FUNCTION_TYPE_6): New.
(DEF_FUNCTION_TYPE_7): New.
(DEF_FUNCTION_TYPE_8): New.
(DEF_FUNCTION_TYPE_9): New.
(DEF_FUNCTION_TYPE_10): New.
(DEF_FUNCTION_TYPE_11): New.
(DEF_FUNCTION_TYPE_VAR_0): New.
(DEF_FUNCTION_TYPE_VAR_1): New.
(DEF_FUNCTION_TYPE_VAR_2): New.
(DEF_FUNCTION_TYPE_VAR_3): New.
(DEF_FUNCTION_TYPE_VAR_4): New.
(DEF_FUNCTION_TYPE_VAR_5): New.
(DEF_FUNCTION_TYPE_VAR_6): New.
(DEF_FUNCTION_TYPE_VAR_7): New.
(DEF_FUNCTION_TYPE_VAR_11): New.
(DEF_POINTER_TYPE): New.
(DEF_ATTR_NULL_TREE): New.
(DEF_ATTR_INT): New.
(DEF_ATTR_STRING): New.
(DEF_ATTR_IDENT): New.
(DEF_ATTR_TREE_LIST): New.
* backend/rust-compile-intrinsic.cc (Intrinsics::compile): Add
comment.
(op_with_overflow_inner): Adjust.
(copy_handler_inner): Adjust.
(prefetch_data_handler): Adjust.
(build_atomic_builtin_name): Adjust.
(atomic_load_handler_inner): Adjust.
(uninit_handler): Adjust.
(move_val_init_handler): Adjust.
(expect_handler_inner): Adjust.
* rust-gcc.cc (fetch_overflow_builtins): Adjust.
* rust-lang.cc (rust_localize_identifier): Adjust.
(LANG_HOOKS_COMMON_ATTRIBUTE_TABLE): New.
* rust-attribs.cc: New file.
gcc/testsuite/ChangeLog:
* rust/compile/torture/intrinsics-4.rs: Adjust.
* rust/compile/torture/intrinsics-math.rs: Adjust.
* rust/execute/torture/atomic_load.rs: Adjust.
* rust/execute/torture/atomic_store.rs: Adjust.
* rust/compile/torture/intrinsics-1.rs: Removed.
* rust/compile/torture/builtin_abort.rs: New test.
* rust/execute/torture/builtin_abort.rs: New test.
Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
Pierre-Emmanuel Patry [Thu, 23 Nov 2023 19:22:29 +0000 (20:22 +0100)]
Change cfg stripper to use default visitor
Cfg visitor used it's own visit patterns, this made the code longer than
required.
gcc/rust/ChangeLog:
* expand/rust-cfg-strip.cc (CfgStrip::visit): Change calls from visitor
to default visitor.
(CfgStrip::go): Add call to visit crate.
* expand/rust-cfg-strip.h (class CfgStrip): Update prototypes and
remove empty ones.
* ast/rust-ast-visitor.cc: add WhereClause condition check.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Mon, 27 Nov 2023 13:12:20 +0000 (14:12 +0100)]
Make expand visitor inherit from default visitor
Many visit functions in the expand visitor simply visit their components
like the default visitor. Making the expand visitor inherit from the
default visitor allows us to keep all visitor in sync without having to
change every visitor.
gcc/rust/ChangeLog:
* expand/rust-expand-visitor.cc (ExpandVisitor::go): Add call to visit
on the crate.
(ExpandVisitor::visit): Remove some visit functions in favor of their
default visitor counterpart.
* expand/rust-expand-visitor.h (class ExpandVisitor): Inherit from
default visitor and remove now useless function prototypes.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Mon, 27 Nov 2023 16:00:56 +0000 (17:00 +0100)]
Make default resolver inherit from default visitor
The default resolver put some scope in place but mostly has traversal
functions similar to the default ast visitor, making it inherit from the
default visitor allows us to avoid code duplication.
gcc/rust/ChangeLog:
* resolve/rust-default-resolver.cc (DefaultResolver::visit): Remove
duplicated functions.
* resolve/rust-default-resolver.h (class DefaultResolver): Make the
default resolver inherit from the default visitor.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Owen Avery [Sat, 9 Dec 2023 06:22:02 +0000 (01:22 -0500)]
Allow enabling lang_items and no_core features
gcc/rust/ChangeLog:
* checks/errors/rust-feature.cc
(Feature::name_hash_map):
Add entries for Name::LANG_ITEMS and Name::NO_CORE.
* checks/errors/rust-feature.h
(Feature::Name::LANG_ITEMS): New.
(Feature::Name::NO_CORE): New.
gcc/testsuite/ChangeLog:
* rust/compile/sized-stub.rs: New test.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Kushal Pal [Sat, 9 Dec 2023 06:34:01 +0000 (12:04 +0530)]
Renamed `WIN64` to `WIN_64`
Fixes issue #2768
gcc/rust/ChangeLog:
* backend/rust-compile-base.cc (HIRCompileBase::setup_abi_options):
Renamed `WIN64` to `WIN_64`
* util/rust-abi.cc (get_abi_from_string): Likewise
(get_string_from_abi): Likewise
* util/rust-abi.h (enum ABI): Likewise
Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
Nobel Singh [Tue, 5 Dec 2023 12:27:29 +0000 (18:12 +0545)]
Generate error for const trait functions
Fixes issue #2040
Add check to assure that a function cant be declared const inside trait impl
blocks.
gcc/rust/ChangeLog:
* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add
check for const funtion.
gcc/testsuite/ChangeLog:
* rust/compile/issue-2040.rs: New test.
Signed-off-by: Nobel Singh <nobel2073@gmail.com>
Pierre-Emmanuel Patry [Thu, 23 Nov 2023 13:08:50 +0000 (14:08 +0100)]
Add a regression test for function body check
Function body check emit an error message when a required function body
is missing.
gcc/testsuite/ChangeLog:
* rust/compile/functions_without_body.rs: New test.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Wed, 22 Nov 2023 15:37:17 +0000 (16:37 +0100)]
Add validation for functions without body
Add checks in the ast validation pass to error out with functions
(either free or associated) without a definition.
gcc/rust/ChangeLog:
* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add
a validation check and emit an error depending on the context.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Wed, 22 Nov 2023 14:15:29 +0000 (15:15 +0100)]
Make function bodies truly optional
Missing body on a function should be rejected at a later stage in the
compiler, not during parsing.
gcc/rust/ChangeLog:
* ast/rust-ast-collector.cc (TokenCollector::visit): Adapt defintion
getter.
* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Likewise.
* expand/rust-cfg-strip.cc (CfgStrip::visit): Likewise.
* expand/rust-expand-visitor.cc (ExpandVisitor::visit): Likewise.
* hir/rust-ast-lower-implitem.h: Likewise.
* hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): Likewise.
* resolve/rust-ast-resolve-item.cc (ResolveItem::visit): Likewise.
* resolve/rust-ast-resolve-stmt.h: Likewise.
* resolve/rust-default-resolver.cc (DefaultResolver::visit): Likewise.
* util/rust-attributes.cc (AttributeChecker::visit): Likewise.
* parse/rust-parse-impl.h: Allow empty function body during parsing.
* ast/rust-ast.cc (Function::Function): Constructor now take an
optional for the body.
(Function::operator=): Adapt to new optional member.
(Function::as_string): Likewise.
* ast/rust-item.h (class Function): Make body optional and do not
rely on nullptr anymore.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Thu, 30 Nov 2023 12:27:01 +0000 (13:27 +0100)]
Add execution test for name resolution 2.0
We already have some compile tests but it lacked an execution test to
ensure everything compiles correctly to the correct value.
gcc/testsuite/ChangeLog:
* rust/execute/torture/name_resolution.rs: New test.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Thu, 30 Nov 2023 09:43:36 +0000 (10:43 +0100)]
Add multiple regression test in name resolution
Local variables and functions or global variables have different
resolution when binded to a variable. This was not covered before, even
though it was handled by the new name resolution. This commit highlight
this behavior from the new name resolution mechanism.
gcc/testsuite/ChangeLog:
* rust/compile/name_resolution11.rs: New test.
* rust/compile/name_resolution12.rs: New test.
* rust/compile/name_resolution13.rs: New test.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Mon, 27 Nov 2023 14:39:24 +0000 (15:39 +0100)]
Make early name resolver inherit from default one
Many visit functions in the early name resolver are just plain old
traversal visit functions like the ones from the default visitor.
gcc/rust/ChangeLog:
* resolve/rust-early-name-resolver.cc (EarlyNameResolver::resolve_generic_args):
Move function.
(EarlyNameResolver::resolve_qualified_path_type): Likewise.
(EarlyNameResolver::visit): Add a top level visit function for crate
and remove duplicated code.
* resolve/rust-early-name-resolver.h (class EarlyNameResolver): Update
overriden function list.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Fri, 24 Nov 2023 13:09:23 +0000 (14:09 +0100)]
Change the attribute checker visitor to default one
Make the attribute checker visitor inherit from the default visitor
in order to keep visit behavior shared.
gcc/rust/ChangeLog:
* util/rust-attributes.cc (AttributeChecker::visit): Add visit function
for crates.
* util/rust-attributes.h (class AttributeChecker): Update function
prototypes.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Fri, 24 Nov 2023 10:17:52 +0000 (11:17 +0100)]
Make feature gate visitor inherit from default one
The feature gating behavior may be shortened and kept cleaner using the
default visitor. This means less maintenance on visit functions as the
traversal is shared by multiple visitors.
gcc/rust/ChangeLog:
* checks/errors/rust-feature-gate.cc (FeatureGate::visit): Add a visit
function for the crate level.
(FeatureGate::check): Add call to crate visit.
* checks/errors/rust-feature-gate.h (class FeatureGate): Remove now
useless visit functions (traversal only).
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Wed, 22 Nov 2023 12:22:42 +0000 (13:22 +0100)]
Add regression test for const fn in trait
Const fn declaration in trait declarations shall emit an error. This new
test highlight this behavior.
gcc/testsuite/ChangeLog:
* rust/compile/const_trait_fn.rs: New test.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Wed, 22 Nov 2023 12:08:13 +0000 (13:08 +0100)]
Add AST validation check for const in trait
Add a new check in AST validation pass that checks that no function
declaration in traits are declared const.
gcc/rust/ChangeLog:
* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add
const check.
* checks/errors/rust-ast-validation.h: Add visit function prototype.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Wed, 22 Nov 2023 10:12:05 +0000 (11:12 +0100)]
Add a regression test for async const functions
Functions that are both async and const shall be rejected during the
AST validation pass. This new test highlight this behavior.
gcc/testsuite/ChangeLog:
* rust/compile/const_async_function.rs: New test.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Wed, 22 Nov 2023 09:44:08 +0000 (10:44 +0100)]
Add async const function ast validation pass
Add a check during AST validation pass to ensure functions are either
const or async but not both.
gcc/rust/ChangeLog:
* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add
async const check.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Wed, 22 Nov 2023 09:35:44 +0000 (10:35 +0100)]
Allow const and async specifiers in functions
We need to account for const specifiers in async parsing as const
can be used in the syntax before the async keyword.
gcc/rust/ChangeLog:
* parse/rust-parse-impl.h (Parser::parse_vis_item): Allow parsing async
items in const.
(Parser::parse_async_item): Account for const offset during async
lookahead.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Tue, 21 Nov 2023 09:29:35 +0000 (10:29 +0100)]
Split async and const function qualifiers
A function cannot be both async and const, however this should not be
handled in the parser but rather at a later stage in the compiler. This
commit change the AsyncConstStatus in the AST and the HIR to allows a
function to be both async and const.
gcc/rust/ChangeLog:
* ast/rust-ast-builder.cc (AstBuilder::fn_qualifiers): Change
constructor to match the new arguments.
* ast/rust-ast-collector.cc (TokenCollector::visit): Change behavior
to handle both const and async specifiers at the same time.
* ast/rust-ast.cc (FunctionQualifiers::as_string): Likewise.
* ast/rust-item.h (class FunctionQualifiers): Remove AsyncConstStatus
and replace it with both Async and Const status. Also change the safety
arguments to use an enum instead of a boolean.
* hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_qualifiers):
Update constructor call.
* hir/tree/rust-hir-item.h: Add Const and Async status, remove
AsyncConstStatus, update the constructor.
* hir/tree/rust-hir.cc (FunctionQualifiers::as_string): Update with
the new status.
* parse/rust-parse-impl.h (Parser::parse_function_qualifiers): Update
constructor call.
* util/rust-common.h (enum Mutability): Make an enum class.
(enum class): Add Async and Const enum class to avoid booleans.
(enum Unsafety): Change to an enum class.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Owen Avery [Tue, 28 Nov 2023 06:07:00 +0000 (01:07 -0500)]
Remove class AST::InherentImplItem
gcc/rust/ChangeLog:
* ast/rust-ast-full-decls.h
(class InherentImplItem): Remove.
* ast/rust-ast.h
(class InherentImplItem): Remove.
(class SingleASTNode):
Store pointer to AssociatedItem instead of InherentImplItem.
* ast/rust-ast.cc
(SingleASTNode::SingleASTNode):
Use clone_associated_item instead of clone_inherent_impl_item.
(SingleASTNode::operator=): Likewise.
* ast/rust-item.h
(class InherentImpl):
Use AssociatedItem rather than InherentImplItem.
(class Function): Likewise.
(class ConstantItem): Likewise.
* ast/rust-macro.h
(class MacroInvocation): Likewise.
* expand/rust-expand-visitor.cc
(ExpandVisitor::visit): Likewise.
* parse/rust-parse-impl.h
(Parser::parse_impl): Likewise.
(Parser::parse_inherent_impl_item): Likewise.
(Parser::parse_inherent_impl_function_or_method): Likewise.
* parse/rust-parse.h
(Parser::parse_inherent_impl_item): Likewise.
(Parser::parse_inherent_impl_function_or_method): Likewise.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Philip Herron [Mon, 2 Oct 2023 17:41:33 +0000 (18:41 +0100)]
gccrs: Remove backend dependancy on resolution rib information
When making more desugaring for the HIR we can need to add new Let bindings
which will require namesolution information but also rib information for
which block the let binding is associated which was very unnessecary. This
patch simply updates the BLOCK_CONTEXT of the current scope as we are
compiling and encounter HIR::LetStmts instead of trying to do it all
upfront which lots of wierd checks
gcc/rust/ChangeLog:
* backend/rust-compile-base.cc (HIRCompileBase::compile_locals_for_block): removed
* backend/rust-compile-base.h: update header
* backend/rust-compile-block.cc (CompileBlock::visit): remove old logic
* backend/rust-compile-expr.cc (CompileExpr::generate_closure_function): likewise
* backend/rust-compile-stmt.cc (CompileStmt::visit): likewise
* backend/rust-compile-var-decl.h: ensure we setup tuple bindings correctly
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Pierre-Emmanuel Patry [Tue, 21 Nov 2023 18:34:36 +0000 (19:34 +0100)]
Add a regression test for unsafe module validation
Add a new test to check for unsafe modules during AST validation pass.
gcc/testsuite/ChangeLog:
* rust/compile/unsafe_module.rs: New test.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Tue, 21 Nov 2023 17:51:21 +0000 (18:51 +0100)]
Emit an error on unsafe modules
An error should be emitted on unsafe modules during the AST validation
pass as the syntax allows those even though they're not alowed later down
the line.
gcc/rust/ChangeLog:
* ast/rust-item.h: Add safety getter to modules.
* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Check
a module's safety and emit an error when meeting an unsafe module.
* checks/errors/rust-ast-validation.h: Add function prototype.
* parse/rust-parse-impl.h (Parser::parse_module): Move the module locus
to the first token instead of the mod keyword.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Tue, 21 Nov 2023 17:28:30 +0000 (18:28 +0100)]
Parse module safety
Unsafe module are rejected at a later stage but could not be parsed
properly. This commit changes the parser in order to allow unsafe module
in the AST.
gcc/rust/ChangeLog:
* parse/rust-parse-impl.h (Parser::parse_vis_item): Dispatch to parse
module when meeting an unsafe module.
(Parser::parse_module): Set unsafe status when the parser encounter an
unsafe keyword.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Tue, 21 Nov 2023 16:56:10 +0000 (17:56 +0100)]
Add unsafety member to modules
The rust syntax allows unsafe module even if those are rejected at a
later stage.
gcc/rust/ChangeLog:
* ast/rust-item.h: Add safety status to Modules in the AST.
* parse/rust-parse-impl.h (Parser::parse_module): Adapt constructors.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Owen Avery [Tue, 3 Oct 2023 21:50:14 +0000 (17:50 -0400)]
Create base class for TupleStructItems and TuplePatternItems
gcc/rust/ChangeLog:
* hir/tree/rust-hir-pattern.h
(class TupleItems): New.
(class TupleStructItems): Inherit from TupleItems.
(class TuplePatternItems): Likewise.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Arthur Cohen [Wed, 23 Aug 2023 11:51:06 +0000 (13:51 +0200)]
toplevel: Resolve `use` declarations
gcc/rust/ChangeLog:
* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::insert_or_error_out): New functions.
(TopLevel::handle_use_dec): New function.
(flatten_rebind): Likewise.
(flatten_list): Likewise.
(flatten_glob): Likewise.
(flatten): Likewise.
(TopLevel::visit): Visit various `use` declaration nodes.
* resolve/rust-toplevel-name-resolver-2.0.h: Declare functions and
visitors.
Arthur Cohen [Wed, 23 Aug 2023 11:50:54 +0000 (13:50 +0200)]
early: Move `use` declaration resolving to TopLevel
gcc/rust/ChangeLog:
* resolve/rust-early-name-resolver-2.0.cc
(Early::visit): Remove visitors.
* resolve/rust-early-name-resolver-2.0.h: Likewise.
Arthur Cohen [Wed, 23 Aug 2023 11:49:24 +0000 (13:49 +0200)]
ast: Add NodeId to UseTree base class
gcc/rust/ChangeLog:
* ast/rust-item.h (class UseTree): Add `node_id` member.
Arthur Cohen [Tue, 22 Aug 2023 15:29:56 +0000 (17:29 +0200)]
toplevel: Add comment about running the collector twice
gcc/rust/ChangeLog:
* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::insert_or_error_out): Add documentation comment.
(TopLevel::go): Likewise.
Arthur Cohen [Mon, 21 Aug 2023 14:52:48 +0000 (16:52 +0200)]
early: Resolve paths properly
gcc/rust/ChangeLog:
* resolve/rust-early-name-resolver-2.0.cc
(Early::insert_once): New function.
(Early::visit): Likewise.
* resolve/rust-early-name-resolver-2.0.h: Likewise.
Arthur Cohen [Tue, 22 Aug 2023 15:29:05 +0000 (17:29 +0200)]
late: Start storing mappings properly in the resolver
gcc/rust/ChangeLog:
* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Store mappings
after having resolved them.
* resolve/rust-late-name-resolver-2.0.h: Add `TypePath` visitor.
Arthur Cohen [Tue, 22 Aug 2023 14:58:28 +0000 (16:58 +0200)]
late: Start setting up builtin types
gcc/rust/ChangeLog:
* resolve/rust-late-name-resolver-2.0.cc
(Late::setup_builtin_types): New function.
(Late::go): Setup builtin types.
* resolve/rust-late-name-resolver-2.0.h:
* resolve/rust-name-resolution-context.cc
(NameResolutionContext::map_usage): New function.
* resolve/rust-name-resolution-context.h: Likewise.
Arthur Cohen [Tue, 22 Aug 2023 13:40:25 +0000 (15:40 +0200)]
nr2.0: Store mappings in NameResolutionContext
gcc/rust/ChangeLog:
* resolve/rust-name-resolution-context.h: Store a reference to the
mappings.
* resolve/rust-name-resolution-context.cc
(NameResolutionContext::NameResolutionContext): Likewise.
Arthur Cohen [Wed, 15 Nov 2023 10:33:25 +0000 (11:33 +0100)]
toplevel: Use DefaultResolver for Function
gcc/rust/ChangeLog:
* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Use
the DefaultResolver in the toplevel visitor.
Arthur Cohen [Fri, 23 Jun 2023 14:37:51 +0000 (16:37 +0200)]
nr2.0: Add base for late name resolution
gcc/rust/ChangeLog:
* Make-lang.in: Compile late name resolver.
* resolve/rust-late-name-resolver-2.0.cc: New file.
* resolve/rust-late-name-resolver-2.0.h: New file.
Arthur Cohen [Thu, 17 Aug 2023 12:07:27 +0000 (14:07 +0200)]
ctx: Add Labels ForeverStack to the resolver.
Not sure if dealing with "labels" is the proper way of doing so, so we
might eventually change this to use `resolver.values` later on.
gcc/rust/ChangeLog:
* resolve/rust-name-resolution-context.h: Add a Labels stack.
M V V S Manoj Kumar [Tue, 21 Nov 2023 16:34:24 +0000 (22:04 +0530)]
Added support to Parse ASYNC function
Fixes issue #2650
The parser now parses ASYNC functions. Added ASYNC case to parse_item
Added a new function parse_async_item which is called in
parse_vis_item to handle the ASYNC case. Parse_async_item
also checks the current Rust edition and generates an error if the
edition is 2015
gcc/rust/ChangeLog:
* parse/rust-parse-impl.h (Parser::parse_item): Likewise.
(Parser::parse_vis_item): Likewise.
(Parser::parse_async_item): Likewise.
* parse/rust-parse.h: Made declaration for parse_async_item.
gcc/testsuite/ChangeLog:
* rust/compile/issue-2650-1.rs: New test.(edition=2018)
* rust/compile/issue-2650-2.rs: New test.(edition=2015)
Signed-off-by: M V V S Manoj Kumar <mvvsmanojkumar@gmail.com>
Pierre-Emmanuel Patry [Thu, 16 Nov 2023 15:20:49 +0000 (16:20 +0100)]
Introduce a proper keyword list
The old "keyword" list was used for the lexer, and could therefore not
be used with keyword spanning over multiple tokens as those tokens should
remain lexed as is. Hence the introduction of a new list macro for
keyword exclusive tasks. This also means we can no longer match a token
id for each keyword. The token id map has been renamed to keep it's
properties.
gcc/rust/ChangeLog:
* lex/rust-lex.cc (Lexer::classify_keyword): Update keyword map name.
* lex/rust-token.h (enum PrimitiveCoreType): Remove some deprecated
comments.
* util/rust-keyword-values.cc (get_keywords): Update the keyword map
name.
(RS_TOKEN): Define as empty
(RS_TOKEN_KEYWORD_2015): Add the emission value.
(RS_TOKEN_KEYWORD_2018): Likewise.
* util/rust-keyword-values.h (RS_KEYWORD_LIST): Introduce the keyword
list.
(RS_TOKEN_KEYWORD_2018): Define multiple new keywords.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Thu, 16 Nov 2023 14:18:41 +0000 (15:18 +0100)]
Replace some weak keyword raw value with constexpr
Raw values may have typos or contain error, replacing those will
improve the codebase.
gcc/rust/ChangeLog:
* ast/rust-ast-collector.cc (TokenCollector::visit): Replace raw value.
* parse/rust-parse-impl.h (Parser::is_macro_rules_def): Likewise.
(Parser::parse_item): Likewise.
(Parser::parse_vis_item): Likewise.
(Parser::parse_macro_rules_def): Likewise.
(Parser::parse_union): Likewise.
(Parser::parse_trait_impl_item): Likewise.
(Parser::parse_stmt): Likewise.
(Parser::parse_stmt_or_expr): Likewise.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Thu, 16 Nov 2023 14:02:11 +0000 (15:02 +0100)]
Add a list of weak keyword
Retrieving a weak keyword value is done using raw values. Introducing a
list of weak keywords means this could change.
gcc/rust/ChangeLog:
* util/rust-keyword-values.h (class WeakKeywords): Add new class with
weak keyword constexpr.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Thu, 16 Nov 2023 12:41:46 +0000 (13:41 +0100)]
Replace some keyword raw values
Raw values cannot be understood easily by most tools. This commit replace
some raw values with their variable counterpart.
gcc/rust/ChangeLog:
* ast/rust-ast-collector.cc (TokenCollector::visit): Replace raw value
with keyword call.
* ast/rust-ast.h: Likewise.
* parse/rust-parse-impl.h (Parser::parse_path_ident_segment): Likewise.
(Parser::parse_macro_match_fragment): Likewise.
(Parser::parse_extern_crate): Likewise.
(Parser::parse_use_tree): Likewise.
(Parser::parse_const_item): Likewise.
(Parser::parse_literal_expr): Likewise.
(Parser::parse_maybe_named_param): Likewise.
(Parser::parse_pattern_no_alt): Likewise.
(Parser::left_denotation): Likewise.
(Parser::parse_path_in_expression_pratt): Likewise.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Thu, 16 Nov 2023 12:11:33 +0000 (13:11 +0100)]
Add await keyword
The 2018 edition await keyword was missing from the keyword list.
gcc/rust/ChangeLog:
* lex/rust-token.h (enum PrimitiveCoreType): Add await keyword
definition.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Thu, 16 Nov 2023 11:39:37 +0000 (12:39 +0100)]
Treat underscore as a keyword
Make the underscore token a 2015 keyword.
gcc/rust/ChangeLog:
* lex/rust-token.h (enum PrimitiveCoreType): Change macro for
underscore in token list.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Thu, 16 Nov 2023 10:42:35 +0000 (11:42 +0100)]
Add edition separation for keywords
It might be required in the future to get only the keywords from a
specific edition. To do so we need a mean to differentiate keywords based
on their edition. This commit changes the existing keyword macro to
allow such behavior.
gcc/rust/ChangeLog:
* lex/rust-token.h (enum PrimitiveCoreType): Change enum macro calls.
(RS_TOKEN_KEYWORD): Remove generic token keyword macro.
(RS_TOKEN_KEYWORD_2015): Introduce keywords for edition 2015.
(RS_TOKEN_KEYWORD_2018): Likewise with edition 2018.
* lex/rust-token.cc (RS_TOKEN_KEYWORD): Remove old macro definition.
(RS_TOKEN_KEYWORD_2015): Replace with 2015 definition...
(RS_TOKEN_KEYWORD_2018): ... and 2018 definition.
* util/rust-keyword-values.cc (RS_TOKEN_KEYWORD): Likewise.
(RS_TOKEN_KEYWORD_2015): Likewise.
(RS_TOKEN_KEYWORD_2018): Likewise.
* util/rust-keyword-values.h (RS_TOKEN_KEYWORD): Likewise.
(RS_TOKEN_KEYWORD_2015): Likewise.
(RS_TOKEN_KEYWORD_2018): Likewise.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Wed, 15 Nov 2023 15:24:56 +0000 (16:24 +0100)]
Replace TOK suffix with KW
TOK suffix was chosen to disambiguate some identifiers with c++ reserved
keyword. Even though this list lies within the rust-token header, this
macro is used in many context sometimes unrelated with the lexer and
tokens. This TOK suffix may appear surprising in such context.
gcc/rust/ChangeLog:
* lex/rust-token.h (enum PrimitiveCoreType): Change keyword suffix from
tok to kw.
* ast/rust-ast-collector.cc (TokenCollector::visit): Update suffix to
match the new declaration.
* lex/rust-lex.cc (Lexer::parse_raw_identifier): Likewise.
* parse/rust-parse-impl.h (can_tok_start_type): Likewise.
(Parser::parse_item): Likewise.
(Parser::parse_vis_item): Likewise.
(Parser::parse_extern_crate): Likewise.
(Parser::parse_function): Likewise.
(Parser::parse_function_qualifiers): Likewise.
(Parser::parse_struct): Likewise.
(Parser::parse_enum): Likewise.
(Parser::parse_static_item): Likewise.
(Parser::parse_trait_item): Likewise.
(Parser::parse_inherent_impl_item): Likewise.
(Parser::parse_trait_impl_item): Likewise.
(Parser::parse_extern_block): Likewise.
(Parser::parse_external_item): Likewise.
(Parser::parse_stmt): Likewise.
(Parser::parse_return_expr): Likewise.
(Parser::parse_match_expr): Likewise.
(Parser::parse_type): Likewise.
(Parser::parse_for_prefixed_type): Likewise.
(Parser::parse_type_no_bounds): Likewise.
(Parser::parse_stmt_or_expr): Likewise.
* parse/rust-parse.cc (peculiar_fragment_match_compatible): Likewie.
* util/rust-token-converter.cc (convert): Likewise.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Mon, 20 Nov 2023 14:41:39 +0000 (15:41 +0100)]
Add ast validation check on union variant number
Unions with zero fields are forbidden. Add regression test for empty
unions.
gcc/rust/ChangeLog:
* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add
zero field check during ast validation pass.
* checks/errors/rust-ast-validation.h: Add union visit function
prototype.
gcc/testsuite/ChangeLog:
* rust/compile/const_generics_8.rs: Fill the union with dummy values.
* rust/compile/empty_union.rs: New test.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Mon, 20 Nov 2023 10:37:12 +0000 (11:37 +0100)]
Add a test regular variadic functions errors
Add a new regression test for the error message in regular function
variadic errors during ast validation pass.
gcc/testsuite/ChangeLog:
* rust/compile/non_foreign_variadic_function.rs: New test.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Mon, 20 Nov 2023 10:19:46 +0000 (11:19 +0100)]
Emit an error on variadic non extern functions
Variadic regular functions were recently added in the parser as they
should be rejected in the ast validation pass. This commit add the ast
validation pass rejecting this kind of variadic arguments.
gcc/rust/ChangeLog:
* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add
ast validation pass to reject variadic arguments on regular functions.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Mon, 20 Nov 2023 13:59:56 +0000 (14:59 +0100)]
Add check for associated items on auto traits
Reject rust code with associated items on auto traits.
gcc/rust/ChangeLog:
* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add auto
trait associated item check in AST validation pass.
* parse/rust-parse-impl.h: Remove old error emission done during
parsing pass.
gcc/testsuite/ChangeLog:
* rust/compile/auto_trait_invalid.rs: Update old test with updated
error message.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Mon, 20 Nov 2023 13:16:41 +0000 (14:16 +0100)]
Add a regression test for super trait on auto trait
Add a new regression test to highlight the error behavior with a super
trait on an auto trait.
gcc/testsuite/ChangeLog:
* rust/compile/auto_trait_super_trait.rs: New test.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Mon, 20 Nov 2023 13:04:35 +0000 (14:04 +0100)]
Reject auto traits with super trait
Reject auto traits containing a super trait bound during AST validation
pass.
gcc/rust/ChangeLog:
* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Reject
auto traits with super traits.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Mon, 20 Nov 2023 12:53:51 +0000 (13:53 +0100)]
Add regression test for generic auto traits
Generics are forbidden on auto traits and an error should be emitted.
This commit highlight this behavior.
gcc/testsuite/ChangeLog:
* rust/compile/generic_auto_trait.rs: New test.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Mon, 20 Nov 2023 12:43:48 +0000 (13:43 +0100)]
Reject auto traits with generic parameters
Generic parameters are not allowed on auto traits, the compiler should
emit an error.
gcc/rust/ChangeLog:
* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add
check for generics on auto traits.
* checks/errors/rust-ast-validation.h: Add visit function prototype.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>