From 13198bce37ae28de401a0e125cc669646acd4c67 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sun, 23 May 2021 09:22:42 -0400 Subject: [PATCH] Update comments to no longer reference malloc --- compiler/gen/src/llvm/build.rs | 8 +++----- compiler/gen/src/llvm/build_list.rs | 6 ++---- compiler/gen/src/llvm/refcounting.rs | 12 ++++++------ 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/compiler/gen/src/llvm/build.rs b/compiler/gen/src/llvm/build.rs index 967225398f..d82c110d10 100644 --- a/compiler/gen/src/llvm/build.rs +++ b/compiler/gen/src/llvm/build.rs @@ -1944,7 +1944,7 @@ pub fn allocate_with_refcount_help<'a, 'ctx, 'env>( "get_data_ptr", ), ptr_type, - "malloc_cast_to_desired", + "alloc_cast_to_desired", ) .into_pointer_value() } @@ -1952,12 +1952,12 @@ pub fn allocate_with_refcount_help<'a, 'ctx, 'env>( let refcount_ptr = match extra_bytes { n if n == env.ptr_bytes => { - // the malloced pointer is the same as the refcounted pointer + // the allocated pointer is the same as the refcounted pointer unsafe { PointerToRefcount::from_ptr(env, ptr) } } n if n == 2 * env.ptr_bytes => { // the refcount is stored just before the start of the actual data - // but in this case (because of alignment) not at the start of the malloced buffer + // but in this case (because of alignment) not at the start of the allocated buffer PointerToRefcount::from_ptr_to_data(env, data_ptr) } n => unreachable!("invalid extra_bytes {}", n), @@ -1986,8 +1986,6 @@ fn list_literal<'a, 'ctx, 'env>( let len = len_type.const_int(len_u64, false); allocate_list(env, inplace, elem_layout, len) - - // TODO check if malloc returned null; if so, runtime error for OOM! }; // Copy the elements from the list literal into the array diff --git a/compiler/gen/src/llvm/build_list.rs b/compiler/gen/src/llvm/build_list.rs index 1637f33c8a..06913f5a92 100644 --- a/compiler/gen/src/llvm/build_list.rs +++ b/compiler/gen/src/llvm/build_list.rs @@ -185,7 +185,7 @@ pub fn list_prepend<'a, 'ctx, 'env>( if elem_layout.safe_to_memcpy() { // Copy the bytes from the original array into the new - // one we just malloc'd. + // one we just allocated // // TODO how do we decide when to do the small memcpy vs the normal one? builder @@ -1335,12 +1335,10 @@ fn clone_nonempty_list<'a, 'ctx, 'env>( // Allocate space for the new array that we'll copy into. let clone_ptr = allocate_list(env, inplace, elem_layout, list_len); - // TODO check if malloc returned null; if so, runtime error for OOM! - // Either memcpy or deep clone the array elements if elem_layout.safe_to_memcpy() { // Copy the bytes from the original array into the new - // one we just malloc'd. + // one we just allocated // // TODO how do we decide when to do the small memcpy vs the normal one? builder diff --git a/compiler/gen/src/llvm/refcounting.rs b/compiler/gen/src/llvm/refcounting.rs index 9abd011fa9..710c34cdd2 100644 --- a/compiler/gen/src/llvm/refcounting.rs +++ b/compiler/gen/src/llvm/refcounting.rs @@ -40,8 +40,8 @@ impl<'ctx> PointerToRefcount<'ctx> { /// # Safety /// /// the invariant is that the given pointer really points to the refcount, - /// not the data, and only is the start of the malloced buffer if the alignment - /// works out that way. + /// not the data, and only is the start of the allocated buffer if the + /// alignment works out that way. pub unsafe fn from_ptr<'a, 'env>(env: &Env<'a, 'ctx, 'env>, ptr: PointerValue<'ctx>) -> Self { // must make sure it's a pointer to usize let refcount_type = ptr_int(env.context, env.ptr_bytes); @@ -277,13 +277,13 @@ impl<'ctx> PointerToRefcount<'ctx> { match alignment { n if env.ptr_bytes == n => { - // the refcount ptr is also the ptr to the malloced region + // the refcount ptr is also the ptr to the allocated region env.call_dealloc(alignment, ptr); } n if 2 * env.ptr_bytes == n => { - // we need to step back another ptr_bytes to get the malloced ptr - let malloced = Self::from_ptr_to_data(env, ptr); - env.call_dealloc(alignment, malloced.value); + // we need to step back another ptr_bytes to get the allocated ptr + let allocated = Self::from_ptr_to_data(env, ptr); + env.call_dealloc(alignment, allocated.value); } n => unreachable!("invalid extra_bytes {:?}", n), }