Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory: Create newtype ContextId #1117

Merged
merged 17 commits into from
Oct 25, 2023
Merged

Memory: Create newtype ContextId #1117

merged 17 commits into from
Oct 25, 2023

Conversation

plafer
Copy link
Contributor

@plafer plafer commented Oct 22, 2023

Creates the ContextId type instead of using u32 everywhere. This makes the code easier to understand to a newcomer; e.g. types such as (u32, u32, u32) make understanding the code harder. And this newtype will also prevent bugs which e.g. use the context ID as an address (who's also a u32).

I suggest we also introduce a newtype for memory Address.

@plafer plafer changed the base branch from main to next October 22, 2023 14:33
Copy link
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Totally agree with the motivation of the PR (and also think it would be a good idea to have a special type for memory address - though, probably in a different PR). A few preliminary comments:

  1. I think a single ContextId type will probably suffice. Specifically, I don't think we need another type for MemoryContextId. I would also put the definition of ContextId into /src/system/mod.rs rather than into memory chiplet.
  2. I don't think we need to implement arithmetic operations on ContextId. As far as I remember, we never actually add/subtract contexts.
  3. We usually try to reduce the number of non-dev dependencies as much as possible. So, I would probably manually implement Display, Into etc. traits on ContextId rather than adding an extra dependency.

@plafer
Copy link
Contributor Author

plafer commented Oct 23, 2023

I don't think we need to implement arithmetic operations on ContextId. As far as I remember, we never actually add/subtract contexts.

The only arithmetic we do is a subtraction here. For now I'll implement only Sub with a Sub::Output=u32, but we can change it.

I applied all the other requested changes!

Copy link
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Looks good! I left a few small comments inline. Once these are addressed, we can merge.

processor/src/chiplets/memory/mod.rs Outdated Show resolved Hide resolved
processor/src/chiplets/memory/mod.rs Outdated Show resolved Hide resolved
processor/src/decoder/block_stack.rs Outdated Show resolved Hide resolved
processor/src/system/mod.rs Outdated Show resolved Hide resolved
processor/src/system/mod.rs Outdated Show resolved Hide resolved
processor/src/system/mod.rs Outdated Show resolved Hide resolved
processor/src/system/mod.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All looks good! Thank you! I left one small nit inline. After this, let's squash the commits and merge.

processor/src/system/mod.rs Outdated Show resolved Hide resolved
@plafer plafer merged commit c52f813 into next Oct 25, 2023
15 checks passed
@plafer plafer deleted the plafer-memory-new-types branch October 25, 2023 10:09
Al-Kindi-0 pushed a commit that referenced this pull request Dec 5, 2023
* ContextId type

* propagate MemoryContextId

* fix tests

* MemoryContextId -> ContextId

* move definition

* Remove derive-more dependency

* fix repl

* fmt

* docstring

* import newline

* Remove `Sub` from `ContextId`

* blank line

* section name change

* blank line

* use `ContextId::root()`

* fmt

* memory context -> execution context
bobbinth pushed a commit that referenced this pull request Feb 26, 2024
* ContextId type

* propagate MemoryContextId

* fix tests

* MemoryContextId -> ContextId

* move definition

* Remove derive-more dependency

* fix repl

* fmt

* docstring

* import newline

* Remove `Sub` from `ContextId`

* blank line

* section name change

* blank line

* use `ContextId::root()`

* fmt

* memory context -> execution context
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants