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

deriving cleanup #2810

Closed
catamorphism opened this issue Jul 5, 2012 · 7 comments
Closed

deriving cleanup #2810

catamorphism opened this issue Jul 5, 2012 · 7 comments
Labels
A-frontend Area: Compiler frontend (errors, parsing and HIR) A-syntaxext Area: Syntax extensions C-cleanup Category: PRs that clean code up or issues documenting cleanup. P-low Low priority

Comments

@catamorphism
Copy link
Contributor

  • Hygiene
  • Search for "__" strings
  • Don't assume std is the standard library

(from a FIXME in syntax::ext::deriving)

@sanxiyn
Copy link
Member

sanxiyn commented Jun 24, 2013

auto_serialize changed to auto_encode which changed to deriving(Encodable). FIXME is still there. I updated the issue accordingly.

@alexcrichton
Copy link
Member

auto_serialize and auto_encode have migrated to deriving(Encodable) and deriving(Decodable).

The third bullet on this list is the same issue as #8242.

The first and second bullets are pretty much the same thing, @jbclements I saw you doing some stuff related to hygiene recently. Do you know if that work will "magically fix" this issue of creating code that can't conflict with user's variable names?

@steveklabnik
Copy link
Member

Is this issue still relevant? There are still some __ strings, but I'm not sure what should actually be done to fix them.

@jbclements
Copy link
Contributor

I'm guessing these __ identifiers are module-level bindings, right? We don't yet have hygiene for module-level identifiers.

@pnkfelix
Copy link
Member

pnkfelix commented Sep 2, 2014

@jbclements ah that is good to know. Am I right in assuming that we want to try to put in hygiene for module level identifiers, and we just have not put in the machinery yet?

@alexcrichton
Copy link
Member

triage: P-low

I believe most cleanup here has been done and the leftover __ are either implementation details or either aspects of hygiene which haven't been implemented yet, so I no longer think this is a backwards-compatibility problem for libraries.

@rust-highfive rust-highfive added P-low Low priority and removed P-backcompat-libs labels Mar 24, 2015
@durka
Copy link
Contributor

durka commented Mar 7, 2016

So I went through and looked at the __ strings throughout src/libsyntax_ext/deriving.

