Skip to content

Commit d493b7c

Browse files
committed
Auto merge of #155710 - tgross35:rollup-skXlTFI, r=tgross35
Rollup of 7 pull requests Successful merges: - #155660 (c-variadic: fix for sparc64) - #153482 (tests/ui/macros: add annotations for reference rules) - #155075 (Add docs about SDKs and C compilation on armv7a-vex-v5) - #155685 (Fix `get_child_at_index` return type hints) - #155686 (Fix array template arg lookup behavior) - #155689 (Const initialize `LOCK_LATCH` thread local) - #155690 (Fix classify_union to return Union for regular unions)
2 parents 9836b06 + 2493328 commit d493b7c

55 files changed

Lines changed: 432 additions & 180 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

compiler/rustc_codegen_llvm/src/va_arg.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,30 @@ enum SlotSize {
8888
Bytes1 = 1,
8989
}
9090

91+
/// Whether to respect a value alignment that is higher than the slot alignment.
92+
///
93+
/// When `No` the argument is in the next slot, when `Yes` there will be empty slots
94+
/// until a slot's starting address has the required alignment.
9195
enum AllowHigherAlign {
9296
No,
9397
Yes,
9498
}
9599

100+
/// Determines where in the slot the value is located. Only takes effect on big-endian targets.
101+
///
102+
/// with 8-byte slots, a 32-bit integer is either stored right-adjusted:
103+
///
104+
/// ```text
105+
/// [0x0, 0x0, 0x0, 0x0, 0xaa, 0xaa, 0xaa, 0xaa]
106+
/// ```
107+
///
108+
/// or left-adjusted:
109+
///
110+
/// ```text
111+
/// [0xaa, 0xaa, 0xaa, 0xaa, 0x0, 0x0, 0x0, 0x0]
112+
/// ```
113+
///
114+
/// Most big-endian targets store values as right-adjusted.
96115
enum ForceRightAdjust {
97116
No,
98117
Yes,
@@ -1169,7 +1188,8 @@ pub(super) fn emit_va_arg<'ll, 'tcx>(
11691188
if target_ty_size > 2 * 8 { PassMode::Indirect } else { PassMode::Direct },
11701189
SlotSize::Bytes8,
11711190
AllowHigherAlign::Yes,
1172-
ForceRightAdjust::No,
1191+
// sparc64 is a big-endian target and stores variable arguments right-adjusted.
1192+
ForceRightAdjust::Yes,
11731193
),
11741194
Arch::Mips | Arch::Mips32r6 | Arch::Mips64 | Arch::Mips64r6 => emit_ptr_va_arg(
11751195
bx,

compiler/rustc_thread_pool/src/latch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ pub(super) struct LockLatch {
220220

221221
impl LockLatch {
222222
#[inline]
223-
pub(super) fn new() -> LockLatch {
223+
pub(super) const fn new() -> LockLatch {
224224
LockLatch { m: Mutex::new(false), v: Condvar::new() }
225225
}
226226

compiler/rustc_thread_pool/src/registry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ impl Registry {
524524
OP: FnOnce(&WorkerThread, bool) -> R + Send,
525525
R: Send,
526526
{
527-
thread_local!(static LOCK_LATCH: LockLatch = LockLatch::new());
527+
thread_local!(static LOCK_LATCH: LockLatch = const { LockLatch::new() });
528528

529529
LOCK_LATCH.with(|l| {
530530
// This thread isn't a member of *any* thread pool, so just block.

src/doc/rustc/src/platform-support/armv7a-vex-v5.md

Lines changed: 94 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
Allows compiling user programs for the [VEX V5 Brain](https://www.vexrobotics.com/276-4810.html), a microcontroller for educational and competitive robotics.
66

7-
Rust support for this target is not affiliated with VEX Robotics or IFI, and does not link to any official VEX SDK.
7+
Rust support for this target is not affiliated with VEX Robotics or IFI, and does not link against any official VEX SDK.
88

99
## Target maintainers
1010

1111
This target is maintained by members of the [vexide](https://github.com/vexide) organization:
1212

1313
- [@lewisfm](https://github.com/lewisfm)
14-
- [@Tropix126](https://github.com/Tropix126)
14+
- [@tropicaaal](https://github.com/tropicaaal)
1515
- [@Gavin-Niederman](https://github.com/Gavin-Niederman)
1616
- [@max-niederman](https://github.com/max-niederman)
1717

@@ -22,27 +22,37 @@ This target is cross-compiled. Dynamic linking is unsupported.
2222
`#![no_std]` crates can be built using `build-std` to build `core` and `panic_abort` and optionally `alloc`. Unwinding panics are not yet supported on this target.
2323

2424
`std` has only partial support due to platform limitations. Notably:
25+
2526
- `std::process` and `std::net` are unimplemented. `std::thread` only supports sleeping and yielding, as this is a single-threaded environment.
2627
- `std::time` has full support for `Instant`, but no support for `SystemTime`.
2728
- `std::io` has full support for `stdin`/`stdout`/`stderr`. `stdout` and `stderr` both write to USB channel 1 on this platform and are not differentiated.
28-
- `std::fs` has limited support for reading or writing to files. Directory operations, file deletion, and some file opening features are unsupported and will return errors.
29+
- `std::fs` has limited support for reading or writing to files. The following features are unsupported:
30+
- All directory operations (including `mkdir` and `readdir`), although reading directories is possible through [third-party crates](https://docs.rs/vex-sdk/latest/vex_sdk/file/fn.vexFileDirectoryGet.html)
31+
- Deleting files and directories
32+
- File metadata other than file size and type (that is, file vs. directory)
33+
- Opening files with an uncommon combination of open options, such as read + write at the same time.
34+
The supported modes for opening files are in read-only mode, append mode, or write mode (with or without truncation).
2935
- A global allocator implemented on top of `dlmalloc` is provided.
30-
- Modules that do not need to interact with the OS beyond allocation such as `std::collections`, `std::hash`, `std::future`, `std::sync`, etc are fully supported.
36+
- Modules that do not need to interact with the OS beyond allocation, such as `std::collections`, `std::hash`, `std::future`, `std::sync`, etc., are fully supported.
3137
- Random number generation and hashing is insecure, as there is no reliable source of entropy on this platform.
3238

33-
In order to support some APIs, users are expected to provide a supporting runtime SDK for `libstd` to link against. This library may be provided either by [`vex-sdk-build`](https://github.com/vexide/vex-sdk/tree/main/packages/vex-sdk-build) (which will download an official SDK from VEX) or through an open-source implementation such as [`vex-sdk-jumptable`](https://crates.io/crates/vex-sdk-jumptable).
34-
3539
When compiling for this target, the "C" calling convention maps to AAPCS with VFP registers (hard float ABI) and the "system" calling convention maps to AAPCS without VFP registers (softfp ABI).
3640

3741
This target generates binaries in the ELF format that may be uploaded to the brain with external tools.
3842

43+
### Platform SDKs
44+
45+
To use most platform-specific APIs, users must configure a supporting runtime SDK for `libstd` to link against. Official *VEXcode* SDKs from VEX can be downloaded and linked via the [`vex-sdk-vexcode`](https://crates.io/crates/vex-sdk-vexcode) crate, but they have a restrictive redistribution policy that might not be suitable for all projects. The suggested SDK for open-source projects is the community-supported [`vex-sdk-jumptable`](https://crates.io/crates/vex-sdk-jumptable) crate. SDK implementations are generally thin wrappers over system calls, so projects should not expect to see significant differences in behavior depending on which SDK they use.
46+
47+
Libraries may access symbols from the active VEX SDK without depending on a specific implementation by using the [`vex-sdk`](https://crates.io/crates/vex-sdk) crate.
48+
3949
## Building the target
4050

4151
You can build Rust with support for this target by adding it to the `target` list in `bootstrap.toml`, and then running `./x build --target armv7a-vex-v5 compiler`.
4252

4353
## Building Rust programs
4454

45-
Rust does not yet ship pre-compiled artifacts for this target. To compile for this target, you will either need to build Rust with the target enabled (see "Building the target" above), or build your own copy of `core` by using `build-std` or similar.
55+
Rust does not yet ship pre-compiled artifacts for this target. To compile for this target, you will either need to build Rust with the target enabled (see "Building the target" above), or build your own copy of `std` using `build-std` or similar.
4656

4757
When the compiler builds a binary, an ELF build artifact will be produced. Additional tools are required for this artifact to be recognizable to VEXos as a user program.
4858

@@ -78,9 +88,19 @@ Programs can also be directly uploaded to the brain over a USB connection immedi
7888
cargo v5 upload --release
7989
```
8090

91+
### Hello World program
92+
93+
```rs
94+
use ::vex_sdk_jumptable as _; // Bring VEX SDK symbols into scope
95+
96+
fn main() {
97+
println!("Hello, world");
98+
}
99+
```
100+
81101
## Testing
82102

83-
Binaries built for this target can be run in an emulator (such as [vex-v5-qemu](https://github.com/vexide/vex-v5-qemu)), or uploaded to a physical device over a serial (USB) connection.
103+
Binaries built for this target can be run in an emulator (such as [vex-v5-qemu](https://github.com/vexide/vex-v5-qemu)), or uploaded to a physical device over a USB serial connection.
84104

85105
The default Rust test runner is not supported.
86106

@@ -90,4 +110,69 @@ The Rust test suite for `library/std` is not yet supported.
90110

91111
This target can be cross-compiled from any host.
92112

93-
Linking to C libraries is not supported.
113+
The recommended configuration for compiling compatible C code is to use the [Arm Toolchain for Embedded](https://github.com/arm/arm-toolchain/tree/arm-software/arm-software/embedded#readme) with the following compilation flags:
114+
115+
```sh
116+
clang --target=arm-none-eabi -mcpu=cortex-a9 -mfpu=neon -mfloat-abi=hard -fno-pic -fno-exceptions -fno-rtti -funwind-tables
117+
```
118+
119+
The following Cargo configuration can be used to link with picolibc (the libc used by the Arm Toolchain for Embedded):
120+
121+
```toml
122+
[target.armv7a-vex-v5]
123+
# We use ARM Clang as a linker because ld.lld by itself doesn't include the
124+
# multilib logic for resolving static libraries.
125+
linker = "clang"
126+
127+
rustflags = [
128+
# These link flags resolve to this sysroot:
129+
# `…/arm-none-eabi/armv7a_hard_vfpv3_d16_unaligned`
130+
# (hard float / VFP version 3 with 16 regs / unaligned access)
131+
"-Clink-arg=--target=armv7a-none-eabihf",
132+
133+
# To disable crt0 and use Rust's _boot implementation
134+
# (or something custom):
135+
#"-Clink-arg=-nostartfiles",
136+
137+
# Explicit `-lc` required because Rust calls the linker with
138+
# `-nodefaultlibs` which disables libc, libm, etc.
139+
"-Clink-arg=-lc",
140+
]
141+
```
142+
143+
You may also want to set these environment variables so that third-party crates use the correct C compiler:
144+
145+
```sh
146+
PATH=/path/to/arm-toolchain/bin:$PATH
147+
CC_armv7a_vex_v5=clang
148+
AR_armv7a_vex_v5=clang
149+
CFLAGS_armv7a_vex_v5=[See above]
150+
```
151+
152+
### CMake
153+
154+
It may be helpful to create a CMake toolchain like the following if you are depending on the `cmake` crate:
155+
156+
```cmake
157+
# toolchain.cmake
158+
set(CMAKE_SYSTEM_NAME Generic)
159+
set(CMAKE_SYSTEM_PROCESSOR arm)
160+
161+
set(triple armv7a-none-eabihf)
162+
163+
set(CMAKE_C_COMPILER clang)
164+
set(CMAKE_C_COMPILER_TARGET ${triple})
165+
set(CMAKE_CXX_COMPILER clang++)
166+
set(CMAKE_CXX_COMPILER_TARGET ${triple})
167+
set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY")
168+
```
169+
170+
You can enable it by setting the following environment variable alongside the previously mentioned environment variables:
171+
172+
```sh
173+
CMAKE_TOOLCHAIN_FILE_armv7a_vex_v5=/path/to/toolchain.cmake
174+
```
175+
176+
### Implementation of libc functions
177+
178+
You may have to implement [certain system support functions](https://github.com/picolibc/picolibc/blob/main/doc/os.md) for some parts of libc to work properly.

src/etc/lldb_providers.py

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22
import sys
3-
from typing import Generator, List, TYPE_CHECKING
3+
from typing import Generator, List, TYPE_CHECKING, Optional
44

55
from lldb import (
66
SBData,
@@ -112,7 +112,7 @@ def get_child_index(self, name: str) -> int:
112112
return self.valobj.Dereference().GetSyntheticValue()
113113
return self.valobj.GetIndexOfChildWithName(name)
114114

115-
def get_child_at_index(self, index: int) -> SBValue:
115+
def get_child_at_index(self, index: int) -> Optional[SBValue]:
116116
return self.valobj.GetChildAtIndex(index)
117117

118118
def update(self):
@@ -137,7 +137,7 @@ def get_child_index(self, name: str) -> int:
137137
return 0
138138
return -1
139139

140-
def get_child_at_index(self, index: int) -> SBValue:
140+
def get_child_at_index(self, index: int) -> Optional[SBValue]:
141141
if index == 0:
142142
return self.valobj.Dereference().GetSyntheticValue()
143143
return None
@@ -164,7 +164,7 @@ def num_children(self) -> int:
164164
def get_child_index(self, name: str) -> int:
165165
return -1
166166

167-
def get_child_at_index(self, index: int) -> SBValue:
167+
def get_child_at_index(self, index: int) -> Optional[SBValue]:
168168
return None
169169

170170
def update(self):
@@ -233,8 +233,6 @@ def resolve_msvc_template_arg(arg_name: str, target: SBTarget) -> SBType:
233233
return result.GetPointerType()
234234

235235
if arg_name.startswith("array$<"):
236-
arg_name = arg_name[7:-1].strip()
237-
238236
template_args = get_template_args(arg_name)
239237

240238
element_name = next(template_args)
@@ -425,7 +423,7 @@ def num_children(self) -> int:
425423
def get_child_index(self, name: str) -> int:
426424
return self.fields.get(name, -1)
427425

428-
def get_child_at_index(self, index: int) -> SBValue:
426+
def get_child_at_index(self, index: int) -> Optional[SBValue]:
429427
if self.is_variant:
430428
field = self.type.GetFieldAtIndex(index + 1)
431429
else:
@@ -470,7 +468,7 @@ def get_child_index(self, name: str) -> int:
470468

471469
return -1
472470

473-
def get_child_at_index(self, index: int) -> SBValue:
471+
def get_child_at_index(self, index: int) -> Optional[SBValue]:
474472
if not 0 <= index < self.length:
475473
return None
476474
start = self.data_ptr.GetValueAsUnsigned()
@@ -506,7 +504,7 @@ def get_child_index(self, name: str) -> int:
506504

507505
return -1
508506

509-
def get_child_at_index(self, index: int) -> SBValue:
507+
def get_child_at_index(self, index: int) -> Optional[SBValue]:
510508
if not 0 <= index < self.length:
511509
return None
512510
start = self.data_ptr.GetValueAsUnsigned()
@@ -562,7 +560,7 @@ def num_children(self) -> int:
562560
def get_child_index(self, name: str) -> int:
563561
return self.value.GetIndexOfChildWithName(name)
564562

565-
def get_child_at_index(self, index: int) -> SBValue:
563+
def get_child_at_index(self, index: int) -> Optional[SBValue]:
566564
return self.value.GetChildAtIndex(index)
567565

568566
def update(self):
@@ -768,7 +766,7 @@ def num_children(self) -> int:
768766
def get_child_index(self, name: str) -> int:
769767
return self.value.GetIndexOfChildWithName(name)
770768

771-
def get_child_at_index(self, index: int) -> SBValue:
769+
def get_child_at_index(self, index: int) -> Optional[SBValue]:
772770
return self.value.GetChildAtIndex(index)
773771

774772
def has_children(self) -> bool:
@@ -858,7 +856,7 @@ def get_child_index(self, name: str) -> int:
858856
else:
859857
return -1
860858

861-
def get_child_at_index(self, index: int) -> SBValue:
859+
def get_child_at_index(self, index: int) -> Optional[SBValue]:
862860
if self.is_variant:
863861
field = self.type.GetFieldAtIndex(index + 1)
864862
else:
@@ -887,7 +885,7 @@ def num_children(self) -> int:
887885
def get_child_index(self, name: str) -> int:
888886
return self.valobj.GetIndexOfChildWithName(name)
889887

890-
def get_child_at_index(self, index: int) -> SBValue:
888+
def get_child_at_index(self, index: int) -> Optional[SBValue]:
891889
child: SBValue = self.valobj.GetChildAtIndex(index)
892890
offset = self.valobj.GetType().GetFieldAtIndex(index).byte_offset
893891
return self.valobj.CreateChildAtOffset(str(index), offset, child.GetType())
@@ -935,7 +933,7 @@ def get_child_index(self, name: str) -> int:
935933
else:
936934
return -1
937935

938-
def get_child_at_index(self, index: int) -> SBValue:
936+
def get_child_at_index(self, index: int) -> Optional[SBValue]:
939937
start = self.data_ptr.GetValueAsUnsigned()
940938
address = start + index * self.element_type_size
941939
element = self.data_ptr.CreateValueFromAddress(
@@ -983,7 +981,7 @@ def get_child_index(self, name: str) -> int:
983981
else:
984982
return -1
985983

986-
def get_child_at_index(self, index: int) -> SBValue:
984+
def get_child_at_index(self, index: int) -> Optional[SBValue]:
987985
start = self.data_ptr.GetValueAsUnsigned()
988986
address = start + index * self.element_size
989987
element = self.data_ptr.CreateValueFromAddress(
@@ -1047,7 +1045,7 @@ def get_child_index(self, name: str) -> int:
10471045
else:
10481046
return -1
10491047

1050-
def get_child_at_index(self, index: int) -> SBValue:
1048+
def get_child_at_index(self, index: int) -> Optional[SBValue]:
10511049
start = self.data_ptr.GetValueAsUnsigned()
10521050
address = start + ((index + self.head) % self.cap) * self.element_type_size
10531051
element = self.data_ptr.CreateValueFromAddress(
@@ -1106,7 +1104,7 @@ def get_child_index(self, name: str) -> int:
11061104
else:
11071105
return -1
11081106

1109-
def get_child_at_index(self, index: int) -> SBValue:
1107+
def get_child_at_index(self, index: int) -> Optional[SBValue]:
11101108
# logger = Logger.Logger()
11111109
start = self.data_ptr.GetValueAsUnsigned() & ~1
11121110

@@ -1195,7 +1193,7 @@ def get_child_index(self, name: str) -> int:
11951193
else:
11961194
return -1
11971195

1198-
def get_child_at_index(self, index: int) -> SBValue:
1196+
def get_child_at_index(self, index: int) -> Optional[SBValue]:
11991197
pairs_start = self.data_ptr.GetValueAsUnsigned()
12001198
idx = self.valid_indices[index]
12011199
if self.new_layout:
@@ -1318,7 +1316,7 @@ def get_child_index(self, name: str) -> int:
13181316
return 2
13191317
return -1
13201318

1321-
def get_child_at_index(self, index: int) -> SBValue:
1319+
def get_child_at_index(self, index: int) -> Optional[SBValue]:
13221320
if index == 0:
13231321
return self.value
13241322
if index == 1:
@@ -1351,7 +1349,7 @@ def get_child_index(self, name: str) -> int:
13511349
return 0
13521350
return -1
13531351

1354-
def get_child_at_index(self, index: int) -> SBValue:
1352+
def get_child_at_index(self, index: int) -> Optional[SBValue]:
13551353
if index == 0:
13561354
return self.value
13571355
return None
@@ -1406,7 +1404,7 @@ def get_child_index(self, name: str) -> int:
14061404
return 1
14071405
return -1
14081406

1409-
def get_child_at_index(self, index: int) -> SBValue:
1407+
def get_child_at_index(self, index: int) -> Optional[SBValue]:
14101408
if index == 0:
14111409
return self.value
14121410
if index == 1:

src/etc/rust_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,4 @@ def classify_union(fields: List) -> RustType:
130130
assert len(fields) == 1
131131
return RustType.CompressedEnum
132132
else:
133-
return RustType.RegularEnum
133+
return RustType.Union

0 commit comments

Comments
 (0)