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

Implement skip handling for fields of fixed size #1646

Merged
merged 4 commits into from
Jan 17, 2024

Conversation

bbannier
Copy link
Member

@bbannier bbannier commented Jan 10, 2024

Closes #1640.

@bbannier bbannier self-assigned this Jan 10, 2024
@bbannier bbannier force-pushed the topic/bbannier/issue-1640 branch from 1feb1e1 to 8731132 Compare January 12, 2024 15:36
@bbannier bbannier marked this pull request as ready for review January 12, 2024 15:57
@bbannier bbannier requested a review from rsmmr January 16, 2024 08:39
Copy link
Member

@rsmmr rsmmr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good stuff. A further future extension could be inferring static sizes for units that don't have an explicit &size: if all their fields are fixed size, the unit is so too.

spicy/toolchain/src/compiler/codegen/parser-builder.cc Outdated Show resolved Hide resolved
spicy/toolchain/src/compiler/codegen/parser-builder.cc Outdated Show resolved Hide resolved
@bbannier bbannier force-pushed the topic/bbannier/issue-1640 branch from 8731132 to 1b175d1 Compare January 16, 2024 15:48
doc/programming/parsing.rst Outdated Show resolved Hide resolved
hilti/toolchain/include/ast/types/bitfield.h Outdated Show resolved Hide resolved
spicy/toolchain/src/ast/types/unit.cc Outdated Show resolved Hide resolved
spicy/toolchain/src/ast/types/unit.cc Outdated Show resolved Hide resolved
@@ -30,3 +33,30 @@ std::optional<std::pair<const Expression, std::optional<const Type>>> spicy::typ

return {};
}

std::optional<const Expression> spicy::type::unit::item::Field::size() const {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple things:

Good point that the size can depend not just on types, but also on field attributes, I didn't think about that. Given that, I'm now wondering if the type-side size() method is really as helpful as I originally thought because we now have two levels of size(), each with just a couple of cases/implementations (Type::size() and (Field::size). So maybe putting it all here into Field::size() is the better approach.

And then I think I'd use a visitor instead of the if/else-chain, both for readability/consistency-in-style and (I believe ...) performance.

Copy link
Member Author

@bbannier bbannier Jan 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this as suggested. PTAL.

hilti/toolchain/include/ast/type.api Outdated Show resolved Hide resolved
@bbannier bbannier requested a review from rsmmr January 17, 2024 13:25
rsmmr
rsmmr previously approved these changes Jan 17, 2024
This patch adds `skip` support for fields with `&size` attribute or of
builtin type with known size. If a unit has a known size and it is
specified in a `&size` attribute this also allows to skip over unit
fields.

Closes #1640.
@bbannier bbannier force-pushed the topic/bbannier/issue-1640 branch from 5c96c06 to ed937e4 Compare January 17, 2024 15:53
@bbannier bbannier merged commit 24efdef into main Jan 17, 2024
9 of 19 checks passed
@bbannier bbannier deleted the topic/bbannier/issue-1640 branch January 17, 2024 15:53
@bbannier
Copy link
Member Author

I backported 2559ed4) to release/1.8.

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.

Optimize skip for fixed sized types and units
2 participants