Skip to content

Revamp codegen tests to check IR quality instead of quantity #25762

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

Merged
merged 1 commit into from
May 27, 2015

Conversation

dotdash
Copy link
Contributor

@dotdash dotdash commented May 24, 2015

The current codegen tests only compare IR line counts between similar
rust and C programs, the latter getting compiled with clang. That looked
like a good idea back then, but actually things like lifetime intrinsics
mean that less IR isn't always better, so the metric isn't really
helpful.

Instead, we can start doing tests that check specific aspects of the
generated IR, like attributes or metadata. To do that, we can use LLVM's
FileCheck tool which has a number of useful features for such tests.

To start off, I created some tests for a few things that were recently
added and/or broken.

@rust-highfive
Copy link
Contributor

r? @pcwalton

(rust_highfive has picked a reviewer for you, use r? to override)

@huonw
Copy link
Member

huonw commented May 25, 2015

Very cool.

@luqmana
Copy link
Member

luqmana commented May 25, 2015

Looks good to me! I'll refrain from r+'ing though since it seems like @nikomatsakis or someone should get the chance to see it first.

@alexcrichton
Copy link
Member

Amazing! I'm really looking forward to turning back on these kinds of tests. A few questions:

  • I forget if we're actually running these by default, but these look like they'll be solid enough to enable by default, so just to confirm, these are run on make check, right?
  • What's up with the -C no-prepopulate-passes argument to each test? Should that be an argument specified by compiletest or are there tests that may not wish to pass that?
  • Do you know how brittle these tests would be across LLVM versions? In theory we have support for a number of LLVM version ranges, but we may want to disable the tests entirely on earlier LLVM versions if it causes problems. Also, do you know if it'd be difficult to update these tests with an LLVM upgrade?

@luqmana
Copy link
Member

luqmana commented May 26, 2015

It would probably be a good idea to let different tests decide whether or not they want to pass -C no-prepopulate-passes. I can see a test that wants to make sure something about an always_inline function and thus doesn't want it to disappear from the IR. On the other side, we might want to test that always inline is indeed always inline.

As for brittleness, that really depends on how specific the tests get. For the initial couple in this pull we're only checking things like argument attributes (noalias, nocapture etc) and I don't expect those to change all that much. In any case, in the event they did change, we'd have to upgrade librustc anyways to emit the right flags, changing some tests wouldn't be all that bad.

@alexcrichton
Copy link
Member

@luqmana hm yeah makes sense about no-prepopulate-passes. How come these tests require it though? (just curious)

As for brittleness, that really depends on how specific the tests get.

True, I suspect it wouldn't be too hard to upgrade. I'm mostly just worried about multiple LLVM versions but we can always deal with that later as well!

@dotdash
Copy link
Contributor Author

dotdash commented May 26, 2015

@luqmana hm yeah makes sense about no-prepopulate-passes. How come these tests require it though? (just curious)

That's to make sure we actually check what we emit and not what LLVM can deduce. Also, the way the tests are written, the deduced flags would actually make them fail.

The tests should run by default, but I'll test that tomorrow to make sure. I also forgot to remove some remaining code from the old codegen test setup that checks for clang. Will fix that tomorrow, too.

@alexcrichton
Copy link
Member

That's to make sure we actually check what we emit and not what LLVM can deduce.

Ah of course!

The tests should run by default, but I'll test that tomorrow to make sure. I also forgot to remove some remaining code from the old codegen test setup that checks for clang. Will fix that tomorrow, too.

Perfect! r=me with those minor changes and/or validations.

The current codegen tests only compare IR line counts between similar
rust and C programs, the latter getting compiled with clang. That looked
like a good idea back then, but actually things like lifetime intrinsics
mean that less IR isn't always better, so the metric isn't really
helpful.

Instead, we can start doing tests that check specific aspects of the
generated IR, like attributes or metadata. To do that, we can use LLVM's
FileCheck tool which has a number of useful features for such tests.

To start off, I created some tests for a few things that were recently
added and/or broken.
@dotdash
Copy link
Contributor Author

dotdash commented May 27, 2015

@bors r=alexcrichton 6773675

@bors
Copy link
Collaborator

bors commented May 27, 2015

⌛ Testing commit 6773675 with merge f56782a...

bors added a commit that referenced this pull request May 27, 2015
The current codegen tests only compare IR line counts between similar
rust and C programs, the latter getting compiled with clang. That looked
like a good idea back then, but actually things like lifetime intrinsics
mean that less IR isn't always better, so the metric isn't really
helpful.

Instead, we can start doing tests that check specific aspects of the
generated IR, like attributes or metadata. To do that, we can use LLVM's
FileCheck tool which has a number of useful features for such tests.

To start off, I created some tests for a few things that were recently
added and/or broken.
@bors bors merged commit 6773675 into rust-lang:master May 27, 2015
@dotdash dotdash deleted the codegen_test branch July 27, 2015 08:49
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.

7 participants