Skip to content
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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

dlongnecke-cray
Copy link
Contributor

@dlongnecke-cray dlongnecke-cray commented Jul 2, 2024

This PR adds support for _ throwaway variables, de-tupled loop index variables e.g., for (i, _) in foo() do;, and ref tuples.

@dlongnecke-cray
Copy link
Contributor Author

Adjusting this branch to call resolveTupleDecl instead of resolveTupleUnpackDecl on the index variable, and running into some new challenges.

@DanilaFe DanilaFe self-requested a review July 12, 2024 05:52
Copy link
Contributor

@DanilaFe DanilaFe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great improvement, thanks!

Comment on lines 1978 to 1993
// 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() });
}
}
Copy link
Contributor

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.

Comment on lines 1987 to 1989
auto combiner = KindProperties::fromKind(kind);
combiner.setConst(true);
kind = combiner.toKind();
Copy link
Contributor

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.

} else if (auto namedDecl = actual->toNamedDecl()) {
resolveNamedDecl(namedDecl, rhsEltType.type());

// If the element is an index variable, then use the RHS's intent.
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor

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.

Comment on lines 874 to 880
assert(qtTup.kind() == QualifiedType::CONST_VAR);
assert(qtTup.type()->isTupleType());
Copy link
Contributor

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.

Comment on lines 966 to 969
assert(m["i"].kind() == QualifiedType::CONST_VAR);
assert(m["i"].type()->isIntType());
assert(m["j"].kind() == QualifiedType::CONST_VAR);
assert(m["j"].type()->isIntType());
Copy link
Contributor

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?

Copy link
Contributor Author

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() {
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good reminder, thanks!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants