aboutsummaryrefslogtreecommitdiff
AgeCommit message (Collapse)AuthorFilesLines
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-29Merge #1188bors[bot]12-5/+223
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-29Merge #1194bors[bot]4-2/+195
1194: Add support for transmute r=philberty a=philberty This PR adds support for the transmute intrinsic by utilizing the convert expression code. It also fixes a bug with our coercion rules which miss two chances for inference variables to resolve slices and arrays. Fixes #1130 Addresses #658 Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2022-04-28Add support for transmute intrinsicPhilip Herron3-2/+171
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]16-400/+323
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-28Merge #1172bors[bot]10-165/+987
1172: Resolve visibility paths r=CohenArthur a=CohenArthur This tackles the remaining issues in #1158. ~~It also contains the commit from #1168 so you should wait for bors to merge that before reviewing it :D~~ done The paths get resolved but their `NodeId`s are not used in the privacy visibility resolver yet. Closes #1158 Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
2022-04-28ast: resolve: Implement `resolve_visibility` methodArthur Cohen5-62/+109
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 Herron4-9/+36
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 Faust12-5/+223
2022-04-27ast: ResolvePath: Move into its own source fileArthur Cohen7-266/+328
2022-04-27Merge #1184bors[bot]9-107/+96
1184: Fix bad name resolution on path with generic segments r=philberty a=philberty This fix breaks down into two commits the first commit fixes the issue directly then the second one fixes the regression that was introduced in the first. The TLDR for this patch set is that when we resolve the path here: module::transmute The name-resolver wronly added the specified generic arguments into the canonical path meaning that the root segment could not be name-resolved such that during type resolution we iterate and apply the generic arguments appropriately to the root segment. In fixing this it introduced a regression exposing a few more complex issues with inference variables but for a more complete explanation about that please read the commit message from ea38a59ee8329bb7b309400a7de57d53ad7bde31 Fixes #1173 Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2022-04-27Merge #1163bors[bot]5-13/+83
1163: rust-session-manager: handle `crate_name` attribute r=philberty a=liushuyu - rust-session-manager: handle `crate_name` attribute Fix #789 properly Co-authored-by: liushuyu <liushuyu011@gmail.com>
2022-04-26rust-session-manager: handle crate_name attributeliushuyu5-13/+83
Signed-off-by: Zixing Liu <liushuyu011@gmail.com>
2022-04-26Fix regression in fix for #1173Philip Herron8-102/+76
A regression was introduced in e476433c45624ec713395c85bcbd410806e90639 this was a tricky bug to fix. There are several fixes here but they all rely on one another so in order to have a commit which does not introduce more regressions it seems best to keep these fixes together. In this patch we remove the check at the end of type resolution to look for any error type nodes within the type context since this will only ever produce false postive/duplicate errors. Since any real error will have been emitted at the time of occurance. We also fixed a bug in infering the types on a generic type so for example: struct Foo<A,B>(A,B); impl<T> Foo<T,T> { ... } In this example the Self type on the impl block will be Foo<T,T> so in the code for infering the arguments for the type we simply iterated each of the generic parameter mappings and if any of them need substitution we generate implict inference variables for them but in this case the ParamType is T so generating one for each of these T's will introduce a stay inference variable which we cannot infer so it will not be used. This patch keeps a mapping inside SubstitutionRef::infer_substitions to ensure we don't introduce any extra inference variables than required. The final fix was around how we clone inference variables, there is a comment explaining this but we cannot safely clone a inference variables simply by creating a new object, inference variables are closely tied to the type-conext so that when we infer the type to be a concrete type we need to be able to update the reference in memory but simply cloning an inference variable does not guarentee this to occur. This change ensures that we create a new implict inference variable and setup the reference and chain apropirately.
2022-04-26Fix bad name resolution of path with generic segmentsPhilip Herron3-7/+22
When name-resolving paths we expect the name-resolver must resolve the root of the path. Such that a path might be module::type::associated_function We expect that the name resolution step must be able to resolve the module::type Portion of the path, it is permissive to allow everything after that to fail name resolution as this may require generic arguments of type inferencing to figure out which associated items are required. The issue in this referenced issue was that the generic arguments here were wrongly canonicalized to be part of the root path which meant the segment could not be name-resolved allowing the type resolution system to perform the generic specialization. Fixes #1173
2022-04-26Merge #1176bors[bot]2-0/+61
1176: Keep `SimplePath{Segment}`s in mappings r=CohenArthur a=CohenArthur Addresses #1159 Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
2022-04-26Merge #1174bors[bot]4-14/+24
1174: Remove default location for `SimplePath`s r=CohenArthur a=CohenArthur This removes the default argument for the locus of `SimplePath`s. Addresses #1159 There are a lot of places in the code where it is not possible to insert a "correct" location for these `SimplePath`s: namely, when creating the use statement for the standard library's prelude, or when creating the `SimplePath`s of attributes. I've left a few FIXMEs in these cases because I'm unsure about the proper course of action. Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
2022-04-26Merge #1171bors[bot]1-2/+2
1171: Dockerfile: change base image r=philberty a=liushuyu - Dockerfile: change base image This commit fixes a recent Docker building error where the GLibc version mismatches. Co-authored-by: liushuyu <liushuyu011@gmail.com>
2022-04-26mappings: Add mappings for SimplePath{Segment}sArthur Cohen2-0/+61
2022-04-26ast: SimplePath: Remove default location parameterArthur Cohen4-14/+24
2022-04-26dockerfile: change the base image ...liushuyu1-2/+2
... to match Rust container image's base image Signed-off-by: Zixing Liu <liushuyu011@gmail.com>
2022-04-26Merge #1162 #1167 #1168 #1170bors[bot]8-900/+1059
1162: CI: catch malformed test cases r=philberty a=liushuyu - catch malformed test cases and use GitHub Actions' annotation feature to mark the failures 1167: Fix nullptr when resolving the root of a path expression r=philberty a=philberty When we resolve paths we don't have a _type_, in this scenario there is a bug in our resolution of this generic function so this means the root_tyty is nullptr but the offset is non zero so we return nullptr. Addresses #1132 This test case no longer ICE's but still fails. I have a fix in progress for this ```rust mod mem { extern "rust-intrinsic" { fn transmute<U, V>(_: U) -> V; } } pub trait Hasher { fn write(&mut self, bytes: &[u8]); fn write_u16(&mut self, i: u16) { self.write(&mem::transmute::<_, [u8; 2]>(i)) } } pub struct SipHasher; impl Hasher for SipHasher { #[inline] fn write(&mut self, msg: &[u8]) {} } ``` 1168: ast: resolve: Move ResolveItem into its own source file r=CohenArthur a=CohenArthur Since we need to add new functions to resolve visibilities, we might as well refactor this file before hand :) 1170: Implement macro expansion in `IfExpr`, `IfExprConseqElse`, `IfExprConseqIf`, `IfExprConseqIfLet`. r=CohenArthur a=antego Addresses #1141. Following up on #1161. This change adds support for the macros inside the `if` condition expressions. Things to note: 1. Judging by my research, the `IfExprConseqIfLet` isn't used. The parser treats the syntax `let var = if ...` as a `let` expression followed by `if` expression: ![Screen Shot 2022-04-26 at 9 47 29 am](https://user-images.githubusercontent.com/1451467/165258060-6a42f918-2585-4aef-9da5-9d60d69ca248.png) 2. I didn't add the macro expansion to the `IfLetExpr...` family of expressions because I wasn't able to write a test case reproducing the missing macro expansion. I've tried the following code ```rust fn main() -> i32 { let mut res = 0; enum E { X(u8), Y(u8), Z(u8), } let v = E::Y(12); if let E::Y(n) = v { res = 1; } 0 } ``` which caused the compiler error ``` FAIL: rust/compile/macro43.rs (internal compiler error: in append_reference_for_def, at rust/resolve/rust-name-resolver.h:227) ``` Co-authored-by: liushuyu <liushuyu011@gmail.com> Co-authored-by: Philip Herron <philip.herron@embecosm.com> Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com> Co-authored-by: antego <antego@users.noreply.github.com>
2022-04-26Merge #1166bors[bot]2-20/+5
1166: Support inference of generic parameters on paths behind reference's r=philberty a=philberty We used a hack in the parser to turn simple cases such as &Foo(..) into: BorrowExpr CallExpr( IdentifierExpr + <Argument-expressions>)) The IdentifierExpr here is parsed as a PathExpression but to simplify things at the time it seemed logic to see these as identifier expressions but this is actually a Path and we need to be careful about generic arguments here. Identifiers are simply identifiers and must not be changed or coherence of inference variables will become a jumble of inference variables trying to infer one another inside purely generic code. This patch leaves the PathInExpressions as Path's instead of trying to be clever and turn them into identifiers. Fixes #1165 Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2022-04-26Implement macro expansion in `IfExpr`, `IfExprConseqElse`, `IfExprConseqIf`, ↵antego2-0/+43
`IfExprConseqIfLet`. Addresses #1141
2022-04-25CI: catch malformed test casesliushuyu2-6/+32
Signed-off-by: Zixing Liu <liushuyu011@gmail.com>
2022-04-25ast: resolve: Move ResolveItem into its own source fileArthur Cohen3-893/+983
2022-04-25Merge #1164bors[bot]2-2/+11
1164: Add `NodeId`s to `SimplePath{Segment}`s r=CohenArthur a=CohenArthur This is a necessary first step which addresses #1158 I am working on the visibility resolver and simple-path name resolver in parallel and will need those changes. I'm not sure if the `has_path` method is necessary since we will have `HIR::Visibilities` in the visibility resolver, which will be desugared. Maybe I am doing this wrong and we should be working on `AST::Visibilities` instead? Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
2022-04-25Fix nullptr when resolving the root of a path expressionPhilip Herron1-1/+1
When we resolve paths we don't have a _type_, in this senario there is a bug in our resolution of this generic function so this means the root_tyty is nullptr but the offset is non zero so we return nullptr. Addresses #1132
2022-04-25Support inference of generic parameters on paths behind reference'sPhilip Herron2-20/+5
We used a hack in the parser to turn simple cases such as &Foo(..) into: BorrowExpr CallExpr( IdentifierExpr + <Argument-expressions>)) The IdentifierExpr here is parsed as a PathExpression but to simplify things at the time it seemed logic to see these as identifier expressions but this is actually a Path and we need to be careful about generic arguments here. Identifiers are simply identifiers and must not be changed or coherence of inference variables will become a jumble of inference variables trying to infer one another inside purely generic code. This patch leaves the PathInExpressions as Path's instead of trying to be clever and turn them into identifiers. Fixes #1165
2022-04-25ast: Visibility: Add `has_path` methodArthur Cohen1-0/+3
2022-04-25ast: SimplePath{Segment}: Add NodeId fieldsArthur Cohen1-2/+8
2022-04-25Merge #1161bors[bot]4-6/+103
1161: Implement macro expansion for ComparisonExpr, LazyBooleanExpr, AssignmentExpr r=CohenArthur a=antego Following up on https://github.com/Rust-GCC/gccrs/issues/1141 Currently the macro expansion doesn't work for ComparisonExpr, LazyBooleanExpr, AssignmentExpr. To fix this, I just copied the code from the `ArithmeticOrLogicalExpr` and it seemed to work. I don't like the code duplication, happy to try refactoring it into a separate function. Will work on the macro expansion in the `if` expressions next. Co-authored-by: antego <antego@users.noreply.github.com>
2022-04-25Merge #1160bors[bot]5-541/+563
1160: Refactor name resolver r=CohenArthur a=CohenArthur This PR splits up the `rust-name-resolver.h` file into source and header. It also removes a bunch of `iterate_*` functions: Some were not used anymore, and some were refactored. Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>