forked from chapel-lang/chapel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dyno: add non-param casts to and from enums (chapel-lang#24563)
This PR adds casts to and from enums when the enum / integer is not a param value. It does so by mimicking what the production compiler does: building a single, generic "from" function, and a single, generic "to" function. The functions look something like this: ```Chapel operator :(from: theEnum, type to: integral) operator :(from: integral, type to: theEnum) ``` This requires some adjustments: * An easy initial adjustment is that the existing framework relies on the first formal to determine whether a compiler-generated candidate should be considered. However, in the above, the cast _to_ an enum uses a generic integral type as its "receiver". Thus, I make changes to support finding compiler-generated candidates for general binary operation. * A more significant adjustment is that to make the functions generic, we need to allow them to be instantiated. However, instantiation until this point has relied on the ability to find ASTs associated with each formal. In this PR I adjust the instantiation code to no longer have this assumption. With this PR, @benharsh's example resolves (when the standard library is enabled): <details> <summary>See motivatign example</summary> ```Chapel enum numbers { zero = 0, one = 1, two = 2, three = 3 } proc foo(param num : int) { select num:numbers { // no matching candidates when numbers.zero do return 42; when numbers.one do return 5.0; when numbers.two do return "hello"; } return b"hello"; } proc baz(num: int) { select num:numbers { // no matching candidates when numbers.zero do return 0; when numbers.one do return 1; when numbers.two do return 2; otherwise return 3; } } var x = foo(2); var y = baz(2); ```` </details> Reviewed by @benharsh -- thanks! ## Testing - [x] dyno tests - [x] paratest
- Loading branch information
Showing
7 changed files
with
463 additions
and
121 deletions.
There are no files selected for viewing
This file contains 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 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 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 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.