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

Minor changes needed for borrowck #2770

Merged
merged 7 commits into from
Dec 19, 2023
Merged

Conversation

jdupak
Copy link
Contributor

@jdupak jdupak commented Dec 3, 2023

Sending them separatelly to not clutter the later bigger PRs.

For all commits:

  • make check-rust passes locally
  • Run clang-format

@jdupak jdupak mentioned this pull request Dec 4, 2023
@P-E-P P-E-P added this to the Borrow Checking 1 milestone Dec 6, 2023
@P-E-P P-E-P requested review from P-E-P and CohenArthur December 6, 2023 18:17
Copy link
Member

@philberty philberty left a comment

Choose a reason for hiding this comment

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

This callable type interface could be useful but we may end up changing its name to FunctionItemTypes or some other but for not this is fine.

I think that for loop over the ADT Type check just needs changed and then this is good to be merged

@@ -442,12 +442,9 @@ TypeCheckType::resolve_root_path (HIR::TypePath &path, size_t *offset,
root_tyty = lookup;

// this enforces the proper get_segments checks to take place
bool is_adt = root_tyty->get_kind () == TyTy::TypeKind::ADT;
if (is_adt)
if (auto adt = root_tyty->try_as<const TyTy::ADTType> ())
Copy link
Member

Choose a reason for hiding this comment

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

Hmm i am not sure this is safe to do because try_as will return null if it is not an ADT Type so its not required to turn this into an ADT here.

Copy link
Member

Choose a reason for hiding this comment

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

actually i am sorry i somehow read that as a for loop. But i would still prefer the old check, this is hard to read

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@philberty This is something we should discuss more in depth, because you liked the API when I introduced it and now I am using it heavily in unpublished borrowchecker code.

Copy link
Member

Choose a reason for hiding this comment

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

I like the API i just think in that specific if statement I don't like introducing variables like that. It looks too much like a for loop.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, now the question is, whether we want to keep the try_as part of the API at all (versus only is and as). I like it (well it is pretty much if let Some(adt) = ... :D), but it feels to me that it will always look like that.

Another example here: https://github.com/jdupak/gccrs/blob/borrowck-stage2/gcc/rust/checks/errors/borrowck/rust-bir-fact-collector.h#L419

Copy link
Member

Choose a reason for hiding this comment

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

I don't have any problem with the try_as, is and as API I think its great.

Copy link
Member

Choose a reason for hiding this comment

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

I agree that it would be more readable to initialize the variable above the if and then check for its validity in the if's condition

@jdupak
Copy link
Contributor Author

jdupak commented Dec 11, 2023

Notice: I have added some small changed I missed before. Plase see the last force push diff.

gcc/rust/ChangeLog:

	* hir/tree/rust-hir-item.h: Ad lifetime getter.
	* hir/tree/rust-hir-path.h: Make getter const ref.
	* hir/tree/rust-hir.h: Const ref and new getter.

Signed-off-by: Jakub Dupak <[email protected]>
gcc/rust/ChangeLog:

	* typecheck/rust-tyty.h: Fix nodiscard to warn unused.

Signed-off-by: Jakub Dupak <[email protected]>
gcc/rust/ChangeLog:

	* checks/errors/borrowck/rust-bir-builder-internal.h: Replace nodiscard.
	* checks/errors/borrowck/rust-bir-place.h: Replace nodiscard.

Signed-off-by: Jakub Dupak <[email protected]>
@jdupak jdupak force-pushed the borrowck-minor branch 2 times, most recently from d9e7a3a to b1eff15 Compare December 11, 2023 22:29
Comment on lines +910 to +930
// DEPRECATED: Use get_param_type_at
BaseType *param_at (size_t idx) const { return get_param_type_at (idx); }
Copy link
Member

Choose a reason for hiding this comment

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

This is fine, but could you please open an issue to remove that function entirely?

@@ -442,12 +442,9 @@ TypeCheckType::resolve_root_path (HIR::TypePath &path, size_t *offset,
root_tyty = lookup;

// this enforces the proper get_segments checks to take place
bool is_adt = root_tyty->get_kind () == TyTy::TypeKind::ADT;
if (is_adt)
if (auto adt = root_tyty->try_as<const TyTy::ADTType> ())
Copy link
Member

Choose a reason for hiding this comment

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

I agree that it would be more readable to initialize the variable above the if and then check for its validity in the if's condition

@CohenArthur
Copy link
Member

I think this is great and am in favor of merging it if you do that if change :) thanks for the work!

gcc/rust/ChangeLog:

	* typecheck/rust-hir-type-check-type.cc (TypeCheckType::resolve_root_path): Refactor.

Signed-off-by: Jakub Dupak <[email protected]>
gcc/rust/ChangeLog:

	* typecheck/rust-tyty.h (class ClosureType): Inherit interface.
	(class FnPtr): Inherit interface.
	(class FnType): Inherit interface.
	(class CallableTypeInterface): New interface.
	(BaseType::is): Detect interface members API.

Signed-off-by: Jakub Dupak <[email protected]>
Allows skipping parent check when casting.

gcc/rust/ChangeLog:

	* typecheck/rust-tyty.h (BaseType::is): Cast API.
	(SubstitutionRef>): Cast API.
	(BaseType::as): Cast API.
	(BaseType::try_as): Cast API.

Signed-off-by: Jakub Dupak <[email protected]>
gcc/rust/ChangeLog:

	* checks/errors/borrowck/rust-bir-place.h: Cleanup.
	* checks/errors/borrowck/rust-borrow-checker.h: Cleanup.

Signed-off-by: Jakub Dupak <[email protected]>
Copy link
Member

@philberty philberty left a comment

Choose a reason for hiding this comment

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

LGTM

@philberty philberty added this pull request to the merge queue Dec 19, 2023
Merged via the queue into Rust-GCC:master with commit 03a38a4 Dec 19, 2023
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Merged
Development

Successfully merging this pull request may close these issues.

4 participants