authorgravatar for 35231115+Rocknest@users.noreply.github.comRocknest <35231115+Rocknest@users.noreply.github.com> 2019-10-11 01:28:43+03:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2019-10-11 01:28:43+03:00
log352663a34c885eb9b944929ac076806ce2f0d416
treecb4e7c48d6ac2191d23842b3d97ffd6f82c05243
parent429d5f287982cf82ee4229acd44509d782304141
parentd15a71afc95f148966be2f5fd9f66b8396e8293d
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge branch 'master' into docs-local


8 files changed, 280 insertions(+), 55 deletions(-)

lib/std/io.zig+6
...@@ -17,9 +17,15 @@ const File = std.fs.File;...@@ -17,9 +17,15 @@ const File = std.fs.File;
17const testing = std.testing;17const testing = std.testing;
1818
19pub const Mode = enum {19pub const Mode = enum {
20 /// I/O operates normally, waiting for the operating system syscalls to complete.
20 blocking,21 blocking,
22
23 /// I/O functions are generated async and rely on a global event loop. Event-based I/O.
21 evented,24 evented,
22};25};
26
27/// The application's chosen I/O mode. This defaults to `Mode.blocking` but can be overridden
28/// by `root.event_loop`.
23pub const mode: Mode = if (@hasDecl(root, "io_mode"))29pub const mode: Mode = if (@hasDecl(root, "io_mode"))
24 root.io_mode30 root.io_mode
25else if (@hasDecl(root, "event_loop"))31else if (@hasDecl(root, "event_loop"))
lib/std/special/docs/main.js+72-29
...@@ -43,6 +43,7 @@...@@ -43,6 +43,7 @@
4343
44 var typeKinds = indexTypeKinds();44 var typeKinds = indexTypeKinds();
45 var typeTypeId = findTypeTypeId();45 var typeTypeId = findTypeTypeId();
46 var pointerSizeEnum = { One: 0, Many: 1, Slice: 2, C: 3 };
4647
47 // for each package, is an array with packages to get to this one48 // for each package, is an array with packages to get to this one
48 var canonPkgPaths = computeCanonicalPackagePaths();49 var canonPkgPaths = computeCanonicalPackagePaths();
...@@ -376,24 +377,41 @@...@@ -376,24 +377,41 @@
376 }377 }
377 }378 }
378379
379 function typeIndexName(typeIndex, wantHtml, wantLink, fnDecl, skipFnName) {380 function typeIndexName(typeIndex, wantHtml, wantLink, fnDecl, linkFnNameDecl) {
380 var typeObj = zigAnalysis.types[typeIndex];381 var typeObj = zigAnalysis.types[typeIndex];
382 var declNameOk = declCanRepresentTypeKind(typeObj.kind);
381 if (wantLink) {383 if (wantLink) {
382 var declIndex = getCanonTypeDecl(typeIndex);384 var declIndex = getCanonTypeDecl(typeIndex);
383 var declPath = getCanonDeclPath(declIndex);385 var declPath = getCanonDeclPath(declIndex);
384 var haveLink = declPath != null;386 if (declPath == null) {
385 var typeNameHtml = typeName(typeObj, true, !haveLink, fnDecl, skipFnName);387 return typeName(typeObj, wantHtml, wantLink, fnDecl, linkFnNameDecl);
386 if (haveLink) {388 }
387 return '<a href="' + navLink(declPath.pkgNames, declPath.declNames) + '">' + typeNameHtml + '</a>';389 var name = (wantLink && declCanRepresentTypeKind(typeObj.kind)) ?
390 declPath.declNames[declPath.declNames.length - 1] :
391 typeName(typeObj, wantHtml, false, fnDecl, linkFnNameDecl);
392 if (wantLink && wantHtml) {
393 return '<a href="' + navLink(declPath.pkgNames, declPath.declNames) + '">' + name + '</a>';
388 } else {394 } else {
389 return typeNameHtml;395 return name;
390 }396 }
391 } else {397 } else {
392 return typeName(typeObj, wantHtml, false, fnDecl, skipFnName);398 return typeName(typeObj, wantHtml, false, fnDecl, linkFnNameDecl);
393 }399 }
394 }400 }
395401
396 function typeName(typeObj, wantHtml, wantSubLink, fnDecl, skipFnName) {402 function shouldSkipParamName(typeIndex, paramName) {
403 var typeObj = zigAnalysis.types[typeIndex];
404 if (typeObj.kind === typeKinds.Pointer && getPtrSize(typeObj) === pointerSizeEnum.One) {
405 typeIndex = typeObj.elem;
406 }
407 return typeIndexName(typeIndex, false, true).toLowerCase() === paramName;
408 }
409
410 function getPtrSize(typeObj) {
411 return (typeObj.len == null) ? pointerSizeEnum.One : typeObj.len;
412 }
413
414 function typeName(typeObj, wantHtml, wantSubLink, fnDecl, linkFnNameDecl) {
397 switch (typeObj.kind) {415 switch (typeObj.kind) {
398 case typeKinds.Array:416 case typeKinds.Array:
399 var name = "[";417 var name = "[";
...@@ -408,17 +426,17 @@...@@ -408,17 +426,17 @@
408 case typeKinds.Pointer:426 case typeKinds.Pointer:
409 var name = "";427 var name = "";
410 switch (typeObj.len) {428 switch (typeObj.len) {
411 case 0:429 case pointerSizeEnum.One:
412 default:430 default:
413 name += "*";431 name += "*";
414 break;432 break;
415 case 1:433 case pointerSizeEnum.Many:
416 name += "[*]";434 name += "[*]";
417 break;435 break;
418 case 2:436 case pointerSizeEnum.Slice:
419 name += "[]";437 name += "[]";
420 break;438 break;
421 case 3:439 case pointerSizeEnum.C:
422 name += "[*c]";440 name += "[*c]";
423 break;441 break;
424 }442 }
...@@ -542,8 +560,15 @@...@@ -542,8 +560,15 @@
542 var payloadHtml = "";560 var payloadHtml = "";
543 if (wantHtml) {561 if (wantHtml) {
544 payloadHtml += '<span class="tok-kw">fn</span>';562 payloadHtml += '<span class="tok-kw">fn</span>';
545 if (fnDecl != null && !skipFnName) {563 if (fnDecl != null) {
546 payloadHtml += ' <span class="tok-fn">' + escapeHtml(fnDecl.name) + '</span>';564 payloadHtml += ' <span class="tok-fn">';
565 if (linkFnNameDecl != null) {
566 payloadHtml += '<a href="' + linkFnNameDecl + '">' +
567 escapeHtml(fnDecl.name) + '</a>';
568 } else {
569 payloadHtml += escapeHtml(fnDecl.name);
570 }
571 payloadHtml += '</span>';
547 }572 }
548 } else {573 } else {
549 payloadHtml += 'fn'574 payloadHtml += 'fn'
...@@ -554,7 +579,21 @@...@@ -554,7 +579,21 @@
554 if (i != 0) {579 if (i != 0) {
555 payloadHtml += ', ';580 payloadHtml += ', ';
556 }581 }
582
557 var argTypeIndex = typeObj.args[i];583 var argTypeIndex = typeObj.args[i];
584
585 if (fnDecl != null && zigAnalysis.astNodes[fnDecl.src].fields != null) {
586 var paramDeclIndex = zigAnalysis.astNodes[fnDecl.src].fields[i];
587 var paramName = zigAnalysis.astNodes[paramDeclIndex].name;
588
589 if (paramName != null) {
590 // skip if it matches the type name
591 if (argTypeIndex == null || !shouldSkipParamName(argTypeIndex, paramName)) {
592 payloadHtml += paramName + ': ';
593 }
594 }
595 }
596
558 if (argTypeIndex != null) {597 if (argTypeIndex != null) {
559 payloadHtml += typeIndexName(argTypeIndex, wantHtml, wantSubLink);598 payloadHtml += typeIndexName(argTypeIndex, wantHtml, wantSubLink);
560 } else if (wantHtml) {599 } else if (wantHtml) {
...@@ -645,7 +684,7 @@...@@ -645,7 +684,7 @@
645 }684 }
646685
647 function renderValue(decl) {686 function renderValue(decl) {
648 domFnProtoCode.innerHTML = '<span class="tok-kw">pub</span> <span class="tok-kw">const</span> ' +687 domFnProtoCode.innerHTML = '<span class="tok-kw">const</span> ' +
649 escapeHtml(decl.name) + ': ' + typeIndexName(decl.type, true, true);688 escapeHtml(decl.name) + ': ' + typeIndexName(decl.type, true, true);
650689
651 var docs = zigAnalysis.astNodes[decl.src].docs;690 var docs = zigAnalysis.astNodes[decl.src].docs;
...@@ -658,7 +697,7 @@...@@ -658,7 +697,7 @@
658 }697 }
659698
660 function renderVar(decl) {699 function renderVar(decl) {
661 domFnProtoCode.innerHTML = '<span class="tok-kw">pub</span> <span class="tok-kw">var</span> ' +700 domFnProtoCode.innerHTML = '<span class="tok-kw">var</span> ' +
662 escapeHtml(decl.name) + ': ' + typeIndexName(decl.type, true, true);701 escapeHtml(decl.name) + ': ' + typeIndexName(decl.type, true, true);
663702
664 var docs = zigAnalysis.astNodes[decl.src].docs;703 var docs = zigAnalysis.astNodes[decl.src].docs;
...@@ -748,21 +787,15 @@...@@ -748,21 +787,15 @@
748 }787 }
749788
750 if (fnsList.length !== 0) {789 if (fnsList.length !== 0) {
751 resizeDomList(domListFns, fnsList.length,790 resizeDomList(domListFns, fnsList.length, '<tr><td></td><td></td></tr>');
752 '<tr><td><a href="#"></a></td><td></td><td></td></tr>');
753 for (var i = 0; i < fnsList.length; i += 1) {791 for (var i = 0; i < fnsList.length; i += 1) {
754 var decl = fnsList[i];792 var decl = fnsList[i];
755 var trDom = domListFns.children[i];793 var trDom = domListFns.children[i];
756794
757 var tdName = trDom.children[0];795 var tdFnCode = trDom.children[0];
758 var tdNameA = tdName.children[0];796 var tdDesc = trDom.children[1];
759 var tdType = trDom.children[1];
760 var tdDesc = trDom.children[2];
761
762 tdNameA.setAttribute('href', navLinkDecl(decl.name));
763 tdNameA.textContent = decl.name;
764797
765 tdType.innerHTML = typeIndexName(decl.type, true, true, decl, true);798 tdFnCode.innerHTML = typeIndexName(decl.type, true, true, decl, navLinkDecl(decl.name));
766799
767 var docs = zigAnalysis.astNodes[decl.src].docs;800 var docs = zigAnalysis.astNodes[decl.src].docs;
768 if (docs != null) {801 if (docs != null) {
...@@ -776,14 +809,24 @@...@@ -776,14 +809,24 @@
776809
777 if (container.fields != null && container.fields.length !== 0) {810 if (container.fields != null && container.fields.length !== 0) {
778 resizeDomList(domListFields, container.fields.length, '<div></div>');811 resizeDomList(domListFields, container.fields.length, '<div></div>');
812
813 var containerNode = zigAnalysis.astNodes[container.src];
779 for (var i = 0; i < container.fields.length; i += 1) {814 for (var i = 0; i < container.fields.length; i += 1) {
780 var field = container.fields[i];815 var field = container.fields[i];
816 var fieldNode = zigAnalysis.astNodes[containerNode.fields[i]];
781 var divDom = domListFields.children[i];817 var divDom = domListFields.children[i];
782818
783 var html = '<pre>' + escapeHtml(field.name) + ": " +819 var html = '<pre>' + escapeHtml(fieldNode.name);
784 typeIndexName(field.type, true, true) + ',</pre>';820
821 if (container.kind === typeKinds.Enum) {
822 html += ' = <span class="tok-number">' + field + '</span>';
823 } else {
824 html += ": " + typeIndexName(field, true, true);
825 }
826
827 html += ',</pre>';
785828
786 var docs = zigAnalysis.astNodes[field.src].docs;829 var docs = fieldNode.docs;
787 if (docs != null) {830 if (docs != null) {
788 html += markdown(docs);831 html += markdown(docs);
789 }832 }
src/dump_analysis.cpp+176-18
...@@ -216,6 +216,21 @@ static void jw_int(JsonWriter *jw, int64_t x) {...@@ -216,6 +216,21 @@ static void jw_int(JsonWriter *jw, int64_t x) {
216 jw_pop_state(jw);216 jw_pop_state(jw);
217}217}
218218
219static void jw_bigint(JsonWriter *jw, const BigInt *x) {
220 assert(jw->state[jw->state_index] == JsonWriterStateValue);
221 Buf *str = buf_alloc();
222 bigint_append_buf(str, x, 10);
223
224 if (bigint_fits_in_bits(x, 52, true)) {
225 fprintf(jw->f, "%s", buf_ptr(str));
226 } else {
227 fprintf(jw->f, "\"%s\"", buf_ptr(str));
228 }
229 jw_pop_state(jw);
230
231 buf_destroy(str);
232}
233
219static void jw_string(JsonWriter *jw, const char *s) {234static void jw_string(JsonWriter *jw, const char *s) {
220 assert(jw->state[jw->state_index] == JsonWriterStateValue);235 assert(jw->state[jw->state_index] == JsonWriterStateValue);
221 jw_write_escaped_string(jw, s);236 jw_write_escaped_string(jw, s);
...@@ -732,23 +747,6 @@ static void anal_dump_pointer_attrs(AnalDumpCtx *ctx, ZigType *ty) {...@@ -732,23 +747,6 @@ static void anal_dump_pointer_attrs(AnalDumpCtx *ctx, ZigType *ty) {
732 anal_dump_type_ref(ctx, ty->data.pointer.child_type);747 anal_dump_type_ref(ctx, ty->data.pointer.child_type);
733}748}
734749
735static void anal_dump_struct_field(AnalDumpCtx *ctx, const TypeStructField *struct_field) {
736 JsonWriter *jw = &ctx->jw;
737
738 jw_begin_object(jw);
739
740 jw_object_field(jw, "name");
741 jw_string(jw, buf_ptr(struct_field->name));
742
743 jw_object_field(jw, "type");
744 anal_dump_type_ref(ctx, struct_field->type_entry);
745
746 jw_object_field(jw, "src");
747 anal_dump_node_ref(ctx, struct_field->decl_node);
748
749 jw_end_object(jw);
750}
751
752static void anal_dump_type(AnalDumpCtx *ctx, ZigType *ty) {750static void anal_dump_type(AnalDumpCtx *ctx, ZigType *ty) {
753 JsonWriter *jw = &ctx->jw;751 JsonWriter *jw = &ctx->jw;
754 jw_array_elem(jw);752 jw_array_elem(jw);
...@@ -771,6 +769,10 @@ static void anal_dump_type(AnalDumpCtx *ctx, ZigType *ty) {...@@ -771,6 +769,10 @@ static void anal_dump_type(AnalDumpCtx *ctx, ZigType *ty) {
771769
772 jw_object_field(jw, "name");770 jw_object_field(jw, "name");
773 jw_string(jw, buf_ptr(&ty->name));771 jw_string(jw, buf_ptr(&ty->name));
772
773 jw_object_field(jw, "src");
774 anal_dump_node_ref(ctx, ty->data.structure.decl_node);
775
774 {776 {
775 jw_object_field(jw, "pubDecls");777 jw_object_field(jw, "pubDecls");
776 jw_begin_array(jw);778 jw_begin_array(jw);
...@@ -817,7 +819,7 @@ static void anal_dump_type(AnalDumpCtx *ctx, ZigType *ty) {...@@ -817,7 +819,7 @@ static void anal_dump_type(AnalDumpCtx *ctx, ZigType *ty) {
817819
818 for(size_t i = 0; i < ty->data.structure.src_field_count; i += 1) {820 for(size_t i = 0; i < ty->data.structure.src_field_count; i += 1) {
819 jw_array_elem(jw);821 jw_array_elem(jw);
820 anal_dump_struct_field(ctx, &ty->data.structure.fields[i]);822 anal_dump_type_ref(ctx, ty->data.structure.fields[i].type_entry);
821 }823 }
822 jw_end_array(jw);824 jw_end_array(jw);
823 }825 }
...@@ -827,7 +829,124 @@ static void anal_dump_type(AnalDumpCtx *ctx, ZigType *ty) {...@@ -827,7 +829,124 @@ static void anal_dump_type(AnalDumpCtx *ctx, ZigType *ty) {
827829
828 jw_object_field(jw, "file");830 jw_object_field(jw, "file");
829 anal_dump_file_ref(ctx, path_buf);831 anal_dump_file_ref(ctx, path_buf);
832 }
833 break;
834 }
835 case ZigTypeIdUnion: {
836 jw_object_field(jw, "name");
837 jw_string(jw, buf_ptr(&ty->name));
838
839 jw_object_field(jw, "src");
840 anal_dump_node_ref(ctx, ty->data.unionation.decl_node);
841
842 {
843 jw_object_field(jw, "pubDecls");
844 jw_begin_array(jw);
845
846 ScopeDecls *decls_scope = ty->data.unionation.decls_scope;
847 auto it = decls_scope->decl_table.entry_iterator();
848 for (;;) {
849 auto *entry = it.next();
850 if (!entry)
851 break;
852
853 Tld *tld = entry->value;
854 if (tld->visib_mod == VisibModPub) {
855 jw_array_elem(jw);
856 anal_dump_decl_ref(ctx, tld);
857 }
858 }
859 jw_end_array(jw);
860 }
861
862 {
863 jw_object_field(jw, "privDecls");
864 jw_begin_array(jw);
865
866 ScopeDecls *decls_scope = ty->data.unionation.decls_scope;
867 auto it = decls_scope->decl_table.entry_iterator();
868 for (;;) {
869 auto *entry = it.next();
870 if (!entry)
871 break;
872
873 Tld *tld = entry->value;
874 if (tld->visib_mod == VisibModPrivate) {
875 jw_array_elem(jw);
876 anal_dump_decl_ref(ctx, tld);
877 }
878 }
879 jw_end_array(jw);
880 }
881
882 if (ty->data.unionation.src_field_count != 0) {
883 jw_object_field(jw, "fields");
884 jw_begin_array(jw);
885
886 for(size_t i = 0; i < ty->data.unionation.src_field_count; i += 1) {
887 jw_array_elem(jw);
888 anal_dump_type_ref(ctx, ty->data.unionation.fields[i].type_entry);
889 }
890 jw_end_array(jw);
891 }
892 break;
893 }
894 case ZigTypeIdEnum: {
895 jw_object_field(jw, "name");
896 jw_string(jw, buf_ptr(&ty->name));
897
898 jw_object_field(jw, "src");
899 anal_dump_node_ref(ctx, ty->data.enumeration.decl_node);
830900
901 {
902 jw_object_field(jw, "pubDecls");
903 jw_begin_array(jw);
904
905 ScopeDecls *decls_scope = ty->data.enumeration.decls_scope;
906 auto it = decls_scope->decl_table.entry_iterator();
907 for (;;) {
908 auto *entry = it.next();
909 if (!entry)
910 break;
911
912 Tld *tld = entry->value;
913 if (tld->visib_mod == VisibModPub) {
914 jw_array_elem(jw);
915 anal_dump_decl_ref(ctx, tld);
916 }
917 }
918 jw_end_array(jw);
919 }
920
921 {
922 jw_object_field(jw, "privDecls");
923 jw_begin_array(jw);
924
925 ScopeDecls *decls_scope = ty->data.enumeration.decls_scope;
926 auto it = decls_scope->decl_table.entry_iterator();
927 for (;;) {
928 auto *entry = it.next();
929 if (!entry)
930 break;
931
932 Tld *tld = entry->value;
933 if (tld->visib_mod == VisibModPrivate) {
934 jw_array_elem(jw);
935 anal_dump_decl_ref(ctx, tld);
936 }
937 }
938 jw_end_array(jw);
939 }
940
941 if (ty->data.enumeration.src_field_count != 0) {
942 jw_object_field(jw, "fields");
943 jw_begin_array(jw);
944
945 for(size_t i = 0; i < ty->data.enumeration.src_field_count; i += 1) {
946 jw_array_elem(jw);
947 jw_bigint(jw, &ty->data.enumeration.fields[i].value);
948 }
949 jw_end_array(jw);
831 }950 }
832 break;951 break;
833 }952 }
...@@ -974,6 +1093,45 @@ static void anal_dump_node(AnalDumpCtx *ctx, const AstNode *node) {...@@ -974,6 +1093,45 @@ static void anal_dump_node(AnalDumpCtx *ctx, const AstNode *node) {
974 jw_string(jw, buf_ptr(doc_comments_buf));1093 jw_string(jw, buf_ptr(doc_comments_buf));
975 }1094 }
9761095
1096 const Buf *name_buf;
1097 switch (node->type) {
1098 case NodeTypeStructField:
1099 name_buf = node->data.struct_field.name;
1100 break;
1101 case NodeTypeParamDecl:
1102 name_buf = node->data.param_decl.name;
1103 break;
1104 default:
1105 name_buf = nullptr;
1106 break;
1107 }
1108 if (name_buf != nullptr) {
1109 jw_object_field(jw, "name");
1110 jw_string(jw, buf_ptr(name_buf));
1111 }
1112
1113 const ZigList<AstNode *> *fieldNodes;
1114 switch (node->type) {
1115 case NodeTypeContainerDecl:
1116 fieldNodes = &node->data.container_decl.fields;
1117 break;
1118 case NodeTypeFnProto:
1119 fieldNodes = &node->data.fn_proto.params;
1120 break;
1121 default:
1122 fieldNodes = nullptr;
1123 break;
1124 }
1125 if (fieldNodes != nullptr) {
1126 jw_object_field(jw, "fields");
1127 jw_begin_array(jw);
1128 for (size_t i = 0; i < fieldNodes->length; i += 1) {
1129 jw_array_elem(jw);
1130 anal_dump_node_ref(ctx, fieldNodes->at(i));
1131 }
1132 jw_end_array(jw);
1133 }
1134
977 jw_end_object(jw);1135 jw_end_object(jw);
978}1136}
9791137
src/ir.cpp+4-5
...@@ -13122,7 +13122,6 @@ static bool ir_resolve_float_mode(IrAnalyze *ira, IrInstruction *value, FloatMod...@@ -13122,7 +13122,6 @@ static bool ir_resolve_float_mode(IrAnalyze *ira, IrInstruction *value, FloatMod
13122 return true;13122 return true;
13123}13123}
1312413124
13125
13126static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) {13125static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) {
13127 if (type_is_invalid(value->value.type))13126 if (type_is_invalid(value->value.type))
13128 return nullptr;13127 return nullptr;
...@@ -13143,11 +13142,11 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) {...@@ -13143,11 +13142,11 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) {
1314313142
13144 assert(ptr_field->data.x_ptr.special == ConstPtrSpecialBaseArray);13143 assert(ptr_field->data.x_ptr.special == ConstPtrSpecialBaseArray);
13145 ConstExprValue *array_val = ptr_field->data.x_ptr.data.base_array.array_val;13144 ConstExprValue *array_val = ptr_field->data.x_ptr.data.base_array.array_val;
13146 if (array_val->data.x_array.special == ConstArraySpecialBuf) {
13147 return array_val->data.x_array.data.s_buf;
13148 }
13149 expand_undef_array(ira->codegen, array_val);13145 expand_undef_array(ira->codegen, array_val);
13150 size_t len = bigint_as_usize(&len_field->data.x_bigint);13146 size_t len = bigint_as_usize(&len_field->data.x_bigint);
13147 if (array_val->data.x_array.special == ConstArraySpecialBuf && len == buf_len(array_val->data.x_array.data.s_buf)) {
13148 return array_val->data.x_array.data.s_buf;
13149 }
13151 Buf *result = buf_alloc();13150 Buf *result = buf_alloc();
13152 buf_resize(result, len);13151 buf_resize(result, len);
13153 for (size_t i = 0; i < len; i += 1) {13152 for (size_t i = 0; i < len; i += 1) {
...@@ -17952,7 +17951,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_...@@ -17952,7 +17951,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
17952 union_val->special = ConstValSpecialStatic;17951 union_val->special = ConstValSpecialStatic;
17953 bigint_init_bigint(&union_val->data.x_union.tag, &field->enum_field->value);17952 bigint_init_bigint(&union_val->data.x_union.tag, &field->enum_field->value);
17954 union_val->data.x_union.payload = payload_val;17953 union_val->data.x_union.payload = payload_val;
17955 } else {17954 } else if (bare_type->data.unionation.layout != ContainerLayoutExtern) {
17956 TypeUnionField *actual_field = find_union_field_by_tag(bare_type, &union_val->data.x_union.tag);17955 TypeUnionField *actual_field = find_union_field_by_tag(bare_type, &union_val->data.x_union.tag);
17957 if (actual_field == nullptr)17956 if (actual_field == nullptr)
17958 zig_unreachable();17957 zig_unreachable();
test/stage1/behavior.zig+1
...@@ -35,6 +35,7 @@ comptime {...@@ -35,6 +35,7 @@ comptime {
35 _ = @import("behavior/bugs/3046.zig");35 _ = @import("behavior/bugs/3046.zig");
36 _ = @import("behavior/bugs/3112.zig");36 _ = @import("behavior/bugs/3112.zig");
37 _ = @import("behavior/bugs/3367.zig");37 _ = @import("behavior/bugs/3367.zig");
38 _ = @import("behavior/bugs/3384.zig");
38 _ = @import("behavior/bugs/394.zig");39 _ = @import("behavior/bugs/394.zig");
39 _ = @import("behavior/bugs/421.zig");40 _ = @import("behavior/bugs/421.zig");
40 _ = @import("behavior/bugs/529.zig");41 _ = @import("behavior/bugs/529.zig");
test/stage1/behavior/bugs/3367.zig-3
...@@ -1,6 +1,3 @@...@@ -1,6 +1,3 @@
1const std = @import("std");
2const expect = std.testing.expect;
3
4const Foo = struct {1const Foo = struct {
5 usingnamespace Mixin;2 usingnamespace Mixin;
6};3};
test/stage1/behavior/bugs/3384.zig created+11
...@@ -0,0 +1,11 @@
1const std = @import("std");
2const expect = std.testing.expect;
3
4test "resolve array slice using builtin" {
5 expect(@hasDecl(@This(), "std") == true);
6 expect(@hasDecl(@This(), "std"[0..0]) == false);
7 expect(@hasDecl(@This(), "std"[0..1]) == false);
8 expect(@hasDecl(@This(), "std"[0..2]) == false);
9 expect(@hasDecl(@This(), "std"[0..3]) == true);
10 expect(@hasDecl(@This(), "std"[0..]) == true);
11}
test/stage1/behavior/union.zig+10
...@@ -511,3 +511,13 @@ test "union with comptime_int tag" {...@@ -511,3 +511,13 @@ test "union with comptime_int tag" {
511 };511 };
512 comptime expect(@TagType(@TagType(Union)) == comptime_int);512 comptime expect(@TagType(@TagType(Union)) == comptime_int);
513}513}
514
515test "extern union doesn't trigger field check at comptime" {
516 const U = extern union {
517 x: u32,
518 y: u8,
519 };
520
521 const x = U{ .x = 0x55AAAA55 };
522 comptime expect(x.y == 0x55);
523}