-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Function body is translated more than once #7349
Comments
This is a little tricky with closures. Note that even though the closures are not polymorphic, they can close over type variables. The first closure in |
Oops, looking at the ll code, it's not actually the closure that is translated multiple times, but the FFI wrapper, sorry. |
Nominating for milestone 5, production-ready |
Needs more explanation; not a milestone issue. |
The original code isn't present anymore, but here's a testcase: fn outer<T>(x: T) -> T {
fn inner(x: uint) -> uint {
x
}
x
}
fn main() {
outer(5i);
outer(5u);
} Results in: ; Function Attrs: uwtable
define internal i64 @_ZN5outer5inner67h7600d001aed24abe20f7e4097463dde0dedcf59bbd47ee5a6329d5a851388702ap4v0.0E({ i64, %tydesc*, i8*, i8*, i8 }*, i64) unnamed_addr #4 {
"function top level":
%__arg = alloca i64
store i64 %1, i64* %__arg
%2 = load i64* %__arg
ret i64 %2
"function top level1": ; No predecessors!
%__arg2 = alloca i64
store i64 %1, i64* %__arg2
%3 = load i64* %__arg2
ret i64 %3
"function top level3": ; No predecessors!
%__arg4 = alloca i64
store i64 %1, i64* %__arg4
%4 = load i64* %__arg4
ret i64 %4
}
i.e. |
Fixed by #16059. |
The closures in
std::os::with_env_lock
are translated multiple times, probably once for each monomorphic version of that function. Since the closure isn't actually generic, we end up with a single function that has its body repeated multiple times:This is not limited to closures, the same happens for
rustc::middle::typeck::astconv::ast_ty_to_ty::check_path_args
, which contains its body 6 times.The text was updated successfully, but these errors were encountered: