Skip to content

Commit 28cf995

Browse files
authored
cranelift-frontend: make FunctionBuilder::finalize consume self (#5316)
1 parent 044b57f commit 28cf995

File tree

3 files changed

+29
-31
lines changed

3 files changed

+29
-31
lines changed

cranelift/frontend/src/frontend.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -596,10 +596,11 @@ impl<'a> FunctionBuilder<'a> {
596596
}
597597
}
598598

599-
/// Declare that translation of the current function is complete. This
600-
/// resets the state of the `FunctionBuilder` in preparation to be used
601-
/// for another function.
602-
pub fn finalize(&mut self) {
599+
/// Declare that translation of the current function is complete.
600+
///
601+
/// This resets the state of the `FunctionBuilderContext` in preparation to
602+
/// be used for another function.
603+
pub fn finalize(self) {
603604
// Check that all the `Block`s are filled and sealed.
604605
#[cfg(debug_assertions)]
605606
{
@@ -637,10 +638,6 @@ impl<'a> FunctionBuilder<'a> {
637638
// Clear the state (but preserve the allocated buffers) in preparation
638639
// for translation another function.
639640
self.func_ctx.clear();
640-
641-
// Reset srcloc and position to initial states.
642-
self.srcloc = Default::default();
643-
self.position = Default::default();
644641
}
645642
}
646643

crates/cranelift/src/compiler.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ impl Compiler {
766766
.ins()
767767
.call_indirect(new_sig, callee_value, &callee_args);
768768

769-
self.wasm_to_host_load_results(ty, &mut builder, values_vec_ptr_val);
769+
self.wasm_to_host_load_results(ty, builder, values_vec_ptr_val);
770770

771771
let func = self.finish_trampoline(&mut context, cache_ctx.as_mut(), isa)?;
772772
self.save_context(CompilerContext {
@@ -840,7 +840,7 @@ impl Compiler {
840840
fn wasm_to_host_load_results(
841841
&self,
842842
ty: &WasmFuncType,
843-
builder: &mut FunctionBuilder,
843+
mut builder: FunctionBuilder,
844844
values_vec_ptr_val: Value,
845845
) {
846846
let isa = &*self.isa;

crates/cranelift/src/compiler/component.rs

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ impl ComponentCompiler for Compiler {
145145

146146
// After the host function has returned the results are loaded from
147147
// `values_vec_ptr_val` and then returned.
148-
self.wasm_to_host_load_results(ty, &mut builder, values_vec_ptr_val);
148+
self.wasm_to_host_load_results(ty, builder, values_vec_ptr_val);
149149

150150
let func: CompiledFunction =
151151
self.finish_trampoline(&mut context, incremental_cache_ctx.as_mut(), isa)?;
@@ -219,7 +219,7 @@ impl ComponentCompiler for Compiler {
219219
builder.switch_to_block(block0);
220220
builder.seal_block(block0);
221221

222-
self.translate_transcode(&mut builder, &offsets, transcoder, block0);
222+
self.translate_transcode(builder, &offsets, transcoder, block0);
223223

224224
let func: CompiledFunction =
225225
self.finish_trampoline(&mut context, incremental_cache_ctx.as_mut(), isa)?;
@@ -280,7 +280,7 @@ impl Compiler {
280280

281281
fn translate_transcode(
282282
&self,
283-
builder: &mut FunctionBuilder<'_>,
283+
mut builder: FunctionBuilder<'_>,
284284
offsets: &VMComponentOffsets<u8>,
285285
transcoder: &Transcoder,
286286
block: ir::Block,
@@ -290,7 +290,7 @@ impl Compiler {
290290

291291
// Save the exit FP and return address for stack walking purposes. This
292292
// is used when an invalid encoding is encountered and a trap is raised.
293-
self.save_last_wasm_fp_and_pc(builder, &offsets, vmctx);
293+
self.save_last_wasm_fp_and_pc(&mut builder, &offsets, vmctx);
294294

295295
// Determine the static signature of the host libcall for this transcode
296296
// operation and additionally calculate the static offset within the
@@ -329,8 +329,9 @@ impl Compiler {
329329
);
330330

331331
// Load the base pointers for the from/to linear memories.
332-
let from_base = self.load_runtime_memory_base(builder, vmctx, offsets, transcoder.from);
333-
let to_base = self.load_runtime_memory_base(builder, vmctx, offsets, transcoder.to);
332+
let from_base =
333+
self.load_runtime_memory_base(&mut builder, vmctx, offsets, transcoder.from);
334+
let to_base = self.load_runtime_memory_base(&mut builder, vmctx, offsets, transcoder.to);
334335

335336
// Helper function to cast a core wasm input to a host pointer type
336337
// which will go into the host libcall.
@@ -378,24 +379,24 @@ impl Compiler {
378379
| Transcode::Utf8ToLatin1
379380
| Transcode::Utf16ToLatin1
380381
| Transcode::Utf8ToUtf16 => {
381-
args.push(ptr_param(builder, 0, from64, from_base));
382-
args.push(len_param(builder, 1, from64));
383-
args.push(ptr_param(builder, 2, to64, to_base));
382+
args.push(ptr_param(&mut builder, 0, from64, from_base));
383+
args.push(len_param(&mut builder, 1, from64));
384+
args.push(ptr_param(&mut builder, 2, to64, to_base));
384385
}
385386

386387
Transcode::Utf16ToUtf8 | Transcode::Latin1ToUtf8 => {
387-
args.push(ptr_param(builder, 0, from64, from_base));
388-
args.push(len_param(builder, 1, from64));
389-
args.push(ptr_param(builder, 2, to64, to_base));
390-
args.push(len_param(builder, 3, to64));
388+
args.push(ptr_param(&mut builder, 0, from64, from_base));
389+
args.push(len_param(&mut builder, 1, from64));
390+
args.push(ptr_param(&mut builder, 2, to64, to_base));
391+
args.push(len_param(&mut builder, 3, to64));
391392
}
392393

393394
Transcode::Utf8ToCompactUtf16 | Transcode::Utf16ToCompactUtf16 => {
394-
args.push(ptr_param(builder, 0, from64, from_base));
395-
args.push(len_param(builder, 1, from64));
396-
args.push(ptr_param(builder, 2, to64, to_base));
397-
args.push(len_param(builder, 3, to64));
398-
args.push(len_param(builder, 4, to64));
395+
args.push(ptr_param(&mut builder, 0, from64, from_base));
396+
args.push(len_param(&mut builder, 1, from64));
397+
args.push(ptr_param(&mut builder, 2, to64, to_base));
398+
args.push(len_param(&mut builder, 3, to64));
399+
args.push(len_param(&mut builder, 4, to64));
399400
}
400401
};
401402
let call = builder.ins().call_indirect(sig, transcode_libcall, &args);
@@ -425,15 +426,15 @@ impl Compiler {
425426
| Transcode::Utf16ToCompactProbablyUtf16
426427
| Transcode::Utf8ToCompactUtf16
427428
| Transcode::Utf16ToCompactUtf16 => {
428-
raw_results.push(cast_from_pointer(builder, results[0], to64));
429+
raw_results.push(cast_from_pointer(&mut builder, results[0], to64));
429430
}
430431

431432
Transcode::Latin1ToUtf8
432433
| Transcode::Utf16ToUtf8
433434
| Transcode::Utf8ToLatin1
434435
| Transcode::Utf16ToLatin1 => {
435-
raw_results.push(cast_from_pointer(builder, results[0], from64));
436-
raw_results.push(cast_from_pointer(builder, results[1], to64));
436+
raw_results.push(cast_from_pointer(&mut builder, results[0], from64));
437+
raw_results.push(cast_from_pointer(&mut builder, results[1], to64));
437438
}
438439
};
439440

0 commit comments

Comments
 (0)