-
Notifications
You must be signed in to change notification settings - Fork 144
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
base: master
Are you sure you want to change the base?
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.
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. 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-place.h: Likewise. * checks/errors/borrowck/rust-bir.h: Likewise. Signed-off-by: Kushal Pal <[email protected]>
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.