Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .github/RELEASING.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
# Release policy

Celox is released as one lockstep distribution. `VERSION`,
`.release-please-manifest.json`, the npm packages, and all Rust workspace crates
`.release-please-manifest.json`, the npm packages, and all Celox Rust workspace crates
must always carry the same version. The public Rust entry points are `celox`,
`celox-frontend-sdk`, `celox-test-suite`, and the Rust adapter API in `celox-napi`; the remaining
published `celox-*` crates satisfy their Cargo dependency graph and remain
implementation details.

Aplite has its own version and release train (`release-aplite.yml` and
`publish-aplite.yml`). Publish the Aplite version required by the workspace
before releasing Celox: `celox-heap` depends on it, and Cargo resolves the
published Aplite crate when packaging Celox crates. A bootstrap `0.0.0` release
does not satisfy this dependency. Aplite is deliberately absent from Celox's
lockstep publication list.

## Versioning before 1.0

Pull request titles are the input to release automation after GitHub copies the
Expand Down
12 changes: 10 additions & 2 deletions .mergify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ priority_rules:
priority: 10000
allow_checks_interruption: true

- name: Priority merges without interruption
conditions:
- label = merge-priority
priority: 9000
allow_checks_interruption: false

- name: Lightweight validated changes first
conditions:
- check-success = Lint & Format
Expand Down Expand Up @@ -160,7 +166,7 @@ queue_rules:
# rulesets. Keep those rules enforced by GitHub; Mergify gets no bypass.

pull_request_rules:
- name: Authorize emergency merge requests
- name: Authorize prioritized merge requests
conditions:
- or:
- base ~= ^(master|develop)$
Expand All @@ -169,7 +175,9 @@ pull_request_rules:
- and:
- base ~= ^stack/
- 'body ~= (?m)^Depends-On: '
- label = merge-urgent
- or:
- label = merge-urgent
- label = merge-priority
- -label = release:hold
- -label = dequeued
- -draft
Expand Down
27 changes: 16 additions & 11 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -435,20 +435,25 @@ regressions and manual scaling measurements are not made passing by blindly
running every `#[ignore]` test. New exclusions need a concrete reason and
evidence; an unexpected failure must not become a skip.

## Emergency merge priority
## Merge priority labels

Apply `merge-urgent` to request an emergency merge. Mergify adds `merge-ready`
and gives the PR priority 10000, ahead of the normal and lightweight priorities.
It may interrupt lower-priority queue checks to test the urgent PR first; use
this only when the urgency justifies restarting that work. Existing queue
categories and batching still apply, as do stack dependency ordering and all
required checks. This is priority, not permission to merge failing CI.
Both labels add `merge-ready` and request normal queue admission:

| Label | Priority | Running lower-priority checks |
| --- | --- | --- |
| `merge-priority` | 9000 | Finish first; this PR goes ahead of waiting ordinary PRs |
| `merge-urgent` | 10000 | May be interrupted to test this PR first |

Both outrank normal and lightweight priorities. If both labels are present,
`merge-urgent` wins. Reserve it for emergencies that justify restarting checks.
Existing queue categories, batching, stack dependency ordering, and all required
checks still apply. These labels do not permit merging failing CI.

Drafts, conflicts, `release:hold`, and `dequeued` still block automatic admission.
After addressing a dequeue's cause, remove `dequeued` to retry. Removing
`merge-urgent` restores normal priority; remove `merge-ready` and explicitly
After addressing a dequeue's cause, remove `dequeued` to retry. Remove both
priority labels to restore normal priority; remove `merge-ready` and explicitly
dequeue as usual to withdraw the merge request entirely. The generated
`merge-ready` label also activates the existing release-PR freeze mechanism.

The label works after this configuration reaches the PR's base branch. Creating
or applying the label alone does not install the queue policy.
Each label's behavior works after its configuration reaches the PR's base
branch. Creating or applying a label alone does not install the queue policy.
8 changes: 6 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ description = "Celox HDL Simulator"
rust-version = "1.99.1"

[workspace.dependencies]
# Aplite has its own release version; these consumers are unpublished.
aplite = { path = "crates/aplite" }
# Aplite has an independent release version.
aplite = { version = "0.1.0", path = "crates/aplite" }
celox = { version = "=0.11.0", path = "crates/celox", default-features = false } # x-release-please-version
celox-analysis = { version = "=0.11.0", path = "crates/celox-analysis" } # x-release-please-version
celox-backend-arm64 = { version = "=0.11.0", path = "crates/celox-backend-arm64" } # x-release-please-version
Expand Down
64 changes: 40 additions & 24 deletions crates/celox-backend-x86/src/backend/native/isel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1480,10 +1480,6 @@ pub fn lower_execution_unit_with_diagnostics(
sparse_write_states.metadata_action(sir_block_id, inst_idx),
);
}
if cfg!(debug_assertions) {
ctx.verify_wide_values();
}

