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

Trans Refactor: Episode 2 #7182

Closed
wants to merge 13 commits into from
Closed

Conversation

Aatch
Copy link
Contributor

@Aatch Aatch commented Jun 16, 2013

This is another big refactoring of trans though this is unlikely to have much of an
impact on code size or speed.

The major change here is the implementation of a Type struct which is the new
home for all your LLVM TypeRef needs. It's a simple wrapper struct, with static
methods for constructing types, then regular methods for
manipulating/interrogating them. The purpose of this is mostly to make the code
surrounding them somewhat more ideomatic. A line like: T_ptr(T_ptr(T_i8())) is
now Type::i8().ptr_to().ptr_to(),which is much more like regular Rust code.

There are a variety of smaller changes here and there:

  • Remove address spaces. At least it doesn't generate them, I haven't spent much
    time looking for related code.
  • Use a macro for declaring the LLVM intrinsics, makes it look much nicer.
  • Make the type for a string slice actually create a named str_slice type in LLVM,
    this makes reading the appropriate code much easier.
  • Change the way struct and enum type names are generated. This just means
    that a struct like struct Foo { a: int } now produces the IR
    %struct.Foo = type { i64 }, which is much easier to read. Similarly, other structs
    are a bit tighter to make it easier to read.

This PR did get away from me a little, as I occasionally got distracted or as I fixed
up problems with unrelated code that were stopping me from continuing. One major
thing is that this PR contains the work from #7168, since that would have conflicted
with this and it was broken anyway. Sorry for bundling it like this.

Fixes #3670 and #7063


EDIT: This no longer removes the llvm insn stats.

@graydon
Copy link
Contributor

graydon commented Jun 16, 2013

count-llvm-insns has helped us find several major codegen problems, I'd prefer reworking it somehow, not removing it.

@graydon
Copy link
Contributor

graydon commented Jun 16, 2013

Possible: sink it into the block wrapper struct, such that it reports a hierarchy of blocks, not translation fn calls? Alternative: tls?

@Aatch
Copy link
Contributor Author

Aatch commented Jun 17, 2013

@graydon I removed the offending commit (I did see this coming, so deliberately made it easier for me to undo) and re-based. I'm just checking it now.

I'll re-implement the counter using task-local storage, since it makes a bit more sense anyway.

@Aatch
Copy link
Contributor Author

Aatch commented Jun 18, 2013

@graydon I fixed the issue with the error messages and took the opportunity to clean up the ppaux.rs code a little and make sure that the parameterized lifetimes print properly. Originally I changed it to print &'a Foo, but it seems that isn't actually correct for that case, since it's actually a parameter on Foo not a region pointer. So it now correctly prints Foo<'a> and the tests reflect that.

Because of that, this code:

fn foo<'a, 'b, T>(a: Foo<'a,T>) -> Foo<'b,T> {
    a
}

would produce an error something like: expected Foo<'b,'a> found Foo<'a,'a> which is confusing, so this also changes the way type parameters are printed by starting at 'T' and wrapping around to 'A' if the character goes above 'Z'. I made the assumption that if you have > 26 type parameters then you have bigger problems than seeing 'T' twice.

In short, printing a type like Foo<'r,T,R,I> produces Foo<'r,T,U,V> instead of Foo<'r,'a,'b,'c>.

I also added the commit I mentioned to make count-llvm-insn stuff use task-local storage instead of being directly attached to the crate context, though the stats themselves are still on the crate context.

bors added a commit that referenced this pull request Jun 22, 2013
This is another big refactoring of `trans` though this is unlikely to have much of an
impact on code size or speed.

The major change here is the implementation of a `Type` struct which is the new
home for all your LLVM `TypeRef` needs. It's a simple wrapper struct, with static
methods for constructing types, then regular methods for
manipulating/interrogating them. The purpose of this is mostly to make the code
surrounding them somewhat more ideomatic. A line like: `T_ptr(T_ptr(T_i8()))` is 
now `Type::i8().ptr_to().ptr_to()`,which is much more like regular Rust code.

There are a variety of smaller changes here and there:

* Remove address spaces. At least it doesn't generate them, I haven't spent much
  time looking for related code.
* Use a macro for declaring the LLVM intrinsics, makes it look much nicer.
* Make the type for a string slice actually create a named `str_slice` type in LLVM,
  this makes reading the appropriate code much easier.
* Change the way struct and enum type names are generated. This just means
  that a struct like `struct Foo { a: int }` now produces the IR 
  `%struct.Foo = type { i64 }`, which is much easier to read. Similarly, other structs
  are a bit tighter to make it easier to read.

--- --- ---

This PR did get away from me a little, as I occasionally got distracted or as I fixed
up problems with unrelated code that were stopping me from continuing. One major
thing is that this PR contains the work from #7168, since that would have conflicted
with this and it was broken anyway. Sorry for bundling it like this.

Fixes #3670 and #7063

--- --- ---

EDIT: This no longer removes the llvm insn stats.
@bors bors closed this Jun 22, 2013
@emberian
Copy link
Member

benchmark

flip1995 pushed a commit to flip1995/rust that referenced this pull request May 20, 2021
…ant, r=flip1995

For `to_*` variant don't lint in trait impl taking `self` when non-`Copy` type

Lint name: `wrong_self_convention`.
It relaxes rules for `to_*` variant, so it doesn't lint in trait definitions and implementations anymore.
Although, non-`Copy` type implementing trait's `to_*` method taking
`self` feels not good (consumes ownership, so should be rather named `into_`), it would be better if this case was a pedantic lint (allow-by-default) instead.
More information in the discussion with `@flip1995` [here](rust-lang/rust-clippy#7002 (comment))

changelog: `wrong_self_convention`: For `to_*` variant don't lint in trait impl taking `self` when non-`Copy` type
r? `@flip1995`
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.

Dead functions in middle::trans::shape can't be removed
4 participants