Making runtime APIs with sized arrays consistently (count, array). (#9416)

I think I'd originally been using (array, count) to match things like
the std::string constructor, but I think it makes it harder to read
when not actually constructing a span.
diff --git a/runtime/bindings/python/hal.cc b/runtime/bindings/python/hal.cc
index 234aa63..09a5c07 100644
--- a/runtime/bindings/python/hal.cc
+++ b/runtime/bindings/python/hal.cc
@@ -126,7 +126,7 @@
   iree_hal_buffer_view_t* hal_buffer_view;
   CheckApiStatus(
       iree_hal_buffer_view_create(
-          hal_buffer, dims.data(), dims.size(), *element_type, encoding_type,
+          hal_buffer, dims.size(), dims.data(), *element_type, encoding_type,
           iree_hal_allocator_host_allocator(raw_ptr()), &hal_buffer_view),
       "Error allocating buffer_view");
   iree_hal_buffer_release(hal_buffer);
@@ -210,12 +210,12 @@
 //------------------------------------------------------------------------------
 
 std::vector<std::string> HalDriver::Query() {
-  iree_hal_driver_info_t* driver_infos = NULL;
   iree_host_size_t driver_info_count = 0;
+  iree_hal_driver_info_t* driver_infos = NULL;
   CheckApiStatus(
       iree_hal_driver_registry_enumerate(iree_hal_driver_registry_default(),
-                                         iree_allocator_system(), &driver_infos,
-                                         &driver_info_count),
+                                         iree_allocator_system(),
+                                         &driver_info_count, &driver_infos),
       "Error enumerating HAL drivers");
   std::vector<std::string> driver_names(driver_info_count);
   for (iree_host_size_t i = 0; i < driver_info_count; ++i) {
diff --git a/runtime/bindings/python/hal.h b/runtime/bindings/python/hal.h
index 27c9351..1aac34c 100644
--- a/runtime/bindings/python/hal.h
+++ b/runtime/bindings/python/hal.h
@@ -142,7 +142,7 @@
     iree_hal_encoding_type_t encoding_type =
         IREE_HAL_ENCODING_TYPE_DENSE_ROW_MAJOR;
     CheckApiStatus(iree_hal_buffer_view_create(
-                       raw_ptr(), shape.s.data(), shape.s.size(), element_type,
+                       raw_ptr(), shape.s.size(), shape.s.data(), element_type,
                        encoding_type, iree_allocator_system(), &bv),
                    "Error creating buffer view");
     return HalBufferView::StealFromRawPtr(bv);
diff --git a/runtime/bindings/python/vm.cc b/runtime/bindings/python/vm.cc
index f74e8aa..d6a78e5 100644
--- a/runtime/bindings/python/vm.cc
+++ b/runtime/bindings/python/vm.cc
@@ -93,8 +93,8 @@
       module_handles[i] = (*modules)[i]->raw_ptr();
     }
     auto status = iree_vm_context_create_with_modules(
-        instance->raw_ptr(), IREE_VM_CONTEXT_FLAG_NONE, module_handles.data(),
-        module_handles.size(), iree_allocator_system(), &context);
+        instance->raw_ptr(), IREE_VM_CONTEXT_FLAG_NONE, module_handles.size(),
+        module_handles.data(), iree_allocator_system(), &context);
     CheckApiStatus(status, "Error creating vm context with modules");
   }
 
@@ -108,8 +108,8 @@
   for (size_t i = 0, e = module_handles.size(); i < e; ++i) {
     module_handles[i] = modules[i]->raw_ptr();
   }
-  auto status = iree_vm_context_register_modules(raw_ptr(), &module_handles[0],
-                                                 module_handles.size());
+  auto status = iree_vm_context_register_modules(
+      raw_ptr(), module_handles.size(), &module_handles[0]);
   CheckApiStatus(status, "Error registering modules");
 }
 
diff --git a/runtime/bindings/tflite/interpreter.c b/runtime/bindings/tflite/interpreter.c
index 28c132a..74a6398 100644
--- a/runtime/bindings/tflite/interpreter.c
+++ b/runtime/bindings/tflite/interpreter.c
@@ -34,11 +34,11 @@
   iree_hal_driver_registry_t* driver_registry =
       iree_hal_driver_registry_default();
 
-  iree_hal_driver_info_t* driver_infos = NULL;
   iree_host_size_t driver_info_count = 0;
+  iree_hal_driver_info_t* driver_infos = NULL;
   IREE_RETURN_IF_ERROR(iree_hal_driver_registry_enumerate(
-      driver_registry, interpreter->allocator, &driver_infos,
-      &driver_info_count));
+      driver_registry, interpreter->allocator, &driver_info_count,
+      &driver_infos));
 
   // TODO(benvanik): figure out how we want to emulate device selection; may
   // just say "whatever is first" on a query.
@@ -371,7 +371,7 @@
   // IREE functions that will call custom ops through TfLiteRegistrations.
   IREE_RETURN_IF_ERROR(iree_vm_context_create_with_modules(
       interpreter->instance, IREE_VM_CONTEXT_FLAG_NONE,
-      interpreter->all_modules, IREE_ARRAYSIZE(interpreter->all_modules),
+      IREE_ARRAYSIZE(interpreter->all_modules), interpreter->all_modules,
       interpreter->allocator, &interpreter->context));
 
   // Setup all I/O tensors and buffer views.
diff --git a/runtime/bindings/tflite/tensor.c b/runtime/bindings/tflite/tensor.c
index a6891dc..68f694b 100644
--- a/runtime/bindings/tflite/tensor.c
+++ b/runtime/bindings/tflite/tensor.c
@@ -123,7 +123,7 @@
   iree_device_size_t allocation_size = 0;
   IREE_RETURN_AND_END_ZONE_IF_ERROR(
       z0, iree_hal_buffer_compute_view_size(
-              shape_dims, tensor->shape_rank, element_type,
+              tensor->shape_rank, shape_dims, element_type,
               IREE_HAL_ENCODING_TYPE_DENSE_ROW_MAJOR, &allocation_size));
   allocation_size *= storage_scalar;
 
diff --git a/runtime/src/iree/base/bitfield.c b/runtime/src/iree/base/bitfield.c
index 15a46b0..428220c 100644
--- a/runtime/src/iree/base/bitfield.c
+++ b/runtime/src/iree/base/bitfield.c
@@ -9,9 +9,10 @@
 #include <stdlib.h>
 #include <string.h>
 
-IREE_API_EXPORT iree_status_t iree_bitfield_format(
-    uint32_t value, const iree_bitfield_string_mapping_t* mappings,
-    iree_host_size_t mapping_count, iree_string_builder_t* string_builder) {
+IREE_API_EXPORT iree_status_t
+iree_bitfield_format(uint32_t value, iree_host_size_t mapping_count,
+                     const iree_bitfield_string_mapping_t* mappings,
+                     iree_string_builder_t* string_builder) {
   uint32_t remaining_bits = value;
   int i = 0;
   for (iree_host_size_t mapping_index = 0; mapping_index < mapping_count;
@@ -39,14 +40,15 @@
   return iree_ok_status();
 }
 
-IREE_API_EXPORT iree_string_view_t iree_bitfield_format_inline(
-    uint32_t value, const iree_bitfield_string_mapping_t* mappings,
-    iree_host_size_t mapping_count, iree_bitfield_string_temp_t* out_temp) {
+IREE_API_EXPORT iree_string_view_t
+iree_bitfield_format_inline(uint32_t value, iree_host_size_t mapping_count,
+                            const iree_bitfield_string_mapping_t* mappings,
+                            iree_bitfield_string_temp_t* out_temp) {
   iree_string_builder_t string_builder;
   iree_string_builder_initialize_with_storage(
       out_temp->buffer, IREE_ARRAYSIZE(out_temp->buffer), &string_builder);
   iree_status_t status =
-      iree_bitfield_format(value, mappings, mapping_count, &string_builder);
+      iree_bitfield_format(value, mapping_count, mappings, &string_builder);
   if (iree_status_is_ok(status)) {
     return iree_string_builder_view(&string_builder);
   }
diff --git a/runtime/src/iree/base/bitfield.h b/runtime/src/iree/base/bitfield.h
index e67fce5..4329d53 100644
--- a/runtime/src/iree/base/bitfield.h
+++ b/runtime/src/iree/base/bitfield.h
@@ -46,17 +46,18 @@
 //  // Produces the string "A|B":
 //  IREE_RETURN_IF_ERROR(iree_bitfield_format(
 //      MY_BITFIELD_A | MY_BITFIELD_B,
-//      my_bitfield_mappings, IREE_ARRAYSIZE(my_bitfield_mappings),
+//      IREE_ARRAYSIZE(my_bitfield_mappings), my_bitfield_mappings,
 //      &string_builder));
 //
 //  // Produces the string "ALL":
 //  IREE_RETURN_IF_ERROR(iree_bitfield_format(
 //      MY_BITFIELD_A | MY_BITFIELD_B | MY_BITFIELD_C,
-//      my_bitfield_mappings, IREE_ARRAYSIZE(my_bitfield_mappings),
+//      IREE_ARRAYSIZE(my_bitfield_mappings), my_bitfield_mappings,
 //      &string_builder));
-IREE_API_EXPORT iree_status_t iree_bitfield_format(
-    uint32_t value, const iree_bitfield_string_mapping_t* mappings,
-    iree_host_size_t mapping_count, iree_string_builder_t* string_builder);
+IREE_API_EXPORT iree_status_t
+iree_bitfield_format(uint32_t value, iree_host_size_t mapping_count,
+                     const iree_bitfield_string_mapping_t* mappings,
+                     iree_string_builder_t* string_builder);
 
 // Stack storage for iree_bitfield_format_inline temporary strings.
 typedef struct iree_bitfield_string_temp_t {
@@ -72,11 +73,12 @@
 //  iree_bitfield_string_temp_t temp;
 //  iree_string_view_t my_str = iree_bitfield_format_inline(
 //      MY_BITFIELD_A | MY_BITFIELD_B,
-//      my_bitfield_mappings, IREE_ARRAYSIZE(my_bitfield_mappings),
+//      IREE_ARRAYSIZE(my_bitfield_mappings), my_bitfield_mappings,
 //      &temp);
-IREE_API_EXPORT iree_string_view_t iree_bitfield_format_inline(
-    uint32_t value, const iree_bitfield_string_mapping_t* mappings,
-    iree_host_size_t mapping_count, iree_bitfield_string_temp_t* out_temp);
+IREE_API_EXPORT iree_string_view_t
+iree_bitfield_format_inline(uint32_t value, iree_host_size_t mapping_count,
+                            const iree_bitfield_string_mapping_t* mappings,
+                            iree_bitfield_string_temp_t* out_temp);
 
 #ifdef __cplusplus
 }  // extern "C"
diff --git a/runtime/src/iree/base/bitfield_test.cc b/runtime/src/iree/base/bitfield_test.cc
index c6e9356..95109ed 100644
--- a/runtime/src/iree/base/bitfield_test.cc
+++ b/runtime/src/iree/base/bitfield_test.cc
@@ -26,7 +26,7 @@
     uint32_t value,
     const iree_bitfield_string_mapping_t (&mappings)[mapping_count]) {
   iree_bitfield_string_temp_t temp;
-  auto sv = iree_bitfield_format_inline(value, mappings, mapping_count, &temp);
+  auto sv = iree_bitfield_format_inline(value, mapping_count, mappings, &temp);
   return std::string(sv.data, sv.size);
 }
 
@@ -48,7 +48,7 @@
       {0, IREE_SV("UNUSED")},
   };
   iree_bitfield_string_temp_t temp;
-  auto sv = iree_bitfield_format_inline(MY_BITFIELD_NONE, mappings, 0, &temp);
+  auto sv = iree_bitfield_format_inline(MY_BITFIELD_NONE, 0, mappings, &temp);
   EXPECT_TRUE(iree_string_view_is_empty(sv));
 }
 
diff --git a/runtime/src/iree/hal/buffer.c b/runtime/src/iree/hal/buffer.c
index 3af50a6..07139fd 100644
--- a/runtime/src/iree/hal/buffer.c
+++ b/runtime/src/iree/hal/buffer.c
@@ -34,7 +34,7 @@
       {IREE_HAL_MEMORY_TYPE_HOST_CACHED, IREE_SVL("HOST_CACHED")},
       {IREE_HAL_MEMORY_TYPE_DEVICE_VISIBLE, IREE_SVL("DEVICE_VISIBLE")},
   };
