# Internal error - type does not have a visitor

**URL:** <https://community.zeek.org/t/internal-error-type-does-not-have-a-visitor/6856>\
**Category:** Spicy\
**Created:** [December 12, 2022, 11:57am UTC](https://community.zeek.org/t/internal-error-type-does-not-have-a-visitor/6856 "2022-12-12T11:57:10Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kyth](https://avatars.discourse-cdn.com/v4/letter/k/da6949/32.png) [@Kyth](https://community.zeek.org/u/Kyth)\
**Post date:** [December 12, 2022, 11:57am UTC](https://community.zeek.org/t/internal-error-type-does-not-have-a-visitor/6856/1 "2022-12-12T11:57:10Z")

</div>

Hello there. I’m new to zeek and to coding in general.  
What does that error mean?

```auto
[internal-error] t104.spicy:740:12-743:2: codegen: type T104::QOS does not have a visitor

```

The code that caused the error :

```auto
type QOS = bitfield(8) {
    ql : 0..6; 
    se : 7;  
};

```

---

<div class="post-metadata">

**Author:** ![Benjamin\_Bannier](https://yyz1.discourse-cdn.com/flex011/user_avatar/community.zeek.org/benjamin_bannier/32/595_2.png) [@Benjamin\_Bannier](https://community.zeek.org/u/Benjamin_Bannier)\
**Post date:** [December 12, 2022, 12:05pm UTC](https://community.zeek.org/t/internal-error-type-does-not-have-a-visitor/6856/2 "2022-12-12T12:05:59Z")

</div>

I suspect the error message you are seeing also mentions that this is an `internal-error` somewhere. In general `internal-error`s are probably due to Spicy bugs.

The concrete issue you are seeing here is

> <https://github.com/zeek/spicy/issues/1032>
>
> Currently the following code passes validation, but fails with an internal error… when compiled:
> 
> \`\`\`.r
> \# file: /tmp/bitfield.spicy
> module foo;
> 
> type X = bitfield(32) {
> x: 0..4;
> };
> \`\`\`
> 
> \`\`\`
> $ spicyc -j /tmp/bitfield.spicy
> || - spicy::type::Bitfield (bitset.spicy:3:10-5:2) (non-const) (type-id: foo::X) (resolved) \[@s:7f81cb412c60\]
> || - type::UnsignedInteger \<width="32"\> (bitset.spicy:3:10-5:2) (const) (resolved) \[@t:7f81cb411e70\]
> || - type::Tuple \<wildcard="false"\> (bitset.spicy:3:10-5:2) (const) (resolved) \[@t:7f81cb48ee30\]
> || - type::tuple::Element (bitset.spicy:3:10-5:2) \[@t:7f81cb48f120\]
> || - ID \<name="x"\> (bitset.spicy:4:5) \[@i:7f81cb48e010\]
> || - type::UnsignedInteger \<width="32"\> (const) (resolved) \[@t:7f81cb4120e0\]
> || - spicy::type::bitfield::Bits \<field\_width="32" lower="0" upper="4"\> (bitset.spicy:4:5) \[@s:7f81cb412c00\]
> || - ID \<name="x"\> (bitset.spicy:4:5) \[@i:7f81cb412240\]
> || - declaration::Expression %4 \<linkage="private"\> (bitset.spicy:4:5) \[canon-id: foo::X::\_\_dd\] \[@d:7f81cb412580\]
> || - ID \<name="\_\_dd"\> \[@i:7f81cb4121d0\]
> || - expression::Keyword \<kind="$$"\> (non-const) (resolved) \[@e:7f81cb412170\]
> || - type::UnsignedInteger \<width="32"\> (const) (resolved) \[@t:7f81cb4120e0\]
> || - node::None (bitset.spicy:4:5) \[@n:7f81cb405fb0\]
> || - type::UnsignedInteger \<width="32"\> (const) (resolved) \[@t:7f81cb4120e0\]
> || - node::None (bitset.spicy:4:5) \[@n:7f81cb405fb0\]
> || \[internal-error\] /private/tmp/bitset.spicy:3:10-5:2: codegen: type foo::X does not have a visitor
> || 
> || --- Aborting
> || # 0 libhilti.dylib 0x000000010fef0696 \_ZN5hilti2rt9BacktraceC1Ev + 118
> || # 1 libhilti.dylib 0x000000010f87576b \_ZN5hilti4util20abort\_with\_backtraceEv + 139
> || # 2 libhilti.dylib 0x000000010f86e6f7 \_ZN5hilti6Logger13internalErrorERKNSt3\_\_112basic\_stringIcNS1\_11char\_traitsIcEENS1\_9allocatorIcEEEERKNS\_8LocationE + 55
> || # 3 libhilti.dylib 0x000000010f8fdb8a \_ZN5hilti6Logger13internalErrorINS\_4TypeELPv0EEEvNSt3\_\_112basic\_stringIcNS4\_11char\_traitsIcEENS4\_9allocatorIcEEEERKT\_ + 90
> || # 4 libhilti.dylib 0x000000010f8f97d4 \_ZN5hilti6detail7CodeGen7compileERKNS\_4TypeENS0\_7codegen9TypeUsageE + 2244
> || # 5 libhilti.dylib 0x000000010f895ef5 \_ZN5hilti6detail7visitor7VisitorIvN12\_GLOBAL\_\_N\_114GlobalsVisitorENS\_4NodeELNS1\_5OrderE0EE8dispatchERKS5\_ + 4053
> || # 6 libhilti.dylib 0x000000010f87f10b \_ZN12\_GLOBAL\_\_N\_114GlobalsVisitor15addDeclarationsEPN5hilti6detail7CodeGenERKNS1\_4NodeERKNS1\_2IDEPNS2\_3cxx4UnitEb + 219
> || # 7 libhilti.dylib 0x000000010f87c26b \_ZN5hilti6detail7CodeGen13compileModuleERNS\_4NodeEPNS\_4UnitEb + 891
> || # 8 libhilti.dylib 0x000000010fa50418 \_ZN5hilti4Unit7codegenEv + 744
> || # 9 libhilti.dylib 0x000000010f9f862f \_ZN5hilti6Driver13\_codegenUnitsEv + 959
> || # 10 libhilti.dylib 0x000000010f9f96f7 \_ZN5hilti6Driver12compileUnitsEv + 1447
> || # 11 libhilti.dylib 0x000000010f9fa2bd \_ZN5hilti6Driver7compileEv + 45
> || # 12 libhilti.dylib 0x000000010f9f9df9 \_ZN5hilti6Driver3runEv + 185
> || # 13 spicyc 0x000000010efa0467 main + 311
> || # 14 libdyld.dylib 0x00007fff72201cc9 start + 1
> || 
> \`\`\`
> 
> We should probably reject using a type decl with a \`bitfield\` during validation, or alternatively add proper support for it.

A possible workaround is to wrap your `bitfield` type declaration in a `unit` similar to [what I described in the issue](https://github.com/zeek/spicy/issues/1032#issuecomment-1328854535), e.g.,

```auto
type QOS = unit {
	x: bitfield(8) {
		ql: 0..6;
		se: 7;
	};
} &convert=self.x;

```

The trick here is that a `unit` allows us to introduce a new name for a parsing construct, but we can remove that extra level of indirection again with `&convert=self.x`.

---

<div class="post-metadata">

**Author:** ![Kyth](https://avatars.discourse-cdn.com/v4/letter/k/da6949/32.png) [@Kyth](https://community.zeek.org/u/Kyth)\
**Post date:** [December 12, 2022, 1:12pm UTC](https://community.zeek.org/t/internal-error-type-does-not-have-a-visitor/6856/3 "2022-12-12T13:12:52Z")

</div>

@Benjamin_Bannier  
Thanks a lot for your helpful and quick responses!

Now I got the next error:

```auto
fatal error: error during compilation: <Spicy Plugin for Zeek>: JIT compilation failed

```

What could cause that error?

---

<div class="post-metadata">

**Author:** ![Benjamin\_Bannier](https://yyz1.discourse-cdn.com/flex011/user_avatar/community.zeek.org/benjamin_bannier/32/595_2.png) [@Benjamin\_Bannier](https://community.zeek.org/u/Benjamin_Bannier)\
**Post date:** [December 12, 2022, 1:14pm UTC](https://community.zeek.org/t/internal-error-type-does-not-have-a-visitor/6856/4 "2022-12-12T13:14:12Z")

</div>

Is this the full output you are seeing?

---

<div class="post-metadata">

**Author:** ![Kyth](https://avatars.discourse-cdn.com/v4/letter/k/da6949/32.png) [@Kyth](https://community.zeek.org/u/Kyth)\
**Post date:** [December 12, 2022, 1:14pm UTC](https://community.zeek.org/t/internal-error-type-does-not-have-a-visitor/6856/5 "2022-12-12T13:14:36Z")

</div>

Yes, only that one line

---

<div class="post-metadata">

**Author:** ![Benjamin\_Bannier](https://yyz1.discourse-cdn.com/flex011/user_avatar/community.zeek.org/benjamin_bannier/32/595_2.png) [@Benjamin\_Bannier](https://community.zeek.org/u/Benjamin_Bannier)\
**Post date:** [December 12, 2022, 1:21pm UTC](https://community.zeek.org/t/internal-error-type-does-not-have-a-visitor/6856/6 "2022-12-12T13:21:16Z")

</div>

This would mean that the C++ compiler which we start to JIT code returned an error, but gave no output.

One scenario where that could happen is if the compiler was killed by the OS since it ran out of available RAM. You could force Spicy to use at most a single C++ compiler process by setting the in your environment `export HILTI_JIT_PARALLELISM=1`, see [6. Toolchain — Spicy v1.6.0-dev.147](https://docs.zeek.org/projects/spicy/en/latest/toolchain.html?highlight=HILTI_JIT_PARALLELISM#spicyc).

---

<div class="post-metadata">

**Author:** ![Kyth](https://avatars.discourse-cdn.com/v4/letter/k/da6949/32.png) [@Kyth](https://community.zeek.org/u/Kyth)\
**Post date:** [December 12, 2022, 1:48pm UTC](https://community.zeek.org/t/internal-error-type-does-not-have-a-visitor/6856/7 "2022-12-12T13:48:36Z")

</div>

I added 3gb ram to VM(4bg total) this time and tried to run zeek again. Now it’s the same error but with the termination message:

```auto
c++: fatal error: Killed signal terminated program cc1plus
compilation terminated.
fatal error: error during compilation: <Spicy Plugin for Zeek>: JIT compilation failed

```

I think it should be the same as previous attempt. I dont know if it’s important but it took around 10 minutes of compiling before error showed up. Should I add more ram and try again?

---

<div class="post-metadata">

**Author:** ![Benjamin\_Bannier](https://yyz1.discourse-cdn.com/flex011/user_avatar/community.zeek.org/benjamin_bannier/32/595_2.png) [@Benjamin\_Bannier](https://community.zeek.org/u/Benjamin_Bannier)\
**Post date:** [December 12, 2022, 1:55pm UTC](https://community.zeek.org/t/internal-error-type-does-not-have-a-visitor/6856/8 "2022-12-12T13:55:59Z")

</div>

This is the same kind of error.

It is really hard to tell what is going on exactly with what you shared, but I would expect a single JIT job to need between 500 MB (if using Clang), and 2-3GB (if using GCC). You can check which compiler Spicy uses by default by running `spicy-config --cxx`. Alternatively, you can override the compiler by setting `HILTI_CXX`.

If this does not help, also try setting `HILTI_JIT_PARALLELISM=1` like I suggested above. If you are running Spicy before 1.5.0 you need to set `HILTI_JIT_SEQUENTIAL=1` instead, but you should not use any version that old.

---

<div class="post-metadata">

**Author:** ![Kyth](https://avatars.discourse-cdn.com/v4/letter/k/da6949/32.png) [@Kyth](https://community.zeek.org/u/Kyth)\
**Post date:** [December 12, 2022, 2:12pm UTC](https://community.zeek.org/t/internal-error-type-does-not-have-a-visitor/6856/9 "2022-12-12T14:12:36Z")

</div>

`spicy-config --cxx` showed  
`/usr/bin/c++` as an output.  
Could you tell me please exaclty how to set `HILTI_JIT_PARALLELISM=1` ? Sorry, I’m completely new to all that.

I got the latest stable version of zeek couple weeks ago so I think in terms of version of spicy plugin it should be the latest one.

---

<div class="post-metadata">

**Author:** ![Benjamin\_Bannier](https://yyz1.discourse-cdn.com/flex011/user_avatar/community.zeek.org/benjamin_bannier/32/595_2.png) [@Benjamin\_Bannier](https://community.zeek.org/u/Benjamin_Bannier)\
**Post date:** [December 12, 2022, 2:26pm UTC](https://community.zeek.org/t/internal-error-type-does-not-have-a-visitor/6856/10 "2022-12-12T14:26:14Z")

</div>

Spicy interprets a number of environment variables like e.g., `HILTI_JIT_PARALLELISM`. If you are running from a shell (e.g., Bash in some terminal), you can set them for your shell session and all processes started from it by running the following in your shell

```auto
export HILTI_JIT_PARALLELISM=1

```

You might want to familiarize yourself with working with a shell. There are a number of tutorials for that, e.g., this articel on variables in Bash on TLDP

[https://tldp.org/LDP/Bash-Beginners-Guide/html/sect\_03\_02.html](https://tldp.org/LDP/Bash-Beginners-Guide/html/sect_03_02.html)

---

<div class="post-metadata">

**Author:** ![Kyth](https://avatars.discourse-cdn.com/v4/letter/k/da6949/32.png) [@Kyth](https://community.zeek.org/u/Kyth)\
**Post date:** [December 12, 2022, 2:32pm UTC](https://community.zeek.org/t/internal-error-type-does-not-have-a-visitor/6856/11 "2022-12-12T14:32:26Z")

</div>

Thank you very much for your time and help!
