mirror of
https://github.com/ziglang/zig.git
synced 2025-12-14 18:23:12 +00:00
stage2: fix comptime_float negation
This commit is contained in:
parent
3df19b765d
commit
a0c44e806b
51
src/Sema.zig
51
src/Sema.zig
@ -6639,9 +6639,9 @@ fn zirNegate(
|
|||||||
defer tracy.end();
|
defer tracy.end();
|
||||||
|
|
||||||
const inst_data = sema.code.instructions.items(.data)[inst].un_node;
|
const inst_data = sema.code.instructions.items(.data)[inst].un_node;
|
||||||
const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };
|
const src = inst_data.src();
|
||||||
const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
|
const lhs_src = src;
|
||||||
const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
|
const rhs_src = src; // TODO better source location
|
||||||
const lhs = sema.resolveInst(.zero);
|
const lhs = sema.resolveInst(.zero);
|
||||||
const rhs = sema.resolveInst(inst_data.operand);
|
const rhs = sema.resolveInst(inst_data.operand);
|
||||||
|
|
||||||
@ -9909,7 +9909,8 @@ fn zirCDefine(
|
|||||||
const src: LazySrcLoc = .{ .node_offset = extra.node };
|
const src: LazySrcLoc = .{ .node_offset = extra.node };
|
||||||
|
|
||||||
const name = try sema.resolveConstString(block, src, extra.lhs);
|
const name = try sema.resolveConstString(block, src, extra.lhs);
|
||||||
if (sema.typeOf(extra.rhs).zigTypeTag() != .Void) {
|
const rhs = sema.resolveInst(extra.rhs);
|
||||||
|
if (sema.typeOf(rhs).zigTypeTag() != .Void) {
|
||||||
const value = try sema.resolveConstString(block, src, extra.rhs);
|
const value = try sema.resolveConstString(block, src, extra.rhs);
|
||||||
try block.c_import_buf.?.writer().print("#define {s} {s}\n", .{ name, value });
|
try block.c_import_buf.?.writer().print("#define {s} {s}\n", .{ name, value });
|
||||||
} else {
|
} else {
|
||||||
@ -12085,16 +12086,19 @@ fn resolvePeerTypes(
|
|||||||
const chosen_ty = sema.typeOf(chosen);
|
const chosen_ty = sema.typeOf(chosen);
|
||||||
if (candidate_ty.eql(chosen_ty))
|
if (candidate_ty.eql(chosen_ty))
|
||||||
continue;
|
continue;
|
||||||
if (candidate_ty.zigTypeTag() == .NoReturn)
|
const candidate_ty_tag = candidate_ty.zigTypeTag();
|
||||||
|
const chosen_ty_tag = chosen_ty.zigTypeTag();
|
||||||
|
|
||||||
|
if (candidate_ty_tag == .NoReturn)
|
||||||
continue;
|
continue;
|
||||||
if (chosen_ty.zigTypeTag() == .NoReturn) {
|
if (chosen_ty_tag == .NoReturn) {
|
||||||
chosen = candidate;
|
chosen = candidate;
|
||||||
chosen_i = candidate_i + 1;
|
chosen_i = candidate_i + 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (candidate_ty.zigTypeTag() == .Undefined)
|
if (candidate_ty_tag == .Undefined)
|
||||||
continue;
|
continue;
|
||||||
if (chosen_ty.zigTypeTag() == .Undefined) {
|
if (chosen_ty_tag == .Undefined) {
|
||||||
chosen = candidate;
|
chosen = candidate;
|
||||||
chosen_i = candidate_i + 1;
|
chosen_i = candidate_i + 1;
|
||||||
continue;
|
continue;
|
||||||
@ -12117,30 +12121,41 @@ fn resolvePeerTypes(
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chosen_ty.zigTypeTag() == .ComptimeInt and candidate_ty.isInt()) {
|
if (chosen_ty_tag == .ComptimeInt and candidate_ty.isInt()) {
|
||||||
chosen = candidate;
|
chosen = candidate;
|
||||||
chosen_i = candidate_i + 1;
|
chosen_i = candidate_i + 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chosen_ty.isInt() and candidate_ty.zigTypeTag() == .ComptimeInt) {
|
if (chosen_ty.isInt() and candidate_ty_tag == .ComptimeInt) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chosen_ty.zigTypeTag() == .ComptimeFloat and candidate_ty.isRuntimeFloat()) {
|
if ((chosen_ty_tag == .ComptimeFloat or chosen_ty_tag == .ComptimeInt) and
|
||||||
|
candidate_ty.isRuntimeFloat())
|
||||||
|
{
|
||||||
|
chosen = candidate;
|
||||||
|
chosen_i = candidate_i + 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (chosen_ty.isRuntimeFloat() and
|
||||||
|
(candidate_ty_tag == .ComptimeFloat or candidate_ty_tag == .ComptimeInt))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (chosen_ty_tag == .Enum and candidate_ty_tag == .EnumLiteral) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (chosen_ty_tag == .EnumLiteral and candidate_ty_tag == .Enum) {
|
||||||
chosen = candidate;
|
chosen = candidate;
|
||||||
chosen_i = candidate_i + 1;
|
chosen_i = candidate_i + 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chosen_ty.isRuntimeFloat() and candidate_ty.zigTypeTag() == .ComptimeFloat) {
|
if (chosen_ty_tag == .ComptimeFloat and candidate_ty_tag == .ComptimeInt)
|
||||||
continue;
|
continue;
|
||||||
}
|
if (chosen_ty_tag == .ComptimeInt and candidate_ty_tag == .ComptimeFloat) {
|
||||||
|
|
||||||
if (chosen_ty.zigTypeTag() == .Enum and candidate_ty.zigTypeTag() == .EnumLiteral) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (chosen_ty.zigTypeTag() == .EnumLiteral and candidate_ty.zigTypeTag() == .Enum) {
|
|
||||||
chosen = candidate;
|
chosen = candidate;
|
||||||
chosen_i = candidate_i + 1;
|
chosen_i = candidate_i + 1;
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@ -183,3 +183,37 @@ test "@setEvalBranchQuota" {
|
|||||||
try expect(sum == 500500);
|
try expect(sum == 500500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "constant struct with negation" {
|
||||||
|
try expect(vertices[0].x == @as(f32, -0.6));
|
||||||
|
}
|
||||||
|
const Vertex = struct {
|
||||||
|
x: f32,
|
||||||
|
y: f32,
|
||||||
|
r: f32,
|
||||||
|
g: f32,
|
||||||
|
b: f32,
|
||||||
|
};
|
||||||
|
const vertices = [_]Vertex{
|
||||||
|
Vertex{
|
||||||
|
.x = -0.6,
|
||||||
|
.y = -0.4,
|
||||||
|
.r = 1.0,
|
||||||
|
.g = 0.0,
|
||||||
|
.b = 0.0,
|
||||||
|
},
|
||||||
|
Vertex{
|
||||||
|
.x = 0.6,
|
||||||
|
.y = -0.4,
|
||||||
|
.r = 0.0,
|
||||||
|
.g = 1.0,
|
||||||
|
.b = 0.0,
|
||||||
|
},
|
||||||
|
Vertex{
|
||||||
|
.x = 0.0,
|
||||||
|
.y = 0.6,
|
||||||
|
.r = 0.0,
|
||||||
|
.g = 0.0,
|
||||||
|
.b = 1.0,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|||||||
@ -41,40 +41,6 @@ pub fn vec3(x: f32, y: f32, z: f32) Vec3 {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
test "constant struct with negation" {
|
|
||||||
try expect(vertices[0].x == -0.6);
|
|
||||||
}
|
|
||||||
const Vertex = struct {
|
|
||||||
x: f32,
|
|
||||||
y: f32,
|
|
||||||
r: f32,
|
|
||||||
g: f32,
|
|
||||||
b: f32,
|
|
||||||
};
|
|
||||||
const vertices = [_]Vertex{
|
|
||||||
Vertex{
|
|
||||||
.x = -0.6,
|
|
||||||
.y = -0.4,
|
|
||||||
.r = 1.0,
|
|
||||||
.g = 0.0,
|
|
||||||
.b = 0.0,
|
|
||||||
},
|
|
||||||
Vertex{
|
|
||||||
.x = 0.6,
|
|
||||||
.y = -0.4,
|
|
||||||
.r = 0.0,
|
|
||||||
.g = 1.0,
|
|
||||||
.b = 0.0,
|
|
||||||
},
|
|
||||||
Vertex{
|
|
||||||
.x = 0.0,
|
|
||||||
.y = 0.6,
|
|
||||||
.r = 0.0,
|
|
||||||
.g = 0.0,
|
|
||||||
.b = 1.0,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
test "statically initialized struct" {
|
test "statically initialized struct" {
|
||||||
st_init_str_foo.x += 1;
|
st_init_str_foo.x += 1;
|
||||||
try expect(st_init_str_foo.x == 14);
|
try expect(st_init_str_foo.x == 14);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user