Skip to content
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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

braw-lee
Copy link
Contributor

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.

@braw-lee
Copy link
Contributor Author

should I work on my branch the whole time, and you can merge it after 2-3 months?
or should I just create new PRs whenever I get something done and you will merge those from time to time? @CohenArthur @P-E-P

@P-E-P
Copy link
Member

P-E-P commented May 21, 2024

should I work on my branch the whole time, and you can merge it after 2-3 months? or should I just create new PRs whenever I get something done and you will merge those from time to time? @CohenArthur @P-E-P

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.

Comment on lines 258 to 262
void push_tmp_assignment (PlaceId rhs, location_t location)
{
push_tmp_assignment (new Assignment (rhs), ctx.place_db[rhs].tyty);
Copy link
Member

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?

Copy link
Contributor Author

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;
Copy link
Member

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

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, will fix that

Copy link
Contributor

@jdupak jdupak left a 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 (),
Copy link
Contributor

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;
Copy link
Contributor

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 ()},
Copy link
Contributor

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.

Copy link
Contributor Author

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;
Copy link
Contributor

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.

@braw-lee braw-lee marked this pull request as draft May 27, 2024 11:58
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

None yet

4 participants