Skip to content
This repository has been archived by the owner on Jan 2, 2021. It is now read-only.

Simplify and deduplicate ModSummary logic #884

Merged
merged 4 commits into from
Oct 27, 2020

Conversation

wz1000
Copy link
Collaborator

@wz1000 wz1000 commented Oct 25, 2020

We can re-use the modsummary when we parse, don't need to generate a new one.

let preproc_warnings = diagFromStrings "parser" DsWarning preproc_warns
ms <- getModSummaryFromBuffer filename modTime dflags parsed' contents
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mpickering need your help here. Does removePackageImports need to be called before we compute the ModSummary? Because we don't recompute the ModSummary here anymore, we just re-use the one we computed before.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My take on this: since we don't allow GHC to resolve imports anymore, the only place where import resolution happens is in our code, namely in GetLocatedImportsRule. So the removal of package imports can be inlined there in order to preserve the AST and original imports as much as possible. Otherwise plugins like the HLS import lens or code actions which use the AST might end up "losing" package imports accidentally.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, but I'm confused. GetLocatedImportsRule uses GetModSummaryWithoutTimestamps, which doesn't call removePackageImports, so it should never have been affected by it. The only things which are affected by removePackageImports are things which use the modsummary from the parsed module.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Back in the day when removePackageImports was added, GetModSummary didn't exist and GetLocatedImportsRule still used the parsed AST to extract the imports.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like we need a testcase. How do I invoke this code path? Will a multi-cradle with a file using PackageImports to import a conflicting module from two different packages do it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we can just remove it, since the logic is already present in findImports: https://github.com/haskell/ghcide/blob/master/src/Development/IDE/Import/FindImports.hs#L126

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test case is the generic-lens repo. I think the situation was as you described (conflicting module from two different packages)

@wz1000 wz1000 changed the title Simplify and deduplicate parsing logic Simplify and deduplicate ModSummary logic Oct 25, 2020
@wz1000
Copy link
Collaborator Author

wz1000 commented Oct 25, 2020

Allocation seems to consistently be slightly decreased:

