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

Fixed #2500 #3390

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Fixed #2500 #3390

wants to merge 1 commit into from

Conversation

zhanghe9702
Copy link
Contributor

Add a seperate typecheck pass collect impl blocks, then report errors.

Signed-off-by: Zhang He [email protected]

ChangLog:

    * gcc/rust/typecheck/rust-hir-inherent-impl-check.h: new typecheck pass
    * gcc/rust/typecheck/rust-hir-type-check.cc: modify the function which test primitive type
    * gcc/rust/typecheck/rust-tyty.cc: the new typecheck pass entrypoint
    * gcc/testsuite/rust/compile/issue-2500-rustc.rs: testsuite case same with rustc
    * gcc/testsuite/rust/compile/issue-2500.rs: testsuite case

Thank you for making Rust GCC better!

If your PR fixes an issue, you can add "Fixes #issue_number" into this
PR description and the git commit message. This way the issue will be
automatically closed when your PR is merged. If your change addresses
an issue but does not fully fix it please mark it as "Addresses #issue_number"
in the git commit message.

Here is a checklist to help you with your PR.

Note that you can skip the above if you are just opening a WIP PR in
order to get feedback.

*Please write a comment explaining your change. This is the message
that will be part of the merge commit.

@zhanghe9702 zhanghe9702 force-pushed the HEAD branch 2 times, most recently from fe57261 to c8b9399 Compare January 28, 2025 08:17
#include "rust-hir-inherent-impl-overlap.h"
#include "rust-hir-inherent-impl-check.h"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Duplicate includes

@@ -0,0 +1,81 @@
// Copyright (C) 2020-2024 Free Software Foundation, Inc.
Copy link
Member

Choose a reason for hiding this comment

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

I believe we're in 2025 now 😅

Suggested change
// Copyright (C) 2020-2024 Free Software Foundation, Inc.
// Copyright (C) 2020-2025 Free Software Foundation, Inc.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Should it be changed from 2020-2024 to just 2025, since it's a new file?

Copy link
Member

@CohenArthur CohenArthur left a comment

Choose a reason for hiding this comment

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

Great work, you really did a good job using our existing framework and checking for the impls :D It's missing one bit of logic with the lang items I think, but this is honestly impressive - well done!

#include "rust-hir-item.h"
#include "rust-hir-type-check-base.h"
#include "rust-type-util.h"
#include <vector>
Copy link
Member

Choose a reason for hiding this comment

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

This include should be removed, you should include "rust-system.h" instead if it is necessary

Comment on lines +40 to +43
void scan ()

{
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
void scan ()
{
void scan ()
{

Comment on lines +52 to +60
if (is_primitive_type_kind (impl_type->get_kind ()))
{
possible_primitive_impl.push_back (impl);
}
Copy link
Member

Choose a reason for hiding this comment

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

I think this is a good start, but we must also check if the implementation is a lang item. In Rust 1.49, this is the implementation for the official impl of i8 for example:

#[lang = "i8"]
impl i8 {
    int_impl! { i8, i8, u8, 8, -128, 127, "", "", 2, "-0x7e", "0xa", "0x12", "0x12", "0x48",
    "[0x12]", "[0x12]", "", "" }
}

because the standard library does define methods for the i8 type so we still need to be able to do that somewhere.

Here is another primitive implementation if you want to take a look: https://github.com/rust-lang/rust/blob/e1884a8e3c3e813aada8254edfa120e85bf5ffca/library/core/src/ptr/mut_ptr.rs#L6

We can maybe address this in a later PR if this doesn't cause any regressions though

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'm not sure if all these failed regressions just because missing lang item check, so many! sorry for that! :) maybe some of them need modify , I will take the time to do some reseach about your suggestions, thx!

Copy link
Member

Choose a reason for hiding this comment

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

Yes some of the regressions are due to this, e.g. in gcc/testsuite/rust/compile/const-issue1440.rs where we define the primitive implementation for integers (which I assume will cause your error to trigger). but you'll need to fix the testcase as well to add the attribute

Comment on lines 65 to 71
void report_error (HIR::ImplBlock *impl)

{
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
void report_error (HIR::ImplBlock *impl)
{
void report_error (HIR::ImplBlock *impl)
{

@zhanghe9702
Copy link
Contributor Author

make check-rust pass at local machine, i will fix code format tomorrow

@zhanghe9702 zhanghe9702 force-pushed the HEAD branch 3 times, most recently from ac5a768 to 714c863 Compare February 1, 2025 02:03
Add a seperate typecheck pass collect impl blocks, then report errors.

gcc/rust/ChangeLog:
	* typecheck/rust-hir-inherent-impl-check.h: new typecheck pass
	* typecheck/rust-hir-type-check.cc: modify the function which test primitive type
	* typecheck/rust-tyty.cc: the new typecheck pass entrypoint
	* util/rust-hir-map.cc: add the map lookup lang item by defid
	* util/rust-hir-map.h:  add the map lookup lang item by defid
gcc/testsuite/ChangeLog:
	* rust/compile/issue-2500-rustc.rs: testsuite case same with rustc
	* rust/compile/issue-2500.rs: testsuite case
	* rust/compile/const-issue1440.rs: add lang item attribute
	* rust/compile/issue-1005.rs: add lang item attribute
	* rust/compile/issue-1130.rs: add lang item attribute
	* rust/compile/issue-1235.rs: add lang item attribute
	* rust/compile/issue-1237.rs: add lang item attribute
	* rust/compile/issue-2190-2.rs: add lang item attribute
	* rust/compile/issue-2905-2.rs: add lang item attribute
	* rust/compile/iterators1.rs: add lang item attribute
	* rust/compile/macros/mbe/macro-issue1233.rs: add lang item attribute
	* rust/compile/macros/mbe/macro54.rs: add lang item attribute
	* rust/compile/torture/intrinsics-8.rs: add lang item attribute
	* rust/compile/torture/issue-1075.rs: add lang item attribute
	* rust/compile/torture/issue-1432.rs: add lang item attribute
	* rust/execute/torture/issue-1436.rs: add lang item attribute
	* rust/execute/torture/issue-2236.rs: add lang item attribute
	* rust/execute/torture/iter1.rs: add lang item attribute
	* rust/execute/torture/str-layout1.rs: add lang item attribute
Signed-off-by: Zhang He <[email protected]>
// filtering trait-impl-blocks
if (impl->has_trait_ref ())
return true;
HirId impl_ty_id = impl->get_type ().get_mappings ().get_hirid ();
Copy link
Member

Choose a reason for hiding this comment

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

I think some line breaks here will help make this easier to read maybe after those returns

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants