Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(173)

Side by Side Diff: src/types.h

Issue 759013003: Avoid number range holes in bitset types. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Add PlainNumber type to bunch of tests. Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_TYPES_H_ 5 #ifndef V8_TYPES_H_
6 #define V8_TYPES_H_ 6 #define V8_TYPES_H_
7 7
8 #include "src/conversions.h" 8 #include "src/conversions.h"
9 #include "src/factory.h" 9 #include "src/factory.h"
10 #include "src/handles.h" 10 #include "src/handles.h"
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 V(TaggedInt, 1u << 30 | kSemantic) \ 172 V(TaggedInt, 1u << 30 | kSemantic) \
173 V(TaggedPtr, 1u << 31 | kSemantic) \ 173 V(TaggedPtr, 1u << 31 | kSemantic) \
174 \ 174 \
175 V(UntaggedInt, kUntaggedInt1 | kUntaggedInt8 | \ 175 V(UntaggedInt, kUntaggedInt1 | kUntaggedInt8 | \
176 kUntaggedInt16 | kUntaggedInt32) \ 176 kUntaggedInt16 | kUntaggedInt32) \
177 V(UntaggedFloat, kUntaggedFloat32 | kUntaggedFloat64) \ 177 V(UntaggedFloat, kUntaggedFloat32 | kUntaggedFloat64) \
178 V(UntaggedNumber, kUntaggedInt | kUntaggedFloat) \ 178 V(UntaggedNumber, kUntaggedInt | kUntaggedFloat) \
179 V(Untagged, kUntaggedNumber | kUntaggedPtr) \ 179 V(Untagged, kUntaggedNumber | kUntaggedPtr) \
180 V(Tagged, kTaggedInt | kTaggedPtr) 180 V(Tagged, kTaggedInt | kTaggedPtr)
181 181
182 #define SEMANTIC_BITSET_TYPE_LIST(V) \ 182 #define INTERNAL_BITSET_TYPE_LIST(V) \
rossberg 2014/12/03 14:07:01 How about moving OtherString and OtherNumber to th
183 V(Null, 1u << 1 | REPRESENTATION(kTaggedPtr)) \ 183 V(OtherUnsigned31, 1u << 1 | REPRESENTATION(kTagged | kUntaggedNumber)) \
184 V(Undefined, 1u << 2 | REPRESENTATION(kTaggedPtr)) \ 184 V(OtherUnsigned32, 1u << 2 | REPRESENTATION(kTagged | kUntaggedNumber)) \
185 V(Boolean, 1u << 3 | REPRESENTATION(kTaggedPtr)) \ 185 V(OtherSigned32, 1u << 3 | REPRESENTATION(kTagged | kUntaggedNumber)) \
186 V(UnsignedSmall, 1u << 4 | REPRESENTATION(kTagged | kUntaggedNumber)) \ 186 V(OtherNumber, 1u << 4 | REPRESENTATION(kTagged | kUntaggedNumber))
187 V(OtherSignedSmall, 1u << 5 | REPRESENTATION(kTagged | kUntaggedNumber)) \ 187
188 V(OtherUnsigned31, 1u << 6 | REPRESENTATION(kTagged | kUntaggedNumber)) \ 188 #define SEMANTIC_BITSET_TYPE_LIST(V) \
189 V(OtherUnsigned32, 1u << 7 | REPRESENTATION(kTagged | kUntaggedNumber)) \ 189 V(NegativeSignedSmall, 1u << 5 | REPRESENTATION(kTagged | kUntaggedNumber)) \
190 V(OtherSigned32, 1u << 8 | REPRESENTATION(kTagged | kUntaggedNumber)) \ 190 V(Null, 1u << 6 | REPRESENTATION(kTaggedPtr)) \
191 V(MinusZero, 1u << 9 | REPRESENTATION(kTagged | kUntaggedNumber)) \ 191 V(Undefined, 1u << 7 | REPRESENTATION(kTaggedPtr)) \
192 V(NaN, 1u << 10 | REPRESENTATION(kTagged | kUntaggedNumber)) \ 192 V(Boolean, 1u << 8 | REPRESENTATION(kTaggedPtr)) \
193 V(OtherNumber, 1u << 11 | REPRESENTATION(kTagged | kUntaggedNumber)) \ 193 V(UnsignedSmall, 1u << 9 | REPRESENTATION(kTagged | kUntaggedNumber)) \
194 V(Symbol, 1u << 12 | REPRESENTATION(kTaggedPtr)) \ 194 V(MinusZero, 1u << 10 | REPRESENTATION(kTagged | kUntaggedNumber)) \
195 V(InternalizedString, 1u << 13 | REPRESENTATION(kTaggedPtr)) \ 195 V(NaN, 1u << 11 | REPRESENTATION(kTagged | kUntaggedNumber)) \
196 V(OtherString, 1u << 14 | REPRESENTATION(kTaggedPtr)) \ 196 V(Symbol, 1u << 12 | REPRESENTATION(kTaggedPtr)) \
197 V(Undetectable, 1u << 15 | REPRESENTATION(kTaggedPtr)) \ 197 V(InternalizedString, 1u << 13 | REPRESENTATION(kTaggedPtr)) \
198 V(Array, 1u << 16 | REPRESENTATION(kTaggedPtr)) \ 198 V(OtherString, 1u << 14 | REPRESENTATION(kTaggedPtr)) \
199 V(Buffer, 1u << 17 | REPRESENTATION(kTaggedPtr)) \ 199 V(Undetectable, 1u << 15 | REPRESENTATION(kTaggedPtr)) \
200 V(Function, 1u << 18 | REPRESENTATION(kTaggedPtr)) \ 200 V(Array, 1u << 16 | REPRESENTATION(kTaggedPtr)) \
201 V(RegExp, 1u << 19 | REPRESENTATION(kTaggedPtr)) \ 201 V(Buffer, 1u << 17 | REPRESENTATION(kTaggedPtr)) \
202 V(OtherObject, 1u << 20 | REPRESENTATION(kTaggedPtr)) \ 202 V(Function, 1u << 18 | REPRESENTATION(kTaggedPtr)) \
203 V(Proxy, 1u << 21 | REPRESENTATION(kTaggedPtr)) \ 203 V(RegExp, 1u << 19 | REPRESENTATION(kTaggedPtr)) \
204 V(Internal, 1u << 22 | REPRESENTATION(kTagged | kUntagged)) \ 204 V(OtherObject, 1u << 20 | REPRESENTATION(kTaggedPtr)) \
205 \ 205 V(Proxy, 1u << 21 | REPRESENTATION(kTaggedPtr)) \
206 V(SignedSmall, kUnsignedSmall | kOtherSignedSmall) \ 206 V(Internal, 1u << 22 | REPRESENTATION(kTagged | kUntagged)) \
207 V(Signed32, kSignedSmall | kOtherUnsigned31 | kOtherSigned32) \ 207 \
208 V(Unsigned32, kUnsignedSmall | kOtherUnsigned31 | kOtherUnsigned32) \ 208 V(SignedSmall, kUnsignedSmall | kNegativeSignedSmall) \
209 V(Integral32, kSigned32 | kUnsigned32) \ 209 V(Signed32, kSignedSmall | kOtherUnsigned31 | kOtherSigned32) \
210 V(OrderedNumber, kIntegral32 | kMinusZero | kOtherNumber) \ 210 V(NegativeSigned32, kNegativeSignedSmall | kOtherSigned32) \
211 V(Number, kOrderedNumber | kNaN) \ 211 V(NonNegativeSigned32, kUnsignedSmall | kOtherUnsigned31) \
212 V(String, kInternalizedString | kOtherString) \ 212 V(Unsigned32, kNonNegativeSigned32 | kOtherUnsigned32) \
213 V(UniqueName, kSymbol | kInternalizedString) \ 213 V(Integral32, kSigned32 | kUnsigned32) \
214 V(Name, kSymbol | kString) \ 214 V(PlainNumber, kIntegral32 | kOtherNumber) \
215 V(NumberOrString, kNumber | kString) \ 215 V(OrderedNumber, kPlainNumber | kMinusZero) \
216 V(Primitive, kNumber | kName | kBoolean | kNull | kUndefined) \ 216 V(Number, kOrderedNumber | kNaN) \
217 V(DetectableObject, kArray | kFunction | kRegExp | kOtherObject) \ 217 V(String, kInternalizedString | kOtherString) \
218 V(DetectableReceiver, kDetectableObject | kProxy) \ 218 V(UniqueName, kSymbol | kInternalizedString) \
219 V(Detectable, kDetectableReceiver | kNumber | kName) \ 219 V(Name, kSymbol | kString) \
220 V(Object, kDetectableObject | kUndetectable) \ 220 V(NumberOrString, kNumber | kString) \
221 V(Receiver, kObject | kProxy) \ 221 V(Primitive, kNumber | kName | kBoolean | kNull | kUndefined) \
222 V(Unique, kBoolean | kUniqueName | kNull | kUndefined | \ 222 V(DetectableObject, kArray | kFunction | kRegExp | kOtherObject) \
223 kReceiver) \ 223 V(DetectableReceiver, kDetectableObject | kProxy) \
224 V(NonNumber, kUnique | kString | kInternal) \ 224 V(Detectable, kDetectableReceiver | kNumber | kName) \
225 V(Any, 0xfffffffeu) 225 V(Object, kDetectableObject | kUndetectable) \
226 V(Receiver, kObject | kProxy) \
227 V(Unique, kBoolean | kUniqueName | kNull | kUndefined | \
228 kReceiver) \
229 V(NonNumber, kUnique | kString | kInternal) \
230 V(Any, 0xfffffffeu)
226 231
227 /* 232 /*
228 * The following diagrams show how integers (in the mathematical sense) are 233 * The following diagrams show how integers (in the mathematical sense) are
229 * divided among the different atomic numerical types. 234 * divided among the different atomic numerical types.
230 * 235 *
231 * If SmiValuesAre31Bits(): 236 * If SmiValuesAre31Bits():
232 * 237 *
233 * ON OS32 OSS US OU31 OU32 ON 238 * ON OS32 OSS US OU31 OU32 ON
234 * ______[_______[_______[_______[_______[_______[_______ 239 * ______[_______[_______[_______[_______[_______[_______
235 * -2^31 -2^30 0 2^30 2^31 2^32 240 * -2^31 -2^30 0 2^30 2^31 2^32
236 * 241 *
237 * Otherwise: 242 * Otherwise:
238 * 243 *
239 * ON OSS US OU32 ON 244 * ON OSS US OU32 ON
240 * ______[_______________[_______________[_______[_______ 245 * ______[_______________[_______________[_______[_______
241 * -2^31 0 2^31 2^32 246 * -2^31 0 2^31 2^32
242 * 247 *
243 * 248 *
244 * E.g., OtherUnsigned32 (OU32) covers all integers from 2^31 to 2^32-1. 249 * E.g., OtherUnsigned32 (OU32) covers all integers from 2^31 to 2^32-1.
245 * 250 *
246 * NOTE: OtherSigned32 (OS32) and OU31 (OtherUnsigned31) are empty if Smis are 251 * NOTE: OtherSigned32 (OS32) and OU31 (OtherUnsigned31) are empty if Smis are
247 * 32-bit wide. They should thus never be used directly, only indirectly 252 * 32-bit wide. They should thus never be used directly, only indirectly
248 * via e.g. Number. 253 * via e.g. Number.
249 */ 254 */
250 255
251 #define PROPER_BITSET_TYPE_LIST(V) \ 256 #define PROPER_BITSET_TYPE_LIST(V) \
252 REPRESENTATION_BITSET_TYPE_LIST(V) \ 257 REPRESENTATION_BITSET_TYPE_LIST(V) \
253 SEMANTIC_BITSET_TYPE_LIST(V) 258 SEMANTIC_BITSET_TYPE_LIST(V)
254 259
255 #define BITSET_TYPE_LIST(V) \ 260 #define BITSET_TYPE_LIST(V) \
256 MASK_BITSET_TYPE_LIST(V) \ 261 MASK_BITSET_TYPE_LIST(V) \
257 PROPER_BITSET_TYPE_LIST(V) 262 REPRESENTATION_BITSET_TYPE_LIST(V) \
263 INTERNAL_BITSET_TYPE_LIST(V) \
264 SEMANTIC_BITSET_TYPE_LIST(V)
258 265
259 266
260 // ----------------------------------------------------------------------------- 267 // -----------------------------------------------------------------------------
261 // The abstract Type class, parameterized over the low-level representation. 268 // The abstract Type class, parameterized over the low-level representation.
262 269
263 // struct Config { 270 // struct Config {
264 // typedef TypeImpl<Config> Type; 271 // typedef TypeImpl<Config> Type;
265 // typedef Base; 272 // typedef Base;
266 // typedef Struct; 273 // typedef Struct;
267 // typedef Region; 274 // typedef Region;
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 #define DECLARE_TYPE(type, value) k##type = (value), 591 #define DECLARE_TYPE(type, value) k##type = (value),
585 BITSET_TYPE_LIST(DECLARE_TYPE) 592 BITSET_TYPE_LIST(DECLARE_TYPE)
586 #undef DECLARE_TYPE 593 #undef DECLARE_TYPE
587 kUnusedEOL = 0 594 kUnusedEOL = 0
588 }; 595 };
589 596
590 bitset Bitset() { return Config::as_bitset(this); } 597 bitset Bitset() { return Config::as_bitset(this); }
591 598
592 static TypeImpl* New(bitset bits) { 599 static TypeImpl* New(bitset bits) {
593 DCHECK(bits == kNone || IsInhabited(bits)); 600 DCHECK(bits == kNone || IsInhabited(bits));
601
602 if (FLAG_enable_slow_asserts) {
603 // Check that the bitset does not contain any holes in number ranges.
604 bitset mask = kSemantic;
605 if (!i::SmiValuesAre31Bits()) {
606 mask &= ~(kOtherUnsigned31 | kOtherSigned32);
607 }
608 bitset number_bits = bits & kPlainNumber & mask;
609 if (number_bits != 0) {
610 bitset lub = Lub(Min(number_bits), Max(number_bits)) & mask;
611 CHECK(lub == number_bits);
612 }
613 }
614
594 return Config::from_bitset(bits); 615 return Config::from_bitset(bits);
595 } 616 }
596 static TypeHandle New(bitset bits, Region* region) { 617 static TypeHandle New(bitset bits, Region* region) {
597 DCHECK(bits == kNone || IsInhabited(bits)); 618 DCHECK(bits == kNone || IsInhabited(bits));
598 return Config::from_bitset(bits, region); 619 return Config::from_bitset(bits, region);
599 } 620 }
600 // TODO(neis): Eventually allow again for types with empty semantics 621 // TODO(neis): Eventually allow again for types with empty semantics
601 // part and modify intersection and possibly subtyping accordingly. 622 // part and modify intersection and possibly subtyping accordingly.
602 623
603 static bool IsInhabited(bitset bits) { 624 static bool IsInhabited(bitset bits) {
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after
1063 bool Narrows(BoundsImpl that) { 1084 bool Narrows(BoundsImpl that) {
1064 return that.lower->Is(this->lower) && this->upper->Is(that.upper); 1085 return that.lower->Is(this->lower) && this->upper->Is(that.upper);
1065 } 1086 }
1066 }; 1087 };
1067 1088
1068 typedef BoundsImpl<ZoneTypeConfig> Bounds; 1089 typedef BoundsImpl<ZoneTypeConfig> Bounds;
1069 1090
1070 } } // namespace v8::internal 1091 } } // namespace v8::internal
1071 1092
1072 #endif // V8_TYPES_H_ 1093 #endif // V8_TYPES_H_
OLDNEW
« no previous file with comments | « src/compiler/typer.cc ('k') | src/types.cc » ('j') | test/cctest/types-fuzz.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698