Skip to content

Commit 0b15000

Browse files
committed
feat(utils): use ConstAllocator in ComptimeVec
Removes the hard-coded element count limitation.
1 parent ee75038 commit 0b15000

File tree

8 files changed

+203
-131
lines changed

8 files changed

+203
-131
lines changed

src/r3/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ While much of the application-level API has retained its general shape, there ar
2121

2222
TODO
2323

24+
### Fixed
25+
26+
- The hard-coded kernel object count limitation has been removed. This was made possible by the use of growable arrays in the compile-time kernel configurator.
27+
2428
## [0.1.3] - 2021-10-29
2529

2630
This release only includes changes to the documentation.

src/r3_core/src/kernel/cfg.rs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Kernel configuration
22
use crate::{
33
kernel::{hook, interrupt, raw, raw_cfg},
4-
utils::{ComptimeVec, ConstAllocator, Init, PhantomInvariant},
4+
utils::{ComptimeVec, ConstAllocator, Frozen, Init, PhantomInvariant},
55
};
66

77
macro overview_ref() {
@@ -29,15 +29,15 @@ enum CfgSt {
2929

3030
impl<'c, C: raw_cfg::CfgBase> Cfg<'c, C> {
3131
/// Construct `Cfg`.
32-
const fn new(raw: &'c mut C, _allocator: &'c ConstAllocator, st: CfgSt) -> Self {
32+
const fn new(raw: &'c mut C, allocator: &'c ConstAllocator, st: CfgSt) -> Self {
3333
Self {
3434
raw,
3535
st,
36-
startup_hooks: ComptimeVec::new(),
36+
startup_hooks: ComptimeVec::new_in(allocator.clone()),
3737
hunk_pool_len: 0,
3838
hunk_pool_align: 1,
39-
interrupt_lines: ComptimeVec::new(),
40-
interrupt_handlers: ComptimeVec::new(),
39+
interrupt_lines: ComptimeVec::new_in(allocator.clone()),
40+
interrupt_handlers: ComptimeVec::new_in(allocator.clone()),
4141
}
4242
}
4343

@@ -116,10 +116,12 @@ impl<'c, C: raw_cfg::CfgBase> Cfg<'c, C> {
116116

117117
CfgPhase1Data {
118118
_phantom: Init::INIT,
119-
startup_hooks: self.startup_hooks.map(hook::CfgStartupHook::to_attr),
119+
startup_hooks: Frozen::leak_slice(
120+
&self.startup_hooks.map(hook::CfgStartupHook::to_attr),
121+
),
120122
hunk_pool_len: self.hunk_pool_len,
121123
hunk_pool_align: self.hunk_pool_align,
122-
interrupt_handlers: self.interrupt_handlers,
124+
interrupt_handlers: Frozen::leak_slice(&self.interrupt_handlers),
123125
}
124126
}
125127

@@ -198,8 +200,8 @@ impl<'c, C: raw_cfg::CfgBase> Cfg<'c, C> {
198200

199201
// Clear these fields to indicate that this method has been called
200202
// as required
201-
self.interrupt_lines = ComptimeVec::new();
202-
self.interrupt_handlers = ComptimeVec::new();
203+
self.interrupt_lines.clear();
204+
self.interrupt_handlers.clear();
203205
}
204206

205207
/// Finalize `self` for the phase 3 configuration.
@@ -250,10 +252,10 @@ impl<'c, C: raw_cfg::CfgBase> Cfg<'c, C> {
250252
#[doc = overview_ref!()]
251253
pub struct CfgPhase1Data<System> {
252254
_phantom: PhantomInvariant<System>,
253-
pub startup_hooks: ComptimeVec<hook::StartupHookAttr>,
255+
pub startup_hooks: &'static [Frozen<hook::StartupHookAttr>],
254256
pub hunk_pool_len: usize,
255257
pub hunk_pool_align: usize,
256-
pub interrupt_handlers: ComptimeVec<interrupt::CfgInterruptHandler>,
258+
pub interrupt_handlers: &'static [Frozen<interrupt::CfgInterruptHandler>],
257259
}
258260

259261
/// The inputs to [`attach_phase2!`].
@@ -619,13 +621,15 @@ pub macro attach_phase1($params:expr, impl CfgPhase1<$System:ty> for $Ty:ty $(,)
619621
array_item_from_fn! {
620622
const STARTUP_HOOKS: [hook::StartupHookAttr; _] =
621623
(0..STATIC_PARAMS.startup_hooks.len())
622-
.map(|i| STATIC_PARAMS.startup_hooks[i]);
624+
.map(|i| STATIC_PARAMS.startup_hooks[i].get());
623625
}
624626

625627
// Consturct a table of combined second-level interrupt handlers
626-
const INTERRUPT_HANDLERS: [interrupt::CfgInterruptHandler; {
627-
STATIC_PARAMS.interrupt_handlers.len()
628-
}] = STATIC_PARAMS.interrupt_handlers.to_array();
628+
array_item_from_fn! {
629+
const INTERRUPT_HANDLERS: [interrupt::CfgInterruptHandler; _] =
630+
(0..STATIC_PARAMS.interrupt_handlers.len())
631+
.map(|i| STATIC_PARAMS.interrupt_handlers[i].get());
632+
}
629633
const NUM_INTERRUPT_HANDLERS: usize = INTERRUPT_HANDLERS.len();
630634
const NUM_INTERRUPT_LINES: usize =
631635
interrupt::num_required_interrupt_line_slots(&INTERRUPT_HANDLERS);

src/r3_core/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#![feature(const_ptr_write)]
2525
#![feature(core_intrinsics)]
2626
#![feature(const_heap)]
27+
#![feature(let_else)]
2728
#![feature(exhaustive_patterns)] // `let Ok(()) = Ok::<(), !>(())`
2829
#![feature(decl_macro)]
2930
#![feature(set_ptr_value)] // `<*const T>::set_ptr_value`

0 commit comments

Comments
 (0)