-  return iree_bitfield_format_inline(value, mappings, IREE_ARRAYSIZE(mappings),
+  return iree_bitfield_format_inline(value, IREE_ARRAYSIZE(mappings), mappings,
                                      out_temp);
 }
 
@@ -51,7 +51,7 @@
       {IREE_HAL_MEMORY_ACCESS_MAY_ALIAS, IREE_SVL("MAY_ALIAS")},
       {IREE_HAL_MEMORY_ACCESS_ANY, IREE_SVL("ANY")},
   };
-  return iree_bitfield_format_inline(value, mappings, IREE_ARRAYSIZE(mappings),
+  return iree_bitfield_format_inline(value, IREE_ARRAYSIZE(mappings), mappings,
                                      out_temp);
 }
 
@@ -65,7 +65,7 @@
       {IREE_HAL_BUFFER_USAGE_MAPPING, IREE_SVL("MAPPING")},
       {IREE_HAL_BUFFER_USAGE_DISPATCH, IREE_SVL("DISPATCH")},
   };
-  return iree_bitfield_format_inline(value, mappings, IREE_ARRAYSIZE(mappings),
+  return iree_bitfield_format_inline(value, IREE_ARRAYSIZE(mappings), mappings,
                                      out_temp);
 }
 
diff --git a/runtime/src/iree/hal/buffer_view.c b/runtime/src/iree/hal/buffer_view.c
index c338235..dc71644 100644
--- a/runtime/src/iree/hal/buffer_view.c
+++ b/runtime/src/iree/hal/buffer_view.c
@@ -24,8 +24,8 @@
 };
 
 IREE_API_EXPORT iree_status_t iree_hal_buffer_view_create(
-    iree_hal_buffer_t* buffer, const iree_hal_dim_t* shape,
-    iree_host_size_t shape_rank, iree_hal_element_type_t element_type,
+    iree_hal_buffer_t* buffer, iree_host_size_t shape_rank,
+    const iree_hal_dim_t* shape, iree_hal_element_type_t element_type,
     iree_hal_encoding_type_t encoding_type, iree_allocator_t host_allocator,
     iree_hal_buffer_view_t** out_buffer_view) {
   IREE_ASSERT_ARGUMENT(buffer);
@@ -214,22 +214,22 @@
 }
 
 IREE_API_EXPORT iree_status_t iree_hal_buffer_view_compute_offset(
-    const iree_hal_buffer_view_t* buffer_view, const iree_hal_dim_t* indices,
-    iree_host_size_t indices_count, iree_device_size_t* out_offset) {
+    const iree_hal_buffer_view_t* buffer_view, iree_host_size_t indices_count,
+    const iree_hal_dim_t* indices, iree_device_size_t* out_offset) {
   IREE_ASSERT_ARGUMENT(buffer_view);
   return iree_hal_buffer_compute_view_offset(
-      buffer_view->shape, buffer_view->shape_rank, buffer_view->element_type,
-      buffer_view->encoding_type, indices, indices_count, out_offset);
+      buffer_view->shape_rank, buffer_view->shape, buffer_view->element_type,
+      buffer_view->encoding_type, indices_count, indices, out_offset);
 }
 
 IREE_API_EXPORT iree_status_t iree_hal_buffer_view_compute_range(
-    const iree_hal_buffer_view_t* buffer_view,
-    const iree_hal_dim_t* start_indices, iree_host_size_t indices_count,
-    const iree_hal_dim_t* lengths, iree_host_size_t lengths_count,
-    iree_device_size_t* out_start_offset, iree_device_size_t* out_length) {
+    const iree_hal_buffer_view_t* buffer_view, iree_host_size_t indices_count,
+    const iree_hal_dim_t* start_indices, iree_host_size_t lengths_count,
+    const iree_hal_dim_t* lengths, iree_device_size_t* out_start_offset,
+    iree_device_size_t* out_length) {
   IREE_ASSERT_ARGUMENT(buffer_view);
   return iree_hal_buffer_compute_view_range(
-      buffer_view->shape, buffer_view->shape_rank, buffer_view->element_type,
-      buffer_view->encoding_type, start_indices, indices_count, lengths,
-      lengths_count, out_start_offset, out_length);
+      buffer_view->shape_rank, buffer_view->shape, buffer_view->element_type,
+      buffer_view->encoding_type, indices_count, start_indices, lengths_count,
+      lengths, out_start_offset, out_length);
 }
diff --git a/runtime/src/iree/hal/buffer_view.h b/runtime/src/iree/hal/buffer_view.h
index e802003..6f648cd 100644
--- a/runtime/src/iree/hal/buffer_view.h
+++ b/runtime/src/iree/hal/buffer_view.h
@@ -170,8 +170,8 @@
 // Creates a buffer view with the given |buffer|.
 // |out_buffer_view| must be released by the caller.
 IREE_API_EXPORT iree_status_t iree_hal_buffer_view_create(
-    iree_hal_buffer_t* buffer, const iree_hal_dim_t* shape,
-    iree_host_size_t shape_rank, iree_hal_element_type_t element_type,
+    iree_hal_buffer_t* buffer, iree_host_size_t shape_rank,
+    const iree_hal_dim_t* shape, iree_hal_element_type_t element_type,
     iree_hal_encoding_type_t encoding_type, iree_allocator_t host_allocator,
     iree_hal_buffer_view_t** out_buffer_view);
 
@@ -248,16 +248,16 @@
 // Calculates a byte offset into the |buffer_view| at the given indices.
 // Requires that the encoding and element type support indexing.
 IREE_API_EXPORT iree_status_t iree_hal_buffer_view_compute_offset(
-    const iree_hal_buffer_view_t* buffer_view, const iree_hal_dim_t* indices,
-    iree_host_size_t indices_count, iree_device_size_t* out_offset);
+    const iree_hal_buffer_view_t* buffer_view, iree_host_size_t indices_count,
+    const iree_hal_dim_t* indices, iree_device_size_t* out_offset);
 
 // Calculates a byte range into the |buffer_view| of the given contiguous range.
 // Requires that the encoding and element type support indexing.
 IREE_API_EXPORT iree_status_t iree_hal_buffer_view_compute_range(
-    const iree_hal_buffer_view_t* buffer_view,
-    const iree_hal_dim_t* start_indices, iree_host_size_t indices_count,
-    const iree_hal_dim_t* lengths, iree_host_size_t lengths_count,
-    iree_device_size_t* out_start_offset, iree_device_size_t* out_length);
+    const iree_hal_buffer_view_t* buffer_view, iree_host_size_t indices_count,
+    const iree_hal_dim_t* start_indices, iree_host_size_t lengths_count,
+    const iree_hal_dim_t* lengths, iree_device_size_t* out_start_offset,
+    iree_device_size_t* out_length);
 
 //===----------------------------------------------------------------------===//
 // iree_hal_buffer_view_t implementation details
diff --git a/runtime/src/iree/hal/buffer_view_util.c b/runtime/src/iree/hal/buffer_view_util.c
index d403375..89add92 100644
--- a/runtime/src/iree/hal/buffer_view_util.c
+++ b/runtime/src/iree/hal/buffer_view_util.c
@@ -20,7 +20,7 @@
 //===----------------------------------------------------------------------===//
 
 IREE_API_EXPORT iree_status_t iree_hal_buffer_compute_view_size(
-    const iree_hal_dim_t* shape, iree_host_size_t shape_rank,
+    iree_host_size_t shape_rank, const iree_hal_dim_t* shape,
     iree_hal_element_type_t element_type,
     iree_hal_encoding_type_t encoding_type,
     iree_device_size_t* out_allocation_size) {
@@ -54,12 +54,12 @@
 }
 
 IREE_API_EXPORT iree_status_t iree_hal_buffer_compute_view_offset(
-    const iree_hal_dim_t* shape, iree_host_size_t shape_rank,
+    iree_host_size_t shape_rank, const iree_hal_dim_t* shape,
     iree_hal_element_type_t element_type,
-    iree_hal_encoding_type_t encoding_type, const iree_hal_dim_t* indices,
-    iree_host_size_t indices_count, iree_device_size_t* out_offset) {
-  IREE_ASSERT_ARGUMENT(shape);
-  IREE_ASSERT_ARGUMENT(indices);
+    iree_hal_encoding_type_t encoding_type, iree_host_size_t indices_count,
+    const iree_hal_dim_t* indices, iree_device_size_t* out_offset) {
+  IREE_ASSERT_ARGUMENT(!shape_rank || shape);
+  IREE_ASSERT_ARGUMENT(!indices_count || indices);
   IREE_ASSERT_ARGUMENT(out_offset);
   *out_offset = 0;
   if (IREE_UNLIKELY(encoding_type != IREE_HAL_ENCODING_TYPE_DENSE_ROW_MAJOR)) {
@@ -98,15 +98,15 @@
 }
 
 IREE_API_EXPORT iree_status_t iree_hal_buffer_compute_view_range(
-    const iree_hal_dim_t* shape, iree_host_size_t shape_rank,
+    iree_host_size_t shape_rank, const iree_hal_dim_t* shape,
     iree_hal_element_type_t element_type,
-    iree_hal_encoding_type_t encoding_type, const iree_hal_dim_t* start_indices,
-    iree_host_size_t indices_count, const iree_hal_dim_t* lengths,
-    iree_host_size_t lengths_count, iree_device_size_t* out_start_offset,
+    iree_hal_encoding_type_t encoding_type, iree_host_size_t indices_count,
+    const iree_hal_dim_t* start_indices, iree_host_size_t lengths_count,
+    const iree_hal_dim_t* lengths, iree_device_size_t* out_start_offset,
     iree_device_size_t* out_length) {
-  IREE_ASSERT_ARGUMENT(shape);
-  IREE_ASSERT_ARGUMENT(start_indices);
-  IREE_ASSERT_ARGUMENT(lengths);
+  IREE_ASSERT_ARGUMENT(!shape_rank || shape);
+  IREE_ASSERT_ARGUMENT(!indices_count || start_indices);
+  IREE_ASSERT_ARGUMENT(!lengths_count || lengths);
   IREE_ASSERT_ARGUMENT(out_start_offset);
   IREE_ASSERT_ARGUMENT(out_length);
   *out_start_offset = 0;
@@ -142,11 +142,11 @@
 
   iree_device_size_t start_byte_offset = 0;
   IREE_RETURN_IF_ERROR(iree_hal_buffer_compute_view_offset(
-      shape, shape_rank, element_type, encoding_type, start_indices,
-      indices_count, &start_byte_offset));
+      shape_rank, shape, element_type, encoding_type, shape_rank, start_indices,
+      &start_byte_offset));
   iree_device_size_t end_byte_offset = 0;
   IREE_RETURN_IF_ERROR(iree_hal_buffer_compute_view_offset(
-      shape, shape_rank, element_type, encoding_type, end_indices, shape_rank,
+      shape_rank, shape, element_type, encoding_type, shape_rank, end_indices,
       &end_byte_offset));
 
   // Non-contiguous regions not yet implemented. Will be easier to detect when
