]> git.ipfire.org Git - people/ms/gcc.git/log
people/ms/gcc.git
2 years 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>
2 years 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>
2 years 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>
2 years 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>
2 years 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>
2 years 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>
2 years 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>
2 years 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>
2 years 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

2 years 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>
2 years 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>
2 years agobuild: Regenerate build files
Pierre-Emmanuel Patry [Thu, 9 Mar 2023 14:29:08 +0000 (15:29 +0100)] 
build: Regenerate build files

Regenerate all build files.

ChangeLog:

* Makefile.in:
* configure: Regenerate.
* libgrust/Makefile.in: New file.
* libgrust/aclocal.m4: New file.
* libgrust/configure: New file.
* libgrust/libproc_macro/Makefile.in: New file.

libgm2/ChangeLog:

* Makefile.in: Regenerate.
* aclocal.m4: Regenerate.
* libm2cor/Makefile.in: Regenerate.
* libm2iso/Makefile.in: Regenerate.
* libm2log/Makefile.in: Regenerate.
* libm2min/Makefile.in: Regenerate.
* libm2pim/Makefile.in: Regenerate.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2 years agobuild: Add libgrust as compilation modules
Pierre-Emmanuel Patry [Mon, 27 Feb 2023 16:10:38 +0000 (17:10 +0100)] 
build: Add libgrust as compilation modules

Define the libgrust directory as a host compilation module as well as
for targets.

ChangeLog:

* Makefile.def: Add libgrust as host & target module.
* configure.ac: Add libgrust to host tools list.

gcc/rust/ChangeLog:

* config-lang.in: Add libgrust as a target module for the rust
language.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2 years agolibrust: Add libproc_macro and build system
Pierre-Emmanuel Patry [Wed, 22 Feb 2023 16:14:24 +0000 (17:14 +0100)] 
librust: Add libproc_macro and build system

Add some dummy files in libproc_macro along with it's build system.

ChangeLog:

* libgrust/Makefile.am: New file.
* libgrust/configure.ac: New file.
* libgrust/libproc_macro/Makefile.am: New file.
* libgrust/libproc_macro/proc_macro.cc: New file.
* libgrust/libproc_macro/proc_macro.h: New file.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2 years agoresolve: Handle multiple bindings to the same identifier
Mahmoud Mohamed [Mon, 13 Mar 2023 14:18:11 +0000 (17:18 +0300)] 
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>
2 years agohir: Improve pattern bindings handling in closure parameters
Mahmoud Mohamed [Tue, 14 Mar 2023 22:06:46 +0000 (01:06 +0300)] 
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>
2 years agogccrs: Rename compiler proper
Arthur Cohen [Tue, 14 Mar 2023 16:28:54 +0000 (17:28 +0100)] 
gccrs: Rename compiler proper

ChangeLog:

* README.md (process): Rename `rust1` to `crab1` in examples.

gcc/rust/ChangeLog:

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

2 years agoAdd method to access SlicePattern items
Owen Avery [Tue, 14 Mar 2023 23:17:26 +0000 (19:17 -0400)] 
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>
2 years agoConvert structs to classes
Owen Avery [Tue, 14 Mar 2023 22:52:50 +0000 (18:52 -0400)] 
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>
2 years agoHIR::AltPattern fixes
Owen Avery [Tue, 14 Mar 2023 21:35:16 +0000 (17:35 -0400)] 
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>
2 years agohir: Add ExportedMacro node and handling.
Arthur Cohen [Wed, 1 Mar 2023 11:35:18 +0000 (12:35 +0100)] 
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.

2 years agohir: Provide basic handling for ReferencePattern in function parameter
Mahmoud Mohamed [Tue, 7 Mar 2023 23:57:24 +0000 (02:57 +0300)] 
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>
2 years agoenr: Fetch module items during early name resolution
Arthur Cohen [Thu, 2 Mar 2023 15:56:33 +0000 (16:56 +0100)] 
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.

