Skip to content

Conversation

@fitzgen
Copy link
Member

@fitzgen fitzgen commented Mar 9, 2017

When instantiating templates whose definitions have non-type generic parameters, prefer the layout of the instantiation type to the garbage we get from the definition's layout. In general, an instantiation's layout will always be a better choice than the definition's layout, regardless of non-type parameters.

Fixes #569

r? @emilio

fitzgen added 3 commits March 9, 2017 13:56
This pulls existing code out of Type's ToRustTy implementation and into an
implementation of ToRustTy for TemplateInstantiation. Purely code motion.
If we hit a case where we generate an opaque blob instead of an instantiation of
a generic, then we won't ever be attaching generic parameters, and can bail out
of the function early.
When instantiating templates whose definitions have non-type generic parameters,
prefer the layout of the instantiation type to the garbage we get from the
definition's layout. In general, an instantiation's layout will always be a
better choice than the definition's layout, regardless of non-type parameters.

Fixes rust-lang#569
@highfive
Copy link

highfive commented Mar 9, 2017

warning Warning warning

  • These commits modify unsafe code. Please review it carefully!

Copy link
Contributor

@emilio emilio left a comment

Choose a reason for hiding this comment

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

Looks fine! What do you think about the comments?

r=me with those addressed or a reply.

// partial template specialization, in which case we just
// use the opaque type's layout. If we don't have a layout,
// we cross our fingers and hope for the best :-/
debug_assert!(ctx.resolve_type_through_type_refs(decl)
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's use match here instead of if let ... else return?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure thing.

} else {
inner_item.to_rust_ty(ctx)
let inner_rust_ty = inner_item.to_rust_ty(ctx);
if inner_rust_ty == aster::AstBuilder::new().ty().unit() {
Copy link
Contributor

Choose a reason for hiding this comment

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

This conditional is hacky enough it deserves at least a comment. But I really think we should just check the type to see if it's a template instantiation? Or at least, given to_rust_ty should never generate unit types unless that, what about debug_assert!ing instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

Will do.

I was also thinking that ToRustTy::to_rust_ty should return an Option or a Result, and then instead of ever returning () we would return None. This is a slightly more invasive change, however, and I can do it if you want, but don't feel like going out of my way at the moment :-P

@fitzgen
Copy link
Member Author

fitzgen commented Mar 9, 2017

Thanks for the super speedy review :)

@bors-servo r=emilio

@bors-servo
Copy link

📌 Commit 8b17b65 has been approved by emilio

@bors-servo
Copy link

⌛ Testing commit 8b17b65 with merge ecd9770...

bors-servo pushed a commit that referenced this pull request Mar 9, 2017
Generate better opaque blobs in the face of non-type parameters

When instantiating templates whose definitions have non-type generic parameters, prefer the layout of the instantiation type to the garbage we get from the definition's layout. In general, an instantiation's layout will always be a better choice than the definition's layout, regardless of non-type parameters.

Fixes #569

r? @emilio
@bors-servo
Copy link

☀️ Test successful - status-travis
Approved by: emilio
Pushing ecd9770 to master...

@bors-servo bors-servo merged commit 8b17b65 into rust-lang:master Mar 9, 2017
@fitzgen fitzgen deleted the sm-layout-test-failures branch March 9, 2017 23:04
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.

4 participants