| ... | @@ -738,12 +738,13 @@ static void resolve_function_proto(CodeGen *g, AstNode *node, FnTableEntry *fn_t | ... | @@ -738,12 +738,13 @@ static void resolve_function_proto(CodeGen *g, AstNode *node, FnTableEntry *fn_t |
| 738 | | 738 | |
| 739 | TypeTableEntry *fn_type = analyze_fn_proto_type(g, import, import->block_context, nullptr, node, is_naked); | 739 | TypeTableEntry *fn_type = analyze_fn_proto_type(g, import, import->block_context, nullptr, node, is_naked); |
| 740 | | 740 | |
| | 741 | fn_table_entry->type_entry = fn_type; |
| | 742 | |
| 741 | if (fn_type->id == TypeTableEntryIdInvalid) { | 743 | if (fn_type->id == TypeTableEntryIdInvalid) { |
| 742 | fn_proto->skip = true; | 744 | fn_proto->skip = true; |
| 743 | return; | 745 | return; |
| 744 | } | 746 | } |
| 745 | | 747 | |
| 746 | fn_table_entry->type_entry = fn_type; | | |
| 747 | | 748 | |
| 748 | fn_table_entry->fn_value = LLVMAddFunction(g->module, buf_ptr(&fn_table_entry->symbol_name), | 749 | fn_table_entry->fn_value = LLVMAddFunction(g->module, buf_ptr(&fn_table_entry->symbol_name), |
| 749 | fn_type->data.fn.raw_type_ref); | 750 | fn_type->data.fn.raw_type_ref); |
| ... | @@ -1293,19 +1294,34 @@ static void resolve_top_level_decl(CodeGen *g, ImportTableEntry *import, AstNode | ... | @@ -1293,19 +1294,34 @@ static void resolve_top_level_decl(CodeGen *g, ImportTableEntry *import, AstNode |
| 1293 | AstNode *type_node = node->data.type_decl.child_type; | 1294 | AstNode *type_node = node->data.type_decl.child_type; |
| 1294 | Buf *decl_name = &node->data.type_decl.symbol; | 1295 | Buf *decl_name = &node->data.type_decl.symbol; |
| 1295 | | 1296 | |
| 1296 | TypeTableEntry *typedecl_type; | 1297 | TypeTableEntry *entry; |
| 1297 | if (node->data.type_decl.override_type) { | 1298 | if (node->data.type_decl.override_type) { |
| 1298 | typedecl_type = node->data.type_decl.override_type; | 1299 | entry = node->data.type_decl.override_type; |
| 1299 | } else { | 1300 | } else { |
| 1300 | TypeTableEntry *child_type = analyze_type_expr(g, import, import->block_context, type_node); | 1301 | TypeTableEntry *child_type = analyze_type_expr(g, import, import->block_context, type_node); |
| 1301 | if (child_type->id == TypeTableEntryIdInvalid) { | 1302 | if (child_type->id == TypeTableEntryIdInvalid) { |
| 1302 | typedecl_type = child_type; | 1303 | entry = child_type; |
| 1303 | } else { | 1304 | } else { |
| 1304 | typedecl_type = get_typedecl_type(g, buf_ptr(decl_name), child_type); | 1305 | entry = get_typedecl_type(g, buf_ptr(decl_name), child_type); |
| 1305 | } | 1306 | } |
| 1306 | } | 1307 | } |
| 1307 | | 1308 | |
| 1308 | import->block_context->type_table.put(decl_name, typedecl_type); | 1309 | import->block_context->type_table.put(decl_name, entry); |
| | 1310 | |
| | 1311 | bool is_pub = (node->data.type_decl.visib_mod != VisibModPrivate); |
| | 1312 | if (is_pub) { |
| | 1313 | for (int i = 0; i < import->importers.length; i += 1) { |
| | 1314 | ImporterInfo importer = import->importers.at(i); |
| | 1315 | auto table_entry = importer.import->block_context->type_table.maybe_get(&entry->name); |
| | 1316 | if (table_entry) { |
| | 1317 | add_node_error(g, importer.source_node, |
| | 1318 | buf_sprintf("import of type '%s' overrides existing definition", |
| | 1319 | buf_ptr(&entry->name))); |
| | 1320 | } else { |
| | 1321 | importer.import->block_context->type_table.put(&entry->name, entry); |
| | 1322 | } |
| | 1323 | } |
| | 1324 | } |
| 1309 | | 1325 | |
| 1310 | break; | 1326 | break; |
| 1311 | } | 1327 | } |
| ... | @@ -1388,8 +1404,8 @@ static TypeTableEntry *get_return_type(BlockContext *context) { | ... | @@ -1388,8 +1404,8 @@ static TypeTableEntry *get_return_type(BlockContext *context) { |
| 1388 | return unwrapped_node_type(return_type_node); | 1404 | return unwrapped_node_type(return_type_node); |
| 1389 | } | 1405 | } |
| 1390 | | 1406 | |
| 1391 | static bool type_has_codegen_value(TypeTableEntryId id) { | 1407 | static bool type_has_codegen_value(TypeTableEntry *type_entry) { |
| 1392 | switch (id) { | 1408 | switch (type_entry->id) { |
| 1393 | case TypeTableEntryIdInvalid: | 1409 | case TypeTableEntryIdInvalid: |
| 1394 | case TypeTableEntryIdMetaType: | 1410 | case TypeTableEntryIdMetaType: |
| 1395 | case TypeTableEntryIdVoid: | 1411 | case TypeTableEntryIdVoid: |
| ... | @@ -1413,13 +1429,13 @@ static bool type_has_codegen_value(TypeTableEntryId id) { | ... | @@ -1413,13 +1429,13 @@ static bool type_has_codegen_value(TypeTableEntryId id) { |
| 1413 | return true; | 1429 | return true; |
| 1414 | | 1430 | |
| 1415 | case TypeTableEntryIdTypeDecl: | 1431 | case TypeTableEntryIdTypeDecl: |
| 1416 | zig_unreachable(); | 1432 | return type_has_codegen_value(type_entry->data.type_decl.canonical_type); |
| 1417 | } | 1433 | } |
| 1418 | } | 1434 | } |
| 1419 | | 1435 | |
| 1420 | static void add_global_const_expr(CodeGen *g, Expr *expr) { | 1436 | static void add_global_const_expr(CodeGen *g, Expr *expr) { |
| 1421 | if (expr->const_val.ok && | 1437 | if (expr->const_val.ok && |
| 1422 | type_has_codegen_value(expr->type_entry->id) && | 1438 | type_has_codegen_value(expr->type_entry) && |
| 1423 | !expr->has_global_const && | 1439 | !expr->has_global_const && |
| 1424 | expr->type_entry->size_in_bits > 0) | 1440 | expr->type_entry->size_in_bits > 0) |
| 1425 | { | 1441 | { |
| ... | @@ -2381,6 +2397,7 @@ static TypeTableEntry *analyze_symbol_expr(CodeGen *g, ImportTableEntry *import, | ... | @@ -2381,6 +2397,7 @@ static TypeTableEntry *analyze_symbol_expr(CodeGen *g, ImportTableEntry *import, |
| 2381 | | 2397 | |
| 2382 | auto fn_table_entry = import->fn_table.maybe_get(variable_name); | 2398 | auto fn_table_entry = import->fn_table.maybe_get(variable_name); |
| 2383 | if (fn_table_entry) { | 2399 | if (fn_table_entry) { |
| | 2400 | assert(fn_table_entry->value->type_entry); |
| 2384 | node->data.symbol_expr.fn_entry = fn_table_entry->value; | 2401 | node->data.symbol_expr.fn_entry = fn_table_entry->value; |
| 2385 | return resolve_expr_const_val_as_fn(g, node, fn_table_entry->value); | 2402 | return resolve_expr_const_val_as_fn(g, node, fn_table_entry->value); |
| 2386 | } | 2403 | } |