library: Move CStr to libcore, and CString to liballoc#94079
library: Move CStr to libcore, and CString to liballoc#94079bors merged 5 commits intorust-lang:masterfrom
CStr to libcore, and CString to liballoc#94079Conversation
|
r? @yaahc (rust-highfive has picked a reviewer for you, use r? to override) |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
|
This is great! I'd love to see this move, to make it easier to interface with C FFI in contexts that don't necessarily want std. Platform |
This comment has been minimized.
This comment has been minimized.
Relying on target ABI in libcore is okA lot of attention in #46736 is put on whether depending on Obviously, libcore cannot depend on calling OS services, be it syscalls or functions or system libraries. Even without libcore the compiler cares about the target's ABI and keeps the relevant data in target specifications (inside rustc and LLVM). Recently core contains more of target-dependent stuff than back in 2017 when #46736 was created, because it's simply too useful to break that restriction sometimes. I personally don't see issues with putting that #[cfg(target_c_char_signed)]
type c_char = i8;
#[cfg(not(target_c_char_signed))]
type c_char = u8; |
I am generally in favor of depending on more libc symbols in core ( |
This comment was marked as resolved.
This comment was marked as resolved.
|
|
We discussed this in today's @rust-lang/libs-api team meeting. Many people are enthusiastic to see this work happen. Regarding relying on target ABI, there were zero objections. Regarding strlen, there was a consensus in favor of the general approach @Amanieu suggested, of going ahead and using platform C library functions in core as long as they're functions that we can fall back to compiler-builtins for, so that we can use the optimized implementations from the C library if available. Regarding CStr functions that return types only available in alloc or std: we had some discussion about whether we should use an extension trait for this, or use a lang item or some similar mechanism to allow extending Ultimately, though, we decided that we'd rather not add lang items for this, and we'd rather use an extension trait as long as that won't break anything in practice. So, summary: let's do a crater run to confirm that the extension trait doesn't break anything, and then go with the extension trait. |
When implementing this I recalled that we had such extension traits before, but I couldn't find any of them in libcore now. This |
|
@petrochenkov A lang item seems fine as well. And (EDIT: corrected) we don't need a crater run in that case. |
|
Note that #94503 has just moved |
|
We discussed this again in today's @rust-lang/libs meeting. We're fine with using a lang item in this case, since that's what we already do in other cases. In general, we'd like to steer away in the future from having any inherent methods on types in core that return types from alloc or std (or inherent methods on types in alloc that return types from std, if any). Such methods make the binding between those two types more special, and make it a little harder to write drop-in replacements for types like CString/String/etc. So, for instance, in this case we should ideally steer people towards But none of that is a blocker for this move; this method can go ahead and use a lang item as other methods do, and we'll have the more general discussion in the future. |
|
@bors r=joshtriplett |
|
📌 Commit 6eaec56 has been approved by |
|
⌛ Testing commit 6eaec56 with merge f50f07b174bc2022c40eefc1b9b5f6ade8b4505a... |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
|
@bors r=joshtriplett |
|
📌 Commit f62c84e has been approved by |
|
☀️ Test successful - checks-actions |
|
Finished benchmarking commit (1e6fe58): comparison url. Summary:
If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. Next Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression Footnotes |
|
@lygstate If you have issues with this setup, could you open a new issue and describe your case? |
|
Visiting for weekly performance triage
@rustbot label: +perf-regression-triaged |
|
I want to note that this is a regression in rustdoc output, as https://doc.rust-lang.org/nightly/std/ffi/type.CString.html is now just a link to https://doc.rust-lang.org/nightly/alloc/ffi/struct.CString.html. (This also causes the type to show up as an external type for implementations.) Also, should this get a tracking issue rather than pointing to this PR? |
|
@CAD97 When we stabilize this, we can switch back from type aliases to re-exports, which should address that. |
Closes #46736
Interesting points:
CStr(ing)from libcore/liballoc unusable without enabling features I had to make these structures unstable, and reexport them from libstd using stable type aliases instead ofpub usereexports. (Because stability ofuseitems is not checked.)CStrto libcore, andCStringto liballoc #94079 (comment)trait CStrExt(UPDATE: used only incfg(bootstrap)mode, otherwise lang items are used instead)CStrto libcore, andCStringto liballoc #94079 (comment)strlenCStrto libcore, andCStringto liballoc #94079 (comment)Otherwise it's just a code move + some minor hackery usual for liballoc in
cfg(test)mode.