2 years agohir: Simplify indentation to single line
Jakub Dupak [Sat, 11 Mar 2023 19:50:09 +0000 (20:50 +0100)] 
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>
2 years agohir: Unify indentation approach with ast
Jakub Dupak [Sat, 11 Mar 2023 19:36:11 +0000 (20:36 +0100)] 
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>
2 years agohir: Fix ReferencePattern typechecking
Mahmoud Mohamed [Sun, 12 Mar 2023 23:26:13 +0000 (02:26 +0300)] 
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>
2 years 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>
2 years agohir: add a helper function for visit
vincent [Tue, 7 Mar 2023 20:32:04 +0000 (20:32 +0000)] 
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>
2 years agotypecheck: Add basic typechecking for ReferenceType
goar5670 [Mon, 6 Mar 2023 22:25:39 +0000 (01:25 +0300)] 
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>
2 years agoAdd coherence related lang_items
Owen Avery [Tue, 7 Mar 2023 18:37:08 +0000 (13:37 -0500)] 
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.

2 years agoAdd AltPattern HIR node
Owen Avery [Mon, 20 Feb 2023 19:46:03 +0000 (14:46 -0500)] 
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>
2 years agoexpand: Add stringify macro
Pierre-Emmanuel Patry [Mon, 6 Mar 2023 08:58:02 +0000 (09:58 +0100)] 
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>
2 years agoAdd length checking for tuple patterns
Nikos Alexandris [Fri, 3 Mar 2023 21:55:59 +0000 (23:55 +0200)] 
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>
2 years agoparser: Fix handling of multiple left angles in null denotation
goar5670 [Sat, 4 Mar 2023 19:13:18 +0000 (22:13 +0300)] 
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>
2 years agoCleanup and Assertion
Parthib [Mon, 6 Mar 2023 02:04:43 +0000 (07:34 +0530)] 
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>
2 years agoResolve closure parameters without given type
Owen Avery [Sat, 4 Mar 2023 01:05:59 +0000 (20:05 -0500)] 
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>
2 years 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.

2 years 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

2 years 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

2 years 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

2 years 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

2 years 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

2 years 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

2 years agoparser: Fix parsing closure parameter
goar5670 [Thu, 2 Mar 2023 18:34:44 +0000 (21:34 +0300)] 
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>
2 years agoparser: Fix while let expr parsing
Pierre-Emmanuel Patry [Wed, 1 Mar 2023 16:45:51 +0000 (17:45 +0100)] 
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>
2 years 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.

2 years agoparser: Add 0 sized slice pattern parsing
Pierre-Emmanuel Patry [Wed, 1 Mar 2023 17:46:33 +0000 (18:46 +0100)] 
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>
2 years agofixup: parser: Fix bootstrap compile error
Pierre-Emmanuel Patry [Wed, 1 Mar 2023 09:04:04 +0000 (10:04 +0100)] 
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>
2 years agoadded support for printing HIR dump of functions, statements, arithematic/logical...
Abdul Rafey [Mon, 27 Feb 2023 12:01:31 +0000 (17:31 +0530)] 
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>
2 years agoAdd location info when opening a file fails in include_str and include_bytes. Resolve...
Nikos Alexandris [Thu, 2 Mar 2023 01:14:46 +0000 (03:14 +0200)] 
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>
2 years agotestsuite: Add a test for .. in slice patterns
Pierre-Emmanuel Patry [Wed, 1 Mar 2023 10:36:42 +0000 (11:36 +0100)] 
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>
2 years agoparser: Add RestPattern parsing
Pierre-Emmanuel Patry [Wed, 1 Mar 2023 10:00:29 +0000 (11:00 +0100)] 
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>
2 years agoast: Add NodeId and clone to RestPattern
Pierre-Emmanuel Patry [Wed, 1 Mar 2023 09:54:29 +0000 (10:54 +0100)] 
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>
2 years agotestsuite: Add a test for if let syntax
Pierre-Emmanuel Patry [Wed, 1 Mar 2023 13:20:23 +0000 (14:20 +0100)] 
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>
2 years agoparser: Fix if let parsing
Pierre-Emmanuel Patry [Wed, 1 Mar 2023 13:13:01 +0000 (14:13 +0100)] 
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>
2 years 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.

2 years agohir: Refactor ASTLoweringStmt to source file.
Arthur Cohen [Wed, 1 Mar 2023 10:03:24 +0000 (11:03 +0100)] 
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.

