Skip to content

Niche Optimization for Option<ReferenceId> and IndexVec<ReferenceId, T> #55

@Boshen

Description

@Boshen

we have these index types

https://github.com/oxc-project/oxc/blob/712ee0dde8e03d79513b42bad3b6736b566dd60b/crates/oxc_syntax/src/reference.rs#L6-L8

https://github.com/oxc-project/oxc/blob/712ee0dde8e03d79513b42bad3b6736b566dd60b/crates/oxc_syntax/src/symbol.rs#L7-L9

where

https://github.com/oxc-project/oxc/blob/712ee0dde8e03d79513b42bad3b6736b566dd60b/crates/oxc_ast/src/ast/js.rs#L451

https://github.com/oxc-project/oxc/blob/712ee0dde8e03d79513b42bad3b6736b566dd60b/crates/oxc_semantic/src/reference.rs#L22

can be trimmed by niche optimization.

But,

use std::num::NonZeroU32;
define_index_type! {
    pub struct ReferenceId = NonZeroU32;
}

is not supported by the macro define_index_type

error[E0599]: no function or associated item named `max_value` found for struct `NonZero` in the current scope
   --> crates/oxc_syntax/src/reference.rs:7:1
    |
7   | / define_index_type! {
8   | |     pub struct ReferenceId = NonZeroU32;
9   | | }
    | |_^ function or associated item not found in `NonZero<u32>`
    |
note: if you're trying to build a new `NonZero<u32>` consider using one of the following associated functions:
      NonZero::<T>::new
      NonZero::<T>::new_unchecked
   --> /Users/boshen/.rustup/toolchains/1.78.0-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/num/nonzero.rs:308:5

but the good news is that we forked it and lives in https://github.com/oxc-project/oxc/tree/main/crates/oxc_index

The task of this issue is to make it work, if possible.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions