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

Compute sizedness with a fixed-point analysis #1102

Merged
merged 3 commits into from
Oct 25, 2017

Conversation

fitzgen
Copy link
Member

@fitzgen fitzgen commented Oct 25, 2017

This fixes a couple bugs where we weren't properly adding an _address byte. It also helps pave the way for computing implicit fields (such as padding, _address, vtable pointers, etc) in its own pass, before codegen.

Fixes #768

r? @pepyakin

Copy link
Contributor

@pepyakin pepyakin left a comment

Choose a reason for hiding this comment

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

looks great!

}

TypeKind::ObjCInterface(..) => {
trace!(" I guess obj-c interfaces are not zero-sized?");
Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW, as far as I know, every obj-c "interface" have an isa pointer.

Copy link
Member Author

Choose a reason for hiding this comment

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

Cool, I'll note this. FWIW, I was just copying existing behavior.

trace!(" comp considers its own fields and bases");

if !info.fields().is_empty() {
return self.insert(id, SizednessResult::NonZeroSized);
Copy link
Contributor

Choose a reason for hiding this comment

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

But what if all fields are zero sized 🤔 ?

Copy link
Member Author

Choose a reason for hiding this comment

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

They can't be, because of the every-object-must-be-addressable rules. Only base members can truly be zero sized, because its the "same" object.

Copy link
Member Author

Choose a reason for hiding this comment

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

That is, with

struct Empty {};

struct Inherits : public Empty {
    int x;
};

struct Contains {
    Empty empty;
    int x;
};

sizeof(Contains) is one greater than sizeof(Inherits)

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah, makes sense. Thank you!

@fitzgen
Copy link
Member Author

fitzgen commented Oct 25, 2017

Thanks for the review @pepyakin !

This fixes a couple bugs where we weren't properly adding an `_address`
byte. It also helps pave the way for computing implicit fields (such as padding,
`_address`, vtable pointers, etc) in its own pass, before codegen.

Fixes rust-lang#768
@fitzgen
Copy link
Member Author

fitzgen commented Oct 25, 2017

I added that example, and another for arrays of zero-sized types, as tests.

Thanks again for review @pepyakin !

@bors-servo r=pepyakin

@bors-servo
Copy link

📌 Commit d018f42 has been approved by pepyakin

@bors-servo
Copy link

⌛ Testing commit d018f42 with merge 88a1e24...

bors-servo pushed a commit that referenced this pull request Oct 25, 2017
Compute sizedness with a fixed-point analysis

This fixes a couple bugs where we weren't properly adding an `_address` byte. It also helps pave the way for computing implicit fields (such as padding, `_address`, vtable pointers, etc) in its own pass, before codegen.

Fixes #768

r? @pepyakin
@fitzgen
Copy link
Member Author

fitzgen commented Oct 25, 2017

Added one more test for arrays of zero elements and flexible arrays also.

@bors-servo r=pepyakin

@bors-servo
Copy link

📌 Commit fd7afb6 has been approved by pepyakin

@bors-servo
Copy link

⌛ Testing commit fd7afb6 with merge 1cb1101...

bors-servo pushed a commit that referenced this pull request Oct 25, 2017
Compute sizedness with a fixed-point analysis

This fixes a couple bugs where we weren't properly adding an `_address` byte. It also helps pave the way for computing implicit fields (such as padding, `_address`, vtable pointers, etc) in its own pass, before codegen.

Fixes #768

r? @pepyakin
@bors-servo
Copy link

☀️ Test successful - status-travis
Approved by: pepyakin
Pushing 1cb1101 to master...

@bors-servo bors-servo merged commit fd7afb6 into rust-lang:master Oct 25, 2017
bors-servo pushed a commit that referenced this pull request Oct 30, 2017
…g, r=emilio

Simple refactoring of derive_partialeq_or_partialord

Just simple refactoring with some tricks from #1102

r? @fitzgen
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.

Rewrite is_unsized as a fix-point analysis
4 participants