]> git.ipfire.org Git - thirdparty/gcc.git/log
thirdparty/gcc.git
18 months agogccrs: add extra debug line for method resolve select
Philip Herron [Mon, 13 Mar 2023 16:58:59 +0000 (16:58 +0000)] 
gccrs: add extra debug line for method resolve select

gcc/rust/ChangeLog:

* typecheck/rust-hir-dot-operator.cc (MethodResolver::select): add debug

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: Remove solve_missing_mappings_from_this to handle covariants
Philip Herron [Mon, 13 Mar 2023 16:49:36 +0000 (16:49 +0000)] 
gccrs: Remove solve_missing_mappings_from_this to handle covariants

change how we monomorphize dyn-items when we need to compute the generics

We might have a trait item such as:

  impl<'a, T> FnLike<&'a T, &'a T> for Identity {
      fn call(&self, arg: &'a T) -> &'a T { ... }
  }

Which ended up monomorphized badly to:

  const isize & const &
    <example::Identity as example::FnLike::<& T, & T>>::call<& isize>
    (const struct example::Identity & const self,
     const isize & const & const arg)

This is wrong because it turned into a double reference type becasuse this
bug was consistent bugs were not picked up but this is not correct. We now
reuse our type inference infrastructure to solve the parameters instead.

Fixes #1984

gcc/rust/ChangeLog:

* backend/rust-compile.cc: use unify_and instead
* typecheck/rust-tyty-subst.cc (SubstitutionRef::solve_missing_mappings_from_this): remove
* typecheck/rust-tyty-subst.h: update header

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: get rid of can_eq in CoerceionRules selection
Philip Herron [Mon, 13 Mar 2023 14:08:07 +0000 (14:08 +0000)] 
gccrs: get rid of can_eq in CoerceionRules selection

The can_eq interface is very inconsistent so this begins the journey to
remove this and also address part of #1981

gcc/rust/ChangeLog:

* typecheck/rust-coercion.cc (TypeCoercionRules::select): use new unify_and interface
* typecheck/rust-hir-dot-operator.cc (MethodResolver::try_hook): grab bounds behind refs

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: cleanup header usage to decouple includes
Philip Herron [Sun, 12 Mar 2023 18:38:08 +0000 (18:38 +0000)] 
gccrs: cleanup header usage to decouple includes

gcc/rust/ChangeLog:

* backend/rust-compile-base.cc: fix headers
* backend/rust-compile-base.h: likewise
* backend/rust-compile-expr.cc: likewise
* backend/rust-compile-extern.h: likewise
* backend/rust-compile-pattern.cc: likewise
* backend/rust-compile.cc: likewise
* typecheck/rust-autoderef.cc: likewise
* typecheck/rust-hir-dot-operator.cc: likewise
* typecheck/rust-hir-inherent-impl-overlap.h: likewise
* typecheck/rust-hir-path-probe.cc: likewise
* typecheck/rust-hir-trait-resolve.cc: likewise
* typecheck/rust-hir-type-check-base.cc: likewise
* typecheck/rust-hir-type-check-base.h (RUST_HIR_TYPE_CHECK_BASE): likewise
* typecheck/rust-hir-type-check-enumitem.cc: likewise
* typecheck/rust-hir-type-check-expr.cc: likewise
* typecheck/rust-hir-type-check-implitem.cc: likewise
* typecheck/rust-hir-type-check-item.cc: likewise
* typecheck/rust-hir-type-check-path.cc: likewise
* typecheck/rust-hir-type-check-pattern.cc: likewise
* typecheck/rust-hir-type-check-stmt.cc: likewise
* typecheck/rust-hir-type-check-struct.cc: likewise
* typecheck/rust-hir-type-check-type.cc: likewise
* typecheck/rust-hir-type-check-type.h: likewise
* typecheck/rust-hir-type-check.h (RUST_HIR_TYPE_CHECK): likewise
* typecheck/rust-tyty-bounds.cc: likewise
* typecheck/rust-tyty-call.cc: likewise
* typecheck/rust-tyty-subst.cc: likewise
* typecheck/rust-tyty.cc: likewise

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: get rid of virtual dispatch for substitution proxys
Philip Herron [Sat, 11 Mar 2023 12:55:30 +0000 (12:55 +0000)] 
gccrs: get rid of virtual dispatch for substitution proxys

gcc/rust/ChangeLog:

* typecheck/rust-tyty.cc (BaseType::has_subsititions_defined): new implementation
(BaseType::needs_generic_substitutions): likewise
(ProjectionType::needs_generic_substitutions): remove
(ProjectionType::has_subsititions_defined): remove
* typecheck/rust-tyty.h: update header

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: tyty get rid of useless virtuals
Philip Herron [Fri, 10 Mar 2023 18:13:01 +0000 (18:13 +0000)] 
gccrs: tyty get rid of useless virtuals

This removes can_substitute and contains_type_parameters which were
confusing interfaces to act as a proxy to the SubstitionRef types. This
replaces them with a single base implementation which is much easier to
debug and follow.

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::visit): update to use new interface
(TypeCheckExpr::resolve_root_path): likewise
(TypeCheckExpr::resolve_segments): likewise
* typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit): likewise
(TypeCheckType::resolve_root_path): likewise
* typecheck/rust-tyty-subst.cc (SubstitutionRef::get_mappings_from_generic_args): likewise
* typecheck/rust-tyty.cc (BaseType::supports_substitutions): likewise
(BaseType::can_substitute): remove
(BaseType::contains_type_parameters): remove
(handle_substitions): cleanup
(TupleType::handle_substitions): update
(FnType::handle_substitions): update
(ProjectionType::supports_substitutions): update
* typecheck/rust-tyty.h: update header

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: group basetype virtuals together and remove unused virtual
Philip Herron [Fri, 10 Mar 2023 18:08:18 +0000 (18:08 +0000)] 
gccrs: group basetype virtuals together and remove unused virtual

gcc/rust/ChangeLog:

* typecheck/rust-tyty.h: cleanup ordering of header

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: refactor monomoprhized_clone to not use virtual dispatch
Philip Herron [Fri, 10 Mar 2023 16:31:14 +0000 (16:31 +0000)] 
gccrs: refactor monomoprhized_clone to not use virtual dispatch

gcc/rust/ChangeLog:

* typecheck/rust-tyty.cc (BaseType::monomorphized_clone): new impl
(InferType::monomorphized_clone): remove
(ErrorType::monomorphized_clone): likewise
(ADTType::monomorphized_clone): likewise
(TupleType::monomorphized_clone): likewise
(FnType::monomorphized_clone): likewise
(FnPtr::monomorphized_clone): likewise
(ClosureType::monomorphized_clone): likewise
(ArrayType::clone): likewise
(ArrayType::get_var_element_type): likewise
(ArrayType::monomorphized_clone): likewise
(SliceType::clone): likewise
(SliceType::get_var_element_type): likewise
(SliceType::monomorphized_clone): likewise
(BoolType::monomorphized_clone): likewise
(IntType::monomorphized_clone): likewise
(UintType::monomorphized_clone): likewise
(FloatType::monomorphized_clone): likewise
(USizeType::monomorphized_clone): likewise
(ISizeType::monomorphized_clone): likewise
(CharType::monomorphized_clone): likewise
(ReferenceType::clone): likewise
(ReferenceType::get_var_element_type): likewise
(ReferenceType::monomorphized_clone): likewise
(PointerType::clone): likewise
(PointerType::get_var_element_type): likewise
(PointerType::monomorphized_clone): likewise
(ParamType::monomorphized_clone): likewise
(StrType::monomorphized_clone): likewise
(NeverType::monomorphized_clone): likewise
(PlaceholderType::monomorphized_clone): likewise
(ProjectionType::monomorphized_clone): likewise
(DynamicObjectType::monomorphized_clone): likewise
* typecheck/rust-tyty.h: update header

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: refactor TyTy::BaseType::is_unit to not use virtual dispatch
Philip Herron [Fri, 10 Mar 2023 14:31:50 +0000 (14:31 +0000)] 
gccrs: refactor TyTy::BaseType::is_unit to not use virtual dispatch

gcc/rust/ChangeLog:

* typecheck/rust-tyty.cc (BaseType::is_unit): new implementation
(ErrorType::is_unit): remove
(TupleType::is_unit): likewise
(NeverType::is_unit): likewise
(PlaceholderType::is_unit): likewise
(ProjectionType::is_unit): likewise
* typecheck/rust-tyty.h: update header

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: refactor is_concrete to not just virtual dispatch
Philip Herron [Fri, 10 Mar 2023 14:10:54 +0000 (14:10 +0000)] 
gccrs: refactor is_concrete to not just virtual dispatch

Its easier to debug and maintain one base function for this than relying
on virtual dispatch

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* typecheck/rust-tyty.cc (BaseType::is_concrete): new implementation
(InferType::is_concrete): remove
(ErrorType::is_concrete): likewise
(StructFieldType::is_concrete): likewise
(ADTType::is_concrete): likewise
(TupleType::is_concrete): likewise
(BoolType::is_concrete): likewise
(IntType::is_concrete): likewise
(UintType::is_concrete): likewise
(FloatType::is_concrete): likewise
(USizeType::is_concrete): likewise
(ISizeType::is_concrete): likewise
(CharType::is_concrete): likewise
(ReferenceType::is_concrete): likewise
(PointerType::is_concrete): likewise
(ParamType::is_concrete): likewise
(StrType::is_concrete): likewise
(NeverType::is_concrete): likewise
(PlaceholderType::is_concrete): likewise
(ProjectionType::is_concrete): likewise
(DynamicObjectType::is_concrete): likewise
* typecheck/rust-tyty.h: update header

18 months agogccrs: reuse destructure code in compilation of types
Philip Herron [Fri, 10 Mar 2023 13:10:11 +0000 (13:10 +0000)] 
gccrs: reuse destructure code in compilation of types

