Skip to content

Commit cb3ac41

Browse files
committed
Fix some tests
1 parent 4dac237 commit cb3ac41

File tree

9 files changed

+44
-38
lines changed

9 files changed

+44
-38
lines changed

src/repl/eval.zig

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,21 @@ const LoadedModule = struct {
2727
gpa: std.mem.Allocator,
2828

2929
fn deinit(self: *LoadedModule) void {
30-
// IMPORTANT: When a module is deserialized from a buffer, all its internal structures
31-
// (common, types, external_decls, imports, store) contain pointers INTO the buffer,
32-
// not separately allocated memory. Therefore we should NOT call deinit() on any of them.
33-
// The only memory we need to free is:
34-
// 1. The buffer itself (which contains all the deserialized data)
35-
// 2. The env struct itself (which was allocated with create())
36-
37-
// Free the buffer (all data structures point into this buffer)
30+
// IMPORTANT: When a module is deserialized from a buffer, most internal structures
31+
// (common, types, external_decls, store, imports.items) contain pointers INTO the buffer,
32+
// not separately allocated memory. However, the imports HASHMAP IS separately
33+
// allocated during deserialization and MUST be freed.
34+
//
35+
// Memory to free:
36+
// 1. The imports hashmap only (allocated during deserialization at CIR.zig:648)
37+
// 2. The buffer itself (which contains all the deserialized data)
38+
// 3. The env struct itself (which was allocated with create())
39+
40+
// Free ONLY the imports hashmap (allocated during deserialization at CIR.zig:648)
41+
// Do NOT call full deinit on imports store as the items list points into the buffer!
42+
self.env.imports.map.deinit(self.gpa);
43+
44+
// Free the buffer (all other data structures point into this buffer)
3845
self.gpa.free(self.buffer);
3946

4047
// Free the env struct itself

test/snapshots/can_import_exposing_types.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -751,8 +751,8 @@ combineResults = |jsonResult, httpStatus|
751751
(p-assign (ident "handleRequest"))
752752
(e-closure
753753
(captures
754-
(capture (ident "error"))
755-
(capture (ident "value")))
754+
(capture (ident "value"))
755+
(capture (ident "error")))
756756
(e-lambda
757757
(args
758758
(p-assign (ident "req")))
@@ -841,8 +841,8 @@ combineResults = |jsonResult, httpStatus|
841841
(p-assign (ident "handleResponse"))
842842
(e-closure
843843
(captures
844-
(capture (ident "error"))
845-
(capture (ident "status")))
844+
(capture (ident "status"))
845+
(capture (ident "error")))
846846
(e-lambda
847847
(args
848848
(p-assign (ident "response")))

test/snapshots/crash_and_ellipsis_test.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,9 @@ main! = |_| {
235235
(p-assign (ident "main!"))
236236
(e-closure
237237
(captures
238-
(capture (ident "testCrashSimple"))
239238
(capture (ident "testEllipsis"))
240-
(capture (ident "testCrash")))
239+
(capture (ident "testCrash"))
240+
(capture (ident "testCrashSimple")))
241241
(e-lambda
242242
(args
243243
(p-underscore))

test/snapshots/formatting/multiline_without_comma/everything.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1766,7 +1766,6 @@ h = |x, y| {
17661766
(capture (ident "h"))
17671767
(capture (ident "a"))
17681768
(capture (ident "a"))
1769-
(capture (ident "h"))
17701769
(capture (ident "a"))
17711770
(capture (ident "a")))
17721771
(e-lambda

test/snapshots/function_no_annotation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ NO CHANGE
137137
(p-assign (ident "process!"))
138138
(e-closure
139139
(captures
140-
(capture (ident "multiply"))
141-
(capture (ident "print_number!")))
140+
(capture (ident "print_number!"))
141+
(capture (ident "multiply")))
142142
(e-lambda
143143
(args
144144
(p-assign (ident "x")))

test/snapshots/lambda_capture/lambda_capture_three_levels.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ NO CHANGE
6060
(p-assign (ident "middle")))
6161
(e-closure
6262
(captures
63-
(capture (ident "middle"))
64-
(capture (ident "outer")))
63+
(capture (ident "outer"))
64+
(capture (ident "middle")))
6565
(e-lambda
6666
(args
6767
(p-assign (ident "inner")))

test/snapshots/let_polymorphism_lists.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,9 +397,9 @@ main = |_| {
397397
(p-assign (ident "main"))
398398
(e-closure
399399
(captures
400+
(capture (ident "all_int_list"))
400401
(capture (ident "all_str_list"))
401-
(capture (ident "all_float_list"))
402-
(capture (ident "all_int_list")))
402+
(capture (ident "all_float_list")))
403403
(e-lambda
404404
(args
405405
(p-underscore))

test/snapshots/static_dispatch/MethodDispatch.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -244,12 +244,12 @@ NO CHANGE
244244
(annotation
245245
(ty-fn (effectful false)
246246
(ty-rigid-var (name "a"))
247-
(ty-lookup (name "Str") (builtin)))
247+
(ty-lookup (name "Str") (external-module "Str")))
248248
(where
249249
(method (ty-rigid-var-lookup (ty-rigid-var (name "a"))) (name "get_value")
250250
(args
251251
(ty-rigid-var-lookup (ty-rigid-var (name "a"))))
252-
(ty-lookup (name "Str") (builtin))))))
252+
(ty-lookup (name "Str") (external-module "Str"))))))
253253
(d-let
254254
(p-assign (ident "modify"))
255255
(e-lambda
@@ -268,17 +268,17 @@ NO CHANGE
268268
(ty-rigid-var (name "a"))
269269
(ty-parens
270270
(ty-fn (effectful false)
271-
(ty-lookup (name "Str") (builtin))
272-
(ty-lookup (name "Str") (builtin))))
271+
(ty-lookup (name "Str") (external-module "Str"))
272+
(ty-lookup (name "Str") (external-module "Str"))))
273273
(ty-rigid-var-lookup (ty-rigid-var (name "a"))))
274274
(where
275275
(method (ty-rigid-var-lookup (ty-rigid-var (name "a"))) (name "transform")
276276
(args
277277
(ty-rigid-var-lookup (ty-rigid-var (name "a")))
278278
(ty-parens
279279
(ty-fn (effectful false)
280-
(ty-lookup (name "Str") (builtin))
281-
(ty-lookup (name "Str") (builtin)))))
280+
(ty-lookup (name "Str") (external-module "Str"))
281+
(ty-lookup (name "Str") (external-module "Str")))))
282282
(ty-rigid-var-lookup (ty-rigid-var (name "a")))))))
283283
(d-let
284284
(p-assign (ident "container"))
@@ -306,7 +306,7 @@ NO CHANGE
306306
(p-assign (ident "myContainer"))))
307307
(args))
308308
(annotation
309-
(ty-lookup (name "Str") (builtin))))
309+
(ty-lookup (name "Str") (external-module "Str"))))
310310
(d-let
311311
(p-assign (ident "result1"))
312312
(e-call
@@ -315,7 +315,7 @@ NO CHANGE
315315
(e-lookup-local
316316
(p-assign (ident "container"))))
317317
(annotation
318-
(ty-lookup (name "Str") (builtin))))
318+
(ty-lookup (name "Str") (external-module "Str"))))
319319
(d-let
320320
(p-assign (ident "result2"))
321321
(e-call
@@ -348,9 +348,9 @@ NO CHANGE
348348
(p-assign (ident "result2"))))))
349349
(annotation
350350
(ty-tuple
351-
(ty-lookup (name "Str") (builtin))
352-
(ty-lookup (name "Str") (builtin))
353-
(ty-lookup (name "Str") (builtin)))))
351+
(ty-lookup (name "Str") (external-module "Str"))
352+
(ty-lookup (name "Str") (external-module "Str"))
353+
(ty-lookup (name "Str") (external-module "Str")))))
354354
(d-let
355355
(p-assign (ident "Container.get_value"))
356356
(e-closure
@@ -365,7 +365,7 @@ NO CHANGE
365365
(annotation
366366
(ty-fn (effectful false)
367367
(ty-lookup (name "Container") (local))
368-
(ty-lookup (name "Str") (builtin)))))
368+
(ty-lookup (name "Str") (external-module "Str")))))
369369
(d-let
370370
(p-assign (ident "Container.transform"))
371371
(e-closure
@@ -389,14 +389,14 @@ NO CHANGE
389389
(ty-lookup (name "Container") (local))
390390
(ty-parens
391391
(ty-fn (effectful false)
392-
(ty-lookup (name "Str") (builtin))
393-
(ty-lookup (name "Str") (builtin))))
392+
(ty-lookup (name "Str") (external-module "Str"))
393+
(ty-lookup (name "Str") (external-module "Str"))))
394394
(ty-lookup (name "Container") (local)))))
395395
(s-nominal-decl
396396
(ty-header (name "Container"))
397397
(ty-tag-union
398398
(ty-tag-name (name "Box")
399-
(ty-lookup (name "Str") (builtin))))))
399+
(ty-lookup (name "Str") (external-module "Str"))))))
400400
~~~
401401
# TYPES
402402
~~~clojure

test/snapshots/type_higher_order_multiple_vars.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ main! = |_| {}
171171
(p-assign (ident "g")))
172172
(e-closure
173173
(captures
174-
(capture (ident "g"))
175-
(capture (ident "f")))
174+
(capture (ident "f"))
175+
(capture (ident "g")))
176176
(e-lambda
177177
(args
178178
(p-assign (ident "x")))

0 commit comments

Comments
 (0)