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

Allow concatenation of tuples that contain a mix of runtime and comptime values #4573

Merged
merged 6 commits into from Mar 4, 2020

Conversation

alexnask
Copy link
Contributor

Closes #4571.

@alexnask alexnask changed the title Allow tuple concatenation of tuples that contain a mix of runtime and comptime values Allow concatenation of tuples that contain a mix of runtime and comptime values Feb 28, 2020
@mikdusan
Copy link
Member

mikdusan commented Feb 28, 2020

on macOS, latest Xcode/clang:

../src/ir.cpp:16964:10: error: unused variable 'is_comptime' [-Werror,-Wunused-variable]
    bool is_comptime = ir_should_inline(ira->old_irb.exec, source_instr->scope);
         ^
1 error generated.
diff --git a/src/ir.cpp b/src/ir.cpp
index 5855f0a08..f4b2ad364 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -16961,8 +16961,6 @@ static IrInstGen *ir_analyze_tuple_cat(IrAnalyze *ira, IrInst* source_instr,
     new_type->data.structure.special = StructSpecialInferredTuple;
     new_type->data.structure.resolve_status = ResolveStatusBeingInferred;
 
-    bool is_comptime = ir_should_inline(ira->old_irb.exec, source_instr->scope);
-
     IrInstGen *new_struct_ptr = ir_resolve_result(ira, source_instr, no_result_loc(),
             new_type, nullptr, false, true);
     uint32_t new_field_count = op1_field_count + op2_field_count;

@alexnask
Copy link
Contributor Author

Thanks, will update soon.

@mlarouche
Copy link
Sponsor Contributor

Confirmed that it fix the issue I had to make COM call more natural

Without this PR

fn comCall(comptime name: []const u8, args: var) comFindReturnType(comFindVtableType(@TypeOf(args[0])), name) {
    if (@field(args[0].lpVtbl[0], name)) |func| {
        return @call(.{}, func, args);
    }

    return undefined;
}

fn createRenderTarget() void {
    var pBackBuffer: ?*dx.ID3D11Texture2D = null;
    if (dxContext.swapChain) |swapChain| {
        _ = comCall("GetBuffer" , "GetBuffer", .{ swapChain, 0, &dx.IID_ID3D11Texture2D, @ptrCast([*c]?*c_void, &pBackBuffer) });
    }
    if (dxContext.device) |device| {
        _ = comCall("CreateRenderTargetView", .{ device, @ptrCast([*c]dx.struct_ID3D11Resource, pBackBuffer), null, @ptrCast([*c][*c]dx.struct_ID3D11RenderTargetView, &dxContext.mainRenderTargetView) });
    }
    if (pBackBuffer) |backBuffer| {
        _ = comCall("Release", .{backBuffer});
    }
}

With this PR:

fn comCall(self: var, comptime name: []const u8, args: var) comFindReturnType(comFindVtableType(@TypeOf(self)), name) {
    if (@field(self.lpVtbl[0], name)) |func| {
        return @call(.{}, func, .{self} ++ args);
    }

    return undefined;
}

fn createRenderTarget() void {
    var pBackBuffer: ?*dx.ID3D11Texture2D = null;
    if (dxContext.swapChain) |swapChain| {
        _ = comCall(swapChain, "GetBuffer", .{ 0, &dx.IID_ID3D11Texture2D, @ptrCast([*c]?*c_void, &pBackBuffer) });
    }
    if (dxContext.device) |device| {
        _ = comCall(device, "CreateRenderTargetView", .{ @ptrCast([*c]dx.struct_ID3D11Resource, pBackBuffer), null, @ptrCast([*c][*c]dx.struct_ID3D11RenderTargetView, &dxContext.mainRenderTargetView) });
    }
    if (pBackBuffer) |backBuffer| {
        _ = comCall(backBuffer, "Release", .{});
    }
}

@andrewrk andrewrk merged commit 24fc69a into ziglang:master Mar 4, 2020
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.

Concatenating tuples with a mix of runtime and comptime values fails
4 participants