diff options
author | Nadrieril | 2020-12-07 19:02:07 +0000 |
---|---|---|
committer | Nadrieril | 2020-12-07 19:35:30 +0000 |
commit | 4473f3549f331c51a7df0e307d356a06c00d7288 (patch) | |
tree | ba36f2ecb834d861f606d2fef09038f0de5cdc91 /dhall/src/semantics/resolve/hir.rs | |
parent | 7a392b07166c089979e69d4c8a68da3298964c28 (diff) |
Resolve imports and alternatives outside of the ast traversal
Diffstat (limited to '')
-rw-r--r-- | dhall/src/semantics/resolve/hir.rs | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/dhall/src/semantics/resolve/hir.rs b/dhall/src/semantics/resolve/hir.rs index 05a8550..8baad10 100644 --- a/dhall/src/semantics/resolve/hir.rs +++ b/dhall/src/semantics/resolve/hir.rs @@ -1,7 +1,7 @@ use crate::error::TypeError; use crate::semantics::{type_with, typecheck, NameEnv, Nir, NzEnv, Tir, TyEnv}; use crate::syntax::{Expr, ExprKind, Span, V}; -use crate::{Ctxt, ImportId, ToExprOptions}; +use crate::{Ctxt, ImportAlternativeId, ImportId, ToExprOptions}; /// Stores an alpha-normalized variable. #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] @@ -15,8 +15,10 @@ pub enum HirKind<'cx> { Var(AlphaVar), /// A variable that couldn't be resolved. Detected during resolution, but causes an error during typeck. MissingVar(V), - /// An import. It must have been resolved by the time we get to typechecking/normalization. + /// An import. It must have been resolved after resolution. Import(ImportId<'cx>), + /// An import alternative. It must have been decided after resolution. + ImportAlternative(ImportAlternativeId<'cx>, Hir<'cx>, Hir<'cx>), // Forbidden ExprKind variants: Var, Import, Completion Expr(ExprKind<Hir<'cx>>), } @@ -111,6 +113,14 @@ fn hir_to_expr<'cx>( let typed = cx[import].unwrap_result(); return hir_to_expr(cx, &typed.hir, opts, &mut NameEnv::new()); } + HirKind::ImportAlternative(alt, left, right) => { + let hir = if cx[alt].unwrap_selected() { + left + } else { + right + }; + return hir_to_expr(cx, hir, opts, env); + } HirKind::Expr(e) => { let e = e.map_ref_maybe_binder(|l, hir| { if let Some(l) = l { |