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 like alias in module #35812

Closed
wants to merge 6 commits into from

Conversation

ZihanChen-MSFT
Copy link
Contributor

Summary

Turbo module codegen support interface like alias in module.

In typescript, interface allows inheritance, but the codegen schema doesn't have such information. In this PR the codegen schema is not changed, interfaces are flattened.

In the next change, I will update the codegen schema so that it allows inheritance, in order to generate more precise C++ code.

Changelog

[GENERAL] [CHANGED] - Turbo module codegen support interface like alias 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 11, 2023
@analysis-bot
Copy link

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 8,493,485 +0
android hermes armeabi-v7a 7,813,452 +0
android hermes x86 8,967,867 +0
android hermes x86_64 8,827,371 +0
android jsc arm64-v8a 9,679,111 +0
android jsc armeabi-v7a 8,412,818 +0
android jsc x86 9,742,216 +0
android jsc x86_64 10,220,841 +0

Base commit: ac54a5b
Branch: main

Copy link
Contributor

@cipolleschi cipolleschi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good. Just to double-check: do we need something similar with Components also?

I'm thinking about a component with some props like:

interface BaseProps {
  sharedProp: number
}

interface iOSProps extends BaseProps {
  iOSProp: number
}

interface AndroidProps extends BaseProps {
  androidProp: number
}

If we need it, it is fine to add it in a new PR, though.

@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 12, 2023
@facebook-github-bot
Copy link
Contributor

@cipolleschi merged this pull request in 8befb74.

@ZihanChen-MSFT
Copy link
Contributor Author

ZihanChen-MSFT commented Jan 12, 2023

@cipolleschi Hi, component doesn't support alias, all interfaces or aliases got inlined into the component. And I remember I've already made interface features available for component before as data types, as a component itself is not tested though.

@migueldaipre
Copy link
Collaborator

Hey Guys, it's released?

@cortinico
Copy link
Contributor

Hey Guys, it's released?

@migueldaipre Nope this will land in 0.72

facebook-github-bot pushed a commit that referenced this pull request Jan 31, 2023
…6011)

Summary:
The [previous pull request](#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: #36011

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

Reviewed By: rshest

Differential Revision: D42882650

Pulled By: cipolleschi

fbshipit-source-id: 32d502e8a99c4151fae0a1f4dfa60db9ac827963
@ZihanChen-MSFT ZihanChen-MSFT deleted the ts-rncodegen17 branch February 13, 2023 22:29
OlimpiaZurek pushed a commit to OlimpiaZurek/react-native that referenced this pull request May 22, 2023
…#35812)

Summary:
Turbo module codegen support interface like alias in module.

In typescript, interface allows inheritance, but the codegen schema doesn't have such information. In this PR the codegen schema is not changed, interfaces are flattened.

In the next change, I will update the codegen schema so that it allows inheritance, in order to generate more precise C++ code.

## Changelog

[GENERAL] [CHANGED] - Turbo module codegen support interface like alias in module

Pull Request resolved: facebook#35812

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

Reviewed By: cortinico

Differential Revision: D42475368

Pulled By: cipolleschi

fbshipit-source-id: 26025f8a55b600dfea27026c998cd8b5fe752af4
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.

6 participants