special case TyAndLayout
debug impl
This commit is contained in:
parent
06a76ab415
commit
71cab64079
@ -2,6 +2,7 @@
|
|||||||
use crate::abi::{HasDataLayout, TyAbiInterface, TyAndLayout};
|
use crate::abi::{HasDataLayout, TyAbiInterface, TyAndLayout};
|
||||||
use crate::spec::{self, HasTargetSpec};
|
use crate::spec::{self, HasTargetSpec};
|
||||||
use rustc_span::Symbol;
|
use rustc_span::Symbol;
|
||||||
|
use std::fmt;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
mod aarch64;
|
mod aarch64;
|
||||||
@ -515,12 +516,20 @@ pub fn homogeneous_aggregate<C>(&self, cx: &C) -> Result<HomogeneousAggregate, H
|
|||||||
|
|
||||||
/// Information about how to pass an argument to,
|
/// Information about how to pass an argument to,
|
||||||
/// or return a value from, a function, under some ABI.
|
/// or return a value from, a function, under some ABI.
|
||||||
#[derive(Clone, PartialEq, Eq, Hash, Debug, HashStable_Generic)]
|
#[derive(Clone, PartialEq, Eq, Hash, HashStable_Generic)]
|
||||||
pub struct ArgAbi<'a, Ty> {
|
pub struct ArgAbi<'a, Ty> {
|
||||||
pub layout: TyAndLayout<'a, Ty>,
|
pub layout: TyAndLayout<'a, Ty>,
|
||||||
pub mode: PassMode,
|
pub mode: PassMode,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Needs to be a custom impl because of the bounds on the `TyAndLayout` debug impl.
|
||||||
|
impl<'a, Ty: fmt::Display> fmt::Debug for ArgAbi<'a, Ty> {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
let ArgAbi { layout, mode } = self;
|
||||||
|
f.debug_struct("ArgAbi").field("layout", layout).field("mode", mode).finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a, Ty> ArgAbi<'a, Ty> {
|
impl<'a, Ty> ArgAbi<'a, Ty> {
|
||||||
/// This defines the "default ABI" for that type, that is then later adjusted in `fn_abi_adjust_for_abi`.
|
/// This defines the "default ABI" for that type, that is then later adjusted in `fn_abi_adjust_for_abi`.
|
||||||
pub fn new(
|
pub fn new(
|
||||||
@ -694,7 +703,7 @@ pub fn as_str(&self) -> &'static str {
|
|||||||
///
|
///
|
||||||
/// I will do my best to describe this structure, but these
|
/// I will do my best to describe this structure, but these
|
||||||
/// comments are reverse-engineered and may be inaccurate. -NDM
|
/// comments are reverse-engineered and may be inaccurate. -NDM
|
||||||
#[derive(Clone, PartialEq, Eq, Hash, Debug, HashStable_Generic)]
|
#[derive(Clone, PartialEq, Eq, Hash, HashStable_Generic)]
|
||||||
pub struct FnAbi<'a, Ty> {
|
pub struct FnAbi<'a, Ty> {
|
||||||
/// The LLVM types of each argument.
|
/// The LLVM types of each argument.
|
||||||
pub args: Box<[ArgAbi<'a, Ty>]>,
|
pub args: Box<[ArgAbi<'a, Ty>]>,
|
||||||
@ -715,6 +724,21 @@ pub struct FnAbi<'a, Ty> {
|
|||||||
pub can_unwind: bool,
|
pub can_unwind: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Needs to be a custom impl because of the bounds on the `TyAndLayout` debug impl.
|
||||||
|
impl<'a, Ty: fmt::Display> fmt::Debug for FnAbi<'a, Ty> {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
let FnAbi { args, ret, c_variadic, fixed_count, conv, can_unwind } = self;
|
||||||
|
f.debug_struct("FnAbi")
|
||||||
|
.field("args", args)
|
||||||
|
.field("ret", ret)
|
||||||
|
.field("c_variadic", c_variadic)
|
||||||
|
.field("fixed_count", fixed_count)
|
||||||
|
.field("conv", conv)
|
||||||
|
.field("can_unwind", can_unwind)
|
||||||
|
.finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Error produced by attempting to adjust a `FnAbi`, for a "foreign" ABI.
|
/// Error produced by attempting to adjust a `FnAbi`, for a "foreign" ABI.
|
||||||
#[derive(Copy, Clone, Debug, HashStable_Generic)]
|
#[derive(Copy, Clone, Debug, HashStable_Generic)]
|
||||||
pub enum AdjustForForeignAbiError {
|
pub enum AdjustForForeignAbiError {
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
use crate::json::{Json, ToJson};
|
use crate::json::{Json, ToJson};
|
||||||
|
|
||||||
|
use std::fmt;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
|
||||||
use rustc_macros::HashStable_Generic;
|
use rustc_macros::HashStable_Generic;
|
||||||
@ -24,12 +25,22 @@ fn to_json(&self) -> Json {
|
|||||||
/// to that obtained from `layout_of(ty)`, as we need to produce
|
/// to that obtained from `layout_of(ty)`, as we need to produce
|
||||||
/// layouts for which Rust types do not exist, such as enum variants
|
/// layouts for which Rust types do not exist, such as enum variants
|
||||||
/// or synthetic fields of enums (i.e., discriminants) and fat pointers.
|
/// or synthetic fields of enums (i.e., discriminants) and fat pointers.
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, HashStable_Generic)]
|
#[derive(Copy, Clone, PartialEq, Eq, Hash, HashStable_Generic)]
|
||||||
pub struct TyAndLayout<'a, Ty> {
|
pub struct TyAndLayout<'a, Ty> {
|
||||||
pub ty: Ty,
|
pub ty: Ty,
|
||||||
pub layout: Layout<'a>,
|
pub layout: Layout<'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a, Ty: fmt::Display> fmt::Debug for TyAndLayout<'a, Ty> {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
// Print the type in a readable way, not its debug representation.
|
||||||
|
f.debug_struct("TyAndLayout")
|
||||||
|
.field("ty", &format_args!("{}", self.ty))
|
||||||
|
.field("layout", &self.layout)
|
||||||
|
.finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a, Ty> Deref for TyAndLayout<'a, Ty> {
|
impl<'a, Ty> Deref for TyAndLayout<'a, Ty> {
|
||||||
type Target = &'a LayoutS;
|
type Target = &'a LayoutS;
|
||||||
fn deref(&self) -> &&'a LayoutS {
|
fn deref(&self) -> &&'a LayoutS {
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
// normalize-stderr-test "(valid_range): 0\.\.=(4294967295|18446744073709551615)" -> "$1: $$FULL"
|
// normalize-stderr-test "(valid_range): 0\.\.=(4294967295|18446744073709551615)" -> "$1: $$FULL"
|
||||||
// This pattern is prepared for when we account for alignment in the niche.
|
// This pattern is prepared for when we account for alignment in the niche.
|
||||||
// normalize-stderr-test "(valid_range): [1-9]\.\.=(429496729[0-9]|1844674407370955161[0-9])" -> "$1: $$NON_NULL"
|
// normalize-stderr-test "(valid_range): [1-9]\.\.=(429496729[0-9]|1844674407370955161[0-9])" -> "$1: $$NON_NULL"
|
||||||
// normalize-stderr-test "Leaf\(0x0*20\)" -> "Leaf(0x0...20)"
|
|
||||||
// Some attributes are only computed for release builds:
|
// Some attributes are only computed for release builds:
|
||||||
// compile-flags: -O
|
// compile-flags: -O
|
||||||
#![feature(rustc_attrs)]
|
#![feature(rustc_attrs)]
|
||||||
|
@ -87,7 +87,7 @@ error: fn_abi_of(test) = FnAbi {
|
|||||||
conv: Rust,
|
conv: Rust,
|
||||||
can_unwind: $SOME_BOOL,
|
can_unwind: $SOME_BOOL,
|
||||||
}
|
}
|
||||||
--> $DIR/debug.rs:16:1
|
--> $DIR/debug.rs:15:1
|
||||||
|
|
|
|
||||||
LL | fn test(_x: u8) -> bool { true }
|
LL | fn test(_x: u8) -> bool { true }
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
@ -181,7 +181,7 @@ error: fn_abi_of(TestFnPtr) = FnAbi {
|
|||||||
conv: Rust,
|
conv: Rust,
|
||||||
can_unwind: $SOME_BOOL,
|
can_unwind: $SOME_BOOL,
|
||||||
}
|
}
|
||||||
--> $DIR/debug.rs:19:1
|
--> $DIR/debug.rs:18:1
|
||||||
|
|
|
|
||||||
LL | type TestFnPtr = fn(bool) -> u8;
|
LL | type TestFnPtr = fn(bool) -> u8;
|
||||||
| ^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^
|
||||||
@ -190,7 +190,7 @@ error: fn_abi_of(test_generic) = FnAbi {
|
|||||||
args: [
|
args: [
|
||||||
ArgAbi {
|
ArgAbi {
|
||||||
layout: TyAndLayout {
|
layout: TyAndLayout {
|
||||||
ty: *const T/#0,
|
ty: *const T,
|
||||||
layout: Layout {
|
layout: Layout {
|
||||||
size: $SOME_SIZE,
|
size: $SOME_SIZE,
|
||||||
align: AbiAndPrefAlign {
|
align: AbiAndPrefAlign {
|
||||||
@ -257,13 +257,13 @@ error: fn_abi_of(test_generic) = FnAbi {
|
|||||||
conv: Rust,
|
conv: Rust,
|
||||||
can_unwind: $SOME_BOOL,
|
can_unwind: $SOME_BOOL,
|
||||||
}
|
}
|
||||||
--> $DIR/debug.rs:22:1
|
--> $DIR/debug.rs:21:1
|
||||||
|
|
|
|
||||||
LL | fn test_generic<T>(_x: *const T) { }
|
LL | fn test_generic<T>(_x: *const T) { }
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: `#[rustc_abi]` can only be applied to function items, type aliases, and associated functions
|
error: `#[rustc_abi]` can only be applied to function items, type aliases, and associated functions
|
||||||
--> $DIR/debug.rs:25:1
|
--> $DIR/debug.rs:24:1
|
||||||
|
|
|
|
||||||
LL | const C: () = ();
|
LL | const C: () = ();
|
||||||
| ^^^^^^^^^^^
|
| ^^^^^^^^^^^
|
||||||
@ -409,7 +409,7 @@ error: ABIs are not compatible
|
|||||||
conv: Rust,
|
conv: Rust,
|
||||||
can_unwind: $SOME_BOOL,
|
can_unwind: $SOME_BOOL,
|
||||||
}
|
}
|
||||||
--> $DIR/debug.rs:41:1
|
--> $DIR/debug.rs:40:1
|
||||||
|
|
|
|
||||||
LL | type TestAbiNe = (fn(u8), fn(u32));
|
LL | type TestAbiNe = (fn(u8), fn(u32));
|
||||||
| ^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^
|
||||||
@ -419,7 +419,7 @@ error: ABIs are not compatible
|
|||||||
args: [
|
args: [
|
||||||
ArgAbi {
|
ArgAbi {
|
||||||
layout: TyAndLayout {
|
layout: TyAndLayout {
|
||||||
ty: [u8; Const { ty: usize, kind: Leaf(0x0...20) }],
|
ty: [u8; 32],
|
||||||
layout: Layout {
|
layout: Layout {
|
||||||
size: Size(32 bytes),
|
size: Size(32 bytes),
|
||||||
align: AbiAndPrefAlign {
|
align: AbiAndPrefAlign {
|
||||||
@ -490,7 +490,7 @@ error: ABIs are not compatible
|
|||||||
args: [
|
args: [
|
||||||
ArgAbi {
|
ArgAbi {
|
||||||
layout: TyAndLayout {
|
layout: TyAndLayout {
|
||||||
ty: [u32; Const { ty: usize, kind: Leaf(0x0...20) }],
|
ty: [u32; 32],
|
||||||
layout: Layout {
|
layout: Layout {
|
||||||
size: Size(128 bytes),
|
size: Size(128 bytes),
|
||||||
align: AbiAndPrefAlign {
|
align: AbiAndPrefAlign {
|
||||||
@ -557,7 +557,7 @@ error: ABIs are not compatible
|
|||||||
conv: Rust,
|
conv: Rust,
|
||||||
can_unwind: $SOME_BOOL,
|
can_unwind: $SOME_BOOL,
|
||||||
}
|
}
|
||||||
--> $DIR/debug.rs:44:1
|
--> $DIR/debug.rs:43:1
|
||||||
|
|
|
|
||||||
LL | type TestAbiNeLarger = (fn([u8; 32]), fn([u32; 32]));
|
LL | type TestAbiNeLarger = (fn([u8; 32]), fn([u32; 32]));
|
||||||
| ^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^
|
||||||
@ -700,7 +700,7 @@ error: ABIs are not compatible
|
|||||||
conv: Rust,
|
conv: Rust,
|
||||||
can_unwind: $SOME_BOOL,
|
can_unwind: $SOME_BOOL,
|
||||||
}
|
}
|
||||||
--> $DIR/debug.rs:47:1
|
--> $DIR/debug.rs:46:1
|
||||||
|
|
|
|
||||||
LL | type TestAbiNeFloat = (fn(f32), fn(u32));
|
LL | type TestAbiNeFloat = (fn(f32), fn(u32));
|
||||||
| ^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^
|
||||||
@ -846,13 +846,13 @@ error: ABIs are not compatible
|
|||||||
conv: Rust,
|
conv: Rust,
|
||||||
can_unwind: $SOME_BOOL,
|
can_unwind: $SOME_BOOL,
|
||||||
}
|
}
|
||||||
--> $DIR/debug.rs:51:1
|
--> $DIR/debug.rs:50:1
|
||||||
|
|
|
|
||||||
LL | type TestAbiNeSign = (fn(i32), fn(u32));
|
LL | type TestAbiNeSign = (fn(i32), fn(u32));
|
||||||
| ^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error[E0277]: the size for values of type `str` cannot be known at compilation time
|
error[E0277]: the size for values of type `str` cannot be known at compilation time
|
||||||
--> $DIR/debug.rs:54:46
|
--> $DIR/debug.rs:53:46
|
||||||
|
|
|
|
||||||
LL | type TestAbiEqNonsense = (fn((str, str)), fn((str, str)));
|
LL | type TestAbiEqNonsense = (fn((str, str)), fn((str, str)));
|
||||||
| ^^^^^^^^^^ doesn't have a size known at compile-time
|
| ^^^^^^^^^^ doesn't have a size known at compile-time
|
||||||
@ -861,7 +861,7 @@ LL | type TestAbiEqNonsense = (fn((str, str)), fn((str, str)));
|
|||||||
= note: only the last element of a tuple may have a dynamically sized type
|
= note: only the last element of a tuple may have a dynamically sized type
|
||||||
|
|
||||||
error: `#[rustc_abi]` can only be applied to function items, type aliases, and associated functions
|
error: `#[rustc_abi]` can only be applied to function items, type aliases, and associated functions
|
||||||
--> $DIR/debug.rs:29:5
|
--> $DIR/debug.rs:28:5
|
||||||
|
|
|
|
||||||
LL | const C: () = ();
|
LL | const C: () = ();
|
||||||
| ^^^^^^^^^^^
|
| ^^^^^^^^^^^
|
||||||
@ -870,7 +870,7 @@ error: fn_abi_of(assoc_test) = FnAbi {
|
|||||||
args: [
|
args: [
|
||||||
ArgAbi {
|
ArgAbi {
|
||||||
layout: TyAndLayout {
|
layout: TyAndLayout {
|
||||||
ty: &ReErased Adt(S, []),
|
ty: &S,
|
||||||
layout: Layout {
|
layout: Layout {
|
||||||
size: $SOME_SIZE,
|
size: $SOME_SIZE,
|
||||||
align: AbiAndPrefAlign {
|
align: AbiAndPrefAlign {
|
||||||
@ -949,7 +949,7 @@ error: fn_abi_of(assoc_test) = FnAbi {
|
|||||||
conv: Rust,
|
conv: Rust,
|
||||||
can_unwind: $SOME_BOOL,
|
can_unwind: $SOME_BOOL,
|
||||||
}
|
}
|
||||||
--> $DIR/debug.rs:34:5
|
--> $DIR/debug.rs:33:5
|
||||||
|
|
|
|
||||||
LL | fn assoc_test(&self) { }
|
LL | fn assoc_test(&self) { }
|
||||||
| ^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^
|
||||||
|
Loading…
Reference in New Issue
Block a user