]> gcc.gnu.org Git - gcc.git/log
gcc.git
2 years agoAdd missing bound to impl-type Self
Philip Herron [Thu, 4 Nov 2021 13:34:45 +0000 (13:34 +0000)]
Add missing bound to impl-type Self

2 years agoAdd ImplItemTypes enum to switch between HIR::ImplItem types
Philip Herron [Thu, 4 Nov 2021 12:12:15 +0000 (12:12 +0000)]
Add ImplItemTypes enum to switch between HIR::ImplItem types

2 years agoDesugar AST::TraitObjectTypeOneBound
Philip Herron [Tue, 2 Nov 2021 17:10:24 +0000 (17:10 +0000)]
Desugar AST::TraitObjectTypeOneBound

We have two ways to represent TraitObjectType's:

- AST::TraitObjectType
- AST::TraitObjectTypeOneBound

This desugars this within HIR into a single HIR::TraitObjectType which
contains a list of bounds.

Addresses #786

2 years agoMerge #781
bors[bot] [Tue, 2 Nov 2021 13:54:14 +0000 (13:54 +0000)]
Merge #781

781: Add missing typechecking for enums r=philberty a=philberty

This PR splits up the Algebraic data type into one which can support many variants which is what an enum is.
It then changes the type checking for construction of ADT's to use the VariantDef structures as required. This
does not fully implement but does allow us to have most of the type checking in place to start code-generation work.

