[lldb][bytecode] Improvements to compiler generated Swift (#189425)

Following feedback from @benrimmington in
https://github.com/apple/swift-collections/pull/607, this changes the
following:

1. Uses `objectFormat()` compiler conditional instead of `os()` (see
"Cross-platform object file format support" in
[SE-0492](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0492-section-control.md#cross-platform-object-file-format-support))
2. Uses a raw identifier for the generated Swift symbol name, instead of
an escaped name (see
[SE-0451](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0451-escaped-identifiers.md))
This commit is contained in:
Dave Lee 2026-03-31 08:23:30 -07:00 committed by GitHub
parent 67c34294a6
commit b66d98afb9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 10 deletions

View File

@ -295,11 +295,6 @@ class BytecodeSection:
builder.emit_uleb(len(bc), "program size")
builder.emit_bytes(bc, "program")
@property
def _var_name(self):
var_name = re.sub(r"\W", "_", self.type_name)
return f"_{var_name}_formatter"
def write_c(self, output: TextIO) -> None:
self.validate()
@ -322,7 +317,8 @@ class BytecodeSection:
"__attribute__((used, section(FORMATTER_SECTION)))",
file=output,
)
print(f"unsigned char {self._var_name}[] =", file=output)
var_name = re.sub(r"\W", "_", self.type_name)
print(f"unsigned char _{var_name}_formatter[] =", file=output)
indent = " "
for string, comment in builder.entries:
print(f"{indent}// {comment}", file=output)
@ -339,7 +335,7 @@ class BytecodeSection:
textwrap.dedent(
"""\
#if swift(>=6.3)
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(visionOS)
#if objectFormat(MachO)
@section("__DATA_CONST,__lldbformatters")
#else
@section(".lldbformatters")
@ -349,7 +345,7 @@ class BytecodeSection:
file=output,
)
print(
f"let {self._var_name}: {builder.type_decl} = (",
f"let `{self.type_name} formatter`: {builder.type_decl} = (",
file=output,
)
indent = " "

View File

@ -1,11 +1,11 @@
#if swift(>=6.3)
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(visionOS)
#if objectFormat(MachO)
@section("__DATA_CONST,__lldbformatters")
#else
@section(".lldbformatters")
#endif
@used
let _RigidArray_formatter: (UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8) = (
let `RigidArray formatter`: (UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8) = (
// version
0x01,
// remaining record size