fix dependency loops, pub, tests, use decls, root source

* fix dependency loop detection
   - closes #679
   - closes #1500
 * fix `pub`
 * fix tests
 * fix use decls
 * main package file gets a special "" namespace path
master
Andrew Kelley 2019-03-01 15:35:29 -05:00
parent faf76032f1
commit 582fdc2869
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
18 changed files with 825 additions and 731 deletions

View File

@ -47,7 +47,7 @@ pub const ZigCompiler = struct {
var lazy_init_targets = std.lazyInit(void);
fn init(loop: *event.Loop) !ZigCompiler {
pub fn init(loop: *event.Loop) !ZigCompiler {
lazy_init_targets.get() orelse {
Target.initializeAll();
lazy_init_targets.resolve();

View File

@ -369,8 +369,6 @@ struct Tld {
ZigType *import;
Scope *parent_scope;
// set this flag temporarily to detect infinite loops
bool dep_loop_flag;
TldResolution resolution;
};
@ -380,6 +378,7 @@ struct TldVar {
ZigVar *var;
Buf *extern_lib_name;
Buf *section_name;
bool analyzing_type; // flag to detect dependency loops
};
struct TldFn {

View File

@ -1900,7 +1900,9 @@ static Error resolve_enum_type(CodeGen *g, ZigType *enum_type) {
if (!enum_type->data.enumeration.reported_infinite_err) {
enum_type->data.enumeration.is_invalid = true;
enum_type->data.enumeration.reported_infinite_err = true;
add_node_error(g, decl_node, buf_sprintf("enum '%s' contains itself", buf_ptr(&enum_type->name)));
ErrorMsg *msg = add_node_error(g, decl_node,
buf_sprintf("enum '%s' contains itself", buf_ptr(&enum_type->name)));
emit_error_notes_for_ref_stack(g, msg);
}
return ErrorSemanticAnalyzeFail;
}
@ -2071,8 +2073,9 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) {
if (struct_type->data.structure.resolve_loop_flag) {
if (struct_type->data.structure.resolve_status != ResolveStatusInvalid) {
struct_type->data.structure.resolve_status = ResolveStatusInvalid;
add_node_error(g, decl_node,
ErrorMsg *msg = add_node_error(g, decl_node,
buf_sprintf("struct '%s' contains itself", buf_ptr(&struct_type->name)));
emit_error_notes_for_ref_stack(g, msg);
}
return ErrorSemanticAnalyzeFail;
}
@ -2296,7 +2299,9 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) {
if (!union_type->data.unionation.reported_infinite_err) {
union_type->data.unionation.reported_infinite_err = true;
union_type->data.unionation.is_invalid = true;
add_node_error(g, decl_node, buf_sprintf("union '%s' contains itself", buf_ptr(&union_type->name)));
ErrorMsg *msg = add_node_error(g, decl_node,
buf_sprintf("union '%s' contains itself", buf_ptr(&union_type->name)));
emit_error_notes_for_ref_stack(g, msg);
}
return ErrorSemanticAnalyzeFail;
}
@ -2527,8 +2532,9 @@ static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) {
return ErrorNone;
if (enum_type->data.enumeration.zero_bits_loop_flag) {
add_node_error(g, enum_type->data.enumeration.decl_node,
ErrorMsg *msg = add_node_error(g, enum_type->data.enumeration.decl_node,
buf_sprintf("'%s' depends on itself", buf_ptr(&enum_type->name)));
emit_error_notes_for_ref_stack(g, msg);
enum_type->data.enumeration.is_invalid = true;
return ErrorSemanticAnalyzeFail;
}
@ -2800,8 +2806,9 @@ static Error resolve_struct_alignment(CodeGen *g, ZigType *struct_type) {
if (struct_type->data.structure.resolve_loop_flag) {
if (struct_type->data.structure.resolve_status != ResolveStatusInvalid) {
struct_type->data.structure.resolve_status = ResolveStatusInvalid;
add_node_error(g, decl_node,
ErrorMsg *msg = add_node_error(g, decl_node,
buf_sprintf("struct '%s' contains itself", buf_ptr(&struct_type->name)));
emit_error_notes_for_ref_stack(g, msg);
}
return ErrorSemanticAnalyzeFail;
}
@ -3239,7 +3246,7 @@ static void get_fully_qualified_decl_name(Buf *buf, Tld *tld) {
}
ScopeDecls *decls_scope = reinterpret_cast<ScopeDecls *>(scope);
buf_append_buf(buf, &decls_scope->container_type->name);
buf_append_char(buf, NAMESPACE_SEP_CHAR);
if (buf_len(buf) != 0) buf_append_char(buf, NAMESPACE_SEP_CHAR);
buf_append_buf(buf, tld->name);
}
@ -3775,8 +3782,16 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var) {
ZigType *explicit_type = nullptr;
if (var_decl->type) {
ZigType *proposed_type = analyze_type_expr(g, tld_var->base.parent_scope, var_decl->type);
explicit_type = validate_var_type(g, var_decl->type, proposed_type);
if (tld_var->analyzing_type) {
ErrorMsg *msg = add_node_error(g, var_decl->type,
buf_sprintf("type of '%s' depends on itself", buf_ptr(tld_var->base.name)));
emit_error_notes_for_ref_stack(g, msg);
explicit_type = g->builtin_types.entry_invalid;
} else {
tld_var->analyzing_type = true;
ZigType *proposed_type = analyze_type_expr(g, tld_var->base.parent_scope, var_decl->type);
explicit_type = validate_var_type(g, var_decl->type, proposed_type);
}
}
assert(!is_export || !is_extern);
@ -3863,7 +3878,8 @@ void resolve_top_level_decl(CodeGen *g, Tld *tld, AstNode *source_node) {
if (tld->resolution != TldResolutionUnresolved)
return;
tld->dep_loop_flag = true;
assert(tld->resolution != TldResolutionResolving);
tld->resolution = TldResolutionResolving;
g->tld_ref_source_node_stack.append(source_node);
switch (tld->id) {
@ -3894,27 +3910,31 @@ void resolve_top_level_decl(CodeGen *g, Tld *tld, AstNode *source_node) {
}
tld->resolution = TldResolutionOk;
tld->dep_loop_flag = false;
g->tld_ref_source_node_stack.pop();
}
Tld *find_container_decl(CodeGen *g, ScopeDecls *decls_scope, Buf *name) {
// resolve all the use decls
for (size_t i = 0; i < decls_scope->use_decls.length; i += 1) {
AstNode *use_decl_node = decls_scope->use_decls.at(i);
if (use_decl_node->data.use.resolution == TldResolutionUnresolved) {
preview_use_decl(g, use_decl_node);
resolve_use_decl(g, use_decl_node);
}
}
auto entry = decls_scope->decl_table.maybe_get(name);
return (entry == nullptr) ? nullptr : entry->value;
}
Tld *find_decl(CodeGen *g, Scope *scope, Buf *name) {
while (scope) {
if (scope->id == ScopeIdDecls) {
ScopeDecls *decls_scope = (ScopeDecls *)scope;
// resolve all the use decls
for (size_t i = 0; i < decls_scope->use_decls.length; i += 1) {
AstNode *use_decl_node = decls_scope->use_decls.at(i);
if (use_decl_node->data.use.resolution == TldResolutionUnresolved) {
preview_use_decl(g, use_decl_node);
resolve_use_decl(g, use_decl_node);
}
}
auto entry = decls_scope->decl_table.maybe_get(name);
if (entry)
return entry->value;
Tld *result = find_container_decl(g, decls_scope, name);
if (result != nullptr)
return result;
}
scope = scope->parent;
}
@ -4475,10 +4495,12 @@ ZigType *add_source_file(CodeGen *g, ZigPackage *package, Buf *resolved_path, Bu
Buf resolved_root_src_dir = os_path_resolve(&pkg_root_src_dir, 1);
Buf namespace_name = BUF_INIT;
buf_init_from_buf(&namespace_name, &package->pkg_path);
if (buf_len(&namespace_name) != 0) buf_append_char(&namespace_name, NAMESPACE_SEP_CHAR);
buf_append_mem(&namespace_name, buf_ptr(&noextname) + buf_len(&resolved_root_src_dir) + 1,
buf_len(&noextname) - (buf_len(&resolved_root_src_dir) + 1));
buf_replace(&namespace_name, ZIG_OS_SEP_CHAR, NAMESPACE_SEP_CHAR);
if (source_kind == SourceKindNonRoot) {
if (buf_len(&namespace_name) != 0) buf_append_char(&namespace_name, NAMESPACE_SEP_CHAR);
buf_append_mem(&namespace_name, buf_ptr(&noextname) + buf_len(&resolved_root_src_dir) + 1,
buf_len(&noextname) - (buf_len(&resolved_root_src_dir) + 1));
buf_replace(&namespace_name, ZIG_OS_SEP_CHAR, NAMESPACE_SEP_CHAR);
}
RootStruct *root_struct = allocate<RootStruct>(1);
root_struct->package = package;
@ -6806,3 +6828,16 @@ bool ptr_allows_addr_zero(ZigType *ptr_type) {
}
return false;
}
void emit_error_notes_for_ref_stack(CodeGen *g, ErrorMsg *msg) {
size_t i = g->tld_ref_source_node_stack.length;
for (;;) {
if (i == 0)
break;
i -= 1;
AstNode *source_node = g->tld_ref_source_node_stack.at(i);
if (source_node) {
msg = add_error_note(g, msg, source_node, buf_sprintf("referenced here"));
}
}
}

View File

@ -14,6 +14,7 @@ void semantic_analyze(CodeGen *g);
ErrorMsg *add_node_error(CodeGen *g, AstNode *node, Buf *msg);
ErrorMsg *add_token_error(CodeGen *g, ZigType *owner, Token *token, Buf *msg);
ErrorMsg *add_error_note(CodeGen *g, ErrorMsg *parent_msg, AstNode *node, Buf *msg);
void emit_error_notes_for_ref_stack(CodeGen *g, ErrorMsg *msg);
ZigType *new_type_table_entry(ZigTypeId id);
ZigType *get_pointer_to_type(CodeGen *g, ZigType *child_type, bool is_const);
ZigType *get_pointer_to_type_extra(CodeGen *g, ZigType *child_type, bool is_const,
@ -49,6 +50,7 @@ bool type_is_nonnull_ptr(ZigType *type);
enum SourceKind {
SourceKindRoot,
SourceKindPkgMain,
SourceKindNonRoot,
};
ZigType *add_source_file(CodeGen *g, ZigPackage *package, Buf *abs_full_path, Buf *source_code,
@ -56,6 +58,7 @@ ZigType *add_source_file(CodeGen *g, ZigPackage *package, Buf *abs_full_path, Bu
ZigVar *find_variable(CodeGen *g, Scope *orig_context, Buf *name, ScopeFnDef **crossed_fndef_scope);
Tld *find_decl(CodeGen *g, Scope *scope, Buf *name);
Tld *find_container_decl(CodeGen *g, ScopeDecls *decls_scope, Buf *name);
void resolve_top_level_decl(CodeGen *g, Tld *tld, AstNode *source_node);
bool type_is_codegen_pointer(ZigType *type);

View File

@ -7748,7 +7748,7 @@ static Error define_builtin_compile_vars(CodeGen *g) {
g->std_package->package_table.put(buf_create_from_str("builtin"), g->compile_var_package);
g->std_package->package_table.put(buf_create_from_str("std"), g->std_package);
g->compile_var_import = add_source_file(g, g->compile_var_package, builtin_zig_path, contents,
SourceKindNonRoot);
SourceKindPkgMain);
return ErrorNone;
}
@ -7987,7 +7987,7 @@ static ZigType *add_special_code(CodeGen *g, ZigPackage *package, const char *ba
zig_panic("unable to open '%s': %s\n", buf_ptr(&path_to_code_src), err_str(err));
}
return add_source_file(g, package, resolved_path, import_code, SourceKindNonRoot);
return add_source_file(g, package, resolved_path, import_code, SourceKindPkgMain);
}
static ZigPackage *create_bootstrap_pkg(CodeGen *g, ZigPackage *pkg_with_main) {

View File

@ -15753,12 +15753,17 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
}
}
ScopeDecls *container_scope = get_container_scope(child_type);
if (container_scope != nullptr) {
auto entry = container_scope->decl_table.maybe_get(field_name);
Tld *tld = entry ? entry->value : nullptr;
if (tld) {
return ir_analyze_decl_ref(ira, &field_ptr_instruction->base, tld);
Tld *tld = find_container_decl(ira->codegen, container_scope, field_name);
if (tld) {
if (tld->visib_mod == VisibModPrivate &&
tld->import != get_scope_import(field_ptr_instruction->base.scope))
{
ErrorMsg *msg = ir_add_error(ira, &field_ptr_instruction->base,
buf_sprintf("'%s' is private", buf_ptr(field_name)));
add_error_note(ira->codegen, msg, tld->source_node, buf_sprintf("declared here"));
return ira->codegen->invalid_instruction;
}
return ir_analyze_decl_ref(ira, &field_ptr_instruction->base, tld);
}
if (child_type->id == ZigTypeIdUnion &&
(child_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr ||
@ -15776,9 +15781,11 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
}
}
const char *container_name = (child_type == ira->codegen->root_import) ?
"root source file" : buf_ptr(buf_sprintf("container '%s'", buf_ptr(&child_type->name)));
ir_add_error(ira, &field_ptr_instruction->base,
buf_sprintf("container '%s' has no member called '%s'",
buf_ptr(&child_type->name), buf_ptr(field_name)));
buf_sprintf("%s has no member called '%s'",
container_name, buf_ptr(field_name)));
return ira->codegen->invalid_instruction;
} else if (child_type->id == ZigTypeIdErrorSet) {
ErrorTableEntry *err_entry;
@ -16999,10 +17006,12 @@ static IrInstruction *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructio
assert(import->data.structure.root_struct->package);
ZigPackage *target_package;
auto package_entry = import->data.structure.root_struct->package->package_table.maybe_get(import_target_str);
SourceKind source_kind;
if (package_entry) {
target_package = package_entry->value;
import_target_path = &target_package->root_src_path;
search_dir = &target_package->root_src_dir;
source_kind = SourceKindPkgMain;
} else {
// try it as a filename
target_package = import->data.structure.root_struct->package;
@ -17011,6 +17020,8 @@ static IrInstruction *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructio
// search relative to importing file
search_dir = buf_alloc();
os_path_dirname(import->data.structure.root_struct->path, search_dir);
source_kind = SourceKindNonRoot;
}
Buf full_path = BUF_INIT;
@ -17039,8 +17050,7 @@ static IrInstruction *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructio
}
}
ZigType *target_import = add_source_file(ira->codegen, target_package, resolved_path, import_code,
SourceKindNonRoot);
ZigType *target_import = add_source_file(ira->codegen, target_package, resolved_path, import_code, source_kind);
return ir_const_type(ira, &import_instruction->base, target_import);
}
@ -17375,17 +17385,7 @@ static IrInstruction *ir_analyze_instruction_compile_err(IrAnalyze *ira,
return ira->codegen->invalid_instruction;
ErrorMsg *msg = ir_add_error(ira, &instruction->base, msg_buf);
size_t i = ira->codegen->tld_ref_source_node_stack.length;
for (;;) {
if (i == 0)
break;
i -= 1;
AstNode *source_node = ira->codegen->tld_ref_source_node_stack.at(i);
if (source_node) {
add_error_note(ira->codegen, msg, source_node,
buf_sprintf("referenced here"));
}
}
emit_error_notes_for_ref_stack(ira->codegen, msg);
return ira->codegen->invalid_instruction;
}
@ -17642,6 +17642,12 @@ static IrInstruction *ir_analyze_instruction_bit_offset_of(IrAnalyze *ira,
return ir_const_unsigned(ira, &instruction->base, bit_offset);
}
static IrInstruction *ir_error_dependency_loop(IrAnalyze *ira, IrInstruction *source_instr) {
ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("dependency loop detected"));
emit_error_notes_for_ref_stack(ira->codegen, msg);
return ira->codegen->invalid_instruction;
}
static void ensure_field_index(ZigType *type, const char *field_name, size_t index) {
Buf *field_name_buf;
@ -17688,7 +17694,9 @@ static ZigType *ir_type_info_get_type(IrAnalyze *ira, const char *type_name, Zig
return var->const_value->data.x_type;
}
static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, ScopeDecls *decls_scope) {
static Error ir_make_type_info_defs(IrAnalyze *ira, IrInstruction *source_instr, ConstExprValue *out_val,
ScopeDecls *decls_scope)
{
Error err;
ZigType *type_info_definition_type = ir_type_info_get_type(ira, "Definition", nullptr);
if ((err = ensure_complete_type(ira->codegen, type_info_definition_type)))
@ -17808,6 +17816,11 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco
ZigFn *fn_entry = ((TldFn *)curr_entry->value)->fn_entry;
assert(!fn_entry->is_test);
if (fn_entry->type_entry == nullptr) {
ir_error_dependency_loop(ira, source_instr);
return ErrorSemanticAnalyzeFail;
}
AstNodeFnProto *fn_node = (AstNodeFnProto *)(fn_entry->proto_node);
ConstExprValue *fn_def_val = create_const_vals(1);
@ -18013,7 +18026,9 @@ static void make_enum_field_val(IrAnalyze *ira, ConstExprValue *enum_field_val,
enum_field_val->data.x_struct.fields = inner_fields;
}
static Error ir_make_type_info_value(IrAnalyze *ira, AstNode *source_node, ZigType *type_entry, ConstExprValue **out) {
static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr, ZigType *type_entry,
ConstExprValue **out)
{
Error err;
assert(type_entry != nullptr);
assert(!type_is_invalid(type_entry));
@ -18224,8 +18239,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, AstNode *source_node, ZigTy
}
// defs: []TypeInfo.Definition
ensure_field_index(result->type, "defs", 3);
if ((err = ir_make_type_info_defs(ira, &fields[3], type_entry->data.enumeration.decls_scope)))
if ((err = ir_make_type_info_defs(ira, source_instr, &fields[3],
type_entry->data.enumeration.decls_scope)))
{
return err;
}
break;
}
@ -18242,11 +18260,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, AstNode *source_node, ZigTy
ensure_field_index(result->type, "errors", 0);
ZigType *type_info_error_type = ir_type_info_get_type(ira, "Error", nullptr);
if (!resolve_inferred_error_set(ira->codegen, type_entry, source_node)) {
if (!resolve_inferred_error_set(ira->codegen, type_entry, source_instr->source_node)) {
return ErrorSemanticAnalyzeFail;
}
if (type_is_global_error_set(type_entry)) {
ir_add_error_node(ira, source_node,
ir_add_error(ira, source_instr,
buf_sprintf("TODO: compiler bug: implement @typeInfo support for anyerror. https://github.com/ziglang/zig/issues/1936"));
return ErrorSemanticAnalyzeFail;
}
@ -18388,8 +18406,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, AstNode *source_node, ZigTy
}
// defs: []TypeInfo.Definition
ensure_field_index(result->type, "defs", 3);
if ((err = ir_make_type_info_defs(ira, &fields[3], type_entry->data.unionation.decls_scope)))
if ((err = ir_make_type_info_defs(ira, source_instr, &fields[3],
type_entry->data.unionation.decls_scope)))
{
return err;
}
break;
}
@ -18463,8 +18484,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, AstNode *source_node, ZigTy
}
// defs: []TypeInfo.Definition
ensure_field_index(result->type, "defs", 2);
if ((err = ir_make_type_info_defs(ira, &fields[2], type_entry->data.structure.decls_scope)))
if ((err = ir_make_type_info_defs(ira, source_instr, &fields[2],
type_entry->data.structure.decls_scope)))
{
return err;
}
break;
}
@ -18576,7 +18600,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, AstNode *source_node, ZigTy
{
ZigType *fn_type = type_entry->data.bound_fn.fn_type;
assert(fn_type->id == ZigTypeIdFn);
if ((err = ir_make_type_info_value(ira, source_node, fn_type, &result)))
if ((err = ir_make_type_info_value(ira, source_instr, fn_type, &result)))
return err;
break;
@ -18601,7 +18625,7 @@ static IrInstruction *ir_analyze_instruction_type_info(IrAnalyze *ira,
ZigType *result_type = ir_type_info_get_type(ira, nullptr, nullptr);
ConstExprValue *payload;
if ((err = ir_make_type_info_value(ira, instruction->base.source_node, type_entry, &payload)))
if ((err = ir_make_type_info_value(ira, &instruction->base, type_entry, &payload)))
return ira->codegen->invalid_instruction;
IrInstruction *result = ir_const(ira, &instruction->base, result_type);
@ -21504,6 +21528,10 @@ static IrInstruction *ir_analyze_instruction_decl_ref(IrAnalyze *ira,
TldVar *tld_var = (TldVar *)tld;
ZigVar *var = tld_var->var;
if (var == nullptr) {
return ir_error_dependency_loop(ira, &instruction->base);
}
IrInstruction *var_ptr = ir_get_var_ptr(ira, &instruction->base, var);
if (type_is_invalid(var_ptr->value.type))
return ira->codegen->invalid_instruction;

View File

@ -34,8 +34,8 @@ pub const Blake2s256 = Blake2s(256);
fn Blake2s(comptime out_len: usize) type {
return struct {
const Self = @This();
const block_length = 64;
const digest_length = out_len / 8;
pub const block_length = 64;
pub const digest_length = out_len / 8;
const iv = [8]u32{
0x6A09E667,

View File

@ -29,8 +29,8 @@ fn Rp(a: usize, b: usize, c: usize, d: usize, k: usize, s: u32, t: u32) RoundPar
pub const Md5 = struct {
const Self = @This();
const block_length = 64;
const digest_length = 16;
pub const block_length = 64;
pub const digest_length = 16;
s: [4]u32,
// Streaming Cache

View File

@ -26,8 +26,8 @@ fn Rp(a: usize, b: usize, c: usize, d: usize, e: usize, i: u32) RoundParam {
pub const Sha1 = struct {
const Self = @This();
const block_length = 64;
const digest_length = 20;
pub const block_length = 64;
pub const digest_length = 20;
s: [5]u32,
// Streaming Cache

View File

@ -78,8 +78,8 @@ pub const Sha256 = Sha2_32(Sha256Params);
fn Sha2_32(comptime params: Sha2Params32) type {
return struct {
const Self = @This();
const block_length = 64;
const digest_length = params.out_len / 8;
pub const block_length = 64;
pub const digest_length = params.out_len / 8;
s: [8]u32,
// Streaming Cache

View File

@ -13,8 +13,8 @@ pub const Sha3_512 = Keccak(512, 0x06);
fn Keccak(comptime bits: usize, comptime delim: u8) type {
return struct {
const Self = @This();
const block_length = 200;
const digest_length = bits / 8;
pub const block_length = 200;
pub const digest_length = bits / 8;
s: [200]u8,
offset: usize,

View File

@ -12,7 +12,6 @@ const ArrayList = std.ArrayList;
// Note: most of this is based on information gathered from LLVM source code,
// documentation and/or contributors.
// https://llvm.org/docs/PDB/DbiStream.html#stream-header
pub const DbiStreamHeader = packed struct {
VersionSignature: i32,
@ -393,10 +392,9 @@ pub const LineNumberEntry = packed struct {
Flags: u32,
/// TODO runtime crash when I make the actual type of Flags this
const Flags = packed struct {
pub const Flags = packed struct {
/// Start line number
Start: u24,
/// Delta of lines to the end of the expression. Still unclear.
// TODO figure out the point of this field.
End: u7,

View File

@ -617,7 +617,7 @@ pub const Node = struct {
pub const DeclList = Root.DeclList;
const InitArg = union(enum) {
pub const InitArg = union(enum) {
None,
Enum: ?*Node,
Type: *Node,
@ -1744,7 +1744,7 @@ pub const Node = struct {
kind: Kind,
rhs: ?*Node,
const Kind = union(enum) {
pub const Kind = union(enum) {
Break: ?*Node,
Continue: ?*Node,
Return,
@ -2022,7 +2022,7 @@ pub const Node = struct {
kind: Kind,
rparen: TokenIndex,
const Kind = union(enum) {
pub const Kind = union(enum) {
Variable: *Identifier,
Return: *Node,
};
@ -2101,9 +2101,9 @@ pub const Node = struct {
clobbers: ClobberList,
rparen: TokenIndex,
const OutputList = SegmentedList(*AsmOutput, 2);
const InputList = SegmentedList(*AsmInput, 2);
const ClobberList = SegmentedList(TokenIndex, 2);
pub const OutputList = SegmentedList(*AsmOutput, 2);
pub const InputList = SegmentedList(*AsmInput, 2);
pub const ClobberList = SegmentedList(TokenIndex, 2);
pub fn iterate(self: *Asm, index: usize) ?*Node {
var i = index;

File diff suppressed because it is too large Load Diff

View File

@ -18,6 +18,7 @@ comptime {
_ = @import("behavior/bugs/1421.zig");
_ = @import("behavior/bugs/1442.zig");
_ = @import("behavior/bugs/1486.zig");
_ = @import("behavior/bugs/1500.zig");
_ = @import("behavior/bugs/1851.zig");
_ = @import("behavior/bugs/2006.zig");
_ = @import("behavior/bugs/394.zig");
@ -25,6 +26,7 @@ comptime {
_ = @import("behavior/bugs/529.zig");
_ = @import("behavior/bugs/655.zig");
_ = @import("behavior/bugs/656.zig");
_ = @import("behavior/bugs/679.zig");
_ = @import("behavior/bugs/704.zig");
_ = @import("behavior/bugs/718.zig");
_ = @import("behavior/bugs/726.zig");

View File

@ -0,0 +1,10 @@
const A = struct {
b: B,
};
const B = fn (A) void;
test "allow these dependencies" {
var a: A = undefined;
var b: B = undefined;
}

View File

@ -0,0 +1,17 @@
const std = @import("std");
const expect = std.testing.expect;
pub fn List(comptime T: type) type {
return u32;
}
const ElementList = List(Element);
const Element = struct {
link: ElementList,
};
test "false dependency loop in struct definition" {
const listType = ElementList;
var x: listType = 42;
expect(x == 42);
}

View File

@ -569,7 +569,7 @@ pub const CompileErrorContext = struct {
const ErrLineIter = struct {
lines: mem.SplitIterator,
const source_file = ".tmp_source.zig";
const source_file = "tmp.zig";
fn init(input: []const u8) ErrLineIter {
return ErrLineIter{ .lines = mem.separate(input, "\n") };
@ -759,7 +759,7 @@ pub const CompileErrorContext = struct {
.is_test = false,
};
tc.addSourceFile(".tmp_source.zig", source);
tc.addSourceFile("tmp.zig", source);
comptime var arg_i = 0;
inline while (arg_i < expected_lines.len) : (arg_i += 1) {
tc.addExpectedError(expected_lines[arg_i]);