Skip to content

Dyno: implement removed cast copy behavior#27593

Merged
DanilaFe merged 4 commits intochapel-lang:mainfrom
DanilaFe:removed-cast-copy
Aug 5, 2025
Merged

Dyno: implement removed cast copy behavior#27593
DanilaFe merged 4 commits intochapel-lang:mainfrom
DanilaFe:removed-cast-copy

Conversation

@DanilaFe
Copy link
Contributor

@DanilaFe DanilaFe commented Aug 1, 2025

Closes https://github.com/Cray/chapel-private/issues/7329.

This causes the following program to cause a copy initialization of a:

record R {
}
proc consume(ref x) {}

proc test() {
  var a : R;
  var ret = a:R;
  consume(a);
  return ret;
}
var x = test();

The error in the original issue was resolved by @benharsh as of #27486; the program in the example works under --dyno-resolve-only. The key contribution of this PR is the invocation of the copy initializer, which production introduces via a call to _removed_cast, which has an in intent.

In the spirit of dyno -- where we try to avoid odd calls to unexpected internal functions -- this PR does not replicate the call to _removed_cast. Instead, it simply detects the auto-implemented redundant cast (added in #27486) and invokes the in-intent handling logic.

Generally speaking, once call resolution is completed, there's no way for the Resolver, or any other code, to detect how the resolution was performed. I was faced with a choice between implementing a general signaling mechanism (e.g., storing an enumeration for "how was this resolved" in CallResolutionResult or detecting the auto-cast as a special case. For now, lacking enough examples of how a general mechanism would be useful, and given how easy special-case detection is, I went with the special-casing. As a result, the VarScopeVisitor -- which performs the call to the in-intent handler -- has to do some sleuthing, detecting calls to : where no function candidate was detected.

Testing

  • dyno tests
  • motivator now produces a copy
  • paratest
  • paratest --dyno-resolve-only

Reviewed by @benharsh -- thanks!

This copy behavior relies on treating the LHS like
a thing-passed-to-in-intent, which is what production
effectively does by wrapping the cast in a `_removed_cast`
call.

Signed-off-by: Danila Fedorin <daniel.fedorin@hpe.com>
Signed-off-by: Danila Fedorin <daniel.fedorin@hpe.com>
This should prevent cases where the lhs and the whole cast
are both unknown/erroneous, in which case we shouldn't try
to invoke `in` intent logic

Signed-off-by: Danila Fedorin <daniel.fedorin@hpe.com>
@DanilaFe DanilaFe force-pushed the removed-cast-copy branch from 1c03e30 to 19d5f92 Compare August 1, 2025 21:57
Signed-off-by: Danila Fedorin <daniel.fedorin@hpe.com>
@benharsh benharsh self-requested a review August 5, 2025 20:11
Copy link
Member

@benharsh benharsh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! This should also help quiet down some of the noise in the typed converter.

@DanilaFe DanilaFe merged commit 8cf2648 into chapel-lang:main Aug 5, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants