Skip to content

Commit 4b19729

Browse files
mlechuc42f
andcommitted
Changes from code review
Co-authored-by: Claire Foster <[email protected]>
1 parent 36fb40e commit 4b19729

File tree

6 files changed

+378
-406
lines changed

6 files changed

+378
-406
lines changed

src/desugaring.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3814,7 +3814,7 @@ function insert_struct_shim(ctx, fieldtypes, name)
38143814
ex[2].name_val == name.name_val
38153815
@ast ctx ex [K"call" "struct_name_shim"::K"core" ex[1] ex[2] ctx.mod::K"Value" name]
38163816
elseif numchildren(ex) > 0
3817-
@ast ctx ex [ex.kind map(replace_type, children(ex))...]
3817+
mapchildren(replace_type, ctx, ex)
38183818
else
38193819
ex
38203820
end

src/linear_ir.jl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,11 @@ function emit_label(ctx, srcref)
378378
l
379379
end
380380

381+
function emit_latestworld(ctx, srcref)
382+
(isempty(ctx.code) || kind(last(ctx.code)) != K"latestworld") &&
383+
emit(ctx, makeleaf(ctx, srcref, K"latestworld"))
384+
end
385+
381386
function compile_condition_term(ctx, ex)
382387
cond = compile(ctx, ex, true, false)
383388
if !is_valid_body_ir_argument(ctx, cond)
@@ -831,7 +836,7 @@ function compile(ctx::LinearIRContext, ex, needs_value, in_tail_pos)
831836
throw(LoweringError(ex, "misplaced global declaration in value position"))
832837
end
833838
emit(ctx, ex)
834-
ctx.is_toplevel_thunk && emit(ctx, makenode(ctx, ex, K"latestworld"))
839+
ctx.is_toplevel_thunk && emit_latestworld(ctx, ex)
835840
nothing
836841
elseif k == K"meta"
837842
emit(ctx, ex)
@@ -888,11 +893,11 @@ function compile(ctx::LinearIRContext, ex, needs_value, in_tail_pos)
888893
rr = emit_assign_tmp(ctx, ex[2])
889894
emit(ctx, @ast ctx ex [K"globaldecl" ex[1] rr])
890895
end
891-
ctx.is_toplevel_thunk && emit(ctx, makenode(ctx, ex, K"latestworld"))
896+
ctx.is_toplevel_thunk && emit_latestworld(ctx, ex)
892897
elseif k == K"latestworld"
893-
emit(ctx, ex)
898+
emit_latestworld(ctx, ex)
894899
elseif k == K"latestworld_if_toplevel"
895-
ctx.is_toplevel_thunk && emit(ctx, makeleaf(ctx, ex, K"latestworld"))
900+
ctx.is_toplevel_thunk && emit_latestworld(ctx, ex)
896901
else
897902
throw(LoweringError(ex, "Invalid syntax; $(repr(k))"))
898903
end

test/closures_ir.jl

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -449,13 +449,12 @@ end
449449
2 (call %₁ slot₂/y 2)
450450
3 (return %₂)
451451
16 (latestworld)
452-
17 (latestworld)
453-
18 TestMod.#do##0
454-
19 (new %₁₈)
455-
20 (latestworld)
456-
21 TestMod.x
457-
22 (call core.kwcall %%%₁₉ %₂₁)
458-
23 (return %₂₂)
452+
17 TestMod.#do##0
453+
18 (new %₁₇)
454+
19 (latestworld)
455+
20 TestMod.x
456+
21 (call core.kwcall %%%₁₈ %₂₀)
457+
22 (return %₂₁)
459458

460459
########################################
461460
# Error: Static parameter clashing with closure name
@@ -701,13 +700,12 @@ end
701700
42 (call JuliaLowering.replace_captured_locals! %₃₉ %₄₁)
702701
43 --- method core.nothing %₃₈ %₄₂
703702
44 (latestworld)
704-
45 (latestworld)
705-
46 TestMod.#f_kw_closure##0
706-
47 (call core.svec %₄₆)
707-
48 (call core.svec)
708-
49 SourceLocation::2:14
709-
50 (call core.svec %₄₇ %₄₈ %₄₉)
710-
51 --- method core.nothing %₅₀
703+
45 TestMod.#f_kw_closure##0
704+
46 (call core.svec %₄₅)
705+
47 (call core.svec)
706+
48 SourceLocation::2:14
707+
49 (call core.svec %₄₆ %₄₇ %₄₈)
708+
50 --- method core.nothing %₄₉
711709
slots: [slot₁/#self# slot₂/#f_kw_closure#0(!read)]
712710
1 (call core.getfield slot₁/#self# :#f_kw_closure#0)
713711
2 (call core.isdefined %:contents)
@@ -719,9 +717,9 @@ end
719717
8 TestMod.x_default
720718
9 (call %%₈ slot₁/#self#)
721719
10 (return %₉)
722-
52 (latestworld)
723-
53 slot₃/f_kw_closure
724-
54 (return %)
720+
51 (latestworld)
721+
52 slot₃/f_kw_closure
722+
53 (return %)
725723

726724
########################################
727725
# Closure capturing a typed local must also capture the type expression

test/functions_ir.jl

Lines changed: 99 additions & 107 deletions
Large diffs are not rendered by default.

test/generators_ir.jl

Lines changed: 47 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@
1717
2 (call %₁ slot₂/x 1)
1818
3 (return %₂)
1919
11 (latestworld)
20-
12 (latestworld)
21-
13 TestMod.#->##0
22-
14 (new %₁₃)
23-
15 (latestworld)
24-
16 TestMod.xs
25-
17 (call top.Generator %₁₄ %₁₆)
26-
18 (return %₁₇)
20+
12 TestMod.#->##0
21+
13 (new %₁₂)
22+
14 (latestworld)
23+
15 TestMod.xs
24+
16 (call top.Generator %₁₃ %₁₅)
25+
17 (return %₁₆)
2726

2827
########################################
2928
# Product iteration
@@ -52,15 +51,14 @@
5251
10 (call %%%₉)
5352
11 (return %₁₀)
5453
11 (latestworld)
55-
12 (latestworld)
56-
13 TestMod.#->##1
57-
14 (new %₁₃)
58-
15 (latestworld)
59-
16 TestMod.xs
60-
17 TestMod.ys
61-
18 (call top.product %₁₆ %₁₇)
62-
19 (call top.Generator %₁₄ %₁₈)
63-
20 (return %₁₉)
54+
12 TestMod.#->##1
55+
13 (new %₁₂)
56+
14 (latestworld)
57+
15 TestMod.xs
58+
16 TestMod.ys
59+
17 (call top.product %₁₅ %₁₆)
60+
18 (call top.Generator %₁₃ %₁₇)
61+
19 (return %₁₈)
6462

6563
########################################
6664
# Use `identity` as the Generator function when possible eg in filters
@@ -88,14 +86,13 @@
8886
9 (call %%₈)
8987
10 (return %₉)
9088
11 (latestworld)
91-
12 (latestworld)
92-
13 TestMod.#->##2
93-
14 (new %₁₃)
94-
15 (latestworld)
95-
16 TestMod.iter
96-
17 (call top.Filter %₁₄ %₁₆)
97-
18 (call top.Generator top.identity %₁₇)
98-
19 (return %₁₈)
89+
12 TestMod.#->##2
90+
13 (new %₁₂)
91+
14 (latestworld)
92+
15 TestMod.iter
93+
16 (call top.Filter %₁₃ %₁₅)
94+
17 (call top.Generator top.identity %₁₆)
95+
18 (return %₁₇)
9996

10097
########################################
10198
# Use of placeholders in iteration vars
@@ -114,13 +111,12 @@
114111
slots: [slot₁/#self#(!read) slot₂/_(!read)]
115112
1 (return 1)
116113
11 (latestworld)
117-
12 (latestworld)
118-
13 TestMod.#->##3
119-
14 (new %₁₃)
120-
15 (latestworld)
121-
16 TestMod.xs
122-
17 (call top.Generator %₁₄ %₁₆)
123-
18 (return %₁₇)
114+
12 TestMod.#->##3
115+
13 (new %₁₂)
116+
14 (latestworld)
117+
15 TestMod.xs
118+
16 (call top.Generator %₁₃ %₁₅)
119+
17 (return %₁₆)
124120

125121
########################################
126122
# Error: Use of placeholders in body
@@ -158,13 +154,12 @@ LoweringError:
158154
11 TestMod.body
159155
12 (return %₁₁)
160156
11 (latestworld)
161-
12 (latestworld)
162-
13 TestMod.#->##5
163-
14 (new %₁₃)
164-
15 (latestworld)
165-
16 TestMod.iter
166-
17 (call top.Generator %₁₄ %₁₆)
167-
18 (return %₁₇)
157+
12 TestMod.#->##5
158+
13 (new %₁₂)
159+
14 (latestworld)
160+
15 TestMod.iter
161+
16 (call top.Generator %₁₃ %₁₅)
162+
17 (return %₁₆)
168163

169164
########################################
170165
# return permitted in quoted syntax in generator
@@ -184,13 +179,12 @@ LoweringError:
184179
1 (call JuliaLowering.interpolate_ast (inert (return x)))
185180
2 (return %₁)
186181
11 (latestworld)
187-
12 (latestworld)
188-
13 TestMod.#->##6
189-
14 (new %₁₃)
190-
15 (latestworld)
191-
16 TestMod.iter
192-
17 (call top.Generator %₁₄ %₁₆)
193-
18 (return %₁₇)
182+
12 TestMod.#->##6
183+
13 (new %₁₂)
184+
14 (latestworld)
185+
15 TestMod.iter
186+
16 (call top.Generator %₁₃ %₁₅)
187+
17 (return %₁₆)
194188

195189
########################################
196190
# Error: `return` not permitted in generator body
@@ -238,15 +232,14 @@ LoweringError:
238232
5 (call top.Generator %%₄)
239233
6 (return %₅)
240234
22 (latestworld)
241-
23 (latestworld)
242-
24 TestMod.#->##7
243-
25 (new %₂₄)
244-
26 (latestworld)
245-
27 TestMod.:
246-
28 (call %₂₇ 1 3)
247-
29 (call top.Generator %₂₅ %₂₈)
248-
30 (call top.Flatten %₂₉)
249-
31 (return %₃₀)
235+
23 TestMod.#->##7
236+
24 (new %₂₃)
237+
25 (latestworld)
238+
26 TestMod.:
239+
27 (call %₂₆ 1 3)
240+
28 (call top.Generator %₂₄ %₂₇)
241+
29 (call top.Flatten %₂₈)
242+
30 (return %₂₉)
250243

251244
########################################
252245
# Comprehension lowers to generator with collect

0 commit comments

Comments
 (0)