Skip to content
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

Dyno: check return types when validating interface constraints #26471

Merged
merged 12 commits into from
Jan 17, 2025

Conversation

DanilaFe
Copy link
Contributor

@DanilaFe DanilaFe commented Jan 6, 2025

Depends on #26396.

This PR implements return type checking for interfaces. To fit that nicely into the existing structure, it separates the main "find function that matches the given interface requirement" into pieces (building the call, picking a candidate, checking the formals, return type, and return intent). From there, it implements the rules as currently specified in interfaceResolution.

The rules are as follows:

For types:

  • For iterators, we check the yield type of the iterator, since calls to different iter procedures produce distinct return types.
  • Otherwise, we expect an exact match of the return type, with the one exception...
  • When using a promoted call to satisfy an interface constraint (allowed in production), we require that both the interface requirement and the matching function return 'void'.

For intents:

  • Outside of an exact match, we allow ref, const ref, and param returns where values are expected (we can just dereference / construct a value).
  • For functions that expect cons ref, we allow ref, since we can always not modify the mutable reference.

Reviewed by @dlongnecke-cray -- thanks!

Testing

  • dyno tests
  • paratest

@DanilaFe DanilaFe force-pushed the dyno-interfaces-return-types branch 2 times, most recently from 9da542f to c8afd59 Compare January 8, 2025 00:51
@DanilaFe DanilaFe force-pushed the dyno-interfaces-return-types branch from c8afd59 to 8c41029 Compare January 15, 2025 01:36
Signed-off-by: Danila Fedorin <[email protected]>
@DanilaFe DanilaFe merged commit 76bd456 into chapel-lang:main Jan 17, 2025
8 checks passed
DanilaFe added a commit that referenced this pull request Jan 21, 2025
This PR adds support for context managers:

```Chapel
manage bla as foo {
  // etc.
}
```

It does so by leaning on interface support, since we have decided to use
them to "bless" the special methods `enterContext` and `exitContext`. As
such, this PR depends on
#26396 and
#26471.

The diff without the interface implementations can be found here:
https://github.com/chapel-lang/chapel/pull/26494/files/8c4102910462ff3e792bddaa75e01bdbf1b2ee63..a2e2745e3d47a65c284fb8119660288f028bbaa4

The general approach is straightforward: since we can compute witnesses
for special interfaces like `contextManager`, this PR ensures that
`manage` statements find the `contextManager` interface, and then use
the witness functions as associated actions. Some complications arise
due to the fact that context managers are design right now must be able
to resolve return-intent-overloaded functions at `manage` time, which
means (if the witness approach is to be used) that witnesses must
contain all overloads. This PR adjusts for that, but only stores the
additional overloads when `ifc any return intent` (the pragma that
decorates `enterContext`) is used, thus attempting to avoid paying the
multi-overload cost for other interfaces and functions.

Reviewed by @riftEmber -- thanks!

## Testing
- [x] dyno tests
- [x] paratest
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