Skip to content

Add static and runtime type checking to the CAPI2 Schema.#781

Open
HU90m wants to merge 3 commits into
olofk:mainfrom
HU90m:pydantic-capi2
Open

Add static and runtime type checking to the CAPI2 Schema.#781
HU90m wants to merge 3 commits into
olofk:mainfrom
HU90m:pydantic-capi2

Conversation

@HU90m
Copy link
Copy Markdown
Collaborator

@HU90m HU90m commented May 11, 2026

I've made these changes such that the interface of fusesoc.core.Core remains unchanged. This was done in the interest of keeping changes minimal.

We can change this interface, and make use of the CAPI2 objects, as we expand type checking into the rest of the repository in later PRs.

As discussed, I've dumped the python version. Python 3.9 is end-of-life and 3.10 offers many ergonomic features. See: #734

Pydantic has been used for runtime type checking, which saves a lot of schema validation logic. Pydantic can be used to generate the jsonschema. A future PR could use sphinx-autodoc-pydantic to generate nice documentation, remove use of the old jsonschema and provide the jsonschema generated from Pydantic for people creating tools in other languages. This may be of interest to you @amykyta3

Both mypy and ty have been added to pre-commit for static type checking.

Beyond the normal test suite, I also checked for changes in the output of:

fusesoc --cores-root=/tmp/repos/serv run \
  --setup --build-root=/tmp/build \
  --target=verilator_tb \
  servant
fusesoc --cores-root=/tmp/repos/opentitan/hw run \
  --setup --build-root=/tmp/build \
  --target=lint --flag=tool_ascentlint \
  --flag=files_rtl_tapeout \
  --mapping=lowrisc:systems:top_earlgrey:0.1 \
  --mapping=lowrisc:prim_generic:all:0.1 \
  lowrisc:systems:chip_earlgrey_asic

NB: e7c243b broke some opentitan core files, so has to be reverted whenever testing against opentitan. Something to be aware of when updating FuseSoC in opentitan @machshev

Python 3.10 has a nice syntax features for type annotations, such as `|`
unions, and 3.9 will be end of life by the end of 2025.

Pydantic has been added to allow runtime type checking.
@HU90m HU90m force-pushed the pydantic-capi2 branch from 2b65ac0 to e62e589 Compare May 11, 2026 18:57
@HU90m HU90m requested review from ArkoshEternal and olofk May 11, 2026 20:54
@HU90m HU90m force-pushed the pydantic-capi2 branch from e62e589 to 0aa0ba4 Compare May 12, 2026 13:20
Copy link
Copy Markdown
Collaborator

@ArkoshEternal ArkoshEternal left a comment

Choose a reason for hiding this comment

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

Since this is majorly non-breaking, and checking would require that we have active fusesoc runs to check against edge-cases that are not in the existing test framework, it may make sense to add the local checks into the CI for fusesoc.

I think we should merge this in as an initial set and then we may have to make revisions after we do more integration into the rest of the codebase

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