Cabal-3.0.0.0                upstream   hover                        True      100       25.793343481         0.0                  0.16236879300000004   4.691163400000001e-2    0.220640349           289851760      22030191560
Cabal-3.0.0.0                HEAD       hover                        True      100       25.401801616         0.0                  0.16855398100000005   5.255851399999999e-2    0.22930546200000002   373782664      21816920536
Cabal-3.0.0.0                upstream   edit                         True      100       25.482009282         0.0                  54.325568903000026    4.527764200000001e-2    54.380331591          327080200      74298801120
Cabal-3.0.0.0                HEAD       edit                         True      100       25.210569009         0.0                  55.011756799000004    5.437737599999998e-2    55.076222508          310954800      73394705464
Cabal-3.0.0.0                upstream   getDefinition                True      100       25.935764744         0.0                  0.13509874999999996   4.607146600000001e-2    0.188710489           387834208      21975966568
Cabal-3.0.0.0                HEAD       getDefinition                True      100       25.00325402          0.0                  0.12643358200000004   4.8468205000000014e-2   0.182144529           288457344      21772793408
Cabal-3.0.0.0                upstream   hover after edit             True      100       26.332472131000003   0.0                  1.711378834           45.511703555            47.230929488          350168072      68646356384
Cabal-3.0.0.0                HEAD       hover after edit             True      100       25.664963997         0.0                  2.2459681000000002    45.50188309400001       47.756508079          279730328      67790362736
Cabal-3.0.0.0                upstream   completions after edit       True      100       26.266564305000003   0.0                  6.635224382999999     41.180279043999974      47.82468833           300760320      68295750648
Cabal-3.0.0.0                HEAD       completions after edit       True      100       25.260676735         0.0                  6.214298085999999     40.45634754899999       46.679372435000005    307838136      67475949864
Cabal-3.0.0.0                upstream   code actions                 True      100       26.751641076000002   1.467685219          2.1468474899999994    5.5034154000000016e-2   2.215886346           367498656      24647758176
Cabal-3.0.0.0                HEAD       code actions                 True      100       24.893968733         1.4616993550000001   1.6609205690000004    5.1741973e-2            1.72252998            334833504      24441570448
Cabal-3.0.0.0                upstream   code actions after edit      True      100       27.03956312          0.0                  108.31374823800003    0.285569898             108.614115247         294133736      113612951384
Cabal-3.0.0.0                HEAD       code actions after edit      True      100       24.931743013000002   0.0                  103.202996737         0.279181454             103.50093825200001    312562120      113039096320
Cabal-3.0.0.0                upstream   documentSymbols after edit   True      100       26.428653628000003   0.0                  2.8671353030000004    2.618475947000001       5.530413076           287102368      30350607272
Cabal-3.0.0.0                HEAD       documentSymbols after edit   True      100       25.077187099000003   0.0                  2.7622393479999996    1.7318165390000009      4.52045964            322110904      29221161248
haskell-lsp-types-0.22.0.0   upstream   hover                        True      100       11.496312212000001   0.0                  0.17637869800000003   4.630458100000001e-2    0.23022139100000003   197510288      6048552712
haskell-lsp-types-0.22.0.0   HEAD       hover                        True      100       10.596880816         0.0                  0.143307378           4.1906212000000005e-2   0.193007078           196784024      6019216128
haskell-lsp-types-0.22.0.0   upstream   edit                         True      100       10.792450318         0.0                  100.13973241699999    4.873996699999998e-2    100.197539452         256165920      79499945984
haskell-lsp-types-0.22.0.0   HEAD       edit                         True      100       10.790441051         0.0                  100.881638099         4.6959731000000025e-2   100.939180221         292295128      79383735512
haskell-lsp-types-0.22.0.0   upstream   getDefinition                True      100       10.462229091000001   0.0                  0.3467945190000002    6.072863299999999e-2    0.41405524600000004   198748608      6040963608
haskell-lsp-types-0.22.0.0   HEAD       getDefinition                True      100       10.515960731         0.0                  0.3024905389999999    7.449331700000006e-2    0.38443393600000003   197475936      6012745680
haskell-lsp-types-0.22.0.0   upstream   hover after edit             True      100       10.662641101         0.0                  7.130637587000001     61.76411521100001       68.90274843           271392248      54842783408
haskell-lsp-types-0.22.0.0   HEAD       hover after edit             True      100       10.788610974000001   0.0                  6.080634165999999     62.236788857999976      68.32578934200001     268298840      54507598024
haskell-lsp-types-0.22.0.0   upstream   completions after edit       True      100       10.446070371000001   0.0                  26.633590179          43.592152687            70.24410082300001     271056072      71576476600
haskell-lsp-types-0.22.0.0   HEAD       completions after edit       True      100       10.457191029         0.0                  27.730883483999996    43.94995463599999       71.69984627800001     270320224      71329726336
haskell-lsp-types-0.22.0.0   upstream   code actions                 True      100       10.814827625000001   6.740846204          1.3920771349999996    4.995033100000001e-2    1.451926477           283245056      12464048312
haskell-lsp-types-0.22.0.0   HEAD       code actions                 True      100       10.702982899         6.2182413500000004   1.4504877959999996    5.516086300000002e-2    1.515943177           281230032      12414402360
haskell-lsp-types-0.22.0.0   upstream   code actions after edit      True      100       11.067998382         0.0                  132.130662634         0.4871755839999996      132.63939251800002    329539096      110074195616
haskell-lsp-types-0.22.0.0   HEAD       code actions after edit      True      100       11.053840233         0.0                  126.949787759         0.8246494279999999      127.79924934900001    338953280      107345014488
haskell-lsp-types-0.22.0.0   upstream   documentSymbols after edit   True      100       161.580907833        0.0                  0.9590848159999997    6.364661741999999       7.338525069           197592960      13088024520
haskell-lsp-types-0.22.0.0   HEAD       documentSymbols after edit   True      100       10.961388072         0.0                  0.9404087250000003    0.5972474170000001      1.553774368           197665704      8787065368

@pepeiborra I often observe that results for documentSymbols after edit are a bit strange, as if somehow some samples are dropped from the end.

Copy link
Collaborator

@pepeiborra pepeiborra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice

@wz1000 wz1000 merged commit 933c0c9 into haskell:master Oct 27, 2020
@wz1000
Copy link
Collaborator Author

wz1000 commented Oct 27, 2020

Note that the document symbol benchmarking weirdness shows up in the final results, but reversed this time:

haskell-lsp-types-0.22.0.0   upstream   documentSymbols after edit   True      100       141.00007825100002   0.0                  0.8356579339999999    0.747637367             1.595183011           153509936      9281975776
haskell-lsp-types-0.22.0.0   HEAD       documentSymbols after edit   True      100       9.280972012000001    0.0                  0.7239032349999996    5.714553659             6.451683308000001     198016896      13151368288

pepeiborra pushed a commit to pepeiborra/ide that referenced this pull request Dec 29, 2020
* Simplify and dedup parsing logic

* delete removePackageImports

* add dependencies on included files

* hlint
pepeiborra pushed a commit to pepeiborra/ide that referenced this pull request Dec 29, 2020
* Simplify and dedup parsing logic

* delete removePackageImports

* add dependencies on included files

* hlint
pepeiborra pushed a commit to pepeiborra/ide that referenced this pull request Dec 29, 2020
* Simplify and dedup parsing logic

* delete removePackageImports

* add dependencies on included files

* hlint
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants