Skip to content

Commit

Permalink
Records result type for imports, does not yet use
Browse files Browse the repository at this point in the history
  • Loading branch information
MasonRemaley committed Jun 29, 2024
1 parent 01f9c37 commit 3d5ec4c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
6 changes: 5 additions & 1 deletion lib/std/zig/AstGen.zig
Original file line number Diff line number Diff line change
Expand Up @@ -9130,7 +9130,11 @@ fn builtinCall(
} else if (str.len == 0) {
return astgen.failTok(str_lit_token, "import path cannot be empty", .{});
}
const result = try gz.addStrTok(.import, str.index, str_lit_token);
const result_ty = try ri.rl.resultType(gz, node) orelse .none;
const result = try gz.addPlNode(.import, node, Zir.Inst.Import{
.result_ty = result_ty,
.name = str.index,
});
const gop = try astgen.imports.getOrPut(astgen.gpa, str.index);
if (!gop.found_existing) {
gop.value_ptr.* = str_lit_token;
Expand Down
7 changes: 6 additions & 1 deletion lib/std/zig/Zir.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1643,7 +1643,7 @@ pub const Inst = struct {
.func = .pl_node,
.func_inferred = .pl_node,
.func_fancy = .pl_node,
.import = .str_tok,
.import = .pl_node,
.int = .int,
.int_big = .str,
.float = .float,
Expand Down Expand Up @@ -3474,6 +3474,11 @@ pub const Inst = struct {
/// If `.none`, restore unconditionally.
operand: Ref,
};

pub const Import = struct {
result_ty: Ref,
name: NullTerminatedString,
};
};

pub const SpecialProng = enum { none, @"else", under };
Expand Down
7 changes: 4 additions & 3 deletions src/Sema.zig
Original file line number Diff line number Diff line change
Expand Up @@ -13896,10 +13896,11 @@ fn zirImport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
defer tracy.end();

const mod = sema.mod;
const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;
const operand_src = block.tokenOffset(inst_data.src_tok);
const operand = inst_data.get(sema.code);
const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
const extra = sema.code.extraData(Zir.Inst.Import, inst_data.payload_index).data;
const operand = sema.code.nullTerminatedString(extra.name);

const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
const result = mod.importFile(block.getFileScope(mod), operand) catch |err| switch (err) {
error.ImportOutsideModulePath => {
return sema.fail(block, operand_src, "import of file outside module path: '{s}'", .{operand});
Expand Down
2 changes: 1 addition & 1 deletion src/print_zir.zig
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ const Writer = struct {
.elem_val,
.array_type,
.coerce_ptr_elem_ty,
.import,
=> try self.writePlNodeBin(stream, inst),

.for_len => try self.writePlNodeMultiOp(stream, inst),
Expand Down Expand Up @@ -485,7 +486,6 @@ const Writer = struct {
.enum_literal,
.decl_ref,
.decl_val,
.import,
.ret_err_value,
.ret_err_value_code,
.param_anytype,
Expand Down

0 comments on commit 3d5ec4c

Please sign in to comment.