Skip to content

Commit 071a9ba

Browse files
authored
rename "lift" and "lower" functions (#65)
The "lift" and "lower" terminology was misleading and confusing for anyone familiar with their meanings in the Component Model ABI. I was overloading them to mean "lift from the canonical ABI representation to Python" and "lower from Python to the canonical ABI representation", respectively, but that's easy to confuse with how the canonical ABI uses them to mean "lift a core function to a component function" and "lower a component function to a core function". In order to avoid such confusion, I've renamed them to "from-canon" and "to-canon", respectively. Signed-off-by: Joel Dice <joel.dice@fermyon.com>
1 parent 7dafe2d commit 071a9ba

4 files changed

Lines changed: 194 additions & 167 deletions

File tree

runtime/src/lib.rs

Lines changed: 44 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -381,26 +381,25 @@ impl Guest for MyExports {
381381
#[export_name = "componentize-py#Dispatch"]
382382
pub unsafe extern "C" fn componentize_py_dispatch(
383383
export: usize,
384-
lift: u32,
385-
lower: u32,
384+
from_canon: u32,
385+
to_canon: u32,
386386
param_count: u32,
387387
return_style: ReturnStyle,
388-
params: *const c_void,
389-
results: *mut c_void,
388+
params_canon: *const c_void,
389+
results_canon: *mut c_void,
390390
) {
391391
Python::with_gil(|py| {
392-
let mut params_lifted =
393-
vec![MaybeUninit::<&PyAny>::uninit(); param_count.try_into().unwrap()];
392+
let mut params_py = vec![MaybeUninit::<&PyAny>::uninit(); param_count.try_into().unwrap()];
394393

395394
componentize_py_call_indirect(
396395
&py as *const _ as _,
397-
params,
398-
params_lifted.as_mut_ptr() as _,
399-
lift,
396+
params_canon,
397+
params_py.as_mut_ptr() as _,
398+
from_canon,
400399
);
401400

402401
// todo: is this sound, or do we need to `.into_iter().map(MaybeUninit::assume_init).collect()` instead?
403-
let params_lifted = mem::transmute::<Vec<MaybeUninit<&PyAny>>, Vec<&PyAny>>(params_lifted);
402+
let params_py = mem::transmute::<Vec<MaybeUninit<&PyAny>>, Vec<&PyAny>>(params_py);
404403

405404
static ONCE: Once = Once::new();
406405
ONCE.call_once(|| {
@@ -424,15 +423,15 @@ pub unsafe extern "C" fn componentize_py_dispatch(
424423
let export = &EXPORTS.get().unwrap()[export];
425424
let result = match export {
426425
Export::Freestanding { instance, name } => {
427-
instance.call_method1(py, name.as_ref(py), PyTuple::new(py, params_lifted))
426+
instance.call_method1(py, name.as_ref(py), PyTuple::new(py, params_py))
428427
}
429-
Export::Constructor(class) => class.call1(py, PyTuple::new(py, params_lifted)),
430-
Export::Method(name) => params_lifted[0]
431-
.call_method1(name.as_ref(py), PyTuple::new(py, &params_lifted[1..]))
428+
Export::Constructor(class) => class.call1(py, PyTuple::new(py, params_py)),
429+
Export::Method(name) => params_py[0]
430+
.call_method1(name.as_ref(py), PyTuple::new(py, &params_py[1..]))
432431
.map(|r| r.into()),
433432
Export::Static { class, name } => class
434433
.getattr(py, name.as_ref(py))
435-
.and_then(|function| function.call1(py, PyTuple::new(py, params_lifted))),
434+
.and_then(|function| function.call1(py, PyTuple::new(py, params_py))),
436435
};
437436

438437
let result = match return_style {
@@ -468,8 +467,8 @@ pub unsafe extern "C" fn componentize_py_dispatch(
468467
componentize_py_call_indirect(
469468
&py as *const _ as _,
470469
result_array.as_ptr() as *const _ as _,
471-
results,
472-
lower,
470+
results_canon,
471+
to_canon,
473472
);
474473
});
475474
}
@@ -488,37 +487,37 @@ pub unsafe extern "C" fn componentize_py_free(ptr: *mut u8, size: usize, align:
488487
alloc::dealloc(ptr, Layout::from_size_align(size, align).unwrap())
489488
}
490489

491-
#[export_name = "componentize-py#LowerI32"]
492-
pub extern "C" fn componentize_py_lower_i32(_py: &Python, value: &PyAny) -> i32 {
490+
#[export_name = "componentize-py#ToCanonI32"]
491+
pub extern "C" fn componentize_py_to_canon_i32(_py: &Python, value: &PyAny) -> i32 {
493492
value.extract().unwrap()
494493
}
495494

496-
#[export_name = "componentize-py#LowerI64"]
497-
pub extern "C" fn componentize_py_lower_i64(_py: &Python, value: &PyAny) -> i64 {
495+
#[export_name = "componentize-py#ToCanonI64"]
496+
pub extern "C" fn componentize_py_to_canon_i64(_py: &Python, value: &PyAny) -> i64 {
498497
value.extract().unwrap()
499498
}
500499

501-
#[export_name = "componentize-py#LowerF32"]
502-
pub extern "C" fn componentize_py_lower_f32(_py: &Python, value: &PyAny) -> f32 {
500+
#[export_name = "componentize-py#ToCanonF32"]
501+
pub extern "C" fn componentize_py_to_canon_f32(_py: &Python, value: &PyAny) -> f32 {
503502
value.extract().unwrap()
504503
}
505504

506-
#[export_name = "componentize-py#LowerF64"]
507-
pub extern "C" fn componentize_py_lower_f64(_py: &Python, value: &PyAny) -> f64 {
505+
#[export_name = "componentize-py#ToCanonF64"]
506+
pub extern "C" fn componentize_py_to_canon_f64(_py: &Python, value: &PyAny) -> f64 {
508507
value.extract().unwrap()
509508
}
510509

511-
#[export_name = "componentize-py#LowerChar"]
512-
pub extern "C" fn componentize_py_lower_char(_py: &Python, value: &PyAny) -> u32 {
510+
#[export_name = "componentize-py#ToCanonChar"]
511+
pub extern "C" fn componentize_py_to_canon_char(_py: &Python, value: &PyAny) -> u32 {
513512
let value = value.extract::<String>().unwrap();
514513
assert!(value.chars().count() == 1);
515514
value.chars().next().unwrap() as u32
516515
}
517516

518517
/// # Safety
519518
/// TODO
520-
#[export_name = "componentize-py#LowerString"]
521-
pub unsafe extern "C" fn componentize_py_lower_string(
519+
#[export_name = "componentize-py#ToCanonString"]
520+
pub unsafe extern "C" fn componentize_py_to_canon_string(
522521
_py: &Python,
523522
value: &PyAny,
524523
destination: *mut (*const u8, usize),
@@ -663,28 +662,28 @@ pub extern "C" fn componentize_py_get_list_element<'a>(
663662
value.downcast::<PyList>().unwrap().get_item(index).unwrap()
664663
}
665664

666-
#[export_name = "componentize-py#LiftI32"]
667-
pub extern "C" fn componentize_py_lift_i32<'a>(py: &'a Python<'a>, value: i32) -> &'a PyAny {
665+
#[export_name = "componentize-py#FromCanonI32"]
666+
pub extern "C" fn componentize_py_from_canon_i32<'a>(py: &'a Python<'a>, value: i32) -> &'a PyAny {
668667
value.to_object(*py).into_ref(*py).downcast().unwrap()
669668
}
670669

671-
#[export_name = "componentize-py#LiftI64"]
672-
pub extern "C" fn componentize_py_lift_i64<'a>(py: &'a Python<'a>, value: i64) -> &'a PyAny {
670+
#[export_name = "componentize-py#FromCanonI64"]
671+
pub extern "C" fn componentize_py_from_canon_i64<'a>(py: &'a Python<'a>, value: i64) -> &'a PyAny {
673672
value.to_object(*py).into_ref(*py).downcast().unwrap()
674673
}
675674

676-
#[export_name = "componentize-py#LiftF32"]
677-
pub extern "C" fn componentize_py_lift_f32<'a>(py: &'a Python<'a>, value: f32) -> &'a PyAny {
675+
#[export_name = "componentize-py#FromCanonF32"]
676+
pub extern "C" fn componentize_py_from_canon_f32<'a>(py: &'a Python<'a>, value: f32) -> &'a PyAny {
678677
value.to_object(*py).into_ref(*py).downcast().unwrap()
679678
}
680679

681-
#[export_name = "componentize-py#LiftF64"]
682-
pub extern "C" fn componentize_py_lift_f64<'a>(py: &'a Python<'a>, value: f64) -> &'a PyAny {
680+
#[export_name = "componentize-py#FromCanonF64"]
681+
pub extern "C" fn componentize_py_from_canon_f64<'a>(py: &'a Python<'a>, value: f64) -> &'a PyAny {
683682
value.to_object(*py).into_ref(*py).downcast().unwrap()
684683
}
685684

686-
#[export_name = "componentize-py#LiftChar"]
687-
pub extern "C" fn componentize_py_lift_char<'a>(py: &'a Python<'a>, value: u32) -> &'a PyAny {
685+
#[export_name = "componentize-py#FromCanonChar"]
686+
pub extern "C" fn componentize_py_from_canon_char<'a>(py: &'a Python<'a>, value: u32) -> &'a PyAny {
688687
char::from_u32(value)
689688
.unwrap()
690689
.to_string()
@@ -696,8 +695,8 @@ pub extern "C" fn componentize_py_lift_char<'a>(py: &'a Python<'a>, value: u32)
696695

697696
/// # Safety
698697
/// TODO
699-
#[export_name = "componentize-py#LiftString"]
700-
pub unsafe extern "C" fn componentize_py_lift_string<'a>(
698+
#[export_name = "componentize-py#FromCanonString"]
699+
pub unsafe extern "C" fn componentize_py_from_canon_string<'a>(
701700
py: &'a Python,
702701
data: *const u8,
703702
len: usize,
@@ -888,8 +887,8 @@ pub unsafe extern "C" fn componentize_py_make_bytes<'a>(
888887
.unwrap()
889888
}
890889

891-
#[export_name = "componentize-py#LiftHandle"]
892-
pub extern "C" fn componentize_py_lift_handle<'a>(
890+
#[export_name = "componentize-py#FromCanonHandle"]
891+
pub extern "C" fn componentize_py_from_canon_handle<'a>(
893892
py: &'a Python<'a>,
894893
value: i32,
895894
borrow: i32,
@@ -983,8 +982,8 @@ pub extern "C" fn componentize_py_lift_handle<'a>(
983982
}
984983
}
985984

986-
#[export_name = "componentize-py#LowerHandle"]
987-
pub extern "C" fn componentize_py_lower_handle(
985+
#[export_name = "componentize-py#ToCanonHandle"]
986+
pub extern "C" fn componentize_py_to_canon_handle(
988987
py: &Python,
989988
value: &PyAny,
990989
borrow: i32,

0 commit comments

Comments
 (0)