# \[Pitch/Discussion\] Rename symbols that have been audited as unsafe (or fix LLVM)

**URL:** <https://forums.swift.org/t/pitch-discussion-rename-symbols-that-have-been-audited-as-unsafe-or-fix-llvm/88498>\
**Category:** Pitches\
**Created:** [July 23, 2026, 10:57pm UTC](https://forums.swift.org/t/pitch-discussion-rename-symbols-that-have-been-audited-as-unsafe-or-fix-llvm/88498 "2026-07-23T22:57:07Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![glessard](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/glessard/32/409_2.png) [@glessard](https://forums.swift.org/u/glessard)\
**Post date:** [July 23, 2026, 10:57pm UTC](https://forums.swift.org/t/pitch-discussion-rename-symbols-that-have-been-audited-as-unsafe-or-fix-llvm/88498/1 "2026-07-23T22:57:07Z")

</div>

As part of the initial set of proposals for `Span`, `RawSpan`, `MutableSpan` and others, we accepted some functions that reinterpret typed memory as untyped bytes. Some of these have since then had to be revised with an `@unsafe` annotation. As a result, their names do not reflect the unsafety in typical use (when compiled without `-strict-memory-safety`). This discussion is about how to solve this discrepancy.

The underlying issue is that after LLVM initializes some storage with a value, it may choose to treat any padding bytes within the storage of the value as uninitialized. This in keeping with its identity as a C compiler, but is neither the only possible choice nor necessarily a desirable behaviour from the compiler for languages that use LLVM but are _not_ C, such as Swift.

We can solve the naming discrepancy in one of two ways:

- Change LLVM's treatment of padding bytes (in Swift mode) so that they do not lead to undefined behaviour, and then remove the `@unsafe` annotations for these functions or properties.
- Rename these functions and properties to reflect that they are unsafe.

The second option is the simpler one, but doesn't solve the underlying issue. The unsafety comes from a decision of the C language that Swift might not make; is it feasible to make a different decision?

In the meantime, I have prepared a [proposal document](https://github.com/glessard/swift-evolution/blob/046bb3aac1ccf78333c9118b8d806ce40d992413/proposals/nnnn-rename-unsafe-span-byte-conversions.md) for renaming ([PR](https://github.com/swiftlang/swift-evolution/pull/3371)), since the standard library is the part of the system I understand best. In short, the `@unsafe` symbols to be renamed are as follows:

- `bytes` → `unsafeBytes` (`Span`, `MutableSpan`)
- `mutableBytes` → `unsafeMutableBytes` (`MutableSpan`)
- `append(_:as:)` → `append(unsafeBytes:as:)` (`OutputRawSpan`)
- `append(repeating:count:as:)` → `append(repeatingUnsafeBytes:count:as:)` (`OutputRawSpan`)

I'd be glad for this proposal to be put aside in favor of changing LLVM. While the amount of effort is not the same, both have a similar time horizon for completion because of the lengthy deprecation window we must allow for.

---

<div class="post-metadata">

**Author:** ![xwu](https://avatars.discourse-cdn.com/v4/letter/x/b487fb/32.png) [@xwu](https://forums.swift.org/u/xwu)\
**Post date:** [July 23, 2026, 11:02pm UTC](https://forums.swift.org/t/pitch-discussion-rename-symbols-that-have-been-audited-as-unsafe-or-fix-llvm/88498/2 "2026-07-23T23:02:36Z")

</div>

> [@glessard](#):
>
> In the meantime, I have prepared a [proposal document](https://github.com/glessard/swift-evolution/blob/046bb3aac1ccf78333c9118b8d806ce40d992413/proposals/nnnn-rename-unsafe-span-byte-conversions.md) for renaming, since the standard library is the part of the system I understand best. In short, the `@unsafe` symbols to be renamed are as follows:
> 
> - `bytes` → `unsafeBytes` (`Span`, `MutableSpan`)
> - `mutableBytes` → `unsafeMutableBytes` (`MutableSpan`)
> - `append(_:as:)` → `append(unsafeBytes:as:)` (`OutputRawSpan`)
> - `append(repeating:count:as:)` → `append(repeatingUnsafeBytes:count:as:)` (`OutputRawSpan`)

Nit regarding the latter two operations: is it the _append_ which is unsafe or the _bytes_ being read from? If the former, the name really should be `unsafeAppend`.

Safety is always better than unsafety of course. If we rename now to reflect the currently unsafe reality but then make LLVM better, the newly-made-safe-previously-deprecated APIs can be straightforwardly undeprecated, presumably. So it doesn't seem either-or.

---

<div class="post-metadata">

**Author:** ![glessard](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/glessard/32/409_2.png) [@glessard](https://forums.swift.org/u/glessard)\
**Post date:** [July 23, 2026, 11:05pm UTC](https://forums.swift.org/t/pitch-discussion-rename-symbols-that-have-been-audited-as-unsafe-or-fix-llvm/88498/3 "2026-07-23T23:05:35Z")

</div>

> [@xwu](#):
>
> is it the _append_ which is unsafe or the _bytes_ being read from?

It's actually both. The source bytes might include some locations marked by the compiler as undefined, and it can kindly copy that state over.

> [@xwu](#):
>
> So it doesn't seem either-or.

Indeed.

---

<div class="post-metadata">

**Author:** ![sliemeobn](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/sliemeobn/32/27698_2.png) [@sliemeobn](https://forums.swift.org/u/sliemeobn)\
**Post date:** [July 24, 2026, 6:55am UTC](https://forums.swift.org/t/pitch-discussion-rename-symbols-that-have-been-audited-as-unsafe-or-fix-llvm/88498/4 "2026-07-24T06:55:01Z")

</div>

What are the downsides to changing LLVM's behavior (if any)?

Because honestly, to me as a "user" of the language, this reads:  
Option A:  
Deal with deprecations, migration work for everyone, a messy transition phase, and more `unsafe` littered all over codebases (for the shiny new "safe" language addition mind you), - or -

Option B:  
just make the problem go away without any changes

so, why would anyone NOT want the LLVM adjustments?

---

<div class="post-metadata">

**Author:** ![ben-lev](https://avatars.discourse-cdn.com/v4/letter/b/90ced4/32.png) [@ben-lev](https://forums.swift.org/u/ben-lev)\
**Post date:** [July 24, 2026, 7:31pm UTC](https://forums.swift.org/t/pitch-discussion-rename-symbols-that-have-been-audited-as-unsafe-or-fix-llvm/88498/5 "2026-07-24T19:31:07Z")

</div>

Would changing LLVM behavior as described incur any performance impact to initialize the padding bytes? If so IMO it sounds questionable to do extra real runtime work for the purpose of avoiding uninitialized memory in the padding bytes of a struct, since interpreting a struct instance as raw bytes is uncommon and generally dangerous (not using the strict definition of that word) to begin with.

---

<div class="post-metadata">

**Author:** ![glessard](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/glessard/32/409_2.png) [@glessard](https://forums.swift.org/u/glessard)\
**Post date:** [July 24, 2026, 8:04pm UTC](https://forums.swift.org/t/pitch-discussion-rename-symbols-that-have-been-audited-as-unsafe-or-fix-llvm/88498/6 "2026-07-24T20:04:42Z")

</div>

(Hand-waving follows… and since I might not have retained an earlier discussion correctly, it's probably wrong.) The idea would be to mark the state of such bytes so that if they're read once, they will keep providing the same value if they're read again. This doesn't require actually writing to them, but it's a change in the internal housekeeping of the compiler. Currently if the compiler has decided not to write a padding byte and marks it undefined instead, then trying to read that byte later might as well be from a random-number generator. If still in a scope where the compiler is still keeping track of that byte.

---

<div class="post-metadata">

**Author:** ![ksluder](https://avatars.discourse-cdn.com/v4/letter/k/eada6e/32.png) [@ksluder](https://forums.swift.org/u/ksluder)\
**Post date:** [July 24, 2026, 8:06pm UTC](https://forums.swift.org/t/pitch-discussion-rename-symbols-that-have-been-audited-as-unsafe-or-fix-llvm/88498/7 "2026-07-24T20:06:02Z")

</div>

I thought this point was specifically raised during the evolution discussion, and there was a distinction drawn between the domains of safety that the `@unsafe` attribute and the `unsafe` API prefix relate to.

---

<div class="post-metadata">

**Author:** ![glessard](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/glessard/32/409_2.png) [@glessard](https://forums.swift.org/u/glessard)\
**Post date:** [August 8, 2026, 1:03am UTC](https://forums.swift.org/t/pitch-discussion-rename-symbols-that-have-been-audited-as-unsafe-or-fix-llvm/88498/8 "2026-08-08T01:03:55Z")

</div>

Pushing further on the idea of what happens if LLVM does get fixed, it's interesting to note that while hazards from undefined behaviour would be eliminated, there would remain a hazard from bytes whose value has not been intentionally set by the running program. Perhaps then a name should point to _that_ hazard rather than to memory unsafety. The memory unsafety is already indicated by `@unsafe`, so maybe we can find a hazard-word about reading padding bytes.

`unsafeBytes`: this is the obvious starting point, but overstates the case once LLVM is fixed.

`paddedBytes`: similarly compact to `unsafeBytes`.

`unspecifiedBytes`: seems to refer to all the bytes.

`bytesWithArbitraryPadding`: quite explicit, but long.

`bytesWithUnspecifiedPadding`: see above

`sparseBytes`: not bad, but suggests a low signal-to-noise ratio. Independently suggested by two different colleagues.

These would be for the read direction; the read-write case of `mutableBytes` should probably keep "unsafe" in its new name.

---

<div class="post-metadata">

**Author:** ![scanon](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/scanon/32/2445_2.png) [@scanon](https://forums.swift.org/u/scanon)\
**Post date:** [August 8, 2026, 1:26am UTC](https://forums.swift.org/t/pitch-discussion-rename-symbols-that-have-been-audited-as-unsafe-or-fix-llvm/88498/9 "2026-08-08T01:26:01Z")

</div>

I stand by my suggestion of ``bytes, maybe``. 🤪

---

<div class="post-metadata">

**Author:** ![xwu](https://avatars.discourse-cdn.com/v4/letter/x/b487fb/32.png) [@xwu](https://forums.swift.org/u/xwu)\
**Post date:** [August 8, 2026, 3:37pm UTC](https://forums.swift.org/t/pitch-discussion-rename-symbols-that-have-been-audited-as-unsafe-or-fix-llvm/88498/10 "2026-08-08T15:37:52Z")

</div>

> [@scanon](#):
>
> I stand by my suggestion of ``bytes, maybe``. 🤪

Well, they're _always_ bytes, right? They just might be...bitey?

* * *

> [@](#):
>
> `paddedBytes`: similarly compact to `unsafeBytes`.

I like this one not simply due to compactness but because it doesn't sound too absurd for padding of zero (at least to me, the verb in this context implies that nothing will be padded if there's no need for it--à la string padding). If we want to be wordy we could call it `arbitrarilyPaddedBytes`. I think the names that say the bytes come "_with_ padding" are maybe a bit strong for that case.

---

<div class="post-metadata">

**Author:** ![glessard](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/glessard/32/409_2.png) [@glessard](https://forums.swift.org/u/glessard)\
**Post date:** [September 11, 2026, 1:31am UTC](https://forums.swift.org/t/pitch-discussion-rename-symbols-that-have-been-audited-as-unsafe-or-fix-llvm/88498/11 "2026-09-11T01:31:08Z")

</div>

I've updated the proposal document to use `padded` as the word to indicate the hazard, so that `bytes` becomes `paddedBytes`, `append(_:as:)` becomes `append(paddedBytes:as:)`, etc.
