react-native-windows 0.74.10 → 0.75.0-preview.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (327) hide show
  1. package/.flowconfig +8 -2
  2. package/Common/Common.vcxproj +8 -0
  3. package/Common/Utilities.cpp +2 -2
  4. package/Directory.Build.targets +5 -0
  5. package/Folly/Folly.vcxproj +10 -2
  6. package/Folly/Folly.vcxproj.filters +0 -7
  7. package/Folly/TEMP_UntilFollyUpdate/ConstexprMath.h +970 -0
  8. package/Folly/TEMP_UntilFollyUpdate/json.cpp +1110 -0
  9. package/Folly/TEMP_UntilFollyUpdate/lang/ToAscii.cpp +4 -2
  10. package/Libraries/Animated/AnimatedImplementation.js +2 -0
  11. package/Libraries/Animated/NativeAnimatedHelper.js +4 -0
  12. package/Libraries/Animated/createAnimatedComponent.js +10 -4
  13. package/Libraries/Animated/useAnimatedProps.js +56 -28
  14. package/Libraries/BatchedBridge/MessageQueue.js +1 -0
  15. package/Libraries/Components/Button.js +10 -5
  16. package/Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.android.js +11 -2
  17. package/Libraries/Components/Flyout/Flyout.js +10 -10
  18. package/Libraries/Components/Flyout/FlyoutNativeComponent.js +8 -7
  19. package/Libraries/Components/Pressable/Pressable.js +13 -6
  20. package/Libraries/Components/Pressable/Pressable.windows.js +13 -6
  21. package/Libraries/Components/ScrollView/AndroidHorizontalScrollViewNativeComponent.js +4 -0
  22. package/Libraries/Components/ScrollView/ScrollView.js +109 -29
  23. package/Libraries/Components/ScrollView/ScrollViewNativeComponent.js +6 -0
  24. package/Libraries/Components/ScrollView/ScrollViewNativeComponent.windows.js +6 -0
  25. package/Libraries/Components/ScrollView/ScrollViewStickyHeader.js +13 -1
  26. package/Libraries/Components/StatusBar/StatusBar.js +1 -21
  27. package/Libraries/Components/Switch/Switch.windows.js +2 -0
  28. package/Libraries/Components/TextInput/AndroidTextInputNativeComponent.js +0 -15
  29. package/Libraries/Components/TextInput/InputAccessoryView.js +10 -1
  30. package/Libraries/Components/TextInput/RCTTextInputViewConfig.js +0 -12
  31. package/Libraries/Components/TextInput/TextInput.d.ts +0 -19
  32. package/Libraries/Components/TextInput/TextInput.js +20 -73
  33. package/Libraries/Components/TextInput/TextInput.windows.js +21 -75
  34. package/Libraries/Components/TextInput/WindowsTextInputNativeComponent.js +27 -12
  35. package/Libraries/Components/Touchable/Touchable.js +2 -2
  36. package/Libraries/Components/Touchable/TouchableHighlight.d.ts +4 -10
  37. package/Libraries/Components/Touchable/TouchableHighlight.js +3 -1
  38. package/Libraries/Components/Touchable/TouchableHighlight.windows.js +3 -1
  39. package/Libraries/Components/Touchable/TouchableOpacity.d.ts +4 -32
  40. package/Libraries/Components/Touchable/TouchableOpacity.js +3 -1
  41. package/Libraries/Components/Touchable/TouchableOpacity.windows.js +3 -1
  42. package/Libraries/Components/Touchable/TouchableWithoutFeedback.d.ts +8 -0
  43. package/Libraries/Components/Touchable/TouchableWithoutFeedback.js +117 -111
  44. package/Libraries/Components/Touchable/TouchableWithoutFeedback.windows.js +129 -110
  45. package/Libraries/Components/View/ReactNativeStyleAttributes.js +6 -0
  46. package/Libraries/Components/View/ReactNativeViewAttributes.js +1 -0
  47. package/Libraries/Components/View/ReactNativeViewAttributes.windows.js +1 -0
  48. package/Libraries/Components/View/View.js +0 -11
  49. package/Libraries/Components/View/View.windows.js +0 -11
  50. package/Libraries/Components/View/ViewAccessibility.js +4 -4
  51. package/Libraries/Components/View/ViewAccessibility.windows.js +4 -4
  52. package/Libraries/Components/View/ViewPropTypes.d.ts +21 -59
  53. package/Libraries/Components/View/ViewPropTypes.js +7 -0
  54. package/Libraries/Components/View/ViewPropTypes.windows.js +7 -0
  55. package/Libraries/Core/Devtools/loadBundleFromServer.js +3 -3
  56. package/Libraries/Core/Devtools/loadBundleFromServer.windows.js +153 -0
  57. package/Libraries/Core/Devtools/parseErrorStack.js +5 -5
  58. package/Libraries/Core/Devtools/parseHermesStack.js +22 -16
  59. package/Libraries/Core/ErrorHandlers.js +116 -0
  60. package/Libraries/Core/ExceptionsManager.js +2 -2
  61. package/Libraries/Core/ReactNativeVersion.js +3 -3
  62. package/Libraries/Core/setUpDeveloperTools.js +3 -1
  63. package/Libraries/Core/setUpPerformance.js +6 -4
  64. package/Libraries/Core/setUpReactDevTools.js +70 -10
  65. package/Libraries/Core/setUpTimers.js +50 -31
  66. package/Libraries/Debugging/DebuggingOverlayRegistry.js +1 -1
  67. package/Libraries/Image/Image.android.js +23 -13
  68. package/Libraries/Image/Image.d.ts +14 -15
  69. package/Libraries/Image/Image.ios.js +21 -11
  70. package/Libraries/Image/Image.windows.js +21 -11
  71. package/Libraries/Image/ImageProps.js +16 -5
  72. package/Libraries/Image/ImageTypes.flow.js +7 -2
  73. package/Libraries/Image/ImageUtils.js +1 -0
  74. package/Libraries/Image/ImageViewNativeComponent.js +2 -1
  75. package/Libraries/Inspector/ElementBox.js +6 -3
  76. package/Libraries/Inspector/ElementProperties.js +1 -1
  77. package/Libraries/Interaction/TouchHistoryMath.js +4 -4
  78. package/Libraries/IntersectionObserver/IntersectionObserverManager.js +6 -26
  79. package/Libraries/JSInspector/NetworkAgent.js +1 -1
  80. package/Libraries/LogBox/Data/LogBoxData.js +39 -29
  81. package/Libraries/LogBox/Data/LogBoxLog.js +114 -2
  82. package/Libraries/LogBox/Data/parseLogBoxLog.js +168 -53
  83. package/Libraries/LogBox/LogBox.js +29 -12
  84. package/Libraries/LogBox/LogBoxNotificationContainer.js +4 -0
  85. package/Libraries/LogBox/UI/LogBoxInspector.js +8 -70
  86. package/Libraries/LogBox/UI/LogBoxInspectorBody.js +87 -0
  87. package/Libraries/LogBox/UI/LogBoxInspectorFooter.js +6 -42
  88. package/Libraries/LogBox/UI/LogBoxInspectorFooterButton.js +58 -0
  89. package/Libraries/LogBox/UI/LogBoxInspectorHeader.js +5 -66
  90. package/Libraries/LogBox/UI/LogBoxInspectorHeader.windows.js +5 -66
  91. package/Libraries/LogBox/UI/LogBoxInspectorHeaderButton.js +76 -0
  92. package/Libraries/LogBox/UI/LogBoxInspectorReactFrames.js +8 -5
  93. package/Libraries/LogBox/UI/LogBoxInspectorReactFrames.windows.js +8 -5
  94. package/Libraries/LogBox/UI/LogBoxNotification.js +13 -152
  95. package/Libraries/LogBox/UI/LogBoxNotificationCountBadge.js +63 -0
  96. package/Libraries/LogBox/UI/LogBoxNotificationDismissButton.js +67 -0
  97. package/Libraries/LogBox/UI/LogBoxNotificationMessage.js +57 -0
  98. package/Libraries/NativeComponent/BaseViewConfig.android.js +5 -0
  99. package/Libraries/NativeComponent/BaseViewConfig.ios.js +5 -0
  100. package/Libraries/NativeComponent/BaseViewConfig.windows.js +5 -0
  101. package/Libraries/NativeComponent/NativeComponentRegistry.js +12 -5
  102. package/Libraries/NativeComponent/StaticViewConfigValidator.js +3 -0
  103. package/Libraries/Network/XMLHttpRequest.js +5 -1
  104. package/Libraries/NewAppScreen/components/LearnMoreLinks.js +3 -3
  105. package/Libraries/Pressability/Pressability.js +3 -51
  106. package/Libraries/Pressability/Pressability.windows.js +3 -51
  107. package/Libraries/ReactNative/AppRegistry.d.ts +4 -0
  108. package/Libraries/ReactNative/AppRegistry.js +2 -4
  109. package/Libraries/ReactNative/BridgelessUIManager.js +1 -21
  110. package/Libraries/ReactNative/FabricUIManager.js +0 -51
  111. package/Libraries/ReactNative/ReactFabricPublicInstance/warnForStyleProps.js +1 -0
  112. package/Libraries/ReactNative/RendererImplementation.js +20 -2
  113. package/Libraries/ReactNative/UIManager.d.ts +0 -21
  114. package/Libraries/ReactNative/UIManagerProperties.js +0 -3
  115. package/Libraries/ReactNative/__mocks__/FabricUIManager.js +5 -341
  116. package/Libraries/ReactNative/getNativeComponentAttributes.js +8 -8
  117. package/Libraries/Renderer/implementations/ReactFabric-dev.js +15682 -27088
  118. package/Libraries/Renderer/implementations/ReactFabric-prod.js +5082 -4381
  119. package/Libraries/Renderer/implementations/ReactFabric-profiling.js +3480 -2571
  120. package/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js +15943 -27543
  121. package/Libraries/Renderer/implementations/ReactNativeRenderer-prod.js +5303 -4606
  122. package/Libraries/Renderer/implementations/ReactNativeRenderer-profiling.js +3450 -2572
  123. package/Libraries/Renderer/shims/ReactFabric.js +2 -2
  124. package/Libraries/Renderer/shims/ReactFeatureFlags.js +2 -2
  125. package/Libraries/Renderer/shims/ReactNative.js +2 -3
  126. package/Libraries/Renderer/shims/ReactNativeTypes.js +24 -3
  127. package/Libraries/Renderer/shims/ReactNativeViewConfigRegistry.js +2 -2
  128. package/Libraries/Renderer/shims/createReactNativeComponentClass.js +2 -2
  129. package/Libraries/Share/Share.d.ts +16 -10
  130. package/Libraries/Share/Share.js +14 -15
  131. package/Libraries/StyleSheet/StyleSheet.d.ts +1 -1
  132. package/Libraries/StyleSheet/StyleSheet.js +3 -10
  133. package/Libraries/StyleSheet/StyleSheetTypes.d.ts +21 -21
  134. package/Libraries/StyleSheet/StyleSheetTypes.js +24 -18
  135. package/Libraries/StyleSheet/flattenStyle.js +1 -0
  136. package/Libraries/StyleSheet/processFilter.js +132 -0
  137. package/Libraries/StyleSheet/processTransform.js +18 -3
  138. package/Libraries/Text/Text.js +151 -128
  139. package/Libraries/Text/Text.windows.js +144 -127
  140. package/Libraries/Text/TextNativeComponent.js +5 -4
  141. package/Libraries/Text/TextProps.js +6 -6
  142. package/Libraries/Text/TextProps.windows.js +6 -6
  143. package/Libraries/TurboModule/TurboModuleRegistry.js +2 -1
  144. package/Libraries/Types/CodegenTypes.js +3 -0
  145. package/Libraries/Utilities/{LoadingView.android.js → DevLoadingView.js} +33 -11
  146. package/Libraries/Utilities/Dimensions.js +1 -0
  147. package/Libraries/Utilities/HMRClient.js +36 -8
  148. package/Libraries/Utilities/HMRClientProdShim.js +1 -0
  149. package/Libraries/Utilities/NativePlatformConstantsWin.js +2 -2
  150. package/Libraries/Utilities/Platform.android.js +4 -4
  151. package/Libraries/Utilities/RCTLog.js +1 -0
  152. package/Libraries/Utilities/ReactNativeTestTools.js +12 -24
  153. package/Libraries/Utilities/verifyComponentAttributeEquivalence.js +11 -6
  154. package/Libraries/__tests__/ViewWindows-test.js +6 -6
  155. package/Libraries/promiseRejectionTrackingOptions.js +1 -0
  156. package/Microsoft.ReactNative/Base/FollyIncludes.h +1 -1
  157. package/Microsoft.ReactNative/ComponentView.idl +0 -17
  158. package/Microsoft.ReactNative/Fabric/AbiState.cpp +3 -45
  159. package/Microsoft.ReactNative/Fabric/AbiState.h +0 -6
  160. package/Microsoft.ReactNative/Fabric/Composition/ImageComponentView.cpp +10 -6
  161. package/Microsoft.ReactNative/Fabric/Composition/ImageComponentView.h +4 -4
  162. package/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.cpp +12 -3
  163. package/Microsoft.ReactNative/Fabric/Composition/ScrollViewComponentView.cpp +1 -1
  164. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputComponentView.cpp +7 -12
  165. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputShadowNode.cpp +1 -2
  166. package/Microsoft.ReactNative/Fabric/Composition/UriImageManager.cpp +9 -3
  167. package/Microsoft.ReactNative/Fabric/Composition/UriImageManager.h +1 -1
  168. package/Microsoft.ReactNative/Fabric/FabricUIManagerModule.cpp +11 -18
  169. package/Microsoft.ReactNative/Fabric/FabricUIManagerModule.h +3 -5
  170. package/Microsoft.ReactNative/Fabric/WindowsImageManager.cpp +23 -11
  171. package/Microsoft.ReactNative/Fabric/WindowsImageManager.h +5 -2
  172. package/Microsoft.ReactNative/Fabric/platform/react/renderer/components/view/HostPlatformViewEventEmitter.cpp +2 -10
  173. package/Microsoft.ReactNative/Fabric/platform/react/renderer/textlayoutmanager/TextLayoutManager.cpp +107 -36
  174. package/Microsoft.ReactNative/Fabric/platform/react/renderer/textlayoutmanager/TextLayoutManager.h +18 -12
  175. package/Microsoft.ReactNative/Modules/DevSettingsModule.cpp +4 -0
  176. package/Microsoft.ReactNative/Modules/DevSettingsModule.h +1 -0
  177. package/Microsoft.ReactNative/Modules/ImageViewManagerModule.cpp +1 -2
  178. package/Microsoft.ReactNative/Modules/NativeUIManager.cpp +7 -4
  179. package/Microsoft.ReactNative/Modules/NativeUIManager.h +1 -1
  180. package/Microsoft.ReactNative/Modules/PlatformConstantsWinModule.cpp +2 -2
  181. package/Microsoft.ReactNative/Modules/PlatformConstantsWinModule.h +3 -3
  182. package/Microsoft.ReactNative/ReactHost/ReactInstanceWin.cpp +11 -17
  183. package/Microsoft.ReactNative/ReactHost/ReactInstanceWin.h +1 -1
  184. package/Microsoft.ReactNative/Timer.idl +1 -3
  185. package/Microsoft.ReactNative/Utils/BatchingEventEmitter.cpp +1 -1
  186. package/Microsoft.ReactNative/Utils/LocalBundleReader.cpp +2 -3
  187. package/Microsoft.ReactNative/Utils/ValueUtils.cpp +1 -1
  188. package/Microsoft.ReactNative/Views/DynamicAutomationPeer.cpp +2 -2
  189. package/Microsoft.ReactNative/Views/TextInputViewManager.cpp +1 -1
  190. package/Microsoft.ReactNative/packages.lock.json +45 -72
  191. package/Microsoft.ReactNative.Cxx/JSI/LongLivedJsiValue.h +1 -1
  192. package/Microsoft.ReactNative.Cxx/Microsoft.ReactNative.Cxx.vcxitems +5 -0
  193. package/Microsoft.ReactNative.Cxx/Microsoft.ReactNative.Cxx.vcxitems.filters +1 -0
  194. package/Microsoft.ReactNative.Cxx/TurboModuleProvider.cpp +14 -6
  195. package/Microsoft.ReactNative.Cxx/TurboModuleProvider.h +2 -2
  196. package/Microsoft.ReactNative.Managed/Microsoft.ReactNative.Managed.csproj +1 -1
  197. package/Microsoft.ReactNative.Managed/packages.lock.json +3 -3
  198. package/PropertySheets/ARM64EC.props +13 -0
  199. package/PropertySheets/Application/ARM64EC.props +13 -0
  200. package/PropertySheets/DynamicLibrary/ARM64EC.props +13 -0
  201. package/PropertySheets/External/Microsoft.ReactNative.WindowsSdk.Default.props +4 -4
  202. package/PropertySheets/Generated/PackageVersion.g.props +4 -4
  203. package/PropertySheets/JSEngine.props +2 -0
  204. package/PropertySheets/StaticLibrary/ARM64EC.props +13 -0
  205. package/README.md +21 -21
  206. package/ReactCommon/ReactCommon.vcxproj +11 -1
  207. package/ReactCommon/ReactCommon.vcxproj.filters +19 -12
  208. package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/JSExecutor.cpp +67 -0
  209. package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/JSExecutor.h +180 -0
  210. package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/NativeToJsBridge.cpp +351 -0
  211. package/ReactCommon/TEMP_UntilReactCommonUpdate/jsi/jsi/test/testlib.cpp +6 -3
  212. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/bridging/Base.h +152 -0
  213. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/bridging/Bridging.h +2 -1
  214. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/bridging/CallbackWrapper.h +13 -15
  215. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/bridging/EventEmitter.h +137 -0
  216. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/bridging/Function.h +283 -0
  217. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/nativemodule/core/ReactCommon/TurboModule.cpp +7 -10
  218. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/nativemodule/core/ReactCommon/TurboModule.h +162 -0
  219. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/nativemodule/core/ReactCommon/TurboModuleUtils.h +2 -4
  220. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/components/scrollview/ScrollViewProps.cpp +33 -8
  221. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/runtime/JSRuntimeFactory.cpp +45 -0
  222. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/runtime/JSRuntimeFactory.h +67 -0
  223. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/runtime/ReactInstance.cpp +104 -74
  224. package/Scripts/StripAdditionalPlatformsFromNuspec.ps1 +1 -1
  225. package/Scripts/Tfs/Layout-MSRN-Headers.ps1 +10 -6
  226. package/Scripts/rnw-dependencies.ps1 +36 -23
  227. package/Shared/HermesRuntimeHolder.cpp +19 -1
  228. package/Shared/HermesRuntimeHolder.h +8 -1
  229. package/Shared/HermesSamplingProfiler.cpp +1 -2
  230. package/Shared/Networking/WinRTWebSocketResource.cpp +3 -3
  231. package/Shared/OInstance.cpp +1 -2
  232. package/Shared/Shared.vcxitems +21 -15
  233. package/Shared/Shared.vcxitems.filters +8 -3
  234. package/Shared/Threading/BatchingQueueThread.cpp +6 -2
  235. package/Shared/Threading/BatchingQueueThread.h +2 -2
  236. package/Shared/Utils/CppWinrtLessExceptions.h +2 -2
  237. package/codegen/NativeAppStateSpec.g.h +8 -8
  238. package/codegen/NativeBlobModuleSpec.g.h +0 -10
  239. package/codegen/NativeDOMSpec.g.h +136 -0
  240. package/codegen/NativeDevSettingsSpec.g.h +11 -5
  241. package/codegen/NativeIdleCallbacksSpec.g.h +64 -0
  242. package/codegen/NativeIntersectionObserverSpec.g.h +14 -14
  243. package/codegen/NativeMicrotasksSpec.g.h +34 -0
  244. package/codegen/NativePerformanceSpec.g.h +35 -7
  245. package/codegen/NativePlatformConstantsWindowsSpec.g.h +81 -0
  246. package/codegen/NativePushNotificationManagerIOSSpec.g.h +15 -19
  247. package/codegen/NativeReactNativeFeatureFlagsSpec.g.h +111 -39
  248. package/codegen/NativeUIManagerSpec.g.h +5 -17
  249. package/codegen/react/components/rnwcore/Props.cpp +1 -1
  250. package/codegen/react/components/rnwcore/Props.h +16 -12
  251. package/codegen/react/components/rnwcore/States.h +0 -26
  252. package/codegen/rnwcoreJSI-generated.cpp +688 -463
  253. package/codegen/rnwcoreJSI.h +1374 -2867
  254. package/fmt/TEMP_UntilFmtUpdate/core.h +2925 -0
  255. package/fmt/fmt.vcxproj +10 -2
  256. package/jest/mockComponent.js +7 -0
  257. package/jest/renderer.js +25 -14
  258. package/jest/setup.js +19 -13
  259. package/package.json +29 -27
  260. package/rn-get-polyfills.js +1 -0
  261. package/src/private/core/composeStyles.js +27 -0
  262. package/src/private/featureflags/ReactNativeFeatureFlags.js +93 -33
  263. package/src/private/featureflags/ReactNativeFeatureFlagsBase.js +23 -4
  264. package/src/private/featureflags/specs/NativeReactNativeFeatureFlags.js +56 -0
  265. package/src/private/fusebox/setUpFuseboxReactDevToolsDispatcher.js +108 -0
  266. package/src/private/specs/modules/NativeBlobModule.js +4 -2
  267. package/src/private/specs/modules/NativeDevSettings.js +1 -0
  268. package/src/private/specs/modules/NativePushNotificationManagerIOS.js +0 -4
  269. package/src/private/specs/modules/NativeUIManager.js +0 -7
  270. package/src/private/webapis/dom/geometry/DOMRectReadOnly.js +24 -24
  271. package/src/private/webapis/dom/nodes/ReactNativeElement.js +11 -14
  272. package/src/private/webapis/dom/nodes/ReadOnlyCharacterData.js +2 -3
  273. package/src/private/webapis/dom/nodes/ReadOnlyElement.js +24 -54
  274. package/src/private/webapis/dom/nodes/ReadOnlyNode.js +5 -13
  275. package/src/private/webapis/dom/nodes/specs/NativeDOM.js +468 -0
  276. package/src/private/webapis/dom/nodes/specs/__mocks__/NativeDOMMock.js +413 -0
  277. package/src/private/webapis/dom/oldstylecollections/DOMRectList.js +4 -4
  278. package/src/private/webapis/dom/oldstylecollections/HTMLCollection.js +4 -4
  279. package/src/private/webapis/dom/oldstylecollections/NodeList.js +5 -5
  280. package/src/private/webapis/idlecallbacks/specs/NativeIdleCallbacks.js +34 -0
  281. package/src/private/webapis/microtasks/specs/NativeMicrotasks.js +21 -0
  282. package/src/private/webapis/performance/EventCounts.js +1 -1
  283. package/src/private/webapis/performance/MemoryInfo.js +9 -9
  284. package/src/private/webapis/performance/Performance.js +10 -56
  285. package/src/private/webapis/performance/PerformanceObserver.js +30 -22
  286. package/src/private/webapis/performance/RawPerformanceEntry.js +2 -7
  287. package/src/private/webapis/performance/ReactNativeStartupTiming.js +18 -18
  288. package/src/private/webapis/performance/UserTiming.js +63 -0
  289. package/src/private/webapis/performance/{NativePerformance.js → specs/NativePerformance.js} +3 -2
  290. package/src/private/webapis/performance/{NativePerformanceObserver.js → specs/NativePerformanceObserver.js} +2 -2
  291. package/src/private/webapis/performance/{__mocks__ → specs/__mocks__}/NativePerformance.js +1 -1
  292. package/src/private/webapis/performance/{__mocks__ → specs/__mocks__}/NativePerformanceObserver.js +3 -4
  293. package/stubs/glog/logging.h +1 -0
  294. package/template/cpp-lib/proj/MyLib.vcxproj +1 -1
  295. package/template/cs-lib/proj/MyLib.csproj +1 -1
  296. package/template/metro.config.js +13 -2
  297. package/templates/cpp-app/template.config.js +1 -1
  298. package/templates/cpp-lib/example/metro.config.js +2 -2
  299. package/templates/cpp-lib/template.config.js +1 -1
  300. package/templates/old/generateWrapper.js +4 -1
  301. package/types/modules/globals.d.ts +4 -0
  302. package/Libraries/Lists/FlatList.windows.js +0 -717
  303. package/Libraries/NativeModules/specs/NativeAnimationsDebugModule.js +0 -13
  304. package/Libraries/Utilities/LoadingView.ios.js +0 -50
  305. package/Libraries/Utilities/LoadingView.js +0 -16
  306. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/nativemodule/core/ReactCommon/TurboModuleBinding.cpp +0 -178
  307. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/utils/jsi-utils.cpp +0 -39
  308. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/utils/jsi-utils.h +0 -31
  309. package/ReactCommon/TEMP_UntilReactCommonUpdate/yoga/yoga/YGEnums.h +0 -137
  310. package/ReactCommon/TEMP_UntilReactCommonUpdate/yoga/yoga/algorithm/CalculateLayout.cpp +0 -2375
  311. package/ReactCommon/TEMP_UntilReactCommonUpdate/yoga/yoga/enums/ExperimentalFeature.h +0 -40
  312. package/codegen/NativeAnimationsDebugModuleSpec.g.h +0 -40
  313. package/codegen/NativePlatformConstantsWinSpec.g.h +0 -81
  314. package/jest/ReactNativeInternalFeatureFlagsMock.js +0 -13
  315. package/src/private/featureflags/NativeReactNativeFeatureFlags.js +0 -44
  316. package/src/private/featureflags/__tests__/ReactNativeFeatureFlags-test.js +0 -92
  317. package/src/private/specs/modules/NativeAnimationsDebugModule.js +0 -20
  318. package/src/private/webapis/dom/oldstylecollections/__tests__/DOMRectList-test.js +0 -85
  319. package/src/private/webapis/dom/oldstylecollections/__tests__/HTMLCollection-test.js +0 -80
  320. package/src/private/webapis/dom/oldstylecollections/__tests__/NodeList-test.js +0 -161
  321. package/src/private/webapis/performance/__tests__/EventCounts-test.js +0 -116
  322. package/src/private/webapis/performance/__tests__/NativePerformanceMock-test.js +0 -82
  323. package/src/private/webapis/performance/__tests__/NativePerformanceObserverMock-test.js +0 -108
  324. package/src/private/webapis/performance/__tests__/Performance-test.js +0 -117
  325. package/src/private/webapis/performance/__tests__/PerformanceObserver-test.js +0 -208
  326. package/template/metro.devMode.config.js +0 -56
  327. /package/src/private/specs/modules/{NativePlatformConstantsWin.js → NativePlatformConstantsWindows.js} +0 -0
@@ -0,0 +1,970 @@
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ #pragma once
18
+
19
+ #include <cassert>
20
+ #include <cstddef>
21
+ #include <cstdint>
22
+ #include <functional>
23
+ #include <limits>
24
+ #include <type_traits>
25
+
26
+ #include <folly/Portability.h>
27
+
28
+ namespace folly {
29
+
30
+ /// numbers
31
+ ///
32
+ /// mimic: std::numbers, C++20 (partial)
33
+ namespace numbers {
34
+
35
+ namespace detail {
36
+ template <typename T>
37
+ using enable_if_floating_t =
38
+ std::enable_if_t<std::is_floating_point<T>::value, T>;
39
+ }
40
+
41
+ /// e_v
42
+ ///
43
+ /// mimic: std::numbers::e_v, C++20
44
+ template <typename T>
45
+ FOLLY_INLINE_VARIABLE constexpr T e_v = detail::enable_if_floating_t<T>(
46
+ 2.71828182845904523536028747135266249775724709369995L);
47
+
48
+ /// ln2_v
49
+ ///
50
+ /// mimic: std::numbers::ln2_v, C++20
51
+ template <typename T>
52
+ FOLLY_INLINE_VARIABLE constexpr T ln2_v = detail::enable_if_floating_t<T>(
53
+ 0.69314718055994530941723212145817656807550013436025L);
54
+
55
+ /// e
56
+ ///
57
+ /// mimic: std::numbers::e, C++20
58
+ FOLLY_INLINE_VARIABLE constexpr double e = e_v<double>;
59
+
60
+ /// ln2
61
+ ///
62
+ /// mimic: std::numbers::ln2, C++20
63
+ FOLLY_INLINE_VARIABLE constexpr double ln2 = ln2_v<double>;
64
+
65
+ } // namespace numbers
66
+
67
+ /// floating_point_integral_constant
68
+ ///
69
+ /// Like std::integral_constant but for floating-point types holding integral
70
+ /// values representable in an integral type.
71
+ template <typename T, typename S, S Value>
72
+ struct floating_point_integral_constant {
73
+ using value_type = T;
74
+ static constexpr value_type value = static_cast<value_type>(Value);
75
+ constexpr operator value_type() const noexcept { return value; }
76
+ constexpr value_type operator()() const noexcept { return value; }
77
+ };
78
+ #if FOLLY_CPLUSPLUS < 201703L
79
+ template <typename T, typename S, S Value>
80
+ constexpr typename floating_point_integral_constant<T, S, Value>::value_type
81
+ floating_point_integral_constant<T, S, Value>::value;
82
+ #endif
83
+
84
+ // ----
85
+
86
+ namespace detail {
87
+
88
+ template <typename T>
89
+ constexpr size_t constexpr_iterated_squares_desc_size_(T const base) {
90
+ using lim = std::numeric_limits<T>;
91
+ size_t s = 1;
92
+ auto r = base;
93
+ while (r <= lim::max() / r) {
94
+ ++s;
95
+ r *= r;
96
+ }
97
+ return s;
98
+ }
99
+
100
+ } // namespace detail
101
+
102
+ /// constexpr_iterated_squares_desc_size_v
103
+ ///
104
+ /// Effectively calculates: floor(log(max_exponent)/log(base))
105
+ ///
106
+ /// For use with constexpr_iterated_squares_desc below.
107
+ template <typename Base>
108
+ FOLLY_INLINE_VARIABLE constexpr size_t constexpr_iterated_squares_desc_size_v =
109
+ detail::constexpr_iterated_squares_desc_size_(Base::value);
110
+
111
+ /// constexpr_iterated_squares_desc
112
+ ///
113
+ /// A constexpr scaling array of integer powers-of-powers-of-two, descending,
114
+ /// with the associated powers-of-two.
115
+ ///
116
+ /// scaling = [..., {8, b^8}, {4, b^4}, {2, b^2}, {1, b^1}] for b = base
117
+ ///
118
+ /// Includes select constexpr scaling algorithms based on the scaling array.
119
+ ///
120
+ /// The scaling array and the scaling algorithms are general-purpose, if niche.
121
+ /// They may be used by other constexpr math functions (floating-point) either
122
+ /// to improve runtime performance or to improve numerical approximations.
123
+ ///
124
+ /// Some compilers fail to support passing some types as non-type template
125
+ /// params. In particular, long double is not universally supported. Therefore,
126
+ /// this utility takes its base as a type rather than as a value. For floating-
127
+ /// point integral bases, that is, bases of floating-point type but of integral
128
+ /// value, floating_point_integral_constant is the easiest parameterization.
129
+ template <typename T, std::size_t Size>
130
+ struct constexpr_iterated_squares_desc {
131
+ static_assert(Size > 0, "requires non-zero size");
132
+
133
+ using size_type = decltype(Size);
134
+ using base_type = T;
135
+
136
+ struct item_type {
137
+ size_type power;
138
+ base_type scale;
139
+ };
140
+
141
+ static constexpr size_type size = Size;
142
+ base_type base;
143
+ item_type scaling[size];
144
+
145
+ private:
146
+ using lim = std::numeric_limits<base_type>;
147
+
148
+ static_assert(
149
+ lim::max_exponent < std::numeric_limits<size_type>::max(),
150
+ "size_type too small for base_type");
151
+
152
+ public:
153
+ explicit constexpr constexpr_iterated_squares_desc(base_type r) noexcept
154
+ : base{r}, scaling{} {
155
+ assert(size <= detail::constexpr_iterated_squares_desc_size_(base));
156
+ size_type i = 0;
157
+ size_type p = 1;
158
+ while (true) { // a for-loop might cause multiplication overflow below
159
+ scaling[size - 1 - i] = {p, r};
160
+ if (++i == size) {
161
+ break;
162
+ }
163
+ p *= 2;
164
+ r *= r;
165
+ }
166
+ }
167
+
168
+ /// shrink
169
+ ///
170
+ /// Returns scaling params of the form:
171
+ /// item_type{power, scale} with scale = base ^ power
172
+ /// With power the smallest nonnegative integer such that:
173
+ /// abs(num) / scale <= max
174
+ constexpr item_type shrink(base_type const num, base_type const max) const {
175
+ assert(max > base_type(0));
176
+ auto const rmax = max / base;
177
+ auto const snum = num < base_type(0) ? -num : num;
178
+ auto power = size_type(0);
179
+ auto scale = base_type(1);
180
+ if (!(snum / scale <= max)) {
181
+ for (auto const& i : scaling) {
182
+ auto const next = scale * i.scale;
183
+ auto const div = snum / next;
184
+ if (div <= rmax) {
185
+ continue;
186
+ }
187
+ power += i.power;
188
+ scale = next;
189
+ if (div <= max) {
190
+ break;
191
+ }
192
+ }
193
+ }
194
+ assert(snum / scale <= max);
195
+ return {power, scale};
196
+ }
197
+
198
+ /// growth
199
+ ///
200
+ /// Returns scaling params of the form:
201
+ /// item_type{power, scale} with scale = base ^ power
202
+ /// With power the smallest nonnegative integer such that:
203
+ /// abs(num) * scale >= min
204
+ constexpr item_type growth(base_type const num, base_type const min) const {
205
+ assert(min > base_type(0));
206
+ auto const rmin = min * base;
207
+ auto const snum = num < base_type(0) ? -num : num;
208
+ auto power = size_type(0);
209
+ auto scale = base_type(1);
210
+ if (!(snum * scale >= min)) {
211
+ for (auto const& i : scaling) {
212
+ auto const next = scale * i.scale;
213
+ auto const mul = snum * next;
214
+ if (mul >= rmin) {
215
+ continue;
216
+ }
217
+ power += i.power;
218
+ scale = next;
219
+ if (mul >= min) {
220
+ break;
221
+ }
222
+ }
223
+ }
224
+ assert(snum * scale >= min);
225
+ return {power, scale};
226
+ }
227
+ };
228
+ #if FOLLY_CPLUSPLUS < 201703L
229
+ template <typename T, std::size_t Size>
230
+ constexpr typename constexpr_iterated_squares_desc<T, Size>::size_type
231
+ constexpr_iterated_squares_desc<T, Size>::size;
232
+ #endif
233
+
234
+ /// constexpr_iterated_squares_desc_v
235
+ ///
236
+ /// An instance of constexpr_iterated_squares_desc of max size with the given
237
+ /// base.
238
+ template <typename Base>
239
+ FOLLY_INLINE_VARIABLE constexpr auto constexpr_iterated_squares_desc_v =
240
+ constexpr_iterated_squares_desc<
241
+ typename Base::value_type,
242
+ constexpr_iterated_squares_desc_size_v<Base>>{Base::value};
243
+
244
+ /// constexpr_iterated_squares_desc_2_v
245
+ ///
246
+ /// An alias for constexpr_iterated_squares_desc_v with base 2, which is the
247
+ /// most common base to use with iterated-squares.
248
+ template <typename T>
249
+ constexpr auto& constexpr_iterated_squares_desc_2_v =
250
+ constexpr_iterated_squares_desc_v<
251
+ floating_point_integral_constant<T, int, 2>>;
252
+
253
+ // TLDR: Prefer using operator< for ordering. And when
254
+ // a and b are equivalent objects, we return b to make
255
+ // sorting stable.
256
+ // See http://stepanovpapers.com/notes.pdf for details.
257
+ template <typename T, typename... Ts>
258
+ constexpr T constexpr_max(T a, Ts... ts) {
259
+ T list[] = {ts..., a}; // 0-length arrays are illegal
260
+ // [Windows #12703 - Fix folly CodeQL issues]
261
+ for (size_t i = 0; i < sizeof...(Ts); ++i) {
262
+ a = list[i] < a ? a : list[i];
263
+ }
264
+ return a;
265
+ }
266
+
267
+ // When a and b are equivalent objects, we return a to
268
+ // make sorting stable.
269
+ template <typename T, typename... Ts>
270
+ constexpr T constexpr_min(T a, Ts... ts) {
271
+ T list[] = {ts..., a}; // 0-length arrays are illegal
272
+ // [Windows #12703 - Fix folly CodeQL issues]
273
+ for (size_t i = 0; i < sizeof...(Ts); ++i) {
274
+ a = list[i] < a ? list[i] : a;
275
+ }
276
+ return a;
277
+ }
278
+
279
+ template <typename T, typename Less>
280
+ constexpr T const& constexpr_clamp(
281
+ T const& v, T const& lo, T const& hi, Less less) {
282
+ T const& a = less(v, lo) ? lo : v;
283
+ T const& b = less(hi, a) ? hi : a;
284
+ return b;
285
+ }
286
+ template <typename T>
287
+ constexpr T const& constexpr_clamp(T const& v, T const& lo, T const& hi) {
288
+ return constexpr_clamp(v, lo, hi, std::less<T>{});
289
+ }
290
+
291
+ template <typename T>
292
+ constexpr bool constexpr_isnan(T const t) {
293
+ return t != t; // NOLINT
294
+ }
295
+
296
+ namespace detail {
297
+
298
+ template <typename T, typename = void>
299
+ struct constexpr_abs_helper {};
300
+
301
+ template <typename T>
302
+ struct constexpr_abs_helper<
303
+ T,
304
+ typename std::enable_if<std::is_floating_point<T>::value>::type> {
305
+ static constexpr T go(T t) { return t < static_cast<T>(0) ? -t : t; }
306
+ };
307
+
308
+ template <typename T>
309
+ struct constexpr_abs_helper<
310
+ T,
311
+ typename std::enable_if<
312
+ std::is_integral<T>::value && !std::is_same<T, bool>::value &&
313
+ std::is_unsigned<T>::value>::type> {
314
+ static constexpr T go(T t) { return t; }
315
+ };
316
+
317
+ template <typename T>
318
+ struct constexpr_abs_helper<
319
+ T,
320
+ typename std::enable_if<
321
+ std::is_integral<T>::value && !std::is_same<T, bool>::value &&
322
+ std::is_signed<T>::value>::type> {
323
+ static constexpr typename std::make_unsigned<T>::type go(T t) {
324
+ return typename std::make_unsigned<T>::type(t < static_cast<T>(0) ? -t : t);
325
+ }
326
+ };
327
+
328
+ } // namespace detail
329
+
330
+ template <typename T>
331
+ constexpr auto constexpr_abs(T t)
332
+ -> decltype(detail::constexpr_abs_helper<T>::go(t)) {
333
+ return detail::constexpr_abs_helper<T>::go(t);
334
+ }
335
+
336
+ namespace detail {
337
+
338
+ template <typename T>
339
+ constexpr T constexpr_log2_(T a, T e) {
340
+ return e == T(1) ? a : constexpr_log2_(a + T(1), e / T(2));
341
+ }
342
+
343
+ template <typename T>
344
+ constexpr T constexpr_log2_ceil_(T l2, T t) {
345
+ return l2 + T(T(1) << l2 < t ? 1 : 0);
346
+ }
347
+
348
+ } // namespace detail
349
+
350
+ template <typename T>
351
+ constexpr T constexpr_log2(T t) {
352
+ return detail::constexpr_log2_(T(0), t);
353
+ }
354
+
355
+ template <typename T>
356
+ constexpr T constexpr_log2_ceil(T t) {
357
+ return detail::constexpr_log2_ceil_(constexpr_log2(t), t);
358
+ }
359
+
360
+ /// constexpr_trunc
361
+ ///
362
+ /// mimic: std::trunc (C++23)
363
+ template <
364
+ typename T,
365
+ std::enable_if_t<std::is_floating_point<T>::value, int> = 0>
366
+ constexpr T constexpr_trunc(T const t) {
367
+ using lim = std::numeric_limits<T>;
368
+ using int_type = std::uintmax_t;
369
+ using int_lim = std::numeric_limits<int_type>;
370
+ static_assert(lim::radix == 2, "non-binary radix");
371
+ static_assert(lim::digits <= int_lim::digits, "overwide mantissa");
372
+ constexpr auto bound = static_cast<T>(std::uintmax_t(1) << (lim::digits - 1));
373
+ auto const neg = !constexpr_isnan(t) && t < T(0);
374
+ auto const s = neg ? -t : t;
375
+ if (constexpr_isnan(t) || t == T(0) || !(s < bound)) {
376
+ return t;
377
+ }
378
+ if (s < T(1)) {
379
+ return neg ? -T(0) : T(0);
380
+ }
381
+ auto const r = static_cast<T>(static_cast<int_type>(s));
382
+ return neg ? -r : r;
383
+ }
384
+
385
+ template <typename T, std::enable_if_t<std::is_integral<T>::value, int> = 0>
386
+ constexpr T constexpr_trunc(T const t) {
387
+ return t;
388
+ }
389
+
390
+ /// constexpr_round
391
+ ///
392
+ /// mimic: std::round (C++23)
393
+ template <typename T>
394
+ constexpr T constexpr_round(T const t) {
395
+ constexpr auto half = T(1) / T(2);
396
+ auto const same = constexpr_isnan(t) || t == T(0);
397
+ return same ? t : constexpr_trunc(t < T(0) ? t - half : t + half);
398
+ }
399
+
400
+ /// constexpr_floor
401
+ ///
402
+ /// mimic: std::floor (C++23)
403
+ template <typename T>
404
+ constexpr T constexpr_floor(T const t) {
405
+ auto const s = constexpr_trunc(t);
406
+ return t < s ? s - T(1) : s;
407
+ }
408
+
409
+ /// constexpr_ceil
410
+ ///
411
+ /// mimic: std::ceil (C++23)
412
+ template <typename T>
413
+ constexpr T constexpr_ceil(T const t) {
414
+ auto const s = constexpr_trunc(t);
415
+ return s < t ? s + T(1) : s;
416
+ }
417
+
418
+ /// constexpr_ceil
419
+ ///
420
+ /// The least integer at least t that round divides.
421
+ template <typename T>
422
+ constexpr T constexpr_ceil(T t, T round) {
423
+ return round == T(0)
424
+ ? t
425
+ : ((t + (t < T(0) ? T(0) : round - T(1))) / round) * round;
426
+ }
427
+
428
+ /// constexpr_mult
429
+ ///
430
+ /// Multiply two values, allowing for constexpr floating-pooint overflow to
431
+ /// infinity.
432
+ template <typename T>
433
+ constexpr T constexpr_mult(T const a, T const b) {
434
+ using lim = std::numeric_limits<T>;
435
+ if (constexpr_isnan(a) || constexpr_isnan(b)) {
436
+ return constexpr_isnan(a) ? a : b;
437
+ }
438
+ if (std::is_floating_point<T>::value) {
439
+ constexpr auto inf = lim::infinity();
440
+ auto const ax = constexpr_abs(a);
441
+ auto const bx = constexpr_abs(b);
442
+ if ((ax == T(0) && bx == inf) || (bx == T(0) && ax == inf)) {
443
+ return lim::quiet_NaN();
444
+ }
445
+ // floating-point multiplication overflow, ie where multiplication of two
446
+ // finite values overflows to infinity of either sign, is not constexpr per
447
+ // gcc
448
+ // floating-point division overflow, ie where division of two finite values
449
+ // overflows to infinity of either sign, is not constexpr per gcc
450
+ // floating-point division by zero is not constexpr per any compiler, but we
451
+ // use it in the checks for the other two conditions
452
+ if (ax != inf && bx != inf && T(1) < bx && lim::max() / bx < ax) {
453
+ auto const a_neg = static_cast<bool>(a < T(0));
454
+ auto const b_neg = static_cast<bool>(b < T(0));
455
+ auto const sign = a_neg == b_neg ? T(1) : T(-1);
456
+ return sign * inf;
457
+ }
458
+ }
459
+ return a * b;
460
+ }
461
+
462
+ namespace detail {
463
+
464
+ template <
465
+ typename T,
466
+ typename E,
467
+ std::enable_if_t<std::is_signed<E>::value, int> = 1>
468
+ constexpr T constexpr_ipow(T const base, E const exp) {
469
+ if (std::is_floating_point<T>::value) {
470
+ if (exp < E(0)) {
471
+ return T(1) / constexpr_ipow(base, -exp);
472
+ }
473
+ if (exp == E(0)) {
474
+ return T(1);
475
+ }
476
+ if (constexpr_isnan(base)) {
477
+ return base;
478
+ }
479
+ }
480
+ assert(!(exp < E(0)) && "negative exponent with integral base");
481
+ if (exp == E(0)) {
482
+ return T(1);
483
+ }
484
+ if (exp == E(1)) {
485
+ return base;
486
+ }
487
+ auto const hexp = constexpr_trunc(exp / E(2));
488
+ auto const div = constexpr_ipow(base, hexp);
489
+ auto const rem = hexp * E(2) == exp ? T(1) : base;
490
+ return constexpr_mult(constexpr_mult(div, div), rem);
491
+ }
492
+
493
+ template <
494
+ typename T,
495
+ typename E,
496
+ std::enable_if_t<std::is_unsigned<E>::value, int> = 1>
497
+ constexpr T constexpr_ipow(T const base, E const exp) {
498
+ if (std::is_floating_point<T>::value) {
499
+ if (exp == E(0)) {
500
+ return T(1);
501
+ }
502
+ if (constexpr_isnan(base)) {
503
+ return base;
504
+ }
505
+ }
506
+ if (exp == E(0)) {
507
+ return T(1);
508
+ }
509
+ if (exp == E(1)) {
510
+ return base;
511
+ }
512
+ auto const hexp = constexpr_trunc(exp / E(2));
513
+ auto const div = constexpr_ipow(base, hexp);
514
+ auto const rem = hexp * E(2) == exp ? T(1) : base;
515
+ return constexpr_mult(constexpr_mult(div, div), rem);
516
+ }
517
+
518
+ } // namespace detail
519
+
520
+ /// constexpr_exp
521
+ ///
522
+ /// Calculates an approximation of the mathematical function exp(num). Usable in
523
+ /// constant evaluations. Like std::exp, which becomes constexpr in C++26.
524
+ ///
525
+ /// The integer overload uses iterated squaring and multiplication. The
526
+ /// floating-point overlaod naively evaluates the taylor series of exp(num)
527
+ /// until approximate convergence.
528
+ ///
529
+ /// mimic: std::exp (C++23, C++26)
530
+ template <
531
+ typename T,
532
+ typename N,
533
+ std::enable_if_t<
534
+ std::is_floating_point<T>::value && std::is_integral<N>::value &&
535
+ !std::is_same<N, bool>::value,
536
+ int> = 0>
537
+ constexpr T constexpr_exp(N const power) {
538
+ auto const npower = constexpr_abs(power);
539
+ auto const result = detail::constexpr_ipow(numbers::e_v<T>, npower);
540
+ return power < N(0) ? T(1) / result : result;
541
+ }
542
+ template <
543
+ typename N,
544
+ std::enable_if_t<
545
+ std::is_integral<N>::value && !std::is_same<N, bool>::value,
546
+ int> = 0>
547
+ constexpr double constexpr_exp(N const power) {
548
+ return constexpr_exp<double>(power);
549
+ }
550
+ template <
551
+ typename T,
552
+ std::enable_if_t<std::is_floating_point<T>::value, int> = 0>
553
+ constexpr T constexpr_exp(T const power) {
554
+ using lim = std::numeric_limits<T>;
555
+
556
+ // edge cases
557
+ if (constexpr_isnan(power)) {
558
+ return power;
559
+ }
560
+ if (power == -lim::infinity()) {
561
+ return +T(0);
562
+ }
563
+ if (power == +lim::infinity()) {
564
+ return power;
565
+ }
566
+
567
+ // convergence works better with positive powers since signs do not alternate
568
+ auto const abspower = constexpr_abs(power);
569
+ // convergence must short-circuit when terms grow to floating-point infinity
570
+ auto const bound = T(1) < abspower ? lim::max() / abspower : lim::infinity();
571
+
572
+ // term #index = power * coeff
573
+ auto index = size_t(0);
574
+ auto term = T(1);
575
+ // result = sum of terms
576
+ auto result = T(1);
577
+ // sum the terms until ~convergence
578
+ while (!(constexpr_abs(term) < lim::epsilon())) {
579
+ if (bound < term) {
580
+ return power < T(0) ? T(0) : lim::infinity();
581
+ }
582
+ index += 1;
583
+ term = term * abspower / index;
584
+ result += term;
585
+ }
586
+ return power < T(0) ? T(1) / result : result;
587
+ }
588
+
589
+ /// constexpr_log
590
+ ///
591
+ /// Calculates an approximation of the natural logarithm ln(num).
592
+ ///
593
+ /// The implementation uses a quickly-converging, high-precision iterative
594
+ /// technique as described in:
595
+ /// https://en.wikipedia.org/wiki/Natural_logarithm#High_precision
596
+ ///
597
+ /// The technique works best with numbers that are close enough to 1, so the
598
+ /// implementation uses a quick shrink/growth technique as described in:
599
+ /// https://en.wikipedia.org/wiki/Natural_logarithm#Efficient_computation
600
+ template <
601
+ typename T,
602
+ std::enable_if_t<std::is_floating_point<T>::value, int> = 0>
603
+ constexpr T constexpr_log(T const num) {
604
+ using lim = std::numeric_limits<T>;
605
+ constexpr auto& isq = constexpr_iterated_squares_desc_2_v<T>;
606
+
607
+ // edge cases
608
+ if (constexpr_isnan(num)) {
609
+ return num;
610
+ }
611
+ if (num < T(0)) {
612
+ return lim::quiet_NaN();
613
+ }
614
+ if (num == T(0)) {
615
+ return -lim::infinity();
616
+ }
617
+ if (num == lim::infinity()) {
618
+ return num;
619
+ }
620
+
621
+ // compression
622
+ auto const shrink = isq.shrink(num, isq.base);
623
+ auto const growth = isq.growth(num, T(1));
624
+ auto const scaled = num * growth.scale / shrink.scale;
625
+ assert(scaled <= isq.base);
626
+ assert(scaled >= T(1));
627
+
628
+ auto sum = T(0);
629
+ auto delta = T(2);
630
+ while (constexpr_abs(delta) >= lim::epsilon()) {
631
+ auto expterm = constexpr_exp(sum);
632
+ delta = T(2) * (scaled - expterm) / (scaled + expterm);
633
+ sum += delta;
634
+ }
635
+ auto const ln2 = numbers::ln2_v<T>;
636
+ return sum - growth.power * ln2 + shrink.power * ln2;
637
+ }
638
+
639
+ /// constexpr_pow
640
+ ///
641
+ /// Calculates an approximation of the value of base raised to the exponent exp.
642
+ ///
643
+ /// The implementation uses iterated squaring and multiplication for the integer
644
+ /// part of the exponent and uses the identity x^y = exp(y * log(x)) for the
645
+ /// fractional part of the exponent.
646
+ ///
647
+ /// Notes:
648
+ /// * Forbids base of +0 or -0 with finite non-positive exponent: in part since
649
+ /// the plausible infinite result would be sensitive to the sign of the zero;
650
+ /// and in part since std::pow would be required or permitted to raise error
651
+ /// div-by-zero.
652
+ /// * Forbids finite negative base with finite non-integer exponent: in part
653
+ /// since std::pow would be required to raise error invalid.
654
+ ///
655
+ /// mimic: std::pow (C++26)
656
+ template <
657
+ typename T,
658
+ typename E,
659
+ std::enable_if_t<
660
+ std::is_integral<E>::value && !std::is_same<E, bool>::value,
661
+ int> = 0>
662
+ constexpr T constexpr_pow(T const base, E const exp) {
663
+ return detail::constexpr_ipow(base, exp);
664
+ }
665
+ template <
666
+ typename T,
667
+ std::enable_if_t<std::is_floating_point<T>::value, int> = 0>
668
+ constexpr T constexpr_pow(T const base, T const exp) {
669
+ using lim = std::numeric_limits<T>;
670
+
671
+ // edge cases
672
+ if (exp == T(0)) {
673
+ return T(1);
674
+ }
675
+ if (constexpr_isnan(base)) {
676
+ return base;
677
+ }
678
+ if (exp == lim::infinity() || exp == -lim::infinity()) {
679
+ auto const abase = constexpr_abs(base);
680
+ if (abase < T(1)) {
681
+ return exp == lim::infinity() ? T(0) : lim::infinity();
682
+ }
683
+ if (T(1) < abase) {
684
+ return exp == lim::infinity() ? lim::infinity() : T(0);
685
+ }
686
+ return T(1);
687
+ }
688
+ if (base == T(1)) {
689
+ return base;
690
+ }
691
+ if (constexpr_isnan(exp)) {
692
+ return exp;
693
+ }
694
+ assert(base != T(0) || exp > T(0)); // error div-by-zero
695
+ if (base == lim::infinity()) {
696
+ return exp < T(0) ? T(0) : lim::infinity();
697
+ }
698
+ if (base == -lim::infinity()) {
699
+ auto const oddi = //
700
+ exp == constexpr_trunc(exp) &&
701
+ exp != constexpr_trunc(exp / T(2)) * T(2);
702
+ return (oddi ? -T(1) : T(1)) * (exp < T(0) ? T(0) : lim::infinity());
703
+ }
704
+ if (base == T(0)) {
705
+ auto const oddi = //
706
+ exp == constexpr_trunc(exp) &&
707
+ exp != constexpr_trunc(exp / T(2)) * T(2);
708
+ return oddi ? base : T(0);
709
+ }
710
+ if (exp < T(0)) {
711
+ return T(1) / constexpr_pow(base, -exp);
712
+ }
713
+
714
+ // as an identity: x^y = exp(y * log(x)); but calculation is imprecise ... so,
715
+ // for better precision, split the calculation into its integral-power and its
716
+ // fractional-power components
717
+ // as a cost, the complexity of constexpr_ipow here is logarithmic in y, i.e.,
718
+ // linear in the logarithm of y, which can be prohibitive
719
+ auto const exp_trunc = constexpr_trunc(exp);
720
+ assert(T(0) < base || exp == exp_trunc); // error invalid
721
+ auto const exp_fract = exp - exp_trunc;
722
+ auto const anyi = exp_fract == T(0);
723
+ return constexpr_mult(
724
+ detail::constexpr_ipow(base, exp_trunc),
725
+ anyi ? T(1) : constexpr_exp(exp_fract * constexpr_log(base)));
726
+ }
727
+
728
+ /// constexpr_find_last_set
729
+ ///
730
+ /// Return the 1-based index of the most significant bit which is set.
731
+ /// For x > 0, constexpr_find_last_set(x) == 1 + floor(log2(x)).
732
+ template <typename T>
733
+ constexpr std::size_t constexpr_find_last_set(T const t) {
734
+ using U = std::make_unsigned_t<T>;
735
+ return t == T(0) ? 0 : 1 + constexpr_log2(static_cast<U>(t));
736
+ }
737
+
738
+ namespace detail {
739
+ template <typename U>
740
+ constexpr std::size_t constexpr_find_first_set_(
741
+ std::size_t s, std::size_t a, U const u) {
742
+ return s == 0 ? a
743
+ : constexpr_find_first_set_(
744
+ s / 2, a + s * bool((u >> a) % (U(1) << s) == U(0)), u);
745
+ }
746
+ } // namespace detail
747
+
748
+ /// constexpr_find_first_set
749
+ ///
750
+ /// Return the 1-based index of the least significant bit which is set.
751
+ /// For x > 0, the exponent in the largest power of two which does not divide x.
752
+ template <typename T>
753
+ constexpr std::size_t constexpr_find_first_set(T t) {
754
+ using U = std::make_unsigned_t<T>;
755
+ using size = std::integral_constant<std::size_t, sizeof(T) * 4>;
756
+ return t == T(0)
757
+ ? 0
758
+ : 1 + detail::constexpr_find_first_set_(size{}, 0, static_cast<U>(t));
759
+ }
760
+
761
+ template <typename T>
762
+ constexpr T constexpr_add_overflow_clamped(T a, T b) {
763
+ using L = std::numeric_limits<T>;
764
+ using M = std::intmax_t;
765
+ static_assert(
766
+ !std::is_integral<T>::value || sizeof(T) <= sizeof(M),
767
+ "Integral type too large!");
768
+ // clang-format off
769
+ return
770
+ // don't do anything special for non-integral types.
771
+ !std::is_integral<T>::value ? a + b :
772
+ // for narrow integral types, just convert to intmax_t.
773
+ sizeof(T) < sizeof(M)
774
+ ? T(constexpr_clamp(
775
+ static_cast<M>(a) + static_cast<M>(b),
776
+ static_cast<M>(L::min()),
777
+ static_cast<M>(L::max()))) :
778
+ // when a >= 0, cannot add more than `MAX - a` onto a.
779
+ !(a < 0) ? a + constexpr_min(b, T(L::max() - a)) :
780
+ // a < 0 && b >= 0, `a + b` will always be in valid range of type T.
781
+ !(b < 0) ? a + b :
782
+ // a < 0 && b < 0, keep the result >= MIN.
783
+ a + constexpr_max(b, T(L::min() - a));
784
+ // clang-format on
785
+ }
786
+
787
+ template <typename T>
788
+ constexpr T constexpr_sub_overflow_clamped(T a, T b) {
789
+ using L = std::numeric_limits<T>;
790
+ using M = std::intmax_t;
791
+ static_assert(
792
+ !std::is_integral<T>::value || sizeof(T) <= sizeof(M),
793
+ "Integral type too large!");
794
+ // clang-format off
795
+ return
796
+ // don't do anything special for non-integral types.
797
+ !std::is_integral<T>::value ? a - b :
798
+ // for unsigned type, keep result >= 0.
799
+ std::is_unsigned<T>::value ? (a < b ? 0 : a - b) :
800
+ // for narrow signed integral types, just convert to intmax_t.
801
+ sizeof(T) < sizeof(M)
802
+ ? T(constexpr_clamp(
803
+ static_cast<M>(a) - static_cast<M>(b),
804
+ static_cast<M>(L::min()),
805
+ static_cast<M>(L::max()))) :
806
+ // (a >= 0 && b >= 0) || (a < 0 && b < 0), `a - b` will always be valid.
807
+ (a < 0) == (b < 0) ? a - b :
808
+ // MIN < b, so `-b` should be in valid range (-MAX <= -b <= MAX),
809
+ // convert subtraction to addition.
810
+ L::min() < b ? constexpr_add_overflow_clamped(a, T(-b)) :
811
+ // -b = -MIN = (MAX + 1) and a <= -1, result is in valid range.
812
+ a < 0 ? a - b :
813
+ // -b = -MIN = (MAX + 1) and a >= 0, result > MAX.
814
+ L::max();
815
+ // clang-format on
816
+ }
817
+
818
+ // clamp_cast<> provides sane numeric conversions from float point numbers to
819
+ // integral numbers, and between different types of integral numbers. It helps
820
+ // to avoid unexpected bugs introduced by bad conversion, and undefined behavior
821
+ // like overflow when casting float point numbers to integral numbers.
822
+ //
823
+ // When doing clamp_cast<Dst>(value), if `value` is in valid range of Dst,
824
+ // it will give correct result in Dst, equal to `value`.
825
+ //
826
+ // If `value` is outside the representable range of Dst, it will be clamped to
827
+ // MAX or MIN in Dst, instead of being undefined behavior.
828
+ //
829
+ // Float NaNs are converted to 0 in integral type.
830
+ //
831
+ // Here's some comparison with static_cast<>:
832
+ // (with FB-internal gcc-5-glibc-2.23 toolchain)
833
+ //
834
+ // static_cast<int32_t>(NaN) = 6
835
+ // clamp_cast<int32_t>(NaN) = 0
836
+ //
837
+ // static_cast<int32_t>(9999999999.0f) = -348639895
838
+ // clamp_cast<int32_t>(9999999999.0f) = 2147483647
839
+ //
840
+ // static_cast<int32_t>(2147483647.0f) = -348639895
841
+ // clamp_cast<int32_t>(2147483647.0f) = 2147483647
842
+ //
843
+ // static_cast<uint32_t>(4294967295.0f) = 0
844
+ // clamp_cast<uint32_t>(4294967295.0f) = 4294967295
845
+ //
846
+ // static_cast<uint32_t>(-1) = 4294967295
847
+ // clamp_cast<uint32_t>(-1) = 0
848
+ //
849
+ // static_cast<int16_t>(32768u) = -32768
850
+ // clamp_cast<int16_t>(32768u) = 32767
851
+
852
+ template <typename Dst, typename Src>
853
+ constexpr typename std::enable_if<std::is_integral<Src>::value, Dst>::type
854
+ constexpr_clamp_cast(Src src) {
855
+ static_assert(
856
+ std::is_integral<Dst>::value && sizeof(Dst) <= sizeof(int64_t),
857
+ "constexpr_clamp_cast can only cast into integral type (up to 64bit)");
858
+
859
+ using L = std::numeric_limits<Dst>;
860
+ // clang-format off
861
+ return
862
+ // Check if Src and Dst have same signedness.
863
+ std::is_signed<Src>::value == std::is_signed<Dst>::value
864
+ ? (
865
+ // Src and Dst have same signedness. If sizeof(Src) <= sizeof(Dst),
866
+ // we can safely convert Src to Dst without any loss of accuracy.
867
+ sizeof(Src) <= sizeof(Dst) ? Dst(src) :
868
+ // If Src is larger in size, we need to clamp it to valid range in Dst.
869
+ Dst(constexpr_clamp(src, Src(L::min()), Src(L::max()))))
870
+ // Src and Dst have different signedness.
871
+ // Check if it's signed -> unsigend cast.
872
+ : std::is_signed<Src>::value && std::is_unsigned<Dst>::value
873
+ ? (
874
+ // If src < 0, the result should be 0.
875
+ src < 0 ? Dst(0) :
876
+ // Otherwise, src >= 0. If src can fit into Dst, we can safely cast it
877
+ // without loss of accuracy.
878
+ sizeof(Src) <= sizeof(Dst) ? Dst(src) :
879
+ // If Src is larger in size than Dst, we need to ensure the result is
880
+ // at most Dst MAX.
881
+ Dst(constexpr_min(src, Src(L::max()))))
882
+ // It's unsigned -> signed cast.
883
+ : (
884
+ // Since Src is unsigned, and Dst is signed, Src can fit into Dst only
885
+ // when sizeof(Src) < sizeof(Dst).
886
+ sizeof(Src) < sizeof(Dst) ? Dst(src) :
887
+ // If Src does not fit into Dst, we need to ensure the result is at most
888
+ // Dst MAX.
889
+ Dst(constexpr_min(src, Src(L::max()))));
890
+ // clang-format on
891
+ }
892
+
893
+ namespace detail {
894
+ // Upper/lower bound values that could be accurately represented in both
895
+ // integral and float point types.
896
+ constexpr double kClampCastLowerBoundDoubleToInt64F = -9223372036854774784.0;
897
+ constexpr double kClampCastUpperBoundDoubleToInt64F = 9223372036854774784.0;
898
+ constexpr double kClampCastUpperBoundDoubleToUInt64F = 18446744073709549568.0;
899
+
900
+ constexpr float kClampCastLowerBoundFloatToInt32F = -2147483520.0f;
901
+ constexpr float kClampCastUpperBoundFloatToInt32F = 2147483520.0f;
902
+ constexpr float kClampCastUpperBoundFloatToUInt32F = 4294967040.0f;
903
+
904
+ // This works the same as constexpr_clamp, but the comparison are done in Src
905
+ // to prevent any implicit promotions.
906
+ template <typename D, typename S>
907
+ constexpr D constexpr_clamp_cast_helper(S src, S sl, S su, D dl, D du) {
908
+ return src < sl ? dl : (src > su ? du : D(src));
909
+ }
910
+ } // namespace detail
911
+
912
+ template <typename Dst, typename Src>
913
+ constexpr typename std::enable_if<std::is_floating_point<Src>::value, Dst>::type
914
+ constexpr_clamp_cast(Src src) {
915
+ static_assert(
916
+ std::is_integral<Dst>::value && sizeof(Dst) <= sizeof(int64_t),
917
+ "constexpr_clamp_cast can only cast into integral type (up to 64bit)");
918
+
919
+ using L = std::numeric_limits<Dst>;
920
+ // clang-format off
921
+ return
922
+ // Special case: cast NaN into 0.
923
+ constexpr_isnan(src) ? Dst(0) :
924
+ // using `sizeof(Src) > sizeof(Dst)` as a heuristic that Dst can be
925
+ // represented in Src without loss of accuracy.
926
+ // see: https://en.wikipedia.org/wiki/Floating-point_arithmetic
927
+ sizeof(Src) > sizeof(Dst) ?
928
+ detail::constexpr_clamp_cast_helper(
929
+ src, Src(L::min()), Src(L::max()), L::min(), L::max()) :
930
+ // sizeof(Src) < sizeof(Dst) only happens when doing cast of
931
+ // 32bit float -> u/int64_t.
932
+ // Losslessly promote float into double, change into double -> u/int64_t.
933
+ sizeof(Src) < sizeof(Dst) ? (
934
+ src >= 0.0
935
+ ? constexpr_clamp_cast<Dst>(
936
+ constexpr_clamp_cast<std::uint64_t>(double(src)))
937
+ : constexpr_clamp_cast<Dst>(
938
+ constexpr_clamp_cast<std::int64_t>(double(src)))) :
939
+ // The following are for sizeof(Src) == sizeof(Dst).
940
+ std::is_same<Src, double>::value && std::is_same<Dst, int64_t>::value ?
941
+ detail::constexpr_clamp_cast_helper(
942
+ double(src),
943
+ detail::kClampCastLowerBoundDoubleToInt64F,
944
+ detail::kClampCastUpperBoundDoubleToInt64F,
945
+ L::min(),
946
+ L::max()) :
947
+ std::is_same<Src, double>::value && std::is_same<Dst, uint64_t>::value ?
948
+ detail::constexpr_clamp_cast_helper(
949
+ double(src),
950
+ 0.0,
951
+ detail::kClampCastUpperBoundDoubleToUInt64F,
952
+ L::min(),
953
+ L::max()) :
954
+ std::is_same<Src, float>::value && std::is_same<Dst, int32_t>::value ?
955
+ detail::constexpr_clamp_cast_helper(
956
+ float(src),
957
+ detail::kClampCastLowerBoundFloatToInt32F,
958
+ detail::kClampCastUpperBoundFloatToInt32F,
959
+ L::min(),
960
+ L::max()) :
961
+ detail::constexpr_clamp_cast_helper(
962
+ float(src),
963
+ 0.0f,
964
+ detail::kClampCastUpperBoundFloatToUInt32F,
965
+ L::min(),
966
+ L::max());
967
+ // clang-format on
968
+ }
969
+
970
+ } // namespace folly