@@ -169,8 +169,8 @@
 //===----------------------------------------------------------------------===//
 
 IREE_API_EXPORT iree_status_t iree_hal_buffer_view_allocate_buffer(
-    iree_hal_allocator_t* allocator, const iree_hal_dim_t* shape,
-    iree_host_size_t shape_rank, iree_hal_element_type_t element_type,
+    iree_hal_allocator_t* allocator, iree_host_size_t shape_rank,
+    const iree_hal_dim_t* shape, iree_hal_element_type_t element_type,
     iree_hal_encoding_type_t encoding_type,
     iree_hal_buffer_params_t buffer_params, iree_const_byte_span_t initial_data,
     iree_hal_buffer_view_t** out_buffer_view) {
@@ -181,7 +181,7 @@
 
   iree_device_size_t allocation_size = 0;
   iree_status_t status = iree_hal_buffer_compute_view_size(
-      shape, shape_rank, element_type, encoding_type, &allocation_size);
+      shape_rank, shape, element_type, encoding_type, &allocation_size);
 
   iree_hal_buffer_t* buffer = NULL;
   if (iree_status_is_ok(status)) {
@@ -191,7 +191,7 @@
 
   if (iree_status_is_ok(status)) {
     status = iree_hal_buffer_view_create(
-        buffer, shape, shape_rank, element_type, encoding_type,
+        buffer, shape_rank, shape, element_type, encoding_type,
         iree_hal_allocator_host_allocator(allocator), out_buffer_view);
   }
 
@@ -201,8 +201,8 @@
 }
 
 static iree_status_t iree_hal_buffer_view_generate_buffer_in_situ(
-    iree_hal_allocator_t* allocator, const iree_hal_dim_t* shape,
-    iree_host_size_t shape_rank, iree_hal_element_type_t element_type,
+    iree_hal_allocator_t* allocator, iree_host_size_t shape_rank,
+    const iree_hal_dim_t* shape, iree_hal_element_type_t element_type,
     iree_hal_encoding_type_t encoding_type,
     iree_hal_buffer_params_t buffer_params,
     iree_hal_buffer_view_generator_callback_t callback, void* user_data,
@@ -211,7 +211,7 @@
   // type and the mapping bits.
   iree_hal_buffer_view_t* buffer_view = NULL;
   IREE_RETURN_IF_ERROR(iree_hal_buffer_view_allocate_buffer(
-      allocator, shape, shape_rank, element_type, encoding_type,
+      allocator, shape_rank, shape, element_type, encoding_type,
       iree_hal_buffer_params_with_usage(buffer_params,
                                         IREE_HAL_BUFFER_USAGE_MAPPING),
       iree_const_byte_span_empty(), &buffer_view));
@@ -239,8 +239,8 @@
 }
 
 static iree_status_t iree_hal_buffer_view_generate_buffer_on_host(
-    iree_hal_allocator_t* allocator, const iree_hal_dim_t* shape,
-    iree_host_size_t shape_rank, iree_hal_element_type_t element_type,
+    iree_hal_allocator_t* allocator, iree_host_size_t shape_rank,
+    const iree_hal_dim_t* shape, iree_hal_element_type_t element_type,
     iree_hal_encoding_type_t encoding_type,
     iree_hal_buffer_params_t buffer_params, iree_device_size_t allocation_size,
     iree_hal_buffer_view_generator_callback_t callback, void* user_data,
@@ -264,7 +264,7 @@
   // We could try importing but that may create buffers that are slower to
   // access and we want users to opt in to that instead.
   status = iree_hal_buffer_view_allocate_buffer(
-      allocator, shape, shape_rank, element_type, encoding_type, buffer_params,
+      allocator, shape_rank, shape, element_type, encoding_type, buffer_params,
       iree_make_const_byte_span(host_ptr, allocation_size), out_buffer_view);
 
   iree_allocator_free(host_allocator, host_ptr);
@@ -272,8 +272,8 @@
 }
 
 IREE_API_EXPORT iree_status_t iree_hal_buffer_view_generate_buffer(
-    iree_hal_allocator_t* allocator, const iree_hal_dim_t* shape,
-    iree_host_size_t shape_rank, iree_hal_element_type_t element_type,
+    iree_hal_allocator_t* allocator, iree_host_size_t shape_rank,
+    const iree_hal_dim_t* shape, iree_hal_element_type_t element_type,
     iree_hal_encoding_type_t encoding_type,
     iree_hal_buffer_params_t buffer_params,
     iree_hal_buffer_view_generator_callback_t callback, void* user_data,
@@ -287,7 +287,7 @@
   // Compute how large of an allocation we need to hold the whole view.
   iree_device_size_t allocation_size = 0;
   IREE_RETURN_AND_END_ZONE_IF_ERROR(
-      z0, iree_hal_buffer_compute_view_size(shape, shape_rank, element_type,
+      z0, iree_hal_buffer_compute_view_size(shape_rank, shape, element_type,
                                             encoding_type, &allocation_size));
 
   // If we can create the requested memory type with mapping then we'll do that
@@ -307,12 +307,12 @@
   if (is_mappable) {
     // Compatible with allocate -> map -> generate.
     status = iree_hal_buffer_view_generate_buffer_in_situ(
-        allocator, shape, shape_rank, element_type, encoding_type,
+        allocator, shape_rank, shape, element_type, encoding_type,
         mappable_params, callback, user_data, out_buffer_view);
   } else {
     // Allocate host-local memory first and generate into that.
     status = iree_hal_buffer_view_generate_buffer_on_host(
-        allocator, shape, shape_rank, element_type, encoding_type,
+        allocator, shape_rank, shape, element_type, encoding_type,
         buffer_params, allocation_size, callback, user_data, out_buffer_view);
   }
 
@@ -373,7 +373,7 @@
   // AxBxC...
   iree_host_size_t shape_rank = 0;
   iree_status_t shape_result =
-      iree_hal_parse_shape(shape_str, 0, NULL, &shape_rank);
+      iree_hal_parse_shape(shape_str, 0, &shape_rank, NULL);
   if (!iree_status_is_ok(shape_result) &&
       !iree_status_is_out_of_range(shape_result)) {
     return shape_result;
@@ -386,7 +386,7 @@
   iree_hal_dim_t* shape =
       (iree_hal_dim_t*)iree_alloca(shape_rank * sizeof(iree_hal_dim_t));
   IREE_RETURN_IF_ERROR(
-      iree_hal_parse_shape(shape_str, shape_rank, shape, &shape_rank));
+      iree_hal_parse_shape(shape_str, shape_rank, &shape_rank, shape));
 
   // f32, i32, etc
   iree_hal_element_type_t element_type = IREE_HAL_ELEMENT_TYPE_NONE;
@@ -406,7 +406,7 @@
       .element_type = element_type,
   };
   return iree_hal_buffer_view_generate_buffer(
-      buffer_allocator, shape, shape_rank, element_type, encoding_type,
+      buffer_allocator, shape_rank, shape, element_type, encoding_type,
       buffer_params, iree_hal_buffer_view_parse_into, &parse_params,
       out_buffer_view);
 }
@@ -453,8 +453,8 @@
     // Shape: 1x2x3
     iree_host_size_t shape_length = 0;
     iree_status_t status = iree_hal_format_shape(
-        iree_hal_buffer_view_shape_dims(buffer_view),
         iree_hal_buffer_view_shape_rank(buffer_view),
+        iree_hal_buffer_view_shape_dims(buffer_view),
         buffer ? buffer_capacity - buffer_length : 0,
         buffer ? buffer + buffer_length : NULL, &shape_length);
     buffer_length += shape_length;
@@ -497,8 +497,8 @@
   status = iree_hal_format_buffer_elements(
       iree_make_const_byte_span(buffer_mapping.contents.data,
                                 buffer_mapping.contents.data_length),
-      iree_hal_buffer_view_shape_dims(buffer_view),
       iree_hal_buffer_view_shape_rank(buffer_view),
+      iree_hal_buffer_view_shape_dims(buffer_view),
       iree_hal_buffer_view_element_type(buffer_view), max_element_count,
       buffer ? buffer_capacity - buffer_length : 0,
       buffer ? buffer + buffer_length : NULL, &elements_length);
diff --git a/runtime/src/iree/hal/buffer_view_util.h b/runtime/src/iree/hal/buffer_view_util.h
index a7d7f61..19c0077 100644
--- a/runtime/src/iree/hal/buffer_view_util.h
+++ b/runtime/src/iree/hal/buffer_view_util.h
@@ -25,7 +25,7 @@
 
 // Calculates the allocation size of a buffer view.
 IREE_API_EXPORT iree_status_t iree_hal_buffer_compute_view_size(
-    const iree_hal_dim_t* shape, iree_host_size_t shape_rank,
+    iree_host_size_t shape_rank, const iree_hal_dim_t* shape,
     iree_hal_element_type_t element_type,
     iree_hal_encoding_type_t encoding_type,
     iree_device_size_t* out_allocation_size);
@@ -33,19 +33,19 @@
 // Calculates a byte offset into a buffer at the given indices.
 // Only works with densely-packed representations.
 IREE_API_EXPORT iree_status_t iree_hal_buffer_compute_view_offset(
-    const iree_hal_dim_t* shape, iree_host_size_t shape_rank,
+    iree_host_size_t shape_rank, const iree_hal_dim_t* shape,
     iree_hal_element_type_t element_type,
-    iree_hal_encoding_type_t encoding_type, const iree_hal_dim_t* indices,
-    size_t indices_count, iree_device_size_t* out_offset);
+    iree_hal_encoding_type_t encoding_type, iree_host_size_t indices_count,
+    const iree_hal_dim_t* indices, iree_device_size_t* out_offset);
 
 // Calculates a byte range into a buffer of the given contiguous range.
 // Only works with densely-packed representations.
 IREE_API_EXPORT iree_status_t iree_hal_buffer_compute_view_range(
-    const iree_hal_dim_t* shape, iree_host_size_t shape_rank,
+    iree_host_size_t shape_rank, const iree_hal_dim_t* shape,
     iree_hal_element_type_t element_type,
-    iree_hal_encoding_type_t encoding_type, const iree_hal_dim_t* start_indices,
-    iree_host_size_t indices_count, const iree_hal_dim_t* lengths,
-    iree_host_size_t lengths_count, iree_device_size_t* out_start_offset,
+    iree_hal_encoding_type_t encoding_type, iree_host_size_t indices_count,
+    const iree_hal_dim_t* start_indices, iree_host_size_t lengths_count,
+    const iree_hal_dim_t* lengths, iree_device_size_t* out_start_offset,
     iree_device_size_t* out_length);
 
 //===----------------------------------------------------------------------===//
