Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve layout table printing #1081

Merged
merged 1 commit into from
Oct 1, 2024
Merged

Improve layout table printing #1081

merged 1 commit into from
Oct 1, 2024

Conversation

feds01
Copy link
Contributor

@feds01 feds01 commented Sep 28, 2024

## Description

This PR improves the layout table printing by removing the empty gap
at the end of a row for non-single element rows. This means that previously
the layout table would print for a struct like this:

#layout_of Boon := enum(
    Foo(x: i32, y: i32),
    Faz(z: f64),
);

Before:

info: Layout of `Boon` (size=16b align=8b):
┌──────────────┬─────────────────────────┐
│ 4b tag (u32) │                         │
├──────────────┼────────────┬────────────┤
│     Foo      │   x: i32   │   y: i32   │
│              │            │            │
│      0       │   size: 4b │   size: 4b │
│              │ offset: 4b │ offset: 8b │
│              │  align: 4b │  align: 4b │
├──────────────┼────────┬───┴────────┬───┤
│     Faz      │ 4b pad │   z: f64   │   │
│              │        │            │   │
│      1       │   ##   │   size: 8b │   │
│              │   ##   │ offset: 8b │   │
│              │   ##   │  align: 8b │   │
└──────────────┴────────┴────────────┴───┘

After the change, we now print the following:

info: Layout of `Boon` (size=16b align=8b):
┌──────────────┬─────────────────────────┐
│ 4b tag (u32) │                         │
├──────────────┼────────────┬────────────┤
│     Foo      │   x: i32   │   y: i32   │
│              │            │            │
│      0       │   size: 4b │   size: 4b │
│              │ offset: 4b │ offset: 8b │
│              │  align: 4b │  align: 4b │
├──────────────┼────────┬───┴────────────┤
│     Faz      │ 4b pad │     z: f64     │
│              │        │                │
│      1       │   ##   │     size: 8b   │
│              │   ##   │   offset: 8b   │
│              │   ##   │    align: 8b   │
└──────────────┴────────┴────────────────┘

This commit improves the layout table printing by removing the empty gap
at the end of a row for non-single element rows. This means that previously
the layout table would print for a struct like this:

```rs
\#layout_of Boon := enum(
    Foo(x: i32, y: i32),
    Faz(z: f64),
);
```

Before:

```
info: Layout of `Boon` (size=16b align=8b):
┌──────────────┬─────────────────────────┐
│ 4b tag (u32) │                         │
├──────────────┼────────────┬────────────┤
│     Foo      │   x: i32   │   y: i32   │
│              │            │            │
│      0       │   size: 4b │   size: 4b │
│              │ offset: 4b │ offset: 8b │
│              │  align: 4b │  align: 4b │
├──────────────┼────────┬───┴────────┬───┤
│     Faz      │ 4b pad │   z: f64   │   │
│              │        │            │   │
│      1       │   ##   │   size: 8b │   │
│              │   ##   │ offset: 8b │   │
│              │   ##   │  align: 8b │   │
└──────────────┴────────┴────────────┴───┘
```

After the change, we now print the following:

```
info: Layout of `Boon` (size=16b align=8b):
┌──────────────┬─────────────────────────┐
│ 4b tag (u32) │                         │
├──────────────┼────────────┬────────────┤
│     Foo      │   x: i32   │   y: i32   │
│              │            │            │
│      0       │   size: 4b │   size: 4b │
│              │ offset: 4b │ offset: 8b │
│              │  align: 4b │  align: 4b │
├──────────────┼────────┬───┴────────────┤
│     Faz      │ 4b pad │     z: f64     │
│              │        │                │
│      1       │   ##   │     size: 8b   │
│              │   ##   │   offset: 8b   │
│              │   ##   │    align: 8b   │
└──────────────┴────────┴────────────────┘
```
@feds01 feds01 self-assigned this Sep 28, 2024
@feds01 feds01 merged commit 1699427 into main Oct 1, 2024
1 check passed
@feds01 feds01 deleted the repr/remove-empty-gap branch October 1, 2024 21:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants