Repository navigation
feat(sv)!: support shallow copies of class objects - #1810
Conversation
|
This pull request is part of a Mergify stack:
|
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9831f346cc
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| let Some(source_class) = native_class(tree, *source, native, dimensions) else { | ||
| return Err(unsupported( | ||
| "shallow copy of a value that is not a class handle", | ||
| )); |
There was a problem hiding this comment.
Support class-valued expressions as copy sources
When the shallow-copy operand is a class-valued function or method call, cast, or conditional expression—for example, C dst = new make_c();—native_class cannot determine its class because it only recognizes handle variables, selected array elements, and properties. This branch therefore reports that the value is not a class handle before bind_value runs, rejecting valid new expression shallow copies. Infer the operand's class from its expression type rather than requiring one of the narrow syntactic forms accepted by native_class.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Tracked in #1891 (shallow copies of class-valued expressions, in any context and of null): these forms are rejected with a diagnostic today, not lowered wrongly.
| // `new h` copies the properties of the object of `h` into a new object | ||
| // of its class; handles are copied, not the objects they refer to (IEEE | ||
| // 1800-2023 8.12). | ||
| if let ExprKind::Copy(source) = &native.expression(ungroup(id, native)).kind { |
There was a problem hiding this comment.
Lower copy nodes in non-assignment expression contexts
A Copy node is lowered only when constructor is called for the complete right-hand side of an assignment, declaration initializer, or property initializer. In other valid contextual positions such as take(new h), return new h, or a conditional branch, normal bind_value traversal reaches the new node and rejects it as an unsupported primary expression, even when the formal, return, or enclosing assignment type supplies the required class. Handle ExprKind::Copy wherever a class-valued expression is bound, rather than only at top-level assignment sites.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Tracked in #1891 (shallow copies of class-valued expressions, in any context and of null): these forms are rejected with a diagnostic today, not lowered wrongly.
| TokenKind::Identifier | TokenKind::EscapedIdentifier | ||
| ) && (!self.reserved_identifier(token) | ||
| || matches!(token.text.as_str(), "this" | "super")) |
There was a problem hiding this comment.
Accept null as a shallow-copy operand
The lookahead recognizes a shallow copy only when the token after new is a non-reserved identifier, this, or super, so an assignment such as C dst; initial dst = new null; does not produce ExprKind::Copy and fails during parsing instead of reaching the null-copy runtime fault implemented by this change. null is an expression operand of the new expression form, so it needs to be recognized here and typed from the destination context.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Tracked in #1891 (shallow copies of class-valued expressions, in any context and of null): these forms are rejected with a diagnostic today, not lowered wrongly.
|
Queued — the merge queue status continues in this comment ↓. |
c1e74be to
b582538
Compare
9831f34 to
fd93137
Compare
Revision history
|
fd93137 to
75eeaba
Compare
b582538 to
f3f644e
Compare
f3f644e to
76f7612
Compare
75eeaba to
2a56321
Compare
2a56321 to
e11b661
Compare
76f7612 to
a534644
Compare
e11b661 to
d441141
Compare
c6c132b to
d9b70cf
Compare
d441141 to
458faa0
Compare
d9b70cf to
ba224ec
Compare
458faa0 to
322bd44
Compare
ba224ec to
e07fd68
Compare
322bd44 to
9120d4d
Compare
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
1 similar comment
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
e07fd68 to
1f3bd97
Compare
9120d4d to
06d0395
Compare
|
Local review (Codex CLI) of this commit:
Rebased onto master: |
1f3bd97 to
880e92e
Compare
06d0395 to
ce9510e
Compare
`new h` creates an object of the class of the object that `h` refers to, with a copy of its properties, without running a constructor or property initializers; a property holding a handle keeps referring to the same object (IEEE 1800-2023 8.12). The copy is assignment checked like any other handle, and copying `null` is a runtime error. The parser gives `new h` its own expression node, also as a variable initializer, where it used to be accepted and dropped. The analyzer lowers it to an object copy operation, and the heap copies the object, keeping its handle properties visible to collection. sv-tests: 8.12--shallow_copy passes (1081/1092 passing). Icarus 13.0 does not parse shallow copies, which is recorded with evidence; Verilator passes the shared case. BREAKING CHANGE: celox_sv_syntax::ExprKind gains Copy and the analyzer IR ObjectOp gains Copy. Change-Id: Iace3f3bb801198a7b371c95fdb979244dbd95fb4
ce9510e to
0cc4b2e
Compare
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Merge Queue Status
This pull request spent 28 minutes 28 seconds in the queue, including 26 minutes 48 seconds running CI. Required conditions to merge
|
new hcreates an object of the class of the object thathrefers to,with a copy of its properties, without running a constructor or property
initializers; a property holding a handle keeps referring to the same object
(IEEE 1800-2023 8.12). The copy is assignment checked like any other handle,
and copying
nullis a runtime error.The parser gives
new hits own expression node, also as a variableinitializer, where it used to be accepted and dropped. The analyzer lowers
it to an object copy operation, and the heap copies the object, keeping its
handle properties visible to collection.
sv-tests: 8.12--shallow_copy passes (1081/1092 passing). Icarus 13.0 does not
parse shallow copies, which is recorded with evidence; Verilator passes the
shared case.
BREAKING CHANGE: celox_sv_syntax::ExprKind gains Copy and the analyzer IR
ObjectOp gains Copy.
Depends-On: #2093