Skip to content

Commit

Permalink
Merge pull request ziglang#22777 from mlugg/some-bugs
Browse files Browse the repository at this point in the history
Fix a bunch of frontend bugs
  • Loading branch information
mlugg authored Feb 6, 2025
2 parents b0ed602 + 5d935e1 commit 43e52ec
Show file tree
Hide file tree
Showing 19 changed files with 395 additions and 74 deletions.
6 changes: 5 additions & 1 deletion lib/std/zig/AstGen.zig
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,10 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE
const cursor = maybeAdvanceSourceCursorToMainToken(gz, node);
const start = try expr(gz, scope, .{ .rl = .{ .coerced_ty = .usize_type } }, full.ast.start);
const end = if (full.ast.end != 0) try expr(gz, scope, .{ .rl = .{ .coerced_ty = .usize_type } }, full.ast.end) else .none;
const sentinel = if (full.ast.sentinel != 0) try expr(gz, scope, .{ .rl = .none }, full.ast.sentinel) else .none;
const sentinel = if (full.ast.sentinel != 0) s: {
const sentinel_ty = try gz.addUnNode(.slice_sentinel_ty, lhs, node);
break :s try expr(gz, scope, .{ .rl = .{ .coerced_ty = sentinel_ty } }, full.ast.sentinel);
} else .none;
try emitDbgStmt(gz, cursor);
if (sentinel != .none) {
const result = try gz.addPlNode(.slice_sentinel, node, Zir.Inst.SliceSentinel{
Expand Down Expand Up @@ -2855,6 +2858,7 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As
.slice_end,
.slice_sentinel,
.slice_length,
.slice_sentinel_ty,
.import,
.switch_block,
.switch_block_ref,
Expand Down
8 changes: 8 additions & 0 deletions lib/std/zig/Zir.zig
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,10 @@ pub const Inst = struct {
/// Returns a pointer to the subslice.
/// Uses the `pl_node` field. AST node is the slice syntax. Payload is `SliceLength`.
slice_length,
/// Given a value which is a pointer to the LHS of a slice operation, return the sentinel
/// type, used as the result type of the slice sentinel (i.e. `s` in `lhs[a..b :s]`).
/// Uses the `un_node` field. AST node is the slice syntax. Operand is `lhs`.
slice_sentinel_ty,
/// Same as `store` except provides a source location.
/// Uses the `pl_node` union field. Payload is `Bin`.
store_node,
Expand Down Expand Up @@ -1185,6 +1189,7 @@ pub const Inst = struct {
.slice_end,
.slice_sentinel,
.slice_length,
.slice_sentinel_ty,
.import,
.typeof_log2_int_type,
.resolve_inferred_alloc,
Expand Down Expand Up @@ -1472,6 +1477,7 @@ pub const Inst = struct {
.slice_end,
.slice_sentinel,
.slice_length,
.slice_sentinel_ty,
.import,
.typeof_log2_int_type,
.switch_block,
Expand Down Expand Up @@ -1702,6 +1708,7 @@ pub const Inst = struct {
.slice_end = .pl_node,
.slice_sentinel = .pl_node,
.slice_length = .pl_node,
.slice_sentinel_ty = .un_node,
.store_node = .pl_node,
.store_to_inferred_ptr = .pl_node,
.str = .str,
Expand Down Expand Up @@ -4162,6 +4169,7 @@ fn findTrackableInner(
.slice_end,
.slice_sentinel,
.slice_length,
.slice_sentinel_ty,
.store_node,
.store_to_inferred_ptr,
.str,
Expand Down
10 changes: 6 additions & 4 deletions src/Compilation.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2196,6 +2196,8 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) !void {

zcu.compile_log_text.shrinkAndFree(gpa, 0);

zcu.skip_analysis_errors = false;

// Make sure std.zig is inside the import_table. We unconditionally need
// it for start.zig.
const std_mod = zcu.std_mod;
Expand Down Expand Up @@ -3208,7 +3210,7 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {
});
}

if (comp.zcu) |zcu| {
if (comp.zcu) |zcu| zcu_errors: {
for (zcu.failed_files.keys(), zcu.failed_files.values()) |file, error_msg| {
if (error_msg) |msg| {
try addModuleErrorMsg(zcu, &bundle, msg.*);
Expand All @@ -3225,6 +3227,7 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {
}
}
}
if (zcu.skip_analysis_errors) break :zcu_errors;
var sorted_failed_analysis: std.AutoArrayHashMapUnmanaged(InternPool.AnalUnit, *Zcu.ErrorMsg).DataList.Slice = s: {
const SortOrder = struct {
zcu: *Zcu,
Expand Down Expand Up @@ -3360,7 +3363,7 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {
try comp.link_diags.addMessagesToBundle(&bundle, comp.bin_file);

if (comp.zcu) |zcu| {
if (bundle.root_list.items.len == 0 and zcu.compile_log_sources.count() != 0) {
if (!zcu.skip_analysis_errors and bundle.root_list.items.len == 0 and zcu.compile_log_sources.count() != 0) {
const values = zcu.compile_log_sources.values();
// First one will be the error; subsequent ones will be notes.
const src_loc = values[0].src();
Expand Down Expand Up @@ -3861,10 +3864,9 @@ fn performAllTheWorkInner(
// We give up right now! No updating of ZIR refs, no nothing. The idea is that this prevents
// us from invalidating lots of incremental dependencies due to files with e.g. parse errors.
// However, this means our analysis data is invalid, so we want to omit all analysis errors.
// To do that, let's just clear the analysis roots!

assert(zcu.failed_files.count() > 0); // we will get an error
zcu.analysis_roots.clear(); // no analysis happened
zcu.skip_analysis_errors = true;
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/InternPool.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4011,7 +4011,7 @@ pub const LoadedStructType = struct {

pub fn haveFieldTypes(s: LoadedStructType, ip: *const InternPool) bool {
const types = s.field_types.get(ip);
return types.len == 0 or types[0] != .none;
return types.len == 0 or types[types.len - 1] != .none;
}

pub fn haveFieldInits(s: LoadedStructType, ip: *const InternPool) bool {
Expand Down
Loading

0 comments on commit 43e52ec

Please sign in to comment.