Skip to content

remove interior mutability of type-flags#42015

Merged
bors merged 14 commits into
rust-lang:masterfrom
nikomatsakis:chalk-trait-env-2
May 23, 2017
Merged

remove interior mutability of type-flags#42015
bors merged 14 commits into
rust-lang:masterfrom
nikomatsakis:chalk-trait-env-2

Conversation

@nikomatsakis

@nikomatsakis nikomatsakis commented May 15, 2017

Copy link
Copy Markdown
Contributor

We were previously using the flags on Ty<'tcx> instances to do some ad-hoc caching schemes around things like is_sized(), is_freeze(), and moves_by_default(). This PR replaces those schemes with a proper query; the query key is based on the pair of a (ParameterEnvironment<'tcx>, Ty<'tcx>) pair. This is also intended to be a preliminary template for what trait-selection and projection will eventually look like.

I did some performance measurements. In the past, I observed a noticeable speedup (6%) for building rustc, but since I've rebased, the numbers appear to be more of a wash:

Crate Before After Percentage
syntax 167s 166s 0.6% faster
rustc 376s 382s 1.5% slower

Some advantages of this new scheme:

  • is_sized etc are proper queries
  • we get caching across generic fns, so long as trait environment is identical
  • dependency tracking is correct

@rust-highfive

Copy link
Copy Markdown
Contributor

r? @eddyb

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

@nikomatsakis

Copy link
Copy Markdown
Contributor Author

cc @arielb1

Comment thread src/librustc/ty/mod.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Only two flags removed?

@Mark-Simulacrum Mark-Simulacrum left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just some minor nits, no need to bother if you don't want to.

Comment thread src/librustc/infer/mod.rs Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We could just use ty::ParameterEnvironment here and avoid adding the import.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Speaking of which, renaming it to ParamEnv might be a good idea?

@nikomatsakis nikomatsakis May 15, 2017

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.

I always go back and forth on the importing question. I tend to prefer the import, so as to avoid having to write modules everywhere, and comply more closely with the Rust style guidelines (which suggest importing types, but not fns) -- but it does mean more merge conflicts around use declarations, which is annoying.

Comment thread src/librustc/ty/mod.rs Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this is now small enough to be a u16 instead of a u32 bitflags!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It was always wasteful, heh. And I think due to padding it ends up using a lot anyway.

Comment thread src/librustc_trans/context.rs Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Minor, but we could avoid the additional import with ty::ParamEnv. I think this occurs elsewhere, too.

Comment thread src/librustc/ty/mod.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

😻

Comment thread src/librustc/ty/util.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I see you killed some of the shortcutting?

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.

I figured it'd fall out from the caching anyway.

@eddyb eddyb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, modulo nits.

@nikomatsakis

Copy link
Copy Markdown
Contributor Author

ok, I made some style changes (s/ParameterEnvironment/ParamEnv/, removed imports) -- I haven't finished building this locally yet though :)

Comment thread src/librustc/traits/README.md Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks wrong, but is minor. Should ideally be "to the ParamEnv".

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.

fixed.

Comment thread src/librustc/ty/util.rs Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is again somewhat painful to me since we use both ty::ParamEnv and ParamEnv in this file. Don't bother fixing if you don't want to though.

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.

fixed.

@arielb1 arielb1 added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 16, 2017
@bors

bors commented May 18, 2017

Copy link
Copy Markdown
Collaborator

☔ The latest upstream changes (presumably #41911) made this pull request unmergeable. Please resolve the merge conflicts.

@carols10cents carols10cents added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 22, 2017
@carols10cents

Copy link
Copy Markdown
Member

@nikomatsakis looks like this is back in your court now, friendly ping!

Ideally, we'd have the `Ty` inserted directly in the dep-node, but since
we can't do that yet, we extract the characteristic def-id of the type
in question.
@nikomatsakis

Copy link
Copy Markdown
Contributor Author

@bors r=eddyb

@bors

bors commented May 22, 2017

Copy link
Copy Markdown
Collaborator

📌 Commit 83641a9 has been approved by eddyb

@bors

bors commented May 23, 2017

Copy link
Copy Markdown
Collaborator

⌛ Testing commit 83641a9 with merge 9fa25a7...

bors added a commit that referenced this pull request May 23, 2017
remove interior mutability of type-flags

We were previously using the flags on `Ty<'tcx>` instances to do some ad-hoc caching schemes around things like `is_sized()`, `is_freeze()`, and `moves_by_default()`. This PR replaces those schemes with a proper query; the query key is based on the pair of a `(ParameterEnvironment<'tcx>, Ty<'tcx>)` pair. This is also intended to be a preliminary template for what trait-selection and projection will eventually look like.

I did some performance measurements. In the past, I observed a noticeable speedup (6%) for building rustc, but since I've rebased, the numbers appear to be more of a wash:

| Crate | Before | After | Percentage |
| --- | --- | --- | -- |
| syntax | 167s | 166s | 0.6% faster |
| rustc | 376s | 382s | 1.5% slower |

Some advantages of this new scheme:

- `is_sized` etc are proper queries
- we get caching across generic fns, so long as trait environment is identical
- dependency tracking is correct
@bors

bors commented May 23, 2017

Copy link
Copy Markdown
Collaborator

☀️ Test successful - status-appveyor, status-travis
Approved by: eddyb
Pushing 9fa25a7 to master...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants