mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
to use it. ConcurrentReadableHashMap is lock-free for readers, with writers using a lock to ensure mutual exclusion amongst each other. The intent is to eventually replace all uses ConcurrentMap with ConcurrentReadableHashMap. ConcurrentReadableHashMap provides for relatively quick lookups by using a hash table. Rearders perform an atomic increment/decrement in order to inform writers that there are active readers. The design attempts to minimize wasted memory by storing the actual elements out-of-line, and having the table store indices into a separate array of elements. The protocol conformance cache now uses ConcurrentReadableHashMap, which provides faster lookups and less memory use than the previous ConcurrentMap implementation. The previous implementation caches ProtocolConformanceDescriptors and extracts the WitnessTable after the cache lookup. The new implementation directly caches the WitnessTable, removing an extra step (potentially a quite slow one) from the fast path. The previous implementation used a generational scheme to detect when negative cache entries became obsolete due to new dynamic libraries being loaded, and update them in place. The new implementation just clears the entire cache when libraries are loaded, greatly simplifying the code and saving the memory needed to track the current generation in each negative cache entry. This means we need to re-cache all requested conformances after loading a dynamic library, but loading libraries at runtime is rare and slow anyway. rdar://problem/67268325
227 lines
9.4 KiB
C++
227 lines
9.4 KiB
C++
//===--- CompatibilityOverrides.def - Compatibility Overrides Database -*- C++ -*-===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See https://swift.org/LICENSE.txt for license information
|
|
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file defines x-macros used for metaprogramming with the set of
|
|
// compatibility override functions.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// #define OVERRIDE(name, ret, attrs, namespace, typedArgs, namedArgs)
|
|
/// Provides information about an overridable function.
|
|
/// - name is the name of the function, without any leading swift_ or
|
|
/// namespace.
|
|
/// - ret is the return type of the function.
|
|
/// - attrs is the attributes, if any, applied to the function definition.
|
|
/// - namespace is the namespace, if any, the function is in, including a
|
|
/// trailing ::
|
|
/// - typedArgs is the argument list, including types, surrounded by
|
|
/// parentheses
|
|
/// - namedArgs is the list of argument names, with no types, surrounded by
|
|
/// parentheses
|
|
///
|
|
/// The entries are organized by group. A user may define OVERRIDE to get all
|
|
/// entries, or define one or more of OVERRIDE_METADATALOOKUP, OVERRIDE_CASTING,
|
|
/// OVERRIDE_OBJC, OVERRIDE_FOREIGN, OVERRIDE_PROTOCOLCONFORMANCE,
|
|
/// and OVERRIDE_KEYPATH to get only those entries.
|
|
|
|
// NOTE: this file is used to build the definition of OverrideSection in
|
|
// CompatibilityOverride.cpp, which is part of the ABI. Do not move or remove entries
|
|
// in this file after ABI stability. Additional entries can be added to the end.
|
|
|
|
#ifdef OVERRIDE
|
|
# define OVERRIDE_METADATALOOKUP OVERRIDE
|
|
# define OVERRIDE_CASTING OVERRIDE
|
|
# define OVERRIDE_OBJC OVERRIDE
|
|
# define OVERRIDE_FOREIGN OVERRIDE
|
|
# define OVERRIDE_PROTOCOLCONFORMANCE OVERRIDE
|
|
# define OVERRIDE_KEYPATH OVERRIDE
|
|
# define OVERRIDE_WITNESSTABLE OVERRIDE
|
|
#else
|
|
# ifndef OVERRIDE_METADATALOOKUP
|
|
# define OVERRIDE_METADATALOOKUP(...)
|
|
# endif
|
|
# ifndef OVERRIDE_CASTING
|
|
# define OVERRIDE_CASTING(...)
|
|
# endif
|
|
# ifndef OVERRIDE_OBJC
|
|
# define OVERRIDE_OBJC(...)
|
|
# endif
|
|
# ifndef OVERRIDE_FOREIGN
|
|
# define OVERRIDE_FOREIGN(...)
|
|
# endif
|
|
# ifndef OVERRIDE_PROTOCOLCONFORMANCE
|
|
# define OVERRIDE_PROTOCOLCONFORMANCE(...)
|
|
# endif
|
|
# ifndef OVERRIDE_KEYPATH
|
|
# define OVERRIDE_KEYPATH(...)
|
|
# endif
|
|
# ifndef OVERRIDE_WITNESSTABLE
|
|
# define OVERRIDE_WITNESSTABLE(...)
|
|
# endif
|
|
#endif
|
|
|
|
OVERRIDE_CASTING(dynamicCast, bool, , , swift::,
|
|
(OpaqueValue *dest, OpaqueValue *src,
|
|
const Metadata *srcType,
|
|
const Metadata *targetType,
|
|
DynamicCastFlags flags),
|
|
(dest, src, srcType, targetType, flags))
|
|
|
|
|
|
OVERRIDE_CASTING(dynamicCastClass, const void *, , , swift::,
|
|
(const void *object,
|
|
const ClassMetadata *targetType),
|
|
(object, targetType))
|
|
|
|
|
|
OVERRIDE_CASTING(dynamicCastClassUnconditional, const void *, , , swift::,
|
|
(const void *object,
|
|
const ClassMetadata *targetType,
|
|
const char *file, unsigned line, unsigned column),
|
|
(object, targetType, file, line, column))
|
|
|
|
|
|
|
|
OVERRIDE_CASTING(dynamicCastUnknownClass, const void *, , , swift::,
|
|
(const void *object, const Metadata *targetType),
|
|
(object, targetType))
|
|
|
|
|
|
OVERRIDE_CASTING(dynamicCastUnknownClassUnconditional, const void *, , , swift::,
|
|
(const void *object, const Metadata *targetType,
|
|
const char *file, unsigned line, unsigned column),
|
|
(object, targetType, file, line, column))
|
|
|
|
|
|
OVERRIDE_CASTING(dynamicCastMetatype, const Metadata *, , , swift::,
|
|
(const Metadata *sourceType,
|
|
const Metadata *targetType),
|
|
(sourceType, targetType))
|
|
|
|
|
|
OVERRIDE_CASTING(dynamicCastMetatypeUnconditional, const Metadata *, , , swift::,
|
|
(const Metadata *sourceType,
|
|
const Metadata *targetType,
|
|
const char *file, unsigned line, unsigned column),
|
|
(sourceType, targetType, file, line, column))
|
|
|
|
|
|
OVERRIDE_FOREIGN(dynamicCastForeignClassMetatype, const ClassMetadata *, , , swift::,
|
|
(const ClassMetadata *sourceType,
|
|
const ClassMetadata *targetType),
|
|
(sourceType, targetType))
|
|
|
|
|
|
OVERRIDE_FOREIGN(dynamicCastForeignClassMetatypeUnconditional,
|
|
const ClassMetadata *, , , swift::,
|
|
(const ClassMetadata *sourceType,
|
|
const ClassMetadata *targetType,
|
|
const char *file, unsigned line, unsigned column),
|
|
(sourceType, targetType, file, line, column))
|
|
|
|
|
|
OVERRIDE_PROTOCOLCONFORMANCE(conformsToProtocol, const WitnessTable *, , , swift::,
|
|
(const Metadata * const type,
|
|
const ProtocolDescriptor *protocol),
|
|
(type, protocol))
|
|
|
|
OVERRIDE_PROTOCOLCONFORMANCE(conformsToSwiftProtocol,
|
|
const ProtocolConformanceDescriptor *, , , swift::,
|
|
(const Metadata * const type,
|
|
const ProtocolDescriptor *protocol,
|
|
StringRef moduleName),
|
|
(type, protocol, moduleName))
|
|
|
|
OVERRIDE_KEYPATH(getKeyPath, const HeapObject *, , , swift::,
|
|
(const void *pattern, const void *arguments),
|
|
(pattern, arguments))
|
|
|
|
OVERRIDE_METADATALOOKUP(getTypeByMangledNode, TypeInfo, , SWIFT_CC(swift), swift::,
|
|
(MetadataRequest request,
|
|
Demangler &demangler,
|
|
Demangle::NodePointer node,
|
|
const void * const *arguments,
|
|
SubstGenericParameterFn substGenericParam,
|
|
SubstDependentWitnessTableFn substWitnessTable),
|
|
(request, demangler, node, arguments, substGenericParam, substWitnessTable))
|
|
OVERRIDE_METADATALOOKUP(getTypeByMangledName, TypeInfo, , SWIFT_CC(swift), swift::,
|
|
(MetadataRequest request,
|
|
StringRef typeName,
|
|
const void * const *arguments,
|
|
SubstGenericParameterFn substGenericParam,
|
|
SubstDependentWitnessTableFn substWitnessTable),
|
|
(request, typeName, arguments, substGenericParam, substWitnessTable))
|
|
|
|
OVERRIDE_WITNESSTABLE(getAssociatedTypeWitnessSlow, MetadataResponse,
|
|
SWIFT_RUNTIME_STDLIB_INTERNAL, SWIFT_CC(swift), swift::,
|
|
(MetadataRequest request, WitnessTable *wtable,
|
|
const Metadata *conformingType,
|
|
const ProtocolRequirement *reqBase,
|
|
const ProtocolRequirement *assocType),
|
|
(request, wtable, conformingType, reqBase, assocType))
|
|
|
|
OVERRIDE_WITNESSTABLE(getAssociatedConformanceWitnessSlow, const WitnessTable *,
|
|
SWIFT_RUNTIME_STDLIB_INTERNAL, SWIFT_CC(swift), swift::,
|
|
(WitnessTable *wtable, const Metadata *conformingType,
|
|
const Metadata *assocType,
|
|
const ProtocolRequirement *reqBase,
|
|
const ProtocolRequirement *assocConformance),
|
|
(wtable, conformingType, assocType, reqBase,
|
|
assocConformance))
|
|
#if SWIFT_OBJC_INTEROP
|
|
|
|
OVERRIDE_OBJC(dynamicCastObjCClass, const void *, , , swift::,
|
|
(const void *object,
|
|
const ClassMetadata *targetType),
|
|
(object, targetType))
|
|
|
|
|
|
OVERRIDE_OBJC(dynamicCastObjCClassUnconditional, const void *, , , swift::,
|
|
(const void *object,
|
|
const ClassMetadata *targetType,
|
|
const char *file, unsigned line, unsigned column),
|
|
(object, targetType, file, line, column))
|
|
|
|
OVERRIDE_OBJC(dynamicCastObjCClassMetatype, const ClassMetadata *, , , swift::,
|
|
(const ClassMetadata *sourceType,
|
|
const ClassMetadata *targetType),
|
|
(sourceType, targetType))
|
|
|
|
|
|
OVERRIDE_OBJC(dynamicCastObjCClassMetatypeUnconditional, const ClassMetadata *, , , swift::,
|
|
(const ClassMetadata *sourceType, const ClassMetadata *targetType,
|
|
const char *file, unsigned line, unsigned column),
|
|
(sourceType, targetType, file, line, column))
|
|
|
|
|
|
OVERRIDE_FOREIGN(dynamicCastForeignClass, const void *, , , swift::,
|
|
(const void *object,
|
|
const ForeignClassMetadata *targetType),
|
|
(object, targetType))
|
|
|
|
|
|
OVERRIDE_FOREIGN(dynamicCastForeignClassUnconditional, const void *, , , swift::,
|
|
(const void *object, const ForeignClassMetadata *targetType,
|
|
const char *file, unsigned line, unsigned column),
|
|
(object, targetType, file, line, column))
|
|
|
|
#endif
|
|
|
|
#undef OVERRIDE
|
|
#undef OVERRIDE_METADATALOOKUP
|
|
#undef OVERRIDE_CASTING
|
|
#undef OVERRIDE_OBJC
|
|
#undef OVERRIDE_FOREIGN
|
|
#undef OVERRIDE_PROTOCOLCONFORMANCE
|
|
#undef OVERRIDE_KEYPATH
|
|
#undef OVERRIDE_WITNESSTABLE
|