We can just return error_mark_node instead of our own custom
recursion limit checker code. This makes the backend more reuseable
in error states.

gcc/rust/ChangeLog:

* backend/rust-compile-type.cc (TyTyResolveCompile::TyTyResolveCompile): call destructure
(TyTyResolveCompile::compile): use error_mark_node
(TyTyResolveCompile::visit): use error_mark_node
* backend/rust-compile-type.h: remove recursive ops

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: Add all rust keywords (except priv) to the follow-set of `:vis` when parsing...
Tage Johansson [Sat, 4 Mar 2023 18:43:02 +0000 (19:43 +0100)] 
gccrs: Add all rust keywords (except priv) to the follow-set of `:vis` when parsing macro rules

Previously, the following macro rules were rejected by gccrs:
```Rust
macro_rules! {
    ($v:vis <KEY_WORD>) => { ... };
}
```

This PR fixes so the above code is accepted by the compiler for all key words like `async` or `unsafe`.
The only exception is the keyword `priv` which is not allowed.
See [this page](https://doc.rust-lang.org/reference/macro-ambiguity.html) for reference. Especially the following excerpt:
> FOLLOW(vis) = {,l any keyword or identifier except a non-raw priv; any token that can begin a type; ident, ty, and path nonterminals}.

Fixes #1060

gcc/rust/ChangeLog:

* parse/rust-parse.cc: fix follow-sets

gcc/testsuite/ChangeLog:

* rust/compile/macro47.rs: Test that :vis can be followed by some keywords
* rust/compile/macro48.rs: Test that :vis cannot be followed by the keyword priv

Signed-off-by: Tage Johansson <frans.tage@gmail.com>
18 months agogccrs: resolve: Handle multiple bindings to the same identifier
Mahmoud Mohamed [Mon, 13 Mar 2023 14:18:11 +0000 (17:18 +0300)] 
gccrs: resolve: Handle multiple bindings to the same identifier

https://github.com/rust-lang/rust/blob/master/compiler/rustc_resolve/src/late.rs#L3168
This commit follows rustc's implementation of handling multiple bindings
to the same identifier in parameters.

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit) :declare and
pass bindings to PatternDeclaration::go.
(ResolveExpr::resolve_closure_param): Likewise.
* resolve/rust-ast-resolve-expr.h: Likewise.
* resolve/rust-ast-resolve-item.cc (ResolveTraitItems::visit): Likewise.
(ResolveItem::visit): Likewise.
* resolve/rust-ast-resolve-pattern.cc (PatternDeclaration::go): Likewise.
(PatternDeclaration::visit): check for previous identifier bindings
before inserting the new one.
* resolve/rust-ast-resolve-pattern.h (enum PatternBoundCtx): New enum.
* resolve/rust-ast-resolve-stmt.h: pass bindings to PatterDeclaration::go.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Mahmoud Mohamed <mahadelr19@gmail.com>
18 months agogccrs: hir: Improve pattern bindings handling in closure parameters
Mahmoud Mohamed [Tue, 14 Mar 2023 22:06:46 +0000 (01:06 +0300)] 
gccrs: hir: Improve pattern bindings handling in closure parameters

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::generate_closure_function):
handle closure parameters pattern bindings using CompilePatternBindings visitor

gcc/testsuite/ChangeLog:

* rust/execute/torture/closure4.rs: New test.
* rust/execute/torture/ref-pattern2.rs: New test.

Signed-off-by: Mahmoud Mohamed <mahadelr19@gmail.com>
18 months agogccrs: Rename compiler proper
Arthur Cohen [Tue, 14 Mar 2023 16:28:54 +0000 (17:28 +0100)] 
gccrs: Rename compiler proper

gcc/rust/ChangeLog:

* README.md (process): Rename `rust1` to `crab1` in examples.
* Make-lang.in: Rename `rust1` to `crab1`.
* config-lang.in: Likewise.
* lang-specs.h: Likewise.
* rustspec.cc (lang_specific_driver): Likewise.

18 months agogccrs: Add method to access SlicePattern items
Owen Avery [Tue, 14 Mar 2023 23:17:26 +0000 (19:17 -0400)] 
gccrs: Add method to access SlicePattern items

gcc/rust/ChangeLog:

* hir/tree/rust-hir-pattern.h
(SlicePattern::get_items): Add.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: Convert structs to classes
Owen Avery [Tue, 14 Mar 2023 22:52:50 +0000 (18:52 -0400)] 
gccrs: Convert structs to classes

gcc/rust/ChangeLog:

* hir/tree/rust-hir-full-decls.h
(struct GenericArgsBinding): Convert to class.
(class GenericArgsBinding): Convert from struct.
(struct TypePathFunction): See above.
(class TypePathFunction): See above.
(struct QualifiedPathType): See above.
(class QualifiedPathType): See above.
* ast/rust-ast-full-decls.h
(struct WhereClause): See above.
(class WhereClause): See above.
(struct SelfParam): See above.
(class SelfParam): See above.
(struct FunctionQualifiers): See above.
(class FunctionQualifiers): See above.
(struct FunctionParam): See above.
(class FunctionParam): See above.
(struct StructField): See above.
(class StructField): See above.
(struct TupleField): See above.
(class TupleField): See above.
(struct TraitFunctionDecl): See above.
(class TraitFunctionDecl): See above.
(struct TraitMethodDecl): See above.
(class TraitMethodDecl): See above.
(struct NamedFunctionParam): See above.
(class NamedFunctionParam): See above.
* hir/tree/rust-hir-path.h
(struct GenericArgsBinding): See above.
(class GenericArgsBinding): See above.
(struct TypePathFunction): See above.
(class TypePathFunction): See above.
(struct QualifiedPathType): See above.
(class QualifiedPathType): See above.
* ast/rust-item.h
(struct WhereClause): See above.
(class WhereClause): See above.
(struct SelfParam): See above.
(class SelfParam): See above.
(struct FunctionQualifiers): See above.
(class FunctionQualifiers): See above.
(struct FunctionParam): See above.
(class FunctionParam): See above.
(struct StructField): See above.
(class StructField): See above.
(struct TupleField): See above.
(class TupleField): See above.
(struct TraitFunctionDecl): See above.
(class TraitFunctionDecl): See above.
(struct TraitMethodDecl): See above.
(class TraitMethodDecl): See above.
(struct NamedFunctionParam): See above.
(class NamedFunctionParam): See above.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: HIR::AltPattern fixes
Owen Avery [Tue, 14 Mar 2023 21:35:16 +0000 (17:35 -0400)] 
gccrs: HIR::AltPattern fixes

gcc/rust/ChangeLog:

* hir/tree/rust-hir-pattern.h
(class AltPattern): Remove duplicate access specifier.
(AltPattern::get_alts): Add.
* hir/tree/rust-hir.cc
(AltPattern::as_string): Add.
(AltPattern::accept_vis): Add.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: hir: Add ExportedMacro node and handling.
Arthur Cohen [Wed, 1 Mar 2023 11:35:18 +0000 (12:35 +0100)] 
gccrs: hir: Add ExportedMacro node and handling.

This HIR node represents macros which should be exported into the final
Rust metadata files. Because our metadata exporter operates on the HIR,
while macros are inherently tied to the AST, we need a way to propagate
exported macros up until the metadata export pass on the HIR. Hence the
existence of this class, whose sole purpose is to keep enough information
for the metadata exporter to retrieve the original AST::MacroRulesDefinition.
Handling for actually exporting these macros will come later.

gcc/rust/ChangeLog:

* hir/tree/rust-hir-item.h (class ExportedMacro): Add new ExportedMacro class.
* hir/tree/rust-hir.cc (ExportedMacro::accept_vis): New function.
(ExportedMacro::get_locus): Likewise.
(ExportedMacro::get_item_kind): Likewise.
(ExportedMacro::clone_item_impl): Likewise.
* hir/tree/rust-hir-full-decls.h (class ExportedMacro): Forward declare class.
* backend/rust-compile-item.h: Add visitor for ExportedMacro.
* backend/rust-compile-stmt.h: Likewise.
* checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::visit): Likewise.
* checks/errors/privacy/rust-privacy-reporter.h: Likewise.
* checks/errors/privacy/rust-pub-restricted-visitor.cc (PubRestrictedVisitor::visit):
Likewise.
* checks/errors/privacy/rust-pub-restricted-visitor.h: Likewise.
* checks/errors/privacy/rust-reachability.cc (ReachabilityVisitor::visit): Likewise.
* checks/errors/privacy/rust-reachability.h: Likewise.
* checks/errors/privacy/rust-visibility-resolver.cc (VisibilityResolver::visit): Likewise.
* checks/errors/privacy/rust-visibility-resolver.h: Likewise.
* checks/errors/rust-const-checker.cc (ConstChecker::visit): Likewise.
* checks/errors/rust-const-checker.h: Likewise.
* checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Likewise.
* checks/errors/rust-unsafe-checker.h: Likewise.
* hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): Likewise.
* hir/rust-ast-lower-item.h: Likewise.
* hir/rust-hir-dump.cc (Dump::visit): Likewise.
* hir/rust-hir-dump.h: Likewise.
* hir/tree/rust-hir-visitor.h: Likewise.
* metadata/rust-export-metadata.cc: Likewise.
* typecheck/rust-hir-type-check-item.h: Likewise.
* typecheck/rust-hir-type-check-stmt.cc (TypeCheckStmt::visit): Likewise.
* typecheck/rust-hir-type-check-stmt.h: Likewise.
* typecheck/rust-tycheck-dump.h: Likewise.
* hir/tree/rust-hir.h: Add new ItemKind::MacroExport variant.
* util/rust-attributes.cc: Add #[macro_export] attribute.

18 months agogccrs: hir: Provide basic handling for ReferencePattern in function parameter
Mahmoud Mohamed [Tue, 7 Mar 2023 23:57:24 +0000 (02:57 +0300)] 
gccrs: hir: Provide basic handling for ReferencePattern in function parameter

