Skip to content

[nll] compiler spinning forever #49936

@zengsai

Description

@zengsai

dev env:

Default host: x86_64-apple-darwin

nightly-x86_64-apple-darwin (default)
rustc 1.27.0-nightly (ad610bed8 2018-04-11)

code like this:

pub struct Operations<'a>(pub &'a Conn);

impl<'a> Operations<'a> {
    pub fn query(&self, query: Option<Query>) -> QueryResult<(Vec<Dian>, i64, i64)> {
        // if query is null { return dians::table.paginate(1).load_and_count_numbers(self.0) }
        // if query.filters is not null { create_filter_param;  }
        // if query.page is not null { create_paginated; }

        let default_page_params = PageParams {
            size: 10,
            number: 1,
        };

        let page_info = query
            .as_ref()
            .and_then(|q| q.page)
            .map_or(default_page_params, |p| p);

        let preadite: Box<BoxableExpression<dians::table, Db, SqlType = Bool>> = query
            .and_then(|q| q.filters)
            .map(|fs| {
                fs.iter()    // BUG?: focus on this line.
                    .filter_map(|(key, val)| {
                        match key.as_str() {
                            "name" => Some(Box::new(dians::name.eq(val)) as Box<_>),
                            "mima" => Some(Box::new(dians::mima.eq(val)) as Box<_>),
                            _ => None,
                        }
                    })
                    .fold(
                        Box::new(true.into_sql::<Bool>())
                            as Box<BoxableExpression<dians::table, Db, SqlType = Bool>>,
                        |v, e: Box<BoxableExpression<dians::table, Db, SqlType = Bool>>| {
                            Box::new(v.and(e))
                        },
                    )
            })
            .unwrap_or(Box::new(true.into_sql::<Bool>()));

        let query = dians::table
            .as_query()
            .filter(preadite)
            .paginate(page_info.number as i64)
            .size(page_info.size as i64);


        let debug = ::diesel::debug_query::<Db, _>(&query);

        println!("debug: {:?}", debug);

        query.load_and_count_numbers(self.0)
    }

    pub fn query_by_id(&self, id: i32) -> QueryResult<Dian> {
        dians::table.filter(dians::id.eq(id)).first(self.0)
    }
}

and then run RUST_LOG=logger=info co watch -x run, then the compiler keep running, It seams will not finish the compile, and my cups are almost full-load. after a while, my Iterm2 into no response mode.

image

after change this line fs.iter() // BUG?: focus on this line. to fs.into_iter() // BUG?: focus on this line. compiler restored to normal.

Metadata

Metadata

Assignees

Labels

A-NLLArea: Non-lexical lifetimes (NLL)NLL-performantWorking towards the "performance is good" goal

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions