Lower ErrorPropagationExpr from AST to HIR#2124
Conversation
789041c to
d1bdf3f
Compare
philberty
left a comment
There was a problem hiding this comment.
LGTM
This adds the HIR lowering with no desugaring, but we are probably missing the name-resolution for this and type-checking then we need code-generation etc...
|
IF you fix the commit message format, then this is good to merge. |
|
Thanks!
Yes. I saw that there exists I was going to look into how lang items are implemented next, to see if I could find/add
I will, but that will have to wait until tomorrow. |
CohenArthur
left a comment
There was a problem hiding this comment.
LGTM :) If you're interested in taking care of the later parts of the pipeline we'd be more than happy to help, if you want to chat on our Zulip to get quicker feedback on what to do etc feel free! Thank you :D
gcc/rust/ChangeLog: * hir/rust-ast-lower-expr.h, hir/rust-ast-lower-expr.cc: Lower AST::ErrorPropagationExpr to HIR::ErrorPropagationExpr Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
d1bdf3f to
2bf9be5
Compare
I'd love to!
Maybe, but I must admit the prospect of joining yet another IM platform does not sound very appealing 🙂
|
I found this: gccrs/gcc/rust/typecheck/rust-hir-type-check-expr.cc Lines 1581 to 1595 in 74b4d6d (by the way, instead of just a But also, the following looks just wrong: gccrs/gcc/rust/typecheck/rust-hir-type-check-expr.cc Lines 1597 to 1616 in 74b4d6d We should not attempt to resolve a method named, say, #[lang = "add"]
pub trait Add<Rhs = Self> {
type Output;
fn add(self, rhs: Rhs) -> Self::Output;
}
trait AlsoAdd {
fn add(self);
}
struct MyStruct(i32);
impl Add for MyStruct {
type Output = i32;
fn add(self, rhs: MyStruct) -> i32 {
self.0 + rhs.0
}
}
impl AlsoAdd for MyStruct {
fn add(self) { }
}
fn foo() ->i32 {
MyStruct(35) + MyStruct(42)
}I get the error: Who cares whether or not there happens to be another method named |
I'll address all of the other points you raised in your message shortly, but I just wanted to say we also have an IRC channel and mailing list if you do prefer that :D #gccrust on irc.oftc.net and https://gcc.gnu.org/mailman/listinfo/gcc-rust. So if you'd rather chat on there, feel free! |
I was not being very serious, but thank you! 😄 The next round of questions:
|
That's correct :)
Our HIR is then translated to GCC's highest level intermediate representation, GENERIC (or TREE which is the same). That happens in all the visitors within
There isn't :) we don't have the need for one at the moment.
Most of the desugaring will happen during the AST-lowering pass. I believe it could be the case for the error propagation expressions as well but they are very complex, so maybe not.
It is a 1-to-1 translation except in the cases where it can be simplified, as well as for AST nodes which cannot exist this late in the pipeline (macro invocations for example). There are some exceptions to this rule like the
The
yes, that's exactly what you'll have to do. I would suggest also looking at gccrs/gcc/rust/typecheck/rust-hir-type-check-expr.cc Lines 1457 to 1579 in 74b4d6d which does the same lookup as well as some error handling.
#[lang = "add"]
pub trait Add<Rhs = Self> {
type Output;
fn add(self, rhs: Rhs) -> Self::Output;
}
trait AlsoAdd {
fn add(self);
}
struct MyStruct(i32);
impl Add for MyStruct {
type Output = i32;
fn add(self, rhs: MyStruct) -> i32 {
self.0 + rhs.0
}
}
impl AlsoAdd for MyStruct {
fn add(self) { }
}
fn foo() ->i32 {
MyStruct(35) + MyStruct(42)
}
and I agree with this. Could you open an issue with the above code? it would be nice to have error handling here as well if the |
|
Thank you!
I'd rather open a pull request :D but for that, please reply to the second set of questions. |
|
I think some of this will be a bit simpler when i merge my work over here: #2140 Traits a complicated, so you can have a plain basic trait, so we need a way to work with them which is what the TraitReference object is, which is mostly just a helper object around it. The other part is the TypeBoundPredicate Rustc has something similar cant remember the name but this is all about managing generic traits. Generic Traits are a pain and the current master code has one main issue here, where Trait has an implicit Self generic type parameter. This is left as a generic in the case of the Self type bound predicate but in every other case such as: impl Foo for u8 {...} This means we really create a type-bound predicate to wrap up the generics here properly which means we end up with Foo<u8, i32> The current master code does not track the Self parameter properly here which is confusing but i have fixes on the way. This is all required to handle complicated cases of associated types and trait disambiguation. The other part to be aware of the is another bug in master for qualified path syntax such is always resolving the to the trait item and we are relying on code generation to always monomorphize it which is wrong again i have fixes for this laready. You test case: I havented chaged if this is working or broken but here this is a generic unit struct the generic U has a type bound predicate of Foo and then we its argument is the trait item of Bar but i have a feeling if this is not working its likely missing the piece i mentioned earlier thats not tracking the Self type properly here. Associated types like this are really awkward because assoicated types can be the one implemented on the impl block or the placeholder on the trait which will need setup if possible when we get more information. So in the case the best case you can hope for us that SomeItem will turn into SomeItem because there is not enough type info to get any further. |
I have no idea what I'm doing, but using a
?was causing an ICE and now it does not (I get regular errors instead), so, good? A step towards #166 perhaps?