Rust-GCC / Rust-GCC/gccrs

NR2: ICE in visit, at rust/typecheck/rust-tyty-variance-analysis-private.h:164

Open
#3,650 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
C++
Stars
2.9k
Forks
231
Avg merge
19h 55m
Merged PRs (30d)
67

Description

auto-reduced (treereduce-rust):

//@compile-flags: -frust-incomplete-and-experimental-compiler-do-not-use -frust-name-resolution-2.0
type FxpStorageHelper<const INT_BITS: u8> = PhantomU8;

original code

original:

// revisions: full min
#![cfg_attr(full, feature(const_generics))]
#![cfg_attr(full, allow(incomplete_features))]
#![cfg_attr(min, feature(min_const_generics))]

struct PhantomU8<const X: u8>;

trait FxpStorage {
    type SInt; // Add arithmetic traits as needed.
}

macro_rules! fxp_storage_impls {
    ($($($n:literal)|+ => $sint:ty),* $(,)?) => {
        $($(impl FxpStorage for PhantomU8<$n> {
            type SInt = $sint;
        })*)*
    }
}

fxp_storage_impls! {
    1 => i8,
    2 => i16,
    3 | 4 => i32,
    5 | 6 | 7 | 8 => i64,
    9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 => i128,
}

type FxpStorageHelper<const INT_BITS: u8, const FRAC_BITS: u8> =
    PhantomU8<{(FRAC_BITS + FRAC_BITS + 7) / 8}>;
    //[min]~^ ERROR generic parameters may not be used in const operations
    //[min]~| ERROR generic parameters may not be used in const operations

struct Fxp<const INT_BITS: u8, const FRAC_BITS: u8>
where
    FxpStorageHelper<INT_BITS, FRAC_BITS>: FxpStorage,
    //[full]~^ ERROR constant expression depends on a generic parameter
{
    storage: <i64 as FxpStorage>::SInt,
}

fn main() {
    Fxp::<1, 15> { storage: 0i16 };
    Fxp::<2, 15> { storage: 0i32 };
}

Version information:

765121736dfe3f5b319bbe9837880deda326394e

Command:
/home/matthias/vcs/github/gccrs/gccrs-build/gcc/crab1 -frust-incomplete-and-experimental-compiler-do-not-use -frust-name-resolution-2.0

Program output

/tmp/icemaker_global_tempdir.NKudfJBTYGQf/rustc_testrunner_tmpdir_reporting.Jhy7tsDB0QaY/mvce.rs:1:45: error: could not resolve type path ‘PhantomU8’
    1 | type FxpStorageHelper<const INT_BITS: u8> = PhantomU8;
      |                                             ^~~~~~~~~

Analyzing compilation unit

Time variable                                   usr           sys          wall           GGC
 TOTAL                              :   0.00          0.00          0.00          150k
Extra diagnostic checks enabled; compiler may run slowly.
Configure with --enable-checking=release to disable checks.

original stacktrace

crab1: internal compiler error: in visit, at rust/typecheck/rust-tyty-variance-analysis-private.h:164
0x88ff90 Rust::TyTy::VarianceAnalysis::VisitorBase<Rust::TyTy::VarianceAnalysis::Term>::visit(Rust::TyTy::PlaceholderType&)
	../../gcc/rust/typecheck/rust-tyty-variance-analysis-private.h:164
0xf54582 Rust::TyTy::VarianceAnalysis::GenericTyVisitorCtx::add_constraints_from_ty(Rust::TyTy::BaseType*, Rust::TyTy::VarianceAnalysis::Term)
	../../gcc/rust/typecheck/rust-tyty-variance-analysis.cc:400
0xf57d49 Rust::TyTy::VarianceAnalysis::GenericTyVisitorCtx::process_type(Rust::TyTy::ADTType&)
	../../gcc/rust/typecheck/rust-tyty-variance-analysis.cc:250
0xf57d49 Rust::TyTy::VarianceAnalysis::GenericTyPerCrateCtx::process_type(Rust::TyTy::ADTType&)
	../../gcc/rust/typecheck/rust-tyty-variance-analysis.cc:131
0xf57d49 Rust::TyTy::VarianceAnalysis::CrateCtx::add_type_constraints(Rust::TyTy::ADTType&)
	../../gcc/rust/typecheck/rust-tyty-variance-analysis.cc:26
0xf8bf4c Rust::Resolver::TypeCheckItem::visit(Rust::HIR::StructStruct&)
	../../gcc/rust/typecheck/rust-hir-type-check-item.cc:331
0xf7dbb7 Rust::Resolver::TypeCheckItem::Resolve(Rust::HIR::Item&)
	../../gcc/rust/typecheck/rust-hir-type-check-item.cc:59
0xf1518b Rust::Resolver::TypeResolution::Resolve(Rust::HIR::Crate&)
	../../gcc/rust/typecheck/rust-hir-type-check.cc:75
0xce8f73 Rust::Session::compile_crate(char const*)
	../../gcc/rust/rust-session-manager.cc:685
Please submit a full bug report, with preprocessed source (by using -freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the ICE with the reduced Rust case and the command shown in the issue. Start at rust/typecheck/rust-tyty-variance-analysis-private.h:164, then trace add_constraints_from_ty and process_type in rust/typecheck/rust-tyty-variance-analysis.cc. Done means the case no longer aborts in the compiler and reports a normal diagnostic.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.