Commit Graph

51 Commits

Author SHA1 Message Date
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
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 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
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
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 610dcf488b Implement method dispatch using TurboModuleSchema
Summary:
This is the final diff in the JS TurboModule codegen stack for Android. It implements method dispatch using the TurboModuleSchema object.

Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D22837486

fbshipit-source-id: f91b03f064941457d4b8c5e37e011468559dee71
2020-11-08 14:24:05 -08:00
Ramanpreet Nara 165dcccc58 Introduce TurboModuleSchema
Summary:
JavaTurboModule will use instances of this class to perform method invocation. TurboModuleSchema is created by parsing the `jsi::Value` that represents the TurboModule's schema.

Changelog: [Internal]

Reviewed By: PeteTheHeat

Differential Revision: D22832729

fbshipit-source-id: 792736e176c33a302f6a41c6f63a4812b09af585
2020-11-08 14:24:05 -08:00
Ramanpreet Nara cb7f3f4499 Setup TurboModule JS Codegen experiment
Summary:
## Android API
```
// Before we initialize TurboModuleManager
ReactFeatureFlags.useTurboModuleJSCodegen = true
```

## iOS API
```
// Before we initialize RCTBridge
RCTEnableTurboModuleJSCodegen(true);
```

## How is the JS Codegen actually enabled?
The above native flags are translated to the following global variable in JavaScript:
```
global.RN$JSTurboModuleCodegenEnabled = true;
```

Then, all our NativeModule specs are transpiled to contain this logic:
```
interface Foo extends TurboModule {
  // ...
}

function __getModuleSchema() {
  if (!global.RN$JSTurboModuleCodegenEnabled) {
    return undefined;
  }

  // Return the schema of this spec.
  return {...};
}

export default TurboModuleRegistry.get<Foo>('foo', __getModuleSchema());
```

Then, in our C++ JavaTurboModule, and ObjCTurboModule classes, we use the TurboModule JS codegen when the jsi::Object schema is provided from JavaScript in the TurboModuleRegistry.get call.

Changelog: [Internal]

Reviewed By: PeteTheHeat

Differential Revision: D24636307

fbshipit-source-id: 80dcd604cc1121b8a69df875bbfc87e9bb8e4814
2020-11-06 13:28:15 -08:00
Ramanpreet Nara b141dd7008 Make getTurboModule required in RCTTurboModule protocol
Summary:
This change should make all type-safe NativeModules TurboModule-compatible.

Changelog: [Internal]

Differential Revision: D24729493

fbshipit-source-id: 7712708a24d675ca567225797016a7ff66a2920e
2020-11-04 11:22:25 -08:00
Kevin Gozali 7cfc7d65f7 Codegen: Make react-native-codegen BUCK deps OSS-compatible
Summary:
Added a few FB vs OSS polyfills:
* react_native_root_target() to refer to the root FB react-native-github/ dir or repo dir in OSS
* react_native_xplat_synced_target() for anything xplat
* a few others

Changelog: [Internal]

Reviewed By: yungsters

Differential Revision: D24437245

fbshipit-source-id: ee290a87a98a8e9be67b102a96f2faac2a2cb92b
2020-10-22 17:09:29 -07:00
Ramanpreet Nara 9a7f2b590e Log QPL Events from TM + NM, when Perf. Logging is enabled
Summary:
## Previously
- When TurboModules system was on, we'd only log events from the TurboModules system.
- When TurboModules system was off, we'd only log events from the NativeModule system.

This ultimately gives us less data to analyze both systems in production.

## Changes in This Diff
When perf. logging is on, we'll log events from both systems. Each QPL event now include an annotation of which system the event is coming from. Concretely, this will allow us to see how much of the NativeModule system is being exercised in the TurboModule test group.

Changelog: [Internal]

Reviewed By: hramos

Differential Revision: D24232594

fbshipit-source-id: 7dff57bd74fc7ef744d3e06ff174304f25790456
2020-10-10 02:51:59 -07:00
Ramanpreet Nara 5535031ba4 Gate TurboModule block copy behind an MC
Summary: Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D24145506

fbshipit-source-id: 7e374c3bd2378cc1dcd9372d7cbb10ae445a2582
2020-10-06 18:40:20 -07:00
Neil Dhar dffb61dcbb Remove capture of instance_
Summary:
The captured `instance_` will result in a call to JVM code to release the reference when the lambda is destroyed. However, Hermes may destroy the lambda in a non-JVM background thread.

Since `instance_` is a member of the class, and `this` is already captured, there is no need to capture it.

Changelog: [Internal]

Reviewed By: RSNara

Differential Revision: D24141179

fbshipit-source-id: e3b268485ed229ee933281a80e5dbe2feba55719
2020-10-06 17:33:05 -07:00
Kevin Gozali 5be44456f2 TurboModule Android: compile TurboModule C++ Core into ReactAndroid
Summary:
This is to prepare for enabling TurboModule on Android. This commit compiles in all the core files (C++) into the ReactAndroid NDK build step. This doesn't yet enable TurboModule by default, just compiling in the infra, just like for iOS.

New shared libs:
* libreact_nativemodule_core.so: The TurboModule Android core
* libreact_nativemodule_manager.so: The TurboModule manager/delegate

To be compatible with `<ReactCommon/` .h include prefix, the files had to move to local `ReactCommon` subdirs.

Changelog: [Internal]

Reviewed By: sammy-SC

Differential Revision: D23805717

fbshipit-source-id: b41c392a592dd095ae003f7b2a689f4add2c37a9
2020-09-20 14:23:43 -07:00