All news

Published

More region ergonomics in Jik v0.1.0-alpha.23

Jik v0.1.0-alpha.23 is now available. This release makes it easier to construct and return composite values in the region shared by a function's arguments. It also adds standard-error output to jik/io and includes language-tooling and variant-syntax fixes.

Allocate in the implicit region with @

A postfix @ on a composite literal allocates it in the function's implicit region: the unique region inferred from its non-foreign composite and Region parameters. This is useful for intermediate values that must live long enough to be returned.

struct Article:
    title: String
end

func labels_for(article: Article) -> Vec[String]:
    labels := ["release", "latest"]@
    return labels
end

func main():
    article := Article{title = "Jik v0.1.0-alpha.23"}
    labels := labels_for(article)
    println(article.title, ": ", labels[0], ", ", labels[1])
end

Here, @ is equivalent to allocating the vector in the region of article, without naming that parameter in the allocation suffix. Named allocation specifiers remain available when there is no implicit region or when naming the destination is clearer.

Return composite literals directly

A directly returned composite literal can now be allocated automatically in the caller-owned region established by the same-region rule. The compiler can therefore give a returned string, vector, struct, or other composite value the correct lifetime without an explicit allocation suffix.

struct User:
    name: String
end

func display_name(user: User) -> String:
    if user.name == "":
        return "Anonymous"
    end
    return user.name
end

func main():
    user := User{}
    println(display_name(user))
end

This applies only to literals used directly as return expressions. Returning a local variable, a foreign value, or a global value follows the existing region rules.

Write diagnostics to standard error

The standard library's jik/io module now provides write_stderr, so command-line programs can keep diagnostics separate from their normal output.

use "jik/io"

func main():
    io::write_stderr("warning: using a fallback value\n")
end

Other changes