Running scoped/parts of DCE analysis only?
zth opened this issue · 3 comments
Hi!
I'm wondering if there's a way to run DCE on only a part of the code base's types. Let me explain my use case:
I'm building and maintaining a way of using Relay (FB GraphQL client fw) with ReScript. Relay has its own compiler that'll take a GraphQL definition written inside of ReScript, and generate an actual file with type definitions etc matching that GraphQL definition. The ReScript code can then reference those types for type safe interaction with the data Relay gives it. It looks roughly like this:
Define a GraphQL operation:
https://github.com/zth/rescript-relay/blob/master/example/src/SingleTodo.res#L1-L7
The compiler generates a file with records representing the ReScript types that GraphQL can return:
https://github.com/zth/rescript-relay/blob/master/example/src/__generated__/SingleTodo_todoItem_graphql.res#L6-L11
All of the generated files are put in a single directory, __generated__
.
Now, sometimes you forget to remove selections from your GraphQL definitions when you stop needing/using the data. That in turn causes overfetching. What I'd like to be able to do is to run DCE analysis only on the records inside of the module Types
in each res
file in the __generated__
folder, since it's those records that represent the actual fields in GraphQL that the developer has selected. So, basically, via DCE figure out if there are record fields that aren't accessed anymore, and that can be safely removed.
I'm guessing this isn't possible as of now, but do you understand the use case/what I'm after...?
I think you want to run the analysis on the whole codebase (otherwise you would not discover what is dead), and report only on some subset of it.
The closest option for that is:
reanalyze -help
...
-suppress comma-separated-path-prefixes Don't report on files whose path has a prefix in the list
Not sure if the files can be arranged into paths to get the granularity you need.
If not, likely a little regexp on the output will be enough to filter out what you don't need.
Thank you, that works great!