8000 feature: Refit should be linker-friendly and support trimming · Issue #1389 · reactiveui/refit · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
feature: Refit should be linker-friendly and support trimming #1389
Open
@Sergio0694

Description

@Sergio0694

Is your feature request related to a problem? Please describe.

Yes. The issue is that despite Refit uses source generators, the generated code is just a thin proxy back to the reflection-powered functionality in the main library. This means that using Refit with trimming enabled completely breaks it. As it is, there's not much value in having source generators. They should be updated so that all the reflection-powered logic is executed at compile time, and the generated stubs will just have all the logic that is today done at runtime by the method builder APIs. This library should effectively require no runtime reflection at all (or, virtually none, but especially none that can break trimming).

Describe the solution you'd like

As mentioned, the source generator should be updated so that instead of just calling back into the method builder and invoking that reflection-based callback to perform the request, it'd instead emit all the same logic that's today done at runtime. That is, all the various marshalling of parameters, request building etc. should just be done in a statically-analyzeable way and generated at compile time. The library should just expose helper APIs for the generator to use to construct the individual bits of a request/response.

All the information that the method builder is using at runtime is there at compile time too anyway. That logic should just essentially be inverted, and the generator APIs should be used to achieve static reflection, instead of runtime reflection like today.

If there's any reflection left, additionally, all those APIs should be properly annotated.

Refit as a whole should have the trimming analyzers enabled when on the .NET 6+ target.

Describe alternatives you've considered

Runtime directives can be used to patch the problem. This is extremely cumbersome, hard to do especially for beginners, and causes an unnecessary binary size increased, given you'd be forced to preserve way more stuff than strictly needed, to be safe.

Describe suggestions on how to achieve the feature

  • Investigate all the individual bits that method builder uses to construct the request.
  • Expose the necessary helper APIs for them from that type.
  • Update the generator to do all that introspection at compile time.
  • Update the generator to perform the needed calls to those helpers to construct and execute the request right there.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0