reanalyze icon indicating copy to clipboard operation
reanalyze copied to clipboard

Dead Types wrt consumed types

Open AlexMoutonNoble opened this issue 2 years ago • 7 comments

Hi again Cristiano. Just added dce to our CI process and going through the output i get:

Warning Dead Type
  File "/home/circleci/noble/web/src/requests.res", line 200, characters 2-17
  argsClone.with_data is a record label never used to read a value
  <-- line 200
    @dead("argsClone.with_data") with_data: bool,

argsClone is consumed by an external Axios.post, and this type is a preposition for our clone action, so these warnings seem like false positive to me. Its not wrong, granted, but suggests I can remove that field which is wrong.

Are you doing any work in this direction?

Thanks! Alex

AlexMoutonNoble avatar May 25 '22 18:05 AlexMoutonNoble

How does the Axis post get access to it? Is argsClone exported to JS, and if so is genType used?

cristianoc avatar May 25 '22 18:05 cristianoc

added dce to our CI process

Great!

cristianoc avatar May 25 '22 18:05 cristianoc

@send
external postImpl: (
  axios,
  string,
  'data,
  config,
) => Js.Promise.t<response<'datasend, 'datarecv, 'headersrecv, 'request>> = "post"

let post = (url, data, config) => axios->postImpl(url, data, config)

type argsClone<'id> = {
  name: string,
  description: string,
  with_data: bool,
  clone_id: 'id,
}

type clone = {id: int}

let clone = (data: argsClone<int>): Js.Promise.t<
  Axios.response<'datasend, cloneCapability, 'headers, 'request>,
> => {
  Axios.post(`/api/capability/`, data, configJson)
}

AlexMoutonNoble avatar May 25 '22 18:05 AlexMoutonNoble

Currently there's no magic that tries to understand flow of values to externals. The only magic is values annotated @genType are automatically treated as not dead. But there's no special provision at the moment for types used in externals.

In these cases, it's best to annotate the type argsClone live manually: @live type argsClone....

cristianoc avatar May 25 '22 19:05 cristianoc

E.g.

@live("sent to Axios")
type argsClone<'id> = {
  name: string,
  description: string,
  with_data: bool,
  clone_id: 'id,
}

cristianoc avatar May 25 '22 19:05 cristianoc

The other thing is just because a value is sent to an external, that does not mean that the external function. is going to read all its fields, so any automatic analysis would be pretty coarse.

cristianoc avatar May 25 '22 19:05 cristianoc

That seems pretty reasonable to me. False positives and aggressive annotations are a burden

adding just for context that -dce produces 8500 lines of output for our codebase, so basically too much for our small team

(anyways thanks again!)

AlexMoutonNoble avatar May 26 '22 17:05 AlexMoutonNoble