-
Notifications
You must be signed in to change notification settings - Fork 165
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
Conversation
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.
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> ()) |
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 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.
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 am sorry i somehow read that as a for loop. But i would still prefer the old check, this is hard to read
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.
@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.
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 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.
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.
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
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 don't have any problem with the try_as, is and as API I think its great.
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 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
2cb5332
to
4b93eae
Compare
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]>
d9e7a3a
to
b1eff15
Compare
// DEPRECATED: Use get_param_type_at | ||
BaseType *param_at (size_t idx) const { return get_param_type_at (idx); } |
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.
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> ()) |
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 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
I think this is great and am in favor of merging it if you do that |
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]>
b1eff15
to
6947501
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.
LGTM
Sending them separatelly to not clutter the later bigger PRs.
For all commits:
make check-rust
passes locallyclang-format