aboutsummaryrefslogtreecommitdiff
path: root/gcc
AgeCommit message (Collapse)AuthorFilesLines
2021-11-16Initial support operator overloading on [lang = "add"]Philip Herron9-229/+696
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
2021-11-16Update path probe with optional filter for specific associated traitPhilip Herron1-5/+25
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.
2021-11-16Support parsing LangItems on traitsPhilip Herron2-4/+181
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.
2021-11-16Add new TypeCheckContextItem to track current contextPhilip Herron6-18/+100
FIXME
2021-11-16Traits do allow TypeParameters with defaultsPhilip Herron1-23/+0
Core traits such as the arithmetic operations have generic arguments such as: pub trait Add<Rhs = Self> Addresses #249
2021-11-16Update AttrInput with AttrInputTypePhilip Herron2-7/+27
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
2021-11-16Remove useless comments from HIR::MethodCallExprPhilip Herron1-5/+0
2021-11-09Partially disable clang-format in rust-diagnostics.hMarc Poulhiès1-0/+4
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>
2021-11-08Merge pull request #792 from npate012/defid_to_structCohenArthur3-12/+27
Change DefId type from uint64_t to be struct
2021-11-07Changed DefId type from uint64_t to be structNirmal Patel3-12/+27
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>
2021-11-07Merge #798bors[bot]1-2/+58
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>
2021-11-05Merge #796bors[bot]10-34/+88
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>
2021-11-05Tag 'rust_fatal_error' as 'noreturn'Thomas Schwinge1-2/+4
... like GCC's underlying 'fatal_error'. By definition, we cannot continue, upon having run into a fatal error.
2021-11-05Turn 'rust_error_at' plus always-failing 'rust_assert' into ↵Thomas Schwinge2-18/+9
'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.
2021-11-05Add 'rust_internal_error_at'Thomas Schwinge4-0/+29
... corresponding to GCC's 'internal_error'.
2021-11-05Add missing const-folding for (expr)Philip Herron1-0/+5
2021-11-05Const fold ref,pointer,borrow+derefPhilip Herron1-2/+53
2021-11-05Support forward declared items within blocksPhilip Herron6-34/+68
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
2021-11-05Add is_item helper to AST and HIRPhilip Herron4-0/+20
BlockExpr can contain Items and Stmts this allows us to differentiate between them on the Stmt level.
2021-11-05Merge #794bors[bot]31-195/+614
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>
2021-11-05Support computing the addresses of the object safe items in dyn objectsPhilip Herron7-52/+325
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
2021-11-05Enforce the is_concrete inferface to start cleaning up the ↵Philip Herron2-14/+112
needs_substitution helpers
2021-11-05Add missing generic arguments to type-bound-predicate on trait-objectsPhilip Herron1-1/+18
2021-11-05Add generic-arguments to predicate as_stringPhilip Herron1-1/+4
2021-11-05Remove duplicate accessors which can be constPhilip Herron1-3/+1
2021-11-05When we are resolving TypePaths default the result to ErrorTypePhilip Herron1-8/+6
2021-11-05Fix nullptr as the result is not setup in this casePhilip Herron1-1/+1
2021-11-05Make self const when compiling trait-itemsPhilip Herron1-3/+3
2021-11-05Add a recursion-limit when resolving Parameter TypesPhilip Herron1-1/+8
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.
2021-11-04Add missing bound to impl-type SelfPhilip Herron1-0/+24
2021-11-04Add ImplItemTypes enum to switch between HIR::ImplItem typesPhilip Herron2-4/+28
2021-11-03Merge #785bors[bot]12-58/+169
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>
2021-11-03Replace TupleType::iterate_fields with get_fieldsConnor Lane Smith2-13/+6
Fixes #735 Signed-off-by: Connor Lane Smith <cls@lubutu.com>
2021-11-03Desugar AST::TraitObjectTypeOneBoundPhilip Herron19-109/+86
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
2021-11-03rust: track inline module scopes for module file resolutionBen Boeckel12-58/+169
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>
2021-11-02Merge #781bors[bot]29-521/+1204
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>
2021-11-02Default type checking on CallExpr's to TyTy::ErrorTypePhilip Herron6-11/+2
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.
2021-11-02Support Typechecking of ADT's of enumsPhilip Herron8-31/+121
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
2021-11-02gccrs: add the `-frust-crate=` option to set the crate nameBen Boeckel3-3/+23
Signed-off-by: Ben Boeckel <mathstuf@gmail.com>
2021-11-02Refactor struct-expr typechecking into its own impl filePhilip Herron3-271/+296
2021-11-01Add missing ID to variant idsPhilip Herron4-37/+38
2021-11-01Add TypePath resolution for enum ctorPhilip Herron2-1/+59
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
2021-11-01Get rid of bad gcc_unreachablePhilip Herron1-22/+3
2021-11-01Add type-resolution for enum itemsMark Wielaard3-0/+254
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
2021-11-01Refactor ADTType to consist of multiple variantsPhilip Herron15-184/+452
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
2021-11-01Extract reuseable function to handle substitutions for struct fieldsMark Wielaard1-44/+54
2021-11-01Get rid of lambda get_fields in structMark Wielaard3-61/+50
2021-11-01Add missing accessors for enum itemsMark Wielaard2-4/+20
2021-11-01Get rid of lambda within AST::TypePath and provide a method to return a ↵Kadoi Takemaru3-46/+24
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>
2021-10-30Merge #780bors[bot]4-22/+31
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>