-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
crash / wrong behavior mixing runtime and comptime conditionals in inline for
?
#4364
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
Comments
Thanks for the report. I will look into this |
This diff makes it compile for me: --- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -20387,8 +20387,10 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i
if (type_is_invalid(peer_parent->resolved_type))
return ira->codegen->invalid_inst_gen;
- // the logic below assumes there are no instructions in the new current basic block yet
- ir_assert(ira->new_irb.current_basic_block->instruction_list.length == 0, &phi_instruction->base.base);
+ ZigList<IrInstGen *> instrs_to_move = {};
+ while (ira->new_irb.current_basic_block->instruction_list.length != 0) {
+ instrs_to_move.append(ira->new_irb.current_basic_block->instruction_list.pop());
+ }
// In case resolving the parent activates a suspend, do it now
IrInstGen *parent_result_loc = ir_resolve_result(ira, &phi_instruction->base.base, peer_parent->parent,
@@ -20400,7 +20402,6 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i
}
// If the above code generated any instructions in the current basic block, we need
// to move them to the peer parent predecessor.
- ZigList<IrInstGen *> instrs_to_move = {};
while (ira->new_irb.current_basic_block->instruction_list.length != 0) {
instrs_to_move.append(ira->new_irb.current_basic_block->instruction_list.pop());
}
The title screen comes up, but when I play the game, I get this:
are you able to tell if this is progress, or does that crash seem related to the gbe code? |
Thanks for looking into it. The crash is absolutely related to the gbe code. Your patch does help me look a little deeper with debug prints. Quick explainer: the entity iterator takes custom structs like this one: https://github.com/dbandstra/oxid/blob/master/src/oxid/systems/player_movement.zig#L15 . The By adding some debug prints, I figured out that Because this loop broke before it was supposed to, fields of the returned struct end up unset (left undefined), hence the garbage pointers and runtime crash. There are You might not need this, but I pushed a branch with debug prints added. Here is the same code with prints added: https://github.com/dbandstra/oxid/blob/zig-issue-4364/lib/gbe/gbe.zig#L394 And the output I get, demonstrating that the loop is being exited early (
Should have seen it continue with another field instead of printing "outside the loop". |
Thanks for the clues. I'll have another look this week. This might be a good time for me to experiment with creduce. |
Reduction (I'm still running your zig patch): const std = @import("std");
const T = struct {
id: u64,
one: u32,
two: u32,
three: u32,
};
pub fn main() void {
var runtime_value = false;
inline for (@typeInfo(T).Struct.fields) |field, field_index| {
std.debug.warn("- {}\n", .{field.name});
if (runtime_value) {
} else if (runtime_value) {
} else if (field.field_type == u64) {
}
}
} Output:
Delete the Put the field_type branch (comptime known condition) at the beginning and it works. So it seems the problem has something to do with the pattern edit: I pushed a workaround to oxid, so no rush with the fix. We should change the issue title though. |
ir-clean-up-vars
PRinline for
?
Ah, that's really helpful. I prioritized #2727 - I'll solve that bug and then we can revisit this one. |
Fixed by 4618c41 |
Uh oh!
There was an error while loading. Please reload this page.
See latest comment for minimal case #4364 (comment)
This was broken by the
ir-clean-up-vars
PR.Apologies in advance, I haven't been able to create a minimal reproduction.
Oxid contains a really big comptime function and the compiler is now asserting while analyzing this function. (However I'm not sure if the problem has anything to do with comptime.) It worked before #4152 was merged in.
Commit that works: d896500
Commit that doesn't work: 76fba5b
What happens when I build (my tests will hit it):
The line in my code where it died isn't very informative, at least to me:
https://github.com/dbandstra/oxid/blob/2459c2cd2395f25412c15e8002d9b2af5a4090af/lib/gbe/gbe.zig#L378
lldb excerpt (on commit 76fba5b):
The code in ir.cpp where the assertion happens:
The text was updated successfully, but these errors were encountered: