Skip to content

Improve reflection support #2085

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

Closed
alfonsogarciacaro opened this issue Jun 12, 2020 · 4 comments
Closed

Improve reflection support #2085

alfonsogarciacaro opened this issue Jun 12, 2020 · 4 comments
Labels

Comments

@alfonsogarciacaro
Copy link
Member

alfonsogarciacaro commented Jun 12, 2020

It'd be great to improve reflection support for Fable 3. We can do it by bringing the reflection changes in #1839, but if possible I'd like to have these changes:

  • Have a separate PR for reflection and quotation support.
  • Keep the current style in Reflection.ts. That is, use module functions instead of class methods so it works better with tree shaking.
  • Instead of adding attribute and member information to all types. We could have the following functions in the Fable.Core.Reflection module:
generateConstructors<'T>()
generateProperties<'T>()
generateProperty<'T>(name)
generateMethods<'T>()
generateMethod<'T>(name)
generateCustomAttributes<'T>()

The Replacements module would replace calls to these methods with the necessary info inline, so we only generate the code where is needed.

What do you think @krauthaufen? Do the changes look good? Would you like to help with this? (If you want to sart working, please note we'll be using the next branch for Fable 3 development).

@lfr
Copy link

lfr commented Dec 16, 2020

Did this make it to Fable 3 in the end?

@alfonsogarciacaro
Copy link
Member Author

No unfortunately it didn't. I realized that my original idea of having something like generateMethods<'T>() wouldn't work for many use cases, like quotations, so I'm still unsure how to balance improving reflection support while keeping JS bundle sizes small.

@lfr
Copy link

lfr commented Dec 18, 2020

As suggested by @fable-compiler on twitter, I was able to find work arounds using a mix of dynamic code and inline functions. While the dynamic code is more brittle, it's quite contained and can be made somewhat safe with tests.

I find the inline workaround more problematic as it renders the generated JS unreadable, which is a shame as the JS generated by Fable seems otherwise surprisingly readable.

@alfonsogarciacaro
Copy link
Member Author

Closing as this didn't make it into Fable 3 at the end. There are a few other issues still open about increasing reflection support in specific situations. We can try to deal with them in a case-by-case basis.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants