Skip to content

Commit 5d68959

Browse files
Merge pull request #7628 from roc-lang/parse-s-expr
Various changes
2 parents 1620ed0 + 2648141 commit 5d68959

File tree

33 files changed

+390
-589
lines changed

33 files changed

+390
-589
lines changed

crates/cli/tests/test-projects/issue7461.roc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ new_scatter = \{ data, orientation ? Vertical, name ? ""} ->
3636
}
3737
)
3838

39-
# CHANING ANYHTING IN HERE SEEMS TO "FIX" IT
39+
# CHANING ANYTHING IN HERE SEEMS TO "FIX" IT
4040
scatter_to_str : Trace x -> Str where x implements Inspect
4141
scatter_to_str = \@Trace inner ->
4242

@@ -62,4 +62,4 @@ new_marker : {} -> Result Marker _
6262
new_marker = \{} -> Ok (@Marker {})
6363

6464
marker_to_str : Marker -> Str
65-
marker_to_str = \_ -> ""
65+
marker_to_str = \_ -> ""

crates/glue/writing_a_glue_plugin.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Writing a glue plugin
22

3-
In order to write a platform, the language the platform is written in must know how to interoperate with Roc. As Roc is statically typed, the required FFI wrapper code must be tailored to the datatypes that form the FFI boundry between the host and the Roc application. Handily, the `roc glue` subcommand will take these types as defined in a `platform.roc` file and turn them into layout information. A glue plugin then in turn uses this to generate the appropriate source code in a target language. This layout information comes in the form of a data structure that requires some additional explanation.
3+
In order to write a platform, the language the platform is written in must know how to interoperate with Roc. As Roc is statically typed, the required FFI wrapper code must be tailored to the datatypes that form the FFI boundary between the host and the Roc application. Handily, the `roc glue` subcommand will take these types as defined in a `platform.roc` file and turn them into layout information. A glue plugin then in turn uses this to generate the appropriate source code in a target language. This layout information comes in the form of a data structure that requires some additional explanation.
44

55
- [Writing a glue plugin](#writing-a-glue-plugin)
66
- [The Types data structure](#the-types-data-structure)
@@ -30,7 +30,7 @@ In order to write a platform, the language the platform is written in must know
3030

3131
# The Types data structure
3232

33-
`Types` is a data structure that stores the layout information of all types on the host-application FFI boundry for a specific architecture. This includes these types' size, alignment, order of declaration, and their `Shape`.
33+
`Types` is a data structure that stores the layout information of all types on the host-application FFI boundary for a specific architecture. This includes these types' size, alignment, order of declaration, and their `Shape`.
3434

3535
# The Shape data structure
3636

@@ -51,7 +51,7 @@ A number type. Either a signed integer (I8 through I128), an unsigned integer (U
5151
## RocStr, RocList, RocDict, RocSet, RocBox
5252

5353
Roc builtin datatypes. The Roc compiler is planned to expose parts of the standard library to glue code via C FFI to avoid having the reimplement them by hand in every host language. In the meantime:
54-
- The authoratitive Zig implementations for Roc builtins can be found under `crates/compiler/builtins/bitcode/src`. These are more made for use by the compiler, and thus are better used for reference than for human use.
54+
- The authoritative Zig implementations for Roc builtins can be found under `crates/compiler/builtins/bitcode/src`. These are more made for use by the compiler, and thus are better used for reference than for human use.
5555
- Rust implementations of the `Str`, `List`, and `Box` datatypes can be found under `crates/roc_std`. These are made for use by humans, and as such are a better example for what their wrapper APIs might look like. Do note that these are not guaranteed to be in sync with their Zig implementations.
5656

5757
## Struct
@@ -154,7 +154,7 @@ Color : [Red, Green, Blue]
154154
```roc
155155
# shape reported by `roc glue`
156156
TagUnion (Enumeration {
157-
name: "Expr",
157+
name: "Expr",
158158
size: 1,
159159
tags: ["Blue", "Green", "Red"]
160160
})
@@ -343,7 +343,7 @@ ConsList : [
343343
```roc
344344
# shape reported by `roc glue`
345345
TagUnion (NullableUnwrapped {
346-
name: "ConsList",
346+
name: "ConsList",
347347
nonNullPayload: (@TypeId 3), # == TagUnionPayload { name: ConsList_Cons, .. }
348348
nonNullTag: "Cons",
349349
nullTag: "Nil",
@@ -418,7 +418,7 @@ Color [
418418
name: "Color_Rgb",
419419
fields: (HasNoClosure [
420420
# `@TypeId 1` == `Num U8`
421-
{id: (@TypeId 1), name: "0"},
421+
{id: (@TypeId 1), name: "0"},
422422
{id: (@TypeId 1), name: "1"},
423423
{id: (@TypeId 1), name: "2"}
424424
]),
@@ -447,4 +447,4 @@ TODO
447447

448448
## RecursivePointer
449449

450-
(TODO: a `RecursivePointer` causes no code to be generated in `RustGlue.roc`, and is otherwise always treated as an instance of the type it's "pointing to", with no pointer indirection like the name implies. Is this shape vestigial?)
450+
(TODO: a `RecursivePointer` causes no code to be generated in `RustGlue.roc`, and is otherwise always treated as an instance of the type it's "pointing to", with no pointer indirection like the name implies. Is this shape vestigial?)

src/README.fuzzing.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ If the test case is complex or interesting, it likely is worthwhile to add a sna
5050

5151
For better fuzzing performance you will want to modify `std.mem.backend_can_use_eql_bytes` to return false, otherwise AFL++ will not be able to observe char-by-char string comparisons and its fuzzing capabilities will be greatly reduced.
5252

53-
This means modifying your copy of the Zig stdlib. If you have ZLS you can simply write `std.mem` anywhere in your code and goto definiton, otherwise you can invoke `zig env` and modify `$std_dir/mem.zig`.
53+
This means modifying your copy of the Zig stdlib. If you have ZLS you can simply write `std.mem` anywhere in your code and goto definition, otherwise you can invoke `zig env` and modify `$std_dir/mem.zig`.
5454

5555
**Also don't forget to revert this change after you're done!**
5656

5757
## Advanced Usage
5858

5959
afl++ has a ton of bells and whistle to get way more performance and better results out of it.
60-
The largest one is probably [running multiple copies of afl (preferrably with different configs)](https://aflplus.plus/docs/fuzzing_in_depth/#c-using-multiple-cores) to use all your compute power.
60+
The largest one is probably [running multiple copies of afl (preferably with different configs)](https://aflplus.plus/docs/fuzzing_in_depth/#c-using-multiple-cores) to use all your compute power.
6161

6262
Probably the largest other gain is in keeping around and managing a corpus of examples.
6363
This enables the fuzzer to build up more and more information about the target executable of different execution sessions.

src/base.zig

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ pub const Ident = @import("base/Ident.zig");
22
pub const Module = @import("base/Module.zig");
33
pub const Region = @import("base/Region.zig");
44
pub const Package = @import("base/Package.zig");
5-
pub const TagName = @import("base/TagName.zig");
6-
pub const FieldName = @import("base/FieldName.zig");
75
pub const ModuleEnv = @import("base/ModuleEnv.zig");
8-
pub const TypeVarName = @import("base/TypeVarName.zig");
96
pub const StringLiteral = @import("base/StringLiteral.zig");
107

118
pub const Recursive = enum {

src/base/FieldName.zig

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/base/Ident.zig

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,15 @@ pub const Store = struct {
5757
exposing_modules: std.ArrayList(Module.Idx),
5858
next_unique_name: u32,
5959

60-
pub fn init(allocator: std.mem.Allocator) Store {
60+
pub fn init(arena: *std.heap.ArenaAllocator) Store {
6161
return Store{
62-
.interner = SmallStringInterner.init(allocator),
63-
.exposing_modules = std.ArrayList(Module.Idx).init(allocator),
62+
.interner = SmallStringInterner.init(arena),
63+
// error: expected type 'heap.arena_allocator.ArenaAllocator', found '*heap.arena_allocator.ArenaAllocator'
64+
.exposing_modules = std.ArrayList(Module.Idx).init(arena.allocator()),
6465
.next_unique_name = 0,
6566
};
6667
}
6768

68-
pub fn deinit(self: *Store) void {
69-
self.interner.deinit();
70-
self.exposing_modules.deinit();
71-
}
72-
7369
pub fn insert(self: *Store, ident: Ident, region: Region) Idx {
7470
const idx = self.interner.insert(ident.raw_text, region);
7571
self.exposing_modules.append(@enumFromInt(0)) catch exitOnOom();

src/base/Module.zig

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,28 +32,28 @@ pub const Idx = List.Idx;
3232
pub const Store = struct {
3333
modules: List,
3434
ident_store: *Ident.Store,
35-
allocator: std.mem.Allocator,
35+
arena: *std.heap.ArenaAllocator,
3636

3737
pub const LookupResult = struct {
3838
module_idx: Idx,
3939
was_present: bool,
4040
};
4141

42-
pub fn init(allocator: std.mem.Allocator, ident_store: *Ident.Store) Store {
43-
var modules = collections.SafeMultiList(Module).init(allocator);
42+
pub fn init(arena: *std.heap.ArenaAllocator, ident_store: *Ident.Store) Store {
43+
var modules = collections.SafeMultiList(Module).init(arena.allocator());
4444
_ = modules.append(Module{
4545
.name = &.{},
4646
.package_shorthand = null,
4747
.is_builtin = false,
48-
.exposed_idents = collections.SafeList(Ident.Idx).init(allocator),
48+
.exposed_idents = collections.SafeList(Ident.Idx).init(arena.allocator()),
4949
});
5050

5151
// TODO: insert builtins automatically?
5252

5353
return Store{
5454
.modules = modules,
5555
.ident_store = ident_store,
56-
.allocator = allocator,
56+
.arena = arena,
5757
};
5858
}
5959

@@ -109,7 +109,7 @@ pub const Store = struct {
109109
.name = name,
110110
.package_shorthand = package_shorthand,
111111
.is_builtin = false,
112-
.exposed_idents = collections.SafeList(Ident.Idx).init(self.allocator),
112+
.exposed_idents = collections.SafeList(Ident.Idx).init(self.arena.allocator()),
113113
});
114114

115115
return LookupResult{ .module_idx = idx, .was_present = false };

src/base/ModuleEnv.zig

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ const problem = @import("../problem.zig");
1010

1111
const Ident = @import("./Ident.zig");
1212
const Module = @import("./Module.zig");
13-
const TagName = @import("./TagName.zig");
14-
const FieldName = @import("./FieldName.zig");
1513
const StringLiteral = @import("./StringLiteral.zig");
1614
const Type = @import("../types/type.zig").Type;
1715

@@ -22,41 +20,25 @@ const Self = @This();
2220
idents: Ident.Store,
2321
ident_ids_for_slicing: collections.SafeList(Ident.Idx),
2422
modules: Module.Store,
25-
tag_names: TagName.Store,
26-
tag_name_ids_for_slicing: collections.SafeList(TagName.Idx),
27-
field_names: FieldName.Store,
2823
strings: StringLiteral.Store,
2924
problems: std.ArrayList(Problem),
3025
type_store: Type.Store,
26+
arena: *std.heap.ArenaAllocator,
3127

32-
pub fn init(allocator: std.mem.Allocator) Self {
33-
var ident_store = Ident.Store.init(allocator);
28+
pub fn init(arena: *std.heap.ArenaAllocator) Self {
29+
var ident_store = Ident.Store.init(arena);
3430

3531
return Self{
3632
.idents = ident_store,
37-
.ident_ids_for_slicing = collections.SafeList(Ident.Idx).init(allocator),
38-
.modules = Module.Store.init(allocator, &ident_store),
39-
.tag_names = TagName.Store.init(allocator),
40-
.tag_name_ids_for_slicing = collections.SafeList(TagName.Idx).init(allocator),
41-
.field_names = FieldName.Store.init(allocator),
42-
.strings = StringLiteral.Store.init(allocator),
43-
.problems = std.ArrayList(Problem).init(allocator),
44-
.type_store = Type.Store.init(allocator),
33+
.ident_ids_for_slicing = collections.SafeList(Ident.Idx).init(arena.allocator()),
34+
.modules = Module.Store.init(arena, &ident_store),
35+
.strings = StringLiteral.Store.init(arena.allocator()),
36+
.problems = std.ArrayList(Problem).init(arena.allocator()),
37+
.type_store = Type.Store.init(arena.allocator()),
38+
.arena = arena,
4539
};
4640
}
4741

48-
pub fn deinit(self: *Self) void {
49-
self.idents.deinit();
50-
self.ident_ids_for_slicing.deinit();
51-
self.modules.deinit();
52-
self.tag_names.deinit();
53-
self.tag_name_ids_for_slicing.deinit();
54-
self.field_names.deinit();
55-
self.strings.deinit();
56-
self.problems.deinit();
57-
self.type_store.deinit();
58-
}
59-
6042
pub fn addExposedIdentForModule(self: *Self, ident: Ident.Idx, module: Module.Idx) void {
6143
self.modules.addExposedIdent(module, ident, &self.problems);
6244
self.idents.setExposingModule(ident, module);

src/base/Region.zig

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@ pub fn zero() Region {
1818
};
1919
}
2020

21-
pub fn format(self: *const Region, comptime fmt: []const u8, _: std.fmt.FormatOptions, writer: anytype) void {
21+
pub fn format(self: *const Region, comptime fmt: []const u8, _: std.fmt.FormatOptions, writer: std.io.AnyWriter) !void {
2222
if (fmt.len != 0) {
2323
std.fmt.invalidFmtError(fmt, self);
2424
}
2525

26-
if ((self.start == Position.zero()) and (self.end == Position.zero())) {
26+
if ((self.start.isZero()) and (self.end.isZero())) {
2727
// In tests, it's super common to set all Located values to 0.
2828
// Also in tests, we don't want to bother printing the locations
2929
// because it makes failed assertions much harder to read.
30-
return writer.print("…", .{});
30+
try writer.print("…", .{});
3131
} else {
32-
return writer.print("@{}-{}", .{ self.start.offset, self.end.offset });
32+
try writer.print("@{}-{}", .{ self.start.offset, self.end.offset });
3333
}
3434
}
3535

@@ -39,4 +39,8 @@ pub const Position = struct {
3939
pub fn zero() Position {
4040
return Position{ .offset = 0 };
4141
}
42+
43+
pub fn isZero(self: Position) bool {
44+
return self.offset == 0;
45+
}
4246
};

src/base/TagName.zig

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)