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

core: resolve circular dependency #16458

Closed
wants to merge 5 commits into from
Closed

Conversation

maribu
Copy link
Member

@maribu maribu commented May 7, 2021

Contribution description

Dependency graph before:

     +-------------------------------------+
     |                                     |
     |                                     V
+----------+        +-------+         +---------+
| thread.h | -----> | msg.h | ------> | sched.h |
+----------+        +-------+         +---------+
     ^                                     |
     |                                     |
     +-------------------------------------+

Dependency graph after:

                 +--------------+
                 | core_types.h |
                 +--------------+
                    ^   ^   ^
                    |   |   |
      +-------------+   |   +--------------+
      |                 |                  |
+----------+            |             +---------+
| thread.h |            |             | sched.h |
+----------+            |             +---------+
                        |                  ^
                    +-------+              |
                    | msg.h |--------------+
                    +-------+

Testing procedure

This PR doesn't change code. It only relocates it. Hence, binaries shouldn't change.

Issues/PRs references

This circular dependency became an issue in #16174

@maribu maribu requested review from miri64, benpicco and kaspar030 May 7, 2021 18:01
@maribu maribu added Area: core Area: RIOT kernel. Handle PRs marked with this with care! CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Impact: minor The PR is small in size and might only require a quick look of a knowledgeable reviewer Process: needs >1 ACK Integration Process: This PR requires more than one ACK Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation labels May 7, 2021
Copy link
Contributor

@benpicco benpicco left a comment

Choose a reason for hiding this comment

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

Nice cleanup!

Copy link
Contributor

@kaspar030 kaspar030 left a comment

Choose a reason for hiding this comment

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

Pleas don't merge too quick, I'd like to take a closer look.

@benpicco
Copy link
Contributor

benpicco commented May 8, 2021

Yea Murdock has found some isssues.

@kaspar030
Copy link
Contributor

I'm not in favour of shuffling the headers around like this.

How about just forward declaring msg_t? The only reason thread.h needs msg_t is a single pointer. -> #16477

@MrKevinWeiss MrKevinWeiss removed this from the Release 2021.07 milestone Jul 15, 2021
@aabadie
Copy link
Contributor

aabadie commented Jan 5, 2022

This seems cleaner than #16477 (and needs a rebase).

@github-actions github-actions bot added Area: cpu Area: CPU/MCU ports Area: examples Area: Example Applications Area: tests Area: tests and testing framework Platform: RISC-V Platform: This PR/issue effects RISC-V-based platforms labels Jan 13, 2022
@maribu
Copy link
Member Author

maribu commented Jan 13, 2022

I'm not in favour of shuffling the headers around like this.

How about just forward declaring msg_t? The only reason thread.h needs msg_t is a single pointer. -> #16477

That doesn't solve the issue that sched.h depends on thread.h depends on sched.h ...

core/include/core_types.h Outdated Show resolved Hide resolved
@maribu
Copy link
Member Author

maribu commented Jan 13, 2022

@chrysn For this to be compatible with rust, riot_sys should use thread_t instead of struct _thread, right? That should also work with both current master and this PR.

@maribu maribu removed the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Jan 13, 2022
@chrysn
Copy link
Member

chrysn commented Jan 13, 2022

Rust has no difference between type names and named structs, and it looks at all the headers at once, so I don't think it makes any difference. Bindings already look like this:

#[repr(C)]
pub struct _thread {
    pub sp: *mut c_char,
    pub status: thread_status_t,
    // ...
}
pub type thread_t = _thread;

where thread_t is purely an alias for _thread and usable everywhere interchangeabl. That is, functions may declare either in their signature, but a user would use thread_t everywhere and it would be accepted -- it could just as well say pub struct thread_t { ... } / pub type _thread = thread_t;.

@maribu
Copy link
Member Author

maribu commented Jan 13, 2022

The issue is that with this PR, struct _thread is dropped and only thread_t is provided. It is a pity that Rust internally references the internal alias _thread. Would it be possible to drop this, so that this rust example would still build with this PR?

@chrysn
Copy link
Member

chrysn commented Jan 13, 2022 via email

@chrysn
Copy link
Member

chrysn commented Jan 13, 2022 via email

chrysn added a commit to RIOT-OS/rust-riot-sys that referenced this pull request May 31, 2022
_thread shouldn't have been used being an imlementationn detail; this
caused trouble with [16458].

[16458]: RIOT-OS/RIOT#16458 (comment)
@stale
Copy link

stale bot commented Aug 13, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions.

@stale stale bot added the State: stale State: The issue / PR has no activity for >185 days label Aug 13, 2022
@miri64
Copy link
Member

miri64 commented Aug 13, 2022

Huh, what happened here? Seems somewhat important!

@miri64 miri64 removed the State: stale State: The issue / PR has no activity for >185 days label Aug 13, 2022
@maribu
Copy link
Member Author

maribu commented Aug 13, 2022

I still think this should go in

maribu added 5 commits August 13, 2022 14:57
use `thread_t` instead of `struct _thread`
Dependency graph before:

     +-------------------------------------+
     |                                     |
     |                                     V
+----------+        +-------+         +---------+
| thread.h | -----> | msg.h | ------> | sched.h |
+----------+        +-------+         +---------+
     ^                                     |
     |                                     |
     +-------------------------------------+

Dependency graph after:

                 +--------------+
                 | core_types.h |
                 +--------------+
                    ^   ^   ^
                    |   |   |
      +-------------+   |   +--------------+
      |                 |                  |
+----------+            |             +---------+
| thread.h |            |             | sched.h |
+----------+            |             +---------+
                        |                  ^
                    +-------+              |
                    | msg.h |--------------+
                    +-------+
@maribu
Copy link
Member Author

maribu commented Aug 13, 2022

Rebased and reordered the commits so that the addition of missing #includes (which previously were pulled in indirectly) are added first, and the actual change comes afterwards. That way bisecting should be easier.

@benpicco benpicco added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Feb 22, 2023
@github-actions github-actions bot added the Process: missing approvals Integration Process: PR needs more ACKS (handled by action) label Feb 22, 2023
@Teufelchen1
Copy link
Contributor

Did we have another issue with circular dependency since #16174?
I feel a bit like not having enough insights into /core/ to have an opinion but if taken with a grain of salt, this looks like a reasonable change. I would approve it :>
Maybe you can rebase if you are still interested maribu?

@maribu
Copy link
Member Author

maribu commented Jan 24, 2024

We eventually have worked around the issue. But generally, circular dependencies in C headers are a bit messy, so this may be useful later down the road.

Maybe close this for now and pick this up again when someone bumps their feet on this again?

@Teufelchen1
Copy link
Contributor

Teufelchen1 commented Jan 25, 2024

Closed.

  • Problem has been identified
  • Multiple proposed solution, including this one, didn't get "enough approval"
  • Solution is not urgently needed
  • Will be revisited if someone finds another circular dependency error / issue

Thanks for your proposal @maribu! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: core Area: RIOT kernel. Handle PRs marked with this with care! Area: cpu Area: CPU/MCU ports Area: examples Area: Example Applications Area: tests Area: tests and testing framework CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Impact: minor The PR is small in size and might only require a quick look of a knowledgeable reviewer Platform: RISC-V Platform: This PR/issue effects RISC-V-based platforms Process: missing approvals Integration Process: PR needs more ACKS (handled by action) Process: needs >1 ACK Integration Process: This PR requires more than one ACK Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants