Browse Source

Make diverging procedure types different from ones without a return type

gingerBill 7 years ago
parent
commit
12902821d6
6 changed files with 17 additions and 16 deletions
  1. 1 1
      src/check_stmt.cpp
  2. 1 1
      src/check_type.cpp
  3. 2 2
      src/ir_print.cpp
  4. 7 7
      src/parser.cpp
  5. 1 1
      src/parser.hpp
  6. 5 4
      src/types.cpp

+ 1 - 1
src/check_stmt.cpp

@@ -1213,7 +1213,7 @@ void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) {
 		GB_ASSERT(proc_type->kind == Type_Proc);
 		GB_ASSERT(proc_type->kind == Type_Proc);
 		// Type *proc_type = c->proc_stack[c->proc_stack.count-1];
 		// Type *proc_type = c->proc_stack[c->proc_stack.count-1];
 		TypeProc *pt = &proc_type->Proc;
 		TypeProc *pt = &proc_type->Proc;
-		if (pt->no_return) {
+		if (pt->diverging) {
 			error(rs->token, "Diverging procedures may not return");
 			error(rs->token, "Diverging procedures may not return");
 			break;
 			break;
 		}
 		}

+ 1 - 1
src/check_type.cpp

@@ -1951,7 +1951,7 @@ bool check_procedure_type(CheckerContext *ctx, Type *type, Ast *proc_type_node,
 	type->Proc.calling_convention   = cc;
 	type->Proc.calling_convention   = cc;
 	type->Proc.is_polymorphic       = pt->generic;
 	type->Proc.is_polymorphic       = pt->generic;
 	type->Proc.specialization_count = specialization_count;
 	type->Proc.specialization_count = specialization_count;
-	type->Proc.no_return            = pt->no_return;
+	type->Proc.diverging            = pt->diverging;
 
 
 	if (param_count > 0) {
 	if (param_count > 0) {
 		Entity *end = params->Tuple.variables[param_count-1];
 		Entity *end = params->Tuple.variables[param_count-1];

+ 2 - 2
src/ir_print.cpp

@@ -1475,7 +1475,7 @@ void ir_print_instr(irFileBuffer *f, irModule *m, irValue *value) {
 		}
 		}
 		ir_write_str_lit(f, ")");
 		ir_write_str_lit(f, ")");
 
 
-		if (proc_type->Proc.no_return) {
+		if (proc_type->Proc.diverging) {
 			ir_write_str_lit(f, " noreturn");
 			ir_write_str_lit(f, " noreturn");
 		}
 		}
 		ir_print_debug_location(f, m, value, instr->block->proc);
 		ir_print_debug_location(f, m, value, instr->block->proc);
@@ -1627,7 +1627,7 @@ void ir_print_proc(irFileBuffer *f, irModule *m, irProcedure *proc) {
 		break;
 		break;
 	}
 	}
 
 
-	if (proc_type->no_return) {
+	if (proc_type->diverging) {
 		ir_write_str_lit(f, "noreturn ");
 		ir_write_str_lit(f, "noreturn ");
 	}
 	}
 
 

+ 7 - 7
src/parser.cpp

@@ -866,7 +866,7 @@ Ast *ast_poly_type(AstFile *f, Token token, Ast *type, Ast *specialization) {
 }
 }
 
 
 
 
-Ast *ast_proc_type(AstFile *f, Token token, Ast *params, Ast *results, u64 tags, ProcCallingConvention calling_convention, bool generic, bool no_return) {
+Ast *ast_proc_type(AstFile *f, Token token, Ast *params, Ast *results, u64 tags, ProcCallingConvention calling_convention, bool generic, bool diverging) {
 	Ast *result = alloc_ast_node(f, Ast_ProcType);
 	Ast *result = alloc_ast_node(f, Ast_ProcType);
 	result->ProcType.token = token;
 	result->ProcType.token = token;
 	result->ProcType.params = params;
 	result->ProcType.params = params;
@@ -874,7 +874,7 @@ Ast *ast_proc_type(AstFile *f, Token token, Ast *params, Ast *results, u64 tags,
 	result->ProcType.tags = tags;
 	result->ProcType.tags = tags;
 	result->ProcType.calling_convention = calling_convention;
 	result->ProcType.calling_convention = calling_convention;
 	result->ProcType.generic = generic;
 	result->ProcType.generic = generic;
-	result->ProcType.no_return = no_return;
+	result->ProcType.diverging = diverging;
 	return result;
 	return result;
 }
 }
 
 
@@ -2621,13 +2621,13 @@ Ast *parse_block_stmt(AstFile *f, b32 is_when) {
 
 
 
 
 
 
-Ast *parse_results(AstFile *f, bool *no_return) {
+Ast *parse_results(AstFile *f, bool *diverging) {
 	if (!allow_token(f, Token_ArrowRight)) {
 	if (!allow_token(f, Token_ArrowRight)) {
 		return nullptr;
 		return nullptr;
 	}
 	}
 
 
 	if (allow_token(f, Token_Not)) {
 	if (allow_token(f, Token_Not)) {
-		if (no_return) *no_return = true;
+		if (diverging) *diverging = true;
 		return nullptr;
 		return nullptr;
 	}
 	}
 
 
@@ -2667,7 +2667,7 @@ ProcCallingConvention string_to_calling_convention(String s) {
 Ast *parse_proc_type(AstFile *f, Token proc_token) {
 Ast *parse_proc_type(AstFile *f, Token proc_token) {
 	Ast *params = nullptr;
 	Ast *params = nullptr;
 	Ast *results = nullptr;
 	Ast *results = nullptr;
-	bool no_return = false;
+	bool diverging = false;
 
 
 	ProcCallingConvention cc = ProcCC_Invalid;
 	ProcCallingConvention cc = ProcCC_Invalid;
 	if (f->curr_token.kind == Token_String) {
 	if (f->curr_token.kind == Token_String) {
@@ -2691,7 +2691,7 @@ Ast *parse_proc_type(AstFile *f, Token proc_token) {
 	expect_token(f, Token_OpenParen);
 	expect_token(f, Token_OpenParen);
 	params = parse_field_list(f, nullptr, FieldFlag_Signature, Token_CloseParen, true, true);
 	params = parse_field_list(f, nullptr, FieldFlag_Signature, Token_CloseParen, true, true);
 	expect_token_after(f, Token_CloseParen, "parameter list");
 	expect_token_after(f, Token_CloseParen, "parameter list");
-	results = parse_results(f, &no_return);
+	results = parse_results(f, &diverging);
 
 
 	u64 tags = 0;
 	u64 tags = 0;
 	parse_proc_tags(f, &tags);
 	parse_proc_tags(f, &tags);
@@ -2717,7 +2717,7 @@ Ast *parse_proc_type(AstFile *f, Token proc_token) {
 		}
 		}
 	}
 	}
 end:
 end:
-	return ast_proc_type(f, proc_token, params, results, tags, cc, is_generic, no_return);
+	return ast_proc_type(f, proc_token, params, results, tags, cc, is_generic, diverging);
 }
 }
 
 
 Ast *parse_var_type(AstFile *f, bool allow_ellipsis, bool allow_type_token) {
 Ast *parse_var_type(AstFile *f, bool allow_ellipsis, bool allow_type_token) {

+ 1 - 1
src/parser.hpp

@@ -446,7 +446,7 @@ AST_KIND(_TypeBegin, "", bool) \
 		u64 tags;    \
 		u64 tags;    \
 		ProcCallingConvention calling_convention; \
 		ProcCallingConvention calling_convention; \
 		bool generic; \
 		bool generic; \
-		bool no_return; \
+		bool diverging; \
 	}) \
 	}) \
 	AST_KIND(PointerType, "pointer type", struct { \
 	AST_KIND(PointerType, "pointer type", struct { \
 		Token token; \
 		Token token; \

+ 5 - 4
src/types.cpp

@@ -157,7 +157,7 @@ struct TypeUnion {
 		bool            are_offsets_set;                  \
 		bool            are_offsets_set;                  \
 	})                                                    \
 	})                                                    \
 	TYPE_KIND(Proc, struct {                              \
 	TYPE_KIND(Proc, struct {                              \
-		Ast *node;                                    \
+		Ast *node;                                        \
 		Scope *  scope;                                   \
 		Scope *  scope;                                   \
 		Type *   params;  /* Type_Tuple */                \
 		Type *   params;  /* Type_Tuple */                \
 		Type *   results; /* Type_Tuple */                \
 		Type *   results; /* Type_Tuple */                \
@@ -174,7 +174,7 @@ struct TypeUnion {
 		bool     is_poly_specialized;                     \
 		bool     is_poly_specialized;                     \
 		bool     has_proc_default_values;                 \
 		bool     has_proc_default_values;                 \
 		bool     has_named_results;                       \
 		bool     has_named_results;                       \
-		bool     no_return;                               \
+		bool     diverging; /* no return */               \
 		isize    specialization_count;                    \
 		isize    specialization_count;                    \
 		ProcCallingConvention calling_convention;         \
 		ProcCallingConvention calling_convention;         \
 	})                                                    \
 	})                                                    \
@@ -1405,8 +1405,9 @@ bool are_types_identical(Type *x, Type *y) {
 	case Type_Proc:
 	case Type_Proc:
 		if (y->kind == Type_Proc) {
 		if (y->kind == Type_Proc) {
 			return x->Proc.calling_convention == y->Proc.calling_convention &&
 			return x->Proc.calling_convention == y->Proc.calling_convention &&
-			       x->Proc.c_vararg == y->Proc.c_vararg &&
-			       x->Proc.variadic == y->Proc.variadic &&
+			       x->Proc.c_vararg  == y->Proc.c_vararg  &&
+			       x->Proc.variadic  == y->Proc.variadic  &&
+			       x->Proc.diverging == y->Proc.diverging &&
 			       are_types_identical(x->Proc.params, y->Proc.params) &&
 			       are_types_identical(x->Proc.params, y->Proc.params) &&
 			       are_types_identical(x->Proc.results, y->Proc.results);
 			       are_types_identical(x->Proc.results, y->Proc.results);
 		}
 		}