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

Implement copy assignment operator for hvec_map #4388

Merged
merged 2 commits into from
Feb 8, 2024
Merged

Conversation

asl
Copy link
Contributor

@asl asl commented Feb 3, 2024

We cannot use a default one since it would involved copying of std::pair<const KEY, VAL> that had its copy ctor explicitly disabled.

Instead, go the "standard way" for maps via clear() and reinsert().

Fixes #4331

@fruffy
Copy link
Collaborator

fruffy commented Feb 4, 2024

@grg Do you use hvec_map?

Copy link
Contributor

@vlstill vlstill left a comment

Choose a reason for hiding this comment

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

Looks reasonable to me, although I am not familiar with hvec_map.

@@ -52,7 +53,18 @@ class hvec_map : hash_vector_base {
}
hvec_map(const hvec_map &) = default;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please add a test case showing the copy ctor works?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am sorry, the name is misleading :) Certainly the copy assignment operator is implemented. And there is test for it (https://github.com/p4lang/p4c/pull/4388/files#diff-3c84a1bd26855410fe97ba63b1a655b54f10f618fbe2bb5471946ab7e33f9518R159)

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep, I've noticed the implemented copy-assignment operator. At the same time, when we have implementation and test for copy assignment, we should also have a test for copy-construction -- if one is supposed to work, both should. Therefore, could you please add a test for the ctor, even though you have not touched it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, done: 2e80292

@asl asl changed the title Implement copy constructor for hvec_map Implement copy assignment operator for hvec_map Feb 5, 2024
@grg
Copy link
Contributor

grg commented Feb 7, 2024

@grg Do you use hvec_map?

No, I don't see any uses in either Tofino or IPU compiler code.

since it would involved copying of std::pair<const KEY, VAL> that had
its copy ctor explicitly disabled.

Instead, go the standard "way" for maps via clear() and reinsert().

Fixes p4lang#4331
@asl asl enabled auto-merge (squash) February 8, 2024 21:13
@asl asl merged commit 40fc6bb into p4lang:main Feb 8, 2024
16 checks passed
@asl asl deleted the hvec-map-copy branch February 27, 2024 20:17
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.

Cannot use hvec_map for cstring keys
4 participants