authorchloe caruso <git@paperclover.net> 2024-09-21 15:35:31-07:00
committerchloe caruso <git@paperclover.net> 2024-09-21 15:35:31-07:00
log5b35e0a263fe2a35d0e494709fd2f716c565e591
tree9df1b5f3d943b1bfa7451440c68a44bd7a0bc3b4
parentb31251c359b01b400486bfbb17ee15d90a663c95

chore: reduce size of report in debug build


4 files changed, 39 insertions(+), 104 deletions(-)

CHANGELOG.md+1
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1## 0.1.71## 0.1.7
22
3- chore: rename the language to "ix"3- chore: rename the language to "ix"
4- feat: language manual gets a pleasing redesign
4- feat: allow any expression as a function body5- feat: allow any expression as a function body
5- fix: coerce `break` operands and implicit breaks to result type6- fix: coerce `break` operands and implicit breaks to result type
6- fix: coerce results when `if` expression branches merge7- fix: coerce results when `if` expression branches merge
doc/language-manual.md+12-75
...@@ -43,6 +43,14 @@ calling it when the program starts....@@ -43,6 +43,14 @@ calling it when the program starts.
43> In the future, common APIs will be available in the standard library, such as43> In the future, common APIs will be available in the standard library, such as
44> `std.log.info()`. For now, no such library exists.44> `std.log.info()`. For now, no such library exists.
4545
46## Module Scope and Declarations
47
48The top-level
49
50```
51let x = 1;
52```
53
46## Primitive Data Types54## Primitive Data Types
4755
48| name | ts equivalent | description |56| name | ts equivalent | description |
...@@ -61,19 +69,18 @@ calling it when the program starts....@@ -61,19 +69,18 @@ calling it when the program starts.
6169
62### Built-in Constants70### Built-in Constants
6371
64In addition to the above types being built-in constants, the following are
65available.
66
67| name | description |72| name | description |
68| ------- | ------------------------------------- |73| ------- | ------------------------------------- |
69| `true` | boolean true (result of `1 == 1`) |74| `true` | boolean true (result of `1 == 1`) |
70| `false` | boolean false (result of `1 == 2`) |75| `false` | boolean false (result of `1 == 2`) |
71| `std` | handle to the standard library module |76| `std` | handle to the standard library module |
7277
73These constants are reserved names, and it is an error to re-declare them.78These constants act as reserved names, and it is an error to re-declare them.
79Note that primitive data types are also considered built-in constants.
7480
75```lang:build81```lang:build
76fn main {82fn main {
83 let opaque = -5.2;
77 let true = 1 == 0;84 let true = 1 == 0;
78}85}
79```86```
...@@ -185,7 +192,7 @@ The function body is a block, which may use implicit return to return....@@ -185,7 +192,7 @@ The function body is a block, which may use implicit return to return.
185```lang:run192```lang:run
186let print = @extern("console").log;193let print = @extern("console").log;
187194
188fn add(a: int, b: int) -> int {195fn add(a: int, b: int) {
189 a + b196 a + b
190}197}
191198
...@@ -194,10 +201,6 @@ fn main {...@@ -194,10 +201,6 @@ fn main {
194}201}
195```202```
196203
197> **Bug**: Return types are currently required. Omitting the `-> type` syntax
198> currently makes the return type `void`, but this will be changed in the future
199> to be an inferred return type.
200
201The `return` expression can be used within functions to return early.204The `return` expression can be used within functions to return early.
202205
203```lang:run206```lang:run
...@@ -296,69 +299,3 @@ fn main {...@@ -296,69 +299,3 @@ fn main {
296 print(Person{ name: "hello", age: 42 });299 print(Person{ name: "hello", age: 42 });
297}300}
298```301```
299
300## A
301
302### B
303
304## C
305
306### a
307
308### somewhat long header name but still is within dave's reasonable-ish constraints
309
310#### Number Literals 2
311
312TODO
313
314#### String Literals 2
315
316TODO
317
318#### String WAdsafdsa
319
320TODO
321
322### hewwo
323
324cat
325
326### cat
327
328#### yeah
329
330## what
331
332## omg
333
334## Lorem ipsum dolor sit
335
336## amet, consectetur adipiscing
337
338## elit. Proin vulputate ligula
339
340## ac risus blandit, eu accumsan
341
342## rna feugiat. Phasellus quis
343
344## metus felis. Semper mattis
345
346## augue eu elementum. Sed nec odio
347
348## cursus neque fringilla rutrum.
349
350## Cras vestibulum bibendum hendrerit.
351
352## Duis porta, leo vel
353
354## sollicitudin rhoncus, arcu nulla
355
356## lobortis est, vitae interdum
357
358## quam ante eu ante. Integer luctus
359
360## justo a odio cursus auctor. Phasellus
361
362## blandit urna vitae quam dapibus
363
364## efficitur. Proin sagittis urna non
src/core/Report.zig+25-28
...@@ -5,8 +5,8 @@...@@ -5,8 +5,8 @@
5//!5//!
6//! Across the compiler, `Report.Builder`s' `.err` and `.warn` methods6//! Across the compiler, `Report.Builder`s' `.err` and `.warn` methods
7//! can add messages by ID.7//! can add messages by ID.
8errors: []Item,8errors: []Item(Err),
9warnings: []Item,9warnings: []Item(Warn),
10string_bytes: []u8,10string_bytes: []u8,
1111
12pub const empty: Report = .{12pub const empty: Report = .{
...@@ -18,23 +18,20 @@ pub const empty: Report = .{...@@ -18,23 +18,20 @@ pub const empty: Report = .{
18pub var debug_show_report_trace: if (builtin.mode == .Debug) bool else void =18pub var debug_show_report_trace: if (builtin.mode == .Debug) bool else void =
19 if (builtin.mode == .Debug) false;19 if (builtin.mode == .Debug) false;
2020
21pub const Item = struct {21pub fn Item(T: type) type {
22 /// What is this diagnostic22 return struct {
23 data: union { @"error": Err, warn: Warn },23 data: T,
2424 debug_stack_trace: DebugStoredTrace = .empty,
25 debug_stack_trace: DebugStoredTrace = .empty,25 };
2626}
27 /// Type is never stored, inferred from which list it is in.
28 pub const Type = enum { @"error", warn };
29};
3027
31pub const Err = union(enum) {28pub const Err = union(enum) {
32 pub const FieldEnum = core.FieldEnum(Err);29 pub const FieldEnum = core.FieldEnum(Err);
3330
34 /// Constructs a `Report` with just a single error.31 /// Constructs a `Report` with just a single error.
35 pub fn toReport(err: Err, alloc: Allocator, trace: DebugStoredTrace) !Report {32 pub fn toReport(err: Err, alloc: Allocator, trace: DebugStoredTrace) !Report {
36 const errors = try alloc.dupe(Item, &.{.{33 const errors = try alloc.dupe(Item(Err), &.{.{
37 .data = .{ .@"error" = err },34 .data = err,
38 .debug_stack_trace = trace,35 .debug_stack_trace = trace,
39 }});36 }});
40 return .{ .errors = errors, .warnings = &.{}, .string_bytes = &.{} };37 return .{ .errors = errors, .warnings = &.{}, .string_bytes = &.{} };
...@@ -641,7 +638,7 @@ pub fn dump(report: Report, ctx: DumpContext, out: core.OutStream) !void {...@@ -641,7 +638,7 @@ pub fn dump(report: Report, ctx: DumpContext, out: core.OutStream) !void {
641 const ast: *const Ast = switch (ctx) {638 const ast: *const Ast = switch (ctx) {
642 .comp => |comp_ctx|639 .comp => |comp_ctx|
643 // Ast cannot be queried if the error is in computing the Ast640 // Ast cannot be queried if the error is in computing the Ast
644 if (report.errors.len > 0 and report.errors[0].data.@"error" == .ast) fake_ast: {641 if (report.errors.len > 0 and report.errors[0].data == .ast) fake_ast: {
645 fake_ast_data = .{642 fake_ast_data = .{
646 .utf8_source = (comp_ctx.file.getSource(comp_ctx.comp.gpa) catch {643 .utf8_source = (comp_ctx.file.getSource(comp_ctx.comp.gpa) catch {
647 @panic("TODO");644 @panic("TODO");
...@@ -695,18 +692,18 @@ pub fn dump(report: Report, ctx: DumpContext, out: core.OutStream) !void {...@@ -695,18 +692,18 @@ pub fn dump(report: Report, ctx: DumpContext, out: core.OutStream) !void {
695 };692 };
696693
697 for (report.errors) |item| {694 for (report.errors) |item| {
698 try formatItem(item, .@"error", arena.allocator(), url, msg_ctx, out);695 try formatItem(Err, item, arena.allocator(), url, msg_ctx, out);
699 _ = arena.reset(.retain_capacity);696 _ = arena.reset(.retain_capacity);
700 }697 }
701 for (report.warnings) |item| {698 for (report.warnings) |item| {
702 try formatItem(item, .warn, arena.allocator(), url, msg_ctx, out);699 try formatItem(Warn, item, arena.allocator(), url, msg_ctx, out);
703 _ = arena.reset(.retain_capacity);700 _ = arena.reset(.retain_capacity);
704 }701 }
705}702}
706703
707fn formatItem(704fn formatItem(
708 item: Item,705 comptime T: type,
709 item_type: Item.Type,706 item: Item(T),
710 arena: Allocator,707 arena: Allocator,
711 url: []const u8,708 url: []const u8,
712 ctx_init: MsgContext,709 ctx_init: MsgContext,
...@@ -720,10 +717,8 @@ fn formatItem(...@@ -720,10 +717,8 @@ fn formatItem(
720 ctx.components = ArrayListUnmanaged(Component).initCapacity(alloc, 16) catch717 ctx.components = ArrayListUnmanaged(Component).initCapacity(alloc, 16) catch
721 unreachable; // stack-fallback allocator has enough space.718 unreachable; // stack-fallback allocator has enough space.
722719
723 switch (item_type) {720 switch (item.data) {
724 inline else => |tag| switch (@field(item.data, @tagName(tag))) {721 inline else => |payload| try payload.build(&ctx),
725 inline else => |payload| try payload.build(&ctx),
726 },
727 }722 }
728723
729 assert(ctx.components.items.len > 0);724 assert(ctx.components.items.len > 0);
...@@ -744,8 +739,10 @@ fn formatItem(...@@ -744,8 +739,10 @@ fn formatItem(
744739
745 for (ctx.components.items, 1..) |component, i| {740 for (ctx.components.items, 1..) |component, i| {
746 const prefix: Prefix = if (i == 1)741 const prefix: Prefix = if (i == 1)
747 switch (item_type) {742 switch (T) {
748 inline else => |tag| @field(Prefix, @tagName(tag)),743 Err => .@"error",
744 Warn => .warn,
745 else => @compileError(unreachable),
749 }746 }
750 else747 else
751 .note;748 .note;
...@@ -862,8 +859,8 @@ fn formatItem(...@@ -862,8 +859,8 @@ fn formatItem(
862859
863pub const Builder = struct {860pub const Builder = struct {
864 gpa: Allocator,861 gpa: Allocator,
865 errors: ArrayListUnmanaged(Item),862 errors: ArrayListUnmanaged(Item(Err)),
866 warnings: ArrayListUnmanaged(Item),863 warnings: ArrayListUnmanaged(Item(Warn)),
867 string_bytes: ArrayListUnmanaged(u8),864 string_bytes: ArrayListUnmanaged(u8),
868865
869 pub fn init(gpa: Allocator) Builder {866 pub fn init(gpa: Allocator) Builder {
...@@ -890,7 +887,7 @@ pub const Builder = struct {...@@ -890,7 +887,7 @@ pub const Builder = struct {
890 return_address: usize,887 return_address: usize,
891 ) !void {888 ) !void {
892 try b.errors.append(b.gpa, .{889 try b.errors.append(b.gpa, .{
893 .data = .{ .@"error" = @unionInit(Err, @tagName(kind), data) },890 .data = @unionInit(Err, @tagName(kind), data),
894 .debug_stack_trace = DebugStoredTrace.capture(return_address),891 .debug_stack_trace = DebugStoredTrace.capture(return_address),
895 });892 });
896 }893 }
...@@ -902,7 +899,7 @@ pub const Builder = struct {...@@ -902,7 +899,7 @@ pub const Builder = struct {
902 return_address: usize,899 return_address: usize,
903 ) !void {900 ) !void {
904 try b.warnings.append(b.gpa, .{901 try b.warnings.append(b.gpa, .{
905 .data = .{ .warn = @unionInit(Warn, @tagName(kind), data) },902 .data = @unionInit(Warn, @tagName(kind), data),
906 .debug_stack_trace = DebugStoredTrace.capture(return_address),903 .debug_stack_trace = DebugStoredTrace.capture(return_address),
907 });904 });
908 }905 }
src/core/Sema.zig+1-1
...@@ -46,7 +46,7 @@ instruction_step_lock: std.debug.SafetyLock,...@@ -46,7 +46,7 @@ instruction_step_lock: std.debug.SafetyLock,
4646
47pub const Error = error{47pub const Error = error{
48 /// The analysis of this branch or declaration has failed.48 /// The analysis of this branch or declaration has failed.
49 /// At least one error will be placed in the `Sema`'s report49 /// At least one error will exist in `.report`
50 AnalysisFail,50 AnalysisFail,
51 /// There is a dependency on another declaration that we are waiting on.51 /// There is a dependency on another declaration that we are waiting on.
52 Interrupt,52 Interrupt,