-
-
Notifications
You must be signed in to change notification settings - Fork 29
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
Introduce inst
generic boundary
#1192
Introduce inst
generic boundary
#1192
Conversation
CodSpeed Performance ReportMerging #1192 will not alter performanceComparing Summary
|
e7c90ff
to
60cf6da
Compare
@@ -210,12 +210,62 @@ impl VerylGrammarTrait for CheckType<'_> { | |||
)); | |||
} | |||
} | |||
GenericBoundKind::Inst(proto) => { | |||
let proto_match = if arg.is_resolvable() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At Rust 2024 (Rust 1.85), if-let chain will be stabilized.
After it, this large if chain can be re-written like below. So TODO
comment may be useful to mark for re-writing.
if arg.is_resolvable()
&& let Ok(symbol) = ...
&& let SymbolKind::Instance(x) = ...
&& let Ok(x) = ...
&& let Some(ref x) = x.found.proto() {
...
} else {
false
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added todo comments.
// TODO: |
// TODO: |
@@ -41,3 +42,9 @@ module Module55H::<W: const> { | |||
|
|||
let _a: StructH::<W> = 0; | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this example is bit strange.
IF
is bound by Interface55I
, but Interface55I
is not proto
but specific type, so IF
is always Interface55I
.
Therefore I think generics is not required in this case.
How about adding proto interface
support described at #963 like below?
proto interface PInterface {
function FuncA(a: input logic, b: input logic) -> logic;
}
interface Interface55I for PInterface {
function FuncA(a: input logic, b: input logic) -> logic {
return 0;
}
}
module Module55I::<IF: PInterface> {
inst u: IF;
}
module X {
inst u: Module55I::<Interface55I>;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with you but a lot of changes is needed to introduce proto interface
.
For now, how about removing this example and opening a new PR to introduce proto interface
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree you. check_type.rs:387-390
and symbol.rs:304
should be removed probably.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed changes to allow interface to be used as generic boundary.
59aa506
to
c353e61
Compare
inst
generic boundary
crates/analyzer/src/symbol.rs
Outdated
pub fn proto(&self) -> Option<SymbolPath> { | ||
match &self.kind { | ||
SymbolKind::Module(x) => x.proto.clone(), | ||
SymbolKind::Interface(_) => Some((&self.token).into()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this line necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
It is used at here.
if let Some(ref x) = symbol.found.proto() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this PR, interface can't be used as generic boudary. So I think adding SymbolKind::Interface(_)
is not necessary, and SymbolKind::Interface(x) => x.proto.clone(),
should be added at introducing proto interface.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The inst
boundary with specific interface is needed for usecase shown in #793.
Therefore, this change is needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understood this line is used, but I think it is not appropriate that non proto symbol returns Some
from proto()
.
Changing proto()
to proto_or_inst()
or splitting it into proto()
and inst()
is better.
I prefer the splitting way because inst can be assigned to a generic parameter bound as proto if proto and inst are not distincted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the statement for the SymbolKind::Interface
but did not add the inst
function.
Instead of the function, I added resolve_inst_generic_arg_type
and resolve_proto_generic_arg_type
functions to simplify resolving type of generic arguments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
I think this is better than my idea.
314175c
to
446f727
Compare
* introduce a new generic bound `inst` to specify module/interface instance
446f727
to
33f9eb6
Compare
This PR is to a new generic boundary named
inst
.The
isnt
boundary is to specify module or interface instance as a generic parameter.refs: #963 (comment)