Skip to content

Conversation

@zygoloid
Copy link
Contributor

@zygoloid zygoloid commented Dec 2, 2025

Synthesize an impl of Destroy for C++ classes in response to impl lookup.

@zygoloid zygoloid requested a review from a team as a code owner December 2, 2025 07:20
@zygoloid zygoloid requested review from danakj and removed request for a team December 2, 2025 07:20
Copy link
Contributor

@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.

LGTM

// CHECK:STDERR: var a: Cpp.AmbiguousDestructor = {};
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~
// CHECK:STDERR:
// CHECK:STDERR: fail_destroy_nondestroyable.carbon:[[@LINE-8]]:3: error: attempt to use a deleted function [CppInteropParseError]
Copy link
Contributor

Choose a reason for hiding this comment

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

The sorting here is confusing. Maybe just split up the deleted vs ambiguous test cases into separate splits?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reordering the two tests was enough to make this more readable; I've done that.

var a: Cpp.TrivialDestructor = {};
//@dump-sem-ir-end
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want a test where we inherit from ProtectedDestructor in Carbon and destroy 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. That works, but deriving from PrivateDestructor also works, so I've added a todo_fail test for that.

return LookupCopyImpl(context, loc_id, self_type_id, specific_interface);
}

if (context.identifiers().Get(interface.name_id.AsIdentifierId()) ==
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to note, I'd been thinking that all types would use the TypeCanDestroy logic in order to go through type.destroy, so this is kind of creating a case where TypeCanDestroy would be false but it's actually language-destructible. Not sure what the impact will be, particularly since I'd been expecting Destroy should have a single final impl -- will that work with this kind of approach?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, and for context also note the decided interface from #6124:

interface Destroy {
  final fn Op[ref self: Self]() = <some builtin>;
}

@zygoloid
Copy link
Contributor Author

zygoloid commented Dec 5, 2025

This PR is temporarily on hold while we decide how we want to model Destroy impls in general.

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