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

symbolizeExpr crashes due to error when Unknown language #887

Open
didrikmunther opened this issue Jan 7, 2025 · 0 comments
Open

symbolizeExpr crashes due to error when Unknown language #887

didrikmunther opened this issue Jan 7, 2025 · 0 comments

Comments

@didrikmunther
Copy link
Contributor

Example:

Unknown language in symbolize: MLangAst

Caused by (stdlib/mexpr/symbolize.mc):

sem symLookupError lkup =| ident ->
    errorSingle lkup.info
      (join ["Unknown ", lkup.kind, " in symbolize: ", nameGetStr ident])

This makes it impossible to provide language support, since the compiler crashes when typing the language fragment. A better solution would be to change the symbolizeExpr signature to something like this:

syn SymbolizeError =
  | UnknownLanguageError String
  | OtherError String
  
  sem symbolizeExpr : SymEnv -> Expr -> Result [(Info, SymbolizeWarning)] [(Info, SymbolizeError)] Expr

And then changing all symbolizeExpr to use results, e.g.:

lang LetSym = Sym + LetAst + AllTypeAst
  sem symbolizeExpr (env : SymEnv) =
  | TmLet t ->
    match symbolizeTyAnnot env t.tyAnnot with (tyVarEnv, tyAnnot) in
    match setSymbol env.currentEnv.varEnv t.ident with (varEnv, ident) in
    let body = symbolizeExpr (symbolizeUpdateTyVarEnv env tyVarEnv) t.body in
    let inexpr = symbolizeExpr (symbolizeUpdateVarEnv env varEnv) t.inexpr in
    result.map2 (
      lam body. lam inexpr.
        TmLet {t with ident = ident,
                  tyAnnot = tyAnnot,
                  body = body,
                  inexpr = inexpr}
    ) body inexpr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant