You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was just debugging around in hdevtools, printing some stuff (namely this stuff), when I noticed that the ghcOptExtensionMap contains many more entries than I think it should (multiple thousands - we dont' have that many language extensions just yet). The language extensions are repeated (40 times in my case), I believe that's just as many times as I have packages used in this project (ghcOptPackages).
Of course we also do a repeaded linear lookup in this data structure.
Nice catch, but I don't think that Cabal code ever mappends large numbers of GhcOptions records. Basically, the only place GhcOptions.mappend is used is D.S.GHC, and the usage pattern in that file is a mappendmempty {...}mappend mempty {...} ..., so current behaviour of GhcOptions.mappend should be fine.
In your code, however, I see a line let ghcOpts' = foldl' mappend ..., which is likely what triggered the behaviour you describe.
I wanted to say something like "it would be nice if the monoid instance was resistant to people doing things like that", but I see you already patched everything. Nice :)
@23Skidoo Perfect. One last thing: Set union is not stable (the output order is defined by the Ord instance instead of the order of occurrence in the two lists). For ghcOptExtensionMap this surely doesn't matter, but I don't know if it does for the other fields.
It would matter, for example, for ghc options: -Wall -w -Wall has the effect of -Wall (because the last one matters), but if it gets rearranged to -Wall -w, then it has the effect of -w.
If order-stable equivalents are necessary here, there are some well tested ones on the ordNub page.
Your ordNub is left-biased, if I'm reading it right, and ghc's treatment of extensions is right-biased (which is the most natural, if you think about it).
For instance, -XOverloadedStrings -XNoOverloadedStrings -XOverloadedStrings is equivalent to -XOverloadedStrings, but cabal will reduce it to -XOverloadedStrings -XNoOverloadedStrings, which is equivalent to -XNoOverloadedStrings.
@feuerbach
Good point. Changed to use right-biased union (e.g. ["-nofoo", "-foo"] union ["-foo", "-nofoo", "-foo"] now produces ["-foo", "-nofoo", "-foo"]).
Activity
nh2 commentedon Sep 17, 2014
Maybe we could also have a look at whether something like this can happen for other fields.
23Skidoo commentedon Sep 17, 2014
Nice catch, but I don't think that Cabal code ever
mappends large numbers ofGhcOptionsrecords. Basically, the only placeGhcOptions.mappendis used isD.S.GHC, and the usage pattern in that file isamappendmempty {...}mappendmempty {...} ..., so current behaviour ofGhcOptions.mappendshould be fine.In your code, however, I see a line
let ghcOpts' = foldl' mappend ..., which is likely what triggered the behaviour you describe.GhcOptions.mappend: use `Data.List.union` where appropriate.
GhcOptions.mappend: use `Data.List.union` where appropriate.
nh2 commentedon Sep 17, 2014
I wanted to say something like "it would be nice if the monoid instance was resistant to people doing things like that", but I see you already patched everything. Nice :)
nh2 commentedon Sep 17, 2014
@23Skidoo Careful though: Like
nub,Data.List.unionis O(n²).Mind using
toList . Set.union . fromList?GhcOptions.mappend: use `Data.List.union` where appropriate.
23Skidoo commentedon Sep 17, 2014
@nh2 OK, done.
nh2 commentedon Sep 17, 2014
@23Skidoo Perfect. One last thing: Set union is not stable (the output order is defined by the Ord instance instead of the order of occurrence in the two lists). For
ghcOptExtensionMapthis surely doesn't matter, but I don't know if it does for the other fields.It would matter, for example, for ghc options:
-Wall -w -Wallhas the effect of-Wall(because the last one matters), but if it gets rearranged to-Wall -w, then it has the effect of-w.If order-stable equivalents are necessary here, there are some well tested ones on the ordNub page.
GhcOptions.mappend: use `Data.List.union` where appropriate.
23Skidoo commentedon Sep 17, 2014
Thanks, changed to use your
listUnionfunction.Add support for cabalized projects
UnkindPartition commentedon Sep 25, 2014
This is still wrong, I'm afraid.
Your
ordNubis left-biased, if I'm reading it right, and ghc's treatment of extensions is right-biased (which is the most natural, if you think about it).For instance,
-XOverloadedStrings -XNoOverloadedStrings -XOverloadedStringsis equivalent to-XOverloadedStrings, but cabal will reduce it to-XOverloadedStrings -XNoOverloadedStrings, which is equivalent to-XNoOverloadedStrings.A right-biased
ordNubshould do the job.nh2 commentedon Sep 25, 2014
You are right; I actually thought I mentioned it but that was somewhere else.
GhcOptions.mappend: use `ordNubRight` where appropriate.
23Skidoo commentedon Sep 26, 2014
@feuerbach
Good point. Changed to use right-biased union (e.g.
["-nofoo", "-foo"]union["-foo", "-nofoo", "-foo"]now produces["-foo", "-nofoo", "-foo"]).GhcOptions.mappend: use `ordNubRight` where appropriate.
GhcOptions.mappend: use `ordNubRight` where appropriate.
GhcOptions.mappend: use `ordNubRight` where appropriate.
GhcOptions.mappend: use `ordNubRight` where appropriate.
GhcOptions: use `NubListR` where appropriate.