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

Functionality for int_format_into for integer types #138338

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

madhav-madhusoodanan
Copy link
Contributor

@madhav-madhusoodanan madhav-madhusoodanan commented Mar 11, 2025

ACP approval: rust-lang/libs-team#546 (comment)

Context

  1. Implemented integer formatting into a fixed-size buffer without relying on fmt.
  2. Added a NumBuffer type to help with this process.

Associated Issue

r? @hanna-kruppe

@rustbot
Copy link
Collaborator

rustbot commented Mar 11, 2025

Failed to set assignee to hanna-kruppe: invalid assignee

Note: Only org members with at least the repository "read" role, users with write permissions, or people who have commented on the PR may be assigned.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Mar 11, 2025
@madhav-madhusoodanan
Copy link
Contributor Author

@rustbot author

@rustbot rustbot 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 Mar 11, 2025
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot added O-solid Operating System: SOLID O-unix Operating system: Unix-like O-wasi Operating system: Wasi, Webassembly System Interface O-wasm Target: WASM (WebAssembly), http://webassembly.org/ O-windows Operating system: Windows labels Mar 18, 2025
@madhav-madhusoodanan
Copy link
Contributor Author

madhav-madhusoodanan commented Mar 18, 2025

@rustbot label -O-hermit -O-SGX -O-solid -O-wasi -O-wasm -O-windows -O-unix

@rustbot rustbot removed O-hermit Operating System: Hermit O-SGX Target: SGX O-solid Operating System: SOLID O-wasi Operating system: Wasi, Webassembly System Interface O-wasm Target: WASM (WebAssembly), http://webassembly.org/ O-windows Operating system: Windows O-unix Operating system: Unix-like labels Mar 18, 2025
@madhav-madhusoodanan madhav-madhusoodanan marked this pull request as ready for review March 18, 2025 15:00
@madhav-madhusoodanan
Copy link
Contributor Author

I was able to gain more clarity on what was needed, and I've moved the updates to the fmt module.

Primarily I've broken down impl_Display into impl_NumBuffer (the primitives) and impl_Display so that I can reuse functionality into the new macro impl_FormatInto.

Sorry for the long history in this PR. Please let me know if this looks good.

@madhav-madhusoodanan madhav-madhusoodanan changed the title [WIP] Functionality for int_format_into for integer types Functionality for int_format_into for integer types Mar 18, 2025
Copy link
Contributor

@hanna-kruppe hanna-kruppe left a comment

Choose a reason for hiding this comment

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

Thank you for working on this! The bird's eye view of the diff is now basically what I'd expect. I left some smaller comments I've noticed while scrolling through. I don't expect I'll have the time to review the implementation details as carefully as unsafe code deserves, so please work out those details with a reviewer who actually has permissions on this repository.

Comment on lines 29 to 56
pub fn len(&self) -> usize {
BUF_SIZE
}

/// Extracts a slice of the contents of the buffer.
/// `index` must be bounds-checked before calling this function.
///
/// SAFETY: `index` is bound-checked by the caller.
#[unstable(feature = "int_format_into", issue = "138215")]
pub unsafe fn extract<I>(&self, index: I) -> &I::Output
where
I: SliceIndex<[MaybeUninit<u8>]>,
{
// SAFETY: `index` is bound-checked by the caller.
unsafe { self.contents.get_unchecked(index) }
}

/// Returns a mutable pointer pointing to the start of the buffer.
#[unstable(feature = "int_format_into", issue = "138215")]
pub fn extract_start_mut_ptr(&mut self) -> *mut u8 {
MaybeUninit::slice_as_mut_ptr(&mut self.contents)
}

/// Writes data at index `offset` of the buffer.
///
/// SAFETY: `offset` is bound-checked by the caller
#[unstable(feature = "int_format_into", issue = "138215")]
pub unsafe fn write(&mut self, offset: usize, data: u8) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Likewise, none of these methods should be public I think. Or, if they need to be public e.g. for unit tests of the standard library, they should be behind a perma-unstable "for internal use only" feature gate, not tied to int_format_into / #138215.

Copy link
Contributor Author

@madhav-madhusoodanan madhav-madhusoodanan Mar 18, 2025

Choose a reason for hiding this comment

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

Other than the new function, I don't see usage of the other functions in other crates.
Thank you for suggesting me.

@madhav-madhusoodanan
Copy link
Contributor Author

madhav-madhusoodanan commented Mar 18, 2025

Thank you for working on this! The bird's eye view of the diff is now basically what I'd expect. I left some smaller comments I've noticed while scrolling through. I don't expect I'll have the time to review the implementation details as carefully as unsafe code deserves, so please work out those details with a reviewer who actually has permissions on this repository.

I must thank you for patiently going through my updates multiple times. There was a lot for me to learn.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@scottmcm
Copy link
Member

I'm going to re-roll to get someone hopefully more familiar with the formatting stuff.
r? libs

@rustbot rustbot assigned thomcc and unassigned scottmcm Mar 20, 2025
@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-llvm-18 failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
#19 exporting to docker image format
#19 sending tarball 19.9s done
#19 DONE 24.6s
##[endgroup]
Setting extra environment values for docker:  --env ENABLE_GCC_CODEGEN=1 --env GCC_EXEC_PREFIX=/usr/lib/gcc/
[CI_JOB_NAME=x86_64-gnu-llvm-18]
[CI_JOB_NAME=x86_64-gnu-llvm-18]
debug: `DISABLE_CI_RUSTC_IF_INCOMPATIBLE` configured.
---
sccache: Listening on address 127.0.0.1:4226
##[group]Configure the build
configure: processing command line
configure: 
configure: build.configure-args := ['--build=x86_64-unknown-linux-gnu', '--llvm-root=/usr/lib/llvm-18', '--enable-llvm-link-shared', '--set', 'rust.randomize-layout=true', '--set', 'rust.thin-lto-import-instr-limit=10', '--set', 'build.print-step-timings', '--enable-verbose-tests', '--set', 'build.metrics', '--enable-verbose-configure', '--enable-sccache', '--disable-manage-submodules', '--enable-locked-deps', '--enable-cargo-native-static', '--set', 'rust.codegen-units-std=1', '--set', 'dist.compression-profile=balanced', '--dist-compression-formats=xz', '--set', 'rust.lld=false', '--disable-dist-src', '--release-channel=nightly', '--enable-debug-assertions', '--enable-overflow-checks', '--enable-llvm-assertions', '--set', 'rust.verify-llvm-ir', '--set', 'rust.codegen-backends=llvm,cranelift,gcc', '--set', 'llvm.static-libstdcpp', '--enable-new-symbol-mangling']
configure: build.build          := x86_64-unknown-linux-gnu
configure: target.x86_64-unknown-linux-gnu.llvm-config := /usr/lib/llvm-18/bin/llvm-config
configure: llvm.link-shared     := True
configure: rust.randomize-layout := True
configure: rust.thin-lto-import-instr-limit := 10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants