authorgravatar for me@paperdave.netdave caruso <me@paperdave.net> 2024-09-21 15:35:31-07:00
committergravatar for me@paperdave.netdave caruso <me@paperdave.net> 2024-09-21 15:35:31-07:00
logb23b6b4e532fa02ad461ce4d321e22d10db64858
tree9df1b5f3d943b1bfa7451440c68a44bd7a0bc3b4
parentf0f7c6e0da14e600e621576558c77cc999160801
signature Commit is signed but in an unrecognized format.

chore: reduce size of report in debug build


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

CHANGELOG.md+1
......@@ -1,6 +1,7 @@
11## 0.1.7
22
33- chore: rename the language to "ix"
4- feat: language manual gets a pleasing redesign
45- feat: allow any expression as a function body
56- fix: coerce `break` operands and implicit breaks to result type
67- fix: coerce results when `if` expression branches merge
doc/language-manual.md+12-75
......@@ -43,6 +43,14 @@ calling it when the program starts.
4343> In the future, common APIs will be available in the standard library, such as
4444> `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
4654## Primitive Data Types
4755
4856| name | ts equivalent | description |
......@@ -61,19 +69,18 @@ calling it when the program starts.
6169
6270### Built-in Constants
6371
64In addition to the above types being built-in constants, the following are
65available.
66
6772| name | description |
6873| ------- | ------------------------------------- |
6974| `true` | boolean true (result of `1 == 1`) |
7075| `false` | boolean false (result of `1 == 2`) |
7176| `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
7581```lang:build
7682fn main {
83 let opaque = -5.2;
7784 let true = 1 == 0;
7885}
7986```
......@@ -185,7 +192,7 @@ The function body is a block, which may use implicit return to return.
185192```lang:run
186193let print = @extern("console").log;
187194
188fn add(a: int, b: int) -> int {
195fn add(a: int, b: int) {
189196 a + b
190197}
191198
......@@ -194,10 +201,6 @@ fn main {
194201}
195202```
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
201204The `return` expression can be used within functions to return early.
202205
203206```lang:run
......@@ -296,69 +299,3 @@ fn main {
296299 print(Person{ name: "hello", age: 42 });
297300}
298301```
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 @@
55//!
66//! Across the compiler, `Report.Builder`s' `.err` and `.warn` methods
77//! can add messages by ID.
8errors: []Item,
9warnings: []Item,
8errors: []Item(Err),
9warnings: []Item(Warn),
1010string_bytes: []u8,
1111
1212pub const empty: Report = .{
......@@ -18,23 +18,20 @@ pub const empty: Report = .{
1818pub var debug_show_report_trace: if (builtin.mode == .Debug) bool else void =
1919 if (builtin.mode == .Debug) false;
2020
21pub const Item = struct {
22 /// What is this diagnostic
23 data: union { @"error": Err, warn: Warn },
24
25 debug_stack_trace: DebugStoredTrace = .empty,
26
27 /// Type is never stored, inferred from which list it is in.
28 pub const Type = enum { @"error", warn };
29};
21pub fn Item(T: type) type {
22 return struct {
23 data: T,
24 debug_stack_trace: DebugStoredTrace = .empty,
25 };
26}
3027
3128pub const Err = union(enum) {
3229 pub const FieldEnum = core.FieldEnum(Err);
3330
3431 /// Constructs a `Report` with just a single error.
3532 pub fn toReport(err: Err, alloc: Allocator, trace: DebugStoredTrace) !Report {
36 const errors = try alloc.dupe(Item, &.{.{
37 .data = .{ .@"error" = err },
33 const errors = try alloc.dupe(Item(Err), &.{.{
34 .data = err,
3835 .debug_stack_trace = trace,
3936 }});
4037 return .{ .errors = errors, .warnings = &.{}, .string_bytes = &.{} };
......@@ -641,7 +638,7 @@ pub fn dump(report: Report, ctx: DumpContext, out: core.OutStream) !void {
641638 const ast: *const Ast = switch (ctx) {
642639 .comp => |comp_ctx|
643640 // 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: {
645642 fake_ast_data = .{
646643 .utf8_source = (comp_ctx.file.getSource(comp_ctx.comp.gpa) catch {
647644 @panic("TODO");
......@@ -695,18 +692,18 @@ pub fn dump(report: Report, ctx: DumpContext, out: core.OutStream) !void {
695692 };
696693
697694 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);
699696 _ = arena.reset(.retain_capacity);
700697 }
701698 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);
703700 _ = arena.reset(.retain_capacity);
704701 }
705702}
706703
707704fn formatItem(
708 item: Item,
709 item_type: Item.Type,
705 comptime T: type,
706 item: Item(T),
710707 arena: Allocator,
711708 url: []const u8,
712709 ctx_init: MsgContext,
......@@ -720,10 +717,8 @@ fn formatItem(
720717 ctx.components = ArrayListUnmanaged(Component).initCapacity(alloc, 16) catch
721718 unreachable; // stack-fallback allocator has enough space.
722719
723 switch (item_type) {
724 inline else => |tag| switch (@field(item.data, @tagName(tag))) {
725 inline else => |payload| try payload.build(&ctx),
726 },
720 switch (item.data) {
721 inline else => |payload| try payload.build(&ctx),
727722 }
728723
729724 assert(ctx.components.items.len > 0);
......@@ -744,8 +739,10 @@ fn formatItem(
744739
745740 for (ctx.components.items, 1..) |component, i| {
746741 const prefix: Prefix = if (i == 1)
747 switch (item_type) {
748 inline else => |tag| @field(Prefix, @tagName(tag)),
742 switch (T) {
743 Err => .@"error",
744 Warn => .warn,
745 else => @compileError(unreachable),
749746 }
750747 else
751748 .note;
......@@ -862,8 +859,8 @@ fn formatItem(
862859
863860pub const Builder = struct {
864861 gpa: Allocator,
865 errors: ArrayListUnmanaged(Item),
866 warnings: ArrayListUnmanaged(Item),
862 errors: ArrayListUnmanaged(Item(Err)),
863 warnings: ArrayListUnmanaged(Item(Warn)),
867864 string_bytes: ArrayListUnmanaged(u8),
868865
869866 pub fn init(gpa: Allocator) Builder {
......@@ -890,7 +887,7 @@ pub const Builder = struct {
890887 return_address: usize,
891888 ) !void {
892889 try b.errors.append(b.gpa, .{
893 .data = .{ .@"error" = @unionInit(Err, @tagName(kind), data) },
890 .data = @unionInit(Err, @tagName(kind), data),
894891 .debug_stack_trace = DebugStoredTrace.capture(return_address),
895892 });
896893 }
......@@ -902,7 +899,7 @@ pub const Builder = struct {
902899 return_address: usize,
903900 ) !void {
904901 try b.warnings.append(b.gpa, .{
905 .data = .{ .warn = @unionInit(Warn, @tagName(kind), data) },
902 .data = @unionInit(Warn, @tagName(kind), data),
906903 .debug_stack_trace = DebugStoredTrace.capture(return_address),
907904 });
908905 }
src/core/Sema.zig+1-1
......@@ -46,7 +46,7 @@ instruction_step_lock: std.debug.SafetyLock,
4646
4747pub const Error = error{
4848 /// The analysis of this branch or declaration has failed.
49 /// At least one error will be placed in the `Sema`'s report
49 /// At least one error will exist in `.report`
5050 AnalysisFail,
5151 /// There is a dependency on another declaration that we are waiting on.
5252 Interrupt,