Skip to content

rust1: internal compiler error: in visit, at rust/typecheck/rust-hir-type-check-path.cc:144 #1132

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

Closed
Tracked by #1247
bjorn3 opened this issue Apr 18, 2022 · 6 comments · Fixed by #1190
Closed
Tracked by #1247
Assignees
Labels

Comments

@bjorn3
Copy link

bjorn3 commented Apr 18, 2022

I tried this code:

mod mem {
    extern "rust-intrinsic" {
        fn transmute<U, V>(_: U) -> V;
    }
}

pub trait Hasher {
    fn write(&mut self, bytes: &[u8]);
    fn write_u16(&mut self, i: u16) {
        self.write(&mem::transmute::<_, [u8; 2]>(i))
    }
}

pub struct SipHasher;

impl Hasher for SipHasher {
    #[inline]
    fn write(&mut self, msg: &[u8]) {}
}

I expected to see this happen: explanation

Instead, this happened:

rust1: internal compiler error: in visit, at rust/typecheck/rust-hir-type-check-path.cc:144
0x204e319 internal_error(char const*, ...)
	???:0
0x8027ef fancy_abort(char const*, int, char const*)
	???:0
0xa10a9e Rust::Resolver::TypeCheckExpr::visit(Rust::HIR::PathInExpression&)
	???:0
0x9c137c Rust::Resolver::TypeCheckExpr::Resolve(Rust::HIR::Expr*, bool)
	???:0
0x9c2364 Rust::Resolver::TypeCheckExpr::visit(Rust::HIR::CallExpr&)
	???:0
0x9c137c Rust::Resolver::TypeCheckExpr::Resolve(Rust::HIR::Expr*, bool)
	???:0
0x9c4fca Rust::Resolver::TypeCheckExpr::visit(Rust::HIR::BorrowExpr&)
	???:0
0x9c137c Rust::Resolver::TypeCheckExpr::Resolve(Rust::HIR::Expr*, bool)
	???:0
0x9d5a10 Rust::TyTy::TypeCheckMethodCallExpr::visit(Rust::TyTy::FnType&)
	???:0
0x9cd012 Rust::Resolver::TypeCheckExpr::visit(Rust::HIR::MethodCallExpr&)
	???:0
0x9c137c Rust::Resolver::TypeCheckExpr::Resolve(Rust::HIR::Expr*, bool)
	???:0
0x9b7b6a Rust::Resolver::TypeCheckExpr::visit(Rust::HIR::BlockExpr&)
	???:0
0x9c137c Rust::Resolver::TypeCheckExpr::Resolve(Rust::HIR::Expr*, bool)
	???:0
0x9be73b Rust::Resolver::TraitResolver::go(Rust::HIR::TypePath&)
	???:0
0x9cd567 Rust::Resolver::TypeCheckItem::visit(Rust::HIR::ImplBlock&)
	???:0
0x9b8d92 Rust::Resolver::TypeResolution::Resolve(Rust::HIR::Crate&)
	???:0
0x8c88a8 Rust::Session::parse_file(char const*)
	???:0
0x8c9548 Rust::Session::parse_files(int, char const**)
	???:0
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
Compiler returned: 1

or as variation:

mod mem {
    extern "rust-intrinsic" {
        fn transmute<U, V>(_: U) -> V;
    }
}

pub trait Hasher {
    fn write(&mut self, bytes: &[u8]);
    fn write_u16(&mut self, i: u16) {
        self.write(&mem::transmute::<_, [u8; 2]>(i))
    }
}
rust1: internal compiler error: in visit_generic_predicates, at rust/privacy/rust-reachability.cc:56
0x204e319 internal_error(char const*, ...)
	???:0
0x8027ef fancy_abort(char const*, int, char const*)
	???:0
0x9ceb45 Rust::Privacy::Resolver::resolve(Rust::HIR::Crate&)
	???:0
0x8c8927 Rust::Session::parse_file(char const*)
	???:0
0x8c9548 Rust::Session::parse_files(int, char const**)
	???:0
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
Compiler returned: 1

Meta

  • What version of Rust GCC were you using, git sha if possible.
@bjorn3 bjorn3 added the bug label Apr 18, 2022
@liushuyu
Copy link
Contributor

liushuyu commented Apr 20, 2022

Reduced case:

pub trait Hasher {}

Backtrace with debug info:

rust1: internal compiler error: in visit_generic_predicates, at rust/privacy/rust-reachability.cc:56
0x74686b Rust::Privacy::ReachabilityVisitor::visit_generic_predicates(std::vector<std::unique_ptr<Rust::HIR::GenericParam, std::default_delete<Rust::HIR::GenericParam> >, std::allocator<std::unique_ptr<Rust::HIR::GenericParam, std::default_delete<Rust::HIR::GenericParam> > > > const&, Rust::Privacy::ReachLevel)
        ../../gcc/rust/privacy/rust-reachability.cc:56
0xb10d68 Rust::Privacy::Resolver::resolve(Rust::HIR::Crate&)
        ../../gcc/rust/privacy/rust-privacy-check.cc:41
0x9ec2ce Rust::Session::parse_file(char const*)
        ../../gcc/rust/rust-session-manager.cc:704
0x9ec94a Rust::Session::parse_files(int, char const**)
        ../../gcc/rust/rust-session-manager.cc:579
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.

Probably addressable by #1135

@CohenArthur
Copy link
Member

Reduced case:

Probably addressable by #1135

Yeah, this part of the issue is the same as #1135 so the "initial draft fix" should fix it. However, there is also an ICE in the typechecking pass which I think is separate

@liushuyu
Copy link
Contributor

Reduced case:

Probably addressable by #1135

Yeah, this part of the issue is the same as #1135 so the "initial draft fix" should fix it. However, there is also an ICE in the typechecking pass which I think is separate

Yes. I have conducted a preliminary investigation, and it seems like this was due to transmute not being implemented as an intrinsic.

Related: #658.

@philberty
Copy link
Member

Updated stack trace:

rust1: internal compiler error: in visit, at rust/typecheck/rust-hir-type-check-path.cc:144
0x1302d7a Rust::Resolver::TypeCheckExpr::visit(Rust::HIR::PathInExpression&)
        ../../gccrs/gcc/rust/typecheck/rust-hir-type-check-path.cc:144
0x119b5b1 Rust::HIR::PathInExpression::accept_vis(Rust::HIR::HIRFullVisitor&)
        ../../gccrs/gcc/rust/hir/tree/rust-hir-full-test.cc:3785
0x127ad67 Rust::Resolver::TypeCheckExpr::Resolve(Rust::HIR::Expr*, bool)
        ../../gccrs/gcc/rust/typecheck/rust-hir-type-check-expr.h:49
0x119bf15 Rust::HIR::CallExpr::accept_vis(Rust::HIR::HIRFullVisitor&)
        ../../gccrs/gcc/rust/hir/tree/rust-hir-full-test.cc:4041
0x127ad67 Rust::Resolver::TypeCheckExpr::Resolve(Rust::HIR::Expr*, bool)
        ../../gccrs/gcc/rust/typecheck/rust-hir-type-check-expr.h:49
0x119b82b Rust::HIR::BorrowExpr::accept_vis(Rust::HIR::HIRFullVisitor&)
        ../../gccrs/gcc/rust/hir/tree/rust-hir-full-test.cc:3849
0x127ad67 Rust::Resolver::TypeCheckExpr::Resolve(Rust::HIR::Expr*, bool)
        ../../gccrs/gcc/rust/typecheck/rust-hir-type-check-expr.h:49
0x12b2be4 Rust::TyTy::TypeCheckMethodCallExpr::visit(Rust::TyTy::FnType&)
        ../../gccrs/gcc/rust/typecheck/rust-tyty.cc:3073
0x12aa55f Rust::TyTy::FnType::accept_vis(Rust::TyTy::TyVisitor&)
        ../../gccrs/gcc/rust/typecheck/rust-tyty.cc:1133
0x1279a5a Rust::TyTy::TypeCheckMethodCallExpr::go(Rust::TyTy::BaseType*, Rust::HIR::MethodCallExpr&, Rust::TyTy::BaseType*, Rust::Resolver::TypeCheckContext*)
        ../../gccrs/gcc/rust/typecheck/rust-tyty-call.h:96
0x119bf4d Rust::HIR::MethodCallExpr::accept_vis(Rust::HIR::HIRFullVisitor&)
        ../../gccrs/gcc/rust/hir/tree/rust-hir-full-test.cc:4047
0x127ad67 Rust::Resolver::TypeCheckExpr::Resolve(Rust::HIR::Expr*, bool)
        ../../gccrs/gcc/rust/typecheck/rust-hir-type-check-expr.h:49
0x1272aab Rust::Resolver::TypeCheckExpr::visit(Rust::HIR::BlockExpr&)
        ../../gccrs/gcc/rust/typecheck/rust-hir-type-check.cc:130
0x119bff5 Rust::HIR::BlockExpr::accept_vis(Rust::HIR::HIRFullVisitor&)
        ../../gccrs/gcc/rust/hir/tree/rust-hir-full-test.cc:4065
0x127ad67 Rust::Resolver::TypeCheckExpr::Resolve(Rust::HIR::Expr*, bool)
        ../../gccrs/gcc/rust/typecheck/rust-hir-type-check-expr.h:49
0x12e18df Rust::Resolver::TraitItemReference::resolve_item(Rust::HIR::TraitItemFunc&)
        ../../gccrs/gcc/rust/typecheck/rust-hir-trait-resolve.cc:122
0x12e1678 Rust::Resolver::TraitItemReference::on_resolved()
        ../../gccrs/gcc/rust/typecheck/rust-hir-trait-resolve.cc:80
0x12775e3 Rust::Resolver::TraitReference::on_resolved()
        ../../gccrs/gcc/rust/typecheck/rust-hir-trait-ref.h:368
