-
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
Prepare lang-item {AST, HIR}::PathInExpressions
#3378
Prepare lang-item {AST, HIR}::PathInExpressions
#3378
Conversation
// FIXME: We probably need to check *if* the type needs substitutions | ||
// or not | ||
if (LangItem::IsEnumVariant (expr.get_lang_item ())) | ||
{ | ||
std::pair<HIR::Enum *, HIR::EnumItem *> enum_item_lookup | ||
= mappings.lookup_hir_enumitem (*hir_id); | ||
bool enum_item_ok = enum_item_lookup.first != nullptr | ||
&& enum_item_lookup.second != nullptr; | ||
rust_assert (enum_item_ok); | ||
|
||
HirId variant_id | ||
= enum_item_lookup.second->get_mappings ().get_hirid (); | ||
|
||
HIR::EnumItem *enum_item = enum_item_lookup.second; | ||
resolved_node_id = enum_item->get_mappings ().get_nodeid (); | ||
|
||
// insert the id of the variant we are resolved to | ||
context->insert_variant_definition (expr.get_mappings ().get_hirid (), | ||
variant_id); | ||
|
||
query_type (variant_id, &infered); | ||
infered = SubstMapper::InferSubst (infered, expr.get_locus ()); | ||
} |
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 super dodgy, @philberty please check it good lol
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.
If I could ask, how could you end up with a lang-item path that DOESN'T need substitution inferencing? I'm curious because I think the only way you could generate an option type that doesn't need inferencing would be to generate a lang-item path like Option::<i32>::Some(3)
, but that wouldn't be possible since lang-item paths wouldn't have PathExprSegments which can be generic arguments
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.
The only other way would be to have a lang-item path to an enumeration variant with no generic parameter?
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.
Yeah maybe something like that, but you're right that I don't think it's the case - there aren't that many enum variants long items, and I think they are all generic. Still, it feels wrong to always do substitution mapping lol so that's why I added the comment. It might also evolve in the future. I'm happy removing the comment though
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 it's probably better to keep it I would imagine, since if it ever becomes an issue, the comment clarifies that ALWAYS doing substitution inference is not a design choice
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.
there might be a change needed for the generics but would need to try it out a bit myself to try our some tests on it
19b0e5f
to
3e31b59
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
final_segment | ||
= HIR::PathIdentSegment (LangItem::ToString (expr.get_lang_item ())); |
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.
Could this end up getting confused if there are multiple Some
declarations floating around?
I.e.
fn Some () {
let _ = option_env!("PWD"); // Yields lang-item path to Some("/tmp")
}
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.
Maybe - I'm adding a different implementation right now which is more precise and makes use of the lang item's known NodeId
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 the version you have up now works, at least from tracing the code by eye.
3e31b59
to
70384f2
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 lets get this merged soon
281fcbf
to
9053922
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 nice work the artification ident segment will work fine here
@@ -32,32 +32,39 @@ | |||
namespace Rust { | |||
namespace Compile { | |||
|
|||
void | |||
ResolvePathRef::visit (HIR::QualifiedPathInExpression &expr) | |||
template <typename T> |
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 always forget you can do this!!! thanks for reminding me of this trick :D
= Analysis::Mappings::get ().get_lang_item_node (expr.get_lang_item ()); | ||
|
||
// FIXME: Is that correct? :/ | ||
auto final_segment |
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.
yes this should work the only reason i passed the node around was because it was handy to get the location and node id so in theory it can fall back to the query system interface.
Not part of your pr but yeah this has given me alot of though of loads of good-first-pr's to cleanup the interfaces here
its super confusing for new people.
|
||
return resolve_with_node_id (final_segment, expr.get_mappings (), | ||
expr.get_locus (), true, lang_item); | ||
} | ||
else |
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 the only change i might do here is get rid of the else and just return that
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.
thanks! fixed in the latest version
|
||
resolved | ||
= resolve (final_segment, expr.get_mappings (), expr.get_locus (), true); | ||
resolved = resolve_path_like (expr); |
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 love this so much
ResolvePathRef::resolve_with_node_id ( | ||
const HIR::PathIdentSegment &final_segment, | ||
const Analysis::NodeMapping &mappings, location_t expr_locus, | ||
bool is_qualified_path, NodeId resolved_node_id) |
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 have a feeling the is_qualified_path is no longer used here now which is neat
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.
ah I kept it cause we need it for query_compile
9053922
to
a53f5b0
Compare
gcc/rust/ChangeLog: * ast/rust-collect-lang-items.h: Declare visitor. * ast/rust-collect-lang-items.cc (CollectLangItems::visit): New.
gcc/rust/ChangeLog: * util/rust-hir-map.cc (Mappings::get_lang_item_node): Better formatting when a lang item does not exist when it should.
gcc/rust/ChangeLog: * util/rust-lang-item.cc (LangItem::IsEnumVariant): New function. * util/rust-lang-item.h: Declare it.
gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit): Adapt visitor to lang item PathInExpressions. * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Likewise. * expand/rust-cfg-strip.cc (CfgStrip::visit): Likewise. * expand/rust-expand-visitor.cc (ExpandVisitor::visit): Likewise. * hir/rust-ast-lower.cc (ASTLoweringExprWithBlock::visit): Likewise. (ASTLowerPathInExpression::visit): Likewise. * resolve/rust-ast-resolve-path.cc (ResolvePath::resolve_path): Likewise. * resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit): Likewise.
gcc/rust/ChangeLog: * hir/tree/rust-hir-path.h: Adapt PathPattern to accept lang-item paths. * hir/tree/rust-hir-path.cc: Assert we are dealing with a segmented path, create lang-item constructors. * hir/tree/rust-hir.cc (PathPattern::convert_to_simple_path): Likewise.
gcc/rust/ChangeLog: * backend/rust-compile-resolve-path.cc (ResolvePathRef::visit): Adapt visitor to lang item HIR::PathInExpressions. * typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::visit): Likewise.
gcc/rust/ChangeLog: * checks/lints/rust-lint-marklive.cc (MarkLive::visit): Adapt to lang items.
gcc/rust/ChangeLog: * ast/rust-path.h: New function.
gcc/rust/ChangeLog: * backend/rust-compile-resolve-path.cc (ResolvePathRef::visit): Call into resolve_path_like instead. (ResolvePathRef::resolve_path_like): New. (ResolvePathRef::resolve): Call into resolve_with_node_id. * backend/rust-compile-resolve-path.h: Declare new functions and document them.
a53f5b0
to
b85c362
Compare
This is an important base for desugaring expression lang items, e.g. when calling something like
IntoIterator::into_iter(i)
. This changes our AST and HIR visitors to make it possible to use lang items in more places which will be necessary.