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

String de-duplication for localtime_r #4025

Closed
tiif opened this issue Nov 10, 2024 · 9 comments · Fixed by rust-lang/rust#133861 or #4069
Closed

String de-duplication for localtime_r #4025

tiif opened this issue Nov 10, 2024 · 9 comments · Fixed by rust-lang/rust#133861 or #4069
Assignees
Labels
A-interpreter Area: affects the core interpreter C-enhancement Category: a PR with an enhancement or an issue tracking an accepted enhancement E-good-first-issue A good way to start contributing, mentoring is available

Comments

@tiif
Copy link
Contributor

tiif commented Nov 10, 2024

Since this is already brought up in #3470 (comment), I will just open a new issue for this.

To resolve the FIXME here,

miri/src/shims/time.rs

Lines 198 to 199 in 052bdcb

// FIXME: String de-duplication is needed so that we only allocate this string only once
// even when there are multiple calls to this function.

we could do:

We should have allocate_bytes which allocates a byte slice, and that should use the cache. allocate_str can call that, and transmute the result to &str.

@tiif
Copy link
Contributor Author

tiif commented Nov 10, 2024

@rustbot label +C-enhancement

@rustbot rustbot added the C-enhancement Category: a PR with an enhancement or an issue tracking an accepted enhancement label Nov 10, 2024
@RalfJung RalfJung added A-interpreter Area: affects the core interpreter E-good-first-issue A good way to start contributing, mentoring is available labels Nov 10, 2024
@shamb0
Copy link
Contributor

shamb0 commented Dec 2, 2024

Hi @tiif, @RalfJung, could you please assign this issue to me? I’d like to work on it.

@saethlin
Copy link
Member

saethlin commented Dec 2, 2024

Done.

@RalfJung
Copy link
Member

RalfJung commented Dec 3, 2024

Thanks for the PR! I am replying here so that the issue has at least a rough sketch of some mentoring instructions.

However, adding a new string cache is the wrong approach here. We already have a deduplication machinery in Miri: this.allocate_str. We don't want a second system doing the same thing. We definitely don't want static storing Pointer, that will go completely wrong if someone runs more than one Miri interpreter instance in the same process.

So this change will have to be done in stages:

  • first a rustc PR that adds a new allocate_bytes, very similar to allocate_str that exist here. allocate_str should then use allocate_bytes.
  • Then a Miri PR that changes the timezone logic to use allocate_bytes. (We don't really need the alloc_os_str_as_c_str stuff there since we start with a String for the timezone, not an OsString.)

workingjubilee added a commit to workingjubilee/rustc that referenced this issue Dec 8, 2024
…str, r=RalfJung

Add allocate_bytes and refactor allocate_str in InterpCx for raw byte…

Fixes rust-lang/miri#4025

This PR introduces a new `allocate_bytes` function in InterpCx and refactors `allocate_str` to use it internally. This change improves memory allocation handling in the interpreter by:

1. Adding `allocate_bytes`:
   - Direct byte slice allocation support
   - Handles both mutable and immutable allocations
   - Maintains proper memory alignment and deduplication

2. Refactoring `allocate_str`:
   - Now uses `allocate_bytes` internally
   - Adds string-specific metadata handling
   - Preserves existing string allocation behavior

This is part 1 of the planned changes to improve timezone string handling in Miri. A follow-up PR will update Miri's timezone logic to use this new allocation mechanism.

Related: rust-lang/miri#4069
workingjubilee added a commit to workingjubilee/rustc that referenced this issue Dec 8, 2024
…str, r=RalfJung

Add allocate_bytes and refactor allocate_str in InterpCx for raw byte…

Fixes rust-lang/miri#4025

This PR introduces a new `allocate_bytes` function in InterpCx and refactors `allocate_str` to use it internally. This change improves memory allocation handling in the interpreter by:

1. Adding `allocate_bytes`:
   - Direct byte slice allocation support
   - Handles both mutable and immutable allocations
   - Maintains proper memory alignment and deduplication

2. Refactoring `allocate_str`:
   - Now uses `allocate_bytes` internally
   - Adds string-specific metadata handling
   - Preserves existing string allocation behavior

This is part 1 of the planned changes to improve timezone string handling in Miri. A follow-up PR will update Miri's timezone logic to use this new allocation mechanism.

Related: rust-lang/miri#4069
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Dec 8, 2024
Rollup merge of rust-lang#133861 - shamb0:refactor_InterpCx_allocate_str, r=RalfJung

Add allocate_bytes and refactor allocate_str in InterpCx for raw byte…

Fixes rust-lang/miri#4025

This PR introduces a new `allocate_bytes` function in InterpCx and refactors `allocate_str` to use it internally. This change improves memory allocation handling in the interpreter by:

1. Adding `allocate_bytes`:
   - Direct byte slice allocation support
   - Handles both mutable and immutable allocations
   - Maintains proper memory alignment and deduplication

2. Refactoring `allocate_str`:
   - Now uses `allocate_bytes` internally
   - Adds string-specific metadata handling
   - Preserves existing string allocation behavior

This is part 1 of the planned changes to improve timezone string handling in Miri. A follow-up PR will update Miri's timezone logic to use this new allocation mechanism.

Related: rust-lang/miri#4069
@RalfJung
Copy link
Member

RalfJung commented Dec 9, 2024

No this has not been fixed yet...

@RalfJung RalfJung reopened this Dec 9, 2024
@DianQK
Copy link
Member

DianQK commented Dec 9, 2024

What is GitHub doing with my account? 🤔

@RalfJung
Copy link
Member

RalfJung commented Dec 9, 2024 via email

@saethlin
Copy link
Member

saethlin commented Dec 9, 2024

This is a long-standing GifHub design flaw. The "fixes" magic commit messages are applied when you push to the default branch of a fork.

Most contributors "fix" this by not keeping their master branch up to date which is gross but better than randomly closing issues. I recently ran into the same problem and had to tweak my local workflow as a result. It's really unfortunate.

@DianQK
Copy link
Member

DianQK commented Dec 9, 2024

Thanks. Very weird behavior. I have prevented accidental pushes by checking "Lock branch" and "Do not allow bypassing the above settings":

Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Delta compression using up to 32 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 447 bytes | 447.00 KiB/s, done.
Total 2 (delta 1), reused 0 (delta 0), pack-reused 0 (from 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
remote: error: GH006: Protected branch update failed for refs/heads/master.
remote:
remote: - Cannot change this locked branch
To github.com:DianQK/rust.git
 ! [remote rejected]         master -> master (protected branch hook declined)
error: failed to push some refs to 'github.com:DianQK/rust.git'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-interpreter Area: affects the core interpreter C-enhancement Category: a PR with an enhancement or an issue tracking an accepted enhancement E-good-first-issue A good way to start contributing, mentoring is available
Projects
None yet
6 participants