From 3242b4fa1b8be3e8c42234ece4571babadafceed Mon Sep 17 00:00:00 2001 From: Alona Enraght-Moony Date: Sun, 16 Apr 2023 23:16:52 +0000 Subject: [PATCH 1/7] rustdoc-json: Add tests for field ordering. --- tests/rustdoc-json/enums/field_order.rs | 40 +++++++++++++++++++++++ tests/rustdoc-json/structs/field_order.rs | 38 +++++++++++++++++++++ tests/rustdoc-json/unions/field_order.rs | 38 +++++++++++++++++++++ 3 files changed, 116 insertions(+) create mode 100644 tests/rustdoc-json/enums/field_order.rs create mode 100644 tests/rustdoc-json/structs/field_order.rs create mode 100644 tests/rustdoc-json/unions/field_order.rs diff --git a/tests/rustdoc-json/enums/field_order.rs b/tests/rustdoc-json/enums/field_order.rs new file mode 100644 index 0000000000000..c7316f75bc683 --- /dev/null +++ b/tests/rustdoc-json/enums/field_order.rs @@ -0,0 +1,40 @@ +// Check that the order of fields is preserved. + +pub enum Whatever { + Foo { + // Important: random prefixes are used here to ensure that + // sorting fields by name would cause this test to fail. + ews_0: i32, + dik_1: i32, + hsk_2: i32, + djt_3: i32, + jnr_4: i32, + dfs_5: i32, + bja_6: i32, + lyc_7: i32, + yqd_8: i32, + vll_9: i32, + }, +} + +// @set 0 = '$.index[*][?(@.name == "ews_0")].id' +// @set 1 = '$.index[*][?(@.name == "dik_1")].id' +// @set 2 = '$.index[*][?(@.name == "hsk_2")].id' +// @set 3 = '$.index[*][?(@.name == "djt_3")].id' +// @set 4 = '$.index[*][?(@.name == "jnr_4")].id' +// @set 5 = '$.index[*][?(@.name == "dfs_5")].id' +// @set 6 = '$.index[*][?(@.name == "bja_6")].id' +// @set 7 = '$.index[*][?(@.name == "lyc_7")].id' +// @set 8 = '$.index[*][?(@.name == "yqd_8")].id' +// @set 9 = '$.index[*][?(@.name == "vll_9")].id' + +// @is '$.index[*][?(@.name == "Foo")].inner.kind.struct.fields[0]' $0 +// @is '$.index[*][?(@.name == "Foo")].inner.kind.struct.fields[1]' $1 +// @is '$.index[*][?(@.name == "Foo")].inner.kind.struct.fields[2]' $2 +// @is '$.index[*][?(@.name == "Foo")].inner.kind.struct.fields[3]' $3 +// @is '$.index[*][?(@.name == "Foo")].inner.kind.struct.fields[4]' $4 +// @is '$.index[*][?(@.name == "Foo")].inner.kind.struct.fields[5]' $5 +// @is '$.index[*][?(@.name == "Foo")].inner.kind.struct.fields[6]' $6 +// @is '$.index[*][?(@.name == "Foo")].inner.kind.struct.fields[7]' $7 +// @is '$.index[*][?(@.name == "Foo")].inner.kind.struct.fields[8]' $8 +// @is '$.index[*][?(@.name == "Foo")].inner.kind.struct.fields[9]' $9 diff --git a/tests/rustdoc-json/structs/field_order.rs b/tests/rustdoc-json/structs/field_order.rs new file mode 100644 index 0000000000000..f36788ec9ad3a --- /dev/null +++ b/tests/rustdoc-json/structs/field_order.rs @@ -0,0 +1,38 @@ +// Check that the order of fields is preserved. + +pub struct Foo { + // Important: random prefixes are used here to ensure that + // sorting fields by name would cause this test to fail. + pub ews_0: i32, + pub dik_1: i32, + pub hsk_2: i32, + pub djt_3: i32, + pub jnr_4: i32, + pub dfs_5: i32, + pub bja_6: i32, + pub lyc_7: i32, + pub yqd_8: i32, + pub vll_9: i32, +} + +// @set 0 = '$.index[*][?(@.name == "ews_0")].id' +// @set 1 = '$.index[*][?(@.name == "dik_1")].id' +// @set 2 = '$.index[*][?(@.name == "hsk_2")].id' +// @set 3 = '$.index[*][?(@.name == "djt_3")].id' +// @set 4 = '$.index[*][?(@.name == "jnr_4")].id' +// @set 5 = '$.index[*][?(@.name == "dfs_5")].id' +// @set 6 = '$.index[*][?(@.name == "bja_6")].id' +// @set 7 = '$.index[*][?(@.name == "lyc_7")].id' +// @set 8 = '$.index[*][?(@.name == "yqd_8")].id' +// @set 9 = '$.index[*][?(@.name == "vll_9")].id' + +// @is '$.index[*][?(@.name == "Foo")].inner.kind.plain.fields[0]' $0 +// @is '$.index[*][?(@.name == "Foo")].inner.kind.plain.fields[1]' $1 +// @is '$.index[*][?(@.name == "Foo")].inner.kind.plain.fields[2]' $2 +// @is '$.index[*][?(@.name == "Foo")].inner.kind.plain.fields[3]' $3 +// @is '$.index[*][?(@.name == "Foo")].inner.kind.plain.fields[4]' $4 +// @is '$.index[*][?(@.name == "Foo")].inner.kind.plain.fields[5]' $5 +// @is '$.index[*][?(@.name == "Foo")].inner.kind.plain.fields[6]' $6 +// @is '$.index[*][?(@.name == "Foo")].inner.kind.plain.fields[7]' $7 +// @is '$.index[*][?(@.name == "Foo")].inner.kind.plain.fields[8]' $8 +// @is '$.index[*][?(@.name == "Foo")].inner.kind.plain.fields[9]' $9 diff --git a/tests/rustdoc-json/unions/field_order.rs b/tests/rustdoc-json/unions/field_order.rs new file mode 100644 index 0000000000000..d55d762e7b9cc --- /dev/null +++ b/tests/rustdoc-json/unions/field_order.rs @@ -0,0 +1,38 @@ +// Check that the order of fields is preserved. + +pub union Foo { + // Important: random prefixes are used here to ensure that + // sorting fields by name would cause this test to fail. + pub ews_0: i32, + pub dik_1: i32, + pub hsk_2: i32, + pub djt_3: i32, + pub jnr_4: i32, + pub dfs_5: i32, + pub bja_6: i32, + pub lyc_7: i32, + pub yqd_8: i32, + pub vll_9: i32, +} + +// @set 0 = '$.index[*][?(@.name == "ews_0")].id' +// @set 1 = '$.index[*][?(@.name == "dik_1")].id' +// @set 2 = '$.index[*][?(@.name == "hsk_2")].id' +// @set 3 = '$.index[*][?(@.name == "djt_3")].id' +// @set 4 = '$.index[*][?(@.name == "jnr_4")].id' +// @set 5 = '$.index[*][?(@.name == "dfs_5")].id' +// @set 6 = '$.index[*][?(@.name == "bja_6")].id' +// @set 7 = '$.index[*][?(@.name == "lyc_7")].id' +// @set 8 = '$.index[*][?(@.name == "yqd_8")].id' +// @set 9 = '$.index[*][?(@.name == "vll_9")].id' + +// @is '$.index[*][?(@.name == "Foo")].inner.fields[0]' $0 +// @is '$.index[*][?(@.name == "Foo")].inner.fields[1]' $1 +// @is '$.index[*][?(@.name == "Foo")].inner.fields[2]' $2 +// @is '$.index[*][?(@.name == "Foo")].inner.fields[3]' $3 +// @is '$.index[*][?(@.name == "Foo")].inner.fields[4]' $4 +// @is '$.index[*][?(@.name == "Foo")].inner.fields[5]' $5 +// @is '$.index[*][?(@.name == "Foo")].inner.fields[6]' $6 +// @is '$.index[*][?(@.name == "Foo")].inner.fields[7]' $7 +// @is '$.index[*][?(@.name == "Foo")].inner.fields[8]' $8 +// @is '$.index[*][?(@.name == "Foo")].inner.fields[9]' $9 From 006903ea61b72186c1596c7b3a9f5ad789ed918c Mon Sep 17 00:00:00 2001 From: Alona Enraght-Moony Date: Tue, 18 Apr 2023 15:15:50 +0000 Subject: [PATCH 2/7] rustdoc-json: Add tests for variant ordering. --- tests/rustdoc-json/enums/variant_order.rs | 38 +++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 tests/rustdoc-json/enums/variant_order.rs diff --git a/tests/rustdoc-json/enums/variant_order.rs b/tests/rustdoc-json/enums/variant_order.rs new file mode 100644 index 0000000000000..bec1f2241566a --- /dev/null +++ b/tests/rustdoc-json/enums/variant_order.rs @@ -0,0 +1,38 @@ +// Check that the order of variants is preserved. + +pub enum Foo { + // Important: random prefixes are used here to ensure that + // sorting fields by name would cause this test to fail. + Ews0, + Dik1, + Hsk2, + Djt3, + Jnr4, + Dfs5, + Bja6, + Lyc7, + Yqd8, + Vll9, +} + +// @set 0 = '$.index[*][?(@.name == "Ews0")].id' +// @set 1 = '$.index[*][?(@.name == "Dik1")].id' +// @set 2 = '$.index[*][?(@.name == "Hsk2")].id' +// @set 3 = '$.index[*][?(@.name == "Djt3")].id' +// @set 4 = '$.index[*][?(@.name == "Jnr4")].id' +// @set 5 = '$.index[*][?(@.name == "Dfs5")].id' +// @set 6 = '$.index[*][?(@.name == "Bja6")].id' +// @set 7 = '$.index[*][?(@.name == "Lyc7")].id' +// @set 8 = '$.index[*][?(@.name == "Yqd8")].id' +// @set 9 = '$.index[*][?(@.name == "Vll9")].id' + +// @is '$.index[*][?(@.name == "Foo")].inner.variants[0]' $0 +// @is '$.index[*][?(@.name == "Foo")].inner.variants[1]' $1 +// @is '$.index[*][?(@.name == "Foo")].inner.variants[2]' $2 +// @is '$.index[*][?(@.name == "Foo")].inner.variants[3]' $3 +// @is '$.index[*][?(@.name == "Foo")].inner.variants[4]' $4 +// @is '$.index[*][?(@.name == "Foo")].inner.variants[5]' $5 +// @is '$.index[*][?(@.name == "Foo")].inner.variants[6]' $6 +// @is '$.index[*][?(@.name == "Foo")].inner.variants[7]' $7 +// @is '$.index[*][?(@.name == "Foo")].inner.variants[8]' $8 +// @is '$.index[*][?(@.name == "Foo")].inner.variants[9]' $9 From 72dd53c8e52e3f6995cfa29a66dcde28a691beb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A9=E5=91=BD=E5=89=91=E4=B8=BB?= Date: Fri, 7 Jul 2023 17:44:48 +0800 Subject: [PATCH 3/7] add aarch64-unknown-teeos target MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 袁浩 --- .../src/spec/aarch64_unknown_teeos.rs | 16 +++ compiler/rustc_target/src/spec/mod.rs | 3 + compiler/rustc_target/src/spec/teeos_base.rs | 29 +++++ src/bootstrap/lib.rs | 2 +- src/doc/rustc/src/SUMMARY.md | 1 + src/doc/rustc/src/platform-support.md | 1 + .../platform-support/aarch64-unknown-teeos.md | 100 ++++++++++++++++++ tests/ui/check-cfg/values-target-json.stderr | 2 +- tests/ui/check-cfg/well-known-values.stderr | 2 +- 9 files changed, 153 insertions(+), 3 deletions(-) create mode 100644 compiler/rustc_target/src/spec/aarch64_unknown_teeos.rs create mode 100644 compiler/rustc_target/src/spec/teeos_base.rs create mode 100644 src/doc/rustc/src/platform-support/aarch64-unknown-teeos.md diff --git a/compiler/rustc_target/src/spec/aarch64_unknown_teeos.rs b/compiler/rustc_target/src/spec/aarch64_unknown_teeos.rs new file mode 100644 index 0000000000000..64a7dc681c896 --- /dev/null +++ b/compiler/rustc_target/src/spec/aarch64_unknown_teeos.rs @@ -0,0 +1,16 @@ +use crate::spec::Target; + +pub fn target() -> Target { + let mut base = super::teeos_base::opts(); + base.features = "+strict-align,+neon,+fp-armv8".into(); + base.max_atomic_width = Some(128); + base.linker = Some("aarch64-linux-gnu-ld".into()); + + Target { + llvm_target: "aarch64-unknown-none".into(), + pointer_width: 64, + data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".into(), + arch: "aarch64".into(), + options: base, + } +} diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index 7114c243ea14d..0229fa06e8531 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -83,6 +83,7 @@ mod openbsd_base; mod redox_base; mod solaris_base; mod solid_base; +mod teeos_base; mod thumb_base; mod uefi_msvc_base; mod unikraft_linux_musl_base; @@ -1492,6 +1493,8 @@ supported_targets! { ("x86_64-unknown-none", x86_64_unknown_none), + ("aarch64-unknown-teeos", aarch64_unknown_teeos), + ("mips64-openwrt-linux-musl", mips64_openwrt_linux_musl), ("aarch64-unknown-nto-qnx710", aarch64_unknown_nto_qnx_710), diff --git a/compiler/rustc_target/src/spec/teeos_base.rs b/compiler/rustc_target/src/spec/teeos_base.rs new file mode 100644 index 0000000000000..1bc71bab01605 --- /dev/null +++ b/compiler/rustc_target/src/spec/teeos_base.rs @@ -0,0 +1,29 @@ +use super::{Cc, LinkerFlavor, Lld, PanicStrategy}; +use crate::spec::{RelroLevel, TargetOptions}; + +pub fn opts() -> TargetOptions { + let lld_args = &["-zmax-page-size=4096", "-znow", "-ztext", "--execute-only"]; + let cc_args = &["-Wl,-zmax-page-size=4096", "-Wl,-znow", "-Wl,-ztext", "-mexecute-only"]; + + let mut pre_link_args = TargetOptions::link_args(LinkerFlavor::Gnu(Cc::No, Lld::No), lld_args); + super::add_link_args(&mut pre_link_args, LinkerFlavor::Gnu(Cc::Yes, Lld::No), cc_args); + + TargetOptions { + os: "teeos".into(), + vendor: "unknown".into(), + dynamic_linking: true, + linker_flavor: LinkerFlavor::Gnu(Cc::Yes, Lld::No), + // rpath hardcodes -Wl, so it can't be used together with ld.lld. + // C TAs also don't support rpath, so this is fine. + has_rpath: false, + // Note: Setting has_thread_local to true causes an error when + // loading / dyn-linking the TA + has_thread_local: false, + position_independent_executables: true, + relro_level: RelroLevel::Full, + crt_static_respected: true, + pre_link_args, + panic_strategy: PanicStrategy::Abort, + ..Default::default() + } +} diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index 365deb8e155df..a00db502e0807 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -134,7 +134,7 @@ const EXTRA_CHECK_CFGS: &[(Option, &'static str, Option<&[&'static str]>)] // #[cfg(bootstrap)] (Some(Mode::Std), "target_vendor", Some(&["unikraft"])), (Some(Mode::Std), "target_env", Some(&["libnx"])), - // (Some(Mode::Std), "target_os", Some(&[])), + (Some(Mode::Std), "target_os", Some(&["teeos"])), // #[cfg(bootstrap)] mips32r6, mips64r6 ( Some(Mode::Std), diff --git a/src/doc/rustc/src/SUMMARY.md b/src/doc/rustc/src/SUMMARY.md index f108831138d85..00c6ca133347b 100644 --- a/src/doc/rustc/src/SUMMARY.md +++ b/src/doc/rustc/src/SUMMARY.md @@ -28,6 +28,7 @@ - [armv7-unknown-linux-uclibceabihf](platform-support/armv7-unknown-linux-uclibceabihf.md) - [\*-android and \*-androideabi](platform-support/android.md) - [\*-linux-ohos](platform-support/openharmony.md) + - [aarch64-unknown-teeos](platform-support/aarch64-unknown-teeos.md) - [\*-esp-espidf](platform-support/esp-idf.md) - [\*-unknown-fuchsia](platform-support/fuchsia.md) - [\*-kmc-solid_\*](platform-support/kmc-solid.md) diff --git a/src/doc/rustc/src/platform-support.md b/src/doc/rustc/src/platform-support.md index 8c5dc11eeef37..72c3f15388443 100644 --- a/src/doc/rustc/src/platform-support.md +++ b/src/doc/rustc/src/platform-support.md @@ -221,6 +221,7 @@ target | std | host | notes [`aarch64-nintendo-switch-freestanding`](platform-support/aarch64-nintendo-switch-freestanding.md) | * | | ARM64 Nintendo Switch, Horizon [`aarch64-pc-windows-gnullvm`](platform-support/pc-windows-gnullvm.md) | ✓ | ✓ | [`aarch64-unknown-linux-ohos`](platform-support/openharmony.md) | ✓ | | ARM64 OpenHarmony | +[`aarch64-unknown-teeos`](platform-support/aarch64-unknown-teeos.md) | ? | | ARM64 TEEOS | [`aarch64-unknown-nto-qnx710`](platform-support/nto-qnx.md) | ✓ | | ARM64 QNX Neutrino 7.1 RTOS | `aarch64-unknown-freebsd` | ✓ | ✓ | ARM64 FreeBSD [`aarch64-unknown-hermit`](platform-support/hermit.md) | ✓ | | ARM64 Hermit diff --git a/src/doc/rustc/src/platform-support/aarch64-unknown-teeos.md b/src/doc/rustc/src/platform-support/aarch64-unknown-teeos.md new file mode 100644 index 0000000000000..8fc5e6dd92b42 --- /dev/null +++ b/src/doc/rustc/src/platform-support/aarch64-unknown-teeos.md @@ -0,0 +1,100 @@ +# `aarch64-unknown-teeos` + +**Tier: 3** + +Target for the TEEOS operating system. + +TEEOS is a mini os run in TrustZone, for trusted/security apps. The kernel of TEEOS is HongMeng/ChCore micro kernel. The libc for TEEOS is a part of musl. +It's very small that there is no RwLock, no network, no stdin, and no file system for apps in TEEOS. + +Some abbreviation: +| Abbreviation | The full text | Description | +| ---- | ---- | ---- | +| TEE | Trusted Execution Environment | ARM TrustZone devide the system into two worlds/modes -- the secure world/mode and the normal world/mode. TEE is in the secure world/mode. | +| REE | Rich Execution Environment | The normal world. for example, Linux for Android phone is in REE side. | +| TA | Trusted Application | The app run in TEE side system. | +| CA | Client Application | The progress run in REE side system. | + +TEEOS is open source in progress. [MORE about](https://gitee.com/opentrustee-group) + +## Target maintainers + +- Petrochenkov Vadim +- Sword-Destiny + +## Setup +We use OpenHarmony SDK for TEEOS. + +The OpenHarmony SDK doesn't currently support Rust compilation directly, so +some setup is required. + +First, you must obtain the OpenHarmony SDK from [this page](https://gitee.com/openharmony/docs/tree/master/en/release-notes). +Select the version of OpenHarmony you are developing for and download the "Public SDK package for the standard system". + +Create the following shell scripts that wrap Clang from the OpenHarmony SDK: + +`aarch64-unknown-teeos-clang.sh` + +```sh +#!/bin/sh +exec /path/to/ohos-sdk/linux/native/llvm/bin/clang \ + --target aarch64-linux-gnu \ + "$@" +``` + +`aarch64-unknown-teeos-clang++.sh` + +```sh +#!/bin/sh +exec /path/to/ohos-sdk/linux/native/llvm/bin/clang++ \ + --target aarch64-linux-gnu \ + "$@" +``` + +## Building the target + +To build a rust toolchain, create a `config.toml` with the following contents: + +```toml +profile = "compiler" +changelog-seen = 2 + +[build] +sanitizers = true +profiler = true +target = ["x86_64-unknown-linux-gnu", "aarch64-unknown-teeos"] +submodules = false +compiler-docs = false +extended = true + +[install] +bindir = "bin" +libdir = "lib" + +[target.aarch64-unknown-teeos] +cc = "/path/to/scripts/aarch64-unknown-teeos-clang.sh" +cxx = "/path/to/scripts/aarch64-unknown-teeos-clang.sh" +linker = "/path/to/scripts/aarch64-unknown-teeos-clang.sh" +ar = "/path/to/ohos-sdk/linux/native/llvm/bin/llvm-ar" +ranlib = "/path/to/ohos-sdk/linux/native/llvm/bin/llvm-ranlib" +llvm-config = "/path/to/ohos-sdk/linux/native/llvm/bin/llvm-config" +``` + +## Building Rust programs + +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. + +You will need to configure the linker to use in `~/.cargo/config`: +```toml +[target.aarch64-unknown-teeos] +linker = "/path/to/aarch64-unknown-teeos-clang.sh" +``` + +## Testing + +Running the Rust testsuite is not possible now. + +More information about how to test CA/TA. [See here](https://gitee.com/openharmony-sig/tee_tee_dev_kit/tree/master/docs) diff --git a/tests/ui/check-cfg/values-target-json.stderr b/tests/ui/check-cfg/values-target-json.stderr index eb81535e3edb0..e773d5d83ccfa 100644 --- a/tests/ui/check-cfg/values-target-json.stderr +++ b/tests/ui/check-cfg/values-target-json.stderr @@ -6,7 +6,7 @@ LL | #[cfg(target_os = "linuz")] | | | help: there is a expected value with a similar name: `"linux"` | - = note: expected values for `target_os` are: `aix`, `android`, `cuda`, `dragonfly`, `emscripten`, `ericos`, `espidf`, `freebsd`, `fuchsia`, `haiku`, `hermit`, `horizon`, `illumos`, `ios`, `l4re`, `linux`, `macos`, `netbsd`, `none`, `nto`, `openbsd`, `psp`, `redox`, `solaris`, `solid_asp3`, `tvos`, `uefi`, `unknown`, `vita`, `vxworks`, `wasi`, `watchos`, `windows`, `xous` + = note: expected values for `target_os` are: `aix`, `android`, `cuda`, `dragonfly`, `emscripten`, `ericos`, `espidf`, `freebsd`, `fuchsia`, `haiku`, `hermit`, `horizon`, `illumos`, `ios`, `l4re`, `linux`, `macos`, `netbsd`, `none`, `nto`, `openbsd`, `psp`, `redox`, `solaris`, `solid_asp3`, `teeos`, `tvos`, `uefi`, `unknown`, `vita`, `vxworks`, `wasi`, `watchos`, `windows`, `xous` = note: `#[warn(unexpected_cfgs)]` on by default warning: 1 warning emitted diff --git a/tests/ui/check-cfg/well-known-values.stderr b/tests/ui/check-cfg/well-known-values.stderr index 2d18cb82e037a..1f7758146563f 100644 --- a/tests/ui/check-cfg/well-known-values.stderr +++ b/tests/ui/check-cfg/well-known-values.stderr @@ -6,7 +6,7 @@ LL | #[cfg(target_os = "linuz")] | | | help: there is a expected value with a similar name: `"linux"` | - = note: expected values for `target_os` are: `aix`, `android`, `cuda`, `dragonfly`, `emscripten`, `espidf`, `freebsd`, `fuchsia`, `haiku`, `hermit`, `horizon`, `illumos`, `ios`, `l4re`, `linux`, `macos`, `netbsd`, `none`, `nto`, `openbsd`, `psp`, `redox`, `solaris`, `solid_asp3`, `tvos`, `uefi`, `unknown`, `vita`, `vxworks`, `wasi`, `watchos`, `windows`, `xous` + = note: expected values for `target_os` are: `aix`, `android`, `cuda`, `dragonfly`, `emscripten`, `espidf`, `freebsd`, `fuchsia`, `haiku`, `hermit`, `horizon`, `illumos`, `ios`, `l4re`, `linux`, `macos`, `netbsd`, `none`, `nto`, `openbsd`, `psp`, `redox`, `solaris`, `solid_asp3`, `teeos`, `tvos`, `uefi`, `unknown`, `vita`, `vxworks`, `wasi`, `watchos`, `windows`, `xous` = note: `#[warn(unexpected_cfgs)]` on by default warning: unexpected `cfg` condition value From 1ca4bc966ec5215a8daacf584d337f75322c0e9a Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Sun, 6 Aug 2023 14:00:12 +0000 Subject: [PATCH 4/7] Migrate a trait selection error to use diagnostic translation --- compiler/rustc_middle/src/ty/closure.rs | 19 ++++++- compiler/rustc_middle/src/ty/print/pretty.rs | 6 +-- compiler/rustc_trait_selection/messages.ftl | 9 ++++ compiler/rustc_trait_selection/src/errors.rs | 36 ++++++++++++- .../src/traits/error_reporting/mod.rs | 50 +++++++------------ 5 files changed, 79 insertions(+), 41 deletions(-) diff --git a/compiler/rustc_middle/src/ty/closure.rs b/compiler/rustc_middle/src/ty/closure.rs index 2e5c6a4457900..74bdd07a1c946 100644 --- a/compiler/rustc_middle/src/ty/closure.rs +++ b/compiler/rustc_middle/src/ty/closure.rs @@ -7,6 +7,7 @@ use std::fmt::Write; use crate::query::Providers; use rustc_data_structures::fx::FxIndexMap; +use rustc_errors::{DiagnosticArgValue, IntoDiagnosticArg}; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::{self as hir, LangItem}; use rustc_span::def_id::LocalDefIdMap; @@ -89,10 +90,18 @@ pub enum ClosureKind { FnOnce, } -impl<'tcx> ClosureKind { +impl ClosureKind { /// This is the initial value used when doing upvar inference. pub const LATTICE_BOTTOM: ClosureKind = ClosureKind::Fn; + pub const fn as_str(self) -> &'static str { + match self { + ClosureKind::Fn => "Fn", + ClosureKind::FnMut => "FnMut", + ClosureKind::FnOnce => "FnOnce", + } + } + /// Returns `true` if a type that impls this closure kind /// must also implement `other`. pub fn extends(self, other: ty::ClosureKind) -> bool { @@ -115,7 +124,7 @@ impl<'tcx> ClosureKind { /// Returns the representative scalar type for this closure kind. /// See `Ty::to_opt_closure_kind` for more details. - pub fn to_ty(self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> { + pub fn to_ty<'tcx>(self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> { match self { ClosureKind::Fn => tcx.types.i8, ClosureKind::FnMut => tcx.types.i16, @@ -124,6 +133,12 @@ impl<'tcx> ClosureKind { } } +impl IntoDiagnosticArg for ClosureKind { + fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + DiagnosticArgValue::Str(self.as_str().into()) + } +} + /// A composite describing a `Place` that is captured by a closure. #[derive(PartialEq, Clone, Debug, TyEncodable, TyDecodable, HashStable)] #[derive(TypeFoldable, TypeVisitable)] diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index d3fd49150ba2a..0c90e223a84c4 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -2870,11 +2870,7 @@ define_print_and_forward_display! { } ty::ClosureKind { - match *self { - ty::ClosureKind::Fn => p!("Fn"), - ty::ClosureKind::FnMut => p!("FnMut"), - ty::ClosureKind::FnOnce => p!("FnOnce"), - } + p!(write("{}", self.as_str())) } ty::Predicate<'tcx> { diff --git a/compiler/rustc_trait_selection/messages.ftl b/compiler/rustc_trait_selection/messages.ftl index f57f1bad15dca..f4c9dfa34882e 100644 --- a/compiler/rustc_trait_selection/messages.ftl +++ b/compiler/rustc_trait_selection/messages.ftl @@ -8,6 +8,15 @@ trait_selection_adjust_signature_remove_borrow = consider adjusting the signatur *[other] arguments } +trait_selection_closure_fn_mut_label = closure is `FnMut` because it mutates the variable `{$place}` here + +trait_selection_closure_fn_once_label = closure is `FnOnce` because it moves the variable `{$place}` out of its environment + +trait_selection_closure_kind_mismatch = expected a closure that implements the `{$expected}` trait, but this closure only implements `{$found}` + .label = this closure implements `{$found}`, not `{$expected}` + +trait_selection_closure_kind_requirement = the requirement to implement `{$expected}` derives from here + trait_selection_dump_vtable_entries = vtable entries for `{$trait_ref}`: {$entries} trait_selection_empty_on_clause_in_rustc_on_unimplemented = empty `on`-clause in `#[rustc_on_unimplemented]` diff --git a/compiler/rustc_trait_selection/src/errors.rs b/compiler/rustc_trait_selection/src/errors.rs index dde9e9c9ac694..c1fb287d63efa 100644 --- a/compiler/rustc_trait_selection/src/errors.rs +++ b/compiler/rustc_trait_selection/src/errors.rs @@ -4,7 +4,7 @@ use rustc_errors::{ SubdiagnosticMessage, }; use rustc_macros::Diagnostic; -use rustc_middle::ty::{self, PolyTraitRef, Ty}; +use rustc_middle::ty::{self, ClosureKind, PolyTraitRef, Ty}; use rustc_span::{Span, Symbol}; #[derive(Diagnostic)] @@ -131,3 +131,37 @@ impl AddToDiagnostic for AdjustSignatureBorrow { } } } + +#[derive(Diagnostic)] +#[diag(trait_selection_closure_kind_mismatch, code = "E0525")] +pub struct ClosureKindMismatch { + #[primary_span] + #[label] + pub closure_span: Span, + pub expected: ClosureKind, + pub found: ClosureKind, + #[label(trait_selection_closure_kind_requirement)] + pub cause_span: Span, + + #[subdiagnostic] + pub fn_once_label: Option, + + #[subdiagnostic] + pub fn_mut_label: Option, +} + +#[derive(Subdiagnostic)] +#[label(trait_selection_closure_fn_once_label)] +pub struct ClosureFnOnceLabel { + #[primary_span] + pub span: Span, + pub place: String, +} + +#[derive(Subdiagnostic)] +#[label(trait_selection_closure_fn_mut_label)] +pub struct ClosureFnMutLabel { + #[primary_span] + pub span: Span, + pub place: String, +} diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index 4d85e2b60893e..071d545251d80 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -7,6 +7,7 @@ use super::{ ObligationCauseCode, ObligationCtxt, OutputTypeParameterMismatch, Overflow, PredicateObligation, SelectionError, TraitNotObjectSafe, }; +use crate::errors::{ClosureFnMutLabel, ClosureFnOnceLabel, ClosureKindMismatch}; use crate::infer::error_reporting::{TyCategory, TypeAnnotationNeeded as ErrorCode}; use crate::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use crate::infer::{self, InferCtxt}; @@ -3142,24 +3143,15 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { kind: ty::ClosureKind, ) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> { let closure_span = self.tcx.def_span(closure_def_id); - let mut err = struct_span_err!( - self.tcx.sess, - closure_span, - E0525, - "expected a closure that implements the `{}` trait, \ - but this closure only implements `{}`", - kind, - found_kind - ); - err.span_label( + let mut err = ClosureKindMismatch { closure_span, - format!("this closure implements `{found_kind}`, not `{kind}`"), - ); - err.span_label( - obligation.cause.span, - format!("the requirement to implement `{kind}` derives from here"), - ); + expected: kind, + found: found_kind, + cause_span: obligation.cause.span, + fn_once_label: None, + fn_mut_label: None, + }; // Additional context information explaining why the closure only implements // a particular trait. @@ -3167,30 +3159,22 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { let hir_id = self.tcx.hir().local_def_id_to_hir_id(closure_def_id.expect_local()); match (found_kind, typeck_results.closure_kind_origins().get(hir_id)) { (ty::ClosureKind::FnOnce, Some((span, place))) => { - err.span_label( - *span, - format!( - "closure is `FnOnce` because it moves the \ - variable `{}` out of its environment", - ty::place_to_string_for_capture(self.tcx, place) - ), - ); + err.fn_once_label = Some(ClosureFnOnceLabel { + span: *span, + place: ty::place_to_string_for_capture(self.tcx, &place), + }) } (ty::ClosureKind::FnMut, Some((span, place))) => { - err.span_label( - *span, - format!( - "closure is `FnMut` because it mutates the \ - variable `{}` here", - ty::place_to_string_for_capture(self.tcx, place) - ), - ); + err.fn_mut_label = Some(ClosureFnMutLabel { + span: *span, + place: ty::place_to_string_for_capture(self.tcx, &place), + }) } _ => {} } } - err + self.tcx.sess.create_err(err) } fn report_type_parameter_mismatch_cyclic_type_error( From 078b942fef1a8a699ae3a276d7d9695e46025f7e Mon Sep 17 00:00:00 2001 From: bohan Date: Tue, 8 Aug 2023 14:20:22 +0800 Subject: [PATCH 5/7] fix: not insert missing lifetime for `ConstParamTy` --- compiler/rustc_resolve/src/late/diagnostics.rs | 6 ++++-- .../const-generics/lifetime-in-const-param.rs | 9 +++++++++ .../lifetime-in-const-param.stderr | 18 ++++++++++++++++++ .../lifetimes/unusual-rib-combinations.stderr | 5 ----- 4 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 tests/ui/const-generics/lifetime-in-const-param.rs create mode 100644 tests/ui/const-generics/lifetime-in-const-param.stderr diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index ba9bbbb14634c..c34b7df9b4603 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -2404,7 +2404,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> { should_continue = suggest(err, false, span, message, sugg); } } - LifetimeRibKind::Item => break, + LifetimeRibKind::Item | LifetimeRibKind::ConstParamTy => break, _ => {} } if !should_continue { @@ -2510,7 +2510,9 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> { .lifetime_ribs .iter() .rev() - .take_while(|rib| !matches!(rib.kind, LifetimeRibKind::Item)) + .take_while(|rib| { + !matches!(rib.kind, LifetimeRibKind::Item | LifetimeRibKind::ConstParamTy) + }) .flat_map(|rib| rib.bindings.iter()) .map(|(&ident, &res)| (ident, res)) .filter(|(ident, _)| ident.name != kw::UnderscoreLifetime) diff --git a/tests/ui/const-generics/lifetime-in-const-param.rs b/tests/ui/const-generics/lifetime-in-const-param.rs new file mode 100644 index 0000000000000..be90dbb213eef --- /dev/null +++ b/tests/ui/const-generics/lifetime-in-const-param.rs @@ -0,0 +1,9 @@ +// https://github.com/rust-lang/rust/issues/113462 + +struct S2<'b>(&'b ()); + +struct S<'a, const N: S2>(&'a ()); +//~^ ERROR missing lifetime specifier [E0106] +//~| ERROR `S2<'_>` is forbidden as the type of a const generic parameter + +fn main() {} diff --git a/tests/ui/const-generics/lifetime-in-const-param.stderr b/tests/ui/const-generics/lifetime-in-const-param.stderr new file mode 100644 index 0000000000000..8fd9068e8efd2 --- /dev/null +++ b/tests/ui/const-generics/lifetime-in-const-param.stderr @@ -0,0 +1,18 @@ +error[E0106]: missing lifetime specifier + --> $DIR/lifetime-in-const-param.rs:5:23 + | +LL | struct S<'a, const N: S2>(&'a ()); + | ^^ expected named lifetime parameter + +error: `S2<'_>` is forbidden as the type of a const generic parameter + --> $DIR/lifetime-in-const-param.rs:5:23 + | +LL | struct S<'a, const N: S2>(&'a ()); + | ^^ + | + = note: the only supported types are integers, `bool` and `char` + = help: more complex types are supported with `#![feature(adt_const_params)]` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0106`. diff --git a/tests/ui/lifetimes/unusual-rib-combinations.stderr b/tests/ui/lifetimes/unusual-rib-combinations.stderr index 4994e4dc444ee..01ec69a6110fa 100644 --- a/tests/ui/lifetimes/unusual-rib-combinations.stderr +++ b/tests/ui/lifetimes/unusual-rib-combinations.stderr @@ -3,11 +3,6 @@ error[E0106]: missing lifetime specifier | LL | fn d() {} | ^ expected named lifetime parameter - | -help: consider introducing a named lifetime parameter - | -LL | fn d<'a, const C: S<'a>>() {} - | +++ ++++ error[E0770]: the type of const parameters must not depend on other generic parameters --> $DIR/unusual-rib-combinations.rs:29:22 From da00356e5570e66dc90e6f403345bbbab255b95a Mon Sep 17 00:00:00 2001 From: Pietro Albini Date: Tue, 8 Aug 2023 10:19:21 +0200 Subject: [PATCH 6/7] prevent constant rebuilds of rustc-main (and thus everything else) --- src/bootstrap/compile.rs | 37 +++++++++++++++++++++++++++++-------- src/bootstrap/llvm.rs | 20 +++++++------------- 2 files changed, 36 insertions(+), 21 deletions(-) diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index 2c63ec80c3e58..62c7b96b5be94 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -31,6 +31,7 @@ use crate::util::get_clang_cl_resource_dir; use crate::util::{exe, is_debug_info, is_dylib, output, symlink_dir, t, up_to_date}; use crate::LLVM_TOOLS; use crate::{CLang, Compiler, DependencyType, GitRepo, Mode}; +use filetime::FileTime; #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct Std { @@ -904,19 +905,12 @@ impl Step for Rustc { // our LLVM wrapper. Unless we're explicitly requesting `librustc_driver` to be built with // debuginfo (via the debuginfo level of the executables using it): strip this debuginfo // away after the fact. - // FIXME: to make things simpler for now, limit this to the host and target where we know - // `strip -g` is both available and will fix the issue, i.e. on a x64 linux host that is not - // cross-compiling. Expand this to other appropriate targets in the future. if builder.config.rust_debuginfo_level_rustc == DebuginfoLevel::None && builder.config.rust_debuginfo_level_tools == DebuginfoLevel::None - && target == "x86_64-unknown-linux-gnu" - && target == builder.config.build { let target_root_dir = stamp.parent().unwrap(); let rustc_driver = target_root_dir.join("librustc_driver.so"); - if rustc_driver.exists() { - output(Command::new("strip").arg("--strip-debug").arg(rustc_driver)); - } + strip_debug(builder, target, &rustc_driver); } builder.ensure(RustcLink::from_rustc( @@ -1974,3 +1968,30 @@ pub enum CargoMessage<'a> { success: bool, }, } + +pub fn strip_debug(builder: &Builder<'_>, target: TargetSelection, path: &Path) { + // FIXME: to make things simpler for now, limit this to the host and target where we know + // `strip -g` is both available and will fix the issue, i.e. on a x64 linux host that is not + // cross-compiling. Expand this to other appropriate targets in the future. + if target != "x86_64-unknown-linux-gnu" || target != builder.config.build || !path.exists() { + return; + } + + let previous_mtime = FileTime::from_last_modification_time(&path.metadata().unwrap()); + // Note: `output` will propagate any errors here. + output(Command::new("strip").arg("--strip-debug").arg(path)); + + // After running `strip`, we have to set the file modification time to what it was before, + // otherwise we risk Cargo invalidating its fingerprint and rebuilding the world next time + // bootstrap is invoked. + // + // An example of this is if we run this on librustc_driver.so. In the first invocation: + // - Cargo will build librustc_driver.so (mtime of 1) + // - Cargo will build rustc-main (mtime of 2) + // - Bootstrap will strip librustc_driver.so (changing the mtime to 3). + // + // In the second invocation of bootstrap, Cargo will see that the mtime of librustc_driver.so + // is greater than the mtime of rustc-main, and will rebuild rustc-main. That will then cause + // everything else (standard library, future stages...) to be rebuilt. + t!(filetime::set_file_mtime(path, previous_mtime)); +} diff --git a/src/bootstrap/llvm.rs b/src/bootstrap/llvm.rs index 14ee5659ed563..4943f93fa9a01 100644 --- a/src/bootstrap/llvm.rs +++ b/src/bootstrap/llvm.rs @@ -512,27 +512,21 @@ impl Step for Llvm { // When building LLVM as a shared library on linux, it can contain unexpected debuginfo: // some can come from the C++ standard library. Unless we're explicitly requesting LLVM to // be built with debuginfo, strip it away after the fact, to make dist artifacts smaller. - // FIXME: to make things simpler for now, limit this to the host and target where we know - // `strip -g` is both available and will fix the issue, i.e. on a x64 linux host that is not - // cross-compiling. Expand this to other appropriate targets in the future. if builder.llvm_link_shared() && builder.config.llvm_optimize && !builder.config.llvm_release_debuginfo - && target == "x86_64-unknown-linux-gnu" - && target == builder.config.build { // Find the name of the LLVM shared library that we just built. let lib_name = find_llvm_lib_name("so"); // If the shared library exists in LLVM's `/build/lib/` or `/lib/` folders, strip its - // debuginfo. Note: `output` will propagate any errors here. - let strip_if_possible = |path: PathBuf| { - if path.exists() { - output(Command::new("strip").arg("--strip-debug").arg(path)); - } - }; - strip_if_possible(out_dir.join("lib").join(&lib_name)); - strip_if_possible(out_dir.join("build").join("lib").join(&lib_name)); + // debuginfo. + crate::compile::strip_debug(builder, target, &out_dir.join("lib").join(&lib_name)); + crate::compile::strip_debug( + builder, + target, + &out_dir.join("build").join("lib").join(&lib_name), + ); } t!(stamp.write()); From bcf7bfc9f4b6fb01cf36d7a3834cbd60a70f660a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Tue, 8 Aug 2023 07:12:15 +0000 Subject: [PATCH 7/7] remove llvm-wrapper include to silence deprecation warning Includes of `include/llvm/Support/Host.h` now emit a deprecated warning: `warning: This header is deprecated, please use llvm/TargetParser/Host.h`. --- compiler/rustc_llvm/llvm-wrapper/LLVMWrapper.h | 1 - compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp | 1 - 2 files changed, 2 deletions(-) diff --git a/compiler/rustc_llvm/llvm-wrapper/LLVMWrapper.h b/compiler/rustc_llvm/llvm-wrapper/LLVMWrapper.h index ea04546284523..3f2bf2c9b444d 100644 --- a/compiler/rustc_llvm/llvm-wrapper/LLVMWrapper.h +++ b/compiler/rustc_llvm/llvm-wrapper/LLVMWrapper.h @@ -15,7 +15,6 @@ #include "llvm/Support/DynamicLibrary.h" #include "llvm/Support/FormattedStream.h" #include "llvm/Support/JSON.h" -#include "llvm/Support/Host.h" #include "llvm/Support/Memory.h" #include "llvm/Support/SourceMgr.h" #include "llvm/Support/TargetSelect.h" diff --git a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp index 48b5fd6e283be..69580c0f76e5a 100644 --- a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp +++ b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp @@ -25,7 +25,6 @@ #if LLVM_VERSION_GE(17, 0) #include "llvm/Support/VirtualFileSystem.h" #endif -#include "llvm/Support/Host.h" #include "llvm/Target/TargetMachine.h" #include "llvm/Transforms/IPO/AlwaysInliner.h" #include "llvm/Transforms/IPO/FunctionImport.h"