Skip to content

Commit

Permalink
initial round of @Vexu's review
Browse files Browse the repository at this point in the history
  • Loading branch information
g-w1 committed Dec 26, 2020
1 parent 4533a04 commit 70088f9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 19 deletions.
9 changes: 5 additions & 4 deletions src/Module.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2822,10 +2822,6 @@ pub fn coerce(self: *Module, scope: *Scope, dest_type: Type, inst: *Inst) !*Inst
}
}

// comptime known number to other number
if (try self.coerceNum(scope, dest_type, inst)) |some|
return some;

// error set widening
if (inst.ty.zigTypeTag() == .ErrorSet and dest_type.zigTypeTag() == .ErrorSet) {
const gotten_err_set = inst.ty.getErrs();
Expand Down Expand Up @@ -2889,6 +2885,11 @@ pub fn coerce(self: *Module, scope: *Scope, dest_type: Type, inst: *Inst) !*Inst
else => unreachable,
}
}

// comptime known number to other number
if (try self.coerceNum(scope, dest_type, inst)) |some|
return some;

// integer widening
if (inst.ty.zigTypeTag() == .Int and dest_type.zigTypeTag() == .Int) {
assert(inst.value() == null); // handled above
Expand Down
13 changes: 4 additions & 9 deletions src/type.zig
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,9 @@ pub const Type = extern union {
.ErrorSet => {
if (a.tag() == .anyerror) {
if (b.tag() == .anyerror)
return true;
return false;
return true
else
return false;
}

if (a.tag() == .error_set_single and b.tag() == .error_set_single) {
Expand Down Expand Up @@ -260,15 +261,9 @@ pub const Type = extern union {
return false;
}
}
var b_fields_it = b_fields.iterator();
while (b_fields_it.next()) |entry| {
if (!a_fields.contains(entry.key)) {
return false;
}
}
return true;
}
return false;
unreachable;
},
.ErrorUnion => {
const a_casted = a.cast(Payload.ErrorUnion).?;
Expand Down
2 changes: 1 addition & 1 deletion src/value.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1240,7 +1240,7 @@ pub const Value = extern union {
const b_name = @fieldParentPtr(Payload.Bytes, "base", b.ptr_otherwise).data;
return std.mem.eql(u8, a_name, b_name);
} else if (a.tag() == .@"error" and b.tag() == .@"error") {
return std.mem.eql(u8, a.cast(Payload.Error).?.name, b.cast(Payload.Error).?.name);
return a.cast(Payload.Error).?.value == b.cast(Payload.Error).?.value;
}
}
if (a.isType() and b.isType()) {
Expand Down
9 changes: 4 additions & 5 deletions src/zir_sema.zig
Original file line number Diff line number Diff line change
Expand Up @@ -892,17 +892,16 @@ fn analyzeInstMergeErrorSets(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp)
.err_single => 1,
.multiple => |mul| mul.size,
else => unreachable,
})); // TODO should we do this? only true when no overlapping
}));

switch (lhs_fields) {
.err_single => |name| {
const entry = try mod.getErrorValue(name);
payload.fields.putAssumeCapacity(entry.key, entry.value);
const entry = mod.global_error_set.get(name).?;
payload.fields.putAssumeCapacity(name, entry);
},
.multiple => |multiple| {
var it = multiple.iterator();
while (it.next()) |name| {
const entry = try mod.getErrorValue(name.key);
while (it.next()) |entry| {
payload.fields.putAssumeCapacity(entry.key, entry.value);
}
},
Expand Down

0 comments on commit 70088f9

Please sign in to comment.