www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - CompilerInvocationException

reply guacs <guacs gmail.com> writes:
Hi,

I'm facing this error and I'm not sure why. For context, I'm 
trying to build a parser for simple mathematical expressions 
given as strings i.e. "1 + 2". My main experience is in Python 
and I wanted to explore the D language so I thought of doing this 
small project as an exercise. The source code is 
[here](https://github.com/VisakhChekur/meval/tree/error/source).

NOTE: The error is happening when I'm using the SumType and I 
suspect that I'm using it incorrectly.

The error can be seen below:
```
❯ dub run --vverbose --config=executable
Using dub registry url 'https://code.dlang.org/'
'git --git-dir=/home/guacs/projects/meval/.git describe --long 
--tags' failed with exit code 128: fatal: No names found, cannot 
describe anything.
Determined package version using GIT: meval ~main
Collecting dependencies for meval
Scanning local packages...
iterating dir /home/guacs/.dub/packages/
iterating dir /home/guacs/.dub/packages/ entry libddoc-0.8.0
iterating dir /home/guacs/.dub/packages/ entry 
emsi_containers-0.9.0
iterating dir /home/guacs/.dub/packages/ entry libdparse-0.22.0
iterating dir /home/guacs/.dub/packages/ entry inifiled-1.3.3
iterating dir /home/guacs/.dub/packages/ entry silly-1.1.1
iterating dir /home/guacs/.dub/packages/ entry dunit-1.0.16
iterating dir /home/guacs/.dub/packages/ entry dcd-0.15.2
iterating dir /home/guacs/.dub/packages/ entry dscanner-0.14.0
   Found dependency silly 1.1.1
   Collecting dependencies for silly
Add config silly library
Add config meval unittest
Including meval unittest -> silly library
Add config meval executable
Including meval executable -> silly library
NON-PRIMARY: meval executable
Eliminating config executable for meval
     meval unittest -> silly library
Using configuration 'library' for silly
Using configuration 'unittest' for meval
Generating using build
Creating build generator.
Add config meval executable
Add config silly library
Add config meval unittest
Including meval unittest -> silly library
Including meval executable -> silly library
NON-PRIMARY: meval unittest
Eliminating config unittest for meval
     meval executable -> silly library
Using configuration 'executable' for meval
Using configuration 'library' for silly
Configuring target meval (executable /home/guacs/projects/meval 
meval)
deps: meval -> "silly"
   Configuring target without output silly
deps: silly ->
Configure dependencies of meval, deps:
Configuring dependent meval, deps:
     Starting Performing "debug" build using 
/home/guacs/dlang/dmd-2.102.1/linux/bin64/dmd for x86_64.
Target 
'/home/guacs/.dub/cache/meval/~main/build/executable-debug-linux.posix-x86_64-dmd_v2.102.1-BA8BA57C46223F272147C400395CD614568C52989F3A410949B
6AC73D142207/meval' doesn't exist, need rebuild.
     Building meval ~main: building configuration [executable]
[cwd=/home/guacs/projects/meval] 
/home/guacs/dlang/dmd-2.102.1/linux/bin64/dmd -c 
-of../../.dub/cache/meval/~main/build/executable-debug-linux.posix-x86_64-dmd_v2.102.1-BA8BA57C46223F272147C400395CD614568C52989F3A410949BE
AC73D142207/meval.o -debug -g -w -version=Have_meval -version=Have_silly
-Isource/ -I../../.dub/packages/silly-1.1.1/silly source/app.d source/enums.d
source/evaluator.d source/exceptions.d source/expr.d source/parser.d
source/tokenizer.d source/utils.d ../../.dub/packages/silly-1.1.1/silly/silly.d
-vcolumns
Error: unknown, please file report on issues.dlang.org
FAIL 
../../.dub/cache/meval/~main/build/executable-debug-linux.posix-x86_64-dmd_v2.102.1-BA8BA57C46223F272147C400395CD614568C52989F3A
10949BE6AC73D142207 meval executable
Error /home/guacs/dlang/dmd-2.102.1/linux/bin64/dmd failed with 
exit code 1.
Full exception: 
dub.compilers.compiler.CompilerInvocationException source/dub/compil
rs/compiler.d(170): /home/guacs/dlang/dmd-2.102.1/linux/bin64/dmd failed with
exit code 1.
----------------
??:? [0x5632bfdc21e6]
??:? [0x5632bfdc3cf6]
??:? [0x5632bfda4cef]
??:? [0x5632bfca798a]
??:? [0x5632bfc526ea]
??:? [0x5632bfc58b5a]
??:? [0x5632bfc2eefa]
??:? [0x5632bfc2cb79]
??:? [0x5632bfc2980f]
??:? [0x5632bfc28e41]
??:? [0x5632bfc27e05]
??:? [0x5632bfa5e1a4]
??:? [0x5632bfd3fcd2]
??:? [0x5632bfd40a3d]
??:? [0x5632bfd38b06]
??:? [0x5632bfda49db]
??:? [0x5632bfda48d5]
??:? [0x5632bfda472d]
??:? __libc_start_main [0x7f3bec33f082]
??:? [0x5632bfa25c49]
```

Compiler/DUB details:
```
❯ dub --version
DUB version 1.31.1, built on Feb 15 2023

❯ dmd --version
DMD64 D Compiler v2.102.1
Copyright (C) 1999-2023 by The D Language Foundation, All Rights 
Reserved written by Walter Bright
```

Also, I'm using WSL2 on Windows 10 and the Linux version is: 
`Ubuntu 20.04.5 LTS`
Feb 25 2023
parent reply Paul Backus <snarwin gmail.com> writes:
On Sunday, 26 February 2023 at 02:33:21 UTC, guacs wrote:
 NOTE: The error is happening when I'm using the SumType and I 
 suspect that I'm using it incorrectly.
I am not sure whether this is the specific error that is causing your problem, but there is a mistake in your use of `SumType` in `expr.d`. [1] On line 10, you declare alias Expression = SumType!(Number, Binary, Unary, Group); Later, you declare `Binary` and `Unary` like this: struct Binary { Expression leftOperand; Expression rightOperand; Token operator; // etc. } struct Unary { Expression operand; Token operator; // etc. } Since `Expression` contains `Binary` and `Unary`, and `Binary` and `Unary` contain `Expression`, that means `Expression` contains itself--which is not allowed, because it would result in `Expression.sizeof` being infinite. The fix is to change `Binary` and `Unary` so that they contain *pointers* to `Expression`, like this: struct Binary { Expression* leftOperand; // pointer Expression* rightOperand; // pointer Token operator; // etc. } struct Unary { Expression* operand; // pointer Token operator; // etc. } [1] https://github.com/VisakhChekur/meval/blob/error/source/expr.d
Feb 25 2023
parent reply ryuukk_ <ryuukk.dev gmail.com> writes:
On Sunday, 26 February 2023 at 07:11:55 UTC, Paul Backus wrote:
 Since `Expression` contains `Binary` and `Unary`, and `Binary` 
 and `Unary` contain `Expression`, that means `Expression` 
 contains itself--which is not allowed, because it would result 
 in `Expression.sizeof` being infinite.
It should display the proper error message then
Feb 26 2023
next sibling parent ryuukk_ <ryuukk.dev gmail.com> writes:
On Sunday, 26 February 2023 at 14:17:50 UTC, ryuukk_ wrote:
 On Sunday, 26 February 2023 at 07:11:55 UTC, Paul Backus wrote:
 Since `Expression` contains `Binary` and `Unary`, and `Binary` 
 and `Unary` contain `Expression`, that means `Expression` 
 contains itself--which is not allowed, because it would result 
 in `Expression.sizeof` being infinite.
It should display the proper error message then
Example of error message for this particular error with zig: ``` An error occurred: /tmp/playground921468696/play.zig:4:20: error: union 'play.Expression' depends on itself const Expression = union(enum) { ^~~~~ /tmp/playground921468696/play.zig:23:5: note: while checking this field expr: Expression ^~~~~~~~~~~~~~~~ /tmp/playground921468696/play.zig:8:5: note: while checking this field group: Group, ^~~~~~~~~~~~ referenced by: callMain: /usr/local/bin/lib/std/start.zig:604:17 initEventLoopAndCallMain: /usr/local/bin/lib/std/start.zig:548:51 remaining reference traces hidden; use '-freference-trace' to see all reference traces ``` I don't particularly enjoy zig, but they tell us how errors should be reported to the users, they do it very nicely
Feb 26 2023
prev sibling parent Paul Backus <snarwin gmail.com> writes:
On Sunday, 26 February 2023 at 14:17:50 UTC, ryuukk_ wrote:
 On Sunday, 26 February 2023 at 07:11:55 UTC, Paul Backus wrote:
 Since `Expression` contains `Binary` and `Unary`, and `Binary` 
 and `Unary` contain `Expression`, that means `Expression` 
 contains itself--which is not allowed, because it would result 
 in `Expression.sizeof` being infinite.
It should display the proper error message then
Normally when you do this you *will* get a proper error message. For example, attempting to compile the following program: import std.sumtype; alias Test = SumType!S; struct S { Test st; } ...will give you this error message: /usr/include/dmd/phobos/std/sumtype.d(309): Error: union `std.sumtype.SumType!(S).SumType.Storage` no size because of forward reference forum.d(3): Error: template instance `std.sumtype.SumType!(S)` error instantiating I'm not sure why OP didn't get a proper error message. It's possible that there's some other issue with their code that stops the error message from being printed. I did not attempt to reproduce their error myself.
Feb 26 2023