andrey-zherikov / argparse

Parser for command-line arguments
https://andrey-zherikov.github.io/argparse/
Boost Software License 1.0
30 stars 6 forks source link

Doesn't seem to be compilable with LDC 1.37.0 nor 1.38.0 #161

Open ljmf00-wekaio opened 1 month ago

ljmf00-wekaio commented 1 month ago

This is almost probably a compiler/Phobos regression. CC @pbackus perhaps are you aware of some change on sumtype that affected this? There's no other informational error, so, I can't understand clearly where the issue resides exactly. All I have is this log, and I'm confident its from argparse given the type names:

/home/luis/.local/bin/../import/std/sumtype.d(418): Error: template instance `DeducedParameterType!(inout(Unknown))` does not match template declaration `DeducedParameterType(T)`
/home/luis/.local/bin/../import/std/sumtype.d(418): Error: template instance `DeducedParameterType!(inout(Argument))` does not match template declaration `DeducedParameterType(T)`
/home/luis/.local/bin/../import/std/sumtype.d(418): Error: template instance `DeducedParameterType!(inout(SubCommand))` does not match template declaration `DeducedParameterType(T)`
/home/luis/.local/bin/../import/std/sumtype.d(418): Error: template instance `DeducedParameterType!(inout(Unknown))` does not match template declaration `DeducedParameterType(T)`
/home/luis/.local/bin/../import/std/sumtype.d(418): Error: template instance `DeducedParameterType!(inout(Argument))` does not match template declaration `DeducedParameterType(T)`
/home/luis/.local/bin/../import/std/sumtype.d(418): Error: template instance `DeducedParameterType!(inout(SubCommand))` does not match template declaration `DeducedParameterType(T)`
/home/luis/.local/bin/../import/std/sumtype.d(418): Error: template instance `DeducedParameterType!(inout(Unknown))` does not match template declaration `DeducedParameterType(T)`
/home/luis/.local/bin/../import/std/sumtype.d(418): Error: template instance `DeducedParameterType!(inout(Argument))` does not match template declaration `DeducedParameterType(T)`
/home/luis/.local/bin/../import/std/sumtype.d(418): Error: template instance `DeducedParameterType!(inout(SubCommand))` does not match template declaration `DeducedParameterType(T)`
/home/luis/.local/bin/../import/std/sumtype.d(418): Error: template instance `DeducedParameterType!(inout(Unknown))` does not match template declaration `DeducedParameterType(T)`
/home/luis/.local/bin/../import/std/sumtype.d(418): Error: template instance `DeducedParameterType!(inout(Argument))` does not match template declaration `DeducedParameterType(T)`
/home/luis/.local/bin/../import/std/sumtype.d(418): Error: template instance `DeducedParameterType!(inout(SubCommand))` does not match template declaration `DeducedParameterType(T)`
/home/luis/.local/bin/../import/std/sumtype.d(418): Error: template instance `DeducedParameterType!(inout(Unknown))` does not match template declaration `DeducedParameterType(T)`
/home/luis/.local/bin/../import/std/sumtype.d(418): Error: template instance `DeducedParameterType!(inout(Argument))` does not match template declaration `DeducedParameterType(T)`
/home/luis/.local/bin/../import/std/sumtype.d(418): Error: template instance `DeducedParameterType!(inout(SubCommand))` does not match template declaration `DeducedParameterType(T)`
/home/luis/.local/bin/../import/std/sumtype.d(418): Error: template instance `DeducedParameterType!(inout(Unknown))` does not match template declaration `DeducedParameterType(T)`
/home/luis/.local/bin/../import/std/sumtype.d(418): Error: template instance `DeducedParameterType!(inout(Argument))` does not match template declaration `DeducedParameterType(T)`
/home/luis/.local/bin/../import/std/sumtype.d(418): Error: template instance `DeducedParameterType!(inout(SubCommand))` does not match template declaration `DeducedParameterType(T)`
/home/luis/.local/bin/../import/std/sumtype.d(418): Error: template instance `DeducedParameterType!(inout(Unknown))` does not match template declaration `DeducedParameterType(T)`
/home/luis/.local/bin/../import/std/sumtype.d(418): Error: template instance `DeducedParameterType!(inout(Argument))` does not match template declaration `DeducedParameterType(T)`
ljmf00-wekaio commented 1 month ago

I've seen other weird issues on compiler upgrades at Weka codebase, with type implicit conversions, so compiler certainly got weirder. e.g. switch cases with string are no longer CTFEable with null, as it now says null of typetypeof(null) is not implicitly convertible to type string, which, in reality, it is. Non CTFE compilation works, but for other types implicit conversion got broken too. Need to find a simple testcase to report to issues.dlang.org.

@JohanEngelen can confirm these evidences.

pbackus commented 1 month ago

The only recent change to std.sumtype is https://github.com/dlang/phobos/pull/8933

ljmf00-wekaio commented 1 month ago

