-
Notifications
You must be signed in to change notification settings - Fork 75
Fixed a recursive inling bug, added a test for it #666
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work!
Here are some nitpicks.
6259a7d
to
f217230
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some nitpicks about formatting and spelling.
} | ||
/// Get GCC attribute for the provided inline heuristic, attached to `instance`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} | |
/// Get GCC attribute for the provided inline heuristic, attached to `instance`. | |
} | |
/// Get GCC attribute for the provided inline heuristic, attached to `instance`. |
use mini_core::*; | ||
#[inline(always)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use mini_core::*; | |
#[inline(always)] | |
use mini_core::*; | |
#[inline(always)] |
} | ||
#[inline(always)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} | |
#[inline(always)] | |
} | |
#[inline(always)] |
} | ||
#[inline(always)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} | |
#[inline(always)] | |
} | |
#[inline(always)] |
} | ||
#[no_mangle] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} | |
#[no_mangle] | |
} | |
#[no_mangle] |
use rustc_middle::ty; | ||
|
||
use crate::context::CodegenCx; | ||
use crate::gcc_util::to_gcc_features; | ||
|
||
/// Get GCC attribute for the provided inline heuristic. | ||
/// Checks if the function `instance` is recursively inline. | ||
/// Returns `false` if a functions is guranteed to be non-recursive, and `true` if it *might* be recursive. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Returns `false` if a functions is guranteed to be non-recursive, and `true` if it *might* be recursive. | |
/// Returns `false` if a functions is guaranteed to be non-recursive, and `true` if it *might* be recursive. |
let body = cx.tcx.optimized_mir(instance.def_id()); | ||
for block in body.basic_blocks.iter() { | ||
let Some(ref terminator) = block.terminator else { continue }; | ||
// I assmume that the resursive-inline issue applies only to functions, and not to drops. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// I assmume that the resursive-inline issue applies only to functions, and not to drops. | |
// I assume that the recursive-inline issue applies only to functions, and not to drops. |
) -> Option<FnAttribute<'gcc>> { | ||
match inline { | ||
InlineAttr::Always => { | ||
// We can't simply always return `always_inline` unconditionally. | ||
// It is *NOT A HINT* and does not work for recurisve functions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// It is *NOT A HINT* and does not work for recurisve functions. | |
// It is *NOT A HINT* and does not work for recursive functions. |
// It is *NOT A HINT* and does not work for recurisve functions. | ||
// | ||
// So, it can only be applied *if*: | ||
// The current function does not call any functions makred `#[inline(always)]`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// The current function does not call any functions makred `#[inline(always)]`. | |
// The current function does not call any functions marked `#[inline(always)]`. |
Fixes #599.
Instead of always translating
#[inline(always)]
(which is a hint) toFnAttribute::AlwaysInline
(which makes inlining mandatory), we now do so only for functions which don't call any functions with the#[inline(always)]
or the rustc force inline attribute.In cases where
#[inline(always)]
is applied to a function which might be recursive, it is demoted to#[inline]
instead.This breaks the cycle, and prevents libjitgcc errors.
The regression test checks for direct and indirect recursion.