Skip to content
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

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

Open
ljmf00-wekaio opened this issue Jun 16, 2024 · 13 comments
Open

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

ljmf00-wekaio opened this issue Jun 16, 2024 · 13 comments

Comments

@ljmf00-wekaio
Copy link

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
Copy link
Author

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 type typeof(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
Copy link

pbackus commented Jun 16, 2024

The only recent change to std.sumtype is dlang/phobos#8933

@ljmf00-wekaio
Copy link
Author

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

@andrey-zherikov
Copy link
Owner

@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
Copy link

JohanEngelen commented Jul 24, 2024

@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
Copy link
Author

@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
Copy link
Author

ljmf00-wekaio commented Jul 25, 2024

@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
Copy link

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.

@ljmf00-wekaio
Copy link
Author

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.

I'm making a few compiler changes regarding this error, to make it more clear to debug. Will xref here.

@ljmf00-wekaio
Copy link
Author

xref: dlang/dmd#16755

@ljmf00-wekaio
Copy link
Author

After the patch:

/usr/local/include/d/std/sumtype.d(418): Error: template instance `DeducedParameterType!(inout(Unknown))` does not match template declaration `DeducedParameterType(T)`
/usr/local/include/d/std/sumtype.d(418):        instantiated from here: `DeducedParameterType!(inout(Unknown))`
/usr/local/include/d/std/traits.d(9232):        Candidate match: DeducedParameterType(T)

@ljmf00
Copy link

ljmf00 commented Jul 26, 2024

I confirmed this works dlang/phobos#9031 .

@andrey-zherikov
Copy link
Owner

I was wondering why error message has Unknown, Argument and SubCommand only although there are few other places where SumType is used. Then I realized that I forgot to put private to these members so I fixed it in #167. IDK whether this will address the issue but the change is good anyway.

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

No branches or pull requests

5 participants