Skip to content

Conversation

josh11b
Copy link
Contributor

@josh11b josh11b commented Apr 29, 2025

We propose:

  • Special type Core.Form whose values describe the form (category, phase, and so on) of parameters or returns in the signature of functions.
  • A form(...) literal syntax for writing values of these form types.
  • Form facet types for expressing constraints on form types, which may be composed using &.
  • :? binding and ->? return syntax parameterized by a form value.
  • Form versions of interfaces, facets, and facet types.
  • Use these new form facet types to create new "primitive" versions of the operator interfaces, like Core.CallPrimitive, that allow control over the form of the parameters and return.
  • A call(...) syntax for concisely and naturally writing facet types of the Core.CallPrimitive interface.
  • Impl lookup will allow some conversions between Core.Form values in interface arguments and associated constants, when specified by the interface, replacing the existing mechanism where impls use like to allow implicit conversions in arguments.
  • A number of increased capabilities for named constraints.

Together these changes will allow:

  • the operator interfaces to support Carbon's full range of function semantics, particularly in the Core.CallPrimitive form interface;
  • replacing our existing operator interfaces like Core.Call and Core.AddWidth with named constraints that use types instead of forms;
  • a new, more capable definition of alias, along with a shorthand using;
  • full-fidelity forwarding of function parameters; and
  • a syntax for a compile-time parameter that is equal to a specified value.

@josh11b josh11b added proposal A proposal proposal draft Proposal in draft, not ready for review labels Apr 29, 2025
@josh11b josh11b changed the title Function overloading Call interface upgrade Apr 30, 2025
@josh11b josh11b changed the title Call interface upgrade Generic across forms May 19, 2025
@josh11b josh11b marked this pull request as ready for review September 10, 2025 00:34
@github-actions github-actions bot requested a review from chandlerc September 10, 2025 00:34
@github-actions github-actions bot added proposal rfc Proposal with request-for-comment sent out documentation An issue or proposed change to our documentation and removed proposal draft Proposal in draft, not ready for review labels Sep 10, 2025

In addition, there are a number of outstanding problems in Carbon that arise
from a construct requiring some specification of aspects in a binding when it
should instead to a
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like something's missing here.

- `Core.ValSelf`, `Cor.RefSelf`, and `Core.VarSelf` that take a `Core.Form`
facet type and return an ordinary `type` facet type with the specified
category used for `Self`.
- `Core.Form where .type = T` which gives a form facet type that matches any
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems like it follows from what's already been said about Core.Form and .type, rather than being a separate feature introduced by this proposal. Am I missing something?

- An `impl` may use `anchor` or `exact` to limit the conversions allowed,
which can be needed to satisfy the orphan rule.
- Implied constraints are not added for variant parameters.
- When normally we would for a facets of an interface, if that interface
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm having a hard time parsing this sentence -- I feel like maybe there's a missing verb after "would", and "a facets" is clearly a typo but I'm not sure what the correct version is.

Comment on lines +3405 to +3407
The [compound form approach we settled on](#compound-form-values) had the
advantage of supporting all the composition we wanted without needing any
dedicated syntax. It is a bit verbose, but that is perhaps acceptable given that
Copy link
Contributor

Choose a reason for hiding this comment

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

Why can't we instead say that form() can contain anything that can appear in a ->? return form, e.g. form((var i32, ref f64, formof(7)))? That requires no more dedicated syntax than the current proposal, and it would make the language more consistent, as well as making compound form literals less verbose.

With this approach, the call to `F` would convert the reference expression `a`
into a value before overload resolution and select "Overload V."

We instead decided that `ref` on an argument only affects deduction. In this
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
We instead decided that `ref` on an argument only affects deduction. In this
We instead decided that `ref` on an argument only affects deduction, because this
minimizes the divergence between function calls and other forms of pattern maching. In this

Feel free to take or leave that particular suggestion, but it would be good to give some indication of why we chose this.

Comment on lines +2028 to +2032
This allows us to address the use case of creating a binding that is
[referentially transparent](https://en.wikipedia.org/wiki/Referential_transparency),
as considered in leads issues
[#996](https://github.com/carbon-language/carbon-lang/issues/996) and
[#1371](https://github.com/carbon-language/carbon-lang/issues/1371). For
Copy link
Contributor

Choose a reason for hiding this comment

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

If I understand correctly, the binding itself isn't quite referentially transparent, because if y is an initializing expression, x will be a reference expression. Instead, ~x is referentially transparent (given the assumptions you make elsewhere about the semantics of ~). It's probably worth saying so explicitly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation An issue or proposed change to our documentation proposal rfc Proposal with request-for-comment sent out proposal A proposal

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants