Stream: contributing

Topic: Decimal max and to


view this post on Zulip Wizard ish (Nov 27 2024 at 23:55):

Anyone else working on #5446 or #5486?

view this post on Zulip Luke Boswell (Nov 28 2024 at 00:00):

I don't think anyone is

view this post on Zulip Luke Boswell (Nov 28 2024 at 00:00):

Want me to assign them to you?

view this post on Zulip Wizard ish (Nov 28 2024 at 00:00):

yes :)

view this post on Zulip Luke Boswell (Nov 28 2024 at 00:00):

Oh, wait I need a comment again :smiley:

view this post on Zulip Wizard ish (Nov 29 2024 at 14:50):

What is the internal form of the toXChecked functions?

view this post on Zulip Anton (Nov 29 2024 at 14:59):

internal form?

view this post on Zulip Wizard ish (Nov 29 2024 at 16:17):

Yeah, so what is the actual data that should be returned.
Also, why are their both X_op functions in the llvm/lowlevel.rs as well as run_low_level

view this post on Zulip Anton (Nov 29 2024 at 16:34):

why are their both X_op functions in the llvm/lowlevel.rs as well as run_low_level

I'm a little confused, run_low_level is inside llvm/lowlevel.rs

view this post on Zulip Wizard ish (Nov 29 2024 at 17:34):

Sorry, these questions were a complete mess. So, there are functions like toI32Checked, which returns Result I32 [OutOfBounds], so what does the [OutOfBounds] correspond to, is it a tag?
Second question, the run_low_level function is indeed in llvm/lowlevel.rs. However there is also build_int_unary_op, build_int_binary_op, among others. Why is this? What should be put into run_low_level and what should be made into an op?
Hopefully this clears up the questions about the questions.

view this post on Zulip Anton (Nov 29 2024 at 18:19):

so what does the [OutOfBounds] correspond to, is it a tag?

Yes, OutOfBounds is a tag

view this post on Zulip Wizard ish (Nov 29 2024 at 18:20):

i see, and when should one use the _op functions as opposed to the run_low_level

view this post on Zulip Wizard ish (Nov 29 2024 at 18:20):

is it just a way to seperate the code out

view this post on Zulip Anton (Nov 29 2024 at 18:22):

Yes, I believe so

view this post on Zulip Wizard ish (Nov 29 2024 at 18:23):

ok got it

view this post on Zulip Wizard ish (Nov 30 2024 at 20:48):

Hey anyone know why running

app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.16.0/O00IPk-Krg_diNS2dVWlI0ZQP794Vctxzv0ha96mK0E.tar.br" }

import pf.Stdout

main =
    numF64 = 1701411834604692531795.748
    numDec = Num.toDecChecked numF64
    Stdout.line! (Inspect.toStr numDec)

Gives this error

An internal compiler expectation was broken.
This is definitely a compiler bug.
Please file an issue here: <https://github.com/roc-lang/roc/issues/new/choose>
Invalid decimal for float literal = 1701411834604692531795.748. This should be a type error!
Location: crates/compiler/mono/src/ir/literal.rs:115:25

