mirror of
https://github.com/ziglang/zig.git
synced 2026-02-12 20:37:54 +00:00
Delete Module.Scope, move Block into Sema
This commit is contained in:
parent
fd60012c21
commit
272bad3f12
@ -54,7 +54,7 @@ c_object_work_queue: std.fifo.LinearFifo(*CObject, .Dynamic),
|
||||
/// These jobs are to tokenize, parse, and astgen files, which may be outdated
|
||||
/// since the last compilation, as well as scan for `@import` and queue up
|
||||
/// additional jobs corresponding to those new files.
|
||||
astgen_work_queue: std.fifo.LinearFifo(*Module.Scope.File, .Dynamic),
|
||||
astgen_work_queue: std.fifo.LinearFifo(*Module.File, .Dynamic),
|
||||
|
||||
/// The ErrorMsg memory is owned by the `CObject`, using Compilation's general purpose allocator.
|
||||
/// This data is accessed by multiple threads and is protected by `mutex`.
|
||||
@ -446,7 +446,7 @@ pub const AllErrors = struct {
|
||||
pub fn addZir(
|
||||
arena: *Allocator,
|
||||
errors: *std.ArrayList(Message),
|
||||
file: *Module.Scope.File,
|
||||
file: *Module.File,
|
||||
) !void {
|
||||
assert(file.zir_loaded);
|
||||
assert(file.tree_loaded);
|
||||
@ -1444,7 +1444,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
|
||||
.emit_docs = options.emit_docs,
|
||||
.work_queue = std.fifo.LinearFifo(Job, .Dynamic).init(gpa),
|
||||
.c_object_work_queue = std.fifo.LinearFifo(*CObject, .Dynamic).init(gpa),
|
||||
.astgen_work_queue = std.fifo.LinearFifo(*Module.Scope.File, .Dynamic).init(gpa),
|
||||
.astgen_work_queue = std.fifo.LinearFifo(*Module.File, .Dynamic).init(gpa),
|
||||
.keep_source_files_loaded = options.keep_source_files_loaded,
|
||||
.use_clang = use_clang,
|
||||
.clang_argv = options.clang_argv,
|
||||
@ -2465,14 +2465,14 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor
|
||||
const AstGenSrc = union(enum) {
|
||||
root,
|
||||
import: struct {
|
||||
importing_file: *Module.Scope.File,
|
||||
importing_file: *Module.File,
|
||||
import_tok: std.zig.Ast.TokenIndex,
|
||||
},
|
||||
};
|
||||
|
||||
fn workerAstGenFile(
|
||||
comp: *Compilation,
|
||||
file: *Module.Scope.File,
|
||||
file: *Module.File,
|
||||
prog_node: *std.Progress.Node,
|
||||
wg: *WaitGroup,
|
||||
src: AstGenSrc,
|
||||
@ -2742,7 +2742,7 @@ fn reportRetryableCObjectError(
|
||||
fn reportRetryableAstGenError(
|
||||
comp: *Compilation,
|
||||
src: AstGenSrc,
|
||||
file: *Module.Scope.File,
|
||||
file: *Module.File,
|
||||
err: anyerror,
|
||||
) error{OutOfMemory}!void {
|
||||
const mod = comp.bin_file.options.module.?;
|
||||
|
||||
992
src/Module.zig
992
src/Module.zig
File diff suppressed because it is too large
Load Diff
1000
src/Sema.zig
1000
src/Sema.zig
File diff suppressed because it is too large
Load Diff
@ -246,7 +246,7 @@ pub const DeclGen = struct {
|
||||
fn fail(dg: *DeclGen, comptime format: []const u8, args: anytype) error{ AnalysisFail, OutOfMemory } {
|
||||
@setCold(true);
|
||||
const src: LazySrcLoc = .{ .node_offset = 0 };
|
||||
const src_loc = src.toSrcLocWithDecl(dg.decl);
|
||||
const src_loc = src.toSrcLoc(dg.decl);
|
||||
dg.error_msg = try Module.ErrorMsg.create(dg.module.gpa, src_loc, format, args);
|
||||
return error.AnalysisFail;
|
||||
}
|
||||
|
||||
@ -557,7 +557,7 @@ pub const DeclGen = struct {
|
||||
fn todo(self: *DeclGen, comptime format: []const u8, args: anytype) error{ OutOfMemory, CodegenFail } {
|
||||
@setCold(true);
|
||||
assert(self.err_msg == null);
|
||||
const src_loc = @as(LazySrcLoc, .{ .node_offset = 0 }).toSrcLocWithDecl(self.decl);
|
||||
const src_loc = @as(LazySrcLoc, .{ .node_offset = 0 }).toSrcLoc(self.decl);
|
||||
self.err_msg = try Module.ErrorMsg.create(self.gpa, src_loc, "TODO (LLVM): " ++ format, args);
|
||||
return error.CodegenFail;
|
||||
}
|
||||
|
||||
@ -295,7 +295,7 @@ pub const DeclGen = struct {
|
||||
fn fail(self: *DeclGen, comptime format: []const u8, args: anytype) Error {
|
||||
@setCold(true);
|
||||
const src: LazySrcLoc = .{ .node_offset = 0 };
|
||||
const src_loc = src.toSrcLocWithDecl(self.decl);
|
||||
const src_loc = src.toSrcLoc(self.decl);
|
||||
self.error_msg = try Module.ErrorMsg.create(self.spv.module.gpa, src_loc, format, args);
|
||||
return error.AnalysisFail;
|
||||
}
|
||||
|
||||
@ -540,7 +540,7 @@ pub const Context = struct {
|
||||
/// Sets `err_msg` on `Context` and returns `error.CodegemFail` which is caught in link/Wasm.zig
|
||||
fn fail(self: *Context, comptime fmt: []const u8, args: anytype) InnerError {
|
||||
const src: LazySrcLoc = .{ .node_offset = 0 };
|
||||
const src_loc = src.toSrcLocWithDecl(self.decl);
|
||||
const src_loc = src.toSrcLoc(self.decl);
|
||||
self.err_msg = try Module.ErrorMsg.create(self.gpa, src_loc, fmt, args);
|
||||
return error.CodegenFail;
|
||||
}
|
||||
|
||||
@ -8,6 +8,7 @@ const print_zir = @import("print_zir.zig");
|
||||
const Module = @import("Module.zig");
|
||||
const Sema = @import("Sema.zig");
|
||||
const Zir = @import("Zir.zig");
|
||||
const Decl = Module.Decl;
|
||||
|
||||
pub const is_enabled = builtin.mode == .Debug;
|
||||
|
||||
@ -36,7 +37,7 @@ fn en(val: anytype) En(@TypeOf(val)) {
|
||||
pub const AnalyzeBody = struct {
|
||||
parent: if (is_enabled) ?*AnalyzeBody else void,
|
||||
sema: En(*Sema),
|
||||
block: En(*Module.Scope.Block),
|
||||
block: En(*Sema.Block),
|
||||
body: En([]const Zir.Inst.Index),
|
||||
body_index: En(usize),
|
||||
|
||||
@ -64,7 +65,7 @@ pub const AnalyzeBody = struct {
|
||||
|
||||
threadlocal var zir_state: ?*AnalyzeBody = if (is_enabled) null else @compileError("Cannot use zir_state if crash_report is disabled.");
|
||||
|
||||
pub fn prepAnalyzeBody(sema: *Sema, block: *Module.Scope.Block, body: []const Zir.Inst.Index) AnalyzeBody {
|
||||
pub fn prepAnalyzeBody(sema: *Sema, block: *Sema.Block, body: []const Zir.Inst.Index) AnalyzeBody {
|
||||
if (is_enabled) {
|
||||
return .{
|
||||
.parent = null,
|
||||
@ -87,7 +88,7 @@ fn dumpStatusReport() !void {
|
||||
const allocator = &fba.allocator;
|
||||
|
||||
const stderr = io.getStdErr().writer();
|
||||
const block: *Scope.Block = anal.block;
|
||||
const block: *Sema.Block = anal.block;
|
||||
|
||||
try stderr.writeAll("Analyzing ");
|
||||
try writeFullyQualifiedDeclWithFile(block.src_decl, stderr);
|
||||
@ -134,12 +135,9 @@ fn dumpStatusReport() !void {
|
||||
try stderr.writeAll("\n");
|
||||
}
|
||||
|
||||
const Scope = Module.Scope;
|
||||
const Decl = Module.Decl;
|
||||
|
||||
var crash_heap: [16 * 4096]u8 = undefined;
|
||||
|
||||
fn writeFilePath(file: *Scope.File, stream: anytype) !void {
|
||||
fn writeFilePath(file: *Module.File, stream: anytype) !void {
|
||||
if (file.pkg.root_src_directory.path) |path| {
|
||||
try stream.writeAll(path);
|
||||
try stream.writeAll(std.fs.path.sep_str);
|
||||
|
||||
@ -57,7 +57,7 @@ path_arena: std.heap.ArenaAllocator,
|
||||
/// of the function to know what file it came from.
|
||||
/// If we group the decls by file, it makes it really easy to do this (put the symbol in the correct place)
|
||||
fn_decl_table: std.AutoArrayHashMapUnmanaged(
|
||||
*Module.Scope.File,
|
||||
*Module.File,
|
||||
struct { sym_index: u32, functions: std.AutoArrayHashMapUnmanaged(*Module.Decl, FnDeclOutput) = .{} },
|
||||
) = .{},
|
||||
data_decl_table: std.AutoArrayHashMapUnmanaged(*Module.Decl, []const u8) = .{},
|
||||
|
||||
@ -3233,7 +3233,7 @@ pub fn cmdFmt(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !voi
|
||||
const Module = @import("Module.zig");
|
||||
const AstGen = @import("AstGen.zig");
|
||||
|
||||
var file: Module.Scope.File = .{
|
||||
var file: Module.File = .{
|
||||
.status = .never_loaded,
|
||||
.source_loaded = true,
|
||||
.zir_loaded = false,
|
||||
@ -3429,7 +3429,7 @@ fn fmtPathFile(
|
||||
const Module = @import("Module.zig");
|
||||
const AstGen = @import("AstGen.zig");
|
||||
|
||||
var file: Module.Scope.File = .{
|
||||
var file: Module.File = .{
|
||||
.status = .never_loaded,
|
||||
.source_loaded = true,
|
||||
.zir_loaded = false,
|
||||
@ -4019,7 +4019,7 @@ pub fn cmdAstCheck(
|
||||
}
|
||||
}
|
||||
|
||||
var file: Module.Scope.File = .{
|
||||
var file: Module.File = .{
|
||||
.status = .never_loaded,
|
||||
.source_loaded = false,
|
||||
.tree_loaded = false,
|
||||
@ -4170,7 +4170,7 @@ pub fn cmdChangelist(
|
||||
if (stat.size > max_src_size)
|
||||
return error.FileTooBig;
|
||||
|
||||
var file: Module.Scope.File = .{
|
||||
var file: Module.File = .{
|
||||
.status = .never_loaded,
|
||||
.source_loaded = false,
|
||||
.tree_loaded = false,
|
||||
|
||||
@ -11,7 +11,7 @@ const LazySrcLoc = Module.LazySrcLoc;
|
||||
/// Write human-readable, debug formatted ZIR code to a file.
|
||||
pub fn renderAsTextToFile(
|
||||
gpa: *Allocator,
|
||||
scope_file: *Module.Scope.File,
|
||||
scope_file: *Module.File,
|
||||
fs_file: std.fs.File,
|
||||
) !void {
|
||||
var arena = std.heap.ArenaAllocator.init(gpa);
|
||||
@ -64,7 +64,7 @@ pub fn renderInstructionContext(
|
||||
gpa: *Allocator,
|
||||
block: []const Zir.Inst.Index,
|
||||
block_index: usize,
|
||||
scope_file: *Module.Scope.File,
|
||||
scope_file: *Module.File,
|
||||
parent_decl_node: Ast.Node.Index,
|
||||
indent: u32,
|
||||
stream: anytype,
|
||||
@ -96,7 +96,7 @@ pub fn renderInstructionContext(
|
||||
pub fn renderSingleInstruction(
|
||||
gpa: *Allocator,
|
||||
inst: Zir.Inst.Index,
|
||||
scope_file: *Module.Scope.File,
|
||||
scope_file: *Module.File,
|
||||
parent_decl_node: Ast.Node.Index,
|
||||
indent: u32,
|
||||
stream: anytype,
|
||||
@ -122,7 +122,7 @@ pub fn renderSingleInstruction(
|
||||
const Writer = struct {
|
||||
gpa: *Allocator,
|
||||
arena: *Allocator,
|
||||
file: *Module.Scope.File,
|
||||
file: *Module.File,
|
||||
code: Zir,
|
||||
indent: u32,
|
||||
parent_decl_node: Ast.Node.Index,
|
||||
|
||||
@ -3067,7 +3067,7 @@ pub const Type = extern union {
|
||||
}
|
||||
|
||||
/// Returns null if the type has no namespace.
|
||||
pub fn getNamespace(self: Type) ?*Module.Scope.Namespace {
|
||||
pub fn getNamespace(self: Type) ?*Module.Namespace {
|
||||
return switch (self.tag()) {
|
||||
.@"struct" => &self.castTag(.@"struct").?.data.namespace,
|
||||
.enum_full => &self.castTag(.enum_full).?.data.namespace,
|
||||
@ -3833,12 +3833,12 @@ pub const Type = extern union {
|
||||
/// Most commonly used for files.
|
||||
pub const ContainerScope = struct {
|
||||
base: Payload,
|
||||
data: *Module.Scope.Namespace,
|
||||
data: *Module.Namespace,
|
||||
};
|
||||
|
||||
pub const Opaque = struct {
|
||||
base: Payload = .{ .tag = .@"opaque" },
|
||||
data: Module.Scope.Namespace,
|
||||
data: Module.Namespace,
|
||||
};
|
||||
|
||||
pub const Struct = struct {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user