Skip to content

Conversation

@dwblaikie
Copy link
Contributor

Otherwise the value fails in confusing ways while untagging:

CHECK failure at ./toolchain/base/value_store.h:71:
index >= initial_reserved_ids_: When removing tagging bits,
found an index that shouldn't've been tagged in the first place.

With this change:

CHECK failure at ./toolchain/base/fixed_size_value_store.h:112:
id.index >= 0: instFFFFFFFFFFFFFFFD

…on-language#6370

Otherwise the value fails in confusing ways while untagging:

  CHECK failure at ./toolchain/base/value_store.h:71:
  index >= initial_reserved_ids_: When removing tagging bits,
  found an index that shouldn't've been tagged in the first place.

With this change:

  CHECK failure at ./toolchain/base/fixed_size_value_store.h:112:
  id.index >= 0: instFFFFFFFFFFFFFFFD
@dwblaikie dwblaikie requested a review from a team as a code owner November 18, 2025 17:24
@dwblaikie dwblaikie requested review from chandlerc and removed request for a team November 18, 2025 17:24
@dwblaikie dwblaikie requested review from danakj and removed request for chandlerc November 18, 2025 17:25
@danakj
Copy link
Contributor

danakj commented Nov 19, 2025

Otherwise the value fails in confusing ways while untagging:

CHECK failure at ./toolchain/base/value_store.h:71: index >= initial_reserved_ids_: When removing tagging bits, found an index that shouldn't've been tagged in the first place.

With this change:

CHECK failure at ./toolchain/base/fixed_size_value_store.h:112: id.index >= 0: instFFFFFFFFFFFFFFFD

Do you think we can print negative values as negative instead of as a large positive number?

Copy link
Contributor

@danakj danakj left a comment

Choose a reason for hiding this comment

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

Looking at #6310, I think we need to do the same in relational_value_store.h too, as GetRawIndex starts with Remove()?

@danakj
Copy link
Contributor

danakj commented Nov 19, 2025

Otherwise the value fails in confusing ways while untagging:
CHECK failure at ./toolchain/base/value_store.h:71: index >= initial_reserved_ids_: When removing tagging bits, found an index that shouldn't've been tagged in the first place.
With this change:
CHECK failure at ./toolchain/base/fixed_size_value_store.h:112: id.index >= 0: instFFFFFFFFFFFFFFFD

Do you think we can print negative values as negative instead of as a large positive number?

I think we need to do something for a bunch of id types, I have a PR for this in the works.

// Given the related ID and a value, stores the value and returns a mapped ID
// to reference it in the store.
auto Add(RelatedIdType related_id, ValueType value) -> IdT {
auto related_index = related_store_->GetRawIndex(related_id);
Copy link
Contributor

Choose a reason for hiding this comment

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

This GetRawIndex calls Remove() which makes the confusing error in the negative case right? Do we want the DCHECK in here and TryGetId?

@dwblaikie
Copy link
Contributor Author

Looking at #6310, I think we need to do the same in relational_value_store.h too, as GetRawIndex starts with Remove()?

Made the same transformation for RelationalValueStore::Get (moving the CHECK up above the Remove call) - though for the GetRawIndex I added CHECKs down in the IdTag to check its pre/post conditions. In some ways this would remove the need for the checks up in the ValueStores - but given your preferences about having checks higher up (& I can appreciate it - it is a precondition of these higher functions too - should we check at every level? I'd worry about performance, but they probably get inlined and optimized away relatively easily)

Copy link
Contributor

@danakj danakj left a comment

Choose a reason for hiding this comment

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

Oh I see, this LGTM

Re performance, the checks are debug only and cheap so I don't think it's really a concern but this is okay as is.

@danakj danakj enabled auto-merge November 19, 2025 17:58
@danakj danakj added this pull request to the merge queue Nov 19, 2025
Merged via the queue into carbon-language:trunk with commit 7a400d2 Nov 19, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants