aboutsummaryrefslogtreecommitdiff
path: root/gcc
AgeCommit message (Collapse)AuthorFilesLines
2022-04-16Merge #1122bors[bot]1-1/+1
1122: testsuite/rust: fix test case failure on macOS r=CohenArthur a=liushuyu - extent `macro_return` xfail targets to three-segment triples Co-authored-by: liushuyu <liushuyu011@gmail.com>
2022-04-16Merge #1118bors[bot]3-6/+92
1118: Add reachability visitor to Enum variants r=CohenArthur a=CohenArthur This visits all of an enum's variants and their fields if present. To do that properly, this adds a new `EnumItemKind` enum which allows static casting when visiting each variant of the enum (kept as an `EnumItem` class which is derived three times) Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
2022-04-15testsuite/rust: extent xfail targetsliushuyu1-1/+1
2022-04-15Merge #1107bors[bot]2-0/+14
1107: tests: Improve timeout handling r=philberty a=liushuyu - add a 10-second timeout for individual compile test - add a xfail test case to ensure the timeout mechanism is working Co-authored-by: liushuyu <liushuyu011@gmail.com>
2022-04-15Move cfg!() macro to builtinsantego5-49/+40
Fixes #1039
2022-04-14privacy: reachability: Visit all variants of an Enum and their fieldsArthur Cohen1-0/+32
2022-04-14hir: Add `EnumItemKind` enum for EnumItem classesArthur Cohen2-2/+41
2022-04-14privacy: reachability: wip: Update all base reach levelsArthur Cohen1-4/+19
2022-04-14Merge #1110bors[bot]2-42/+87
1110: Add Reachability visitors for items with generics r=CohenArthur a=CohenArthur This factors generics' predicates visiting in the `ReachabilityVisitor` and calls the function in other items with generic parameters Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
2022-04-14Merge #1113bors[bot]5-0/+119
1113: macros: Add env! macro r=CohenArthur a=omachota Added the `env!()` macro and relevant test cases Fixes: #977 Signed-off-by: Ondřej Machota <ondrejmachota@gmail.com> Co-authored-by: Ondřej Machota <ondrejmachota@gmail.com>
2022-04-13macros: Add env! macroOndřej Machota5-0/+119
Signed-off-by: Ondřej Machota <ondrejmachota@gmail.com>
2022-04-13Merge #1088bors[bot]11-11/+170
1088: rust-session-manager: better crate name handling logic r=philberty a=liushuyu - rust-session-manager: set and validate crate name properly - testsuite/rust: fix the testcases and add more testcases for testing crate name handling Co-authored-by: liushuyu <liushuyu011@gmail.com>
2022-04-13privacy: reachability: Add base visitor for items with generic paramsArthur Cohen2-22/+58
Co-authored-by: philberty <philip.herron@embecosm.com>
2022-04-13privacy: reachability: Cleanup Struct definition visitorArthur Cohen2-33/+42
2022-04-13Merge #1111bors[bot]4-37/+45
1111: Add AST Private Visibilities r=CohenArthur a=CohenArthur When parsing a visibility in `parse_visibility`, it is not an error to not have a pub token: It simply means we want to create a private visibility. If we had C++14 or another language, we could instead represent all visibilities as an optional<AST::Visibility> where the Visibility class would not need to change. But I think the best course of action for our case is to instead keep visibilities even when they are private and have a special case in the `VisKind` enumeration. This also enables HIR lowering of visibilities to be performed properly for private items Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
2022-04-13rust-session-manager: address more commentsliushuyu2-22/+32
Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com> Signed-off-by: Zixing Liu <liushuyu011@gmail.com>
2022-04-13visibility: Add create_private() static functionArthur Cohen4-37/+45
When parsing a visibility in `parse_visibility`, it is not an error to not have a pub token: It simply means we want to create a private visibility. If we had C++14 or another language, we could instead represent all visibilities as an optional<AST::Visibility> where the Visibility class would not need to change. But I think the best course of action for our case is to instead keep visibilities even when they are private and have a special case in the `VisKind` enumeration.
2022-04-12rust-session-manager: address comments ...liushuyu6-44/+89
... also more closely match rustc's behavior Signed-off-by: Zixing Liu <liushuyu011@gmail.com>
2022-04-12testsuite/rust: adapt/fix the testcases ...liushuyu9-2/+32
... so that the tests will still pass after the crate name logic change Signed-off-by: Zixing Liu <liushuyu011@gmail.com>
2022-04-12rust-session-manager: set and validate crate name properly ...liushuyu2-6/+80
... should fix #789 Signed-off-by: Zixing Liu <liushuyu011@gmail.com>
2022-04-12Merge #1109bors[bot]23-47/+22
1109: rust: Allow gccrs to build on x86_64-apple-darwin with clang/libc++ r=CohenArthur a=simonpcook This makes changes to the includes such that gccrs can be built with clang/libc++, and for x86_64-apple-darwin. Similarly, a couple of changes have been made to creating MacroInvocations and wrapping into ExprOrStmts for libc++ compatibility. Co-authored-by: Simon Cook <simon.cook@embecosm.com>
2022-04-12rust: Allow gccrs to build on x86_64-apple-darwin with clang/libc++Simon Cook23-47/+22
This makes changes to the includes such that gccrs can be built with clang/libc++, and for x86_64-apple-darwin. Similarly, a couple of changes have been made to creating MacroInvocations and wrapping into ExprOrStmts for libc++ compatibility.
2022-04-12Merge #1082bors[bot]14-9/+591
1082: Add base for privacy visitor r=CohenArthur a=CohenArthur This PR is extremely early and implements some building blocks for privacy visitors. I'd like to get some feedback on the architecture and, if satisfactory, merge this first "visitor" which only takes care of visiting HIR struct definitions, to make reviewing easier. We could also merge it to a different branch for now, in order to not add an incomplete pass to the compiler. Thanks! Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
2022-04-12Merge #1108bors[bot]1-0/+60
1108: Add missing unify rules for inference variables r=philberty a=philberty Inference variables can unify with anything so this includes these covariant types like references/slices etc. This patch is needed for more complex type-checking in libcore and generics. Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2022-04-12Merge #1106bors[bot]2-5/+9
1106: macros: fix an infinite loop in `concat!` macro parser r=CohenArthur a=liushuyu - Fix concat macro parser issue which caused an infinite loop when invalid token is encountered Co-authored-by: liushuyu <liushuyu011@gmail.com>
2022-04-12privacy: reachability: Visit all types of a struct's public fieldsArthur Cohen1-7/+4
2022-04-12privacy: reachability: Visit all struct generic predicatesArthur Cohen4-9/+38
2022-04-12typectx: Mark lookup_type() method as constArthur Cohen2-2/+2
2022-04-12privacy: Keep DefIds in reachability map insteadArthur Cohen3-5/+19
This commit also specialized `std::hash<DefId>` to be able to use it as key in {unordered_}maps
2022-04-12hir: Keep BaseKind enum inside the Node classArthur Cohen4-26/+27
Co-authored-by: philberty <philip.herron@embecosm.com>
2022-04-12privacy: reachability: Add base for visiting struct definitionsArthur Cohen1-4/+25
2022-04-12hir: StructField: Add `get_visibility()` methodArthur Cohen1-0/+2
2022-04-12privacy: reachability: Add better implementation for StructStructArthur Cohen2-7/+8
2022-04-12privacy: reachability: Add `maybe_get_vis_item` helper static functionArthur Cohen1-8/+16
2022-04-12Add missing unify rules for inference variablesPhilip Herron1-0/+60
Inference variables can unify with anything so this includes these covariant types like references/slices etc. This patch is needed for more complex type-checking in libcore and generics.
2022-04-12privacy: ctx: Add proper implementations for insert_reachability() andArthur Cohen4-11/+88
lookup_reachability() Inserting reach levels in the reachability_map should only be done if the existing reach level is lower than the provided one. If the node is not yet present in the reachability map, insert it no matter what
2022-04-12hir: Visibility: Add is_public() methodArthur Cohen1-0/+3
2022-04-12privacy: reach: Rename ReachLevel enumArthur Cohen3-5/+8
2022-04-12privacy: Add base for privacy-related visitorsArthur Cohen8-0/+373
2022-04-12hir: Add `Kind` enum to downcast safelyArthur Cohen2-7/+60
2022-04-12Merge #1103bors[bot]12-121/+120
1103: Lower AST::Visibility to HIR::Visibility properly r=CohenArthur a=CohenArthur Fixes #1093 This should cover every case since the previous code simply created public HIR visibilities. The PR refactors the HIR::Visibility struct to be tinier and a desugared version of the AST one. Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
2022-04-12macros: fix an infinite loop ...liushuyu2-5/+9
... introduced in fed5a41fb1c2c91b77297fdd6d3731078f480441, should fix #1102 Signed-off-by: Zixing Liu <liushuyu011@gmail.com>
2022-04-11testsuite/rust: add a xfail test case ...liushuyu1-0/+10
... to show case the timeout system is working
2022-04-11testsuite/rust: add a 10-second timeout for each compile testliushuyu1-0/+4
2022-04-11Support Slices from rustc libcore 1.49.0Philip Herron21-289/+804
This is unfortunatly a mega commit, in testing gccrs against the slice code which is highly generic stress tested our implementation of generics and poked the hole in or lack of support of generic higher ranked trait bounds and more specificily generic associated types. More refactoring is needed to eventually remove the setup_associated_types and replace it entirely with this new setup_associated_types2 which takes into account the trait bound receiver and its predicate. In order to support slices, the code in libcore defines an index lang item ```rust impl<T, I> Index<I> for [T] where I: SliceIndex<[T]>, { type Output = I::Output; fn index(&self, index: I) -> &I::Output { index.index(self) } } ``` This is the entry point where by the self here is a generic slice. So in our case we have: ```rust let a = [1, 2, 3, 4, 5]; let b = &a[1..3]; ``` 'a' is an array and b is our desired slice, so we must remember that from algebraic data type constructor. But our receiver is still an array, so in order to be able to call this index lang item we must 'unsize' our array (see #1045) this allows for method resolution to adjust an array into a FatPtr which is simply a struct containing reference to the array and the capacity (GCC MAX_DOMAIN) of the underlying array data type. So now we are able to infer the substituions for this index fn call to: ``` fn index(&self : [<integer>], index: Range<integer>) -> &I::Output->placeholder ``` The complex piece here is the Higher ranked trait bound: ``` where I: SliceIndex<[T]> ``` So in this method call no generic arguments are specified so we must try and infer the types. So during monomorphization the inference variables need to be recursively propogated into the higher ranked trait bound. So that the higher ranked trait bound looks like: ``` SliceIndex<[<integer>]> // like we seen earlier for the Self type ``` The monomorphization stage also needs to take into account the higher ranked trait bound's type which is 'I' and infered to be: Range<integer>. This is where specialization needs to occur. ```rust unsafe impl<T> SliceIndex<[T]> for Range<usize> { type Output = [T]; unsafe fn get_unchecked(self, slice: *const [T]) -> *const [T] { unsafe { let a: *const T = slice.as_ptr(); let b: *const T = a.add(self.start); slice_from_raw_parts(b, self.end - self.start) } } fn index(self, slice: &[T]) -> &[T] { unsafe { &*self.get_unchecked(slice) } } } ``` So now we need to compute the constrained type-parameters for this specialized impl block. And in this case is fairly simple: ``` impl<T> SliceIndex<[T]> for Range<usize> vs I: SliceIndex<[<integer>]> and Range<<integer>> ``` Here we need to compute that T is <integer>, which is required since associated type Output is used in our original method call and this is generic which requires us to set it up but both the Self type or the trait bound here in this impl block could be generic so special care needs to be taken to compute this safely. Once the constrained types are computer we can also unify the Self types which specializes our original Range<integer> type into the correct Range<usize> that this trait bound expects. We used a callback here when we reusively pass down the SubstitutionArgumentMappings when any Parameter type is substitued we get a callback to hold a set of mappings in a generic way what generic types are being substituted. From all of this work this stressed our generics implementation to breaking point due to the use of the generic trait bound which was not supported and it also exposed many bugs in our implementation. This is why I feel it is best to keep this a large patch as so much of this patch will cause regressions if we don't keep it together. One of the main changes we have made is how we handle parameters substitution for example we might have a generic such as '&Y' but this gets substituted with Y=T which is a new type parameter. Before we used to directly just change this from &Y to &T which is correct but this looses context from the generic argument bindings. So now we maintain the information that &Y changes to &(Y=T) so that we see Y was substutued with T so that subsequent substitutions or inferences can change Y=?T and correctly map &Y to &(Y=T) to &(Y=?T). The other major piece which was changed during this patch was how we perform the method resolution on higher ranked trait bound calls where we compute the specified bound possible candidates once so that in the case: ``` trait Bar { fn baz(&self) } fn <T:Bar> foo(a: &T) { a.baz() } ``` Here the type parameter T gets derefed to find the specified bound of Bar which contains the method baz. This means that we try calling baz with T vs &T which fails then we try the reference type T again. This results into two useless adjustments of indirection and referencing but GCC optimizes this away. Before this patch we computed the specified bound for each attempt which was wrong. Fixes #849
2022-04-11ast: Translate visibilities properly when lowering AST nodesArthur Cohen7-35/+37
Previously, the lowering code would simply create public `HIR::Visibility`s for every AST Node being lowered. We now call `translate_visibility()` properly to perform the necessary conversions
2022-04-11ast: lowering: Add translate_visibility() static functionArthur Cohen4-16/+66
This function desugars `AST::Visibility`s into `HIR::Visibility`s, performing all the necessary checks and conversions
2022-04-11hir: Cleanup Visibility structArthur Cohen4-77/+24
The HIR::Visibility struct was extremely similar to the AST::Visibility one. However, we do not need to keep as much information at the HIR level: Syntactic sugar such as pub(crate) can be kept as the desugared form, which is pub(in crate). Likewise, pub(self) can be desugared to pub(in self) which amounts to having a private item.
2022-04-11Allow substitutions to be handled on primitive types without causing unreachablePhilip Herron1-13/+16
2022-04-11Make the can equal interface more permissive with associated typesPhilip Herron1-4/+7