2 years agoAdd feature gate definition for `extern_types`.
mxlol233 [Wed, 1 Mar 2023 11:31:19 +0000 (19:31 +0800)] 
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>
2 years agoFix assignment operator overloads for AST and HIR patterns
Owen Avery [Mon, 27 Feb 2023 16:18:56 +0000 (11:18 -0500)] 
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>
2 years agotypecheck: Fix casting error behind generics
bl7awy [Tue, 28 Feb 2023 17:53:01 +0000 (20:53 +0300)] 
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>
2 years agoChange struct StructPatternElements into class
Owen Avery [Mon, 27 Feb 2023 16:02:02 +0000 (11:02 -0500)] 
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>
2 years agoReplace gcc_unreachable with rust_sorry_at
Owen Avery [Mon, 27 Feb 2023 15:23:19 +0000 (10:23 -0500)] 
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>
2 years agoFix formatting
Owen Avery [Mon, 20 Feb 2023 21:05:41 +0000 (16:05 -0500)] 
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>
2 years agoast: Add RestPattern AST node
Pierre-Emmanuel Patry [Tue, 28 Feb 2023 16:34:31 +0000 (17:34 +0100)] 
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>
2 years 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

2 years 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.

2 years 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

2 years 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

2 years 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

2 years 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

2 years 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

2 years 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.

2 years 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

2 years 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

2 years agotestsuite: Add test with missing semicolon
Pierre-Emmanuel Patry [Mon, 27 Feb 2023 13:08:10 +0000 (14:08 +0100)] 
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>
2 years agotestsuite: Add extern type item test
Pierre-Emmanuel Patry [Mon, 27 Feb 2023 13:07:00 +0000 (14:07 +0100)] 
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>
2 years agoparser: Parse external type item
Pierre-Emmanuel Patry [Mon, 27 Feb 2023 09:10:51 +0000 (10:10 +0100)] 
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>
2 years agoImplement and test include_str eager expansion
omkar-mohanty [Thu, 16 Feb 2023 04:40:24 +0000 (10:10 +0530)] 
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>
2 years agoparser: Parse `default` impl Functions and Methods
Arthur Cohen [Thu, 23 Feb 2023 14:11:04 +0000 (15:11 +0100)] 
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.

2 years agotypecheck: Refactor cast_site
Pierre-Emmanuel Patry [Thu, 23 Feb 2023 18:00:07 +0000 (19:00 +0100)] 
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>
2 years agoast: Add proper visitors for ExternalTypeItem
Arthur Cohen [Thu, 23 Feb 2023 15:59:20 +0000 (16:59 +0100)] 
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.

2 years agoast: Add ExternalTypeItem node
Arthur Cohen [Thu, 23 Feb 2023 15:50:39 +0000 (16:50 +0100)] 
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.

2 years agomacro_invoc_lexer: Add `split_current_token` implementation
Arthur Cohen [Tue, 21 Feb 2023 12:51:54 +0000 (13:51 +0100)] 
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.

2 years agoMerge remote-tracking branch 'upstream/tschwinge/merge-upstream'
Arthur Cohen [Thu, 23 Feb 2023 15:02:43 +0000 (16:02 +0100)] 
Merge remote-tracking branch 'upstream/tschwinge/merge-upstream'

2 years agoparser: Add parsing of auto traits
Arthur Cohen [Wed, 15 Feb 2023 15:53:41 +0000 (16:53 +0100)] 
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.

2 years agotypecheck: Refactor coercion_site
Pierre-Emmanuel Patry [Wed, 22 Feb 2023 09:44:16 +0000 (10:44 +0100)] 
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>
2 years agoMerge upstream (dummy), 2023-02-21 "Rust front-end update"
Thomas Schwinge [Wed, 22 Feb 2023 07:43:44 +0000 (08:43 +0100)] 
Merge upstream (dummy), 2023-02-21 "Rust front-end update"

In #1908 'Merge upstream, last commit before 2023-02-21 "Rust front-end update"'
we merged commit ecc863e85efe259c799515de0c38c2297b0e3bd7 from upstream GCC
master branch.

