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

Implement #fmt extension in rustc. #175

Closed
toolness opened this issue Oct 20, 2010 · 11 comments
Closed

Implement #fmt extension in rustc. #175

toolness opened this issue Oct 20, 2010 · 11 comments
Labels
A-frontend Area: Compiler frontend (errors, parsing and HIR) E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

Comments

@toolness
Copy link

Talking to pcwalton here at a Rust hack session and he mentioned that it'd be really great to have a printf() implementation.

At first the implementation could be non-typesafe, but once compiler plugins are implemented, we can actually make one that statically type-checks at compile time.

@graydon
Copy link
Contributor

graydon commented Oct 20, 2010

I wrote one as a syntax extension a couple weeks ago. It's called #fmt, and is typesafe. It's implemented in boot/fe/extfmt.ml.

(Incomplete mind you; I think I left it at the point of only knowing how to do %d, %u, %s, %c and %x. The easy bits. Feel free to extend.)

@graydon
Copy link
Contributor

graydon commented Jan 27, 2011

Shifting to rustc to track the #fmt extension.

@brson
Copy link
Contributor

brson commented Mar 3, 2011

This is partially implemented now, waiting on vector append and crate access.

@brson
Copy link
Contributor

brson commented May 2, 2011

I'm taking a bit of a break from this, so here's a brain dump of where #fmt stands.

This is implemented now for bool (b), string (s), char (c), int (i, d), uint (u), unsigned hex (x, X), unsigned binary (t), and unsigned octal (o) types, with explicit width and precision, and the left justify (-), zero pad (0), sign (+), leave space for sign (' ') flags, all according to printf rules.

Things it doesn't implement yet:

  • specify the index of the argument, count or precision ("%_d", "%2$_1$d", etc)
  • alternate forms (#)
  • print a percent sign (%%)
  • floats

Things that it should probably do:

  • make compile failures of invalid format strings
  • automatically use the correct signed or unsigned type at compile time - right now it's strictly int and uint
  • implement some of Go's interesting printf conversions

Implementation deficiencies:

  • Performance. Needs to do something smarter than string addition.
  • More performance. The syntax-extension-fmt test translates very slowly (1m30s). I'm hoping this gets resolved by other performance work.
  • It's currently not usable from the standard library because it generates ASTs with hardcoded paths prefixed with "std."
  • Needs boatloads of compile-fail tests

@ghost ghost assigned brson May 26, 2011
brson added a commit that referenced this issue Jul 11, 2011
At long last, this patch makes #fmt usable from inside the standard library.
The way it does it us very hackish, but at least it works now.
@msullivan
Copy link
Contributor

Should this be closed?

@brson
Copy link
Contributor

brson commented Aug 3, 2011

No. Not complete.

@brson
Copy link
Contributor

brson commented Aug 3, 2011

I suppose it could be split out into the remaining tasks.

@brson
Copy link
Contributor

brson commented Oct 12, 2011

See also #1014

@kud1ing
Copy link

kud1ing commented Nov 8, 2011

Does this relate to #246?

@brson
Copy link
Contributor

brson commented Nov 8, 2011

Yes. #246 implemented most of #fmt, but the majority of the features I mentioned in my previous comment in May are still not implemented.

@brson
Copy link
Contributor

brson commented Jan 24, 2012

#fmt's deficiencies have slowly been chipped away. I filed new issues for the remaining problems. Closing.

@brson brson closed this as completed Jan 24, 2012
oli-obk pushed a commit to oli-obk/rust that referenced this issue Jul 19, 2017
remove unneeded '-gnu' suffix from compiletest ignore directives
keeperofdakeys pushed a commit to keeperofdakeys/rust that referenced this issue Dec 12, 2017
dlrobertson pushed a commit to dlrobertson/rust that referenced this issue Nov 29, 2018
Say what traits that function items impl by default.
workingjubilee added a commit to workingjubilee/rustc that referenced this issue Nov 10, 2021
Delete travis config, move tests to github actions.
djtech-dev pushed a commit to djtech-dev/rust that referenced this issue Dec 9, 2021
Make symbol and section names optional, for when llvm returns a nullptr.
djtech-dev pushed a commit to djtech-dev/rust that referenced this issue Dec 9, 2021
Also remove unused imports.
antoyo added a commit to antoyo/rust that referenced this issue Jun 7, 2022
celinval pushed a commit to celinval/rust-dev that referenced this issue Nov 22, 2024
By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 and MIT licenses.
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) E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
Projects
None yet
Development

No branches or pull requests

5 participants