Skip to content

Commit

Permalink
revert Seamless Slices... fix file-upload-form example
Browse files Browse the repository at this point in the history
  • Loading branch information
lukewilliamboswell committed Dec 19, 2024
1 parent 44f811c commit d82ad30
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 29 deletions.
20 changes: 0 additions & 20 deletions ci/all_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,26 +67,6 @@ find . -type d -name "roc_nightly" -prune -o -type f -name "*.roc" -print | whil
done

for script in ci/expect_scripts/*.exp; do

# skip file-upload-form.exp
# + expect ci/expect_scripts/file-upload-form.exp
# spawn examples/file-upload-form
# Listening on <http://127.0.0.1:8000>
# WARNING: The convert command is deprecated in IMv7, use "magick" instead of "convert" or "magick convert"

# while executing
# "exec convert -size 100x100 xc:red red_test_image.png"
# invoked from within
# "expect "Listening on <http://127.0.0.1:8000>\r\n" {

# exec convert -size 100x100 xc:red red_test_image.png

# set script_dir [file dirname [info ..."
# (file "ci/expect_scripts/file-upload-form.exp" line 10)
if [ $script == "ci/expect_scripts/file-upload-form.exp" ]; then
continue
fi

expect "$script"
done

Expand Down
2 changes: 1 addition & 1 deletion ci/expect_scripts/file-upload-form.exp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ spawn $env(EXAMPLES_DIR)file-upload-form

expect "Listening on <http://127.0.0.1:8000>\r\n" {

exec convert -size 100x100 xc:red red_test_image.png
exec magick -size 100x100 xc:red red_test_image.png

set script_dir [file dirname [info script]]

Expand Down
20 changes: 13 additions & 7 deletions crates/roc_host/src/http_server.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::roc::{self, to_const_seamless_roc_str};
use crate::roc::{self};
use bytes::Bytes;
use futures::{Future, FutureExt};
use hyper::header::{HeaderName, HeaderValue};
Expand Down Expand Up @@ -44,23 +44,29 @@ fn call_roc<'a>(
) -> hyper::Response<hyper::Body> {
let headers: RocList<roc_http::Header> = headers
.map(|(key, value)| roc_http::Header {
name: unsafe { to_const_seamless_roc_str(key.as_str()) },
value: unsafe {
to_const_seamless_roc_str(value.to_str().expect("valid header value from hyper"))
},
// NOTE: we should be able to make this a seamless slice somehow
// we tried but it was causing some issues, so removing just land the PI upgrade with
// for now with something we know works ok.
// TODO use to_const_seamless_roc_str()
name: key.as_str().into(),
value: value
.to_str()
.expect("valid header value from hyper")
.into(),
})
.collect();

// NOTE: we should be able to make this a seamless slice somehow
// and possible avoid making this a rust String
// and possible avoid making this a rust String or Vev<u8> first
let uri: RocStr = url.to_string().as_str().into();
let body: RocList<u8> = body.to_vec().as_slice().into();

let roc_request = roc_http::RequestToAndFromHost {
headers,
uri,
timeout_ms: 0,
method_ext: RocStr::empty(),
body: unsafe { roc::to_const_seamless_roc_list(&body) },
body,
method: roc_http::RequestToAndFromHost::from_hyper_method(&method),
};

Expand Down
7 changes: 6 additions & 1 deletion crates/roc_host/src/roc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,19 +482,24 @@ pub fn call_roc_respond(
}
}

// TODO use these functions to create seamless slices and avoid unnecessary allocations

#[allow(dead_code)]
const REFCOUNT_CONSTANT: u64 = 0;
#[allow(dead_code)]
const SEAMLESS_SLICE_BIT: usize = isize::MIN as usize;

// This is only safe to call if the underlying data is guaranteed to be alive for the lifetime of the roc list.
#[allow(dead_code)]
pub unsafe fn to_const_seamless_roc_list(data: &[u8]) -> RocList<u8> {
let const_refcount_allocation =
(&REFCOUNT_CONSTANT as *const u64) as usize + size_of_val(&REFCOUNT_CONSTANT);
let const_seamless_slice = (const_refcount_allocation >> 1) | SEAMLESS_SLICE_BIT;

RocList::from_raw_parts(data.as_ptr() as *mut u8, data.len(), const_seamless_slice)
}

// This is only safe to call if the underlying data is guaranteed to be alive for the lifetime of the roc list.
#[allow(dead_code)]
pub unsafe fn to_const_seamless_roc_str(data: &str) -> RocStr {
// TODO: consider still generating small strings here if the str is small enough.
let const_refcount_allocation =
Expand Down

0 comments on commit d82ad30

Please sign in to comment.