Auto merge of #146348 - jdonszelmann:eiiv3, r=lcnr,oli-obk
Externally implementable items Supersedes https://github.com/rust-lang/rust/pull/140010 Tracking issue: https://github.com/rust-lang/rust/issues/125418 Getting started: ```rust #![feature(eii)] #[eii(eii1)] pub fn decl1(x: u64) // body optional (it's the default) { println!("default {x}"); } // in another crate, maybe #[eii1] pub fn decl2(x: u64) { println!("explicit {x}"); } fn main() { decl1(4); } ``` - tiny perf regression, underlying issue makes multiple things in the compiler slow, not just EII, planning to solve those separately. - No codegen_gcc support, they don't have bindings for weak symbols yet but could - No windows support yet for weak definitions This PR merges the implementation of EII for just llvm + not windows, doesn't yet contain like a new panic handler implementation or alloc handler. With this implementation, it would support implementing the panic handler in terms of EII already since it requires no default implementation so no weak symbols The PR has been open in various forms for about a year now, but I feel that having some implementation merged to build upon
This commit is contained in:
commit
3f4dc1e02d
140 changed files with 3452 additions and 65 deletions
|
|
@ -2107,6 +2107,19 @@ pub struct MacroDef {
|
|||
pub body: Box<DelimArgs>,
|
||||
/// `true` if macro was defined with `macro_rules`.
|
||||
pub macro_rules: bool,
|
||||
|
||||
/// If this is a macro used for externally implementable items,
|
||||
/// it refers to an extern item which is its "target". This requires
|
||||
/// name resolution so can't just be an attribute, so we store it in this field.
|
||||
pub eii_extern_target: Option<EiiExternTarget>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Encodable, Decodable, Debug, HashStable_Generic, Walkable)]
|
||||
pub struct EiiExternTarget {
|
||||
/// path to the extern item we're targetting
|
||||
pub extern_item_path: Path,
|
||||
pub impl_unsafe: bool,
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(Clone, Encodable, Decodable, Debug, Copy, Hash, Eq, PartialEq)]
|
||||
|
|
@ -3746,6 +3759,21 @@ pub struct Fn {
|
|||
pub contract: Option<Box<FnContract>>,
|
||||
pub define_opaque: Option<ThinVec<(NodeId, Path)>>,
|
||||
pub body: Option<Box<Block>>,
|
||||
|
||||
/// This function is an implementation of an externally implementable item (EII).
|
||||
/// This means, there was an EII declared somewhere and this function is the
|
||||
/// implementation that should be run when the declaration is called.
|
||||
pub eii_impls: ThinVec<EiiImpl>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Encodable, Decodable, Debug, Walkable)]
|
||||
pub struct EiiImpl {
|
||||
pub node_id: NodeId,
|
||||
pub eii_macro_path: Path,
|
||||
pub impl_safety: Safety,
|
||||
pub span: Span,
|
||||
pub inner_span: Span,
|
||||
pub is_default: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Encodable, Decodable, Debug, Walkable)]
|
||||
|
|
@ -4112,7 +4140,7 @@ mod size_asserts {
|
|||
static_assert_size!(Block, 32);
|
||||
static_assert_size!(Expr, 72);
|
||||
static_assert_size!(ExprKind, 40);
|
||||
static_assert_size!(Fn, 184);
|
||||
static_assert_size!(Fn, 192);
|
||||
static_assert_size!(ForeignItem, 80);
|
||||
static_assert_size!(ForeignItemKind, 16);
|
||||
static_assert_size!(GenericArg, 24);
|
||||
|
|
|
|||
|
|
@ -393,6 +393,7 @@ macro_rules! common_visitor_and_walkers {
|
|||
ThinVec<Pat>,
|
||||
ThinVec<Box<Ty>>,
|
||||
ThinVec<TyPat>,
|
||||
ThinVec<EiiImpl>,
|
||||
);
|
||||
|
||||
// This macro generates `impl Visitable` and `impl MutVisitable` that forward to `Walkable`
|
||||
|
|
@ -486,6 +487,8 @@ macro_rules! common_visitor_and_walkers {
|
|||
WhereEqPredicate,
|
||||
WhereRegionPredicate,
|
||||
YieldKind,
|
||||
EiiExternTarget,
|
||||
EiiImpl,
|
||||
);
|
||||
|
||||
/// Each method of this trait is a hook to be potentially
|
||||
|
|
@ -920,13 +923,13 @@ macro_rules! common_visitor_and_walkers {
|
|||
_ctxt,
|
||||
// Visibility is visited as a part of the item.
|
||||
_vis,
|
||||
Fn { defaultness, ident, sig, generics, contract, body, define_opaque },
|
||||
Fn { defaultness, ident, sig, generics, contract, body, define_opaque, eii_impls },
|
||||
) => {
|
||||
let FnSig { header, decl, span } = sig;
|
||||
visit_visitable!($($mut)? vis,
|
||||
defaultness, ident, header, generics, decl,
|
||||
contract, body, span, define_opaque
|
||||
)
|
||||
contract, body, span, define_opaque, eii_impls
|
||||
);
|
||||
}
|
||||
FnKind::Closure(binder, coroutine_kind, decl, body) =>
|
||||
visit_visitable!($($mut)? vis, binder, coroutine_kind, decl, body),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue