flix / flix

The Flix Programming Language
https://flix.dev/
Other
2.1k stars 150 forks source link

Disallow non-variable and non-constant patterns in body atoms #5067

Closed magnus-madsen closed 1 year ago

magnus-madsen commented 1 year ago

The grammar for TypedAst for constraints has:

    sealed trait Body extends TypedAst.Predicate

    object Body {

      case class Atom(pred: Name.Pred, den: Denotation, polarity: Ast.Polarity, fixity: Ast.Fixity, terms: List[TypedAst.Pattern], tpe: Type, loc: SourceLocation) extends TypedAst.Predicate.Body

      case class Guard(exp: TypedAst.Expression, loc: SourceLocation) extends TypedAst.Predicate.Body

      case class Loop(varSyms: List[Symbol.VarSym], exp: TypedAst.Expression, loc: SourceLocation) extends TypedAst.Predicate.Body

    }

The safety phase should check that the terms passed to Atom are only variables and constants.

If not, it should emit a SafetyError saying that such patterns are not supported.

magnus-madsen commented 1 year ago

The right place to start is around here: https://github.com/flix/flix/blob/master/main/src/ca/uwaterloo/flix/language/phase/Safety.scala#L539

magnus-madsen commented 1 year ago

The goal is to reject programs that contain constraints like:

A(x) :- B(Some(x)).

which currently crash the compiler.

mlutze commented 1 year ago

IMO this should be its own AST node rather than reusing pattern. Resolver is messy as a result of the reuse. See also https://github.com/flix/flix/issues/4854

magnus-madsen commented 1 year ago

@mlutze We want to allow patterns some day, we just dont have engine support yet. In that case, is it ok?

mlutze commented 1 year ago

@mlutze We want to allow patterns some day, we just dont have engine support yet. In that case, is it ok?

Yes, in that case it's worth the slight weirdness in resolver.

magnus-madsen commented 1 year ago

@AStenbaek CC