This one now merges the 2023-02-21 "Rust front-end update", commits
ecc863e85efe259c799515de0c38c2297b0e3bd7..ecb409b23b86363fa085ec32e89e1aeda002cb70:

      - 7e7a95880443 gccrs: Fix missing dead code analysis ICE on local enum definition
      - 708085446189 gccrs: visibility: Rename get_public_vis_type -> get_vis_type
      - 1e8eb1022009 gccrs: dump: Emit visibility when dumping items
      - 543ba35905b9 gccrs: Add catch for recusive type queries
      - d072b4a5164e gccrs: testing: try loop in const function
      - 980bd25e2560 gccrs: ast: dump assignment and compound assignment expr
      - aeed747093c2 gccrs: ast: dump If expressions
      - 00e0684a78a3 gccrs: builtins: Move implementation into source file
      - 79434fabf762 gccrs: Track DefId on ADT variants
      - 31b77593edbf gccrs: Ensure uniqueness on Path probe's
      - a5d3586a9b15 gccrs: Support looking up super traits for trait items
      - 8d02ef57a691 gccrs: ast: dump: add emit_generic_params helper
      - 4c807ef70db1 gccrs: ast: dump: add format_{tuple,struct}_field helpers
      - 0a762d204980 gccrs: ast: dump structs, enums and unions
      - ab6d8ad3f595 gccrs: intrinsics: Add data prefetching intrinsics
      - 570415e75c42 gccrs: fix ICE on missing closing paren
      - a08f265625e5 gccrs: mappings: Add MacroInvocation -> MacroRulesDef mappings
      - 295cd2650888 gccrs: rust-ast-resolve-item: Add note about resolving glob uses
      - 2f1035fc91ce gccrs: ast: Add accept_vis() method to `GenericArg`
      - 522197469179 gccrs: early-name-resolver: Add simple macro name resolution
      - 13556413e384 gccrs: Support type resolution on super traits on dyn objects
      - f49e25282413 gccrs: Add mappings for fn_once lang item
      - 2d7661e76e12 gccrs: Add ABI mappings for rust-call to map to ABI::RUST
      - 59bee4d4663e gccrs: Method resolution must support multiple candidates
      - b1510ce0fc77 gccrs: ast: dump: fix extra newline in block without tail
      - 0a9114c151b8 gccrs: ast: dump: minor fixups to IfExpr formatting
      - c091fd5f4a2d gccrs: ast: dump: ComparisonExpr and LazyBooleanExpr
      - f26e9ca3e9aa gccrs: ast: dump: ArrayExpr
      - d1db46191ea5 gccrs: ast: dump: various simple Exprs
      - 173f98ae49d8 gccrs: ast: dump: RangeExprs
      - 74065c000e33 gccrs: Refactor TraitResolver to not require a visitor
      - acbaadfa46d0 gccrs: ast: dump TypeAlias
      - 8f0b1526e04c gccrs: Support outer attribute handling on trait items just like normal items
      - 421494b5929f gccrs: dump: Emit visibility when dumping items
      - 31150a6366db gccrs: dump: Dump items within modules
      - 2f16df1b4433 gccrs: dump: Fix module dumping
      - e535b7b3e385 gccrs: ast: Module: unloaded module and inner attributes
      - ec28fdb6aad3 gccrs: dump: Dump macro rules definition
      - 643ec1c253d9 gccrs: Add check for recursive trait cycles
      - e2647e5e5ad1 gccrs: ast: Refactor ASTFragment -> Fragment class
      - 68e743090df6 gccrs: rust: Replace uses of ASTFragment -> Fragment
      - b326cced19e5 gccrs: ast: Improve Fragment API
      - ed75e142a708 gccrs: Add missing fn_once_output langitem
      - 870dd9d5d3c5 gccrs: Refactor expression hir lowering into cc file
      - 9e19f329e523 gccrs: Formatting cleanup in HIR lowering pattern
      - 977e0e5227d4 gccrs: Add name resolution for closures
      - 4d021d9e019d gccrs: Refactor method call type checking
      - 898240946ca2 gccrs: Add closures to lints and error checking
      - 740a1997228d gccrs: Initial Type resolution for closures
      - 699e7e862763 gccrs: Closure support at CallExpr
      - 12e94515f894 gccrs: Add missing name resolution to Function type-path segments
      - 875f722de5ea gccrs: Add missing hir lowering to function type-path segments
      - 51d180fcd7e6 gccrs: Add missing type resolution for function type segments
      - 21d19d2cf606 gccrs: Support Closure calls as generic trait bounds
      - a8531cd9a82a gccrs: Implement the inline visitor
      - 6ef1089ec27e gccrs: rust: Allow gccrs to build on x86_64-apple-darwin with clang/libc++
      - 4d39d3912ffe gccrs: builtins: Rename all bang macro handlers
      - 782e070374ac gccrs: intrinsics: Add `sorry_handler` intrinsic handler
      - 514284ecd97f gccrs: constexpr: Add `rust_sorry_at` in places relying on init values
      - a7c8f7ee3433 gccrs: intrinsics: Add early implementation for atomic_store_{seqcst, relaxed, release}
      - 1c586a1d1c12 gccrs: intrinsics: Add unchecked operation intrinsics
      - cb2cf21cf336 gccrs: intrinsics: Use lambdas for wrapping_<op> intrinsics
      - f4c818c623c0 gccrs: intrinsics: Cleanup error handling around atomic_store_*
      - 5b5a0ca77179 gccrs: intrinsics: Implement atomic_load intrinsics
      - aedd97a537cb gccrs: ast: visitor pattern -> overload syntax compatibility layer
      - 3b5fb3f89b0f gccrs: ast: transform helper methods to visits and add methods to simplify repeated patterns
      - a56faba96369 gccrs: ast: refer correctly to arguments in docs-strings
      - 04a16c58e343 gccrs: ast: Dump unit struct
      - 2fc013036041 gccrs: add lang item "phantom_data"
      - b84222899cac gccrs: add Location to AST::Visibility
      - 85f69a9b6abd gccrs: typecheck: Fix overzealous `delete` call
      - 907d11194ed9 gccrs: ast: add visit overload for references
      - bd2240d30f80 gccrs: ast: Dump where clause and recursively needed nodes
      - 59fb0747cc2c gccrs: ast: Dump slice type
      - 140a2aed7e1c gccrs: ast: Dump array type
      - 971d16cbfade gccrs: ast: Dump raw pointer type
      - c4c859bff8d0 gccrs: ast: Dump never type
      - 91409d27d5c5 gccrs: ast: Dump tuple type
      - ee0166fa1b88 gccrs: ast: Dump inferred type
      - ae1f6b3a96dd gccrs: ast: Dump bare function type
      - ca06115eac10 gccrs: ast: Dump impl trait type one bound
      - 638f65b20832 gccrs: ast: Dump impl trait type
      - 7ed4a0ebc1d1 gccrs: ast: Dump trait object type
      - e311e9b7c591 gccrs: ast: Dump parenthesised type
      - 0bb33cb5741e gccrs: ast: Dump trait object type one bound
      - 1acb7e02ed82 gccrs: ast: Dump type param type
      - b8863414eda2 gccrs: ast: Dump generic parameters
      - ce13edd879da gccrs: ast: Remove unused include in rust-ast-dump.cc
      - 0e44abb1b509 gccrs: ast: Dump remove /* stmp */ comment to not clutter the dump
      - 567494f7030b gccrs: ast: Dump no comma after self in fn params if it is the last one
      - 78c70a50f744 gccrs: Remove default location. Add visibility location to create_* functions
      - 0ef795c3278e gccrs: Improve lexer dump
      - 01af669357c4 gccrs: Get rid of make builtin macro
      - 32a4659c5e40 gccrs: Refactor name resolver to take a Rib::ItemType
      - f7c258b29118 gccrs: Add closure binding's tracking to name resolution
      - eb1202224f8e gccrs: Add capture tracking to the type info for closures
      - 92389b46a96c gccrs: Add initial support for argument capture of closures
      - e7a69d4533ad gccrs: Fix undefined behaviour issues on macos
      - 03df9a040c97 gccrs: Skip this debug test case which is failing on the latest mac-os devtools and its only for debug info
      - 9f455ed820cc gccrs: Cleanup unused parameters to fix the bootstrap build
      - b9203d82ad27 gccrs: Repair 'gcc/rust/lang.opt' comment
      - 064bbd0fe104 gccrs: const evaluator: Remove get_nth_callarg
      - ecb409b23b86 gccrs: add math intrinsics

..., and:

      - e28c5b33b987 Update copyright years.

This merge is done with 'git merge --strategy=ours', so effectively doesn't
merge any changes.  Rationale: those commits are taken from GCC/Rust master
branch, and any remaining changes we'd either like to persist, or assess
individually, later.

2 years agotypecheck: Refactor unify_site
Pierre-Emmanuel Patry [Tue, 21 Feb 2023 16:29:53 +0000 (17:29 +0100)] 
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>
2 years agoci: Run GCC 4.8 job in Ubuntu 18.04 container
Arthur Cohen [Tue, 21 Feb 2023 13:08:10 +0000 (14:08 +0100)] 
ci: Run GCC 4.8 job in Ubuntu 18.04 container

We should probably think about building GCC 4.8 from source from time
to time and hosting the image on our Dockerhub, but I think this is okay
as well for now.

ChangeLog:

* .github/workflows/ccpp.yml: Run GCC 4.8 action in ubuntu 18.04 container

2 years agoAdjust '.github/bors_log_expected_warnings'
Thomas Schwinge [Tue, 21 Feb 2023 21:37:04 +0000 (22:37 +0100)] 
Adjust '.github/bors_log_expected_warnings'

2 years agoMerge commit 'ecc863e85efe259c799515de0c38c2297b0e3bd7' into HEAD
Thomas Schwinge [Tue, 21 Feb 2023 20:13:49 +0000 (21:13 +0100)] 
Merge commit 'ecc863e85efe259c799515de0c38c2297b0e3bd7' into HEAD

