Skip to content

Fix issue where code analysis would not track types in inner modules … #650

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@

- Fix issue with completing `foo. x` where `x` should not be part of the completion https://github.com/rescript-lang/rescript-vscode/pull/644

- Fix issue where code analysis would not track types in inner modules across implementations and interfaces https://github.com/rescript-association/reanalyze/issues/186

## v1.8.2

#### :rocket: New Feature
Expand Down
17 changes: 17 additions & 0 deletions analysis/reanalyze/examples/deadcode/expected/deadcode.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,14 @@
addValueDeclaration +make ImportMyBanner.res:12:4 path:+ImportMyBanner
addRecordLabelDeclaration text ImportMyBanner.res:5:16 path:+ImportMyBanner.message
addValueReference ImportMyBanner.res:12:4 --> ImportMyBanner.res:7:0
Scanning InnerModuleTypes.cmt Source:InnerModuleTypes.res
addVariantCaseDeclaration Foo InnerModuleTypes.res:2:11 path:+InnerModuleTypes.I.t
Scanning InnerModuleTypes.cmti Source:InnerModuleTypes.resi
addVariantCaseDeclaration Foo InnerModuleTypes.resi:2:11 path:InnerModuleTypes.I.t
extendTypeDependencies InnerModuleTypes.res:2:11 --> InnerModuleTypes.resi:2:11
extendTypeDependencies InnerModuleTypes.resi:2:11 --> InnerModuleTypes.res:2:11
addTypeReference InnerModuleTypes.res:2:11 --> InnerModuleTypes.resi:2:11
addTypeReference InnerModuleTypes.resi:2:11 --> InnerModuleTypes.res:2:11
Scanning JSResource.cmt Source:JSResource.res
Scanning JsxV4.cmt Source:JsxV4.res
addValueDeclaration +make JsxV4.res:4:23 path:+JsxV4.C
Expand Down Expand Up @@ -1496,6 +1504,9 @@
addValueReference TestImport.res:13:4 --> TestImport.res:1:0
addRecordLabelDeclaration text TestImport.res:22:16 path:+TestImport.message
addValueReference TestImport.res:27:4 --> TestImport.res:24:0
Scanning TestInnedModuleTypes.cmt Source:TestInnedModuleTypes.res
addValueDeclaration +_ TestInnedModuleTypes.res:1:0 path:+TestInnedModuleTypes
addTypeReference TestInnedModuleTypes.res:1:8 --> InnerModuleTypes.resi:2:11
Scanning TestModuleAliases.cmt Source:TestModuleAliases.res
addValueDeclaration +testInner1 TestModuleAliases.res:32:4 path:+TestModuleAliases
addValueDeclaration +testInner1Expanded TestModuleAliases.res:35:4 path:+TestModuleAliases
Expand Down Expand Up @@ -1890,6 +1901,8 @@ File References
ImportIndex.res -->>
ImportJsValue.res -->>
ImportMyBanner.res -->>
InnerModuleTypes.res -->>
InnerModuleTypes.resi -->>
JSResource.res -->>
JsxV4.res -->> React.res
LetPrivate.res -->>
Expand All @@ -1914,6 +1927,7 @@ File References
TestFirstClassModules.res -->>
TestImmutableArray.res -->> ImmutableArray.resi
TestImport.res -->>
TestInnedModuleTypes.res -->>
TestModuleAliases.res -->>
TestOptArg.res -->> OptArg.resi
TestPromise.res -->>
Expand Down Expand Up @@ -2126,6 +2140,8 @@ File References
Dead Value +ImportMyBanner.+make: 0 references () [0]
Live Value +ImportMyBanner.+make: 0 references () [0]
Dead RecordLabel +ImportMyBanner.message.text: 0 references () [0]
Live VariantCase InnerModuleTypes.I.t.Foo: 1 references (TestInnedModuleTypes.res:1:8) [1]
Live VariantCase +InnerModuleTypes.I.t.Foo: 1 references (InnerModuleTypes.resi:2:11) [0]
Live Value +JsxV4.C.+make: 1 references (JsxV4.res:7:9) [0]
Live Value +LetPrivate.+y: 0 references () [0]
Live Value +LetPrivate.local_1.+x: 1 references (LetPrivate.res:7:4) [0]
Expand Down Expand Up @@ -2269,6 +2285,7 @@ File References
Dead Value +TestImport.+innerStuffContents: 0 references () [0]
Live Value +TestImport.+innerStuffContentsAsEmptyObject: 0 references () [0]
Live Value +TestImport.+innerStuffContents: 0 references () [0]
Dead Value +TestInnedModuleTypes.+_: 0 references () [0]
Live Value +TestModuleAliases.+testInner2Expanded: 0 references () [0]
Live Value +TestModuleAliases.+testInner2: 0 references () [0]
Live Value +TestModuleAliases.+testInner1Expanded: 0 references () [0]
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions analysis/reanalyze/examples/deadcode/src/InnerModuleTypes.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module I = {
type t = Foo
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module I: {
type t = Foo
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let _ = InnerModuleTypes.I.Foo
12 changes: 10 additions & 2 deletions analysis/reanalyze/src/DeadValue.ml
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@ let rec getSignature (moduleType : Types.module_type) =

let rec processSignatureItem ~doTypes ~doValues ~moduleLoc ~path
(si : Types.signature_item) =
match si with
let oldModulePath = ModulePath.getCurrent () in
(match si with
| Sig_type (id, t, _) when doTypes ->
if !Config.analyzeTypes then
DeadType.addDeclaration ~typeId:id ~typeKind:t.type_kind
Expand All @@ -260,6 +261,12 @@ let rec processSignatureItem ~doTypes ~doValues ~moduleLoc ~path
~sideEffects:false
| Sig_module (id, {Types.md_type = moduleType; md_loc = moduleLoc}, _)
| Sig_modtype (id, {Types.mtd_type = Some moduleType; mtd_loc = moduleLoc}) ->
ModulePath.setCurrent
{
oldModulePath with
loc = moduleLoc;
path = (id |> Ident.name |> Name.create) :: oldModulePath.path;
};
let collect =
match si with
| Sig_modtype _ -> false
Expand All @@ -270,7 +277,8 @@ let rec processSignatureItem ~doTypes ~doValues ~moduleLoc ~path
|> List.iter
(processSignatureItem ~doTypes ~doValues ~moduleLoc
~path:((id |> Ident.name |> Name.create) :: path))
| _ -> ()
| _ -> ());
ModulePath.setCurrent oldModulePath

(* Traverse the AST *)
let traverseStructure ~doTypes ~doExternals =
Expand Down