-
Notifications
You must be signed in to change notification settings - Fork 183
Simplify lowering #602
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify lowering #602
Conversation
594b215
to
aee7742
Compare
aee7742
to
9f1fd2f
Compare
7a30599
to
7c21b0b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some nits. But I think I still would prefer the lower_*
functions to just implement Lower
but not use the environment.
chalk-integration/src/lowering.rs
Outdated
@@ -86,7 +86,8 @@ struct AssociatedTyLookup { | |||
addl_variable_kinds: Vec<chalk_ir::VariableKind<ChalkIr>>, | |||
} | |||
|
|||
enum ApplyTypeLookup { | |||
enum ApplyTypeLookup<'k> { | |||
Param(&'k chalk_ir::WithKind<ChalkIr, BoundVar>), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, so. I'm not super sure about this name, because I don't want it to be confused with the rustc Param
type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, not sure what else to go with, since BoundVar
would be confusing as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it ends up serving a similar purpose to rustc's Param
, so if we can't think of a better name, Param
is probably acceptable. Another option: Parameter
. Feel free to take it or leave it.
lower_param_map!(AdtDefn, None); | ||
lower_param_map!(FnDefn, None); | ||
lower_param_map!(ClosureDefn, None); | ||
lower_param_map!(Impl, None); | ||
lower_param_map!(AssocTyDefn, None); | ||
lower_param_map!(AssocTyValue, None); | ||
lower_param_map!(Clause, None); | ||
lower_param_map!( | ||
TraitDefn, | ||
Some(chalk_ir::WithKind::new( | ||
chalk_ir::VariableKind::Ty(TyKind::General), | ||
Atom::from(SELF), | ||
)) | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Beautiful.
The problem is that some functions, like I've tried having 2 Lower traits, one with environment and one without, but the one without is just less consistent, since it doesn't always return a |
I don't think having two separate traits is all that bad. We're looking for the solution that best conveys what's going on in the lowering as a whole. Having one or two traits implemented for most things makes more sense that one trait for some and a bunch of functions for everything else. (I'm curious if we could refactor away the arguments in all of the functions, but I'm purposely that out from this PR, because I would like to land us somewhere that is definitely better than get us stuck on what ifs). I think we can always just return a Another thing worth thinking about is which of the functions must be called before the environment is constructed. Then, these could be special and everything else takes an env. (This somewhat depends on how much there are and such) |
👍
This is awkward when lowering vecs, so let's go with this instead, even if it's a bit inconsistent:
Turns out that the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple more minor comments. But this looks great. Feel free to merge with/without comments addressed.
chalk-integration/src/lowering.rs
Outdated
@@ -86,7 +86,8 @@ struct AssociatedTyLookup { | |||
addl_variable_kinds: Vec<chalk_ir::VariableKind<ChalkIr>>, | |||
} | |||
|
|||
enum ApplyTypeLookup { | |||
enum ApplyTypeLookup<'k> { | |||
Param(&'k chalk_ir::WithKind<ChalkIr, BoundVar>), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it ends up serving a similar purpose to rustc's Param
, so if we can't think of a better name, Param
is probably acceptable. Another option: Parameter
. Feel free to take it or leave it.
return Err(RustIrError::NotStruct(name.clone())); | ||
.cast(interner)), | ||
Err(_) => { | ||
if let Some(id) = self.foreign_ty_ids.get(&name.str) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, how did this end up on this path (I would expect it to be returned in lookup_apply_type
)? Is it just because these can't have generics?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess so, since there's no foreign_ty_kinds
. Possibly lookup_apply_type
and lookup_generic_arg
should just use their own lookups, but it's kind of awkward to have all these separate maps.
@bors r+ |
@bors r=jackh726 |
📌 Commit b1c6c4e has been approved by |
Wait, that didn't merge it? Huh, I don't really get how bors works |
I think there's some bors weirdness happening right now. |
Env
to a singleLower
trait with associatedtype Lowered
, to get rid of all the single-use traits. This retains.lower(env)
chaining for the most important types.lower_adt_repr
makes the code clearer IMO.LowerParameterMap
(also removing some unused functions there) andlower_type_kind
(renamedOpaqueTyDefn.identifier
toOpaqueTyDefn.name
to line things up better)lookup_apply_type
inApplyTypeLookup
by changing it slightly, to avoid duplicating map lookup code