@@ -80,17 +80,24 @@ struct IdTag {
80
80
return (llvm::reverseBits (2 ) & tagged_index) != 0 ;
81
81
}
82
82
83
+ template <class TagT >
83
84
struct TagAndIndex {
84
- int32_t tag;
85
+ TagT tag;
85
86
int32_t index;
86
87
};
87
88
88
- static auto DecomposeWithBestEffort (int32_t tagged_index) -> TagAndIndex {
89
+ template <typename TagT>
90
+ static auto DecomposeWithBestEffort (int32_t tagged_index)
91
+ -> TagAndIndex<TagT> {
89
92
if (tagged_index < 0 ) {
90
- return {-1 , tagged_index};
93
+ // TODO: This should return TagT::None, but we need a fallback TagT other
94
+ // than `int32_t`.
95
+ return {TagT{-1 }, tagged_index};
91
96
}
92
97
if (!HasTag (tagged_index)) {
93
- return {-1 , tagged_index};
98
+ // TODO: This should return TagT::None, but we need a fallback TagT other
99
+ // than `int32_t`.
100
+ return {TagT{-1 }, tagged_index};
94
101
}
95
102
int length = 0 ;
96
103
int location = 0 ;
@@ -110,12 +117,14 @@ struct IdTag {
110
117
}
111
118
}
112
119
if (length < 8 ) {
113
- return {-1 , tagged_index};
120
+ // TODO: This should return TagT::None, but we need a fallback TagT other
121
+ // than `int32_t`.
122
+ return {TagT{-1 }, tagged_index};
114
123
}
115
124
auto index_mask = llvm::maskTrailingOnes<uint32_t >(location);
116
125
auto tag = (llvm::reverseBits (tagged_index & ~index_mask) >> 2 ) - 1 ;
117
126
auto index = tagged_index & index_mask;
118
- return {.tag = static_cast <int32_t >(tag),
127
+ return {.tag = TagT{ static_cast <int32_t >(tag)} ,
119
128
.index = static_cast <int32_t >(index)};
120
129
}
121
130
@@ -296,11 +305,14 @@ class ValueStore
296
305
// Attempt to decompose id.index to include extra detail in the check here
297
306
#ifndef NDEBUG
298
307
if (index >= size_) {
299
- auto [ir_id, decomposed_index] = IdTag::DecomposeWithBestEffort (id.index );
308
+ // TODO: Could we add InstId::TagType = CheckIRId and use that here to
309
+ // print the ChcekIRId properly?
310
+ auto [ir_id, decomposed_index] =
311
+ IdTag::DecomposeWithBestEffort<int32_t >(id.index );
300
312
CARBON_DCHECK (
301
313
index < size_,
302
314
" Untagged index was outside of container range. Possibly tagged "
303
- " index {0}. Best-effort decomposition: CheckIRId : {1}, index: {2}. "
315
+ " index {0}. Best-effort decomposition: Tag : {1}, index: {2}. "
304
316
" The IdTag for this container is: {3}" ,
305
317
id.index , ir_id, decomposed_index, tag_.GetContainerTag ());
306
318
}
0 commit comments