So I recently encountered a very strange bug when I introduced a new field to a type aliased record. I have two functions which each build this record in slightly different ways, but are nearly identical. However, one of my functions crashes the compiler when I include assignment of this field in the function. It crashes with the following message:
thread 'main' panicked at crates/compiler/gen_llvm/src/llvm/build.rs:5764:19:
Error in alias analysis: error in module ModName("UserApp"), function definition FuncName("\x0c\x00\x00\x00\x18\x00\x00\x00\xd3m\xe6\x0f\xa9\xd7\x9c\x94"), definition of value binding ValueId(12): could not find func in module ModName("UserApp") with name FuncName("<\x00\x00\x00\x1a\x00\x00\x00\xb8\x89\xb1cv\xbb\x90\x8e")
My function is below. Note that the field which causes the crash is currently commented out. Also note: as it currently stands, with the value is being assigned to a placeholder at the top of the function but not included in the record, I do not get the compiler panic. The compiler simply complains about my record not matching the expected return type. The crash only occurs if I include the value in the record.
## Build the request body to be sent in the Http request using a prompt string
buildPromptRequestBody : Client, Str -> RequestBody
buildPromptRequestBody = \client, prompt ->
responseFormat = client.responseFormat
{
model: client.model,
messages: Option.none {},
prompt: Option.some prompt,
temperature: client.temperature,
topA: client.topA,
topP: client.topP,
topK: client.topK,
frequencyPenalty: client.frequencyPenalty,
presencePenalty: client.presencePenalty,
repetitionPenalty: client.repetitionPenalty,
minP: client.minP,
seed: client.seed,
maxTokens: client.maxTokens,
provider: { order: client.providerOrder },
# responseFormat,
models: client.models,
route: client.route,
}
I have a second function which is nearly identical, but instead of prompt, it assigns messages. The second function has no problems with the responseFormat
record field, and is assigning it without issue - I can leave that line in, and no crash is encountered.
responseFormat
is of the type Option { type: Str}
, where Option is the opaque from roc-json.responseFormat: Option.some { type: "" }
crashes as described.responseFormat: Option.some { type: "", extra: "" }
does not crash.responseFormat: Option.some { type: 0 }
does not crash.responseFormat: Option.none {}
crashes with a new panic message.Here is the code for Json.Option:
Option val := [Some val, None] implements [ Eq, Decoding { decoder: decoderRes }, Encoding { toEncoder: toEncoderRes } ]
none = \{} -> @Option (None)
some = \val -> @Option (Some val)
One more detail: after splitting my two functions described in my original message into separate modules, both produce the same crash.
TLDR:
There appears to be a bug in the compiler that does not like:
Option { field: Str }
as a type.
I need to do more troubleshooting, I have this same type elsewhere in code and working fine (IE, its in my client). Not sure what differentiates, since both are records with a field of this type.
Last updated: Jul 06 2025 at 12:14 UTC