@@ -59,8 +59,8 @@
 //   2. iree_hal_allocator_allocate_buffer
 //   3. iree_hal_buffer_view_create
 IREE_API_EXPORT iree_status_t iree_hal_buffer_view_allocate_buffer(
-    iree_hal_allocator_t* allocator, const iree_hal_dim_t* shape,
-    iree_host_size_t shape_rank, iree_hal_element_type_t element_type,
+    iree_hal_allocator_t* allocator, iree_host_size_t shape_rank,
+    const iree_hal_dim_t* shape, iree_hal_element_type_t element_type,
     iree_hal_encoding_type_t encoding_type,
     iree_hal_buffer_params_t buffer_params, iree_const_byte_span_t initial_data,
     iree_hal_buffer_view_t** out_buffer_view);
@@ -91,8 +91,8 @@
 //   3. iree_hal_buffer_map_range + callback + iree_hal_buffer_unmap_range
 //   4. iree_hal_buffer_view_create
 IREE_API_EXPORT iree_status_t iree_hal_buffer_view_generate_buffer(
-    iree_hal_allocator_t* allocator, const iree_hal_dim_t* shape,
-    iree_host_size_t shape_rank, iree_hal_element_type_t element_type,
+    iree_hal_allocator_t* allocator, iree_host_size_t shape_rank,
+    const iree_hal_dim_t* shape, iree_hal_element_type_t element_type,
     iree_hal_encoding_type_t encoding_type,
     iree_hal_buffer_params_t buffer_params,
     iree_hal_buffer_view_generator_callback_t callback, void* user_data,
diff --git a/runtime/src/iree/hal/command_buffer.c b/runtime/src/iree/hal/command_buffer.c
index e4c7fdf..aeeffae 100644
--- a/runtime/src/iree/hal/command_buffer.c
+++ b/runtime/src/iree/hal/command_buffer.c
@@ -43,7 +43,7 @@
        IREE_SVL("ALLOW_INLINE_EXECUTION")},
       {IREE_HAL_COMMAND_BUFFER_MODE_UNVALIDATED, IREE_SVL("UNVALIDATED")},
   };
-  return iree_bitfield_format_inline(value, mappings, IREE_ARRAYSIZE(mappings),
+  return iree_bitfield_format_inline(value, IREE_ARRAYSIZE(mappings), mappings,
                                      out_temp);
 }
 
@@ -56,7 +56,7 @@
       {IREE_HAL_COMMAND_CATEGORY_TRANSFER, IREE_SVL("TRANSFER")},
       {IREE_HAL_COMMAND_CATEGORY_DISPATCH, IREE_SVL("DISPATCH")},
   };
-  return iree_bitfield_format_inline(value, mappings, IREE_ARRAYSIZE(mappings),
+  return iree_bitfield_format_inline(value, IREE_ARRAYSIZE(mappings), mappings,
                                      out_temp);
 }
 
diff --git a/runtime/src/iree/hal/cts/command_buffer_dispatch_test.h b/runtime/src/iree/hal/cts/command_buffer_dispatch_test.h
index d30b5d0..370033f 100644
--- a/runtime/src/iree/hal/cts/command_buffer_dispatch_test.h
+++ b/runtime/src/iree/hal/cts/command_buffer_dispatch_test.h
@@ -89,8 +89,8 @@
   iree_hal_buffer_view_t* input_buffer_view = NULL;
   float input_data[1] = {-2.5f};
   IREE_ASSERT_OK(iree_hal_buffer_view_allocate_buffer(
-      device_allocator_, /*shape=*/NULL,
-      /*shape_rank=*/0, IREE_HAL_ELEMENT_TYPE_FLOAT_32,
+      device_allocator_,
+      /*shape_rank=*/0, /*shape=*/NULL, IREE_HAL_ELEMENT_TYPE_FLOAT_32,
       IREE_HAL_ENCODING_TYPE_DENSE_ROW_MAJOR, input_params,
       iree_make_const_byte_span((void*)input_data, sizeof(input_data)),
       &input_buffer_view));
diff --git a/runtime/src/iree/hal/cts/driver_test.h b/runtime/src/iree/hal/cts/driver_test.h
index 10796eb..88bb648 100644
--- a/runtime/src/iree/hal/cts/driver_test.h
+++ b/runtime/src/iree/hal/cts/driver_test.h
@@ -23,10 +23,10 @@
 class driver_test : public CtsTestBase {};
 
 TEST_P(driver_test, QueryAndCreateAvailableDevices) {
+  iree_host_size_t device_info_count = 0;
   iree_hal_device_info_t* device_infos = NULL;
-  iree_host_size_t device_info_count;
   IREE_ASSERT_OK(iree_hal_driver_query_available_devices(
-      driver_, iree_allocator_system(), &device_infos, &device_info_count));
+      driver_, iree_allocator_system(), &device_info_count, &device_infos));
 
   std::cout << "Driver has " << device_info_count << " device(s)";
   for (iree_host_size_t i = 0; i < device_info_count; ++i) {
diff --git a/runtime/src/iree/hal/driver.c b/runtime/src/iree/hal/driver.c
index c851a89..7b72de2 100644
--- a/runtime/src/iree/hal/driver.c
+++ b/runtime/src/iree/hal/driver.c
@@ -20,15 +20,15 @@
 
 IREE_API_EXPORT iree_status_t iree_hal_driver_query_available_devices(
     iree_hal_driver_t* driver, iree_allocator_t host_allocator,
-    iree_hal_device_info_t** out_device_infos,
-    iree_host_size_t* out_device_info_count) {
+    iree_host_size_t* out_device_info_count,
+    iree_hal_device_info_t** out_device_infos) {
   IREE_ASSERT_ARGUMENT(driver);
-  IREE_ASSERT_ARGUMENT(out_device_infos);
   IREE_ASSERT_ARGUMENT(out_device_info_count);
+  IREE_ASSERT_ARGUMENT(out_device_infos);
   *out_device_info_count = 0;
   IREE_TRACE_ZONE_BEGIN(z0);
   iree_status_t status = _VTABLE_DISPATCH(driver, query_available_devices)(
-      driver, host_allocator, out_device_infos, out_device_info_count);
+      driver, host_allocator, out_device_info_count, out_device_infos);
   IREE_TRACE_ZONE_END(z0);
   return status;
 }
@@ -45,11 +45,11 @@
   IREE_TRACE_ZONE_APPEND_VALUE(z0, (uint64_t)device_ordinal);
 
   // Query the devices from the driver.
-  iree_hal_device_info_t* device_infos = NULL;
   iree_host_size_t device_info_count = 0;
+  iree_hal_device_info_t* device_infos = NULL;
   IREE_RETURN_AND_END_ZONE_IF_ERROR(
       z0, iree_hal_driver_query_available_devices(
-              driver, host_allocator, &device_infos, &device_info_count));
+              driver, host_allocator, &device_info_count, &device_infos));
 
   // Get the ID of the Nth device.
   iree_hal_device_id_t device_id = IREE_HAL_DEVICE_ID_DEFAULT;
diff --git a/runtime/src/iree/hal/driver.h b/runtime/src/iree/hal/driver.h
index 1bac743..3226a43 100644
--- a/runtime/src/iree/hal/driver.h
+++ b/runtime/src/iree/hal/driver.h
@@ -67,8 +67,8 @@
 // allocator by the caller.
 IREE_API_EXPORT iree_status_t iree_hal_driver_query_available_devices(
     iree_hal_driver_t* driver, iree_allocator_t host_allocator,
-    iree_hal_device_info_t** out_device_infos,
-    iree_host_size_t* out_device_info_count);
+    iree_host_size_t* out_device_info_count,
+    iree_hal_device_info_t** out_device_infos);
 
 // Creates a device with the given |device_ordinal| as enumerated by
 // iree_hal_driver_query_available_devices. The ordering of devices is driver
