Stream: compiler development

Topic: generating an InLayout


view this post on Zulip Brendan Hansknecht (Nov 20 2023 at 18:57):

I am manually writing out some mono ir in rust. I am trying to call the List.sublist builtin. To do that, I first have to create a symbol that stores the parameters. To bind the symbol I have to specify the layout.

example code:

let sublist_params_sym = env.unique_symbol();
let sublist_params_expr = Expr::Struct(env.arena.alloc([start_sym, rest_len_sym]));
let sublist_params_layout = ???;
stmt = Stmt::Let(
    sublist_params_sym,
    sublist_params_expr,
    sublist_params_layout,
    env.arena.alloc(stmt),
 );

I tried to build the layout manually, but the fields are private, so this must be the wrong way to generate it:

let sublist_params_layout = layout_cache.interner.insert(Layout {
    repr: LayoutWrapper::Direct(LayoutRepr::Struct(env.arena.alloc([
        usize_layout,
        usize_layout,
    ]))),
    semantic: SemanticRepr::record(env.arena.alloc(["start", "len"])),
}));

Any help?

view this post on Zulip Ayaz Hafiz (Nov 20 2023 at 19:01):

Are you working in mono?

view this post on Zulip Ayaz Hafiz (Nov 20 2023 at 19:01):

There's Layout::new

view this post on Zulip Ayaz Hafiz (Nov 20 2023 at 19:02):

What are you trying to do though? Generally constructing a layout directly is not preferred

view this post on Zulip Brendan Hansknecht (Nov 20 2023 at 19:24):

Trying to fix binding rest in a list pattern match.

view this post on Zulip Brendan Hansknecht (Nov 20 2023 at 19:24):

Also, turns out the that low level doesn't use the struct, so I didn't need the layout.

view this post on Zulip Brendan Hansknecht (Nov 20 2023 at 19:36):

#6030 for context


Last updated: Jul 06 2025 at 12:14 UTC