Skip to content

Severe compilation time blowup in typeck_tables_of #70513

@syntacticsugarglider

Description

@syntacticsugarglider

This simple test of a codegen macro from protocol using a transport from protocol-mve-transport takes an unreasonable amount of time to compile. protocol itself takes 4 to 5 minutes to compile on my laptop but compiling this simple example takes up to 20 minutes on the same hardware, and that's with a lot of the macro expansion in protocol disabled to reduce the time spent. -Z self-profile indicates that time is overwhelmingly (> 90%) spent as self time in typeck_tables_of for this main function under collect_mod_item_types etc.

use core::fmt::{self, Display, Formatter};
use core_error::Error;
use futures::{channel::mpsc::unbounded, executor::LocalPool, task::LocalSpawnExt, StreamExt};
use protocol::protocol;
use protocol_mve_transport::{Coalesce, Unravel};
use void::Void;

#[protocol]
#[derive(Debug)]
pub struct Unit;

#[protocol]
#[derive(Debug)]
pub struct Newtype(u16);

#[protocol]
#[derive(Debug)]
pub struct Tuple(Vec<String>, u8, Newtype);

#[protocol]
#[derive(Debug)]
pub struct Test {
    data: u8,
    other: String,
    unit: Unit,
    tuple: Tuple,
}

fn main() {
    let mut pool = LocalPool::new();

    let s = pool.spawner();
    let spawner = s.clone();

    let (a_sender, a_receiver) = unbounded();
    let (b_sender, b_receiver) = unbounded();

    s.spawn_local(async move {
        Unravel::<Void, _, _, _, Test>::new(
            a_receiver.map(Ok::<Vec<u8>, Void>),
            b_sender,
            spawner,
            Test {
                data: 10,
                other: "hello".to_owned(),
                unit: Unit,
                tuple: Tuple(
                    ["there", "general", "kenoi"]
                        .iter()
                        .cloned()
                        .map(String::from)
                        .collect(),
                    5,
                    Newtype(20),
                ),
            },
        )
        .await
        .unwrap();
    })
    .unwrap();

    let spawner = s.clone();

    s.spawn_local(async move {
        let data = Coalesce::<_, _, _, _, Test>::new(
            b_receiver.map(Ok::<Vec<u8>, Void>),
            a_sender,
            spawner,
        );
        println!("{:?}", data.await.unwrap())
    })
    .unwrap();

    pool.run();
}

Unfortunately, there isn't a lot that I can do to reduce this as I have no idea what the underlying factors are that would lead to this occurring. I have a very limited understanding of incremental compilation or what individual queries are responsible for. If any logs, profile traces, etc. would be helpful please let me know and I will provide them.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-type-systemArea: Type systemC-bugCategory: This is a bug.E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable ExampleI-compiletimeIssue: Problems and improvements with respect to compile times.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions