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

stage2: implement noinline fn #12179

Merged
merged 2 commits into from Jul 24, 2022
Merged

stage2: implement noinline fn #12179

merged 2 commits into from Jul 24, 2022

Conversation

nektro
Copy link
Contributor

@nektro nektro commented Jul 20, 2022

Fixes #11767

test {
    foo();
}

noinline fn foo() void {
    //
}
[meg@nixos:~/dev/zig]$ ./zig-out/bin/zig ast-check -t test.zig 
# Source bytes:       55B
# Tokens:             16 (104B)
# AST Nodes:          9 (237B)
# Total ZIR bytes:    398B
# Instructions:       15 (135B)
# String Table Bytes: 7B
# Extra Data Items:   48 (192B)
%0 = extended(struct_decl(parent, Auto, {
  test line(0) hash(53b4e586ab7c73d53a2fda7c58ad19aa): %1 = block_inline({
    %9 = func_fancy(test, inferror, body={
      %2 = dbg_block_begin())
      %3 = dbg_stmt(2, 5)
      %4 = decl_val("foo") token_offset:2:5 to :2:8
      %5 = dbg_stmt(2, 8)
      %7 = dbg_block_end())
      %6 = call(nodiscard .auto, %4, []) node_offset:2:5 to :2:10
      %8 = ret_tok(@Zir.Inst.Ref.void_value) token_offset:3:1 to :3:2
    }) (lbrace=1:6,rbrace=3:1) node_offset:1:1 to :1:5
    %10 = break_inline(%1, %9)
  }) node_offset:1:1 to :1:5
  [40] foo line(4) hash(f3339e121db838fc9d98c7412345a9c5): %11 = block_inline({
    %13 = func_fancy(noinline, body={
      %12 = ret_tok(@Zir.Inst.Ref.void_value) token_offset:7:1 to :7:2
    }) (lbrace=1:24,rbrace=3:1) node_offset:5:1 to :5:12
    %14 = break_inline(%11, %13)
  }) node_offset:5:1 to :5:23
}, {}, {})
<snip>

; Function Attrs: noinline nounwind
define internal fastcc void @test.foo() unnamed_addr #0 !dbg !4183 {
Entry:
  ret void
}

<snip>

Full .ll log: https://clbin.com/ztvi5

src/AstGen.zig Outdated Show resolved Hide resolved
@wooster0
Copy link
Contributor

Can it also handle this?

pub fn main() void {
    x();
}

noinline fn x() callconv(.Inline) void {}

I think it should be an error because it's ambiguous. In stage1 it's

broken LLVM module found: Attributes 'noinline and alwaysinline' are incompatible!
void ()* @x

This is a bug in the Zig compiler.thread 29374 panic:
Unable to dump stack trace: debug info stripped
Aborted (core dumped)

And we might also want to check other possibly problematic calling conventions in std.builtin.CallingConvention but I don't see any other apart from .Inline.

@nektro
Copy link
Contributor Author

nektro commented Jul 21, 2022

good catch, ill fix both notes and re-push

src/Sema.zig Outdated Show resolved Hide resolved
@Vexu Vexu merged commit dea437e into ziglang:master Jul 24, 2022
@nektro nektro deleted the stage2-noinline branch July 24, 2022 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

implement noinline
3 participants