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

AstGen: add result location pointers to function calls #8824

Open
andrewrk opened this issue May 18, 2021 · 0 comments
Open

AstGen: add result location pointers to function calls #8824

andrewrk opened this issue May 18, 2021 · 0 comments
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase. frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Milestone

Comments

@andrewrk
Copy link
Member

const Foo = struct {
    x: i32,
    y: i32,
};

test {
    var x = foo();
}

fn foo() Foo {
    return .{ .x = 1, .y = 2 };
}
%27 = extended(struct_decl(parent, Auto, {
  [67] Foo line(0) hash(2de2fa0aaeae8e73185740a28fbfe332): %0 = block_inline({
    %1 = extended(struct_decl(parent, Auto, {}, {}, {
      x: @Ref.i32_type,
      y: @Ref.i32_type,
    }) node_offset:1:13
    %2 = break_inline(%0, %1)
  }) node_offset:1:1
  test line(5) hash(dbcecee70b63388d70a9ee646a22e98a): %3 = block_inline({
    %11 = extended(func(test, [], @Ref.void_type, inferror, {
      %4 = dbg_stmt(1, 4)
      %5 = alloc_inferred_mut() node_offset:7:5
      %6 = decl_val("foo") token_offset:7:13
      %7 = call(%6, []) node_offset:7:16
      %8 = store_to_inferred_ptr(%5, %7)
      %9 = resolve_inferred_alloc(%5) node_offset:7:5
      %10 = ret_coerce(@Ref.void_value) token_offset:8:1
    }) (lbrace=0:5,rbrace=2:0) node_offset:6:1
    %12 = break_inline(%3, %11)
  }) node_offset:6:1
  [81] foo line(9) hash(a123f81685e817c35bd084473236d80d): %13 = block_inline({
    %14 = decl_val("Foo") token_offset:10:10
    %15 = as_node(@Ref.type_type, %14) node_offset:10:10
    %25 = func([], %15, {
      %16 = dbg_stmt(1, 4)
      %17 = extended(ret_ptr()) node_offset:11:5
      %18 = field_ptr(%17, "x") node_offset:11:20
      %19 = store_node(%18, @Ref.one) node_offset:11:20
      %20 = field_ptr(%17, "y") node_offset:11:28
      %21 = int(2)
      %22 = store_node(%20, %21) node_offset:11:28
      %23 = validate_struct_init_ptr({
        %18 = field_ptr(%17, "x") node_offset:11:20
        %20 = field_ptr(%17, "y") node_offset:11:28
      }) node_offset:11:13
      %24 = ret_node(@Ref.void_value) node_offset:11:5
    }) (lbrace=0:13,rbrace=2:0) node_offset:10:1
    %26 = break_inline(%13, %25)
  }) node_offset:10:1
}, {}, {})

The problem is that the result location for x does not get passed to the function call:

// result location for `x`:
       %5 = alloc_inferred_mut() node_offset:7:5

// function call of `foo()`:
      %7 = call(%6, []) node_offset:7:16

Instead it is treated as returning a value. AstGen needs to be modified to pass the result location pointer to the function call, so the function can populate the result pointer.

@andrewrk andrewrk added enhancement Solving this issue will likely involve adding new logic or components to the codebase. frontend Tokenization, parsing, AstGen, Sema, and Liveness. labels May 18, 2021
@andrewrk andrewrk added this to the 0.8.0 milestone May 18, 2021
@andrewrk andrewrk modified the milestones: 0.8.0, 0.9.0 Jun 4, 2021
@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 Nov 24, 2021
@andrewrk andrewrk modified the milestones: 0.10.0, 0.11.0 Apr 17, 2022
@Vexu Vexu modified the milestones: 0.11.0, 0.12.0 Apr 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase. frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Projects
None yet
Development

No branches or pull requests

2 participants