Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turbo module codegen support interface with inheritance in module #36011

Closed
wants to merge 6 commits into from

Conversation

ZihanChen-MSFT
Copy link
Contributor

Summary

The previous pull request enables defining interfaces and using them in a turbo module, but all members are flattened, this is not the best option for codegen for object oriented languages.

In this pull request, an optional member baseTypes is added to aliased objects. Members are still flattened for backward compatibility, if a codegen doesn't care about that nothing needs to be changed.

Example

interface A {
  a : string;
}

interface B extends A {
  b : number;
}

Before the previous pull request

interface is not allowed here, you must use type alias.

At the previous pull request

interface is allowed, but it is translated to

type A = {a : string};
type B = {a : string, b : number};

At this pull request

Extra information is provided so that you know B extends A. By comparing B to A it is easy to know that B::a is obtained from A.

Changelog

[GENERAL] [CHANGED] - Turbo module codegen support interface with inheritance in module

Test Plan

yarn jest react-native-codegen passed

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. p: Microsoft Partner: Microsoft Partner labels Jan 31, 2023
@analysis-bot
Copy link

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 8,463,544 +134
android hermes armeabi-v7a 7,783,956 +220
android hermes x86 8,936,644 +252
android hermes x86_64 8,794,679 +328
android jsc arm64-v8a 9,648,959 +0
android jsc armeabi-v7a 8,383,226 +0
android jsc x86 9,710,923 +0
android jsc x86_64 10,187,777 +0

Base commit: 8568b93
Branch: main

@facebook-github-bot
Copy link
Contributor

@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Jan 31, 2023
@facebook-github-bot
Copy link
Contributor

@cipolleschi merged this pull request in bf34810.

@ZihanChen-MSFT ZihanChen-MSFT deleted the ts-rncodegen18 branch February 13, 2023 22:28
OlimpiaZurek pushed a commit to OlimpiaZurek/react-native that referenced this pull request May 22, 2023
…cebook#36011)

Summary:
The [previous pull request](facebook#35812) enables defining interfaces and using them in a turbo module, but all members are flattened, this is not the best option for codegen for object oriented languages.

In this pull request, an optional member `baseTypes` is added to aliased objects. Members are still flattened for backward compatibility, if a codegen doesn't care about that nothing needs to be changed.

### Example

```typescript
interface A {
  a : string;
}

interface B extends A {
  b : number;
}
```

#### Before the previous pull request

`interface` is not allowed here, you must use type alias.

#### At the previous pull request

`interface` is allowed, but it is translated to

```typescript
type A = {a : string};
type B = {a : string, b : number};
```

#### At this pull request

Extra information is provided so that you know `B` extends `A`. By comparing `B` to `A` it is easy to know that `B::a` is obtained from `A`.

## Changelog

[GENERAL] [CHANGED] - Turbo module codegen support interface with inheritance in module

Pull Request resolved: facebook#36011

Test Plan: `yarn jest react-native-codegen` passed

Reviewed By: rshest

Differential Revision: D42882650

Pulled By: cipolleschi

fbshipit-source-id: 32d502e8a99c4151fae0a1f4dfa60db9ac827963
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. p: Microsoft Partner: Microsoft Partner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants