No more lowercase for opaques

This commit is contained in:
Ayaz Hafiz 2022-04-29 10:01:04 -04:00
parent 5e47e4767e
commit ca7c9ec5e6
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
6 changed files with 31 additions and 20 deletions

View file

@ -1045,26 +1045,35 @@ pub fn instantiate_and_freshen_alias_type(
pub fn freshen_opaque_def( pub fn freshen_opaque_def(
var_store: &mut VarStore, var_store: &mut VarStore,
opaque: &Alias, opaque: &Alias,
) -> (Vec<(Lowercase, Type)>, Vec<LambdaSet>, Type) { ) -> (Vec<Variable>, Vec<LambdaSet>, Type) {
debug_assert!(opaque.kind == AliasKind::Opaque); debug_assert!(opaque.kind == AliasKind::Opaque);
let fresh_arguments = opaque let fresh_variables: Vec<Variable> = opaque
.type_variables .type_variables
.iter() .iter()
.map(|_| Type::Variable(var_store.fresh())) .map(|_| var_store.fresh())
.collect(); .collect();
// TODO this gets ignored; is that a problem let fresh_type_arguments = fresh_variables
.iter()
.copied()
.map(Type::Variable)
.collect();
// NB: We don't introduce the fresh variables here, we introduce them during constraint gen.
// NB: If there are bugs, check whether this is a problem!
let mut introduced_variables = IntroducedVariables::default(); let mut introduced_variables = IntroducedVariables::default();
instantiate_and_freshen_alias_type( let (_fresh_type_arguments, fresh_lambda_set, fresh_type) = instantiate_and_freshen_alias_type(
var_store, var_store,
&mut introduced_variables, &mut introduced_variables,
&opaque.type_variables, &opaque.type_variables,
fresh_arguments, fresh_type_arguments,
&opaque.lambda_set_variables, &opaque.lambda_set_variables,
opaque.typ.clone(), opaque.typ.clone(),
) );
(fresh_variables, fresh_lambda_set, fresh_type)
} }
fn insertion_sort_by<T, F>(arr: &mut [T], mut compare: F) fn insertion_sort_by<T, F>(arr: &mut [T], mut compare: F)

View file

@ -5,7 +5,7 @@ use crate::pattern::Pattern;
use crate::scope::Scope; use crate::scope::Scope;
use roc_collections::{SendMap, VecSet}; use roc_collections::{SendMap, VecSet};
use roc_module::called_via::CalledVia; use roc_module::called_via::CalledVia;
use roc_module::ident::{Lowercase, TagName}; use roc_module::ident::TagName;
use roc_module::symbol::Symbol; use roc_module::symbol::Symbol;
use roc_region::all::{Loc, Region}; use roc_region::all::{Loc, Region};
use roc_types::subs::{ExhaustiveMark, RedundantMark, VarStore, Variable}; use roc_types::subs::{ExhaustiveMark, RedundantMark, VarStore, Variable};
@ -1466,7 +1466,7 @@ fn build_effect_opaque(
fn build_fresh_opaque_variables( fn build_fresh_opaque_variables(
var_store: &mut VarStore, var_store: &mut VarStore,
) -> (Box<Type>, Vec<(Lowercase, Type)>, Vec<LambdaSet>) { ) -> (Box<Type>, Vec<Variable>, Vec<LambdaSet>) {
let closure_var = var_store.fresh(); let closure_var = var_store.fresh();
// NB: if there are bugs, check whether not introducing variables is a problem! // NB: if there are bugs, check whether not introducing variables is a problem!
@ -1478,7 +1478,7 @@ fn build_fresh_opaque_variables(
Box::new(Type::Variable(closure_var)), Box::new(Type::Variable(closure_var)),
Box::new(Type::Variable(a_var)), Box::new(Type::Variable(a_var)),
); );
let type_arguments = vec![("a".into(), Type::Variable(a_var))]; let type_arguments = vec![a_var];
let lambda_set_variables = vec![roc_types::types::LambdaSet(Type::Variable(closure_var))]; let lambda_set_variables = vec![roc_types::types::LambdaSet(Type::Variable(closure_var))];
(Box::new(actual), type_arguments, lambda_set_variables) (Box::new(actual), type_arguments, lambda_set_variables)

View file

@ -190,7 +190,7 @@ pub enum Expr {
// for the expression from the opaque definition. `type_arguments` is something like // for the expression from the opaque definition. `type_arguments` is something like
// [(n, fresh1)], and `specialized_def_type` becomes "[ Id U64 fresh1 ]". // [(n, fresh1)], and `specialized_def_type` becomes "[ Id U64 fresh1 ]".
specialized_def_type: Box<Type>, specialized_def_type: Box<Type>,
type_arguments: Vec<(Lowercase, Type)>, type_arguments: Vec<Variable>,
lambda_set_variables: Vec<LambdaSet>, lambda_set_variables: Vec<LambdaSet>,
}, },

View file

@ -47,7 +47,7 @@ pub enum Pattern {
// for the expression from the opaque definition. `type_arguments` is something like // for the expression from the opaque definition. `type_arguments` is something like
// [(n, fresh1)], and `specialized_def_type` becomes "[ Id U64 fresh1 ]". // [(n, fresh1)], and `specialized_def_type` becomes "[ Id U64 fresh1 ]".
specialized_def_type: Box<Type>, specialized_def_type: Box<Type>,
type_arguments: Vec<(Lowercase, Type)>, type_arguments: Vec<Variable>,
lambda_set_variables: Vec<LambdaSet>, lambda_set_variables: Vec<LambdaSet>,
}, },
RecordDestructure { RecordDestructure {

View file

@ -1022,7 +1022,10 @@ pub fn constrain_expr(
let opaque_type = Type::Alias { let opaque_type = Type::Alias {
symbol: *name, symbol: *name,
type_arguments: type_arguments.clone(), type_arguments: type_arguments
.iter()
.map(|v| ("".into(), Type::Variable(*v)))
.collect(),
lambda_set_variables: lambda_set_variables.clone(), lambda_set_variables: lambda_set_variables.clone(),
actual: Box::new(arg_type.clone()), actual: Box::new(arg_type.clone()),
kind: AliasKind::Opaque, kind: AliasKind::Opaque,
@ -1059,9 +1062,7 @@ pub fn constrain_expr(
let mut vars = vec![*arg_var, *opaque_var]; let mut vars = vec![*arg_var, *opaque_var];
// Also add the fresh variables we created for the type argument and lambda sets // Also add the fresh variables we created for the type argument and lambda sets
vars.extend(type_arguments.iter().map(|(_, t)| { vars.extend(type_arguments);
t.expect_variable("all type arguments should be fresh variables here")
}));
vars.extend(lambda_set_variables.iter().map(|v| { vars.extend(lambda_set_variables.iter().map(|v| {
v.0.expect_variable("all lambda sets should be fresh variables here") v.0.expect_variable("all lambda sets should be fresh variables here")
})); }));

View file

@ -514,7 +514,10 @@ pub fn constrain_pattern(
let opaque_type = Type::Alias { let opaque_type = Type::Alias {
symbol: *opaque, symbol: *opaque,
type_arguments: type_arguments.clone(), type_arguments: type_arguments
.iter()
.map(|v| ("".into(), Type::Variable(*v)))
.collect(),
lambda_set_variables: lambda_set_variables.clone(), lambda_set_variables: lambda_set_variables.clone(),
actual: Box::new(arg_pattern_type.clone()), actual: Box::new(arg_pattern_type.clone()),
kind: AliasKind::Opaque, kind: AliasKind::Opaque,
@ -571,9 +574,7 @@ pub fn constrain_pattern(
.vars .vars
.extend_from_slice(&[*arg_pattern_var, *whole_var]); .extend_from_slice(&[*arg_pattern_var, *whole_var]);
// Also add the fresh variables we created for the type argument and lambda sets // Also add the fresh variables we created for the type argument and lambda sets
state.vars.extend(type_arguments.iter().map(|(_, t)| { state.vars.extend(type_arguments);
t.expect_variable("all type arguments should be fresh variables here")
}));
state.vars.extend(lambda_set_variables.iter().map(|v| { state.vars.extend(lambda_set_variables.iter().map(|v| {
v.0.expect_variable("all lambda sets should be fresh variables here") v.0.expect_variable("all lambda sets should be fresh variables here")
})); }));