aboutsummaryrefslogtreecommitdiff
path: root/gcc
AgeCommit message (Collapse)AuthorFilesLines
2022-06-01Add hir lowering to ForLoopExpr this will eventually all become a simple ↵Philip Herron3-0/+33
HIR::LoopExpr
2022-06-01Add name resolution to ForLoopExprPhilip Herron2-0/+49
2022-05-26Merge #1283bors[bot]8-54/+67
1283: const folding in gccrs: remove ConstCtx class. r=philberty a=abbasfaisal Card: [Link](https://github.com/Rust-GCC/gccrs/projects/16#card-82300522) This class had potential to hinder porting further const folding code from C++. This edit makes it easy to copy code from constexpr.cc to rust-constexpr.cc and so on. Structs `constexpr_ctx` and `constexpr_global_ctx` have been copied as well as to keep `constexpr_ops_count` after removing the class. These structs will be filled further as the port carries on. The prototypes inside ConstCtx have been copied over to rust-constexpr.cc as static prototypes. Co-authored-by: Faisal Abbas <90.abbasfaisal@gmail.com>
2022-05-26Merge #1280bors[bot]11-66/+249
1280: Str's have the same layout as [T] r=philberty a=philberty Raw strings have a very specific type layout which maps over to Slices. It also has very specific type checking rules so for example: let a:&str = "TEST 1"; let b:&str = &"TEST 2"; Are both the same type this is likely to be for all DST's but lets do one rule at a time. Fixes #1023 #1271 Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2022-05-26const folding in gccrs: remove ConstCtx class.Faisal Abbas8-54/+67
This class has potential to hinder porting further const folding code from C++. So this edit makes it easy to copy code from constexpr.cc to rust-constexpr.cc and so on. Signed-off-by: Faisal Abbas <90.abbasfaisal@gmail.com>
2022-05-25Add testcase to prove bug is fixedPhilip Herron1-0/+23
This bug was fixed in commit cb4d935508def8b250345ba5205a90ad9e177ab4 with related PR #1223 The issue is that associated tpyes get updated depending on the context they are used so we need to monomorphize the types when we can so that we don't then throw off the rest of typechecking with bogus errors like this. Fixes #1237
2022-05-25Merge #1278bors[bot]14-122/+95
1278: Remove inside_loop parameter r=philberty a=philberty The parameter was a hack used to support error handling cases in Break and Continue expression's but this is no longer required. Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2022-05-25Str's have the same layout as [T]Philip Herron11-66/+249
Raw strings have a very specific type layout which maps over to Slices. It also has very specific type checking rules so for example: let a:&str = "TEST 1"; let b:&str = &"TEST 2"; Are both the same type this is likely to be for all DST's but lets do one rule at a time. Fixes #1023 #1271
2022-05-25Remove inside_loop parameter from type resolution of stmts and expressionsPhilip Herron14-122/+95
We already have a Context object containing info about loop contexts. This removes the need for us to pass this variable around simplifying the type resolution code. The parameter was a hack used to support error handling cases in Break and Continue expression's but this is no longer required.
2022-05-25Merge #1275bors[bot]1-40/+1
1275: Remove old hack to handle type inferencing in untyped decalred bindings r=philberty a=philberty This reverts the code fix for 89631998d2ffda0c0c05066c148c6fc19398da5c but keeps the test-case proving that we have not regressed. More info in the commit message. Fixes #1274 #1273 Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2022-05-25Merge #1279bors[bot]2-0/+36
1279: Implement type checking for the `IfLet` expression. r=philberty a=antego Addresses #1177. This change implements the type check for the `IfLet` expression. This is the adapted type checking code from the `MatchExpr`. Tested on this code ``` enum E { X(u8), } fn main() -> i32 { let mut res = 0; let v = E::X(4); if let E::X(n) = v { res = n; } 0 } ``` Compilation finishes without errors. Next is the implementation of the code generation but I'll need help to find where it's located. Co-authored-by: antego <antego@users.noreply.github.com>
2022-05-25Remove old hack to handle type inferencing in untyped decalred bindingsPhilip Herron1-40/+1
In the case where you define let a; with no type to then use this binding and let type inferencing infer the type we used this code to implicitly generate a new type binding to the resolved node id of the the lvalue. This was very dangerous and was always meant to be a stop gap untill we supported more of type inferencing. The issue here was that we were badly overriting a function types within the type-context which hits an ICE in the method resolution code which is expecting function TyTy's within in order to match methods correctly. Fixes #1274 #1273
2022-05-25Merge #1277bors[bot]1-2/+1
1277: Reuse index_expr_ty type r=philberty a=philberty This is a small refactor to remove duplicating the work in type checking the index expression. Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2022-05-24Reuse index_expr_ty type instead of type checking the index expression twicePhilip Herron1-2/+1
2022-05-24Wrapup testing code within CHECKING_P guardsPhilip Herron1-0/+7
2022-05-24type checkantego2-0/+36
2022-05-23Merge #1268bors[bot]8-27/+345
1268: Fix Slice Type Layout r=philberty a=philberty Slices in Rust are represented by TypePaths such as '[i32]'. Though if you actually try to use this explicit type-path you will hit errors such as this type has an unknown size at compile time. This is because this is actually what Rust calls a dynamically sized type. This means when you use types such as: '&[i32]' it is not actually a reference type to a slice. Its a slice in its entirety this means for lack of a better word when you use '*const [i32]' or '&mut [i32]' we end up actually passing around a struct by value _not_ at pointer/reference to it. This patch changes the type-layout so that we handle this layout change properly. This patch will also need to be applied to str types which I believe have a similar layout for safety. The patch also sets up TYPE_MAIN_VARIANT so that we can avoid unnessecary view_convert_expressions between *const [i32] and &mut [i32] which will have the same layout. Reference: https://doc.rust-lang.org/reference/dynamically-sized-types.html https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=672adac002939a2dab43b8d231adc1dc Fixes #1232 Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2022-05-23Merge #1241bors[bot]2-0/+27
1241: Implement name resolution for the IfLet expression. r=philberty a=antego Addresses #1177. Guidance from the ticket #1177: > You should be able to copy how we do name resolution for the if blocks from that file. Though if let statements add a new binding and scope level so you need to declare the pattern so you should be able to see how that is done from rust-ast-resolve-stmt. I don't understand how to modify the block expression resolution so that it can handle the `IfLet` expression. For now, I copied the code from the `MatchExpr` resolution. Not sure how to test it either and what is the desired expected result of the name resolution so I just hope that reviewers will spot the errors. I created this PR in order to get some guidance about how to proceed with it. Thanks! Co-authored-by: antego <antego@users.noreply.github.com>
2022-05-23Fix Slice Type LayoutPhilip Herron8-27/+345
Slices in Rust are represented by TypePaths such as '[i32]'. Though if you actually try to use this explicit type-path you will hit errors such as this type has an unknown size at compile time. This is because this is actually what Rust calls a dynamically sized type. This means when you use types such as: '&[i32]' it is not actually a reference type to a slice. Its a slice in its entirety this means for lack of a better word when you use '*const [i32]' or '&mut [i32]' we end up actually passing around a struct by value _not_ at pointer/reference to it. This patch changes the type-layout so that we handle this layout change properly. This patch will also need to be applied to str types which I believe have a similar layout for safety. The patch also sets up TYPE_MAIN_VARIANT so that we can avoid unnessecary view_convert_expressions between *const [i32] and &mut [i32] which will have the same layout. Reference: https://doc.rust-lang.org/reference/dynamically-sized-types.html https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=672adac002939a2dab43b8d231adc1dc Fixes #1232
2022-05-23Make TyTy::BaseType::destructure recursivePhilip Herron4-31/+54
In the case of Generic Associated Types we end up placeholders->projections->generic-param->i32 This means we need to keep destructuring the TyTy object until we finally get the real type at the end. In order to do this safely we need to ensure we add in recursion limits and apply this where it matters such as compiling types in general too.
2022-05-23Merge #1267bors[bot]3-0/+37
1267: Marklive: support match expr r=philberty a=thomasyonug This makes `MarkLive` support `HIR::MatchExpr` and adds a related test case. Co-authored-by: Thomas Young <wenzhang5800@gmail.com>
2022-05-22Marklive: support match exprThomas Young3-0/+37
2022-05-21Revert "Marklive: support match expr"Philip Herron3-42/+0
This reverts commit 75c9f9f61cb2d69f39d490c47a3b42810c31c1ff. Which was accidently pushed to master outside of the PR system. No harm done :). Happy hacking.
2022-05-21Marklive: support match exprThomas Young3-0/+42
2022-05-20Canonicalize types based on hashing than HirIds and TyTy equalityPhilip Herron12-402/+291
When we compile types for GCC we need to make sure we canonicalize them, this means that for any user defined type such as Structs or Tuples we want all expressions or declarations to use the same tree. Even if we have duplicate tree's we can end up confusing the middle-end and lose out on optimizations as we will be using view_convert_exprs to maintain the consistancy which will marshall between the objects unnessecarily. The old method for doing this kept mappings of HirIds which was fine for simple cases but when generics are involved new Id's are generated so this meant we ended up having a vector of pairs {TyTy::BaseType, tree} and we did a liner search to find the relevant TyTy::BaseType that we equaled to. This was not only slow but did not handle the cases for generic associated types or nested generics. So we needed a more general faster implementation therefore hashing. This patch takes the gcc/tree.h type_hash_canon code and adds in hashing for RECORD and UNION types. This means we will generate a duplicate type then hash it and look for an existing type. This patch will also allow us to fix how we implement monomorphization of functions by nesting the hashes behind DefId's.
2022-05-20privacy: PrivacyReporter: Handle builtin and unimplemented types betterArthur Cohen1-4/+8
2022-05-20privacy: PrivacyReporter: Add type privacy checking on explicit typesArthur Cohen6-7/+198
privacy: Circumvent weird behavior about inference types for now The issue we're facing is detailed in #1260. It's not necessary to fix now to have a good type privacy base privacy: PrivacyReporter: Handle projections and placeholders
2022-05-20mappings: Add reverse mappings from HirId -> NodeIdArthur Cohen2-21/+38
2022-05-19Merge #1255bors[bot]4-343/+340
1255: Privacy report expressions r=CohenArthur a=CohenArthur This adds privacy reporting to all expression types inside our HIR. It also restricts the `PrivacyReporter` visitor to `HIR::Expression`s and `HIR::Stmt`s as a lot of the previous types did not need to be visited. Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
2022-05-18Merge #1252 #1254bors[bot]3-10/+28
1252: privacy: Handle calls to functions defined in previous ancestors r=CohenArthur a=CohenArthur Previously, we would only check if `current_module` was a direct descendant of the item's module. However, we also need to visit each of this item's module's children recursively. 1254: issue #1233: Do not rely on the endianness for testing r=CohenArthur a=CohenArthur This testcase uncovered a very interesting bug requiring a refactor of our `AST::Block` class (#1253), but should still be fixed/adapted in the meantime so that the BE builds on our buildbot do not fail. I've tested this newtestcase with a compiler from 74e836599ce80a11b1fe28065ed7aae6ffa3b7e2, which was the commit pointed out in #1233. The same ICE would still trigger, so I can safely say that this is a different exemple showing the same underlying issue. I'll work on fixing #1253 but it is a refactor we need to think about a little. This should make all the architectures on buildbot happy again! Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
2022-05-18Merge #1250bors[bot]13-66/+172
1250: Support extern-blocks defined within blocks r=philberty a=philberty This adds support for declaring extern blocks within blocks. So this adds the missing name resolution visitor for the statement context. Then we extract out a common extern block hir lowering function for both contexts. The type resolution step needs to be updated to be like the code-generation step so that we can solve these paths in a query rather than a top-down approach but this is a known issue. The final step was to support query-based compilation to extern functions. Fixes #976 Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2022-05-18privacy: PrivacyReporter: Add visitors for all expressionsArthur Cohen4-343/+340
2022-05-18issue #1233: Do not rely on the endianness for testingArthur Cohen1-3/+3
This testcase uncovered a very interesting bug requiring a refactor of our `AST::Block` class (#1253), but should still be fixed/adapted in the meantime so that the BE builds on our buildbot do not fail.
2022-05-17privacy: Handle calls to functions defined in previous ancestorsArthur Cohen2-7/+25
Previously, we would only check if `current_module` was a direct descendant of the item's module. However, we also need to visit each of this item's module's children recursively.
2022-05-17Support extern-blocks defined within blocksPhilip Herron13-66/+172
This adds support for declaring extern blocks within blocks. So this adds the missing name resolution visitor for the statement context. Then we extract out a common extern block hir lowering function for both contexts. The type resolution step needs to be updated to be like the code-generation step so that we can solve these paths in a query rather than a top down approach but this is a known issue. The final step was to support query based compilation to extern functions. Fixes #976
2022-05-17Merge #1246bors[bot]19-98/+1164
1246: Report simple privacy violations r=CohenArthur a=CohenArthur This adds a base visitor for reporting basic privacy violations. For now, only function calls are implemented. Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
2022-05-13backend: Compile range patternsDavid Faust4-1/+133
2022-05-13typecheck: type check range patternsDavid Faust2-0/+84
2022-05-12HIR: Lower range patternsDavid Faust4-0/+68
2022-05-12resolve: Resolve range patternsDavid Faust2-0/+36
2022-05-12HIR: Add RangePatternBoundType and helpersDavid Faust1-0/+44
2022-05-12ast: Add RangePatternBoundType and helpersDavid Faust1-0/+28
2022-05-12privacy: Add base for privacy violation visitorArthur Cohen11-7/+885
2022-05-12resolver: TopLevel: Build tree of child modulesArthur Cohen4-10/+17
2022-05-12mappings: Store NodeIds for visibility_mapArthur Cohen6-35/+46
2022-05-12mappings: Add module->children mappingsArthur Cohen2-0/+29
2022-05-12optional: Allow the creation of Optional<T&>Arthur Cohen3-52/+193
Sadly, this requires specializing the class to keep the underlying pointer of the reference.
2022-05-11Merge #1244bors[bot]7-3/+237
1244: Allow match on integer and char types r=dafaust a=dafaust Enable compiling match expressions on other primitive types like `i32`, `usize` and `char`. Co-authored-by: David Faust <david.faust@oracle.com>
2022-05-11Allow match on primitive typesDavid Faust5-3/+214
This patch enables compiling match expressions for other primitive types, like int and char. However, we cannot currently compile matches on floats; CASE_LABEL_EXPR doesn't support floating-point types.
2022-05-11typecheck: add is_primitive_type_kind helperDavid Faust2-0/+23