0x1279f5b Rust::Resolver::TraitResolver::Resolve(Rust::HIR::TypePath&)
        ../../gccrs/gcc/rust/typecheck/rust-hir-trait-resolve.h:73
0x119cbdb Rust::HIR::ImplBlock::accept_vis(Rust::HIR::HIRFullVisitor&)
        ../../gccrs/gcc/rust/hir/tree/rust-hir-full-test.cc:4389

The assertion here is part of a silly nullptr bug in the resolving of the segments i have been meaning to fix since last year lol

philberty added a commit that referenced this issue Apr 25, 2022
When we resolve paths we don't have a _type_, in this senario there is a
bug in our resolution of this generic function so this means the root_tyty
is nullptr but the offset is non zero so we return nullptr.

Addresses #1132
bors bot added a commit that referenced this issue Apr 26, 2022
1162: CI: catch malformed test cases r=philberty a=liushuyu

- catch malformed test cases and use GitHub Actions' annotation feature to mark the failures

1167: Fix nullptr when resolving the root of a path expression r=philberty a=philberty

When we resolve paths we don't have a _type_, in this scenario there is a
bug in our resolution of this generic function so this means the root_tyty
is nullptr but the offset is non zero so we return nullptr.

Addresses #1132

This test case no longer ICE's but still fails. I have a fix in progress for this

```rust
mod mem {
    extern "rust-intrinsic" {
        fn transmute<U, V>(_: U) -> V;
    }
}

pub trait Hasher {
    fn write(&mut self, bytes: &[u8]);
    fn write_u16(&mut self, i: u16) {
        self.write(&mem::transmute::<_, [u8; 2]>(i))
    }
}

pub struct SipHasher;

impl Hasher for SipHasher {
    #[inline]
    fn write(&mut self, msg: &[u8]) {}
}

```

1168: ast: resolve: Move ResolveItem into its own source file r=CohenArthur a=CohenArthur

Since we need to add new functions to resolve visibilities, we might as well refactor this file before hand :) 

1170: Implement macro expansion in `IfExpr`, `IfExprConseqElse`, `IfExprConseqIf`, `IfExprConseqIfLet`. r=CohenArthur a=antego

Addresses #1141. Following up on #1161.

This change adds support for the macros inside the `if` condition expressions.

Things to note:
1. Judging by my research, the `IfExprConseqIfLet` isn't used. The parser treats the syntax `let var = if ...` as a `let` expression followed by `if` expression:
![Screen Shot 2022-04-26 at 9 47 29 am](https://user-images.githubusercontent.com/1451467/165258060-6a42f918-2585-4aef-9da5-9d60d69ca248.png)
2. I didn't add the macro expansion to the `IfLetExpr...` family of expressions because I wasn't able to write a test case reproducing the missing macro expansion. I've tried the following code
```rust
fn main() -> i32 {
    let mut res = 0;

    enum E {
        X(u8),
        Y(u8),
        Z(u8),
    }
    let v = E::Y(12);
    if let E::Y(n) = v {
        res = 1;
    }

    0
}
```
which caused the compiler error
```
FAIL: rust/compile/macro43.rs (internal compiler error: in append_reference_for_def, at rust/resolve/rust-name-resolver.h:227)
```



Co-authored-by: liushuyu <liushuyu011@gmail.com>
Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
Co-authored-by: antego <antego@users.noreply.github.com>
@philberty philberty self-assigned this Apr 28, 2022
@philberty philberty added this to the Imports and visibility milestone Apr 28, 2022
@philberty
Copy link
Member

This was fixed between these two PRs:

#1184
#1190

@philberty
Copy link
Member

Actually i will repoen to lets bors close out from #1190

@philberty philberty reopened this Apr 28, 2022
bors bot added a commit that referenced this issue Apr 28, 2022
1190: Fix ICE in reachability class and refactor associated types code r=philberty a=philberty

There are several fixes going on to solve these issues which overlap with one
another so it seemed best to pack them within the same PR.

The main issue for #1128 was that we did not resolve a trait when it was unused
leading to us hitting the ICE in the privacy pass. Since the type check context was
empty for the trait since it was not resolved. To fix this we needed to refactor the
trait resolver to resolve the trait as part of iterating the crate. This resulted in some
regressions in the testsuite so this is why we need the the other commits. Which
required us to finally perform the refactor specified in #1105 to fix these.

Fixes #1105 #1128 #1132

1192: Add an assertion to avoid peeking when the stack is empty r=philberty a=philberty

This will ensure we get a proper ICE instead of memory corruption/segv.

Addresses #1130 

1193: Remove unused parameter caller from generating Call expressions r=philberty a=philberty

Within const context the fncontext maybe empty which in turn results in a
segv for generating const calls which will be evaluated by the const-expr
code anyway.

Addresses #1130


Co-authored-by: Philip Herron <philip.herron@embecosm.com>
@bors bors bot closed this as completed in #1190 Apr 28, 2022
@philberty philberty mentioned this issue May 12, 2022
16 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants