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

Add initial support for a new formatting syntax #8182

Closed
wants to merge 1 commit into from

Conversation

alexcrichton
Copy link
Member

This pull request is the initial framework necessary for the advent of a new
string formatting system which will eventually replace fmt!. There's certainly
a lot of stuff going on here, so here's a bit of a summary:

This entire implementation is based off of the discussions had on the mailing
lists at:

It should be noted that this is not ready to actually replace the fmt! macro.
This request simply lays all of the groundwork to implement this new system.
The largest missing component is that all formatting specifiers are ignored.
Additionally, I'd like to take some time to bikeshed the format modifier syntax
after researching it a bit more.

Some notable points of the implementation

Testing wise, I've included

  • parser unit tests
  • runtime unit tests
  • run-pass tests for all the new functionality
  • lots of compile-fail tests

Note that all of the code links will become stale as I rebase, but I don't
think that anything major will be changing at this point. The best examples can
be found in the run-pass test, although there's probably a number of cases that
I've missed!

I also realize that this is very large, although I couldn't figure out a really
good way of splitting it up. If there are suggestions of how to make this a bit
more manageable, than I'd definitely take the time to split things up.

The new macro is available under the name ifmt! (only an intermediate name)
@pcwalton
Copy link
Contributor

pcwalton commented Aug 1, 2013

Having a separate pass for fmt trait gathering seems a little ad-hoc. The Lispy way to do this would be to have the syntax extension itself do this.

@pcwalton
Copy link
Contributor

pcwalton commented Aug 1, 2013

Same with the special section in the metadata. I wonder if we could have a generic way for syntax extensions to register serializable and deserializable data.

@alexcrichton
Copy link
Member Author

Yeah I agree that this would be a lot better with a true syntax extension. Right now our current system of syntax extensions doesn't quite support this because it needs access to all of the crates, sadly. This is probably more of an indication that the syntax extension system should be more flexible than anything else.

@graydon
Copy link
Contributor

graydon commented Aug 2, 2013

Yeah, I"m having a hard time with the quantity of machinery here too. Especially the new metadata and expression parts. Is this all because you're trying to support user-extensible formating operator names (eg. fmt!("{z}", thing) where "z" is previously not-known to fmt!)? If so I think it might be overgeneralizing -- the set of format traits is probably small enough (and sufficiently prone to collision -- global flat namespace favoring short names!) that I think we can manually curate the list in libstd, or the fmt extension itself. I figured we'd keep that lit small-ish and assume that most of the time when users want to customize formatting, they want to do so by implementing an existing formatting-trait, not defining a whole new one.

@brson
Copy link
Contributor

brson commented Aug 2, 2013

+1 to keeping fmt! a pure syntax extension.

@pcwalton
Copy link
Contributor

pcwalton commented Aug 2, 2013

+1 to Graydon's comment about manually curating the list for now.

@alexcrichton
Copy link
Member Author

Sure thing, we'll lose the idea that you can create your own formatting traits, but all in all I think you guys are right that it added a bit too much stuff to the compiler. I'll reopen when I've removed all of that infrastructure.

bors added a commit that referenced this pull request Aug 8, 2013
This is a reopening of #8182, although this removes any abuse of the compiler internals. Now it's just a pure syntax extension (hard coded what the attribute names are).
flip1995 pushed a commit to flip1995/rust that referenced this pull request Dec 30, 2021
cache test item names

This avoids quadratic behavior (collecting all test item names for each `eq_op` instance within the module). However, it invests a good deal of memory to buy this speedup. If that becomes a problem, I may need to change the cache to only store the chain of last visited modules.

This hopefully fixes rust-lang#8171.

---

changelog: none
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