Philip Herron [Thu, 18 Nov 2021 13:53:47 +0000 (13:53 +0000)]
Remove implicit name hack for trait associated types
Before the TypePath resolution was updated to support associated type paths
and projections, we used an implict name hack of Self::<associated-type> as
well as the usual TraitName::<associates-type> this was a hack in the short
term to get things working which can now be removed.
bors[bot] [Thu, 18 Nov 2021 00:16:47 +0000 (00:16 +0000)]
Merge #810
810: Fix MethodCalls for covariant impl blocks r=philberty a=philberty
I think we need to research more into how we probe for potential candidates
for method calls. This fixes a few bugs going on in #808 one where the
canonical path was empty and one where we fail to probe directly on the
receiver of reference types to impl blocks but we must be able to also support
that autoderef means that a receiver's root type might actually be the type we
care about for example a reference to a generic type-parameter and we probe
its bounds for candidates for example. Lets consult the rustc code and references on this.
Fixes #808
Co-authored-by: Philip Herron <philip.herron@embecosm.com>
bors[bot] [Wed, 17 Nov 2021 21:22:20 +0000 (21:22 +0000)]
Merge #805
805: Remove Btype, Bexpression, etc. abstractions over gcc trees r=CohenArthur a=dafaust
As discussed in #412, the Rust front end inherits an abstraction over gcc from the initial bootstrap via GCCGO.
This is a cool idea, but adds overhead for the primary goal of gcc compiling Rust. It's not clear that the benefits of maintaining the abstraction are worth the potential extra headaches of maintaining it.
I figured for the sake of discussion, I'd draft an initial step towards removing this abstraction.
The implementations of classes `Bytpe`, `Bexpression`, `Bstatement`, `Bfunction`, and `Bblock` are only wrappers around gcc's GENERIC `tree` structure, with no added functionality. This PR removes them, and changes all the functions for creating and manipulating these abstract types to just use/return `tree` instead. I also deleted a few functions that are vestiges from GCCGO port and aren't used.
Personally, I think the abstraction should be removed in favor of using `tree`s. This is more in line with the other gcc front ends and makes the interface between the frontend and the rest of gcc simpler.
I'm curious to hear other opinions on the matter :)
Addresses: #412
Co-authored-by: David Faust <david.faust@oracle.com>
Philip Herron [Wed, 17 Nov 2021 17:38:41 +0000 (17:38 +0000)]
Probe for candidates on based on the actual receiver type
Impl blocks Self type is a TypeNoBouns which means it can be for types
such as: impl<T> &T {}.
I think we might need to change the probe algorithm for method calls to be
fully based on the autoderef rather than trying to filter based on the Self
type. More investigation is needed for the probe phase here.
Philip Herron [Wed, 17 Nov 2021 16:45:50 +0000 (16:45 +0000)]
Unify the adjusted self argument to the self parameter on MethodCalls
When we must infer the substitutions on method calls we must make sure to
unify the self arguments from the receiver, taking into account the
autoderef mechanism. This enforces the type checks and fixes up any
inference variables along the way.
Philip Herron [Tue, 16 Nov 2021 17:05:40 +0000 (17:05 +0000)]
Fix ICE assertion on bad duplicate name
This fixes the ice for TypeNoBounds canonical paths for reference types
which was not implemented resulting in empty paths for the canonical
path of impl_blocks for example.
A Fixme has been added to point out that we should update this interface
to only take AST::TypeNoBounds.
David Faust [Mon, 15 Nov 2021 19:27:35 +0000 (11:27 -0800)]
rust-backend.h: remove unused function prototypes
These functions are holdovers from the original port from the Go
frontend for Rust. They aren't used anywhere, so delete them from
rust-backend.h and rust-gcc.cc.
bors[bot] [Tue, 16 Nov 2021 15:18:49 +0000 (15:18 +0000)]
Merge #801
801: operator overloading r=philberty a=philberty
This change adds operator overloading by following how the C++ front-end
does it. We are relying on GCC to inline the operator overloads which does
occur once optimizations are enabled. It also brings back the desurgared
compound assignment expression (e2b761b13e6ccd3a7af4100183bb13e32b5b0da0)
for lang_items such as add_assign. You can find more information on how the algorithm works in:
Philip Herron [Mon, 15 Nov 2021 18:13:32 +0000 (18:13 +0000)]
Add negation operator overload support
Unary operator expressions can be treated as simply having a nullptr
rvalue. This patch updates the shared operator overloading code to allow
for a nullptr rhs to canonicalize the code path for all operator overloads.
Philip Herron [Tue, 16 Nov 2021 13:54:43 +0000 (13:54 +0000)]
Initial support operator overloading on [lang = "add"]
This change incorporates a few changes.
1. Create new gcc/rust/backend/rust-compile-expr.cc to split out
implementation code
2. Create new type check context api calls:
- TypeCheckContext::lookup_operator_overload
- TypeCheckContext::insert_operator_overload
3. Update type checking for ArithmeticOrLogicalExpr to look for any
operator overloading
When we are looking for operator overloads we must look up the associated
lang item type for this paticular operation, to resolve the operation to
any known lang_items by looking up the specified lang_item to DefId. Then
we must probe for the lang_item candidate for this paticular lang_item
DefID to see if we can resolve it to a method call. Then based on the
autoderef rules in a MethodCallExpr we must verify that we don't end up
in a recursive operator overload by checking that the current context
is not the same as the actual operator overload for this type. Finally
we mark this expression as operator overload and setup everything as a
resolved MethodCallExpr.
Philip Herron [Tue, 16 Nov 2021 13:49:57 +0000 (13:49 +0000)]
Update path probe with optional filter for specific associated trait
Sometimes when we probe for associated items we need to limit it to
items which are directly associated with a trait. This adds an optional
parameter to achieve this.
Philip Herron [Tue, 16 Nov 2021 13:45:52 +0000 (13:45 +0000)]
Support parsing LangItems on traits
Lang items are attributes that mark traits for specific behaviour with
compiler support kind of like builtin's/intrinsics.
This change adds parsing support for some of the arithmetic operator
overloads. The string names always correspond to the trait-item function
name too.
Nirmal Patel [Wed, 3 Nov 2021 01:01:13 +0000 (21:01 -0400)]
Changed DefId type from uint64_t to be struct
DefId was uint64_t previously but it has been changed to be a struct.
In order to reduce code breakage, ==, !=, and < operators have been implemented
for DefId. Since DefId is now a proper struct, bit manipulation code has been
removed with member accesses.
@mvvsmk [Sat, 6 Nov 2021 14:45:06 +0000 (20:15 +0530)]
Added Remark.yml and .remarkrc
Addresses #487
Remark.yml contains the workflow and .remarkrc is the linter's config file. Signed-off-by: M V V S Manoj Kumar <mvvsmanojkumar@gmail.com>
bors[bot] [Fri, 5 Nov 2021 17:42:34 +0000 (17:42 +0000)]
Merge #796
796: Handle forward declared items within blocks r=philberty a=philberty
This changes the resolution in BlockExpr's to iterate the Items then Stmts
but we might want to handle this by desugaring the HIR BlockExpr to have
items then stmts to ensure we type resolve the items before the stmts.
Fixes #531
Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Thomas Schwinge [Thu, 28 Oct 2021 21:36:37 +0000 (23:36 +0200)]
Turn 'rust_error_at' plus always-failing 'rust_assert' into 'rust_internal_error_at'
These three were added in commit cbfc0ee239fafc0dadaae314138410f9119c65fa
"This allows for query based compilation", part of
<https://github.com/Rust-GCC/gccrs/pull/640> "Optional Trait items constants".
Given:
if ([...]
&& [X])
{
rust_error_at ([...]);
rust_assert (![X]);
}
..., this means that the 'rust_assert' always fires, so this is a condition
that is not meant to happen (also, there are no test cases triggering this),
so use 'rust_internal_error_at' instead.
Philip Herron [Fri, 5 Nov 2021 12:32:44 +0000 (12:32 +0000)]
Support forward declared items within blocks
This changes the BlockExpr resolution to iterate Items first, then the
Stmts. This could be handled in HIR by desugaring the BlockExpr by lowering
the block into { <items>; <stmts>; } would also work. But the HIR lowering
of blocks is a little messy right now and we need to clean up the
unreachable lint.
bors[bot] [Fri, 5 Nov 2021 11:38:05 +0000 (11:38 +0000)]
Merge #794
794: Fix unhandled type bounds in TypeAlias r=philberty a=philberty
This adds support for trait-object-types and desugars HIR::TraitObjectTypeOneBound into a single
HIR::TraitObjectType. This also adds the missing cases of the generic arguments to the TypeBoundPredicates.
It also contains cleanup for helpers used during monomorphization and a recursion limiter which is likely set too
low but it is good enough for the test-cases we have now to get good back-traces.
Fixes #786
Co-authored-by: Philip Herron <philip.herron@embecosm.com>
In the above example the fntype for the bound FnLike is generic and
bound to the ParamType 'T' from the generic impl-block. But the bound
which has a signiture which is compatible for the impl block looks like:
The set of inline modules is required to find the expected location of a
module file. Track this information with an RAII object
(`InlineModuleStackScope`) and pass it down to any out-of-line modules
so that, when requested, the set of inline modules can be added to the
search path.
Signed-off-by: Ben Boeckel <mathstuf@gmail.com>
---
Note that this does not include a test case because I have no idea how to mark up this for all the warnings that come out (#676):
```diff
diff --git a/gcc/testsuite/rust/compile/missing_middle/sub/mod.rs b/gcc/testsuite/rust/compile/missing_middle/sub/mod.rs
new file mode 100644
index 00000000000..f099d61e04a
--- /dev/null
+++ b/gcc/testsuite/rust/compile/missing_middle/sub/mod.rs
`@@` -0,0 +1,3 `@@`
+pub fn f() -> u32 {
+ 1
+}
diff --git a/gcc/testsuite/rust/compile/mod_missing_middle.rs b/gcc/testsuite/rust/compile/mod_missing_middle.rs
new file mode 100644
index 00000000000..d9cdf0a54f1
--- /dev/null
+++ b/gcc/testsuite/rust/compile/mod_missing_middle.rs
`@@` -0,0 +1,11 `@@`
+pub mod missing_middle {
+ pub mod sub;
+}
```
Observed warnings:
```
/home/boeckb/code/depot/group-compilers/gcc/src-gccrs/gcc/testsuite/rust/compile/missing_middle/sub/mod.rs:1:5: warning: unused name 'f'
/home/boeckb/code/depot/group-compilers/gcc/src-gccrs/gcc/testsuite/rust/compile/mod_missing_middle.rs:2:9: warning: unused name 'sub'
/home/boeckb/code/depot/group-compilers/gcc/src-gccrs/gcc/testsuite/rust/compile/missing_middle/sub/mod.rs:1:5: warning: unused name 'sub::f'
/home/boeckb/code/depot/group-compilers/gcc/src-gccrs/gcc/testsuite/rust/compile/mod_missing_middle.rs:2:9: warning: unused name 'missing_middle::sub'
/home/boeckb/code/depot/group-compilers/gcc/src-gccrs/gcc/testsuite/rust/compile/mod_missing_middle.rs:1:5: warning: unused name 'missing_middle'
/home/boeckb/code/depot/group-compilers/gcc/src-gccrs/gcc/testsuite/rust/compile/missing_middle/sub/mod.rs:1:5: warning: unused name 'missing_middle::sub::f'
```
Fixes: #645
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` (leaving to CI)
- \[x] Added any relevant test cases to `gcc/testsuite/rust/` (see above)
bors[bot] [Wed, 3 Nov 2021 15:54:51 +0000 (15:54 +0000)]
Merge #791
791: Replace TyTy::TupleType::iterate_fields with a new function get_fields r=philberty a=cls
This PR replaces TyTy::TupleType::iterate_fields with a new function get_fields.
In #735, `@philberty` mentions two possible implementations of get_fields, one that returns `std::vector<TyVar>&` and one that returns a new `std::vector<BaseType *>`. I've included two commits, the first doing the former and second going on to do the latter. I'm happy with one or both being merged.
This is my first PR, so please let me know if I've missed anything! Thanks.
Fixes #735
Co-authored-by: Connor Lane Smith <cls@lubutu.com>
Ben Boeckel [Sun, 31 Oct 2021 23:59:37 +0000 (19:59 -0400)]
rust: track inline module scopes for module file resolution
The set of inline modules is required to find the expected location of a
module file. Track this information with an RAII object
(`InlineModuleStackScope`) and pass it down to any out-of-line modules
so that, when requested, the set of inline modules can be added to the
search path.
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.