mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 13:29:12 +00:00
switch from type annotation to type variable
This commit is contained in:
parent
8f4945f286
commit
6302a8d4b5
11 changed files with 136 additions and 97 deletions
|
@ -1,4 +1,5 @@
|
|||
use std::cell::Cell;
|
||||
use std::path::Path;
|
||||
|
||||
use crate::abilities::SpecializationId;
|
||||
use crate::exhaustive::{ExhaustiveContext, SketchedRows};
|
||||
|
@ -599,6 +600,7 @@ impl Constraints {
|
|||
| Constraint::PatternPresence(_, _, _, _)
|
||||
| Constraint::Exhaustive { .. }
|
||||
| Constraint::Resolve(..)
|
||||
| Constraint::IngestedFile(..)
|
||||
| Constraint::CheckCycle(..) => false,
|
||||
}
|
||||
}
|
||||
|
@ -673,10 +675,19 @@ impl Constraints {
|
|||
|
||||
Constraint::CheckCycle(cycle_index, cycle_mark)
|
||||
}
|
||||
|
||||
pub fn ingested_file(
|
||||
&mut self,
|
||||
type_index: TypeOrVar,
|
||||
file_path: Box<Path>,
|
||||
bytes: Vec<u8>,
|
||||
) -> Constraint {
|
||||
Constraint::IngestedFile(type_index, file_path, bytes)
|
||||
}
|
||||
}
|
||||
|
||||
roc_error_macros::assert_sizeof_default!(Constraint, 3 * 8);
|
||||
roc_error_macros::assert_sizeof_aarch64!(Constraint, 3 * 8);
|
||||
roc_error_macros::assert_sizeof_default!(Constraint, 6 * 8);
|
||||
roc_error_macros::assert_sizeof_aarch64!(Constraint, 6 * 8);
|
||||
|
||||
impl std::ops::Index<ExpectedTypeIndex> for Constraints {
|
||||
type Output = Expected<TypeOrVar>;
|
||||
|
@ -734,7 +745,7 @@ pub struct OpportunisticResolve {
|
|||
pub specialization_id: SpecializationId,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
#[derive(Clone)]
|
||||
pub enum Constraint {
|
||||
Eq(Eq),
|
||||
Store(TypeOrVar, Variable, Index<&'static str>, u32),
|
||||
|
@ -773,6 +784,10 @@ pub enum Constraint {
|
|||
/// Attempt to resolve a specialization.
|
||||
Resolve(OpportunisticResolve),
|
||||
CheckCycle(Index<Cycle>, IllegalCycleMark),
|
||||
|
||||
// This is terrible and could be a huge cost to copy.
|
||||
// Not sure a better way to get the bytes here so we can check if they are valid utf8 or decode properly.
|
||||
IngestedFile(TypeOrVar, Box<Path>, Vec<u8>),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Default)]
|
||||
|
@ -856,6 +871,9 @@ impl std::fmt::Debug for Constraint {
|
|||
Self::CheckCycle(arg0, arg1) => {
|
||||
write!(f, "CheckCycle({:?}, {:?})", arg0, arg1)
|
||||
}
|
||||
Self::IngestedFile(arg0, arg1, arg2) => {
|
||||
write!(f, "IngestedFile({:?}, {:?}, {:?})", arg0, arg1, arg2)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -277,7 +277,9 @@ fn deep_copy_expr_help<C: CopyEnv>(env: &mut C, copied: &mut Vec<Variable>, expr
|
|||
Float(v1, v2, str, val, bound) => Float(sub!(*v1), sub!(*v2), str.clone(), *val, *bound),
|
||||
Str(str) => Str(str.clone()),
|
||||
SingleQuote(v1, v2, char, bound) => SingleQuote(sub!(*v1), sub!(*v2), *char, *bound),
|
||||
IngestedFile(bytes, anno) => IngestedFile(bytes.clone(), anno.clone()),
|
||||
IngestedFile(file_path, bytes, anno) => {
|
||||
IngestedFile(file_path.clone(), bytes.clone(), anno.clone())
|
||||
}
|
||||
List {
|
||||
elem_var,
|
||||
loc_elems,
|
||||
|
|
|
@ -165,7 +165,9 @@ fn expr<'a>(c: &Ctx, p: EPrec, f: &'a Arena<'a>, e: &'a Expr) -> DocBuilder<'a,
|
|||
Num(_, n, _, _) | Int(_, _, n, _, _) | Float(_, _, n, _, _) => f.text(&**n),
|
||||
Str(s) => f.text(format!(r#""{}""#, s)),
|
||||
SingleQuote(_, _, c, _) => f.text(format!("'{}'", c)),
|
||||
IngestedFile(_,_) => todo!("I am not really sure how we want this to be printed. file name? all bytes? as correct type?"),
|
||||
IngestedFile(file_path, bytes, _) => {
|
||||
f.text(format!("<ingested {:?}, {} bytes>", file_path, bytes.len()))
|
||||
}
|
||||
List {
|
||||
elem_var: _,
|
||||
loc_elems,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::abilities::SpecializationId;
|
||||
use crate::annotation::{self, freshen_opaque_def, IntroducedVariables};
|
||||
use crate::annotation::{freshen_opaque_def, IntroducedVariables};
|
||||
use crate::builtins::builtin_defs_map;
|
||||
use crate::def::{can_defs_with_return, Annotation, Def};
|
||||
use crate::env::Env;
|
||||
|
@ -29,6 +29,7 @@ use roc_types::types::{Alias, Category, IndexOrField, LambdaSet, OptAbleVar, Typ
|
|||
use std::fmt::{Debug, Display};
|
||||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
use std::path::Path;
|
||||
use std::{char, u32};
|
||||
|
||||
/// Derives that an opaque type has claimed, to checked and recorded after solving.
|
||||
|
@ -103,7 +104,7 @@ pub enum Expr {
|
|||
},
|
||||
|
||||
// The bytes of a file and the expected type annotation.
|
||||
IngestedFile(Vec<u8>, annotation::Annotation),
|
||||
IngestedFile(Box<Path>, Vec<u8>, Variable),
|
||||
|
||||
// Lookups
|
||||
Var(Symbol, Variable),
|
||||
|
@ -302,7 +303,7 @@ impl Expr {
|
|||
Self::Int(..) => Category::Int,
|
||||
Self::Float(..) => Category::Frac,
|
||||
Self::Str(..) => Category::Str,
|
||||
Self::IngestedFile(..) => Category::IngestedFile,
|
||||
Self::IngestedFile(file_path, _, _) => Category::IngestedFile(file_path.clone()),
|
||||
Self::SingleQuote(..) => Category::Character,
|
||||
Self::List { .. } => Category::List,
|
||||
&Self::Var(sym, _) => Category::Lookup(sym),
|
||||
|
@ -735,23 +736,12 @@ pub fn canonicalize_expr<'a>(
|
|||
|
||||
ast::Expr::Str(literal) => flatten_str_literal(env, var_store, scope, literal),
|
||||
|
||||
ast::Expr::IngestedFile(file_path, type_ann) => match File::open(file_path) {
|
||||
ast::Expr::IngestedFile(file_path, _) => match File::open(file_path) {
|
||||
Ok(mut file) => {
|
||||
let mut bytes = vec![];
|
||||
match file.read_to_end(&mut bytes) {
|
||||
Ok(_) => (
|
||||
Expr::IngestedFile(
|
||||
bytes,
|
||||
annotation::canonicalize_annotation(
|
||||
env,
|
||||
scope,
|
||||
&type_ann.value,
|
||||
region,
|
||||
var_store,
|
||||
&VecMap::default(),
|
||||
annotation::AnnotationFor::Value,
|
||||
),
|
||||
),
|
||||
Expr::IngestedFile((*file_path).into(), bytes, var_store.fresh()),
|
||||
Output::default(),
|
||||
),
|
||||
Err(e) => {
|
||||
|
@ -3041,7 +3031,7 @@ pub(crate) fn get_lookup_symbols(expr: &Expr) -> Vec<ExpectLookup> {
|
|||
| Expr::Float(_, _, _, _, _)
|
||||
| Expr::Int(_, _, _, _, _)
|
||||
| Expr::Str(_)
|
||||
| Expr::IngestedFile(_, _)
|
||||
| Expr::IngestedFile(..)
|
||||
| Expr::ZeroArgumentTag { .. }
|
||||
| Expr::RecordAccessor(_)
|
||||
| Expr::SingleQuote(..)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue