Skip to content

Commit 8a52e0c

Browse files
mlechuc42f
andcommitted
Disallow static_parameter as valid_ir_argument
See added comment, and discussion at #10 (comment) Co-authored-by: Claire Foster <[email protected]>
1 parent c5a1acd commit 8a52e0c

File tree

4 files changed

+68
-47
lines changed

4 files changed

+68
-47
lines changed

src/linear_ir.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ function is_valid_ir_argument(ctx, ex)
88
elseif k == K"BindingId"
99
binfo = lookup_binding(ctx, ex)
1010
bk = binfo.kind
11-
# TODO: Can we allow bk == :local || bk == :argument || bk == :static_parameter ???
12-
# Why does flisp seem to allow (slot) and (static_parameter), but these
13-
# aren't yet converted to by existing lowering??
14-
(bk == :slot || bk == :static_parameter)
11+
bk === :slot
12+
# TODO: We should theoretically be able to allow `bk ===
13+
# :static_parameter` for slightly more compact IR, but it's uncertain
14+
# what the compiler is built to tolerate. Notably, flisp allows
15+
# static_parameter, but doesn't produce this form until a later pass, so
16+
# it doesn't end up in the IR.
1517
else
1618
false
1719
end

test/closures_ir.jl

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -236,12 +236,14 @@ end
236236
23 --- method core.nothing %₂₂
237237
slots: [slot₁/#self#(!read) slot₂/_(!read) slot₃/g]
238238
1 TestMod.#f#g##2
239-
2 (call core.typeof static_parameter₁)
240-
3 (call core.apply_type %%₂)
241-
4 (new %₃ static_parameter₁)
242-
5 (= slot₃/g %₄)
243-
6 slot₃/g
244-
7 (return %₆)
239+
2 static_parameter₁
240+
3 (call core.typeof %₂)
241+
4 (call core.apply_type %%₃)
242+
5 static_parameter₁
243+
6 (new %%₅)
244+
7 (= slot₃/g %₆)
245+
8 slot₃/g
246+
9 (return %₈)
245247
24 (latestworld)
246248
25 TestMod.f
247249
26 (return %₂₅)

test/functions_ir.jl

Lines changed: 45 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,11 @@ end
161161
17 (call core.svec %₁₁ %₁₅ %₁₆)
162162
18 --- method core.nothing %₁₇
163163
slots: [slot₁/#self#(!read) slot₂/_(!read) slot₃/_(!read) slot₄/_(!read)]
164-
1 (call core.tuple static_parameter₃ static_parameter₁ static_parameter₂)
165-
2 (return %₁)
164+
1 static_parameter₃
165+
2 static_parameter₁
166+
3 static_parameter₂
167+
4 (call core.tuple %%%₃)
168+
5 (return %₄)
166169
19 (latestworld)
167170
20 TestMod.f
168171
21 (return %₂₀)
@@ -190,7 +193,8 @@ end
190193
15 (call core.svec %₁₁ %₁₃ %₁₄)
191194
16 --- method core.nothing %₁₅
192195
slots: [slot₁/#self#(!read) slot₂/_(!read)]
193-
1 (return static_parameter₁)
196+
1 static_parameter₁
197+
2 (return %₁)
194198
17 (latestworld)
195199
18 TestMod.f
196200
19 (return %₁₈)
@@ -220,8 +224,10 @@ end
220224
16 (call core.svec %₁₁ %₁₄ %₁₅)
221225
17 --- method core.nothing %₁₆
222226
slots: [slot₁/#self#(!read) slot₂/x(!read) slot₃/y(!read)]
223-
1 (call core.tuple static_parameter₁ static_parameter₂)
224-
2 (return %₁)
227+
1 static_parameter₁
228+
2 static_parameter₂
229+
3 (call core.tuple %%₂)
230+
4 (return %₃)
225231
18 (latestworld)
226232
19 TestMod.f
227233
20 (return %₁₉)
@@ -329,7 +335,8 @@ end
329335
10 (call core.svec %%%₉)
330336
11 --- method core.nothing %₁₀
331337
slots: [slot₁/x(!read)]
332-
1 (return static_parameter₁)
338+
1 static_parameter₁
339+
2 (return %₁)
333340
12 (latestworld)
334341
13 (return core.nothing)
335342

@@ -664,8 +671,11 @@ end
664671
38 (call core.svec %₃₂ %₃₆ %₃₇)
665672
39 --- method core.nothing %₃₈
666673
slots: [slot₁/#self#(!read) slot₂/x slot₃/y slot₄/z]
667-
1 (call core.tuple slot₂/x slot₃/y slot₄/z static_parameter₁ static_parameter₂ static_parameter₃)
668-
2 (return %₁)
674+
1 static_parameter₁
675+
2 static_parameter₂
676+
3 static_parameter₃
677+
4 (call core.tuple slot₂/x slot₃/y slot₄/z %%%₃)
678+
5 (return %₄)
669679
40 (latestworld)
670680
41 TestMod.f
671681
42 (return %₄₁)
@@ -1316,8 +1326,10 @@ end
13161326
19 --- method core.nothing %₁₈
13171327
slots: [slot₁/#self#(!read) slot₂/a(!read) slot₃/b(!read) slot₄/#self#(!read) slot₅/x(!read)]
13181328
1 (meta :nkw 2)
1319-
2 (call core.tuple static_parameter₁ static_parameter₂)
1320-
3 (return %₂)
1329+
2 static_parameter₁
1330+
3 static_parameter₂
1331+
4 (call core.tuple %%₃)
1332+
5 (return %₄)
13211333
20 (latestworld)
13221334
21 (= slot₄/X (call core.TypeVar :X))
13231335
22 (= slot₃/A (call core.TypeVar :A))
@@ -1343,28 +1355,30 @@ end
13431355
9 (= slot₅/kwtmp %₈)
13441356
10 slot₅/kwtmp
13451357
11 (call core.isdefined slot₂/kws :b)
1346-
12 (gotoifnot %₁₁ label₂)
1358+
12 (gotoifnot %₁₁ label₂)
13471359
13 (call core.getfield slot₂/kws :b)
1348-
14 (call core.isa %₁₃ static_parameter₁)
1349-
15 (gotoifnot %₁₄ label₁₇)
1350-
16 (goto label₁₉)
1351-
17 (new core.TypeError :keyword argument :b static_parameter₁ %₁₃)
1352-
18 (call core.throw %₁₇)
1353-
19 (= slot₅/kwtmp %₁₃)
1354-
20 (goto label₂₃)
1355-
21 TestMod.b_def
1356-
22 (= slot₅/kwtmp %₂₁)
1357-
23 slot₅/kwtmp
1358-
24 (call top.keys slot₂/kws)
1359-
25 (call core.tuple :a :b)
1360-
26 (call top.diff_names %₂₄ %₂₅)
1361-
27 (call top.isempty %₂₆)
1362-
28 (gotoifnot %₂₇ label₃₀)
1363-
29 (goto label₃₁)
1364-
30 (call top.kwerr slot₂/kws slot₃/#self# slot₄/x)
1365-
31 TestMod.#f_kw_sparams#0
1366-
32 (call %₃₁ %₁₀ %₂₃ slot₃/#self# slot₄/x)
1367-
33 (return %₃₂)
1360+
14 static_parameter₁
1361+
15 (call core.isa %₁₃ %₁₄)
1362+
16 (gotoifnot %₁₅ label₁₈)
1363+
17 (goto label₂₁)
1364+
18 static_parameter₁
1365+
19 (new core.TypeError :keyword argument :b %₁₈ %₁₃)
1366+
20 (call core.throw %₁₉)
1367+
21 (= slot₅/kwtmp %₁₃)
1368+
22 (goto label₂₅)
1369+
23 TestMod.b_def
1370+
24 (= slot₅/kwtmp %₂₃)
1371+
25 slot₅/kwtmp
1372+
26 (call top.keys slot₂/kws)
1373+
27 (call core.tuple :a :b)
1374+
28 (call top.diff_names %₂₆ %₂₇)
1375+
29 (call top.isempty %₂₈)
1376+
30 (gotoifnot %₂₉ label₃₂)
1377+
31 (goto label₃₃)
1378+
32 (call top.kwerr slot₂/kws slot₃/#self# slot₄/x)
1379+
33 TestMod.#f_kw_sparams#0
1380+
34 (call %₃₃ %₁₀ %₂₅ slot₃/#self# slot₄/x)
1381+
35 (return %₃₄)
13681382
33 (latestworld)
13691383
34 (= slot₆/X (call core.TypeVar :X))
13701384
35 (= slot₅/A (call core.TypeVar :A))

test/typedefs_ir.jl

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -739,9 +739,10 @@ end
739739
55 --- method core.nothing %₅₄
740740
slots: [slot₁/#self#(!read) slot₂/x]
741741
1 TestMod.X
742-
2 (call core.apply_type %₁ static_parameter₁)
743-
3 (new %₂ slot₂/x)
744-
4 (return %₃)
742+
2 static_parameter₁
743+
3 (call core.apply_type %%₂)
744+
4 (new %₃ slot₂/x)
745+
5 (return %₄)
745746
56 (latestworld)
746747
57 (return core.nothing)
747748

@@ -840,9 +841,11 @@ end
840841
73 --- method core.nothing %₇₂
841842
slots: [slot₁/#self#(!read) slot₂/v]
842843
1 TestMod.X
843-
2 (call core.apply_type %₁ static_parameter₁ static_parameter₂)
844-
3 (new %₂ slot₂/v)
845-
4 (return %₃)
844+
2 static_parameter₁
845+
3 static_parameter₂
846+
4 (call core.apply_type %%%₃)
847+
5 (new %₄ slot₂/v)
848+
6 (return %₅)
846849
74 (latestworld)
847850
75 (return core.nothing)
848851

0 commit comments

Comments
 (0)