Skip to content

Alignment overhaul#13

Open
YerinAlexey wants to merge 4 commits into
garritfra:mainfrom
YerinAlexey:alignment-overhaul
Open

Alignment overhaul#13
YerinAlexey wants to merge 4 commits into
garritfra:mainfrom
YerinAlexey:alignment-overhaul

Conversation

@YerinAlexey

@YerinAlexey YerinAlexey commented Jun 25, 2022

Copy link
Copy Markdown
Contributor

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 thread src/lib.rs
Comment on lines +124 to +128
assert!(
*align == 4 || *align == 8 || *align == 16,
"Invalid stack alignment"
);
write!(f, "alloc{} {}", align, size)

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.🙂

Comment thread src/lib.rs
Self::Aggregate(td) => match td.align {
Some(align) => align,
None => {
assert!(!td.items.is_empty(), "Invalid empty TypeDef");

Copy link
Copy Markdown
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?

@YerinAlexey YerinAlexey Jun 26, 2022

Copy link
Copy Markdown
Contributor Author

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