Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

const_evaluatable_checked can cause a stackoverflow #79615

Closed
lcnr opened this issue Dec 1, 2020 · 3 comments · Fixed by #79635
Closed

const_evaluatable_checked can cause a stackoverflow #79615

lcnr opened this issue Dec 1, 2020 · 3 comments · Fixed by #79635
Assignees
Labels
C-bug Category: This is a bug. F-const_generics `#![feature(const_generics)]` F-generic_const_exprs `#![feature(generic_const_exprs)]`

Comments

@lcnr
Copy link
Contributor

lcnr commented Dec 1, 2020

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=6bdb59061285589534c53004561c978a

#![feature(const_generics, const_evaluatable_checked)]

fn q<T, const N: usize>(_: T) -> [u8; N + 1] {
    todo!()
}

fn supplier<T>() -> T {
    todo!()
}

fn catch_me<const N: usize>() where [u8; N + 1]: Default {
    let mut x = supplier();
    x = q(x);
}

causes

thread 'rustc' has overflowed its stack
fatal runtime error: stack overflow
error: could not compile `playground`

(it does ICE with incremental enabled, this is a different bug and tracked separately)

We end up referencing an inference variable in the value of said inference variable, causing an infinite type.
This should ordinarily be prevented by the occurs check. We either have a bug there or there is something else I have missed

@lcnr lcnr added the C-bug Category: This is a bug. label Dec 1, 2020
@lcnr lcnr self-assigned this Dec 1, 2020
@lcnr lcnr added F-generic_const_exprs `#![feature(generic_const_exprs)]` F-const_generics `#![feature(const_generics)]` labels Dec 1, 2020
@lcnr lcnr changed the title const_evaluatable_checked stackoverflow const_evaluatable_checked stack overflow Dec 1, 2020
@lcnr
Copy link
Contributor Author

lcnr commented Dec 1, 2020

we can't use super_relate_consts for the occurs check with const_evaluatable_checked. We do not try to relate the substs here.

(
ty::ConstKind::Unevaluated(a_def, a_substs, None),
ty::ConstKind::Unevaluated(b_def, b_substs, None),
) if tcx.features().const_evaluatable_checked => {
if tcx.try_unify_abstract_consts(((a_def, a_substs), (b_def, b_substs))) {
Ok(a.val)
} else {
Err(TypeError::ConstMismatch(expected_found(relation, a, b)))
}
}

@lcnr lcnr changed the title const_evaluatable_checked stack overflow const_evaluatable_checked can cause a stackoverflow Dec 1, 2020
@Nadrieril
Copy link
Member

I was playing with this and turns out catch_me does not need to be generic (playground):

#![feature(const_generics, const_evaluatable_checked)]

fn q<T, const N: usize>(_: T) -> [u8; N + 1] {
    todo!()
}

fn supplier<T>() -> T {
    todo!()
}

fn catch_me() {
    let mut x = supplier();
    x = q(x);
}

@lcnr
Copy link
Contributor Author

lcnr commented Dec 3, 2020

yeah, I wanted to first write q::<_, N> 😆 as it already broke without that the N is currently unnecessary

@bors bors closed this as completed in 0c11b93 Dec 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. F-const_generics `#![feature(const_generics)]` F-generic_const_exprs `#![feature(generic_const_exprs)]`
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants