Skip to content

Implement the occurs check for type unification #229

Description

@pcwalton

We can infinite loop if we try to unify e.g. T with option[T]. Fixing this requires implementing the occurs check. Off the top of my head, I can't think of any cases in which we'd actually trip this, but it's theoretically possible.


Tim thinks this may also be the cause of segfaulting on infinitely interior tags:

tag t1 {
    a(int);
    b(@t1);
}

Activity

  1. dherman commented on Feb 18, 2011

    @dherman

    I think maybe some permutation of the following might trigger it:

    fn f[T](T x) -> option[T] {
      auto y = f(Some(x));
      ret Some(t);
    }
    

    I'm not sure if this is exactly right but the idea is to try to write a function that forces the inference algorithm to infer an infinite tower of options.

    Dave

  2. graydon commented on May 26, 2011

    @graydon
    Contributor

    This is done now, yes?

  3. pcwalton commented on May 26, 2011

    @pcwalton
    ContributorAuthor

    No, not done yet.

  4. catamorphism commented on Jul 20, 2011

    @catamorphism
    Contributor

    So, I... can't actually reproduce this. For example, I tried Paul's example from #602 and it correctly prints a type error. I tried a version of Dave's example above, and the result is the same. Maybe something with how tags are handled has been changed recently so that this case just never happens in the unifier? I was going to fix it, but with no test case, I'm going to close it instead (reopen if you have a test case!)

  5. catamorphism commented on Aug 4, 2011

    @catamorphism
    Contributor

    Occurs check is now implemented -- see #768 -- but there may be checks missing in places that should have them.

  6. added a commit that references this issue on Dec 12, 2017
  7. added a commit that references this issue on Mar 7, 2023
  8. added a commit that references this issue on Feb 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-type-systemArea: Type systemI-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions