Skip to content

Allow anonymous template types #575

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

Conversation

fitzgen
Copy link
Member

@fitzgen fitzgen commented Mar 10, 2017

We have various assertions that the only way that some template parameter related methods will return None is if the template definition is marked opaque. These assertions fail in the presence of test cases with unnamed template types, because we never save an IR item for the template type, and subsequently think that the template definition has no template parameters. The assertions are in fact sound and correct, so it doesn't make sense to remove them. Instead it is more correct to save IR items for the anonymous template types and simply let the template usage analysis prevent them from getting
codegen'd.

Fixes #574

r? @emilio

fitzgen added 2 commits March 10, 2017 13:53
We have various assertions that the only way that some template parameter
related methods will return `None` is if the template definition is marked
opaque. These assertions fail in the presence of test cases with unnamed
template types, because we never save an IR item for the template type, and
subsequently think that the template definition has no template parameters. The
assertions are in fact sound and correct, so it doesn't make sense to remove
them. Instead it is more correct to save IR items for the anonymous template
types and simply let the template usage analysis prevent them from getting
codegen'd.

Fixes rust-lang#574
Not sure why rustfmt hasn't caught this before...
@highfive
Copy link

warning Warning warning

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

@fitzgen fitzgen changed the title Issue 574 anonymous template parameters and assertion failure Allow anonymous template types Mar 10, 2017
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.

I'd say let's drop the last commit for now. r=me on the rest.

src/ir/comp.rs Outdated
@@ -357,8 +359,8 @@ impl CompInfo {

let has_destructor = self.has_destructor ||
match self.kind {
CompKind::Union => false,
CompKind::Struct => {
CompKind::Union => false,
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think these changes are really acceptable in general.

Is this only due to a newer version of rustfmt?

src/ir/module.rs Outdated
@@ -63,7 +63,7 @@ impl DotAttributes for Module {
_ctx: &BindgenContext,
out: &mut W)
-> io::Result<()>
where W: io::Write,
where W: io::Write
Copy link
Contributor

Choose a reason for hiding this comment

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

Also, it's no longer respecting the trailing comma in where clauses?

src/ir/named.rs Outdated
.or_insert(vec![])
.push(item);
},
dependencies.entry(sub_item)
Copy link
Contributor

Choose a reason for hiding this comment

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

This change seems also wrong to me.

src/main.rs Outdated
@@ -52,8 +52,8 @@ pub fn main() {
Ok((builder, output, verbose)) => {

let builder_result = panic::catch_unwind(|| {
builder.generate().expect("Unable to generate bindings")
});
builder.generate().expect("Unable to generate bindings")
Copy link
Contributor

Choose a reason for hiding this comment

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

This is also way off I believe.

@fitzgen fitzgen force-pushed the issue-574-anonymous-template-parameters-and-assertion-failure branch from b8cfd9f to b7f7850 Compare March 13, 2017 16:54
@fitzgen
Copy link
Member Author

fitzgen commented Mar 13, 2017

Thanks for the review! Dropped the last commit. Yeah, this is latest rustfmt don't know what's up...

@bors-servo r+

@bors-servo
Copy link

📌 Commit b7f7850 has been approved by fitzgen

@bors-servo
Copy link

⌛ Testing commit b7f7850 with merge eeebba0...

bors-servo pushed a commit that referenced this pull request Mar 13, 2017
…and-assertion-failure, r=fitzgen

Allow anonymous template types

We have various assertions that the only way that some template parameter related methods will return `None` is if the template definition is marked opaque. These assertions fail in the presence of test cases with unnamed template types, because we never save an IR item for the template type, and subsequently think that the template definition has no template parameters. The assertions are in fact sound and correct, so it doesn't make sense to remove them. Instead it is more correct to save IR items for the anonymous template types and simply let the template usage analysis prevent them from getting
codegen'd.

Fixes #574

r? @emilio
@fitzgen
Copy link
Member Author

fitzgen commented Mar 13, 2017

@bors-servo r-

@fitzgen
Copy link
Member Author

fitzgen commented Mar 13, 2017

@bors-servo r=emilio

@bors-servo
Copy link

📌 Commit b7f7850 has been approved by emilio

@fitzgen
Copy link
Member Author

fitzgen commented Mar 13, 2017

FWIW, filed rust-lang/rustfmt#1376 for the rustfmt issues.

@bors-servo
Copy link

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

@bors-servo bors-servo merged commit b7f7850 into rust-lang:master Mar 13, 2017
@fitzgen fitzgen deleted the issue-574-anonymous-template-parameters-and-assertion-failure branch March 14, 2017 16:39
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