Age | Commit message (Collapse) | Author | Files | Lines |
|
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.
Fixes #249
|
|
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.
|
|
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.
|
|
FIXME
|
|
Core traits such as the arithmetic operations have generic arguments such
as: pub trait Add<Rhs = Self>
Addresses #249
|
|
This allows us to switch based on the type which can be used for more complex usage of attributes such as lang_item parsing.
Addresses #742
|
|
|
|
clang-format is confused by attribute macros and does a very bad job at
indenting the code.
Changes merged in #779 make all clang-format checks to fail.
Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
|
|
Change 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.
Fixes #439
Signed-off-by: Nirmal Patel <npate012@gmail.com>
|
|
798: Add missing const folding r=philberty a=philberty
Add some more missing constant-folding operations
Co-authored-by: Philip Herron <philip.herron@embecosm.com>
|
|
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>
|
|
... like GCC's underlying 'fatal_error'.
By definition, we cannot continue, upon having run into a fatal error.
|
|
'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.
|
|
... corresponding to GCC's 'internal_error'.
|
|
|
|
|
|
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.
Fixes #531
|
|
BlockExpr can contain Items and Stmts this allows us to differentiate
between them on the Stmt level.
|
|
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>
|
|
This changes the coercion code for the dyn vtable to compute addresses
for more complex generic methods such as:
```
impl<'a, T> FnLike<&'a T, &'a T> for Identity {
fn call(&self, arg: &'a T) -> &'a T {
arg
}
}
```
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:
```
trait FnLike<A, R> {
fn call(&self, arg: A) -> R;
}
```
This means when we have the trait-object bound:
```
type FnObject<'b> = dyn for<'a> FnLike<&'a isize, &'a isize> + 'b
```
We must be able to figure out that the signiture of the impl block item
```
fn call(&self, arg: &'a T) -> &'a T;
```
T must be substituted with &isize from the arguments used in the bound.
Fixes #786
|
|
needs_substitution helpers
|
|
|
|
|
|
|
|
|
|
|
|
|
|
This limit is likely way too low but its ok for now to get decent
backtraces for the test-cases we are working with right now.
|
|
|
|
|
|
785: rust: track inline module scopes for module file resolution r=CohenArthur a=mathstuf
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)
Co-authored-by: Ben Boeckel <mathstuf@gmail.com>
|
|
Fixes #735
Signed-off-by: Connor Lane Smith <cls@lubutu.com>
|
|
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
|
|
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>
|
|
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>
|
|
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.
|
|
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
|
|
Signed-off-by: Ben Boeckel <mathstuf@gmail.com>
|
|
|
|
|
|
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
|
|
|
|
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
|
|
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
|
|
|
|
|
|
|
|
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>
|
|
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>
|