Commit Graph

62 Commits

Author SHA1 Message Date
Joshua Gross b60e229d7f Remove compiler_flags from BUCK modules
Summary:
Nearly all of these are identical and these compiler_flags are now centralized in rn_defs.bzl. This should have NO CHANGE on build configuration, the flags have just moved for now.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D31631766

fbshipit-source-id: be40ebeb70ae52b7ded07ca08c4a29f10a0ed925
2021-10-14 15:34:29 -07:00
Ramanpreet Nara f617e022c8 Fix methodQueue attachment error message
Summary:
When we fail to assign the methodQueue to a NativeModule in the TurboModule system, we say "You must either synthesize the bridge property", when we should say "You must either synthesize the methodQueue property".

Changelog: [Internal]

Created from CodeHub with https://fburl.com/edit-in-codehub

Reviewed By: philIip

Differential Revision: D30909907

fbshipit-source-id: 07dc1060497be3fdd16bdfcf6e80cfed182bc5c7
2021-09-13 14:20:39 -07:00
Ramanpreet Nara e36bfef0f1 Conditionally disable TurboModuleManager delegate locking
Summary:
## Context
Whenever the TurboModuleManager calls into its delegate, it [acquires a lock](https://www.internalfb.com/code/fbsource/[f14548634e72009989c844a2ef025915ef74159e]/xplat/js/react-native-github/ReactCommon/react/nativemodule/core/platform/ios/RCTTurboModuleManager.mm?lines=429%2C513). We initially introduced this mutex (in D21170099 (https://github.com/facebook/react-native/commit/2c473e1a38c35957fe80b6c334a1983c034c2bbc)). It serializes access to the TurboModuleManager delegate during TurboModule create.

## Problems
- When we call into the delegate, we acquire a lock, and call into arbitrary product code: getModuleClassFromName, getModuleInstanceFromClass. If any of these two product methods create another TurboModule, the application will deadlock, because we'll acquire the same std::mutex twice.

## Fix
The delegate methods of TurboModuleManager are usually implemented as [switch cases over the NativeModule names or NativeModule classes](https://www.internalfb.com/code/fbsource/[f015e461de4e7a18d0d52a697a53086fe6a3b91c]/fbobjc/Apps/Wilde/FBReactModule2/FBReactModuleAPI/FBReactModuleAPI/Exported/FBReactModule.mm?lines=1481-1488%2C1490-1537%2C1539-1577). So, it should be safe to call into them concurrently for two different modules.

So, while we could fix the problem by migrating the TurboModuleManager to an std::recursive_mutex, one could make an argument that this locking shouldn't even be necessary in the first place. We don't have this locking in the Android TurboModule system.

## Changes
This diff introduces a flag in React Native that allows to to safely remove this TurboModuleManager delegate locking in production.

Changelog: [Internal]

Reviewed By: sammy-SC

Differential Revision: D30754875

fbshipit-source-id: d04a831c18a2a8b46e9bc07ddf690d8e4d0be8e0
2021-09-08 12:53:17 -07:00
Ramanpreet Nara 5a44c596b6 Move RCTModuleRegistry attachment into React Native initialization layer
Summary:
## Context
RCTModuleRegistry allows NativeModules to require other NativeModules, regardless of if they're using the old or the new system.

## Problems
Currently, the TurboModuleManager owns the RCTModuleRegistry. This results in the following ownership diagram:
{F660246242}

As you can see, for the bridge case, we're maintaining two *different* RCTModuleRegistry objects, both of which maintain a backward reference to the bridge and the TurboModuleManager.

## Changes
If we stop having TurboModuleManager own the RCTModuleRegistry, and just have React Native's initialization layer attach it to NativeModules, then we can simplify the above ownership diagram to this:
{F660246285}

## Benefits
- Less complicated design for RCTModuleRegistry
- RCTModuleRegistry understands the old and the new NativeModule system. So, it makes more sense for RCTModuleRegistry to be owned by the bridge, which also understands the old and the new NativeModule system.
- **Actual Motivation:** This allows us to start exporting RCTModuleRegistry from the bridgeless core, which is safer than leaking the TurboModuleManager from the bridgeless core. Diffs incoming.

Changelog: [Internal]

Reviewed By: sammy-SC

Differential Revision: D30753286

fbshipit-source-id: cf374092b7b939bc177c3c3448424f2fb53033c3
2021-09-08 12:46:35 -07:00
Neil Dhar 1bc885b8b8 Make JSI a dynamic library
Summary:
Ship libjsi as a standalone dynamic library. This prevents problems
with exception handling caused by duplicate typeinfo across multiple
shared libs, and reduces bundle size by removing duplicate copies of
JSI.

Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D30599215

fbshipit-source-id: abad1398342a5328daa825f3f684e0067cad7a96
2021-08-27 17:16:49 -07:00
Moti Zilberman b26ae3e0c9 Move RCT* Buck targets to GitHub
Summary: Changelog: [Internal]

Reviewed By: GijsWeterings

Differential Revision: D30030454

fbshipit-source-id: 02a4c36f5c5ca519e4de3d1a3d79708d0d0b6d01
2021-08-04 13:03:21 -07:00
Ramanpreet Nara 034c6dfe34 Stop sharing LongLivedObjectCollection with the bridge
Summary:
This is the Android analogue to D30019833.

Changelog: [Internal]

Reviewed By: p-sun

Differential Revision: D30029295

fbshipit-source-id: 13df0dfb915697eeedcc527dcdb6c246e89afb0c
2021-08-02 11:22:22 -07:00
Ramanpreet Nara 32bfd7a857 Stop sharing LongLivedObjectCollection with the bridge
Summary:
## Context
Previously, when you'd call TurboModule methods with JavaScript callbacks, we'd [store the callbacks](https://www.internalfb.com/code/fbsource/[c503ff1b38621aebca87b2bbebeae088b01886c4]/xplat/js/react-native-github/ReactCommon/react/nativemodule/core/platform/ios/RCTTurboModule.mm?lines=173%2C248-249) into [this global LongLivedObjectCollection collection](https://www.internalfb.com/code/fbsource/[c503ff1b38621aebca87b2bbebeae088b01886c4]/xplat/js/react-native-github/ReactCommon/react/nativemodule/core/ReactCommon/TurboModuleUtils.h?lines=65). Then, when React Native's JavaScript VM got torn down, we'd [clear the global collection](https://www.internalfb.com/code/fbsource/[e26f476ce208c578f05b1edb7639d1dad5612c7d]/xplat/js/react-native-github/ReactCommon/react/nativemodule/core/ReactCommon/TurboModuleBinding.cpp?lines=49), which would ensure that we deleted all held jsi::Functions, before deleting the jsi::Runtime.

## Problem
With bridgeless mode enabled, there can be two TurboModule systems. Further, it is possible to tear down bridgeless mode, or the bridge, without tearing down the other initialization infra. In this scenario, the jsi::Function for the other initialization infra would also get deleted, which could lead to mysterious problems.

## Fix
In this diff, I refactored the jsi::Function cleanup in the TurboModule system. Now, there are 3 modes:
- kGlobalScope: Everything works as it did before
- kRCTGlobalScopeUsingRetainJSCallback: We still use the global LongLivedObjectCollection, but we do it through invoking a block passed to every ObjCTurboModule by the TurboModuleManager. This group exists to assess the impact of having each TurboModule retain/use the block. I suspect this will be negligible, but it'd be good to have actual data to back this claim.
- kRCTTurboModuleManagerScope: Every TurboModule uses a LongLivedObjectCollection that is owned by its TurboModuleManager. This should effectively fix the problem I outlined above.

Changelog: [Internal]

Reviewed By: p-sun

Differential Revision: D30019833

fbshipit-source-id: da50d884c7e37190107f570d8ed70eeda7d9ae83
2021-08-02 11:22:22 -07:00
Ramanpreet Nara 1e4dd5e877 Clean up RAIICallbackManager experiment
Summary:
This experiment was shipped in D27436402 (https://github.com/facebook/react-native/commit/3d1afbbda301d48a75e45f73b96cd51ae5105dd8).

Changelog: [Internal]

Reviewed By: JoshuaGross

Differential Revision: D30023039

fbshipit-source-id: 5f7335f2ddaf6f4e2d876a917aaff2cf3d906b5c
2021-08-02 11:22:22 -07:00
Samuel Susla d472efbd72 Remove feature flag for promises block guard
Summary:
Changelog: [internal]

Promises block guard is shipped. Let's remove gating.

Reviewed By: RSNara

Differential Revision: D29262010

fbshipit-source-id: c15e033573b11f0a3470b1ddfbef07b6f03ba069
2021-06-24 03:33:05 -07:00
Ramanpreet Nara a657c2655f Call RCTInitializing initialize on TurboModules
Summary:
After D28435078, TurboModules can conform to the RCTInitializing protocol, and implement the `-(void)initialize` method. This diff makes the TurboModule system execute the module's initialize method after the infra is done setting it up.

Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D28435429

fbshipit-source-id: fe945d616b97ed89f48b914b064e518b122a7b7b
2021-05-20 19:19:57 -07:00
Ramanpreet Nara 478365079b Attach RCTCallableJSModules to NativeModules
Summary:
This diff has the bridge attach RCTCallableJSModules to our NativeModules.

Changelog: [Internal]

Differential Revision: D28395447

fbshipit-source-id: 01ca62442013826d28ba0f710e28a5963f5efb65
2021-05-14 09:22:58 -07:00
Samuel Susla e4b6392ee7 Remove gating for block guard
Summary: Changelog: Remove gating around leak fix in TurboModules infra

Reviewed By: RSNara

Differential Revision: D28253054

fbshipit-source-id: 9b3c236d3752b5ca042f83127e42e69250ccd112
2021-05-06 20:00:15 -07:00
Samuel Susla 10a9a4ed89 Enable block guard for promises
Summary:
Changelog: Resolve memory leak in promises on iOS

Enable block guard for promises

Reviewed By: RSNara

Differential Revision: D28252977

fbshipit-source-id: 052fefca0a6ac54597a46922fc467a2a39f7976f
2021-05-06 20:00:15 -07:00
Ramanpreet Nara 329f58ee46 Attach RCTBundleManager to NativeModules
Summary:
After this diff, every NativeModule that has `synthesize bundleManager = _bundleManager`, will get access to an RCTBundleManager, that it can use to read from/write to the bridge's bundle URL.

Changelog: [iOS][Added] - Attach RCTBundleManager to NativeModules

Reviewed By: PeteTheHeat

Differential Revision: D28086319

fbshipit-source-id: 6e4cd815d300e9036957ec8c743e947d2cb3f365
2021-05-04 18:33:23 -07:00
Ramanpreet Nara e5080e6171 Pull RCTViewRegistry attachment out of TurboModuleManager
Summary:
## Rationale
The TurboModuleManager should only be concerned with modules. The bridge and RCTInstance integrate the TurboModuleManager with the rest of React Native. Therefore, abstractions used by TurboModules that reach into the rest of React Native should be attached by the bridge or by RCTInstance.

## Changes
In this diff, we pull RCTViewRegistry attachment out of the TurboModuleManager. In bridge mode, it'll be attached to TurboModule by the bridge. In bridgeless mode, it'll be attached to TurboModules by the RCTInstance.

Changelog: [Internal]

Reviewed By: PeteTheHeat

Differential Revision: D28086320

fbshipit-source-id: 9d99835bdbb66bb6a41fbd0d8a3970cefae16b81
2021-04-30 16:40:16 -07:00
Ramanpreet Nara 7e05480cc3 Delete @synthesize turboModuleRegistry API in RCTTurboModule
Summary:
All NativeModules/TurboModules can use the following Venice-compatible API instead:
```
synthesize moduleRegistry = _moduleRegistry
```

In bridge mode, it'll look up the module via the TurboModule system/bridge.
In bridgeless mode, it'll look up the module via the TurboModule system.

Therefore, there's no need to support this API.

Changelog: [iOS][Removed] - Delete synthesize turboModuleRegistry API in RCTTurboModule

Reviewed By: fkgozali

Differential Revision: D28070740

fbshipit-source-id: d2c8285fd4c05b67fb03ce82217bf6ddfd1dd685
2021-04-28 16:49:05 -07:00
Ramanpreet Nara da150343f7 TM Create: log error when method queue is nil
Summary:
When TurboModuleManager creates TurboModules, it creates and assigns a method queue to the module using ObjC's Associated Object API:

https://www.internalfb.com/code/fbsource/[c91dc16f4b63]/xplat/js/react-native-github/ReactCommon/react/nativemodule/core/platform/ios/RCTTurboModuleManager.mm?lines=636

Down the line, we retrieve this method queue, and use it to create a native CallInvoker:

https://www.internalfb.com/code/fbsource/[c91dc16f4b63abd05c7c9a038e88ca692a453c69]/xplat/js/react-native-github/ReactCommon/react/nativemodule/core/platform/ios/RCTTurboModuleManager.mm?lines=279-284

We should assert that this method queue isn't nil.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D27956219

fbshipit-source-id: 2554cf2bffc732bb895e6dc082338a38b05f6580
2021-04-23 15:59:24 -07:00
Ramanpreet Nara 497eb578ab Fix invalidation for modules with infra-generated method queues
Summary:
When invalidating TurboModules, the TurboModule infra looks for a methodQueue method on the TurboModule (line 871 below). If it finds one, the TurboModuleManager dispatches module invalidate on that method queue:

https://www.internalfb.com/code/fbsource/[c91dc16f4b63abd05c7c9a038e88ca692a453c69]/xplat/js/react-native-github/ReactCommon/react/nativemodule/core/platform/ios/RCTTurboModuleManager.mm?lines=847-848%2C870-883

## The Problem

TurboModules that neither provide a method queue, nor request a method queue won't respond to selector(methodQueue). For those modules, the TurboModule system won't dispatch invalidate to their method queue

## The Fix
Calling selector(methodQueue) is an unreliable way of getting the module's method queue. The TurboModuleManager attaches a method queue to every TurboModule as an associated object:

https://www.internalfb.com/code/fbsource/[c91dc16f4b63]/xplat/js/react-native-github/ReactCommon/react/nativemodule/core/platform/ios/RCTTurboModuleManager.mm?lines=636

In this diff, in the TurboModule invalidate method, we retrieve the method queue using ObjC's associated object API. This guarantees that all TurboModules will be invalidated on their method queues.

Changelog: [iOS][Fixed] - Invalidate TurboModules with infra-generated method queues on their method queues

Reviewed By: appden

Differential Revision: D27954644

fbshipit-source-id: af4408e444d03a15d8d8e154b3980511b81d5fb1
2021-04-23 15:59:24 -07:00
Ramanpreet Nara f34a2899e4 Invalidate TurboModules on their method queues
Summary:
## Rationale
With the bridge, the invalidate method of every TurboModule gets called on the TurboModule's method queue. This ensures that we can safely clean up resources accessed in the TurboModule's async methods. In bridgeless mode, we don't invalidate each module on its method queue. After this diff, we will clean up every TurboModule on its own method queue.

## Changes
- Make RCTInstance dealloc itself on the JavaScript thread.
- Terminate the JavaScript thread on the JavaScript thread. This ensures that no work executes on the JavaScript thread after we clean up RCTInstance.
- Make [RCTTurboModuleManager invalidate] execute right before RCTInstance terminates the JavaScript thread.
- **Fix:** Make [RCTTurboModuleManger invalidate] synchronously invalidate modules on their own method queues.

Changelog: [Internal]

Reviewed By: PeteTheHeat

Differential Revision: D27933587

fbshipit-source-id: 7630e7fc074df2f5a3293192431105c747b8588f
2021-04-23 15:59:24 -07:00
Ramanpreet Nara c4c34a1237 Delete RCTTurboModuleManagerDelegate getTurboModule:initParams
Summary:
D27316129 made it mandatory for all RCTTurboModules to have a getTurboModule: method. So, there's no need to keep the getTurboModule:initParams method in RCTTurboModuleManagerDelegate. So, to simplify the TurboModule infra, this diff gets rid of that TurboModuleManager delegate method.

Changelog: [iOS][Removed] - Delete RCTTurboModuleManagerDelegate getTurboModule:initParams

Reviewed By: fkgozali

Differential Revision: D27316873

fbshipit-source-id: c0b8449c6088bf08f17ba9a8d1c2cb644e5a242d
2021-04-08 21:15:53 -07:00
Ramanpreet Nara e0b8f5080f Make RCTTurboModule getTurboModule: required
Summary:
## Rationale
There are two ways to associate NativeModule ObjC objects with ObjCTurboModule jsi::HostObjects:
1. Via the NativeModule ObjC class's `getTurboModule:` method.
2. Via the TurboModule manager delegate's getTurboModule:initParams: method.

There's no good reason to support both options. So, this diff stack removes 2, and make 1 mandatory for all RCTTurboModules. Not only will this simplify the infra, but it should also help eliminate a class of runtime errors in the TurboModule standalone app migration: you forget to implement the getTurboModule: method.

Changelog: [iOS][Changed] - Make RCTTurboModule getTurboModule: required

Reviewed By: PeteTheHeat

Differential Revision: D27316129

fbshipit-source-id: baccd155b8c191d0f961b316db552bdfdbeb0a97
2021-04-08 21:15:53 -07:00
Ramanpreet Nara 3f38186b78 Codemod: Give legacy cxx and ObjC-only NativeModules a getTurboModule: method
Summary:
We're making the getTurboModule: method required for all classes that conform to RCTTurboModule.

Many of our ObjC-only and Cxx NativeModules don't implement this method. This diff implements a getTurboModule: method on all those modules that returns nullptr.

**Question:** Why is it fine to make ObjC-only NativeModules return nullptr from their getTurboModule: method?
- Because they're only accessed from ObjC, and should appear as null on the JavaScript side. Longer term, these NativeModules will also go away.

**Question:** Why is it fine to make Cxx NativeModules return nullptr from getTurboModule: method?
- Because after D27316872, the TurboModuleManager checks if the module is a CxxModule first. If it is, we do an early return, and never call the module's getTurboModule: method.

Changelog: [Internal]

Reviewed By: JoshuaGross

Differential Revision: D27316871

fbshipit-source-id: bc693f2927ab3b0de24e6e9e7699390ec0f7d729
2021-04-08 21:15:52 -07:00
Ramanpreet Nara 6a5e98a84c Stop calling getTurboModule:initParams in RCTTurboModuleManager
Summary:
We're going to make RCTTurboModule getTurboModule: required in D27316129. So, RCTTurboModuleManagerDelegate getTurboModule:initParams is no longer necessary.

## Changes
1. Makes TurboModuleManager stop calling RCTTurboModuleManagerDelegate getTurboModule:initParams
2. Makes getTurboModule: have the lowest priority. So, Cxx NativeModules with a getTurboModule: method won't have their getTurboModule: method executed.

Changelog: [Internal]

Reviewed By: PeteTheHeat

Differential Revision: D27316872

fbshipit-source-id: a024e55b8e3692d7117420007dd3947ecfd5019c
2021-04-08 21:15:52 -07:00
Joshua Gross 3d1afbbda3 destroy callbacks even if they aren't called, when java object is destroyed
Summary:
JSI callbacks are only destroyed if the callback is called. If the callback is never called, we're potentially leaking a lot of callbacks.

To mitigate this, we add a wrapper object that is owned by the std::function. Whenever the std::function is destroyed, the wrapper is destroyed and it deallocates the callback as well.

Changelog: [Internal]

Reviewed By: RSNara

Differential Revision: D27436402

fbshipit-source-id: d153640d5d7988c7fadaf2cb332ec00dadd0689a
2021-04-01 16:28:26 -07:00
Samuel Susla 9ef995a14a Enable C++ 17 in React Native
Summary:
Changelog: [Internal] enable support for C++ 17.

C++ 17 in React Native targets.

Short and comprehensive list of C++ features:
https://github.com/AnthonyCalandra/modern-cpp-features#c17-language-features

Reviewed By: JoshuaGross

Differential Revision: D27431145

fbshipit-source-id: e8da6fe9d70e9b7343a8caec21cdbeb043478575
2021-04-01 04:50:59 -07:00
Andrew Coates 81c895fb3f Fix various C++ warnings (#31002)
Summary:
Fix warnings about implicit type truncation.

## Changelog

[Internal] [Fixed] - Fix various C++ warnings

Pull Request resolved: https://github.com/facebook/react-native/pull/31002

Test Plan:
Almost all the changes here are simply making explicit conversions which are already occurring.  With the exception of a couple of constants being changed from doubles to floats.

With these changes I am able to remove a bunch of warning suppressions in react-native-windows.

Reviewed By: shergin

Differential Revision: D26900502

Pulled By: rozele

fbshipit-source-id: d5e415282815c2212a840a863713287bbf118c10
2021-03-10 12:39:12 -08:00
Samuel Susla f7d006e60c Fix memory leak convertJSIFunctionToCallback
Summary:
changelog: [internal]

### When does leak happen?
Leak happens anytime a callback isn't executed inside native module, it will never get cleaned up.
Imagine a native module with method that takes onSuccess and onFail callbacks. Only one of them will be called at any time and the other one will leak.

### Why does it leak?
It leaks because when `CallbackWrapper` is created using `CallbackWrapper::createWeak`. Inside `CallbackWrapper::createWeak`, the newly created object is inserted into `LongLivedObjectCollection`. This object collection will keep it alive until `CallbackWrapper::destroy` is called, which isn't called in case closure isn't executed.

### Solution
Introduce class RCTBlockGuard which ties cleanup of resources to lifetime of the block.

Reviewed By: RSNara

Differential Revision: D26664173

fbshipit-source-id: 9348f7c39eb317cf1e8e5d59e77a378e5e04f3eb
2021-02-27 04:55:52 -08:00
Joshua Gross ee98e6a493 ReactCommon/nativemodule: Migrate uses of NDEBUG to REACT_NATIVE_DEBUG + react_native_assert
Summary:
For better cross-platform consistency, migrate usages of NDEBUG to REACT_NATIVE_DEBUG. See flags.h for explanation.

Changelog: [Internal]

Reviewed By: PeteTheHeat

Differential Revision: D26695016

fbshipit-source-id: 63e6f6fc919076d94f04416f6821f21e0b3707a3
2021-02-26 21:20:25 -08:00
Ramanpreet Nara ab21226457 Migrate away from "@fbsource//tools/build_defs/apple:flag_defs.bzl"
Summary:
We still have usages of "fbsource//tools/build_defs/apple:flag_defs.bzl" in react-native-github. But this should get us closer towards not using the fbsource cell. Hopefully, this is enough to unbreak the  test_docker CircleCI build.

Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D26289304

fbshipit-source-id: 1c6464bb84df4f82f8a797321a73a1ed324e319a
2021-02-08 16:04:51 -08:00
David Vacca 1e6d2e983a Remove strong reference from TM infra
Summary:
This diff refactor strong references on TM infra to use weak references and avoid leaking objects

changelog: [internal] internal

Reviewed By: RSNara

Differential Revision: D26229814

fbshipit-source-id: d4a327dba227378d23764433d5917eb4378a4453
2021-02-03 12:56:17 -08:00
Ramanpreet Nara 8fe25fcd5b Remove TurboModuleSchema and clean up JavaTurboModule
Summary:
This concludes the TurboModule JS codegen cleanup.

Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D25915167

fbshipit-source-id: 901468fd559a7b3d75b929e9ff1167544e71a2d5
2021-01-14 19:14:23 -08:00
Ramanpreet Nara a156ee9b73 Delete JS TurboModule Codegen Gating
Summary: Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D25915171

fbshipit-source-id: b59e21f834a7172055e180eddb9bf15737a6cf0f
2021-01-14 19:14:23 -08:00
Ramanpreet Nara 8ed6659907 Stop forwarding TurboModule schema to TurboModule HostObjects
Summary: Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D25915170

fbshipit-source-id: 2b390428c1f582e55cf3ffe8e691f069bf2fd295
2021-01-14 19:14:23 -08:00
Vladimir Morozov 8aea93022b Remove dependency on Folly in TurboModuleUtils.h (#30672)
Summary:
The TurboModuleUtils.h includes "folly/Optional.h" which is not used and creates an unnecessary dependency on Folly.
In this PR we remove this unnecessary include.

It is required for the https://github.com/microsoft/react-native-windows/pull/6804 where we add an experimental support for the C++ TurboModules. While the C++ TurboModules use the same JSI and TurboModule code defined in react-native, we provide a layer that let them to work over the ABI-safe Microsoft.ReactNative.dll boundary. The RNW Nuget distribution with DLL files includes a few source files to create native/turbo modules that work through the ABI-safe API. The TurboModuleUtils.h is one of such files. By removing the dependency on Folly we reduce requirements for the native module code. After this PR is merged we will remove the fork of the TurboModuleUtils.h  added in https://github.com/microsoft/react-native-windows/pull/6804.

## Changelog

[Internal] [Fixed] - Remove dependency on Folly in TurboModuleUtils.h

Pull Request resolved: https://github.com/facebook/react-native/pull/30672

Test Plan:
The change does not bring any functional changes. It may only affect code compilation where some code may depend on TurboModuleUtils.h when it needs the "folly/Optional.h". The fix is add the `#include <folly/Optional.h>` there explicitly.

I had run the iOS tests and they passed:
```
yarn
pod install in packages\rn-tester
./scripts/objc-test.sh test
```

Reviewed By: mdvacca

Differential Revision: D25758927

Pulled By: fkgozali

fbshipit-source-id: 347d8f6bc333a3df67095ea0dc7221c818432fab
2021-01-04 12:04:58 -08:00
Rubén Norte e088a4fe9c Add support for UnsafeObject to allow using Flow strict in native modules
Summary:
This new type will be valid in Flow strict mode and can be used by native modules and components to replace `Object`, with the same semantics.

This unblocks the migration of the most modules in the React Native package to Flow strict.

Changelog: [Internal] Add UnsafeObject type compatible with Flow strict mode to use in native modules and components

Reviewed By: RSNara

Differential Revision: D25540631

fbshipit-source-id: 60b80bbc84a53aecc747e3a1799cdf551e1859cd
2021-01-04 03:56:57 -08:00
Ramanpreet Nara 1a2d1dbae8 Attach RCTViewRegistry to NativeModules
Summary:
After this diff, NativeModules can synthesize the RCTModuleRegistry, and use that to query for UIViews of components, given their reactTags.

Changelog: [Internal]

Reviewed By: shergin

Differential Revision: D25645052

fbshipit-source-id: bb17606cc4862d07b739ef2c31a5e57f59201364
2020-12-19 06:01:48 -08:00
Ramanpreet Nara 86cdd88569 Integrate TurboModules with Venice's RCTSurfacePresenter
Summary:
After we create the RCTSurfacePresenter in Venice, we use it to create an RCTBridgelessComponentViewProvider, and pass it over to the RCTTurboModuleManager. In Venice, this allows all TurboModules to query components' UIViews given their reactTag.

Changelog: [Internal]

Reviewed By: shergin

Differential Revision: D25643261

fbshipit-source-id: 31da07c490d249534f700b7c8430e9cb43b5b0db
2020-12-19 06:01:48 -08:00
Ramanpreet Nara b71ebd10e5 Attach RCTViewRegistry to TurboModules
Summary:
Now, TurboModules that synthesize RCTModuleRegistry will have it available at runtime.

Changelog: [Internal]

Reviewed By: shergin

Differential Revision: D25643260

fbshipit-source-id: e9915f3da8412de823ae3d3e17849979c5cbd465
2020-12-19 06:01:47 -08:00
Ron Edelstein 8b4e2ac8e5 Explicitly set autoglob (long tail)
Reviewed By: fbanurag, strulovich

Differential Revision: D25620908

fbshipit-source-id: 1dd737d451ddfd07baa427902bdf1c96d7e67e64
2020-12-17 19:35:29 -08:00
Ramanpreet Nara 5275895af5 Roll out TurboModule block copy
Summary:
## Description
During TurboModule method invocation, when we convert JavaScript callbacks (i.e: jsi::Functions) into ObjC blocks inside the TurboModule jsi::HostObject, we [push them into an array](https://fburl.com/diffusion/r1n75ikx) that [gets cleared after the method gets invoked](https://fburl.com/diffusion/ubbvdmfs).

Prior to this experiment, we pushed these ObjC blocks into the array without copying them first. This goes contrary to ObjC best practices, which suggest that if you need to retain a block past its creation context for later invocation, you should defensively copy it to prevent it from being freed early. See the [Apple docs](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Blocks/Articles/bxUsing.html#//apple_ref/doc/uid/TP40007502-CH5-SW1):
> Typically, you shouldn’t need to copy (or retain) a block. You only need to make a copy when you expect the block to be used after destruction of the scope within which it was declared. Copying moves a block to the heap.

The diff that introduced the fix: D23764329 (https://github.com/facebook/react-native/commit/9b76e217bb16935069f0ea5b60f4c4d9b73f86d6).

Reviewed By: PeteTheHeat

Differential Revision: D25617672

fbshipit-source-id: 24863b31a2d82c8d39a91c8ea8eb3a62724b800a
2020-12-17 17:27:09 -08:00
Ramanpreet Nara 5c4f145e33 Roll out TurboModule Promise Async Dispatch
Summary:
## Context
The legacy NativeModule infra implements promise methods using [async NativeModule method calls](https://fburl.com/diffusion/tpkff6vg). In the TurboModule infra, promise methods [treat as sync methods](https://fburl.com/diffusion/yde7xw71), and executed directly on the JavaScript thread. This experiment makes TurboModule promise methods async, and dispatches them to the NativeModules thread, when they're executed from JavaScript.

Reviewed By: fkgozali

Differential Revision: D25623192

fbshipit-source-id: 2b50d771c5272af3b6edf150054bb3e80cab0040
2020-12-17 17:27:09 -08:00
Ramanpreet Nara 18ea422e91 Show RedBoxes during promise resolve/reject errors
Summary:
Previously, we'd throw std::runtime_error objects when we invoked RCTPromiseResolveBlock and RCTPromiseRejectBlock. This would crash the app. Now, we'll just show RedBoxes. The RedBoxes also contain the name of the NativeModule, along with the method.

Changelog: [Internal]

Reviewed By: PeteTheHeat

Differential Revision: D25549149

fbshipit-source-id: 33d5fc4480a577a1c17961c856ac42a9363b35f6
2020-12-17 10:29:41 -08:00
Ramanpreet Nara 0da02ab1ca Don't lookup TurboModules post-invalidation
Summary:
During cleanup, RCTNativeAnimatedModule [requires the RCTEventDispatcher](https://fburl.com/diffusion/0bnln893) to remove itself from the dispatcher a dispatch observer.

When the bridge is invalidated, if RCTEventDispatcher is has been cleaned up by then, we don't warn when this lookup fails: https://fburl.com/diffusion/rfioe5ay. This diff replicates that behaviour in the TurboModule infra.

Notes:
- In the legacy NativeModule infra, we can still query NativeModules post invalidation - we just won't create them. In the TurboModule infra, all requests for TurboModules from the TurboModuleManager start returning nil. Therefore, I simply did an early return inside TurboModuleManager moduleForName in the case that we're already invalidated. In addition to not displaying the warning, we just don't request/create the TurboModule in the first place.

Changelog: [Internal]

Reviewed By: PeteTheHeat

Differential Revision: D25560228

fbshipit-source-id: 102dcc147bab6121daacdb39890bad48c0e60894
2020-12-15 11:20:28 -08:00
Peter Argany 687ddf0f32 Downgrade TurboModule crash to warning
Summary:
This is to address a UBN blocking FBiOSv300 rollout. A TM is attempting to invoke a promise more than once and crashing. We can't find the TM, so downgrading this to a warning to unblock the release.

Plan going forward:
- Replace this with some better logging to try and identify the culprit module.

Changelog: [Internal]

Reviewed By: RSNara

Differential Revision: D25539676

fbshipit-source-id: 5b75b71110eaa393378049de6e0d9a77e6328831
2020-12-14 12:58:29 -08:00
Peter Argany 2a175b14e6 Strip RCT prefix in TurbooduleManager
Summary:
This is a followup to the issue described in D25477044, basically the TM cache can get messed up if `TurboModuleManager` is asked for "RCTNetworking" vs "Networking". This solves that issue globally.

Changelog: [Internal]

Reviewed By: RSNara

Differential Revision: D25480624

fbshipit-source-id: 2024560eadbcf58cdc3d7d5675b4120aa2fa2582
2020-12-11 11:24:27 -08:00
Aditya Kumar e1d7dd3105 sed OBJC_ARC_PREPROCESSOR_FLAGS/get_preprocessor_flags_for_build_mode
Summary: This diff doesn't change any functionality.

Reviewed By: adamjernst

Differential Revision: D25466557

fbshipit-source-id: 813f9631b92e8145b932955cad64a0c4582281e8
2020-12-11 10:18:33 -08:00
Ramanpreet Nara 4974e293c6 Attach RCTModuleRegistry to NativeModules
Summary:
The bridge now creates the RCTModuleRegistry, and assigns it to all NativeModules it creates.

Changelog: [Internal]

Reviewed By: PeteTheHeat

Differential Revision: D25414108

fbshipit-source-id: 81c6a05bde0e52cff8ed60297f27d8aa3ff15a87
2020-12-10 20:23:16 -08:00
Ramanpreet Nara 5b0957962a Attach RCTModuleRegistry to TurboModules
Summary: Changelog: [Internal]

Reviewed By: PeteTheHeat

Differential Revision: D25414882

fbshipit-source-id: 9e45ffb86cf69a2d1921b7ff1c713c186a8c4e01
2020-12-10 20:23:16 -08:00
Ramanpreet Nara 408bcdeedb Remove unneeded @synthesize bridge from NativeModules
Summary:
This is a codemod. All these NativeModules demand access to the bridge. However, they don't use it.

Changelog: [Internal]

Reviewed By: PeteTheHeat, RoelCastano

Differential Revision: D25386708

fbshipit-source-id: f05f4777d2527e96e53581e7ac58f6be47411dce
2020-12-08 20:27:44 -08:00