(Yes I'm implementing the decimal function, but even removing it still gives this error)

view this post on Zulip Luke Boswell (Nov 30 2024 at 20:49):

but even removing it still gives this error

This breaks the same for me on main

app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.16.0/O00IPk-Krg_diNS2dVWlI0ZQP794Vctxzv0ha96mK0E.tar.br" }

import pf.Stdout

main =
    numF64 = 1701411834604692531795.748

    Stdout.line! (Inspect.toStr numF64)
An internal compiler expectation was broken.
This is definitely a compiler bug.
Please file an issue here: <https://github.com/roc-lang/roc/issues/new/choose>
Invalid decimal for float literal = 1701411834604692531795.748. This should be a type error!
Location: crates/compiler/mono/src/ir/literal.rs:115:25

view this post on Zulip Wizard ish (Nov 30 2024 at 20:50):

yeah thats what I'm saying

view this post on Zulip Luke Boswell (Nov 30 2024 at 20:50):

Changing it to 1701411834604692531795.748f64 works fine

view this post on Zulip Luke Boswell (Nov 30 2024 at 20:50):

The default number type is Dec so I imagine that is relevant here

view this post on Zulip Wizard ish (Nov 30 2024 at 20:52):

Do you get this or is this a bug in my addition?

An internal compiler expectation was broken.
This is definitely a compiler bug.
Please file an issue here: <https://github.com/roc-lang/roc/issues/new/choose>
Undefined Symbol in relocation, (+6360, Relocation { kind: PltRelative, encoding: Generic, size: +20, target: Symbol(SymbolIndex(+a6)), addend: +fffffffffffffffc, implicit_addend: false }): Ok(Symbol { name: "__fixdfti", address: +0, size: +0, kind: Unknown, section: Undefined, scope: Unknown, weak: false, flags: Elf { st_info: +10, st_other: +0 } })
Location: crates/linker/src/elf.rs:1452:25

view this post on Zulip Luke Boswell (Nov 30 2024 at 20:52):

This is where it's failing

LayoutRepr::Builtin(Builtin::Decimal) => {
    let dec = match RocDec::from_str(num_str) {
        Some(d) => d,
        None => internal_error!(
            "Invalid decimal for float literal = {}. This should be a type error!",
            num_str
        ),
    };
    NumLiteral::Decimal(dec.to_ne_bytes())
}

view this post on Zulip Luke Boswell (Nov 30 2024 at 20:53):

Do you get this or is this a bug in my addition?

I haven't seen that

My guess is that may be unrelated though... that looks like a linker bug

view this post on Zulip Wizard ish (Nov 30 2024 at 20:53):

ok so that's my bug

view this post on Zulip Wizard ish (Nov 30 2024 at 20:54):

app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.16.0/O00IPk-Krg_diNS2dVWlI0ZQP794Vctxzv0ha96mK0E.tar.br" }

import pf.Stdout

main =
    numF64 = 1701411834604692531795.748f64
    Stdout.line! (Inspect.toStr numF64)
    numDec = Num.toDec numF64
    Stdout.line! (Inspect.toStr numDec)

view this post on Zulip Wizard ish (Nov 30 2024 at 20:54):

With this

view this post on Zulip Luke Boswell (Nov 30 2024 at 20:55):

Can you represent that number as a F64?

» 1701411834604692531795.748f64

1701411834604692400000 : F64

view this post on Zulip Wizard ish (Nov 30 2024 at 20:55):

wdym

view this post on Zulip Luke Boswell (Nov 30 2024 at 20:56):

When I put it in the repl it's getting cut off at the 4, rounding and losing precision

view this post on Zulip Wizard ish (Nov 30 2024 at 20:57):

It's definitly in the range, it's probably just not high percision that far from 0

view this post on Zulip Wizard ish (Nov 30 2024 at 21:02):

Ok yeah i don't think it's related

view this post on Zulip Wizard ish (Nov 30 2024 at 21:02):

but ima check anyway

view this post on Zulip Wizard ish (Nov 30 2024 at 21:07):

Ok yeah it's a bug in another part of the code

view this post on Zulip Brendan Hansknecht (Nov 30 2024 at 21:12):

We should return a constant out of range error if the constant is too large to be converted into a Dec

view this post on Zulip Brendan Hansknecht (Nov 30 2024 at 21:12):

So there is a missing error that needs to be wired up

view this post on Zulip Brendan Hansknecht (Nov 30 2024 at 21:13):

So that error is correct, it just isn't pretty

view this post on Zulip Wizard ish (Nov 30 2024 at 21:13):

No, it is a valid F64, Roc is just saying it isn't

view this post on Zulip Brendan Hansknecht (Nov 30 2024 at 21:14):

It isn't an f64

view this post on Zulip Brendan Hansknecht (Nov 30 2024 at 21:14):

It's a Dec.

view this post on Zulip Brendan Hansknecht (Nov 30 2024 at 21:14):

And it isn't a valid Dec

view this post on Zulip Wizard ish (Nov 30 2024 at 21:15):

At what point?

view this post on Zulip Brendan Hansknecht (Nov 30 2024 at 21:16):

Oh, am I mixed up, I thought it was too large to be a valid Dec and that is the failuer

view this post on Zulip Wizard ish (Nov 30 2024 at 21:16):

oh there was a mistake, but it's still invalid even if I switch toDec to toDecChecked

view this post on Zulip Brendan Hansknecht (Nov 30 2024 at 21:16):

If it fits in a Dec then it is a Dec parsing bug

view this post on Zulip Wizard ish (Nov 30 2024 at 21:17):

Even if its marked as a float?

view this post on Zulip Brendan Hansknecht (Nov 30 2024 at 21:18):

Wizard ish said:

Do you get this or is this a bug in my addition?

An internal compiler expectation was broken.
This is definitely a compiler bug.
Please file an issue here: <https://github.com/roc-lang/roc/issues/new/choose>
Undefined Symbol in relocation, (+6360, Relocation { kind: PltRelative, encoding: Generic, size: +20, target: Symbol(SymbolIndex(+a6)), addend: +fffffffffffffffc, implicit_addend: false }): Ok(Symbol { name: "__fixdfti", address: +0, size: +0, kind: Unknown, section: Undefined, scope: Unknown, weak: false, flags: Elf { st_info: +10, st_other: +0 } })
Location: crates/linker/src/elf.rs:1452:25

You probably need to explicit tell llvm not to Dead code eliminate that function. It's probably part of compiler rt.

view this post on Zulip Wizard ish (Nov 30 2024 at 21:18):

which func

view this post on Zulip Wizard ish (Nov 30 2024 at 21:18):

toDec?

view this post on Zulip Brendan Hansknecht (Nov 30 2024 at 21:19):

__fixdfti

view this post on Zulip Brendan Hansknecht (Nov 30 2024 at 21:21):

Wizard ish said:

Even if its marked as a float?

I don't follow. Based on Luke's comments above, it works with the f64 suffix. So it works when marked as a float.

view this post on Zulip Wizard ish (Nov 30 2024 at 21:21):

no it doesn't

view this post on Zulip Wizard ish (Nov 30 2024 at 21:21):

here

view this post on Zulip Wizard ish (Nov 30 2024 at 21:26):

Here's the work on Dec functions and both of these fail:

app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.16.0/O00IPk-Krg_diNS2dVWlI0ZQP794Vctxzv0ha96mK0E.tar.br" }

import pf.Stdout

main =
    numF64 = 1701411795f64
    numDec = Num.toDecChecked numF64
    Stdout.line! (Inspect.toStr numDec)
app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.16.0/O00IPk-Krg_diNS2dVWlI0ZQP794Vctxzv0ha96mK0E.tar.br" }

import pf.Stdout

main =
    numF64 = 17014117913243243243234223141241.43243f64
    numDec = Num.toDecChecked numF64
    Stdout.line! (Inspect.toStr numDec)

view this post on Zulip Wizard ish (Nov 30 2024 at 21:26):

With

An internal compiler expectation was broken.
This is definitely a compiler bug.
Please file an issue here: <https://github.com/roc-lang/roc/issues/new/choose>
Undefined Symbol in relocation, (+7fb0, Relocation { kind: PltRelative, encoding: Generic, size: +20, target: Symbol(SymbolIndex(+a9)), addend: +fffffffffffffffc, implicit_addend: false }): Ok(Symbol { name: "__fixdfti", address: +0, size: +0, kind: Unknown, section: Undefined, scope: Unknown, weak: false, flags: Elf { st_info: +10, st_other: +0 } })
Location: crates/linker/src/elf.rs:1452:25

view this post on Zulip Brendan Hansknecht (Nov 30 2024 at 21:28):

Oh sure. That is a separate issue from Invalid decimal for float literal = 1701411834604692531795.748. This should be a type error!.

Let me try and find where you need to stop dead code elimination

view this post on Zulip Luke Boswell (Nov 30 2024 at 21:28):

I think Brendan is talking about adding that function here https://github.com/roc-lang/roc/blob/49ab969ff3eedad0d5feaa56dc63e7cb4be3b471/crates/compiler/gen_llvm/src/llvm/build.rs#L1056

view this post on Zulip Brendan Hansknecht (Nov 30 2024 at 21:28):

Yes, exactly. Thanks for finding it!

view this post on Zulip Wizard ish (Nov 30 2024 at 21:29):

hmmm and do i add the llvm operation name or the name given in the code

view this post on Zulip Brendan Hansknecht (Nov 30 2024 at 21:31):

__fixdfti from the linker error

view this post on Zulip Wizard ish (Nov 30 2024 at 21:31):

ah ok

view this post on Zulip Wizard ish (Nov 30 2024 at 21:32):

Yo that fixed it!

view this post on Zulip Wizard ish (Nov 30 2024 at 21:58):

ok and the implementations of the funcs are done
just gonna add some tests and then open the pr

view this post on Zulip Wizard ish (Nov 30 2024 at 23:09):

Why are there three backends, and what even is the dev backend?

view this post on Zulip Luke Boswell (Nov 30 2024 at 23:46):

The gen-llvm backend is used to produce optimised code which means the code that is produces will run fast.

The gen-dev backends are designed to compile and produce code very fast (a few milliseconds) so they are nicer for a development workflow where you don't care (yet) about runtime performance but instead want to iterate fast.

The gen-wasm backend produces native wasm32 bytecode and is the dev backend equivalent for wasm.

LLVM is really great, but it is very slow to compile like on the order of 700 milliseconds for a hello word type app.

view this post on Zulip Wizard ish (Dec 01 2024 at 00:03):

does gen-dev use LLVM?

view this post on Zulip Brendan Hansknecht (Dec 01 2024 at 01:25):

Nope. It generates assembly directly

view this post on Zulip Wizard ish (Dec 01 2024 at 17:58):

Hey, should PRs be seperate from the diffrent backends (so, for instance, should / can I make a PR just implementing toDec for LLVM)?

view this post on Zulip Brendan Hansknecht (Dec 01 2024 at 18:54):

Totally fine either way.

view this post on Zulip Brendan Hansknecht (Dec 01 2024 at 18:55):

Very often llvm backend has features long before the other backends

view this post on Zulip Brendan Hansknecht (Dec 01 2024 at 18:56):

Frankly, we really need to iron out the last few features for the dev backend so that it could be enabled by default (though that may reveal that we also need a proper register allocator and a bigger overhaul)

view this post on Zulip Wizard ish (Dec 01 2024 at 18:56):

Hmm that’s done in mono right?

view this post on Zulip Brendan Hansknecht (Dec 01 2024 at 18:57):

Register allocation? No, it's backend specific.

view this post on Zulip Wizard ish (Dec 01 2024 at 18:57):

I mean gen dev

view this post on Zulip Brendan Hansknecht (Dec 01 2024 at 18:57):

Yep

view this post on Zulip Wizard ish (Dec 01 2024 at 18:58):

Ok

view this post on Zulip Brendan Hansknecht (Dec 01 2024 at 19:01):

Its register allocation is exceptionally naive right now. Runs super fast, but spills all the time. The dev backend currently goes straight from mono to assembly. This is fast, but really the wrong abstraction for generating assembly. So it has some complications and limitations.

Currently the dev backend is used for the repl and can be opted into. I think the only major missing feature is generating the platform interface correctly. Once that is done, it could be the default backend.

view this post on Zulip Brendan Hansknecht (Dec 01 2024 at 19:02):

Wasm backend is farther along. It is used for the web repl, but also can be used for real apps (still requires explicit opt in)

view this post on Zulip Wizard ish (Dec 01 2024 at 19:51):

I’m not familiar with it. Does it just always load stuff into memory even if the next op uses it?

view this post on Zulip Wizard ish (Dec 01 2024 at 20:35):

out of curosity why is mono used?

view this post on Zulip Brendan Hansknecht (Dec 02 2024 at 21:17):

It keeps a working list of stuff in registers, but doesn't track lifetimes in order to be smarter. So it just pushes the oldest thing in a register to stack if it runs out of registers.

view this post on Zulip Brendan Hansknecht (Dec 02 2024 at 21:18):

It uses mono cause that is the bottom of the compiler stack before backends. It is faster to just use mono than to build and convert to another ir.

view this post on Zulip Wizard ish (Dec 02 2024 at 21:37):

ah i see, anything y'all in particular need help with?

view this post on Zulip Brendan Hansknecht (Dec 02 2024 at 21:49):

The plan is actually now to add an extra level of ir:
https://github.com/roc-lang/roc/issues/6498

view this post on Zulip Brendan Hansknecht (Dec 02 2024 at 21:49):

Bigger project, but very useful.

view this post on Zulip Wizard ish (Dec 02 2024 at 22:52):

while you go into it a little, exactly how high level should it be?

view this post on Zulip Wizard ish (Dec 02 2024 at 22:53):

should it be like assembly, where, for instance, types are completly irrelevant and for instance Add<i32> is a completly seperate op from Add<u64> (ie AddSigned4 and AddUnsigned8) or rather should it have types tagged (so have registers also store types) so one writes Add and it will then when translated in binary become either Add<i32> or Add<u64>?

view this post on Zulip Brendan Hansknecht (Dec 03 2024 at 01:00):

I assumed roughly one enum entry per function here: https://github.com/roc-lang/roc/blob/fc6b519b5948023981ac5751d2f6ee48bcef2316/crates/compiler/gen_dev/src/generic64/mod.rs#L153-L742

view this post on Zulip Brendan Hansknecht (Dec 03 2024 at 01:00):

That is our current assembly abstraction

view this post on Zulip Wizard ish (Dec 20 2024 at 16:28):

Hello, I was advised (here)[https://github.com/roc-lang/roc/pull/7261#issuecomment-2556535016], to sign my old commits, however I couldn’t find any source that said how to sign pushed commits in a PR. How would I do this?

view this post on Zulip Anton (Dec 20 2024 at 16:42):

Hi @Wizard ish,
It is explained here but I don't recommend doing that procedure in the case of this PR, because its complicated if you got merges in there. We'll force the merge, I'm just going to check out the failure of the panic check.

view this post on Zulip Wizard ish (Dec 20 2024 at 17:28):

Ok, also that should be linked with signing in the contribution guide

view this post on Zulip Anton (Dec 20 2024 at 18:03):

It is linked: https://github.com/roc-lang/roc/blob/main/CONTRIBUTING.md#commit-signing
But I welcome suggestions on how we can make that more visible

view this post on Zulip Wizard ish (Dec 20 2024 at 19:40):

Oh I was looking under the dropdown

view this post on Zulip Anton (Dec 20 2024 at 19:50):

Yeah my original here link was wrong, the dropdown (Forgot to sign commits?) actually seems to contain the best answer to your question "to sign my old commits".

Hi Wizard ish,
It is explained here but I don't recommend doing that procedure in the case of this PR, because its complicated if you got merges in there. We'll force the merge, I'm just going to check out the failure of the panic check.

view this post on Zulip Anton (Dec 20 2024 at 19:50):

Do you agree?

view this post on Zulip Wizard ish (Dec 20 2024 at 19:53):

Yeah, though both are quite useful

view this post on Zulip Anton (Dec 20 2024 at 19:56):

I'll link to the guide again under the dropdown

view this post on Zulip Anton (Dec 20 2024 at 20:00):

What do you think?
Screenshot from 2024-12-20 21-00-01.png

view this post on Zulip Wizard ish (Dec 20 2024 at 20:23):

it's good, but imo it should really be a alert

view this post on Zulip Anton (Dec 21 2024 at 11:26):

I didn't know about alerts, those are nice!
I did find out that they do not work inside dropdowns so I went with an exclamation emoji instead

view this post on Zulip Wizard ish (Dec 22 2024 at 00:14):

Yeah, github has a lot of fun formatting things, you can find much on them here. My personal favorite has got to be diagramming


Last updated: Jul 06 2025 at 12:14 UTC