Skip to content

Improve reflection support #2085

Closed
Closed

Description

@alfonsogarciacaro

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).

Activity

  1. lfr commented on Dec 16, 2020

    @lfr

    Did this make it to Fable 3 in the end?

  2. alfonsogarciacaro commented on Dec 18, 2020

    @alfonsogarciacaro
    MemberAuthor

    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.

  3. lfr commented on Dec 18, 2020

    @lfr

    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.

  4. alfonsogarciacaro commented on Jul 12, 2021

    @alfonsogarciacaro
    MemberAuthor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions