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

Fix missing occurence check #1019

Merged
merged 2 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions crates/codegen/src/yul/isel/inst_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,13 +464,13 @@ impl<'a> InstSerializer<'a> {
///
/// The scoring function `F` is defined as follows:
/// 1. The initial score of each candidate('cand_bb`) is number of
/// predecessors of the candidate.
/// predecessors of the candidate.
///
/// 2. Find the `top_cand` of each `cand_bb`. `top_cand` can be found by
/// [`Self::try_find_top_cand`] method, see the method for details.
/// [`Self::try_find_top_cand`] method, see the method for details.
///
/// 3. If `top_cand` is found, then add the `cand_bb` score to the
/// `top_cand` score, then set 0 to the `cand_bb` score.
/// `top_cand` score, then set 0 to the `cand_bb` score.
///
/// After the scoring, the candidates with the highest score will be
/// selected.
Expand Down Expand Up @@ -516,16 +516,16 @@ impl<'a> InstSerializer<'a> {
/// A `top_cand` can be found by the following rules:
///
/// 1. Find the block which is contained in DF of `cand_bb` and in
/// `cands_with_score`.
/// `cands_with_score`.
///
/// 2. If a block is found in 1., and the score of the block is positive,
/// then the block is `top_cand`.
/// then the block is `top_cand`.
///
/// 2'. If a block is found in 1., and the score of the block is 0, then the
/// `top_cand` of the block is `top_cand` of `cand_bb`.
/// `top_cand` of the block is `top_cand` of `cand_bb`.
///
/// 2''. If a block is NOT found in 1., then there is no `top_cand` for
/// `cand_bb`.
/// `cand_bb`.
fn try_find_top_cand(
&self,
cands_with_score: &IndexMap<BasicBlockId, usize>,
Expand Down
1 change: 1 addition & 0 deletions crates/hir-analysis/src/ty/def_analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ impl<'db> DefAnalyzer<'db> {
/// This method verifies if
/// 1. the given `ty` has `*` kind.
/// 2. the given `ty` is not const type
///
/// TODO: This method is a stop-gap implementation until we design a true
/// const type system.
fn verify_term_type_kind(&mut self, ty: HirTyId<'db>, span: DynLazySpan<'db>) -> bool {
Expand Down
7 changes: 5 additions & 2 deletions crates/hir-analysis/src/ty/trait_resolution/proof_forest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,11 @@ impl ConsumerNode {
let (pending_inst, canonicalized_pending_inst) = &c_node.query;
let solution = canonicalized_pending_inst.extract_solution(&mut table, solution);

// Unifies pending inst and solution.
table.unify(*pending_inst, solution).unwrap();
// Try to unifies pending inst and solution.
if table.unify(*pending_inst, solution).is_err() {
return true;
}

let tree_root = c_node.root;

if c_node.remaining_goals.is_empty() {
Expand Down
23 changes: 23 additions & 0 deletions crates/uitest/fixtures/ty/trait_bound/occurence_check.fe
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
trait Trait1 {
fn f(self:Self)
}

trait Trait2<T> {}

struct Memory<T> {
x: i32,
}

impl<T> Trait2<Memory<Memory<Memory<T>>>> for Memory<T> { }

impl<T, U> Trait1 for Memory<Memory<Memory<U>>>
where T: Trait1,
U: Trait2<T>
{
fn f(self: Self) {}
}

fn g<T>(y: T) {
let x: Memory<Memory<Memory<T>>>
x.f()
}
13 changes: 13 additions & 0 deletions crates/uitest/fixtures/ty/trait_bound/occurence_check.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
source: crates/uitest/tests/ty.rs
expression: diags
input_file: crates/uitest/fixtures/ty/trait_bound/occurence_check.fe
---
error[6-0003]: trait bound is not satisfied
┌─ occurence_check.fe:22:7
22x.f()
^
│ │
`Memory<Memory<Memory<T>>>` doesn't implement `Trait1`
│ trait bound `T: Trait2<_>` is not satisfied
Loading