Skip to content

Commit 43e219b

Browse files
committed
Merge branch 'master' of github.com:ziglang/zig
2 parents f86ea79 + 6a78b31 commit 43e219b

File tree

3 files changed

+49
-8
lines changed

3 files changed

+49
-8
lines changed

src/ir.cpp

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,28 @@ static void ir_ref_var(ZigVar *var) {
356356
var->ref_count += 1;
357357
}
358358

359+
ZigType *ir_analyze_type_expr(IrAnalyze *ira, Scope *scope, AstNode *node) {
360+
ConstExprValue *result = ir_eval_const_value( ira->codegen
361+
, scope
362+
, node
363+
, ira->codegen->builtin_types.entry_type
364+
, ira->new_irb.exec->backward_branch_count
365+
, ira->new_irb.exec->backward_branch_quota
366+
, nullptr
367+
, nullptr
368+
, node
369+
, nullptr
370+
, ira->new_irb.exec
371+
, nullptr
372+
);
373+
374+
if (type_is_invalid(result->type))
375+
return ira->codegen->builtin_types.entry_invalid;
376+
377+
assert(result->special != ConstValSpecialRuntime);
378+
return result->data.x_type;
379+
}
380+
359381
static IrBasicBlock *ir_create_basic_block(IrBuilder *irb, Scope *scope, const char *name_hint) {
360382
IrBasicBlock *result = allocate<IrBasicBlock>(1);
361383
result->scope = scope;
@@ -13875,7 +13897,7 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node
1387513897
IrInstruction *casted_arg;
1387613898
if (param_decl_node->data.param_decl.var_token == nullptr) {
1387713899
AstNode *param_type_node = param_decl_node->data.param_decl.type;
13878-
ZigType *param_type = analyze_type_expr(ira->codegen, *exec_scope, param_type_node);
13900+
ZigType *param_type = ir_analyze_type_expr(ira, *exec_scope, param_type_node);
1387913901
if (type_is_invalid(param_type))
1388013902
return false;
1388113903

@@ -13915,7 +13937,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
1391513937
} else {
1391613938
if (param_decl_node->data.param_decl.var_token == nullptr) {
1391713939
AstNode *param_type_node = param_decl_node->data.param_decl.type;
13918-
ZigType *param_type = analyze_type_expr(ira->codegen, *child_scope, param_type_node);
13940+
ZigType *param_type = ir_analyze_type_expr(ira, *child_scope, param_type_node);
1391913941
if (type_is_invalid(param_type))
1392013942
return false;
1392113943

@@ -14296,7 +14318,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call
1429614318
}
1429714319

1429814320
AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type;
14299-
ZigType *specified_return_type = analyze_type_expr(ira->codegen, exec_scope, return_type_node);
14321+
ZigType *specified_return_type = ir_analyze_type_expr(ira, exec_scope, return_type_node);
1430014322
if (type_is_invalid(specified_return_type))
1430114323
return ira->codegen->invalid_instruction;
1430214324
ZigType *return_type;
@@ -14532,7 +14554,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call
1453214554

1453314555
if (fn_proto_node->data.fn_proto.return_var_token == nullptr) {
1453414556
AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type;
14535-
ZigType *specified_return_type = analyze_type_expr(ira->codegen, impl_fn->child_scope, return_type_node);
14557+
ZigType *specified_return_type = ir_analyze_type_expr(ira, impl_fn->child_scope, return_type_node);
1453614558
if (type_is_invalid(specified_return_type))
1453714559
return ira->codegen->invalid_instruction;
1453814560
if (fn_proto_node->data.fn_proto.auto_err_set) {
@@ -14559,7 +14581,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call
1455914581
if (call_instruction->is_async) {
1456014582
AstNode *async_allocator_type_node = fn_proto_node->data.fn_proto.async_allocator_type;
1456114583
if (async_allocator_type_node != nullptr) {
14562-
ZigType *async_allocator_type = analyze_type_expr(ira->codegen, impl_fn->child_scope, async_allocator_type_node);
14584+
ZigType *async_allocator_type = ir_analyze_type_expr(ira, impl_fn->child_scope, async_allocator_type_node);
1456314585
if (type_is_invalid(async_allocator_type))
1456414586
return ira->codegen->invalid_instruction;
1456514587
inst_fn_type_id.async_allocator_type = async_allocator_type;

std/hash_map.zig

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3
175175
return hm.get(key) != null;
176176
}
177177

178-
pub fn remove(hm: *Self, key: K) ?*KV {
178+
pub fn remove(hm: *Self, key: K) ?KV {
179179
if (hm.entries.len == 0) return null;
180180
hm.incrementModificationCount();
181181
const start_index = hm.keyToIndex(key);
@@ -189,13 +189,14 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3
189189

190190
if (!eql(entry.kv.key, key)) continue;
191191

192+
const removed_kv = entry.kv;
192193
while (roll_over < hm.entries.len) : (roll_over += 1) {
193194
const next_index = (start_index + roll_over + 1) % hm.entries.len;
194195
const next_entry = &hm.entries[next_index];
195196
if (!next_entry.used or next_entry.distance_from_start_index == 0) {
196197
entry.used = false;
197198
hm.size -= 1;
198-
return &entry.kv;
199+
return removed_kv;
199200
}
200201
entry.* = next_entry.*;
201202
entry.distance_from_start_index -= 1;
@@ -371,7 +372,10 @@ test "basic hash map usage" {
371372

372373
testing.expect(map.contains(2));
373374
testing.expect(map.get(2).?.value == 22);
374-
_ = map.remove(2);
375+
376+
const rmv1 = map.remove(2);
377+
testing.expect(rmv1.?.key == 2);
378+
testing.expect(rmv1.?.value == 22);
375379
testing.expect(map.remove(2) == null);
376380
testing.expect(map.get(2) == null);
377381
}

test/compile_errors.zig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,21 @@ const tests = @import("tests.zig");
22
const builtin = @import("builtin");
33

44
pub fn addCases(cases: *tests.CompileErrorContext) void {
5+
cases.add(
6+
"Generic function where return type is self-referenced",
7+
\\fn Foo(comptime T: type) Foo(T) {
8+
\\ return struct{ x: T };
9+
\\}
10+
\\export fn entry() void {
11+
\\ const t = Foo(u32) {
12+
\\ .x = 1
13+
\\ };
14+
\\}
15+
,
16+
"tmp.zig:1:29: error: evaluation exceeded 1000 backwards branches",
17+
"tmp.zig:1:29: note: called from here",
18+
);
19+
520
cases.add(
621
"@ptrToInt 0 to non optional pointer",
722
\\export fn entry() void {

0 commit comments

Comments
 (0)