Skip to content

stage1 and stage2: closes #7120 #7122

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion lib/std/debug.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1663,7 +1663,6 @@ pub const ModuleDebugInfo = switch (builtin.os.tag) {
.symbol_name = nosuspend self.dwarf.getSymbolName(relocated_address) orelse "???",
.compile_unit_name = compile_unit.die.getAttrString(&self.dwarf, DW.AT_name) catch |err| switch (err) {
error.MissingDebugInfo, error.InvalidDebugInfo => "???",
else => return err,
},
.line_info = nosuspend self.dwarf.getLineNumberInfo(compile_unit.*, relocated_address) catch |err| switch (err) {
error.MissingDebugInfo, error.InvalidDebugInfo => null,
Expand Down
2 changes: 0 additions & 2 deletions lib/std/fmt.zig
Original file line number Diff line number Diff line change
Expand Up @@ -587,12 +587,10 @@ fn formatFloatValue(
if (fmt.len == 0 or comptime std.mem.eql(u8, fmt, "e")) {
formatFloatScientific(value, options, buf_stream.writer()) catch |err| switch (err) {
error.NoSpaceLeft => unreachable,
else => |e| return e,
};
} else if (comptime std.mem.eql(u8, fmt, "d")) {
formatFloatDecimal(value, options, buf_stream.writer()) catch |err| switch (err) {
error.NoSpaceLeft => unreachable,
else => |e| return e,
};
} else {
@compileError("Unknown format string: '" ++ fmt ++ "'");
Expand Down
10 changes: 0 additions & 10 deletions src/Module.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1960,16 +1960,6 @@ pub fn analyzeExport(self: *Module, scope: *Scope, src: usize, borrowed_symbol_n
try self.symbol_exports.putNoClobber(self.gpa, symbol_name, new_export);
self.comp.bin_file.updateDeclExports(self, exported_decl, de_gop.entry.value) catch |err| switch (err) {
error.OutOfMemory => return error.OutOfMemory,
else => {
try self.failed_exports.ensureCapacity(self.gpa, self.failed_exports.items().len + 1);
self.failed_exports.putAssumeCapacityNoClobber(new_export, try Compilation.ErrorMsg.create(
self.gpa,
src,
"unable to export: {}",
.{@errorName(err)},
));
new_export.status = .failed_retryable;
},
};
}

Expand Down
31 changes: 24 additions & 7 deletions src/stage1/ir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6362,7 +6362,7 @@ static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNod
BuiltinFnEntry *builtin_fn = entry->value;
size_t actual_param_count = node->data.fn_call_expr.params.length;

if (builtin_fn->param_count != SIZE_MAX && builtin_fn->param_count != actual_param_count) {
if (builtin_fn->param_count != SIZE_MAX && builtin_fn->param_count != actual_param_count) {
add_node_error(irb->codegen, node,
buf_sprintf("expected %" ZIG_PRI_usize " argument(s), found %" ZIG_PRI_usize,
builtin_fn->param_count, actual_param_count));
Expand Down Expand Up @@ -8576,7 +8576,7 @@ static IrInstSrc *ir_gen_for_expr(IrBuilderSrc *irb, Scope *parent_scope, AstNod

if (is_duplicate_label(irb->codegen, child_scope, node, node->data.for_expr.name))
return irb->codegen->invalid_inst_src;

ZigList<IrInstSrc *> incoming_values = {0};
ZigList<IrBasicBlockSrc *> incoming_blocks = {0};
ScopeLoop *loop_scope = create_loop_scope(irb->codegen, node, child_scope);
Expand Down Expand Up @@ -20854,7 +20854,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
expected_return_type->id != ZigTypeIdErrorUnion && expected_return_type->id != ZigTypeIdErrorSet)
{
if (call_result_loc->id == ResultLocIdReturn) {
add_error_note(ira->codegen, ira->new_irb.exec->first_err_trace_msg,
add_error_note(ira->codegen, ira->new_irb.exec->first_err_trace_msg,
ira->explicit_return_type_source_node, buf_sprintf("function cannot return an error"));
} else {
add_error_note(ira->codegen, ira->new_irb.exec->first_err_trace_msg, result_loc->base.source_node,
Expand Down Expand Up @@ -29479,7 +29479,7 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
}
}
} else if(!switch_type->data.enumeration.non_exhaustive && switch_type->data.enumeration.src_field_count == instruction->range_count) {
ir_add_error_node(ira, instruction->else_prong,
ir_add_error_node(ira, instruction->else_prong,
buf_sprintf("unreachable else prong, all cases already handled"));
return ira->codegen->invalid_inst_gen;
}
Expand Down Expand Up @@ -29544,6 +29544,23 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
}
}
}
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} else {
} else if (!type_is_global_error_set(switch_type)) {

You can save a whole indentation level.

if (!type_is_global_error_set(switch_type)) {
bool needs_else = false;
for (uint32_t i = 0; i < switch_type->data.error_set.err_count; i += 1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this a more expensive version of const bool needs_else = instruction->range_count != switch_type->data.error_set.err_count ?
By the time you reach this line the compiler already knows all the values are correctly typed and the prong list contains no duplicates.

ErrorTableEntry *err_entry = switch_type->data.error_set.errors[i];

AstNode *prev_node = field_prev_uses[err_entry->value];
if (prev_node == nullptr) {
needs_else = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway, the indentation is off and you can exit with a break once this becomes true.

}
}
if (!needs_else) {
ir_add_error_node(ira, instruction->else_prong,
buf_sprintf("unreachable else prong, all cases already handled"));
return ira->codegen->invalid_inst_gen;
}
}
}

heap::c_allocator.deallocate(field_prev_uses, field_prev_uses_count);
Expand Down Expand Up @@ -29600,7 +29617,7 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
ir_add_error(ira, &instruction->base.base, buf_sprintf("switch must handle all possibilities"));
return ira->codegen->invalid_inst_gen;
} else if(handles_all_cases && instruction->else_prong != nullptr) {
ir_add_error_node(ira, instruction->else_prong,
ir_add_error_node(ira, instruction->else_prong,
buf_sprintf("unreachable else prong, all cases already handled"));
return ira->codegen->invalid_inst_gen;
}
Expand Down Expand Up @@ -29639,7 +29656,7 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
}

if(seenTrue == 1 && seenFalse == 1 && instruction->else_prong != nullptr) {
ir_add_error_node(ira, instruction->else_prong,
ir_add_error_node(ira, instruction->else_prong,
buf_sprintf("unreachable else prong, all cases already handled"));
return ira->codegen->invalid_inst_gen;
}
Expand Down Expand Up @@ -29677,7 +29694,7 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
}
}
prevs.deinit();
}
}
return ir_const_void(ira, &instruction->base.base);
}

Expand Down