-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Reorganize TypeContextDescriptorFlags to be a bit more semantic #18253
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
Merged
rjmccall
merged 1 commit into
swiftlang:master
from
rjmccall:reorganize-type-descriptor-flags
Jul 26, 2018
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1180,35 +1180,51 @@ class TypeContextDescriptorFlags : public FlagSet<uint16_t> { | |
// Generic flags build upwards from 0. | ||
// Type-specific flags build downwards from 15. | ||
|
||
/// Set if the type represents an imported C tag type. | ||
/// Set if the type supports reflection. C and Objective-C enums | ||
/// currently don't. | ||
/// | ||
/// Meaningful for all type-descriptor kinds. | ||
IsCTag = 0, | ||
IsReflectable = 0, | ||
|
||
/// Set if the type represents an imported C typedef type. | ||
/// Whether there's something unusual about how the metadata is | ||
/// initialized. | ||
/// | ||
/// Meaningful for all type-descriptor kinds. | ||
IsCTypedef = 1, | ||
|
||
/// Set if the type supports reflection. C and Objective-C enums | ||
/// currently don't. | ||
MetadataInitialization = 1, | ||
MetadataInitialization_width = 2, | ||
|
||
/// The namespace of the imported declaration that gave rise to this type. | ||
/// Some languages (most importantly, C/C++/Objective-C) have different | ||
/// symbol namespaces in which types can be declared; for example, | ||
/// `struct A` and `typedef ... A` can be declared in the same scope and | ||
/// resolve to unrelated types. When these declarations are imported, | ||
/// there are several possible ways to distinguish them in Swift, e.g. | ||
/// by implicitly renaming them; however, the external name used for | ||
/// mangling and metadata must be stable and so is based on the original | ||
/// declared name. Therefore, in these languages, we privilege one | ||
/// symbol namespace as the default (although which may depend on the | ||
/// type kind), and declarations from the other(s) must be marked in | ||
/// order to differentiate them. | ||
/// | ||
/// Meaningful for all type-descriptor kinds. | ||
IsReflectable = 2, | ||
ImportNamespace = 3, | ||
ImportNamespace_width = 3, | ||
|
||
/// Set if the type is a Clang-importer-synthesized related entity. After | ||
/// the null terminator for the type name is another null-terminated string | ||
/// containing the tag that discriminates the entity from other synthesized | ||
/// declarations associated with the same declaration. | ||
IsSynthesizedRelatedEntity = 3, | ||
|
||
/// Set if the type requires non-trivial but non-generic metadata | ||
/// initialization. It may or may not be truly "in place" depending | ||
/// on the kind of metadata. | ||
/// Set if the type is an importer-synthesized related entity. | ||
/// A related entity is an entity synthesized in response to an imported | ||
/// type which is not the type itself; for example, when the importer | ||
/// sees an ObjC error domain, it creates an error-wrapper type (a | ||
/// related entity) and a Code enum (not a related entity because it's | ||
/// exactly the original type). | ||
/// | ||
/// The name and import namespace (together with the parent context) | ||
/// identify the original declaration. | ||
/// | ||
/// Currently only meaningful for value descriptors, but will be | ||
/// extended to class descriptors. | ||
HasInPlaceMetadataInitialization = 4, | ||
/// If this flag is set, then after the null terminator for the type name | ||
/// is another null-terminated string containing the tag that discriminates | ||
/// the entity from other synthesized declarations associated with the | ||
/// same declaration. | ||
IsSynthesizedRelatedEntity = 6, | ||
|
||
/// Set if the context descriptor is includes metadata for dynamically | ||
/// constructing a class's vtables at metadata instantiation time. | ||
|
@@ -1237,18 +1253,74 @@ class TypeContextDescriptorFlags : public FlagSet<uint16_t> { | |
explicit TypeContextDescriptorFlags(uint16_t bits) : FlagSet(bits) {} | ||
constexpr TypeContextDescriptorFlags() {} | ||
|
||
FLAGSET_DEFINE_FLAG_ACCESSORS(IsCTag, isCTag, setIsCTag) | ||
FLAGSET_DEFINE_FLAG_ACCESSORS(IsCTypedef, isCTypedef, setIsCTypedef) | ||
FLAGSET_DEFINE_FLAG_ACCESSORS(IsReflectable, isReflectable, setIsReflectable) | ||
|
||
enum MetadataInitializationKind { | ||
/// There are either no special rules for initializing the metadata | ||
/// or the metadata is generic. (Genericity is set in the | ||
/// non-kind-specific descriptor flags.) | ||
NoMetadataInitialization = 0, | ||
|
||
/// The type requires non-trivial singleton initialization using the | ||
/// "in-place" code pattern. | ||
InPlaceMetadataInitialization = 1, | ||
|
||
// We only have two bits here, so if you add a third special kind, | ||
// include more flag bits in its out-of-line storage. | ||
}; | ||
|
||
FLAGSET_DEFINE_FIELD_ACCESSORS(MetadataInitialization, | ||
MetadataInitialization_width, | ||
MetadataInitializationKind, | ||
getMetadataInitialization, | ||
setMetadataInitialization) | ||
|
||
bool hasInPlaceMetadataInitialization() const { | ||
return getMetadataInitialization() == InPlaceMetadataInitialization; | ||
} | ||
|
||
enum ImportNamespaceKind { | ||
/// The type comes the default namespace for its language. | ||
DefaultNamespace = 0, | ||
|
||
// The behavior for C imported types is complicated in ways that don't | ||
// entirely make sense according to the design laid out in the comment | ||
// on the ImportNamespace field. The rules are basically: | ||
// - Classes are assumed to come from Objective-C by default. | ||
// ObjC classes are in the ordinary namespace in C. | ||
// - Protocols are assumed to come from Objective-C by default. | ||
// ObjC protocols are in their own namespace in C. | ||
// - Structs and enums seem to always get either CTag or CTypedef. | ||
// It would probably make more sense to assume they come from the | ||
// tag namespace in C and then just use CTypedef as an override. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (This part is still fine, though. We would never map a class or protocol to a struct.) |
||
|
||
/// The type comes from an imported C tag type. | ||
CTag = 1, | ||
|
||
/// The type comes from an imported C typedef type. | ||
CTypedef = 2, | ||
|
||
// We only have three bits here, so be judicious about adding new | ||
// namespaces. | ||
}; | ||
|
||
FLAGSET_DEFINE_FIELD_ACCESSORS(ImportNamespace, | ||
ImportNamespace_width, | ||
ImportNamespaceKind, | ||
getImportNamespace, | ||
setImportNamespace) | ||
|
||
bool isCTag() const { | ||
return getImportNamespace() == CTag; | ||
} | ||
bool isCTypedef() const { | ||
return getImportNamespace() == CTypedef; | ||
} | ||
|
||
FLAGSET_DEFINE_FLAG_ACCESSORS(IsSynthesizedRelatedEntity, | ||
isSynthesizedRelatedEntity, | ||
setIsSynthesizedRelatedEntity) | ||
|
||
FLAGSET_DEFINE_FLAG_ACCESSORS(HasInPlaceMetadataInitialization, | ||
hasInPlaceMetadataInitialization, | ||
setHasInPlaceMetadataInitialization) | ||
|
||
FLAGSET_DEFINE_FLAG_ACCESSORS(Class_HasVTable, | ||
class_hasVTable, | ||
class_setHasVTable) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not correct. Structs, enums, and unions always get CTag. CTypedef is only for typedefs with the
swift_wrapper
attribute.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, and for CF types.