Added an implementation for
`CompilePatternBindings::visit (HIR::ReferencePattern)` where we
dereference the initial expression and recurse.
Added an implementation for
`CompilePatternBindings::visit (HIR::IdentifierPattern)` as well since it's
the simplest base case.

In addition to this, a small refactor for the shared code in
`StructPattern` and `TupleStructPattern` visits was added as a helper
function called `create_tmp_param_var`.

gcc/rust/ChangeLog:

* backend/rust-compile-fnparam.cc (CompileFnParam::visit):
Added visit implementation for ReferencePattern.
(CompileFnParam::create_tmp_param_var):
Refactored duplicated code into a helper function.
* backend/rust-compile-fnparam.h: Added visit implementation for
ReferencePattern.
* backend/rust-compile-pattern.cc (CompilePatternBindings::visit):
Added visit implementation for ReferencePattern and
IdentifierPattern.
* backend/rust-compile-pattern.h: Added visit implementation for
ReferencePattern and IdentifierPattern.

gcc/testsuite/ChangeLog:

* rust/compile/ref_pattern_fn_param.rs: Moved to...
* rust/compile/ref_pattern_fn_param1.rs: ...here.
* rust/compile/ref_pattern_fn_param2.rs: New test.
* rust/execute/torture/ref-pattern1.rs: New test.

Signed-off-by: Mahmoud Mohamed <mahadelr19@gmail.com>
18 months agogccrs: enr: Fetch module items during early name resolution
Arthur Cohen [Thu, 2 Mar 2023 15:56:33 +0000 (16:56 +0100)] 
gccrs: enr: Fetch module items during early name resolution

This is important as public macros can be present in other modules,
which would otherwise not be loaded until the expansion phase
happening right after the early name resolution.

gcc/rust/ChangeLog:

* resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit): Move
unloaded module item loading to...
* expand/rust-attribute-visitor.cc (AttrVisitor::visit): ...here.

18 months agogccrs: hir: Simplify indentation to single line
Jakub Dupak [Sat, 11 Mar 2023 19:50:09 +0000 (20:50 +0100)] 
gccrs: hir: Simplify indentation to single line

Improves readability by better corresponding to resulting output.

gcc/rust/ChangeLog:

* hir/rust-hir-dump.cc (Dump::visit): Simplify indentation dump to single line.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
18 months agogccrs: hir: Unify indentation approach with ast
Jakub Dupak [Sat, 11 Mar 2023 19:36:11 +0000 (20:36 +0100)] 
gccrs: hir: Unify indentation approach with ast

gcc/rust/ChangeLog:

* ast/rust-ast-dump.cc (Indent::Indent): Move to separate file.
(operator<<): Move to separate file.
(Indent::increment): Move to separate file.
(Indent::decrement): Move to separate file.
* ast/rust-ast-dump.h (class Indent): Move to separate file.
* hir/rust-hir-dump.cc (Dump::Dump): Use new indentation object.
(Dump::go): Use new indentation object.
(Dump::visit): Use new indention object.
* hir/rust-hir-dump.h: Use new indentation object.
* util/rust-dump.h: New file. Moved Indentation from rust-ast-dump.cc

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
18 months agogccrs: hir: Fix ReferencePattern typechecking
Mahmoud Mohamed [Sun, 12 Mar 2023 23:26:13 +0000 (02:26 +0300)] 
gccrs: hir: Fix ReferencePattern typechecking

The visit for TypeCheckPattern::visit (HIR::ReferencePattern) was missing
an assignment to infered

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
Add the missing infered type assignment

Signed-off-by: Mahmoud Mohamed <mahadelr19@gmail.com>
18 months agogccrs: fix some clang warnings
Marc Poulhiès [Sat, 17 Dec 2022 15:23:05 +0000 (16:23 +0100)] 
gccrs: fix some clang warnings

This fixes some extra warnings reported by clang.

gcc/rust/ChangeLog:
PR rust/108111
* ast/rust-ast-full-decls.h (StructPatternElements): Declare as a
class.
* ast/rust-item.h (EnumItem): Mark several method as being
overrides.
* ast/rust-pattern.h (StructPattern::get_locus): Add override.
* lex/rust-lex.h (BufferInputSource): Use reference_wrapper
instead of bare reference.
(TokenSource::get): Add method to implement the reference_wrapper
interface.
* typecheck/rust-tyty.h (TypeBoundPredicate): Add empty dtor.
* util/rust-buffered-queue.h (peek): Source token stream is now
using a reference_wrapper, use .get()

Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
18 months agogccrs: hir: add a helper function for visit
vincent [Tue, 7 Mar 2023 20:32:04 +0000 (20:32 +0000)] 
gccrs: hir: add a helper function for visit

This commit adds a helper function for TypeCheckPattern::visit
(HIR::RangePattern &pattern) to remove redundancy

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-pattern.cc
(TypeCheckPattern::visit): rewrite part code to helper function
(TypeCheckPattern::typecheck_range_pattern_bound): helper function
* typecheck/rust-hir-type-check-pattern.h
(TypeCheckPattern::typecheck_range_pattern_bound):
change the parameter of the function

Signed-off-by: Jiakun Fan <jfan30@u.rochester.edu>
18 months agogccrs: typecheck: Add basic typechecking for ReferenceType
goar5670 [Mon, 6 Mar 2023 22:25:39 +0000 (01:25 +0300)] 
gccrs: typecheck: Add basic typechecking for ReferenceType

gcc/rust/ChangeLog:
* hir/tree/rust-hir-pattern.h (HIR::ReferencePattern):
added get_referenced_pattern function.
* resolve/rust-ast-resolve-pattern.h
(Resolve::PatternDeclaration): add visit function for
AST::ReferencePattern
* typecheck/rust-hir-type-check-pattern.cc
(Resolver::TypeCheckPattern): add visit function for
HIR::ReferencePattern

gcc/testsuite/ChangeLog:
* rust/compile/ref_pattern_fn_param.rs: New test.

Signed-off-by: Mahmoud Mohamed <mahadelr19@gmail.com>
18 months agogccrs: Add coherence related lang_items
Owen Avery [Tue, 7 Mar 2023 18:37:08 +0000 (13:37 -0500)] 
gccrs: Add coherence related lang_items

gcc/rust/ChangeLog:

* util/rust-lang-item.h
(RustLangItem::ItemType): New enumerators.
(RustLangItem::Parse): Parse new enumerators.
(RustLangItem::ToString): Handle new enumerators.

gcc/testsuite/ChangeLog:

* rust/compile/lang-impl.rs: New test.

18 months agogccrs: Add AltPattern HIR node
Owen Avery [Mon, 20 Feb 2023 19:46:03 +0000 (14:46 -0500)] 
gccrs: Add AltPattern HIR node

Example:
match x {
    0 | 1 => true,
    _ => false
}

gcc/rust/ChangeLog:

* backend/rust-compile-fnparam.h:
(CompileFnParam::visit): Add AltPattern visitor.
* backend/rust-compile-pattern.h:
(CompilePatternCaseLabelExpr::visit): Add AltPattern visitor.
(CompilePatternBindings::visit): Add AltPattern visitor.
(CompilePatternLet::visit): Add AltPattern visitor.
* backend/rust-compile-resolve-path.h:
(ResolvePathRef::visit): Add AltPattern visitor.
* backend/rust-compile-var-decl.h:
(CompileVarDecl::visit): Add AltPattern visitor.
* checks/errors/rust-const-checker.cc
(ConstChecker::visit): Add AltPattern visitor.
* checks/errors/rust-const-checker.h:
(ConstChecker::visit): Add AltPattern visitor.
* checks/errors/rust-unsafe-checker.cc
(UnsafeChecker::visit): Add AltPattern visitor.
* checks/errors/rust-unsafe-checker.h:
(UnsafeChecker::visit): Add AltPattern visitor.
* hir/rust-hir-dump.cc
(Dump::visit): Add AltPattern visitor.
* hir/rust-hir-dump.h:
(Dump::visit): Add AltPattern visitor.
* hir/tree/rust-hir-full-decls.h
(class AltPattern): Add forward declaration.
* hir/tree/rust-hir-pattern.h
(class AltPattern): New class.
* hir/tree/rust-hir-visitor.h:
(HIRFullVisitor::visit): Add AltPattern visitor.
(HIRFullVisitorBase::visit): Add AltPattern visitor.
(HIRPatternVisitor::visit): Add AltPattern visitor.
* hir/tree/rust-hir.h:
(Pattern::PatternType::ALT): New enumerator.
* typecheck/rust-hir-type-check-pattern.cc
(TypeCheckPattern::visit): Add AltPattern visitor.
* typecheck/rust-hir-type-check-pattern.h:
(TypeCheckPattern::visit): Add AltPattern visitor.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: expand: Add stringify macro
Pierre-Emmanuel Patry [Mon, 6 Mar 2023 08:58:02 +0000 (09:58 +0100)] 
gccrs: expand: Add stringify macro

Add the stringify macro expansion as well as some tests.

gcc/rust/ChangeLog:

* ast/rust-macro.cc (builtin_macro_from_string): Add identifier
identification.
* ast/rust-macro.h (enum class): Add Stringify builtin macro
type.
* expand/rust-macro-builtins.cc (make_macro_path_str): Add path
for builtin stringify macro.
(MacroBuiltin::stringify_handler): Add handler for builtin
stringify macro.
* expand/rust-macro-builtins.h: Add stringify handler's
prototype.
* util/rust-hir-map.cc (Mappings::insert_macro_def): Add
stringify handler to builtin hir map.

gcc/testsuite/ChangeLog:

