authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-02-05 01:49:14-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-02-05 01:49:14-05:00
log893f1088dfe40b0141ac6988a1ae6b165f7cc643
treef57fcc6d52217cbaff776d48f405d6d1ad47044e
parent15075d2c3d7e34fe6c75d7072cfa7f4138bf0910

error sets - peer resolution for error unions


2 files changed, 100 insertions(+), 3 deletions(-)

src/ir.cpp+95-2
......@@ -6753,11 +6753,26 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,
67536753 }
67546754
67556755 // if we got here with error sets, make an error showing the incompatibilities
6756 ZigList<ErrorTableEntry *> *missing_errors = nullptr;
67566757 if (const_cast_result.id == ConstCastResultIdErrSet) {
6758 missing_errors = &const_cast_result.data.error_set.missing_errors;
6759 }
6760 if (const_cast_result.id == ConstCastResultIdErrorUnionErrorSet) {
6761 if (const_cast_result.data.error_union_error_set->id == ConstCastResultIdErrSet) {
6762 missing_errors = &const_cast_result.data.error_union_error_set->data.error_set.missing_errors;
6763 } else if (const_cast_result.data.error_union_error_set->id == ConstCastResultIdErrSetGlobal) {
6764 ErrorMsg *msg = ir_add_error(ira, value,
6765 buf_sprintf("expected '%s', found '%s'", buf_ptr(&expected_type->name), buf_ptr(&actual_type->name)));
6766 add_error_note(ira->codegen, msg, value->source_node,
6767 buf_sprintf("unable to cast global error set into smaller set"));
6768 return ImplicitCastMatchResultReportedError;
6769 }
6770 }
6771 if (missing_errors != nullptr) {
67576772 ErrorMsg *msg = ir_add_error(ira, value,
67586773 buf_sprintf("expected '%s', found '%s'", buf_ptr(&expected_type->name), buf_ptr(&actual_type->name)));
6759 for (size_t i = 0; i < const_cast_result.data.error_set.missing_errors.length; i += 1) {
6760 ErrorTableEntry *error_entry = const_cast_result.data.error_set.missing_errors.at(i);
6774 for (size_t i = 0; i < missing_errors->length; i += 1) {
6775 ErrorTableEntry *error_entry = missing_errors->at(i);
67616776 add_error_note(ira->codegen, msg, error_entry->decl_node,
67626777 buf_sprintf("'error.%s' not a member of destination error set", buf_ptr(&error_entry->name)));
67636778 }
......@@ -7187,6 +7202,84 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
71877202 }
71887203 }
71897204
7205 if (prev_type->id == TypeTableEntryIdErrorUnion && cur_type->id == TypeTableEntryIdErrorUnion) {
7206 TypeTableEntry *prev_payload_type = prev_type->data.error_union.payload_type;
7207 TypeTableEntry *cur_payload_type = cur_type->data.error_union.payload_type;
7208
7209 bool const_cast_prev = types_match_const_cast_only(ira, prev_payload_type, cur_payload_type,
7210 source_node).id == ConstCastResultIdOk;
7211 bool const_cast_cur = types_match_const_cast_only(ira, cur_payload_type, prev_payload_type,
7212 source_node).id == ConstCastResultIdOk;
7213
7214 if (const_cast_prev || const_cast_cur) {
7215 if (const_cast_cur) {
7216 prev_inst = cur_inst;
7217 }
7218
7219 TypeTableEntry *prev_err_set_type = prev_type->data.error_union.err_set_type;
7220 TypeTableEntry *cur_err_set_type = cur_type->data.error_union.err_set_type;
7221
7222 if (!resolve_inferred_error_set(ira, prev_err_set_type, cur_inst->source_node)) {
7223 return ira->codegen->builtin_types.entry_invalid;
7224 }
7225
7226 if (!resolve_inferred_error_set(ira, cur_err_set_type, cur_inst->source_node)) {
7227 return ira->codegen->builtin_types.entry_invalid;
7228 }
7229
7230 if (type_is_global_error_set(prev_err_set_type) || type_is_global_error_set(cur_err_set_type)) {
7231 err_set_type = ira->codegen->builtin_types.entry_global_error_set;
7232 continue;
7233 }
7234
7235 if (err_set_type == nullptr) {
7236 err_set_type = prev_err_set_type;
7237 errors = allocate<ErrorTableEntry *>(ira->codegen->errors_by_index.length);
7238 for (uint32_t i = 0; i < prev_err_set_type->data.error_set.err_count; i += 1) {
7239 ErrorTableEntry *error_entry = prev_err_set_type->data.error_set.errors[i];
7240 errors[error_entry->value] = error_entry;
7241 }
7242 }
7243 bool prev_is_superset = true;
7244 for (uint32_t i = 0; i < cur_err_set_type->data.error_set.err_count; i += 1) {
7245 ErrorTableEntry *contained_error_entry = cur_err_set_type->data.error_set.errors[i];
7246 ErrorTableEntry *error_entry = errors[contained_error_entry->value];
7247 if (error_entry == nullptr) {
7248 prev_is_superset = false;
7249 break;
7250 }
7251 }
7252 if (prev_is_superset) {
7253 continue;
7254 }
7255 // unset all the errors
7256 for (uint32_t i = 0; i < prev_err_set_type->data.error_set.err_count; i += 1) {
7257 ErrorTableEntry *error_entry = prev_err_set_type->data.error_set.errors[i];
7258 errors[error_entry->value] = nullptr;
7259 }
7260 for (uint32_t i = 0; i < cur_err_set_type->data.error_set.err_count; i += 1) {
7261 ErrorTableEntry *error_entry = cur_err_set_type->data.error_set.errors[i];
7262 errors[error_entry->value] = error_entry;
7263 }
7264 bool cur_is_superset = true;
7265 for (uint32_t i = 0; i < prev_err_set_type->data.error_set.err_count; i += 1) {
7266 ErrorTableEntry *contained_error_entry = prev_err_set_type->data.error_set.errors[i];
7267 ErrorTableEntry *error_entry = errors[contained_error_entry->value];
7268 if (error_entry == nullptr) {
7269 cur_is_superset = false;
7270 break;
7271 }
7272 }
7273 if (cur_is_superset) {
7274 err_set_type = cur_err_set_type;
7275 continue;
7276 }
7277
7278 err_set_type = get_error_set_union(ira->codegen, errors, cur_err_set_type, prev_err_set_type);
7279 continue;
7280 }
7281 }
7282
71907283 if (types_match_const_cast_only(ira, prev_type, cur_type, source_node).id == ConstCastResultIdOk) {
71917284 continue;
71927285 }
std/debug/index.zig+5-1
......@@ -594,7 +594,11 @@ fn parseFormValueRef(allocator: &mem.Allocator, in_stream: &io.InStream, comptim
594594 return parseFormValueRefLen(allocator, in_stream, block_len);
595595}
596596
597fn parseFormValue(allocator: &mem.Allocator, in_stream: &io.InStream, form_id: u64, is_64: bool) !FormValue {
597const ParseFormValueError = error {};
598
599fn parseFormValue(allocator: &mem.Allocator, in_stream: &io.InStream, form_id: u64, is_64: bool)
600 ParseFormValueError!FormValue
601{
598602 return switch (form_id) {
599603 DW.FORM_addr => FormValue { .Address = try parseFormValueTargetAddrSize(in_stream) },
600604 DW.FORM_block1 => parseFormValueBlock(allocator, in_stream, 1),