Skip to content

Commit 3a9f31a

Browse files
cristianoccknitt
authored andcommitted
reanalyze: restore toplevel ocaml.warning suppression
Fix CollectAnnotations so top-level [@@ocaml.warning("-32")] / [@@warning] continues to suppress dead-value warnings even with scoped @@live/@@dead support. Add regression fixture and update expected deadcode output.
1 parent f42a641 commit 3a9f31a

3 files changed

Lines changed: 31 additions & 4 deletions

File tree

analysis/reanalyze/src/CollectAnnotations.ml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,9 @@ let collectExportLocations ~state ~config ~doGenType =
128128
| Tstr_attribute attribute -> (
129129
match scopeDefaultFromToplevelAttribute attribute with
130130
| Some _ as newDefault -> currentScopeDefault := newDefault
131-
| None -> ())
131+
| None ->
132+
if [attribute] |> Annotation.isOcamlSuppressDeadWarning then
133+
currentlyDisableWarnings := true)
132134
| _ -> ());
133135
super.structure_item self item
134136
in
@@ -145,7 +147,9 @@ let collectExportLocations ~state ~config ~doGenType =
145147
| Tsig_attribute attribute -> (
146148
match scopeDefaultFromToplevelAttribute attribute with
147149
| Some _ as newDefault -> currentScopeDefault := newDefault
148-
| None -> ())
150+
| None ->
151+
if [attribute] |> Annotation.isOcamlSuppressDeadWarning then
152+
currentlyDisableWarnings := true)
149153
| _ -> ());
150154
super.signature_item self item
151155
in

tests/analysis_tests/tests-reanalyze/deadcode/expected/deadcode.txt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,6 +1079,11 @@
10791079
addValueReference Newton.res:31:8 --> Newton.res:29:4
10801080
addValueReference Newton.res:31:18 --> Newton.res:29:4
10811081
addValueReference Newton.res:31:16 --> Newton.res:25:4
1082+
Scanning OcamlWarningSuppressToplevel.cmt Source:OcamlWarningSuppressToplevel.res
1083+
addValueDeclaration +suppressed1 OcamlWarningSuppressToplevel.res:3:4 path:+OcamlWarningSuppressToplevel
1084+
addValueDeclaration +suppressed2 OcamlWarningSuppressToplevel.res:4:4 path:+OcamlWarningSuppressToplevel
1085+
addValueDeclaration +suppressed3 OcamlWarningSuppressToplevel.res:7:6 path:+OcamlWarningSuppressToplevel.M
1086+
addValueDeclaration +suppressed4 OcamlWarningSuppressToplevel.res:8:6 path:+OcamlWarningSuppressToplevel.M
10821087
Scanning Opaque.cmt Source:Opaque.res
10831088
addValueDeclaration +noConversion Opaque.res:5:4 path:+Opaque
10841089
addValueDeclaration +testConvertNestedRecordFromOtherFile Opaque.res:11:4 path:+Opaque
@@ -1827,7 +1832,7 @@
18271832

18281833
Forward Liveness Analysis
18291834

1830-
decls: 655
1835+
decls: 659
18311836
roots(external targets): 122
18321837
decl-deps: decls_with_out=375 edges_to_decls=252
18331838

@@ -1969,6 +1974,7 @@ Forward Liveness Analysis
19691974
Root (annotated): Value +Hooks.Inner.+make
19701975
Root (annotated): Value +Uncurried.+curried3
19711976
Root (external ref): Value +OptArg.+twoArgs
1977+
Root (annotated): Value +OcamlWarningSuppressToplevel.+suppressed1
19721978
Root (external ref): RecordLabel +Records.business2.address2
19731979
Root (annotated): Value +Tuples.+testTuple
19741980
Root (annotated): Value +Records.+testMyObj2
@@ -1992,12 +1998,14 @@ Forward Liveness Analysis
19921998
Root (annotated): Value +TestImport.+make
19931999
Root (external ref): RecordLabel +Unison.t.break
19942000
Root (annotated): Value +ImportJsValue.+default
2001+
Root (annotated): Value +OcamlWarningSuppressToplevel.M.+suppressed4
19952002
Root (annotated): Value +Types.+optFunction
19962003
Root (annotated): Value +Records.+getPayloadRecordPlusOne
19972004
Root (annotated): Value +Types.+swap
19982005
Root (annotated): Value +Types.+jsonStringify
19992006
Root (annotated): RecordLabel +ImportHookDefault.props.person
20002007
Root (annotated): Value +Variants.+saturday
2008+
Root (annotated): Value +OcamlWarningSuppressToplevel.M.+suppressed3
20012009
Root (annotated): Value +Records.+findAddress2
20022010
Root (annotated): Value +Records.+someBusiness
20032011
Root (external ref): RecordLabel +Hooks.vehicle.name
@@ -2127,6 +2135,7 @@ Forward Liveness Analysis
21272135
Root (external ref): RecordLabel +VariantsWithPayload.payload.y
21282136
Root (annotated): RecordLabel +ImportHookDefault.props.children
21292137
Root (annotated): Value +TestModuleAliases.+testInner1
2138+
Root (annotated): Value +OcamlWarningSuppressToplevel.+suppressed2
21302139
Root (annotated): Value +VariantsWithPayload.+testWithPayload
21312140
Root (annotated): Value +Types.+testConvertNull
21322141
Root (annotated): Value +Records.+getPayloadRecord
@@ -2136,7 +2145,7 @@ Forward Liveness Analysis
21362145
Root (annotated): Value +UseImportJsValue.+useGetProp
21372146
Root (external ref): RecordLabel +Hooks.RenderPropRequiresConversion.props.renderVehicle
21382147

2139-
304 roots found
2148+
308 roots found
21402149

21412150
Propagate: +Hooks.+default -> +Hooks.+make
21422151
Propagate: DeadRT.moduleAccessPath.Root -> +DeadRT.moduleAccessPath.Root
@@ -3225,6 +3234,10 @@ Forward Liveness Analysis
32253234
-> +Newton.+newton
32263235
-> +Newton.+f
32273236
-> +Newton.+fPrimed
3237+
Live (annotated) Value +OcamlWarningSuppressToplevel.+suppressed1
3238+
Live (annotated) Value +OcamlWarningSuppressToplevel.+suppressed2
3239+
Live (annotated) Value +OcamlWarningSuppressToplevel.M.+suppressed3
3240+
Live (annotated) Value +OcamlWarningSuppressToplevel.M.+suppressed4
32283241
Dead VariantCase +Opaque.opaqueFromRecords.A
32293242
Live (annotated) Value +Opaque.+noConversion
32303243
Live (annotated) Value +Opaque.+testConvertNestedRecordFromOtherFile
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@@ocaml.warning("-32")
2+
3+
let suppressed1 = 1
4+
let suppressed2 = 2
5+
6+
module M = {
7+
let suppressed3 = 3
8+
let suppressed4 = 4
9+
}
10+

0 commit comments

Comments
 (0)