* rust/compile/stringify.rs: Add a basic test with some text.
* rust/execute/torture/builtin_macro_stringify.rs: Verify the
text is left as is without any other macro expansion.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Add length checking for tuple patterns
Nikos Alexandris [Fri, 3 Mar 2023 21:55:59 +0000 (23:55 +0200)] 
gccrs: Add length checking for tuple patterns

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
Add length checking for tuple patterns.
(TypeCheckPattern::emit_pattern_size_error): New function.
* typecheck/rust-hir-type-check-pattern.h: New function
emit_pattern_size_error.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Nikos Alexandris <nikos-alexandris@protonmail.com>
18 months agogccrs: parser: Fix handling of multiple left angles in null denotation
goar5670 [Sat, 4 Mar 2023 19:13:18 +0000 (22:13 +0300)] 
gccrs: parser: Fix handling of multiple left angles in null denotation

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_expr):
split LEFT_SHIFT before null_denotation.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Mahmoud Mohamed <mahadelr19@gmail.com>
18 months agogccrs: Cleanup and Assertion
Parthib [Mon, 6 Mar 2023 02:04:43 +0000 (07:34 +0530)] 
gccrs: Cleanup and Assertion

gcc/rust/ChangLog:

* rust-object-export.cc: Modified
* hir/rust-ast-lower-type.cc (rust_fatal_error): Removed
(rust_assert): Added

Signed-off-by: Parthib <parthibdutta02@gmail.com>
18 months agogccrs: Resolve closure parameters without given type
Owen Avery [Sat, 4 Mar 2023 01:05:59 +0000 (20:05 -0500)] 
gccrs: Resolve closure parameters without given type

gcc/rust/ChangeLog:

* resolve/rust-early-name-resolver.cc
(EarlyNameResolver::visit):
Check for closure parameter without given type.

gcc/testsuite/ChangeLog:

* rust/compile/closure_no_type_anno.rs: Extend test.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: make predicate bounds overwrite-able
Philip Herron [Fri, 3 Mar 2023 18:17:50 +0000 (18:17 +0000)] 
gccrs: make predicate bounds overwrite-able

When compiling types especially when using queries it needs to be
permissive and allow them to be overwritten and a predicate might have one
set of details in one senario and a new one with the same id later on but
with different types.

Fixes #1524

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* typecheck/rust-typecheck-context.cc (TypeCheckContext::insert_resolved_predicate): remove

gcc/testsuite/ChangeLog:

* rust/compile/issue-1524.rs: New test.

18 months agogccrs: Fix name-resolution to be permissive and carry on
Philip Herron [Fri, 3 Mar 2023 18:01:01 +0000 (18:01 +0000)] 
gccrs: Fix name-resolution to be permissive and carry on

There are a few edge cases when resolving TypePaths that we cannot fully
resolve to an explicit node_id and this is expected. So for example

  <A as B>::foo

A and B are simple Type paths and thats 100% but the segment foo cannot be
100% resolved to an explicit node id as this requires type-resolution to
find the correct path. So when we have complex paths such as:

  <<A as B>::foo as C>

The ::foo part will return UNKNOWN_NODEId and we return early and think its
a failure case but its not necessarily a failure but we need to make sure
to name resolve C so when we do type-resolution we can resolve C properly.

Addresses #1524

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-type.cc (ResolveRelativeQualTypePath::resolve_qual_seg): fix

gcc/testsuite/ChangeLog:

* rust/compile/parse_associated_type_as_generic_arg3.rs: remove -fsyntax-only

18 months agogccrs: Add missing node_id copys in the copy constructors
Philip Herron [Fri, 3 Mar 2023 17:59:00 +0000 (17:59 +0000)] 
gccrs: Add missing node_id copys in the copy constructors

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* ast/rust-path.h: add missing copy for node_id

18 months agogccrs: cleanup headers
Philip Herron [Fri, 3 Mar 2023 16:44:43 +0000 (16:44 +0000)] 
gccrs: cleanup headers

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* rust-gcc.h: remove unused headers

18 months agogccrs: Fix missing move and copy constructors missing the associated-path
Philip Herron [Wed, 1 Mar 2023 22:09:47 +0000 (22:09 +0000)] 
gccrs: Fix missing move and copy constructors missing the associated-path

Addresses #1524

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* ast/rust-ast.cc (QualifiedPathInType::as_string): add missing to string
* ast/rust-path.h: add missing copy+move constructors and assignment overloads
* hir/tree/rust-hir-path.h: likewise
* hir/tree/rust-hir.cc (QualifiedPathInType::as_string): add missing to string

gcc/testsuite/ChangeLog:

* rust/compile/parse_associated_type_as_generic_arg.rs: it now works without -fsyntax-only
* rust/compile/parse_associated_type_as_generic_arg2.rs: likewise

18 months agogccrs: destructure parameter names.
Philip Herron [Fri, 3 Mar 2023 16:12:46 +0000 (16:12 +0000)] 
gccrs: destructure parameter names.

When we have complex generic code you can end up with situations where we
compile types:

  Maybe<<S as Foo>::A>

Into

  Maybe<<placeholder:<Projection=::()>>>

This calls destructure to cleanup the naming here and avoid making non
canonical TREE_TYPES hitting the verify_gimple code triggering non-trival
constructors.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* typecheck/rust-tyty.cc (ParamType::get_name): call destructure

18 months agogccrs: Take advantage of our new unify_and to inject inference
Philip Herron [Fri, 3 Mar 2023 18:42:21 +0000 (18:42 +0000)] 
gccrs: Take advantage of our new unify_and to inject inference

Wen computing higher ranked trait bounds where there are multiple type
params and ones which are not bound entirely on the impl-type we need
to inject inference variables as required to compute the types. The
inference variables we inject are missing the callbacks that we can compute
the bounds properly so this is the first part of the fix.

Addresses #1893

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* typecheck/rust-hir-trait-resolve.cc: use unify_and infer

18 months agogccrs: parser: Fix parsing closure parameter
goar5670 [Thu, 2 Mar 2023 18:34:44 +0000 (21:34 +0300)] 
gccrs: parser: Fix parsing closure parameter

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_closure_param):
Replace parse_pattern with parse_pattern_no_alt.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Mahmoud Mohamed <mahadelr19@gmail.com>
18 months agogccrs: parser: Fix while let expr parsing
Pierre-Emmanuel Patry [Wed, 1 Mar 2023 16:45:51 +0000 (17:45 +0100)] 
gccrs: parser: Fix while let expr parsing

While let expr return unit but are valid construct in rust, they should
therefore be included in the parsing code. Also add a new test to check
parsing of while let expressions.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_while_let_loop_expr):
Prevent hard error on token skip.
(Parser::null_denotation): Fix parser for while let expressions.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: add uninit intrinsic
Philip Herron [Wed, 1 Mar 2023 12:43:56 +0000 (12:43 +0000)] 
gccrs: add uninit intrinsic

Following an investigation from rustc and discussions on zulip the
recommendation was that for uninit we memset to 0x01 which is less likely
to be a null ptr but still an invalid reference.

Fixes #1899

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* backend/rust-builtins.cc (BuiltinsContext::setup): add memset builtin to the map
* backend/rust-compile-intrinsic.cc (uninit_handler): implement uninit intrinsic

gcc/testsuite/ChangeLog:

* rust/compile/torture/uninit-intrinsic-1.rs: New test.

18 months agogccrs: parser: Add 0 sized slice pattern parsing
Pierre-Emmanuel Patry [Wed, 1 Mar 2023 17:46:33 +0000 (18:46 +0100)] 
gccrs: parser: Add 0 sized slice pattern parsing

Check for a closing square bracket before attempting to parse any
pattern within a slice. Also add a new test to verify zero sized
slice parsing.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_slice_pattern): Add
closing square bracket check.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: fixup: parser: Fix bootstrap compile error
Pierre-Emmanuel Patry [Wed, 1 Mar 2023 09:04:04 +0000 (10:04 +0100)] 
gccrs: fixup: parser: Fix bootstrap compile error

The recent changes in the parser bringing the parsing of extern type
items also brought a compilation error when boostrapping the compiler.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_external_type_item):
Fix compilation error due to unnecessary move.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: added support for printing HIR dump of functions, statements, arithematic...
Abdul Rafey [Mon, 27 Feb 2023 12:01:31 +0000 (17:31 +0530)] 
gccrs: added support for printing HIR dump of functions, statements, arithematic/logical expressions and literals.

gcc/rust/ChangeLog:

* hir/rust-hir-dump.cc (Dump::go): support inner attrs, crate items and node mappings
(Dump::visit): support functions, arith/logical exprs, let stmts and literals

Signed-off-by: Abdul Rafey <abdulrafeyq@gmail.com>
18 months agogccrs: Add location info when opening a file fails in include_str and include_bytes...
Nikos Alexandris [Thu, 2 Mar 2023 01:14:46 +0000 (03:14 +0200)] 
gccrs: Add location info when opening a file fails in include_str and include_bytes. Resolves issue #1872

gcc/rust/ChangeLog:

* expand/rust-macro-builtins.cc (load_file_bytes): Add location parameter.
(MacroBuiltin::include_bytes_handler): Pass location to load_file_bytes.
(MacroBuiltin::include_str_handler): Pass location to load_file_bytes.

gcc/testsuite/ChangeLog:

* rust/compile/builtin_macro_include_bytes_location_info.rs: New test.
* rust/compile/builtin_macro_include_str_location_info.rs: New test.

Signed-off-by: Nikos Alexandris <nikos-alexandris@protonmail.com>
18 months agogccrs: testsuite: Add a test for .. in slice patterns
Pierre-Emmanuel Patry [Wed, 1 Mar 2023 10:36:42 +0000 (11:36 +0100)] 
gccrs: testsuite: Add a test for .. in slice patterns

Add a test to check wether the syntax of a RestPattern in a SlicePattern
parse correctly.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: parser: Add RestPattern parsing
Pierre-Emmanuel Patry [Wed, 1 Mar 2023 10:00:29 +0000 (11:00 +0100)] 
gccrs: parser: Add RestPattern parsing

