-
Notifications
You must be signed in to change notification settings - Fork 173
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
borrowck: Added location support to BIR nodes #3013
Conversation
should I work on my branch the whole time, and you can merge it after 2-3 months? |
Actually it would be better to merge your content quite often. This way other contributors can follow your work and can work over it. Moreover it'll be easier to review and you won't have to make huge rebase. We may be a little slow to merge some PRs sometime because reviewing them take some time. You may create some PRs on top of another with the mention "Requires #PRNUMBER", you may even put a link to the actual diff just like in #3014. If you do so please keep those PR in draft whilst it's dependencies are not merged so they don't end up merged. |
void push_tmp_assignment (PlaceId rhs, location_t location) | ||
{ | ||
push_tmp_assignment (new Assignment (rhs), ctx.place_db[rhs].tyty); |
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.
we're not using the location
argument here yet - I assume this is intentional?
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.
missed it, will clean it up
@@ -77,26 +77,40 @@ class Statement | |||
// otherwise: <unused> | |||
std::unique_ptr<AbstractExpr> expr; | |||
TyTy::BaseType *type; | |||
// stores location of the actual expression from source code | |||
// currently only available when kind == Kind::ASSIGNMENT | |||
tl::optional<location_t> location; |
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.
do we want to make this optional? if this is just a temporary measure, then we should add a FIXME
comment
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.
If this is a TODO, it would make more sense to use just location and init it to UNKNOWN_LOCATION.
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.
ok, will fix that
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.
Mostly looks good. There are some issues around Places.
@@ -82,7 +82,9 @@ class PatternBindingBuilder : protected AbstractBuilder, | |||
|
|||
if (init.has_value ()) | |||
{ | |||
push_assignment (translated, init.value ()); | |||
push_assignment ( | |||
translated, init.value (), |
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.
Maybe, it would make more sense here to pass the location to the visit identifier method.
@@ -78,12 +78,13 @@ struct Place | |||
TyTy::BaseType *tyty; | |||
FreeRegions regions{{}}; | |||
std::vector<LoanId> borrowed_by{}; | |||
location_t location; |
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 am not sure, if this is needed. We might have just locations for Origin.
@@ -255,7 +256,9 @@ class PlaceDB | |||
|
|||
PlaceId add_variable (NodeId id, TyTy::BaseType *tyty) | |||
{ | |||
return add_place ({Place::VARIABLE, id, {}, is_type_copy (tyty), tyty}, 0); | |||
return add_place ( | |||
{Place::VARIABLE, id, {}, is_type_copy (tyty), tyty, tyty->get_locus ()}, |
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.
Using location of type does not seem right. As I mentioned before, we might not oven need it here. Alternative could be to extract the location from NodeId. But that can always be done on demand.
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.
actually I was first trying to use get_ast_item() method to retrieve the location, but it seems like the location is copied from AST->HIR->TyTy, so getting locus from NodeId or the TyTy should be same, unless we plan to change the location information of TyTy in future
@@ -77,26 +77,40 @@ class Statement | |||
// otherwise: <unused> | |||
std::unique_ptr<AbstractExpr> expr; | |||
TyTy::BaseType *type; | |||
// stores location of the actual expression from source code | |||
// currently only available when kind == Kind::ASSIGNMENT | |||
tl::optional<location_t> location; |
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.
If this is a TODO, it would make more sense to use just location and init it to UNKNOWN_LOCATION.
7c4222c
to
0f34d93
Compare
template <typename T> | ||
void move_all (T &args, std::vector<location_t> capture_locations) | ||
{ | ||
std::transform (args.begin (), args.end (), args.begin (), | ||
[this] (PlaceId arg) { return move_place (arg); }); | ||
rust_assert (args.size () == capture_locations.size ()); | ||
std::transform (args.begin (), args.end (), capture_locations.begin (), | ||
args.begin (), [this] (PlaceId arg, location_t location) { | ||
return move_place (arg, location); | ||
}); |
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.
hm, I don't know if the second parameters should be called capture_locations
and not locations
. as far as I understand it, this isn't strictly restricted to closure captures, right? @jdupak what do you think?
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.
Well , I think that captures are the only place, where you have multiple different locations. But In that case this function should be renamed. I'm not sure if such function makes sense in this context.
This needs to be rebased as well @braw-lee |
pub loan_errors: bool, | ||
pub subset_errors: bool, | ||
pub move_errors: bool, | ||
pub loan_errors: *mut FFIVector, | ||
pub move_errors: *mut FFIVector, | ||
pub subset_errors: *mut FFIVector, |
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.
Are those changes generated using bindgen ?
@@ -46,6 +63,12 @@ impl From<GccrsAtom> for usize { | |||
} | |||
} | |||
|
|||
impl From<&GccrsAtom> for usize { |
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.
Do we really need to take this by reference ? GccrsAtom
is Copy
this looks weird since we already have a From
implementation for GccrsAtom
I bet every situation can be dealt with at the call site.
This commit adds location_t to BIR::Statement where type is ASSIGNMENT this information will be later used for reporting borrow-checking errors. gcc/rust/ChangeLog: * checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::visit): Added location parameter. * checks/errors/borrowck/rust-bir-builder-internal.h: Likewise. * checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h: Likewise. * checks/errors/borrowck/rust-bir-builder-pattern.h: Likewise. * checks/errors/borrowck/rust-bir-builder.h: Likewise. * checks/errors/borrowck/rust-bir.h: Likewise. Signed-off-by: Kushal Pal <[email protected]>
This commit adds location_t to BIR::Loan, this location will point to location is source code where the borrow occured, this information will be useful for reporting borrow-checking errors. gcc/rust/ChangeLog: * checks/errors/borrowck/rust-bir-builder-internal.h: Fill location for loan. * checks/errors/borrowck/rust-bir-place.h (struct Loan): Add location field. Signed-off-by: Kushal Pal <[email protected]>
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.
LGTM!
depends on #3076
Added
location
field to BIR::Statement and BIR::Place, updated the BIR builders to take the source location from HIR and pass it to BIR node.