-
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
Use lang items as paths #3290
Use lang items as paths #3290
Conversation
eb2bd1a
to
c6bed25
Compare
trait_path (std::unique_ptr<TypePath> (new TypePath (trait_path))), | ||
impl_items (std::move (impl_items)) | ||
{} | ||
|
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 could probably use a delegating constructor
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'm not against that, I think that's a good idea. What did you have in mind exactly?
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 constructor could become a delegating constructor, with this constructor as the target constructor.
https://en.cppreference.com/w/cpp/language/constructor#Delegating_constructor
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 think we can probably turn this into a good first PR as it's a nice cleanup but not functionally any different
651cc09
to
2586a9a
Compare
This commit adds a new kind of Path, changes the base Path class and turns TypePath into a child of the base Path class. gcc/rust/ChangeLog: * ast/rust-path.h (class LangItemPath): New. (class TypePath): Adapt to accomodate LangItemPath. * ast/rust-ast.cc (TraitImpl::as_string): Use new checks for lang items. (QualifiedPathType::as_string): Likewise. (FormatArgs::set_outer_attrs): Likewise. * ast/rust-item.h (class TraitImpl): Likewise.
gcc/rust/ChangeLog: * expand/rust-derive-copy.cc: Use new LangItemPath for derive(Copy).
gcc/rust/ChangeLog: * ast/rust-item.h: Add new method to specifically get a type-path. * ast/rust-path.cc (LangItemPath::as_string): Implement properly. * hir/rust-ast-lower-type.cc (ASTLowerTypePath::translate): Adapt visitor to use the new LangItemPath. * hir/rust-ast-lower-type.h: Likewise. * resolve/rust-ast-resolve-item.cc (ResolveItem::visit): Likewise. * resolve/rust-ast-resolve-type.h: Likewise.
gcc/rust/ChangeLog: * resolve/rust-ast-resolve-item.cc (ResolveItem::visit): Adapt resolver to lang item paths. * resolve/rust-ast-resolve-type.h: Likewise.
gcc/rust/ChangeLog: * hir/rust-ast-lower-type.cc (ASTLowerTypePath::translate): Adapt to handle lang item paths. (ASTLowerTypePath::visit): Likewise. (ASTLowerTypePath::translate_type_path): New. (ASTLowerTypePath::translate_lang_item_type_path): New. * hir/rust-ast-lower-type.h: Adapt to handle lang item paths. * resolve/rust-ast-resolve-type.h: Likewise.
gcc/rust/ChangeLog: * resolve/rust-late-name-resolver-2.0.cc (Late::visit): New. * resolve/rust-late-name-resolver-2.0.h: New.
gcc/rust/ChangeLog: * ast/rust-path.h: Adapt children of Path to fix some NodeId issues.
This PR makes it possible to use lang items as paths, for example when generating code for derives or for-loops. Instead of generating a complex path to something like
core::marker::Copy
, we can just use aLangItemPath
toLangItem::COPY
. This way, the code generation does not need to care about name resolution, about std's module hierarchy changing, or about duplicate definitions with the same module structure (e.g. if a user defines a copy trait in their own source file with their owncore
andmarker
module).This is not going to build until #3289 is merged as it depends on those mappings - but it should still be reviewable