intel / intel/simulator-bindings
simics-macro: incorrect idx_type for Vec/BTreeSet attributes causes SIMICS warning
- Dominant language
- Rust
- Stars
- 17
- Forks
- 9
- PR merge metrics
- No merged PRs in 30d
Description
## Summary
When registering SIMICS class attributes with `Vec` or `BTreeSet` types via the `#[class(attribute(...))]` proc macro, SIMICS emits the following warning at load time:
```
*** Warning: attribute in class not indexed, ignoring non NULL indexed value type
```
## Root Cause
In `simics-macro/src/class/mod.rs` ([line 333](https://github.com/intel/simulator-bindings/blob/main/modules/simics-macro/src/class/mod.rs)), the `ty_to_typestring()` function unconditionally returns `Some(TypeStringType::Integer)` as the `idx_type` for `Vec` and `BTreeSet` types:
```rust
"Vec" | "BTreeSet" => {
// ...
(
quote!(simics::TypeStringType::List(
vec![simics::TypeStringListType::ZeroOrMore(Box::new(#inner))]
)),
Some(quote!(simics::TypeStringType::Integer)), // <-- should be None
)
}
```
This `idx_type` is passed through to `SIM_register_typed_attribute`, telling SIMICS that the attribute supports indexed access with integer keys. However, the attribute is not actually registered with indexed getter/setter callbacks — it is a plain list attribute. SIMICS detects the mismatch and emits the warning.
## Suggested Fix
Return `None` instead of `Some(...)` for the `idx_type`:
```rust
"Vec" | "BTreeSet" => {
// ...
(
quote!(simics::TypeStringType::List(
vec![simics::TypeStringListType::ZeroOrMore(Box::new(#inner))]
)),
None,
)
}
```
## Impact
The warning is cosmetic — SIMICS handles it gracefully and the attribute works correctly as a plain list. However, it is confusing for users and produces noisy output on module load.
## Reproduction
Any SIMICS module using `#[class(attribute(...))]` with a `Vec` or `BTreeSet` field will trigger this warning. For example:
```rust
#[class(attribute(optional))]
pub exceptions: BTreeSet,
```
Discovered in the [tsffs](https://github.com/intel/tsffs) project.
Contributor guide
Assessment
This issue has not been assessed yet.