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

Alignment overhaul #13

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

YerinAlexey
Copy link
Contributor

@YerinAlexey YerinAlexey commented Jun 25, 2022

Description

Fixes issues related to field alignment in Type.size() and adds Type.align() helper

ToDo

  • Proposed feature/fix is sufficiently tested
  • Proposed feature/fix is sufficiently documented
  • The "Unreleased" section in the changelog has been updated, if applicable

This makes it easier for frontends to give it the correct alignment.
Determines the default alignment similar to QBE itself
Comment on lines +124 to +128
assert!(
*align == 4 || *align == 8 || *align == 16,
"Invalid stack alignment"
);
write!(f, "alloc{} {}", align, size)
Copy link
Owner

Choose a reason for hiding this comment

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

Not really a fan of this, as it moves the error from compile-time to run-time, which we should avoid.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure, we have to provide some way to get the corresponding allocation instruction by giving an alignment from Type.align() or similar

Copy link
Owner

Choose a reason for hiding this comment

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

But what keeps you from writing qbe::Alloc(5, 0), which would result in a runtime error?

Copy link
Owner

Choose a reason for hiding this comment

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

An alternative would be to have Alloc(Type, Align) but that diverges too much from the original QBE IL. Let's just keep this as is.🙂

Self::Aggregate(td) => match td.align {
Some(align) => align,
None => {
assert!(!td.items.is_empty(), "Invalid empty TypeDef");
Copy link
Owner

Choose a reason for hiding this comment

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

Is this really needed? Are typedefs required to have at least one item?

Copy link
Contributor Author

@YerinAlexey YerinAlexey Jun 26, 2022

Choose a reason for hiding this comment

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

Yes, absolutely. The only possible way to get empty typedef is not-yet-supported opaque typedefs, but they require explicit alignment.

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