Browse Source

Remove `"pure"` and `"pure_none"` calling conventions

gingerBill 4 years ago
parent
commit
28ed310f31

+ 1 - 1
core/math/math.odin

@@ -36,7 +36,7 @@ RAD_PER_DEG :: TAU/360.0;
 DEG_PER_RAD :: 360.0/TAU;
 
 
-@(default_calling_convention="pure_none")
+@(default_calling_convention="none")
 foreign _ {
 	@(link_name="llvm.sqrt.f32")
 	sqrt_f32 :: proc(x: f32) -> f32 ---;

+ 0 - 2
core/odin/ast/ast.odin

@@ -22,9 +22,7 @@ Proc_Calling_Convention :: enum i32 {
 	C_Decl,
 	Std_Call,
 	Fast_Call,
-	Pure,
 	None,
-	Pure_None,
 
 	Foreign_Block_Default = -1,
 }

+ 0 - 5
core/odin/parser/parser.odin

@@ -1907,13 +1907,8 @@ string_to_calling_convention :: proc(s: string) -> ast.Proc_Calling_Convention {
 	case "fast", "fastcall":
 		return .Fast_Call;
 
-	case "pure":
-		return .Pure;
 	case "none":
 		return .None;
-	case "pure_none":
-		return .Pure_None;
-
 	}
 	return .Invalid;
 }

+ 4 - 6
core/runtime/core.odin

@@ -25,13 +25,11 @@ Calling_Convention :: enum u8 {
 	Invalid     = 0,
 	Odin        = 1,
 	Contextless = 2,
-	Pure        = 3,
-	CDecl       = 4,
-	Std_Call    = 5,
-	Fast_Call   = 6,
+	CDecl       = 3,
+	Std_Call    = 4,
+	Fast_Call   = 5,
 
-	None        = 7,
-	Pure_None   = 8,
+	None        = 6,
 }
 
 Type_Info_Enum_Value :: distinct i64;

+ 0 - 17
examples/demo/demo.odin

@@ -1971,22 +1971,6 @@ relative_data_types :: proc() {
 	fmt.println(rel_slice[1]);
 }
 
-pure_procedures :: proc() {
-	fmt.println("\n#pure procedures");
-
-	square :: proc "pure" (x: int) -> int {
-		return x*x + 1;
-	}
-
-	do_math :: proc "pure" (x: int) -> int {
-		// Only "pure" procedure calls are allowed within a "pure" procedure
-		return square(x) + 1;
-	}
-
-	x := do_math(5);
-	fmt.println(x);
-}
-
 main :: proc() {
 	when true {
 		the_basics();
@@ -2019,6 +2003,5 @@ main :: proc() {
 		union_maybe();
 		explicit_context_definition();
 		relative_data_types();
-		pure_procedures();
 	}
 }

+ 0 - 17
examples/demo_insert_semicolon/demo.odin

@@ -1971,22 +1971,6 @@ relative_data_types :: proc() {
 	fmt.println(rel_slice[1])
 }
 
-pure_procedures :: proc() {
-	fmt.println("\n#pure procedures")
-
-	square :: proc "pure" (x: int) -> int {
-		return x*x + 1
-	}
-
-	do_math :: proc "pure" (x: int) -> int {
-		// Only "pure" procedure calls are allowed within a "pure" procedure
-		return square(x) + 1
-	}
-
-	x := do_math(5)
-	fmt.println(x)
-}
-
 main :: proc() {
 	when true {
 		the_basics()
@@ -2019,6 +2003,5 @@ main :: proc() {
 		union_maybe()
 		explicit_context_definition()
 		relative_data_types()
-		pure_procedures()
 	}
 }

+ 0 - 3
src/check_decl.cpp

@@ -1180,9 +1180,6 @@ void check_proc_body(CheckerContext *ctx_, Token token, DeclInfo *decl, Type *ty
 		case ProcCC_None:
 			error(body, "Procedures with the calling convention \"none\" are not allowed a body");
 			break;
-		case ProcCC_PureNone:
-			error(body, "Procedures with the calling convention \"pure_none\" are not allowed a body");
-			break;
 		}
 	}
 

+ 6 - 23
src/check_expr.cpp

@@ -1162,11 +1162,6 @@ Entity *check_ident(CheckerContext *c, Operand *o, Ast *n, Type *named_type, Typ
 		if (e->flags & EntityFlag_Value) {
 			o->mode = Addressing_Value;
 		}
-		if (c->curr_proc_calling_convention == ProcCC_Pure) {
-			if (e->scope->flags & (ScopeFlag_Global|ScopeFlag_File|ScopeFlag_Pkg)) {
-				error(n, "Global variables are not allowed within a \"pure\" procedure, got '%.*s'", LIT(e->token.string));
-			}
-		}
 		break;
 
 	case Entity_Procedure:
@@ -7816,14 +7811,6 @@ ExprKind check_call_expr(CheckerContext *c, Operand *operand, Ast *call, Ast *pr
 		}
 	}
 
-	{
-		if (c->curr_proc_calling_convention == ProcCC_Pure) {
-			if (pt->kind == Type_Proc && pt->Proc.calling_convention != ProcCC_Pure && pt->Proc.calling_convention != ProcCC_PureNone) {
-				error(call, "Only \"pure\" procedure calls are allowed within a \"pure\" procedure");
-			}
-		}
-	}
-
 	#if 0
 	if (pt->kind == Type_Proc && pt->Proc.calling_convention == ProcCC_Odin) {
 		init_core_context(c->checker);
@@ -8168,17 +8155,13 @@ ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast *node, Type
 					error(node, "'context' is only allowed within procedures %p", c->curr_proc_decl);
 					return kind;
 				}
-				if (c->curr_proc_calling_convention == ProcCC_Pure) {
-					error(node, "'context' is not allowed within a \"pure\" procedure");
-				} else {
-					if (unparen_expr(c->assignment_lhs_hint) == node) {
-						c->scope->flags |= ScopeFlag_ContextDefined;
-					}
+				if (unparen_expr(c->assignment_lhs_hint) == node) {
+					c->scope->flags |= ScopeFlag_ContextDefined;
+				}
 
-					if ((c->scope->flags & ScopeFlag_ContextDefined) == 0) {
-						error(node, "'context' has not been defined within this scope");
-						// Continue with value
-					}
+				if ((c->scope->flags & ScopeFlag_ContextDefined) == 0) {
+					error(node, "'context' has not been defined within this scope");
+					// Continue with value
 				}
 
 				init_core_context(c->checker);

+ 0 - 11
src/check_stmt.cpp

@@ -1403,11 +1403,6 @@ void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) {
 	case_end;
 
 	case_ast_node(as, AssignStmt, node);
-		if (ctx->curr_proc_calling_convention == ProcCC_Pure) {
-			error(node, "Assignment statements are not allowed within a \"pure\" procedure");
-			// Continue
-		}
-
 		switch (as->op.kind) {
 		case Token_Eq: {
 			// a, b, c = 1, 2, 3;  // Multisided
@@ -2142,12 +2137,6 @@ void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) {
 			check_init_variables(ctx, entities, entity_count, vd->values, str_lit("variable declaration"));
 			check_arity_match(ctx, vd, false);
 
-			if (ctx->curr_proc_calling_convention == ProcCC_Pure) {
-				if (vd->values.count == 0) {
-					error(node, "Variable declarations without assignment are not allowed within \"pure\" procedures");
-				}
-			}
-
 			for (isize i = 0; i < entity_count; i++) {
 				Entity *e = entities[i];
 

+ 3 - 9
src/check_type.cpp

@@ -2172,7 +2172,7 @@ Type *type_to_abi_compat_param_type(gbAllocator a, Type *original_type, ProcCall
 		return t_rawptr;
 	}
 
-	if (cc == ProcCC_None || cc == ProcCC_PureNone || cc == ProcCC_InlineAsm) {
+	if (is_calling_convention_none(cc)) {
 		return new_type;
 	}
 
@@ -2312,7 +2312,7 @@ Type *type_to_abi_compat_result_type(gbAllocator a, Type *original_type, ProcCal
 	if (build_context.ODIN_OS == "windows") {
 		if (build_context.ODIN_ARCH == "amd64") {
 			if (is_type_integer_128bit(single_type)) {
-				if (cc == ProcCC_None || cc == ProcCC_PureNone) {
+				if (is_calling_convention_none(cc)) {
 					return original_type;
 				} else {
 					return alloc_type_simd_vector(2, t_u64);
@@ -2378,7 +2378,7 @@ bool abi_compat_return_by_pointer(gbAllocator a, ProcCallingConvention cc, Type
 	if (abi_return_type == nullptr) {
 		return false;
 	}
-	if (cc == ProcCC_None || cc == ProcCC_PureNone || cc == ProcCC_InlineAsm) {
+	if (is_calling_convention_none(cc)) {
 		return false;
 	}
 
@@ -2442,7 +2442,6 @@ void set_procedure_abi_types(Type *type) {
 			switch (type->Proc.calling_convention) {
 			case ProcCC_Odin:
 			case ProcCC_Contextless:
-			case ProcCC_Pure:
 				if (is_type_pointer(new_type) && !is_type_pointer(e->type) && !is_type_proc(e->type)) {
 					e->flags |= EntityFlag_ImplicitReference;
 				}
@@ -2540,11 +2539,6 @@ bool check_procedure_type(CheckerContext *ctx, Type *type, Ast *proc_type_node,
 		type->Proc.has_named_results = first->token.string != "";
 	}
 
-	if (result_count == 0 && cc == ProcCC_Pure) {
-		error(proc_type_node, "\"pure\" procedures must have at least 1 return value");
-	}
-
-
 	bool optional_ok = (pt->tags & ProcTag_optional_ok) != 0;
 	if (optional_ok) {
 		if (result_count != 2) {

+ 0 - 2
src/ir_print.cpp

@@ -1451,13 +1451,11 @@ void ir_print_calling_convention(irFileBuffer *f, irModule *m, ProcCallingConven
 	switch (cc) {
 	case ProcCC_Odin:        ir_write_str_lit(f, "");       break;
 	case ProcCC_Contextless: ir_write_str_lit(f, "");       break;
-	case ProcCC_Pure:        ir_write_str_lit(f, "");       break;
 	// case ProcCC_CDecl:       ir_write_str_lit(f, "ccc ");   break;
 	case ProcCC_CDecl:       ir_write_str_lit(f, "");   break;
 	case ProcCC_StdCall:     ir_write_str_lit(f, "cc 64 "); break;
 	case ProcCC_FastCall:    ir_write_str_lit(f, "cc 65 "); break;
 	case ProcCC_None:        ir_write_str_lit(f, "");       break;
-	case ProcCC_PureNone:    ir_write_str_lit(f, "");       break;
 	default: GB_PANIC("unknown calling convention: %d", cc);
 	}
 }

+ 0 - 1
src/llvm_abi.cpp

@@ -924,7 +924,6 @@ namespace lbAbiAarch64 {
 LB_ABI_INFO(lb_get_abi_info) {
 	switch (calling_convention) {
 	case ProcCC_None:
-	case ProcCC_PureNone:
 	case ProcCC_InlineAsm:
 		{
 			lbFunctionType *ft = gb_alloc_item(heap_allocator(), lbFunctionType);

+ 0 - 2
src/parser.cpp

@@ -3218,8 +3218,6 @@ Ast *parse_results(AstFile *f, bool *diverging) {
 ProcCallingConvention string_to_calling_convention(String s) {
 	if (s == "odin")        return ProcCC_Odin;
 	if (s == "contextless") return ProcCC_Contextless;
-	if (s == "pure")        return ProcCC_Pure;
-	if (s == "pure_none")   return ProcCC_PureNone;
 	if (s == "cdecl")       return ProcCC_CDecl;
 	if (s == "c")           return ProcCC_CDecl;
 	if (s == "stdcall")     return ProcCC_StdCall;

+ 4 - 6
src/parser.hpp

@@ -206,13 +206,11 @@ enum ProcCallingConvention {
 	ProcCC_Invalid = 0,
 	ProcCC_Odin = 1,
 	ProcCC_Contextless = 2,
-	ProcCC_Pure = 3,
-	ProcCC_CDecl = 4,
-	ProcCC_StdCall = 5,
-	ProcCC_FastCall = 6,
+	ProcCC_CDecl = 3,
+	ProcCC_StdCall = 4,
+	ProcCC_FastCall = 5,
 
-	ProcCC_None = 7,
-	ProcCC_PureNone = 8,
+	ProcCC_None = 6,
 
 	ProcCC_InlineAsm = 9,
 

+ 0 - 6
src/types.cpp

@@ -903,7 +903,6 @@ Type *alloc_type_named(String name, Type *base, Entity *type_name) {
 bool is_calling_convention_none(ProcCallingConvention calling_convention) {
 	switch (calling_convention) {
 	case ProcCC_None:
-	case ProcCC_PureNone:
 	case ProcCC_InlineAsm:
 		return true;
 	}
@@ -3610,15 +3609,10 @@ gbString write_type_to_string(gbString str, Type *type) {
 		case ProcCC_FastCall:
 			str = gb_string_appendc(str, " \"fastcall\" ");
 			break;
-		case ProcCC_PureNone:
-			str = gb_string_appendc(str, " \"pure_none\" ");
 			break;
 		case ProcCC_None:
 			str = gb_string_appendc(str, " \"none\" ");
 			break;
-		case ProcCC_Pure:
-			str = gb_string_appendc(str, " \"pure\" ");
-			break;
 		// case ProcCC_VectorCall:
 		// 	str = gb_string_appendc(str, " \"vectorcall\" ");
 		// 	break;