From 81f19303494adc94606ee7d073632173fb19b140 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Mon, 16 Sep 2024 10:40:34 +0200 Subject: [PATCH] Code cleanup. Correct deprecation notice on '$or'. Allow "self" param on macro method to be constant. --- src/compiler/compiler_internal.h | 5 ++++- src/compiler/headers.c | 8 +------- src/compiler/parse_expr.c | 22 ++++++++++------------ src/compiler/parse_global.c | 4 ++-- src/compiler/sema_decls.c | 4 ++-- src/compiler/sema_expr.c | 2 +- src/compiler/sema_types.c | 2 +- src/compiler/types.c | 4 ++-- 8 files changed, 23 insertions(+), 28 deletions(-) diff --git a/src/compiler/compiler_internal.h b/src/compiler/compiler_internal.h index 088dc96f0..caac4ea88 100644 --- a/src/compiler/compiler_internal.h +++ b/src/compiler/compiler_internal.h @@ -65,6 +65,9 @@ typedef uint16_t FileId; #define PRINT_ERROR_LAST(...) print_error_at(c->prev_span, __VA_ARGS__) #define RETURN_PRINT_ERROR_LAST(...) do { print_error_at(c->prev_span, __VA_ARGS__); return false; } while (0) #define SEMA_NOTE(_node, ...) sema_note_prev_at((_node)->span, __VA_ARGS__) +#define SEMA_DEPRECATED(_node, ...) do { if (!compiler.build.silence_deprecation) \ + sema_note_prev_at((_node)->span, __VA_ARGS__); } while (0) + #define EXPAND_EXPR_STRING(str_) (str_)->const_expr.bytes.len, (str_)->const_expr.bytes.ptr #define TABLE_MAX_LOAD 0.5 @@ -1850,7 +1853,7 @@ extern Type *type_cuint; extern Type *type_chars; extern Type *type_wildcard_optional; extern Type *type_string; -extern Type *type_reflect_method; +extern Type *type_reflected_param; extern File stdin_file; extern const char *attribute_list[NUMBER_OF_ATTRIBUTES]; diff --git a/src/compiler/headers.c b/src/compiler/headers.c index c8c37c3b0..ca4781460 100644 --- a/src/compiler/headers.c +++ b/src/compiler/headers.c @@ -497,13 +497,7 @@ RETRY: if (type_is_optional(type)) return; switch (type->type_kind) { - case TYPE_POISONED: - case TYPE_INFERRED_ARRAY: - case TYPE_UNTYPED_LIST: - case TYPE_TYPEINFO: - case TYPE_MEMBER: - case TYPE_INFERRED_VECTOR: - case TYPE_WILDCARD: + case CT_TYPES: case TYPE_OPTIONAL: UNREACHABLE case TYPE_VOID: diff --git a/src/compiler/parse_expr.c b/src/compiler/parse_expr.c index 408a6ec49..35af062eb 100644 --- a/src/compiler/parse_expr.c +++ b/src/compiler/parse_expr.c @@ -466,15 +466,15 @@ Expr *parse_vasplat(ParseContext *c) RANGE_EXTEND_PREV(expr); END: // TODO remove in 0.7 - if (lparen && !compiler.build.silence_deprecation) + if (lparen) { if (expr->vasplat_expr.end || expr->vasplat_expr.start) { - SEMA_NOTE(expr, "'$vasplat(...)' is deprecated, use '$vasplat[...]' instead."); + SEMA_DEPRECATED(expr, "'$vasplat(...)' is deprecated, use '$vasplat[...]' instead."); } else { - SEMA_NOTE(expr, "'$vasplat()' is deprecated, use '$vasplat' instead."); + SEMA_DEPRECATED(expr, "'$vasplat()' is deprecated, use '$vasplat' instead."); } } return expr; @@ -517,10 +517,7 @@ bool parse_arg_list(ParseContext *c, Expr ***result, TokenType param_end, bool v CONSUME_OR_RET(TOKEN_EQ, false); ASSIGN_EXPR_OR_RET(expr->named_argument_expr.value, parse_expr(c), false); RANGE_EXTEND_PREV(expr); - if (!compiler.build.silence_deprecation) - { - SEMA_NOTE(expr, "Named arguments using the '.foo = expr' style are deprecated, please use 'foo: expr' instead."); - } + SEMA_DEPRECATED(expr, "Named arguments using the '.foo = expr' style are deprecated, please use 'foo: expr' instead."); goto DONE; } if (vasplat && tok_is(c, TOKEN_CT_VASPLAT)) @@ -1231,7 +1228,7 @@ static Expr *parse_ct_concat_append(ParseContext *c, Expr *left) { assert(!left && "Unexpected left hand side"); Expr *expr = EXPR_NEW_TOKEN(tok_is(c, TOKEN_CT_CONCATFN) ? EXPR_CT_CONCAT : EXPR_CT_APPEND); - if (!compiler.build.silence_deprecation) SEMA_NOTE(expr, "'%s' is deprecated in favour of '+++'.", symstr(c)); + SEMA_DEPRECATED(expr, "'%s' is deprecated in favour of '+++'.", symstr(c)); advance(c); CONSUME_OR_RET(TOKEN_LPAREN, poisoned_expr); @@ -1267,7 +1264,8 @@ static Expr *parse_ct_and_or(ParseContext *c, Expr *left) assert(!left && "Unexpected left hand side"); Expr *expr = EXPR_NEW_TOKEN(EXPR_CT_AND_OR); expr->ct_and_or_expr.is_and = tok_is(c, TOKEN_CT_ANDFN); - if (!compiler.build.silence_deprecation) SEMA_NOTE(expr, "The use of '%s' is deprecated in favour of '&&&'.", symstr(c)); + SEMA_DEPRECATED(expr, "The use of '%s' is deprecated in favour of '%s'.", symstr(c), + expr->ct_and_or_expr.is_and ? "&&&" : "|||"); advance(c); CONSUME_OR_RET(TOKEN_LPAREN, poisoned_expr); if (!parse_expr_list(c, &expr->ct_and_or_expr.args, TOKEN_RPAREN)) return poisoned_expr; @@ -1308,10 +1306,10 @@ static Expr *parse_ct_arg(ParseContext *c, Expr *left) ASSIGN_EXPRID_OR_RET(expr->ct_arg_expr.arg, parse_expr(c), poisoned_expr); CONSUME_OR_RET(is_lparen ? TOKEN_RPAREN : TOKEN_RBRACKET, poisoned_expr); // TODO remove in 0.7 - if (is_lparen && !compiler.build.silence_deprecation) + if (is_lparen) { - SEMA_NOTE(expr, "'%s(...)' is deprecated, use '%s[...]' instead.", - token_type_to_string(type), token_type_to_string(type)); + SEMA_DEPRECATED(expr, "'%s(...)' is deprecated, use '%s[...]' instead.", + token_type_to_string(type), token_type_to_string(type)); } } RANGE_EXTEND_PREV(expr); diff --git a/src/compiler/parse_global.c b/src/compiler/parse_global.c index b5a723e16..1bb99efb7 100644 --- a/src/compiler/parse_global.c +++ b/src/compiler/parse_global.c @@ -421,9 +421,9 @@ static inline TypeInfo *parse_base_type(ParseContext *c) CONSUME_OR_RET(is_lparen ? TOKEN_RPAREN : TOKEN_RBRACKET, poisoned_type_info); RANGE_EXTEND_PREV(type_info); // TODO remove in 0.7 - if (is_lparen && !compiler.build.silence_deprecation) + if (is_lparen) { - SEMA_NOTE(type_info, "'$vatype(...)' is deprecated, use '$vatype[...]' instead."); + SEMA_DEPRECATED(type_info, "'$vatype(...)' is deprecated, use '$vatype[...]' instead."); } return type_info; } diff --git a/src/compiler/sema_decls.c b/src/compiler/sema_decls.c index b23ef8003..fa7b32a86 100644 --- a/src/compiler/sema_decls.c +++ b/src/compiler/sema_decls.c @@ -3438,9 +3438,9 @@ static bool sema_analyse_macro_method(SemaContext *context, Decl *decl) } if (!sema_is_valid_method_param(context, first_param, parent_type->canonical, false)) return false; - if (first_param->var.kind != VARDECL_PARAM_REF && first_param->var.kind != VARDECL_PARAM) + if (first_param->var.kind != VARDECL_PARAM_CT && first_param->var.kind != VARDECL_PARAM_REF && first_param->var.kind != VARDECL_PARAM) { - RETURN_SEMA_ERROR(first_param, "The first parameter must be a regular or ref (&) type."); + RETURN_SEMA_ERROR(first_param, "The first parameter must be a compile time, regular or ref (&) type."); } return unit_add_method(context, parent_type->canonical, decl); } diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index 69e6c1f34..166b9d3df 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -3859,7 +3859,7 @@ static inline bool sema_create_const_paramsof(SemaContext *context, Expr *expr, Expr *type_expr = expr_new(EXPR_CONST, span); expr_rewrite_const_typeid(type_expr, decl->type->canonical); Expr *values[] = { name_expr, type_expr }; - Expr *struct_value = sema_create_struct_from_expressions(type_reflect_method->decl, expr->span, values); + Expr *struct_value = sema_create_struct_from_expressions(type_reflected_param->decl, expr->span, values); vec_add(param_exprs, struct_value); } expr_rewrite_const_untyped_list(expr, param_exprs); diff --git a/src/compiler/sema_types.c b/src/compiler/sema_types.c index 8def500fa..211b49ee3 100644 --- a/src/compiler/sema_types.c +++ b/src/compiler/sema_types.c @@ -364,7 +364,7 @@ INLINE bool sema_resolve_generic_type(SemaContext *context, TypeInfo *type_info) if (!context->current_macro && (context->call_env.kind == CALL_ENV_FUNCTION || context->call_env.kind == CALL_ENV_FUNCTION_STATIC) && !context->call_env.current_function->func_decl.in_macro) { - if (!compiler.build.silence_deprecation) SEMA_NOTE(type_info, "Direct generic type declarations outside of macros is a deprecated feature, please use 'def' to create an alias."); + SEMA_DEPRECATED(type_info, "Direct generic type declarations outside of macros and type declarations is a deprecated feature, please use 'def' to create an alias."); // TODO, completely disallow // RETURN_SEMA_ERROR(type_info, "Direct generic type declarations are only allowed inside of macros. Use `def` to define an alias for the type instead."); } diff --git a/src/compiler/types.c b/src/compiler/types.c index f77add265..51912dd6d 100644 --- a/src/compiler/types.c +++ b/src/compiler/types.c @@ -49,7 +49,7 @@ Type *type_member = &t.member; Type *type_chars = NULL; Type *type_wildcard_optional = NULL; Type *type_string = &t.string; -Type *type_reflect_method; +Type *type_reflected_param = NULL; Type *type_cint; Type *type_cuint; @@ -1375,7 +1375,7 @@ void type_setup(PlatformTarget *target) Type* types[2] = { type_string, type_typeid }; const char* names[2] = { "name", "type" }; - type_reflect_method = type_create_struct("ReflectedParam", types, names, 2); + type_reflected_param = type_create_struct("ReflectedParam", types, names, 2); } int type_kind_bitsize(TypeKind kind)