They fall into several categories:

  1. function arguments (functions like PartialEq::eq, PartialCmp::partial_cmp, etc)
  2. local bindings, either variables or match pattern captures
  3. type parameters (__H for #[derive(Hash)], __S for #[derive(RustcEncodable)], __D for #[derive(RustcDecodable)])

I believe we can remove the __ from 1 and 2. There is no user code in these functions except for struct and field names, and shadowing those doesn't seem to break things: http://is.gd/5KyXSL expanded (though it does cause non_shorthand_field_patterns warnings)

For the type parameters unfortunately there is a risk of collision: http://is.gd/QYdfx5 expanded
However, it seems to me we could be doing better here: we could actually scan the list of type parameters and make a new one that can't collide.

Thoughts?

durka added a commit to durka/rust that referenced this issue Mar 10, 2016
This changes local variable names in all derives to remove leading
double-underscores. As far as I can tell, this doesn't break anything
because there is no user code in these generated functions except for
struct, field and type parameter names, and this doesn't cause shadowing
of those. But I am still a bit nervous.
durka added a commit to durka/rust that referenced this issue Mar 10, 2016
When deriving Hash, RustcEncodable and RustcDecodable, the syntax extension
needs a type parameter to use in the inner method. They used to use __H, __S
and __D respectively. If this conflicts with a type parameter already declared
for the item, bad times result (see the test). There is no hygiene for type
parameters, but this commit introduces a better heuristic by concatenating the
names of all extant type parameters (and prepending __H).
durka added a commit to durka/rust that referenced this issue Mar 10, 2016
This changes local variable names in all derives to remove leading
double-underscores. As far as I can tell, this doesn't break anything
because there is no user code in these generated functions except for
struct, field and type parameter names, and this doesn't cause shadowing
of those. But I am still a bit nervous.
durka added a commit to durka/rust that referenced this issue Mar 10, 2016
When deriving Hash, RustcEncodable and RustcDecodable, the syntax extension
needs a type parameter to use in the inner method. They used to use __H, __S
and __D respectively. If this conflicts with a type parameter already declared
for the item, bad times result (see the test). There is no hygiene for type
parameters, but this commit introduces a better heuristic by concatenating the
names of all extant type parameters (and prepending __H).
Manishearth added a commit to Manishearth/rust that referenced this issue Mar 12, 2016
cleanups and fixes for #[derive]

This contains a bunch of little cleanups and fixes to `#[derive]`. There are more extensive comments on each individual commit.

- hygiene cleanups
- use `discriminant_value` instead of variant index in `#[derive(Hash)]`
- ~~don't move out of borrowed content in `#[derive(PartialOrd, PartialEq)]`~~
- use `intrinsics::unreachable()` instead of `unreachable!()`

I don't believe there are any breaking changes in here, but I do want some more eyes on that.

Fixes rust-lang#2810 (!), I believe (we still assume that "std" or "core" is the standard library but so does the rest of rustc...).
Fixes rust-lang#21714 (cc @apasel422).
~~Fixes~~ (postponed) rust-lang#24047 (cc @withoutboats @bluss).
Fixes rust-lang#31714 (cc @alexcrichton @bluss).
Fixes rust-lang#31886 (cc @oli-obk).
durka added a commit to durka/rust that referenced this issue Mar 13, 2016
This changes local variable names in all derives to remove leading
double-underscores. As far as I can tell, this doesn't break anything
because there is no user code in these generated functions except for
struct, field and type parameter names, and this doesn't cause shadowing
of those. But I am still a bit nervous.
durka added a commit to durka/rust that referenced this issue Mar 13, 2016
When deriving Hash, RustcEncodable and RustcDecodable, the syntax extension
needs a type parameter to use in the inner method. They used to use __H, __S
and __D respectively. If this conflicts with a type parameter already declared
for the item, bad times result (see the test). There is no hygiene for type
parameters, but this commit introduces a better heuristic by concatenating the
names of all extant type parameters (and prepending __H).
bors added a commit that referenced this issue Mar 13, 2016
cleanups and fixes for #[derive]

This contains a bunch of little cleanups and fixes to `#[derive]`. There are more extensive comments on each individual commit.

- hygiene cleanups
- use `discriminant_value` instead of variant index in `#[derive(Hash)]`
- ~~don't move out of borrowed content in `#[derive(PartialOrd, PartialEq)]`~~
- use `intrinsics::unreachable()` instead of `unreachable!()`

I don't believe there are any breaking changes in here, but I do want some more eyes on that.

Fixes #2810 (!), I believe (we still assume that "std" or "core" is the standard library but so does the rest of rustc...).
Fixes #21714 (cc @apasel422).
~~Fixes~~ (postponed) #24047 (cc @withoutboats @bluss).
Fixes #31714 (cc @alexcrichton @bluss).
Fixes #31886 (cc @oli-obk).
durka added a commit to durka/rust that referenced this issue Mar 14, 2016
This changes local variable names in all derives to remove leading
double-underscores. As far as I can tell, this doesn't break anything
because there is no user code in these generated functions except for
struct, field and type parameter names, and this doesn't cause shadowing
of those. But I am still a bit nervous.
durka added a commit to durka/rust that referenced this issue Mar 14, 2016
When deriving Hash, RustcEncodable and RustcDecodable, the syntax extension
needs a type parameter to use in the inner method. They used to use __H, __S
and __D respectively. If this conflicts with a type parameter already declared
for the item, bad times result (see the test). There is no hygiene for type
parameters, but this commit introduces a better heuristic by concatenating the
names of all extant type parameters (and prepending __H).
bors added a commit that referenced this issue Mar 15, 2016
derive: clean up hygiene

derive: clean up hygiene

Fixes #2810.

Spawned from #32139.

r? @alexcrichton
bors pushed a commit to rust-lang-ci/rust that referenced this issue May 15, 2021
When newline_style is set to Windows, an empty line inside of a macro
results in `\r` being passed to the `fold()` in `MacroBranch::rewrite()`.

`\r` is technically not an empty string, so we try to indent it, leaving
trailing whitespaces behind, even though that was not intended
(as far as I can see).

This commit replaces the `!l.is_empty()` check with calling
`is_empty_line()`, since trying to indent any whitespace-only string
will probably result in problematic trailing whitespaces.

Fixes: rust-lang#2810
bors pushed a commit to rust-lang-ci/rust that referenced this issue May 15, 2021
Try to fix formatting failures on Windows (issue rust-lang#2810)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-frontend Area: Compiler frontend (errors, parsing and HIR) A-syntaxext Area: Syntax extensions C-cleanup Category: PRs that clean code up or issues documenting cleanup. P-low Low priority
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants