authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-10-08 13:41:13-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-10-08 13:41:13-04:00
log784a493dc7114b6e6807c2a37d03dbadecee81e6
treeb2a9709664aed3f9a2d53aa4c233a3887aa93984
parent03a6b33a73612500038635633d4c8326c2b5cf5f
signaturelock-open Commit is signed but in an unrecognized format.

generated docs: functions with inferred error sets display nicely

infrastructure in place for displaying error sets

6 files changed, 156 insertions(+), 20 deletions(-)

lib/std/special/docs/index.html+1
...@@ -262,6 +262,7 @@...@@ -262,6 +262,7 @@
262 </div>262 </div>
263 <h1 id="hdrName" class="hidden"></h1>263 <h1 id="hdrName" class="hidden"></h1>
264 <div id="fnDocs" class="hidden"></div>264 <div id="fnDocs" class="hidden"></div>
265 <div id="fnErrors" class="hidden"></div>
265 <div id="fnExamples" class="hidden"></div>266 <div id="fnExamples" class="hidden"></div>
266 <div id="fnNoExamples" class="hidden">267 <div id="fnNoExamples" class="hidden">
267 <p>This function is not tested or referenced.</p>268 <p>This function is not tested or referenced.</p>
lib/std/special/docs/main.js+56-8
...@@ -11,6 +11,7 @@...@@ -11,6 +11,7 @@
11 var domFnProto = document.getElementById("fnProto");11 var domFnProto = document.getElementById("fnProto");
12 var domFnProtoCode = document.getElementById("fnProtoCode");12 var domFnProtoCode = document.getElementById("fnProtoCode");
13 var domFnDocs = document.getElementById("fnDocs");13 var domFnDocs = document.getElementById("fnDocs");
14 var domFnErrors = document.getElementById("fnErrors");
14 var domFnExamples = document.getElementById("fnExamples");15 var domFnExamples = document.getElementById("fnExamples");
15 var domFnNoExamples = document.getElementById("fnNoExamples");16 var domFnNoExamples = document.getElementById("fnNoExamples");
16 var domSearch = document.getElementById("search");17 var domSearch = document.getElementById("search");
...@@ -33,6 +34,8 @@...@@ -33,6 +34,8 @@
33 var typeKindFloatId;34 var typeKindFloatId;
34 var typeKindIntId;35 var typeKindIntId;
35 var typeKindBoolId;36 var typeKindBoolId;
37 var typeKindErrSetId;
38 var typeKindErrUnionId;
36 findTypeKinds();39 findTypeKinds();
3740
38 // for each package, is an array with packages to get to this one41 // for each package, is an array with packages to get to this one
...@@ -96,6 +99,7 @@...@@ -96,6 +99,7 @@
96 domSectInfo.classList.add("hidden");99 domSectInfo.classList.add("hidden");
97 domHdrName.classList.add("hidden");100 domHdrName.classList.add("hidden");
98 domSectNav.classList.add("hidden");101 domSectNav.classList.add("hidden");
102 domFnErrors.classList.add("hidden");
99 domFnExamples.classList.add("hidden");103 domFnExamples.classList.add("hidden");
100 domFnNoExamples.classList.add("hidden");104 domFnNoExamples.classList.add("hidden");
101105
...@@ -183,7 +187,7 @@...@@ -183,7 +187,7 @@
183187
184 protoHtml += ') ';188 protoHtml += ') ';
185 if (typeObj.ret != null) {189 if (typeObj.ret != null) {
186 protoHtml += typeIndexName(typeObj.ret, true, true);190 protoHtml += typeIndexName(typeObj.ret, true, true, fnDecl.value);
187 } else {191 } else {
188 protoHtml += '<span class="tok-kw">var</span>';192 protoHtml += '<span class="tok-kw">var</span>';
189 }193 }
...@@ -335,24 +339,24 @@...@@ -335,24 +339,24 @@
335 }339 }
336 }340 }
337341
338 function typeIndexName(typeIndex, wantHtml, wantLink) {342 function typeIndexName(typeIndex, wantHtml, wantLink, fnIndex) {
339 var typeObj = zigAnalysis.types[typeIndex];343 var typeObj = zigAnalysis.types[typeIndex];
340 if (wantLink) {344 if (wantLink) {
341 var declIndex = getCanonTypeDecl(typeIndex);345 var declIndex = getCanonTypeDecl(typeIndex);
342 var declPath = getCanonDeclPath(declIndex);346 var declPath = getCanonDeclPath(declIndex);
343 var haveLink = declPath != null;347 var haveLink = declPath != null;
344 var typeNameHtml = typeName(typeObj, true, !haveLink);348 var typeNameHtml = typeName(typeObj, true, !haveLink, fnIndex);
345 if (haveLink) {349 if (haveLink) {
346 return '<a href="' + navLink(declPath.pkgNames, declPath.declNames) + '">' + typeNameHtml + '</a>';350 return '<a href="' + navLink(declPath.pkgNames, declPath.declNames) + '">' + typeNameHtml + '</a>';
347 } else {351 } else {
348 return typeNameHtml;352 return typeNameHtml;
349 }353 }
350 } else {354 } else {
351 return typeName(typeObj, wantHtml);355 return typeName(typeObj, wantHtml, false, fnIndex);
352 }356 }
353 }357 }
354358
355 function typeName(typeObj, wantHtml, wantSubLink) {359 function typeName(typeObj, wantHtml, wantSubLink, fnIndex) {
356 switch (typeObj.kind) {360 switch (typeObj.kind) {
357 case typeKindPtrId:361 case typeKindPtrId:
358 var name = "";362 var name = "";
...@@ -397,11 +401,22 @@...@@ -397,11 +401,22 @@
397 name += typeObj.align;401 name += typeObj.align;
398 }402 }
399 if (typeObj.hostIntBytes != null) {403 if (typeObj.hostIntBytes != null) {
400 name += ":" + typeObj.bitOffsetInHost + ":" + typeObj.hostIntBytes;404 name += ":";
405 if (wantHtml) {
406 name += '<span class="tok-number">' + typeObj.bitOffsetInHost + '</span>';
407 } else {
408 name += typeObj.bitOffsetInHost;
409 }
410 name += ":";
411 if (wantHtml) {
412 name += '<span class="tok-number">' + typeObj.hostIntBytes + '</span>';
413 } else {
414 name += typeObj.hostIntBytes;
415 }
401 }416 }
402 name += ") ";417 name += ") ";
403 }418 }
404 name += typeIndexName(typeObj.elem, wantHtml, wantSubLink);419 name += typeIndexName(typeObj.elem, wantHtml, wantSubLink, null);
405 return name;420 return name;
406 case typeKindFloatId:421 case typeKindFloatId:
407 if (wantHtml) {422 if (wantHtml) {
...@@ -429,6 +444,29 @@...@@ -429,6 +444,29 @@
429 } else {444 } else {
430 return "bool";445 return "bool";
431 }446 }
447 case typeKindErrSetId:
448 if (typeObj.errors == null) {
449 if (wantHtml) {
450 return '<span class="tok-type">anyerror</span>';
451 } else {
452 return "anyerror";
453 }
454 } else {
455 if (wantHtml) {
456 return escapeHtml(typeObj.name);
457 } else {
458 return typeObj.name;
459 }
460 }
461 case typeKindErrUnionId:
462 var errSetTypeObj = zigAnalysis.types[typeObj.err];
463 var payloadHtml = typeIndexName(typeObj.payload, wantHtml, wantSubLink, null);
464 if (errSetTypeObj.fn != null && errSetTypeObj.fn == fnIndex) {
465 // function index parameter supplied and this is the inferred error set of it
466 return "!" + payloadHtml;
467 } else {
468 return typeIndexName(typeObj.err, wantHtml, wantSubLink, null) + "!" + payloadHtml;
469 }
432 default:470 default:
433 if (wantHtml) {471 if (wantHtml) {
434 return escapeHtml(typeObj.name);472 return escapeHtml(typeObj.name);
...@@ -439,7 +477,7 @@...@@ -439,7 +477,7 @@
439 }477 }
440478
441 function renderType(typeObj) {479 function renderType(typeObj) {
442 var name = typeName(typeObj);480 var name = typeName(typeObj, false, false);
443 if (name != null && name != "") {481 if (name != null && name != "") {
444 domHdrName.innerText = zigAnalysis.typeKinds[typeObj.kind] + " " + name;482 domHdrName.innerText = zigAnalysis.typeKinds[typeObj.kind] + " " + name;
445 domHdrName.classList.remove("hidden");483 domHdrName.classList.remove("hidden");
...@@ -543,6 +581,10 @@...@@ -543,6 +581,10 @@
543 typeKindIntId = i;581 typeKindIntId = i;
544 } else if (zigAnalysis.typeKinds[i] === "Bool") {582 } else if (zigAnalysis.typeKinds[i] === "Bool") {
545 typeKindBoolId = i;583 typeKindBoolId = i;
584 } else if (zigAnalysis.typeKinds[i] === "ErrorSet") {
585 typeKindErrSetId = i;
586 } else if (zigAnalysis.typeKinds[i] === "ErrorUnion") {
587 typeKindErrUnionId = i;
546 }588 }
547 }589 }
548 if (typeKindTypeId == null) {590 if (typeKindTypeId == null) {
...@@ -563,6 +605,12 @@...@@ -563,6 +605,12 @@
563 if (typeKindBoolId == null) {605 if (typeKindBoolId == null) {
564 throw new Error("No type kind 'Bool' found");606 throw new Error("No type kind 'Bool' found");
565 }607 }
608 if (typeKindErrSetId == null) {
609 throw new Error("No type kind 'ErrorSet' found");
610 }
611 if (typeKindErrUnionId == null) {
612 throw new Error("No type kind 'ErrorUnion' found");
613 }
566 }614 }
567615
568 function findTypeTypeId() {616 function findTypeTypeId() {
src/all_types.hpp+5-1
...@@ -1290,9 +1290,10 @@ struct ZigTypeErrorUnion {...@@ -1290,9 +1290,10 @@ struct ZigTypeErrorUnion {
1290};1290};
12911291
1292struct ZigTypeErrorSet {1292struct ZigTypeErrorSet {
1293 uint32_t err_count;
1294 ErrorTableEntry **errors;1293 ErrorTableEntry **errors;
1295 ZigFn *infer_fn;1294 ZigFn *infer_fn;
1295 uint32_t err_count;
1296 bool incomplete;
1296};1297};
12971298
1298struct ZigTypeEnum {1299struct ZigTypeEnum {
...@@ -1328,6 +1329,9 @@ bool node_ptr_eql(const AstNode *a, const AstNode *b);...@@ -1328,6 +1329,9 @@ bool node_ptr_eql(const AstNode *a, const AstNode *b);
1328uint32_t fn_ptr_hash(const ZigFn *ptr);1329uint32_t fn_ptr_hash(const ZigFn *ptr);
1329bool fn_ptr_eql(const ZigFn *a, const ZigFn *b);1330bool fn_ptr_eql(const ZigFn *a, const ZigFn *b);
13301331
1332uint32_t err_ptr_hash(const ErrorTableEntry *ptr);
1333bool err_ptr_eql(const ErrorTableEntry *a, const ErrorTableEntry *b);
1334
1331struct ZigTypeUnion {1335struct ZigTypeUnion {
1332 AstNode *decl_node;1336 AstNode *decl_node;
1333 TypeUnionField *fields;1337 TypeUnionField *fields;
src/analyze.cpp+19-6
...@@ -1633,6 +1633,7 @@ ZigType *get_auto_err_set_type(CodeGen *g, ZigFn *fn_entry) {...@@ -1633,6 +1633,7 @@ ZigType *get_auto_err_set_type(CodeGen *g, ZigFn *fn_entry) {
1633 err_set_type->data.error_set.err_count = 0;1633 err_set_type->data.error_set.err_count = 0;
1634 err_set_type->data.error_set.errors = nullptr;1634 err_set_type->data.error_set.errors = nullptr;
1635 err_set_type->data.error_set.infer_fn = fn_entry;1635 err_set_type->data.error_set.infer_fn = fn_entry;
1636 err_set_type->data.error_set.incomplete = true;
1636 err_set_type->size_in_bits = g->builtin_types.entry_global_error_set->size_in_bits;1637 err_set_type->size_in_bits = g->builtin_types.entry_global_error_set->size_in_bits;
1637 err_set_type->abi_align = g->builtin_types.entry_global_error_set->abi_align;1638 err_set_type->abi_align = g->builtin_types.entry_global_error_set->abi_align;
1638 err_set_type->abi_size = g->builtin_types.entry_global_error_set->abi_size;1639 err_set_type->abi_size = g->builtin_types.entry_global_error_set->abi_size;
...@@ -4277,12 +4278,12 @@ static void define_local_param_variables(CodeGen *g, ZigFn *fn_table_entry) {...@@ -4277,12 +4278,12 @@ static void define_local_param_variables(CodeGen *g, ZigFn *fn_table_entry) {
4277bool resolve_inferred_error_set(CodeGen *g, ZigType *err_set_type, AstNode *source_node) {4278bool resolve_inferred_error_set(CodeGen *g, ZigType *err_set_type, AstNode *source_node) {
4278 assert(err_set_type->id == ZigTypeIdErrorSet);4279 assert(err_set_type->id == ZigTypeIdErrorSet);
4279 ZigFn *infer_fn = err_set_type->data.error_set.infer_fn;4280 ZigFn *infer_fn = err_set_type->data.error_set.infer_fn;
4280 if (infer_fn != nullptr) {4281 if (infer_fn != nullptr && err_set_type->data.error_set.incomplete) {
4281 if (infer_fn->anal_state == FnAnalStateInvalid) {4282 if (infer_fn->anal_state == FnAnalStateInvalid) {
4282 return false;4283 return false;
4283 } else if (infer_fn->anal_state == FnAnalStateReady) {4284 } else if (infer_fn->anal_state == FnAnalStateReady) {
4284 analyze_fn_body(g, infer_fn);4285 analyze_fn_body(g, infer_fn);
4285 if (err_set_type->data.error_set.infer_fn != nullptr) {4286 if (err_set_type->data.error_set.incomplete) {
4286 assert(g->errors.length != 0);4287 assert(g->errors.length != 0);
4287 return false;4288 return false;
4288 }4289 }
...@@ -4509,7 +4510,9 @@ static void analyze_fn_ir(CodeGen *g, ZigFn *fn, AstNode *return_type_node) {...@@ -4509,7 +4510,9 @@ static void analyze_fn_ir(CodeGen *g, ZigFn *fn, AstNode *return_type_node) {
45094510
4510 if (fn_type_id->return_type->id == ZigTypeIdErrorUnion) {4511 if (fn_type_id->return_type->id == ZigTypeIdErrorUnion) {
4511 ZigType *return_err_set_type = fn_type_id->return_type->data.error_union.err_set_type;4512 ZigType *return_err_set_type = fn_type_id->return_type->data.error_union.err_set_type;
4512 if (return_err_set_type->data.error_set.infer_fn != nullptr) {4513 if (return_err_set_type->data.error_set.infer_fn != nullptr &&
4514 return_err_set_type->data.error_set.incomplete)
4515 {
4513 ZigType *inferred_err_set_type;4516 ZigType *inferred_err_set_type;
4514 if (fn->src_implicit_return_type->id == ZigTypeIdErrorSet) {4517 if (fn->src_implicit_return_type->id == ZigTypeIdErrorSet) {
4515 inferred_err_set_type = fn->src_implicit_return_type;4518 inferred_err_set_type = fn->src_implicit_return_type;
...@@ -4522,14 +4525,16 @@ static void analyze_fn_ir(CodeGen *g, ZigFn *fn, AstNode *return_type_node) {...@@ -4522,14 +4525,16 @@ static void analyze_fn_ir(CodeGen *g, ZigFn *fn, AstNode *return_type_node) {
4522 return;4525 return;
4523 }4526 }
45244527
4525 if (inferred_err_set_type->data.error_set.infer_fn != nullptr) {4528 if (inferred_err_set_type->data.error_set.infer_fn != nullptr &&
4529 inferred_err_set_type->data.error_set.incomplete)
4530 {
4526 if (!resolve_inferred_error_set(g, inferred_err_set_type, return_type_node)) {4531 if (!resolve_inferred_error_set(g, inferred_err_set_type, return_type_node)) {
4527 fn->anal_state = FnAnalStateInvalid;4532 fn->anal_state = FnAnalStateInvalid;
4528 return;4533 return;
4529 }4534 }
4530 }4535 }
45314536
4532 return_err_set_type->data.error_set.infer_fn = nullptr;4537 return_err_set_type->data.error_set.incomplete = false;
4533 if (type_is_global_error_set(inferred_err_set_type)) {4538 if (type_is_global_error_set(inferred_err_set_type)) {
4534 return_err_set_type->data.error_set.err_count = UINT32_MAX;4539 return_err_set_type->data.error_set.err_count = UINT32_MAX;
4535 } else {4540 } else {
...@@ -7336,6 +7341,14 @@ bool fn_ptr_eql(const ZigFn *a, const ZigFn *b) {...@@ -7336,6 +7341,14 @@ bool fn_ptr_eql(const ZigFn *a, const ZigFn *b) {
7336 return a == b;7341 return a == b;
7337}7342}
73387343
7344uint32_t err_ptr_hash(const ErrorTableEntry *ptr) {
7345 return hash_ptr((void*)ptr);
7346}
7347
7348bool err_ptr_eql(const ErrorTableEntry *a, const ErrorTableEntry *b) {
7349 return a == b;
7350}
7351
7339ConstExprValue *get_builtin_value(CodeGen *codegen, const char *name) {7352ConstExprValue *get_builtin_value(CodeGen *codegen, const char *name) {
7340 Tld *tld = get_container_scope(codegen->compile_var_import)->decl_table.get(buf_create_from_str(name));7353 Tld *tld = get_container_scope(codegen->compile_var_import)->decl_table.get(buf_create_from_str(name));
7341 resolve_top_level_decl(codegen, tld, nullptr, false);7354 resolve_top_level_decl(codegen, tld, nullptr, false);
...@@ -7348,7 +7361,7 @@ ConstExprValue *get_builtin_value(CodeGen *codegen, const char *name) {...@@ -7348,7 +7361,7 @@ ConstExprValue *get_builtin_value(CodeGen *codegen, const char *name) {
73487361
7349bool type_is_global_error_set(ZigType *err_set_type) {7362bool type_is_global_error_set(ZigType *err_set_type) {
7350 assert(err_set_type->id == ZigTypeIdErrorSet);7363 assert(err_set_type->id == ZigTypeIdErrorSet);
7351 assert(err_set_type->data.error_set.infer_fn == nullptr);7364 assert(!err_set_type->data.error_set.incomplete);
7352 return err_set_type->data.error_set.err_count == UINT32_MAX;7365 return err_set_type->data.error_set.err_count == UINT32_MAX;
7353}7366}
73547367
src/dump_analysis.cpp+72-2
...@@ -357,6 +357,9 @@ struct AnalDumpCtx {...@@ -357,6 +357,9 @@ struct AnalDumpCtx {
357357
358 ZigList<AstNode *> node_list;358 ZigList<AstNode *> node_list;
359 HashMap<const AstNode *, uint32_t, node_ptr_hash, node_ptr_eql> node_map;359 HashMap<const AstNode *, uint32_t, node_ptr_hash, node_ptr_eql> node_map;
360
361 ZigList<ErrorTableEntry *> err_list;
362 HashMap<const ErrorTableEntry *, uint32_t, err_ptr_hash, err_ptr_eql> err_map;
360};363};
361364
362static uint32_t anal_dump_get_type_id(AnalDumpCtx *ctx, ZigType *ty);365static uint32_t anal_dump_get_type_id(AnalDumpCtx *ctx, ZigType *ty);
...@@ -444,6 +447,17 @@ static uint32_t anal_dump_get_fn_id(AnalDumpCtx *ctx, ZigFn *fn) {...@@ -444,6 +447,17 @@ static uint32_t anal_dump_get_fn_id(AnalDumpCtx *ctx, ZigFn *fn) {
444 return fn_id;447 return fn_id;
445}448}
446449
450static uint32_t anal_dump_get_err_id(AnalDumpCtx *ctx, ErrorTableEntry *err) {
451 uint32_t err_id = ctx->err_list.length;
452 auto existing_entry = ctx->err_map.put_unique(err, err_id);
453 if (existing_entry == nullptr) {
454 ctx->err_list.append(err);
455 } else {
456 err_id = existing_entry->value;
457 }
458 return err_id;
459}
460
447static uint32_t anal_dump_get_decl_id(AnalDumpCtx *ctx, Tld *tld) {461static uint32_t anal_dump_get_decl_id(AnalDumpCtx *ctx, Tld *tld) {
448 uint32_t decl_id = ctx->decl_list.length;462 uint32_t decl_id = ctx->decl_list.length;
449 auto existing_entry = ctx->decl_map.put_unique(tld, decl_id);463 auto existing_entry = ctx->decl_map.put_unique(tld, decl_id);
...@@ -513,6 +527,11 @@ static void anal_dump_fn_ref(AnalDumpCtx *ctx, ZigFn *fn) {...@@ -513,6 +527,11 @@ static void anal_dump_fn_ref(AnalDumpCtx *ctx, ZigFn *fn) {
513 jw_int(&ctx->jw, fn_id);527 jw_int(&ctx->jw, fn_id);
514}528}
515529
530static void anal_dump_err_ref(AnalDumpCtx *ctx, ErrorTableEntry *err) {
531 uint32_t err_id = anal_dump_get_err_id(ctx, err);
532 jw_int(&ctx->jw, err_id);
533}
534
516static void anal_dump_decl_ref(AnalDumpCtx *ctx, Tld *tld) {535static void anal_dump_decl_ref(AnalDumpCtx *ctx, Tld *tld) {
517 uint32_t decl_id = anal_dump_get_decl_id(ctx, tld);536 uint32_t decl_id = anal_dump_get_decl_id(ctx, tld);
518 jw_int(&ctx->jw, decl_id);537 jw_int(&ctx->jw, decl_id);
...@@ -841,6 +860,33 @@ static void anal_dump_type(AnalDumpCtx *ctx, ZigType *ty) {...@@ -841,6 +860,33 @@ static void anal_dump_type(AnalDumpCtx *ctx, ZigType *ty) {
841 anal_dump_pointer_attrs(ctx, ty);860 anal_dump_pointer_attrs(ctx, ty);
842 break;861 break;
843 }862 }
863 case ZigTypeIdErrorSet: {
864 if (type_is_global_error_set(ty)) {
865 break;
866 }
867 if (ty->data.error_set.infer_fn != nullptr) {
868 jw_object_field(jw, "fn");
869 anal_dump_fn_ref(ctx, ty->data.error_set.infer_fn);
870 }
871 jw_object_field(jw, "errors");
872 jw_begin_array(jw);
873 for (uint32_t i = 0; i < ty->data.error_set.err_count; i += 1) {
874 jw_array_elem(jw);
875 ErrorTableEntry *err = ty->data.error_set.errors[i];
876 anal_dump_err_ref(ctx, err);
877 }
878 jw_end_array(jw);
879 break;
880 }
881 case ZigTypeIdErrorUnion: {
882 jw_object_field(jw, "err");
883 anal_dump_type_ref(ctx, ty->data.error_union.err_set_type);
884
885 jw_object_field(jw, "payload");
886 anal_dump_type_ref(ctx, ty->data.error_union.payload_type);
887
888 break;
889 }
844 default:890 default:
845 jw_object_field(jw, "name");891 jw_object_field(jw, "name");
846 jw_string(jw, buf_ptr(&ty->name));892 jw_string(jw, buf_ptr(&ty->name));
...@@ -849,7 +895,7 @@ static void anal_dump_type(AnalDumpCtx *ctx, ZigType *ty) {...@@ -849,7 +895,7 @@ static void anal_dump_type(AnalDumpCtx *ctx, ZigType *ty) {
849 jw_end_object(jw);895 jw_end_object(jw);
850}896}
851897
852void anal_dump_node(AnalDumpCtx *ctx, const AstNode *node) {898static void anal_dump_node(AnalDumpCtx *ctx, const AstNode *node) {
853 JsonWriter *jw = &ctx->jw;899 JsonWriter *jw = &ctx->jw;
854900
855 jw_begin_object(jw);901 jw_begin_object(jw);
...@@ -892,7 +938,21 @@ void anal_dump_node(AnalDumpCtx *ctx, const AstNode *node) {...@@ -892,7 +938,21 @@ void anal_dump_node(AnalDumpCtx *ctx, const AstNode *node) {
892 jw_end_object(jw);938 jw_end_object(jw);
893}939}
894940
895void anal_dump_fn(AnalDumpCtx *ctx, ZigFn *fn) {941static void anal_dump_err(AnalDumpCtx *ctx, const ErrorTableEntry *err) {
942 JsonWriter *jw = &ctx->jw;
943
944 jw_begin_object(jw);
945
946 jw_object_field(jw, "src");
947 anal_dump_node_ref(ctx, err->decl_node);
948
949 jw_object_field(jw, "name");
950 jw_string(jw, buf_ptr(&err->name));
951
952 jw_end_object(jw);
953}
954
955static void anal_dump_fn(AnalDumpCtx *ctx, ZigFn *fn) {
896 JsonWriter *jw = &ctx->jw;956 JsonWriter *jw = &ctx->jw;
897957
898 jw_begin_object(jw);958 jw_begin_object(jw);
...@@ -918,6 +978,7 @@ void zig_print_analysis_dump(CodeGen *g, FILE *f, const char *one_indent, const...@@ -918,6 +978,7 @@ void zig_print_analysis_dump(CodeGen *g, FILE *f, const char *one_indent, const
918 ctx.decl_map.init(16);978 ctx.decl_map.init(16);
919 ctx.node_map.init(16);979 ctx.node_map.init(16);
920 ctx.fn_map.init(16);980 ctx.fn_map.init(16);
981 ctx.err_map.init(16);
921982
922 jw_begin_object(jw);983 jw_begin_object(jw);
923984
...@@ -1055,6 +1116,15 @@ void zig_print_analysis_dump(CodeGen *g, FILE *f, const char *one_indent, const...@@ -1055,6 +1116,15 @@ void zig_print_analysis_dump(CodeGen *g, FILE *f, const char *one_indent, const
1055 }1116 }
1056 jw_end_array(jw);1117 jw_end_array(jw);
10571118
1119 jw_object_field(jw, "errors");
1120 jw_begin_array(jw);
1121 for (uint32_t i = 0; i < ctx.err_list.length; i += 1) {
1122 const ErrorTableEntry *err = ctx.err_list.at(i);
1123 jw_array_elem(jw);
1124 anal_dump_err(&ctx, err);
1125 }
1126 jw_end_array(jw);
1127
1058 jw_object_field(jw, "astNodes");1128 jw_object_field(jw, "astNodes");
1059 jw_begin_array(jw);1129 jw_begin_array(jw);
1060 for (uint32_t i = 0; i < ctx.node_list.length; i += 1) {1130 for (uint32_t i = 0; i < ctx.node_list.length; i += 1) {
src/ir.cpp+3-3
...@@ -9692,7 +9692,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted...@@ -9692,7 +9692,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
9692 ZigType *container_set = wanted_type;9692 ZigType *container_set = wanted_type;
96939693
9694 // if the container set is inferred, then this will always work.9694 // if the container set is inferred, then this will always work.
9695 if (container_set->data.error_set.infer_fn != nullptr) {9695 if (container_set->data.error_set.infer_fn != nullptr && container_set->data.error_set.incomplete) {
9696 return result;9696 return result;
9697 }9697 }
9698 // if the container set is the global one, it will always work.9698 // if the container set is the global one, it will always work.
...@@ -16157,7 +16157,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c...@@ -16157,7 +16157,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
16157 UndefOk);16157 UndefOk);
1615816158
16159 if (inferred_err_set_type != nullptr) {16159 if (inferred_err_set_type != nullptr) {
16160 inferred_err_set_type->data.error_set.infer_fn = nullptr;16160 inferred_err_set_type->data.error_set.incomplete = false;
16161 if (result->type->id == ZigTypeIdErrorUnion) {16161 if (result->type->id == ZigTypeIdErrorUnion) {
16162 ErrorTableEntry *err = result->data.x_err_union.error_set->data.x_err_set;16162 ErrorTableEntry *err = result->data.x_err_union.error_set->data.x_err_set;
16163 if (err != nullptr) {16163 if (err != nullptr) {
...@@ -23617,7 +23617,7 @@ static IrInstruction *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruct...@@ -23617,7 +23617,7 @@ static IrInstruction *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruct
23617 if (!type_is_global_error_set(err_set_type) &&23617 if (!type_is_global_error_set(err_set_type) &&
23618 err_set_type->data.error_set.err_count == 0)23618 err_set_type->data.error_set.err_count == 0)
23619 {23619 {
23620 assert(err_set_type->data.error_set.infer_fn == nullptr);23620 assert(!err_set_type->data.error_set.incomplete);
23621 return ir_const_bool(ira, &instruction->base, false);23621 return ir_const_bool(ira, &instruction->base, false);
23622 }23622 }
23623 }23623 }