Add simple RestPattern parsing to the pattern parsing function.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_pattern_no_alt): Handle
RestPattern correctly.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: ast: Add NodeId and clone to RestPattern
Pierre-Emmanuel Patry [Wed, 1 Mar 2023 09:54:29 +0000 (10:54 +0100)] 
gccrs: ast: Add NodeId and clone to RestPattern

The RestPattern AST node did not have any NodeId to identify it and
could therefore not be instanciated.

gcc/rust/ChangeLog:

* ast/rust-pattern.h (class RestPattern): Add NodeId as well as
the clone_impl function.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: testsuite: Add a test for if let syntax
Pierre-Emmanuel Patry [Wed, 1 Mar 2023 13:20:23 +0000 (14:20 +0100)] 
gccrs: testsuite: Add a test for if let syntax

Add a new test to check the if let expression syntax parsing.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: parser: Fix if let parsing
Pierre-Emmanuel Patry [Wed, 1 Mar 2023 13:13:01 +0000 (14:13 +0100)] 
gccrs: parser: Fix if let parsing

Fix if let parsing in null_notation function. This problem was due to
the current token already being passed in the function parameters and
already out of the buffered queue. Hence why the peeked token was let
and not if.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::null_denotation): Fix if let
parsing.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: add {add,sub,mul}_with_overflow intrinsics
Philip Herron [Wed, 1 Mar 2023 11:42:36 +0000 (11:42 +0000)] 
gccrs: add {add,sub,mul}_with_overflow intrinsics

Fixes #1898

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* backend/rust-compile-intrinsic.cc (op_with_overflow_inner): wraps op_with_overflow
(std::function<tree): likewise
(op_with_overflow): generate the intrinsic based on the tree_code op

gcc/testsuite/ChangeLog:

* rust/compile/torture/intrinsics-8.rs: New test.

18 months agogccrs: hir: Refactor ASTLoweringStmt to source file.
Arthur Cohen [Wed, 1 Mar 2023 10:03:24 +0000 (11:03 +0100)] 
gccrs: hir: Refactor ASTLoweringStmt to source file.

gcc/rust/ChangeLog:

* Make-lang.in: Add rust-ast-lower-stmt.o
* hir/rust-ast-lower-stmt.h: Move definitions to...
* hir/rust-ast-lower-stmt.cc: ...here.

18 months agogccrs: Add feature gate definition for `extern_types`.
mxlol233 [Wed, 1 Mar 2023 11:31:19 +0000 (19:31 +0800)] 
gccrs: Add feature gate definition for `extern_types`.

This commit add a basic implementation to gating `ExternalTypeItem` AST node.

gcc/rust/ChangeLog:

* checks/errors/rust-feature-gate.cc: Add definition
for `extern_types`.
* checks/errors/rust-feature-gate.h: Likewise.
* checks/errors/rust-feature.cc: Likewise.
* checks/errors/rust-feature.h: Likewise.

gcc/testsuite/ChangeLog:
* rust/compile/feature_extern_types.rs:New file.

Signed-off-by: Xiao Ma <mxlol233@outlook.com>
18 months agogccrs: Fix assignment operator overloads for AST and HIR patterns
Owen Avery [Mon, 27 Feb 2023 16:18:56 +0000 (11:18 -0500)] 
gccrs: Fix assignment operator overloads for AST and HIR patterns

gcc/rust/ChangeLog:

* ast/rust-pattern.h
(StructPatternElements::operator=): Clear vector before inserting.
(TupleStructItemsNoRange::operator=): Clear vector before inserting.
(TupleStructItemsRange::operator=): Clear vectors before inserting.
(TuplePatternItemsMultiple::operator=): Clear vector before inserting.
(TuplePatternItemsRanged::operator=): Clear vectors before inserting.
(SlicePattern::operator=): Clear vector before inserting.
(AltPattern::operator=): Clear vector before inserting.
* hir/tree/rust-hir-pattern.h
(StructPatternElements::operator=): Clear vector before inserting.
(TupleStructItemsNoRange::operator=): Clear vector before inserting.
(TupleStructItemsRange::operator=): Clear vectors before inserting.
(TuplePatternItemsMultiple::operator=): Clear vector before inserting.
(TuplePatternItemsRanged::operator=): Clear vectors before inserting.
(SlicePattern::operator=): Clear vector before inserting.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: typecheck: Fix casting error behind generics
bl7awy [Tue, 28 Feb 2023 17:53:01 +0000 (20:53 +0300)] 
gccrs: typecheck: Fix casting error behind generics

gcc/rust/ChangeLog:
* typecheck/rust-casts.cc (TypeCastRules::cast_rules): Perform destructure on `from` type.

gcc/testsuite/ChangeLog:
* rust/compile/cast_generics.rs: New test.

Signed-off-by: Mahmoud Mohamed <mahadelr19@gmail.com>
18 months agogccrs: Change struct StructPatternElements into class
Owen Avery [Mon, 27 Feb 2023 16:02:02 +0000 (11:02 -0500)] 
gccrs: Change struct StructPatternElements into class

gcc/rust/ChangeLog:

* ast/rust-pattern.h
(struct StructPatternElements): Change to class.
(class StructPatternElements): Change from struct.
* hir/tree/rust-hir-pattern.h
(struct StructPatternElements): Change to class.
(class StructPatternElements): Change from struct.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: Replace gcc_unreachable with rust_sorry_at
Owen Avery [Mon, 27 Feb 2023 15:23:19 +0000 (10:23 -0500)] 
gccrs: Replace gcc_unreachable with rust_sorry_at

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-pattern.cc
(TypeCheckPattern::visit): Improve error messages.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: Fix formatting
Owen Avery [Mon, 20 Feb 2023 21:05:41 +0000 (16:05 -0500)] 
gccrs: Fix formatting

gcc/rust/ChangeLog:

* hir/tree/rust-hir-pattern.h
(class TupleStructItemsNoRange): Fix formatting.
(class TupleStructItemsRange): Fix formatting.
(class TuplePatternItemsMultiple): Fix formatting.
(class TuplePatternItemsRanged): Fix formatting.
(class SlicePattern): Fix formatting.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: ast: Add RestPattern AST node
Pierre-Emmanuel Patry [Tue, 28 Feb 2023 16:34:31 +0000 (17:34 +0100)] 
gccrs: ast: Add RestPattern AST node

Add the RestPattern AST node representing ".." code in some rust
context. This commit also provides the different visitors for this node.

gcc/rust/ChangeLog:

* ast/rust-ast-dump.cc (Dump::visit): Add visitor.
* ast/rust-ast-dump.h: Add visitor prototype.
* ast/rust-ast-full-decls.h (class RestPattern): Add forward
declaration for class RestPattern.
* ast/rust-ast-visitor.h: Add visitor prototype.
* ast/rust-ast.cc (RestPattern::accept_vis): Add function to
accept a foreign visitor.
* ast/rust-pattern.h (class RestPattern): Add class RestPattern.
* checks/errors/rust-feature-gate.h: Add visitor prototype.
* expand/rust-attribute-visitor.cc (AttrVisitor::visit): Add
visitor implementation.
* expand/rust-attribute-visitor.h: Add visitor prototype.
* hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Add
visitor implementation.
* hir/rust-ast-lower-base.h: Add visitor prototype.
* resolve/rust-ast-resolve-base.cc (ResolverBase::visit): Add
visitor implementation.
* resolve/rust-ast-resolve-base.h: Add visitor prototype.
* resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit):
Add visitor implementation.
* resolve/rust-early-name-resolver.h: Add visitor prototype.
* util/rust-attributes.cc (AttributeChecker::visit): Add visitor
implementation.
* util/rust-attributes.h: Add visitor prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Remove cmp_autoderef_mode hack from old autoderef
Philip Herron [Tue, 28 Feb 2023 19:07:11 +0000 (19:07 +0000)] 
gccrs: Remove cmp_autoderef_mode hack from old autoderef

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* typecheck/rust-tyty-cmp.h: remove
* typecheck/rust-tyty.cc (set_cmp_autoderef_mode): likewise
(reset_cmp_autoderef_mode): likewise
* typecheck/rust-tyty.h (set_cmp_autoderef_mode): likewise
(reset_cmp_autoderef_mode): likewise

18 months agogccrs: Fix method resolution to use TryCoerce
Philip Herron [Mon, 27 Feb 2023 19:16:00 +0000 (19:16 +0000)] 
gccrs: Fix method resolution to use TryCoerce

Rust allows us to call generic pointer methods on pointers so in non
generic contexts the old code using the bad can_eq interface couldn't
handle this case. So taking advantage of our new unify_and interface to try
and infer when required we can start using our TryCoerce interface to reuse
existing code to assemble possible candidates more acurately using the
existing coercion rules.

Fixes #1901 #878

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* typecheck/rust-coercion.cc (TypeCoercionRules::Coerce): Add new try_flag
(TypeCoercionRules::TypeCoercionRules): set new try flag
(TypeCoercionRules::do_coercion): default to a final unify_and in the else case
(TypeCoercionRules::coerce_unsafe_ptr): cannot coerce to a ptr from ref during autoderef
(TypeCoercionRules::coerce_borrowed_pointer): respect coerceable mutability
* typecheck/rust-coercion.h: update header
* typecheck/rust-hir-dot-operator.cc (MethodResolver::select): use new TryCoerce interface
(MethodResolver::append_adjustments): ensure we maintain adjustment mappings
* typecheck/rust-hir-dot-operator.h: add new method append_adjustments
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): extra logging

gcc/testsuite/ChangeLog:

* rust/compile/issue-1901.rs: New test.

18 months agogccrs: bug-fix implicit inference checks
Philip Herron [Mon, 27 Feb 2023 17:39:09 +0000 (17:39 +0000)] 
gccrs: bug-fix implicit inference checks

When generating implicit inference variables we can miss cases where the
other side might be another inference variable too but it runs the risk of
generating unending inference cycles needing more info but if they other
side is a non general inference variables like <integer> or <float> this
is safe to do so and allows us to infer mroe cases.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* typecheck/rust-unify.cc (UnifyRules::go): fix inference check

18 months agogccrs: autoderef unconstify so we can use in non const contexts
Philip Herron [Mon, 27 Feb 2023 17:05:13 +0000 (17:05 +0000)] 
gccrs: autoderef unconstify so we can use in non const contexts

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* backend/rust-compile-base.h: unconsify
* backend/rust-compile.cc (HIRCompileBase::coercion_site): likewise
(HIRCompileBase::coercion_site1): likewise
* typecheck/rust-autoderef.cc (Adjuster::try_deref_type): likewise
(Adjuster::try_raw_deref_type): likewise
(Adjuster::try_unsize_type): likewise
(AutoderefCycle::cycle): likewise
(AutoderefCycle::try_autoderefed): likewise
* typecheck/rust-autoderef.h: likewise
* typecheck/rust-coercion.cc (TypeCoercionRules::select): likewise
* typecheck/rust-coercion.h: likewise
* typecheck/rust-hir-dot-operator.cc (MethodResolver::Probe): likewise
(MethodResolver::select): likewise
* typecheck/rust-hir-dot-operator.h: likewise

18 months agogccrs: Only emit errors during type-bounds checking when required
Philip Herron [Mon, 27 Feb 2023 16:38:41 +0000 (16:38 +0000)] 
gccrs: Only emit errors during type-bounds checking when required

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* typecheck/rust-unify.cc (UnifyRules::go): respect the emit_errors flag

18 months agogccrs: Make coercion sites autoderef cycle optional
Philip Herron [Mon, 27 Feb 2023 14:16:29 +0000 (14:16 +0000)] 
gccrs: Make coercion sites autoderef cycle optional

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* typecheck/rust-casts.cc (TypeCastRules::check): update to new interface
* typecheck/rust-coercion.cc (TypeCoercionRules::Coerce): likewise
(TypeCoercionRules::TryCoerce): likewise
(TypeCoercionRules::TypeCoercionRules): likewise
* typecheck/rust-coercion.h: likewise
* typecheck/rust-type-util.cc (coercion_site): likewise

18 months agogccrs: Allow infer vars on the lhs too
Philip Herron [Mon, 27 Feb 2023 13:34:30 +0000 (13:34 +0000)] 
gccrs: Allow infer vars on the lhs too

We should allow implicit inference on the expected side too not just the
receiver.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* typecheck/rust-unify.cc (UnifyRules::go): allow lhs infer vars

18 months agogccrs: Generic pointers are coerceable
Philip Herron [Sun, 26 Feb 2023 22:08:26 +0000 (22:08 +0000)] 
gccrs: Generic pointers are coerceable

This is a complex type-system change where it begins out journey to get
rid of our can_eq interface. Rust allows:

  let x:*mut T
  let y = x as *mut u8;

Which requires us to consider find a way to infer what T should be so as
to keep unify happy. This means we need to introduce a new unify_and
interface where we can optionally inject inference variables as well as
only commit the inference variable joins when they are sucsessful.

So for this case we can then inject an implicit inference variables for T
that can unify against u8 to make this a valid type-resolution.

Fixes #1930

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::resolve_method_address): update to new inteface
* typecheck/rust-coercion.cc (TypeCoercionRules::coerce_unsafe_ptr): likewise
(TypeCoercionRules::coerce_borrowed_pointer): likewise
* typecheck/rust-hir-type-check.h: likewise
* typecheck/rust-type-util.cc (unify_site_and): new interface to allow for infer and commit
* typecheck/rust-type-util.h (unify_site_and): likewise
* typecheck/rust-typecheck-context.cc (TypeCheckContext::clear_type): new interface
* typecheck/rust-unify.cc (UnifyRules::UnifyRules): update
(UnifyRules::Resolve): new optional flags for commit and infer
(UnifyRules::go): likewise
(UnifyRules::expect_adt): refactor to use new interface
(UnifyRules::expect_reference): likewise
(UnifyRules::expect_pointer): likewise
(UnifyRules::expect_array): likewise
(UnifyRules::expect_slice): likewise
(UnifyRules::expect_fndef): likewise
(UnifyRules::expect_fnptr): likewise
(UnifyRules::expect_tuple): likewise
(UnifyRules::expect_closure): likewise
* typecheck/rust-unify.h: refactor interface

gcc/testsuite/ChangeLog:

* rust/compile/issue-1930.rs: New test.

18 months agogccrs: refactor unify commit as a static function from unify code
Philip Herron [Sun, 26 Feb 2023 18:30:49 +0000 (18:30 +0000)] 
gccrs: refactor unify commit as a static function from unify code

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* typecheck/rust-unify.cc (UnifyRules::Resolve): refactor
(UnifyRules::commit): refactor
* typecheck/rust-unify.h: likewise

18 months agogccrs: Fix ICE in ADTType::is_concrete
Philip Herron [Sun, 26 Feb 2023 22:36:20 +0000 (22:36 +0000)] 
gccrs: Fix ICE in ADTType::is_concrete

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* typecheck/rust-tyty.cc (ADTType::is_concrete):  need to consider if is a num_variant
* typecheck/rust-tyty.h: refactor to cc file

18 months agogccrs: testsuite: Add test with missing semicolon
Pierre-Emmanuel Patry [Mon, 27 Feb 2023 13:08:10 +0000 (14:08 +0100)] 
gccrs: testsuite: Add test with missing semicolon

Add a test to the testsuite in order to verify the presence of a
semicolon at the end of an external type item declaration.

gcc/testsuite/ChangeLog:

* rust/compile/extern_type_item_missing_semi.rs: New failing
test.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: testsuite: Add extern type item test
Pierre-Emmanuel Patry [Mon, 27 Feb 2023 13:07:00 +0000 (14:07 +0100)] 
gccrs: testsuite: Add extern type item test

Add a test for extern type item declaration.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: parser: Parse external type item
Pierre-Emmanuel Patry [Mon, 27 Feb 2023 09:10:51 +0000 (10:10 +0100)] 
gccrs: parser: Parse external type item

Add the code to parse type item declaration within an extern block.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_external_type_item):
Add function to parser an external type item.
(Parser::parse_external_item):
Add identification and parsing for external type items.
* parse/rust-parse.h:
Add parser_external_type_item prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Implement and test include_str eager expansion
omkar-mohanty [Thu, 16 Feb 2023 04:40:24 +0000 (10:10 +0530)] 
gccrs: Implement and test include_str eager expansion

builtins: Implement eager expansion for include_str!()

gcc/rust/ChangeLog:

* expand/rust-macro-builtins.cc
(MacroBuiltin::include_str_handler): eager expansion
(make_macro_path_str): macto to string
(parse_single_string_literal): check for eager invocation
(MacroBuiltin::assert_handler): eager expansion
(MacroBuiltin::include_bytes_handler): eager expansion
(MacroBuiltin::include_str_handler): eager expansion
(MacroBuiltin::compile_error_handler): eager expansion
(MacroBuiltin::include_handler): eager expansion

gcc/testsuite/ChangeLog:

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

Signed-off-by: omkar-mohanty <franzohouser@gmail.com>
18 months agogccrs: parser: Parse `default` impl Functions and Methods
Arthur Cohen [Thu, 23 Feb 2023 14:11:04 +0000 (15:11 +0100)] 
gccrs: parser: Parse `default` impl Functions and Methods

gcc/rust/ChangeLog:

* ast/rust-item.h (class Method): Add `is_default` field.
(class Function): Likewise.
* parse/rust-parse-impl.h (Parser::parse_item): Add nice error when
parsing `default` outside of an `impl` block
(Parser::parse_trait_impl_item): Allow parsing functions
or methods when seeing `default`.

gcc/testsuite/ChangeLog:

* rust/compile/parse_invalid_specialization.rs: New test.
* rust/compile/parse_specialization.rs: New test.
* rust/compile/default_not_a_kw.rs: New test.

18 months agogccrs: typecheck: Refactor cast_site
Pierre-Emmanuel Patry [Thu, 23 Feb 2023 18:00:07 +0000 (19:00 +0100)] 
gccrs: typecheck: Refactor cast_site

Refactor cast_site to be a simple function in rust-type-util.h.

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-base.cc (TypeCheckBase::cast_site):
Remove cast_site.
* typecheck/rust-hir-type-check-base.h: Remove cast_site
prototype.
* typecheck/rust-type-util.cc (cast_site): Add cast_site.
* typecheck/rust-type-util.h (cast_site): Add cast_site
prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: ast: Add proper visitors for ExternalTypeItem
Arthur Cohen [Thu, 23 Feb 2023 15:59:20 +0000 (16:59 +0100)] 
gccrs: ast: Add proper visitors for ExternalTypeItem

gcc/rust/ChangeLog:

* ast/rust-item.h: Add non-const `get_visibility` to ExternalTypeItem.
* ast/rust-ast-dump.cc (Dump::visit): Add implementation for ExternalTypeItem.
* expand/rust-attribute-visitor.cc (AttrVisitor::visit): Likewise.

18 months agogccrs: ast: Add ExternalTypeItem node
Arthur Cohen [Thu, 23 Feb 2023 15:50:39 +0000 (16:50 +0100)] 
gccrs: ast: Add ExternalTypeItem node

gcc/rust/ChangeLog:

