-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Introduce CoercePointeeWellformed for coherence checks at typeck stage #136107
base: master
Are you sure you want to change the base?
Introduce CoercePointeeWellformed for coherence checks at typeck stage #136107
Conversation
r? @Nadrieril rustbot has assigned @Nadrieril. Use |
Some changes occurred in diagnostic error codes |
This comment has been minimized.
This comment has been minimized.
}; | ||
let did = def.did(); | ||
let span = | ||
if let Some(local) = did.as_local() { tcx.source_span(local) } else { tcx.def_span(did) }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this as_local
check?
The def id always should be local, right? if it's not, then it's an incoherent impl and we should probably just delay a bug.
}; | ||
let did = def.did(); | ||
let span = | ||
if let Some(local) = did.as_local() { tcx.source_span(local) } else { tcx.def_span(did) }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not use source_span
-- the query says:
. This span is meant for dep-tracking rather than diagnostics. It should not be used outside of
rustc_middle::hir::source_map
.
@@ -790,3 +794,27 @@ fn visit_implementation_of_pointer_like(checker: &Checker<'_>) -> Result<(), Err | |||
.with_note(why_disqualified) | |||
.emit()) | |||
} | |||
|
|||
fn visit_implementation_of_coerce_pointee_wellformed( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we still doing validation inside of the proc macro? Shouldn't we remove the validation from the proc macro since we are doing it here now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Speaking from another perspective, rejecting the derivation earlier as well means that we can refuse to generate the unnecessary ASTs that later compilation passes needs to process. Given the current state of the unstable features involved, it seems to me that it could probably be better for us to intercept inadmissible uses of the macro so that we would not inadvertently expose the behaviour of those unstable features that we had not committed to yet.
I am honestly not sure. This can go either way to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not think we should keep both validation. Please remove it :)
library/core/src/marker.rs
Outdated
|
||
#[cfg(not(bootstrap))] | ||
#[lang = "coerce_pointee_wellformed"] | ||
#[unstable(feature = "derive_coerce_pointee", issue = "123430")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be gated behind a different feature gate, since users should never be able to implement CoercePointeeWellFormed
manually. You can follow StructuralPartialEq
to see how to gate an internal derive-only trait properly.
@@ -110,6 +110,52 @@ pub(crate) fn expand_deriving_coerce_pointee( | |||
// Declare helper function that adds implementation blocks. | |||
// FIXME(dingxiangfei2009): Investigate the set of attributes on target struct to be propagated to impls | |||
let attrs = thin_vec![cx.attr_word(sym::automatically_derived, span),]; | |||
// # Wellformed-ness assertion |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please elaborate what well-formedness means.
I think you may also want to strongly consider using a different term than "well-formed". We already use the term within the type system for a different meaning. I think it's more correct to call this something like "DeriveValidity" or something, to make it clear that we use this impl to validate the correcness of the derive.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still needs fixing?
library/core/src/marker.rs
Outdated
/// and shall not ever be stabilised. | ||
#[cfg(not(bootstrap))] | ||
#[lang = "coerce_pointee_validated"] | ||
#[unstable(feature = "coerce_pointee_validated", issue = "123430")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't need a tracking issue since it's never going to be stabilized. Just put issue = "none"
I think.
4c42131
to
645b231
Compare
This comment has been minimized.
This comment has been minimized.
645b231
to
e55e437
Compare
This comment has been minimized.
This comment has been minimized.
Some changes occurred in compiler/rustc_codegen_cranelift cc @bjorn3 Some changes occurred in compiler/rustc_codegen_gcc |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I'm a bit confused why this PR has gotten so large. It's now introducing a query, interacting with specialization graph somehow, and doing a lot more than it originally set out to do, which as far as I could tell is just a check for the pointee ADT being transparent. I think you should revert most of this PR and explain more clearly in a follow-up issue or zulip thread what you intend to achieve with this validation before committing something that is very difficult to review 😓 @rustbot author |
@compiler-errors Thank you for reviewing! I am going to truncate the commit logs and focus only on the I am moving the discussion to Zulip. |
5324992
to
aea5595
Compare
@rustbot ready
|
Fix #135206
This is the first PR to introduce the "wellformedness" check for
derive(CoercePointee)
.This patch introduces a new error code to cover all the prerequisites of the said macro. The checks that is enforced with this patch is whether the data is indeed
struct
and whether the layout is set torepr(transparent)
.A following series of patch will arrive later to address the following concern.
An open question is whether there is a good schema to encode the
#[pointee]
as well, so that we could also check if the#[pointee]
type parameter is indeed?Sized
.@rustbot label F-derive_coerce_pointee