mirror of
https://github.com/tweag/nickel.git
synced 2024-10-06 16:18:08 +03:00
Replace Wildcards with concrete Types instead of unification variables.
This commit is contained in:
parent
0aa553d85f
commit
5a882ab481
@ -90,10 +90,11 @@ impl Default for AnalysisHost {
|
||||
}
|
||||
}
|
||||
|
||||
use nickel_lang::types::Types;
|
||||
impl Linearizer for AnalysisHost {
|
||||
type Building = Building;
|
||||
type Completed = Completed;
|
||||
type CompletionExtra = (UnifTable, HashMap<usize, Ident>, Vec<TypeWrapper>);
|
||||
type CompletionExtra = (UnifTable, HashMap<usize, Ident>, Vec<Types>);
|
||||
|
||||
fn add_term(
|
||||
&mut self,
|
||||
@ -347,11 +348,7 @@ impl Linearizer for AnalysisHost {
|
||||
fn complete(
|
||||
self,
|
||||
mut lin: Linearization<Building>,
|
||||
(table, reported_names, wildcard_vars): (
|
||||
UnifTable,
|
||||
HashMap<usize, Ident>,
|
||||
Vec<TypeWrapper>,
|
||||
),
|
||||
(table, reported_names, wildcard_vars): (UnifTable, HashMap<usize, Ident>, Vec<Types>),
|
||||
) -> Linearization<Completed> {
|
||||
debug!("linearizing");
|
||||
|
||||
@ -394,21 +391,15 @@ impl Linearizer for AnalysisHost {
|
||||
id_mapping.insert(*id, index);
|
||||
});
|
||||
|
||||
fn transform_wildcard(wildcars: Vec<TypeWrapper>, t: TypeWrapper) -> TypeWrapper {
|
||||
fn transform_wildcard(wildcars: Vec<Types>, t: Types) -> Types {
|
||||
match t {
|
||||
TypeWrapper::Concrete(AbsType::Wildcard(i)) => {
|
||||
wildcars.get(i).unwrap_or(&t).clone()
|
||||
}
|
||||
Types(AbsType::Wildcard(i)) => wildcars.get(i).unwrap_or(&t).clone(),
|
||||
_ => t,
|
||||
}
|
||||
}
|
||||
// resolve types
|
||||
let lin_ = linearization
|
||||
.into_iter()
|
||||
.map(|item| LinearizationItem {
|
||||
ty: transform_wildcard(wildcard_vars.clone(), item.ty),
|
||||
..item
|
||||
})
|
||||
.map(
|
||||
|LinearizationItem {
|
||||
id,
|
||||
@ -426,6 +417,10 @@ impl Linearizer for AnalysisHost {
|
||||
meta,
|
||||
},
|
||||
)
|
||||
.map(|item| LinearizationItem {
|
||||
ty: transform_wildcard(wildcard_vars.clone(), item.ty),
|
||||
..item
|
||||
})
|
||||
.collect();
|
||||
|
||||
Linearization::new(Completed::new(lin_, scope, id_mapping))
|
||||
|
@ -225,7 +225,7 @@ pub fn type_check_linearize<LL>(
|
||||
mut linearizer: LL,
|
||||
) -> Result<(Wildcards, LL::Completed), TypecheckError>
|
||||
where
|
||||
LL: Linearizer<CompletionExtra = (UnifTable, HashMap<usize, Ident>, Vec<TypeWrapper>)>,
|
||||
LL: Linearizer<CompletionExtra = (UnifTable, HashMap<usize, Ident>, Vec<Types>)>,
|
||||
{
|
||||
let (mut table, mut names) = (UnifTable::new(), HashMap::new());
|
||||
let mut building = Linearization::new(LL::Building::default());
|
||||
@ -251,7 +251,7 @@ where
|
||||
|
||||
let result = wildcard_vars_to_type(wildcard_vars.clone(), &table);
|
||||
let lin = linearizer
|
||||
.complete(building, (table, names, wildcard_vars.clone()))
|
||||
.complete(building, (table, names, result.clone()))
|
||||
.into_inner();
|
||||
|
||||
Ok((result, lin))
|
||||
|
Loading…
Reference in New Issue
Block a user