Skip to content

Conversation

bricknerb
Copy link
Contributor

@bricknerb bricknerb commented Jul 7, 2025

Before this change we crash in this case when trying to use the outer type.
After this change we diagnose a TODO.
Will add the missing support for this in a separate PR.

Part of #5533.

@bricknerb bricknerb changed the title Explicitly unsupport and avoid crashing mapping parameter record type defined not in a namespace Explicitly mark as unsupported instead of crashing mapping a parameter record type defined not in a namespace Jul 7, 2025
@github-actions github-actions bot requested a review from jonmeow July 7, 2025 14:27
};

auto foo1(P::C) -> void;
auto foo2(P) -> void;
Copy link
Contributor

@jonmeow jonmeow Jul 7, 2025

Choose a reason for hiding this comment

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

In each of these, you have this foo2 with a call. However, is it necessary for the test (it's not inside the namespace)? If not, I'd suggest removing it; I'm not clear it's testing distinct behavior. If so, please add a comment clarifying what it's doing.

Copy link
Contributor

Choose a reason for hiding this comment

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

Or, if you mean to test behavior of a type that contains another type, maybe that should be a separate test to clarify what you're trying to test?

Copy link
Contributor Author

@bricknerb bricknerb Jul 8, 2025

Choose a reason for hiding this comment

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

Thanks, done.
I've changed this PR to be made of:

  • First commit: Just adds tests that don't diagnose for class and struct and wrongly treat the outer record as a namespace. This can be a separate PR.
  • The rest fixes that and adds the tests that would have crashed without the fix.

Copy link
Contributor

@jonmeow jonmeow Jul 8, 2025

Choose a reason for hiding this comment

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

You've split tests. But I don't think you're addressing my question of what the test is achieving.

That is, why is "Pass outer class after passing inner class" an interesting thing to test, particularly when including all the SemIR for both calls? I agree that's what it does, but what is the test going to be testing that is meaningfully different? (if you just want to test passing the outer class that has a nested class, why not only test that and have less IR? why is "after" important?)

Copy link
Contributor

Choose a reason for hiding this comment

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

To be clear, I'm asking you to comment your code.

Comment on lines 211 to 219
// --- inner_and_outer_value_param_type.h

class O {
public:
class C {};
};

auto foo1(O::C) -> void;
auto foo2(O) -> void;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this same header be shared, rather than copying it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

import Cpp library "inner_and_outer_value_param_type.h";

fn F() {
//@dump-sem-ir-begin
Copy link
Contributor

Choose a reason for hiding this comment

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

Does the SemIR need to be captured for the first call? Will it differ from the above test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

};

auto foo1(P::C) -> void;
auto foo2(P) -> void;
Copy link
Contributor

@jonmeow jonmeow Jul 8, 2025

Choose a reason for hiding this comment

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

You've split tests. But I don't think you're addressing my question of what the test is achieving.

That is, why is "Pass outer class after passing inner class" an interesting thing to test, particularly when including all the SemIR for both calls? I agree that's what it does, but what is the test going to be testing that is meaningfully different? (if you just want to test passing the outer class that has a nested class, why not only test that and have less IR? why is "after" important?)

// CHECK:STDERR: ^~~~~~~~
// CHECK:STDERR:
Cpp.foo1({});
Cpp.foo2({});
Copy link
Contributor

@jonmeow jonmeow Jul 8, 2025

Choose a reason for hiding this comment

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

If you're just trying to verify that Cpp.O is a type, maybe:

Suggested change
Cpp.foo2({});
//@dump-sem-ir-begin
// Verify `O` is a valid type.
var x: Cpp.O;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Trying this out actually revealed another bug here, which I've sent a fix for in #5789.
I think it's better to fix that first.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

…other record type.

The code assumes the outer record is a namespace.
…r record type defined not in a namespace

Before this change we crash in this case.
After this change we diagnose a TODO.
Will add the missing support for this in a separate PR.

Part of carbon-language#5533.
@bricknerb
Copy link
Contributor Author

I believe I've addressed all comments.
Had to rebase and ended up basically recreating this change, so some history is lost. :(

@bricknerb bricknerb requested a review from jonmeow July 17, 2025 16:18
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.

Basically LG, see comment

// CHECK:STDERR:
Cpp.foo({});
//@dump-sem-ir-begin
var x: Cpp.O;
Copy link
Contributor

@jonmeow jonmeow Jul 17, 2025

Choose a reason for hiding this comment

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

Since the second check (x: Cpp.O) is no longer calling, I think it'd make sense to re-combine the two tests now. It just hadn't been clear to me what you intended to test before: if you were testing the type was usable post-Cpp.foo, or if you were testing that a type containing a type could be used at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@bricknerb bricknerb enabled auto-merge July 18, 2025 02:32
@bricknerb bricknerb added this pull request to the merge queue Jul 18, 2025
Merged via the queue into carbon-language:trunk with commit f4f521d Jul 18, 2025
9 checks passed
@bricknerb bricknerb deleted the class branch July 18, 2025 02:54
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