Repository navigation
T-Anthropic-Wire coproduct slice 3 — Anthropic messages 200-body residual paydown #2626
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
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1bff585
WIP: T-Anthropic-Wire coproduct slice 3 — Anthropic messages 200-body…
briansrls ac664d6
WIP: T-Anthropic-Wire coproduct slice 3 — Anthropic messages 200-body…
briansrls a89cba1
WIP: T-Anthropic-Wire coproduct slice 3 — Anthropic messages 200-body…
briansrls 8d81042
WIP: T-Anthropic-Wire coproduct slice 3 — Anthropic messages 200-body…
briansrls abe9c27
WIP: T-Anthropic-Wire coproduct slice 3 — Anthropic messages 200-body…
briansrls File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5276,6 +5276,90 @@ fn wire_child_for_segment(wire_node: Node, seg: String, source_indices: Map<Stri | |
| } | ||
| } | ||
|
|
||
| // REST typed-response projection: when the wire path names a record field on a | ||
| // coproduct arm (e.g. `content/0/text` on `List<AnthropicMessages200ContentBlock>`), | ||
| // struct-style `(...).text` projection fails because the leaf is a Disj. If | ||
| // exactly one variant payload carries a field whose wire/authored key matches | ||
| // `seg`, emit a `match &*(scrutinee) { Enum::Variant { field, .. } => field.clone(), ... }`. | ||
| fn payload_field_child_matching_seg(payload: Node, seg: String, source_indices: Map<String, NewlineIndex>) -> Node? { | ||
| if !is_product_type(n: payload) { | ||
| none | ||
| } else { | ||
| match payload.children |> filter(f => { | ||
| let authored = authored_name_at(source_indices: source_indices, node: f) | ||
| let wire_key = match child_from_key(ch: f, source_indices: source_indices) { | ||
| Some { value: k } => k | ||
| None => authored | ||
| } | ||
| wire_key == seg | ||
| }) |> first { | ||
| Some { value: fch } => Some { value: fch } | ||
| None => none | ||
| } | ||
| } | ||
| } | ||
|
|
||
| fn try_advance_wire_disjunct_field( | ||
| state: WirePathProjection, | ||
| seg: String, | ||
| full_path: String, | ||
| source_indices: Map<String, NewlineIndex> | ||
| ) -> WirePathProjection { | ||
| match state.node { | ||
| Some { value: n } => { | ||
| let normed = normalize_access_type_node(n: n) | ||
| if !is_coproduct_type(n: normed) { | ||
| WirePathProjection { expr: state.expr, node: none, ok: false } | ||
| } else { | ||
| let hit_variants = normed.children |> filter(variant_arm => { | ||
| let payload = resolved_type(n: variant_arm) | ||
| match payload_field_child_matching_seg(payload: payload, seg: seg, source_indices: source_indices) { | ||
| Some { value: _ } => true | ||
| None => false | ||
| } | ||
| }) | ||
| if hit_variants |> count != 1 { | ||
| WirePathProjection { expr: state.expr, node: none, ok: false } | ||
| } else { | ||
| match hit_variants |> first { | ||
| Some { value: variant_arm } => { | ||
| let payload = resolved_type(n: variant_arm) | ||
| match payload_field_child_matching_seg(payload: payload, seg: seg, source_indices: source_indices) { | ||
| Some { value: fch } => { | ||
| let enum_name = authored_name_at(source_indices: source_indices, node: normed) | ||
| let variant_name = authored_name_at(source_indices: source_indices, node: variant_arm) | ||
| let field_rust = emit_ident(name: authored_name_at(source_indices: source_indices, node: fch), target: Rust) | ||
| let match_expr = concat( | ||
| "match &*(", | ||
| state.expr, | ||
| ") { ", | ||
| enum_name, | ||
| "::", | ||
| variant_name, | ||
| " { ", | ||
| field_rust, | ||
| ", .. } => ", | ||
| field_rust, | ||
| ", _ => return Err(format!(\"REST typed response path ", | ||
| full_path, | ||
| ": expected ", | ||
| variant_name, | ||
| " arm\").into()) }" | ||
| ) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BLOCKING: The new variant-aware projection emits match &*(...) but content/0/text reaches an &Rc, so the generated Rust does not compile instead of failing closed as a valid typed projection. |
||
| WirePathProjection { expr: match_expr, node: Some { value: resolved_type(n: fch) }, ok: true } | ||
| } | ||
| None => WirePathProjection { expr: state.expr, node: none, ok: false } | ||
| } | ||
| } | ||
| None => WirePathProjection { expr: state.expr, node: none, ok: false } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| None => WirePathProjection { expr: state.expr, node: none, ok: false } | ||
| } | ||
| } | ||
|
|
||
| fn advance_wire_path_projection(state: WirePathProjection, seg: String, full_path: String, source_indices: Map<String, NewlineIndex>) -> WirePathProjection { | ||
| if !state.ok { state } | ||
| else if path_segment_is_list_index(seg: seg) { | ||
|
|
@@ -5297,7 +5381,7 @@ fn advance_wire_path_projection(state: WirePathProjection, seg: String, full_pat | |
| node: Some { value: resolved_type(n: ch) } | ||
| ok: true | ||
| } | ||
| None => WirePathProjection { expr: state.expr, node: none, ok: false } | ||
| None => try_advance_wire_disjunct_field(state: state, seg: seg, full_path: full_path, source_indices: source_indices) | ||
| } | ||
| None => WirePathProjection { expr: state.expr, node: none, ok: false } | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
BLOCKING: Variant-aware response projection emits match &*(...) even after a list-index step, so content/0/text over Rc<Vec<Rc>> matches &Rc<...> instead of &AnthropicMessages200ContentBlock and the generated client does not compile, violating P3 fail-closed emission.