On 01/05/12 02:34, Iain Buclaw wrote: > Regardless, there is little reason to want to use a forced inline with > gdc. Just like in c++ when you define all methods in the class > definition, gdc considers all methods as candidates for inlining. > Similarly, when -inline is passed, the same is also done for normal > functions that are considered inlinable by the frontend. These > functions marked as inline are treated in the same way as a function > declared 'inline' in C or C++, and will be treated as such by the > backend.
This reminded me: ------------------------------------ bool empty1(T)(T[] a) { return 1; } bool empty2(T)(in T[] a) { return 1; } int main(string[] argv) { auto r1 = empty1(argv[0]); auto r2 = empty2(argv[0]); return r1&&r2; } ------------------------------------ results in: ------------------------------------ # gdc -O3 -finline -frelease -fno-bounds-check notinlined.d -o notinlined 08049ac0 <bool notinlined.empty1!(immutable(char)).empty1(immutable(char)[])>: 8049ac0: 55 push %ebp 8049ac1: b8 01 00 00 00 mov $0x1,%eax 8049ac6: 89 e5 mov %esp,%ebp 8049ac8: 5d pop %ebp 8049ac9: c3 ret 08049ad0 <bool notinlined.empty2!(immutable(char)).empty2(const(immutable(char)[]))>: 8049ad0: 55 push %ebp 8049ad1: b8 01 00 00 00 mov $0x1,%eax 8049ad6: 89 e5 mov %esp,%ebp 8049ad8: 5d pop %ebp 8049ad9: c3 ret 08049ae0 <_Dmain>: 8049ae0: 55 push %ebp 8049ae1: 89 e5 mov %esp,%ebp 8049ae3: 83 ec 18 sub $0x18,%esp 8049ae6: 8b 45 0c mov 0xc(%ebp),%eax 8049ae9: 8b 50 04 mov 0x4(%eax),%edx 8049aec: 8b 00 mov (%eax),%eax 8049aee: 89 54 24 04 mov %edx,0x4(%esp) 8049af2: 89 04 24 mov %eax,(%esp) 8049af5: e8 d6 ff ff ff call 8049ad0 <bool notinlined.empty2!(immutable(char)).empty2(const(immutable(char)[]))> 8049afa: c9 leave 8049afb: 0f b6 c0 movzbl %al,%eax 8049afe: c3 ret ------------------------------------ IOW gdc completely gives up on inlining the function/method because of the "in". Actually, "bool empty2(T)(const T[] a)" is enough to trigger the call. This means that eg array.empty never gets inlined. "pragma(attribute, always_inline)" does not help in this case. artur