Skip to content

Roc crashed: Invalid incref: incrementing non-positive refcount #9044

@godalming123

Description

@godalming123

This bug isn't affecting me right now.

If I have a file called test.roc:

app [main!] {
    pf: platform "https://github.com/lukewilliamboswell/roc-platform-template-zig/releases/download/0.6/2BfGn4M9uWJNhDVeMghGeXNVDFijMfPsmmVeo6M4QjKX.tar.zst"
}

import pf.Stdout

main! : List(Str) => Try({}, [Exit(I32)])
main! = |_args| {
    utf8 = Str.to_utf8("0 % 15 == 0")
    Stdout.line!("converted to utf8")
    result = parse_value!(utf8, get_next_token!(utf8, 0), [])
    Stdout.line!("result: ${Str.inspect(result)}")
    Ok({})
}

NumericRangeType : [
    ExcludesEndValue, # ..<
    IncludesEndValue, # ..=
]

TokenContents : [
    OpenBraceToken, # {
    CloseBraceToken, # }
    CommaToken, # ,
    ColonToken, # :
    AssignToken, # =
    EqualToken, # ==
    MinusToken, # -
    ArrowToken, # ->
    DotDotToken(NumericRangeType),
    DotToken, # .
    ModuloToken, # %
    UIntDigitsToken(U64),
    IntDigitsToken(I64),
    FloatDigitsToken(F64),
    StrDigitsToken(Str),
    IdentToken(Str),
    CommentToken(Str),
    StringToken(Str),
    Err(Str),
    EndOfFileToken,
]
Token : (TokenContents, U64)

tokenize_digits : List(U8), U64, List(U8) -> (List(U8), U64)
tokenize_digits = |file, index, digits| {
    match List.get(file, index) {
        Ok(c) => {
            if '0' <= c and c <= '9' {
                return tokenize_digits(file, index + 1, List.append(digits, c))
            }
        }
        _ => {}
    }
    (digits, index)
}

TokenizerResult : (
    TokenContents,
    U64, # New index in file
)

get_next_token! : List(U8), U64 => TokenizerResult
get_next_token! = |file, index| {
    Stdout.line!(index.to_str())
    match List.get(file, index) {
        Ok(' ') => get_next_token!(file, index + 1)
        Ok('%') => (ModuloToken, index + 1)
        Ok('=') => {
            match List.get(file, index+1) {
                Ok('=') => (EqualToken, index + 2)
                _ => (AssignToken, index + 1)
            }
        }
        Ok(c) => {
            if ('0' <= c and c <= '9') {
                # TODO: Add support for negatives and decimals
                (digits, index2) = tokenize_digits(file, index + 1, [c])
                str = Str.from_utf8_lossy(digits)
                token : TokenContents
                token = match U64.from_str(str) {
                    Ok(num) => UIntDigitsToken(num)
                    Err(_) => StrDigitsToken(str)
                }
                (token, index2)
            } else {
                (Err("todo"), index + 1)
            }
        }
        Err(_) => {
            (EndOfFileToken, index)
        }
    }
}

ValueCombinationMethod := [
    BooleanAnd, BooleanOr, BooleanNot,
    IsEqual, IsNotEqual, IsGreaterThan, IsLessThan, IsGreaterThanOrEqual, IsLessThanOrEqual,
    Multiply, Divide, Modulo,
    Add, Subtract,
]

Value := [
    UInt(U64),
    CombinedValue({
        combination_method: ValueCombinationMethod,
        value1: Value,
        value2: Value,
    }),
]
parse_first_value! : List(U8), TokenizerResult, List(Str) => Try((Value, U64), Str)
parse_first_value! = |file, (token, var $index), possibilities| {
    Ok((UInt(3), $index))
}

parse_value! : List(U8), TokenizerResult, List(Str) => Try((TokenContents, List(Str), Value, U64), Str)
parse_value! = |file, result, possibilities| {
    (value1, var $index) = parse_first_value!(file, result, possibilities)?
    (token2, $index) = get_next_token!(file, $index)
    combination_method1 : ValueCombinationMethod
    combination_method1 = match token2 {
        ModuloToken => Modulo
        EqualToken => IsEqual
        # TODO
        _ => {
            Stdout.line!("Returning early from parse_value!")
            return Ok((token2, ["`%`", "`==`"], value1, $index))
        }
    }
    Stdout.line!("finished creating combination method 1 in parse_value!")
    (token3, expected2, value2, $index) = parse_value!(file, get_next_token!(file, $index), [])?
    value : Value
    value = CombinedValue({combination_method: combination_method1, value1, value2})
    Ok((token3, expected2, value, $index))
}

Then, when I try to run the file, I get the error:

Roc crashed: Invalid incref: incrementing non-positive refcount

The version of the roc compiler that I am using is compiled from ad88807.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions