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>
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.
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.
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
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.
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:
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.
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:
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
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.
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.
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>
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.
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.
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.
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?)
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>
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.
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>
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>
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.
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.
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>
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.
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.
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.
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.
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>
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.
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
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'.
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.
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.
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.
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.
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.
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>
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>
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>
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>
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.