在 Substrate runtime crate 中定义的类型 Log 在哪里?

Where is the type Log defined inside of the Substrate runtime crate?

看看this implementation:

impl consensus::Trait for Runtime {
    type Log = Log;
    type SessionKey = AuthorityId;

    // The Aura module handles offline-reports internally
    // rather than using an explicit report system.
    type InherentOfflineReport = ();
}

Log是怎么定义的?没有用于导入此符号的 use 子句。

运行

cargo rustc -- -Z unstable-options --pretty=expanded

不显示任何带有 type 子句的 Log 条目。它确实显示了在 0 级扩展宏后的其他宏声明,但我不确定这是否相关。

我尝试使用 Atom IDE,因为它会自动解析文件并让您找到符号的定义,但没有帮助。

如何找到 Log 的定义方式?

Logconstruct_runtime 宏定义。 以下是一些相关代码:

construct_runtime宏:

https://github.com/paritytech/substrate/blob/950e90e75dc7d16dcf99972fcc733945a832dc3e/srml/support/src/runtime.rs#L79

macro_rules! construct_runtime {
    (
        pub enum $runtime:ident with Log ($log_internal:ident: DigestItem<$( $log_genarg:ty ),+>)
            where
                Block = $block:ident,
                NodeBlock = $node_block:ty,
                UncheckedExtrinsic = $uncheckedextrinsic:ident
        {
            $( $rest:tt )*
        }
    )

呼叫__decl_outer_log

https://github.com/paritytech/substrate/blob/950e90e75dc7d16dcf99972fcc733945a832dc3e/srml/support/src/runtime.rs#L267

    $crate::__decl_outer_log!(
        $runtime;
        $log_internal < $( $log_genarg ),* >;
        {};
        $(
            $name: $module:: $( < $module_instance >:: )? { $( $modules $( ( $( $modules_args )* ) )* )* }
        )*
    );

__decl_outer_log

https://github.com/paritytech/substrate/blob/950e90e75dc7d16dcf99972fcc733945a832dc3e/srml/support/src/runtime.rs#L706

macro_rules! __decl_outer_log {
    (
        $runtime:ident;
        $log_internal:ident <$( $log_genarg:ty ),+>;
        { $( $parsed:tt )* };
        $name:ident: $module:ident:: $(<$module_instance:ident>::)? {
            Log ( $( $args:ident )* ) $( $modules:ident $( ( $( $modules_args:ident )* ) )* )*
        }
        $( $rest:tt )*
    ) => {

呼叫impl_outer_log

https://github.com/paritytech/substrate/blob/950e90e75dc7d16dcf99972fcc733945a832dc3e/srml/support/src/runtime.rs#L763

(
    $runtime:ident;
    $log_internal:ident <$( $log_genarg:ty ),+>;
    { $(
        $parsed_modules:ident $(< $parsed_instance:ident >)? ( $( $parsed_args:ident )* )
    )* };
) => {
    $crate::paste::item! {
        $crate::runtime_primitives::impl_outer_log!(
            pub enum Log($log_internal: DigestItem<$( $log_genarg ),*>) for $runtime {
                $( [< $parsed_modules $(_ $parsed_instance)? >] $(< $parsed_modules::$parsed_instance >)? ( $( $parsed_args ),* ) ),*
            }
        );
    }
};

impl_outer_log宏: https://github.com/paritytech/substrate/blob/950e90e75dc7d16dcf99972fcc733945a832dc3e/core/sr-primitives/src/lib.rs#L630

macro_rules! impl_outer_log {
    (
        $(#[$attr:meta])*
        pub enum $name:ident ($internal:ident: DigestItem<$( $genarg:ty ),*>) for $trait:ident {
            $( $module:ident $(<$instance:path>)? ( $( $sitem:ident ),* ) ),*
        }
    )

实际上声明并实现了 Log 结构

cargo expand 运行时 crate 时,您应该能够看到结果。