2 years agoMerge commit '7b8916a6fd098546e4e53e53b37a5153664ba17f' into HEAD [#1819, #1864,...
Thomas Schwinge [Tue, 21 Feb 2023 19:48:38 +0000 (20:48 +0100)] 
Merge commit '7b8916a6fd098546e4e53e53b37a5153664ba17f' into HEAD [#1819, #1864, #1885]

2 years agoMerge commit 'ae113080a9f98e807db239f3ad2157c64324542f' into HEAD
Thomas Schwinge [Tue, 21 Feb 2023 19:47:19 +0000 (20:47 +0100)] 
Merge commit 'ae113080a9f98e807db239f3ad2157c64324542f' into HEAD

2 years agoUpdate copyright years.
Thomas Schwinge [Tue, 21 Feb 2023 12:49:42 +0000 (13:49 +0100)] 
Update copyright years.

... which accidentally had gotten reverted in recent
commit r13-6156-g1e8eb102200902e12c1b00e867e338be0a92c292
"gccrs: dump: Emit visibility when dumping items".

2 years agogccrs: add math intrinsics
Raiki Tamura [Thu, 15 Dec 2022 17:27:59 +0000 (02:27 +0900)] 
gccrs: add math intrinsics

gcc/rust/ChangeLog:

* backend/rust-builtins.cc (BuiltinsContext::setup_math_fns): New functions.

gcc/testsuite/ChangeLog:

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

2 years agogccrs: const evaluator: Remove get_nth_callarg
Arthur Cohen [Thu, 17 Nov 2022 15:50:58 +0000 (16:50 +0100)] 
gccrs: const evaluator: Remove get_nth_callarg

We only used one path of the C++ folder's get_nth_callarg function:
CALL_EXPR_ARG. Replace all calls to get_nth_callarg by macro calls to
CALL_EXPR_ARG

gcc/rust/ChangeLog:

* backend/rust-constexpr.cc (get_nth_callarg): Remove function.
(rs_bind_parameters_in_call): Use CALL_EXPR_ARG instead.
(potential_constant_expression_1): Likewise.

2 years agogccrs: Repair 'gcc/rust/lang.opt' comment
Thomas Schwinge [Wed, 7 Dec 2022 08:18:26 +0000 (09:18 +0100)] 
gccrs: Repair 'gcc/rust/lang.opt' comment

... lost in #1527 commit 138a6260124740208b8f3aff2e38617f43b05fe8
"rust: Add -frust-compile-until option".

gcc/rust/ChangeLog:

* lang.opt: Fix ordering of file.

2 years agogccrs: Cleanup unused parameters to fix the bootstrap build
Philip Herron [Mon, 5 Dec 2022 02:20:55 +0000 (02:20 +0000)] 
gccrs: Cleanup unused parameters to fix the bootstrap build

gcc/rust/ChangeLog:

* backend/rust-compile-type.cc (TyTyResolveCompile::visit): Remove unused parameters.
* backend/rust-constexpr.cc (constant_value_1): Likewise.
(fold_non_dependent_init): Likewise.
* backend/rust-tree.cc (publicly_uniquely_derived_p): Likewise.
(instantiation_dependent_expression_p): Likewise.
(type_has_nontrivial_copy_init): Likewise.
(is_normal_capture_proxy): Likewise.
(resolve_nondeduced_context): Likewise.
(undeduced_auto_decl): Likewise.
(require_deduced_type): Likewise.
* checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::visit): Likewise.
* checks/errors/privacy/rust-reachability.cc (ReachabilityVisitor::visit): Likewise.
* checks/errors/privacy/rust-visibility-resolver.cc (VisibilityResolver::visit): Likewise.
* checks/errors/rust-const-checker.cc (ConstChecker::visit): Likewise.
* checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Likewise.
* checks/lints/rust-lint-marklive.cc (MarkLive::go): Likewise.
* checks/lints/rust-lint-unused-var.cc (unused_var_walk_fn): Likewise.
* expand/rust-macro-builtins.cc (try_expand_single_string_literal): Likewise.
(try_expand_many_expr): Likewise.
(parse_single_string_literal): Likewise.
(MacroBuiltin::assert_handler): Likewise.
(MacroBuiltin::file_handler): Likewise.
(MacroBuiltin::column_handler): Likewise.
(MacroBuiltin::concat_handler): Likewise.
(MacroBuiltin::env_handler): Likewise.
(MacroBuiltin::line_handler): Likewise.
* hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Likewise.
(ASTLoweringBase::handle_doc_item_attribute): Likewise.
* hir/rust-hir-dump.cc (Dump::visit): Likewise.
* hir/tree/rust-hir-full-test.cc (ConstGenericParam::accept_vis): Likewise.
* lex/rust-lex.cc (Lexer::parse_utf8_escape): Likewise.
(Lexer::parse_string): Likewise.
(Lexer::parse_char_or_lifetime): Likewise.
* lex/rust-lex.h: Likewise.
* metadata/rust-export-metadata.cc: Likewise.
* resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit): Likewise.
* resolve/rust-ast-resolve-type.cc (ResolveType::visit): Likewise.
(ResolveTypeToCanonicalPath::visit): Likewise.
* resolve/rust-ast-verify-assignee.h: Likewise.
* resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit): Likewise.
* typecheck/rust-hir-type-check-expr.h: Likewise.
* typecheck/rust-hir-type-check-item.h: Likewise.
* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit): Likewise.
* typecheck/rust-tyty-rules.h: Likewise.
* util/rust-attributes.cc (AttributeChecker::visit): Likewise.

2 years agogccrs: Skip this debug test case which is failing on the latest mac-os devtools and...
Philip Herron [Mon, 5 Dec 2022 00:31:18 +0000 (00:31 +0000)] 
gccrs: Skip this debug test case which is failing on the latest mac-os devtools and its only for debug info

gcc/testsuite/ChangeLog:

* rust/debug/chartype.rs: Skip testcases on Darwin architectures.

2 years agogccrs: Fix undefined behaviour issues on macos
Philip Herron [Mon, 7 Nov 2022 13:43:04 +0000 (13:43 +0000)] 
gccrs: Fix undefined behaviour issues on macos

This adds missing copy constructors to HIR::PathExprSegment which were
wrongly defaulting to empty vectors when apply specified generic arguments
to method calls.

gcc/rust/ChangeLog:

* hir/tree/rust-hir-expr.h: Add const `get_method_name`.
* hir/tree/rust-hir-full-decls.h (struct GenericArgs): Move from `struct`...
(class GenericArgs): ...to `class`.
* hir/tree/rust-hir-path.h (struct GenericArgs): Likewise.
(class GenericArgs): Clear `type_args` in copy constructor.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Reorder
debug print.
* typecheck/rust-tyty.h: Add default constructors for `SubstitutionArgumentMappings`.