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

Re-considering package generic boundary #1315

Closed
dalance opened this issue Mar 3, 2025 · 8 comments · Fixed by #1336
Closed

Re-considering package generic boundary #1315

dalance opened this issue Mar 3, 2025 · 8 comments · Fixed by #1336
Labels
lang Language design

Comments

@dalance
Copy link
Collaborator

dalance commented Mar 3, 2025

#1223 and #1294 introduced generic package basename as generic boundary, but there seems to be a problem.
For example, the function signature of func is not determined in the following code.
So deep nested foo_pkg causes long and complex type error like C++'s template.

package foo_pkg::<T: type> {
  function func (x: input T) -> T {
  }
}

This is the reason why proto module was introduced.
So I think making clear what members are visible through generic variables using proto package
is better even though some boilerplate code is necessary.

proto package proto_foo {
  const ADDRESS_WIDTH: u32;
  const DATA_WIDTH:    u32;
  type address_t;
  type data_t;
}

package foo_pkg::<AW: const, DW: const> for proto_foo {
  const ADDRESS_WIDTH: u32 = AW;
  const DATA_WIDTH:    u32 = DW;
  type address_t = logic<ADDRESS_WIDTH>;
  type data_t    = logic<DATA_WIDTH>;
}

module foo_top::<PKG: proto_foo> (
  i_address: input PKG::address_t,
  i_data:    input PKG::data_t,
) {
  import PKG::*;

  var address: address_t;
}

By this approach, controlling member visibility is enabled.

proto package proto_foo {
  type address_t;
  type data_t;
}

package foo_pkg::<AW: const, DW: const> for proto_foo {
  // The following const are not visible through generic variables
  const ADDRESS_WIDTH: u32 = AW;
  const DATA_WIDTH:    u32 = DW;

  type address_t = logic<ADDRESS_WIDTH>;
  type data_t    = logic<DATA_WIDTH>;
}

@taichi-ishitani How do you think about it?

@dalance dalance added the lang Language design label Mar 3, 2025
@taichi-ishitani
Copy link
Contributor

Do we need to speicfy types of parameters and/or result of a proto function?

@dalance
Copy link
Collaborator Author

dalance commented Mar 3, 2025

Do we need to speicfy types of parameters and/or result of a proto function?

I think it is more safety because it protects unexpected type errors caused by wrong usage.

@taichi-ishitani
Copy link
Contributor

OK, I understand.
I will work on this after closing #1312.

@dalance
Copy link
Collaborator Author

dalance commented Mar 3, 2025

I'm preparing to release v0.14.0. How do you think whether this issue and #1312 should be included in v0.14.0?
I can wait to complete all of them, or release v0.14.0 by disabling #1223 temporarily.

@taichi-ishitani
Copy link
Contributor

I think it will take 1 week to fix package boundary issues.

@dalance
Copy link
Collaborator Author

dalance commented Mar 3, 2025

OK.I'll release v0.14.0 without #1223 because it already contains enough updates.

@taichi-ishitani
Copy link
Contributor

definitions of enum, struct and union in a proto package are same with actual definitions.
It would be nice to copy these definitions from proto package from actual package.

@dalance
Copy link
Collaborator Author

dalance commented Mar 4, 2025

It would be nice to copy these definitions from proto package from actual package.

I think so too. But completly automatic copy may be confusable about where these types are defined.
I prefer small explicit syntax. It may be related #1212.

taichi-ishitani added a commit to taichi-ishitani/veryl that referenced this issue Mar 5, 2025
taichi-ishitani added a commit to taichi-ishitani/veryl that referenced this issue Mar 5, 2025
taichi-ishitani added a commit to taichi-ishitani/veryl that referenced this issue Mar 5, 2025
taichi-ishitani added a commit to taichi-ishitani/veryl that referenced this issue Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lang Language design
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants