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

Add facet type values and an instruction that produces them #4460

Merged
merged 24 commits into from
Nov 4, 2024

Conversation

josh11b
Copy link
Contributor

@josh11b josh11b commented Oct 30, 2024

Still to do:

  • Represent facet type values in a canonical form
  • Produce & consume facet type values instead of interface values
  • type should be associated with a canonical facet type value
  • Support & on facet type values
  • Type check and enforce requirements in facet types

@zygoloid zygoloid added this pull request to the merge queue Nov 4, 2024
Merged via the queue into carbon-language:trunk with commit ea0b0b4 Nov 4, 2024
8 checks passed
@@ -79,6 +79,7 @@ auto HandleParseNode(Context& context, Parse::RequirementEqualEqualId node_id)
auto rhs = context.node_stack().PopExpr();
auto lhs = context.node_stack().PopExpr();
// TODO: type check lhs and rhs are comparable
// TODO: require that at least one side uses a designator
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a reminder, as I was seeing several of these, but it'd be helpful if you could adhere to sentence capitalization and punctuation in comments. I believe this includes TODOs.

https://google.github.io/styleguide/cppguide.html#Punctuation,_Spelling_and_Grammar

@josh11b josh11b deleted the facettype branch November 5, 2024 01:17
github-merge-queue bot pushed a commit that referenced this pull request Nov 11, 2024
This does a few things:
* Replaces the single `TypeId` in the `FacetTypeInfo` struct with a
vector of `InterfaceId`, `SpecificId` pairs (sorted in id order)
representing the set of interface requirements of the facet type. This
will later be used to support facet types with multiple interface
requirements (as in `I & J` or `I where .Self impls J`).
* Replace `InterfaceType` instructions (used as the type of an
`InterfaceDecl` instruction) with `FacetType` instructions (introduced
in #4460) with a (newly introduced) `FacetTypeFromInterface()` function.
* Replace code that consumed `InterfaceType` values with code that
consumed `FaceType` values. I've generally left the assumption in the
code that it is dealing with a single interface, using the (newly
introduced) `FacetTypeInfo::TryAsSingleInterface`, and producing an
error otherwise. There isn't yet support for the `&` operator or `where
.Self impls`, so this is generally a good assumption for now, except you
can get a facet type with no associated interfaces from a `type
where`... expression. In some cases, the facet type value is pulled from
the evaluation of an `InterfaceDecl` instruction, where the single
interface assumption will hold permanently.
* Some related cleans up: nicer stringification and formatting of facet
types, suppression of some errors when there already was an error.

There is still a lot left to do, including:
* Type `type` should be a facet type with a reserved id, replacing the
built-in instruction.
* Code using `TryAsSingleInterface` should generally be upgraded to
handle more than (or less than) one interface. Name lookup should be
particularly exciting.
* Operator `&` should be defined on facet types, unioning their
interface and other requirements.
* Requirements from a `where` clause don't do anything yet.
* Impls and impl lookup need to resolve facet types, and do things like
determine if all the associated constants are given values.

---------

Co-authored-by: Josh L <[email protected]>
Co-authored-by: Geoff Romer <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants