Commit 40dbcd09da

Andrew Kelley <superjoe30@gmail.com>
2018-02-23 18:49:21
fix type_is_codegen_pointer being used incorrectly
The names of these functions should probably change, but at least the semantics are correct now: * type_is_codegen_pointer - the type is either a fn, ptr, or promise * get_codegen_ptr_type - - ?&T and &T returns &T - ?promise and promise returns promise - ?fn()void and fn()void returns fn()void - otherwise returns nullptr
1 parent 99985ad
Changed files (3)
src/analyze.cpp
@@ -3679,7 +3679,7 @@ TypeTableEntry *get_codegen_ptr_type(TypeTableEntry *type) {
 }
 
 bool type_is_codegen_pointer(TypeTableEntry *type) {
-    return get_codegen_ptr_type(type) != nullptr;
+    return get_codegen_ptr_type(type) == type;
 }
 
 uint32_t get_ptr_align(TypeTableEntry *type) {
@@ -3688,6 +3688,8 @@ uint32_t get_ptr_align(TypeTableEntry *type) {
         return ptr_type->data.pointer.alignment;
     } else if (ptr_type->id == TypeTableEntryIdFn) {
         return (ptr_type->data.fn.fn_type_id.alignment == 0) ? 1 : ptr_type->data.fn.fn_type_id.alignment;
+    } else if (ptr_type->id == TypeTableEntryIdPromise) {
+        return 1;
     } else {
         zig_unreachable();
     }
@@ -3723,7 +3725,7 @@ static void define_local_param_variables(CodeGen *g, FnTableEntry *fn_table_entr
         TypeTableEntry *param_type = param_info->type;
         bool is_noalias = param_info->is_noalias;
 
-        if (is_noalias && !type_is_codegen_pointer(param_type)) {
+        if (is_noalias && get_codegen_ptr_type(param_type) == nullptr) {
             add_node_error(g, param_decl_node, buf_sprintf("noalias on non-pointer parameter"));
         }
 
src/ir.cpp
@@ -16470,12 +16470,12 @@ static TypeTableEntry *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstruc
     if (type_is_invalid(src_type))
         return ira->codegen->builtin_types.entry_invalid;
 
-    if (!type_is_codegen_pointer(src_type)) {
+    if (get_codegen_ptr_type(src_type) == nullptr) {
         ir_add_error(ira, ptr, buf_sprintf("expected pointer, found '%s'", buf_ptr(&src_type->name)));
         return ira->codegen->builtin_types.entry_invalid;
     }
 
-    if (!type_is_codegen_pointer(dest_type)) {
+    if (get_codegen_ptr_type(dest_type) == nullptr) {
         ir_add_error(ira, dest_type_value,
                 buf_sprintf("expected pointer, found '%s'", buf_ptr(&dest_type->name)));
         return ira->codegen->builtin_types.entry_invalid;
@@ -16662,9 +16662,9 @@ static TypeTableEntry *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstruc
     ensure_complete_type(ira->codegen, dest_type);
     ensure_complete_type(ira->codegen, src_type);
 
-    if (type_is_codegen_pointer(src_type)) {
+    if (get_codegen_ptr_type(src_type) != nullptr) {
         ir_add_error(ira, value,
-            buf_sprintf("unable to @bitCast from type '%s'", buf_ptr(&src_type->name)));
+            buf_sprintf("unable to @bitCast from pointer type '%s'", buf_ptr(&src_type->name)));
         return ira->codegen->builtin_types.entry_invalid;
     }
 
@@ -16689,9 +16689,9 @@ static TypeTableEntry *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstruc
             break;
     }
 
-    if (type_is_codegen_pointer(dest_type)) {
+    if (get_codegen_ptr_type(dest_type) != nullptr) {
         ir_add_error(ira, dest_type_value,
-                buf_sprintf("unable to @bitCast to type '%s'", buf_ptr(&dest_type->name)));
+                buf_sprintf("unable to @bitCast to pointer type '%s'", buf_ptr(&dest_type->name)));
         return ira->codegen->builtin_types.entry_invalid;
     }
 
@@ -16752,7 +16752,7 @@ static TypeTableEntry *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstr
     if (type_is_invalid(dest_type))
         return ira->codegen->builtin_types.entry_invalid;
 
-    if (!type_is_codegen_pointer(dest_type)) {
+    if (get_codegen_ptr_type(dest_type) == nullptr) {
         ir_add_error(ira, dest_type_value, buf_sprintf("expected pointer, found '%s'", buf_ptr(&dest_type->name)));
         return ira->codegen->builtin_types.entry_invalid;
     }
@@ -16858,9 +16858,7 @@ static TypeTableEntry *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstr
 
     TypeTableEntry *usize = ira->codegen->builtin_types.entry_usize;
 
-    if (!(type_is_codegen_pointer(target->value.type) || (target->value.type->id == TypeTableEntryIdMaybe &&
-        type_is_codegen_pointer(target->value.type->data.maybe.child_type))))
-    {
+    if (get_codegen_ptr_type(target->value.type) == nullptr) {
         ir_add_error(ira, target,
                 buf_sprintf("expected pointer, found '%s'", buf_ptr(&target->value.type->name)));
         return ira->codegen->builtin_types.entry_invalid;
std/hash_map.zig
@@ -235,7 +235,7 @@ pub fn HashMap(comptime K: type, comptime V: type,
     };
 }
 
-test "basicHashMapTest" {
+test "basic hash map usage" {
     var map = HashMap(i32, i32, hash_i32, eql_i32).init(debug.global_allocator);
     defer map.deinit();