// Track known bit width for redundant mask elimination.
let dst_reg = inst.defined_register();
if let Some(dr) = dst_reg {
Expand Down Expand Up @@ -1563,6 +1559,12 @@ pub fn lower_execution_unit_with_diagnostics(

// Extract mask_map for phi node construction (ctx borrows func fields)
let saved_mask_map = std::mem::replace(&mut ctx.mask_map, RegMap::new(0));
// Each mutation validates its own entry. Scan the whole map once at
// the boundary rather than once per instruction, which is quadratic in
// large functions with many wide values.
if cfg!(debug_assertions) {
ctx.verify_wide_values();
}
let saved_wide_regs = std::mem::take(&mut ctx.wide_regs);
let saved_wide_masks = std::mem::take(&mut ctx.wide_masks);
drop(ctx); // Release borrows on func
Expand Down Expand Up @@ -1758,6 +1760,11 @@ type WideMaskMap = crate::HashMap<RegisterId, Vec<(VReg, usize)>>;
/// Tracks known constant values for SIR registers (for constant folding in ISel).
type ConstMap = crate::HashMap<RegisterId, u64>;

#[cfg(test)]
thread_local! {
static WIDE_VALUE_VERIFICATIONS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
}

struct ISelContext<'a> {
vregs: &'a mut VRegAllocator,
spill_descs: &'a mut Vec<SpillDesc>,
Expand Down Expand Up @@ -2193,6 +2200,9 @@ impl<'a> ISelContext<'a> {
if width <= 64 {
self.wide_regs.remove(&reg);
} else {
if cfg!(debug_assertions) {
self.verify_wide_value(&reg, &chunks);
}
self.wide_regs.replace(reg, chunks);
}
}
Expand Down Expand Up @@ -2244,28 +2254,34 @@ impl<'a> ISelContext<'a> {
/// this map through a direct insertion.
fn verify_wide_values(&self) {
for (reg, chunks) in self.wide_regs.iter() {
let width = self.sir_width(reg);
assert!(
width > 64,
"narrow SIR register r{} has a wide native representation (width={width})",
reg.0
);
let expected_chunks = Self::num_chunks(width);
self.verify_wide_value(reg, chunks);
}
}

fn verify_wide_value(&self, reg: &RegisterId, chunks: &[(VReg, usize)]) {
#[cfg(test)]
WIDE_VALUE_VERIFICATIONS.with(|count| count.set(count.get() + 1));
let width = self.sir_width(reg);
assert!(
width > 64,
"narrow SIR register r{} has a wide native representation (width={width})",
reg.0
);
let expected_chunks = Self::num_chunks(width);
assert_eq!(
chunks.len(),
expected_chunks,
"wide SIR register r{} has {} chunks, expected {expected_chunks}",
reg.0,
chunks.len()
);
for (index, (_, chunk_width)) in chunks.iter().enumerate() {
let expected_width = width.saturating_sub(index * 64).min(64);
assert_eq!(
chunks.len(),
expected_chunks,
"wide SIR register r{} has {} chunks, expected {expected_chunks}",
reg.0,
chunks.len()
*chunk_width, expected_width,
"wide SIR register r{} chunk {index} has width {chunk_width}, expected {expected_width}",
reg.0
);
for (index, (_, chunk_width)) in chunks.iter().enumerate() {
let expected_width = width.saturating_sub(index * 64).min(64);
assert_eq!(
*chunk_width, expected_width,
"wide SIR register r{} chunk {index} has width {chunk_width}, expected {expected_width}",
reg.0
);
}
}
}

Expand Down
41 changes: 41 additions & 0 deletions crates/celox-backend-x86/src/backend/native/isel/tests/wide.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1463,3 +1463,44 @@ fn widened_zero_compares_equal_to_a_zero_wide_load() {
assert_eq!(state[output_offset] & 1, 1, "four_state={four_state}");
}
}

#[cfg(debug_assertions)]
#[test]
fn wide_value_invariant_validation_scales_with_values() {
const COUNT: usize = 128;
let unit = ExecutionUnit {
entry_block_id: SirBlockId(0),
blocks: [(
SirBlockId(0),
BasicBlock {
id: SirBlockId(0),
params: vec![],
instructions: (0..COUNT)
.map(|i| {
SIRInstruction::Imm(
RegisterId(i),
SIRValue::new_four_state(BigUint::from(i), BigUint::default()),
)
})
.collect(),
terminator: SIRTerminator::Return,
},
)]
.into_iter()
.collect(),
register_map: (0..COUNT)
.map(|i| (RegisterId(i), RegisterType::Logic { width: 65 }))
.collect(),
};
WIDE_VALUE_VERIFICATIONS.with(|count| count.set(0));
let _ = lower_execution_unit(&unit, &empty_layout(), false);
let checks = WIDE_VALUE_VERIFICATIONS.with(|count| count.get());
assert!(
checks >= COUNT,
"the invariant must still be checked: {checks}"
);
assert!(
checks <= 2 * COUNT,
"repeated whole-map validation: {checks}"
);
}
2 changes: 2 additions & 0 deletions crates/celox-frontend-sv/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ edition.workspace = true
rust-version.workspace = true

[dependencies]
serde_json = { workspace = true }

celox-design = { workspace = true }
celox-frontend-core = { workspace = true }
celox-heap = { workspace = true }
Expand Down
48 changes: 28 additions & 20 deletions crates/celox-frontend-sv/src/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ mod procedural;

type RegionedVarAddr = RegionedVarAddrBase<SourceVarId>;
type GlueBlock = GlueBlockBase<SourceVarId>;
const MAX_SV_SPECIALIZATIONS_PER_MODULE: usize = 64;
const MAX_SV_RECURSIVE_SPECIALIZATIONS: usize = 64;
/// The name of a module's [`SimModule::time_slot`].
const TIME_SLOT: &str = "$time";

Expand Down Expand Up @@ -2268,7 +2268,7 @@ fn prepare_external_hierarchy_collecting(
names.sort();

let mut module_ids = HashMap::default();
let mut module_specialization_counts = HashMap::default();
let mut specialization_parents = HashMap::default();
let mut queue = Vec::new();
let mut requested_roots = HashMap::default();
for name in names {
Expand Down Expand Up @@ -2309,7 +2309,6 @@ fn prepare_external_hierarchy_collecting(
}
let module_id = ModuleId(module_ids.len());
module_ids.insert(key.clone(), module_id);
module_specialization_counts.insert(name.clone(), 1usize);
queue.push(key);
}

Expand Down Expand Up @@ -2374,7 +2373,6 @@ fn prepare_external_hierarchy_collecting(
if !module_ids.contains_key(&dependency) {
let id = ModuleId(module_ids.len());
module_ids.insert(dependency.clone(), id);
module_specialization_counts.insert(name.clone(), 1);
queue.push(dependency);
}
}
Expand All @@ -2400,13 +2398,7 @@ fn prepare_external_hierarchy_collecting(
continue;
}
if !module_ids.contains_key(&child_key) {
let specialization_count = module_specialization_counts
.entry(child_key.name.clone())
.or_insert(0);
if *specialization_count >= MAX_SV_SPECIALIZATIONS_PER_MODULE {
return Err(sv_specialization_limit_error(child_key.name.clone()).into());
}
*specialization_count += 1;
register_specialization_parent(&child_key, &key, &mut specialization_parents)?;
let child_id = ModuleId(module_ids.len());
module_ids.insert(child_key.clone(), child_id);
queue.push(child_key);
Expand Down Expand Up @@ -2885,8 +2877,7 @@ fn schedule_sources_collecting(
let root_id = ModuleId(0);
let mut module_ids = HashMap::default();
module_ids.insert(root_key.clone(), root_id);
let mut module_specialization_counts = HashMap::default();
module_specialization_counts.insert(root_key.name.clone(), 1usize);
let mut specialization_parents = HashMap::default();
let mut queue = vec![root_key.clone()];
let mut index = 0;
let mut elaborated = HashMap::default();
Expand Down Expand Up @@ -2923,13 +2914,7 @@ fn schedule_sources_collecting(
return Err(unsupported_sv_instance(child_key.name.clone()).into());
}
if !module_ids.contains_key(&child_key) {
let specialization_count = module_specialization_counts
.entry(child_key.name.clone())
.or_insert(0);
if *specialization_count >= MAX_SV_SPECIALIZATIONS_PER_MODULE {
return Err(sv_specialization_limit_error(child_key.name.clone()).into());
}
*specialization_count += 1;
register_specialization_parent(&child_key, &key, &mut specialization_parents)?;
let child_id = ModuleId(module_ids.len());
module_ids.insert(child_key.clone(), child_id);
queue.push(child_key);
Expand Down Expand Up @@ -3210,6 +3195,29 @@ fn restore_interface_member_paths(module: &mut SimModule, source: &AnalyzedSvMod
}
}

/// Bound parameter-changing recursion along one instantiation path. Independent
/// siblings may have any number of distinct parameter specializations. Repeated
/// identical keys are handled by the hierarchy cycle checks.
fn register_specialization_parent(
child: &LoweredSvModuleKey,
parent: &LoweredSvModuleKey,
parents: &mut HashMap<LoweredSvModuleKey, LoweredSvModuleKey>,
) -> Result<(), ParserError> {
let mut ancestor = Some(parent);
let mut occurrences = 1usize;
while let Some(key) = ancestor {
if key.name == child.name {
occurrences += 1;
if occurrences > MAX_SV_RECURSIVE_SPECIALIZATIONS {
return Err(sv_specialization_limit_error(child.name.clone()));
}
}
ancestor = parents.get(key);
}
parents.insert(child.clone(), parent.clone());
Ok(())
}

fn sv_specialization_limit_error(name: String) -> ParserError {
ParserError::unsupported(
sv::SV_FRONTEND_TRACKING_ISSUE,
Expand Down
Loading
Loading