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

Support BitAnd operator between facet types #5022

Merged
merged 12 commits into from
Feb 27, 2025

Conversation

danakj
Copy link
Contributor

@danakj danakj commented Feb 26, 2025

Doing so results in TODOs in the resulting semir, since we don't handle
combining the facet types together properly or doing lookup into them.
There's a test added demonstrating this, which will be made to work in
followups.

This avoids the suffix changing when adding new impls to the prelude,
or in user code.
Doing so results in TODOs in the resulting semir, since we don't handle
combining the facet types together properly or doing lookup into them.
There's a test added demonstrating this, which will be made to work in
followups.
@danakj
Copy link
Contributor Author

danakj commented Feb 26, 2025

This is rebased on top of #5021

danakj and others added 2 commits February 26, 2025 16:40
Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
@danakj danakj requested a review from jonmeow February 26, 2025 21:53
@jonmeow
Copy link
Contributor

jonmeow commented Feb 26, 2025

@danakj Noting since you requested review again, you might've missed a couple comments

@danakj
Copy link
Contributor Author

danakj commented Feb 26, 2025

@danakj Noting since you requested review again, you might've missed a couple comments

Oh huh, I did thanks

} else {
CARBON_DIAGNOSTIC(
FacetTypeRequiredForTypeAndOperator, Error,
"BitAnd operator on types requires facet type on both sides");
Copy link
Contributor

Choose a reason for hiding this comment

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

How about something like:

Suggested change
"BitAnd operator on types requires facet type on both sides");
"{0} is not a facet type", SemIR::TypeId);

(passing context.types().GetTypeIdForTypeInstId(arg_id))

As I think more about the repeated diagnostic -- https://github.com/carbon-language/carbon-lang/blob/trunk/toolchain/docs/diagnostics.md#diagnostic-message-style-guide says "Diagnostics should describe the situation the toolchain observed. The language rule violated can be mentioned if it wouldn't otherwise be clear."

The current phrasing sounds like a language rule, maybe the suggested message is closer to the source of the error? You could add something like "; using & on types requires facet types` if you think it's needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right true, it's "a non-facet type was found here" error. The downside is that it has to be phrased in the negative with "non-" there. I don't know what name to use for a type that isn't a facet type otherwise.

Copy link
Contributor

Choose a reason for hiding this comment

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

This SG, though why aren't you including the type ID?

Note abstractly:

fn GetC() -> type { return C; }
fn GetA() -> type { return A; }

// Should be happy.
({} as C) as (C as (GetA() & GetA()));
// Would be helpful to print `C` here.
({} as C) as (C as (GetC() & GetC()));

Copy link
Contributor Author

@danakj danakj Feb 27, 2025

Choose a reason for hiding this comment

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

Ah that's a good idea, I hadn't thought of it.

+  // CHECK:STDERR: fail_combine_with_non_facet_type.carbon:[[@LINE+4]]:23: error: non-facet type `C` combined with `&` operator [FacetTypeRequiredForTypeAndOperator]

That's better :) Thanks!

Comment on lines 1341 to 1344
// TODO: Find a location for the lhs or rhs specifically, instead of
// the whole thing. If that's not possible we can change the text to
// say if it's referring to the left or the right side for the error.
context.emitter().Emit(loc, FacetTypeRequiredForTypeAndOperator);
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of loc, can you pass arg_id here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I preemptively answered this - but no. The arg_id has no location at all, so the diagnostics get orphaned at the top of the test output.

Copy link
Contributor

Choose a reason for hiding this comment

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

FTR this is weird to me, I think the instruction should have a location. But that's not for this PR.

Copy link
Contributor Author

@danakj danakj left a comment

Choose a reason for hiding this comment

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

PTAL

Comment on lines 1341 to 1344
// TODO: Find a location for the lhs or rhs specifically, instead of
// the whole thing. If that's not possible we can change the text to
// say if it's referring to the left or the right side for the error.
context.emitter().Emit(loc, FacetTypeRequiredForTypeAndOperator);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I preemptively answered this - but no. The arg_id has no location at all, so the diagnostics get orphaned at the top of the test output.

} else {
CARBON_DIAGNOSTIC(
FacetTypeRequiredForTypeAndOperator, Error,
"BitAnd operator on types requires facet type on both sides");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right true, it's "a non-facet type was found here" error. The downside is that it has to be phrased in the negative with "non-" there. I don't know what name to use for a type that isn't a facet type otherwise.

@danakj danakj requested a review from jonmeow February 26, 2025 22:33
Copy link
Contributor

@jonmeow jonmeow left a comment

Choose a reason for hiding this comment

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

LG, just wondering why you're not putting the TypeId in the diagnostic?

Comment on lines 1341 to 1344
// TODO: Find a location for the lhs or rhs specifically, instead of
// the whole thing. If that's not possible we can change the text to
// say if it's referring to the left or the right side for the error.
context.emitter().Emit(loc, FacetTypeRequiredForTypeAndOperator);
Copy link
Contributor

Choose a reason for hiding this comment

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

FTR this is weird to me, I think the instruction should have a location. But that's not for this PR.

} else {
CARBON_DIAGNOSTIC(
FacetTypeRequiredForTypeAndOperator, Error,
"BitAnd operator on types requires facet type on both sides");
Copy link
Contributor

Choose a reason for hiding this comment

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

This SG, though why aren't you including the type ID?

Note abstractly:

fn GetC() -> type { return C; }
fn GetA() -> type { return A; }

// Should be happy.
({} as C) as (C as (GetA() & GetA()));
// Would be helpful to print `C` here.
({} as C) as (C as (GetC() & GetC()));

@danakj danakj enabled auto-merge February 27, 2025 16:55
@danakj danakj added this pull request to the merge queue Feb 27, 2025
Merged via the queue into carbon-language:trunk with commit 129cf35 Feb 27, 2025
8 checks passed
@danakj danakj deleted the type-and branch February 27, 2025 18:51
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.

2 participants