From 3628b39cb664af910ae2ac7dba8d4020e0c5fe1a Mon Sep 17 00:00:00 2001 From: Leonardo de Moura Date: Thu, 2 May 2019 12:40:37 -0700 Subject: [PATCH] feat(library/init/lean/compiler): add `simpcase` transformation --- library/init/data/array/basic.lean | 3 + library/init/lean/compiler/default.lean | 1 + library/init/lean/compiler/ir.lean | 4 + library/init/lean/compiler/simpcase.lean | 55 ++ src/stage0/CMakeLists.txt | 2 +- src/stage0/init/data/array/basic.cpp | 100 ++++ src/stage0/init/lean/compiler/default.cpp | 5 +- src/stage0/init/lean/compiler/elimdead.cpp | 160 +++-- src/stage0/init/lean/compiler/ir.cpp | 132 +++++ src/stage0/init/lean/compiler/pushproj.cpp | 229 +++++--- src/stage0/init/lean/compiler/simpcase.cpp | 654 +++++++++++++++++++++ 11 files changed, 1217 insertions(+), 128 deletions(-) create mode 100644 library/init/lean/compiler/simpcase.lean create mode 100644 src/stage0/init/lean/compiler/simpcase.cpp diff --git a/library/init/data/array/basic.lean b/library/init/data/array/basic.lean index 35a782ca56..6f6ecd524a 100644 --- a/library/init/data/array/basic.lean +++ b/library/init/data/array/basic.lean @@ -193,6 +193,9 @@ end @[inline] def iterate (a : Array α) (b : β) (f : Π i : Fin a.size, α → β → β) : β := Id.run $ miterateAux a f 0 b +@[inline] def iterateFrom (a : Array α) (b : β) (i : Nat) (f : Π i : Fin a.size, α → β → β) : β := +Id.run $ miterateAux a f i b + @[inline] def foldl (a : Array α) (f : β → α → β) (b : β) : β := iterate a b (λ _ a b, f b a) diff --git a/library/init/lean/compiler/default.lean b/library/init/lean/compiler/default.lean index d3436a9fb5..3a4f0cede3 100644 --- a/library/init/lean/compiler/default.lean +++ b/library/init/lean/compiler/default.lean @@ -8,3 +8,4 @@ import init.lean.compiler.constfolding import init.lean.compiler.ir import init.lean.compiler.pushproj import init.lean.compiler.elimdead +import init.lean.compiler.simpcase diff --git a/library/init/lean/compiler/ir.lean b/library/init/lean/compiler/ir.lean index 7eda612961..d880333bcf 100644 --- a/library/init/lean/compiler/ir.lean +++ b/library/init/lean/compiler/ir.lean @@ -257,6 +257,10 @@ def AltCore.setBody : Alt → FnBody → Alt | (Alt.ctor c b) := Alt.ctor c (f b) | (Alt.default b) := Alt.default (f b) +def Alt.isDefault : Alt → Bool +| (Alt.ctor _ _) := false +| (Alt.default _) := true + def push (bs : Array FnBody) (b : FnBody) : Array FnBody := let b := b.setBody (default _) in bs.push b diff --git a/library/init/lean/compiler/simpcase.lean b/library/init/lean/compiler/simpcase.lean new file mode 100644 index 0000000000..f9b8c6c2cc --- /dev/null +++ b/library/init/lean/compiler/simpcase.lean @@ -0,0 +1,55 @@ +/- +Copyright (c) 2019 Microsoft Corporation. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Leonardo de Moura +-/ +import init.lean.compiler.ir + +namespace Lean +namespace IR + +private def maxOccs (alts : Array Alt) : Alt := +let (alt, _) := + alts.iterateFrom (alts.get 0, 1) 1 $ λ i a p, + let aBody := a.body in + let noccs := alts.iterateFrom 1 (i.val + 1) $ λ _ a' n, + if a'.body == aBody then n+1 else n in + if noccs > p.2 then (a, noccs) else p in +alt + +private def addDefault (alts : Array Alt) : Array Alt := +if alts.size <= 1 || alts.any Alt.isDefault then alts +else + let max := maxOccs alts in + let alts := alts.filter $ (λ alt, alt.body == max.body) in + alts.push (Alt.default max.body) + +private def mkCase (tid : Name) (x : VarId) (alts : Array Alt) : FnBody := +let alts := alts.filter (λ alt, alt.body != FnBody.unreachable) in +let alts := addDefault alts in +if alts.size == 0 then + FnBody.unreachable +else if alts.size == 1 then + (alts.get 0).body +else + FnBody.case tid x alts + +partial def FnBody.simpCase : FnBody → FnBody +| b := + let (bs, term) := b.flatten in + let bs := modifyJPVals bs FnBody.simpCase in + match term with + | FnBody.case tid x alts := reshape bs (mkCase tid x alts) + | other := reshape bs term + +/-- Simplify `case` + - Remove unreachable branches. + - Remove `case` if there is only one branch. + - Merge most common branches using `Alt.default`. -/ +@[export lean.ir.decl_simp_case_core] +def Decl.simpCase : Decl → Decl +| (Decl.fdecl f xs t b) := Decl.fdecl f xs t b.simpCase +| other := other + +end IR +end Lean diff --git a/src/stage0/CMakeLists.txt b/src/stage0/CMakeLists.txt index 4e2bb3d458..a1aa913e49 100644 --- a/src/stage0/CMakeLists.txt +++ b/src/stage0/CMakeLists.txt @@ -1 +1 @@ -add_library (stage0 OBJECT ./init/coe.cpp ./init/control/alternative.cpp ./init/control/applicative.cpp ./init/control/combinators.cpp ./init/control/default.cpp ./init/control/estate.cpp ./init/control/except.cpp ./init/control/functor.cpp ./init/control/id.cpp ./init/control/lift.cpp ./init/control/monad.cpp ./init/control/monadfail.cpp ./init/control/option.cpp ./init/control/reader.cpp ./init/control/state.cpp ./init/core.cpp ./init/data/array/basic.cpp ./init/data/array/default.cpp ./init/data/assoclist.cpp ./init/data/basic.cpp ./init/data/char/basic.cpp ./init/data/char/default.cpp ./init/data/default.cpp ./init/data/dlist.cpp ./init/data/fin/basic.cpp ./init/data/fin/default.cpp ./init/data/hashable.cpp ./init/data/hashmap/basic.cpp ./init/data/hashmap/default.cpp ./init/data/int/basic.cpp ./init/data/int/default.cpp ./init/data/list/basic.cpp ./init/data/list/default.cpp ./init/data/list/instances.cpp ./init/data/nat/basic.cpp ./init/data/nat/bitwise.cpp ./init/data/nat/default.cpp ./init/data/nat/div.cpp ./init/data/option/basic.cpp ./init/data/option/instances.cpp ./init/data/ordering/basic.cpp ./init/data/ordering/default.cpp ./init/data/rbmap/basic.cpp ./init/data/rbmap/default.cpp ./init/data/rbtree/basic.cpp ./init/data/rbtree/default.cpp ./init/data/repr.cpp ./init/data/string/basic.cpp ./init/data/string/default.cpp ./init/data/tostring.cpp ./init/data/uint.cpp ./init/default.cpp ./init/env_ext.cpp ./init/fix.cpp ./init/io.cpp ./init/lean/compiler/constfolding.cpp ./init/lean/compiler/default.cpp ./init/lean/compiler/elimdead.cpp ./init/lean/compiler/ir.cpp ./init/lean/compiler/pushproj.cpp ./init/lean/compiler/util.cpp ./init/lean/config.cpp ./init/lean/declaration.cpp ./init/lean/default.cpp ./init/lean/disjoint_set.cpp ./init/lean/elaborator.cpp ./init/lean/expander.cpp ./init/lean/expr.cpp ./init/lean/extern.cpp ./init/lean/format.cpp ./init/lean/frontend.cpp ./init/lean/kvmap.cpp ./init/lean/level.cpp ./init/lean/message.cpp ./init/lean/name.cpp ./init/lean/name_mangling.cpp ./init/lean/options.cpp ./init/lean/parser/basic.cpp ./init/lean/parser/combinators.cpp ./init/lean/parser/command.cpp ./init/lean/parser/declaration.cpp ./init/lean/parser/identifier.cpp ./init/lean/parser/level.cpp ./init/lean/parser/module.cpp ./init/lean/parser/notation.cpp ./init/lean/parser/parsec.cpp ./init/lean/parser/pratt.cpp ./init/lean/parser/rec.cpp ./init/lean/parser/stringliteral.cpp ./init/lean/parser/syntax.cpp ./init/lean/parser/term.cpp ./init/lean/parser/token.cpp ./init/lean/parser/trie.cpp ./init/lean/position.cpp ./init/lean/trace.cpp ./init/lean/util.cpp ./init/platform.cpp ./init/util.cpp ./init/wf.cpp) +add_library (stage0 OBJECT ./init/coe.cpp ./init/control/alternative.cpp ./init/control/applicative.cpp ./init/control/combinators.cpp ./init/control/default.cpp ./init/control/estate.cpp ./init/control/except.cpp ./init/control/functor.cpp ./init/control/id.cpp ./init/control/lift.cpp ./init/control/monad.cpp ./init/control/monadfail.cpp ./init/control/option.cpp ./init/control/reader.cpp ./init/control/state.cpp ./init/core.cpp ./init/data/array/basic.cpp ./init/data/array/default.cpp ./init/data/assoclist.cpp ./init/data/basic.cpp ./init/data/char/basic.cpp ./init/data/char/default.cpp ./init/data/default.cpp ./init/data/dlist.cpp ./init/data/fin/basic.cpp ./init/data/fin/default.cpp ./init/data/hashable.cpp ./init/data/hashmap/basic.cpp ./init/data/hashmap/default.cpp ./init/data/int/basic.cpp ./init/data/int/default.cpp ./init/data/list/basic.cpp ./init/data/list/default.cpp ./init/data/list/instances.cpp ./init/data/nat/basic.cpp ./init/data/nat/bitwise.cpp ./init/data/nat/default.cpp ./init/data/nat/div.cpp ./init/data/option/basic.cpp ./init/data/option/instances.cpp ./init/data/ordering/basic.cpp ./init/data/ordering/default.cpp ./init/data/rbmap/basic.cpp ./init/data/rbmap/default.cpp ./init/data/rbtree/basic.cpp ./init/data/rbtree/default.cpp ./init/data/repr.cpp ./init/data/string/basic.cpp ./init/data/string/default.cpp ./init/data/tostring.cpp ./init/data/uint.cpp ./init/default.cpp ./init/env_ext.cpp ./init/fix.cpp ./init/io.cpp ./init/lean/compiler/constfolding.cpp ./init/lean/compiler/default.cpp ./init/lean/compiler/elimdead.cpp ./init/lean/compiler/ir.cpp ./init/lean/compiler/pushproj.cpp ./init/lean/compiler/simpcase.cpp ./init/lean/compiler/util.cpp ./init/lean/config.cpp ./init/lean/declaration.cpp ./init/lean/default.cpp ./init/lean/disjoint_set.cpp ./init/lean/elaborator.cpp ./init/lean/expander.cpp ./init/lean/expr.cpp ./init/lean/extern.cpp ./init/lean/format.cpp ./init/lean/frontend.cpp ./init/lean/kvmap.cpp ./init/lean/level.cpp ./init/lean/message.cpp ./init/lean/name.cpp ./init/lean/name_mangling.cpp ./init/lean/options.cpp ./init/lean/parser/basic.cpp ./init/lean/parser/combinators.cpp ./init/lean/parser/command.cpp ./init/lean/parser/declaration.cpp ./init/lean/parser/identifier.cpp ./init/lean/parser/level.cpp ./init/lean/parser/module.cpp ./init/lean/parser/notation.cpp ./init/lean/parser/parsec.cpp ./init/lean/parser/pratt.cpp ./init/lean/parser/rec.cpp ./init/lean/parser/stringliteral.cpp ./init/lean/parser/syntax.cpp ./init/lean/parser/term.cpp ./init/lean/parser/token.cpp ./init/lean/parser/trie.cpp ./init/lean/position.cpp ./init/lean/trace.cpp ./init/lean/util.cpp ./init/platform.cpp ./init/util.cpp ./init/wf.cpp) diff --git a/src/stage0/init/data/array/basic.cpp b/src/stage0/init/data/array/basic.cpp index 7a9aafeefe..dfd2f2ba8c 100644 --- a/src/stage0/init/data/array/basic.cpp +++ b/src/stage0/init/data/array/basic.cpp @@ -21,6 +21,7 @@ obj* l_Array_foldlFrom___rarg(obj*, obj*, obj*, obj*); obj* l_Array_fswapAt___boxed(obj*); obj* l_Array_miterateAux___main___at_Array_append___spec__1___boxed(obj*); obj* l_Array_hmmapAux___main___at_Array_hmapIdx___spec__1(obj*); +obj* l_Array_miterateAux___main___at_Array_iterateFrom___spec__1___rarg(obj*, obj*, obj*, obj*, obj*); obj* l_Array_shrink___main___rarg___boxed(obj*, obj*); obj* l_Array_hmap(obj*); obj* l_Array_miterate_u_2082Aux___main___at_Array_foldl_u_2082___spec__1___rarg___boxed(obj*, obj*, obj*, obj*, obj*, obj*); @@ -45,6 +46,7 @@ uint8 l_Array_anyAux___rarg(obj*, obj*, obj*); obj* l_Array_isEmpty___boxed(obj*); obj* l_Array_iterate___rarg___boxed(obj*, obj*, obj*); obj* l_Array_mfoldl___rarg(obj*, obj*, obj*, obj*); +obj* l_Array_miterateAux___main___at_Array_iterateFrom___spec__1(obj*, obj*); obj* l_Array_miterateAux___main___at_Array_iterate___spec__1(obj*, obj*); obj* l_Array_miterateAux___main___at_Array_foldlFrom___spec__1___rarg___boxed(obj*, obj*, obj*, obj*, obj*); obj* l_Array_reverse(obj*); @@ -80,6 +82,7 @@ obj* l_Array_HasBeq(obj*); obj* l_Array_iterate___boxed(obj*, obj*); obj* l_Array_size___boxed(obj*, obj*); obj* l_Array_uset___boxed(obj*, obj*, obj*, obj*, obj*); +obj* l_Array_miterateAux___main___at_Array_iterateFrom___spec__1___rarg___boxed(obj*, obj*, obj*, obj*, obj*); obj* l_Array_isEqvAux___main___boxed(obj*); obj* l_List_toArrayAux___main___rarg(obj*, obj*); obj* l_Array_isEqv___rarg___boxed(obj*, obj*, obj*); @@ -146,6 +149,7 @@ obj* l_Array_mfindAux___main___rarg(obj*, obj*, obj*, obj*); obj* l_Array_anyAux(obj*); obj* l_Array_isEqv(obj*); obj* l_Array_mfind___boxed(obj*, obj*, obj*); +obj* l_Array_iterateFrom___boxed(obj*, obj*); obj* l_Array_mfindAux___main(obj*, obj*, obj*); obj* l_Array_miterateAux___rarg(obj*, obj*, obj*, obj*, obj*); obj* l_Array_mfindAux___main___boxed(obj*, obj*, obj*); @@ -191,7 +195,9 @@ obj* l___private_init_data_array_basic_1__revIterateAux___main___at_Array_revFol obj* l_Array_extractAux___main___boxed(obj*); obj* l_Array_isEqvAux___boxed(obj*); uint8 l_Array_isEmpty___rarg(obj*); +obj* l_Array_miterateAux___main___at_Array_iterateFrom___spec__1___boxed(obj*, obj*); uint8 l_Array_any___rarg(obj*, obj*); +obj* l_Array_iterateFrom(obj*, obj*); obj* l_Array_map___rarg___boxed(obj*, obj*); obj* l_Array_push___boxed(obj*, obj*, obj*); obj* l_Array_fget___boxed(obj*, obj*, obj*); @@ -212,6 +218,7 @@ obj* l_Array_miterate_u_2082___boxed(obj*, obj*, obj*); obj* l_Array_mfoldl_u_2082(obj*, obj*, obj*); obj* l_Array_filterAux___rarg(obj*, obj*, obj*, obj*); obj* l_Array_miterate_u_2082Aux___main___at_Array_foldl_u_2082___spec__1___boxed(obj*, obj*); +obj* l_Array_iterateFrom___rarg___boxed(obj*, obj*, obj*, obj*); obj* l_Array_back(obj*); obj* l_Array_miterateAux___main___at_Array_mmap___spec__1___rarg___lambda__1(obj*, obj*, obj*); obj* l___private_init_data_array_basic_1__revIterateAux___main___at_Array_toList___spec__1___boxed(obj*); @@ -351,6 +358,7 @@ obj* l_Array_mfindAux(obj*, obj*, obj*); obj* l_Array_miterateAux___boxed(obj*, obj*, obj*); obj* l_Array_anyAux___main___at_Array_all___spec__1___rarg___boxed(obj*, obj*, obj*); obj* l_Array_mkEmpty___boxed(obj*, obj*); +obj* l_Array_iterateFrom___rarg(obj*, obj*, obj*, obj*); obj* l_Array_miterateAux___main___at_Array_map___spec__1___boxed(obj*, obj*); uint8 l_Array_all___rarg(obj*, obj*); obj* l_Array_miterateAux___main___at_Array_iterate___spec__1___boxed(obj*, obj*); @@ -1706,6 +1714,98 @@ lean::dec(x_1); return x_2; } } +obj* l_Array_miterateAux___main___at_Array_iterateFrom___spec__1___rarg(obj* x_0, obj* x_1, obj* x_2, obj* x_3, obj* x_4) { +_start: +{ +obj* x_5; uint8 x_6; +x_5 = lean::array_get_size(x_2); +x_6 = lean::nat_dec_lt(x_3, x_5); +lean::dec(x_5); +if (x_6 == 0) +{ +lean::dec(x_1); +lean::dec(x_3); +return x_4; +} +else +{ +obj* x_10; obj* x_13; obj* x_14; obj* x_15; +x_10 = lean::array_fget(x_2, x_3); +lean::inc(x_3); +lean::inc(x_1); +x_13 = lean::apply_3(x_1, x_3, x_10, x_4); +x_14 = lean::mk_nat_obj(1ul); +x_15 = lean::nat_add(x_3, x_14); +lean::dec(x_3); +x_3 = x_15; +x_4 = x_13; +goto _start; +} +} +} +obj* l_Array_miterateAux___main___at_Array_iterateFrom___spec__1(obj* x_0, obj* x_1) { +_start: +{ +obj* x_2; +x_2 = lean::alloc_closure(reinterpret_cast(l_Array_miterateAux___main___at_Array_iterateFrom___spec__1___rarg___boxed), 5, 0); +return x_2; +} +} +obj* l_Array_iterateFrom___rarg(obj* x_0, obj* x_1, obj* x_2, obj* x_3) { +_start: +{ +obj* x_4; +x_4 = l_Array_miterateAux___main___at_Array_iterateFrom___spec__1___rarg(x_0, x_3, x_0, x_2, x_1); +return x_4; +} +} +obj* l_Array_iterateFrom(obj* x_0, obj* x_1) { +_start: +{ +obj* x_2; +x_2 = lean::alloc_closure(reinterpret_cast(l_Array_iterateFrom___rarg___boxed), 4, 0); +return x_2; +} +} +obj* l_Array_miterateAux___main___at_Array_iterateFrom___spec__1___rarg___boxed(obj* x_0, obj* x_1, obj* x_2, obj* x_3, obj* x_4) { +_start: +{ +obj* x_5; +x_5 = l_Array_miterateAux___main___at_Array_iterateFrom___spec__1___rarg(x_0, x_1, x_2, x_3, x_4); +lean::dec(x_0); +lean::dec(x_2); +return x_5; +} +} +obj* l_Array_miterateAux___main___at_Array_iterateFrom___spec__1___boxed(obj* x_0, obj* x_1) { +_start: +{ +obj* x_2; +x_2 = l_Array_miterateAux___main___at_Array_iterateFrom___spec__1(x_0, x_1); +lean::dec(x_0); +lean::dec(x_1); +return x_2; +} +} +obj* l_Array_iterateFrom___rarg___boxed(obj* x_0, obj* x_1, obj* x_2, obj* x_3) { +_start: +{ +obj* x_4; +x_4 = l_Array_iterateFrom___rarg(x_0, x_1, x_2, x_3); +lean::dec(x_0); +return x_4; +} +} +obj* l_Array_iterateFrom___boxed(obj* x_0, obj* x_1) { +_start: +{ +obj* x_2; +x_2 = l_Array_iterateFrom(x_0, x_1); +lean::dec(x_0); +lean::dec(x_1); +return x_2; +} +} obj* l_Array_miterateAux___main___at_Array_foldl___spec__1___rarg(obj* x_0, obj* x_1, obj* x_2, obj* x_3, obj* x_4) { _start: { diff --git a/src/stage0/init/lean/compiler/default.cpp b/src/stage0/init/lean/compiler/default.cpp index 0c319a4d6b..5efee25020 100644 --- a/src/stage0/init/lean/compiler/default.cpp +++ b/src/stage0/init/lean/compiler/default.cpp @@ -1,6 +1,6 @@ // Lean compiler output // Module: init.lean.compiler.default -// Imports: init.lean.compiler.constfolding init.lean.compiler.ir init.lean.compiler.pushproj init.lean.compiler.elimdead +// Imports: init.lean.compiler.constfolding init.lean.compiler.ir init.lean.compiler.pushproj init.lean.compiler.elimdead init.lean.compiler.simpcase #include "runtime/object.h" #include "runtime/apply.h" typedef lean::object obj; typedef lean::usize usize; @@ -18,6 +18,7 @@ obj* initialize_init_lean_compiler_constfolding(obj*); obj* initialize_init_lean_compiler_ir(obj*); obj* initialize_init_lean_compiler_pushproj(obj*); obj* initialize_init_lean_compiler_elimdead(obj*); +obj* initialize_init_lean_compiler_simpcase(obj*); static bool _G_initialized = false; obj* initialize_init_lean_compiler_default(obj* w) { if (_G_initialized) return w; @@ -31,5 +32,7 @@ w = initialize_init_lean_compiler_pushproj(w); if (io_result_is_error(w)) return w; w = initialize_init_lean_compiler_elimdead(w); if (io_result_is_error(w)) return w; +w = initialize_init_lean_compiler_simpcase(w); +if (io_result_is_error(w)) return w; return w; } diff --git a/src/stage0/init/lean/compiler/elimdead.cpp b/src/stage0/init/lean/compiler/elimdead.cpp index 1b7b0cb5b4..5612b66d20 100644 --- a/src/stage0/init/lean/compiler/elimdead.cpp +++ b/src/stage0/init/lean/compiler/elimdead.cpp @@ -18,15 +18,14 @@ obj* l_Lean_IR_FnBody_collectFreeVars(obj*, obj*); namespace lean { obj* nat_sub(obj*, obj*); } +obj* l_Array_hmmapAux___main___at_Lean_IR_FnBody_elimDead___main___spec__2___closed__1; obj* l_Array_hmmapAux___main___at_Lean_IR_FnBody_elimDead___main___spec__1(obj*, obj*); obj* l_Lean_IR_reshapeWithoutDead(obj*, obj*); obj* l_Array_back___at_Lean_IR_reshapeWithoutDeadAux___main___spec__1(obj*); obj* l_Lean_IR_reshapeWithoutDeadAux(obj*, obj*, obj*); -obj* l_Array_hmmapAux___main___at_Lean_IR_FnBody_elimDead___main___spec__1___closed__1; obj* l_Array_back___at_Lean_IR_reshapeWithoutDeadAux___main___spec__1___boxed(obj*); obj* l_Lean_IR_FnBody_elimDead___main(obj*); obj* l_Lean_IR_FnBody_freeVars(obj*); -obj* l_Lean_IR_reshape(obj*, obj*); obj* l_Lean_IR_reshapeWithoutDeadAux___main(obj*, obj*, obj*); namespace lean { uint8 nat_dec_lt(obj*, obj*); @@ -42,6 +41,7 @@ obj* nat_add(obj*, obj*); } uint8 l_Array_isEmpty___rarg(obj*); obj* l_Lean_IR_Decl_elimDead___main(obj*); +obj* l_Array_hmmapAux___main___at_Lean_IR_FnBody_elimDead___main___spec__2(obj*, obj*); obj* l_Lean_IR_FnBody_setBody___main(obj*, obj*); obj* l_Lean_IR_FnBody_elimDead(obj*); extern obj* l_Lean_IR_Inhabited; @@ -182,16 +182,6 @@ x_4 = l_Lean_IR_reshapeWithoutDeadAux___main(x_0, x_1, x_3); return x_4; } } -obj* _init_l_Array_hmmapAux___main___at_Lean_IR_FnBody_elimDead___main___spec__1___closed__1() { -_start: -{ -obj* x_0; obj* x_1; -x_0 = lean::box(12); -x_1 = lean::alloc_cnstr(1, 1, 0); -lean::cnstr_set(x_1, 0, x_0); -return x_1; -} -} obj* l_Array_hmmapAux___main___at_Lean_IR_FnBody_elimDead___main___spec__1(obj* x_0, obj* x_1) { _start: { @@ -208,7 +198,87 @@ else { obj* x_6; obj* x_7; obj* x_8; obj* x_9; obj* x_10; x_6 = lean::array_fget(x_1, x_0); -x_7 = l_Array_hmmapAux___main___at_Lean_IR_FnBody_elimDead___main___spec__1___closed__1; +x_7 = lean::box(12); +x_8 = lean::array_fset(x_1, x_0, x_7); +x_9 = lean::mk_nat_obj(1ul); +x_10 = lean::nat_add(x_0, x_9); +switch (lean::obj_tag(x_6)) { +case 1: +{ +obj* x_11; obj* x_13; uint8 x_15; obj* x_16; obj* x_18; obj* x_20; obj* x_21; obj* x_22; obj* x_23; obj* x_24; +x_11 = lean::cnstr_get(x_6, 0); +x_13 = lean::cnstr_get(x_6, 1); +x_15 = lean::cnstr_get_scalar(x_6, sizeof(void*)*4); +x_16 = lean::cnstr_get(x_6, 2); +x_18 = lean::cnstr_get(x_6, 3); +if (lean::is_exclusive(x_6)) { + x_20 = x_6; +} else { + lean::inc(x_11); + lean::inc(x_13); + lean::inc(x_16); + lean::inc(x_18); + lean::dec(x_6); + x_20 = lean::box(0); +} +x_21 = l_Lean_IR_FnBody_elimDead___main(x_16); +if (lean::is_scalar(x_20)) { + x_22 = lean::alloc_cnstr(1, 4, 1); +} else { + x_22 = x_20; +} +lean::cnstr_set(x_22, 0, x_11); +lean::cnstr_set(x_22, 1, x_13); +lean::cnstr_set(x_22, 2, x_21); +lean::cnstr_set(x_22, 3, x_18); +lean::cnstr_set_scalar(x_22, sizeof(void*)*4, x_15); +x_23 = x_22; +x_24 = lean::array_fset(x_8, x_0, x_23); +lean::dec(x_0); +x_0 = x_10; +x_1 = x_24; +goto _start; +} +default: +{ +obj* x_27; +x_27 = lean::array_fset(x_8, x_0, x_6); +lean::dec(x_0); +x_0 = x_10; +x_1 = x_27; +goto _start; +} +} +} +} +} +obj* _init_l_Array_hmmapAux___main___at_Lean_IR_FnBody_elimDead___main___spec__2___closed__1() { +_start: +{ +obj* x_0; obj* x_1; +x_0 = lean::box(12); +x_1 = lean::alloc_cnstr(1, 1, 0); +lean::cnstr_set(x_1, 0, x_0); +return x_1; +} +} +obj* l_Array_hmmapAux___main___at_Lean_IR_FnBody_elimDead___main___spec__2(obj* x_0, obj* x_1) { +_start: +{ +obj* x_2; uint8 x_3; +x_2 = lean::array_get_size(x_1); +x_3 = lean::nat_dec_lt(x_0, x_2); +lean::dec(x_2); +if (x_3 == 0) +{ +lean::dec(x_0); +return x_1; +} +else +{ +obj* x_6; obj* x_7; obj* x_8; obj* x_9; obj* x_10; +x_6 = lean::array_fget(x_1, x_0); +x_7 = l_Array_hmmapAux___main___at_Lean_IR_FnBody_elimDead___main___spec__2___closed__1; x_8 = lean::array_fset(x_1, x_0, x_7); x_9 = lean::mk_nat_obj(1ul); x_10 = lean::nat_add(x_0, x_9); @@ -269,50 +339,48 @@ goto _start; obj* l_Lean_IR_FnBody_elimDead___main(obj* x_0) { _start: { -obj* x_1; obj* x_2; +obj* x_1; obj* x_2; obj* x_4; obj* x_7; obj* x_8; x_1 = l_Lean_IR_FnBody_flatten(x_0); -x_2 = lean::cnstr_get(x_1, 1); +x_2 = lean::cnstr_get(x_1, 0); lean::inc(x_2); -switch (lean::obj_tag(x_2)) { -case 9: -{ -obj* x_4; obj* x_7; obj* x_9; obj* x_11; obj* x_13; obj* x_14; obj* x_15; obj* x_16; obj* x_17; -x_4 = lean::cnstr_get(x_1, 0); +x_4 = lean::cnstr_get(x_1, 1); lean::inc(x_4); lean::dec(x_1); -x_7 = lean::cnstr_get(x_2, 0); -x_9 = lean::cnstr_get(x_2, 1); -x_11 = lean::cnstr_get(x_2, 2); -if (lean::is_exclusive(x_2)) { - x_13 = x_2; +x_7 = lean::mk_nat_obj(0ul); +x_8 = l_Array_hmmapAux___main___at_Lean_IR_FnBody_elimDead___main___spec__1(x_7, x_2); +switch (lean::obj_tag(x_4)) { +case 9: +{ +obj* x_9; obj* x_11; obj* x_13; obj* x_15; obj* x_16; obj* x_17; obj* x_18; +x_9 = lean::cnstr_get(x_4, 0); +x_11 = lean::cnstr_get(x_4, 1); +x_13 = lean::cnstr_get(x_4, 2); +if (lean::is_exclusive(x_4)) { + x_15 = x_4; } else { - lean::inc(x_7); lean::inc(x_9); lean::inc(x_11); - lean::dec(x_2); - x_13 = lean::box(0); + lean::inc(x_13); + lean::dec(x_4); + x_15 = lean::box(0); } -x_14 = lean::mk_nat_obj(0ul); -x_15 = l_Array_hmmapAux___main___at_Lean_IR_FnBody_elimDead___main___spec__1(x_14, x_11); -if (lean::is_scalar(x_13)) { - x_16 = lean::alloc_cnstr(9, 3, 0); +x_16 = l_Array_hmmapAux___main___at_Lean_IR_FnBody_elimDead___main___spec__2(x_7, x_13); +if (lean::is_scalar(x_15)) { + x_17 = lean::alloc_cnstr(9, 3, 0); } else { - x_16 = x_13; + x_17 = x_15; } -lean::cnstr_set(x_16, 0, x_7); -lean::cnstr_set(x_16, 1, x_9); -lean::cnstr_set(x_16, 2, x_15); -x_17 = l_Lean_IR_reshape(x_4, x_16); -return x_17; +lean::cnstr_set(x_17, 0, x_9); +lean::cnstr_set(x_17, 1, x_11); +lean::cnstr_set(x_17, 2, x_16); +x_18 = l_Lean_IR_reshapeWithoutDead(x_8, x_17); +return x_18; } default: { -obj* x_18; obj* x_21; -x_18 = lean::cnstr_get(x_1, 0); -lean::inc(x_18); -lean::dec(x_1); -x_21 = l_Lean_IR_reshape(x_18, x_2); -return x_21; +obj* x_19; +x_19 = l_Lean_IR_reshapeWithoutDead(x_8, x_4); +return x_19; } } } @@ -385,7 +453,7 @@ w = initialize_init_default(w); if (io_result_is_error(w)) return w; w = initialize_init_lean_compiler_ir(w); if (io_result_is_error(w)) return w; - l_Array_hmmapAux___main___at_Lean_IR_FnBody_elimDead___main___spec__1___closed__1 = _init_l_Array_hmmapAux___main___at_Lean_IR_FnBody_elimDead___main___spec__1___closed__1(); -lean::mark_persistent(l_Array_hmmapAux___main___at_Lean_IR_FnBody_elimDead___main___spec__1___closed__1); + l_Array_hmmapAux___main___at_Lean_IR_FnBody_elimDead___main___spec__2___closed__1 = _init_l_Array_hmmapAux___main___at_Lean_IR_FnBody_elimDead___main___spec__2___closed__1(); +lean::mark_persistent(l_Array_hmmapAux___main___at_Lean_IR_FnBody_elimDead___main___spec__2___closed__1); return w; } diff --git a/src/stage0/init/lean/compiler/ir.cpp b/src/stage0/init/lean/compiler/ir.cpp index 810522bd8b..7bb1b0c5f1 100644 --- a/src/stage0/init/lean/compiler/ir.cpp +++ b/src/stage0/init/lean/compiler/ir.cpp @@ -45,6 +45,7 @@ obj* nat_sub(obj*, obj*); } obj* l_Lean_IR_vsetInh; obj* l_Lean_IR_VarId_Lean_HasFormat(obj*); +obj* l_Lean_IR_Alt_isDefault___boxed(obj*); obj* l_Lean_Format_pretty(obj*, obj*); obj* l___private_init_lean_compiler_ir_29__collectArgs___boxed(obj*, obj*); obj* l___private_init_lean_compiler_ir_20__formatIRType___main(uint8); @@ -117,6 +118,7 @@ namespace ir { obj* decl_to_string_core(obj*); }} obj* l_Lean_IR_AltCore_modifyBody(obj*, obj*); +obj* l_Array_hmmapAux___main___at_Lean_IR_modifyJPVals___spec__1(obj*, obj*, obj*); obj* l_Array_miterateAux___main___at___private_init_lean_compiler_ir_28__collectArray___spec__1(obj*); obj* l_Lean_Name_toStringWithSep___main(obj*, obj*); obj* l_Lean_IR_formatFnBody___main___closed__17; @@ -294,6 +296,7 @@ obj* l_Lean_IR_altInh; obj* l_Lean_IR_FreeVariables_insertParams___boxed(obj*, obj*); obj* l_Lean_IR_FnBody_body___main___boxed(obj*); obj* l_Lean_IR_FnBody_isTerminal___main___boxed(obj*); +uint8 l_Lean_IR_Alt_isDefault___main(obj*); obj* l_Lean_IR_VarId_HasBeq___boxed(obj*, obj*); obj* l___private_init_lean_compiler_ir_23__collect___boxed(obj*, obj*); obj* l___private_init_lean_compiler_ir_13__collectExpr(obj*, obj*, obj*); @@ -333,6 +336,7 @@ uint8 l_Lean_IR_FnBody_isTerminal(obj*); obj* l_Lean_IR_addVarRename(obj*, obj*, obj*); obj* l___private_init_lean_compiler_ir_19__formatExpr___main___closed__6; obj* l_Array_miterateAux___main___at___private_init_lean_compiler_ir_33__collectAlts___spec__2(obj*, obj*, obj*, obj*, obj*); +obj* l_Lean_IR_modifyJPVals(obj*, obj*); obj* l_Lean_IR_formatFnBody___main___closed__10; uint8 l_Lean_IR_FnBody_isPure___main(obj*); obj* l_Array_miterateAux___main___at___private_init_lean_compiler_ir_16__formatArray___spec__1___rarg(obj*, obj*, obj*, obj*, obj*); @@ -394,6 +398,7 @@ obj* l___private_init_lean_compiler_ir_11__collectArray___rarg___boxed(obj*, obj obj* l___private_init_lean_compiler_ir_27__collectArg___main(obj*, obj*); obj* l_Lean_IR_FnBody_isPure___main___boxed(obj*); obj* l_Lean_IR_litValHasFormat; +uint8 l_Lean_IR_Alt_isDefault(obj*); obj* l_Array_miterateAux___main___at___private_init_lean_compiler_ir_16__formatArray___spec__1___boxed(obj*); obj* l_Lean_IR_FnBody_body___main(obj*); extern obj* l_Lean_Name_toString___closed__1; @@ -452,6 +457,7 @@ obj* l_Array_isEqv___at_Lean_IR_FnBody_alphaEqv___main___spec__1___boxed(obj*, o obj* l_Lean_IR_MData_empty; obj* l___private_init_lean_compiler_ir_11__collectArray___at___private_init_lean_compiler_ir_14__collectAlts___spec__1___boxed(obj*, obj*, obj*, obj*); obj* l_Lean_IR_Inhabited; +obj* l_Lean_IR_Alt_isDefault___main___boxed(obj*); uint8 l_Array_isEqv___at_Lean_IR_FnBody_alphaEqv___main___spec__1___lambda__1(obj*, obj*, obj*); obj* l_Lean_IR_IRType_beq___main___boxed(obj*, obj*); obj* l_Lean_IR_FreeVariables_collectFnBody___main(obj*, obj*, obj*); @@ -1942,6 +1948,51 @@ return x_13; } } } +uint8 l_Lean_IR_Alt_isDefault___main(obj* x_0) { +_start: +{ +if (lean::obj_tag(x_0) == 0) +{ +uint8 x_1; +x_1 = 0; +return x_1; +} +else +{ +uint8 x_2; +x_2 = 1; +return x_2; +} +} +} +obj* l_Lean_IR_Alt_isDefault___main___boxed(obj* x_0) { +_start: +{ +uint8 x_1; obj* x_2; +x_1 = l_Lean_IR_Alt_isDefault___main(x_0); +x_2 = lean::box(x_1); +lean::dec(x_0); +return x_2; +} +} +uint8 l_Lean_IR_Alt_isDefault(obj* x_0) { +_start: +{ +uint8 x_1; +x_1 = l_Lean_IR_Alt_isDefault___main(x_0); +return x_1; +} +} +obj* l_Lean_IR_Alt_isDefault___boxed(obj* x_0) { +_start: +{ +uint8 x_1; obj* x_2; +x_1 = l_Lean_IR_Alt_isDefault(x_0); +x_2 = lean::box(x_1); +lean::dec(x_0); +return x_2; +} +} obj* l_Lean_IR_push(obj* x_0, obj* x_1) { _start: { @@ -2055,6 +2106,87 @@ x_3 = l_Lean_IR_reshapeAux___main(x_0, x_2, x_1); return x_3; } } +obj* l_Array_hmmapAux___main___at_Lean_IR_modifyJPVals___spec__1(obj* x_0, obj* x_1, obj* x_2) { +_start: +{ +obj* x_3; uint8 x_4; +x_3 = lean::array_get_size(x_2); +x_4 = lean::nat_dec_lt(x_1, x_3); +lean::dec(x_3); +if (x_4 == 0) +{ +lean::dec(x_1); +lean::dec(x_0); +return x_2; +} +else +{ +obj* x_8; obj* x_9; obj* x_10; obj* x_11; obj* x_12; +x_8 = lean::array_fget(x_2, x_1); +x_9 = lean::box(12); +x_10 = lean::array_fset(x_2, x_1, x_9); +x_11 = lean::mk_nat_obj(1ul); +x_12 = lean::nat_add(x_1, x_11); +switch (lean::obj_tag(x_8)) { +case 1: +{ +obj* x_13; obj* x_15; uint8 x_17; obj* x_18; obj* x_20; obj* x_22; obj* x_24; obj* x_25; obj* x_26; obj* x_27; +x_13 = lean::cnstr_get(x_8, 0); +x_15 = lean::cnstr_get(x_8, 1); +x_17 = lean::cnstr_get_scalar(x_8, sizeof(void*)*4); +x_18 = lean::cnstr_get(x_8, 2); +x_20 = lean::cnstr_get(x_8, 3); +if (lean::is_exclusive(x_8)) { + x_22 = x_8; +} else { + lean::inc(x_13); + lean::inc(x_15); + lean::inc(x_18); + lean::inc(x_20); + lean::dec(x_8); + x_22 = lean::box(0); +} +lean::inc(x_0); +x_24 = lean::apply_1(x_0, x_18); +if (lean::is_scalar(x_22)) { + x_25 = lean::alloc_cnstr(1, 4, 1); +} else { + x_25 = x_22; +} +lean::cnstr_set(x_25, 0, x_13); +lean::cnstr_set(x_25, 1, x_15); +lean::cnstr_set(x_25, 2, x_24); +lean::cnstr_set(x_25, 3, x_20); +lean::cnstr_set_scalar(x_25, sizeof(void*)*4, x_17); +x_26 = x_25; +x_27 = lean::array_fset(x_10, x_1, x_26); +lean::dec(x_1); +x_1 = x_12; +x_2 = x_27; +goto _start; +} +default: +{ +obj* x_30; +x_30 = lean::array_fset(x_10, x_1, x_8); +lean::dec(x_1); +x_1 = x_12; +x_2 = x_30; +goto _start; +} +} +} +} +} +obj* l_Lean_IR_modifyJPVals(obj* x_0, obj* x_1) { +_start: +{ +obj* x_2; obj* x_3; +x_2 = lean::mk_nat_obj(0ul); +x_3 = l_Array_hmmapAux___main___at_Lean_IR_modifyJPVals___spec__1(x_1, x_2, x_0); +return x_3; +} +} namespace lean { namespace ir { obj* mk_alt_core(obj* x_0, obj* x_1, obj* x_2, obj* x_3, obj* x_4, obj* x_5) { diff --git a/src/stage0/init/lean/compiler/pushproj.cpp b/src/stage0/init/lean/compiler/pushproj.cpp index d34fb3dd83..122ce8d78d 100644 --- a/src/stage0/init/lean/compiler/pushproj.cpp +++ b/src/stage0/init/lean/compiler/pushproj.cpp @@ -28,8 +28,6 @@ obj* decl_push_proj_core(obj*); }} obj* l_RBNode_ins___main___at___private_init_lean_compiler_ir_2__collectIndex___spec__2(obj*, obj*, obj*); obj* l_Lean_IR_pushProjs___main___closed__1; -obj* l_Array_miterateAux___main___at_Lean_IR_FnBody_pushProj___main___spec__1___boxed(obj*, obj*, obj*, obj*); -obj* l_Array_hmmapAux___main___at_Lean_IR_FnBody_pushProj___main___spec__2(obj*, obj*); obj* l_Array_hmmapAux___main___at_Lean_IR_pushProjs___main___spec__4___boxed(obj*, obj*, obj*, obj*, obj*); obj* l_Lean_IR_Decl_pushProj___main(obj*); obj* l_Lean_IR_FnBody_freeVars(obj*); @@ -48,19 +46,22 @@ uint8 l_Array_isEmpty___rarg(obj*); uint8 l_RBNode_isRed___main___rarg(obj*); obj* l_Lean_IR_pushProjs(obj*, obj*, obj*, obj*, obj*); obj* l_Lean_IR_FnBody_pushProj___main(obj*); +obj* l_Array_hmmapAux___main___at_Lean_IR_FnBody_pushProj___main___spec__3(obj*, obj*); obj* l_Nat_decLt___boxed(obj*, obj*); obj* l_Array_reverseAux___main___rarg(obj*, obj*); obj* l_Lean_IR_AltCore_body___main(obj*); obj* l_Lean_IR_pushProjs___main(obj*, obj*, obj*, obj*, obj*); obj* l_Array_back___at_Lean_IR_pushProjs___main___spec__1(obj*); +obj* l_Array_hmmapAux___main___at_Lean_IR_FnBody_pushProj___main___spec__1(obj*, obj*); obj* l_Lean_IR_FnBody_setBody___main(obj*, obj*); obj* l_Array_hmmapAux___main___at_Lean_IR_pushProjs___main___spec__4(obj*, obj*, obj*, obj*, obj*); +obj* l_Array_miterateAux___main___at_Lean_IR_FnBody_pushProj___main___spec__2(obj*, obj*, obj*, obj*); obj* l_Array_anyAux___main___at_Lean_IR_pushProjs___main___spec__2___boxed(obj*, obj*, obj*, obj*); obj* l_Array_back___at_Lean_IR_pushProjs___main___spec__1___boxed(obj*); +obj* l_Array_miterateAux___main___at_Lean_IR_FnBody_pushProj___main___spec__2___boxed(obj*, obj*, obj*, obj*); obj* l_Array_hmmapAux___main___at_Lean_IR_pushProjs___main___spec__3___closed__1; obj* l_Array_hmmapAux___main___at_Lean_IR_pushProjs___main___spec__3___boxed(obj*, obj*, obj*, obj*, obj*, obj*); obj* l_Array_miterateAux___main___at_Array_append___spec__1___rarg(obj*, obj*, obj*, obj*); -obj* l_Array_miterateAux___main___at_Lean_IR_FnBody_pushProj___main___spec__1(obj*, obj*, obj*, obj*); extern obj* l_Lean_IR_Inhabited; obj* l_Array_back___at_Lean_IR_pushProjs___main___spec__1(obj* x_0) { _start: @@ -501,7 +502,77 @@ x_5 = l_Lean_IR_pushProjs___main(x_0, x_1, x_2, x_3, x_4); return x_5; } } -obj* l_Array_miterateAux___main___at_Lean_IR_FnBody_pushProj___main___spec__1(obj* x_0, obj* x_1, obj* x_2, obj* x_3) { +obj* l_Array_hmmapAux___main___at_Lean_IR_FnBody_pushProj___main___spec__1(obj* x_0, obj* x_1) { +_start: +{ +obj* x_2; uint8 x_3; +x_2 = lean::array_get_size(x_1); +x_3 = lean::nat_dec_lt(x_0, x_2); +lean::dec(x_2); +if (x_3 == 0) +{ +lean::dec(x_0); +return x_1; +} +else +{ +obj* x_6; obj* x_7; obj* x_8; obj* x_9; obj* x_10; +x_6 = lean::array_fget(x_1, x_0); +x_7 = lean::box(12); +x_8 = lean::array_fset(x_1, x_0, x_7); +x_9 = lean::mk_nat_obj(1ul); +x_10 = lean::nat_add(x_0, x_9); +switch (lean::obj_tag(x_6)) { +case 1: +{ +obj* x_11; obj* x_13; uint8 x_15; obj* x_16; obj* x_18; obj* x_20; obj* x_21; obj* x_22; obj* x_23; obj* x_24; +x_11 = lean::cnstr_get(x_6, 0); +x_13 = lean::cnstr_get(x_6, 1); +x_15 = lean::cnstr_get_scalar(x_6, sizeof(void*)*4); +x_16 = lean::cnstr_get(x_6, 2); +x_18 = lean::cnstr_get(x_6, 3); +if (lean::is_exclusive(x_6)) { + x_20 = x_6; +} else { + lean::inc(x_11); + lean::inc(x_13); + lean::inc(x_16); + lean::inc(x_18); + lean::dec(x_6); + x_20 = lean::box(0); +} +x_21 = l_Lean_IR_FnBody_pushProj___main(x_16); +if (lean::is_scalar(x_20)) { + x_22 = lean::alloc_cnstr(1, 4, 1); +} else { + x_22 = x_20; +} +lean::cnstr_set(x_22, 0, x_11); +lean::cnstr_set(x_22, 1, x_13); +lean::cnstr_set(x_22, 2, x_21); +lean::cnstr_set(x_22, 3, x_18); +lean::cnstr_set_scalar(x_22, sizeof(void*)*4, x_15); +x_23 = x_22; +x_24 = lean::array_fset(x_8, x_0, x_23); +lean::dec(x_0); +x_0 = x_10; +x_1 = x_24; +goto _start; +} +default: +{ +obj* x_27; +x_27 = lean::array_fset(x_8, x_0, x_6); +lean::dec(x_0); +x_0 = x_10; +x_1 = x_27; +goto _start; +} +} +} +} +} +obj* l_Array_miterateAux___main___at_Lean_IR_FnBody_pushProj___main___spec__2(obj* x_0, obj* x_1, obj* x_2, obj* x_3) { _start: { obj* x_4; uint8 x_5; @@ -530,7 +601,7 @@ goto _start; } } } -obj* l_Array_hmmapAux___main___at_Lean_IR_FnBody_pushProj___main___spec__2(obj* x_0, obj* x_1) { +obj* l_Array_hmmapAux___main___at_Lean_IR_FnBody_pushProj___main___spec__3(obj* x_0, obj* x_1) { _start: { obj* x_2; uint8 x_3; @@ -607,108 +678,106 @@ goto _start; obj* l_Lean_IR_FnBody_pushProj___main(obj* x_0) { _start: { -obj* x_1; obj* x_2; +obj* x_1; obj* x_2; obj* x_4; obj* x_7; obj* x_8; x_1 = l_Lean_IR_FnBody_flatten(x_0); -x_2 = lean::cnstr_get(x_1, 1); +x_2 = lean::cnstr_get(x_1, 0); lean::inc(x_2); -switch (lean::obj_tag(x_2)) { -case 9: -{ -obj* x_4; obj* x_7; obj* x_9; obj* x_11; obj* x_13; obj* x_14; obj* x_15; obj* x_17; obj* x_18; obj* x_19; uint8 x_20; -x_4 = lean::cnstr_get(x_1, 0); +x_4 = lean::cnstr_get(x_1, 1); lean::inc(x_4); lean::dec(x_1); -x_7 = lean::cnstr_get(x_2, 0); -x_9 = lean::cnstr_get(x_2, 1); -x_11 = lean::cnstr_get(x_2, 2); -if (lean::is_exclusive(x_2)) { - lean::cnstr_set(x_2, 0, lean::box(0)); - lean::cnstr_set(x_2, 1, lean::box(0)); - lean::cnstr_set(x_2, 2, lean::box(0)); - x_13 = x_2; +x_7 = lean::mk_nat_obj(0ul); +x_8 = l_Array_hmmapAux___main___at_Lean_IR_FnBody_pushProj___main___spec__1(x_7, x_2); +switch (lean::obj_tag(x_4)) { +case 9: +{ +obj* x_9; obj* x_11; obj* x_13; obj* x_15; obj* x_16; obj* x_17; obj* x_19; obj* x_20; uint8 x_21; +x_9 = lean::cnstr_get(x_4, 0); +x_11 = lean::cnstr_get(x_4, 1); +x_13 = lean::cnstr_get(x_4, 2); +if (lean::is_exclusive(x_4)) { + lean::cnstr_set(x_4, 0, lean::box(0)); + lean::cnstr_set(x_4, 1, lean::box(0)); + lean::cnstr_set(x_4, 2, lean::box(0)); + x_15 = x_4; } else { - lean::inc(x_7); lean::inc(x_9); lean::inc(x_11); - lean::dec(x_2); - x_13 = lean::box(0); + lean::inc(x_13); + lean::dec(x_4); + x_15 = lean::box(0); } -x_14 = lean::array_get_size(x_11); -x_15 = lean::mk_empty_array(x_14); -lean::dec(x_14); -x_17 = lean::mk_nat_obj(0ul); -x_18 = l_Array_miterateAux___main___at_Lean_IR_FnBody_pushProj___main___spec__1(x_11, x_11, x_17, x_15); -x_19 = lean::box(0); -x_20 = l_RBNode_isRed___main___rarg(x_19); -if (x_20 == 0) +x_16 = lean::array_get_size(x_13); +x_17 = lean::mk_empty_array(x_16); +lean::dec(x_16); +x_19 = l_Array_miterateAux___main___at_Lean_IR_FnBody_pushProj___main___spec__2(x_13, x_13, x_7, x_17); +x_20 = lean::box(0); +x_21 = l_RBNode_isRed___main___rarg(x_20); +if (x_21 == 0) { -obj* x_21; obj* x_23; obj* x_24; obj* x_25; obj* x_26; obj* x_28; obj* x_31; obj* x_32; obj* x_33; -x_21 = lean::box(0); -lean::inc(x_9); -x_23 = l_RBNode_ins___main___at___private_init_lean_compiler_ir_2__collectIndex___spec__2(x_19, x_9, x_21); -x_24 = l_Array_empty___closed__1; -x_25 = l_Lean_IR_pushProjs___main(x_4, x_11, x_18, x_24, x_23); -x_26 = lean::cnstr_get(x_25, 0); -lean::inc(x_26); -x_28 = lean::cnstr_get(x_25, 1); -lean::inc(x_28); -lean::dec(x_25); -x_31 = l_Array_hmmapAux___main___at_Lean_IR_FnBody_pushProj___main___spec__2(x_17, x_28); -if (lean::is_scalar(x_13)) { - x_32 = lean::alloc_cnstr(9, 3, 0); +obj* x_22; obj* x_24; obj* x_25; obj* x_26; obj* x_27; obj* x_29; obj* x_32; obj* x_33; obj* x_34; +x_22 = lean::box(0); +lean::inc(x_11); +x_24 = l_RBNode_ins___main___at___private_init_lean_compiler_ir_2__collectIndex___spec__2(x_20, x_11, x_22); +x_25 = l_Array_empty___closed__1; +x_26 = l_Lean_IR_pushProjs___main(x_8, x_13, x_19, x_25, x_24); +x_27 = lean::cnstr_get(x_26, 0); +lean::inc(x_27); +x_29 = lean::cnstr_get(x_26, 1); +lean::inc(x_29); +lean::dec(x_26); +x_32 = l_Array_hmmapAux___main___at_Lean_IR_FnBody_pushProj___main___spec__3(x_7, x_29); +if (lean::is_scalar(x_15)) { + x_33 = lean::alloc_cnstr(9, 3, 0); } else { - x_32 = x_13; + x_33 = x_15; } -lean::cnstr_set(x_32, 0, x_7); -lean::cnstr_set(x_32, 1, x_9); -lean::cnstr_set(x_32, 2, x_31); -x_33 = l_Lean_IR_reshape(x_26, x_32); -return x_33; +lean::cnstr_set(x_33, 0, x_9); +lean::cnstr_set(x_33, 1, x_11); +lean::cnstr_set(x_33, 2, x_32); +x_34 = l_Lean_IR_reshape(x_27, x_33); +return x_34; } else { -obj* x_34; obj* x_36; obj* x_37; obj* x_38; obj* x_39; obj* x_40; obj* x_42; obj* x_45; obj* x_46; obj* x_47; -x_34 = lean::box(0); -lean::inc(x_9); -x_36 = l_RBNode_ins___main___at___private_init_lean_compiler_ir_2__collectIndex___spec__2(x_19, x_9, x_34); -x_37 = l_RBNode_setBlack___main___rarg(x_36); -x_38 = l_Array_empty___closed__1; -x_39 = l_Lean_IR_pushProjs___main(x_4, x_11, x_18, x_38, x_37); -x_40 = lean::cnstr_get(x_39, 0); -lean::inc(x_40); -x_42 = lean::cnstr_get(x_39, 1); -lean::inc(x_42); -lean::dec(x_39); -x_45 = l_Array_hmmapAux___main___at_Lean_IR_FnBody_pushProj___main___spec__2(x_17, x_42); -if (lean::is_scalar(x_13)) { - x_46 = lean::alloc_cnstr(9, 3, 0); +obj* x_35; obj* x_37; obj* x_38; obj* x_39; obj* x_40; obj* x_41; obj* x_43; obj* x_46; obj* x_47; obj* x_48; +x_35 = lean::box(0); +lean::inc(x_11); +x_37 = l_RBNode_ins___main___at___private_init_lean_compiler_ir_2__collectIndex___spec__2(x_20, x_11, x_35); +x_38 = l_RBNode_setBlack___main___rarg(x_37); +x_39 = l_Array_empty___closed__1; +x_40 = l_Lean_IR_pushProjs___main(x_8, x_13, x_19, x_39, x_38); +x_41 = lean::cnstr_get(x_40, 0); +lean::inc(x_41); +x_43 = lean::cnstr_get(x_40, 1); +lean::inc(x_43); +lean::dec(x_40); +x_46 = l_Array_hmmapAux___main___at_Lean_IR_FnBody_pushProj___main___spec__3(x_7, x_43); +if (lean::is_scalar(x_15)) { + x_47 = lean::alloc_cnstr(9, 3, 0); } else { - x_46 = x_13; + x_47 = x_15; } -lean::cnstr_set(x_46, 0, x_7); -lean::cnstr_set(x_46, 1, x_9); -lean::cnstr_set(x_46, 2, x_45); -x_47 = l_Lean_IR_reshape(x_40, x_46); -return x_47; +lean::cnstr_set(x_47, 0, x_9); +lean::cnstr_set(x_47, 1, x_11); +lean::cnstr_set(x_47, 2, x_46); +x_48 = l_Lean_IR_reshape(x_41, x_47); +return x_48; } } default: { -obj* x_48; obj* x_51; -x_48 = lean::cnstr_get(x_1, 0); -lean::inc(x_48); -lean::dec(x_1); -x_51 = l_Lean_IR_reshape(x_48, x_2); -return x_51; +obj* x_49; +x_49 = l_Lean_IR_reshape(x_8, x_4); +return x_49; } } } } -obj* l_Array_miterateAux___main___at_Lean_IR_FnBody_pushProj___main___spec__1___boxed(obj* x_0, obj* x_1, obj* x_2, obj* x_3) { +obj* l_Array_miterateAux___main___at_Lean_IR_FnBody_pushProj___main___spec__2___boxed(obj* x_0, obj* x_1, obj* x_2, obj* x_3) { _start: { obj* x_4; -x_4 = l_Array_miterateAux___main___at_Lean_IR_FnBody_pushProj___main___spec__1(x_0, x_1, x_2, x_3); +x_4 = l_Array_miterateAux___main___at_Lean_IR_FnBody_pushProj___main___spec__2(x_0, x_1, x_2, x_3); lean::dec(x_0); lean::dec(x_1); return x_4; diff --git a/src/stage0/init/lean/compiler/simpcase.cpp b/src/stage0/init/lean/compiler/simpcase.cpp new file mode 100644 index 0000000000..e84abf4061 --- /dev/null +++ b/src/stage0/init/lean/compiler/simpcase.cpp @@ -0,0 +1,654 @@ +// Lean compiler output +// Module: init.lean.compiler.simpcase +// Imports: init.default init.lean.compiler.ir +#include "runtime/object.h" +#include "runtime/apply.h" +typedef lean::object obj; typedef lean::usize usize; +typedef lean::uint8 uint8; typedef lean::uint16 uint16; +typedef lean::uint32 uint32; typedef lean::uint64 uint64; +#if defined(__clang__) +#pragma clang diagnostic ignored "-Wunused-parameter" +#pragma clang diagnostic ignored "-Wunused-label" +#elif defined(__GNUC__) && !defined(__CLANG__) +#pragma GCC diagnostic ignored "-Wunused-parameter" +#pragma GCC diagnostic ignored "-Wunused-label" +#pragma GCC diagnostic ignored "-Wunused-but-set-variable" +#endif +obj* l_Array_miterateAux___main___at___private_init_lean_compiler_simpcase_1__maxOccs___spec__2___boxed(obj*, obj*, obj*, obj*); +obj* l_Array_filterAux___main___at___private_init_lean_compiler_simpcase_3__mkCase___spec__1(obj*, obj*, obj*); +obj* l_Lean_IR_FnBody_simpCase(obj*); +obj* l_Lean_IR_FnBody_simpCase___main(obj*); +obj* l_Array_anyAux___main___at___private_init_lean_compiler_simpcase_2__addDefault___spec__1___boxed(obj*, obj*); +obj* l_Array_miterateAux___main___at___private_init_lean_compiler_simpcase_1__maxOccs___spec__1___boxed(obj*, obj*, obj*, obj*, obj*); +obj* l_Array_filterAux___main___at___private_init_lean_compiler_simpcase_2__addDefault___spec__2___boxed(obj*, obj*, obj*, obj*); +obj* l_Lean_IR_reshape(obj*, obj*); +obj* l_Array_filterAux___main___at___private_init_lean_compiler_simpcase_2__addDefault___spec__2(obj*, obj*, obj*, obj*); +namespace lean { +uint8 nat_dec_lt(obj*, obj*); +} +obj* l_Array_miterateAux___main___at___private_init_lean_compiler_simpcase_1__maxOccs___spec__2(obj*, obj*, obj*, obj*); +obj* l___private_init_lean_compiler_simpcase_3__mkCase(obj*, obj*, obj*); +obj* l_Lean_IR_FnBody_flatten(obj*); +obj* l___private_init_lean_compiler_simpcase_2__addDefault(obj*); +namespace lean { +obj* nat_add(obj*, obj*); +} +namespace lean { +uint8 nat_dec_eq(obj*, obj*); +} +obj* l___private_init_lean_compiler_simpcase_1__maxOccs___boxed(obj*); +extern obj* l_Lean_IR_altInh; +uint8 l_Lean_IR_Alt_isDefault___main(obj*); +uint8 l_Array_anyAux___main___at___private_init_lean_compiler_simpcase_2__addDefault___spec__1(obj*, obj*); +namespace lean { +namespace ir { +obj* decl_simp_case_core(obj*); +}} +obj* l_Array_shrink___main___rarg(obj*, obj*); +obj* l_Lean_IR_AltCore_body___main(obj*); +uint8 l_Lean_IR_FnBody_beq(obj*, obj*); +obj* l_Array_miterateAux___main___at___private_init_lean_compiler_simpcase_1__maxOccs___spec__1(obj*, obj*, obj*, obj*, obj*); +namespace lean { +uint8 nat_dec_le(obj*, obj*); +} +obj* l_Lean_IR_Decl_simpCase___main(obj*); +obj* l___private_init_lean_compiler_simpcase_1__maxOccs(obj*); +obj* l_Array_hmmapAux___main___at_Lean_IR_FnBody_simpCase___main___spec__1(obj*, obj*); +obj* l_Array_miterateAux___main___at___private_init_lean_compiler_simpcase_1__maxOccs___spec__1(obj* x_0, obj* x_1, obj* x_2, obj* x_3, obj* x_4) { +_start: +{ +obj* x_5; uint8 x_6; +x_5 = lean::array_get_size(x_2); +x_6 = lean::nat_dec_lt(x_3, x_5); +lean::dec(x_5); +if (x_6 == 0) +{ +lean::dec(x_1); +lean::dec(x_3); +return x_4; +} +else +{ +obj* x_10; obj* x_11; uint8 x_14; obj* x_15; obj* x_16; +x_10 = lean::array_fget(x_2, x_3); +x_11 = l_Lean_IR_AltCore_body___main(x_10); +lean::dec(x_10); +lean::inc(x_1); +x_14 = l_Lean_IR_FnBody_beq(x_11, x_1); +x_15 = lean::mk_nat_obj(1ul); +x_16 = lean::nat_add(x_3, x_15); +lean::dec(x_3); +if (x_14 == 0) +{ +x_3 = x_16; +goto _start; +} +else +{ +obj* x_19; +x_19 = lean::nat_add(x_4, x_15); +lean::dec(x_4); +x_3 = x_16; +x_4 = x_19; +goto _start; +} +} +} +} +obj* l_Array_miterateAux___main___at___private_init_lean_compiler_simpcase_1__maxOccs___spec__2(obj* x_0, obj* x_1, obj* x_2, obj* x_3) { +_start: +{ +obj* x_4; uint8 x_5; +x_4 = lean::array_get_size(x_1); +x_5 = lean::nat_dec_lt(x_2, x_4); +lean::dec(x_4); +if (x_5 == 0) +{ +lean::dec(x_2); +return x_3; +} +else +{ +obj* x_8; obj* x_9; obj* x_10; obj* x_11; obj* x_14; obj* x_15; uint8 x_17; +x_8 = lean::array_fget(x_1, x_2); +x_9 = l_Lean_IR_AltCore_body___main(x_8); +x_10 = lean::mk_nat_obj(1ul); +x_11 = lean::nat_add(x_2, x_10); +lean::dec(x_2); +lean::inc(x_11); +x_14 = l_Array_miterateAux___main___at___private_init_lean_compiler_simpcase_1__maxOccs___spec__1(x_0, x_9, x_0, x_11, x_10); +x_15 = lean::cnstr_get(x_3, 1); +lean::inc(x_15); +x_17 = lean::nat_dec_lt(x_15, x_14); +lean::dec(x_15); +if (x_17 == 0) +{ +lean::dec(x_14); +lean::dec(x_8); +x_2 = x_11; +goto _start; +} +else +{ +obj* x_23; +lean::dec(x_3); +x_23 = lean::alloc_cnstr(0, 2, 0); +lean::cnstr_set(x_23, 0, x_8); +lean::cnstr_set(x_23, 1, x_14); +x_2 = x_11; +x_3 = x_23; +goto _start; +} +} +} +} +obj* l___private_init_lean_compiler_simpcase_1__maxOccs(obj* x_0) { +_start: +{ +obj* x_1; obj* x_2; obj* x_3; obj* x_4; obj* x_5; obj* x_6; obj* x_7; +x_1 = l_Lean_IR_altInh; +x_2 = lean::mk_nat_obj(0ul); +x_3 = lean::array_get(x_1, x_0, x_2); +x_4 = lean::mk_nat_obj(1ul); +x_5 = lean::alloc_cnstr(0, 2, 0); +lean::cnstr_set(x_5, 0, x_3); +lean::cnstr_set(x_5, 1, x_4); +x_6 = l_Array_miterateAux___main___at___private_init_lean_compiler_simpcase_1__maxOccs___spec__2(x_0, x_0, x_4, x_5); +x_7 = lean::cnstr_get(x_6, 0); +lean::inc(x_7); +lean::dec(x_6); +return x_7; +} +} +obj* l_Array_miterateAux___main___at___private_init_lean_compiler_simpcase_1__maxOccs___spec__1___boxed(obj* x_0, obj* x_1, obj* x_2, obj* x_3, obj* x_4) { +_start: +{ +obj* x_5; +x_5 = l_Array_miterateAux___main___at___private_init_lean_compiler_simpcase_1__maxOccs___spec__1(x_0, x_1, x_2, x_3, x_4); +lean::dec(x_0); +lean::dec(x_2); +return x_5; +} +} +obj* l_Array_miterateAux___main___at___private_init_lean_compiler_simpcase_1__maxOccs___spec__2___boxed(obj* x_0, obj* x_1, obj* x_2, obj* x_3) { +_start: +{ +obj* x_4; +x_4 = l_Array_miterateAux___main___at___private_init_lean_compiler_simpcase_1__maxOccs___spec__2(x_0, x_1, x_2, x_3); +lean::dec(x_0); +lean::dec(x_1); +return x_4; +} +} +obj* l___private_init_lean_compiler_simpcase_1__maxOccs___boxed(obj* x_0) { +_start: +{ +obj* x_1; +x_1 = l___private_init_lean_compiler_simpcase_1__maxOccs(x_0); +lean::dec(x_0); +return x_1; +} +} +uint8 l_Array_anyAux___main___at___private_init_lean_compiler_simpcase_2__addDefault___spec__1(obj* x_0, obj* x_1) { +_start: +{ +obj* x_2; uint8 x_3; +x_2 = lean::array_get_size(x_0); +x_3 = lean::nat_dec_lt(x_1, x_2); +lean::dec(x_2); +if (x_3 == 0) +{ +uint8 x_6; +lean::dec(x_1); +x_6 = 0; +return x_6; +} +else +{ +obj* x_7; uint8 x_8; +x_7 = lean::array_fget(x_0, x_1); +x_8 = l_Lean_IR_Alt_isDefault___main(x_7); +lean::dec(x_7); +if (x_8 == 0) +{ +obj* x_10; obj* x_11; +x_10 = lean::mk_nat_obj(1ul); +x_11 = lean::nat_add(x_1, x_10); +lean::dec(x_1); +x_1 = x_11; +goto _start; +} +else +{ +uint8 x_15; +lean::dec(x_1); +x_15 = 1; +return x_15; +} +} +} +} +obj* l_Array_filterAux___main___at___private_init_lean_compiler_simpcase_2__addDefault___spec__2(obj* x_0, obj* x_1, obj* x_2, obj* x_3) { +_start: +{ +obj* x_4; uint8 x_5; +x_4 = lean::array_get_size(x_1); +x_5 = lean::nat_dec_lt(x_2, x_4); +lean::dec(x_4); +if (x_5 == 0) +{ +obj* x_8; +lean::dec(x_2); +x_8 = l_Array_shrink___main___rarg(x_1, x_3); +lean::dec(x_3); +return x_8; +} +else +{ +obj* x_10; obj* x_11; obj* x_13; uint8 x_14; +x_10 = lean::array_fget(x_1, x_2); +x_11 = l_Lean_IR_AltCore_body___main(x_10); +lean::dec(x_10); +x_13 = l_Lean_IR_AltCore_body___main(x_0); +x_14 = l_Lean_IR_FnBody_beq(x_11, x_13); +if (x_14 == 0) +{ +obj* x_15; obj* x_16; +x_15 = lean::mk_nat_obj(1ul); +x_16 = lean::nat_add(x_2, x_15); +lean::dec(x_2); +x_2 = x_16; +goto _start; +} +else +{ +uint8 x_19; +x_19 = lean::nat_dec_lt(x_3, x_2); +if (x_19 == 0) +{ +obj* x_20; obj* x_21; obj* x_23; +x_20 = lean::mk_nat_obj(1ul); +x_21 = lean::nat_add(x_2, x_20); +lean::dec(x_2); +x_23 = lean::nat_add(x_3, x_20); +lean::dec(x_3); +x_2 = x_21; +x_3 = x_23; +goto _start; +} +else +{ +obj* x_26; obj* x_27; obj* x_28; obj* x_30; +x_26 = lean::array_fswap(x_1, x_2, x_3); +x_27 = lean::mk_nat_obj(1ul); +x_28 = lean::nat_add(x_2, x_27); +lean::dec(x_2); +x_30 = lean::nat_add(x_3, x_27); +lean::dec(x_3); +x_1 = x_26; +x_2 = x_28; +x_3 = x_30; +goto _start; +} +} +} +} +} +obj* l___private_init_lean_compiler_simpcase_2__addDefault(obj* x_0) { +_start: +{ +obj* x_1; obj* x_2; uint8 x_3; +x_1 = lean::array_get_size(x_0); +x_2 = lean::mk_nat_obj(1ul); +x_3 = lean::nat_dec_le(x_1, x_2); +lean::dec(x_1); +if (x_3 == 0) +{ +obj* x_5; uint8 x_6; +x_5 = lean::mk_nat_obj(0ul); +x_6 = l_Array_anyAux___main___at___private_init_lean_compiler_simpcase_2__addDefault___spec__1(x_0, x_5); +if (x_6 == 0) +{ +obj* x_7; obj* x_8; obj* x_9; obj* x_11; obj* x_12; +x_7 = l___private_init_lean_compiler_simpcase_1__maxOccs(x_0); +x_8 = l_Array_filterAux___main___at___private_init_lean_compiler_simpcase_2__addDefault___spec__2(x_7, x_0, x_5, x_5); +x_9 = l_Lean_IR_AltCore_body___main(x_7); +lean::dec(x_7); +x_11 = lean::alloc_cnstr(1, 1, 0); +lean::cnstr_set(x_11, 0, x_9); +x_12 = lean::array_push(x_8, x_11); +return x_12; +} +else +{ +return x_0; +} +} +else +{ +return x_0; +} +} +} +obj* l_Array_anyAux___main___at___private_init_lean_compiler_simpcase_2__addDefault___spec__1___boxed(obj* x_0, obj* x_1) { +_start: +{ +uint8 x_2; obj* x_3; +x_2 = l_Array_anyAux___main___at___private_init_lean_compiler_simpcase_2__addDefault___spec__1(x_0, x_1); +x_3 = lean::box(x_2); +lean::dec(x_0); +return x_3; +} +} +obj* l_Array_filterAux___main___at___private_init_lean_compiler_simpcase_2__addDefault___spec__2___boxed(obj* x_0, obj* x_1, obj* x_2, obj* x_3) { +_start: +{ +obj* x_4; +x_4 = l_Array_filterAux___main___at___private_init_lean_compiler_simpcase_2__addDefault___spec__2(x_0, x_1, x_2, x_3); +lean::dec(x_0); +return x_4; +} +} +obj* l_Array_filterAux___main___at___private_init_lean_compiler_simpcase_3__mkCase___spec__1(obj* x_0, obj* x_1, obj* x_2) { +_start: +{ +obj* x_3; uint8 x_4; +x_3 = lean::array_get_size(x_0); +x_4 = lean::nat_dec_lt(x_1, x_3); +lean::dec(x_3); +if (x_4 == 0) +{ +obj* x_7; +lean::dec(x_1); +x_7 = l_Array_shrink___main___rarg(x_0, x_2); +lean::dec(x_2); +return x_7; +} +else +{ +obj* x_9; obj* x_10; obj* x_12; uint8 x_13; +x_9 = lean::array_fget(x_0, x_1); +x_10 = l_Lean_IR_AltCore_body___main(x_9); +lean::dec(x_9); +x_12 = lean::box(12); +x_13 = l_Lean_IR_FnBody_beq(x_10, x_12); +if (x_13 == 0) +{ +uint8 x_14; +x_14 = lean::nat_dec_lt(x_2, x_1); +if (x_14 == 0) +{ +obj* x_15; obj* x_16; obj* x_18; +x_15 = lean::mk_nat_obj(1ul); +x_16 = lean::nat_add(x_1, x_15); +lean::dec(x_1); +x_18 = lean::nat_add(x_2, x_15); +lean::dec(x_2); +x_1 = x_16; +x_2 = x_18; +goto _start; +} +else +{ +obj* x_21; obj* x_22; obj* x_23; obj* x_25; +x_21 = lean::array_fswap(x_0, x_1, x_2); +x_22 = lean::mk_nat_obj(1ul); +x_23 = lean::nat_add(x_1, x_22); +lean::dec(x_1); +x_25 = lean::nat_add(x_2, x_22); +lean::dec(x_2); +x_0 = x_21; +x_1 = x_23; +x_2 = x_25; +goto _start; +} +} +else +{ +obj* x_28; obj* x_29; +x_28 = lean::mk_nat_obj(1ul); +x_29 = lean::nat_add(x_1, x_28); +lean::dec(x_1); +x_1 = x_29; +goto _start; +} +} +} +} +obj* l___private_init_lean_compiler_simpcase_3__mkCase(obj* x_0, obj* x_1, obj* x_2) { +_start: +{ +obj* x_3; obj* x_4; obj* x_5; obj* x_6; uint8 x_7; +x_3 = lean::mk_nat_obj(0ul); +x_4 = l_Array_filterAux___main___at___private_init_lean_compiler_simpcase_3__mkCase___spec__1(x_2, x_3, x_3); +x_5 = l___private_init_lean_compiler_simpcase_2__addDefault(x_4); +x_6 = lean::array_get_size(x_5); +x_7 = lean::nat_dec_eq(x_6, x_3); +if (x_7 == 0) +{ +obj* x_8; uint8 x_9; +x_8 = lean::mk_nat_obj(1ul); +x_9 = lean::nat_dec_eq(x_6, x_8); +lean::dec(x_6); +if (x_9 == 0) +{ +obj* x_11; +x_11 = lean::alloc_cnstr(9, 3, 0); +lean::cnstr_set(x_11, 0, x_0); +lean::cnstr_set(x_11, 1, x_1); +lean::cnstr_set(x_11, 2, x_5); +return x_11; +} +else +{ +obj* x_14; obj* x_15; obj* x_17; +lean::dec(x_1); +lean::dec(x_0); +x_14 = l_Lean_IR_altInh; +x_15 = lean::array_get(x_14, x_5, x_3); +lean::dec(x_5); +x_17 = l_Lean_IR_AltCore_body___main(x_15); +lean::dec(x_15); +return x_17; +} +} +else +{ +obj* x_23; +lean::dec(x_5); +lean::dec(x_1); +lean::dec(x_6); +lean::dec(x_0); +x_23 = lean::box(12); +return x_23; +} +} +} +obj* l_Array_hmmapAux___main___at_Lean_IR_FnBody_simpCase___main___spec__1(obj* x_0, obj* x_1) { +_start: +{ +obj* x_2; uint8 x_3; +x_2 = lean::array_get_size(x_1); +x_3 = lean::nat_dec_lt(x_0, x_2); +lean::dec(x_2); +if (x_3 == 0) +{ +lean::dec(x_0); +return x_1; +} +else +{ +obj* x_6; obj* x_7; obj* x_8; obj* x_9; obj* x_10; +x_6 = lean::array_fget(x_1, x_0); +x_7 = lean::box(12); +x_8 = lean::array_fset(x_1, x_0, x_7); +x_9 = lean::mk_nat_obj(1ul); +x_10 = lean::nat_add(x_0, x_9); +switch (lean::obj_tag(x_6)) { +case 1: +{ +obj* x_11; obj* x_13; uint8 x_15; obj* x_16; obj* x_18; obj* x_20; obj* x_21; obj* x_22; obj* x_23; obj* x_24; +x_11 = lean::cnstr_get(x_6, 0); +x_13 = lean::cnstr_get(x_6, 1); +x_15 = lean::cnstr_get_scalar(x_6, sizeof(void*)*4); +x_16 = lean::cnstr_get(x_6, 2); +x_18 = lean::cnstr_get(x_6, 3); +if (lean::is_exclusive(x_6)) { + x_20 = x_6; +} else { + lean::inc(x_11); + lean::inc(x_13); + lean::inc(x_16); + lean::inc(x_18); + lean::dec(x_6); + x_20 = lean::box(0); +} +x_21 = l_Lean_IR_FnBody_simpCase___main(x_16); +if (lean::is_scalar(x_20)) { + x_22 = lean::alloc_cnstr(1, 4, 1); +} else { + x_22 = x_20; +} +lean::cnstr_set(x_22, 0, x_11); +lean::cnstr_set(x_22, 1, x_13); +lean::cnstr_set(x_22, 2, x_21); +lean::cnstr_set(x_22, 3, x_18); +lean::cnstr_set_scalar(x_22, sizeof(void*)*4, x_15); +x_23 = x_22; +x_24 = lean::array_fset(x_8, x_0, x_23); +lean::dec(x_0); +x_0 = x_10; +x_1 = x_24; +goto _start; +} +default: +{ +obj* x_27; +x_27 = lean::array_fset(x_8, x_0, x_6); +lean::dec(x_0); +x_0 = x_10; +x_1 = x_27; +goto _start; +} +} +} +} +} +obj* l_Lean_IR_FnBody_simpCase___main(obj* x_0) { +_start: +{ +obj* x_1; obj* x_2; obj* x_4; obj* x_7; obj* x_8; +x_1 = l_Lean_IR_FnBody_flatten(x_0); +x_2 = lean::cnstr_get(x_1, 0); +lean::inc(x_2); +x_4 = lean::cnstr_get(x_1, 1); +lean::inc(x_4); +lean::dec(x_1); +x_7 = lean::mk_nat_obj(0ul); +x_8 = l_Array_hmmapAux___main___at_Lean_IR_FnBody_simpCase___main___spec__1(x_7, x_2); +switch (lean::obj_tag(x_4)) { +case 9: +{ +obj* x_9; obj* x_11; obj* x_13; obj* x_15; obj* x_16; obj* x_17; +x_9 = lean::cnstr_get(x_4, 0); +x_11 = lean::cnstr_get(x_4, 1); +x_13 = lean::cnstr_get(x_4, 2); +if (lean::is_exclusive(x_4)) { + x_15 = x_4; +} else { + lean::inc(x_9); + lean::inc(x_11); + lean::inc(x_13); + lean::dec(x_4); + x_15 = lean::box(0); +} +if (lean::is_scalar(x_15)) { + x_16 = lean::alloc_cnstr(9, 3, 0); +} else { + x_16 = x_15; +} +lean::cnstr_set(x_16, 0, x_9); +lean::cnstr_set(x_16, 1, x_11); +lean::cnstr_set(x_16, 2, x_13); +x_17 = l_Lean_IR_reshape(x_8, x_16); +return x_17; +} +default: +{ +obj* x_18; +x_18 = l_Lean_IR_reshape(x_8, x_4); +return x_18; +} +} +} +} +obj* l_Lean_IR_FnBody_simpCase(obj* x_0) { +_start: +{ +obj* x_1; +x_1 = l_Lean_IR_FnBody_simpCase___main(x_0); +return x_1; +} +} +obj* l_Lean_IR_Decl_simpCase___main(obj* x_0) { +_start: +{ +if (lean::obj_tag(x_0) == 0) +{ +obj* x_1; obj* x_3; uint8 x_5; obj* x_6; obj* x_8; obj* x_9; obj* x_10; obj* x_11; +x_1 = lean::cnstr_get(x_0, 0); +x_3 = lean::cnstr_get(x_0, 1); +x_5 = lean::cnstr_get_scalar(x_0, sizeof(void*)*3); +x_6 = lean::cnstr_get(x_0, 2); +if (lean::is_exclusive(x_0)) { + x_8 = x_0; +} else { + lean::inc(x_1); + lean::inc(x_3); + lean::inc(x_6); + lean::dec(x_0); + x_8 = lean::box(0); +} +x_9 = l_Lean_IR_FnBody_simpCase___main(x_6); +if (lean::is_scalar(x_8)) { + x_10 = lean::alloc_cnstr(0, 3, 1); +} else { + x_10 = x_8; +} +lean::cnstr_set(x_10, 0, x_1); +lean::cnstr_set(x_10, 1, x_3); +lean::cnstr_set(x_10, 2, x_9); +lean::cnstr_set_scalar(x_10, sizeof(void*)*3, x_5); +x_11 = x_10; +return x_11; +} +else +{ +return x_0; +} +} +} +namespace lean { +namespace ir { +obj* decl_simp_case_core(obj* x_0) { +_start: +{ +obj* x_1; +x_1 = l_Lean_IR_Decl_simpCase___main(x_0); +return x_1; +} +} +}} +obj* initialize_init_default(obj*); +obj* initialize_init_lean_compiler_ir(obj*); +static bool _G_initialized = false; +obj* initialize_init_lean_compiler_simpcase(obj* w) { + if (_G_initialized) return w; + _G_initialized = true; +if (io_result_is_error(w)) return w; +w = initialize_init_default(w); +if (io_result_is_error(w)) return w; +w = initialize_init_lean_compiler_ir(w); +if (io_result_is_error(w)) return w; +return w; +}