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

vendor, io: fix missing i_domain and o_domain arguments when specializing #1347

Closed

Conversation

richardeoin
Copy link
Contributor

Platforms implement the get_io_buffer method to provide vendor-specific implementations of io.Buffer, io.FFBuffer and io.DDRBuffer. Currently several platforms use isinstance to match the type of buffer, then construct a child class of the relevant buffer and return this object. Unfortunately these platforms miss the optional i_domain and o_domain arguments when calling the constructor, thus placing the vendor-specific specialisations in the default sync domain even if an different domain is specified in user code. This is the bug.

Only io.FFBuffer and io.DDRBuffer are affected as these are currently the only buffers with optional arguments in the constructor signature.

This could be fixed by modifying each vendor implementation to pass the optional arguments as required. That might look like this:

DDRBufferSpecialised(buffer.direction, buffer.port, i_domain=getattr(buffer, '_i_domain', None), o_domain=getattr(buffer, '_o_domain', None))

However this pushes more complexity into the vendor implementation and requires maintenance across an ever increasing number of vendor files.

This PR implements a factory method called create_from on the base class. This method is used in the vendor implementations to correctly create the specialised classes.

This is a fix for the new lib.io components, so mentioning the tracking issue here #1210

@richardeoin
Copy link
Contributor Author

Arguably this method should also be implemented on Buffer for consistency. Very happy to add that after review.

@whitequark
Copy link
Member

I've taken a quick look at your PR. Offhand, there are two concerns:

  • It adds a new public API, which isn't something we do without at least some upfront design.
  • It raises questions about the design of the existing API as well.

I think this PR should probably be a blocker for the 0.5 release, but other than that we'll need more discussion of the direction first. I'll only be able to get around to that after handling some of the other release blockers first.

@whitequark whitequark added this to the 0.5 milestone May 4, 2024
@whitequark whitequark mentioned this pull request May 4, 2024
77 tasks
@richardeoin
Copy link
Contributor Author

Indeed this was a sharp edge on the existing API (as viewed from the vendor implementation) that I have sanded down with this PR, but it may be that a different solution avoids this completely. I can also write this up as an issue (without the solution) if that is easier for the triage process?

@whitequark
Copy link
Member

The PR is fine.

wanda-phi added a commit to wanda-phi/amaranth that referenced this pull request May 5, 2024
Having conditionally-present attributes causes more problems than it's
worth (see amaranth-lang#1347). Just make them contain `None` when irrelevant.
wanda-phi added a commit to wanda-phi/amaranth that referenced this pull request May 5, 2024
wanda-phi added a commit to wanda-phi/amaranth that referenced this pull request May 5, 2024
Having conditionally-present attributes causes more problems than it's
worth (see amaranth-lang#1347). Just make them contain `None` when irrelevant.
wanda-phi added a commit to wanda-phi/amaranth that referenced this pull request May 5, 2024
github-merge-queue bot pushed a commit that referenced this pull request May 5, 2024
Having conditionally-present attributes causes more problems than it's
worth (see #1347). Just make them contain `None` when irrelevant.
@richardeoin
Copy link
Contributor Author

Awesome that this is fixed now 🎉

@richardeoin richardeoin deleted the platform-buffer-domains-fix branch May 7, 2024 12:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants