|
42 | 42 | #include "swift/Basic/SourceLoc.h" |
43 | 43 | #include "swift/Basic/UUID.h" |
44 | 44 | #include "swift/Basic/Version.h" |
| 45 | +#include "llvm/ADT/bit.h" |
45 | 46 | #include "llvm/ADT/DenseMapInfo.h" |
46 | 47 | #include "llvm/ADT/SmallVector.h" |
47 | 48 | #include "llvm/ADT/StringRef.h" |
@@ -264,7 +265,7 @@ class DeclAttribute : public AttributeBase { |
264 | 265 | }; |
265 | 266 |
|
266 | 267 | public: |
267 | | - enum DeclAttrOptions : uint64_t { |
| 268 | + enum DeclAttrRequirements : uint64_t { |
268 | 269 | // There is one entry for each DeclKind, and some higher level buckets |
269 | 270 | // below. These are used in Attr.def to control which kinds of declarations |
270 | 271 | // an attribute can be attached to. |
@@ -303,71 +304,80 @@ class DeclAttribute : public AttributeBase { |
303 | 304 | #include "swift/AST/DeclNodes.def" |
304 | 305 | , |
305 | 306 |
|
| 307 | + /// Whether this attribute is valid on additional decls in ClangImporter. |
| 308 | + OnAnyClangDecl = 1ull << (unsigned(DeclKindIndex::Last_Decl) + 1), |
| 309 | + }; |
| 310 | + |
| 311 | + static_assert( |
| 312 | + (unsigned(DeclKindIndex::Last_Decl) + 1) < 64, |
| 313 | + "Overflow decl attr requirement bitfields"); |
| 314 | + |
| 315 | + enum DeclAttrBehaviors : uint64_t { |
| 316 | + /// Whether this attribute is only valid when concurrency is enabled. |
| 317 | + ConcurrencyOnly = 1ull << 0, |
| 318 | + |
306 | 319 | /// True if multiple instances of this attribute are allowed on a single |
307 | 320 | /// declaration. |
308 | | - AllowMultipleAttributes = 1ull << (unsigned(DeclKindIndex::Last_Decl) + 1), |
| 321 | + AllowMultipleAttributes = 1ull << 1, |
309 | 322 |
|
310 | 323 | /// True if this is a decl modifier - i.e., that it should not be spelled |
311 | 324 | /// with an @. |
312 | | - DeclModifier = 1ull << (unsigned(DeclKindIndex::Last_Decl) + 2), |
| 325 | + DeclModifier = 1ull << 2, |
313 | 326 |
|
314 | 327 | /// True if this is a long attribute that should be printed on its own line. |
315 | 328 | /// |
316 | 329 | /// Currently has no effect on DeclModifier attributes. |
317 | | - LongAttribute = 1ull << (unsigned(DeclKindIndex::Last_Decl) + 3), |
| 330 | + LongAttribute = 1ull << 3, |
318 | 331 |
|
319 | 332 | /// True if this shouldn't be serialized. |
320 | | - NotSerialized = 1ull << (unsigned(DeclKindIndex::Last_Decl) + 4), |
| 333 | + NotSerialized = 1ull << 4, |
321 | 334 |
|
322 | 335 | /// True if this attribute is only valid when parsing a .sil file. |
323 | | - SILOnly = 1ull << (unsigned(DeclKindIndex::Last_Decl) + 5), |
| 336 | + SILOnly = 1ull << 5, |
324 | 337 |
|
325 | 338 | /// The attribute should be reported by parser as unknown. |
326 | | - RejectByParser = 1ull << (unsigned(DeclKindIndex::Last_Decl) + 6), |
| 339 | + RejectByParser = 1ull << 6, |
327 | 340 |
|
328 | | - /// Whether client code cannot use the attribute. |
329 | | - UserInaccessible = 1ull << (unsigned(DeclKindIndex::Last_Decl) + 7), |
| 341 | + /// Whether client code cannot use the attribute. Hides it in code completion. |
| 342 | + UserInaccessible = 1ull << 7, |
330 | 343 |
|
331 | 344 | /// Whether adding this attribute can break API |
332 | | - APIBreakingToAdd = 1ull << (unsigned(DeclKindIndex::Last_Decl) + 8), |
| 345 | + APIBreakingToAdd = 1ull << 8, |
333 | 346 |
|
334 | 347 | /// Whether removing this attribute can break API |
335 | | - APIBreakingToRemove = 1ull << (unsigned(DeclKindIndex::Last_Decl) + 9), |
| 348 | + APIBreakingToRemove = 1ull << 9, |
336 | 349 |
|
337 | 350 | /// Whether adding this attribute can break ABI |
338 | | - ABIBreakingToAdd = 1ull << (unsigned(DeclKindIndex::Last_Decl) + 10), |
| 351 | + ABIBreakingToAdd = 1ull << 10, |
339 | 352 |
|
340 | 353 | /// Whether removing this attribute can break ABI |
341 | | - ABIBreakingToRemove = 1ull << (unsigned(DeclKindIndex::Last_Decl) + 11), |
| 354 | + ABIBreakingToRemove = 1ull << 11, |
342 | 355 |
|
343 | 356 | /// The opposite of APIBreakingToAdd |
344 | | - APIStableToAdd = 1ull << (unsigned(DeclKindIndex::Last_Decl) + 12), |
| 357 | + APIStableToAdd = 1ull << 12, |
345 | 358 |
|
346 | 359 | /// The opposite of APIBreakingToRemove |
347 | | - APIStableToRemove = 1ull << (unsigned(DeclKindIndex::Last_Decl) + 13), |
| 360 | + APIStableToRemove = 1ull << 13, |
348 | 361 |
|
349 | 362 | /// The opposite of ABIBreakingToAdd |
350 | | - ABIStableToAdd = 1ull << (unsigned(DeclKindIndex::Last_Decl) + 14), |
| 363 | + ABIStableToAdd = 1ull << 14, |
351 | 364 |
|
352 | 365 | /// The opposite of ABIBreakingToRemove |
353 | | - ABIStableToRemove = 1ull << (unsigned(DeclKindIndex::Last_Decl) + 15), |
354 | | - |
355 | | - /// Whether this attribute is only valid when concurrency is enabled. |
356 | | - ConcurrencyOnly = 1ull << (unsigned(DeclKindIndex::Last_Decl) + 16), |
357 | | - |
358 | | - /// Whether this attribute is valid on additional decls in ClangImporter. |
359 | | - OnAnyClangDecl = 1ull << (unsigned(DeclKindIndex::Last_Decl) + 17), |
| 366 | + ABIStableToRemove = 1ull << 15, |
360 | 367 | }; |
361 | 368 |
|
362 | | - static_assert( |
363 | | - (unsigned(DeclKindIndex::Last_Decl) + 17) < 64, |
364 | | - "Overflow decl attr options bitfields"); |
| 369 | + LLVM_READNONE |
| 370 | + static uint64_t getRequirements(DeclAttrKind DK); |
| 371 | + |
| 372 | + uint64_t getRequirements() const { |
| 373 | + return getRequirements(getKind()); |
| 374 | + } |
365 | 375 |
|
366 | 376 | LLVM_READNONE |
367 | | - static uint64_t getOptions(DeclAttrKind DK); |
| 377 | + static uint64_t getBehaviors(DeclAttrKind DK); |
368 | 378 |
|
369 | | - uint64_t getOptions() const { |
370 | | - return getOptions(getKind()); |
| 379 | + uint64_t getBehaviors() const { |
| 380 | + return getBehaviors(getKind()); |
371 | 381 | } |
372 | 382 |
|
373 | 383 | /// Prints this attribute (if applicable), returning `true` if anything was |
@@ -433,74 +443,74 @@ class DeclAttribute : public AttributeBase { |
433 | 443 | /// Returns true if multiple instances of an attribute kind |
434 | 444 | /// can appear on a declaration. |
435 | 445 | static bool allowMultipleAttributes(DeclAttrKind DK) { |
436 | | - return getOptions(DK) & AllowMultipleAttributes; |
| 446 | + return getBehaviors(DK) & AllowMultipleAttributes; |
437 | 447 | } |
438 | 448 |
|
439 | 449 | bool isLongAttribute() const { |
440 | 450 | return isLongAttribute(getKind()); |
441 | 451 | } |
442 | 452 | static bool isLongAttribute(DeclAttrKind DK) { |
443 | | - return getOptions(DK) & LongAttribute; |
| 453 | + return getBehaviors(DK) & LongAttribute; |
444 | 454 | } |
445 | 455 |
|
446 | 456 | static bool shouldBeRejectedByParser(DeclAttrKind DK) { |
447 | | - return getOptions(DK) & RejectByParser; |
| 457 | + return getBehaviors(DK) & RejectByParser; |
448 | 458 | } |
449 | 459 |
|
450 | 460 | static bool isSilOnly(DeclAttrKind DK) { |
451 | | - return getOptions(DK) & SILOnly; |
| 461 | + return getBehaviors(DK) & SILOnly; |
452 | 462 | } |
453 | 463 |
|
454 | 464 | static bool isConcurrencyOnly(DeclAttrKind DK) { |
455 | | - return getOptions(DK) & ConcurrencyOnly; |
| 465 | + return getBehaviors(DK) & ConcurrencyOnly; |
456 | 466 | } |
457 | 467 |
|
458 | 468 | static bool isUserInaccessible(DeclAttrKind DK) { |
459 | | - return getOptions(DK) & UserInaccessible; |
| 469 | + return getBehaviors(DK) & UserInaccessible; |
460 | 470 | } |
461 | 471 |
|
462 | 472 | static bool isAddingBreakingABI(DeclAttrKind DK) { |
463 | | - return getOptions(DK) & ABIBreakingToAdd; |
| 473 | + return getBehaviors(DK) & ABIBreakingToAdd; |
464 | 474 | } |
465 | 475 |
|
466 | | -#define DECL_ATTR(_, CLASS, OPTIONS, ...) \ |
467 | | - static constexpr bool isOptionSetFor##CLASS(DeclAttrOptions Bit) { \ |
468 | | - return (OPTIONS) & Bit; \ |
| 476 | +#define DECL_ATTR(_, CLASS, REQUIREMENTS, BEHAVIORS, ...) \ |
| 477 | + static constexpr bool hasOneBehaviorFor##CLASS(uint64_t Mask) { \ |
| 478 | + return llvm::has_single_bit((BEHAVIORS) & Mask); \ |
469 | 479 | } |
470 | 480 | #include "swift/AST/DeclAttr.def" |
471 | 481 |
|
472 | 482 | static bool isAddingBreakingAPI(DeclAttrKind DK) { |
473 | | - return getOptions(DK) & APIBreakingToAdd; |
| 483 | + return getBehaviors(DK) & APIBreakingToAdd; |
474 | 484 | } |
475 | 485 |
|
476 | 486 | static bool isRemovingBreakingABI(DeclAttrKind DK) { |
477 | | - return getOptions(DK) & ABIBreakingToRemove; |
| 487 | + return getBehaviors(DK) & ABIBreakingToRemove; |
478 | 488 | } |
479 | 489 | static bool isRemovingBreakingAPI(DeclAttrKind DK) { |
480 | | - return getOptions(DK) & APIBreakingToRemove; |
| 490 | + return getBehaviors(DK) & APIBreakingToRemove; |
481 | 491 | } |
482 | 492 |
|
483 | 493 | bool isDeclModifier() const { |
484 | 494 | return isDeclModifier(getKind()); |
485 | 495 | } |
486 | 496 | static bool isDeclModifier(DeclAttrKind DK) { |
487 | | - return getOptions(DK) & DeclModifier; |
| 497 | + return getBehaviors(DK) & DeclModifier; |
488 | 498 | } |
489 | 499 |
|
490 | 500 | static bool isOnParam(DeclAttrKind DK) { |
491 | | - return getOptions(DK) & OnParam; |
| 501 | + return getRequirements(DK) & OnParam; |
492 | 502 | } |
493 | 503 |
|
494 | 504 | static bool isOnFunc(DeclAttrKind DK) { |
495 | | - return getOptions(DK) & OnFunc; |
| 505 | + return getRequirements(DK) & OnFunc; |
496 | 506 | } |
497 | 507 |
|
498 | 508 | static bool isOnClass(DeclAttrKind DK) { |
499 | | - return getOptions(DK) & OnClass; |
| 509 | + return getRequirements(DK) & OnClass; |
500 | 510 | } |
501 | 511 |
|
502 | 512 | static bool isNotSerialized(DeclAttrKind DK) { |
503 | | - return getOptions(DK) & NotSerialized; |
| 513 | + return getBehaviors(DK) & NotSerialized; |
504 | 514 | } |
505 | 515 | bool isNotSerialized() const { |
506 | 516 | return isNotSerialized(getKind()); |
|
0 commit comments