Improve //+vet; remove using in many places; add //+vet !using-stmt where necessary

This commit is contained in:
gingerBill
2023-07-31 11:37:14 +01:00
parent 60e509b1e0
commit 0de7df9eab
14 changed files with 212 additions and 202 deletions
+4 -4
View File
@@ -218,10 +218,10 @@ enum BuildPath : u8 {
enum VetFlags : u64 {
VetFlag_NONE = 0,
VetFlag_Unused = 1u<<0,
VetFlag_Shadowing = 1u<<1,
VetFlag_UsingStmt = 1u<<2,
VetFlag_UsingParam = 1u<<3,
VetFlag_Unused = 1u<<0, // 1
VetFlag_Shadowing = 1u<<1, // 2
VetFlag_UsingStmt = 1u<<2, // 4
VetFlag_UsingParam = 1u<<3, // 8
VetFlag_Extra = 1u<<16,
+2 -2
View File
@@ -1064,7 +1064,7 @@ gb_internal void check_proc_decl(CheckerContext *ctx, Entity *e, DeclInfo *d) {
auto *fp = &ctx->info->foreigns;
StringHashKey key = string_hash_string(name);
Entity **found = string_map_get(fp, key);
if (found) {
if (found && e != *found) {
Entity *f = *found;
TokenPos pos = f->token.pos;
Type *this_type = base_type(e->type);
@@ -1636,7 +1636,7 @@ gb_internal bool check_proc_body(CheckerContext *ctx_, Token token, DeclInfo *de
}
check_close_scope(ctx);
check_scope_usage(ctx->checker, ctx->scope, check_vet_flags(ctx));
check_scope_usage(ctx->checker, ctx->scope, check_vet_flags(body));
add_deps_from_child_to_parent(decl);
+3 -3
View File
@@ -3099,7 +3099,7 @@ gb_internal void check_cast(CheckerContext *c, Operand *x, Type *type) {
update_untyped_expr_type(c, x->expr, final_type, true);
}
if (check_vet_flags(c) & VetFlag_Extra) {
if (check_vet_flags(x->expr) & VetFlag_Extra) {
if (are_types_identical(x->type, type)) {
gbString str = type_to_string(type);
warning(x->expr, "Unneeded cast to the same type '%s'", str);
@@ -3171,7 +3171,7 @@ gb_internal bool check_transmute(CheckerContext *c, Ast *node, Operand *o, Type
return false;
}
if (check_vet_flags(c) & VetFlag_Extra) {
if (check_vet_flags(node) & VetFlag_Extra) {
if (are_types_identical(o->type, dst_t)) {
gbString str = type_to_string(dst_t);
warning(o->expr, "Unneeded transmute to the same type '%s'", str);
@@ -10028,7 +10028,7 @@ gb_internal ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast
Type *type = type_of_expr(ac->expr);
check_cast(c, o, type_hint);
if (is_type_typed(type) && are_types_identical(type, type_hint)) {
if (check_vet_flags(c) & VetFlag_Extra) {
if (check_vet_flags(node) & VetFlag_Extra) {
error(node, "Redundant 'auto_cast' applied to expression");
}
}
+2 -2
View File
@@ -2464,9 +2464,9 @@ gb_internal void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags)
error(us->token, "Empty 'using' list");
return;
}
if (check_vet_flags(ctx) & VetFlag_UsingStmt) {
if (check_vet_flags(node) & VetFlag_UsingStmt) {
ERROR_BLOCK();
error(node, "'using' as a statement is now allowed when '-vet' or '-vet-using' is applied");
error(node, "'using' as a statement is now allowed when '-vet' or '-vet-using' is applied %llu %llu", check_vet_flags(ctx), node->file()->vet_flags);
error_line("\t'using' is considered bad practice to use as a statement outside of immediate refactoring\n");
}
+22
View File
@@ -521,6 +521,28 @@ GB_COMPARE_PROC(entity_variable_pos_cmp) {
}
gb_internal u64 check_vet_flags(CheckerContext *c) {
AstFile *file = c->file;
if (file == nullptr &&
c->curr_proc_decl &&
c->curr_proc_decl->proc_lit) {
file = c->curr_proc_decl->proc_lit->file();
}
if (file && file->vet_flags_set) {
return file->vet_flags;
}
return build_context.vet_flags;
}
gb_internal u64 check_vet_flags(Ast *node) {
AstFile *file = node->file();
if (file && file->vet_flags_set) {
return file->vet_flags;
}
return build_context.vet_flags;
}
enum VettedEntityKind {
VettedEntity_Invalid,
+2 -6
View File
@@ -449,12 +449,8 @@ struct CheckerContext {
Ast *assignment_lhs_hint;
};
u64 check_vet_flags(CheckerContext *c) {
if (c->file && c->file->vet_flags_set) {
return c->file->vet_flags;
}
return build_context.vet_flags;
}
gb_internal u64 check_vet_flags(CheckerContext *c);
gb_internal u64 check_vet_flags(Ast *node);
struct Checker {
+14 -9
View File
@@ -5563,7 +5563,9 @@ gb_internal u64 parse_vet_tag(Token token_for_pos, String s) {
while (s.len > 0) {
String p = string_trim_whitespace(vet_tag_get_token(s, &s));
if (p.len == 0) break;
if (p.len == 0) {
break;
}
bool is_notted = false;
if (p[0] == '!') {
@@ -5571,14 +5573,10 @@ gb_internal u64 parse_vet_tag(Token token_for_pos, String s) {
p = substring(p, 1, p.len);
if (p.len == 0) {
syntax_error(token_for_pos, "Expected a vet flag name after '!'");
break;
return build_context.vet_flags;
}
}
if (p.len == 0) {
continue;
}
u64 flag = get_vet_flag_from_name(p);
if (flag != VetFlag_NONE) {
if (is_notted) {
@@ -5595,13 +5593,20 @@ gb_internal u64 parse_vet_tag(Token token_for_pos, String s) {
error_line("\tusing-stmt\n");
error_line("\tusing-param\n");
error_line("\textra\n");
break;
return build_context.vet_flags;
}
}
if (vet_flags == 0 && vet_not_flags != 0) {
vet_flags = VetFlag_All;
if (vet_flags == 0 && vet_not_flags == 0) {
return build_context.vet_flags;
}
if (vet_flags == 0 && vet_not_flags != 0) {
return build_context.vet_flags &~ vet_not_flags;
}
if (vet_flags != 0 && vet_not_flags == 0) {
return vet_flags;
}
GB_ASSERT(vet_flags != 0 && vet_not_flags != 0);
return vet_flags &~ vet_not_flags;
}