Comments (14)
This is the generated code after DCE:
// Generated by BUCKLESCRIPT, PLEASE EDIT WITH CARE
var Raw = { };
var MyQuery = {
Raw: Raw
};
export {
MyQuery ,
}
/* No side effect */
from reanalyze.
I will follow this up in the 1.0 branch.
from reanalyze.
@jfrolich here's the code annotated dead by the analysis.
Looks like there are a couple of things not considered dead yet which could (e.g. serializeVariables
). Good test, I can look into why.
// generated code by the PPX
module MyQuery = {
module Raw = {
type t = {scalarsInput: string};
};
[@dead "MyQuery.query"] let query = "query ($arg: VariousScalarsInput!) {\nscalarsInput(arg: $arg) \n}\n";
type t = {scalarsInput: string};
type t_variables = {arg: t_variables_VariousScalarsInput}
and t_variables_VariousScalarsInput = {
nullableString: option(string),
string,
nullableInt: option(int),
int,
nullableFloat: option(float),
float,
nullableBoolean: option(bool),
boolean: bool,
nullableID: option(string),
id: string,
};
[@dead "MyQuery.parse"] let parse: Raw.t => t =
(value) => (
{
scalarsInput: {
let value = (value: Raw.t).scalarsInput;
value;
},
}: t
);
[@dead "MyQuery.serialize"] let serialize: t => Raw.t =
(value) => (
{
let scalarsInput = {
let value = (value: t).scalarsInput;
value;
};
{
scalarsInput: scalarsInput,
};
}: Raw.t
);
let rec serializeVariables: t_variables => Js.Json.t =
inp =>
[|
(
"arg",
(a => Some(serializeInputObjectVariousScalarsInput(a)))(inp.arg),
),
|]
|> Js.Array.filter(
fun
| (_, None) => false
| (_, Some(_)) => true,
)
|> Js.Array.map(
fun
| (k, Some(v)) => (k, v)
| (k, None) => (k, Js.Json.null),
)
|> Js.Dict.fromArray
|> Js.Json.object_
and serializeInputObjectVariousScalarsInput:
t_variables_VariousScalarsInput => Js.Json.t =
inp =>
[|
(
"nullableString",
(
a =>
switch (a) {
| None => None
| Some(b) => (a => Some(Js.Json.string(a)))(b)
}
)(
inp.nullableString,
),
),
("string", (a => Some(Js.Json.string(a)))(inp.string)),
(
"nullableInt",
(
a =>
switch (a) {
| None => None
| Some(b) => (a => Some(Js.Json.number(float_of_int(a))))(b)
}
)(
inp.nullableInt,
),
),
("int", (a => Some(Js.Json.number(float_of_int(a))))(inp.int)),
(
"nullableFloat",
(
a =>
switch (a) {
| None => None
| Some(b) => (a => Some(Js.Json.number(a)))(b)
}
)(
inp.nullableFloat,
),
),
("float", (a => Some(Js.Json.number(a)))(inp.float)),
(
"nullableBoolean",
(
a =>
switch (a) {
| None => None
| Some(b) => (a => Some(Js.Json.boolean(a)))(b)
}
)(
inp.nullableBoolean,
),
),
("boolean", (a => Some(Js.Json.boolean(a)))(inp.boolean)),
(
"nullableID",
(
a =>
switch (a) {
| None => None
| Some(b) => (a => Some(Js.Json.string(a)))(b)
}
)(
inp.nullableID,
),
),
("id", (a => Some(Js.Json.string(a)))(inp.id)),
|]
|> Js.Array.filter(
fun
| (_, None) => false
| (_, Some(_)) => true,
)
|> Js.Array.map(
fun
| (k, Some(v)) => (k, v)
| (k, None) => (k, Js.Json.null),
)
|> Js.Dict.fromArray
|> Js.Json.object_;
let makeVar = (~f, ~arg, ()) =>
f(
serializeVariables(
{
arg: arg,
}: t_variables,
),
)
[@dead "MyQuery.makeInputObjectVariousScalarsInput"] and makeInputObjectVariousScalarsInput =
(
~nullableString=?,
~string,
~nullableInt=?,
~int,
~nullableFloat=?,
~float,
~nullableBoolean=?,
~boolean,
~nullableID=?,
~id,
(),
)
: t_variables_VariousScalarsInput => {
nullableString,
string,
nullableInt,
int,
nullableFloat,
float,
nullableBoolean,
boolean,
nullableID,
id,
};
[@dead "MyQuery.definition"] let definition = (parse, query, makeVar, serialize);
let makeVariables = makeVar(~f=f => f);
};
// end of generated code by the ppx
from reanalyze.
So it looks like this is what prevents the final bit of elimination:
Warning Dead Value With Side Effects
/Users/cristianoc/reasonml/reanalyze/examples/deadcode/src/B.re 194:3-40
MyQuery.makeVariables is never used and could have side effects
from reanalyze.
This change would allow the full dead code analysis to fire:
let makeVariables = (~arg) => makeVar( ~f=f => f, arg);
Or, using uncurried application would have forced one into this anyway.
This is one more example of the pitfalls of partial application. In this case, it prevents some analysis optimizaion, and surely a bunch of invisible compiler optimizations are prevented by this.
from reanalyze.
@jfrolich do you have the bandwidth to try and suggest this change upstream in the PPX and follow it through?
This example is on pause at the moment. I'd like to investigate what happens when a subset of the generated code is used. But first I'd like to make sure that if none is used, then everything is eliminated.
from reanalyze.
@jfrolich do you have the bandwidth to try and suggest this change upstream in the PPX and follow it through?
This example is on pause at the moment. I'd like to investigate what happens when a subset of the generated code is used. But first I'd like to make sure that if none is used, then everything is eliminated.
Yes. I think we might be able to eliminate makeVar
it was mostly a proof of concept to enable a fancy API surface, but it had other downsides with currying, and to my knowledge it didn't end up implemented in a client. This is exactly the kind of API changes we can make before releasing 1.0 officially.
from reanalyze.
@jfrolich any other changes to report for gql ppx 1.0?
from reanalyze.
Yes there will be quite a few changes. I am looking to make the definition
a record instead of a tuple (not sure yet about that though). And there is quite a list of things to be done. I made a list here: teamwalnut/graphql-ppx#86, but it is not exhaustive. Anything particular that you are interested about?
from reanalyze.
Build speed comes to mind! We ran some benchmarks lately, and the ppx can really make a difference.
from reanalyze.
Yes. I think there is much room to improve indeed! I yet have to look at performance, still some features to complete, but after that I will dive a bit deeper to improve the performance!
from reanalyze.
@jfrolich I was curious about progress and took a look at teamwalnut/graphql-ppx#86 . Wow lots of activity there!
from reanalyze.
Yes working towards a 1.0 release. We want it to be great!
from reanalyze.
Looks like this is going to work in the next release.
Please reopen if there are any new issues.
from reanalyze.
Related Issues (20)
- Binding operators are incorrectly marked dead HOT 1
- Use single dead annotation if entire module is unused
- Awkward record field dead attribute placement with unusual record formatting HOT 3
- Re-exported variant is incorrectly marked dead HOT 1
- Interpret OCaml compiler's unused value declaration warning suppression attribute HOT 1
- Confusing dead code warning at module include HOT 1
- When a function is annotated `@dead` values inside it are reported dead. HOT 10
- Module incorrectly marked dead when contains non-dead type and submodule definitions HOT 1
- @dead annotation breaks rescript compiler on a destructured value HOT 3
- decorating functions in pipe chains? HOT 4
- Dead Types wrt consumed types HOT 7
- False alarms for native projects that generate new files HOT 9
- [Feature Request] Support `globs` for `suppress` and `unsuppress`.
- [Feature request] Integrate with `@deriving({abstract: light})` HOT 13
- Interface of sub module are not seen used HOT 3
- -write produces syntax error in OCaml w.r.t. destructive substitution on module-items and tuple pattern-matching HOT 4
- Catching on exception from other module leads to incorrect warning HOT 3
- Include Darwin arm64 builds in the NPM package HOT 5
- False Positive When Using First Class Module Type Alias
- OCaml 5.2 support HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from reanalyze.