So, my predictions is that there's some regression in the compiler. I'll try to prove it.

andrey-zherikov commented 1 month ago

@ljmf00-wekaio Do you have test case that I can compile? What argparse version do you use? What OS?

PS I checked both 1.37.0 and 1.38.0 in CI build and everything was successfully built.

JohanEngelen commented 1 day ago

@ljmf00-wekaio It appears to be related by wtracer's own implementation of SumType. If I remove that code and use std.sumtype.SumType instead, things do compile again after commenting-out code that uses typeIndex (Phobos's std.sumtype.SumType does not expose tag/typeIndex)...

Edit: it is very strange that you cannot ask a SumType what type it holds... So I don't know how to rewrite the code that uses typeIndex.

ljmf00-wekaio commented 12 hours ago

@JohanEngelen Thanks for the investigating it! oh, so its not failing on argparse then? Should we close this here then?

Regarding the `SumType` on Phobos vs our implementation: I had a few discussions on how we should have more freedom on `SumType` from Phobos, not only `tag`/`typeIndex` but a way to bypass `get` checks (an unsafe way for trusted code), but it seems they prefer to break the type system internally and provide less APIs to the end user to ensure the user don't do certain pitfalls, which I understand the goal but I don't necessarily agree with it fully. The major reason to have our own copy is also because `match` function takes ridiculous amount of memory and compilation-time, in the scale of hundreds of GB and minutes just to compile a 30 type `SumType`, specially when SumType's have SumType's inside. It seems `match` grows compiler resources exponentially, for `O(N^K), where N is the number of expanded types (all types including inside SumTypes), and K is the max depth of SumType's "wraps". I also tried to suggest a change about this, but got rejected, because it doesn't seem to work for a generic case. I believe I should have explored this further tho, but I didn't have much time either, it works for my case tho. Maybe this is something you can re-discuss with @pbackus and @atilaneves, but I don't have much energy trying to upstream things to Phobos when they have a strong biased opinion about it. This expands to so many things we have on `weka.lib` e.g. that newcomers are baffled that X or Y is not present on the standard library. I think, in the end, it's the fundamental reason to think about yet another Phobos version.
ljmf00-wekaio commented 11 hours ago

@JohanEngelen I can't see why this is own SumType implementation tho, the path is .../import/std/sumtype.d, see the errors:

/opt/hostedtoolcache/ldc2/1.38.0/x64/ldc2-1.38.0-linux-x86_64/bin/../import/std/sumtype.d(418): Error: template instance `DeducedParameterType!(inout(Unknown))` does not match template declaration `DeducedParameterType(T)`
/opt/hostedtoolcache/ldc2/1.38.0/x64/ldc2-1.38.0-linux-x86_64/bin/../import/std/sumtype.d(418): Error: template instance `DeducedParameterType!(inout(Argument))` does not match template declaration `DeducedParameterType(T)`
/opt/hostedtoolcache/ldc2/1.38.0/x64/ldc2-1.38.0-linux-x86_64/bin/../import/std/sumtype.d(418): Error: template instance `DeducedParameterType!(inout(SubCommand))` does not match template declaration `DeducedParameterType(T)`
/opt/hostedtoolcache/ldc2/1.38.0/x64/ldc2-1.38.0-linux-x86_64/bin/../import/std/sumtype.d(418): Error: template instance `DeducedParameterType!(inout(Unknown))` does not match template declaration `DeducedParameterType(T)`
/opt/hostedtoolcache/ldc2/1.38.0/x64/ldc2-1.38.0-linux-x86_64/bin/../import/std/sumtype.d(418): Error: template instance `DeducedParameterType!(inout(Argument))` does not match template declaration `DeducedParameterType(T)`
/opt/hostedtoolcache/ldc2/1.38.0/x64/ldc2-1.38.0-linux-x86_64/bin/../import/std/sumtype.d(418): Error: template instance `DeducedParameterType!(inout(SubCommand))` does not match template declaration `DeducedParameterType(T)`
/opt/hostedtoolcache/ldc2/1.38.0/x64/ldc2-1.38.0-linux-x86_64/bin/../import/std/sumtype.d(418): Error: template instance `DeducedParameterType!(inout(Unknown))` does not match template declaration `DeducedParameterType(T)`
/opt/hostedtoolcache/ldc2/1.38.0/x64/ldc2-1.38.0-linux-x86_64/bin/../import/std/sumtype.d(418): Error: template instance `DeducedParameterType!(inout(Argument))` does not match template declaration `DeducedParameterType(T)`

Unknown, SubCommand and Argument are also types from argparse. Also, this seem to only trigger on release prechecks:

Debug precheck (x86_64)...
Release precheck (x86_64)...
<errors>
JohanEngelen commented 8 hours ago

It could be related to some compiler bug where it mistakes one sumtype for the other, or does something else weird... Perhaps I should just dustmite and see what comes out.