소스 검색

Bump inkwell and other crates (#1622)

Update crates dependencies and fix the CI problems.

Signed-off-by: Sean Young <sean@mess.org>
Sean Young 1 년 전
부모
커밋
d7a875afe7

+ 12 - 12
Cargo.toml

@@ -28,12 +28,12 @@ tiny-keccak = { version = "2.0", features = ["keccak"] }
 serde_json = "1.0"
 serde = "1.0"
 serde_derive = { version = "1.0" }
-inkwell = { version = "0.2.0", features = ["target-webassembly", "no-libffi-linking", "llvm16-0"], optional = true }
+inkwell = { version = "0.4.0", features = ["target-webassembly", "no-libffi-linking", "llvm16-0"], optional = true }
 blake2-rfc = "0.2.18"
-handlebars = "4.4"
+handlebars = "5.1"
 contract-metadata = "3.2"
 semver = { version = "1.0", features = ["serde"] }
-tempfile = "3.8"
+tempfile = "3.9"
 libc = { version = "0.2", optional = true }
 tower-lsp = { version = "0.20", optional = true }
 tokio = { version = "1.27", features = ["rt", "io-std", "macros"], optional = true }
@@ -44,28 +44,28 @@ bitvec = "1"
 funty = "2.0"
 itertools = "0.12"
 num-rational = "0.4"
-indexmap = "2.0"
-once_cell = "1.18"
+indexmap = "2.2"
+once_cell = "1.19"
 solang-parser = { path = "solang-parser", version = "0.3.3" }
 codespan-reporting = "0.11"
 phf = { version = "0.11", features = ["macros"] }
 rust-lapper = { version = "1.1", optional = true }
 anchor-syn = { version = "0.29.0", features = ["idl-build"] }
 convert_case = "0.6"
-parse-display = "0.8"
+parse-display = "0.9"
 parity-scale-codec = "3.6"
 ink_env = "4.3.0"
 ink_metadata = "4.3.0"
-scale-info = "2.9"
+scale-info = "2.10"
 petgraph = "0.6"
-wasmparser = "0.110.0"
-wasm-encoder = "0.31"
+wasmparser = "0.121.0"
+wasm-encoder = "0.41"
 toml = "0.8"
-wasm-opt = { version = "0.112.0", optional = true }
-contract-build = { version = "3.0.1", optional = true }
+wasm-opt = { version = "0.113.0", optional = true }
+contract-build = { version = "3.2", optional = true }
 primitive-types = { version = "0.12", features = ["codec"] }
 normalize-path = "0.2.1"
-bitflags = "2.3.3"
+bitflags = "2.4"
 scopeguard = "1.2.0"
 forge-fmt = { version = "0.2.0", optional = true }
 # We don't use ethers-core directly, but need the correct version for the

+ 1 - 1
integration/anchor/programs/anchor/Cargo.toml

@@ -17,6 +17,6 @@ default = []
 
 [dependencies]
 anchor-lang = "0.29.0"
-solana-program = "1.16.1"
+solana-program = "=1.16.1"
 # TODO: Remove once https://github.com/solana-labs/solana/issues/33504 is resolved.
 ahash = "=0.8.6"

+ 122 - 84
src/emit/binary.rs

@@ -88,13 +88,17 @@ macro_rules! emit_context {
                 $binary
                     .builder
                     .build_call($binary.module.get_function($name).unwrap(), $args, "")
+                    .unwrap()
             };
             ($name:expr, $args:expr, $call_name:literal) => {
-                $binary.builder.build_call(
-                    $binary.module.get_function($name).unwrap(),
-                    $args,
-                    $call_name,
-                )
+                $binary
+                    .builder
+                    .build_call(
+                        $binary.module.get_function($name).unwrap(),
+                        $args,
+                        $call_name,
+                    )
+                    .unwrap()
             };
         }
 
@@ -517,7 +521,7 @@ impl<'a> Binary<'a> {
             self.builder.position_at_end(entry);
         }
 
-        let res = self.builder.build_alloca(ty, name);
+        let res = self.builder.build_alloca(ty, name).unwrap();
 
         self.builder.position_at_end(current);
 
@@ -542,7 +546,7 @@ impl<'a> Binary<'a> {
             self.builder.position_at_end(entry);
         }
 
-        let res = self.builder.build_array_alloca(ty, length, name);
+        let res = self.builder.build_array_alloca(ty, length, name).unwrap();
 
         self.builder.position_at_end(current);
 
@@ -565,12 +569,12 @@ impl<'a> Binary<'a> {
         let done = self.context.append_basic_block(function, "done");
         let entry = self.builder.get_insert_block().unwrap();
 
-        self.builder.build_unconditional_branch(body);
+        self.builder.build_unconditional_branch(body).unwrap();
         self.builder.position_at_end(body);
 
         let loop_ty = from.get_type();
-        let loop_phi = self.builder.build_phi(loop_ty, "index");
-        let data_phi = self.builder.build_phi(data_ref.get_type(), "data");
+        let loop_phi = self.builder.build_phi(loop_ty, "index").unwrap();
+        let data_phi = self.builder.build_phi(data_ref.get_type(), "data").unwrap();
         let mut data = data_phi.as_basic_value().into_pointer_value();
 
         let loop_var = loop_phi.as_basic_value().into_int_value();
@@ -580,12 +584,16 @@ impl<'a> Binary<'a> {
 
         let next = self
             .builder
-            .build_int_add(loop_var, loop_ty.const_int(1, false), "next_index");
+            .build_int_add(loop_var, loop_ty.const_int(1, false), "next_index")
+            .unwrap();
 
         let comp = self
             .builder
-            .build_int_compare(IntPredicate::ULT, next, to, "loop_cond");
-        self.builder.build_conditional_branch(comp, body, done);
+            .build_int_compare(IntPredicate::ULT, next, to, "loop_cond")
+            .unwrap();
+        self.builder
+            .build_conditional_branch(comp, body, done)
+            .unwrap();
 
         let body = self.builder.get_insert_block().unwrap();
         loop_phi.add_incoming(&[(&from, entry), (&next, body)]);
@@ -612,12 +620,12 @@ impl<'a> Binary<'a> {
         let done = self.context.append_basic_block(function, "done");
         let entry = self.builder.get_insert_block().unwrap();
 
-        self.builder.build_unconditional_branch(body);
+        self.builder.build_unconditional_branch(body).unwrap();
         self.builder.position_at_end(body);
 
         let loop_ty = from.get_type();
-        let loop_phi = self.builder.build_phi(loop_ty, "index");
-        let data_phi = self.builder.build_phi(data_ref.get_type(), "data");
+        let loop_phi = self.builder.build_phi(loop_ty, "index").unwrap();
+        let data_phi = self.builder.build_phi(data_ref.get_type(), "data").unwrap();
         let mut data = data_phi.as_basic_value().into_int_value();
 
         let loop_var = loop_phi.as_basic_value().into_int_value();
@@ -627,12 +635,16 @@ impl<'a> Binary<'a> {
 
         let next = self
             .builder
-            .build_int_add(loop_var, loop_ty.const_int(1, false), "next_index");
+            .build_int_add(loop_var, loop_ty.const_int(1, false), "next_index")
+            .unwrap();
 
         let comp = self
             .builder
-            .build_int_compare(IntPredicate::ULT, next, to, "loop_cond");
-        self.builder.build_conditional_branch(comp, body, done);
+            .build_int_compare(IntPredicate::ULT, next, to, "loop_cond")
+            .unwrap();
+        self.builder
+            .build_conditional_branch(comp, body, done)
+            .unwrap();
 
         let body = self.builder.get_insert_block().unwrap();
         loop_phi.add_incoming(&[(&from, entry), (&next, body)]);
@@ -659,24 +671,28 @@ impl<'a> Binary<'a> {
         let done = self.context.append_basic_block(function, "done");
         let entry = self.builder.get_insert_block().unwrap();
 
-        self.builder.build_unconditional_branch(cond);
+        self.builder.build_unconditional_branch(cond).unwrap();
         self.builder.position_at_end(cond);
 
         let loop_ty = from.get_type();
-        let loop_phi = self.builder.build_phi(loop_ty, "index");
-        let data_phi = self.builder.build_phi(data_ref.get_type(), "data");
+        let loop_phi = self.builder.build_phi(loop_ty, "index").unwrap();
+        let data_phi = self.builder.build_phi(data_ref.get_type(), "data").unwrap();
         let mut data = data_phi.as_basic_value().into_int_value();
 
         let loop_var = loop_phi.as_basic_value().into_int_value();
 
         let next = self
             .builder
-            .build_int_add(loop_var, loop_ty.const_int(1, false), "next_index");
+            .build_int_add(loop_var, loop_ty.const_int(1, false), "next_index")
+            .unwrap();
 
         let comp = self
             .builder
-            .build_int_compare(IntPredicate::ULT, loop_var, to, "loop_cond");
-        self.builder.build_conditional_branch(comp, body, done);
+            .build_int_compare(IntPredicate::ULT, loop_var, to, "loop_cond")
+            .unwrap();
+        self.builder
+            .build_conditional_branch(comp, body, done)
+            .unwrap();
 
         self.builder.position_at_end(body);
         // add loop body
@@ -687,7 +703,7 @@ impl<'a> Binary<'a> {
         loop_phi.add_incoming(&[(&from, entry), (&next, body)]);
         data_phi.add_incoming(&[(&*data_ref, entry), (&data, body)]);
 
-        self.builder.build_unconditional_branch(cond);
+        self.builder.build_unconditional_branch(cond).unwrap();
 
         self.builder.position_at_end(done);
 
@@ -710,24 +726,28 @@ impl<'a> Binary<'a> {
         let done = self.context.append_basic_block(function, "done");
         let entry = self.builder.get_insert_block().unwrap();
 
-        self.builder.build_unconditional_branch(cond);
+        self.builder.build_unconditional_branch(cond).unwrap();
         self.builder.position_at_end(cond);
 
         let loop_ty = from.get_type();
-        let loop_phi = self.builder.build_phi(loop_ty, "index");
-        let data_phi = self.builder.build_phi(data_ref.get_type(), "data");
+        let loop_phi = self.builder.build_phi(loop_ty, "index").unwrap();
+        let data_phi = self.builder.build_phi(data_ref.get_type(), "data").unwrap();
         let mut data = data_phi.as_basic_value().into_pointer_value();
 
         let loop_var = loop_phi.as_basic_value().into_int_value();
 
         let next = self
             .builder
-            .build_int_add(loop_var, loop_ty.const_int(1, false), "next_index");
+            .build_int_add(loop_var, loop_ty.const_int(1, false), "next_index")
+            .unwrap();
 
         let comp = self
             .builder
-            .build_int_compare(IntPredicate::ULT, loop_var, to, "loop_cond");
-        self.builder.build_conditional_branch(comp, body, done);
+            .build_int_compare(IntPredicate::ULT, loop_var, to, "loop_cond")
+            .unwrap();
+        self.builder
+            .build_conditional_branch(comp, body, done)
+            .unwrap();
 
         self.builder.position_at_end(body);
         // add loop body
@@ -738,7 +758,7 @@ impl<'a> Binary<'a> {
         loop_phi.add_incoming(&[(&from, entry), (&next, body)]);
         data_phi.add_incoming(&[(&*data_ref, entry), (&data, body)]);
 
-        self.builder.build_unconditional_branch(cond);
+        self.builder.build_unconditional_branch(cond).unwrap();
 
         self.builder.position_at_end(done);
 
@@ -1029,6 +1049,7 @@ impl<'a> Binary<'a> {
                 &[size.into(), elem_size.into(), init.into()],
                 "",
             )
+            .unwrap()
             .try_as_basic_value()
             .left()
             .unwrap()
@@ -1041,40 +1062,48 @@ impl<'a> Binary<'a> {
             // slice
             let slice = vector.into_struct_value();
 
-            self.builder.build_int_truncate(
-                self.builder
-                    .build_extract_value(slice, 1, "slice_len")
-                    .unwrap()
-                    .into_int_value(),
-                self.context.i32_type(),
-                "len",
-            )
+            self.builder
+                .build_int_truncate(
+                    self.builder
+                        .build_extract_value(slice, 1, "slice_len")
+                        .unwrap()
+                        .into_int_value(),
+                    self.context.i32_type(),
+                    "len",
+                )
+                .unwrap()
         } else {
             // field 0 is the length
             let vector = vector.into_pointer_value();
             let vector_type = self.module.get_struct_type("struct.vector").unwrap();
 
             let len = unsafe {
-                self.builder.build_gep(
-                    vector_type,
-                    vector,
-                    &[
-                        self.context.i32_type().const_zero(),
-                        self.context.i32_type().const_zero(),
-                    ],
-                    "vector_len",
-                )
+                self.builder
+                    .build_gep(
+                        vector_type,
+                        vector,
+                        &[
+                            self.context.i32_type().const_zero(),
+                            self.context.i32_type().const_zero(),
+                        ],
+                        "vector_len",
+                    )
+                    .unwrap()
             };
 
             self.builder
                 .build_select(
-                    self.builder.build_is_null(vector, "vector_is_null"),
+                    self.builder
+                        .build_is_null(vector, "vector_is_null")
+                        .unwrap(),
                     self.context.i32_type().const_zero(),
                     self.builder
                         .build_load(self.context.i32_type(), len, "vector_len")
+                        .unwrap()
                         .into_int_value(),
                     "length",
                 )
+                .unwrap()
                 .into_int_value()
         }
     }
@@ -1091,15 +1120,17 @@ impl<'a> Binary<'a> {
         } else {
             let vector_type = self.module.get_struct_type("struct.vector").unwrap();
             unsafe {
-                self.builder.build_gep(
-                    vector_type,
-                    vector.into_pointer_value(),
-                    &[
-                        self.context.i32_type().const_zero(),
-                        self.context.i32_type().const_int(2, false),
-                    ],
-                    "data",
-                )
+                self.builder
+                    .build_gep(
+                        vector_type,
+                        vector.into_pointer_value(),
+                        &[
+                            self.context.i32_type().const_zero(),
+                            self.context.i32_type().const_int(2, false),
+                        ],
+                        "data",
+                    )
+                    .unwrap()
             }
         }
     }
@@ -1118,40 +1149,47 @@ impl<'a> Binary<'a> {
                     // fixed size array
                     let llvm_ty = self.llvm_type(array_ty, ns);
                     unsafe {
-                        self.builder.build_gep(
-                            llvm_ty,
-                            array,
-                            &[self.context.i32_type().const_zero(), index],
-                            "index_access",
-                        )
+                        self.builder
+                            .build_gep(
+                                llvm_ty,
+                                array,
+                                &[self.context.i32_type().const_zero(), index],
+                                "index_access",
+                            )
+                            .unwrap()
                     }
                 } else {
                     let elem_ty = array_ty.array_deref();
                     let llvm_elem_ty = self.llvm_type(elem_ty.deref_memory(), ns);
 
                     // dynamic length array or vector
-                    let index = self.builder.build_int_mul(
-                        index,
-                        llvm_elem_ty
-                            .size_of()
-                            .unwrap()
-                            .const_cast(self.context.i32_type(), false),
-                        "",
-                    );
+                    let index = self
+                        .builder
+                        .build_int_mul(
+                            index,
+                            llvm_elem_ty
+                                .size_of()
+                                .unwrap()
+                                .const_cast(self.context.i32_type(), false),
+                            "",
+                        )
+                        .unwrap();
 
                     let vector_type = self.module.get_struct_type("struct.vector").unwrap();
 
                     unsafe {
-                        self.builder.build_gep(
-                            vector_type,
-                            array,
-                            &[
-                                self.context.i32_type().const_zero(),
-                                self.context.i32_type().const_int(2, false),
-                                index,
-                            ],
-                            "index_access",
-                        )
+                        self.builder
+                            .build_gep(
+                                vector_type,
+                                array,
+                                &[
+                                    self.context.i32_type().const_zero(),
+                                    self.context.i32_type().const_int(2, false),
+                                    index,
+                                ],
+                                "index_access",
+                            )
+                            .unwrap()
                     }
                 }
             }

+ 1 - 1
src/emit/cfg.rs

@@ -244,7 +244,7 @@ pub(super) fn create_block<'a>(
         for v in cfg_phis {
             let ty = bin.llvm_var_ty(&cfg.vars[v].ty, ns);
 
-            phis.insert(*v, bin.builder.build_phi(ty, &cfg.vars[v].id.name));
+            phis.insert(*v, bin.builder.build_phi(ty, &cfg.vars[v].id.name).unwrap());
         }
     }
 

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 359 - 227
src/emit/expression.rs


+ 259 - 188
src/emit/instructions.rs

@@ -38,7 +38,8 @@ pub(super) fn process_instruction<'a, T: TargetRuntime<'a> + ?Sized>(
         Instr::Nop => (),
         Instr::Return { value } if value.is_empty() && ns.target != Target::Soroban => {
             bin.builder
-                .build_return(Some(&bin.return_values[&ReturnCode::Success]));
+                .build_return(Some(&bin.return_values[&ReturnCode::Success]))
+                .unwrap();
         }
         Instr::Return { value } if ns.target != Target::Soroban => {
             let returns_offset = cfg.params.len();
@@ -46,19 +47,22 @@ pub(super) fn process_instruction<'a, T: TargetRuntime<'a> + ?Sized>(
                 let arg = function.get_nth_param((returns_offset + i) as u32).unwrap();
                 let retval = expression(target, bin, val, &w.vars, function, ns);
 
-                bin.builder.build_store(arg.into_pointer_value(), retval);
+                bin.builder
+                    .build_store(arg.into_pointer_value(), retval)
+                    .unwrap();
             }
 
             bin.builder
-                .build_return(Some(&bin.return_values[&ReturnCode::Success]));
+                .build_return(Some(&bin.return_values[&ReturnCode::Success]))
+                .unwrap();
         }
         Instr::Return { value } => match value.iter().next() {
             Some(val) => {
                 let retval = expression(target, bin, val, &w.vars, function, ns);
-                bin.builder.build_return(Some(&retval));
+                bin.builder.build_return(Some(&retval)).unwrap();
             }
             None => {
-                bin.builder.build_return(None);
+                bin.builder.build_return(None).unwrap();
             }
         },
         Instr::Set { res, expr, .. } => {
@@ -80,13 +84,13 @@ pub(super) fn process_instruction<'a, T: TargetRuntime<'a> + ?Sized>(
             let bb = add_or_retrieve_block(*dest, pos, bin, function, blocks, work, w, cfg, ns);
 
             bin.builder.position_at_end(pos);
-            bin.builder.build_unconditional_branch(bb);
+            bin.builder.build_unconditional_branch(bb).unwrap();
         }
         Instr::Store { dest, data } => {
             let value_ref = expression(target, bin, data, &w.vars, function, ns);
             let dest_ref =
                 expression(target, bin, dest, &w.vars, function, ns).into_pointer_value();
-            bin.builder.build_store(dest_ref, value_ref);
+            bin.builder.build_store(dest_ref, value_ref).unwrap();
         }
         Instr::BranchCond {
             cond,
@@ -105,7 +109,8 @@ pub(super) fn process_instruction<'a, T: TargetRuntime<'a> + ?Sized>(
 
             bin.builder.position_at_end(pos);
             bin.builder
-                .build_conditional_branch(cond.into_int_value(), bb_true, bb_false);
+                .build_conditional_branch(cond.into_int_value(), bb_true, bb_false)
+                .unwrap();
         }
         Instr::LoadStorage { res, ty, storage } => {
             let mut slot = expression(target, bin, storage, &w.vars, function, ns).into_int_value();
@@ -188,9 +193,10 @@ pub(super) fn process_instruction<'a, T: TargetRuntime<'a> + ?Sized>(
                 .unwrap()
                 .const_cast(bin.context.i32_type(), false);
             let len = bin.vector_len(arr);
-            let new_len =
-                bin.builder
-                    .build_int_add(len, bin.context.i32_type().const_int(1, false), "");
+            let new_len = bin
+                .builder
+                .build_int_add(len, bin.context.i32_type().const_int(1, false), "")
+                .unwrap();
             let vec_size = bin
                 .module
                 .get_struct_type("struct.vector")
@@ -198,8 +204,8 @@ pub(super) fn process_instruction<'a, T: TargetRuntime<'a> + ?Sized>(
                 .size_of()
                 .unwrap()
                 .const_cast(bin.context.i32_type(), false);
-            let size = bin.builder.build_int_mul(elem_size, new_len, "");
-            let size = bin.builder.build_int_add(size, vec_size, "");
+            let size = bin.builder.build_int_mul(elem_size, new_len, "").unwrap();
+            let size = bin.builder.build_int_add(size, vec_size, "").unwrap();
 
             // Reallocate and reassign the array pointer
             let new = bin
@@ -209,6 +215,7 @@ pub(super) fn process_instruction<'a, T: TargetRuntime<'a> + ?Sized>(
                     &[arr.into(), size.into()],
                     "",
                 )
+                .unwrap()
                 .try_as_basic_value()
                 .left()
                 .unwrap()
@@ -217,16 +224,18 @@ pub(super) fn process_instruction<'a, T: TargetRuntime<'a> + ?Sized>(
 
             // Store the value into the last element
             let slot_ptr = unsafe {
-                bin.builder.build_gep(
-                    llvm_ty,
-                    new,
-                    &[
-                        bin.context.i32_type().const_zero(),
-                        bin.context.i32_type().const_int(2, false),
-                        bin.builder.build_int_mul(len, elem_size, ""),
-                    ],
-                    "data",
-                )
+                bin.builder
+                    .build_gep(
+                        llvm_ty,
+                        new,
+                        &[
+                            bin.context.i32_type().const_zero(),
+                            bin.context.i32_type().const_int(2, false),
+                            bin.builder.build_int_mul(len, elem_size, "").unwrap(),
+                        ],
+                        "data",
+                    )
+                    .unwrap()
             };
             let value = expression(target, bin, value, &w.vars, function, ns);
             let value = if elem_ty.is_fixed_reference_type(ns) {
@@ -234,38 +243,43 @@ pub(super) fn process_instruction<'a, T: TargetRuntime<'a> + ?Sized>(
                 let load_ty = bin.llvm_type(&elem_ty, ns);
                 bin.builder
                     .build_load(load_ty, value.into_pointer_value(), "elem")
+                    .unwrap()
             } else {
                 w.vars.get_mut(res).unwrap().value = value;
                 value
             };
-            bin.builder.build_store(slot_ptr, value);
+            bin.builder.build_store(slot_ptr, value).unwrap();
 
             // Update the len and size field of the vector struct
             let len_ptr = unsafe {
-                bin.builder.build_gep(
-                    llvm_ty,
-                    new,
-                    &[
-                        bin.context.i32_type().const_zero(),
-                        bin.context.i32_type().const_zero(),
-                    ],
-                    "len",
-                )
+                bin.builder
+                    .build_gep(
+                        llvm_ty,
+                        new,
+                        &[
+                            bin.context.i32_type().const_zero(),
+                            bin.context.i32_type().const_zero(),
+                        ],
+                        "len",
+                    )
+                    .unwrap()
             };
-            bin.builder.build_store(len_ptr, new_len);
+            bin.builder.build_store(len_ptr, new_len).unwrap();
 
             let size_ptr = unsafe {
-                bin.builder.build_gep(
-                    llvm_ty,
-                    new,
-                    &[
-                        bin.context.i32_type().const_zero(),
-                        bin.context.i32_type().const_int(1, false),
-                    ],
-                    "size",
-                )
+                bin.builder
+                    .build_gep(
+                        llvm_ty,
+                        new,
+                        &[
+                            bin.context.i32_type().const_zero(),
+                            bin.context.i32_type().const_int(1, false),
+                        ],
+                        "size",
+                    )
+                    .unwrap()
             };
-            bin.builder.build_store(size_ptr, new_len);
+            bin.builder.build_store(size_ptr, new_len).unwrap();
         }
         Instr::PopMemory {
             res,
@@ -275,32 +289,39 @@ pub(super) fn process_instruction<'a, T: TargetRuntime<'a> + ?Sized>(
         } => {
             let a = w.vars[array].value.into_pointer_value();
             let len = unsafe {
-                bin.builder.build_gep(
-                    bin.module.get_struct_type("struct.vector").unwrap(),
-                    a,
-                    &[
-                        bin.context.i32_type().const_zero(),
-                        bin.context.i32_type().const_zero(),
-                    ],
-                    "a_len",
-                )
+                bin.builder
+                    .build_gep(
+                        bin.module.get_struct_type("struct.vector").unwrap(),
+                        a,
+                        &[
+                            bin.context.i32_type().const_zero(),
+                            bin.context.i32_type().const_zero(),
+                        ],
+                        "a_len",
+                    )
+                    .unwrap()
             };
             let len = bin
                 .builder
                 .build_load(bin.context.i32_type(), len, "a_len")
+                .unwrap()
                 .into_int_value();
 
             // First check if the array is empty
-            let is_array_empty = bin.builder.build_int_compare(
-                IntPredicate::EQ,
-                len,
-                bin.context.i32_type().const_zero(),
-                "is_array_empty",
-            );
+            let is_array_empty = bin
+                .builder
+                .build_int_compare(
+                    IntPredicate::EQ,
+                    len,
+                    bin.context.i32_type().const_zero(),
+                    "is_array_empty",
+                )
+                .unwrap();
             let error = bin.context.append_basic_block(function, "error");
             let pop = bin.context.append_basic_block(function, "pop");
             bin.builder
-                .build_conditional_branch(is_array_empty, error, pop);
+                .build_conditional_branch(is_array_empty, error, pop)
+                .unwrap();
 
             bin.builder.position_at_end(error);
             bin.log_runtime_error(target, "pop from empty array".to_string(), Some(*loc), ns);
@@ -318,9 +339,10 @@ pub(super) fn process_instruction<'a, T: TargetRuntime<'a> + ?Sized>(
                 .size_of()
                 .unwrap()
                 .const_cast(bin.context.i32_type(), false);
-            let new_len =
-                bin.builder
-                    .build_int_sub(len, bin.context.i32_type().const_int(1, false), "");
+            let new_len = bin
+                .builder
+                .build_int_sub(len, bin.context.i32_type().const_int(1, false), "")
+                .unwrap();
             let vec_size = bin
                 .module
                 .get_struct_type("struct.vector")
@@ -328,28 +350,31 @@ pub(super) fn process_instruction<'a, T: TargetRuntime<'a> + ?Sized>(
                 .size_of()
                 .unwrap()
                 .const_cast(bin.context.i32_type(), false);
-            let size = bin.builder.build_int_mul(elem_size, new_len, "");
-            let size = bin.builder.build_int_add(size, vec_size, "");
+            let size = bin.builder.build_int_mul(elem_size, new_len, "").unwrap();
+            let size = bin.builder.build_int_add(size, vec_size, "").unwrap();
 
             // Get the pointer to the last element and return it
             let slot_ptr = unsafe {
-                bin.builder.build_gep(
-                    bin.module.get_struct_type("struct.vector").unwrap(),
-                    a,
-                    &[
-                        bin.context.i32_type().const_zero(),
-                        bin.context.i32_type().const_int(2, false),
-                        bin.builder.build_int_mul(new_len, elem_size, ""),
-                    ],
-                    "data",
-                )
+                bin.builder
+                    .build_gep(
+                        bin.module.get_struct_type("struct.vector").unwrap(),
+                        a,
+                        &[
+                            bin.context.i32_type().const_zero(),
+                            bin.context.i32_type().const_int(2, false),
+                            bin.builder.build_int_mul(new_len, elem_size, "").unwrap(),
+                        ],
+                        "data",
+                    )
+                    .unwrap()
             };
             if elem_ty.is_fixed_reference_type(ns) {
                 w.vars.get_mut(res).unwrap().value = slot_ptr.into();
             } else {
                 let ret_val = bin
                     .builder
-                    .build_load(bin.llvm_type(&elem_ty, ns), slot_ptr, "");
+                    .build_load(bin.llvm_type(&elem_ty, ns), slot_ptr, "")
+                    .unwrap();
                 w.vars.get_mut(res).unwrap().value = ret_val;
             }
 
@@ -361,6 +386,7 @@ pub(super) fn process_instruction<'a, T: TargetRuntime<'a> + ?Sized>(
                     &[a.into(), size.into()],
                     "",
                 )
+                .unwrap()
                 .try_as_basic_value()
                 .left()
                 .unwrap()
@@ -369,30 +395,34 @@ pub(super) fn process_instruction<'a, T: TargetRuntime<'a> + ?Sized>(
 
             // Update the len and size field of the vector struct
             let len_ptr = unsafe {
-                bin.builder.build_gep(
-                    llvm_ty,
-                    new,
-                    &[
-                        bin.context.i32_type().const_zero(),
-                        bin.context.i32_type().const_zero(),
-                    ],
-                    "len",
-                )
+                bin.builder
+                    .build_gep(
+                        llvm_ty,
+                        new,
+                        &[
+                            bin.context.i32_type().const_zero(),
+                            bin.context.i32_type().const_zero(),
+                        ],
+                        "len",
+                    )
+                    .unwrap()
             };
-            bin.builder.build_store(len_ptr, new_len);
+            bin.builder.build_store(len_ptr, new_len).unwrap();
 
             let size_ptr = unsafe {
-                bin.builder.build_gep(
-                    llvm_ty,
-                    new,
-                    &[
-                        bin.context.i32_type().const_zero(),
-                        bin.context.i32_type().const_int(1, false),
-                    ],
-                    "size",
-                )
+                bin.builder
+                    .build_gep(
+                        llvm_ty,
+                        new,
+                        &[
+                            bin.context.i32_type().const_zero(),
+                            bin.context.i32_type().const_int(1, false),
+                        ],
+                        "size",
+                    )
+                    .unwrap()
             };
-            bin.builder.build_store(size_ptr, new_len);
+            bin.builder.build_store(size_ptr, new_len).unwrap();
         }
         Instr::AssertFailure { encoded_args: None } => {
             target.assert_failure(
@@ -439,6 +469,7 @@ pub(super) fn process_instruction<'a, T: TargetRuntime<'a> + ?Sized>(
                     } else {
                         bin.builder
                             .build_alloca(bin.llvm_var_ty(&v.ty, ns), v.name_as_str())
+                            .unwrap()
                             .into()
                     });
                 }
@@ -451,42 +482,52 @@ pub(super) fn process_instruction<'a, T: TargetRuntime<'a> + ?Sized>(
             let ret = bin
                 .builder
                 .build_call(bin.functions[cfg_no], &parms, "")
+                .unwrap()
                 .try_as_basic_value()
                 .left()
                 .unwrap();
 
-            let success = bin.builder.build_int_compare(
-                IntPredicate::EQ,
-                ret.into_int_value(),
-                bin.return_values[&ReturnCode::Success],
-                "success",
-            );
+            let success = bin
+                .builder
+                .build_int_compare(
+                    IntPredicate::EQ,
+                    ret.into_int_value(),
+                    bin.return_values[&ReturnCode::Success],
+                    "success",
+                )
+                .unwrap();
 
             let success_block = bin.context.append_basic_block(function, "success");
             let bail_block = bin.context.append_basic_block(function, "bail");
             bin.builder
-                .build_conditional_branch(success, success_block, bail_block);
+                .build_conditional_branch(success, success_block, bail_block)
+                .unwrap();
 
             bin.builder.position_at_end(bail_block);
 
-            bin.builder.build_return(Some(&ret));
+            bin.builder.build_return(Some(&ret)).unwrap();
             bin.builder.position_at_end(success_block);
 
             if !res.is_empty() {
                 for (i, v) in f.returns.iter().enumerate() {
                     let load_ty = bin.llvm_var_ty(&v.ty, ns);
-                    let val = bin.builder.build_load(
-                        load_ty,
-                        parms[args.len() + i].into_pointer_value(),
-                        v.name_as_str(),
-                    );
+                    let val = bin
+                        .builder
+                        .build_load(
+                            load_ty,
+                            parms[args.len() + i].into_pointer_value(),
+                            v.name_as_str(),
+                        )
+                        .unwrap();
                     let dest = w.vars[&res[i]].value;
 
                     if dest.is_pointer_value()
                         && !(v.ty.is_reference_type(ns)
                             || matches!(v.ty, Type::ExternalFunction { .. }))
                     {
-                        bin.builder.build_store(dest.into_pointer_value(), val);
+                        bin.builder
+                            .build_store(dest.into_pointer_value(), val)
+                            .unwrap();
                     } else {
                         w.vars.get_mut(&res[i]).unwrap().value = val;
                     }
@@ -514,6 +555,7 @@ pub(super) fn process_instruction<'a, T: TargetRuntime<'a> + ?Sized>(
                     } else {
                         bin.builder
                             .build_alloca(bin.llvm_var_ty(&v.ty, ns), v.name_as_str())
+                            .unwrap()
                             .into()
                     });
                 }
@@ -527,19 +569,23 @@ pub(super) fn process_instruction<'a, T: TargetRuntime<'a> + ?Sized>(
                 args.first().map(|arg| bin.llvm_type(&arg.ty(), ns)),
                 ns,
             ) {
-                let success = bin.builder.build_int_compare(
-                    IntPredicate::EQ,
-                    ret.into_int_value(),
-                    bin.return_values[&ReturnCode::Success],
-                    "success",
-                );
+                let success = bin
+                    .builder
+                    .build_int_compare(
+                        IntPredicate::EQ,
+                        ret.into_int_value(),
+                        bin.return_values[&ReturnCode::Success],
+                        "success",
+                    )
+                    .unwrap();
                 let success_block = bin.context.append_basic_block(function, "success");
                 let bail_block = bin.context.append_basic_block(function, "bail");
                 bin.builder
-                    .build_conditional_branch(success, success_block, bail_block);
+                    .build_conditional_branch(success, success_block, bail_block)
+                    .unwrap();
 
                 bin.builder.position_at_end(bail_block);
-                bin.builder.build_return(Some(&ret));
+                bin.builder.build_return(Some(&ret)).unwrap();
 
                 bin.builder.position_at_end(success_block);
             }
@@ -553,11 +599,14 @@ pub(super) fn process_instruction<'a, T: TargetRuntime<'a> + ?Sized>(
                     } else {
                         bin.llvm_type(&v.ty, ns)
                     };
-                    let val = bin.builder.build_load(
-                        load_ty,
-                        parms[args.len() + i].into_pointer_value(),
-                        v.name_as_str(),
-                    );
+                    let val = bin
+                        .builder
+                        .build_load(
+                            load_ty,
+                            parms[args.len() + i].into_pointer_value(),
+                            v.name_as_str(),
+                        )
+                        .unwrap();
 
                     let dest = w.vars[&res[i]].value;
 
@@ -565,7 +614,9 @@ pub(super) fn process_instruction<'a, T: TargetRuntime<'a> + ?Sized>(
                         && !(v.ty.is_reference_type(ns)
                             || matches!(v.ty, Type::ExternalFunction { .. }))
                     {
-                        bin.builder.build_store(dest.into_pointer_value(), val);
+                        bin.builder
+                            .build_store(dest.into_pointer_value(), val)
+                            .unwrap();
                     } else {
                         w.vars.get_mut(&res[i]).unwrap().value = val;
                     }
@@ -618,11 +669,13 @@ pub(super) fn process_instruction<'a, T: TargetRuntime<'a> + ?Sized>(
                 .i8_type()
                 .ptr_type(AddressSpace::default())
                 .const_null();
-            let is_ptr_nil =
-                bin.builder
-                    .build_int_compare(IntPredicate::EQ, nil_ptr, callable, "check_nil_ptr");
+            let is_ptr_nil = bin
+                .builder
+                .build_int_compare(IntPredicate::EQ, nil_ptr, callable, "check_nil_ptr")
+                .unwrap();
             bin.builder
-                .build_conditional_branch(is_ptr_nil, ptr_nil_block, ptr_ok);
+                .build_conditional_branch(is_ptr_nil, ptr_nil_block, ptr_ok)
+                .unwrap();
 
             bin.builder.position_at_end(ptr_nil_block);
             bin.log_runtime_error(
@@ -639,40 +692,46 @@ pub(super) fn process_instruction<'a, T: TargetRuntime<'a> + ?Sized>(
             let ret = bin
                 .builder
                 .build_indirect_call(llvm_func, callable, &parms, "")
+                .unwrap()
                 .try_as_basic_value()
                 .left()
                 .unwrap();
 
-            let success = bin.builder.build_int_compare(
-                IntPredicate::EQ,
-                ret.into_int_value(),
-                bin.return_values[&ReturnCode::Success],
-                "success",
-            );
+            let success = bin
+                .builder
+                .build_int_compare(
+                    IntPredicate::EQ,
+                    ret.into_int_value(),
+                    bin.return_values[&ReturnCode::Success],
+                    "success",
+                )
+                .unwrap();
 
             let success_block = bin.context.append_basic_block(function, "success");
             let bail_block = bin.context.append_basic_block(function, "bail");
             bin.builder
-                .build_conditional_branch(success, success_block, bail_block);
+                .build_conditional_branch(success, success_block, bail_block)
+                .unwrap();
 
             bin.builder.position_at_end(bail_block);
 
-            bin.builder.build_return(Some(&ret));
+            bin.builder.build_return(Some(&ret)).unwrap();
             bin.builder.position_at_end(success_block);
 
             if !res.is_empty() {
                 for (i, ty) in returns.iter().enumerate() {
                     let load_ty = bin.llvm_var_ty(ty, ns);
-                    let val = bin.builder.build_load(
-                        load_ty,
-                        parms[args.len() + i].into_pointer_value(),
-                        "",
-                    );
+                    let val = bin
+                        .builder
+                        .build_load(load_ty, parms[args.len() + i].into_pointer_value(), "")
+                        .unwrap();
 
                     let dest = w.vars[&res[i]].value;
 
                     if dest.is_pointer_value() && !ty.is_reference_type(ns) {
-                        bin.builder.build_store(dest.into_pointer_value(), val);
+                        bin.builder
+                            .build_store(dest.into_pointer_value(), val)
+                            .unwrap();
                     } else {
                         w.vars.get_mut(&res[i]).unwrap().value = val;
                     }
@@ -712,7 +771,7 @@ pub(super) fn process_instruction<'a, T: TargetRuntime<'a> + ?Sized>(
                 let address =
                     expression(target, bin, address, &w.vars, function, ns).into_array_value();
 
-                bin.builder.build_store(address_stack, address);
+                bin.builder.build_store(address_stack, address).unwrap();
             }
 
             let seeds = if let Some(seeds) = seeds {
@@ -743,34 +802,38 @@ pub(super) fn process_instruction<'a, T: TargetRuntime<'a> + ?Sized>(
                             .unwrap();
 
                         let dest = unsafe {
-                            bin.builder.build_gep(
-                                seeds_ty,
-                                output_seeds,
-                                &[
-                                    bin.context.i32_type().const_int(i, false),
-                                    bin.context.i32_type().const_zero(),
-                                ],
-                                "dest",
-                            )
+                            bin.builder
+                                .build_gep(
+                                    seeds_ty,
+                                    output_seeds,
+                                    &[
+                                        bin.context.i32_type().const_int(i, false),
+                                        bin.context.i32_type().const_zero(),
+                                    ],
+                                    "dest",
+                                )
+                                .unwrap()
                         };
 
-                        bin.builder.build_store(dest, val);
+                        bin.builder.build_store(dest, val).unwrap();
 
                         let dest = unsafe {
-                            bin.builder.build_gep(
-                                seeds_ty,
-                                output_seeds,
-                                &[
-                                    bin.context.i32_type().const_int(i, false),
-                                    bin.context.i32_type().const_int(1, false),
-                                ],
-                                "dest",
-                            )
+                            bin.builder
+                                .build_gep(
+                                    seeds_ty,
+                                    output_seeds,
+                                    &[
+                                        bin.context.i32_type().const_int(i, false),
+                                        bin.context.i32_type().const_int(1, false),
+                                    ],
+                                    "dest",
+                                )
+                                .unwrap()
                         };
 
                         let val = bin.context.i64_type().const_int(seed_count, false);
 
-                        bin.builder.build_store(dest, val);
+                        bin.builder.build_store(dest, val).unwrap();
                     }
                 }
 
@@ -800,9 +863,10 @@ pub(super) fn process_instruction<'a, T: TargetRuntime<'a> + ?Sized>(
                 *loc,
             );
 
-            w.vars.get_mut(res).unwrap().value =
-                bin.builder
-                    .build_load(bin.address_type(ns), address_stack, "address");
+            w.vars.get_mut(res).unwrap().value = bin
+                .builder
+                .build_load(bin.address_type(ns), address_stack, "address")
+                .unwrap();
         }
         Instr::ExternalCall {
             success,
@@ -834,7 +898,7 @@ pub(super) fn process_instruction<'a, T: TargetRuntime<'a> + ?Sized>(
                     "address",
                 );
 
-                bin.builder.build_store(addr, address);
+                bin.builder.build_store(addr, address).unwrap();
 
                 Some(addr)
             } else {
@@ -904,7 +968,7 @@ pub(super) fn process_instruction<'a, T: TargetRuntime<'a> + ?Sized>(
 
             let addr = bin.build_alloca(function, bin.address_type(ns), "address");
 
-            bin.builder.build_store(addr, address);
+            bin.builder.build_store(addr, address).unwrap();
             let success = match success {
                 Some(n) => Some(&mut w.vars.get_mut(n).unwrap().value),
                 None => None,
@@ -936,6 +1000,7 @@ pub(super) fn process_instruction<'a, T: TargetRuntime<'a> + ?Sized>(
             let start = unsafe {
                 bin.builder
                     .build_gep(bin.context.i8_type(), data, &[offset], "start")
+                    .unwrap()
             };
 
             let is_bytes = if let Type::Bytes(n) = value.ty().unwrap_user_type(ns) {
@@ -953,21 +1018,24 @@ pub(super) fn process_instruction<'a, T: TargetRuntime<'a> + ?Sized>(
                     &format!("bytes{is_bytes}"),
                 );
                 bin.builder
-                    .build_store(value_ptr, emit_value.into_int_value());
-                bin.builder.build_call(
-                    bin.module.get_function("__leNtobeN").unwrap(),
-                    &[
-                        value_ptr.into(),
-                        start.into(),
-                        bin.context
-                            .i32_type()
-                            .const_int(is_bytes as u64, false)
-                            .into(),
-                    ],
-                    "",
-                );
+                    .build_store(value_ptr, emit_value.into_int_value())
+                    .unwrap();
+                bin.builder
+                    .build_call(
+                        bin.module.get_function("__leNtobeN").unwrap(),
+                        &[
+                            value_ptr.into(),
+                            start.into(),
+                            bin.context
+                                .i32_type()
+                                .const_int(is_bytes as u64, false)
+                                .into(),
+                        ],
+                        "",
+                    )
+                    .unwrap();
             } else {
-                bin.builder.build_store(start, emit_value);
+                bin.builder.build_store(start, emit_value).unwrap();
             }
         }
         Instr::MemCopy {
@@ -989,11 +1057,13 @@ pub(super) fn process_instruction<'a, T: TargetRuntime<'a> + ?Sized>(
 
             let size = expression(target, bin, bytes, &w.vars, function, ns);
 
-            bin.builder.build_call(
-                bin.module.get_function("__memcpy").unwrap(),
-                &[dest.into(), src.into(), size.into()],
-                "",
-            );
+            bin.builder
+                .build_call(
+                    bin.module.get_function("__memcpy").unwrap(),
+                    &[dest.into(), src.into(), size.into()],
+                    "",
+                )
+                .unwrap();
         }
         Instr::Switch {
             cond,
@@ -1017,7 +1087,8 @@ pub(super) fn process_instruction<'a, T: TargetRuntime<'a> + ?Sized>(
                 add_or_retrieve_block(*default, pos, bin, function, blocks, work, w, cfg, ns);
             bin.builder.position_at_end(pos);
             bin.builder
-                .build_switch(cond.into_int_value(), default_bb, cases.as_ref());
+                .build_switch(cond.into_int_value(), default_bb, cases.as_ref())
+                .unwrap();
         }
 
         Instr::ReturnData { data, data_len } => {

+ 16 - 10
src/emit/loop_builder.rs

@@ -28,7 +28,10 @@ impl<'a> LoopBuilder<'a> {
         let body_block = binary.context.append_basic_block(function, "body");
         let done_block = binary.context.append_basic_block(function, "done");
 
-        binary.builder.build_unconditional_branch(condition_block);
+        binary
+            .builder
+            .build_unconditional_branch(condition_block)
+            .unwrap();
 
         binary.builder.position_at_end(condition_block);
 
@@ -53,7 +56,7 @@ impl<'a> LoopBuilder<'a> {
         ty: T,
         initial_value: BasicValueEnum<'a>,
     ) -> BasicValueEnum<'a> {
-        let phi = binary.builder.build_phi(ty, name);
+        let phi = binary.builder.build_phi(ty, name).unwrap();
 
         phi.add_incoming(&[(&initial_value, self.entry_block)]);
 
@@ -74,22 +77,24 @@ impl<'a> LoopBuilder<'a> {
         to: IntValue<'a>,
     ) -> IntValue<'a> {
         let loop_ty = from.get_type();
-        let loop_phi = binary.builder.build_phi(loop_ty, "index");
+        let loop_phi = binary.builder.build_phi(loop_ty, "index").unwrap();
 
         let loop_var = loop_phi.as_basic_value().into_int_value();
 
-        let next =
-            binary
-                .builder
-                .build_int_add(loop_var, loop_ty.const_int(1, false), "next_index");
+        let next = binary
+            .builder
+            .build_int_add(loop_var, loop_ty.const_int(1, false), "next_index")
+            .unwrap();
 
         let comp = binary
             .builder
-            .build_int_compare(IntPredicate::ULT, loop_var, to, "loop_cond");
+            .build_int_compare(IntPredicate::ULT, loop_var, to, "loop_cond")
+            .unwrap();
 
         binary
             .builder
-            .build_conditional_branch(comp, self.body_block, self.done_block);
+            .build_conditional_branch(comp, self.body_block, self.done_block)
+            .unwrap();
 
         loop_phi.add_incoming(&[(&from, self.entry_block)]);
 
@@ -124,7 +129,8 @@ impl<'a> LoopBuilder<'a> {
 
         binary
             .builder
-            .build_unconditional_branch(self.condition_block);
+            .build_unconditional_branch(self.condition_block)
+            .unwrap();
 
         binary.builder.position_at_end(self.done_block);
     }

+ 253 - 155
src/emit/math.rs

@@ -30,38 +30,46 @@ fn signed_ovf_detect<'a, T: TargetRuntime<'a> + ?Sized>(
     //  + * + = +
     //  - * + = - (if op1 and op2 != 0)
     // if one of the operands is zero, discard the last rule.
-    let left_negative = bin.builder.build_int_compare(
-        IntPredicate::SLT,
-        left,
-        left.get_type().const_zero(),
-        "left_negative",
-    );
+    let left_negative = bin
+        .builder
+        .build_int_compare(
+            IntPredicate::SLT,
+            left,
+            left.get_type().const_zero(),
+            "left_negative",
+        )
+        .unwrap();
 
     let left_abs = bin
         .builder
         .build_select(
             left_negative,
-            bin.builder.build_int_neg(left, "signed_left"),
+            bin.builder.build_int_neg(left, "signed_left").unwrap(),
             left,
             "left_abs",
         )
+        .unwrap()
         .into_int_value();
 
-    let right_negative = bin.builder.build_int_compare(
-        IntPredicate::SLT,
-        right,
-        right.get_type().const_zero(),
-        "right_negative",
-    );
+    let right_negative = bin
+        .builder
+        .build_int_compare(
+            IntPredicate::SLT,
+            right,
+            right.get_type().const_zero(),
+            "right_negative",
+        )
+        .unwrap();
 
     let right_abs = bin
         .builder
         .build_select(
             right_negative,
-            bin.builder.build_int_neg(right, "signed_right"),
+            bin.builder.build_int_neg(right, "signed_right").unwrap(),
             right,
             "right_abs",
         )
+        .unwrap()
         .into_int_value();
 
     let l = bin.build_alloca(function, mul_ty, "");
@@ -69,9 +77,21 @@ fn signed_ovf_detect<'a, T: TargetRuntime<'a> + ?Sized>(
     let o = bin.build_alloca(function, mul_ty, "");
 
     bin.builder
-        .build_store(l, bin.builder.build_int_z_extend(left_abs, mul_ty, ""));
+        .build_store(
+            l,
+            bin.builder
+                .build_int_z_extend(left_abs, mul_ty, "")
+                .unwrap(),
+        )
+        .unwrap();
     bin.builder
-        .build_store(r, bin.builder.build_int_z_extend(right_abs, mul_ty, ""));
+        .build_store(
+            r,
+            bin.builder
+                .build_int_z_extend(right_abs, mul_ty, "")
+                .unwrap(),
+        )
+        .unwrap();
 
     let return_val = bin.builder.build_call(
         bin.module.get_function("__mul32_with_builtin_ovf").unwrap(),
@@ -87,21 +107,26 @@ fn signed_ovf_detect<'a, T: TargetRuntime<'a> + ?Sized>(
         "",
     );
 
-    let res = bin.builder.build_load(mul_ty, o, "mul");
+    let res = bin.builder.build_load(mul_ty, o, "mul").unwrap();
     let ovf_any_type = if mul_bits != bits {
         // If there are any set bits, then there is an overflow.
-        let check_ovf = bin.builder.build_right_shift(
-            res.into_int_value(),
-            mul_ty.const_int((bits).into(), false),
-            false,
-            "",
-        );
-        bin.builder.build_int_compare(
-            IntPredicate::NE,
-            check_ovf,
-            check_ovf.get_type().const_zero(),
-            "",
-        )
+        let check_ovf = bin
+            .builder
+            .build_right_shift(
+                res.into_int_value(),
+                mul_ty.const_int((bits).into(), false),
+                false,
+                "",
+            )
+            .unwrap();
+        bin.builder
+            .build_int_compare(
+                IntPredicate::NE,
+                check_ovf,
+                check_ovf.get_type().const_zero(),
+                "",
+            )
+            .unwrap()
     } else {
         // If no size extension took place, there is no overflow in most significant N bits
         bin.context.bool_type().const_zero()
@@ -109,15 +134,20 @@ fn signed_ovf_detect<'a, T: TargetRuntime<'a> + ?Sized>(
 
     let negate_result = bin
         .builder
-        .build_xor(left_negative, right_negative, "negate_result");
+        .build_xor(left_negative, right_negative, "negate_result")
+        .unwrap();
 
-    let res = bin.builder.build_select(
-        negate_result,
-        bin.builder
-            .build_int_neg(res.into_int_value(), "unsigned_res"),
-        res.into_int_value(),
-        "res",
-    );
+    let res = bin
+        .builder
+        .build_select(
+            negate_result,
+            bin.builder
+                .build_int_neg(res.into_int_value(), "unsigned_res")
+                .unwrap(),
+            res.into_int_value(),
+            "res",
+        )
+        .unwrap();
 
     let error_block = bin.context.append_basic_block(function, "error");
     let return_block = bin.context.append_basic_block(function, "return_block");
@@ -133,51 +163,78 @@ fn signed_ovf_detect<'a, T: TargetRuntime<'a> + ?Sized>(
         extract_sign_bit(
             bin,
             bin.builder
-                .build_int_truncate(res.into_int_value(), left.get_type(), ""),
+                .build_int_truncate(res.into_int_value(), left.get_type(), "")
+                .unwrap(),
             left.get_type(),
         )
     };
 
-    let value_fits_n_bits = bin.builder.build_not(
-        bin.builder.build_or(
-            return_val
-                .try_as_basic_value()
-                .left()
-                .unwrap()
-                .into_int_value(),
-            ovf_any_type,
+    let value_fits_n_bits = bin
+        .builder
+        .build_not(
+            bin.builder
+                .build_or(
+                    return_val
+                        .unwrap()
+                        .try_as_basic_value()
+                        .left()
+                        .unwrap()
+                        .into_int_value(),
+                    ovf_any_type,
+                    "",
+                )
+                .unwrap(),
             "",
-        ),
-        "",
-    );
+        )
+        .unwrap();
 
-    let left_is_zero =
-        bin.builder
-            .build_int_compare(IntPredicate::EQ, left, left.get_type().const_zero(), "");
-    let right_is_zero =
-        bin.builder
-            .build_int_compare(IntPredicate::EQ, right, right.get_type().const_zero(), "");
+    let left_is_zero = bin
+        .builder
+        .build_int_compare(IntPredicate::EQ, left, left.get_type().const_zero(), "")
+        .unwrap();
+    let right_is_zero = bin
+        .builder
+        .build_int_compare(IntPredicate::EQ, right, right.get_type().const_zero(), "")
+        .unwrap();
 
     // If one of the operands is zero
-    let mul_by_zero = bin.builder.build_or(left_is_zero, right_is_zero, "");
+    let mul_by_zero = bin
+        .builder
+        .build_or(left_is_zero, right_is_zero, "")
+        .unwrap();
 
     // Will resolve to one if signs are differnet
-    let different_signs = bin.builder.build_xor(left_sign_bit, right_sign_bit, "");
+    let different_signs = bin
+        .builder
+        .build_xor(left_sign_bit, right_sign_bit, "")
+        .unwrap();
 
     let not_ok_operation = bin
         .builder
-        .build_not(bin.builder.build_xor(different_signs, res_sign_bit, ""), "");
+        .build_not(
+            bin.builder
+                .build_xor(different_signs, res_sign_bit, "")
+                .unwrap(),
+            "",
+        )
+        .unwrap();
 
     // Here, we disregard the last rule mentioned above if there is a multiplication by zero.
-    bin.builder.build_conditional_branch(
-        bin.builder.build_and(
-            bin.builder.build_or(not_ok_operation, mul_by_zero, ""),
-            value_fits_n_bits,
-            "",
-        ),
-        return_block,
-        error_block,
-    );
+    bin.builder
+        .build_conditional_branch(
+            bin.builder
+                .build_and(
+                    bin.builder
+                        .build_or(not_ok_operation, mul_by_zero, "")
+                        .unwrap(),
+                    value_fits_n_bits,
+                    "",
+                )
+                .unwrap(),
+            return_block,
+            error_block,
+        )
+        .unwrap();
 
     bin.builder.position_at_end(error_block);
 
@@ -189,6 +246,7 @@ fn signed_ovf_detect<'a, T: TargetRuntime<'a> + ?Sized>(
 
     bin.builder
         .build_int_truncate(res.into_int_value(), left.get_type(), "")
+        .unwrap()
 }
 
 /// Call void __mul32 and return the result.
@@ -201,24 +259,27 @@ fn call_mul32_without_ovf<'a>(
     mul_type: IntType<'a>,
     res_type: IntType<'a>,
 ) -> IntValue<'a> {
-    bin.builder.build_call(
-        bin.module.get_function("__mul32").unwrap(),
-        &[
-            l.into(),
-            r.into(),
-            o.into(),
-            bin.context
-                .i32_type()
-                .const_int(mul_bits as u64 / 32, false)
-                .into(),
-        ],
-        "",
-    );
+    bin.builder
+        .build_call(
+            bin.module.get_function("__mul32").unwrap(),
+            &[
+                l.into(),
+                r.into(),
+                o.into(),
+                bin.context
+                    .i32_type()
+                    .const_int(mul_bits as u64 / 32, false)
+                    .into(),
+            ],
+            "",
+        )
+        .unwrap();
 
-    let res = bin.builder.build_load(mul_type, o, "mul");
+    let res = bin.builder.build_load(mul_type, o, "mul").unwrap();
 
     bin.builder
         .build_int_truncate(res.into_int_value(), res_type, "")
+        .unwrap()
 }
 
 /// Utility function to extract the sign bit of an IntValue
@@ -231,9 +292,11 @@ fn extract_sign_bit<'a>(
     let val_to_shift = int_type.const_int(n_bits_to_shift as u64, false);
     let shifted = bin
         .builder
-        .build_right_shift(operand, val_to_shift, false, "");
+        .build_right_shift(operand, val_to_shift, false, "")
+        .unwrap();
     bin.builder
         .build_int_truncate(shifted, bin.context.bool_type(), "")
+        .unwrap()
 }
 
 /// Emit a multiply for any width with or without overflow checking
@@ -262,8 +325,8 @@ pub(super) fn multiply<'a, T: TargetRuntime<'a> + ?Sized>(
         let o = bin.build_alloca(function, mul_ty, "");
 
         if mul_bits == bits {
-            bin.builder.build_store(l, left);
-            bin.builder.build_store(r, right);
+            bin.builder.build_store(l, left).unwrap();
+            bin.builder.build_store(r, right).unwrap();
         }
         // LLVM-IR can handle multiplication of sizes up to 64 bits. If the size is larger, we need to implement our own mutliplication function.
         // We divide the operands into sizes of 32 bits (check __mul32 in stdlib/bigint.c documentation).
@@ -273,9 +336,14 @@ pub(super) fn multiply<'a, T: TargetRuntime<'a> + ?Sized>(
         // In mul with overflow however, it is needed so that overflow can be detected if the most significant bits of the result are not zeros.
         else {
             bin.builder
-                .build_store(l, bin.builder.build_int_z_extend(left, mul_ty, ""));
+                .build_store(l, bin.builder.build_int_z_extend(left, mul_ty, "").unwrap())
+                .unwrap();
             bin.builder
-                .build_store(r, bin.builder.build_int_z_extend(right, mul_ty, ""));
+                .build_store(
+                    r,
+                    bin.builder.build_int_z_extend(right, mul_ty, "").unwrap(),
+                )
+                .unwrap();
         }
 
         if !unchecked {
@@ -290,21 +358,24 @@ pub(super) fn multiply<'a, T: TargetRuntime<'a> + ?Sized>(
             // If that is not the case, some extra work has to be done. We have to check the extended bits for any set bits. If there is any, an overflow occured.
             // For example, if we have uint72, it will be extended to uint96. __mul32 with ovf will raise an ovf flag if the result overflows 96 bits, not 72.
             // We account for that by checking the extended leftmost bits. In the example mentioned, they will be 96-72=24 bits.
-            let return_val = bin.builder.build_call(
-                bin.module.get_function("__mul32_with_builtin_ovf").unwrap(),
-                &[
-                    l.into(),
-                    r.into(),
-                    o.into(),
-                    bin.context
-                        .i32_type()
-                        .const_int(mul_bits as u64 / 32, false)
-                        .into(),
-                ],
-                "ovf",
-            );
-
-            let res = bin.builder.build_load(mul_ty, o, "mul");
+            let return_val = bin
+                .builder
+                .build_call(
+                    bin.module.get_function("__mul32_with_builtin_ovf").unwrap(),
+                    &[
+                        l.into(),
+                        r.into(),
+                        o.into(),
+                        bin.context
+                            .i32_type()
+                            .const_int(mul_bits as u64 / 32, false)
+                            .into(),
+                    ],
+                    "ovf",
+                )
+                .unwrap();
+
+            let res = bin.builder.build_load(mul_ty, o, "mul").unwrap();
 
             let error_block = bin.context.append_basic_block(function, "error");
             let return_block = bin.context.append_basic_block(function, "return_block");
@@ -312,18 +383,23 @@ pub(super) fn multiply<'a, T: TargetRuntime<'a> + ?Sized>(
             // If the operands were extended to nearest 32 bit size, check the most significant N bits, where N equals bit width after extension minus original bit width.
             let ovf_any_type = if mul_bits != bits {
                 // If there are any set bits, then there is an overflow.
-                let check_ovf = bin.builder.build_right_shift(
-                    res.into_int_value(),
-                    mul_ty.const_int((bits).into(), false),
-                    false,
-                    "",
-                );
-                bin.builder.build_int_compare(
-                    IntPredicate::NE,
-                    check_ovf,
-                    check_ovf.get_type().const_zero(),
-                    "",
-                )
+                let check_ovf = bin
+                    .builder
+                    .build_right_shift(
+                        res.into_int_value(),
+                        mul_ty.const_int((bits).into(), false),
+                        false,
+                        "",
+                    )
+                    .unwrap();
+                bin.builder
+                    .build_int_compare(
+                        IntPredicate::NE,
+                        check_ovf,
+                        check_ovf.get_type().const_zero(),
+                        "",
+                    )
+                    .unwrap()
             } else {
                 // If no size extension took place, there is no overflow in most significant N bits
                 bin.context.bool_type().const_zero()
@@ -333,23 +409,29 @@ pub(super) fn multiply<'a, T: TargetRuntime<'a> + ?Sized>(
             // For example: If we have uint72, it will be extended to uint96. We only checked the most significant 24 bits for overflow, which can happen up to 72*2=144 bits.
             // bool __mul32_with_builtin_ovf takes care of overflowing bits beyond 96.
             // What is left now is to or these two ovf flags, and check if any one of them is set. If so, an overflow occured.
-            let lowbit = bin.builder.build_int_truncate(
-                bin.builder.build_or(
-                    ovf_any_type,
-                    return_val
-                        .try_as_basic_value()
-                        .left()
-                        .unwrap()
-                        .into_int_value(),
-                    "",
-                ),
-                bin.context.bool_type(),
-                "bit",
-            );
+            let lowbit = bin
+                .builder
+                .build_int_truncate(
+                    bin.builder
+                        .build_or(
+                            ovf_any_type,
+                            return_val
+                                .try_as_basic_value()
+                                .left()
+                                .unwrap()
+                                .into_int_value(),
+                            "",
+                        )
+                        .unwrap(),
+                    bin.context.bool_type(),
+                    "bit",
+                )
+                .unwrap();
 
             // If ovf, raise an error, else return the result.
             bin.builder
-                .build_conditional_branch(lowbit, error_block, return_block);
+                .build_conditional_branch(lowbit, error_block, return_block)
+                .unwrap();
 
             bin.builder.position_at_end(error_block);
 
@@ -362,6 +444,7 @@ pub(super) fn multiply<'a, T: TargetRuntime<'a> + ?Sized>(
 
             bin.builder
                 .build_int_truncate(res.into_int_value(), left.get_type(), "")
+                .unwrap()
         } else {
             return call_mul32_without_ovf(bin, l, r, o, mul_bits, mul_ty, left.get_type());
         }
@@ -378,7 +461,7 @@ pub(super) fn multiply<'a, T: TargetRuntime<'a> + ?Sized>(
             loc,
         )
     } else {
-        bin.builder.build_int_mul(left, right, "")
+        bin.builder.build_int_mul(left, right, "").unwrap()
     }
 }
 
@@ -440,26 +523,30 @@ pub(super) fn power<'a, T: TargetRuntime<'a> + ?Sized>(
 
     bin.builder.position_at_end(entry);
 
-    bin.builder.build_unconditional_branch(loop_block);
+    bin.builder.build_unconditional_branch(loop_block).unwrap();
 
     bin.builder.position_at_end(loop_block);
-    let base = bin.builder.build_phi(ty, "base");
+    let base = bin.builder.build_phi(ty, "base").unwrap();
     base.add_incoming(&[(&function.get_nth_param(0).unwrap(), entry)]);
 
-    let exp = bin.builder.build_phi(ty, "exp");
+    let exp = bin.builder.build_phi(ty, "exp").unwrap();
     exp.add_incoming(&[(&function.get_nth_param(1).unwrap(), entry)]);
 
-    let result = bin.builder.build_phi(ty, "result");
+    let result = bin.builder.build_phi(ty, "result").unwrap();
     result.add_incoming(&[(&ty.const_int(1, false), entry)]);
 
-    let lowbit = bin.builder.build_int_truncate(
-        exp.as_basic_value().into_int_value(),
-        bin.context.bool_type(),
-        "bit",
-    );
+    let lowbit = bin
+        .builder
+        .build_int_truncate(
+            exp.as_basic_value().into_int_value(),
+            bin.context.bool_type(),
+            "bit",
+        )
+        .unwrap();
 
     bin.builder
-        .build_conditional_branch(lowbit, multiply_block, nomultiply);
+        .build_conditional_branch(lowbit, multiply_block, nomultiply)
+        .unwrap();
 
     bin.builder.position_at_end(multiply_block);
 
@@ -477,35 +564,44 @@ pub(super) fn power<'a, T: TargetRuntime<'a> + ?Sized>(
 
     let multiply_block = bin.builder.get_insert_block().unwrap();
 
-    bin.builder.build_unconditional_branch(nomultiply);
+    bin.builder.build_unconditional_branch(nomultiply).unwrap();
     bin.builder.position_at_end(nomultiply);
 
-    let result3 = bin.builder.build_phi(ty, "result");
+    let result3 = bin.builder.build_phi(ty, "result").unwrap();
     result3.add_incoming(&[
         (&result.as_basic_value(), loop_block),
         (&result2, multiply_block),
     ]);
 
-    let exp2 = bin.builder.build_right_shift(
-        exp.as_basic_value().into_int_value(),
-        ty.const_int(1, false),
-        false,
-        "exp",
-    );
+    let exp2 = bin
+        .builder
+        .build_right_shift(
+            exp.as_basic_value().into_int_value(),
+            ty.const_int(1, false),
+            false,
+            "exp",
+        )
+        .unwrap();
     let zero = bin
         .builder
-        .build_int_compare(IntPredicate::EQ, exp2, ty.const_zero(), "zero");
+        .build_int_compare(IntPredicate::EQ, exp2, ty.const_zero(), "zero")
+        .unwrap();
 
-    bin.builder.build_conditional_branch(zero, done, notdone);
+    bin.builder
+        .build_conditional_branch(zero, done, notdone)
+        .unwrap();
     bin.builder.position_at_end(done);
 
     // If successful operation, load the result in the output pointer then return zero.
-    bin.builder.build_store(
-        function.get_nth_param(2).unwrap().into_pointer_value(),
-        result3.as_basic_value(),
-    );
     bin.builder
-        .build_return(Some(&bin.context.i64_type().const_zero()));
+        .build_store(
+            function.get_nth_param(2).unwrap().into_pointer_value(),
+            result3.as_basic_value(),
+        )
+        .unwrap();
+    bin.builder
+        .build_return(Some(&bin.context.i64_type().const_zero()))
+        .unwrap();
 
     bin.builder.position_at_end(notdone);
 
@@ -527,7 +623,7 @@ pub(super) fn power<'a, T: TargetRuntime<'a> + ?Sized>(
     result.add_incoming(&[(&result3.as_basic_value(), notdone)]);
     exp.add_incoming(&[(&exp2, notdone)]);
 
-    bin.builder.build_unconditional_branch(loop_block);
+    bin.builder.build_unconditional_branch(loop_block).unwrap();
 
     bin.builder.position_at_end(pos);
 
@@ -558,6 +654,7 @@ pub(super) fn build_binary_op_with_overflow_check<'a, T: TargetRuntime<'a> + ?Si
     let op_res = bin
         .builder
         .build_call(binop, &[left.into(), right.into()], "res")
+        .unwrap()
         .try_as_basic_value()
         .left()
         .unwrap()
@@ -573,7 +670,8 @@ pub(super) fn build_binary_op_with_overflow_check<'a, T: TargetRuntime<'a> + ?Si
     let error_block = bin.context.append_basic_block(function, "error");
 
     bin.builder
-        .build_conditional_branch(overflow, error_block, success_block);
+        .build_conditional_branch(overflow, error_block, success_block)
+        .unwrap();
 
     bin.builder.position_at_end(error_block);
 

+ 44 - 30
src/emit/polkadot/mod.rs

@@ -40,11 +40,13 @@ impl PolkadotTarget {
             None,
         );
 
-        binary.vector_init_empty = binary.builder.build_int_to_ptr(
-            binary.context.i32_type().const_all_ones(),
-            binary.context.i8_type().ptr_type(AddressSpace::default()),
-            "empty_vector",
-        );
+        let ptr = binary.context.i8_type().ptr_type(AddressSpace::default());
+
+        binary.vector_init_empty = binary
+            .context
+            .i32_type()
+            .const_all_ones()
+            .const_to_pointer(ptr);
         binary.set_early_value_aborts(contract, ns);
 
         let scratch_len = binary.module.add_global(
@@ -137,41 +139,51 @@ impl PolkadotTarget {
         // init our heap
         binary
             .builder
-            .build_call(binary.module.get_function("__init_heap").unwrap(), &[], "");
+            .build_call(binary.module.get_function("__init_heap").unwrap(), &[], "")
+            .unwrap();
 
         // Call the storage initializers on deploy
         if let Some(initializer) = storage_initializer {
-            binary.builder.build_call(initializer, &[], "");
+            binary.builder.build_call(initializer, &[], "").unwrap();
         }
 
         let scratch_buf = binary.scratch.unwrap().as_pointer_value();
         let scratch_len = binary.scratch_len.unwrap().as_pointer_value();
 
         // copy arguments from input buffer
-        binary.builder.build_store(
-            scratch_len,
-            binary
-                .context
-                .i32_type()
-                .const_int(SCRATCH_SIZE as u64, false),
-        );
-
-        binary.builder.build_call(
-            binary.module.get_function("input").unwrap(),
-            &[scratch_buf.into(), scratch_len.into()],
-            "",
-        );
+        binary
+            .builder
+            .build_store(
+                scratch_len,
+                binary
+                    .context
+                    .i32_type()
+                    .const_int(SCRATCH_SIZE as u64, false),
+            )
+            .unwrap();
 
-        let args_length =
-            binary
-                .builder
-                .build_load(binary.context.i32_type(), scratch_len, "input_len");
+        binary
+            .builder
+            .build_call(
+                binary.module.get_function("input").unwrap(),
+                &[scratch_buf.into(), scratch_len.into()],
+                "",
+            )
+            .unwrap();
+
+        let args_length = binary
+            .builder
+            .build_load(binary.context.i32_type(), scratch_len, "input_len")
+            .unwrap();
 
         // store the length in case someone wants it via msg.data
-        binary.builder.build_store(
-            binary.calldata_len.as_pointer_value(),
-            args_length.into_int_value(),
-        );
+        binary
+            .builder
+            .build_store(
+                binary.calldata_len.as_pointer_value(),
+                args_length.into_int_value(),
+            )
+            .unwrap();
 
         (scratch_buf, args_length.into_int_value())
     }
@@ -296,8 +308,10 @@ impl PolkadotTarget {
             .unwrap_or(DispatchType::Call)
             .to_string();
         let cfg = bin.module.get_function(dispatch_cfg_name).unwrap();
-        bin.builder.build_call(cfg, &args, dispatch_cfg_name);
+        bin.builder
+            .build_call(cfg, &args, dispatch_cfg_name)
+            .unwrap();
 
-        bin.builder.build_unreachable();
+        bin.builder.build_unreachable().unwrap();
     }
 }

+ 246 - 184
src/emit/polkadot/storage.rs

@@ -55,7 +55,8 @@ impl StorageSlot for PolkadotTarget {
 
         binary
             .builder
-            .build_store(scratch_len, i32_const!(ns.address_length as u64));
+            .build_store(scratch_len, i32_const!(ns.address_length as u64))
+            .unwrap();
 
         let exists = seal_get_storage!(
             slot.into(),
@@ -64,12 +65,10 @@ impl StorageSlot for PolkadotTarget {
             scratch_len.into()
         );
 
-        let exists_is_zero = binary.builder.build_int_compare(
-            IntPredicate::EQ,
-            exists,
-            i32_zero!(),
-            "storage_exists",
-        );
+        let exists_is_zero = binary
+            .builder
+            .build_int_compare(IntPredicate::EQ, exists, i32_zero!(), "storage_exists")
+            .unwrap();
 
         binary
             .builder
@@ -78,10 +77,12 @@ impl StorageSlot for PolkadotTarget {
                 binary
                     .builder
                     .build_load(binary.address_type(ns), scratch_buf, "address")
+                    .unwrap()
                     .into_array_value(),
                 binary.address_type(ns).const_zero(),
                 "retrieved_address",
             )
+            .unwrap()
             .into_array_value()
     }
 
@@ -112,11 +113,14 @@ impl StorageSlot for PolkadotTarget {
                 if let Some(ArrayLength::Fixed(d)) = dim.last() {
                     let llvm_ty = bin.llvm_type(ty.deref_any(), ns);
                     // LLVMSizeOf() produces an i64
-                    let size = bin.builder.build_int_truncate(
-                        llvm_ty.size_of().unwrap(),
-                        bin.context.i32_type(),
-                        "size_of",
-                    );
+                    let size = bin
+                        .builder
+                        .build_int_truncate(
+                            llvm_ty.size_of().unwrap(),
+                            bin.context.i32_type(),
+                            "size_of",
+                        )
+                        .unwrap();
 
                     let ty = ty.array_deref();
                     let new = call!("__malloc", &[size.into()])
@@ -132,12 +136,9 @@ impl StorageSlot for PolkadotTarget {
                         slot,
                         |index: IntValue<'a>, slot: &mut IntValue<'a>| {
                             let elem = unsafe {
-                                bin.builder.build_gep(
-                                    llvm_ty,
-                                    new,
-                                    &[i32_zero!(), index],
-                                    "index_access",
-                                )
+                                bin.builder
+                                    .build_gep(llvm_ty, new, &[i32_zero!(), index], "index_access")
+                                    .unwrap()
                             };
 
                             let val =
@@ -147,11 +148,12 @@ impl StorageSlot for PolkadotTarget {
                                 let load_ty = bin.llvm_type(ty.deref_any(), ns);
                                 bin.builder
                                     .build_load(load_ty, val.into_pointer_value(), "elem")
+                                    .unwrap()
                             } else {
                                 val
                             };
 
-                            bin.builder.build_store(elem, val);
+                            bin.builder.build_store(elem, val).unwrap();
                         },
                     );
 
@@ -160,25 +162,34 @@ impl StorageSlot for PolkadotTarget {
                     // iterate over dynamic array
                     let slot_ty = Type::Uint(256);
 
-                    let size = bin.builder.build_int_truncate(
-                        self.storage_load_slot(bin, &slot_ty, slot, slot_ptr, function, ns)
-                            .into_int_value(),
-                        bin.context.i32_type(),
-                        "size",
-                    );
+                    let size = bin
+                        .builder
+                        .build_int_truncate(
+                            self.storage_load_slot(bin, &slot_ty, slot, slot_ptr, function, ns)
+                                .into_int_value(),
+                            bin.context.i32_type(),
+                            "size",
+                        )
+                        .unwrap();
 
                     let llvm_elem_ty = bin.llvm_field_ty(elem_ty, ns);
 
-                    let elem_size = bin.builder.build_int_truncate(
-                        llvm_elem_ty.size_of().unwrap(),
-                        bin.context.i32_type(),
-                        "size_of",
-                    );
-                    let init = bin.builder.build_int_to_ptr(
-                        bin.context.i32_type().const_all_ones(),
-                        bin.context.i8_type().ptr_type(AddressSpace::default()),
-                        "invalid",
-                    );
+                    let elem_size = bin
+                        .builder
+                        .build_int_truncate(
+                            llvm_elem_ty.size_of().unwrap(),
+                            bin.context.i32_type(),
+                            "size_of",
+                        )
+                        .unwrap();
+                    let init = bin
+                        .builder
+                        .build_int_to_ptr(
+                            bin.context.i32_type().const_all_ones(),
+                            bin.context.i8_type().ptr_type(AddressSpace::default()),
+                            "invalid",
+                        )
+                        .unwrap();
 
                     let dest = call!("vector_new", &[size.into(), elem_size.into(), init.into()])
                         .try_as_basic_value()
@@ -201,6 +212,7 @@ impl StorageSlot for PolkadotTarget {
                     let mut elem_slot = bin
                         .builder
                         .build_load(slot.get_type(), slot_ptr, "elem_slot")
+                        .unwrap()
                         .into_int_value();
 
                     bin.emit_loop_cond_first_with_int(
@@ -215,16 +227,18 @@ impl StorageSlot for PolkadotTarget {
                                 self.storage_load_slot(bin, elem_ty, slot, slot_ptr, function, ns);
 
                             let entry = if elem_ty.deref_memory().is_fixed_reference_type(ns) {
-                                bin.builder.build_load(
-                                    bin.llvm_type(elem_ty.deref_memory(), ns),
-                                    entry.into_pointer_value(),
-                                    "elem",
-                                )
+                                bin.builder
+                                    .build_load(
+                                        bin.llvm_type(elem_ty.deref_memory(), ns),
+                                        entry.into_pointer_value(),
+                                        "elem",
+                                    )
+                                    .unwrap()
                             } else {
                                 entry
                             };
 
-                            bin.builder.build_store(elem, entry);
+                            bin.builder.build_store(elem, entry).unwrap();
                         },
                     );
                     // load
@@ -234,11 +248,14 @@ impl StorageSlot for PolkadotTarget {
             Type::Struct(str_ty) => {
                 let llvm_ty = bin.llvm_type(ty.deref_any(), ns);
                 // LLVMSizeOf() produces an i64
-                let size = bin.builder.build_int_truncate(
-                    llvm_ty.size_of().unwrap(),
-                    bin.context.i32_type(),
-                    "size_of",
-                );
+                let size = bin
+                    .builder
+                    .build_int_truncate(
+                        llvm_ty.size_of().unwrap(),
+                        bin.context.i32_type(),
+                        "size_of",
+                    )
+                    .unwrap();
 
                 let new = call!("__malloc", &[size.into()])
                     .try_as_basic_value()
@@ -250,45 +267,44 @@ impl StorageSlot for PolkadotTarget {
                     let val = self.storage_load_slot(bin, &field.ty, slot, slot_ptr, function, ns);
 
                     let elem = unsafe {
-                        bin.builder.build_gep(
-                            llvm_ty,
-                            new,
-                            &[i32_zero!(), i32_const!(i as u64)],
-                            field.name_as_str(),
-                        )
+                        bin.builder
+                            .build_gep(
+                                llvm_ty,
+                                new,
+                                &[i32_zero!(), i32_const!(i as u64)],
+                                field.name_as_str(),
+                            )
+                            .unwrap()
                     };
 
                     let val = if field.ty.deref_memory().is_fixed_reference_type(ns) {
                         let load_ty = bin.llvm_type(field.ty.deref_memory(), ns);
-                        bin.builder.build_load(
-                            load_ty,
-                            val.into_pointer_value(),
-                            field.name_as_str(),
-                        )
+                        bin.builder
+                            .build_load(load_ty, val.into_pointer_value(), field.name_as_str())
+                            .unwrap()
                     } else {
                         val
                     };
 
-                    bin.builder.build_store(elem, val);
+                    bin.builder.build_store(elem, val).unwrap();
                 }
 
                 new.into()
             }
             Type::String | Type::DynamicBytes => {
-                bin.builder.build_store(slot_ptr, *slot);
+                bin.builder.build_store(slot_ptr, *slot).unwrap();
 
                 let ret = self.get_storage_string(bin, function, slot_ptr);
 
-                *slot = bin.builder.build_int_add(
-                    *slot,
-                    bin.number_literal(256, &BigInt::one(), ns),
-                    "string",
-                );
+                *slot = bin
+                    .builder
+                    .build_int_add(*slot, bin.number_literal(256, &BigInt::one(), ns), "string")
+                    .unwrap();
 
                 ret.into()
             }
             Type::InternalFunction { .. } => {
-                bin.builder.build_store(slot_ptr, *slot);
+                bin.builder.build_store(slot_ptr, *slot).unwrap();
 
                 let ptr_ty = bin
                     .context
@@ -303,36 +319,35 @@ impl StorageSlot for PolkadotTarget {
                             .ptr_type(AddressSpace::default()),
                         "",
                     )
+                    .unwrap()
                     .into()
             }
             Type::ExternalFunction { .. } => {
-                bin.builder.build_store(slot_ptr, *slot);
+                bin.builder.build_store(slot_ptr, *slot).unwrap();
 
                 let ret = self.get_storage_extfunc(bin, function, slot_ptr, ns);
 
-                *slot = bin.builder.build_int_add(
-                    *slot,
-                    bin.number_literal(256, &BigInt::one(), ns),
-                    "string",
-                );
+                *slot = bin
+                    .builder
+                    .build_int_add(*slot, bin.number_literal(256, &BigInt::one(), ns), "string")
+                    .unwrap();
 
                 ret.into()
             }
             Type::Address(_) | Type::Contract(_) => {
-                bin.builder.build_store(slot_ptr, *slot);
+                bin.builder.build_store(slot_ptr, *slot).unwrap();
 
                 let ret = self.get_storage_address(bin, slot_ptr, ns);
 
-                *slot = bin.builder.build_int_add(
-                    *slot,
-                    bin.number_literal(256, &BigInt::one(), ns),
-                    "string",
-                );
+                *slot = bin
+                    .builder
+                    .build_int_add(*slot, bin.number_literal(256, &BigInt::one(), ns), "string")
+                    .unwrap();
 
                 ret.into()
             }
             _ => {
-                bin.builder.build_store(slot_ptr, *slot);
+                bin.builder.build_store(slot_ptr, *slot).unwrap();
 
                 let ret = self.get_storage_int(
                     bin,
@@ -341,11 +356,10 @@ impl StorageSlot for PolkadotTarget {
                     bin.llvm_type(ty.deref_any(), ns).into_int_type(),
                 );
 
-                *slot = bin.builder.build_int_add(
-                    *slot,
-                    bin.number_literal(256, &BigInt::one(), ns),
-                    "int",
-                );
+                *slot = bin
+                    .builder
+                    .build_int_add(*slot, bin.number_literal(256, &BigInt::one(), ns), "int")
+                    .unwrap();
 
                 ret.into()
             }
@@ -372,12 +386,14 @@ impl StorageSlot for PolkadotTarget {
                         slot,
                         |index: IntValue<'a>, slot: &mut IntValue<'a>| {
                             let mut elem = unsafe {
-                                bin.builder.build_gep(
-                                    bin.llvm_type(ty.deref_any(), ns),
-                                    dest.into_pointer_value(),
-                                    &[bin.context.i32_type().const_zero(), index],
-                                    "index_access",
-                                )
+                                bin.builder
+                                    .build_gep(
+                                        bin.llvm_type(ty.deref_any(), ns),
+                                        dest.into_pointer_value(),
+                                        &[bin.context.i32_type().const_zero(), index],
+                                        "index_access",
+                                    )
+                                    .unwrap()
                             };
 
                             if elem_ty.is_reference_type(ns)
@@ -388,6 +404,7 @@ impl StorageSlot for PolkadotTarget {
                                 elem = bin
                                     .builder
                                     .build_load(load_ty, elem, "")
+                                    .unwrap()
                                     .into_pointer_value();
                             }
 
@@ -402,11 +419,14 @@ impl StorageSlot for PolkadotTarget {
                             );
 
                             if !elem_ty.is_reference_type(ns) {
-                                *slot = bin.builder.build_int_add(
-                                    *slot,
-                                    bin.number_literal(256, &elem_ty.storage_slots(ns), ns),
-                                    "",
-                                );
+                                *slot = bin
+                                    .builder
+                                    .build_int_add(
+                                        *slot,
+                                        bin.number_literal(256, &elem_ty.storage_slots(ns), ns),
+                                        "",
+                                    )
+                                    .unwrap();
                             }
                         },
                     );
@@ -418,34 +438,45 @@ impl StorageSlot for PolkadotTarget {
 
                     // details about our array elements
                     let llvm_elem_ty = bin.llvm_field_ty(elem_ty, ns);
-                    let elem_size = bin.builder.build_int_truncate(
-                        llvm_elem_ty.size_of().unwrap(),
-                        bin.context.i32_type(),
-                        "size_of",
-                    );
+                    let elem_size = bin
+                        .builder
+                        .build_int_truncate(
+                            llvm_elem_ty.size_of().unwrap(),
+                            bin.context.i32_type(),
+                            "size_of",
+                        )
+                        .unwrap();
 
                     // the previous length of the storage array
                     // we need this to clear any elements
-                    let previous_size = bin.builder.build_int_truncate(
-                        self.storage_load_slot(bin, &slot_ty, slot, slot_ptr, function, ns)
-                            .into_int_value(),
-                        bin.context.i32_type(),
-                        "previous_size",
-                    );
+                    let previous_size = bin
+                        .builder
+                        .build_int_truncate(
+                            self.storage_load_slot(bin, &slot_ty, slot, slot_ptr, function, ns)
+                                .into_int_value(),
+                            bin.context.i32_type(),
+                            "previous_size",
+                        )
+                        .unwrap();
 
                     let new_slot = bin
                         .builder
-                        .build_alloca(bin.llvm_type(&slot_ty, ns).into_int_type(), "new");
+                        .build_alloca(bin.llvm_type(&slot_ty, ns).into_int_type(), "new")
+                        .unwrap();
 
                     // set new length
-                    bin.builder.build_store(
-                        new_slot,
-                        bin.builder.build_int_z_extend(
-                            len,
-                            bin.llvm_type(&slot_ty, ns).into_int_type(),
-                            "",
-                        ),
-                    );
+                    bin.builder
+                        .build_store(
+                            new_slot,
+                            bin.builder
+                                .build_int_z_extend(
+                                    len,
+                                    bin.llvm_type(&slot_ty, ns).into_int_type(),
+                                    "",
+                                )
+                                .unwrap(),
+                        )
+                        .unwrap();
 
                     self.set_storage(bin, slot_ptr, new_slot, bin.llvm_type(&slot_ty, ns));
 
@@ -466,6 +497,7 @@ impl StorageSlot for PolkadotTarget {
                             new_slot,
                             "elem_slot",
                         )
+                        .unwrap()
                         .into_int_value();
 
                     bin.emit_loop_cond_first_with_int(
@@ -474,19 +506,21 @@ impl StorageSlot for PolkadotTarget {
                         len,
                         &mut elem_slot,
                         |elem_no: IntValue<'a>, slot: &mut IntValue<'a>| {
-                            let index = bin.builder.build_int_mul(elem_no, elem_size, "");
+                            let index = bin.builder.build_int_mul(elem_no, elem_size, "").unwrap();
 
                             let mut elem = unsafe {
-                                bin.builder.build_gep(
-                                    bin.llvm_type(ty.deref_any(), ns),
-                                    dest.into_pointer_value(),
-                                    &[
-                                        bin.context.i32_type().const_zero(),
-                                        bin.context.i32_type().const_int(2, false),
-                                        index,
-                                    ],
-                                    "data",
-                                )
+                                bin.builder
+                                    .build_gep(
+                                        bin.llvm_type(ty.deref_any(), ns),
+                                        dest.into_pointer_value(),
+                                        &[
+                                            bin.context.i32_type().const_zero(),
+                                            bin.context.i32_type().const_int(2, false),
+                                            index,
+                                        ],
+                                        "data",
+                                    )
+                                    .unwrap()
                             };
 
                             if elem_ty.is_reference_type(ns)
@@ -495,6 +529,7 @@ impl StorageSlot for PolkadotTarget {
                                 elem = bin
                                     .builder
                                     .build_load(llvm_elem_ty, elem, "")
+                                    .unwrap()
                                     .into_pointer_value();
                             }
 
@@ -509,11 +544,14 @@ impl StorageSlot for PolkadotTarget {
                             );
 
                             if !elem_ty.is_reference_type(ns) {
-                                *slot = bin.builder.build_int_add(
-                                    *slot,
-                                    bin.number_literal(256, &elem_ty.storage_slots(ns), ns),
-                                    "",
-                                );
+                                *slot = bin
+                                    .builder
+                                    .build_int_add(
+                                        *slot,
+                                        bin.number_literal(256, &elem_ty.storage_slots(ns), ns),
+                                        "",
+                                    )
+                                    .unwrap();
                             }
                         },
                     );
@@ -529,11 +567,14 @@ impl StorageSlot for PolkadotTarget {
                             self.storage_delete_slot(bin, elem_ty, slot, slot_ptr, function, ns);
 
                             if !elem_ty.is_reference_type(ns) {
-                                *slot = bin.builder.build_int_add(
-                                    *slot,
-                                    bin.number_literal(256, &elem_ty.storage_slots(ns), ns),
-                                    "",
-                                );
+                                *slot = bin
+                                    .builder
+                                    .build_int_add(
+                                        *slot,
+                                        bin.number_literal(256, &elem_ty.storage_slots(ns), ns),
+                                        "",
+                                    )
+                                    .unwrap();
                             }
                         },
                     );
@@ -542,15 +583,17 @@ impl StorageSlot for PolkadotTarget {
             Type::Struct(str_ty) => {
                 for (i, field) in str_ty.definition(ns).fields.iter().enumerate() {
                     let mut elem = unsafe {
-                        bin.builder.build_gep(
-                            bin.llvm_type(ty.deref_any(), ns),
-                            dest.into_pointer_value(),
-                            &[
-                                bin.context.i32_type().const_zero(),
-                                bin.context.i32_type().const_int(i as u64, false),
-                            ],
-                            field.name_as_str(),
-                        )
+                        bin.builder
+                            .build_gep(
+                                bin.llvm_type(ty.deref_any(), ns),
+                                dest.into_pointer_value(),
+                                &[
+                                    bin.context.i32_type().const_zero(),
+                                    bin.context.i32_type().const_int(i as u64, false),
+                                ],
+                                field.name_as_str(),
+                            )
+                            .unwrap()
                     };
 
                     if field.ty.is_reference_type(ns) && !field.ty.is_fixed_reference_type(ns) {
@@ -560,6 +603,7 @@ impl StorageSlot for PolkadotTarget {
                         elem = bin
                             .builder
                             .build_load(load_ty, elem, field.name_as_str())
+                            .unwrap()
                             .into_pointer_value();
                     }
 
@@ -576,21 +620,24 @@ impl StorageSlot for PolkadotTarget {
                     if !field.ty.is_reference_type(ns)
                         || matches!(field.ty, Type::String | Type::DynamicBytes)
                     {
-                        *slot = bin.builder.build_int_add(
-                            *slot,
-                            bin.number_literal(256, &field.ty.storage_slots(ns), ns),
-                            field.name_as_str(),
-                        );
+                        *slot = bin
+                            .builder
+                            .build_int_add(
+                                *slot,
+                                bin.number_literal(256, &field.ty.storage_slots(ns), ns),
+                                field.name_as_str(),
+                            )
+                            .unwrap();
                     }
                 }
             }
             Type::String | Type::DynamicBytes => {
-                bin.builder.build_store(slot_ptr, *slot);
+                bin.builder.build_store(slot_ptr, *slot).unwrap();
 
                 self.set_storage_string(bin, function, slot_ptr, dest);
             }
             Type::ExternalFunction { .. } => {
-                bin.builder.build_store(slot_ptr, *slot);
+                bin.builder.build_store(slot_ptr, *slot).unwrap();
 
                 self.set_storage_extfunc(
                     bin,
@@ -607,22 +654,22 @@ impl StorageSlot for PolkadotTarget {
 
                 let m = bin.build_alloca(function, ptr_ty, "");
 
-                bin.builder.build_store(
-                    m,
-                    bin.builder.build_ptr_to_int(
-                        dest.into_pointer_value(),
-                        ptr_ty,
-                        "function_pointer",
-                    ),
-                );
+                bin.builder
+                    .build_store(
+                        m,
+                        bin.builder
+                            .build_ptr_to_int(dest.into_pointer_value(), ptr_ty, "function_pointer")
+                            .unwrap(),
+                    )
+                    .unwrap();
 
-                bin.builder.build_store(slot_ptr, *slot);
+                bin.builder.build_store(slot_ptr, *slot).unwrap();
 
                 self.set_storage(bin, slot_ptr, m, ptr_ty.as_basic_type_enum());
             }
             Type::Address(_) | Type::Contract(_) => {
                 if dest.is_pointer_value() {
-                    bin.builder.build_store(slot_ptr, *slot);
+                    bin.builder.build_store(slot_ptr, *slot).unwrap();
 
                     self.set_storage(
                         bin,
@@ -631,11 +678,16 @@ impl StorageSlot for PolkadotTarget {
                         bin.llvm_type(ty, ns),
                     );
                 } else {
-                    let address = bin.builder.build_alloca(bin.address_type(ns), "address");
+                    let address = bin
+                        .builder
+                        .build_alloca(bin.address_type(ns), "address")
+                        .unwrap();
 
-                    bin.builder.build_store(address, dest.into_array_value());
+                    bin.builder
+                        .build_store(address, dest.into_array_value())
+                        .unwrap();
 
-                    bin.builder.build_store(slot_ptr, *slot);
+                    bin.builder.build_store(slot_ptr, *slot).unwrap();
 
                     self.set_storage(
                         bin,
@@ -646,11 +698,11 @@ impl StorageSlot for PolkadotTarget {
                 }
             }
             _ => {
-                bin.builder.build_store(slot_ptr, *slot);
+                bin.builder.build_store(slot_ptr, *slot).unwrap();
 
                 let dest = if dest.is_int_value() {
                     let m = bin.build_alloca(function, dest.get_type(), "");
-                    bin.builder.build_store(m, dest);
+                    bin.builder.build_store(m, dest).unwrap();
 
                     m
                 } else {
@@ -688,22 +740,25 @@ impl StorageSlot for PolkadotTarget {
                             self.storage_delete_slot(bin, &ty, slot, slot_ptr, function, ns);
 
                             if !ty.is_reference_type(ns) {
-                                *slot = bin.builder.build_int_add(
-                                    *slot,
-                                    bin.number_literal(256, &ty.storage_slots(ns), ns),
-                                    "",
-                                );
+                                *slot = bin
+                                    .builder
+                                    .build_int_add(
+                                        *slot,
+                                        bin.number_literal(256, &ty.storage_slots(ns), ns),
+                                        "",
+                                    )
+                                    .unwrap();
                             }
                         },
                     );
                 } else {
                     // dynamic length array.
                     // load length
-                    bin.builder.build_store(slot_ptr, *slot);
+                    bin.builder.build_store(slot_ptr, *slot).unwrap();
 
                     let slot_ty = bin.context.custom_width_int_type(256);
 
-                    let buf = bin.builder.build_alloca(slot_ty, "buf");
+                    let buf = bin.builder.build_alloca(slot_ty, "buf").unwrap();
 
                     let length = self.get_storage_int(bin, function, slot_ptr, slot_ty);
 
@@ -722,6 +777,7 @@ impl StorageSlot for PolkadotTarget {
                     let mut entry_slot = bin
                         .builder
                         .build_load(slot.get_type(), buf, "entry_slot")
+                        .unwrap()
                         .into_int_value();
 
                     // now loop from first slot to first slot + length
@@ -734,11 +790,14 @@ impl StorageSlot for PolkadotTarget {
                             self.storage_delete_slot(bin, &ty, slot, slot_ptr, function, ns);
 
                             if !ty.is_reference_type(ns) {
-                                *slot = bin.builder.build_int_add(
-                                    *slot,
-                                    bin.number_literal(256, &ty.storage_slots(ns), ns),
-                                    "",
-                                );
+                                *slot = bin
+                                    .builder
+                                    .build_int_add(
+                                        *slot,
+                                        bin.number_literal(256, &ty.storage_slots(ns), ns),
+                                        "",
+                                    )
+                                    .unwrap();
                             }
                         },
                     );
@@ -754,11 +813,14 @@ impl StorageSlot for PolkadotTarget {
                     if !field.ty.is_reference_type(ns)
                         || matches!(field.ty, Type::String | Type::DynamicBytes)
                     {
-                        *slot = bin.builder.build_int_add(
-                            *slot,
-                            bin.number_literal(256, &field.ty.storage_slots(ns), ns),
-                            field.name_as_str(),
-                        );
+                        *slot = bin
+                            .builder
+                            .build_int_add(
+                                *slot,
+                                bin.number_literal(256, &field.ty.storage_slots(ns), ns),
+                                field.name_as_str(),
+                            )
+                            .unwrap();
                     }
                 }
             }
@@ -766,7 +828,7 @@ impl StorageSlot for PolkadotTarget {
                 // nothing to do, step over it
             }
             _ => {
-                bin.builder.build_store(slot_ptr, *slot);
+                bin.builder.build_store(slot_ptr, *slot).unwrap();
 
                 self.storage_delete_single_slot(bin, slot_ptr);
             }

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 296 - 205
src/emit/polkadot/target.rs


파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 385 - 251
src/emit/solana/mod.rs


파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 317 - 185
src/emit/solana/target.rs


+ 181 - 117
src/emit/strings.rs

@@ -62,7 +62,7 @@ pub(super) fn format_string<'a, T: TargetRuntime<'a> + ?Sized>(
                     // will be hex encoded, so double
                     let len = bin.vector_len(val);
 
-                    bin.builder.build_int_add(len, len, "hex_len")
+                    bin.builder.build_int_add(len, len, "hex_len").unwrap()
                 }
                 Type::Uint(bits) if *spec == FormatArg::Hex => {
                     bin.context.i32_type().const_int(bits as u64 / 4 + 2, false)
@@ -91,7 +91,7 @@ pub(super) fn format_string<'a, T: TargetRuntime<'a> + ?Sized>(
             }
         };
 
-        length = bin.builder.build_int_add(length, len, "");
+        length = bin.builder.build_int_add(length, len, "").unwrap();
     }
 
     // allocate the string and
@@ -109,15 +109,18 @@ pub(super) fn format_string<'a, T: TargetRuntime<'a> + ?Sized>(
                 let s = bin.emit_global_string("format_arg", value, true);
                 let len = bin.context.i32_type().const_int(value.len() as u64, false);
 
-                bin.builder.build_call(
-                    bin.module.get_function("__memcpy").unwrap(),
-                    &[output.into(), s.into(), len.into()],
-                    "",
-                );
+                bin.builder
+                    .build_call(
+                        bin.module.get_function("__memcpy").unwrap(),
+                        &[output.into(), s.into(), len.into()],
+                        "",
+                    )
+                    .unwrap();
 
                 output = unsafe {
                     bin.builder
                         .build_gep(bin.context.i8_type(), output, &[len], "")
+                        .unwrap()
                 };
             }
         } else {
@@ -135,62 +138,77 @@ pub(super) fn format_string<'a, T: TargetRuntime<'a> + ?Sized>(
                             bin.context.i32_type().const_int(5, false),
                             "bool_length",
                         )
+                        .unwrap()
                         .into_int_value();
 
-                    let s = bin.builder.build_select(
-                        val.into_int_value(),
-                        bin.emit_global_string("bool_true", b"true", true),
-                        bin.emit_global_string("bool_false", b"false", true),
-                        "bool_value",
-                    );
+                    let s = bin
+                        .builder
+                        .build_select(
+                            val.into_int_value(),
+                            bin.emit_global_string("bool_true", b"true", true),
+                            bin.emit_global_string("bool_false", b"false", true),
+                            "bool_value",
+                        )
+                        .unwrap();
 
-                    bin.builder.build_call(
-                        bin.module.get_function("__memcpy").unwrap(),
-                        &[output.into(), s.into(), len.into()],
-                        "",
-                    );
+                    bin.builder
+                        .build_call(
+                            bin.module.get_function("__memcpy").unwrap(),
+                            &[output.into(), s.into(), len.into()],
+                            "",
+                        )
+                        .unwrap();
 
                     output = unsafe {
                         bin.builder
                             .build_gep(bin.context.i8_type(), output, &[len], "")
+                            .unwrap()
                     };
                 }
                 Type::String => {
                     let s = bin.vector_bytes(val);
                     let len = bin.vector_len(val);
 
-                    bin.builder.build_call(
-                        bin.module.get_function("__memcpy").unwrap(),
-                        &[output.into(), s.into(), len.into()],
-                        "",
-                    );
+                    bin.builder
+                        .build_call(
+                            bin.module.get_function("__memcpy").unwrap(),
+                            &[output.into(), s.into(), len.into()],
+                            "",
+                        )
+                        .unwrap();
 
                     output = unsafe {
                         bin.builder
                             .build_gep(bin.context.i8_type(), output, &[len], "")
+                            .unwrap()
                     };
                 }
                 Type::DynamicBytes => {
                     let s = bin.vector_bytes(val);
                     let len = bin.vector_len(val);
 
-                    bin.builder.build_call(
-                        bin.module.get_function("hex_encode").unwrap(),
-                        &[output.into(), s.into(), len.into()],
-                        "",
-                    );
+                    bin.builder
+                        .build_call(
+                            bin.module.get_function("hex_encode").unwrap(),
+                            &[output.into(), s.into(), len.into()],
+                            "",
+                        )
+                        .unwrap();
 
-                    let hex_len = bin.builder.build_int_add(len, len, "hex_len");
+                    let hex_len = bin.builder.build_int_add(len, len, "hex_len").unwrap();
 
                     output = unsafe {
                         bin.builder
                             .build_gep(bin.context.i8_type(), output, &[hex_len], "")
+                            .unwrap()
                     };
                 }
                 Type::Address(_) | Type::Contract(_) => {
                     // FIXME: For Polkadot we should encode in the SS58 format
                     let buf = bin.build_alloca(function, bin.address_type(ns), "address");
-                    bin.builder.build_store(buf, val.into_array_value());
+                    bin.builder
+                        .build_store(buf, val.into_array_value())
+                        .unwrap();
 
                     let len = bin
                         .context
@@ -203,20 +221,24 @@ pub(super) fn format_string<'a, T: TargetRuntime<'a> + ?Sized>(
                             .context
                             .i32_type()
                             .const_int(calculated_len as u64, false);
-                        bin.builder.build_call(
-                            bin.module
-                                .get_function("base58_encode_solana_address")
-                                .unwrap(),
-                            &[buf.into(), len.into(), output.into(), base58_len.into()],
-                            "",
-                        );
+                        bin.builder
+                            .build_call(
+                                bin.module
+                                    .get_function("base58_encode_solana_address")
+                                    .unwrap(),
+                                &[buf.into(), len.into(), output.into(), base58_len.into()],
+                                "",
+                            )
+                            .unwrap();
                         base58_len
                     } else {
-                        bin.builder.build_call(
-                            bin.module.get_function("hex_encode").unwrap(),
-                            &[output.into(), buf.into(), len.into()],
-                            "",
-                        );
+                        bin.builder
+                            .build_call(
+                                bin.module.get_function("hex_encode").unwrap(),
+                                &[output.into(), buf.into(), len.into()],
+                                "",
+                            )
+                            .unwrap();
 
                         bin.context
                             .i32_type()
@@ -226,34 +248,41 @@ pub(super) fn format_string<'a, T: TargetRuntime<'a> + ?Sized>(
                     output = unsafe {
                         bin.builder
                             .build_gep(bin.context.i8_type(), output, &[written_len], "")
+                            .unwrap()
                     };
                 }
                 Type::Bytes(size) => {
                     let buf = bin.build_alloca(function, bin.llvm_type(&arg_ty, ns), "bytesN");
 
-                    bin.builder.build_store(buf, val.into_int_value());
+                    bin.builder.build_store(buf, val.into_int_value()).unwrap();
 
                     let len = bin.context.i32_type().const_int(size as u64, false);
 
-                    bin.builder.build_call(
-                        bin.module.get_function("hex_encode_rev").unwrap(),
-                        &[output.into(), buf.into(), len.into()],
-                        "",
-                    );
+                    bin.builder
+                        .build_call(
+                            bin.module.get_function("hex_encode_rev").unwrap(),
+                            &[output.into(), buf.into(), len.into()],
+                            "",
+                        )
+                        .unwrap();
 
-                    let hex_len = bin.builder.build_int_add(len, len, "hex_len");
+                    let hex_len = bin.builder.build_int_add(len, len, "hex_len").unwrap();
 
                     output = unsafe {
                         bin.builder
                             .build_gep(bin.context.i8_type(), output, &[hex_len], "")
+                            .unwrap()
                     };
                 }
                 Type::Enum(_) => {
-                    let val = bin.builder.build_int_z_extend(
-                        val.into_int_value(),
-                        bin.context.i64_type(),
-                        "val_64bits",
-                    );
+                    let val = bin
+                        .builder
+                        .build_int_z_extend(
+                            val.into_int_value(),
+                            bin.context.i64_type(),
+                            "val_64bits",
+                        )
+                        .unwrap();
 
                     output = bin
                         .builder
@@ -262,6 +291,7 @@ pub(super) fn format_string<'a, T: TargetRuntime<'a> + ?Sized>(
                             &[output.into(), val.into()],
                             "",
                         )
+                        .unwrap()
                         .try_as_basic_value()
                         .left()
                         .unwrap()
@@ -272,11 +302,13 @@ pub(super) fn format_string<'a, T: TargetRuntime<'a> + ?Sized>(
                         let val = if bits == 64 {
                             val.into_int_value()
                         } else {
-                            bin.builder.build_int_z_extend(
-                                val.into_int_value(),
-                                bin.context.i64_type(),
-                                "val_64bits",
-                            )
+                            bin.builder
+                                .build_int_z_extend(
+                                    val.into_int_value(),
+                                    bin.context.i64_type(),
+                                    "val_64bits",
+                                )
+                                .unwrap()
                         };
 
                         output = bin
@@ -286,6 +318,7 @@ pub(super) fn format_string<'a, T: TargetRuntime<'a> + ?Sized>(
                                 &[output.into(), val.into()],
                                 "",
                             )
+                            .unwrap()
                             .try_as_basic_value()
                             .left()
                             .unwrap()
@@ -294,11 +327,13 @@ pub(super) fn format_string<'a, T: TargetRuntime<'a> + ?Sized>(
                         let val = if bits == 128 {
                             val.into_int_value()
                         } else {
-                            bin.builder.build_int_z_extend(
-                                val.into_int_value(),
-                                bin.context.custom_width_int_type(128),
-                                "val_128bits",
-                            )
+                            bin.builder
+                                .build_int_z_extend(
+                                    val.into_int_value(),
+                                    bin.context.custom_width_int_type(128),
+                                    "val_128bits",
+                                )
+                                .unwrap()
                         };
 
                         output = bin
@@ -308,6 +343,7 @@ pub(super) fn format_string<'a, T: TargetRuntime<'a> + ?Sized>(
                                 &[output.into(), val.into()],
                                 "",
                             )
+                            .unwrap()
                             .try_as_basic_value()
                             .left()
                             .unwrap()
@@ -316,11 +352,13 @@ pub(super) fn format_string<'a, T: TargetRuntime<'a> + ?Sized>(
                         let val = if bits == 256 {
                             val.into_int_value()
                         } else {
-                            bin.builder.build_int_z_extend(
-                                val.into_int_value(),
-                                bin.context.custom_width_int_type(256),
-                                "val_256bits",
-                            )
+                            bin.builder
+                                .build_int_z_extend(
+                                    val.into_int_value(),
+                                    bin.context.custom_width_int_type(256),
+                                    "val_256bits",
+                                )
+                                .unwrap()
                         };
 
                         let pval = bin.build_alloca(
@@ -329,7 +367,7 @@ pub(super) fn format_string<'a, T: TargetRuntime<'a> + ?Sized>(
                             "int",
                         );
 
-                        bin.builder.build_store(pval, val);
+                        bin.builder.build_store(pval, val).unwrap();
 
                         output = bin
                             .builder
@@ -338,6 +376,7 @@ pub(super) fn format_string<'a, T: TargetRuntime<'a> + ?Sized>(
                                 &[output.into(), pval.into()],
                                 "",
                             )
+                            .unwrap()
                             .try_as_basic_value()
                             .left()
                             .unwrap()
@@ -345,7 +384,7 @@ pub(super) fn format_string<'a, T: TargetRuntime<'a> + ?Sized>(
                     } else {
                         let buf = bin.build_alloca(function, bin.llvm_type(&arg_ty, ns), "uint");
 
-                        bin.builder.build_store(buf, val.into_int_value());
+                        bin.builder.build_store(buf, val.into_int_value()).unwrap();
 
                         let len = bin.context.i32_type().const_int(bits as u64 / 8, false);
 
@@ -362,6 +401,7 @@ pub(super) fn format_string<'a, T: TargetRuntime<'a> + ?Sized>(
                                 &[output.into(), buf.into(), len.into()],
                                 "",
                             )
+                            .unwrap()
                             .try_as_basic_value()
                             .left()
                             .unwrap()
@@ -371,40 +411,46 @@ pub(super) fn format_string<'a, T: TargetRuntime<'a> + ?Sized>(
                 Type::Int(bits) => {
                     let val = val.into_int_value();
 
-                    let is_negative = bin.builder.build_int_compare(
-                        IntPredicate::SLT,
-                        val,
-                        val.get_type().const_zero(),
-                        "negative",
-                    );
+                    let is_negative = bin
+                        .builder
+                        .build_int_compare(
+                            IntPredicate::SLT,
+                            val,
+                            val.get_type().const_zero(),
+                            "negative",
+                        )
+                        .unwrap();
 
                     let entry = bin.builder.get_insert_block().unwrap();
                     let positive = bin.context.append_basic_block(function, "int_positive");
                     let negative = bin.context.append_basic_block(function, "int_negative");
 
                     bin.builder
-                        .build_conditional_branch(is_negative, negative, positive);
+                        .build_conditional_branch(is_negative, negative, positive)
+                        .unwrap();
 
                     bin.builder.position_at_end(negative);
 
                     // add "-" to output and negate our val
                     bin.builder
-                        .build_store(output, bin.context.i8_type().const_int('-' as u64, false));
+                        .build_store(output, bin.context.i8_type().const_int('-' as u64, false))
+                        .unwrap();
 
                     let minus_len = bin.context.i32_type().const_int(1, false);
 
                     let neg_data = unsafe {
                         bin.builder
                             .build_gep(bin.context.i8_type(), output, &[minus_len], "")
+                            .unwrap()
                     };
-                    let neg_val = bin.builder.build_int_neg(val, "negative_int");
+                    let neg_val = bin.builder.build_int_neg(val, "negative_int").unwrap();
 
-                    bin.builder.build_unconditional_branch(positive);
+                    bin.builder.build_unconditional_branch(positive).unwrap();
 
                     bin.builder.position_at_end(positive);
 
-                    let data_phi = bin.builder.build_phi(output.get_type(), "data");
-                    let val_phi = bin.builder.build_phi(val.get_type(), "val");
+                    let data_phi = bin.builder.build_phi(output.get_type(), "data").unwrap();
+                    let val_phi = bin.builder.build_phi(val.get_type(), "val").unwrap();
 
                     data_phi.add_incoming(&[(&neg_data, negative), (&output, entry)]);
                     val_phi.add_incoming(&[(&neg_val, negative), (&val, entry)]);
@@ -413,11 +459,13 @@ pub(super) fn format_string<'a, T: TargetRuntime<'a> + ?Sized>(
                         let val = if bits == 64 {
                             val_phi.as_basic_value().into_int_value()
                         } else {
-                            bin.builder.build_int_z_extend(
-                                val_phi.as_basic_value().into_int_value(),
-                                bin.context.i64_type(),
-                                "val_64bits",
-                            )
+                            bin.builder
+                                .build_int_z_extend(
+                                    val_phi.as_basic_value().into_int_value(),
+                                    bin.context.i64_type(),
+                                    "val_64bits",
+                                )
+                                .unwrap()
                         };
 
                         let output_after_minus = data_phi.as_basic_value().into_pointer_value();
@@ -429,6 +477,7 @@ pub(super) fn format_string<'a, T: TargetRuntime<'a> + ?Sized>(
                                 &[output_after_minus.into(), val.into()],
                                 "",
                             )
+                            .unwrap()
                             .try_as_basic_value()
                             .left()
                             .unwrap()
@@ -437,11 +486,13 @@ pub(super) fn format_string<'a, T: TargetRuntime<'a> + ?Sized>(
                         let val = if bits == 128 {
                             val_phi.as_basic_value().into_int_value()
                         } else {
-                            bin.builder.build_int_z_extend(
-                                val_phi.as_basic_value().into_int_value(),
-                                bin.context.custom_width_int_type(128),
-                                "val_128bits",
-                            )
+                            bin.builder
+                                .build_int_z_extend(
+                                    val_phi.as_basic_value().into_int_value(),
+                                    bin.context.custom_width_int_type(128),
+                                    "val_128bits",
+                                )
+                                .unwrap()
                         };
 
                         let output_after_minus = data_phi.as_basic_value().into_pointer_value();
@@ -453,6 +504,7 @@ pub(super) fn format_string<'a, T: TargetRuntime<'a> + ?Sized>(
                                 &[output_after_minus.into(), val.into()],
                                 "",
                             )
+                            .unwrap()
                             .try_as_basic_value()
                             .left()
                             .unwrap()
@@ -461,11 +513,13 @@ pub(super) fn format_string<'a, T: TargetRuntime<'a> + ?Sized>(
                         let val = if bits == 256 {
                             val_phi.as_basic_value().into_int_value()
                         } else {
-                            bin.builder.build_int_z_extend(
-                                val_phi.as_basic_value().into_int_value(),
-                                bin.context.custom_width_int_type(256),
-                                "val_256bits",
-                            )
+                            bin.builder
+                                .build_int_z_extend(
+                                    val_phi.as_basic_value().into_int_value(),
+                                    bin.context.custom_width_int_type(256),
+                                    "val_256bits",
+                                )
+                                .unwrap()
                         };
 
                         let pval = bin.build_alloca(
@@ -474,7 +528,7 @@ pub(super) fn format_string<'a, T: TargetRuntime<'a> + ?Sized>(
                             "int",
                         );
 
-                        bin.builder.build_store(pval, val);
+                        bin.builder.build_store(pval, val).unwrap();
 
                         let output_after_minus = data_phi.as_basic_value().into_pointer_value();
 
@@ -485,6 +539,7 @@ pub(super) fn format_string<'a, T: TargetRuntime<'a> + ?Sized>(
                                 &[output_after_minus.into(), pval.into()],
                                 "",
                             )
+                            .unwrap()
                             .try_as_basic_value()
                             .left()
                             .unwrap()
@@ -493,7 +548,8 @@ pub(super) fn format_string<'a, T: TargetRuntime<'a> + ?Sized>(
                         let buf = bin.build_alloca(function, bin.llvm_type(&arg_ty, ns), "int");
 
                         bin.builder
-                            .build_store(buf, val_phi.as_basic_value().into_int_value());
+                            .build_store(buf, val_phi.as_basic_value().into_int_value())
+                            .unwrap();
 
                         let len = bin.context.i32_type().const_int(bits as u64 / 8, false);
 
@@ -512,6 +568,7 @@ pub(super) fn format_string<'a, T: TargetRuntime<'a> + ?Sized>(
                                 &[output_after_minus.into(), buf.into(), len.into()],
                                 "",
                             )
+                            .unwrap()
                             .try_as_basic_value()
                             .left()
                             .unwrap()
@@ -524,27 +581,34 @@ pub(super) fn format_string<'a, T: TargetRuntime<'a> + ?Sized>(
     }
 
     // write the final length into the vector
-    let length = bin.builder.build_int_sub(
-        bin.builder
-            .build_ptr_to_int(output, bin.context.i32_type(), "end"),
-        bin.builder
-            .build_ptr_to_int(output_start, bin.context.i32_type(), "begin"),
-        "datalength",
-    );
+    let length = bin
+        .builder
+        .build_int_sub(
+            bin.builder
+                .build_ptr_to_int(output, bin.context.i32_type(), "end")
+                .unwrap(),
+            bin.builder
+                .build_ptr_to_int(output_start, bin.context.i32_type(), "begin")
+                .unwrap(),
+            "datalength",
+        )
+        .unwrap();
 
     let data_len = unsafe {
-        bin.builder.build_gep(
-            bin.module.get_struct_type("struct.vector").unwrap(),
-            vector,
-            &[
-                bin.context.i32_type().const_zero(),
-                bin.context.i32_type().const_zero(),
-            ],
-            "data_len",
-        )
+        bin.builder
+            .build_gep(
+                bin.module.get_struct_type("struct.vector").unwrap(),
+                vector,
+                &[
+                    bin.context.i32_type().const_zero(),
+                    bin.context.i32_type().const_zero(),
+                ],
+                "data_len",
+            )
+            .unwrap()
     };
 
-    bin.builder.build_store(data_len, length);
+    bin.builder.build_store(data_len, length).unwrap();
 
     vector.into()
 }

+ 4 - 4
vscode/package.json

@@ -106,8 +106,8 @@
 	"devDependencies": {
 		"@types/glob": "^7.1.1",
 		"@types/mocha": "^7.0.2",
-		"@types/node": "^12.12.0",
-		"@types/node-fetch": "^2.5.8",
+		"@types/node": "^18.11.9",
+		"@types/node-fetch": "^2.6.11",
 		"@types/semver": "^7.3.8",
 		"@types/vscode": "^1.43.0 <1.69.0",
 		"@typescript-eslint/eslint-plugin": "^4.15.0",
@@ -116,7 +116,7 @@
 		"eslint": ">=7.0.0",
 		"glob": "^7.1.6",
 		"mocha": "^7.1.2",
-		"typescript": "^3.8.3"
+		"typescript": "^5.3.3"
 	},
 	"__metadata": {
 		"id": "3134b20d-911a-4418-a461-3f2380f4a1c2",
@@ -124,4 +124,4 @@
 		"publisherId": "6c1a8c6d-5493-4493-81d2-e899244f0def",
 		"isPreReleaseVersion": false
 	}
-}
+}

+ 1 - 1
vscode/src/utils/downloadWithRetryDialog.ts

@@ -5,7 +5,7 @@ export default async function downloadWithRetryDialog<T>(downloadFunc: () => Pro
   while (true) {
     try {
       return await downloadFunc();
-    } catch (e) {
+    } catch (e: any) {
       const selected = await vscode.window.showErrorMessage(
         'Failed to download: ' + e.message,
         {},

이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.