@@ -139,8 +139,8 @@
 
   iree_status_t(IREE_API_PTR* query_available_devices)(
       iree_hal_driver_t* driver, iree_allocator_t host_allocator,
-      iree_hal_device_info_t** out_device_infos,
-      iree_host_size_t* out_device_info_count);
+      iree_host_size_t* out_device_info_count,
+      iree_hal_device_info_t** out_device_infos);
 
   iree_status_t(IREE_API_PTR* create_device_by_id)(
       iree_hal_driver_t* driver, iree_hal_device_id_t device_id,
diff --git a/runtime/src/iree/hal/driver_registry.c b/runtime/src/iree/hal/driver_registry.c
index 659f45e..e5e1972 100644
--- a/runtime/src/iree/hal/driver_registry.c
+++ b/runtime/src/iree/hal/driver_registry.c
@@ -190,9 +190,11 @@
 
 IREE_API_EXPORT iree_status_t iree_hal_driver_registry_enumerate(
     iree_hal_driver_registry_t* registry, iree_allocator_t host_allocator,
-    iree_hal_driver_info_t** out_driver_infos,
-    iree_host_size_t* out_driver_info_count) {
+    iree_host_size_t* out_driver_info_count,
+    iree_hal_driver_info_t** out_driver_infos) {
   IREE_ASSERT_ARGUMENT(registry);
+  IREE_ASSERT_ARGUMENT(out_driver_info_count);
+  IREE_ASSERT_ARGUMENT(out_driver_infos);
   IREE_TRACE_ZONE_BEGIN(z0);
 
   *out_driver_info_count = 0;
@@ -210,7 +212,7 @@
     const iree_hal_driver_info_t* driver_infos = NULL;
     iree_host_size_t driver_info_count = 0;
     status =
-        factory->enumerate(factory->self, &driver_infos, &driver_info_count);
+        factory->enumerate(factory->self, &driver_info_count, &driver_infos);
     if (!iree_status_is_ok(status)) break;
     total_driver_info_count += driver_info_count;
     for (iree_host_size_t j = 0; j < driver_info_count; j++) {
@@ -241,7 +243,7 @@
       const iree_hal_driver_info_t* driver_infos = NULL;
       iree_host_size_t driver_info_count = 0;
       status =
-          factory->enumerate(factory->self, &driver_infos, &driver_info_count);
+          factory->enumerate(factory->self, &driver_info_count, &driver_infos);
       if (!iree_status_is_ok(status)) break;
       for (iree_host_size_t j = 0; j < driver_info_count; j++) {
         string_storage_ptr += iree_hal_driver_info_copy(
@@ -288,7 +290,7 @@
     const iree_hal_driver_info_t* driver_infos = NULL;
     iree_host_size_t driver_info_count = 0;
     status =
-        factory->enumerate(factory->self, &driver_infos, &driver_info_count);
+        factory->enumerate(factory->self, &driver_info_count, &driver_infos);
     if (!iree_status_is_ok(status)) break;
 
     // Scan for the specific driver by name.
diff --git a/runtime/src/iree/hal/driver_registry.h b/runtime/src/iree/hal/driver_registry.h
index 2cb4954..b040ebb 100644
--- a/runtime/src/iree/hal/driver_registry.h
+++ b/runtime/src/iree/hal/driver_registry.h
@@ -55,8 +55,8 @@
   //
   // Called with the driver registry lock held; may be called from any thread.
   iree_status_t(IREE_API_PTR* enumerate)(
-      void* self, const iree_hal_driver_info_t** out_driver_infos,
-      iree_host_size_t* out_driver_info_count);
+      void* self, iree_host_size_t* out_driver_info_count,
+      const iree_hal_driver_info_t** out_driver_infos);
 
   // Tries to create a driver as previously queried with enumerate.
   // |driver_id| is the opaque ID returned from enumeration; note that there may
@@ -135,8 +135,8 @@
 // completing and any attempt to instantiate the driver.
 IREE_API_EXPORT iree_status_t iree_hal_driver_registry_enumerate(
     iree_hal_driver_registry_t* registry, iree_allocator_t host_allocator,
-    iree_hal_driver_info_t** out_driver_infos,
-    iree_host_size_t* out_driver_info_count);
+    iree_host_size_t* out_driver_info_count,
+    iree_hal_driver_info_t** out_driver_infos);
 
 // Attempts to create a driver registered with the given canonical driver name.
 // Effectively enumerate + find by name + try_create if found. Factories are
diff --git a/runtime/src/iree/hal/drivers/cuda/cuda_driver.c b/runtime/src/iree/hal/drivers/cuda/cuda_driver.c
index dc393b3..7009e8e 100644
--- a/runtime/src/iree/hal/drivers/cuda/cuda_driver.c
+++ b/runtime/src/iree/hal/drivers/cuda/cuda_driver.c
@@ -129,8 +129,8 @@
 
 static iree_status_t iree_hal_cuda_driver_query_available_devices(
     iree_hal_driver_t* base_driver, iree_allocator_t host_allocator,
-    iree_hal_device_info_t** out_device_infos,
-    iree_host_size_t* out_device_info_count) {
+    iree_host_size_t* out_device_info_count,
+    iree_hal_device_info_t** out_device_infos) {
   iree_hal_cuda_driver_t* driver = iree_hal_cuda_driver_cast(base_driver);
   // Query the number of available CUDA devices.
   int device_count = 0;
@@ -173,10 +173,10 @@
     iree_hal_driver_t* base_driver, iree_hal_cuda_dynamic_symbols_t* syms,
     int default_device_index, iree_allocator_t host_allocator,
     CUdevice* out_device) {
-  iree_hal_device_info_t* out_device_infos;
-  iree_host_size_t device_count;
+  iree_hal_device_info_t* device_infos = NULL;
+  iree_host_size_t device_count = 0;
   IREE_RETURN_IF_ERROR(iree_hal_cuda_driver_query_available_devices(
-      base_driver, host_allocator, &out_device_infos, &device_count));
+      base_driver, host_allocator, &device_count, &device_infos));
   iree_status_t status = iree_ok_status();
   if (device_count == 0) {
     status = iree_make_status(IREE_STATUS_UNAVAILABLE,
@@ -186,9 +186,9 @@
                               "default device %d not found (of %ld enumerated)",
                               default_device_index, device_count);
   } else {
-    *out_device = (CUdevice)out_device_infos[default_device_index].device_id;
+    *out_device = (CUdevice)device_infos[default_device_index].device_id;
   }
-  iree_allocator_free(host_allocator, out_device_infos);
+  iree_allocator_free(host_allocator, device_infos);
   return status;
 }
 
diff --git a/runtime/src/iree/hal/drivers/cuda/registration/driver_module.c b/runtime/src/iree/hal/drivers/cuda/registration/driver_module.c
index cf7d1ce..f609b6d 100644
--- a/runtime/src/iree/hal/drivers/cuda/registration/driver_module.c
+++ b/runtime/src/iree/hal/drivers/cuda/registration/driver_module.c
@@ -27,8 +27,8 @@
 IREE_FLAG(int32_t, cuda_default_index, 0, "Index of the default CUDA device.");
 
 static iree_status_t iree_hal_cuda_driver_factory_enumerate(
-    void* self, const iree_hal_driver_info_t** out_driver_infos,
-    iree_host_size_t* out_driver_info_count) {
+    void* self, iree_host_size_t* out_driver_info_count,
+    const iree_hal_driver_info_t** out_driver_infos) {
   // NOTE: we could query supported cuda versions or featuresets here.
   static const iree_hal_driver_info_t driver_infos[1] = {{
       .driver_name = iree_string_view_literal("cuda"),
diff --git a/runtime/src/iree/hal/drivers/local_sync/registration/driver_module.c b/runtime/src/iree/hal/drivers/local_sync/registration/driver_module.c
index eab407d..1493d09 100644
--- a/runtime/src/iree/hal/drivers/local_sync/registration/driver_module.c
+++ b/runtime/src/iree/hal/drivers/local_sync/registration/driver_module.c
@@ -14,8 +14,8 @@
 #include "iree/hal/local/loaders/registration/init.h"
 
 static iree_status_t iree_hal_local_sync_driver_factory_enumerate(
-    void* self, const iree_hal_driver_info_t** out_driver_infos,
-    iree_host_size_t* out_driver_info_count) {
+    void* self, iree_host_size_t* out_driver_info_count,
+    const iree_hal_driver_info_t** out_driver_infos) {
   static const iree_hal_driver_info_t default_driver_info = {
       .driver_name = IREE_SVL("local-sync"),
       .full_name = IREE_SVL("Local executable execution using a lightweight "
diff --git a/runtime/src/iree/hal/drivers/local_sync/sync_driver.c b/runtime/src/iree/hal/drivers/local_sync/sync_driver.c
index 5b004a6..2071262 100644
--- a/runtime/src/iree/hal/drivers/local_sync/sync_driver.c
+++ b/runtime/src/iree/hal/drivers/local_sync/sync_driver.c
@@ -97,8 +97,8 @@
 
 static iree_status_t iree_hal_sync_driver_query_available_devices(
     iree_hal_driver_t* base_driver, iree_allocator_t host_allocator,
-    iree_hal_device_info_t** out_device_infos,
-    iree_host_size_t* out_device_info_count) {
+    iree_host_size_t* out_device_info_count,
+    iree_hal_device_info_t** out_device_infos) {
   static const iree_hal_device_info_t device_infos[1] = {
       {
           .device_id = IREE_HAL_SYNC_DEVICE_ID_DEFAULT,
diff --git a/runtime/src/iree/hal/drivers/local_task/registration/driver_module.c b/runtime/src/iree/hal/drivers/local_task/registration/driver_module.c
index 393b6bb..1504167 100644
--- a/runtime/src/iree/hal/drivers/local_task/registration/driver_module.c
+++ b/runtime/src/iree/hal/drivers/local_task/registration/driver_module.c
@@ -15,8 +15,8 @@
 #include "iree/task/api.h"
 
 static iree_status_t iree_hal_local_task_driver_factory_enumerate(
-    void* self, const iree_hal_driver_info_t** out_driver_infos,
-    iree_host_size_t* out_driver_info_count) {
+    void* self, iree_host_size_t* out_driver_info_count,
+    const iree_hal_driver_info_t** out_driver_infos) {
   static const iree_hal_driver_info_t driver_infos[1] = {
       {
           .driver_name = IREE_SVL("local-task"),
diff --git a/runtime/src/iree/hal/drivers/local_task/task_driver.c b/runtime/src/iree/hal/drivers/local_task/task_driver.c
index 3051763..7475529 100644
--- a/runtime/src/iree/hal/drivers/local_task/task_driver.c
+++ b/runtime/src/iree/hal/drivers/local_task/task_driver.c
@@ -103,8 +103,8 @@
 
 static iree_status_t iree_hal_task_driver_query_available_devices(
     iree_hal_driver_t* base_driver, iree_allocator_t host_allocator,
-    iree_hal_device_info_t** out_device_infos,
-    iree_host_size_t* out_device_info_count) {
+    iree_host_size_t* out_device_info_count,
+    iree_hal_device_info_t** out_device_infos) {
   static const iree_hal_device_info_t device_infos[1] = {
       {
           .device_id = IREE_HAL_TASK_DEVICE_ID_DEFAULT,
diff --git a/runtime/src/iree/hal/drivers/vulkan/api.h b/runtime/src/iree/hal/drivers/vulkan/api.h
index 927f196..f81acc3 100644
--- a/runtime/src/iree/hal/drivers/vulkan/api.h
+++ b/runtime/src/iree/hal/drivers/vulkan/api.h
@@ -102,7 +102,7 @@
 IREE_API_EXPORT iree_status_t iree_hal_vulkan_query_extensibility_set(
     iree_hal_vulkan_features_t requested_features,
     iree_hal_vulkan_extensibility_set_t set, iree_host_size_t string_capacity,
-    const char** out_string_values, iree_host_size_t* out_string_count);
+    iree_host_size_t* out_string_count, const char** out_string_values);
 
 //===----------------------------------------------------------------------===//
 // iree_hal_vulkan_syms_t
diff --git a/runtime/src/iree/hal/drivers/vulkan/registration/driver_module.cc b/runtime/src/iree/hal/drivers/vulkan/registration/driver_module.cc
index b4dce37..32026e0 100644
--- a/runtime/src/iree/hal/drivers/vulkan/registration/driver_module.cc
+++ b/runtime/src/iree/hal/drivers/vulkan/registration/driver_module.cc
@@ -73,8 +73,8 @@
 }
 
 static iree_status_t iree_hal_vulkan_driver_factory_enumerate(
-    void* self, const iree_hal_driver_info_t** out_driver_infos,
-    iree_host_size_t* out_driver_info_count) {
+    void* self, iree_host_size_t* out_driver_info_count,
+    const iree_hal_driver_info_t** out_driver_infos) {
   // NOTE: we could query supported vulkan versions or featuresets here.
   static const iree_hal_driver_info_t driver_infos[1] = {{
       /*driver_name=*/iree_make_cstring_view("vulkan"),
diff --git a/runtime/src/iree/hal/drivers/vulkan/vulkan_device.cc b/runtime/src/iree/hal/drivers/vulkan/vulkan_device.cc
index 0f294b5..d274423 100644
--- a/runtime/src/iree/hal/drivers/vulkan/vulkan_device.cc
+++ b/runtime/src/iree/hal/drivers/vulkan/vulkan_device.cc
@@ -45,7 +45,7 @@
 IREE_API_EXPORT iree_status_t iree_hal_vulkan_query_extensibility_set(
     iree_hal_vulkan_features_t requested_features,
     iree_hal_vulkan_extensibility_set_t set, iree_host_size_t string_capacity,
-    const char** out_string_values, iree_host_size_t* out_string_count) {
+    iree_host_size_t* out_string_count, const char** out_string_values) {
   *out_string_count = 0;
 
   iree_status_t status = iree_ok_status();
@@ -676,12 +676,12 @@
     iree_hal_vulkan_extensibility_set_t set, iree::Arena* arena,
     iree_hal_vulkan_string_list_t* out_string_list) {
   IREE_RETURN_IF_ERROR(iree_hal_vulkan_query_extensibility_set(
-      requested_features, set, 0, NULL, &out_string_list->count));
+      requested_features, set, 0, &out_string_list->count, NULL));
   out_string_list->values = (const char**)arena->AllocateBytes(
       out_string_list->count * sizeof(out_string_list->values[0]));
   IREE_RETURN_IF_ERROR(iree_hal_vulkan_query_extensibility_set(
-      requested_features, set, out_string_list->count, out_string_list->values,
-      &out_string_list->count));
+      requested_features, set, out_string_list->count, &out_string_list->count,
+      out_string_list->values));
   return iree_ok_status();
 }
 
diff --git a/runtime/src/iree/hal/drivers/vulkan/vulkan_driver.cc b/runtime/src/iree/hal/drivers/vulkan/vulkan_driver.cc
index 405bd38..949899a 100644
--- a/runtime/src/iree/hal/drivers/vulkan/vulkan_driver.cc
+++ b/runtime/src/iree/hal/drivers/vulkan/vulkan_driver.cc
@@ -158,12 +158,12 @@
     iree_hal_vulkan_extensibility_set_t set, iree::Arena* arena,
     iree_hal_vulkan_string_list_t* out_string_list) {
   IREE_RETURN_IF_ERROR(iree_hal_vulkan_query_extensibility_set(
-      requested_features, set, 0, NULL, &out_string_list->count));
+      requested_features, set, 0, &out_string_list->count, NULL));
   out_string_list->values = (const char**)arena->AllocateBytes(
       out_string_list->count * sizeof(out_string_list->values[0]));
   IREE_RETURN_IF_ERROR(iree_hal_vulkan_query_extensibility_set(
-      requested_features, set, out_string_list->count, out_string_list->values,
-      &out_string_list->count));
+      requested_features, set, out_string_list->count, &out_string_list->count,
+      out_string_list->values));
   return iree_ok_status();
 }
 
@@ -377,8 +377,8 @@
 
 static iree_status_t iree_hal_vulkan_driver_query_available_devices(
     iree_hal_driver_t* base_driver, iree_allocator_t host_allocator,
-    iree_hal_device_info_t** out_device_infos,
-    iree_host_size_t* out_device_info_count) {
+    iree_host_size_t* out_device_info_count,
+    iree_hal_device_info_t** out_device_infos) {
   iree_hal_vulkan_driver_t* driver = iree_hal_vulkan_driver_cast(base_driver);
 
   // Query all devices from the Vulkan instance.
diff --git a/runtime/src/iree/hal/local/loaders/vmvx_module_loader.c b/runtime/src/iree/hal/local/loaders/vmvx_module_loader.c
index 7a3bb53..333ab8c 100644
--- a/runtime/src/iree/hal/local/loaders/vmvx_module_loader.c
+++ b/runtime/src/iree/hal/local/loaders/vmvx_module_loader.c
@@ -562,8 +562,9 @@
         bytecode_module,
     };
     status = iree_vm_context_create_with_modules(
-        executable_loader->instance, IREE_VM_CONTEXT_FLAG_NONE, modules,
-        IREE_ARRAYSIZE(modules), executable_loader->host_allocator, &context);
+        executable_loader->instance, IREE_VM_CONTEXT_FLAG_NONE,
+        IREE_ARRAYSIZE(modules), modules, executable_loader->host_allocator,
+        &context);
   }
 
   // Executable takes ownership of the entire context (including the bytecode
diff --git a/runtime/src/iree/hal/string_util.c b/runtime/src/iree/hal/string_util.c
index d9a662c..cd8275b 100644
--- a/runtime/src/iree/hal/string_util.c
+++ b/runtime/src/iree/hal/string_util.c
@@ -20,7 +20,7 @@
 
 IREE_API_EXPORT iree_status_t iree_hal_parse_shape(
     iree_string_view_t value, iree_host_size_t shape_capacity,
-    iree_hal_dim_t* out_shape, iree_host_size_t* out_shape_rank) {
+    iree_host_size_t* out_shape_rank, iree_hal_dim_t* out_shape) {
   IREE_ASSERT_ARGUMENT(out_shape_rank);
   *out_shape_rank = 0;
 
@@ -79,7 +79,7 @@
 }
 
 IREE_API_EXPORT iree_status_t
-iree_hal_format_shape(const iree_hal_dim_t* shape, iree_host_size_t shape_rank,
+iree_hal_format_shape(iree_host_size_t shape_rank, const iree_hal_dim_t* shape,
                       iree_host_size_t buffer_capacity, char* buffer,
                       iree_host_size_t* out_buffer_length) {
   if (out_buffer_length) {
@@ -185,7 +185,7 @@
 
 IREE_API_EXPORT iree_status_t iree_hal_parse_shape_and_element_type(
     iree_string_view_t value, iree_host_size_t shape_capacity,
-    iree_hal_dim_t* out_shape, iree_host_size_t* out_shape_rank,
+    iree_host_size_t* out_shape_rank, iree_hal_dim_t* out_shape,
     iree_hal_element_type_t* out_element_type) {
   *out_shape_rank = 0;
   *out_element_type = IREE_HAL_ELEMENT_TYPE_NONE;
@@ -223,7 +223,7 @@
 
   // AxBxC...
   IREE_RETURN_IF_ERROR(iree_hal_parse_shape(shape_str, shape_capacity,
-                                            out_shape, out_shape_rank));
+                                            out_shape_rank, out_shape));
 
   // f32, i32, etc
   IREE_RETURN_IF_ERROR(iree_hal_parse_element_type(type_str, out_element_type));
@@ -553,8 +553,8 @@
   }
 
 static iree_status_t iree_hal_format_buffer_elements_recursive(
-    iree_const_byte_span_t data, const iree_hal_dim_t* shape,
-    iree_host_size_t shape_rank, iree_hal_element_type_t element_type,
+    iree_const_byte_span_t data, iree_host_size_t shape_rank,
+    const iree_hal_dim_t* shape, iree_hal_element_type_t element_type,
     iree_host_size_t* max_element_count, iree_host_size_t buffer_capacity,
     char* buffer, iree_host_size_t* out_buffer_length) {
   iree_host_size_t buffer_length = 0;
@@ -562,7 +562,7 @@
     // Scalar value; recurse to get on to the leaf dimension path.
     const iree_hal_dim_t one = 1;
     return iree_hal_format_buffer_elements_recursive(
-        data, &one, 1, element_type, max_element_count, buffer_capacity, buffer,
+        data, 1, &one, element_type, max_element_count, buffer_capacity, buffer,
         out_buffer_length);
   } else if (shape_rank > 1) {
     // Nested dimension; recurse into the next innermost dimension.
@@ -585,7 +585,7 @@
       APPEND_CHAR('[');
       iree_host_size_t actual_length = 0;
       iree_status_t status = iree_hal_format_buffer_elements_recursive(
-          subdata, shape + 1, shape_rank - 1, element_type, max_element_count,
+          subdata, shape_rank - 1, shape + 1, element_type, max_element_count,
           buffer ? buffer_capacity - buffer_length : 0,
           buffer ? buffer + buffer_length : NULL, &actual_length);
       buffer_length += actual_length;
@@ -641,8 +641,8 @@
 }
 
 IREE_API_EXPORT iree_status_t iree_hal_format_buffer_elements(
-    iree_const_byte_span_t data, const iree_hal_dim_t* shape,
-    iree_host_size_t shape_rank, iree_hal_element_type_t element_type,
+    iree_const_byte_span_t data, iree_host_size_t shape_rank,
+    const iree_hal_dim_t* shape, iree_hal_element_type_t element_type,
     iree_host_size_t max_element_count, iree_host_size_t buffer_capacity,
     char* buffer, iree_host_size_t* out_buffer_length) {
   if (out_buffer_length) {
@@ -652,6 +652,6 @@
     buffer[0] = '\0';
   }
   return iree_hal_format_buffer_elements_recursive(
-      data, shape, shape_rank, element_type, &max_element_count,
+      data, shape_rank, shape, element_type, &max_element_count,
       buffer_capacity, buffer, out_buffer_length);
 }
diff --git a/runtime/src/iree/hal/string_util.h b/runtime/src/iree/hal/string_util.h
index 4750339..3a53116 100644
--- a/runtime/src/iree/hal/string_util.h
+++ b/runtime/src/iree/hal/string_util.h
@@ -22,13 +22,13 @@
 // (the same as produced by iree_hal_format_shape).
 IREE_API_EXPORT iree_status_t iree_hal_parse_shape(
     iree_string_view_t value, iree_host_size_t shape_capacity,
-    iree_hal_dim_t* out_shape, iree_host_size_t* out_shape_rank);
+    iree_host_size_t* out_shape_rank, iree_hal_dim_t* out_shape);
 
 // Converts shape dimensions into a `4x5x6` format.
 //
 // Follows the standard API string formatting rules. See iree/base/api.h.
 IREE_API_EXPORT iree_status_t
-iree_hal_format_shape(const iree_hal_dim_t* shape, iree_host_size_t shape_rank,
+iree_hal_format_shape(iree_host_size_t shape_rank, const iree_hal_dim_t* shape,
                       iree_host_size_t buffer_capacity, char* buffer,
                       iree_host_size_t* out_buffer_length);
 
@@ -53,7 +53,7 @@
 // iree_hal_parse_element_type. Ignores any training `=`.
 IREE_API_EXPORT iree_status_t iree_hal_parse_shape_and_element_type(
     iree_string_view_t value, iree_host_size_t shape_capacity,
-    iree_hal_dim_t* out_shape, iree_host_size_t* out_shape_rank,
+    iree_host_size_t* out_shape_rank, iree_hal_dim_t* out_shape,
     iree_hal_element_type_t* out_element_type);
 
 // Parses a serialized element of |element_type| to its in-memory form.
@@ -100,8 +100,8 @@
 //
 // Follows the standard API string formatting rules. See iree/base/api.h.
 IREE_API_EXPORT iree_status_t iree_hal_format_buffer_elements(
-    iree_const_byte_span_t data, const iree_hal_dim_t* shape,
-    iree_host_size_t shape_rank, iree_hal_element_type_t element_type,
+    iree_const_byte_span_t data, iree_host_size_t shape_rank,
+    const iree_hal_dim_t* shape, iree_hal_element_type_t element_type,
     iree_host_size_t max_element_count, iree_host_size_t buffer_capacity,
     char* buffer, iree_host_size_t* out_buffer_length);
 
diff --git a/runtime/src/iree/hal/string_util_test.cc b/runtime/src/iree/hal/string_util_test.cc
index b8034f0..47d7291 100644
--- a/runtime/src/iree/hal/string_util_test.cc
+++ b/runtime/src/iree/hal/string_util_test.cc
@@ -39,7 +39,7 @@
   do {
     status =
         iree_hal_parse_shape(iree_string_view_t{value.data(), value.size()},
-                             shape.size(), shape.data(), &actual_rank);
+                             shape.size(), &actual_rank, shape.data());
     shape.resize(actual_rank);
   } while (iree_status_is_out_of_range(status));
   IREE_RETURN_IF_ERROR(std::move(status));
@@ -53,7 +53,7 @@
   iree_status_t status = iree_ok_status();
   do {
     status =
-        iree_hal_format_shape(value.data(), value.size(), buffer.size() + 1,
+        iree_hal_format_shape(value.size(), value.data(), buffer.size() + 1,
                               &buffer[0], &actual_length);
     buffer.resize(actual_length);
   } while (iree_status_is_out_of_range(status));
@@ -108,7 +108,7 @@
   do {
     status = iree_hal_parse_shape_and_element_type(
         iree_string_view_t{value.data(), value.size()}, shape.size(),
-        shape.data(), &actual_rank, &element_type);
+        &actual_rank, shape.data(), &element_type);
     shape.resize(actual_rank);
   } while (iree_status_is_out_of_range(status));
   IREE_RETURN_IF_ERROR(std::move(status));
@@ -184,7 +184,7 @@
     status = iree_hal_format_buffer_elements(
         iree_const_byte_span_t{reinterpret_cast<const uint8_t*>(data.data()),
                                data.size() * sizeof(T)},
-        shape.data(), shape.size(), element_type, max_element_count,
+        shape.size(), shape.data(), element_type, max_element_count,
         result.size() + 1, &result[0], &actual_length);
     result.resize(actual_length);
   } while (iree_status_is_out_of_range(status));
@@ -459,7 +459,7 @@
         IREE_HAL_ENCODING_TYPE_DENSE_ROW_MAJOR;
     BufferView buffer_view;
     iree_status_t status = iree_hal_buffer_view_create(
-        buffer, shape.data(), shape.size(), element_type, encoding_type,
+        buffer, shape.size(), shape.data(), element_type, encoding_type,
         iree_allocator_system(), &buffer_view);
     IREE_RETURN_IF_ERROR(std::move(status));
     return std::move(buffer_view);
diff --git a/runtime/src/iree/modules/check/check_test.cc b/runtime/src/iree/modules/check/check_test.cc
index bb353b6..5d8bb6d 100644
--- a/runtime/src/iree/modules/check/check_test.cc
+++ b/runtime/src/iree/modules/check/check_test.cc
@@ -63,7 +63,7 @@
   void SetUp() override {
     std::vector<iree_vm_module_t*> modules = {hal_module_, check_module_};
     IREE_ASSERT_OK(iree_vm_context_create_with_modules(
-        instance_, IREE_VM_CONTEXT_FLAG_NONE, modules.data(), modules.size(),
+        instance_, IREE_VM_CONTEXT_FLAG_NONE, modules.size(), modules.data(),
         iree_allocator_system(), &context_));
     allocator_ = iree_hal_device_allocator(device_);
   }
@@ -88,7 +88,7 @@
                    IREE_HAL_BUFFER_USAGE_TRANSFER |
                    IREE_HAL_BUFFER_USAGE_MAPPING;
     IREE_ASSERT_OK(iree_hal_buffer_view_allocate_buffer(
-        allocator_, shape.data(), shape.size(), IREE_HAL_ELEMENT_TYPE_INT_32,
+        allocator_, shape.size(), shape.data(), IREE_HAL_ELEMENT_TYPE_INT_32,
         IREE_HAL_ENCODING_TYPE_DENSE_ROW_MAJOR, params,
         iree_make_const_byte_span(contents.data(),
                                   contents.size() * sizeof(int32_t)),
@@ -110,7 +110,7 @@
                    IREE_HAL_BUFFER_USAGE_TRANSFER |
                    IREE_HAL_BUFFER_USAGE_MAPPING;
     IREE_ASSERT_OK(iree_hal_buffer_view_allocate_buffer(
-        allocator_, shape.data(), shape.size(), IREE_HAL_ELEMENT_TYPE_FLOAT_16,
+        allocator_, shape.size(), shape.data(), IREE_HAL_ELEMENT_TYPE_FLOAT_16,
         IREE_HAL_ENCODING_TYPE_DENSE_ROW_MAJOR, params,
         iree_make_const_byte_span(contents.data(),
                                   contents.size() * sizeof(uint16_t)),
@@ -132,7 +132,7 @@
                    IREE_HAL_BUFFER_USAGE_TRANSFER |
                    IREE_HAL_BUFFER_USAGE_MAPPING;
     IREE_ASSERT_OK(iree_hal_buffer_view_allocate_buffer(
-        allocator_, shape.data(), shape.size(), IREE_HAL_ELEMENT_TYPE_FLOAT_32,
+        allocator_, shape.size(), shape.data(), IREE_HAL_ELEMENT_TYPE_FLOAT_32,
         IREE_HAL_ENCODING_TYPE_DENSE_ROW_MAJOR, params,
         iree_make_const_byte_span(contents.data(),
                                   contents.size() * sizeof(float)),
@@ -154,7 +154,7 @@
                    IREE_HAL_BUFFER_USAGE_TRANSFER |
                    IREE_HAL_BUFFER_USAGE_MAPPING;
     IREE_ASSERT_OK(iree_hal_buffer_view_allocate_buffer(
-        allocator_, shape.data(), shape.size(), IREE_HAL_ELEMENT_TYPE_FLOAT_64,
+        allocator_, shape.size(), shape.data(), IREE_HAL_ELEMENT_TYPE_FLOAT_64,
         IREE_HAL_ENCODING_TYPE_DENSE_ROW_MAJOR, params,
         iree_make_const_byte_span(contents.data(),
                                   contents.size() * sizeof(double)),
diff --git a/runtime/src/iree/modules/hal/module.c b/runtime/src/iree/modules/hal/module.c
index ee11383..411c492 100644
--- a/runtime/src/iree/modules/hal/module.c
+++ b/runtime/src/iree/modules/hal/module.c
@@ -610,7 +610,7 @@
 
   iree_hal_buffer_view_t* buffer_view = NULL;
   IREE_RETURN_IF_ERROR(iree_hal_buffer_view_create(
-      source_buffer, shape_dims, shape_rank, element_type, encoding_type,
+      source_buffer, shape_rank, shape_dims, element_type, encoding_type,
       state->host_allocator, &buffer_view));
   rets->r0 = iree_hal_buffer_view_move_ref(buffer_view);
   return iree_ok_status();
@@ -749,10 +749,10 @@
     char expected_shape_str[32];
     iree_host_size_t expected_shape_str_length = 0;
     IREE_RETURN_IF_ERROR(iree_hal_format_shape(
-        actual_shape_dims, actual_shape_rank, sizeof(actual_shape_str),
+        actual_shape_rank, actual_shape_dims, sizeof(actual_shape_str),
         actual_shape_str, &actual_shape_str_length));
     IREE_RETURN_IF_ERROR(iree_hal_format_shape(
-        expected_shape_dims, expected_shape_rank, sizeof(expected_shape_str),
+        expected_shape_rank, expected_shape_dims, sizeof(expected_shape_str),
         expected_shape_str, &expected_shape_str_length));
     shape_status = iree_status_annotate_f(
         shape_status, "expected shape %.*s, actual shape %.*s",
diff --git a/runtime/src/iree/runtime/demo/hello_world_explained.c b/runtime/src/iree/runtime/demo/hello_world_explained.c
index c3a94d7..dded02a 100644
--- a/runtime/src/iree/runtime/demo/hello_world_explained.c
+++ b/runtime/src/iree/runtime/demo/hello_world_explained.c
@@ -195,8 +195,8 @@
       static const float arg0_data[4] = {1.0f, 1.1f, 1.2f, 1.3f};
       status = iree_hal_buffer_view_allocate_buffer(
           device_allocator,
-          // Shape dimensions and rank:
-          arg0_shape, IREE_ARRAYSIZE(arg0_shape),
+          // Shape rank and dimensions:
+          IREE_ARRAYSIZE(arg0_shape), arg0_shape,
           // Element type:
           IREE_HAL_ELEMENT_TYPE_FLOAT_32,
           // Encoding type:
@@ -232,7 +232,7 @@
       static const iree_hal_dim_t arg1_shape[1] = {4};
       static const float arg1_data[4] = {10.0f, 100.0f, 1000.0f, 10000.0f};
       status = iree_hal_buffer_view_allocate_buffer(
-          device_allocator, arg1_shape, IREE_ARRAYSIZE(arg1_shape),
+          device_allocator, IREE_ARRAYSIZE(arg1_shape), arg1_shape,
           IREE_HAL_ELEMENT_TYPE_FLOAT_32,
           IREE_HAL_ENCODING_TYPE_DENSE_ROW_MAJOR,
           (iree_hal_buffer_params_t){
diff --git a/runtime/src/iree/runtime/demo/hello_world_terse.c b/runtime/src/iree/runtime/demo/hello_world_terse.c
index 22256d9..04ac674 100644
--- a/runtime/src/iree/runtime/demo/hello_world_terse.c
+++ b/runtime/src/iree/runtime/demo/hello_world_terse.c
@@ -81,8 +81,8 @@
   static const iree_hal_dim_t arg0_shape[1] = {4};
   static const float arg0_data[4] = {1.0f, 1.1f, 1.2f, 1.3f};
   IREE_CHECK_OK(iree_hal_buffer_view_allocate_buffer(
-      iree_runtime_session_device_allocator(session), arg0_shape,
-      IREE_ARRAYSIZE(arg0_shape), IREE_HAL_ELEMENT_TYPE_FLOAT_32,
+      iree_runtime_session_device_allocator(session),
+      IREE_ARRAYSIZE(arg0_shape), arg0_shape, IREE_HAL_ELEMENT_TYPE_FLOAT_32,
       IREE_HAL_ENCODING_TYPE_DENSE_ROW_MAJOR,
       (iree_hal_buffer_params_t){
           .type = IREE_HAL_MEMORY_TYPE_DEVICE_LOCAL,
@@ -104,8 +104,8 @@
   static const iree_hal_dim_t arg1_shape[1] = {4};
   static const float arg1_data[4] = {10.0f, 100.0f, 1000.0f, 10000.0f};
   IREE_CHECK_OK(iree_hal_buffer_view_allocate_buffer(
-      iree_runtime_session_device_allocator(session), arg1_shape,
-      IREE_ARRAYSIZE(arg1_shape), IREE_HAL_ELEMENT_TYPE_FLOAT_32,
+      iree_runtime_session_device_allocator(session),
+      IREE_ARRAYSIZE(arg1_shape), arg1_shape, IREE_HAL_ELEMENT_TYPE_FLOAT_32,
       IREE_HAL_ENCODING_TYPE_DENSE_ROW_MAJOR,
       (iree_hal_buffer_params_t){
           .type = IREE_HAL_MEMORY_TYPE_DEVICE_LOCAL,
diff --git a/runtime/src/iree/runtime/session.c b/runtime/src/iree/runtime/session.c
index 2394a39..1f5d9d9 100644
--- a/runtime/src/iree/runtime/session.c
+++ b/runtime/src/iree/runtime/session.c
@@ -97,7 +97,8 @@
     status = iree_hal_module_create(device, host_allocator, &hal_module);
   }
   if (iree_status_is_ok(status)) {
-    status = iree_vm_context_register_modules(session->context, &hal_module, 1);
+    status = iree_vm_context_register_modules(
+        session->context, /*module_count=*/1, /*modules=*/&hal_module);
   }
   if (iree_status_is_ok(status)) {
     status = iree_vm_context_resolve_module_state(session->context, hal_module,
@@ -189,8 +190,9 @@
   IREE_TRACE_ZONE_APPEND_TEXT(z0, iree_vm_module_name(module).data,
                               iree_vm_module_name(module).size);
 
-  iree_status_t status = iree_vm_context_register_modules(
-      iree_runtime_session_context(session), &module, 1);
+  iree_status_t status =
+      iree_vm_context_register_modules(iree_runtime_session_context(session),
+                                       /*module_count=*/1, /*modules=*/&module);
 
   IREE_TRACE_ZONE_END(z0);
   return status;
diff --git a/runtime/src/iree/tooling/trace_replay.c b/runtime/src/iree/tooling/trace_replay.c
index 37b5712..4e9d6ef 100644
--- a/runtime/src/iree/tooling/trace_replay.c
+++ b/runtime/src/iree/tooling/trace_replay.c
@@ -116,8 +116,8 @@
         (int)name_node->data.scalar.length, name_node->data.scalar.value);
   }
 
-  iree_status_t status =
-      iree_vm_context_register_modules(replay->context, &module, 1);
+  iree_status_t status = iree_vm_context_register_modules(
+      replay->context, /*module_count=*/1, /*modules=*/&module);
   iree_vm_module_release(module);
   return status;
 }
@@ -161,7 +161,8 @@
 
   // Register the bytecode module with the context.
   if (iree_status_is_ok(status)) {
-    status = iree_vm_context_register_modules(replay->context, &module, 1);
+    status = iree_vm_context_register_modules(
+        replay->context, /*module_count=*/1, /*modules=*/&module);
   }
 
   iree_vm_module_release(module);
@@ -361,7 +362,7 @@
   if (shape_node->type == YAML_SCALAR_NODE) {
     // Short-hand using the canonical shape parser (4x8).
     return iree_hal_parse_shape(iree_yaml_node_as_string(shape_node),
-                                shape_capacity, shape, out_shape_rank);
+                                shape_capacity, out_shape_rank, shape);
   } else if (shape_node->type != YAML_SEQUENCE_NODE) {
     return iree_make_status(IREE_STATUS_INVALID_ARGUMENT,
                             "(%zu): expected scalar or sequence node for shape",
@@ -668,7 +669,7 @@
 
   iree_device_size_t allocation_size = 0;
   IREE_RETURN_IF_ERROR(iree_hal_buffer_compute_view_size(
-      shape, shape_rank, element_type, encoding_type, &allocation_size));
+      shape_rank, shape, element_type, encoding_type, &allocation_size));
 
   iree_hal_buffer_t* buffer = NULL;
   IREE_RETURN_IF_ERROR(iree_hal_allocator_allocate_buffer(
@@ -750,7 +751,7 @@
         .shape_rank = shape_rank,
     };
     IREE_RETURN_IF_ERROR(iree_hal_buffer_view_generate_buffer(
-        iree_hal_device_allocator(replay->device), shape, shape_rank,
+        iree_hal_device_allocator(replay->device), shape_rank, shape,
         element_type, encoding_type,
         (iree_hal_buffer_params_t){
             .type = IREE_HAL_MEMORY_TYPE_DEVICE_LOCAL,
@@ -760,7 +761,7 @@
         iree_trace_replay_generate_hal_buffer_callback, &params, &buffer_view));
   } else {
     IREE_RETURN_IF_ERROR(iree_hal_buffer_view_allocate_buffer(
-        iree_hal_device_allocator(replay->device), shape, shape_rank,
+        iree_hal_device_allocator(replay->device), shape_rank, shape,
         element_type, encoding_type,
         (iree_hal_buffer_params_t){
             .type = IREE_HAL_MEMORY_TYPE_DEVICE_LOCAL,
diff --git a/runtime/src/iree/tooling/vm_util.cc b/runtime/src/iree/tooling/vm_util.cc
index cc5996f..97bfdfd 100644
--- a/runtime/src/iree/tooling/vm_util.cc
+++ b/runtime/src/iree/tooling/vm_util.cc
@@ -37,7 +37,7 @@
   iree_hal_element_type_t element_type = IREE_HAL_ELEMENT_TYPE_NONE;
   iree_host_size_t shape_rank = 0;
   iree_status_t shape_result = iree_hal_parse_shape_and_element_type(
-      metadata, 0, NULL, &shape_rank, &element_type);
+      metadata, 0, &shape_rank, NULL, &element_type);
   if (!iree_status_is_ok(shape_result) &&
       !iree_status_is_out_of_range(shape_result)) {
     return shape_result;
@@ -50,7 +50,7 @@
   iree_hal_dim_t* shape =
       (iree_hal_dim_t*)iree_alloca(shape_rank * sizeof(iree_hal_dim_t));
   IREE_RETURN_IF_ERROR(iree_hal_parse_shape_and_element_type(
-      metadata, shape_rank, shape, &shape_rank, &element_type));
+      metadata, shape_rank, &shape_rank, shape, &element_type));
 
   // TODO(benvanik): allow specifying the encoding.
   iree_hal_encoding_type_t encoding_type =
@@ -75,7 +75,7 @@
       file,
   };
   iree_status_t status = iree_hal_buffer_view_generate_buffer(
-      device_allocator, shape, shape_rank, element_type, encoding_type,
+      device_allocator, shape_rank, shape, element_type, encoding_type,
       buffer_params,
       +[](iree_hal_buffer_mapping_t* mapping, void* user_data) {
         auto* read_params = reinterpret_cast<read_params_t*>(user_data);
diff --git a/runtime/src/iree/vm/bytecode_dispatch_test.cc b/runtime/src/iree/vm/bytecode_dispatch_test.cc
index fa2a1a5..b2d827a 100644
--- a/runtime/src/iree/vm/bytecode_dispatch_test.cc
+++ b/runtime/src/iree/vm/bytecode_dispatch_test.cc
@@ -82,7 +82,7 @@
 
     std::vector<iree_vm_module_t*> modules = {bytecode_module_};
     IREE_CHECK_OK(iree_vm_context_create_with_modules(
-        instance_, IREE_VM_CONTEXT_FLAG_NONE, modules.data(), modules.size(),
+        instance_, IREE_VM_CONTEXT_FLAG_NONE, modules.size(), modules.data(),
         iree_allocator_system(), &context_));
   }
 
diff --git a/runtime/src/iree/vm/bytecode_module_benchmark.cc b/runtime/src/iree/vm/bytecode_module_benchmark.cc
index 9dd7960..8706665 100644
--- a/runtime/src/iree/vm/bytecode_module_benchmark.cc
+++ b/runtime/src/iree/vm/bytecode_module_benchmark.cc
@@ -89,7 +89,7 @@
   std::array<iree_vm_module_t*, 2> modules = {import_module, bytecode_module};
   iree_vm_context_t* context = NULL;
   IREE_CHECK_OK(iree_vm_context_create_with_modules(
-      instance, IREE_VM_CONTEXT_FLAG_NONE, modules.data(), modules.size(),
+      instance, IREE_VM_CONTEXT_FLAG_NONE, modules.size(), modules.data(),
       iree_allocator_system(), &context));
 
   iree_vm_function_t function;
diff --git a/runtime/src/iree/vm/bytecode_module_size_benchmark.cc b/runtime/src/iree/vm/bytecode_module_size_benchmark.cc
index 164a223..6b949e3 100644
--- a/runtime/src/iree/vm/bytecode_module_size_benchmark.cc
+++ b/runtime/src/iree/vm/bytecode_module_size_benchmark.cc
@@ -24,7 +24,7 @@
 
   iree_vm_context_t* context = nullptr;
   iree_vm_context_create_with_modules(instance, IREE_VM_CONTEXT_FLAG_NONE,
-                                      &module, /*module_count=*/1,
+                                      /*module_count=*/1, &module,
                                       iree_allocator_system(), &context);
 
   iree_vm_function_t function;
diff --git a/runtime/src/iree/vm/context.c b/runtime/src/iree/vm/context.c
index 2508075..fe9f87d 100644
--- a/runtime/src/iree/vm/context.c
+++ b/runtime/src/iree/vm/context.c
@@ -219,13 +219,14 @@
 IREE_API_EXPORT iree_status_t iree_vm_context_create(
     iree_vm_instance_t* instance, iree_vm_context_flags_t flags,
     iree_allocator_t allocator, iree_vm_context_t** out_context) {
-  return iree_vm_context_create_with_modules(instance, flags, NULL, 0,
-                                             allocator, out_context);
+  return iree_vm_context_create_with_modules(
+      instance, flags, /*module_count=*/0, /*modules=*/NULL, allocator,
+      out_context);
 }
 
 IREE_API_EXPORT iree_status_t iree_vm_context_create_with_modules(
     iree_vm_instance_t* instance, iree_vm_context_flags_t flags,
-    iree_vm_module_t** modules, iree_host_size_t module_count,
+    iree_host_size_t module_count, iree_vm_module_t** modules,
     iree_allocator_t allocator, iree_vm_context_t** out_context) {
   IREE_TRACE_ZONE_BEGIN(z0);
   IREE_ASSERT_ARGUMENT(out_context);
@@ -236,7 +237,8 @@
       sizeof(iree_vm_module_state_t*) * module_count;
 
   iree_vm_context_t* context = NULL;
-  iree_allocator_malloc(allocator, context_size, (void**)&context);
+  IREE_RETURN_AND_END_ZONE_IF_ERROR(
+      z0, iree_allocator_malloc(allocator, context_size, (void**)&context));
   iree_atomic_ref_count_init(&context->ref_count);
   context->instance = instance;
   iree_vm_instance_retain(context->instance);
@@ -260,7 +262,7 @@
   context->list.capacity = module_count;
 
   iree_status_t register_status =
-      iree_vm_context_register_modules(context, modules, module_count);
+      iree_vm_context_register_modules(context, module_count, modules);
   if (!iree_status_is_ok(register_status)) {
     iree_vm_context_destroy(context);
     IREE_TRACE_ZONE_END(z0);
@@ -324,8 +326,8 @@
 }
 
 IREE_API_EXPORT iree_status_t iree_vm_context_register_modules(
-    iree_vm_context_t* context, iree_vm_module_t** modules,
-    iree_host_size_t module_count) {
+    iree_vm_context_t* context, iree_host_size_t module_count,
+    iree_vm_module_t** modules) {
   IREE_ASSERT_ARGUMENT(context);
   if (!modules && module_count > 1) {
     return iree_make_status(IREE_STATUS_INVALID_ARGUMENT,
diff --git a/runtime/src/iree/vm/context.h b/runtime/src/iree/vm/context.h
index 0a944ec..596acd6 100644
--- a/runtime/src/iree/vm/context.h
+++ b/runtime/src/iree/vm/context.h
@@ -57,7 +57,7 @@
 // |out_context| must be released by the caller.
 IREE_API_EXPORT iree_status_t iree_vm_context_create_with_modules(
     iree_vm_instance_t* instance, iree_vm_context_flags_t flags,
-    iree_vm_module_t** modules, iree_host_size_t module_count,
+    iree_host_size_t module_count, iree_vm_module_t** modules,
     iree_allocator_t allocator, iree_vm_context_t** out_context);
 
 // Retains the given |context| for the caller.
@@ -77,8 +77,8 @@
 // order provided.
 // The modules will be retained by the context until destruction.
 IREE_API_EXPORT iree_status_t iree_vm_context_register_modules(
-    iree_vm_context_t* context, iree_vm_module_t** modules,
-    iree_host_size_t module_count);
+    iree_vm_context_t* context, iree_host_size_t module_count,
+    iree_vm_module_t** modules);
 
 // Freezes a context such that no more modules can be registered.
 // This can be used to ensure that context contents cannot be modified by other
diff --git a/runtime/src/iree/vm/native_module_test.cc b/runtime/src/iree/vm/native_module_test.cc
index 84202d0..ee06bcc 100644
--- a/runtime/src/iree/vm/native_module_test.cc
+++ b/runtime/src/iree/vm/native_module_test.cc
@@ -41,7 +41,7 @@
     // will be allocated.
     std::vector<iree_vm_module_t*> modules = {module_a, module_b};
     IREE_CHECK_OK(iree_vm_context_create_with_modules(
-        instance_, IREE_VM_CONTEXT_FLAG_NONE, modules.data(), modules.size(),
+        instance_, IREE_VM_CONTEXT_FLAG_NONE, modules.size(), modules.data(),
         iree_allocator_system(), &context_));
 
     // No longer need the modules as the context retains them.
diff --git a/runtime/src/iree/vm/test/emitc/module_test.cc b/runtime/src/iree/vm/test/emitc/module_test.cc
index eee8d61..83bf628 100644
--- a/runtime/src/iree/vm/test/emitc/module_test.cc
+++ b/runtime/src/iree/vm/test/emitc/module_test.cc
@@ -127,7 +127,7 @@
 
     std::vector<iree_vm_module_t*> modules = {module_};
     IREE_CHECK_OK(iree_vm_context_create_with_modules(
-        instance_, IREE_VM_CONTEXT_FLAG_NONE, modules.data(), modules.size(),
+        instance_, IREE_VM_CONTEXT_FLAG_NONE, modules.size(), modules.data(),
         iree_allocator_system(), &context_));
 
     iree_vm_module_release(module_);