-
Notifications
You must be signed in to change notification settings - Fork 162
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
gccrs: improve handling of Self Type paths #3269
Conversation
TypePaths have special handling for Self where we can look at the current ctx for more acurate TypeAlias information if required. We cant do this for Impl contexts but not for Traits as we might as well fall back to the TypePathProbe. The other issue was the dyn type comming in because Foo::foo and Foo is a trait reference we represent this as a dyn type as the root resolved path but then find the associated impl block for this but we cannot do this when we have resolved to a Dyn because this is just a representation that we know we are talking about a trait not because we are actually working with a real Dyn type. Fixes #2907 gcc/rust/ChangeLog: * typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_trait): track trait * typecheck/rust-hir-type-check-implitem.cc: trait block * typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_segments): dont when dyn * typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit): look at Self contenxt (TypeCheckType::resolve_root_path): track if Self (TypeCheckType::resolve_associated_type): look at current context for associated types * typecheck/rust-hir-type-check-type.h: change prototype * typecheck/rust-hir-type-check.h (class TypeCheckBlockContextItem): new context system to track current state * typecheck/rust-typecheck-context.cc (TypeCheckContext::have_block_context): likewise (TypeCheckContext::peek_block_context): likewise (TypeCheckContext::push_block_context): likewise (TypeCheckContext::pop_block_context): likewise (TypeCheckBlockContextItem::Item::Item): likewise (TypeCheckBlockContextItem::TypeCheckBlockContextItem): likewise (TypeCheckBlockContextItem::is_impl_block): likewise (TypeCheckBlockContextItem::is_trait_block): likewise (TypeCheckBlockContextItem::get_impl_block): likewise (TypeCheckBlockContextItem::get_trait): likewise gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: nr2 cant handle this * rust/compile/issue-2907.rs: New test. Signed-off-by: Philip Herron <[email protected]>
0670652
to
1b3374d
Compare
bool | ||
TypeCheckContext::have_block_context () const | ||
{ | ||
return !block_stack.empty (); | ||
} | ||
|
||
TypeCheckBlockContextItem | ||
TypeCheckContext::peek_block_context () | ||
{ | ||
rust_assert (!block_stack.empty ()); | ||
return block_stack.back (); | ||
} | ||
|
||
void | ||
TypeCheckContext::push_block_context (TypeCheckBlockContextItem block) | ||
{ | ||
block_stack.push_back (block); | ||
} | ||
|
||
void | ||
TypeCheckContext::pop_block_context () | ||
{ | ||
rust_assert (!block_stack.empty ()); | ||
block_stack.pop_back (); | ||
} | ||
|
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.
Note that we can remove all of that code if we use the StackedContexts
class we have: https://github.com/Rust-GCC/gccrs/blob/master/gcc/rust/util/rust-stacked-contexts.h
would remove some of the lines of code. I can turn this into a good-first-pr issue if you'd like
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.
TypePaths have special handling for Self where we can look at the current ctx for more acurate TypeAlias information if required. We cant do this for Impl contexts but not for Traits as we might as well fall back to the TypePathProbe.
The other issue was the dyn type comming in because Foo::foo and Foo is a trait reference we represent this as a dyn type as the root resolved path but then find the associated impl block for this but we cannot do this when we have resolved to a Dyn because this is just a representation that we know we are talking about a trait not because we are actually working with a real Dyn type.
Fixes #2907
gcc/rust/ChangeLog:
gcc/testsuite/ChangeLog: