-
Notifications
You must be signed in to change notification settings - Fork 419
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
dyno: Add initial support for _
and de-tupled loop index variables
#25418
base: main
Are you sure you want to change the base?
dyno: Add initial support for _
and de-tupled loop index variables
#25418
Conversation
7939772
to
cab3eab
Compare
Adjusting this branch to call |
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.
Great improvement, thanks!
frontend/lib/resolution/Resolver.cpp
Outdated
// If the element is an index variable, then use the RHS's intent. | ||
if (auto var = namedDecl->toVarLikeDecl()) { | ||
if (var->storageKind() == uast::Qualifier::INDEX) { | ||
auto& rr = byPostorder.byAst(var); | ||
auto kind = rhsEltType.kind(); | ||
|
||
// If the kind is a value, set it to 'const'. | ||
if (!rhsEltType.isRef() && !rhsEltType.isParam() && | ||
!rhsEltType.isType()) { | ||
auto combiner = KindProperties::fromKind(kind); | ||
combiner.setConst(true); | ||
kind = combiner.toKind(); | ||
} | ||
rr.setType({ kind, rr.type().type() }); | ||
} | ||
} |
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 be a helper.
frontend/lib/resolution/Resolver.cpp
Outdated
auto combiner = KindProperties::fromKind(kind); | ||
combiner.setConst(true); | ||
kind = combiner.toKind(); |
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 too could be a static helper on KindProperties, probbaly called addConstness
.
frontend/lib/resolution/Resolver.cpp
Outdated
} else if (auto namedDecl = actual->toNamedDecl()) { | ||
resolveNamedDecl(namedDecl, rhsEltType.type()); | ||
|
||
// If the element is an index variable, then use the RHS's intent. |
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.
Not clear to me why this is needed, could you explain?
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 don't do this then the component will have the INDEX
intent, which isn't concrete.
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.
But why do you make it const
?
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 see your comment below.
assert(qtTup.kind() == QualifiedType::CONST_VAR); | ||
assert(qtTup.type()->isTupleType()); |
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.
You should probably be checking the component kinds too, since your code adjusts them one-by-one.
assert(m["i"].kind() == QualifiedType::CONST_VAR); | ||
assert(m["i"].type()->isIntType()); | ||
assert(m["j"].kind() == QualifiedType::CONST_VAR); | ||
assert(m["j"].type()->isIntType()); |
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 you explain why these are const?
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.
They're const because they're const in production, if the RHS is not a reference or a product of a zip()
expression it's usually const.
assert(m["b"].kind() == QualifiedType::CONST_REF); | ||
assert(m["b"].type()->isIntType()); | ||
} | ||
|
||
int main() { |
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 you add one more test that ensures that =
is not resolved for records when they are assigned to _
? You added that logic but I don't see it tested 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.
Good reminder, thanks!!!
Signed-off-by: David Longnecker <[email protected]>
Signed-off-by: David Longnecker <[email protected]>
Signed-off-by: David Longnecker <[email protected]>
Signed-off-by: David Longnecker <[email protected]>
Signed-off-by: David Longnecker <[email protected]>
Signed-off-by: David Longnecker <[email protected]>
896c6b6
to
c1cbad0
Compare
This PR adds support for
_
throwaway variables, de-tupled loop index variables e.g.,for (i, _) in foo() do;
, andref
tuples.