Comments (23)
Hey Josh. Unrelated but glad to see you again =)
from reanalyze.
So for now it seems that indeed treating 42 as @live
is the way forward.
from reanalyze.
I’d have first to make it slower, to give an excuse.
from reanalyze.
I guess this falls in the category: it is dead, it should be considered dead, but should not be reported as dead.
Not sure I'd want to consider global options, only these local @@@ocaml.warning "-32"
. Which makes it an ad-hoc treatment. Also, not clear how to get hold of global options anyway. So one would observe a difference when disabling 32
in the command line, and in the code.
The PPX magic comes to bite back in many subtle ways.
from reanalyze.
Yes: dead but shouldn't be reported. But it is dead in the [@live]
sense rather than the [@dead]
one, since such code might be the only use of other code, and that other code should not be reported dead.
Considering only the attributes seems pragmatically sensible, since it isn't clear what the use case might be for compiling with -w -32
and expecting dead code analysis to not be noisy.
FWIW, I don't think that this really has anything crucially to do with ppx. Warning 32 predates ppx, and there are reasonable cases where e.g. a codebase's style mandates that each type comes with a common set of operations like compare
and hash
.
Also, it is probably a good idea to handle the other "unused" warnings similarly. Maybe 32-39, 60, 66.
from reanalyze.
edit: s/dead/not dead/
from reanalyze.
There’s also the automatic deletion of dead code. And for that one would like to delete even things kept alive only by this.
But it’s not a big issue. I’ll keep it simple.
from reanalyze.
Ok, but for automatic deletion of dead code it's a ppx that outputs a new parsetree right, so no need to change the source, just give it to the rest of the compiler.
from reanalyze.
Currently the analysis adds annotations, and the deletion ppx runs afterwards. So there’s a limit anyway to what can be done with that setup, as you can’t annotate code generated by a ppx.
A fuller solution would require deep integration in the compiler, as typed ast to typed ast xform.
from reanalyze.
Currently the analysis adds annotations
Does this work by adding attributes to the parsetree? If so, it would be rolled into one ppx pipeline and not have to worry about whether code was generated or not.
from reanalyze.
No it’s literally printing into the source file.
So it’s very easy to take a quick look at a project without going through the list of reported issues.
from reanalyze.
Btw the analysis operates on the typed tree. Does not fit a ppx pipeline.
from reanalyze.
Ah, yes, I knew but overlooked that. It would be a bit of work then to get back to the untyped tree, or construct a new one, or... Hmm. I suspect that you could reuse the implementation technique of ppx_import though, as it reads cmt files and generates code. That needs to use the staged_pps instead of pps flow in dune, but that should also be doable for reanalyze I think.
from reanalyze.
The analysis is global so strictly speaking does not fit in the ppx flow by that reason alone. However of course it could store the results somewhere then run a ppx that reads them.
from reanalyze.
from reanalyze.
@jberdine this is done in #13.
Unsure about whether to support other suppressions beyond 32
. What did you have in mind?
from reanalyze.
A relevant one is 34 Unused type declaration
. Though that's a bit different from the sense in which variant/records parts are unused.
Merging this for now.
from reanalyze.
The following might also make sense:
37 Unused constructor.
38 Unused extension constructor.
60 Unused module declaration.
from reanalyze.
It seems that code like
let[@warning "-32"] foo x = print_int x
still gets flagged if foo
is otherwise dead.
from reanalyze.
Let me check.
from reanalyze.
Tried to repro the example here:
#22
No cigar.
What was the example?
from reanalyze.
Oh wait warning
not ocaml.warning
?
from reanalyze.
Yes, they are synonyms.
from reanalyze.
Related Issues (20)
- Static Analysis
- `-write` removes trailing newline from modified file
- 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
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.