mirror of
https://github.com/odin-lang/Odin.git
synced 2026-01-07 05:23:12 +00:00
Make -no-dynamic-literals the default now
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#+vet !using-stmt !using-param
|
||||
#+feature dynamic-literals
|
||||
package main
|
||||
|
||||
import "core:fmt"
|
||||
|
||||
@@ -441,7 +441,6 @@ struct BuildContext {
|
||||
bool ignore_unknown_attributes;
|
||||
bool no_bounds_check;
|
||||
bool no_type_assert;
|
||||
bool no_dynamic_literals;
|
||||
bool no_output_files;
|
||||
bool no_crt;
|
||||
bool no_rpath;
|
||||
@@ -1867,11 +1866,6 @@ gb_internal bool init_build_paths(String init_filename) {
|
||||
produces_output_file = true;
|
||||
}
|
||||
|
||||
if (build_context.ODIN_DEFAULT_TO_NIL_ALLOCATOR ||
|
||||
build_context.ODIN_DEFAULT_TO_PANIC_ALLOCATOR) {
|
||||
bc->no_dynamic_literals = true;
|
||||
}
|
||||
|
||||
if (!produces_output_file) {
|
||||
// Command doesn't produce output files. We're done.
|
||||
return true;
|
||||
|
||||
@@ -9351,6 +9351,23 @@ gb_internal bool is_expr_inferred_fixed_array(Ast *type_expr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
gb_internal bool check_for_dynamic_literals(CheckerContext *c, Ast *node, AstCompoundLit *cl) {
|
||||
if (cl->elems.count > 0 && (check_feature_flags(c, node) & OptInFeatureFlag_DynamicLiterals) == 0) {
|
||||
ERROR_BLOCK();
|
||||
error(node, "Compound literals of dynamic types are disabled by default");
|
||||
error_line("\tSuggestion: If you want to enable them for this specific file, add '#+feature dynamic-literals' at the top of the file\n");
|
||||
error_line("\tWarning: Please understand that dynamic literals will implicitly allocate using the current 'context.allocator' in that scope\n");
|
||||
if (build_context.ODIN_DEFAULT_TO_NIL_ALLOCATOR) {
|
||||
error_line("\tWarning: As '-default-to-panic-allocator' has been set, the dynamic compound literal may not be initialized as expected\n");
|
||||
} else if (build_context.ODIN_DEFAULT_TO_PANIC_ALLOCATOR) {
|
||||
error_line("\tWarning: As '-default-to-panic-allocator' has been set, the dynamic compound literal may not be initialized as expected\n");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return cl->elems.count > 0;
|
||||
}
|
||||
|
||||
gb_internal ExprKind check_compound_literal(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) {
|
||||
ExprKind kind = Expr_Expr;
|
||||
ast_node(cl, CompoundLit, node);
|
||||
@@ -9551,11 +9568,6 @@ gb_internal ExprKind check_compound_literal(CheckerContext *c, Operand *o, Ast *
|
||||
elem_type = t->DynamicArray.elem;
|
||||
context_name = str_lit("dynamic array literal");
|
||||
is_constant = false;
|
||||
|
||||
if (!build_context.no_dynamic_literals) {
|
||||
add_package_dependency(c, "runtime", "__dynamic_array_reserve");
|
||||
add_package_dependency(c, "runtime", "__dynamic_array_append");
|
||||
}
|
||||
} else if (t->kind == Type_SimdVector) {
|
||||
elem_type = t->SimdVector.elem;
|
||||
context_name = str_lit("simd vector literal");
|
||||
@@ -9730,11 +9742,9 @@ gb_internal ExprKind check_compound_literal(CheckerContext *c, Operand *o, Ast *
|
||||
|
||||
|
||||
if (t->kind == Type_DynamicArray) {
|
||||
if (build_context.no_dynamic_literals && cl->elems.count && (node->file()->feature_flags & OptInFeatureFlag_DynamicLiterals) != 0) {
|
||||
ERROR_BLOCK();
|
||||
error(node, "Compound literals of dynamic types have been disabled");
|
||||
error_line("\tSuggestion: If you want to enable them for this specific file, use '#+feature dynamic-literals' at the top of the file\n");
|
||||
error_line("\tWarning: Please understand that dynamic literals will implicitly allocate using the current 'context.allocator' in that scope\n");
|
||||
if (check_for_dynamic_literals(c, node, cl)) {
|
||||
add_package_dependency(c, "runtime", "__dynamic_array_reserve");
|
||||
add_package_dependency(c, "runtime", "__dynamic_array_append");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10123,12 +10133,7 @@ gb_internal ExprKind check_compound_literal(CheckerContext *c, Operand *o, Ast *
|
||||
}
|
||||
}
|
||||
|
||||
if (build_context.no_dynamic_literals && cl->elems.count && (node->file()->feature_flags & OptInFeatureFlag_DynamicLiterals) != 0) {
|
||||
ERROR_BLOCK();
|
||||
error(node, "Compound literals of dynamic types have been disabled");
|
||||
error_line("\tSuggestion: If you want to enable them for this specific file, use '#+feature dynamic-literals' at the top of the file\n");
|
||||
error_line("\tWarning: Please understand that dynamic literals will implicitly allocate using the current 'context.allocator' in that scope\n");
|
||||
} else {
|
||||
if (check_for_dynamic_literals(c, node, cl)) {
|
||||
add_map_reserve_dependencies(c);
|
||||
add_map_set_dependencies(c);
|
||||
}
|
||||
|
||||
@@ -542,6 +542,23 @@ gb_internal u64 check_vet_flags(Ast *node) {
|
||||
return ast_file_vet_flags(file);
|
||||
}
|
||||
|
||||
gb_internal u64 check_feature_flags(CheckerContext *c, Ast *node) {
|
||||
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 == nullptr) {
|
||||
file = node->file();
|
||||
}
|
||||
if (file != nullptr && file->feature_flags_set) {
|
||||
return file->feature_flags;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
enum VettedEntityKind {
|
||||
VettedEntity_Invalid,
|
||||
|
||||
@@ -1164,7 +1181,6 @@ gb_internal void init_universal(void) {
|
||||
add_global_bool_constant("ODIN_NO_BOUNDS_CHECK", build_context.no_bounds_check);
|
||||
add_global_bool_constant("ODIN_NO_TYPE_ASSERT", build_context.no_type_assert);
|
||||
add_global_bool_constant("ODIN_DEFAULT_TO_PANIC_ALLOCATOR", bc->ODIN_DEFAULT_TO_PANIC_ALLOCATOR);
|
||||
add_global_bool_constant("ODIN_NO_DYNAMIC_LITERALS", bc->no_dynamic_literals);
|
||||
add_global_bool_constant("ODIN_NO_CRT", bc->no_crt);
|
||||
add_global_bool_constant("ODIN_USE_SEPARATE_MODULES", bc->use_separate_modules);
|
||||
add_global_bool_constant("ODIN_TEST", bc->command_kind == Command_test);
|
||||
|
||||
@@ -1096,8 +1096,6 @@ gb_internal void lb_internal_dynamic_map_set(lbProcedure *p, lbValue const &map_
|
||||
}
|
||||
|
||||
gb_internal lbValue lb_dynamic_map_reserve(lbProcedure *p, lbValue const &map_ptr, isize const capacity, TokenPos const &pos) {
|
||||
GB_ASSERT(!build_context.no_dynamic_literals);
|
||||
|
||||
TEMPORARY_ALLOCATOR_GUARD();
|
||||
|
||||
String proc_name = {};
|
||||
|
||||
@@ -4813,7 +4813,7 @@ gb_internal lbAddr lb_build_addr_compound_lit(lbProcedure *p, Ast *expr) {
|
||||
if (cl->elems.count == 0) {
|
||||
break;
|
||||
}
|
||||
GB_ASSERT(!build_context.no_dynamic_literals);
|
||||
GB_ASSERT(expr->file()->feature_flags & OptInFeatureFlag_DynamicLiterals);
|
||||
|
||||
lbValue err = lb_dynamic_map_reserve(p, v.addr, 2*cl->elems.count, pos);
|
||||
gb_unused(err);
|
||||
@@ -4902,7 +4902,7 @@ gb_internal lbAddr lb_build_addr_compound_lit(lbProcedure *p, Ast *expr) {
|
||||
if (cl->elems.count == 0) {
|
||||
break;
|
||||
}
|
||||
GB_ASSERT(!build_context.no_dynamic_literals);
|
||||
GB_ASSERT(expr->file()->feature_flags & OptInFeatureFlag_DynamicLiterals);
|
||||
|
||||
Type *et = bt->DynamicArray.elem;
|
||||
lbValue size = lb_const_int(p->module, t_int, type_size_of(et));
|
||||
|
||||
@@ -1192,7 +1192,7 @@ gb_internal bool parse_build_flags(Array<String> args) {
|
||||
build_context.no_type_assert = true;
|
||||
break;
|
||||
case BuildFlag_NoDynamicLiterals:
|
||||
build_context.no_dynamic_literals = true;
|
||||
gb_printf_err("Warning: Use of -no-dynamic-literals is now redundant\n");
|
||||
break;
|
||||
case BuildFlag_NoCRT:
|
||||
build_context.no_crt = true;
|
||||
|
||||
@@ -6320,7 +6320,7 @@ gb_internal u64 parse_feature_tag(Token token_for_pos, String s) {
|
||||
}
|
||||
}
|
||||
|
||||
u64 flag = get_vet_flag_from_name(p);
|
||||
u64 flag = get_feature_flag_from_name(p);
|
||||
if (flag != OptInFeatureFlag_NONE) {
|
||||
if (is_notted) {
|
||||
feature_not_flags |= flag;
|
||||
@@ -6473,7 +6473,7 @@ gb_internal bool parse_file_tag(const String &lc, const Token &tok, AstFile *f)
|
||||
} else if (lc == "no-instrumentation") {
|
||||
f->flags |= AstFile_NoInstrumentation;
|
||||
} else if (string_starts_with(lc, str_lit("feature"))) {
|
||||
f->feature_flags = parse_feature_tag(tok, lc);
|
||||
f->feature_flags |= parse_feature_tag(tok, lc);
|
||||
f->feature_flags_set = true;
|
||||
} else {
|
||||
error(tok, "Unknown tag '%.*s'", LIT(lc));
|
||||
|
||||
Reference in New Issue
Block a user