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

Heuristic for overflow_delimited_expr #203

Open
traviscross opened this issue Dec 31, 2024 · 0 comments
Open

Heuristic for overflow_delimited_expr #203

traviscross opened this issue Dec 31, 2024 · 0 comments

Comments

@traviscross
Copy link

Refiling the comment...

...so it's not lost.

@ia0 writes:

I'd like to suggest another attempt to the one of @pitaj (which I guess could be summarized by "stop recursion if the last 2 elements of the current list are of the same kind, e.g. both arrays, both tuples, etc").

This overflow_delimited_expr feature has a notion of recursion through the nesting of list-like syntax. I suggest looking at the height of this nesting to decide when to stop recursion. I define the height of a list as one plus the maximum height of its elements (zero if there are none). Recursion through the last element should stop if there is another element (in that list) with a greater or equal height as that last element. Equivalently, recursion should continue if the last element has the greatest (unmatched) height in the list. Here are some formatted examples with explanations:

// `write()` elements: we recurse because the last one has a height of 2
//     which is greater than all other elements (`i * 3` has a height of 1).
// `Bar` elements: we stop recursion because all elements have a height of 1,
//     so the last one does not have a height greater than all other elements.
vbuf.write(i * 3, Bar(
    Foo { x: 1, y: 2, z: 3 },
    Foo { x: 1, y: 2, z: 3 },
    Foo { x: 1, y: 2, z: 3 },
));
// Same reasoning here. The last element of `Bar` has a height matched by the first element.
vbuf.write(i * 3, Bar(
    Foo { x: 1, y: 2, z: 3 },
    42,
    Foo { x: 1, y: 2, z: 3 },
));
// Now, the last element of `Bar` has the greatest unmatched height, so we recurse.
// `Foo` elements: They all have the same height, so we don't recurse (anyway, 3 is not a list).
vbuf.write(i * 3, Bar(13, 42, Foo {
    x: 1,
    y: 2,
    z: 3,
}));

cc @rust-lang/style @rust-lang/rustfmt

@traviscross traviscross changed the title Heuristic for overflow-delimited_expr Heuristic for overflow_delimited_expr Dec 31, 2024
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

No branches or pull requests

1 participant