Skip to content

Allow limited access to OsStr bytes - #109698

Merged
bors merged 6 commits into
rust-lang:masterfrom
epage:wtf
May 31, 2023
Merged

Allow limited access to OsStr bytes#109698
bors merged 6 commits into
rust-lang:masterfrom
epage:wtf

Conversation

@epage

@epageepage commented Mar 28, 2023

Copy link
Copy Markdown
Contributor

OsStr has historically kept its implementation details private out of
concern for locking us into a specific encoding on Windows.

This is an alternative to #95290 which proposed specifying the encoding on Windows. Instead, this
only specifies that for cross-platform code, OsStr's encoding is a superset of UTF-8 and defines
rules for safely interacting with it

At minimum, this can greatly simplify the os_str_bytes crate and every
arg parser that interacts with OsStr directly (which is most of those
that support invalid UTF-8).

Tracking issue: #111544

`OsStr` has historically kept its implementation details private out of
concern for locking us into a specific encoding on Windows.
This is an alternative to rust-lang#95290 which proposed specifying the encoding on Windows. Instead, this
only specifies that for cross-platform code, `OsStr`'s encoding is a superset of UTF-8 and defines
rules for safely interacting with it
At minimum, this can greatly simplify the `os_str_bytes` crate and every
arg parser that interacts with `OsStr` directly (which is most of those
that support invalid UTF-8).
@rustbot

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @cuviper (or someone else) soon.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbotrustbot 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 28, 2023
@rustbot

Copy link
Copy Markdown
Collaborator

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

@epage
epageforce-pushed the wtf branch 2 times, most recently from 01f8d93 to 0d87d66CompareMarch 28, 2023 14:26
@cuviper

Copy link
Copy Markdown
Member

I think this counts as new guarantee for API purposes.

@rustbot label +T-libs-api -T-libs
r? libs-api

@rustbotrustbot added T-libs-api [DEPRECATED; DO NOT USE] and removed T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Mar 28, 2023
@rustbotrustbot assigned Amanieu and unassigned cuviperMar 28, 2023
@ChrisDenton

Copy link
Copy Markdown
Member

Out of interest, was there anything in particular that motivated you to propose this now?

@the8472

Copy link
Copy Markdown
Member

I think this should come with an example since it's a wide pointer. Conversion from C to Rust has to jump through extra hoops.

@joshtriplett

Copy link
Copy Markdown
Member

I'm personally amenable to adding this guarantee, but I do agree with @the8472 that we need to confirm that this will actually work as intended.

@epageepage changed the title Allow FFI support for OsStrAllow limited access to OsStr bytes in unsafe blocksMar 31, 2023
@epage

epage commented Mar 31, 2023

Copy link
Copy Markdown
ContributorAuthor

Sorry for the lack of details and confusion on this. I was under the impression that working towards my final goal would best be done in smaller steps of defining OsStr but that meant I didn't have a use case for it which I recognize can be frustrating to deal with when evaluating a major change like this. I've since updated the documentation and PR to reflect the minimum of what I need for my use case: clap and other CLI tools that need to deal with parsing and splitting up OsStrs for however much valid UTF-8 is in them.

My hope that this more limited alternative to #95290 will have a chance to move forward.

@ChrisDenton

Copy link
Copy Markdown
Member

If we do this, I wonder if it makes sense to also offer a split_at method on OsStr that panics if used incorrectly. I.e.:

// Similar to `str::split_at` and `[T]::split_at`// Panics if `mid` is not on a UTF-8 code point boundary.fnsplit_at(&self,mid:usize) -> (&OsStr,&OsStr);

Splitting and joining are the two hazard areas when dealing with known valid OsStrs (whatever form they're in). We have OsString::push for the joining case but nothing to help with splitting. I think it would be unfortunate if we don't have some safe way to check you're doing it right.

@epage

epage commented Mar 31, 2023

Copy link
Copy Markdown
ContributorAuthor

but nothing to help with splitting. I think it would be unfortunate if we don't have some safe way to check you're doing it right.

A part of me finds it weird to offer a safe function like split_at that takes a parameter (mid) that can only be calculated from another type derived from with unsafe code. Documenting use of split_at would then further raise visibility of this feature, for both good (people getting stuff done) and bad (risk of misuse). However, I do see the benefit as that does greatly reduce the risk of something going wrong. In my experiments with transmuting &OsStr, I wrapped all byte operations in functions that only allowed deriving mid from &str parameters (e.g. OsStrExt::strip_prefix(&self, prefix: &str)) so I knew I was splitting at a safe boundary.

EDIT: To make clear, I'm open to adding that function if that is the direction we want to take this.

@ChrisDenton

Copy link
Copy Markdown
Member

Hm, we could offer some safe way to get an index according to these rules. E.g.

// Returns the byte index where `searcher` first returns true.// `searcher` can inspect `char`s decoded from UTF-8.// Non UTF-8 encoded characters are skipped.fnfind_char(&self,searcher:FnMut(char) -> bool) -> Option<usize>;

But at this point I'll stop because I'm practically designing yet another alternative approach.

@chorman0773

Copy link
Copy Markdown
Contributor

Does this confirm that OsStr is a "bag of bytes" on any platform, in that you can put and leave any (init, non-pointer) bytes in the slice, or am I misinterpreting the proposal?

@epage

epage commented Apr 11, 2023

Copy link
Copy Markdown
ContributorAuthor

Does this confirm that OsStr is a "bag of bytes" on any platform, in that you can put and leave any (init, non-pointer) bytes in the slice, or am I misinterpreting the proposal?

For now, this proposals restricts what is safe to transmute from &[u8] to &OsStr, so this does not work as an arbitrary bag of bytes

//! - When [transmuting] from `&[u8]` to `&OsStr`,//! - the slice may only include content from comparable `&OsStr` (see above) or be valid UTF-8//! - any splits of the `&OsStr` must be along char boundaries (the first byte of a UTF-8 code//! point sequence)

@BurntSushi

Copy link
Copy Markdown
Member

I think I buy the rules as written, but I would like to see a doc example using unsafe, along with a SAFETY comment justifying why it's OK. I think that would also help others write correct code.

Also, cc @SimonSapin to see what you think about this. (Let me know if you want me to stop pinging you about this, but I always think of you as the champion against a change like this.)

Popping up a level, this is kind of an interesting use of unsafe, isn't it? It's carving out a strictly more conservative set of things the caller needs to uphold than what is actually true. I wonder, for example, how Miri might detect UB in a case like this.

@blyxxyz

Copy link
Copy Markdown
Contributor

Does this confirm that OsStr is a "bag of bytes" on any platform, in that you can put and leave any (init, non-pointer) bytes in the slice, or am I misinterpreting the proposal?

It actually isn't a bag of bytes on Windows, it must be WTF-8-encoded or you can start reading out of bounds:

fnmain(){let b:&[u8] = b"\xC2";let s:&std::ffi::OsStr = unsafe{ std::mem::transmute(b)};dbg!(s);}
$ cargo run -q --target x86_64-pc-windows-gnu[src/main.rs:4] s = "\u{9b}:] = \n\0\0\0\0\0\0\01\u{10}L[...]thread 'main' panicked at 'failed printing to stderr: Windows stdio in console mode does not support writing non-UTF-8 byte sequences', library\std\src\io\stdio.rs:1008:9

The proposal is phrased to never produce invalid WTF-8.

I think that as written now it allows for any OsStr encoding that's a self-synchronizing superset of UTF-8.

@asquared31415

asquared31415 commented Apr 11, 2023

Copy link
Copy Markdown
Contributor

When [transmuting] from &[u8] to &OsStr,

This wording would provide an additional guarantee that &[u8] and &OsStr have the same layout in terms of their (ptr, len) pairs. As far as I am aware, this is something that is not currently guaranteed, and I don't recall the current stance on guaranteeing layout compatibility between any two fat pointer types that have different pointees.

@borsbors added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 28, 2023
@epage
epageforce-pushed the wtf branch 2 times, most recently from e2d912b to e6a35c4CompareMay 29, 2023 12:57
@epage

Copy link
Copy Markdown
ContributorAuthor

I've addressed what caused the wasm build failure and it should be good to go again.

@Amanieu

Copy link
Copy Markdown
Member

@bors r+

@bors

bors commented May 30, 2023

Copy link
Copy Markdown
Collaborator

📌 Commit e6a35c4 has been approved by Amanieu

It is now in the queue for this repository.

@borsbors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 30, 2023
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request May 30, 2023
Allow limited access to `OsStr` bytes
`OsStr` has historically kept its implementation details private out of
concern for locking us into a specific encoding on Windows.
This is an alternative to rust-lang#95290 which proposed specifying the encoding on Windows. Instead, this
only specifies that for cross-platform code, `OsStr`'s encoding is a superset of UTF-8 and defines
rules for safely interacting with it
At minimum, this can greatly simplify the `os_str_bytes` crate and every
arg parser that interacts with `OsStr` directly (which is most of those
that support invalid UTF-8).
Tracking issue: rust-lang#111544
@Dylan-DPCDylan-DPC mentioned this pull request May 30, 2023
@bors

bors commented May 30, 2023

Copy link
Copy Markdown
Collaborator

⌛ Testing commit e6a35c4 with merge 9610dfe...

@bors

bors commented May 31, 2023

Copy link
Copy Markdown
Collaborator

☀️ Test successful - checks-actions
Approved by: Amanieu
Pushing 9610dfe to master...

@borsbors added the merged-by-bors This PR was explicitly merged by bors. label May 31, 2023
@bors
bors merged commit 9610dfe into rust-lang:masterMay 31, 2023
@rustbotrustbot added this to the 1.72.0 milestone May 31, 2023
@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (9610dfe): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

meanrangecount
Regressions ❌
(primary)
--0
Regressions ❌
(secondary)
--0
Improvements ✅
(primary)
--0
Improvements ✅
(secondary)
-3.5%[-4.6%, -2.5%]2
All ❌✅ (primary)--0

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

meanrangecount
Regressions ❌
(primary)
0.0%[0.0%, 0.1%]5
Regressions ❌
(secondary)
--0
Improvements ✅
(primary)
-0.1%[-0.1%, -0.1%]3
Improvements ✅
(secondary)
--0
All ❌✅ (primary)-0.0%[-0.1%, 0.1%]8

Bootstrap: 642.846s -> 643.715s (0.14%)

@apirainoapiraino removed the to-announce Announce this issue on triage meeting label Jun 15, 2023
epage added a commit to epage/rust that referenced this pull request Jul 7, 2023
This extends rust-lang#109698 to allow no-cost conversion between `Vec<u8>` and `OsString`
as suggested in feedback from `os_str_bytes` crate in rust-lang#111544.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 22, 2023
Allow limited access to `OsString` bytes
This extends rust-lang#109698 to allow no-cost conversion between `Vec<u8>` and `OsString` as suggested in feedback from `os_str_bytes` crate in rust-lang#111544.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 22, 2023
Allow limited access to `OsString` bytes
This extends rust-lang#109698 to allow no-cost conversion between `Vec<u8>` and `OsString` as suggested in feedback from `os_str_bytes` crate in rust-lang#111544.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 22, 2023
Allow limited access to `OsString` bytes
This extends rust-lang#109698 to allow no-cost conversion between `Vec<u8>` and `OsString` as suggested in feedback from `os_str_bytes` crate in rust-lang#111544.
@epage
epage deleted the wtf branch July 22, 2023 14:48
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.merged-by-borsThis PR was explicitly merged by bors.S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-libs-api[DEPRECATED; DO NOT USE]

Projects

None yet

Development

Successfully merging this pull request may close these issues.

20 participants

@epage@rustbot@cuviper@ChrisDenton@the8472@joshtriplett@chorman0773@BurntSushi@blyxxyz@asquared31415@SimonSapin@dylni@rust-log-analyzer@m-ou-se@rfcbot@Amanieu@QuineDot@bors@rust-timer@teor2345
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Allow limited access to `OsStr` bytes by epage · Pull Request #109698 · rust-lang/rust · GitHub
Skip to content

Allow limited access to OsStr bytes - #109698

Merged
bors merged 6 commits into
rust-lang:masterfrom
epage:wtf
May 31, 2023
Merged

Allow limited access to OsStr bytes#109698
bors merged 6 commits into
rust-lang:masterfrom
epage:wtf

Conversation

@epage

@epageepage commented Mar 28, 2023

Copy link
Copy Markdown
Contributor

OsStr has historically kept its implementation details private out of
concern for locking us into a specific encoding on Windows.

This is an alternative to #95290 which proposed specifying the encoding on Windows. Instead, this
only specifies that for cross-platform code, OsStr's encoding is a superset of UTF-8 and defines
rules for safely interacting with it

At minimum, this can greatly simplify the os_str_bytes crate and every
arg parser that interacts with OsStr directly (which is most of those
that support invalid UTF-8).

Tracking issue: #111544

`OsStr` has historically kept its implementation details private out of
concern for locking us into a specific encoding on Windows.
This is an alternative to rust-lang#95290 which proposed specifying the encoding on Windows. Instead, this
only specifies that for cross-platform code, `OsStr`'s encoding is a superset of UTF-8 and defines
rules for safely interacting with it
At minimum, this can greatly simplify the `os_str_bytes` crate and every
arg parser that interacts with `OsStr` directly (which is most of those
that support invalid UTF-8).
@rustbot

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @cuviper (or someone else) soon.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbotrustbot 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 28, 2023
@rustbot

Copy link
Copy Markdown
Collaborator

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

@epage
epageforce-pushed the wtf branch 2 times, most recently from 01f8d93 to 0d87d66CompareMarch 28, 2023 14:26
@cuviper

Copy link
Copy Markdown
Member

I think this counts as new guarantee for API purposes.

@rustbot label +T-libs-api -T-libs
r? libs-api

@rustbotrustbot added T-libs-api [DEPRECATED; DO NOT USE] and removed T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Mar 28, 2023
@rustbotrustbot assigned Amanieu and unassigned cuviperMar 28, 2023
@ChrisDenton

Copy link
Copy Markdown
Member

Out of interest, was there anything in particular that motivated you to propose this now?

@the8472

Copy link
Copy Markdown
Member

I think this should come with an example since it's a wide pointer. Conversion from C to Rust has to jump through extra hoops.

@joshtriplett

Copy link
Copy Markdown
Member

I'm personally amenable to adding this guarantee, but I do agree with @the8472 that we need to confirm that this will actually work as intended.

@epageepage changed the title Allow FFI support for OsStrAllow limited access to OsStr bytes in unsafe blocksMar 31, 2023
@epage

epage commented Mar 31, 2023

Copy link
Copy Markdown
ContributorAuthor

Sorry for the lack of details and confusion on this. I was under the impression that working towards my final goal would best be done in smaller steps of defining OsStr but that meant I didn't have a use case for it which I recognize can be frustrating to deal with when evaluating a major change like this. I've since updated the documentation and PR to reflect the minimum of what I need for my use case: clap and other CLI tools that need to deal with parsing and splitting up OsStrs for however much valid UTF-8 is in them.

My hope that this more limited alternative to #95290 will have a chance to move forward.

@ChrisDenton

Copy link
Copy Markdown
Member

If we do this, I wonder if it makes sense to also offer a split_at method on OsStr that panics if used incorrectly. I.e.:

// Similar to `str::split_at` and `[T]::split_at`// Panics if `mid` is not on a UTF-8 code point boundary.fnsplit_at(&self,mid:usize) -> (&OsStr,&OsStr);

Splitting and joining are the two hazard areas when dealing with known valid OsStrs (whatever form they're in). We have OsString::push for the joining case but nothing to help with splitting. I think it would be unfortunate if we don't have some safe way to check you're doing it right.

@epage

epage commented Mar 31, 2023

Copy link
Copy Markdown
ContributorAuthor

but nothing to help with splitting. I think it would be unfortunate if we don't have some safe way to check you're doing it right.

A part of me finds it weird to offer a safe function like split_at that takes a parameter (mid) that can only be calculated from another type derived from with unsafe code. Documenting use of split_at would then further raise visibility of this feature, for both good (people getting stuff done) and bad (risk of misuse). However, I do see the benefit as that does greatly reduce the risk of something going wrong. In my experiments with transmuting &OsStr, I wrapped all byte operations in functions that only allowed deriving mid from &str parameters (e.g. OsStrExt::strip_prefix(&self, prefix: &str)) so I knew I was splitting at a safe boundary.

EDIT: To make clear, I'm open to adding that function if that is the direction we want to take this.

@ChrisDenton

Copy link
Copy Markdown
Member

Hm, we could offer some safe way to get an index according to these rules. E.g.

// Returns the byte index where `searcher` first returns true.// `searcher` can inspect `char`s decoded from UTF-8.// Non UTF-8 encoded characters are skipped.fnfind_char(&self,searcher:FnMut(char) -> bool) -> Option<usize>;

But at this point I'll stop because I'm practically designing yet another alternative approach.

@chorman0773

Copy link
Copy Markdown
Contributor

Does this confirm that OsStr is a "bag of bytes" on any platform, in that you can put and leave any (init, non-pointer) bytes in the slice, or am I misinterpreting the proposal?

@epage

epage commented Apr 11, 2023

Copy link
Copy Markdown
ContributorAuthor

Does this confirm that OsStr is a "bag of bytes" on any platform, in that you can put and leave any (init, non-pointer) bytes in the slice, or am I misinterpreting the proposal?

For now, this proposals restricts what is safe to transmute from &[u8] to &OsStr, so this does not work as an arbitrary bag of bytes

//! - When [transmuting] from `&[u8]` to `&OsStr`,//! - the slice may only include content from comparable `&OsStr` (see above) or be valid UTF-8//! - any splits of the `&OsStr` must be along char boundaries (the first byte of a UTF-8 code//! point sequence)

@BurntSushi

Copy link
Copy Markdown
Member

I think I buy the rules as written, but I would like to see a doc example using unsafe, along with a SAFETY comment justifying why it's OK. I think that would also help others write correct code.

Also, cc @SimonSapin to see what you think about this. (Let me know if you want me to stop pinging you about this, but I always think of you as the champion against a change like this.)

Popping up a level, this is kind of an interesting use of unsafe, isn't it? It's carving out a strictly more conservative set of things the caller needs to uphold than what is actually true. I wonder, for example, how Miri might detect UB in a case like this.

@blyxxyz

Copy link
Copy Markdown
Contributor

Does this confirm that OsStr is a "bag of bytes" on any platform, in that you can put and leave any (init, non-pointer) bytes in the slice, or am I misinterpreting the proposal?

It actually isn't a bag of bytes on Windows, it must be WTF-8-encoded or you can start reading out of bounds:

fnmain(){let b:&[u8] = b"\xC2";let s:&std::ffi::OsStr = unsafe{ std::mem::transmute(b)};dbg!(s);}
$ cargo run -q --target x86_64-pc-windows-gnu[src/main.rs:4] s = "\u{9b}:] = \n\0\0\0\0\0\0\01\u{10}L[...]thread 'main' panicked at 'failed printing to stderr: Windows stdio in console mode does not support writing non-UTF-8 byte sequences', library\std\src\io\stdio.rs:1008:9

The proposal is phrased to never produce invalid WTF-8.

I think that as written now it allows for any OsStr encoding that's a self-synchronizing superset of UTF-8.

@asquared31415

asquared31415 commented Apr 11, 2023

Copy link
Copy Markdown
Contributor

When [transmuting] from &[u8] to &OsStr,

This wording would provide an additional guarantee that &[u8] and &OsStr have the same layout in terms of their (ptr, len) pairs. As far as I am aware, this is something that is not currently guaranteed, and I don't recall the current stance on guaranteeing layout compatibility between any two fat pointer types that have different pointees.

@borsbors added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 28, 2023
@epage
epageforce-pushed the wtf branch 2 times, most recently from e2d912b to e6a35c4CompareMay 29, 2023 12:57
@epage

Copy link
Copy Markdown
ContributorAuthor

I've addressed what caused the wasm build failure and it should be good to go again.

@Amanieu

Copy link
Copy Markdown
Member

@bors r+

@bors

bors commented May 30, 2023

Copy link
Copy Markdown
Collaborator

📌 Commit e6a35c4 has been approved by Amanieu

It is now in the queue for this repository.

@borsbors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 30, 2023
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request May 30, 2023
Allow limited access to `OsStr` bytes
`OsStr` has historically kept its implementation details private out of
concern for locking us into a specific encoding on Windows.
This is an alternative to rust-lang#95290 which proposed specifying the encoding on Windows. Instead, this
only specifies that for cross-platform code, `OsStr`'s encoding is a superset of UTF-8 and defines
rules for safely interacting with it
At minimum, this can greatly simplify the `os_str_bytes` crate and every
arg parser that interacts with `OsStr` directly (which is most of those
that support invalid UTF-8).
Tracking issue: rust-lang#111544
@Dylan-DPCDylan-DPC mentioned this pull request May 30, 2023
@bors

bors commented May 30, 2023

Copy link
Copy Markdown
Collaborator

⌛ Testing commit e6a35c4 with merge 9610dfe...

@bors

bors commented May 31, 2023

Copy link
Copy Markdown
Collaborator

☀️ Test successful - checks-actions
Approved by: Amanieu
Pushing 9610dfe to master...

@borsbors added the merged-by-bors This PR was explicitly merged by bors. label May 31, 2023
@bors
bors merged commit 9610dfe into rust-lang:masterMay 31, 2023
@rustbotrustbot added this to the 1.72.0 milestone May 31, 2023
@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (9610dfe): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

meanrangecount
Regressions ❌
(primary)
--0
Regressions ❌
(secondary)
--0
Improvements ✅
(primary)
--0
Improvements ✅
(secondary)
-3.5%[-4.6%, -2.5%]2
All ❌✅ (primary)--0

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

meanrangecount
Regressions ❌
(primary)
0.0%[0.0%, 0.1%]5
Regressions ❌
(secondary)
--0
Improvements ✅
(primary)
-0.1%[-0.1%, -0.1%]3
Improvements ✅
(secondary)
--0
All ❌✅ (primary)-0.0%[-0.1%, 0.1%]8

Bootstrap: 642.846s -> 643.715s (0.14%)

@apirainoapiraino removed the to-announce Announce this issue on triage meeting label Jun 15, 2023
epage added a commit to epage/rust that referenced this pull request Jul 7, 2023
This extends rust-lang#109698 to allow no-cost conversion between `Vec<u8>` and `OsString`
as suggested in feedback from `os_str_bytes` crate in rust-lang#111544.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 22, 2023
Allow limited access to `OsString` bytes
This extends rust-lang#109698 to allow no-cost conversion between `Vec<u8>` and `OsString` as suggested in feedback from `os_str_bytes` crate in rust-lang#111544.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 22, 2023
Allow limited access to `OsString` bytes
This extends rust-lang#109698 to allow no-cost conversion between `Vec<u8>` and `OsString` as suggested in feedback from `os_str_bytes` crate in rust-lang#111544.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 22, 2023
Allow limited access to `OsString` bytes
This extends rust-lang#109698 to allow no-cost conversion between `Vec<u8>` and `OsString` as suggested in feedback from `os_str_bytes` crate in rust-lang#111544.
@epage
epage deleted the wtf branch July 22, 2023 14:48
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.merged-by-borsThis PR was explicitly merged by bors.S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-libs-api[DEPRECATED; DO NOT USE]

Projects

None yet

Development

Successfully merging this pull request may close these issues.

20 participants

@epage@rustbot@cuviper@ChrisDenton@the8472@joshtriplett@chorman0773@BurntSushi@blyxxyz@asquared31415@SimonSapin@dylni@rust-log-analyzer@m-ou-se@rfcbot@Amanieu@QuineDot@bors@rust-timer@teor2345
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Allow limited access to `OsStr` bytes by epage · Pull Request #109698 · rust-lang/rust · GitHub
Skip to content

Allow limited access to OsStr bytes - #109698

Merged
bors merged 6 commits into
rust-lang:masterfrom
epage:wtf
May 31, 2023
Merged

Allow limited access to OsStr bytes#109698
bors merged 6 commits into
rust-lang:masterfrom
epage:wtf

Conversation

@epage

@epageepage commented Mar 28, 2023

Copy link
Copy Markdown
Contributor

OsStr has historically kept its implementation details private out of
concern for locking us into a specific encoding on Windows.

This is an alternative to #95290 which proposed specifying the encoding on Windows. Instead, this
only specifies that for cross-platform code, OsStr's encoding is a superset of UTF-8 and defines
rules for safely interacting with it

At minimum, this can greatly simplify the os_str_bytes crate and every
arg parser that interacts with OsStr directly (which is most of those
that support invalid UTF-8).

Tracking issue: #111544

`OsStr` has historically kept its implementation details private out of
concern for locking us into a specific encoding on Windows.
This is an alternative to rust-lang#95290 which proposed specifying the encoding on Windows. Instead, this
only specifies that for cross-platform code, `OsStr`'s encoding is a superset of UTF-8 and defines
rules for safely interacting with it
At minimum, this can greatly simplify the `os_str_bytes` crate and every
arg parser that interacts with `OsStr` directly (which is most of those
that support invalid UTF-8).
@rustbot

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @cuviper (or someone else) soon.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbotrustbot 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 28, 2023
@rustbot

Copy link
Copy Markdown
Collaborator

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

@epage
epageforce-pushed the wtf branch 2 times, most recently from 01f8d93 to 0d87d66CompareMarch 28, 2023 14:26
@cuviper

Copy link
Copy Markdown
Member

I think this counts as new guarantee for API purposes.

@rustbot label +T-libs-api -T-libs
r? libs-api

@rustbotrustbot added T-libs-api [DEPRECATED; DO NOT USE] and removed T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Mar 28, 2023
@rustbotrustbot assigned Amanieu and unassigned cuviperMar 28, 2023
@ChrisDenton

Copy link
Copy Markdown
Member

Out of interest, was there anything in particular that motivated you to propose this now?

@the8472

Copy link
Copy Markdown
Member

I think this should come with an example since it's a wide pointer. Conversion from C to Rust has to jump through extra hoops.

@joshtriplett

Copy link
Copy Markdown
Member

I'm personally amenable to adding this guarantee, but I do agree with @the8472 that we need to confirm that this will actually work as intended.

@epageepage changed the title Allow FFI support for OsStrAllow limited access to OsStr bytes in unsafe blocksMar 31, 2023
@epage

epage commented Mar 31, 2023

Copy link
Copy Markdown
ContributorAuthor

Sorry for the lack of details and confusion on this. I was under the impression that working towards my final goal would best be done in smaller steps of defining OsStr but that meant I didn't have a use case for it which I recognize can be frustrating to deal with when evaluating a major change like this. I've since updated the documentation and PR to reflect the minimum of what I need for my use case: clap and other CLI tools that need to deal with parsing and splitting up OsStrs for however much valid UTF-8 is in them.

My hope that this more limited alternative to #95290 will have a chance to move forward.

@ChrisDenton

Copy link
Copy Markdown
Member

If we do this, I wonder if it makes sense to also offer a split_at method on OsStr that panics if used incorrectly. I.e.:

// Similar to `str::split_at` and `[T]::split_at`// Panics if `mid` is not on a UTF-8 code point boundary.fnsplit_at(&self,mid:usize) -> (&OsStr,&OsStr);

Splitting and joining are the two hazard areas when dealing with known valid OsStrs (whatever form they're in). We have OsString::push for the joining case but nothing to help with splitting. I think it would be unfortunate if we don't have some safe way to check you're doing it right.

@epage

epage commented Mar 31, 2023

Copy link
Copy Markdown
ContributorAuthor

but nothing to help with splitting. I think it would be unfortunate if we don't have some safe way to check you're doing it right.

A part of me finds it weird to offer a safe function like split_at that takes a parameter (mid) that can only be calculated from another type derived from with unsafe code. Documenting use of split_at would then further raise visibility of this feature, for both good (people getting stuff done) and bad (risk of misuse). However, I do see the benefit as that does greatly reduce the risk of something going wrong. In my experiments with transmuting &OsStr, I wrapped all byte operations in functions that only allowed deriving mid from &str parameters (e.g. OsStrExt::strip_prefix(&self, prefix: &str)) so I knew I was splitting at a safe boundary.

EDIT: To make clear, I'm open to adding that function if that is the direction we want to take this.

@ChrisDenton

Copy link
Copy Markdown
Member

Hm, we could offer some safe way to get an index according to these rules. E.g.

// Returns the byte index where `searcher` first returns true.// `searcher` can inspect `char`s decoded from UTF-8.// Non UTF-8 encoded characters are skipped.fnfind_char(&self,searcher:FnMut(char) -> bool) -> Option<usize>;

But at this point I'll stop because I'm practically designing yet another alternative approach.

@chorman0773

Copy link
Copy Markdown
Contributor

Does this confirm that OsStr is a "bag of bytes" on any platform, in that you can put and leave any (init, non-pointer) bytes in the slice, or am I misinterpreting the proposal?

@epage

epage commented Apr 11, 2023

Copy link
Copy Markdown
ContributorAuthor

Does this confirm that OsStr is a "bag of bytes" on any platform, in that you can put and leave any (init, non-pointer) bytes in the slice, or am I misinterpreting the proposal?

For now, this proposals restricts what is safe to transmute from &[u8] to &OsStr, so this does not work as an arbitrary bag of bytes

//! - When [transmuting] from `&[u8]` to `&OsStr`,//! - the slice may only include content from comparable `&OsStr` (see above) or be valid UTF-8//! - any splits of the `&OsStr` must be along char boundaries (the first byte of a UTF-8 code//! point sequence)

@BurntSushi

Copy link
Copy Markdown
Member

I think I buy the rules as written, but I would like to see a doc example using unsafe, along with a SAFETY comment justifying why it's OK. I think that would also help others write correct code.

Also, cc @SimonSapin to see what you think about this. (Let me know if you want me to stop pinging you about this, but I always think of you as the champion against a change like this.)

Popping up a level, this is kind of an interesting use of unsafe, isn't it? It's carving out a strictly more conservative set of things the caller needs to uphold than what is actually true. I wonder, for example, how Miri might detect UB in a case like this.

@blyxxyz

Copy link
Copy Markdown
Contributor

Does this confirm that OsStr is a "bag of bytes" on any platform, in that you can put and leave any (init, non-pointer) bytes in the slice, or am I misinterpreting the proposal?

It actually isn't a bag of bytes on Windows, it must be WTF-8-encoded or you can start reading out of bounds:

fnmain(){let b:&[u8] = b"\xC2";let s:&std::ffi::OsStr = unsafe{ std::mem::transmute(b)};dbg!(s);}
$ cargo run -q --target x86_64-pc-windows-gnu[src/main.rs:4] s = "\u{9b}:] = \n\0\0\0\0\0\0\01\u{10}L[...]thread 'main' panicked at 'failed printing to stderr: Windows stdio in console mode does not support writing non-UTF-8 byte sequences', library\std\src\io\stdio.rs:1008:9

The proposal is phrased to never produce invalid WTF-8.

I think that as written now it allows for any OsStr encoding that's a self-synchronizing superset of UTF-8.

@asquared31415

asquared31415 commented Apr 11, 2023

Copy link
Copy Markdown
Contributor

When [transmuting] from &[u8] to &OsStr,

This wording would provide an additional guarantee that &[u8] and &OsStr have the same layout in terms of their (ptr, len) pairs. As far as I am aware, this is something that is not currently guaranteed, and I don't recall the current stance on guaranteeing layout compatibility between any two fat pointer types that have different pointees.

@borsbors added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 28, 2023
@epage
epageforce-pushed the wtf branch 2 times, most recently from e2d912b to e6a35c4CompareMay 29, 2023 12:57
@epage

Copy link
Copy Markdown
ContributorAuthor

I've addressed what caused the wasm build failure and it should be good to go again.

@Amanieu

Copy link
Copy Markdown
Member

@bors r+

@bors

bors commented May 30, 2023

Copy link
Copy Markdown
Collaborator

📌 Commit e6a35c4 has been approved by Amanieu

It is now in the queue for this repository.

@borsbors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 30, 2023
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request May 30, 2023
Allow limited access to `OsStr` bytes
`OsStr` has historically kept its implementation details private out of
concern for locking us into a specific encoding on Windows.
This is an alternative to rust-lang#95290 which proposed specifying the encoding on Windows. Instead, this
only specifies that for cross-platform code, `OsStr`'s encoding is a superset of UTF-8 and defines
rules for safely interacting with it
At minimum, this can greatly simplify the `os_str_bytes` crate and every
arg parser that interacts with `OsStr` directly (which is most of those
that support invalid UTF-8).
Tracking issue: rust-lang#111544
@Dylan-DPCDylan-DPC mentioned this pull request May 30, 2023
@bors

bors commented May 30, 2023

Copy link
Copy Markdown
Collaborator

⌛ Testing commit e6a35c4 with merge 9610dfe...

@bors

bors commented May 31, 2023

Copy link
Copy Markdown
Collaborator

☀️ Test successful - checks-actions
Approved by: Amanieu
Pushing 9610dfe to master...

@borsbors added the merged-by-bors This PR was explicitly merged by bors. label May 31, 2023
@bors
bors merged commit 9610dfe into rust-lang:masterMay 31, 2023
@rustbotrustbot added this to the 1.72.0 milestone May 31, 2023
@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (9610dfe): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

meanrangecount
Regressions ❌
(primary)
--0
Regressions ❌
(secondary)
--0
Improvements ✅
(primary)
--0
Improvements ✅
(secondary)
-3.5%[-4.6%, -2.5%]2
All ❌✅ (primary)--0

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

meanrangecount
Regressions ❌
(primary)
0.0%[0.0%, 0.1%]5
Regressions ❌
(secondary)
--0
Improvements ✅
(primary)
-0.1%[-0.1%, -0.1%]3
Improvements ✅
(secondary)
--0
All ❌✅ (primary)-0.0%[-0.1%, 0.1%]8

Bootstrap: 642.846s -> 643.715s (0.14%)

@apirainoapiraino removed the to-announce Announce this issue on triage meeting label Jun 15, 2023
epage added a commit to epage/rust that referenced this pull request Jul 7, 2023
This extends rust-lang#109698 to allow no-cost conversion between `Vec<u8>` and `OsString`
as suggested in feedback from `os_str_bytes` crate in rust-lang#111544.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 22, 2023
Allow limited access to `OsString` bytes
This extends rust-lang#109698 to allow no-cost conversion between `Vec<u8>` and `OsString` as suggested in feedback from `os_str_bytes` crate in rust-lang#111544.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 22, 2023
Allow limited access to `OsString` bytes
This extends rust-lang#109698 to allow no-cost conversion between `Vec<u8>` and `OsString` as suggested in feedback from `os_str_bytes` crate in rust-lang#111544.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 22, 2023
Allow limited access to `OsString` bytes
This extends rust-lang#109698 to allow no-cost conversion between `Vec<u8>` and `OsString` as suggested in feedback from `os_str_bytes` crate in rust-lang#111544.
@epage
epage deleted the wtf branch July 22, 2023 14:48
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.merged-by-borsThis PR was explicitly merged by bors.S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-libs-api[DEPRECATED; DO NOT USE]

Projects

None yet

Development

Successfully merging this pull request may close these issues.

20 participants

@epage@rustbot@cuviper@ChrisDenton@the8472@joshtriplett@chorman0773@BurntSushi@blyxxyz@asquared31415@SimonSapin@dylni@rust-log-analyzer@m-ou-se@rfcbot@Amanieu@QuineDot@bors@rust-timer@teor2345
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Allow limited access to `OsStr` bytes by epage · Pull Request #109698 · rust-lang/rust · GitHub
Skip to content

Allow limited access to OsStr bytes - #109698

Merged
bors merged 6 commits into
rust-lang:masterfrom
epage:wtf
May 31, 2023
Merged

Allow limited access to OsStr bytes#109698
bors merged 6 commits into
rust-lang:masterfrom
epage:wtf

Conversation

@epage

@epageepage commented Mar 28, 2023

Copy link
Copy Markdown
Contributor

OsStr has historically kept its implementation details private out of
concern for locking us into a specific encoding on Windows.

This is an alternative to #95290 which proposed specifying the encoding on Windows. Instead, this
only specifies that for cross-platform code, OsStr's encoding is a superset of UTF-8 and defines
rules for safely interacting with it

At minimum, this can greatly simplify the os_str_bytes crate and every
arg parser that interacts with OsStr directly (which is most of those
that support invalid UTF-8).

Tracking issue: #111544

`OsStr` has historically kept its implementation details private out of
concern for locking us into a specific encoding on Windows.
This is an alternative to rust-lang#95290 which proposed specifying the encoding on Windows. Instead, this
only specifies that for cross-platform code, `OsStr`'s encoding is a superset of UTF-8 and defines
rules for safely interacting with it
At minimum, this can greatly simplify the `os_str_bytes` crate and every
arg parser that interacts with `OsStr` directly (which is most of those
that support invalid UTF-8).
@rustbot

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @cuviper (or someone else) soon.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbotrustbot 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 28, 2023
@rustbot

Copy link
Copy Markdown
Collaborator

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

@epage
epageforce-pushed the wtf branch 2 times, most recently from 01f8d93 to 0d87d66CompareMarch 28, 2023 14:26
@cuviper

Copy link
Copy Markdown
Member

I think this counts as new guarantee for API purposes.

@rustbot label +T-libs-api -T-libs
r? libs-api

@rustbotrustbot added T-libs-api [DEPRECATED; DO NOT USE] and removed T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Mar 28, 2023
@rustbotrustbot assigned Amanieu and unassigned cuviperMar 28, 2023
@ChrisDenton

Copy link
Copy Markdown
Member

Out of interest, was there anything in particular that motivated you to propose this now?

@the8472

Copy link
Copy Markdown
Member

I think this should come with an example since it's a wide pointer. Conversion from C to Rust has to jump through extra hoops.

@joshtriplett

Copy link
Copy Markdown
Member

I'm personally amenable to adding this guarantee, but I do agree with @the8472 that we need to confirm that this will actually work as intended.

@epageepage changed the title Allow FFI support for OsStrAllow limited access to OsStr bytes in unsafe blocksMar 31, 2023
@epage

epage commented Mar 31, 2023

Copy link
Copy Markdown
ContributorAuthor

Sorry for the lack of details and confusion on this. I was under the impression that working towards my final goal would best be done in smaller steps of defining OsStr but that meant I didn't have a use case for it which I recognize can be frustrating to deal with when evaluating a major change like this. I've since updated the documentation and PR to reflect the minimum of what I need for my use case: clap and other CLI tools that need to deal with parsing and splitting up OsStrs for however much valid UTF-8 is in them.

My hope that this more limited alternative to #95290 will have a chance to move forward.

@ChrisDenton

Copy link
Copy Markdown
Member

If we do this, I wonder if it makes sense to also offer a split_at method on OsStr that panics if used incorrectly. I.e.:

// Similar to `str::split_at` and `[T]::split_at`// Panics if `mid` is not on a UTF-8 code point boundary.fnsplit_at(&self,mid:usize) -> (&OsStr,&OsStr);

Splitting and joining are the two hazard areas when dealing with known valid OsStrs (whatever form they're in). We have OsString::push for the joining case but nothing to help with splitting. I think it would be unfortunate if we don't have some safe way to check you're doing it right.

@epage

epage commented Mar 31, 2023

Copy link
Copy Markdown
ContributorAuthor

but nothing to help with splitting. I think it would be unfortunate if we don't have some safe way to check you're doing it right.

A part of me finds it weird to offer a safe function like split_at that takes a parameter (mid) that can only be calculated from another type derived from with unsafe code. Documenting use of split_at would then further raise visibility of this feature, for both good (people getting stuff done) and bad (risk of misuse). However, I do see the benefit as that does greatly reduce the risk of something going wrong. In my experiments with transmuting &OsStr, I wrapped all byte operations in functions that only allowed deriving mid from &str parameters (e.g. OsStrExt::strip_prefix(&self, prefix: &str)) so I knew I was splitting at a safe boundary.

EDIT: To make clear, I'm open to adding that function if that is the direction we want to take this.

@ChrisDenton

Copy link
Copy Markdown
Member

Hm, we could offer some safe way to get an index according to these rules. E.g.

// Returns the byte index where `searcher` first returns true.// `searcher` can inspect `char`s decoded from UTF-8.// Non UTF-8 encoded characters are skipped.fnfind_char(&self,searcher:FnMut(char) -> bool) -> Option<usize>;

But at this point I'll stop because I'm practically designing yet another alternative approach.

@chorman0773

Copy link
Copy Markdown
Contributor

Does this confirm that OsStr is a "bag of bytes" on any platform, in that you can put and leave any (init, non-pointer) bytes in the slice, or am I misinterpreting the proposal?

@epage

epage commented Apr 11, 2023

Copy link
Copy Markdown
ContributorAuthor

Does this confirm that OsStr is a "bag of bytes" on any platform, in that you can put and leave any (init, non-pointer) bytes in the slice, or am I misinterpreting the proposal?

For now, this proposals restricts what is safe to transmute from &[u8] to &OsStr, so this does not work as an arbitrary bag of bytes

//! - When [transmuting] from `&[u8]` to `&OsStr`,//! - the slice may only include content from comparable `&OsStr` (see above) or be valid UTF-8//! - any splits of the `&OsStr` must be along char boundaries (the first byte of a UTF-8 code//! point sequence)

@BurntSushi

Copy link
Copy Markdown
Member

I think I buy the rules as written, but I would like to see a doc example using unsafe, along with a SAFETY comment justifying why it's OK. I think that would also help others write correct code.

Also, cc @SimonSapin to see what you think about this. (Let me know if you want me to stop pinging you about this, but I always think of you as the champion against a change like this.)

Popping up a level, this is kind of an interesting use of unsafe, isn't it? It's carving out a strictly more conservative set of things the caller needs to uphold than what is actually true. I wonder, for example, how Miri might detect UB in a case like this.

@blyxxyz

Copy link
Copy Markdown
Contributor

Does this confirm that OsStr is a "bag of bytes" on any platform, in that you can put and leave any (init, non-pointer) bytes in the slice, or am I misinterpreting the proposal?

It actually isn't a bag of bytes on Windows, it must be WTF-8-encoded or you can start reading out of bounds:

fnmain(){let b:&[u8] = b"\xC2";let s:&std::ffi::OsStr = unsafe{ std::mem::transmute(b)};dbg!(s);}
$ cargo run -q --target x86_64-pc-windows-gnu[src/main.rs:4] s = "\u{9b}:] = \n\0\0\0\0\0\0\01\u{10}L[...]thread 'main' panicked at 'failed printing to stderr: Windows stdio in console mode does not support writing non-UTF-8 byte sequences', library\std\src\io\stdio.rs:1008:9

The proposal is phrased to never produce invalid WTF-8.

I think that as written now it allows for any OsStr encoding that's a self-synchronizing superset of UTF-8.

@asquared31415

asquared31415 commented Apr 11, 2023

Copy link
Copy Markdown
Contributor

When [transmuting] from &[u8] to &OsStr,

This wording would provide an additional guarantee that &[u8] and &OsStr have the same layout in terms of their (ptr, len) pairs. As far as I am aware, this is something that is not currently guaranteed, and I don't recall the current stance on guaranteeing layout compatibility between any two fat pointer types that have different pointees.

@borsbors added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 28, 2023
@epage
epageforce-pushed the wtf branch 2 times, most recently from e2d912b to e6a35c4CompareMay 29, 2023 12:57
@epage

Copy link
Copy Markdown
ContributorAuthor

I've addressed what caused the wasm build failure and it should be good to go again.

@Amanieu

Copy link
Copy Markdown
Member

@bors r+

@bors

bors commented May 30, 2023

Copy link
Copy Markdown
Collaborator

📌 Commit e6a35c4 has been approved by Amanieu

It is now in the queue for this repository.

@borsbors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 30, 2023
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request May 30, 2023
Allow limited access to `OsStr` bytes
`OsStr` has historically kept its implementation details private out of
concern for locking us into a specific encoding on Windows.
This is an alternative to rust-lang#95290 which proposed specifying the encoding on Windows. Instead, this
only specifies that for cross-platform code, `OsStr`'s encoding is a superset of UTF-8 and defines
rules for safely interacting with it
At minimum, this can greatly simplify the `os_str_bytes` crate and every
arg parser that interacts with `OsStr` directly (which is most of those
that support invalid UTF-8).
Tracking issue: rust-lang#111544
@Dylan-DPCDylan-DPC mentioned this pull request May 30, 2023
@bors

bors commented May 30, 2023

Copy link
Copy Markdown
Collaborator

⌛ Testing commit e6a35c4 with merge 9610dfe...

@bors

bors commented May 31, 2023

Copy link
Copy Markdown
Collaborator

☀️ Test successful - checks-actions
Approved by: Amanieu
Pushing 9610dfe to master...

@borsbors added the merged-by-bors This PR was explicitly merged by bors. label May 31, 2023
@bors
bors merged commit 9610dfe into rust-lang:masterMay 31, 2023
@rustbotrustbot added this to the 1.72.0 milestone May 31, 2023
@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (9610dfe): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

meanrangecount
Regressions ❌
(primary)
--0
Regressions ❌
(secondary)
--0
Improvements ✅
(primary)
--0
Improvements ✅
(secondary)
-3.5%[-4.6%, -2.5%]2
All ❌✅ (primary)--0

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

meanrangecount
Regressions ❌
(primary)
0.0%[0.0%, 0.1%]5
Regressions ❌
(secondary)
--0
Improvements ✅
(primary)
-0.1%[-0.1%, -0.1%]3
Improvements ✅
(secondary)
--0
All ❌✅ (primary)-0.0%[-0.1%, 0.1%]8

Bootstrap: 642.846s -> 643.715s (0.14%)

@apirainoapiraino removed the to-announce Announce this issue on triage meeting label Jun 15, 2023
epage added a commit to epage/rust that referenced this pull request Jul 7, 2023
This extends rust-lang#109698 to allow no-cost conversion between `Vec<u8>` and `OsString`
as suggested in feedback from `os_str_bytes` crate in rust-lang#111544.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 22, 2023
Allow limited access to `OsString` bytes
This extends rust-lang#109698 to allow no-cost conversion between `Vec<u8>` and `OsString` as suggested in feedback from `os_str_bytes` crate in rust-lang#111544.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 22, 2023
Allow limited access to `OsString` bytes
This extends rust-lang#109698 to allow no-cost conversion between `Vec<u8>` and `OsString` as suggested in feedback from `os_str_bytes` crate in rust-lang#111544.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 22, 2023
Allow limited access to `OsString` bytes
This extends rust-lang#109698 to allow no-cost conversion between `Vec<u8>` and `OsString` as suggested in feedback from `os_str_bytes` crate in rust-lang#111544.
@epage
epage deleted the wtf branch July 22, 2023 14:48
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.merged-by-borsThis PR was explicitly merged by bors.S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-libs-api[DEPRECATED; DO NOT USE]

Projects

None yet

Development

Successfully merging this pull request may close these issues.

20 participants

@epage@rustbot@cuviper@ChrisDenton@the8472@joshtriplett@chorman0773@BurntSushi@blyxxyz@asquared31415@SimonSapin@dylni@rust-log-analyzer@m-ou-se@rfcbot@Amanieu@QuineDot@bors@rust-timer@teor2345
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' Allow limited access to `OsStr` bytes by epage · Pull Request #109698 · rust-lang/rust · GitHub
Skip to content

Allow limited access to OsStr bytes - #109698

Merged
bors merged 6 commits into
rust-lang:masterfrom
epage:wtf
May 31, 2023
Merged

Allow limited access to OsStr bytes#109698
bors merged 6 commits into
rust-lang:masterfrom
epage:wtf

Conversation

@epage

@epageepage commented Mar 28, 2023

Copy link
Copy Markdown
Contributor

OsStr has historically kept its implementation details private out of
concern for locking us into a specific encoding on Windows.

This is an alternative to #95290 which proposed specifying the encoding on Windows. Instead, this
only specifies that for cross-platform code, OsStr's encoding is a superset of UTF-8 and defines
rules for safely interacting with it

At minimum, this can greatly simplify the os_str_bytes crate and every
arg parser that interacts with OsStr directly (which is most of those
that support invalid UTF-8).

Tracking issue: #111544

`OsStr` has historically kept its implementation details private out of
concern for locking us into a specific encoding on Windows.
This is an alternative to rust-lang#95290 which proposed specifying the encoding on Windows. Instead, this
only specifies that for cross-platform code, `OsStr`'s encoding is a superset of UTF-8 and defines
rules for safely interacting with it
At minimum, this can greatly simplify the `os_str_bytes` crate and every
arg parser that interacts with `OsStr` directly (which is most of those
that support invalid UTF-8).
@rustbot

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @cuviper (or someone else) soon.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbotrustbot 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 28, 2023
@rustbot

Copy link
Copy Markdown
Collaborator

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

@epage
epageforce-pushed the wtf branch 2 times, most recently from 01f8d93 to 0d87d66CompareMarch 28, 2023 14:26
@cuviper

Copy link
Copy Markdown
Member

I think this counts as new guarantee for API purposes.

@rustbot label +T-libs-api -T-libs
r? libs-api

@rustbotrustbot added T-libs-api [DEPRECATED; DO NOT USE] and removed T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Mar 28, 2023
@rustbotrustbot assigned Amanieu and unassigned cuviperMar 28, 2023
@ChrisDenton

Copy link
Copy Markdown
Member

Out of interest, was there anything in particular that motivated you to propose this now?

@the8472

Copy link
Copy Markdown
Member

I think this should come with an example since it's a wide pointer. Conversion from C to Rust has to jump through extra hoops.

@joshtriplett

Copy link
Copy Markdown
Member

I'm personally amenable to adding this guarantee, but I do agree with @the8472 that we need to confirm that this will actually work as intended.

@epageepage changed the title Allow FFI support for OsStrAllow limited access to OsStr bytes in unsafe blocksMar 31, 2023
@epage

epage commented Mar 31, 2023

Copy link
Copy Markdown
ContributorAuthor

Sorry for the lack of details and confusion on this. I was under the impression that working towards my final goal would best be done in smaller steps of defining OsStr but that meant I didn't have a use case for it which I recognize can be frustrating to deal with when evaluating a major change like this. I've since updated the documentation and PR to reflect the minimum of what I need for my use case: clap and other CLI tools that need to deal with parsing and splitting up OsStrs for however much valid UTF-8 is in them.

My hope that this more limited alternative to #95290 will have a chance to move forward.

@ChrisDenton

Copy link
Copy Markdown
Member

If we do this, I wonder if it makes sense to also offer a split_at method on OsStr that panics if used incorrectly. I.e.:

// Similar to `str::split_at` and `[T]::split_at`// Panics if `mid` is not on a UTF-8 code point boundary.fnsplit_at(&self,mid:usize) -> (&OsStr,&OsStr);

Splitting and joining are the two hazard areas when dealing with known valid OsStrs (whatever form they're in). We have OsString::push for the joining case but nothing to help with splitting. I think it would be unfortunate if we don't have some safe way to check you're doing it right.

@epage

epage commented Mar 31, 2023

Copy link
Copy Markdown
ContributorAuthor

but nothing to help with splitting. I think it would be unfortunate if we don't have some safe way to check you're doing it right.

A part of me finds it weird to offer a safe function like split_at that takes a parameter (mid) that can only be calculated from another type derived from with unsafe code. Documenting use of split_at would then further raise visibility of this feature, for both good (people getting stuff done) and bad (risk of misuse). However, I do see the benefit as that does greatly reduce the risk of something going wrong. In my experiments with transmuting &OsStr, I wrapped all byte operations in functions that only allowed deriving mid from &str parameters (e.g. OsStrExt::strip_prefix(&self, prefix: &str)) so I knew I was splitting at a safe boundary.

EDIT: To make clear, I'm open to adding that function if that is the direction we want to take this.

@ChrisDenton

Copy link
Copy Markdown
Member

Hm, we could offer some safe way to get an index according to these rules. E.g.

// Returns the byte index where `searcher` first returns true.// `searcher` can inspect `char`s decoded from UTF-8.// Non UTF-8 encoded characters are skipped.fnfind_char(&self,searcher:FnMut(char) -> bool) -> Option<usize>;

But at this point I'll stop because I'm practically designing yet another alternative approach.

@chorman0773

Copy link
Copy Markdown
Contributor

Does this confirm that OsStr is a "bag of bytes" on any platform, in that you can put and leave any (init, non-pointer) bytes in the slice, or am I misinterpreting the proposal?

@epage

epage commented Apr 11, 2023

Copy link
Copy Markdown
ContributorAuthor

Does this confirm that OsStr is a "bag of bytes" on any platform, in that you can put and leave any (init, non-pointer) bytes in the slice, or am I misinterpreting the proposal?

For now, this proposals restricts what is safe to transmute from &[u8] to &OsStr, so this does not work as an arbitrary bag of bytes

//! - When [transmuting] from `&[u8]` to `&OsStr`,//! - the slice may only include content from comparable `&OsStr` (see above) or be valid UTF-8//! - any splits of the `&OsStr` must be along char boundaries (the first byte of a UTF-8 code//! point sequence)

@BurntSushi

Copy link
Copy Markdown
Member

I think I buy the rules as written, but I would like to see a doc example using unsafe, along with a SAFETY comment justifying why it's OK. I think that would also help others write correct code.

Also, cc @SimonSapin to see what you think about this. (Let me know if you want me to stop pinging you about this, but I always think of you as the champion against a change like this.)

Popping up a level, this is kind of an interesting use of unsafe, isn't it? It's carving out a strictly more conservative set of things the caller needs to uphold than what is actually true. I wonder, for example, how Miri might detect UB in a case like this.

@blyxxyz

Copy link
Copy Markdown
Contributor

Does this confirm that OsStr is a "bag of bytes" on any platform, in that you can put and leave any (init, non-pointer) bytes in the slice, or am I misinterpreting the proposal?

It actually isn't a bag of bytes on Windows, it must be WTF-8-encoded or you can start reading out of bounds:

fnmain(){let b:&[u8] = b"\xC2";let s:&std::ffi::OsStr = unsafe{ std::mem::transmute(b)};dbg!(s);}
$ cargo run -q --target x86_64-pc-windows-gnu[src/main.rs:4] s = "\u{9b}:] = \n\0\0\0\0\0\0\01\u{10}L[...]thread 'main' panicked at 'failed printing to stderr: Windows stdio in console mode does not support writing non-UTF-8 byte sequences', library\std\src\io\stdio.rs:1008:9

The proposal is phrased to never produce invalid WTF-8.

I think that as written now it allows for any OsStr encoding that's a self-synchronizing superset of UTF-8.

@asquared31415

asquared31415 commented Apr 11, 2023

Copy link
Copy Markdown
Contributor

When [transmuting] from &[u8] to &OsStr,

This wording would provide an additional guarantee that &[u8] and &OsStr have the same layout in terms of their (ptr, len) pairs. As far as I am aware, this is something that is not currently guaranteed, and I don't recall the current stance on guaranteeing layout compatibility between any two fat pointer types that have different pointees.

@borsbors added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 28, 2023
@epage
epageforce-pushed the wtf branch 2 times, most recently from e2d912b to e6a35c4CompareMay 29, 2023 12:57
@epage

Copy link
Copy Markdown
ContributorAuthor

I've addressed what caused the wasm build failure and it should be good to go again.

@Amanieu

Copy link
Copy Markdown
Member

@bors r+

@bors

bors commented May 30, 2023

Copy link
Copy Markdown
Collaborator

📌 Commit e6a35c4 has been approved by Amanieu

It is now in the queue for this repository.

@borsbors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 30, 2023
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request May 30, 2023
Allow limited access to `OsStr` bytes
`OsStr` has historically kept its implementation details private out of
concern for locking us into a specific encoding on Windows.
This is an alternative to rust-lang#95290 which proposed specifying the encoding on Windows. Instead, this
only specifies that for cross-platform code, `OsStr`'s encoding is a superset of UTF-8 and defines
rules for safely interacting with it
At minimum, this can greatly simplify the `os_str_bytes` crate and every
arg parser that interacts with `OsStr` directly (which is most of those
that support invalid UTF-8).
Tracking issue: rust-lang#111544
@Dylan-DPCDylan-DPC mentioned this pull request May 30, 2023
@bors

bors commented May 30, 2023

Copy link
Copy Markdown
Collaborator

⌛ Testing commit e6a35c4 with merge 9610dfe...

@bors

bors commented May 31, 2023

Copy link
Copy Markdown
Collaborator

☀️ Test successful - checks-actions
Approved by: Amanieu
Pushing 9610dfe to master...

@borsbors added the merged-by-bors This PR was explicitly merged by bors. label May 31, 2023
@bors
bors merged commit 9610dfe into rust-lang:masterMay 31, 2023
@rustbotrustbot added this to the 1.72.0 milestone May 31, 2023
@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (9610dfe): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

meanrangecount
Regressions ❌
(primary)
--0
Regressions ❌
(secondary)
--0
Improvements ✅
(primary)
--0
Improvements ✅
(secondary)
-3.5%[-4.6%, -2.5%]2
All ❌✅ (primary)--0

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

meanrangecount
Regressions ❌
(primary)
0.0%[0.0%, 0.1%]5
Regressions ❌
(secondary)
--0
Improvements ✅
(primary)
-0.1%[-0.1%, -0.1%]3
Improvements ✅
(secondary)
--0
All ❌✅ (primary)-0.0%[-0.1%, 0.1%]8

Bootstrap: 642.846s -> 643.715s (0.14%)

@apirainoapiraino removed the to-announce Announce this issue on triage meeting label Jun 15, 2023
epage added a commit to epage/rust that referenced this pull request Jul 7, 2023
This extends rust-lang#109698 to allow no-cost conversion between `Vec<u8>` and `OsString`
as suggested in feedback from `os_str_bytes` crate in rust-lang#111544.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 22, 2023
Allow limited access to `OsString` bytes
This extends rust-lang#109698 to allow no-cost conversion between `Vec<u8>` and `OsString` as suggested in feedback from `os_str_bytes` crate in rust-lang#111544.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 22, 2023
Allow limited access to `OsString` bytes
This extends rust-lang#109698 to allow no-cost conversion between `Vec<u8>` and `OsString` as suggested in feedback from `os_str_bytes` crate in rust-lang#111544.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 22, 2023
Allow limited access to `OsString` bytes
This extends rust-lang#109698 to allow no-cost conversion between `Vec<u8>` and `OsString` as suggested in feedback from `os_str_bytes` crate in rust-lang#111544.
@epage
epage deleted the wtf branch July 22, 2023 14:48
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.merged-by-borsThis PR was explicitly merged by bors.S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-libs-api[DEPRECATED; DO NOT USE]

Projects

None yet

Development

Successfully merging this pull request may close these issues.

20 participants

@epage@rustbot@cuviper@ChrisDenton@the8472@joshtriplett@chorman0773@BurntSushi@blyxxyz@asquared31415@SimonSapin@dylni@rust-log-analyzer@m-ou-se@rfcbot@Amanieu@QuineDot@bors@rust-timer@teor2345
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Allow limited access to `OsStr` bytes by epage · Pull Request #109698 · rust-lang/rust · GitHub
Skip to content

Allow limited access to OsStr bytes - #109698

Merged
bors merged 6 commits into
rust-lang:masterfrom
epage:wtf
May 31, 2023
Merged

Allow limited access to OsStr bytes#109698
bors merged 6 commits into
rust-lang:masterfrom
epage:wtf

Conversation

@epage

@epageepage commented Mar 28, 2023

Copy link
Copy Markdown
Contributor

OsStr has historically kept its implementation details private out of
concern for locking us into a specific encoding on Windows.

This is an alternative to #95290 which proposed specifying the encoding on Windows. Instead, this
only specifies that for cross-platform code, OsStr's encoding is a superset of UTF-8 and defines
rules for safely interacting with it

At minimum, this can greatly simplify the os_str_bytes crate and every
arg parser that interacts with OsStr directly (which is most of those
that support invalid UTF-8).

Tracking issue: #111544

`OsStr` has historically kept its implementation details private out of
concern for locking us into a specific encoding on Windows.
This is an alternative to rust-lang#95290 which proposed specifying the encoding on Windows. Instead, this
only specifies that for cross-platform code, `OsStr`'s encoding is a superset of UTF-8 and defines
rules for safely interacting with it
At minimum, this can greatly simplify the `os_str_bytes` crate and every
arg parser that interacts with `OsStr` directly (which is most of those
that support invalid UTF-8).
@rustbot

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @cuviper (or someone else) soon.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbotrustbot 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 28, 2023
@rustbot

Copy link
Copy Markdown
Collaborator

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

@epage
epageforce-pushed the wtf branch 2 times, most recently from 01f8d93 to 0d87d66CompareMarch 28, 2023 14:26
@cuviper

Copy link
Copy Markdown
Member

I think this counts as new guarantee for API purposes.

@rustbot label +T-libs-api -T-libs
r? libs-api

@rustbotrustbot added T-libs-api [DEPRECATED; DO NOT USE] and removed T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Mar 28, 2023
@rustbotrustbot assigned Amanieu and unassigned cuviperMar 28, 2023
@ChrisDenton

Copy link
Copy Markdown
Member

Out of interest, was there anything in particular that motivated you to propose this now?

@the8472

Copy link
Copy Markdown
Member

I think this should come with an example since it's a wide pointer. Conversion from C to Rust has to jump through extra hoops.

@joshtriplett

Copy link
Copy Markdown
Member

I'm personally amenable to adding this guarantee, but I do agree with @the8472 that we need to confirm that this will actually work as intended.

@epageepage changed the title Allow FFI support for OsStrAllow limited access to OsStr bytes in unsafe blocksMar 31, 2023
@epage

epage commented Mar 31, 2023

Copy link
Copy Markdown
ContributorAuthor

Sorry for the lack of details and confusion on this. I was under the impression that working towards my final goal would best be done in smaller steps of defining OsStr but that meant I didn't have a use case for it which I recognize can be frustrating to deal with when evaluating a major change like this. I've since updated the documentation and PR to reflect the minimum of what I need for my use case: clap and other CLI tools that need to deal with parsing and splitting up OsStrs for however much valid UTF-8 is in them.

My hope that this more limited alternative to #95290 will have a chance to move forward.

@ChrisDenton

Copy link
Copy Markdown
Member

If we do this, I wonder if it makes sense to also offer a split_at method on OsStr that panics if used incorrectly. I.e.:

// Similar to `str::split_at` and `[T]::split_at`// Panics if `mid` is not on a UTF-8 code point boundary.fnsplit_at(&self,mid:usize) -> (&OsStr,&OsStr);

Splitting and joining are the two hazard areas when dealing with known valid OsStrs (whatever form they're in). We have OsString::push for the joining case but nothing to help with splitting. I think it would be unfortunate if we don't have some safe way to check you're doing it right.

@epage

epage commented Mar 31, 2023

Copy link
Copy Markdown
ContributorAuthor

but nothing to help with splitting. I think it would be unfortunate if we don't have some safe way to check you're doing it right.

A part of me finds it weird to offer a safe function like split_at that takes a parameter (mid) that can only be calculated from another type derived from with unsafe code. Documenting use of split_at would then further raise visibility of this feature, for both good (people getting stuff done) and bad (risk of misuse). However, I do see the benefit as that does greatly reduce the risk of something going wrong. In my experiments with transmuting &OsStr, I wrapped all byte operations in functions that only allowed deriving mid from &str parameters (e.g. OsStrExt::strip_prefix(&self, prefix: &str)) so I knew I was splitting at a safe boundary.

EDIT: To make clear, I'm open to adding that function if that is the direction we want to take this.

@ChrisDenton

Copy link
Copy Markdown
Member

Hm, we could offer some safe way to get an index according to these rules. E.g.

// Returns the byte index where `searcher` first returns true.// `searcher` can inspect `char`s decoded from UTF-8.// Non UTF-8 encoded characters are skipped.fnfind_char(&self,searcher:FnMut(char) -> bool) -> Option<usize>;

But at this point I'll stop because I'm practically designing yet another alternative approach.

@chorman0773

Copy link
Copy Markdown
Contributor

Does this confirm that OsStr is a "bag of bytes" on any platform, in that you can put and leave any (init, non-pointer) bytes in the slice, or am I misinterpreting the proposal?

@epage

epage commented Apr 11, 2023

Copy link
Copy Markdown
ContributorAuthor

Does this confirm that OsStr is a "bag of bytes" on any platform, in that you can put and leave any (init, non-pointer) bytes in the slice, or am I misinterpreting the proposal?

For now, this proposals restricts what is safe to transmute from &[u8] to &OsStr, so this does not work as an arbitrary bag of bytes

//! - When [transmuting] from `&[u8]` to `&OsStr`,//! - the slice may only include content from comparable `&OsStr` (see above) or be valid UTF-8//! - any splits of the `&OsStr` must be along char boundaries (the first byte of a UTF-8 code//! point sequence)

@BurntSushi

Copy link
Copy Markdown
Member

I think I buy the rules as written, but I would like to see a doc example using unsafe, along with a SAFETY comment justifying why it's OK. I think that would also help others write correct code.

Also, cc @SimonSapin to see what you think about this. (Let me know if you want me to stop pinging you about this, but I always think of you as the champion against a change like this.)

Popping up a level, this is kind of an interesting use of unsafe, isn't it? It's carving out a strictly more conservative set of things the caller needs to uphold than what is actually true. I wonder, for example, how Miri might detect UB in a case like this.

@blyxxyz

Copy link
Copy Markdown
Contributor

Does this confirm that OsStr is a "bag of bytes" on any platform, in that you can put and leave any (init, non-pointer) bytes in the slice, or am I misinterpreting the proposal?

It actually isn't a bag of bytes on Windows, it must be WTF-8-encoded or you can start reading out of bounds:

fnmain(){let b:&[u8] = b"\xC2";let s:&std::ffi::OsStr = unsafe{ std::mem::transmute(b)};dbg!(s);}
$ cargo run -q --target x86_64-pc-windows-gnu[src/main.rs:4] s = "\u{9b}:] = \n\0\0\0\0\0\0\01\u{10}L[...]thread 'main' panicked at 'failed printing to stderr: Windows stdio in console mode does not support writing non-UTF-8 byte sequences', library\std\src\io\stdio.rs:1008:9

The proposal is phrased to never produce invalid WTF-8.

I think that as written now it allows for any OsStr encoding that's a self-synchronizing superset of UTF-8.

@asquared31415

asquared31415 commented Apr 11, 2023

Copy link
Copy Markdown
Contributor

When [transmuting] from &[u8] to &OsStr,

This wording would provide an additional guarantee that &[u8] and &OsStr have the same layout in terms of their (ptr, len) pairs. As far as I am aware, this is something that is not currently guaranteed, and I don't recall the current stance on guaranteeing layout compatibility between any two fat pointer types that have different pointees.

@borsbors added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 28, 2023
@epage
epageforce-pushed the wtf branch 2 times, most recently from e2d912b to e6a35c4CompareMay 29, 2023 12:57
@epage

Copy link
Copy Markdown
ContributorAuthor

I've addressed what caused the wasm build failure and it should be good to go again.

@Amanieu

Copy link
Copy Markdown
Member

@bors r+

@bors

bors commented May 30, 2023

Copy link
Copy Markdown
Collaborator

📌 Commit e6a35c4 has been approved by Amanieu

It is now in the queue for this repository.

@borsbors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 30, 2023
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request May 30, 2023
Allow limited access to `OsStr` bytes
`OsStr` has historically kept its implementation details private out of
concern for locking us into a specific encoding on Windows.
This is an alternative to rust-lang#95290 which proposed specifying the encoding on Windows. Instead, this
only specifies that for cross-platform code, `OsStr`'s encoding is a superset of UTF-8 and defines
rules for safely interacting with it
At minimum, this can greatly simplify the `os_str_bytes` crate and every
arg parser that interacts with `OsStr` directly (which is most of those
that support invalid UTF-8).
Tracking issue: rust-lang#111544
@Dylan-DPCDylan-DPC mentioned this pull request May 30, 2023
@bors

bors commented May 30, 2023

Copy link
Copy Markdown
Collaborator

⌛ Testing commit e6a35c4 with merge 9610dfe...

@bors

bors commented May 31, 2023

Copy link
Copy Markdown
Collaborator

☀️ Test successful - checks-actions
Approved by: Amanieu
Pushing 9610dfe to master...

@borsbors added the merged-by-bors This PR was explicitly merged by bors. label May 31, 2023
@bors
bors merged commit 9610dfe into rust-lang:masterMay 31, 2023
@rustbotrustbot added this to the 1.72.0 milestone May 31, 2023
@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (9610dfe): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

meanrangecount
Regressions ❌
(primary)
--0
Regressions ❌
(secondary)
--0
Improvements ✅
(primary)
--0
Improvements ✅
(secondary)
-3.5%[-4.6%, -2.5%]2
All ❌✅ (primary)--0

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

meanrangecount
Regressions ❌
(primary)
0.0%[0.0%, 0.1%]5
Regressions ❌
(secondary)
--0
Improvements ✅
(primary)
-0.1%[-0.1%, -0.1%]3
Improvements ✅
(secondary)
--0
All ❌✅ (primary)-0.0%[-0.1%, 0.1%]8

Bootstrap: 642.846s -> 643.715s (0.14%)

@apirainoapiraino removed the to-announce Announce this issue on triage meeting label Jun 15, 2023
epage added a commit to epage/rust that referenced this pull request Jul 7, 2023
This extends rust-lang#109698 to allow no-cost conversion between `Vec<u8>` and `OsString`
as suggested in feedback from `os_str_bytes` crate in rust-lang#111544.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 22, 2023
Allow limited access to `OsString` bytes
This extends rust-lang#109698 to allow no-cost conversion between `Vec<u8>` and `OsString` as suggested in feedback from `os_str_bytes` crate in rust-lang#111544.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 22, 2023
Allow limited access to `OsString` bytes
This extends rust-lang#109698 to allow no-cost conversion between `Vec<u8>` and `OsString` as suggested in feedback from `os_str_bytes` crate in rust-lang#111544.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 22, 2023
Allow limited access to `OsString` bytes
This extends rust-lang#109698 to allow no-cost conversion between `Vec<u8>` and `OsString` as suggested in feedback from `os_str_bytes` crate in rust-lang#111544.
@epage
epage deleted the wtf branch July 22, 2023 14:48
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.merged-by-borsThis PR was explicitly merged by bors.S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-libs-api[DEPRECATED; DO NOT USE]

Projects

None yet

Development

Successfully merging this pull request may close these issues.

20 participants

@epage@rustbot@cuviper@ChrisDenton@the8472@joshtriplett@chorman0773@BurntSushi@blyxxyz@asquared31415@SimonSapin@dylni@rust-log-analyzer@m-ou-se@rfcbot@Amanieu@QuineDot@bors@rust-timer@teor2345
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Allow limited access to `OsStr` bytes by epage · Pull Request #109698 · rust-lang/rust · GitHub
Skip to content

Allow limited access to OsStr bytes - #109698

Merged
bors merged 6 commits into
rust-lang:masterfrom
epage:wtf
May 31, 2023
Merged

Allow limited access to OsStr bytes#109698
bors merged 6 commits into
rust-lang:masterfrom
epage:wtf

Conversation

@epage

@epageepage commented Mar 28, 2023

Copy link
Copy Markdown
Contributor

OsStr has historically kept its implementation details private out of
concern for locking us into a specific encoding on Windows.

This is an alternative to #95290 which proposed specifying the encoding on Windows. Instead, this
only specifies that for cross-platform code, OsStr's encoding is a superset of UTF-8 and defines
rules for safely interacting with it

At minimum, this can greatly simplify the os_str_bytes crate and every
arg parser that interacts with OsStr directly (which is most of those
that support invalid UTF-8).

Tracking issue: #111544

`OsStr` has historically kept its implementation details private out of
concern for locking us into a specific encoding on Windows.
This is an alternative to rust-lang#95290 which proposed specifying the encoding on Windows. Instead, this
only specifies that for cross-platform code, `OsStr`'s encoding is a superset of UTF-8 and defines
rules for safely interacting with it
At minimum, this can greatly simplify the `os_str_bytes` crate and every
arg parser that interacts with `OsStr` directly (which is most of those
that support invalid UTF-8).
@rustbot

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @cuviper (or someone else) soon.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbotrustbot 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 28, 2023
@rustbot

Copy link
Copy Markdown
Collaborator

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

@epage
epageforce-pushed the wtf branch 2 times, most recently from 01f8d93 to 0d87d66CompareMarch 28, 2023 14:26
@cuviper

Copy link
Copy Markdown
Member

I think this counts as new guarantee for API purposes.

@rustbot label +T-libs-api -T-libs
r? libs-api

@rustbotrustbot added T-libs-api [DEPRECATED; DO NOT USE] and removed T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Mar 28, 2023
@rustbotrustbot assigned Amanieu and unassigned cuviperMar 28, 2023
@ChrisDenton

Copy link
Copy Markdown
Member

Out of interest, was there anything in particular that motivated you to propose this now?

@the8472

Copy link
Copy Markdown
Member

I think this should come with an example since it's a wide pointer. Conversion from C to Rust has to jump through extra hoops.

@joshtriplett

Copy link
Copy Markdown
Member

I'm personally amenable to adding this guarantee, but I do agree with @the8472 that we need to confirm that this will actually work as intended.

@epageepage changed the title Allow FFI support for OsStrAllow limited access to OsStr bytes in unsafe blocksMar 31, 2023
@epage

epage commented Mar 31, 2023

Copy link
Copy Markdown
ContributorAuthor

Sorry for the lack of details and confusion on this. I was under the impression that working towards my final goal would best be done in smaller steps of defining OsStr but that meant I didn't have a use case for it which I recognize can be frustrating to deal with when evaluating a major change like this. I've since updated the documentation and PR to reflect the minimum of what I need for my use case: clap and other CLI tools that need to deal with parsing and splitting up OsStrs for however much valid UTF-8 is in them.

My hope that this more limited alternative to #95290 will have a chance to move forward.

@ChrisDenton

Copy link
Copy Markdown
Member

If we do this, I wonder if it makes sense to also offer a split_at method on OsStr that panics if used incorrectly. I.e.:

// Similar to `str::split_at` and `[T]::split_at`// Panics if `mid` is not on a UTF-8 code point boundary.fnsplit_at(&self,mid:usize) -> (&OsStr,&OsStr);

Splitting and joining are the two hazard areas when dealing with known valid OsStrs (whatever form they're in). We have OsString::push for the joining case but nothing to help with splitting. I think it would be unfortunate if we don't have some safe way to check you're doing it right.

@epage

epage commented Mar 31, 2023

Copy link
Copy Markdown
ContributorAuthor

but nothing to help with splitting. I think it would be unfortunate if we don't have some safe way to check you're doing it right.

A part of me finds it weird to offer a safe function like split_at that takes a parameter (mid) that can only be calculated from another type derived from with unsafe code. Documenting use of split_at would then further raise visibility of this feature, for both good (people getting stuff done) and bad (risk of misuse). However, I do see the benefit as that does greatly reduce the risk of something going wrong. In my experiments with transmuting &OsStr, I wrapped all byte operations in functions that only allowed deriving mid from &str parameters (e.g. OsStrExt::strip_prefix(&self, prefix: &str)) so I knew I was splitting at a safe boundary.

EDIT: To make clear, I'm open to adding that function if that is the direction we want to take this.

@ChrisDenton

Copy link
Copy Markdown
Member

Hm, we could offer some safe way to get an index according to these rules. E.g.

// Returns the byte index where `searcher` first returns true.// `searcher` can inspect `char`s decoded from UTF-8.// Non UTF-8 encoded characters are skipped.fnfind_char(&self,searcher:FnMut(char) -> bool) -> Option<usize>;

But at this point I'll stop because I'm practically designing yet another alternative approach.

@chorman0773

Copy link
Copy Markdown
Contributor

Does this confirm that OsStr is a "bag of bytes" on any platform, in that you can put and leave any (init, non-pointer) bytes in the slice, or am I misinterpreting the proposal?

@epage

epage commented Apr 11, 2023

Copy link
Copy Markdown
ContributorAuthor

Does this confirm that OsStr is a "bag of bytes" on any platform, in that you can put and leave any (init, non-pointer) bytes in the slice, or am I misinterpreting the proposal?

For now, this proposals restricts what is safe to transmute from &[u8] to &OsStr, so this does not work as an arbitrary bag of bytes

//! - When [transmuting] from `&[u8]` to `&OsStr`,//! - the slice may only include content from comparable `&OsStr` (see above) or be valid UTF-8//! - any splits of the `&OsStr` must be along char boundaries (the first byte of a UTF-8 code//! point sequence)

@BurntSushi

Copy link
Copy Markdown
Member

I think I buy the rules as written, but I would like to see a doc example using unsafe, along with a SAFETY comment justifying why it's OK. I think that would also help others write correct code.

Also, cc @SimonSapin to see what you think about this. (Let me know if you want me to stop pinging you about this, but I always think of you as the champion against a change like this.)

Popping up a level, this is kind of an interesting use of unsafe, isn't it? It's carving out a strictly more conservative set of things the caller needs to uphold than what is actually true. I wonder, for example, how Miri might detect UB in a case like this.

@blyxxyz

Copy link
Copy Markdown
Contributor

Does this confirm that OsStr is a "bag of bytes" on any platform, in that you can put and leave any (init, non-pointer) bytes in the slice, or am I misinterpreting the proposal?

It actually isn't a bag of bytes on Windows, it must be WTF-8-encoded or you can start reading out of bounds:

fnmain(){let b:&[u8] = b"\xC2";let s:&std::ffi::OsStr = unsafe{ std::mem::transmute(b)};dbg!(s);}
$ cargo run -q --target x86_64-pc-windows-gnu[src/main.rs:4] s = "\u{9b}:] = \n\0\0\0\0\0\0\01\u{10}L[...]thread 'main' panicked at 'failed printing to stderr: Windows stdio in console mode does not support writing non-UTF-8 byte sequences', library\std\src\io\stdio.rs:1008:9

The proposal is phrased to never produce invalid WTF-8.

I think that as written now it allows for any OsStr encoding that's a self-synchronizing superset of UTF-8.

@asquared31415

asquared31415 commented Apr 11, 2023

Copy link
Copy Markdown
Contributor

When [transmuting] from &[u8] to &OsStr,

This wording would provide an additional guarantee that &[u8] and &OsStr have the same layout in terms of their (ptr, len) pairs. As far as I am aware, this is something that is not currently guaranteed, and I don't recall the current stance on guaranteeing layout compatibility between any two fat pointer types that have different pointees.

@borsbors added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 28, 2023
@epage
epageforce-pushed the wtf branch 2 times, most recently from e2d912b to e6a35c4CompareMay 29, 2023 12:57
@epage

Copy link
Copy Markdown
ContributorAuthor

I've addressed what caused the wasm build failure and it should be good to go again.

@Amanieu

Copy link
Copy Markdown
Member

@bors r+

@bors

bors commented May 30, 2023

Copy link
Copy Markdown
Collaborator

📌 Commit e6a35c4 has been approved by Amanieu

It is now in the queue for this repository.

@borsbors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 30, 2023
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request May 30, 2023
Allow limited access to `OsStr` bytes
`OsStr` has historically kept its implementation details private out of
concern for locking us into a specific encoding on Windows.
This is an alternative to rust-lang#95290 which proposed specifying the encoding on Windows. Instead, this
only specifies that for cross-platform code, `OsStr`'s encoding is a superset of UTF-8 and defines
rules for safely interacting with it
At minimum, this can greatly simplify the `os_str_bytes` crate and every
arg parser that interacts with `OsStr` directly (which is most of those
that support invalid UTF-8).
Tracking issue: rust-lang#111544
@Dylan-DPCDylan-DPC mentioned this pull request May 30, 2023
@bors

bors commented May 30, 2023

Copy link
Copy Markdown
Collaborator

⌛ Testing commit e6a35c4 with merge 9610dfe...

@bors

bors commented May 31, 2023

Copy link
Copy Markdown
Collaborator

☀️ Test successful - checks-actions
Approved by: Amanieu
Pushing 9610dfe to master...

@borsbors added the merged-by-bors This PR was explicitly merged by bors. label May 31, 2023
@bors
bors merged commit 9610dfe into rust-lang:masterMay 31, 2023
@rustbotrustbot added this to the 1.72.0 milestone May 31, 2023
@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (9610dfe): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

meanrangecount
Regressions ❌
(primary)
--0
Regressions ❌
(secondary)
--0
Improvements ✅
(primary)
--0
Improvements ✅
(secondary)
-3.5%[-4.6%, -2.5%]2
All ❌✅ (primary)--0

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

meanrangecount
Regressions ❌
(primary)
0.0%[0.0%, 0.1%]5
Regressions ❌
(secondary)
--0
Improvements ✅
(primary)
-0.1%[-0.1%, -0.1%]3
Improvements ✅
(secondary)
--0
All ❌✅ (primary)-0.0%[-0.1%, 0.1%]8

Bootstrap: 642.846s -> 643.715s (0.14%)

@apirainoapiraino removed the to-announce Announce this issue on triage meeting label Jun 15, 2023
epage added a commit to epage/rust that referenced this pull request Jul 7, 2023
This extends rust-lang#109698 to allow no-cost conversion between `Vec<u8>` and `OsString`
as suggested in feedback from `os_str_bytes` crate in rust-lang#111544.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 22, 2023
Allow limited access to `OsString` bytes
This extends rust-lang#109698 to allow no-cost conversion between `Vec<u8>` and `OsString` as suggested in feedback from `os_str_bytes` crate in rust-lang#111544.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 22, 2023
Allow limited access to `OsString` bytes
This extends rust-lang#109698 to allow no-cost conversion between `Vec<u8>` and `OsString` as suggested in feedback from `os_str_bytes` crate in rust-lang#111544.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 22, 2023
Allow limited access to `OsString` bytes
This extends rust-lang#109698 to allow no-cost conversion between `Vec<u8>` and `OsString` as suggested in feedback from `os_str_bytes` crate in rust-lang#111544.
@epage
epage deleted the wtf branch July 22, 2023 14:48
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.merged-by-borsThis PR was explicitly merged by bors.S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-libs-api[DEPRECATED; DO NOT USE]

Projects

None yet

Development

Successfully merging this pull request may close these issues.

20 participants

@epage@rustbot@cuviper@ChrisDenton@the8472@joshtriplett@chorman0773@BurntSushi@blyxxyz@asquared31415@SimonSapin@dylni@rust-log-analyzer@m-ou-se@rfcbot@Amanieu@QuineDot@bors@rust-timer@teor2345
, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })(); Allow limited access to `OsStr` bytes by epage · Pull Request #109698 · rust-lang/rust · GitHub
Skip to content

Allow limited access to OsStr bytes - #109698

Merged
bors merged 6 commits into
rust-lang:masterfrom
epage:wtf
May 31, 2023
Merged

Allow limited access to OsStr bytes#109698
bors merged 6 commits into
rust-lang:masterfrom
epage:wtf

Conversation

@epage

@epageepage commented Mar 28, 2023

Copy link
Copy Markdown
Contributor

OsStr has historically kept its implementation details private out of
concern for locking us into a specific encoding on Windows.

This is an alternative to #95290 which proposed specifying the encoding on Windows. Instead, this
only specifies that for cross-platform code, OsStr's encoding is a superset of UTF-8 and defines
rules for safely interacting with it

At minimum, this can greatly simplify the os_str_bytes crate and every
arg parser that interacts with OsStr directly (which is most of those
that support invalid UTF-8).

Tracking issue: #111544

`OsStr` has historically kept its implementation details private out of
concern for locking us into a specific encoding on Windows.
This is an alternative to rust-lang#95290 which proposed specifying the encoding on Windows. Instead, this
only specifies that for cross-platform code, `OsStr`'s encoding is a superset of UTF-8 and defines
rules for safely interacting with it
At minimum, this can greatly simplify the `os_str_bytes` crate and every
arg parser that interacts with `OsStr` directly (which is most of those
that support invalid UTF-8).
@rustbot

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @cuviper (or someone else) soon.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbotrustbot 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 28, 2023
@rustbot

Copy link
Copy Markdown
Collaborator

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

@epage
epageforce-pushed the wtf branch 2 times, most recently from 01f8d93 to 0d87d66CompareMarch 28, 2023 14:26
@cuviper

Copy link
Copy Markdown
Member

I think this counts as new guarantee for API purposes.

@rustbot label +T-libs-api -T-libs
r? libs-api

@rustbotrustbot added T-libs-api [DEPRECATED; DO NOT USE] and removed T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Mar 28, 2023
@rustbotrustbot assigned Amanieu and unassigned cuviperMar 28, 2023
@ChrisDenton

Copy link
Copy Markdown
Member

Out of interest, was there anything in particular that motivated you to propose this now?

@the8472

Copy link
Copy Markdown
Member

I think this should come with an example since it's a wide pointer. Conversion from C to Rust has to jump through extra hoops.

@joshtriplett

Copy link
Copy Markdown
Member

I'm personally amenable to adding this guarantee, but I do agree with @the8472 that we need to confirm that this will actually work as intended.

@epageepage changed the title Allow FFI support for OsStrAllow limited access to OsStr bytes in unsafe blocksMar 31, 2023
@epage

epage commented Mar 31, 2023

Copy link
Copy Markdown
ContributorAuthor

Sorry for the lack of details and confusion on this. I was under the impression that working towards my final goal would best be done in smaller steps of defining OsStr but that meant I didn't have a use case for it which I recognize can be frustrating to deal with when evaluating a major change like this. I've since updated the documentation and PR to reflect the minimum of what I need for my use case: clap and other CLI tools that need to deal with parsing and splitting up OsStrs for however much valid UTF-8 is in them.

My hope that this more limited alternative to #95290 will have a chance to move forward.

@ChrisDenton

Copy link
Copy Markdown
Member

If we do this, I wonder if it makes sense to also offer a split_at method on OsStr that panics if used incorrectly. I.e.:

// Similar to `str::split_at` and `[T]::split_at`// Panics if `mid` is not on a UTF-8 code point boundary.fnsplit_at(&self,mid:usize) -> (&OsStr,&OsStr);

Splitting and joining are the two hazard areas when dealing with known valid OsStrs (whatever form they're in). We have OsString::push for the joining case but nothing to help with splitting. I think it would be unfortunate if we don't have some safe way to check you're doing it right.

@epage

epage commented Mar 31, 2023

Copy link
Copy Markdown
ContributorAuthor

but nothing to help with splitting. I think it would be unfortunate if we don't have some safe way to check you're doing it right.

A part of me finds it weird to offer a safe function like split_at that takes a parameter (mid) that can only be calculated from another type derived from with unsafe code. Documenting use of split_at would then further raise visibility of this feature, for both good (people getting stuff done) and bad (risk of misuse). However, I do see the benefit as that does greatly reduce the risk of something going wrong. In my experiments with transmuting &OsStr, I wrapped all byte operations in functions that only allowed deriving mid from &str parameters (e.g. OsStrExt::strip_prefix(&self, prefix: &str)) so I knew I was splitting at a safe boundary.

EDIT: To make clear, I'm open to adding that function if that is the direction we want to take this.

@ChrisDenton

Copy link
Copy Markdown
Member

Hm, we could offer some safe way to get an index according to these rules. E.g.

// Returns the byte index where `searcher` first returns true.// `searcher` can inspect `char`s decoded from UTF-8.// Non UTF-8 encoded characters are skipped.fnfind_char(&self,searcher:FnMut(char) -> bool) -> Option<usize>;

But at this point I'll stop because I'm practically designing yet another alternative approach.

@chorman0773

Copy link
Copy Markdown
Contributor

Does this confirm that OsStr is a "bag of bytes" on any platform, in that you can put and leave any (init, non-pointer) bytes in the slice, or am I misinterpreting the proposal?

@epage

epage commented Apr 11, 2023

Copy link
Copy Markdown
ContributorAuthor

Does this confirm that OsStr is a "bag of bytes" on any platform, in that you can put and leave any (init, non-pointer) bytes in the slice, or am I misinterpreting the proposal?

For now, this proposals restricts what is safe to transmute from &[u8] to &OsStr, so this does not work as an arbitrary bag of bytes

//! - When [transmuting] from `&[u8]` to `&OsStr`,//! - the slice may only include content from comparable `&OsStr` (see above) or be valid UTF-8//! - any splits of the `&OsStr` must be along char boundaries (the first byte of a UTF-8 code//! point sequence)

@BurntSushi

Copy link
Copy Markdown
Member

I think I buy the rules as written, but I would like to see a doc example using unsafe, along with a SAFETY comment justifying why it's OK. I think that would also help others write correct code.

Also, cc @SimonSapin to see what you think about this. (Let me know if you want me to stop pinging you about this, but I always think of you as the champion against a change like this.)

Popping up a level, this is kind of an interesting use of unsafe, isn't it? It's carving out a strictly more conservative set of things the caller needs to uphold than what is actually true. I wonder, for example, how Miri might detect UB in a case like this.

@blyxxyz

Copy link
Copy Markdown
Contributor

Does this confirm that OsStr is a "bag of bytes" on any platform, in that you can put and leave any (init, non-pointer) bytes in the slice, or am I misinterpreting the proposal?

It actually isn't a bag of bytes on Windows, it must be WTF-8-encoded or you can start reading out of bounds:

fnmain(){let b:&[u8] = b"\xC2";let s:&std::ffi::OsStr = unsafe{ std::mem::transmute(b)};dbg!(s);}
$ cargo run -q --target x86_64-pc-windows-gnu[src/main.rs:4] s = "\u{9b}:] = \n\0\0\0\0\0\0\01\u{10}L[...]thread 'main' panicked at 'failed printing to stderr: Windows stdio in console mode does not support writing non-UTF-8 byte sequences', library\std\src\io\stdio.rs:1008:9

The proposal is phrased to never produce invalid WTF-8.

I think that as written now it allows for any OsStr encoding that's a self-synchronizing superset of UTF-8.

@asquared31415

asquared31415 commented Apr 11, 2023

Copy link
Copy Markdown
Contributor

When [transmuting] from &[u8] to &OsStr,

This wording would provide an additional guarantee that &[u8] and &OsStr have the same layout in terms of their (ptr, len) pairs. As far as I am aware, this is something that is not currently guaranteed, and I don't recall the current stance on guaranteeing layout compatibility between any two fat pointer types that have different pointees.

@borsbors added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 28, 2023
@epage
epageforce-pushed the wtf branch 2 times, most recently from e2d912b to e6a35c4CompareMay 29, 2023 12:57
@epage

Copy link
Copy Markdown
ContributorAuthor

I've addressed what caused the wasm build failure and it should be good to go again.

@Amanieu

Copy link
Copy Markdown
Member

@bors r+

@bors

bors commented May 30, 2023

Copy link
Copy Markdown
Collaborator

📌 Commit e6a35c4 has been approved by Amanieu

It is now in the queue for this repository.

@borsbors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 30, 2023
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request May 30, 2023
Allow limited access to `OsStr` bytes
`OsStr` has historically kept its implementation details private out of
concern for locking us into a specific encoding on Windows.
This is an alternative to rust-lang#95290 which proposed specifying the encoding on Windows. Instead, this
only specifies that for cross-platform code, `OsStr`'s encoding is a superset of UTF-8 and defines
rules for safely interacting with it
At minimum, this can greatly simplify the `os_str_bytes` crate and every
arg parser that interacts with `OsStr` directly (which is most of those
that support invalid UTF-8).
Tracking issue: rust-lang#111544
@Dylan-DPCDylan-DPC mentioned this pull request May 30, 2023
@bors

bors commented May 30, 2023

Copy link
Copy Markdown
Collaborator

⌛ Testing commit e6a35c4 with merge 9610dfe...

@bors

bors commented May 31, 2023

Copy link
Copy Markdown
Collaborator

☀️ Test successful - checks-actions
Approved by: Amanieu
Pushing 9610dfe to master...

@borsbors added the merged-by-bors This PR was explicitly merged by bors. label May 31, 2023
@bors
bors merged commit 9610dfe into rust-lang:masterMay 31, 2023
@rustbotrustbot added this to the 1.72.0 milestone May 31, 2023
@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (9610dfe): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

meanrangecount
Regressions ❌
(primary)
--0
Regressions ❌
(secondary)
--0
Improvements ✅
(primary)
--0
Improvements ✅
(secondary)
-3.5%[-4.6%, -2.5%]2
All ❌✅ (primary)--0

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

meanrangecount
Regressions ❌
(primary)
0.0%[0.0%, 0.1%]5
Regressions ❌
(secondary)
--0
Improvements ✅
(primary)
-0.1%[-0.1%, -0.1%]3
Improvements ✅
(secondary)
--0
All ❌✅ (primary)-0.0%[-0.1%, 0.1%]8

Bootstrap: 642.846s -> 643.715s (0.14%)

@apirainoapiraino removed the to-announce Announce this issue on triage meeting label Jun 15, 2023
epage added a commit to epage/rust that referenced this pull request Jul 7, 2023
This extends rust-lang#109698 to allow no-cost conversion between `Vec<u8>` and `OsString`
as suggested in feedback from `os_str_bytes` crate in rust-lang#111544.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 22, 2023
Allow limited access to `OsString` bytes
This extends rust-lang#109698 to allow no-cost conversion between `Vec<u8>` and `OsString` as suggested in feedback from `os_str_bytes` crate in rust-lang#111544.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 22, 2023
Allow limited access to `OsString` bytes
This extends rust-lang#109698 to allow no-cost conversion between `Vec<u8>` and `OsString` as suggested in feedback from `os_str_bytes` crate in rust-lang#111544.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 22, 2023
Allow limited access to `OsString` bytes
This extends rust-lang#109698 to allow no-cost conversion between `Vec<u8>` and `OsString` as suggested in feedback from `os_str_bytes` crate in rust-lang#111544.
@epage
epage deleted the wtf branch July 22, 2023 14:48
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.merged-by-borsThis PR was explicitly merged by bors.S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-libs-api[DEPRECATED; DO NOT USE]

Projects

None yet

Development

Successfully merging this pull request may close these issues.

20 participants

@epage@rustbot@cuviper@ChrisDenton@the8472@joshtriplett@chorman0773@BurntSushi@blyxxyz@asquared31415@SimonSapin@dylni@rust-log-analyzer@m-ou-se@rfcbot@Amanieu@QuineDot@bors@rust-timer@teor2345