* ast/rust-item.h (class ExternalTypeItem): New class.
* ast/rust-ast.cc (ExternalTypeItem::as_string): New function.
(ExternalTypeItem::accept_vis): Likewise.
* ast/rust-ast-full-decls.h (class ExternalTypeItem): Declare class.
* ast/rust-ast-dump.cc (Dump::visit): Add base visitor for ExternalTypeItem.
* ast/rust-ast-dump.h: Likewise.
* ast/rust-ast-visitor.h: Likewise.
* checks/errors/rust-feature-gate.h: Likewise.
* expand/rust-attribute-visitor.cc (AttrVisitor::visit): Likewise.
* expand/rust-attribute-visitor.h: Likewise.
* hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Likewise.
* hir/rust-ast-lower-base.h: Likewise.
* resolve/rust-ast-resolve-base.cc (ResolverBase::visit): Likewise.
* resolve/rust-ast-resolve-base.h: Likewise.
* resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit): Likewise.
* resolve/rust-early-name-resolver.h: Likewise.
* util/rust-attributes.cc (AttributeChecker::visit): Likewise.
* util/rust-attributes.h: Likewise.

18 months agogccrs: macro_invoc_lexer: Add `split_current_token` implementation
Arthur Cohen [Tue, 21 Feb 2023 12:51:54 +0000 (13:51 +0100)] 
gccrs: macro_invoc_lexer: Add `split_current_token` implementation

gcc/rust/ChangeLog:

* expand/rust-macro-invoc-lexer.cc (MacroInvocLexer::split_current_token):
Add proper implementation.

gcc/testsuite/ChangeLog:

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

18 months agogccrs: parser: Add parsing of auto traits
Arthur Cohen [Wed, 15 Feb 2023 15:53:41 +0000 (16:53 +0100)] 
gccrs: parser: Add parsing of auto traits

This adds enough handling to start parsing `auto` traits but not handle
them in the AST, lowering phase or HIR yet.

The feature is named `optin_builtin_traits` in Rust 1.49 but changes to
`auto_traits` later down the line. So we'll need to take care of this later
on.

Finally, this also changes the way the lexer detects if a string is a
keyword or not. We relied on a call to `std::lower_bound` to figure
out if a string was contained in an array or not, and this ended up
causing issues when adding new keywords. We can instead switch to a
simple hashmap and search for the key. The code *might* be less
optimized (unsure) but it is definitely simpler and easier to read.

Fixes #1814

gcc/rust/ChangeLog:

* ast/rust-item.h (class Trait): Add `has_auto` field.
* checks/errors/rust-feature.cc: Add handling for `feature(optin_builtin_traits)`
* checks/errors/rust-feature.h: Likewise.
* lex/rust-lex.cc: Fix keyword classification using hashmap.
* lex/rust-token.h: Add `auto` keyword token.
* parse/rust-parse-impl.h (Parser::parse_vis_item): Parse auto traits
on `auto` keyword.

gcc/testsuite/ChangeLog:

* rust/compile/auto_trait_invalid.rs: New test.
* rust/compile/auto_trait_valid.rs: New test.

18 months agogccrs: typecheck: Refactor coercion_site
Pierre-Emmanuel Patry [Wed, 22 Feb 2023 09:44:16 +0000 (10:44 +0100)] 
gccrs: typecheck: Refactor coercion_site

Refactor coercion_site to be a simple function in rust-type-util.h
instead of a static function in TypeCheckBase.
gcc/rust/ChangeLog:

* typecheck/rust-hir-trait-resolve.cc (TraitItemReference::resolve_item):
Remove TypeCheckBase namespace qualifier.
* typecheck/rust-hir-type-check-base.cc (TypeCheckBase::coercion_site):
Remove coercion_site function.
* typecheck/rust-hir-type-check-base.h: Remove coercion_site
prototype.
* typecheck/rust-type-util.cc (coercion_site): Add coercion_site
function.
* typecheck/rust-type-util.h (coercion_site): Add coercion_site
prototype.
* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit):
Remove TypeCheckBase namespace qualifier.
(TypeCheckMethodCallExpr::check): Remove TypeCheckBase namespace
qualifier.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: typecheck: Refactor unify_site
Pierre-Emmanuel Patry [Tue, 21 Feb 2023 16:29:53 +0000 (17:29 +0100)] 
gccrs: typecheck: Refactor unify_site

Refactor unify_site to be a simple function in rust-type-util.h.

gcc/rust/ChangeLog:

* typecheck/rust-autoderef.cc: Remove TypeCheckBase qualifier.
* typecheck/rust-hir-trait-resolve.cc: Remove TypeCheckBase
qualifier.
* typecheck/rust-hir-type-check-base.cc (TypeCheckBase::unify_site):
Remove unify_site.
* typecheck/rust-hir-type-check-base.h: Remove unify_site
header.
* typecheck/rust-hir-type-check.cc (TypeResolution::Resolve):
Remove TypeCheckBase qualifier.
* typecheck/rust-type-util.cc (unify_site): Add unify_site
function.
* typecheck/rust-type-util.h (unify_site): Add unify_site
prototype.
* typecheck/rust-tyty-call.cc (TypeCheckMethodCallExpr::check):
Remove TypeCheckBase qualifier.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: parser: Allow `LEFT_SHIFT` to start `parse_type`
Arthur Cohen [Fri, 17 Feb 2023 13:24:07 +0000 (14:24 +0100)] 
gccrs: parser: Allow `LEFT_SHIFT` to start `parse_type`

Similarly to the last commit, we need to allow `LEFT_SHIFT` tokens to
start a qualified path type and split them into two `LEFT_ANGLE` tokens.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_type): Allow LEFT_SHIFT to
start a type and then split it in `parse_qualified_path_type`

gcc/testsuite/ChangeLog:

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

18 months agogccrs: parser: Allow parsing of qualified type path as nested generic argument
Arthur Cohen [Thu, 16 Feb 2023 12:53:22 +0000 (13:53 +0100)] 
gccrs: parser: Allow parsing of qualified type path as nested generic argument

Let's take the example of lexing `Option<<T as Iterator>::Item>` and look
at the first few tokens. Originally, `Option<<T` was lexed as 3 tokens:

* IDENTIFIER(Option)
* LEFT_SHIFT
* IDENTIFIER(T)

The parser did not allow a list of generic arguments to start with a left
shift, and rejected the above type. We are now splitting the left shift
into two left angles, as this allows complex generic arguments and overall
makes sense parsing wise. Thus, the above list becomes:

* IDENTIFIER(Option)
* LEFT_ANGLE
* LEFT_ANGLE
* IDENTIFIER(T)

and `<T as Iterator>` is properly parsed as a qualified path.

Fixes #1815
Fixed #1809

Addresses #1524

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_path_generic_args): Split leading
`LEFT_SHIFT` token into two `LEFT_ANGLE` tokens when parsing generic arguments.
(Parser::parse_type_path_segment): Allow `LEFT_ANGLE` as starting token for
parsing generic arguments.

gcc/testsuite/ChangeLog:

* rust/compile/parse_associated_type_as_generic_arg.rs: New test.
* rust/compile/parse_associated_type_as_generic_arg2.rs: New test.
* rust/compile/path_as_generic_arg.rs: New test.
* rust/compile/nested_generic.rs: New test.

18 months agogccrs: Add feature gate for "rustc_attri".
mxlol233 [Thu, 16 Feb 2023 11:38:42 +0000 (19:38 +0800)] 
gccrs: Add feature gate for "rustc_attri".

This commit implemented a basic feature gate to check some attributes
for `rustc_attri`.

gcc/rust/ChangeLog:

* checks/errors/rust-feature-gate.cc: Add implementations
for `rustc_attri`.
* checks/errors/rust-feature-gate.h: Likewise.

gcc/testsuite/ChangeLog:

* rust/compile/builtin_macro_compile_error.rs: Add
crate feature `rustc_attri`.
* rust/compile/builtin_macro_concat.rs: Likewise.
* rust/compile/builtin_macro_eager1.rs: Likewise.
* rust/compile/builtin_macro_eager2.rs: Likewise.
* rust/compile/builtin_macro_env.rs: Likewise.
* rust/compile/builtin_macro_include_bytes.rs:
Likewise.
* rust/compile/builtin_macro_include_str.rs:
Likewise.
* rust/compile/builtin_macro_not_found.rs:
Likewise.
* rust/compile/builtin_macro_recurse2.rs:
Likewise.
* rust/compile/feature_rust_attri0.rs:New file.
* rust/compile/feature_rust_attri1.rs:New file.
* rust/compile/include_empty.rs:Add crate feature
`rustc_attri`.
* rust/compile/issue-1830_bytes.rs:Likewise.
* rust/compile/issue-1830_str.rs:Likewise.
* rust/compile/macro42.rs:Likewise.
* rust/execute/torture/builtin_macro_cfg.rs:
Likewise.
* 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/macros29.rs:Likewise.
* rust/execute/torture/macros30.rs:Likewise.
* rust/execute/torture/macros31.rs:Likewise.

Signed-off-by: Xiao Ma <mxlol233@outlook.com>
18 months agoAArch64: Reassociate CONST in address expressions
Wilco Dijkstra [Tue, 16 Jan 2024 16:27:02 +0000 (16:27 +0000)] 
AArch64: Reassociate CONST in address expressions

GCC tends to optimistically create CONST of globals with an immediate offset.
However it is almost always better to CSE addresses of globals and add immediate
offsets separately (the offset could be merged later in single-use cases).
Splitting CONST expressions with an index in aarch64_legitimize_address fixes
part of PR112573.

gcc/ChangeLog:
PR target/112573
* config/aarch64/aarch64.cc (aarch64_legitimize_address): Reassociate
badly formed CONST expressions.

gcc/testsuite/ChangeLog:
PR target/112573
* gcc.target/aarch64/pr112573.c: Add new test.

18 months agogccrs: Parse AltPattern
Owen Avery [Tue, 14 Feb 2023 23:42:39 +0000 (18:42 -0500)] 
gccrs: Parse AltPattern

Renamed Parser::parse_pattern to Parser::parse_pattern_no_alt and created
new method Parser::parse_pattern to handle alternate patterns.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h
(Parser::parse_pattern): Add.
(Parser::parse_pattern_no_alt): Rename.
* parse/rust-parse.h:
(Parser::parse_pattern): Add.
(Parser::parse_pattern_no_alt): Rename.

