aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust
AgeCommit message (Collapse)AuthorFilesLines
2022-05-06Ensure the coercion sites are applied correctly on unionsPhilip Herron1-7/+41
When we construct a union, we were wrongly compiling the constructor without taking into account the associated union index. This means we ended up trying to coerce the wrong field which was always zero here which resulted in a silent failure by returning error mark node. The offending test case was: gcc/testsuite/execute/torture/slice1.rs
2022-05-06ast: lower: Refactor ASTLowerItem in its own source fileArthur Cohen2-778/+788
2022-05-05Merge #1217bors[bot]1-1/+7
1217: Fix size used in unsized adjustments r=philberty a=philberty When we coerce from an array to a slice we take the full capacity of the array as the size to the FatPtr slice object but this was off by one. This The TYPE_MAX_VALUE is not the correct method of accessing this but instead it needs to take into account other values to get the correct HOST_WIDE_INT Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2022-05-05privacy: Add base for resolving SimplePaths to ModulesArthur Cohen8-30/+95
This also fixes the missing kind in HIR::Visibility. Having both `pub` and `pub restricted` as a single variant in the HIR::Visibility::Kind enum was a mistake, as it cause the path resolver to be triggered for `pub` visibilities which do not refer to any paths. Finally, erroneous calls to Visibility::create_error() are removed. This caused a lot of ICEs now that the Visibility lowering logic is fixed
2022-05-05Fix size used in unsized adjustmentsPhilip Herron1-1/+7
When we coerce from an array to a slice we take the full capacity of the array as the size to the FatPtr slice object but this was off by one. This The TYPE_MAX_VALUE is not the correct method of accessing this but instead it needs to take into account other values to get the correct HOST_WIDE_INT
2022-05-04hir: SimplePath: Add location infoArthur Cohen3-7/+9
2022-05-04ast: Lower SimplePaths properlyArthur Cohen9-17/+135
2022-05-04Take advantage of OBJ_TYPE_REF'S in dyn callsPhilip Herron4-72/+83
OBJ_TYPE_REF's are the gcc nodes that signify that this is a virtual call which gives a hint to the optimizers for devirtualization. Fixes #996 Fixes #854
2022-05-04Merge #1206 #1209 #1211 #1212 #1213bors[bot]6-25/+186
1206: Use correct format specifiers for unisnged HOST_WIDE_INT r=philberty a=philberty The code here was wrongly assuming the unsigned long interface which is not correctly for all targets. 1209: Allow match on boolean expressions r=philberty a=dafaust Enables compiling `match` expressions where the scrutinee is a boolean expression. Also enable compiling match arms with Literal patterns, since `true` and `false` literals are commonly used with matches on boolean expressions. Fixes: #1207 1211: Preserve inside_loop context when type checking match r=philberty a=dafaust Previously, we would lose the context of being inside a loop when compiling a `match`. This would lead to incorrect error messages like "cannot 'break' outside of a loop" when trying to break out of a loop from within a `match` expression. Fixes: #1196 1212: intrinsic: add breakpoint intrinsic r=philberty a=liushuyu - intrinsic: add breakpoint intrinsic Addresses #658 1213: intrinsic: add rotate_left and rotate_right intrinsic r=philberty a=liushuyu - intrinsic: add rotate_left and rotate_right intrinsic Address #658 Co-authored-by: Philip Herron <philip.herron@embecosm.com> Co-authored-by: David Faust <david.faust@oracle.com> Co-authored-by: liushuyu <liushuyu011@gmail.com>
2022-05-04intrinsic: add rotate_left and rotate_right intrinsicliushuyu1-1/+124
2022-05-03Preserve inside_loop context when compiling matchDavid Faust1-1/+1
2022-05-03Compile matches on boolean expressionsDavid Faust1-16/+35
2022-05-03Compile literal patterns for match expressionsDavid Faust2-1/+15
2022-05-03Use correct format specifiers for unisnged HOST_WIDE_INTPhilip Herron1-6/+7
The code here was wrongly assuming the unsigned long interface which is not correcty for all targets.
2022-05-03intrinsic: add breakpoint intrinsicliushuyu1-0/+4
2022-05-02Merge #1197bors[bot]7-95/+151
1197: Support recursive coercion sites r=philberty a=philberty There are two changes are part of this PR one where we update the address_expression helper to take a ptrtype tree. Since the default build_address_expr_loc was automatically building a pointer type of the TREE_TYPE of the operand which is not correct since we sometimes want REFERENCE_TYPES instead of POINTER_TYPES. The 2nd commit enhances the coercion_site code to recursively walk the tree and their types to handle coercions to dyn traits or do array bounds checking etc. This gets rid of the get_root hack used and cleans up the code in general. Fixes #1146 Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2022-05-02Merge #1199bors[bot]3-2/+25
1199: Add new as_name interface for Dynamic types r=philberty a=philberty The Gimple names of our dyn trait objects were looking like: const struct dyn [HIR Trait: FnLike->[C: 0 Nid: 31 Hid: 38 Lid: 13] [(FN call ), ]<Self, &isize, &isize>] & const f This is a horrible name but useful for debugging this patch fixes this so we have a seperate naming for generating the type. So now it looks like: const struct dyn [FnLike<Self, &isize, &isize>] & const f Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2022-05-02Merge #1201bors[bot]2-4/+6
1201: Generic functions should not be TREE_PUBLIC r=philberty a=philberty Generic functions cannot be public since the symbols could overlap in linking other crates reusing the same generic. The other benefit here is that when optimizations are turned on we can eliminate more code since the symbol does not _need_ to be public. Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2022-05-02Merge #1191bors[bot]8-69/+438
1191: Resolve simple paths in use items r=CohenArthur a=CohenArthur In order to resolve `SimplePath`s, we have to expand all paths present in a `UseDeclaration` and resolve them. For example, we want to resolve two paths with the following statement `use foo::bar::{baz, bul}`: `foo::bar::baz` and `foo::bar::bul` This also removes the prelude inclusion (`use std::prelude::v1::*`) since we cannot resolve it (yet!) Needs #1172 to compile Adresses #1159 Adresses #1187 Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
2022-05-02Update gcc/rust/expand/rust-attribute-visitor.ccantego1-0/+1
Co-authored-by: CohenArthur <cohenarthur.dev@gmail.com>
2022-05-02Generic functions should not be TREE_PUBLICPhilip Herron2-4/+6
Generic functions cannot be public since the symbols could overlap in linking other crates reusing the same generic. The other benifit here is that when optimizations are turned on we can eliminate more code since the symbol does not _need_ to be public.
2022-05-01Code deduplication for expression and type expansions.antego2-120/+56
Follow-up for #1161
2022-04-30Add new as_name interface for Dynamic typesPhilip Herron3-2/+25
The Gimple names of our dyn trait objects were looking like: const struct dyn [HIR Trait: FnLike->[C: 0 Nid: 31 Hid: 38 Lid: 13] [(FN call ), ]<Self, &isize, &isize>] & const f This is a horrible name but useful for debugging this patch fixes this so we have a seperate naming for generating the type. So now it looks like: const struct dyn [FnLike<Self, &isize, &isize>] & const f
2022-04-30Support recursive coercion sitesPhilip Herron2-78/+101
Our code for coercion sites are handled in two places once where we do the type-checking portion and one where we do the code-generation. This makes the code-generation piece recursive so that we apply the behaviours consistantly when types need checked or converted. Fixes #1146
2022-04-30Fix address expression to respect reference/pointer typesPhilip Herron7-20/+53
2022-04-29Merge #1188bors[bot]8-5/+149
1188: Support align and packed repr layout on structs r=dafaust a=dafaust This is a start at handling the various layout options supported by Rust, beginning with `#[repr(align(N))]` and `#[repr(packed(N))]`, on structs and tuple structs. There are several other layout options which remain to be supported such as `#[repr(C)]`, `#[repr(transparent)]`, combinations e.g. `#[repr(C, packed(2))]`, as well as layouts on union and enum types. Fixes: #915 Co-authored-by: David Faust <david.faust@oracle.com>
2022-04-29ast: Resolver: Refactor ResolveRelativeTypePath in its own source fileArthur Cohen2-50/+52
2022-04-29ast: Resolver: Flatten use declarations to pathsArthur Cohen6-19/+386
In order to resolve `SimplePath`s, we have to expand all paths present in a `UseDeclaration` and resolve them. For example, we want to resolve two paths with the following statement `use foo::bar::{baz, bul}`: `foo::bar::baz` and `foo::bar::bul`. This also removes the prelude inclusion (`use std::prelude::v1::*`) since we cannot resolve it (yet!)
2022-04-28Add support for transmute intrinsicPhilip Herron1-2/+113
This adds in the transmute intrisic by utilizing the convert_expression framework we have in the backend class. Fixes #1130 Addresses #658
2022-04-28Add missing type inferencing rules for arrays and slicesPhilip Herron1-0/+24
2022-04-28Merge #1190 #1192 #1193bors[bot]15-400/+317
1190: Fix ICE in reachability class and refactor associated types code r=philberty a=philberty There are several fixes going on to solve these issues which overlap with one another so it seemed best to pack them within the same PR. The main issue for #1128 was that we did not resolve a trait when it was unused leading to us hitting the ICE in the privacy pass. Since the type check context was empty for the trait since it was not resolved. To fix this we needed to refactor the trait resolver to resolve the trait as part of iterating the crate. This resulted in some regressions in the testsuite so this is why we need the the other commits. Which required us to finally perform the refactor specified in #1105 to fix these. Fixes #1105 #1128 #1132 1192: Add an assertion to avoid peeking when the stack is empty r=philberty a=philberty This will ensure we get a proper ICE instead of memory corruption/segv. Addresses #1130 1193: Remove unused parameter caller from generating Call expressions r=philberty a=philberty Within const context the fncontext maybe empty which in turn results in a segv for generating const calls which will be evaluated by the const-expr code anyway. Addresses #1130 Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2022-04-28ast: resolve: Implement `resolve_visibility` methodArthur Cohen4-62/+95
2022-04-28Remove unused parameter caller from generating Call expressionsPhilip Herron3-22/+13
Within const context the fncontext maybe empty which in turn results in a segv for generating const calls which will be evaluated by the const-expr code anyway. Addresses #1130
2022-04-28Add an assertion to avoid peeking when the stack is emptyPhilip Herron1-1/+5
2022-04-28ast: resolve: Add SimplePath path resolverArthur Cohen2-1/+100
2022-04-28ast: resolve: Add SimplePathSeg -> CanonicalPath resolverArthur Cohen2-0/+12
2022-04-28ast: resolve: Add source for ResolverBaseArthur Cohen3-165/+813
2022-04-28privacy: visibility: Do not use SimplePaths this lateArthur Cohen1-0/+11
2022-04-28ast: resolve: Move ResolveItem into its own source fileArthur Cohen1-0/+5
2022-04-28Fix ICE on missing TypeParam within type contextPhilip Herron3-9/+30
During type-resolution we resolve/type-check traits in a query based way. So when we reference a trait we look it up as required but this left a case for the privacy pass where the type-context information on the trait when the trait was not used meant there was no type-checking performed on the trait. This patch adds an interface to directly resolve the trait when as we iterate the crate so we do it as required. There is already code in the trait resolver to check if we have already type-resolved this trait. Fixes #1128
2022-04-28Refactor trait resolution code into cc file from headerPhilip Herron2-179/+197
2022-04-28Complete refactor of generic traits handlingPhilip Herron9-197/+67
From PR #1086 I introduced a new setup_associated_types2 interface which is used to ensure we handle the complex associated types in libcore slices but this interface was inconsistant as well as the get_projected_type. This path refactors the code base to get rid of the old setup_associated_types interface in favour of this new one. It also removes the get_projected_type interface which was not going to work either. Fixes #1105
2022-04-28Fix equality interface on TyTy::FnTypePhilip Herron1-0/+13
We missed a case to ensure the substitutions are equal in the is_equal interface. This becomes important when dealing with generic associated types since the projections could end up overlapping and we need to differentiate them by the substitutions and monomorphization.
2022-04-28Merge #1189bors[bot]5-42/+53
1189: Add missing `SimplePath`s location r=CohenArthur a=CohenArthur Sorry to new contributors but I think I've taken all the good first issues we opened yesterday... Closes #1179 Closes #1180 Closes #1181 Closes #1182 Necessary for #1172 Addresses #1159 Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
2022-04-28Merge #1186bors[bot]7-266/+328
1186: Refactor `ResolvePath` in its own file r=CohenArthur a=CohenArthur Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
2022-04-28ast: Add location info to remaining meta itemsArthur Cohen2-19/+20
2022-04-28ast: Add location info to MetaWordArthur Cohen2-4/+6
2022-04-28ast: Add location info to MetaValueStrArthur Cohen2-10/+21
2022-04-28parse: Add correct location to all public visibilitiesArthur Cohen3-19/+16
2022-04-27Support align and packed repr on structsDavid Faust8-5/+149