This combines work from Mark Wielaard (https://code.wildebeest.org/git/user/mjw/gccrs/commit/?h=enum-type) and Philip

Addresses #79

Co-authored-by: Mark Wielaard <mark@klomp.org>
Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2 years agoMerge #788
bors[bot] [Tue, 2 Nov 2021 11:55:44 +0000 (11:55 +0000)]
Merge #788

788: gccrs: add the `-frust-crate=` option to set the crate name r=philberty a=mathstuf

Signed-off-by: Ben Boeckel <mathstuf@gmail.com>
Fixes: #627
Co-authored-by: Ben Boeckel <mathstuf@gmail.com>
2 years agoDefault type checking on CallExpr's to TyTy::ErrorType
Philip Herron [Tue, 2 Nov 2021 11:48:06 +0000 (11:48 +0000)]
Default type checking on CallExpr's to TyTy::ErrorType

It is ok for type checking to error/fail on a construct within the crate,
we can try our best to continue on to find as many errors as possible. To
achieve this without running into nullptr's we can use the ErrorType node
to signify an error. This also cleans up alot of noise in our error
handling.

2 years agoSupport Typechecking of ADT's of enums
Philip Herron [Sat, 30 Oct 2021 23:02:58 +0000 (00:02 +0100)]
Support Typechecking of ADT's of enums

Enums are ADT's with multiple variants where as structs are ADT's with a
single variant, this changes the typechecking on construction of these to
support enums.

Addresses #79

2 years agogccrs: add the `-frust-crate=` option to set the crate name
Ben Boeckel [Tue, 2 Nov 2021 00:47:21 +0000 (20:47 -0400)]
gccrs: add the `-frust-crate=` option to set the crate name

Signed-off-by: Ben Boeckel <mathstuf@gmail.com>
2 years agoRefactor struct-expr typechecking into its own impl file
Philip Herron [Tue, 2 Nov 2021 10:10:58 +0000 (10:10 +0000)]
Refactor struct-expr typechecking into its own impl file

2 years agoMerge #787
bors[bot] [Tue, 2 Nov 2021 09:12:12 +0000 (09:12 +0000)]
Merge #787

787: gha: save `check-rust` results as artifacts r=philberty a=mathstuf

They will stick around for 90 days (as per GitHub default limits).

     https://docs.github.com/en/actions/advanced-guides/storing-workflow-data-as-artifacts

Signed-off-by: Ben Boeckel <mathstuf@gmail.com>
Fixes: #634
Co-authored-by: Ben Boeckel <mathstuf@gmail.com>
2 years agogha: save `check-rust` results as artifacts
Ben Boeckel [Mon, 1 Nov 2021 22:44:37 +0000 (18:44 -0400)]
gha: save `check-rust` results as artifacts

They will stick around for 90 days (as per GitHub default limits).

     https://docs.github.com/en/actions/advanced-guides/storing-workflow-data-as-artifacts

Signed-off-by: Ben Boeckel <mathstuf@gmail.com>
2 years agoAdd missing ID to variant ids
Philip Herron [Sat, 30 Oct 2021 16:22:19 +0000 (17:22 +0100)]
Add missing ID to variant ids

2 years agoAdd TypePath resolution for enum ctor
Philip Herron [Sat, 30 Oct 2021 15:24:34 +0000 (16:24 +0100)]
Add TypePath resolution for enum ctor

When constructing enums we end up with a path like Enum::discriminant so
we must lookup the variant to figure out how to construct the enum.

Addresses #79

2 years agoGet rid of bad gcc_unreachable
Philip Herron [Sat, 30 Oct 2021 15:20:45 +0000 (16:20 +0100)]
Get rid of bad gcc_unreachable

2 years agoAdd type-resolution for enum items
Mark Wielaard [Sat, 30 Oct 2021 14:59:01 +0000 (15:59 +0100)]
Add type-resolution for enum items

This patch does the type resolution to actually create the types when we
encounter enums within toplevel HIR::Items and HIR::Stmt conext's.

We don't support actual creation of enums yet in this patch but this is
an isolated building block.

Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Addresses #79

2 years agoRefactor ADTType to consist of multiple variants
Philip Herron [Fri, 29 Oct 2021 16:38:29 +0000 (17:38 +0100)]
Refactor ADTType to consist of multiple variants

Algebraic data types represent Structs, Tuple Structs, unit
structs and enums in rust. The key difference here is that
each of these are an ADT with a single variant and enums
are an ADT with multiple variants.

It adds indirection to where the fields of an ADT are
managed.

Co-authored-by: Mark Wielaard <mark@klomp.org>
Addresses #79

2 years agoExtract reuseable function to handle substitutions for struct fields
Mark Wielaard [Fri, 29 Oct 2021 16:36:56 +0000 (17:36 +0100)]
Extract reuseable function to handle substitutions for struct fields

2 years agoGet rid of lambda get_fields in struct
Mark Wielaard [Fri, 29 Oct 2021 16:34:13 +0000 (17:34 +0100)]
Get rid of lambda get_fields in struct

2 years agoAdd missing accessors for enum items
Mark Wielaard [Fri, 29 Oct 2021 15:39:31 +0000 (16:39 +0100)]
Add missing accessors for enum items

2 years agoMerge #783
bors[bot] [Mon, 1 Nov 2021 11:52:51 +0000 (11:52 +0000)]
Merge #783

783: Get rid of lambda within `AST::TypePath` and provide a method to return a reference r=philberty a=diohabara

## Related issue

This PR will fix <https://github.com/Rust-GCC/gccrs/issues/718>

- \[x] GCC development requires copyright assignment or the Developer's Certificate of Origin sign-off, see https://gcc.gnu.org/contribute.html or https://gcc.gnu.org/dco.html
- \[x] Read contributing guidlines
- \[x] `make check-rust` passes locally
- \[x] Run `clang-format`
- \[x] Added any relevant test cases to `gcc/testsuite/rust/`

Note that you can skip the above if you are just opening a WIP PR in
order to get feedback.

Co-authored-by: Kadoi Takemaru <diohabara@gmail.com>
2 years agoGet rid of lambda within AST::TypePath and provide a method to return a reference
Kadoi Takemaru [Sun, 31 Oct 2021 13:22:21 +0000 (22:22 +0900)]
Get rid of lambda within AST::TypePath and provide a method to return a reference

Remove lambda expressions within AST::TypePath and use get_segments() to
iterate over AST::TypePathSegment

Fixes #718

Signed-off-by: Kadoi Takemaru <diohabara@gmail.com>
2 years agoMerge #780
bors[bot] [Sat, 30 Oct 2021 12:30:50 +0000 (12:30 +0000)]
Merge #780

780: No side effects in 'assert' expressions r=philberty a=tschwinge

Usually, if 'assert'ions are disabled, 'assert' expressions are not evaluated,
so in that case won't effect any side effects.

Via spurious ICEs/test suite FAILs, this may be observed in GCC/Rust, for
example, if configuring with '--enable-checking=no' and disabling a "more
forgiving" 'gcc/system.h:gcc_assert' definition, so that '0 && (EXPR)' gets
used:

     /* Use gcc_assert(EXPR) to test invariants.  */
     #if ENABLE_ASSERT_CHECKING
     #define gcc_assert(EXPR)                                               \
        ((void)(!(EXPR) ? fancy_abort (__FILE__, __LINE__, __FUNCTION__), 0 : 0))
    -#elif (GCC_VERSION >= 4005)
    +#elif (0) //GCC_VERSION >= 4005)
     #define gcc_assert(EXPR)                                               \
       ((void)(__builtin_expect (!(EXPR), 0) ? __builtin_unreachable (), 0 : 0))
     #else
     /* Include EXPR, so that unused variable warnings do not occur.  */
     #define gcc_assert(EXPR) ((void)(0 && (EXPR)))
     #endif

As that one does cause some issues in GCC proper (that I shall fix separately),
may use this change to 'gcc/rust/rust-system.h:rust_assert' instead:

    +#if 0
     #define rust_assert(EXPR) gcc_assert (EXPR)
    +#else
    +#define rust_assert(EXPR) ((void) (0 && (EXPR)))
    +#endif

To fix these, use the same pattern as is already used in a lot of existing
GCC/Rust code:

    bool ok = [expression with side effects];
    rust_assert (ok);

I've only done a quick manual review; maybe there is a tool for doing this?

Co-authored-by: Thomas Schwinge <thomas@codesourcery.com>
2 years agoMerge #778
bors[bot] [Sat, 30 Oct 2021 12:02:17 +0000 (12:02 +0000)]
Merge #778

778: Add location info in AST::TypeBoundWhereClauseItem and HIR::TypeBoundWhereClauseItem r=philberty a=npate012

Location info has been added to AST::TypeBoundWhereClauseItem and HIR::TypeBoundWhereClauseItem. parse_type_bound_where_clause_item () has been modified to fetch location info and store it in AST::TypeBoundWhereClauseItem.

Fixes #766

Signed-off-by: Nirmal Patel <npate012@gmail.com>
Co-authored-by: Nirmal Patel <npate012@gmail.com>
2 years agoNo side effects in 'assert' expressions
Thomas Schwinge [Thu, 28 Oct 2021 19:36:34 +0000 (21:36 +0200)]
No side effects in 'assert' expressions

Usually, if 'assert'ions are disabled, 'assert' expressions are not evaluated,
so in that case won't effect any side effects.

Via spurious ICEs/test suite FAILs, this may be observed in GCC/Rust, for
example, if configuring with '--enable-checking=no' and disabling a "more
forgiving" 'gcc/system.h:gcc_assert' definition, so that '0 && (EXPR)' gets
used:

     /* Use gcc_assert(EXPR) to test invariants.  */
     #if ENABLE_ASSERT_CHECKING
     #define gcc_assert(EXPR)                                               \
        ((void)(!(EXPR) ? fancy_abort (__FILE__, __LINE__, __FUNCTION__), 0 : 0))
    -#elif (GCC_VERSION >= 4005)
    +#elif (0) //GCC_VERSION >= 4005)
     #define gcc_assert(EXPR)                                               \
       ((void)(__builtin_expect (!(EXPR), 0) ? __builtin_unreachable (), 0 : 0))
     #else
     /* Include EXPR, so that unused variable warnings do not occur.  */
     #define gcc_assert(EXPR) ((void)(0 && (EXPR)))
     #endif

As that one does cause some issues in GCC proper (that I shall fix separately),
may use this change to 'gcc/rust/rust-system.h:rust_assert' instead:

    +#if 0
     #define rust_assert(EXPR) gcc_assert (EXPR)
    +#else
    +#define rust_assert(EXPR) ((void) (0 && (EXPR)))
    +#endif

To fix these, use the same pattern as is already used in a lot of existing
GCC/Rust code:

    bool ok = [expression with side effects];
    rust_assert (ok);

I've only done a quick manual review; maybe there is a tool for doing this?

2 years agoAdd location info in AST::TypeBoundWhereClauseItem and HIR::TypeBoundWhereClauseItem
Nirmal Patel [Fri, 29 Oct 2021 18:27:50 +0000 (14:27 -0400)]
Add location info in AST::TypeBoundWhereClauseItem and HIR::TypeBoundWhereClauseItem

Location info has been added to AST::TypeBoundWhereClauseItem and
HIR::TypeBoundWhereClauseItem. parse_type_bound_where_clause_item () has been
modified to fetch location info and store it in AST::TypeBoundWhereClauseItem

Fixes #766

Signed-off-by: Nirmal Patel <npate012@gmail.com>
2 years agoMerge #774
bors[bot] [Thu, 28 Oct 2021 18:46:18 +0000 (18:46 +0000)]
Merge #774

774: Removed lambda in iterate_params within CallExpr and MethodCallExpr r=tschwinge a=npate012

Signed-off-by: Nirmal Patel <npate012@gmail.com>
Removed iterate_params from AST::CallExpr and AST::MethodCallExpr.

Fixes #722 #723

Co-authored-by: Nirmal Patel <npate012@gmail.com>
2 years agoRemove iterate_params from AST::CallExpr and AST::MethodCallExpr
Nirmal Patel [Thu, 28 Oct 2021 17:58:03 +0000 (13:58 -0400)]
Remove iterate_params from AST::CallExpr and AST::MethodCallExpr

These lambda iterators are removed because they make working
with IR more complex. Instead, we are using the get_params ()
to access the parameters with the help of a for loop.

Fixes #722 #723

Signed-off-by: Nirmal Patel <npate012@gmail.com>
2 years agoMerge #775
bors[bot] [Thu, 28 Oct 2021 10:13:12 +0000 (10:13 +0000)]
Merge #775

775: Support const within block-expr's r=philberty a=philberty

This adds support for constant folding within block expr's and constant
ArrayIndexExpression.

Fixes #711

Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2 years agoAdd constant folding to ArrayIndexExpr
Philip Herron [Thu, 28 Oct 2021 10:07:13 +0000 (11:07 +0100)]
Add constant folding to ArrayIndexExpr

This ensures that constexpr is enforced for array-index-exprs resulting in
gimple like this:

```rust
fn main() {
    const A: [i32; 3] = [1, 2, 3];
    const B: i32 = A[1];
    const C: usize = 42;
    const D: i32 = 7;

    let _a = C;
    let _b: [i32; C] = [0; C];
    let _c = B + D;
}
```

```c
void main ()
{
  const usize _a;
  i32 _b[42];
  const i32 _c;

  try
    {
      _a = 42;
      _b = {};
      _1 = 2;
      _c = _1 + 7;
    }
  finally
    {
      _b = {CLOBBER};
    }
}
```

2 years agoAdd support for constants within blocks
Philip Herron [Thu, 28 Oct 2021 09:57:37 +0000 (10:57 +0100)]
Add support for constants within blocks

BlockExpr's can contain constants these are Items which can exist within
the BlockExpr Stmt list. Items like structs, functions and constants all
inherit from Item so there is some duplication of code but we still
do not support the forward declared Items within a stmt list so the
duplication will need to be fixed as part of that bug.

Fixes #711

2 years agoMerge #771
bors[bot] [Wed, 27 Oct 2021 15:12:05 +0000 (15:12 +0000)]
Merge #771

771: Add higher ranked trait bounds r=philberty a=philberty

This adds support for where clauses and higher ranked trait bounds more test cases are needed
since where clauses are supported on associated types, impls, ADT's etc. See the individual
commits for more detail on implementation.

Fixes #773 #442

Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2 years agoFix parser error for lifetime arguments
Philip Herron [Wed, 27 Oct 2021 14:57:30 +0000 (15:57 +0100)]
Fix parser error for lifetime arguments

The loop was eagerly trying to ensure that there was multiple lifetimes
since the predicate assumed there will be a comma or delimiter for the
arguments. This changes the loop to keep reading lifetimes untill we fail to parse a lifetime or hit the end of the arguments.

Fixes #773

2 years agoAdd support for higher ranked trait bounds
Philip Herron [Mon, 25 Oct 2021 17:15:33 +0000 (18:15 +0100)]
Add support for higher ranked trait bounds

This adds the type checking for the bounds which will add the relevant
bounds to the associated types and perform the relevant type checking
required.

Fixes #442

2 years agoTyTy add bounds in debug string
Philip Herron [Tue, 26 Oct 2021 13:26:33 +0000 (14:26 +0100)]
TyTy add bounds in debug string

2 years agoRemove assertion for has_where_clause
Philip Herron [Mon, 25 Oct 2021 17:15:10 +0000 (18:15 +0100)]
Remove assertion for has_where_clause

This assertion doesn't protect against bad pointers or behaviour, when we
access the where clause it is simply a wrapper over a vector of where
clause items so we can safely iterate even when the where clause item
vector is empty.

2 years agoAdd HIR lowering for where clause items
Philip Herron [Mon, 25 Oct 2021 16:34:21 +0000 (17:34 +0100)]
Add HIR lowering for where clause items

2 years agoAdd WhereClauseItem::ItemType specifier to differentiate between items
Philip Herron [Mon, 25 Oct 2021 16:08:55 +0000 (17:08 +0100)]
Add WhereClauseItem::ItemType specifier to differentiate between items

2 years agoAdd name resolution to higher ranked trait bounds
Philip Herron [Mon, 25 Oct 2021 15:46:03 +0000 (16:46 +0100)]
Add name resolution to higher ranked trait bounds

2 years agoAdd missing node mappings to HIR::WhereClauseItems
Philip Herron [Mon, 25 Oct 2021 15:08:14 +0000 (16:08 +0100)]
Add missing node mappings to HIR::WhereClauseItems

2 years agoAdd missing NodeId to where clause items
Philip Herron [Mon, 25 Oct 2021 14:40:07 +0000 (15:40 +0100)]
Add missing NodeId to where clause items

2 years agoMerge #770
bors[bot] [Tue, 26 Oct 2021 09:25:44 +0000 (09:25 +0000)]
Merge #770

770: TraitImpl: track the polarity of the impl r=philberty a=mathstuf

The internal representation now tracks whether a trait impl is a
positive or negative impl.

Signed-off-by: Ben Boeckel <mathstuf@gmail.com>
Fixes: #732
Co-authored-by: Ben Boeckel <mathstuf@gmail.com>
2 years agoMerge #772
bors[bot] [Tue, 26 Oct 2021 08:58:39 +0000 (08:58 +0000)]
Merge #772

772: Converted FnType preprocessor defines into constants r=philberty a=npate012

Fixes #737

I have converted FnType preprocessor defines to static const of uint8_t. I did not change the variable case.

Co-authored-by: Nirmal Patel <npate012@gmail.com>
2 years agoConverted FnType preprocessor defines into constants
Nirmal Patel [Tue, 26 Oct 2021 01:55:04 +0000 (21:55 -0400)]
Converted FnType preprocessor defines into constants

Signed-off-by: Nirmal Patel <npate012@gmail.com>
2 years agoTraitImpl: track the polarity of the impl
Ben Boeckel [Mon, 25 Oct 2021 16:56:32 +0000 (12:56 -0400)]
TraitImpl: track the polarity of the impl

The internal representation now tracks whether a trait impl is a
positive or negative impl.

Signed-off-by: Ben Boeckel <mathstuf@gmail.com>
2 years agoMerge #769
bors[bot] [Mon, 25 Oct 2021 17:01:37 +0000 (17:01 +0000)]
Merge #769

769: LifetimeWhereClauseItem: store the location of the item r=philberty a=mathstuf

Signed-off-by: Ben Boeckel <mathstuf@gmail.com>
---
Fixes: #765
Here is a checklist to help you with your PR.

- \[x] GCC development requires copyright assignment or the Developer's Certificate of Origin sign-off, see https://gcc.gnu.org/contribute.html or https://gcc.gnu.org/dco.html
- \[x] Read contributing guidlines
- \[x] `make check-rust` passes locally
- \[x] Run `clang-format` (letting CI handle this)
- \[x] Added any relevant test cases to `gcc/testsuite/rust/`

I didn't find any ctor calls for the `HIR` type, but it's updated as well.

Co-authored-by: Ben Boeckel <mathstuf@gmail.com>
2 years agoLifetimeWhereClauseItem: store the location of the item
Ben Boeckel [Mon, 25 Oct 2021 14:10:48 +0000 (10:10 -0400)]
LifetimeWhereClauseItem: store the location of the item

Signed-off-by: Ben Boeckel <mathstuf@gmail.com>
2 years agoMerge #768
bors[bot] [Mon, 25 Oct 2021 15:22:35 +0000 (15:22 +0000)]
Merge #768

768: CompileExpr: fix copy pasta error message r=philberty a=mathstuf

Also downgrade from a fatal error to a compilation error.

Signed-off-by: Ben Boeckel <mathstuf@gmail.com>
---
Fixes: #702
Here is a checklist to help you with your PR.

- \[x] GCC development requires copyright assignment or the Developer's Certificate of Origin sign-off, see https://gcc.gnu.org/contribute.html or https://gcc.gnu.org/dco.html
- \[x] Read contributing guidlines
- \[x] `make check-rust` passes locally
- \[x] Run `clang-format` (letting CI handle this)
- \[ ] Added any relevant test cases to `gcc/testsuite/rust/` (I don't see any existing tests that seem to test things like this; it's a gccrs internal error about lookup up the type it seems?)

Co-authored-by: Ben Boeckel <mathstuf@gmail.com>
2 years agoCompileExpr: fix copy pasta error message
Ben Boeckel [Mon, 25 Oct 2021 13:40:23 +0000 (09:40 -0400)]
CompileExpr: fix copy pasta error message

Also downgrade from a fatal error to a compilation error.

Signed-off-by: Ben Boeckel <mathstuf@gmail.com>
2 years agoMerge #767
bors[bot] [Mon, 25 Oct 2021 13:26:21 +0000 (13:26 +0000)]
Merge #767

767: gccrs: StructExprStructFields: remove `iterate` method r=philberty a=mathstuf

This provides a getter for the set of fields in a struct expression
rather than a visitor with a callback which is more complicated for
callers, especially static analysis.

Signed-off-by: Ben Boeckel <mathstuf@gmail.com>
Fixes: #721
Co-authored-by: Ben Boeckel <mathstuf@gmail.com>
2 years agogccrs: StructExprStructFields: remove `iterate` method
Ben Boeckel [Mon, 25 Oct 2021 11:48:42 +0000 (07:48 -0400)]
gccrs: StructExprStructFields: remove `iterate` method

This provides a getter for the set of fields in a struct expression
rather than a visitor with a callback which is more complicated for
callers, especially static analysis.

Signed-off-by: Ben Boeckel <mathstuf@gmail.com>
2 years agoMerge #764
bors[bot] [Fri, 22 Oct 2021 16:46:54 +0000 (16:46 +0000)]
Merge #764

764: Update GCC/Rust files per 'contrib/update-copyright.py --this-year' r=philberty a=tschwinge

As noted by `@dkm/@CohenArthur` in <https://github.com/Rust-GCC/gccrs/pull/747#issuecomment-945581716>/<https://github.com/Rust-GCC/gccrs/issues/747#issuecomment-945585735>.

Co-authored-by: Thomas Schwinge <thomas@codesourcery.com>
2 years agoMerge #762
bors[bot] [Fri, 22 Oct 2021 16:07:18 +0000 (16:07 +0000)]
Merge #762

762: Add missing coercion site code to MethodCallExpr's r=philberty a=philberty

Arguments to methods are coercion sites and may have implicit conversions
to be performed this adds this missing code for this case.

Fixes #755

Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2 years agoMerge #763
bors[bot] [Fri, 22 Oct 2021 15:42:12 +0000 (15:42 +0000)]
Merge #763

763: Cleanup IR symbol names in gimple r=philberty a=philberty

When we have generic code the full as_string is too verbose for symbol
names. This changes the ir_symbol_names to become the name of the types
not the full debug as_string version.

Fixes #745

Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2 years agoUpdate GCC/Rust files per 'contrib/update-copyright.py --this-year'
Thomas Schwinge [Fri, 22 Oct 2021 14:27:02 +0000 (16:27 +0200)]
Update GCC/Rust files per 'contrib/update-copyright.py --this-year'

2 years agoFix copyright/licensing information in 'gcc/rust/rust-linemap.h'
Thomas Schwinge [Fri, 22 Oct 2021 14:12:49 +0000 (16:12 +0200)]
Fix copyright/licensing information in 'gcc/rust/rust-linemap.h'

This evidently has originally been copied from 'gcc/go/gofrontend/go-linemap.h'
(with a bit too much 's%go%rust').  Restore the original notes, and extend
suitably.

2 years agoCleanup IR symbol names in gimple
Philip Herron [Fri, 22 Oct 2021 12:45:21 +0000 (13:45 +0100)]
Cleanup IR symbol names in gimple

When we have generic code the full as_string is too verbose for symbol
names. This changes the ir_symbol_names to become the name of the types
not the full debug as_string version.

Fixes #745

2 years agoAdd missing coercion site code to MethodCallExpr's
Philip Herron [Fri, 22 Oct 2021 12:32:20 +0000 (13:32 +0100)]
Add missing coercion site code to MethodCallExpr's

Arguments to methods are coercion sites and may have implicit conversions
to be performed this adds this missing code for this case.

Fixes #755

2 years agoMerge #752
bors[bot] [Fri, 22 Oct 2021 11:08:44 +0000 (11:08 +0000)]
Merge #752

752: Bugfix ICE in trait resolution r=philberty a=philberty

This is a series of patches which need to go in order to fix the linked bugs.

- Fix type resolution of associated types in the generic context
- Ensure autoderef is applied on generic receivers
- Support generic substitutions on type-bounds

Fixes #743 #753 #744 #741

Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2 years agoSupport generic arguments on TypeBounds
Philip Herron [Thu, 21 Oct 2021 21:48:18 +0000 (22:48 +0100)]
Support generic arguments on TypeBounds

This adds support to managing generic arguments within type bounds. Such
as:

```rust
fn test<T: GenericBound<i32>>(a:T) { ... }
```

The interesting piece here is that for any usage of the bounds on T the
items must be substituted with the inherited arguments specified within
the bound.

This fixes the test case from #743 by removing the lifetimes and where
constraint which needs to be implemented in #442. This associated test
case will fail the rust borrow checker but we need a way to work though
bugs in the short term in some senario's.

Fixes #743

2 years agoDecouple the loop from processing a potential candidate in a path
Philip Herron [Thu, 21 Oct 2021 21:31:21 +0000 (22:31 +0100)]
Decouple the loop from processing a potential candidate in a path

Code cleanup to extract the body out of the loop to make the code more
testable and reuseable.

2 years agoExtract const helper method is_receiver_generic for path probes.
Philip Herron [Thu, 21 Oct 2021 21:22:19 +0000 (22:22 +0100)]
Extract const helper method is_receiver_generic for path probes.

2 years agoEnsure autoderef for generic recivers in method calls
Philip Herron [Wed, 20 Oct 2021 18:39:01 +0000 (19:39 +0100)]
Ensure autoderef for generic recivers in method calls

This changes our TyTy::BaseType::can_eq interface to allow
ParamTypes to be compatable with everything except reference
and pointer types to ensure we apply autoderef adjustments
correctly.

Fixes #753

2 years agoFix ICE when trying to resolve associated type from type bounds
Philip Herron [Wed, 20 Oct 2021 16:47:17 +0000 (17:47 +0100)]
Fix ICE when trying to resolve associated type from type bounds

When we have a generic function with specified type bounds this allows rust
code to actually then look up the relevant bounds for associated types,
functions or constants. This means at code generation the relevant
associated mappings msut be setup such that we compile to the
implementaiton if available or the default implementation if possible.

The bug here was that the resolution for associated types were auto setting
up the associated type mappings even when the receiver was generic. So for
example:

```rust
pub trait Foo {
    type A;

    fn bar(self) -> Self::A;
}

struct S(i32);
impl Foo for S {
    type A = i32;

    fn bar(self) -> Self::A {
        self.0
    }
}

fn test_bar<T: Foo>(x: T) -> T::A {
    x.bar()
}
```

The generic function of test_bar was auto resolving the T::A to A=i32 since
it found the type-bound Foo was specified and the only implementation of
Foo is on S. This is usually the correct flow to auto setup these mappings
but in the conjtext of a generic receiver this needs to still result in
a Placeholder type of the bound Foo to type check correctly.

Fixes: #744 #741
2 years agoMerge #761
bors[bot] [Fri, 22 Oct 2021 10:44:54 +0000 (10:44 +0000)]
Merge #761

761: Squash unused parameter warning. r=philberty a=philberty

This should fix out bootstrap build again.

Fixes #750

Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2 years agoSquash unused parameter warning.
Philip Herron [Thu, 21 Oct 2021 21:56:40 +0000 (22:56 +0100)]
Squash unused parameter warning.

Fixes #750

2 years agoMerge #757 #758 #759 #760
bors[bot] [Fri, 22 Oct 2021 10:15:12 +0000 (10:15 +0000)]
Merge #757 #758 #759 #760

757: Fix TypePath resolution to iterate segments r=philberty a=philberty

Associated types in rust can be of the form:

```rust
trait Foo {
  type A;
   ...
}

fn test<T:Foo>(a:T) -> T::A { .. }
```

Where the type-bound of Foo is applied to T this allows for a the associated type T::A to exist
which is a placeholder type within the trait definition. This path cannot be resolved at name-resolution
time and requires a path probe.

Fixes #746

758: The number of required substituions is offset from inherited ones r=philberty a=philberty

When doing HIR::GenericArgs substitutions we must offset from the already
partially substituted arguments.

759: Remove second lookup for query compiled functions r=philberty a=philberty

This cleans up the code here to make use of the query based
compilation which returns the address of the function which
removes extra lookups.

760: Cleanup lookup interfaces r=philberty a=philberty

These patches change the associated impl mapping's to use a boolean
return type for error handling, to stop looking for UNKNOWN_HIRID for
error handling which is too easy to make mistakes with.

It also updates instances of code to use TyTy::ErrorType node instead of
nullptr's for error handling.

Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2 years agoMerge #756
bors[bot] [Fri, 22 Oct 2021 09:51:12 +0000 (09:51 +0000)]
Merge #756

756: Add const to enforce ownership over pointers r=philberty a=philberty

This consify's a bunch of interfaces in the code base which helps make the ownership
over pointers more clear. These are building blocks from a wider cleanup of the type-checking
code to make it more readable.

- BaseType::get_root
- SubstitutionArgumentMappings::solve_mappings_from_receiver_for_self
- Autoderef adjustments
- GetUsedSubstArgs
- SubstitutionArg field SubstitutionParamMapping
- Backend resolve compile interface

Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2 years agoAdd FIXME comment for inheriting bounds
Philip Herron [Wed, 20 Oct 2021 15:24:04 +0000 (16:24 +0100)]
Add FIXME comment for inheriting bounds

2 years agoCleanup interfaces for associated impl mappings
Philip Herron [Wed, 20 Oct 2021 16:19:32 +0000 (17:19 +0100)]
Cleanup interfaces for associated impl mappings

This changes the lookups to return boolean if they are found rather than
default UNKNOWN_HIRID which is more ambigious.

2 years agoError handling is done via the TyTy::ErrorType instead of nullptr's
Philip Herron [Wed, 20 Oct 2021 15:31:50 +0000 (16:31 +0100)]
Error handling is done via the TyTy::ErrorType instead of nullptr's

2 years agoRefactor fill_param_ty into cc file
Philip Herron [Wed, 20 Oct 2021 15:28:50 +0000 (16:28 +0100)]
Refactor fill_param_ty into cc file

This also changes the signiture to take a fat pointer instead of raw
pointer for the substitution.

2 years agoRemove second lookup for query compiled functions
Philip Herron [Thu, 21 Oct 2021 21:17:19 +0000 (22:17 +0100)]
Remove second lookup for query compiled functions

When compiling method calls we need to compile functions in a query based
manar sometimes, recently there was a query mode api added to the relevant
functions which will return the address of the function when asked to try
and compile. This patch uses this returned address avoiding a duplicate
lookup for the compiled function

2 years agoThe number of required substituions is offset from the already substituted
Philip Herron [Thu, 21 Oct 2021 17:27:37 +0000 (18:27 +0100)]
The number of required substituions is offset from the already substituted

When doing HIR::GenericArgs substitutions we must offset from the already
partially substituted arguments.

2 years agoBugFix: TypePath resolution to handle associated types
Philip Herron [Fri, 15 Oct 2021 17:02:51 +0000 (18:02 +0100)]
BugFix: TypePath resolution to handle associated types

TypePath's can be fully resolved at name resolution time for example a
primitive types are single segments which can be resolved. But in the event
of a generic TypeBound path such as: T::A where T is the generic type param
in a function and A is its own associated type this require's the
resolution to be split over the name resolver and type resolver.

Like PathInExpression's the name resolver is able to resolve the root
segment of 'T' but requires a path probe on the type-bounds of T to find
the associated type 'A'.

Fixes #746

2 years agoRemove bad prefix from RelativeTypePath resolution
Philip Herron [Fri, 15 Oct 2021 12:01:42 +0000 (13:01 +0100)]
Remove bad prefix from RelativeTypePath resolution

The TypePath resolver is a naieve and assumes all paths are fully
resolveable at name resolution time. This is the first patch to update
this to resolve each segement in turn.

Addresses #746

2 years agoConstify BaseType::get_root since this should not change ownership
Philip Herron [Wed, 20 Oct 2021 15:21:37 +0000 (16:21 +0100)]
Constify BaseType::get_root since this should not change ownership

2 years agoConstify SubstitutionArgumentMappings::solve_mappings_from_receiver_for_self
Philip Herron [Wed, 20 Oct 2021 15:20:03 +0000 (16:20 +0100)]
Constify SubstitutionArgumentMappings::solve_mappings_from_receiver_for_self

2 years agoConstify autoderef ajustments expected type field
Philip Herron [Wed, 20 Oct 2021 15:17:13 +0000 (16:17 +0100)]
Constify autoderef ajustments expected type field

2 years agoConstify GetUsedSubstArgs
Philip Herron [Wed, 20 Oct 2021 15:13:16 +0000 (16:13 +0100)]
Constify GetUsedSubstArgs

This mapper class does not need mutability and can easily be made const
enforcing ownership.

2 years agoConstify SubstitutionArg field SubstitutionParamMapping
Philip Herron [Wed, 20 Oct 2021 15:09:31 +0000 (16:09 +0100)]
Constify SubstitutionArg field SubstitutionParamMapping

Argument mappings need to reference the generic parameter they are going
to substitute this should really be const since this class does not own
the mapping pointer here.

2 years agoConstify the Backend resolve compile interface
Philip Herron [Wed, 20 Oct 2021 14:53:13 +0000 (15:53 +0100)]
Constify the Backend resolve compile interface

This is a bad name for this class, but it will compile a TyTy type into a
GCC Backend::Btype* node. The class also tries to determine if we have
already compiled this node for monomorphization and canonicalization of
types which will avoid unnessecary conversion code based on type equality.

This patch simply makes this a const visitor to enforce pointer ownership
rules.

2 years agoMerge #754
bors[bot] [Fri, 22 Oct 2021 09:05:50 +0000 (09:05 +0000)]
Merge #754

754: Add new unafety enum r=philberty a=npate012

Fixes #733

unsafety enum has been implemented in rust/util/rust-common.h. Occurrences of has_unsafe boolean variable has been replaced with an unsafety variable of new enum type.

Co-authored-by: Nirmal Patel <npate012@gmail.com>
2 years agoFixed formatting issues
Nirmal Patel [Thu, 21 Oct 2021 23:45:08 +0000 (19:45 -0400)]
Fixed formatting issues

Signed-off-by: Nirmal Patel <npate012@gmail.com>
2 years agoImplement unsafety enum and replaced boolean variable has_unsafe with a variable...
Nirmal Patel [Thu, 21 Oct 2021 01:14:00 +0000 (21:14 -0400)]
Implement unsafety enum and replaced boolean variable has_unsafe with a variable of unsafety enum type

Signed-off-by: Nirmal Patel <npate012@gmail.com>
2 years agoMerge #747
bors[bot] [Mon, 18 Oct 2021 09:24:56 +0000 (09:24 +0000)]
Merge #747

747: Base v0 mangling grammar r=philberty a=CohenArthur

This PR adds base functions to deal with the v0 mangling grammar, [found here](https://rust-lang.github.io/rfcs/2603-rust-symbol-name-mangling-v0.html#syntax-of-mangled-names).

I have a few questions regarding this implementation:
1/ Is there any existing implementation for the base62 algorithm used here? This is directly adapted from [rustc's base_n module](https://github.com/rust-lang/rust/blob/6f53ddfa74ac3c10ceb63ad4a7a9c95e55853c87/compiler/rustc_data_structures/src/base_n.rs#L16) which I'm assuming is relatively standard and might already exist in the compiler. I haven't been able to find it however.
2/ gccrs cannot yet deal with unicode identifiers, as pointed out by `@bjorn3` in #418. This means that a big chunk of the `v0_add_identifier` implementation is missing. Should it be added in this PR too?
3/ As mentionned in zulip, it would be great to be able to create unit tests for this piece of code. It would be quite easy to generate a bunch of base62 strings and ensure that the algorithm here matches with them.

Co-authored-by: CohenArthur <arthur.cohen@epita.fr>
2 years agoutil: Add rust-base62 implementation from rustc
CohenArthur [Mon, 18 Oct 2021 09:02:58 +0000 (11:02 +0200)]
util: Add rust-base62 implementation from rustc

2 years agoMerge #748
bors[bot] [Mon, 18 Oct 2021 08:53:50 +0000 (08:53 +0000)]
Merge #748

748: Const fold ArrayElemsCopied r=philberty a=rodrigovalle

Added support for const fold inside of an ArrayElemsCopied expression, e.g. `const array: [i32; 10] = [0; 10];`. I also removed a .swp file that I accidentally merged in a previous commit and added a test for this new functionality.

Co-authored-by: Rodrigo Valle <rdan.valle@gmail.com>
2 years agoConst fold ArrayElemsCopied
Rodrigo Valle [Mon, 11 Oct 2021 07:22:15 +0000 (00:22 -0700)]
Const fold ArrayElemsCopied

Added support for const fold inside of an ArrayElemsCopied expression, e.g.
`const array: [i32; 10] = [0; 10];`. I also removed a .swp file that I
accidentally merged in a previous commit and added a test for this new
functionality.

Signed-off-by: Rodrigo Valle <rdan.valle@gmail.com>
2 years agov0-mangling: Add base functions for mangling scheme
CohenArthur [Sun, 17 Oct 2021 16:03:45 +0000 (18:03 +0200)]
v0-mangling: Add base functions for mangling scheme

2 years agov0-mangling: Add base for base62 encoding
CohenArthur [Sun, 17 Oct 2021 09:35:27 +0000 (11:35 +0200)]
v0-mangling: Add base for base62 encoding

2 years agoMerge #725
bors[bot] [Sat, 16 Oct 2021 19:28:45 +0000 (19:28 +0000)]
Merge #725

725: Add array constant folding r=philberty a=rodrigovalle

Fixes #681

I created a new ConstFoldArrayElems folder to visit ArrayElemsCopied and ArrayElemsValues while holding onto the original ArrayExpr object that we recurse into.

Co-authored-by: Rodrigo Valle <rdan.valle@gmail.com>
2 years agoAdd array constant folding
Rodrigo Valle [Wed, 6 Oct 2021 19:55:25 +0000 (12:55 -0700)]
Add array constant folding

Create a new ConstFoldArrayElems folder to visit ArrayElemsValues while holding
onto the original ArrayExpr object that we recurse into.

Fixes #681

Signed-off-by: Rodrigo Valle <rdan.valle@gmail.com>
2 years agoMerge #740
bors[bot] [Fri, 15 Oct 2021 14:50:15 +0000 (14:50 +0000)]
Merge #740

740: Add boiler plate for TyTy::ClosureType r=philberty a=philberty

This simply adds in the boilerplate for closure types for type-checking.
The closure branch is blocked until we get lang-item support in next.

Addresses #195

Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2 years agoAdd boiler plate for TyTy::ClosureType
Philip Herron [Thu, 14 Oct 2021 11:32:43 +0000 (12:32 +0100)]
Add boiler plate for TyTy::ClosureType

This adds all the nesecary boiler plate to introduce the ClosureType. More
work is needed to be make this actually useable for type resolution.

Addresses #195

2 years agoMerge #730
bors[bot] [Thu, 14 Oct 2021 09:31:20 +0000 (09:31 +0000)]
Merge #730

730: GCC allows for the DCO sign-off r=philberty a=philberty

This updates the contributor guide to let people know the update applies to
gccrs.

Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Co-authored-by: Thomas Schwinge <thomas@schwinge.name>
2 years agoMerge #738
bors[bot] [Thu, 14 Oct 2021 09:08:10 +0000 (09:08 +0000)]
Merge #738

738: Refactor HIR to use new Mutability enum r=philberty a=dafaust

Introduce a new header rust/util/rust-common.h and move the enum
previously Rust::TyTy::TypeMutability there as Rust::Mutability.

Update the following objects to use Mutability enum rather than a bool:
- HIR::IdentifierPattern
- HIR::ReferencePattern
- HIR::StructPatternFieldIdent
- HIR::BorrowExpr
- HIR::RawPointerType
- HIR::ReferenceType
- HIR::StaticItem
- HIR::ExternalStaticItem

Also add a HIR::SelfParam::get_mut () helper, mapping its internal
custom mutability to the common Rust::Mutability.

Fixes: #731
Co-authored-by: David Faust <david.faust@oracle.com>
2 years agoUpdate 'README.md' for DCO
Thomas Schwinge [Thu, 14 Oct 2021 08:39:18 +0000 (10:39 +0200)]
Update 'README.md' for DCO

... using the same wording as in 'CONTRIBUTING.md'.

2 years agoSome polishing of DCO wording
Thomas Schwinge [Thu, 14 Oct 2021 08:35:24 +0000 (10:35 +0200)]
Some polishing of DCO wording

<https://github.com/Rust-GCC/gccrs/pull/730/files#r728027852>.

2 years agoAlign DCO wording in '.github/PULL_REQUEST_TEMPLATE.md'
Thomas Schwinge [Thu, 14 Oct 2021 08:32:55 +0000 (10:32 +0200)]
Align DCO wording in '.github/PULL_REQUEST_TEMPLATE.md'

... to that used in 'CONTRIBUTING.md'.

2 years agoRefactor HIR to use new Mutability enum
David Faust [Wed, 13 Oct 2021 16:50:13 +0000 (09:50 -0700)]
Refactor HIR to use new Mutability enum

Introduce a new header rust/util/rust-common.h and move the enum
previously Rust::TyTy::TypeMutability there as Rust::Mutability.

Update the following objects to use Mutability enum rather than a bool:
- HIR::IdentifierPattern
- HIR::ReferencePattern
- HIR::StructPatternFieldIdent
- HIR::BorrowExpr
- HIR::RawPointerType
- HIR::ReferenceType
- HIR::StaticItem
- HIR::ExternalStaticItem

Also add a HIR::SelfParam::get_mut () helper, mapping its internal
custom mutability to the common Rust::Mutability.

Fixes: #731
This page took 0.101698 seconds and 5 git commands to generate.