gcc/testsuite/ChangeLog:

* rust/compile/pattern-or.rs: New test.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: Fix missing build dependency
Pierre-Emmanuel Patry [Mon, 12 Jun 2023 08:51:49 +0000 (10:51 +0200)] 
gccrs: Fix missing build dependency

Fix the missing dependency between the gcc and libgrust.

ChangeLog:

* Makefile.def: Add a dependency to libgrust for all-gcc.
* Makefile.in: Regenerate the file.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Fix bootstrap build
Pierre-Emmanuel Patry [Wed, 3 May 2023 16:43:10 +0000 (18:43 +0200)] 
gccrs: Fix bootstrap build

This commit fixes bootstrapping for future additions to libgrust/

ChangeLog:

* Makefile.def: Add libgrust target to bootstrap.
* Makefile.in: Regenerate.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agosparc: Char arrays are 64-bit aligned on SPARC
Daniel Cederman [Fri, 8 Dec 2023 08:49:12 +0000 (09:49 +0100)] 
sparc: Char arrays are 64-bit aligned on SPARC

pr88077 fails on SPARC since char HeaderStr[1] in pr88077_1.c and
long HeaderStr in pr88077_0.c differs in alignment.

Warning printed by Binutils ld:
warning: alignment 4 of normal symbol `HeaderStr' in c_lto_pr88077_0.o is
smaller than 8 used by the common definition in c_lto_pr88077_1.o

gcc/testsuite/ChangeLog:

* gcc.dg/lto/pr88077_0.c: Change type to match alignment for SPARC

18 months agotestsuite: Skip ifcvt-4.c for SPARC V8
Daniel Cederman [Mon, 8 Jan 2024 08:08:43 +0000 (09:08 +0100)] 
testsuite: Skip ifcvt-4.c for SPARC V8

Conditional moves are not available in SPARC V8.

gcc/testsuite/ChangeLog:

* gcc.dg/ifcvt-4.c: Skip for SPARC V8

18 months agosparc: Treat instructions with length 0 as empty
Daniel Cederman [Tue, 5 Dec 2023 14:26:27 +0000 (15:26 +0100)] 
sparc: Treat instructions with length 0 as empty

This is to handle the membar_empty instruction that can be generated
when compiling for UT699.

gcc/ChangeLog:

* config/sparc/sparc.cc (next_active_non_empty_insn): Length 0 treated as empty

18 months agosparc: Add errata workaround to membar patterns
Daniel Cederman [Thu, 4 Jan 2024 13:56:06 +0000 (14:56 +0100)] 
sparc: Add errata workaround to membar patterns

LEON now uses the standard V8 membar patterns that contains an ldstub
instruction. This instruction needs to be aligned properly when the
GR712RC errata workaround is enabled.

gcc/ChangeLog:

* config/sparc/sparc.cc (atomic_insn_for_leon3_p): Treat membar_storeload as atomic
* config/sparc/sync.md (membar_storeload): Turn into named insn
and add GR712RC errata workaround.
(membar_v8): Add GR712RC errata workaround.

18 months agosparc: Revert membar optimization that is not suitable for LEON5
Andreas Larsson [Mon, 16 Jan 2023 14:43:24 +0000 (15:43 +0100)] 
sparc: Revert membar optimization that is not suitable for LEON5

LEON5 has a deeper write-buffer and hence stb is not enough to flush a
write out. For compatibility, use the default V8 approach for both
LEON3 and LEON5.

This reverts commit 49cc765db35a5a21cab2aece27a44983fa70b94b,
"sync.md (*membar_storeload_leon3): New insn."

gcc/ChangeLog:

* config/sparc/sync.md (*membar_storeload_leon3): Remove
(*membar_storeload): Enable for LEON

18 months agoFix crash of -fdump-ada-spec in a pathological case
Eric Botcazou [Tue, 16 Jan 2024 11:15:31 +0000 (12:15 +0100)] 
Fix crash of -fdump-ada-spec in a pathological case

gcc/c-family/
PR ada/113397
* c-ada-spec.cc (check_type_name_conflict): Add guard for the
presence of DECL_NAME on a TYPE_DECL.

18 months agocfgexpand: Workaround CSE of ADDR_EXPRs in VAR_DECL partitioning [PR113372]
Jakub Jelinek [Tue, 16 Jan 2024 10:49:34 +0000 (11:49 +0100)] 
cfgexpand: Workaround CSE of ADDR_EXPRs in VAR_DECL partitioning [PR113372]

The following patch adds a quick workaround to bugs in VAR_DECL
partitioning.
The problem is that there is no dependency between ADDR_EXPRs of local
decls and CLOBBERs of those vars, so VN can CSE uses of ADDR_EXPRs
(including ivopts integral variants thereof), which can break
add_scope_conflicts discovery of what variables are actually used
in certain region.
E.g. we can have
  ivtmp.40_3 = (unsigned long) &MEM <unsigned long[100]> [(void *)&bitint.6 + 8B];
...
  uses of ivtmp.40_3
...
  bitint.6 ={v} {CLOBBER(eos)};
...
  ivtmp.28_43 = (unsigned long) &MEM <unsigned long[100]> [(void *)&bitint.6 + 8B];
...
  uses of ivtmp.28_43
before VN (such as dom3), which the add_scope_conflicts code identifies as 2
independent uses of bitint.6 variable (which is correct), but then VN
determines ivtmp.28_43 is the same as ivtmp.40_3 and just uses ivtmp.40_3
even in the second region; at that point add_scope_conflict thinks the
bitint.6 variable is not used in that region anymore.

The following patch does a simple single def-stmt check for such ADDR_EXPRs
(rather than say trying to do a full propagation of what SSA_NAMEs can
contain ADDR_EXPRs of local variables), which seems to workaround all 4 PRs.

In addition to this patch I've used the attached one to gather statistics
on the total size of all variable partitions in a function and seems besides
the new testcases nothing is really affected compared to no patch (I've
actually just modified the patch to == OMP_SCAN instead of == ADDR_EXPR, so
it looks the same except that it never triggers).  The comparison wasn't
perfect because I've only gathered BITS_PER_WORD, main_input_filename (did
some replacement of build directories and /tmp/ccXXXXXX names of LTO to make
it more similar between the two bootstraps/regtests), current_function_name
and the total size of all variable partitions if any, because I didn't
record e.g. the optimization options and so e.g. torture tests which iterate
over options could have different partition sizes even in one compiler when
BITS_PER_WORD, main_input_filename and current_function_name are all equal.
So had to write an awk script to check if the first triple in the second
build appeared in the first one and the quadruple in the second build
appeared in the first one too, otherwise print result and that only
triggered in the new tests.
Also, the cc1plus binary according to objdump -dr is identical between the
two builds except for the ADDR_EXPR vs. OMP_SCAN constant in the two spots.

2024-01-16  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/113372
PR middle-end/90348
PR middle-end/110115
PR middle-end/111422
* cfgexpand.cc (add_scope_conflicts_2): New function.
(add_scope_conflicts_1): Use it.

* gcc.dg/torture/bitint-49.c: New test.
* gcc.c-torture/execute/pr90348.c: New test.
* gcc.c-torture/execute/pr110115.c: New test.
* gcc.c-torture/execute/pr111422.c: New test.

18 months agoAVR: Add AVR16EB, AVR16EA and AVR32EA devices.
Georg-Johann Lay [Tue, 16 Jan 2024 10:38:06 +0000 (11:38 +0100)] 
AVR: Add AVR16EB, AVR16EA and AVR32EA devices.

gcc/
* config/avr/avr-mcus.def (avr16eb14, avr16eb20, avr16eb28, avr16eb32)
(avr16ea28, avr16ea32, avr16ea48, avr32ea28, avr32ea32, avr32ea48): Add.
* doc/avr-mmcu.texi: Regenerate.

18 months agoDo not count unused scalar use when marking STMT_VINFO_LIVE_P [PR113091]
Feng Xue [Thu, 28 Dec 2023 08:55:39 +0000 (16:55 +0800)] 
Do not count unused scalar use when marking STMT_VINFO_LIVE_P [PR113091]

When pattern recognition is involved, a statement whose definition is
consumed in some pattern, may not be included in the final replacement
pattern statements, and would be skipped when building SLP graph.

 * Original
  char a_c = *(char *) a;
  char b_c = *(char *) b;
  unsigned short a_s = (unsigned short) a_c;
  int a_i = (int) a_s;
  int b_i = (int) b_c;
  int r_i = a_i - b_i;

 * After pattern replacement
  a_s = (unsigned short) a_c;
  a_i = (int) a_s;

  patt_b_s = (unsigned short) b_c;    // b_i = (int) b_c
  patt_b_i = (int) patt_b_s;          // b_i = (int) b_c

  patt_r_s = widen_minus(a_c, b_c);   // r_i = a_i - b_i
  patt_r_i = (int) patt_r_s;          // r_i = a_i - b_i

The definitions of a_i(original statement) and b_i(pattern statement)
are related to, but actually not part of widen_minus pattern.
Vectorizing the pattern does not cause these definition statements to
be marked as PURE_SLP.  For this case, we need to recursively check
whether their uses are all absorbed into vectorized code.  But there
is an exception that some use may participate in an vectorized
operation via an external SLP node containing that use as an element.

gcc/ChangeLog:

PR tree-optimization/113091
* tree-vect-slp.cc (vect_slp_has_scalar_use): New function.
(vect_bb_slp_mark_live_stmts): New parameter scalar_use_map, check
scalar use with new function.
(vect_bb_slp_mark_live_stmts): New function as entry to existing
overriden functions with same name.
(vect_slp_analyze_operations): Call new entry function to mark
live statements.

gcc/testsuite/ChangeLog:

* gcc.target/aarch64/bb-slp-pr113091.c: New test.